]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/man/man2/getattrlist.2
xnu-3789.70.16.tar.gz
[apple/xnu.git] / bsd / man / man2 / getattrlist.2
... / ...
CommitLineData
1.\" Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
2.\"
3.\" The contents of this file constitute Original Code as defined in and
4.\" are subject to the Apple Public Source License Version 1.1 (the
5.\" "License"). You may not use this file except in compliance with the
6.\" License. Please obtain a copy of the License at
7.\" http://www.apple.com/publicsource and read it before using this file.
8.\"
9.\" This Original Code and all software distributed under the License are
10.\" distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
11.\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
12.\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
13.\" FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
14.\" License for the specific language governing rights and limitations
15.\" under the License.
16.\"
17.\" @(#)getattrlist.2
18.
19.Dd February 25, 2014
20.Dt GETATTRLIST 2
21.Os Darwin
22.Sh NAME
23.Nm getattrlist ,
24.Nm fgetattrlist ,
25.Nm getattrlistat
26.Nd get file system attributes
27.Sh SYNOPSIS
28.Fd #include <sys/attr.h>
29.Fd #include <unistd.h>
30.Ft int
31.Fn getattrlist "const char* path" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned long options"
32.
33.Ft int
34.Fn fgetattrlist "int fd" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned long options"
35.Ft int
36.Fo getattrlistat
37.Fa "int fd" "const char *path" "struct attrlist * attrList" "void * attrBuf"
38.Fa "size_t attrBufSize" "unsigned long options"
39.Fc
40.Sh DESCRIPTION
41The
42.Fn getattrlist
43function returns attributes (that is, metadata) of file system objects.
44.Fn getattrlist
45works on the file system object named by
46.Fa path ,
47while
48.Fn fgetattrlist
49works on the provided file descriptor
50.Fa fd .
51.Pp
52The
53.Fn getattrlistat
54system call is equivalent to
55.Fn getattrlist
56except in the case where
57.Fa path
58specifies a relative path.
59In this case the attributes are returned for the file system object named by
60path relative to the directory associated with the file descriptor
61.Fa fd
62instead of the current working directory.
63If
64.Fn getattrlistat
65is passed the special value
66.Dv AT_FDCWD
67in the
68.Fa fd
69parameter, the current working directory is used and the behavior is
70identical to a call to
71.Fn getattrlist .
72.Pp
73You can think of
74.Fn getattrlist
75as a seriously enhanced version of
76.Xr stat 2 .
77The functions return attributes about the specified file system object
78into the buffer specified by
79.Fa attrBuf
80and
81.Fa attrBufSize .
82The
83.Fa attrList
84parameter determines what attributes are returned.
85The
86.Fa options
87parameter lets you control specific aspects of the function's behavior.
88.Pp
89.
90Not all volumes support all attributes.
91See the discussion of
92.Dv ATTR_VOL_ATTRIBUTES
93for a discussion of how to determine whether a particular volume supports a
94particular attribute.
95.Pp
96Furthermore, you should only request the attributes that you need.
97Some attributes are expensive to calculate on some volume formats.
98For example,
99.Dv ATTR_DIR_ENTRYCOUNT
100is usually expensive to calculate on non-HFS [Plus] volumes.
101If you don't need a particular attribute, you should not ask for it.
102.Pp
103.
104.\" path parameter
105.
106The
107.Fa path
108parameter must reference a valid file system object.
109Read, write or execute permission of the object itself is not required, but
110all directories listed in the path name leading to the object must be
111searchable.
112.Pp
113.
114.\" attrList parameter
115.
116The
117.Fa attrList
118parameter is a pointer to an
119.Vt attrlist
120structure, as defined by
121.Aq Pa sys/attr.h
122(shown below).
123It determines what attributes are returned by the function.
124You are responsible for filling out all fields of this structure before calling the function.
125.Bd -literal
126typedef u_int32_t attrgroup_t;
127.Pp
128struct attrlist {
129 u_short bitmapcount; /* number of attr. bit sets in list */
130 u_int16_t reserved; /* (to maintain 4-byte alignment) */
131 attrgroup_t commonattr; /* common attribute group */
132 attrgroup_t volattr; /* volume attribute group */
133 attrgroup_t dirattr; /* directory attribute group */
134 attrgroup_t fileattr; /* file attribute group */
135 attrgroup_t forkattr; /* fork attribute group */
136};
137#define ATTR_BIT_MAP_COUNT 5
138.Ed
139.Pp
140.
141.\" attrlist elements
142.
143The fields of the
144.Vt attrlist
145structure are defined as follows.
146.Bl -tag -width XXXbitmapcount
147.
148.It bitmapcount
149Number of attribute bit sets in the structure.
150In current systems you must set this to
151.Dv ATTR_BIT_MAP_COUNT .
152.
153.It reserved
154Reserved.
155You must set this to 0.
156.
157.It commonattr
158A bit set that specifies the common attributes that you require.
159Common attributes relate to all types of file system objects.
160See below for a description of these attributes.
161.
162.It volattr
163A bit set that specifies the volume attributes that you require.
164Volume attributes relate to volumes (that is, mounted file systems).
165See below for a description of these attributes.
166If you request volume attributes,
167.Fa path
168must reference the root of a volume.
169In addition, you can't request volume attributes if you also request
170file or directory attributes.
171.
172.It dirattr
173A bit set that specifies the directory attributes that you require.
174See below for a description of these attributes.
175.
176.It fileattr
177A bit set that specifies the file attributes that you require.
178See below for a description of these attributes.
179.
180.It forkattr
181A bit set that specifies the fork attributes that you require.
182Fork attributes relate to the actual data in the file,
183which can be held in multiple named contiguous ranges, or forks.
184See below for a description of these attributes.
185If the FSOPT_ATTR_CMN_EXTENDED option is given, this bit set is reinterpreted
186as extended common attributes attributes, also described below.
187.
188.El
189.Pp
190.
191Unless otherwise noted in the lists below, attributes are read-only.
192Attributes labelled as read/write can be set using
193.Xr setattrlist 2 .
194.Pp
195.
196.\" attrBuf and attrBufSize parameters
197.
198The
199.Fa attrBuf
200and
201.Fa attrBufSize
202parameters specify a buffer into which the function places attribute values.
203The format of this buffer is sufficiently complex that its description
204requires a separate section (see below).
205The initial contents of this buffer are ignored.
206.Pp
207.
208.\" option parameter
209.
210The
211.Fa options
212parameter is a bit set that controls the behaviour of
213the functions.
214The following option bits are defined.
215.
216.Bl -tag -width FSOPT_PACK_INVAL_ATTRS
217.
218.It FSOPT_NOFOLLOW
219If this bit is set,
220.Fn getattrlist
221will not follow a symlink if it occurs as
222the last component of
223.Fa path .
224.
225.It FSOPT_REPORT_FULLSIZE
226The size of the attributes reported (in the first
227.Vt u_int32_t
228field in the attribute buffer) will be the size needed to hold all the
229requested attributes; if not set, only the attributes actually returned
230will be reported. This allows the caller to determine if any truncation
231occurred.
232.
233.It FSOPT_PACK_INVAL_ATTRS
234If this is bit is set, then all requested attributes, even ones that are
235not supported by the object or file system, will be returned. Default values
236will be used for the invalid ones. Requires that
237.Dv ATTR_CMN_RETURNED_ATTRS
238be requested.
239.
240.It FSOPT_ATTR_CMN_EXTENDED
241If this is bit is set, then
242.Dv ATTR_CMN_GEN_COUNT
243and
244.Dv ATTR_CMN_DOCUMENT_ID
245can be requested. When this option is used, forkattrs are reinterpreted as a
246set of extended common attributes.
247.
248.El
249.
250.Sh ATTRIBUTE BUFFER
251.
252The data returned in the buffer described by
253.Fa attrBuf
254and
255.Fa attrBufSize
256is formatted as follows.
257.Pp
258.
259.Bl -enum
260.
261.It
262The first element of the buffer is a
263.Vt u_int32_t
264that contains the overall length, in bytes, of the attributes returned.
265This size includes the length field itself.
266.
267.It
268Following the length field is a list of attributes.
269Each attribute is represented by a field of its type,
270where the type is given as part of the attribute description (below).
271.
272.It
273The attributes are placed into the attribute buffer in the order
274that they are described below.
275.
276.It
277Each attribute is aligned to a 4-byte boundary (including 64-bit data types).
278.El
279.Pp
280.
281If the attribute is of variable length, it is represented
282in the list by an
283.Vt attrreference
284structure, as defined by
285.Aq Pa sys/attr.h
286(shown below).
287.
288.Bd -literal
289typedef struct attrreference {
290 int32_t attr_dataoffset;
291 u_int32_t attr_length;
292} attrreference_t;
293.Ed
294.Pp
295.
296This structure contains a 'pointer' to the variable length attribute data.
297The
298.Fa attr_length
299field is the length of the attribute data (in bytes).
300The
301.Fa attr_dataoffset
302field is the offset in bytes from the
303.Vt attrreference
304structure
305to the attribute data.
306This offset will always be a multiple of sizeof(u_int32_t) bytes,
307so you can safely access common data types without fear of alignment
308exceptions.
309.Pp
310.
311The
312.Fn getattrlist
313function will silently truncate attribute data if
314.Fa attrBufSize
315is too small.
316The length field at the front of the attribute list always represents
317the length of the data actually copied into the attribute buffer.
318If the data is truncated, there is no easy way to determine the
319buffer size that's required to get all of the requested attributes.
320You should always pass an
321.Fa attrBufSize
322that is large enough to accommodate the known size of the attributes
323in the attribute list (including the leading length field).
324.Pp
325.
326Because the returned attributes are simply truncated if the buffer is
327too small, it's possible for a variable length attribute to reference
328data beyond the end of the attribute buffer. That is, it's possible
329for the attribute data to start beyond the end of the attribute buffer
330(that is, if
331.Fa attrRef
332is a pointer to the
333.Vt attrreference_t ,
334( ( (char *)
335.Fa attrRef
336) +
337.Fa attr_dataoffset
338) > ( ( (char *)
339.Fa attrBuf
340) +
341.Fa attrSize
342) ) or, indeed, for the attribute data to extend beyond the end of the attribute buffer (that is,
343( ( (char *)
344.Fa attrRef
345) +
346.Fa attr_dataoffset
347+
348.Fa attr_datalength
349) > ( ( (char *)
350.Fa attrBuf
351) +
352.Fa attrSize
353) ).
354If this happens you must increase the size of the buffer and call
355.Fn getattrlist
356to get an accurate copy of the attribute.
357.
358.Sh COMMON ATTRIBUTES
359.
360Common attributes relate to all types of file system objects.
361The following common attributes are defined.
362.
363.Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
364.
365.It ATTR_CMN_RETURNED_ATTRS
366An
367.Vt attribute_set_t
368structure which is used to report which of the requested attributes
369were actually returned. This attribute, when requested, will always
370be the first attribute returned. By default, unsupported attributes
371will be skipped (i.e. not packed into the output buffer). This behavior
372can be over-ridden using the FSOPT_PACK_INVAL_ATTRS option flag. Both
373.Xr getattrlist 2 and
374.Xr getatttrlistbulk 2 support this attribute while
375.Xr searchfs 2 does not.
376.
377.It ATTR_CMN_NAME
378An
379.Vt attrreference
380structure containing the name of the file system object as
381UTF-8 encoded, null terminated C string.
382The attribute data length will not be greater than
383.Dv NAME_MAX
384+ 1 characters, which is
385.Dv NAME_MAX
386* 3 + 1 bytes (as one UTF-8-encoded character may
387take up to three bytes).
388.Pp
389.
390.It ATTR_CMN_DEVID
391A
392.Vt dev_t
393containing the device number of the device on which this
394file system object's volume is mounted.
395Equivalent to the
396.Fa st_dev
397field of the
398.Vt stat
399structure returned by
400.Xr stat 2 .
401.
402.It ATTR_CMN_FSID
403An
404.Vt fsid_t
405structure containing the file system identifier for the volume on which
406the file system object resides.
407Equivalent to the
408.Fa f_fsid
409field of the
410.Vt statfs
411structure returned by
412.Xr statfs 2 .
413.
414.It ATTR_CMN_OBJTYPE
415An
416.Vt fsobj_type_t
417that identifies the type of file system object.
418The values are taken from
419.Vt enum vtype
420in
421.Aq Pa sys/vnode.h .
422.
423.It ATTR_CMN_OBJTAG
424An
425.Vt fsobj_tag_t
426that identifies the type of file system containing the object.
427The values are taken from
428.Vt enum vtagtype
429in
430.Aq Pa sys/vnode.h .
431.
432.It ATTR_CMN_OBJID
433An
434.Vt fsobj_id_t
435structure that uniquely identifies the file system object within a mounted
436volume for the duration of it's mount; this identifier is not guaranteed to be
437persistent for the volume and may change every time the volume is mounted.
438If the VOL_CAP_FMT_64BIT_OBJECT_IDS capability is set, this is instead a 64-bit
439object identifier.
440.Pp
441On HFS+ volumes, the ATTR_CMN_OBJID of a file system object is distinct from
442the ATTR_CMN_OBJID of any hard link to that file system object. Although the
443ATTR_CMN_OBJID of a file system object may appear similar (in whole
444or in part) to it's ATTR_CMN_FILEID (see description of ATTR_CMN_FILEID below),
445\fBno relation between the two attributes should ever be implied.\fP
446.
447.It ATTR_CMN_OBJPERMANENTID
448An
449.Vt fsobj_id_t
450structure that uniquely and persistently identifies the file system object
451within its volume; persistence implies that this attribute is unaffected by
452mount/unmount operations on the volume.
453If the VOL_CAP_FMT_64BIT_OBJECT_IDS capability is set, this is instead a 64-bit
454object identifier.
455.Pp
456Some file systems can not return this attribute when the volume is mounted
457read-only and will fail the request with error
458.Dv EROFS.
459.br
460(e.g. original HFS modifies on disk structures to generate persistent
461identifiers, and hence cannot do so if the volume is mounted read only.)
462.
463.It ATTR_CMN_PAROBJID
464An
465.Vt fsobj_id_t
466structure that uniquely identifies the parent directory of the file system
467object within a mounted volume, for the duration of the volume mount; this
468identifier is not guaranteed to be persistent for the volume and may change
469every time the volume is mounted.
470If the VOL_CAP_FMT_64BIT_OBJECT_IDS capability is set, this is instead a 64-bit
471object identifier.
472.Pp
473.
474If a file system object is hard linked from multiple directories, the parent
475directory returned for this attribute is non deterministic; it can be any one
476of the parent directories of this object.
477.
478For some volume formats the computing cost for this attribute is significant;
479developers are advised to request this attribute sparingly.
480.
481.It ATTR_CMN_SCRIPT
482(read/write) A
483.Vt text_encoding_t
484containing a text encoding hint for
485the file system object's name.
486It is included to facilitate the lossless round trip conversion of names between
487Unicode and traditional Mac OS script encodings.
488File systems that do not have an appropriate text encoding value should return
489kTextEncodingMacUnicode.
490.
491.It ATTR_CMN_CRTIME
492(read/write) A
493.Vt timespec
494structure containing the time that the file system object
495was created.
496.
497.It ATTR_CMN_MODTIME
498(read/write) A
499.Vt timespec
500structure containing the time that the file system object
501was last modified.
502Equivalent to the
503.Fa st_mtimespec
504field of the
505.Vt stat
506structure returned by
507.Xr stat 2 .
508.
509.It ATTR_CMN_CHGTIME
510A
511.Vt timespec
512structure containing the time that the file system object's
513attributes were last modified.
514Equivalent to the
515.Fa st_ctimespec
516field of the
517.Vt stat
518structure returned by
519.Xr stat 2 .
520.
521.It ATTR_CMN_ACCTIME
522(read/write) A
523.Vt timespec
524structure containing the time that the file system object
525was last accessed.
526Equivalent to the
527.Fa st_atimespec
528field of the
529.Vt stat
530structure returned by
531.Xr stat 2 .
532.
533.It ATTR_CMN_BKUPTIME
534(read/write) A
535.Vt timespec
536structure containing the time that the file system object was
537last backed up.
538This value is for use by backup utilities.
539The file system stores but does not interpret the value.
540.
541.It ATTR_CMN_FNDRINFO
542(read/write) 32 bytes of data for use by the Finder.
543Equivalent to the concatenation of a
544.Vt FileInfo
545structure and an
546.Vt ExtendedFileInfo
547structure
548(or, for directories, a
549.Vt FolderInfo
550structure and an
551.Vt ExtendedFolderInfo
552structure).
553.Pp
554This attribute is not byte swapped by the file system.
555The value of multibyte fields on disk is always big endian.
556When running on a little endian system (such as Darwin on x86),
557you must byte swap any multibyte fields.
558.
559.It ATTR_CMN_OWNERID
560(read/write) A
561.Vt uid_t
562containing the owner of the file system object.
563Equivalent to the
564.Fa st_uid
565field of the
566.Vt stat
567structure returned by
568.Xr stat 2 .
569.
570.It ATTR_CMN_GRPID
571(read/write) A
572.Vt gid_t
573containing the group of the file system object.
574Equivalent to the
575.Fa st_gid
576field of the
577.Vt stat
578structure returned by
579.Xr stat 2 .
580.
581.It ATTR_CMN_ACCESSMASK
582(read/write) A
583.Vt u_int32_t
584containing the access permissions of the file system object.
585Equivalent to the
586.Fa st_mode
587field of the
588.Vt stat
589structure returned by
590.Xr stat 2 .
591Only the permission bits of
592.Fa st_mode
593are valid; other bits should be ignored,
594e.g., by masking with
595.Dv ~S_IFMT .
596.
597.It ATTR_CMN_FLAGS
598(read/write) A
599.Vt u_int32_t
600containing file flags.
601Equivalent to the
602.Fa st_flags
603field of the
604.Vt stat
605structure returned by
606.Xr stat 2 .
607For more information about these flags, see
608.Xr chflags 2 .
609.
610.It ATTR_CMN_GEN_COUNT
611A
612.Vt u_int32_t
613containing a non zero monotonically increasing generation
614count for this file system object. The generation count tracks
615the number of times the data in a file system object has been
616modified. No meaning can be implied from its value. The
617value of the generation count for a file system object can
618be compared against a previous value of the same file system
619object for equality; i.e. an unchanged generation
620count indicates identical data. Requesting this attribute requires the
621FSOPT_ATTR_CMN_EXTENDED option flag.
622.Pp
623.
624A generation count value of 0 is invalid and cannot be used to
625determine data change.
626.Pp
627The generation count is invalid while a file is mmap'ed. An invalid
628generation count value of 0 will be returned for mmap'ed files.
629.
630.It ATTR_CMN_DOCUMENT_ID
631A
632.Vt u_int32_t
633containing the document id. The document id is a value assigned
634by the kernel to a document (which can be a file or directory)
635and is used to track the data regardless of where it gets moved.
636The document id survives safe saves; i.e it is sticky to the path it
637was assigned to. Requesting this attribute requires the
638FSOPT_ATTR_CMN_EXTENDED option flag.
639.Pp
640A document id of 0 is invalid.
641.
642.It ATTR_CMN_USERACCESS
643A
644.Vt u_int32_t
645containing the effective permissions of the current user
646(the calling process's effective UID) for this file system object.
647You can test for read, write, and execute permission using
648.Dv R_OK ,
649.Dv W_OK ,
650and
651.Dv X_OK ,
652respectively.
653See
654.Xr access 2
655for more details.
656.
657.It ATTR_CMN_EXTENDED_SECURITY
658A variable-length object (thus an
659.Vt attrreference
660structure) containing a
661.Vt kauth_filesec
662structure, of which only the ACL entry is used.
663.
664.It ATTR_CMN_UUID
665A
666.Vt guid_t
667of the owner of the file system object. Analoguous to
668.Dv ATTR_CMN_OWNERID .
669.
670.It ATTR_CMN_GRPUUID
671A
672.Vt guid_t
673of the group to which the file system object belongs.
674Analoguous to
675.Dv ATTR_CMN_GRPID .
676.
677.It ATTR_CMN_FILEID
678A
679.Vt u_int64_t
680that uniquely identifies the file system object within it's mounted volume.
681Equivalent to
682.Fa st_ino
683field of the
684.Vt stat
685structure returned by
686.Xr stat 2 .
687.
688.It ATTR_CMN_PARENTID
689A
690.Vt u_int64_t
691that identifies the parent directory of the file system object.
692.
693.It ATTR_CMN_FULLPATH
694An
695.Vt attrreference
696structure containing the full path (resolving all symlinks) to
697the file system object as
698a UTF-8 encoded, null terminated C string.
699The attribute data length will not be greater than
700.Dv PATH_MAX.
701Inconsistent behavior may be observed when this attribute is requested on
702hard-linked items, particularly when the file system does not support ATTR_CMN_PARENTID
703natively. Callers should be aware of this when requesting the full path of a hard-linked item.
704.
705.It ATTR_CMN_ADDEDTIME
706A
707.Vt timespec
708that contains the time that the file system object was created or renamed into
709its containing directory. Note that inconsistent behavior may be observed
710when this attribute is requested on hard-linked items.
711.
712.It ATTR_CMN_DATA_PROTECT_FLAGS
713A
714.Vt u_int32_t
715that contains the file or directory's data protection class.
716.Pp
717.
718.El
719.
720.Sh VOLUME ATTRIBUTES
721.
722Volume attributes relate to volumes (that is, mounted file systems).
723The following volume attributes are defined.
724.
725.Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
726.
727.It ATTR_VOL_INFO
728For reasons that are not at all obvious, you must set
729.Dv ATTR_VOL_INFO
730in the
731.Fa volattr
732field if you request any other volume attributes.
733This does not result in any attribute data being added to the attribute buffer.
734.
735.It ATTR_VOL_FSTYPE
736A
737.Vt u_int32_t
738containing the file system type.
739Equivalent to the
740.Fa f_type
741field of the
742.Vt statfs
743structure returned by
744.Xr statfs 2 .
745Generally not a useful value.
746.
747.It ATTR_VOL_SIGNATURE
748A
749.Vt u_int32_t
750containing the volume signature word.
751This value is unique within a given file system type and lets you
752distinguish between different volume formats handled by the same file system.
753.
754.It ATTR_VOL_SIZE
755An
756.Vt off_t
757containing the total size of the volume in bytes.
758.
759.It ATTR_VOL_SPACEFREE
760An
761.Vt off_t
762containing the free space on the volume in bytes.
763.
764.It ATTR_VOL_SPACEAVAIL
765An
766.Vt off_t
767containing the space, in bytes, on the volume available to non-privileged processes.
768This is the free space minus the amount of space reserved by the system to prevent critical
769disk exhaustion errors.
770Non-privileged programs, like a disk management tool, should use this value to display the
771space available to the user.
772.Pp
773.Dv ATTR_VOL_SPACEAVAIL
774is to
775.Dv ATTR_VOL_SPACEFREE
776as
777.Fa f_bavail
778is to
779.Fa f_bfree
780in
781.Xr statfs 2 .
782.
783.It ATTR_VOL_MINALLOCATION
784An
785.Vt off_t
786containing the minimum allocation size on the volume in bytes.
787If you create a file containing one byte, it will consume this much space.
788.
789.It ATTR_VOL_ALLOCATIONCLUMP
790An
791.Vt off_t
792containing the allocation clump size on the volume, in bytes.
793As a file is extended, the file system will attempt to allocate
794this much space each time in order to reduce fragmentation.
795.
796.It ATTR_VOL_IOBLOCKSIZE
797A
798.Vt u_int32_t
799containing the optimal block size when reading or writing data.
800Equivalent to the
801.Fa f_iosize
802field of the
803.Vt statfs
804structure returned by
805.Xr statfs 2 .
806.
807.It ATTR_VOL_OBJCOUNT
808A
809.Vt u_int32_t
810containing the number of file system objects on the volume.
811.
812.It ATTR_VOL_FILECOUNT
813A
814.Vt u_int32_t
815containing the number of files on the volume.
816.
817.It ATTR_VOL_DIRCOUNT
818A
819.Vt u_int32_t
820containing the number of directories on the volume.
821.
822.It ATTR_VOL_MAXOBJCOUNT
823A
824.Vt u_int32_t
825containing the maximum number of file system objects that can be stored on the volume.
826.
827.It ATTR_VOL_MOUNTPOINT
828An
829.Vt attrreference
830structure containing the path to the volume's mount point as a
831UTF-8 encoded, null terminated C string.
832The attribute data length will not be greater than
833.Dv MAXPATHLEN .
834Equivalent to the
835.Fa f_mntonname
836field of the
837.Vt statfs
838structure returned by
839.Xr statfs 2 .
840.
841.It ATTR_VOL_NAME
842(read/write) An
843.Vt attrreference
844structure containing the name of the volume as a
845UTF-8 encoded, null terminated C string.
846The attribute data length will not be greater than
847.Dv NAME_MAX +
8481.
849.Pp
850.
851This attribute is only read/write if the
852.Dv VOL_CAP_INT_VOL_RENAME
853bit is set in the volume capabilities (see below).
854.Pp
855.
856.It ATTR_VOL_MOUNTFLAGS
857A
858.Vt u_int32_t
859containing the volume mount flags.
860This is a copy of the value passed to the
861.Fa flags
862parameter of
863.Xr mount 2
864when the volume was mounted.
865Equivalent to the
866.Fa f_flags
867field of the
868.Vt statfs
869structure returned by
870.Xr statfs 2 .
871.
872.It ATTR_VOL_MOUNTEDDEVICE
873An
874.Vt attrreference
875structure that returns the same value as the
876.Fa f_mntfromname
877field of the
878.Vt statfs
879structure returned by
880.Xr statfs 2 .
881For local volumes this is the path to the device on which the volume is mounted as a
882UTF-8 encoded, null terminated C string.
883For network volumes, this is a unique string that identifies the mount.
884The attribute data length will not be greater than
885.Dv MAXPATHLEN .
886.Pp
887.
888.It ATTR_VOL_ENCODINGSUSED
889An
890.Vt unsigned long long
891containing a bitmap of the text encodings used on this volume.
892For more information about this, see the discussion of
893.Fa encodingsBitmap
894in DTS Technote 1150 "HFS Plus Volume Format".
895.
896.It ATTR_VOL_CAPABILITIES
897A
898.Vt vol_capabilities_attr_t
899structure describing the optional features supported by this volume.
900See below for a discussion of volume capabilities.
901.
902.It ATTR_VOL_UUID
903A
904.Vt uuid_t
905containing the file system UUID. Typically this will be a
906version 5 UUID.
907.
908.It ATTR_VOL_QUOTA_SIZE
909An
910.Vt off_t
911containing the maximum size of the volume in bytes.
912.
913.It ATTR_VOL_RESERVED_SIZE
914An
915.Vt off_t
916containing the minimum size of the volume in bytes.
917.
918.It ATTR_VOL_ATTRIBUTES
919A
920.Vt vol_attributes_attr_t
921structure describing the attributes supported by this volume.
922This structure is discussed below, along with volume capabilities.
923.
924.El
925.
926.Sh DIRECTORY ATTRIBUTES
927.
928The following directory attributes are defined.
929.
930.Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
931.
932.It ATTR_DIR_LINKCOUNT
933A
934.Vt u_int32_t
935containing the number of hard links to the directory;
936this does not include the historical "." and ".." entries.
937For file systems that do not support hard links to directories,
938this value will be 1.
939.
940.It ATTR_DIR_ENTRYCOUNT
941A
942.Vt u_int32_t
943containing the number of file system objects in the directory, not including
944any synthetic items. The historical "." and ".." entries are also
945excluded from this count.
946.
947.It ATTR_DIR_MOUNTSTATUS
948A
949.Vt u_int32_t
950containing flags describing what's mounted on the directory.
951Currently the only flag defined is
952.Dv DIR_MNTSTATUS_MNTPOINT,
953which indicates that there is a file system mounted on this directory.
954.
955.It ATTR_DIR_ALLOCSIZE
956An
957.Vt off_t
958containing the number of bytes on disk used by the directory
959(the physical size).
960.
961.It ATTR_DIR_IOBLOCKSIZE
962A
963.Vt u_int32_t
964containing the optimal block size when reading or writing data.
965.
966.It ATTR_DIR_DATALENGTH
967An
968.Vt off_t
969containing the length of the directory in bytes (the logical size).
970.El
971.
972.Pp
973Requested directory attributes are not returned for file system objects that
974are not directories.
975.
976.Sh FILE ATTRIBUTES
977.
978The following file attributes are defined.
979.
980.Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
981.
982.It ATTR_FILE_LINKCOUNT
983A
984.Vt u_int32_t
985containing the number of hard links to this file.
986Equivalent to the
987.Fa st_nlink
988field of the
989.Vt stat
990structure returned by
991.Xr stat 2 .
992.
993.It ATTR_FILE_TOTALSIZE
994An
995.Vt off_t
996containing the total number of bytes in all forks of the file (the logical size).
997.
998.It ATTR_FILE_ALLOCSIZE
999An
1000.Vt off_t
1001containing a count of the bytes on disk used by all of the file's forks (the physical size).
1002.
1003.It ATTR_FILE_IOBLOCKSIZE
1004A
1005.Vt u_int32_t
1006containing the optimal block size when reading or writing this file's data.
1007.
1008.It ATTR_FILE_CLUMPSIZE
1009A
1010.Vt u_int32_t
1011containing the allocation clump size for this file, in bytes.
1012As the file is extended, the file system will attempt to allocate
1013this much space each time in order to reduce fragmentation.
1014This value applies to the data fork.
1015.
1016.It ATTR_FILE_DEVTYPE
1017(read/write) A
1018.Vt u_int32_t
1019containing the device type for a special device file.
1020Equivalent to the
1021.Fa st_rdev
1022field of the
1023.Vt stat
1024structure returned by
1025.Xr stat 2 .
1026.
1027.It ATTR_FILE_FILETYPE
1028A
1029.Vt u_int32_t
1030that whose value is reserved.
1031Clients should ignore its value.
1032New volume format implementations should not support this attribute.
1033.
1034.It ATTR_FILE_FORKCOUNT
1035A
1036.Vt u_int32_t
1037containing the number of forks in the file.
1038No built-in file systems on Mac OS X currently support forks other
1039than the data and resource fork.
1040.
1041.It ATTR_FILE_FORKLIST
1042An
1043.Vt attrreference
1044structure containing a list of named forks of the file.
1045No built-in file systems on Mac OS X currently support forks
1046other than the data and resource fork.
1047Because of this, the structure of this attribute's value is not yet defined.
1048.
1049.It ATTR_FILE_DATALENGTH
1050An
1051.Vt off_t
1052containing the length of the data fork in bytes (the logical size).
1053.
1054.It ATTR_FILE_DATAALLOCSIZE
1055An
1056.Vt off_t
1057containing a count of the bytes on disk used by the data fork (the physical size).
1058.
1059.It ATTR_FILE_DATAEXTENTS
1060An
1061.Vt extentrecord
1062array for the data fork.
1063The array contains eight
1064.Vt diskextent
1065structures which represent the first
1066eight extents of the fork.
1067.Pp
1068This attributes exists for compatibility reasons.
1069New clients should not use this attribute.
1070Rather, they should use the
1071.Dv F_LOG2PHYS
1072command in
1073.Xr fcntl 2 .
1074.Pp
1075.
1076In current implementations the value may not be entirely accurate for
1077a variety of reasons.
1078.
1079.It ATTR_FILE_RSRCLENGTH
1080An
1081.Vt off_t
1082containing the length of the resource fork in bytes (the logical size).
1083.
1084.It ATTR_FILE_RSRCALLOCSIZE
1085An
1086.Vt off_t
1087containing a count of the bytes on disk used by the resource fork (the physical size).
1088.
1089.It ATTR_FILE_RSRCEXTENTS
1090An
1091.Vt extentrecord
1092array for the resource fork.
1093The array contains eight
1094.Vt diskextent
1095structures which represent the first
1096eight extents of the fork.
1097.Pp
1098See also
1099.Dv ATTR_FILE_DATAEXTENTS .
1100.
1101.El
1102.
1103.Pp
1104File attributes are used for any file system object that is not a directory,
1105not just ordinary files.
1106Requested file attributes are not returned for file system objects that
1107are directories.
1108.
1109.Sh FORK ATTRIBUTES
1110.
1111Fork attributes relate to the actual data in the file,
1112which can be held in multiple named contiguous ranges, or forks.
1113These cannot be used if the FSOPT_ATTR_CMN_EXTENDED is given.
1114The following fork attributes are defined.
1115.
1116.Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
1117.
1118.It ATTR_FORK_TOTALSIZE
1119Deprecated.
1120An
1121.Vt off_t
1122containing the length of the fork in bytes (the logical size).
1123.
1124.It ATTR_FORK_ALLOCSIZE
1125Deprecated.
1126An
1127.Vt off_t
1128containing a count of the bytes on disk used by the fork (the physical size).
1129.
1130.It ATTR_FORK_RESERVED
1131Reserved.
1132You must set this to 0.
1133.
1134.El
1135.Pp
1136.
1137Fork attributes are deprecated and all bits are reserved.
1138They are not properly implemented by any current Mac OS X
1139volume format implementation.
1140We strongly recommend that client programs do not request fork attributes.
1141If you are implementing a volume format, you should not support these attributes.
1142.
1143.Sh COMMON EXTENDED ATTRIBUTES
1144.
1145Common extended attributes are like common attributes except that they are set
1146in the forkattr field and can only be used if the FSOPT_ATTR_CMN_EXTENDED
1147option is given. Use of these attributes is mutually exclusive with the above
1148fork attributes.
1149.
1150.Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
1151.
1152.It ATTR_CMNEXT_RELPATH
1153An
1154.Vt attrreference
1155structure containing the mount-relative path of
1156the file system object as
1157a UTF-8 encoded, null terminated C string.
1158The attribute data length will not be greater than
1159.Dv PATH_MAX.
1160Inconsistent behavior may be observed when this attribute is requested on
1161hard-linked items, particularly when the file system does not support
1162ATTR_CMN_PARENTID natively. Callers should be aware of this when requesting the
1163relative path of a hard-linked item.
1164.
1165.It ATTR_CMNEXT_PRIVATESIZE
1166An
1167.Vt off_t
1168containing the number of bytes that are \fBnot\fP trapped inside a clone
1169or snapshot, and which would be freed immediately if the file were deleted.
1170.
1171.El
1172.
1173.Sh VOLUME CAPABILITIES
1174.
1175.\" vol_capabilities_attr_t
1176.
1177Not all volumes support all features.
1178The
1179.Dv ATTR_VOL_CAPABILITIES
1180attribute returns a
1181.Vt vol_capabilities_attr_t
1182structure (shown below) that indicates which features are supported by the volume.
1183.
1184.Bd -literal
1185typedef u_int32_t vol_capabilities_set_t[4];
1186.Pp
1187.
1188#define VOL_CAPABILITIES_FORMAT 0
1189#define VOL_CAPABILITIES_INTERFACES 1
1190#define VOL_CAPABILITIES_RESERVED1 2
1191#define VOL_CAPABILITIES_RESERVED2 3
1192.Pp
1193.
1194typedef struct vol_capabilities_attr {
1195 vol_capabilities_set_t capabilities;
1196 vol_capabilities_set_t valid;
1197} vol_capabilities_attr_t;
1198.Ed
1199.Pp
1200.
1201The structure contains two fields,
1202.Fa capabilities
1203and
1204.Fa valid .
1205Each consists of an array of four elements.
1206The arrays are indexed by the following values.
1207.
1208.Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1209.
1210.It VOL_CAPABILITIES_FORMAT
1211This element contains information about the volume format.
1212See
1213.Dv VOL_CAP_FMT_PERSISTENTOBJECTIDS
1214and so on, below.
1215.
1216.It VOL_CAPABILITIES_INTERFACES
1217This element contains information about which optional functions are
1218supported by the volume format implementation.
1219See
1220.Dv VOL_CAP_INT_SEARCHFS
1221and so on, below.
1222.
1223.It VOL_CAPABILITIES_RESERVED1
1224Reserved.
1225A file system implementation should set this element to zero.
1226A client program should ignore this element.
1227.
1228.It VOL_CAPABILITIES_RESERVED2
1229Reserved.
1230A file system implementation should set this element to zero.
1231A client program should ignore this element.
1232.
1233.El
1234.Pp
1235.
1236The
1237.Fa valid
1238field contains bit sets that indicate which flags are known to the volume format
1239implementation.
1240Each bit indicates whether the contents of the corresponding bit in the
1241.Fa capabilities
1242field is valid.
1243.Pp
1244.
1245The
1246.Fa capabilities
1247field contains bit sets that indicate whether a particular feature is implemented
1248by this volume format.
1249.Pp
1250.
1251The following bits are defined in the first element (indexed by
1252.Dv VOL_CAPABILITIES_FORMAT )
1253of the
1254.Fa capabilities
1255and
1256.Fa valid
1257fields of the
1258.Vt vol_capabilities_attr_t
1259structure.
1260.
1261.Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1262.
1263.It VOL_CAP_FMT_PERSISTENTOBJECTIDS
1264If this bit is set the volume format supports persistent object identifiers
1265and can look up file system objects by their IDs.
1266See
1267.Dv ATTR_CMN_OBJPERMANENTID
1268for details about how to obtain these identifiers.
1269.
1270.It VOL_CAP_FMT_SYMBOLICLINKS
1271If this bit is set the volume format supports symbolic links.
1272.
1273.It VOL_CAP_FMT_HARDLINKS
1274If this bit is set the volume format supports hard links.
1275.
1276.It VOL_CAP_FMT_JOURNAL
1277If this bit is set the volume format supports a journal used to
1278speed recovery in case of unplanned restart (such as a power outage
1279or crash).
1280This does not necessarily mean the volume is actively using a journal.
1281.Pp
1282Introduced with Darwin 7.0 (Mac OS X version 10.3).
1283.
1284.It VOL_CAP_FMT_JOURNAL_ACTIVE
1285If this bit is set the volume is currently using a journal for
1286speedy recovery after an unplanned restart.
1287This bit can be set only if
1288.Dv VOL_CAP_FMT_JOURNAL
1289is also set.
1290.Pp
1291Introduced with Darwin 7.0 (Mac OS X version 10.3).
1292.
1293.It VOL_CAP_FMT_NO_ROOT_TIMES
1294If this bit is set the volume format does not store reliable times for
1295the root directory, so you should not depend on them to detect changes,
1296identify volumes across unmount/mount, and so on.
1297.Pp
1298Introduced with Darwin 7.0 (Mac OS X version 10.3).
1299.
1300.It VOL_CAP_FMT_SPARSE_FILES
1301If this bit is set the volume format supports sparse files,
1302that is, files which can have 'holes' that have never been written
1303to, and thus do not consume space on disk.
1304A sparse file may have an allocated size on disk that is less than its logical length (that is,
1305.Dv ATTR_FILE_ALLOCSIZE
1306<
1307.Dv ATTR_FILE_TOTALSIZE ).
1308.
1309.Pp
1310Introduced with Darwin 7.0 (Mac OS X version 10.3).
1311.
1312.It VOL_CAP_FMT_ZERO_RUNS
1313For security reasons, parts of a file (runs) that have never been
1314written to must appear to contain zeroes.
1315When this bit is set, the volume keeps track of allocated but unwritten
1316runs of a file so that it can substitute zeroes without actually
1317writing zeroes to the media.
1318This provides performance similar to sparse files, but not the space savings.
1319.Pp
1320Introduced with Darwin 7.0 (Mac OS X version 10.3).
1321.
1322.It VOL_CAP_FMT_CASE_SENSITIVE
1323If this bit is set the volume format treats upper and lower case
1324characters in file and directory names as different.
1325Otherwise an upper case character is equivalent to a lower case character,
1326and you can't have two names that differ solely in the case of
1327the characters.
1328.Pp
1329Introduced with Darwin 7.0 (Mac OS X version 10.3).
1330.
1331.It VOL_CAP_FMT_CASE_PRESERVING
1332If this bit is set the volume format preserves the case of
1333file and directory names.
1334Otherwise the volume may change the case of some characters
1335(typically making them all upper or all lower case).
1336A volume that sets
1337.Dv VOL_CAP_FMT_CASE_SENSITIVE
1338must also set
1339.Dv VOL_CAP_FMT_CASE_PRESERVING .
1340.Pp
1341Introduced with Darwin 7.0 (Mac OS X version 10.3).
1342.
1343.It VOL_CAP_FMT_FAST_STATFS
1344This bit is used as a hint to upper layers to
1345indicate that
1346.Xr statfs 2
1347is fast enough that its results need not be cached by the caller.
1348A volume format implementation that caches the
1349.Xr statfs 2
1350information in memory should set this bit.
1351An implementation that must always read from disk or always perform a network
1352transaction to satisfy
1353.Xr statfs 2
1354should not set this bit.
1355.Pp
1356Introduced with Darwin 7.0 (Mac OS X version 10.3).
1357.
1358.It VOL_CAP_FMT_2TB_FILESIZE
1359If this bit is set the volume format supports file sizes larger
1360than 4GB, and potentially up to 2TB; it does not indicate
1361whether the file system supports files larger than that.
1362.Pp
1363Introduced with Darwin 8.0 (Mac OS X version 10.4).
1364.
1365.It VOL_CAP_FMT_OPENDENYMODES
1366If this bit is set, the volume format supports open deny modes
1367(e.g., "open for read write, deny write").
1368.
1369.It VOL_CAP_FMT_HIDDEN_FILES
1370If this bit is set, the volume format supports the
1371.Dv UF_HIDDEN
1372file flag, and the
1373.Dv UF_HIDDEN
1374flag is mapped to that volume's native "hidden" or "invisible"
1375bit (e.g., the invisible bit from the Finder Info extended attribute).
1376.
1377.It VOL_CAP_FMT_PATH_FROM_ID
1378If this bit is set, the volume format supports the ability to derive a pathname
1379to the root of the file system given only the ID of an object. This also
1380implies that object IDs on this file system are persistent and not recycled.
1381Most file systems will not support this capability.
1382.
1383.It VOL_CAP_FMT_NO_VOLUME_SIZES
1384If this bit is set the volume format does not support
1385determining values for total data blocks, available blocks, or free blocks, as in
1386.Fa f_blocks,
1387.Fa f_bavail,
1388and
1389.Fa f_bfree
1390in the
1391.Fa struct statfs
1392returned by
1393.Xr statfs 2 .
1394Historically, those values were set to 0xFFFFFFFF for volumes
1395that did not support them.
1396.Pp
1397Introduced with Darwin 10.0 (Mac OS X version 10.6).
1398.
1399.It VOL_CAP_FMT_64BIT_OBJECT_IDS
1400If this bit is set, the volume format uses object IDs that are 64-bit.
1401This means that ATTR_CMN_FILEID and ATTR_CMN_PARENTID are the primary means of
1402obtaining object IDs from this volume. The values returned by ATTR_CMN_OBJID,
1403ATTR_CMN_OBJPERMANENTID, and ATTR_CMN_PAROBJID can be interpreted as 64-bit
1404object IDs instead of fsobj_id_t.
1405.
1406.It VOL_CAP_FMT_NO_IMMUTABLE_FILES
1407If this bit is set, the volume format does not support setting the UF_IMMUTABLE
1408flag.
1409See ATTR_CMN_FLAGS for more details.
1410.It VOL_CAP_FMT_NO_PERMISSIONS
1411If this bit is set, the volume format does not support setting file
1412permissions.
1413See ATTR_CMN_USERACCESS for more details.
1414.
1415.El
1416.Pp
1417.
1418The following bits are defined in the second element (indexed by
1419.Dv VOL_CAPABILITIES_INTERFACES )
1420of the
1421.Fa capabilities
1422and
1423.Fa valid
1424fields of the
1425.Vt vol_capabilities_attr_t
1426structure.
1427.
1428.Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1429.
1430.It VOL_CAP_INT_SEARCHFS
1431If this bit is set the volume format implementation supports
1432.Xr searchfs 2 .
1433.
1434.It VOL_CAP_INT_ATTRLIST
1435If this bit is set the volume format implementation supports
1436.Fn getattrlist
1437and
1438.Xr setattrlist 2 .
1439.
1440.It VOL_CAP_INT_NFSEXPORT
1441If this bit is set the volume format implementation allows this volume to be exported via NFS.
1442.
1443.It VOL_CAP_INT_READDIRATTR
1444If this bit is set the volume format implementation supports
1445.Xr getdirentriesattr 2 .
1446.
1447.It VOL_CAP_INT_EXCHANGEDATA
1448If this bit is set the volume format implementation supports
1449.Xr exchangedata 2 .
1450.Pp
1451Introduced with Darwin 7.0 (Mac OS X version 10.3).
1452.
1453.It VOL_CAP_INT_COPYFILE
1454If this bit is set the volume format implementation supports the (private and undocumented)
1455copyfile() function.
1456(This is not the
1457.Xr copyfile 3
1458function.)
1459.Pp
1460Introduced with Darwin 7.0 (Mac OS X version 10.3).
1461.
1462.It VOL_CAP_INT_ALLOCATE
1463If this bit is set the volume format implementation supports the
1464.Dv F_PREALLOCATE
1465selector of
1466.Xr fcntl 2 .
1467.Pp
1468Introduced with Darwin 7.0 (Mac OS X version 10.3).
1469.
1470.It VOL_CAP_INT_VOL_RENAME
1471If this bit is set the volume format implementation allows you to
1472modify the volume name using
1473.Xr setattrlist 2 .
1474.Pp
1475Introduced with Darwin 7.0 (Mac OS X version 10.3).
1476.
1477.It VOL_CAP_INT_ADVLOCK
1478If this bit is set the volume format implementation supports
1479advisory locking, that is, the
1480.Dv F_GETLK ,
1481.Dv F_SETLK ,
1482and
1483.Dv F_SETLKW
1484selectors to
1485.Xr fcntl 2 .
1486.Pp
1487Introduced with Darwin 7.0 (Mac OS X version 10.3).
1488.
1489.It VOL_CAP_INT_FLOCK
1490If this bit is set the volume format implementation supports
1491whole file locks.
1492This includes
1493.Xr flock 2
1494and the
1495.Dv O_EXLOCK
1496and
1497.Dv O_SHLOCK
1498flags to
1499.Xr open 2 .
1500.Pp
1501Introduced with Darwin 7.0 (Mac OS X version 10.3).
1502.
1503.It VOL_CAP_INT_EXTENDED_SECURITY
1504If this bit is set the volume format implementation supports
1505extended security controls (ACLs).
1506.Pp
1507Introduced with Darwin 8.0 (Mac OS X version 10.4).
1508.
1509.It VOL_CAP_INT_USERACCESS
1510If this bit is set the volume format implementation supports the
1511ATTR_CMN_USERACCESS attribute.
1512.Pp
1513Introduced with Darwin 8.0 (Mac OS X version 10.4).
1514.
1515.It VOL_CAP_INT_MANLOCK
1516If this bit is set, the volume format implementation supports
1517AFP-style mandatory byte range locks via
1518.Xr ioctl 2 .
1519.
1520.It VOL_CAP_INT_EXTENDED_ATTR
1521If this bit is set, the volume format implementation supports
1522native extended attributes (see
1523.Xr setxattr 2 Ns ).
1524.
1525.It VOL_CAP_INT_CLONE
1526If this bit is set, the file system supports cloning files and directories.
1527See
1528.Xr clonefileat 2
1529for more details.
1530.
1531.It VOL_CAP_INT_NAMEDSTREAMS
1532If this bit is set, the volume format implementation supports
1533native named streams.
1534.
1535.It VOL_CAP_INT_RENAME_SWAP
1536If this bit is set, the file system supports swapping file system
1537objects. See
1538.Xr rename 2
1539for more details.
1540.
1541.It VOL_CAP_INT_RENAME_EXCL
1542If this bit is set, the file system supports an exclusive rename
1543operation. See
1544.Xr rename 2
1545for more details.
1546.
1547.El
1548.Pp
1549.
1550.\" vol_attributes_attr_t
1551.
1552A volume can also report which attributes it supports.
1553This information is returned by the
1554.Dv ATTR_VOL_ATTRIBUTES
1555attribute, which returns a
1556.Vt vol_attributes_attr_t
1557structure (shown below).
1558.
1559.Bd -literal
1560typedef struct attribute_set {
1561 attrgroup_t commonattr; /* common attribute group */
1562 attrgroup_t volattr; /* volume attribute group */
1563 attrgroup_t dirattr; /* directory attribute group */
1564 attrgroup_t fileattr; /* file attribute group */
1565 attrgroup_t forkattr; /* fork attribute group */
1566} attribute_set_t;
1567.Pp
1568.
1569typedef struct vol_attributes_attr {
1570 attribute_set_t validattr;
1571 attribute_set_t nativeattr;
1572} vol_attributes_attr_t;
1573.Ed
1574.Pp
1575.
1576The
1577.Fa validattr
1578field consists of a number of bit sets that indicate whether an attribute is
1579supported by the volume format implementation.
1580The
1581.Fa nativeattr
1582is similar except that the bit sets indicate whether an attribute is supported
1583natively by the volume format.
1584An attribute is supported natively if the volume format implementation does not have to do
1585any complex conversions to access the attribute.
1586For example, a volume format might support persistent object identifiers, but
1587doing so requires a complex table lookup that is not part of the core volume
1588format.
1589In that case, the
1590.Dv ATTR_VOL_ATTRIBUTES
1591attribute would return
1592.Dv ATTR_CMN_OBJPERMANENTID
1593set in the
1594.Fa validattr
1595field of the
1596.Vt vol_attributes_attr_t ,
1597but not in the
1598.Fa nativeattr
1599field.
1600.
1601.Sh RETURN VALUES
1602Upon successful completion a value of 0 is returned.
1603Otherwise, a value of -1 is returned and
1604.Va errno
1605is set to indicate the error.
1606.
1607.Sh COMPATIBILITY
1608Not all volumes support
1609.Fn getattrlist .
1610The best way to test whether a volume supports this function is to
1611simply call it and check the error result.
1612.Fn getattrlist
1613will return
1614.Dv ENOTSUP
1615if it is not supported on a particular volume.
1616.Pp
1617.
1618The
1619.Fn getattrlist
1620function has been undocumented for more than two years.
1621In that time a number of volume format implementations have been created without
1622a proper specification for the behaviour of this routine.
1623You may encounter volume format implementations with slightly different
1624behaviour than what is described here.
1625Your program is expected to be tolerant of this variant behaviour.
1626.Pp
1627.
1628If you're implementing a volume format that supports
1629.Fn getattrlist ,
1630you should be careful to support the behaviour specified by this document.
1631.
1632.Sh ERRORS
1633.Fn getattrlist
1634and
1635.Fn fgetattrlist
1636will fail if:
1637.Bl -tag -width Er
1638.
1639.It Bq Er ENOTSUP
1640The volume does not support the query.
1641.
1642.It Bq Er ENOTDIR
1643A component of the path prefix for
1644.Fn getattrlist
1645is not a directory.
1646.
1647.It Bq Er ENAMETOOLONG
1648A component of a path name for
1649.Fn getattrlist
1650exceeded
1651.Dv NAME_MAX
1652characters, or an entire path name exceeded
1653.Dv PATH_MAX
1654characters.
1655.
1656.It Bq Er ENOENT
1657The file system object for
1658.Fn getattrlist
1659does not exist.
1660.
1661.It Bq Er EBADF
1662The file descriptor argument for
1663.Fn fgetattrlist
1664is not a valid file descriptor.
1665.
1666.It Bq Er EACCES
1667Search permission is denied for a component of the path prefix for
1668.Fn getattrlist .
1669.
1670.It Bq Er ELOOP
1671Too many symbolic links were encountered in translating the pathname
1672for
1673.Fn getattrlist .
1674.
1675.It Bq Er EFAULT
1676.Fa path ,
1677.Fa attrList
1678or
1679.Em attrBuf
1680points to an invalid address.
1681.
1682.It Bq Er EINVAL
1683The
1684.Fa bitmapcount
1685field of
1686.Fa attrList
1687is not
1688.Dv ATTR_BIT_MAP_COUNT .
1689.
1690.It Bq Er EINVAL
1691You requested an invalid attribute.
1692.
1693.It Bq Er EINVAL
1694You requested an attribute that is not supported for this file system object.
1695.
1696.It Bq Er EINVAL
1697You requested volume attributes and directory or file attributes.
1698.
1699.It Bq Er EINVAL
1700You requested volume attributes but
1701.Fa path
1702does not reference the root of the volume.
1703.
1704.It Bq Er EROFS
1705The volume is read-only but must be modified in order to return this attribute.
1706.
1707.It Bq Er EIO
1708An I/O error occurred while reading from or writing to the file system.
1709.El
1710.Pp
1711In addition to the errors returned by the
1712.Fn getattrlist ,
1713the
1714.Fn getattrlistat
1715function may fail if:
1716.Bl -tag -width Er
1717.It Bq Er EBADF
1718The
1719.Fa path
1720argument does not specify an absolute path and the
1721.Fa fd
1722argument is neither
1723.Dv AT_FDCWD
1724nor a valid file descriptor open for searching.
1725.It Bq Er ENOTDIR
1726The
1727.Fa path
1728argument is not an absolute path and
1729.Fa fd
1730is neither
1731.Dv AT_FDCWD
1732nor a file descriptor associated with a directory.
1733.El
1734.Pp
1735.
1736.Sh CAVEATS
1737.
1738If you request any volume attributes, you must set
1739.Dv ATTR_VOL_INFO
1740in the
1741.Fa volattr
1742field, even though it generates no result in the attribute buffer.
1743.Pp
1744.
1745The order that attributes are stored in the attribute buffer almost
1746invariably matches the order of attribute mask bit values.
1747For example,
1748.Dv ATTR_CMN_NAME
1749(0x00000001) comes before
1750.Dv ATTR_CMN_DEVID
1751(0x00000002) because its value is smaller.
1752When ordering attributes, you should always use the order in which they
1753are described above.
1754.Pp
1755.
1756The
1757.Vt timespec
1758structure is 64-bits (two 32-bit elements) in 32-bit code, and
1759128-bits (two 64-bit elements) in 64-bit code; however, it is aligned
1760on a 4-byte (32-bit) boundary, even in 64-bit code.
1761.Pp
1762If you use a structure
1763for the attribute data, it must be correctly packed and aligned (see
1764examples).
1765.Pp
1766.
1767Inconsistent behavior may be observed when the ATTR_CMN_FULLPATH attribute is requested on
1768hard-linked items, particularly when the file system does not support ATTR_CMN_PARENTID
1769natively. Callers should be aware of this when requesting the full path of a hard-linked item, especially
1770if the full path crosses mount points.
1771.Pp
1772.
1773For more caveats, see also the compatibility notes above.
1774.
1775.Sh EXAMPLES
1776.
1777The following code prints the file type and creator of a file,
1778assuming that the volume supports the required attributes.
1779.
1780.Bd -literal
1781#include <assert.h>
1782#include <stdio.h>
1783#include <string.h>
1784#include <sys/attr.h>
1785#include <sys/errno.h>
1786#include <unistd.h>
1787#include <sys/vnode.h>
1788.Pp
1789.
1790typedef struct attrlist attrlist_t;
1791.Pp
1792.
1793struct FInfoAttrBuf {
1794 u_int32_t length;
1795 fsobj_type_t objType;
1796 char finderInfo[32];
1797} __attribute__((aligned(4), packed));
1798typedef struct FInfoAttrBuf FInfoAttrBuf;
1799.Pp
1800.
1801static int FInfoDemo(const char *path)
1802{
1803 int err;
1804 attrlist_t attrList;
1805 FInfoAttrBuf attrBuf;
1806.Pp
1807.
1808 memset(&attrList, 0, sizeof(attrList));
1809 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
1810 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
1811.Pp
1812
1813 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
1814 if (err != 0) {
1815 err = errno;
1816 }
1817.Pp
1818
1819 if (err == 0) {
1820 assert(attrBuf.length == sizeof(attrBuf));
1821.Pp
1822
1823 printf("Finder information for %s:\en", path);
1824 switch (attrBuf.objType) {
1825 case VREG:
1826 printf("file type = '%.4s'\en", &attrBuf.finderInfo[0]);
1827 printf("file creator = '%.4s'\en", &attrBuf.finderInfo[4]);
1828 break;
1829 case VDIR:
1830 printf("directory\en");
1831 break;
1832 default:
1833 printf("other object type, %d\en", attrBuf.objType);
1834 break;
1835 }
1836 }
1837.Pp
1838.
1839 return err;
1840}
1841.Ed
1842.Pp
1843.
1844The following code is an alternative implementation that uses nested structures
1845to group the related attributes.
1846.
1847.Bd -literal
1848#include <assert.h>
1849#include <stdio.h>
1850#include <stddef.h>
1851#include <string.h>
1852#include <sys/attr.h>
1853#include <sys/errno.h>
1854#include <unistd.h>
1855#include <sys/vnode.h>
1856.Pp
1857.
1858typedef struct attrlist attrlist_t;
1859.Pp
1860.
1861struct FInfo2CommonAttrBuf {
1862 fsobj_type_t objType;
1863 char finderInfo[32];
1864} __attribute__((aligned(4), packed));
1865typedef struct FInfo2CommonAttrBuf FInfo2CommonAttrBuf;
1866.Pp
1867.
1868struct FInfo2AttrBuf {
1869 u_int32_t length;
1870 FInfo2CommonAttrBuf common;
1871} __attribute__((aligned(4), packed));;
1872typedef struct FInfo2AttrBuf FInfo2AttrBuf;
1873.Pp
1874.
1875static int FInfo2Demo(const char *path)
1876{
1877 int err;
1878 attrlist_t attrList;
1879 FInfo2AttrBuf attrBuf;
1880.Pp
1881.
1882 memset(&attrList, 0, sizeof(attrList));
1883 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
1884 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
1885.Pp
1886.
1887 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
1888 if (err != 0) {
1889 err = errno;
1890 }
1891.Pp
1892.
1893 if (err == 0) {
1894 assert(attrBuf.length == sizeof(attrBuf));
1895.Pp
1896.
1897 printf("Finder information for %s:\en", path);
1898 switch (attrBuf.common.objType) {
1899 case VREG:
1900 printf(
1901 "file type = '%.4s'\en",
1902 &attrBuf.common.finderInfo[0]
1903 );
1904 printf(
1905 "file creator = '%.4s'\en",
1906 &attrBuf.common.finderInfo[4]
1907 );
1908 break;
1909 case VDIR:
1910 printf("directory\en");
1911 break;
1912 default:
1913 printf(
1914 "other object type, %d\en",
1915 attrBuf.common.objType
1916 );
1917 break;
1918 }
1919 }
1920.Pp
1921.
1922 return err;
1923}
1924.Ed
1925.Pp
1926.
1927The following example shows how to deal with variable length attributes.
1928It assumes that the volume specified by
1929.Fa path
1930supports the necessary attributes.
1931.
1932.Bd -literal
1933#include <assert.h>
1934#include <stdio.h>
1935#include <stddef.h>
1936#include <string.h>
1937#include <sys/attr.h>
1938#include <sys/errno.h>
1939#include <unistd.h>
1940#include <sys/vnode.h>
1941.Pp
1942.
1943typedef struct attrlist attrlist_t;
1944.Pp
1945.
1946struct VolAttrBuf {
1947 u_int32_t length;
1948 u_int32_t fileCount;
1949 u_int32_t dirCount;
1950 attrreference_t mountPointRef;
1951 attrreference_t volNameRef;
1952 char mountPointSpace[MAXPATHLEN];
1953 char volNameSpace[MAXPATHLEN];
1954} __attribute__((aligned(4), packed));
1955typedef struct VolAttrBuf VolAttrBuf;
1956.Pp
1957.
1958static int VolDemo(const char *path)
1959{
1960 int err;
1961 attrlist_t attrList;
1962 VolAttrBuf attrBuf;
1963.Pp
1964.
1965 memset(&attrList, 0, sizeof(attrList));
1966 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
1967 attrList.volattr = ATTR_VOL_INFO
1968 | ATTR_VOL_FILECOUNT
1969 | ATTR_VOL_DIRCOUNT
1970 | ATTR_VOL_MOUNTPOINT
1971 | ATTR_VOL_NAME;
1972.Pp
1973
1974 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
1975 if (err != 0) {
1976 err = errno;
1977 }
1978.Pp
1979
1980 if (err == 0) {
1981 assert(attrBuf.length > offsetof(VolAttrBuf, mountPointSpace));
1982 assert(attrBuf.length <= sizeof(attrBuf));
1983.Pp
1984
1985 printf("Volume information for %s:\en", path);
1986 printf("ATTR_VOL_FILECOUNT: %u\en", attrBuf.fileCount);
1987 printf("ATTR_VOL_DIRCOUNT: %u\en", attrBuf.dirCount);
1988 printf(
1989 "ATTR_VOL_MOUNTPOINT: %.*s\en",
1990 (int) attrBuf.mountPointRef.attr_length,
1991 ( ((char *) &attrBuf.mountPointRef)
1992 + attrBuf.mountPointRef.attr_dataoffset )
1993 );
1994 printf(
1995 "ATTR_VOL_NAME: %.*s\en",
1996 (int) attrBuf.volNameRef.attr_length,
1997 ( ((char *) &attrBuf.volNameRef)
1998 + attrBuf.volNameRef.attr_dataoffset )
1999 );
2000 }
2001.Pp
2002.
2003 return err;
2004}
2005.Ed
2006.Pp
2007The following sample demonstrates the need to use packing and alignment
2008controls; without the attribute, in 64-bit code, the fields of the structure are not
2009placed at the locations that the kernel expects.
2010.
2011.Bd -literal
2012#include <stdio.h>
2013#include <stdlib.h>
2014#include <unistd.h>
2015#include <string.h>
2016#include <err.h>
2017#include <time.h>
2018#include <sys/attr.h>
2019.Pp
2020/* The alignment and packing attribute is necessary in 64-bit code */
2021struct AttrListTimes {
2022 u_int32_t length;
2023 struct timespec st_crtime;
2024 struct timespec st_modtime;
2025} __attribute__((aligned(4), packed));
2026.Pp
2027main(int argc, char **argv)
2028{
2029 int rv;
2030 int i;
2031.Pp
2032 for (i = 1; i < argc; i++) {
2033 struct attrlist attrList;
2034 struct AttrListTimes myStat = {0};
2035 char *path = argv[i];
2036.Pp
2037 memset(&attrList, 0, sizeof(attrList));
2038 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
2039 attrList.commonattr = ATTR_CMN_CRTIME |
2040 ATTR_CMN_MODTIME;
2041.Pp
2042 rv = getattrlist(path, &attrList, &myStat, sizeof(myStat), 0);
2043.Pp
2044 if (rv == -1) {
2045 warn("getattrlist(%s)", path);
2046 continue;
2047 }
2048 printf("%s: Modification time = %s", argv[i], ctime(&myStat.st_modtime.tv_sec));
2049 }
2050 return 0;
2051}
2052.Ed
2053.Pp
2054.
2055.Sh SEE ALSO
2056.
2057.Xr access 2 ,
2058.Xr chflags 2 ,
2059.Xr exchangedata 2 ,
2060.Xr fcntl 2 ,
2061.Xr getattrlistbulk 2 ,
2062.Xr mount 2 ,
2063.Xr searchfs 2 ,
2064.Xr setattrlist 2 ,
2065.Xr stat 2 ,
2066.Xr statfs 2
2067.
2068.Sh HISTORY
2069A
2070.Fn getattrlist
2071function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).
2072The
2073.Fn getattrlistat
2074function call appeared in OS X 10.10 .