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