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