1 .\" Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
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.
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.
26 .Nd get file system attributes
28 .Fd #include <sys/attr.h>
29 .Fd #include <unistd.h>
31 .Fn getattrlist "const char* path" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned long options"
34 .Fn fgetattrlist "int fd" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned long options"
37 .Fa "int fd" "const char *path" "struct attrlist * attrList" "void * attrBuf"
38 .Fa "size_t attrBufSize" "unsigned long options"
43 function returns attributes (that is, metadata) of file system objects.
45 works on the file system object named by
49 works on the provided file descriptor
54 system call is equivalent to
56 except in the case where
58 specifies a relative path.
59 In this case the attributes are returned for the file system object named by
60 path relative to the directory associated with the file descriptor
62 instead of the current working directory.
65 is passed the special value
69 parameter, the current working directory is used and the behavior is
70 identical to a call to
75 as a seriously enhanced version of
77 The functions return attributes about the specified file system object
78 into the buffer specified by
84 parameter determines what attributes are returned.
87 parameter lets you control specific aspects of the function's behavior.
90 Not all volumes support all attributes.
92 .Dv ATTR_VOL_ATTRIBUTES
93 for a discussion of how to determine whether a particular volume supports a
96 Furthermore, you should only request the attributes that you need.
97 Some attributes are expensive to calculate on some volume formats.
99 .Dv ATTR_DIR_ENTRYCOUNT
100 is usually expensive to calculate on non-HFS [Plus] volumes.
101 If you don't need a particular attribute, you should not ask for it.
108 parameter must reference a valid file system object.
109 Read, write or execute permission of the object itself is not required, but
110 all directories listed in the path name leading to the object must be
114 .\" attrList parameter
118 parameter is a pointer to an
120 structure, as defined by
123 It determines what attributes are returned by the function.
124 You are responsible for filling out all fields of this structure before calling the function.
126 typedef u_int32_t attrgroup_t;
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 */
137 #define ATTR_BIT_MAP_COUNT 5
141 .\" attrlist elements
145 structure are defined as follows.
146 .Bl -tag -width XXXbitmapcount
149 Number of attribute bit sets in the structure.
150 In current systems you must set this to
151 .Dv ATTR_BIT_MAP_COUNT .
155 You must set this to 0.
158 A bit set that specifies the common attributes that you require.
159 Common attributes relate to all types of file system objects.
160 See below for a description of these attributes.
163 A bit set that specifies the volume attributes that you require.
164 Volume attributes relate to volumes (that is, mounted file systems).
165 See below for a description of these attributes.
166 If you request volume attributes,
168 must reference the root of a volume.
169 You must set ATTR_VOL_INFO in the volattr field if you request any
170 other volume attributes.
171 In addition, you can't request volume attributes if you also request
172 file, directory, fork or extended common attributes.
173 In addition, you can't request volume attributes if you also request the common
174 attributes ATTR_CMN_EXTENDED_SECURITY, ATTR_CMN_UUID, ATTR_CMN_GRPUUID,
175 ATTR_CMN_FILEID, or ATTR_CMN_PARENTID.
178 A bit set that specifies the directory attributes that you require.
179 See below for a description of these attributes.
182 A bit set that specifies the file attributes that you require.
183 See below for a description of these attributes.
186 A bit set that specifies the fork attributes that you require.
187 Fork attributes relate to the actual data in the file,
188 which can be held in multiple named contiguous ranges, or forks.
189 See below for a description of these attributes.
190 If the FSOPT_ATTR_CMN_EXTENDED option is given, this bit set is reinterpreted
191 as extended common attributes attributes, also described below.
196 Unless otherwise noted in the lists below, attributes are read-only.
197 Attributes labelled as read/write can be set using
201 .\" attrBuf and attrBufSize parameters
207 parameters specify a buffer into which the function places attribute values.
208 The format of this buffer is sufficiently complex that its description
209 requires a separate section (see below).
210 The initial contents of this buffer are ignored.
217 parameter is a bit set that controls the behaviour of
219 The following option bits are defined.
221 .Bl -tag -width FSOPT_PACK_INVAL_ATTRS
226 will not follow a symlink if it occurs as
227 the last component of
230 .It FSOPT_REPORT_FULLSIZE
231 The size of the attributes reported (in the first
233 field in the attribute buffer) will be the size needed to hold all the
234 requested attributes; if not set, only the attributes actually returned
235 will be reported. This allows the caller to determine if any truncation
238 .It FSOPT_PACK_INVAL_ATTRS
239 If this is bit is set, then all requested attributes, even ones that are
240 not supported by the object or file system, will be returned. Default values
241 will be used for the invalid ones. Requires that
242 .Dv ATTR_CMN_RETURNED_ATTRS
245 .It FSOPT_ATTR_CMN_EXTENDED
246 If this is bit is set, then
247 .Dv ATTR_CMN_GEN_COUNT
249 .Dv ATTR_CMN_DOCUMENT_ID
250 can be requested. When this option is used, forkattrs are reinterpreted as a
251 set of extended common attributes.
253 .It FSOPT_RETURN_REALDEV
254 If this is bit is set, then ATTR_CMN_DEVID and ATTR_CMN_FSID will return
255 the values corresponding to the physical volume they are on. When a
256 filesystem supports VOL_CAP_INT_VOLUME_GROUPS, it is possible that the
257 filesystem may return a common logical value for these attributes otherwise.
263 The data returned in the buffer described by
267 is formatted as follows.
273 The first element of the buffer is a
275 that contains the overall length, in bytes, of the attributes returned.
276 This size includes the length field itself.
279 Following the length field is a list of attributes.
280 Each attribute is represented by a field of its type,
281 where the type is given as part of the attribute description (below).
284 The attributes are placed into the attribute buffer in the order
285 that they are described below.
288 Each attribute is aligned to a 4-byte boundary (including 64-bit data types).
292 If the attribute is of variable length, it is represented
295 structure, as defined by
300 typedef struct attrreference {
301 int32_t attr_dataoffset;
302 u_int32_t attr_length;
307 This structure contains a 'pointer' to the variable length attribute data.
310 field is the length of the attribute data (in bytes).
313 field is the offset in bytes from the
316 to the attribute data.
317 This offset will always be a multiple of sizeof(u_int32_t) bytes,
318 so you can safely access common data types without fear of alignment
324 function will silently truncate attribute data if
327 The length field at the front of the attribute list always represents
328 the length of the data actually copied into the attribute buffer.
329 If the data is truncated, there is no easy way to determine the
330 buffer size that's required to get all of the requested attributes.
331 You should always pass an
333 that is large enough to accommodate the known size of the attributes
334 in the attribute list (including the leading length field).
337 Because the returned attributes are simply truncated if the buffer is
338 too small, it's possible for a variable length attribute to reference
339 data beyond the end of the attribute buffer. That is, it's possible
340 for the attribute data to start beyond the end of the attribute buffer
344 .Vt attrreference_t ,
353 ) ) or, indeed, for the attribute data to extend beyond the end of the attribute buffer (that is,
365 If this happens you must increase the size of the buffer and call
367 to get an accurate copy of the attribute.
369 .Sh COMMON ATTRIBUTES
371 Common attributes relate to all types of file system objects.
372 The following common attributes are defined.
374 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
376 .It ATTR_CMN_RETURNED_ATTRS
379 structure which is used to report which of the requested attributes
380 were actually returned. This attribute, when requested, will always
381 be the first attribute returned. By default, unsupported attributes
382 will be skipped (i.e. not packed into the output buffer). This behavior
383 can 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.
391 structure containing the name of the file system object as
392 UTF-8 encoded, null terminated C string.
393 The attribute data length will not be greater than
395 + 1 characters, which is
397 * 3 + 1 bytes (as one UTF-8-encoded character may
398 take up to three bytes).
404 containing the device number of the device on which this
405 file system object's volume is mounted.
410 structure returned by
416 structure containing the file system identifier for the volume on which
417 the file system object resides.
422 structure returned by
428 that identifies the type of file system object.
429 The values are taken from
437 that identifies the type of file system containing the object.
438 The values are taken from
446 structure that uniquely identifies the file system object within a mounted
447 volume for the duration of its mount; this identifier is not guaranteed to be
448 persistent for the volume and may change every time the volume is mounted.
450 On HFS+ volumes, the ATTR_CMN_OBJID of a file system object is distinct from
451 the ATTR_CMN_OBJID of any hard link to that file system object. Although the
452 ATTR_CMN_OBJID of a file system object may appear similar (in whole
453 or 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
456 ATTR_CMN_OBJID is deprecated sarting with macOS 10.13, iOS 11.0, watchOS 4.0 and
457 tvOS 11.0 and ATTR_CMNEXT_LINKID should be used in its place.
458 ATTR_CMN_OBJID can only be used on older operating systems only if the file
459 system doesn't 64 bit IDs. See the
461 function in the EXAMPLES section.
463 .It ATTR_CMN_OBJPERMANENTID
466 structure that uniquely and persistently identifies the file system object
467 within its volume; persistence implies that this attribute is unaffected by
468 mount/unmount operations on the volume.
470 Some file systems can not return this attribute when the volume is mounted
471 read-only and will fail the request with error
474 (e.g. original HFS modifies on disk structures to generate persistent
475 identifiers, and hence cannot do so if the volume is mounted read only.)
477 .It ATTR_CMN_PAROBJID
480 structure that uniquely identifies the parent directory of the file system
481 object within a mounted volume, for the duration of the volume mount; this
482 identifier is not guaranteed to be persistent for the volume and may change
483 every time the volume is mounted.
486 If a file system object is hard linked from multiple directories, the parent
487 directory returned for this attribute is non deterministic; it can be any one
488 of the parent directories of this object.
490 For some volume formats the computing cost for this attribute is significant;
491 developers are advised to request this attribute sparingly.
496 containing a text encoding hint for
497 the file system object's name.
498 It is included to facilitate the lossless round trip conversion of names between
499 Unicode and traditional Mac OS script encodings.
500 File systems that do not have an appropriate text encoding value should return
501 kTextEncodingMacUnicode.
506 structure containing the time that the file system object
512 structure containing the time that the file system object
518 structure returned by
524 structure containing the time that the file system object's
525 attributes were last modified.
530 structure returned by
536 structure containing the time that the file system object
542 structure returned by
545 .It ATTR_CMN_BKUPTIME
548 structure containing the time that the file system object was
550 This value is for use by backup utilities.
551 The file system stores but does not interpret the value.
553 .It ATTR_CMN_FNDRINFO
554 (read/write) 32 bytes of data for use by the Finder.
555 Equivalent to the concatenation of a
560 (or, for directories, a
563 .Vt ExtendedFolderInfo
566 This attribute is not byte swapped by the file system.
567 The value of multibyte fields on disk is always big endian.
568 When running on a little endian system (such as Darwin on x86),
569 you must byte swap any multibyte fields.
574 containing the owner of the file system object.
579 structure returned by
585 containing the group of the file system object.
590 structure returned by
593 .It ATTR_CMN_ACCESSMASK
596 containing the access permissions of the file system object.
601 structure returned by
603 Only the permission bits of
605 are valid; other bits should be ignored,
606 e.g., by masking with
612 containing file flags.
617 structure returned by
619 For more information about these flags, see
622 .It ATTR_CMN_GEN_COUNT
625 containing a non zero monotonically increasing generation
626 count for this file system object. The generation count tracks
627 the number of times the data in a file system object has been
628 modified. No meaning can be implied from its value. The
629 value of the generation count for a file system object can
630 be compared against a previous value of the same file system
631 object for equality; i.e. an unchanged generation
632 count indicates identical data. Requesting this attribute requires the
633 FSOPT_ATTR_CMN_EXTENDED option flag.
636 A generation count value of 0 is invalid and cannot be used to
637 determine data change.
639 The generation count is invalid while a file is mmap'ed. An invalid
640 generation count value of 0 will be returned for mmap'ed files.
642 .It ATTR_CMN_DOCUMENT_ID
645 containing the document id. The document id is a value assigned
646 by the kernel to a document (which can be a file or directory)
647 and is used to track the data regardless of where it gets moved.
648 The document id survives safe saves; i.e it is sticky to the path it
649 was assigned to. Requesting this attribute requires the
650 FSOPT_ATTR_CMN_EXTENDED option flag.
652 A document id of 0 is invalid.
654 .It ATTR_CMN_USERACCESS
657 containing the effective permissions of the current user
658 (the calling process's effective UID) for this file system object.
659 You can test for read, write, and execute permission using
669 .It ATTR_CMN_EXTENDED_SECURITY
670 A variable-length object (thus an
672 structure) containing a
674 structure, of which only the ACL entry is used.
679 of the owner of the file system object. Analoguous to
680 .Dv ATTR_CMN_OWNERID .
685 of the group to which the file system object belongs.
692 that uniquely identifies the file system object within its mounted volume.
697 structure returned by
700 .It ATTR_CMN_PARENTID
703 that identifies the parent directory of the file system object.
705 .It ATTR_CMN_FULLPATH
708 structure containing the full path (resolving all symlinks) to
709 the file system object as
710 a UTF-8 encoded, null terminated C string.
711 The attribute data length will not be greater than
713 Inconsistent behavior may be observed when this attribute is requested on
714 hard-linked items, particularly when the file system does not support ATTR_CMN_PARENTID
715 natively. Callers should be aware of this when requesting the full path of a hard-linked item.
717 .It ATTR_CMN_ADDEDTIME
720 that contains the time that the file system object was created or renamed into
721 its containing directory. Note that inconsistent behavior may be observed
722 when this attribute is requested on hard-linked items.
724 .It ATTR_CMN_DATA_PROTECT_FLAGS
727 that contains the file or directory's data protection class.
732 .Sh VOLUME ATTRIBUTES
734 Volume attributes relate to volumes (that is, mounted file systems).
735 The following volume attributes are defined.
737 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
740 For historical reasons you must set
744 field if you request any other volume attributes.
749 containing the file system type.
754 structure returned by
756 Generally not a useful value.
758 .It ATTR_VOL_SIGNATURE
761 containing the volume signature word.
762 This value is unique within a given file system type and lets you
763 distinguish between different volume formats handled by the same file system.
768 containing the total size of the volume in bytes.
770 .It ATTR_VOL_SPACEFREE
773 containing the free space on the volume in bytes.
775 .It ATTR_VOL_SPACEAVAIL
778 containing the space, in bytes, on the volume available to non-privileged processes.
779 This is the free space minus the amount of space reserved by the system to prevent critical
780 disk exhaustion errors.
781 Non-privileged programs, like a disk management tool, should use this value to display the
782 space available to the user.
784 .Dv ATTR_VOL_SPACEAVAIL
786 .Dv ATTR_VOL_SPACEFREE
794 .It ATTR_VOL_MINALLOCATION
797 containing the minimum allocation size on the volume in bytes.
798 If you create a file containing one byte, it will consume this much space.
800 .It ATTR_VOL_ALLOCATIONCLUMP
803 containing the allocation clump size on the volume, in bytes.
804 As a file is extended, the file system will attempt to allocate
805 this much space each time in order to reduce fragmentation.
807 .It ATTR_VOL_IOBLOCKSIZE
810 containing the optimal block size when reading or writing data.
815 structure returned by
818 .It ATTR_VOL_OBJCOUNT
821 containing the number of file system objects on the volume.
823 .It ATTR_VOL_FILECOUNT
826 containing the number of files on the volume.
828 .It ATTR_VOL_DIRCOUNT
831 containing the number of directories on the volume.
833 .It ATTR_VOL_MAXOBJCOUNT
836 containing the maximum number of file system objects that can be stored on the volume.
838 .It ATTR_VOL_MOUNTPOINT
841 structure containing the path to the volume's mount point as a
842 UTF-8 encoded, null terminated C string.
843 The attribute data length will not be greater than
849 structure returned by
855 structure containing the name of the volume as a
856 UTF-8 encoded, null terminated C string.
857 The attribute data length will not be greater than
862 This attribute is only read/write if the
863 .Dv VOL_CAP_INT_VOL_RENAME
864 bit is set in the volume capabilities (see below).
867 .It ATTR_VOL_MOUNTFLAGS
870 containing the volume mount flags.
871 This is a copy of the value passed to the
875 when the volume was mounted.
880 structure returned by
883 .It ATTR_VOL_MOUNTEDDEVICE
886 structure that returns the same value as the
890 structure returned by
892 For local volumes this is the path to the device on which the volume is mounted as a
893 UTF-8 encoded, null terminated C string.
894 For network volumes, this is a unique string that identifies the mount.
895 The attribute data length will not be greater than
899 .It ATTR_VOL_ENCODINGSUSED
901 .Vt unsigned long long
902 containing a bitmap of the text encodings used on this volume.
903 For more information about this, see the discussion of
905 in DTS Technote 1150 "HFS Plus Volume Format".
907 .It ATTR_VOL_CAPABILITIES
909 .Vt vol_capabilities_attr_t
910 structure describing the optional features supported by this volume.
911 See below for a discussion of volume capabilities.
916 containing the file system UUID. Typically this will be a
919 .It ATTR_VOL_QUOTA_SIZE
922 containing the maximum size of the volume in bytes.
924 .It ATTR_VOL_RESERVED_SIZE
927 containing the minimum size of the volume in bytes.
929 .It ATTR_VOL_ATTRIBUTES
931 .Vt vol_attributes_attr_t
932 structure describing the attributes supported by this volume.
933 This structure is discussed below, along with volume capabilities.
937 .Sh DIRECTORY ATTRIBUTES
939 The following directory attributes are defined.
941 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
943 .It ATTR_DIR_LINKCOUNT
946 containing the number of hard links to the directory;
947 this does not include the historical "." and ".." entries.
948 For file systems that do not support hard links to directories,
949 this value will be 1.
951 .It ATTR_DIR_ENTRYCOUNT
954 containing the number of file system objects in the directory, not including
955 any synthetic items. The historical "." and ".." entries are also
956 excluded from this count.
958 .It ATTR_DIR_MOUNTSTATUS
961 containing flags describing what's mounted on the directory.
962 Currently the only flag defined is
963 .Dv DIR_MNTSTATUS_MNTPOINT,
964 which indicates that there is a file system mounted on this directory.
966 .It ATTR_DIR_ALLOCSIZE
969 containing the number of bytes on disk used by the directory
972 .It ATTR_DIR_IOBLOCKSIZE
975 containing the optimal block size when reading or writing data.
977 .It ATTR_DIR_DATALENGTH
980 containing the length of the directory in bytes (the logical size).
984 Requested directory attributes are not returned for file system objects that
989 The following file attributes are defined.
991 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
993 .It ATTR_FILE_LINKCOUNT
996 containing the number of hard links to this file.
1001 structure returned by
1004 .It ATTR_FILE_TOTALSIZE
1007 containing the total number of bytes in all forks of the file (the logical size).
1009 .It ATTR_FILE_ALLOCSIZE
1012 containing a count of the bytes on disk used by all of the file's forks (the physical size).
1014 .It ATTR_FILE_IOBLOCKSIZE
1017 containing the optimal block size when reading or writing this file's data.
1019 .It ATTR_FILE_CLUMPSIZE
1022 containing the allocation clump size for this file, in bytes.
1023 As the file is extended, the file system will attempt to allocate
1024 this much space each time in order to reduce fragmentation.
1025 This value applies to the data fork.
1027 .It ATTR_FILE_DEVTYPE
1030 containing the device type for a special device file.
1035 structure returned by
1038 .It ATTR_FILE_FILETYPE
1041 that whose value is reserved.
1042 Clients should ignore its value.
1043 New volume format implementations should not support this attribute.
1045 .It ATTR_FILE_FORKCOUNT
1048 containing the number of forks in the file.
1049 No built-in file systems on Mac OS X currently support forks other
1050 than the data and resource fork.
1052 .It ATTR_FILE_FORKLIST
1055 structure containing a list of named forks of the file.
1056 No built-in file systems on Mac OS X currently support forks
1057 other than the data and resource fork.
1058 Because of this, the structure of this attribute's value is not yet defined.
1060 .It ATTR_FILE_DATALENGTH
1063 containing the length of the data fork in bytes (the logical size).
1065 .It ATTR_FILE_DATAALLOCSIZE
1068 containing a count of the bytes on disk used by the data fork (the physical size).
1070 .It ATTR_FILE_DATAEXTENTS
1073 array for the data fork.
1074 The array contains eight
1076 structures which represent the first
1077 eight extents of the fork.
1079 This attributes exists for compatibility reasons.
1080 New clients should not use this attribute.
1081 Rather, they should use the
1087 In current implementations the value may not be entirely accurate for
1088 a variety of reasons.
1090 .It ATTR_FILE_RSRCLENGTH
1093 containing the length of the resource fork in bytes (the logical size).
1095 .It ATTR_FILE_RSRCALLOCSIZE
1098 containing a count of the bytes on disk used by the resource fork (the physical size).
1100 .It ATTR_FILE_RSRCEXTENTS
1103 array for the resource fork.
1104 The array contains eight
1106 structures which represent the first
1107 eight extents of the fork.
1110 .Dv ATTR_FILE_DATAEXTENTS .
1115 File attributes are used for any file system object that is not a directory,
1116 not just ordinary files.
1117 Requested file attributes are not returned for file system objects that
1122 Fork attributes relate to the actual data in the file,
1123 which can be held in multiple named contiguous ranges, or forks.
1124 These cannot be used if the FSOPT_ATTR_CMN_EXTENDED is given.
1125 The following fork attributes are defined.
1127 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
1129 .It ATTR_FORK_TOTALSIZE
1133 containing the length of the fork in bytes (the logical size).
1135 .It ATTR_FORK_ALLOCSIZE
1139 containing a count of the bytes on disk used by the fork (the physical size).
1141 .It ATTR_FORK_RESERVED
1143 You must set this to 0.
1148 Fork attributes are deprecated and all bits are reserved.
1149 They are not properly implemented by any current Mac OS X
1150 volume format implementation.
1151 We strongly recommend that client programs do not request fork attributes.
1152 If you are implementing a volume format, you should not support these attributes.
1154 .Sh COMMON EXTENDED ATTRIBUTES
1156 Common extended attributes are like common attributes except that they are set
1157 in the forkattr field and can only be used if the FSOPT_ATTR_CMN_EXTENDED
1158 option is given. Use of these attributes is mutually exclusive with the above
1161 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
1163 .It ATTR_CMNEXT_RELPATH
1166 structure containing the mount-relative path of
1167 the file system object as
1168 a UTF-8 encoded, null terminated C string.
1169 The attribute data length will not be greater than
1171 Inconsistent behavior may be observed when this attribute is requested on
1172 hard-linked items, particularly when the file system does not support
1173 ATTR_CMN_PARENTID natively. Callers should be aware of this when requesting the
1174 relative path of a hard-linked item.
1176 .It ATTR_CMNEXT_PRIVATESIZE
1179 containing the number of bytes that are \fBnot\fP trapped inside a clone
1180 or snapshot, and which would be freed immediately if the file were deleted.
1182 .It ATTR_CMNEXT_LINKID
1185 that uniquely identifies the file system object within a mounted volume for the
1186 duration of its mount.
1188 On HFS+ and APFS volumes, the ATTR_CMNEXT_LINKID of a file system
1189 object is distinct from the ATTR_CMNEXT_LINKID of any hard link to that file
1190 system object. Although the ATTR_CMNEXT_LINKID of a file system object may appear
1191 similar (in whole or in part) to its ATTR_CMN_FILEID (see description of
1192 ATTR_CMN_FILEID above), \fBno relation between the two attributes should ever be implied.\fP
1194 .It ATTR_CMNEXT_NOFIRMLINKPATH
1197 structure containing a path that does not have firmlinks of
1198 the file system object as
1199 a UTF-8 encoded, null terminated C string.
1200 The attribute data length will not be greater than
1202 Inconsistent behavior may be observed when this attribute is requested on
1203 hard-linked items, particularly when the file system does not support
1204 ATTR_CMN_PARENTID natively. Callers should be aware of this when requesting the
1205 canonical path of a hard-linked item.
1206 .It ATTR_CMNEXT_REALDEVID
1209 containing the real device number of the device on which this
1210 file system object's volume is mounted.
1215 structure returned by
1218 .It ATTR_CMNEXT_REALFSID
1221 structure containing the real file system identifier for the volume on which
1222 the file system object resides.
1227 structure returned by
1230 .It ATTR_CMNEXT_CLONEID
1233 that uniquely identifies the data stream associated with the file
1234 system object. Useful for finding which files are pure clones of each
1235 other (as they will have the same clone-id).
1237 .It ATTR_CMNEXT_EXT_FLAGS
1240 that contains additional flags with information about the file. The
1243 .Bl -tag -width EF_MAY_SHARE_BLOCKS
1245 .It EF_MAY_SHARE_BLOCKS
1246 If this bit is set then the file may share blocks with another file
1247 (i.e. it is a clone of another file).
1250 If this bit is set then the file has no extended attributes. Useful
1251 for avoiding a call to listxattr().
1254 If this bit is set the directory is a "sync root". This bit will
1255 never be set for regular files.
1258 If this bit is set the item is a "purgeable" item that can be deleted
1259 by the file system when asked to free space.
1262 If this bit is set the item has sparse regions.
1265 If this bit is set the item is a synthetic directory/symlink.
1269 .It ATTR_CMNEXT_RECURSIVE_GENCOUNT
1272 that represents the recursive generation count of a directory that has
1273 been marked as maintain-dir-stats in an apfs file system. This
1274 gencount is updated any time any child is modified (as part of the
1275 contract that a maintain-dir-stats directory manages). If the
1276 directory is not marked maintain-dir-stats, a zero is returned.
1281 .Sh VOLUME CAPABILITIES
1283 .\" vol_capabilities_attr_t
1285 Not all volumes support all features.
1287 .Dv ATTR_VOL_CAPABILITIES
1289 .Vt vol_capabilities_attr_t
1290 structure (shown below) that indicates which features are supported by the volume.
1293 typedef u_int32_t vol_capabilities_set_t[4];
1296 #define VOL_CAPABILITIES_FORMAT 0
1297 #define VOL_CAPABILITIES_INTERFACES 1
1298 #define VOL_CAPABILITIES_RESERVED1 2
1299 #define VOL_CAPABILITIES_RESERVED2 3
1302 typedef struct vol_capabilities_attr {
1303 vol_capabilities_set_t capabilities;
1304 vol_capabilities_set_t valid;
1305 } vol_capabilities_attr_t;
1309 The structure contains two fields,
1313 Each consists of an array of four elements.
1314 The arrays are indexed by the following values.
1316 .Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1318 .It VOL_CAPABILITIES_FORMAT
1319 This element contains information about the volume format.
1321 .Dv VOL_CAP_FMT_PERSISTENTOBJECTIDS
1324 .It VOL_CAPABILITIES_INTERFACES
1325 This element contains information about which optional functions are
1326 supported by the volume format implementation.
1328 .Dv VOL_CAP_INT_SEARCHFS
1331 .It VOL_CAPABILITIES_RESERVED1
1333 A file system implementation should set this element to zero.
1334 A client program should ignore this element.
1336 .It VOL_CAPABILITIES_RESERVED2
1338 A file system implementation should set this element to zero.
1339 A client program should ignore this element.
1346 field contains bit sets that indicate which flags are known to the volume format
1348 Each bit indicates whether the contents of the corresponding bit in the
1355 field contains bit sets that indicate whether a particular feature is implemented
1356 by this volume format.
1359 The following bits are defined in the first element (indexed by
1360 .Dv VOL_CAPABILITIES_FORMAT )
1366 .Vt vol_capabilities_attr_t
1369 .Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1371 .It VOL_CAP_FMT_PERSISTENTOBJECTIDS
1372 If this bit is set the volume format supports persistent object identifiers
1373 and can look up file system objects by their IDs.
1375 .Dv ATTR_CMN_OBJPERMANENTID
1376 for details about how to obtain these identifiers.
1378 .It VOL_CAP_FMT_SYMBOLICLINKS
1379 If this bit is set the volume format supports symbolic links.
1381 .It VOL_CAP_FMT_HARDLINKS
1382 If this bit is set the volume format supports hard links.
1384 .It VOL_CAP_FMT_JOURNAL
1385 If this bit is set the volume format supports a journal used to
1386 speed recovery in case of unplanned restart (such as a power outage
1388 This does not necessarily mean the volume is actively using a journal.
1390 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1392 .It VOL_CAP_FMT_JOURNAL_ACTIVE
1393 If this bit is set the volume is currently using a journal for
1394 speedy recovery after an unplanned restart.
1395 This bit can be set only if
1396 .Dv VOL_CAP_FMT_JOURNAL
1399 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1401 .It VOL_CAP_FMT_NO_ROOT_TIMES
1402 If this bit is set the volume format does not store reliable times for
1403 the root directory, so you should not depend on them to detect changes,
1404 identify volumes across unmount/mount, and so on.
1406 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1408 .It VOL_CAP_FMT_SPARSE_FILES
1409 If this bit is set the volume format supports sparse files,
1410 that is, files which can have 'holes' that have never been written
1411 to, and thus do not consume space on disk.
1412 A sparse file may have an allocated size on disk that is less than its logical length (that is,
1413 .Dv ATTR_FILE_ALLOCSIZE
1415 .Dv ATTR_FILE_TOTALSIZE ).
1418 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1420 .It VOL_CAP_FMT_ZERO_RUNS
1421 For security reasons, parts of a file (runs) that have never been
1422 written to must appear to contain zeroes.
1423 When this bit is set, the volume keeps track of allocated but unwritten
1424 runs of a file so that it can substitute zeroes without actually
1425 writing zeroes to the media.
1426 This provides performance similar to sparse files, but not the space savings.
1428 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1430 .It VOL_CAP_FMT_CASE_SENSITIVE
1431 If this bit is set the volume format treats upper and lower case
1432 characters in file and directory names as different.
1433 Otherwise an upper case character is equivalent to a lower case character,
1434 and you can't have two names that differ solely in the case of
1437 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1439 .It VOL_CAP_FMT_CASE_PRESERVING
1440 If this bit is set the volume format preserves the case of
1441 file and directory names.
1442 Otherwise the volume may change the case of some characters
1443 (typically making them all upper or all lower case).
1445 .Dv VOL_CAP_FMT_CASE_SENSITIVE
1447 .Dv VOL_CAP_FMT_CASE_PRESERVING .
1449 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1451 .It VOL_CAP_FMT_FAST_STATFS
1452 This bit is used as a hint to upper layers to
1455 is fast enough that its results need not be cached by the caller.
1456 A volume format implementation that caches the
1458 information in memory should set this bit.
1459 An implementation that must always read from disk or always perform a network
1460 transaction to satisfy
1462 should not set this bit.
1464 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1466 .It VOL_CAP_FMT_2TB_FILESIZE
1467 If this bit is set the volume format supports file sizes larger
1468 than 4GB, and potentially up to 2TB; it does not indicate
1469 whether the file system supports files larger than that.
1471 Introduced with Darwin 8.0 (Mac OS X version 10.4).
1473 .It VOL_CAP_FMT_OPENDENYMODES
1474 If this bit is set, the volume format supports open deny modes
1475 (e.g., "open for read write, deny write").
1477 .It VOL_CAP_FMT_HIDDEN_FILES
1478 If this bit is set, the volume format supports the
1482 flag is mapped to that volume's native "hidden" or "invisible"
1483 bit (e.g., the invisible bit from the Finder Info extended attribute).
1485 .It VOL_CAP_FMT_PATH_FROM_ID
1486 If this bit is set, the volume format supports the ability to derive a pathname
1487 to the root of the file system given only the ID of an object. This also
1488 implies that object IDs on this file system are persistent and not recycled.
1489 Most file systems will not support this capability.
1491 .It VOL_CAP_FMT_NO_VOLUME_SIZES
1492 If this bit is set the volume format does not support
1493 determining values for total data blocks, available blocks, or free blocks, as in
1502 Historically, those values were set to 0xFFFFFFFF for volumes
1503 that did not support them.
1505 Introduced with Darwin 10.0 (Mac OS X version 10.6).
1507 .It VOL_CAP_FMT_64BIT_OBJECT_IDS
1508 If this bit is set, the volume format uses object IDs that are 64-bit.
1509 This means that ATTR_CMN_FILEID and ATTR_CMN_PARENTID are the primary means of
1510 obtaining object IDs from this volume. The values returned by ATTR_CMN_OBJID,
1511 ATTR_CMN_OBJPERMANENTID, and ATTR_CMN_PAROBJID can be interpreted as 64-bit
1512 object IDs instead of fsobj_id_t.
1514 .It VOL_CAP_FMT_NO_IMMUTABLE_FILES
1515 If this bit is set, the volume format does not support setting the UF_IMMUTABLE
1517 See ATTR_CMN_FLAGS for more details.
1518 .It VOL_CAP_FMT_NO_PERMISSIONS
1519 If this bit is set, the volume format does not support setting file
1521 See ATTR_CMN_USERACCESS for more details.
1522 .It VOL_CAP_FMT_SHARED_SPACE
1523 If this bit is set, the volume format supports having multiple logical filesystems
1524 in a single "partition" which share space.
1525 .It VOL_CAP_FMT_VOL_GROUPS
1526 If this bit is set, the volume format supports having multiple logical filesystems
1527 which may be mounted and unmounted together and may present common filesystem
1528 identifier information.
1529 .It VOL_CAP_FMT_SEALED
1530 If this bit is set, the volume is cryptographically sealed and any modifications
1531 may render the volume unusable.
1537 The following bits are defined in the second element (indexed by
1538 .Dv VOL_CAPABILITIES_INTERFACES )
1544 .Vt vol_capabilities_attr_t
1547 .Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1549 .It VOL_CAP_INT_SEARCHFS
1550 If this bit is set the volume format implementation supports
1553 .It VOL_CAP_INT_ATTRLIST
1554 If this bit is set the volume format implementation supports
1559 .It VOL_CAP_INT_NFSEXPORT
1560 If this bit is set the volume format implementation allows this volume to be exported via NFS.
1562 .It VOL_CAP_INT_READDIRATTR
1563 If this bit is set the volume format implementation supports
1564 .Xr getdirentriesattr 2 .
1566 .It VOL_CAP_INT_EXCHANGEDATA
1567 If this bit is set the volume format implementation supports
1568 .Xr exchangedata 2 .
1570 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1572 .It VOL_CAP_INT_COPYFILE
1573 If this bit is set the volume format implementation supports the (private and undocumented)
1574 copyfile() function.
1579 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1581 .It VOL_CAP_INT_ALLOCATE
1582 If this bit is set the volume format implementation supports the
1587 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1589 .It VOL_CAP_INT_VOL_RENAME
1590 If this bit is set the volume format implementation allows you to
1591 modify the volume name using
1594 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1596 .It VOL_CAP_INT_ADVLOCK
1597 If this bit is set the volume format implementation supports
1598 advisory locking, that is, the
1606 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1608 .It VOL_CAP_INT_FLOCK
1609 If this bit is set the volume format implementation supports
1620 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1622 .It VOL_CAP_INT_EXTENDED_SECURITY
1623 If this bit is set the volume format implementation supports
1624 extended security controls (ACLs).
1626 Introduced with Darwin 8.0 (Mac OS X version 10.4).
1628 .It VOL_CAP_INT_USERACCESS
1629 If this bit is set the volume format implementation supports the
1630 ATTR_CMN_USERACCESS attribute.
1632 Introduced with Darwin 8.0 (Mac OS X version 10.4).
1634 .It VOL_CAP_INT_MANLOCK
1635 If this bit is set, the volume format implementation supports
1636 AFP-style mandatory byte range locks via
1639 .It VOL_CAP_INT_EXTENDED_ATTR
1640 If this bit is set, the volume format implementation supports
1641 native extended attributes (see
1642 .Xr setxattr 2 Ns ).
1644 .It VOL_CAP_INT_CLONE
1645 If this bit is set, the file system supports cloning files and directories.
1650 .It VOL_CAP_INT_SNAPSHOT
1651 If this bit is set, the file system supports snapshots.
1653 .Xr fs_snapshot_create 2
1656 .It VOL_CAP_INT_NAMEDSTREAMS
1657 If this bit is set, the volume format implementation supports
1658 native named streams.
1660 .It VOL_CAP_INT_RENAME_SWAP
1661 If this bit is set, the file system supports swapping file system
1666 .It VOL_CAP_INT_RENAME_EXCL
1667 If this bit is set, the file system supports an exclusive rename
1672 .It VOL_CAP_INT_RENAME_OPENFAIL
1673 If this bit is set, the file system may fail a rename operation
1674 of a directory if one of its descendents is open.
1682 .\" vol_attributes_attr_t
1684 A volume can also report which attributes it supports.
1685 This information is returned by the
1686 .Dv ATTR_VOL_ATTRIBUTES
1687 attribute, which returns a
1688 .Vt vol_attributes_attr_t
1689 structure (shown below).
1692 typedef struct attribute_set {
1693 attrgroup_t commonattr; /* common attribute group */
1694 attrgroup_t volattr; /* volume attribute group */
1695 attrgroup_t dirattr; /* directory attribute group */
1696 attrgroup_t fileattr; /* file attribute group */
1697 attrgroup_t forkattr; /* fork attribute group */
1701 typedef struct vol_attributes_attr {
1702 attribute_set_t validattr;
1703 attribute_set_t nativeattr;
1704 } vol_attributes_attr_t;
1710 field consists of a number of bit sets that indicate whether an attribute is
1711 supported by the volume format implementation.
1714 is similar except that the bit sets indicate whether an attribute is supported
1715 natively by the volume format.
1716 An attribute is supported natively if the volume format implementation does not have to do
1717 any complex conversions to access the attribute.
1718 For example, a volume format might support persistent object identifiers, but
1719 doing so requires a complex table lookup that is not part of the core volume
1722 .Dv ATTR_VOL_ATTRIBUTES
1723 attribute would return
1724 .Dv ATTR_CMN_OBJPERMANENTID
1728 .Vt vol_attributes_attr_t ,
1734 Upon successful completion a value of 0 is returned.
1735 Otherwise, a value of -1 is returned and
1737 is set to indicate the error.
1740 Not all volumes support
1742 The best way to test whether a volume supports this function is to
1743 simply call it and check the error result.
1747 if it is not supported on a particular volume.
1752 function has been undocumented for more than two years.
1753 In that time a number of volume format implementations have been created without
1754 a proper specification for the behaviour of this routine.
1755 You may encounter volume format implementations with slightly different
1756 behaviour than what is described here.
1757 Your program is expected to be tolerant of this variant behaviour.
1760 If you're implementing a volume format that supports
1762 you should be careful to support the behaviour specified by this document.
1772 The volume does not support the query.
1775 A component of the path prefix for
1779 .It Bq Er ENAMETOOLONG
1780 A component of a path name for
1784 characters, or an entire path name exceeded
1789 The file system object for
1794 The file descriptor argument for
1796 is not a valid file descriptor.
1799 Search permission is denied for a component of the path prefix for
1803 Too many symbolic links were encountered in translating the pathname
1812 points to an invalid address.
1816 is too small to hold a u_int32_t.
1824 .Dv ATTR_BIT_MAP_COUNT .
1827 You requested an invalid attribute.
1830 You requested an attribute that is not supported for this file system object.
1833 You requested volume attributes and directory or file attributes.
1836 You requested volume attributes but
1838 does not reference the root of the volume.
1841 The volume is read-only but must be modified in order to return this attribute.
1844 An I/O error occurred while reading from or writing to the file system.
1847 In addition to the errors returned by the
1851 function may fail if:
1856 argument does not specify an absolute path and the
1860 nor a valid file descriptor open for searching.
1864 argument is not an absolute path and
1868 nor a file descriptor associated with a directory.
1874 If you request any volume attributes, you must set
1878 field, even though it generates no result in the attribute buffer.
1881 The order that attributes are stored in the attribute buffer almost
1882 invariably matches the order of attribute mask bit values.
1885 (0x00000001) comes before
1887 (0x00000002) because its value is smaller.
1888 When ordering attributes, you should always use the order in which they
1889 are described above.
1894 structure is 64-bits (two 32-bit elements) in 32-bit code, and
1895 128-bits (two 64-bit elements) in 64-bit code; however, it is aligned
1896 on a 4-byte (32-bit) boundary, even in 64-bit code.
1898 If you use a structure
1899 for the attribute data, it must be correctly packed and aligned (see
1903 Inconsistent behavior may be observed when the ATTR_CMN_FULLPATH attribute is requested on
1904 hard-linked items, particularly when the file system does not support ATTR_CMN_PARENTID
1905 natively. Callers should be aware of this when requesting the full path of a hard-linked item, especially
1906 if the full path crosses mount points.
1909 For more caveats, see also the compatibility notes above.
1913 The following code prints the file type and creator of a file,
1914 assuming that the volume supports the required attributes.
1920 #include <sys/attr.h>
1921 #include <sys/errno.h>
1923 #include <sys/vnode.h>
1926 typedef struct attrlist attrlist_t;
1929 struct FInfoAttrBuf {
1931 fsobj_type_t objType;
1932 char finderInfo[32];
1933 } __attribute__((aligned(4), packed));
1934 typedef struct FInfoAttrBuf FInfoAttrBuf;
1937 static int FInfoDemo(const char *path)
1940 attrlist_t attrList;
1941 FInfoAttrBuf attrBuf;
1944 memset(&attrList, 0, sizeof(attrList));
1945 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
1946 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
1949 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
1956 assert(attrBuf.length == sizeof(attrBuf));
1959 printf("Finder information for %s:\en", path);
1960 switch (attrBuf.objType) {
1962 printf("file type = '%.4s'\en", &attrBuf.finderInfo[0]);
1963 printf("file creator = '%.4s'\en", &attrBuf.finderInfo[4]);
1966 printf("directory\en");
1969 printf("other object type, %d\en", attrBuf.objType);
1980 The following code is an alternative implementation that uses nested structures
1981 to group the related attributes.
1988 #include <sys/attr.h>
1989 #include <sys/errno.h>
1991 #include <sys/vnode.h>
1994 typedef struct attrlist attrlist_t;
1997 struct FInfo2CommonAttrBuf {
1998 fsobj_type_t objType;
1999 char finderInfo[32];
2000 } __attribute__((aligned(4), packed));
2001 typedef struct FInfo2CommonAttrBuf FInfo2CommonAttrBuf;
2004 struct FInfo2AttrBuf {
2006 FInfo2CommonAttrBuf common;
2007 } __attribute__((aligned(4), packed));;
2008 typedef struct FInfo2AttrBuf FInfo2AttrBuf;
2011 static int FInfo2Demo(const char *path)
2014 attrlist_t attrList;
2015 FInfo2AttrBuf attrBuf;
2018 memset(&attrList, 0, sizeof(attrList));
2019 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
2020 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
2023 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
2030 assert(attrBuf.length == sizeof(attrBuf));
2033 printf("Finder information for %s:\en", path);
2034 switch (attrBuf.common.objType) {
2037 "file type = '%.4s'\en",
2038 &attrBuf.common.finderInfo[0]
2041 "file creator = '%.4s'\en",
2042 &attrBuf.common.finderInfo[4]
2046 printf("directory\en");
2050 "other object type, %d\en",
2051 attrBuf.common.objType
2063 The following example shows how to deal with variable length attributes.
2064 It assumes that the volume specified by
2066 supports the necessary attributes.
2073 #include <sys/attr.h>
2074 #include <sys/errno.h>
2076 #include <sys/vnode.h>
2079 typedef struct attrlist attrlist_t;
2084 u_int32_t fileCount;
2086 attrreference_t mountPointRef;
2087 attrreference_t volNameRef;
2088 char mountPointSpace[MAXPATHLEN];
2089 char volNameSpace[MAXPATHLEN];
2090 } __attribute__((aligned(4), packed));
2091 typedef struct VolAttrBuf VolAttrBuf;
2094 static int VolDemo(const char *path)
2097 attrlist_t attrList;
2101 memset(&attrList, 0, sizeof(attrList));
2102 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
2103 attrList.volattr = ATTR_VOL_INFO
2104 | ATTR_VOL_FILECOUNT
2106 | ATTR_VOL_MOUNTPOINT
2110 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
2117 assert(attrBuf.length > offsetof(VolAttrBuf, mountPointSpace));
2118 assert(attrBuf.length <= sizeof(attrBuf));
2121 printf("Volume information for %s:\en", path);
2122 printf("ATTR_VOL_FILECOUNT: %u\en", attrBuf.fileCount);
2123 printf("ATTR_VOL_DIRCOUNT: %u\en", attrBuf.dirCount);
2125 "ATTR_VOL_MOUNTPOINT: %.*s\en",
2126 (int) attrBuf.mountPointRef.attr_length,
2127 ( ((char *) &attrBuf.mountPointRef)
2128 + attrBuf.mountPointRef.attr_dataoffset )
2131 "ATTR_VOL_NAME: %.*s\en",
2132 (int) attrBuf.volNameRef.attr_length,
2133 ( ((char *) &attrBuf.volNameRef)
2134 + attrBuf.volNameRef.attr_dataoffset )
2143 The following sample demonstrates the need to use packing and alignment
2144 controls; without the attribute, in 64-bit code, the fields of the structure are not
2145 placed at the locations that the kernel expects.
2154 #include <sys/attr.h>
2156 /* The alignment and packing attribute is necessary in 64-bit code */
2157 struct AttrListTimes {
2159 struct timespec st_crtime;
2160 struct timespec st_modtime;
2161 } __attribute__((aligned(4), packed));
2163 main(int argc, char **argv)
2168 for (i = 1; i < argc; i++) {
2169 struct attrlist attrList;
2170 struct AttrListTimes myStat = {0};
2171 char *path = argv[i];
2173 memset(&attrList, 0, sizeof(attrList));
2174 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
2175 attrList.commonattr = ATTR_CMN_CRTIME |
2178 rv = getattrlist(path, &attrList, &myStat, sizeof(myStat), 0);
2181 warn("getattrlist(%s)", path);
2184 printf("%s: Modification time = %s", argv[i], ctime(&myStat.st_modtime.tv_sec));
2190 The getLinkIDInfo() function determines if ATTR_CMNEXT_LINKID and ATTR_CMN_OBJID
2191 are valid to use on the file system specified by path.
2194 int getLinkIDInfo(const char *path, bool *cmnExtLinkIDValid, bool *cmnObjIDValid)
2197 struct statfs statfsBuf;
2198 struct attrlist attrList;
2199 struct volAttrsBuf {
2201 vol_capabilities_attr_t capabilities;
2202 vol_attributes_attr_t attributes;
2203 } __attribute__((aligned(4), packed));
2204 struct volAttrsBuf volAttrs;
2206 memset(&attrList, 0, sizeof(attrList));
2207 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
2208 attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_CAPABILITIES | ATTR_VOL_ATTRIBUTES;
2209 // get the file system's mount point path for the input path
2210 result = statfs(path, &statfsBuf);
2211 if ( result == 0 ) {
2212 // get the supported capabilities and attributes
2213 result = getattrlist(statfsBuf.f_mntonname, &attrList, &volAttrs, sizeof(volAttrs), FSOPT_ATTR_CMN_EXTENDED);
2214 if ( result == 0 ) {
2215 if ( volAttrs.attributes.validattr.forkattr & ATTR_CMNEXT_LINKID ) {
2216 // ATTR_CMNEXT_LINKID is available; do not use ATTR_CMN_OBJID
2217 *cmnExtLinkIDValid = true;
2218 *cmnObjIDValid = false;
2221 // ATTR_CMNEXT_LINKID is not available
2222 cmnExtLinkIDValid = false;
2223 // ATTR_CMN_OBJID can only be used if the file system does not use 64-bit object IDs
2224 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) ) {
2225 *cmnObjIDValid = false;
2228 *cmnObjIDValid = true;
2233 if ( result != 0 ) {
2234 *cmnExtLinkIDValid = *cmnObjIDValid = false;
2245 .Xr exchangedata 2 ,
2247 .Xr getattrlistbulk 2 ,
2257 function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).
2260 function call appeared in OS X 10.10 .