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 In addition, you can't request volume attributes if you also request
170 file or directory attributes.
173 A bit set that specifies the directory attributes that you require.
174 See below for a description of these attributes.
177 A bit set that specifies the file attributes that you require.
178 See below for a description of these attributes.
181 A bit set that specifies the fork attributes that you require.
182 Fork attributes relate to the actual data in the file,
183 which can be held in multiple named contiguous ranges, or forks.
184 See below for a description of these attributes.
185 If the FSOPT_ATTR_CMN_EXTENDED option is given, this bit set is reinterpreted
186 as extended common attributes attributes, also described below.
191 Unless otherwise noted in the lists below, attributes are read-only.
192 Attributes labelled as read/write can be set using
196 .\" attrBuf and attrBufSize parameters
202 parameters specify a buffer into which the function places attribute values.
203 The format of this buffer is sufficiently complex that its description
204 requires a separate section (see below).
205 The initial contents of this buffer are ignored.
212 parameter is a bit set that controls the behaviour of
214 The following option bits are defined.
216 .Bl -tag -width FSOPT_PACK_INVAL_ATTRS
221 will not follow a symlink if it occurs as
222 the last component of
225 .It FSOPT_REPORT_FULLSIZE
226 The size of the attributes reported (in the first
228 field in the attribute buffer) will be the size needed to hold all the
229 requested attributes; if not set, only the attributes actually returned
230 will be reported. This allows the caller to determine if any truncation
233 .It FSOPT_PACK_INVAL_ATTRS
234 If this is bit is set, then all requested attributes, even ones that are
235 not supported by the object or file system, will be returned. Default values
236 will be used for the invalid ones. Requires that
237 .Dv ATTR_CMN_RETURNED_ATTRS
240 .It FSOPT_ATTR_CMN_EXTENDED
241 If this is bit is set, then
242 .Dv ATTR_CMN_GEN_COUNT
244 .Dv ATTR_CMN_DOCUMENT_ID
245 can be requested. When this option is used, forkattrs are reinterpreted as a
246 set of extended common attributes.
252 The data returned in the buffer described by
256 is formatted as follows.
262 The first element of the buffer is a
264 that contains the overall length, in bytes, of the attributes returned.
265 This size includes the length field itself.
268 Following the length field is a list of attributes.
269 Each attribute is represented by a field of its type,
270 where the type is given as part of the attribute description (below).
273 The attributes are placed into the attribute buffer in the order
274 that they are described below.
277 Each attribute is aligned to a 4-byte boundary (including 64-bit data types).
281 If the attribute is of variable length, it is represented
284 structure, as defined by
289 typedef struct attrreference {
290 int32_t attr_dataoffset;
291 u_int32_t attr_length;
296 This structure contains a 'pointer' to the variable length attribute data.
299 field is the length of the attribute data (in bytes).
302 field is the offset in bytes from the
305 to the attribute data.
306 This offset will always be a multiple of sizeof(u_int32_t) bytes,
307 so you can safely access common data types without fear of alignment
313 function will silently truncate attribute data if
316 The length field at the front of the attribute list always represents
317 the length of the data actually copied into the attribute buffer.
318 If the data is truncated, there is no easy way to determine the
319 buffer size that's required to get all of the requested attributes.
320 You should always pass an
322 that is large enough to accommodate the known size of the attributes
323 in the attribute list (including the leading length field).
326 Because the returned attributes are simply truncated if the buffer is
327 too small, it's possible for a variable length attribute to reference
328 data beyond the end of the attribute buffer. That is, it's possible
329 for the attribute data to start beyond the end of the attribute buffer
333 .Vt attrreference_t ,
342 ) ) or, indeed, for the attribute data to extend beyond the end of the attribute buffer (that is,
354 If this happens you must increase the size of the buffer and call
356 to get an accurate copy of the attribute.
358 .Sh COMMON ATTRIBUTES
360 Common attributes relate to all types of file system objects.
361 The following common attributes are defined.
363 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
365 .It ATTR_CMN_RETURNED_ATTRS
368 structure which is used to report which of the requested attributes
369 were actually returned. This attribute, when requested, will always
370 be the first attribute returned. By default, unsupported attributes
371 will be skipped (i.e. not packed into the output buffer). This behavior
372 can be over-ridden using the FSOPT_PACK_INVAL_ATTRS option flag. Both
373 .Xr getattrlist 2 and
374 .Xr getatttrlistbulk 2 support this attribute while
375 .Xr searchfs 2 does not.
380 structure containing the name of the file system object as
381 UTF-8 encoded, null terminated C string.
382 The attribute data length will not be greater than
384 + 1 characters, which is
386 * 3 + 1 bytes (as one UTF-8-encoded character may
387 take up to three bytes).
393 containing the device number of the device on which this
394 file system object's volume is mounted.
399 structure returned by
405 structure containing the file system identifier for the volume on which
406 the file system object resides.
411 structure returned by
417 that identifies the type of file system object.
418 The values are taken from
426 that identifies the type of file system containing the object.
427 The values are taken from
435 structure that uniquely identifies the file system object within a mounted
436 volume for the duration of it's mount; this identifier is not guaranteed to be
437 persistent for the volume and may change every time the volume is mounted.
439 On HFS+ volumes, the ATTR_CMN_OBJID of a file system object is distinct from
440 the ATTR_CMN_OBJID of any hard link to that file system object. Although the
441 ATTR_CMN_OBJID of a file system object may appear similar (in whole
442 or in part) to it's ATTR_CMN_FILEID (see description of ATTR_CMN_FILEID below),
443 \fBno relation between the two attributes should ever be implied.\fP
445 ATTR_CMN_OBJID is deprecated sarting with macOS 10.13, iOS 11.0, watchOS 4.0 and
446 tvOS 11.0 and ATTR_CMNEXT_LINKID should be used in its place.
447 ATTR_CMN_OBJID can only be used on older operating systems only if the file
448 system doesn't 64 bit IDs. See the
450 function in the EXAMPLES section.
452 .It ATTR_CMN_OBJPERMANENTID
455 structure that uniquely and persistently identifies the file system object
456 within its volume; persistence implies that this attribute is unaffected by
457 mount/unmount operations on the volume.
459 Some file systems can not return this attribute when the volume is mounted
460 read-only and will fail the request with error
463 (e.g. original HFS modifies on disk structures to generate persistent
464 identifiers, and hence cannot do so if the volume is mounted read only.)
466 .It ATTR_CMN_PAROBJID
469 structure that uniquely identifies the parent directory of the file system
470 object within a mounted volume, for the duration of the volume mount; this
471 identifier is not guaranteed to be persistent for the volume and may change
472 every time the volume is mounted.
475 If a file system object is hard linked from multiple directories, the parent
476 directory returned for this attribute is non deterministic; it can be any one
477 of the parent directories of this object.
479 For some volume formats the computing cost for this attribute is significant;
480 developers are advised to request this attribute sparingly.
485 containing a text encoding hint for
486 the file system object's name.
487 It is included to facilitate the lossless round trip conversion of names between
488 Unicode and traditional Mac OS script encodings.
489 File systems that do not have an appropriate text encoding value should return
490 kTextEncodingMacUnicode.
495 structure containing the time that the file system object
501 structure containing the time that the file system object
507 structure returned by
513 structure containing the time that the file system object's
514 attributes were last modified.
519 structure returned by
525 structure containing the time that the file system object
531 structure returned by
534 .It ATTR_CMN_BKUPTIME
537 structure containing the time that the file system object was
539 This value is for use by backup utilities.
540 The file system stores but does not interpret the value.
542 .It ATTR_CMN_FNDRINFO
543 (read/write) 32 bytes of data for use by the Finder.
544 Equivalent to the concatenation of a
549 (or, for directories, a
552 .Vt ExtendedFolderInfo
555 This attribute is not byte swapped by the file system.
556 The value of multibyte fields on disk is always big endian.
557 When running on a little endian system (such as Darwin on x86),
558 you must byte swap any multibyte fields.
563 containing the owner of the file system object.
568 structure returned by
574 containing the group of the file system object.
579 structure returned by
582 .It ATTR_CMN_ACCESSMASK
585 containing the access permissions of the file system object.
590 structure returned by
592 Only the permission bits of
594 are valid; other bits should be ignored,
595 e.g., by masking with
601 containing file flags.
606 structure returned by
608 For more information about these flags, see
611 .It ATTR_CMN_GEN_COUNT
614 containing a non zero monotonically increasing generation
615 count for this file system object. The generation count tracks
616 the number of times the data in a file system object has been
617 modified. No meaning can be implied from its value. The
618 value of the generation count for a file system object can
619 be compared against a previous value of the same file system
620 object for equality; i.e. an unchanged generation
621 count indicates identical data. Requesting this attribute requires the
622 FSOPT_ATTR_CMN_EXTENDED option flag.
625 A generation count value of 0 is invalid and cannot be used to
626 determine data change.
628 The generation count is invalid while a file is mmap'ed. An invalid
629 generation count value of 0 will be returned for mmap'ed files.
631 .It ATTR_CMN_DOCUMENT_ID
634 containing the document id. The document id is a value assigned
635 by the kernel to a document (which can be a file or directory)
636 and is used to track the data regardless of where it gets moved.
637 The document id survives safe saves; i.e it is sticky to the path it
638 was assigned to. Requesting this attribute requires the
639 FSOPT_ATTR_CMN_EXTENDED option flag.
641 A document id of 0 is invalid.
643 .It ATTR_CMN_USERACCESS
646 containing the effective permissions of the current user
647 (the calling process's effective UID) for this file system object.
648 You can test for read, write, and execute permission using
658 .It ATTR_CMN_EXTENDED_SECURITY
659 A variable-length object (thus an
661 structure) containing a
663 structure, of which only the ACL entry is used.
668 of the owner of the file system object. Analoguous to
669 .Dv ATTR_CMN_OWNERID .
674 of the group to which the file system object belongs.
681 that uniquely identifies the file system object within its mounted volume.
686 structure returned by
689 .It ATTR_CMN_PARENTID
692 that identifies the parent directory of the file system object.
694 .It ATTR_CMN_FULLPATH
697 structure containing the full path (resolving all symlinks) to
698 the file system object as
699 a UTF-8 encoded, null terminated C string.
700 The attribute data length will not be greater than
702 Inconsistent behavior may be observed when this attribute is requested on
703 hard-linked items, particularly when the file system does not support ATTR_CMN_PARENTID
704 natively. Callers should be aware of this when requesting the full path of a hard-linked item.
706 .It ATTR_CMN_ADDEDTIME
709 that contains the time that the file system object was created or renamed into
710 its containing directory. Note that inconsistent behavior may be observed
711 when this attribute is requested on hard-linked items.
713 .It ATTR_CMN_DATA_PROTECT_FLAGS
716 that contains the file or directory's data protection class.
721 .Sh VOLUME ATTRIBUTES
723 Volume attributes relate to volumes (that is, mounted file systems).
724 The following volume attributes are defined.
726 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
729 For reasons that are not at all obvious, you must set
733 field if you request any other volume attributes.
734 This does not result in any attribute data being added to the attribute buffer.
739 containing the file system type.
744 structure returned by
746 Generally not a useful value.
748 .It ATTR_VOL_SIGNATURE
751 containing the volume signature word.
752 This value is unique within a given file system type and lets you
753 distinguish between different volume formats handled by the same file system.
758 containing the total size of the volume in bytes.
760 .It ATTR_VOL_SPACEFREE
763 containing the free space on the volume in bytes.
765 .It ATTR_VOL_SPACEAVAIL
768 containing the space, in bytes, on the volume available to non-privileged processes.
769 This is the free space minus the amount of space reserved by the system to prevent critical
770 disk exhaustion errors.
771 Non-privileged programs, like a disk management tool, should use this value to display the
772 space available to the user.
774 .Dv ATTR_VOL_SPACEAVAIL
776 .Dv ATTR_VOL_SPACEFREE
784 .It ATTR_VOL_MINALLOCATION
787 containing the minimum allocation size on the volume in bytes.
788 If you create a file containing one byte, it will consume this much space.
790 .It ATTR_VOL_ALLOCATIONCLUMP
793 containing the allocation clump size on the volume, in bytes.
794 As a file is extended, the file system will attempt to allocate
795 this much space each time in order to reduce fragmentation.
797 .It ATTR_VOL_IOBLOCKSIZE
800 containing the optimal block size when reading or writing data.
805 structure returned by
808 .It ATTR_VOL_OBJCOUNT
811 containing the number of file system objects on the volume.
813 .It ATTR_VOL_FILECOUNT
816 containing the number of files on the volume.
818 .It ATTR_VOL_DIRCOUNT
821 containing the number of directories on the volume.
823 .It ATTR_VOL_MAXOBJCOUNT
826 containing the maximum number of file system objects that can be stored on the volume.
828 .It ATTR_VOL_MOUNTPOINT
831 structure containing the path to the volume's mount point as a
832 UTF-8 encoded, null terminated C string.
833 The attribute data length will not be greater than
839 structure returned by
845 structure containing the name of the volume as a
846 UTF-8 encoded, null terminated C string.
847 The attribute data length will not be greater than
852 This attribute is only read/write if the
853 .Dv VOL_CAP_INT_VOL_RENAME
854 bit is set in the volume capabilities (see below).
857 .It ATTR_VOL_MOUNTFLAGS
860 containing the volume mount flags.
861 This is a copy of the value passed to the
865 when the volume was mounted.
870 structure returned by
873 .It ATTR_VOL_MOUNTEDDEVICE
876 structure that returns the same value as the
880 structure returned by
882 For local volumes this is the path to the device on which the volume is mounted as a
883 UTF-8 encoded, null terminated C string.
884 For network volumes, this is a unique string that identifies the mount.
885 The attribute data length will not be greater than
889 .It ATTR_VOL_ENCODINGSUSED
891 .Vt unsigned long long
892 containing a bitmap of the text encodings used on this volume.
893 For more information about this, see the discussion of
895 in DTS Technote 1150 "HFS Plus Volume Format".
897 .It ATTR_VOL_CAPABILITIES
899 .Vt vol_capabilities_attr_t
900 structure describing the optional features supported by this volume.
901 See below for a discussion of volume capabilities.
906 containing the file system UUID. Typically this will be a
909 .It ATTR_VOL_QUOTA_SIZE
912 containing the maximum size of the volume in bytes.
914 .It ATTR_VOL_RESERVED_SIZE
917 containing the minimum size of the volume in bytes.
919 .It ATTR_VOL_ATTRIBUTES
921 .Vt vol_attributes_attr_t
922 structure describing the attributes supported by this volume.
923 This structure is discussed below, along with volume capabilities.
927 .Sh DIRECTORY ATTRIBUTES
929 The following directory attributes are defined.
931 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
933 .It ATTR_DIR_LINKCOUNT
936 containing the number of hard links to the directory;
937 this does not include the historical "." and ".." entries.
938 For file systems that do not support hard links to directories,
939 this value will be 1.
941 .It ATTR_DIR_ENTRYCOUNT
944 containing the number of file system objects in the directory, not including
945 any synthetic items. The historical "." and ".." entries are also
946 excluded from this count.
948 .It ATTR_DIR_MOUNTSTATUS
951 containing flags describing what's mounted on the directory.
952 Currently the only flag defined is
953 .Dv DIR_MNTSTATUS_MNTPOINT,
954 which indicates that there is a file system mounted on this directory.
956 .It ATTR_DIR_ALLOCSIZE
959 containing the number of bytes on disk used by the directory
962 .It ATTR_DIR_IOBLOCKSIZE
965 containing the optimal block size when reading or writing data.
967 .It ATTR_DIR_DATALENGTH
970 containing the length of the directory in bytes (the logical size).
974 Requested directory attributes are not returned for file system objects that
979 The following file attributes are defined.
981 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
983 .It ATTR_FILE_LINKCOUNT
986 containing the number of hard links to this file.
991 structure returned by
994 .It ATTR_FILE_TOTALSIZE
997 containing the total number of bytes in all forks of the file (the logical size).
999 .It ATTR_FILE_ALLOCSIZE
1002 containing a count of the bytes on disk used by all of the file's forks (the physical size).
1004 .It ATTR_FILE_IOBLOCKSIZE
1007 containing the optimal block size when reading or writing this file's data.
1009 .It ATTR_FILE_CLUMPSIZE
1012 containing the allocation clump size for this file, in bytes.
1013 As the file is extended, the file system will attempt to allocate
1014 this much space each time in order to reduce fragmentation.
1015 This value applies to the data fork.
1017 .It ATTR_FILE_DEVTYPE
1020 containing the device type for a special device file.
1025 structure returned by
1028 .It ATTR_FILE_FILETYPE
1031 that whose value is reserved.
1032 Clients should ignore its value.
1033 New volume format implementations should not support this attribute.
1035 .It ATTR_FILE_FORKCOUNT
1038 containing the number of forks in the file.
1039 No built-in file systems on Mac OS X currently support forks other
1040 than the data and resource fork.
1042 .It ATTR_FILE_FORKLIST
1045 structure containing a list of named forks of the file.
1046 No built-in file systems on Mac OS X currently support forks
1047 other than the data and resource fork.
1048 Because of this, the structure of this attribute's value is not yet defined.
1050 .It ATTR_FILE_DATALENGTH
1053 containing the length of the data fork in bytes (the logical size).
1055 .It ATTR_FILE_DATAALLOCSIZE
1058 containing a count of the bytes on disk used by the data fork (the physical size).
1060 .It ATTR_FILE_DATAEXTENTS
1063 array for the data fork.
1064 The array contains eight
1066 structures which represent the first
1067 eight extents of the fork.
1069 This attributes exists for compatibility reasons.
1070 New clients should not use this attribute.
1071 Rather, they should use the
1077 In current implementations the value may not be entirely accurate for
1078 a variety of reasons.
1080 .It ATTR_FILE_RSRCLENGTH
1083 containing the length of the resource fork in bytes (the logical size).
1085 .It ATTR_FILE_RSRCALLOCSIZE
1088 containing a count of the bytes on disk used by the resource fork (the physical size).
1090 .It ATTR_FILE_RSRCEXTENTS
1093 array for the resource fork.
1094 The array contains eight
1096 structures which represent the first
1097 eight extents of the fork.
1100 .Dv ATTR_FILE_DATAEXTENTS .
1105 File attributes are used for any file system object that is not a directory,
1106 not just ordinary files.
1107 Requested file attributes are not returned for file system objects that
1112 Fork attributes relate to the actual data in the file,
1113 which can be held in multiple named contiguous ranges, or forks.
1114 These cannot be used if the FSOPT_ATTR_CMN_EXTENDED is given.
1115 The following fork attributes are defined.
1117 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
1119 .It ATTR_FORK_TOTALSIZE
1123 containing the length of the fork in bytes (the logical size).
1125 .It ATTR_FORK_ALLOCSIZE
1129 containing a count of the bytes on disk used by the fork (the physical size).
1131 .It ATTR_FORK_RESERVED
1133 You must set this to 0.
1138 Fork attributes are deprecated and all bits are reserved.
1139 They are not properly implemented by any current Mac OS X
1140 volume format implementation.
1141 We strongly recommend that client programs do not request fork attributes.
1142 If you are implementing a volume format, you should not support these attributes.
1144 .Sh COMMON EXTENDED ATTRIBUTES
1146 Common extended attributes are like common attributes except that they are set
1147 in the forkattr field and can only be used if the FSOPT_ATTR_CMN_EXTENDED
1148 option is given. Use of these attributes is mutually exclusive with the above
1151 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
1153 .It ATTR_CMNEXT_RELPATH
1156 structure containing the mount-relative path of
1157 the file system object as
1158 a UTF-8 encoded, null terminated C string.
1159 The attribute data length will not be greater than
1161 Inconsistent behavior may be observed when this attribute is requested on
1162 hard-linked items, particularly when the file system does not support
1163 ATTR_CMN_PARENTID natively. Callers should be aware of this when requesting the
1164 relative path of a hard-linked item.
1166 .It ATTR_CMNEXT_PRIVATESIZE
1169 containing the number of bytes that are \fBnot\fP trapped inside a clone
1170 or snapshot, and which would be freed immediately if the file were deleted.
1172 .It ATTR_CMNEXT_LINKID
1175 that uniquely identifies the file system object within a mounted volume for the
1176 duration of its mount.
1178 On HFS+ and APFS volumes, the ATTR_CMNEXT_LINKID of a file system
1179 object is distinct from the ATTR_CMNEXT_LINKID of any hard link to that file
1180 system object. Although the ATTR_CMNEXT_LINKID of a file system object may appear
1181 similar (in whole or in part) to its ATTR_CMN_FILEID (see description of
1182 ATTR_CMN_FILEID above), \fBno relation between the two attributes should ever be implied.\fP
1186 .Sh VOLUME CAPABILITIES
1188 .\" vol_capabilities_attr_t
1190 Not all volumes support all features.
1192 .Dv ATTR_VOL_CAPABILITIES
1194 .Vt vol_capabilities_attr_t
1195 structure (shown below) that indicates which features are supported by the volume.
1198 typedef u_int32_t vol_capabilities_set_t[4];
1201 #define VOL_CAPABILITIES_FORMAT 0
1202 #define VOL_CAPABILITIES_INTERFACES 1
1203 #define VOL_CAPABILITIES_RESERVED1 2
1204 #define VOL_CAPABILITIES_RESERVED2 3
1207 typedef struct vol_capabilities_attr {
1208 vol_capabilities_set_t capabilities;
1209 vol_capabilities_set_t valid;
1210 } vol_capabilities_attr_t;
1214 The structure contains two fields,
1218 Each consists of an array of four elements.
1219 The arrays are indexed by the following values.
1221 .Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1223 .It VOL_CAPABILITIES_FORMAT
1224 This element contains information about the volume format.
1226 .Dv VOL_CAP_FMT_PERSISTENTOBJECTIDS
1229 .It VOL_CAPABILITIES_INTERFACES
1230 This element contains information about which optional functions are
1231 supported by the volume format implementation.
1233 .Dv VOL_CAP_INT_SEARCHFS
1236 .It VOL_CAPABILITIES_RESERVED1
1238 A file system implementation should set this element to zero.
1239 A client program should ignore this element.
1241 .It VOL_CAPABILITIES_RESERVED2
1243 A file system implementation should set this element to zero.
1244 A client program should ignore this element.
1251 field contains bit sets that indicate which flags are known to the volume format
1253 Each bit indicates whether the contents of the corresponding bit in the
1260 field contains bit sets that indicate whether a particular feature is implemented
1261 by this volume format.
1264 The following bits are defined in the first element (indexed by
1265 .Dv VOL_CAPABILITIES_FORMAT )
1271 .Vt vol_capabilities_attr_t
1274 .Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1276 .It VOL_CAP_FMT_PERSISTENTOBJECTIDS
1277 If this bit is set the volume format supports persistent object identifiers
1278 and can look up file system objects by their IDs.
1280 .Dv ATTR_CMN_OBJPERMANENTID
1281 for details about how to obtain these identifiers.
1283 .It VOL_CAP_FMT_SYMBOLICLINKS
1284 If this bit is set the volume format supports symbolic links.
1286 .It VOL_CAP_FMT_HARDLINKS
1287 If this bit is set the volume format supports hard links.
1289 .It VOL_CAP_FMT_JOURNAL
1290 If this bit is set the volume format supports a journal used to
1291 speed recovery in case of unplanned restart (such as a power outage
1293 This does not necessarily mean the volume is actively using a journal.
1295 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1297 .It VOL_CAP_FMT_JOURNAL_ACTIVE
1298 If this bit is set the volume is currently using a journal for
1299 speedy recovery after an unplanned restart.
1300 This bit can be set only if
1301 .Dv VOL_CAP_FMT_JOURNAL
1304 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1306 .It VOL_CAP_FMT_NO_ROOT_TIMES
1307 If this bit is set the volume format does not store reliable times for
1308 the root directory, so you should not depend on them to detect changes,
1309 identify volumes across unmount/mount, and so on.
1311 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1313 .It VOL_CAP_FMT_SPARSE_FILES
1314 If this bit is set the volume format supports sparse files,
1315 that is, files which can have 'holes' that have never been written
1316 to, and thus do not consume space on disk.
1317 A sparse file may have an allocated size on disk that is less than its logical length (that is,
1318 .Dv ATTR_FILE_ALLOCSIZE
1320 .Dv ATTR_FILE_TOTALSIZE ).
1323 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1325 .It VOL_CAP_FMT_ZERO_RUNS
1326 For security reasons, parts of a file (runs) that have never been
1327 written to must appear to contain zeroes.
1328 When this bit is set, the volume keeps track of allocated but unwritten
1329 runs of a file so that it can substitute zeroes without actually
1330 writing zeroes to the media.
1331 This provides performance similar to sparse files, but not the space savings.
1333 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1335 .It VOL_CAP_FMT_CASE_SENSITIVE
1336 If this bit is set the volume format treats upper and lower case
1337 characters in file and directory names as different.
1338 Otherwise an upper case character is equivalent to a lower case character,
1339 and you can't have two names that differ solely in the case of
1342 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1344 .It VOL_CAP_FMT_CASE_PRESERVING
1345 If this bit is set the volume format preserves the case of
1346 file and directory names.
1347 Otherwise the volume may change the case of some characters
1348 (typically making them all upper or all lower case).
1350 .Dv VOL_CAP_FMT_CASE_SENSITIVE
1352 .Dv VOL_CAP_FMT_CASE_PRESERVING .
1354 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1356 .It VOL_CAP_FMT_FAST_STATFS
1357 This bit is used as a hint to upper layers to
1360 is fast enough that its results need not be cached by the caller.
1361 A volume format implementation that caches the
1363 information in memory should set this bit.
1364 An implementation that must always read from disk or always perform a network
1365 transaction to satisfy
1367 should not set this bit.
1369 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1371 .It VOL_CAP_FMT_2TB_FILESIZE
1372 If this bit is set the volume format supports file sizes larger
1373 than 4GB, and potentially up to 2TB; it does not indicate
1374 whether the file system supports files larger than that.
1376 Introduced with Darwin 8.0 (Mac OS X version 10.4).
1378 .It VOL_CAP_FMT_OPENDENYMODES
1379 If this bit is set, the volume format supports open deny modes
1380 (e.g., "open for read write, deny write").
1382 .It VOL_CAP_FMT_HIDDEN_FILES
1383 If this bit is set, the volume format supports the
1387 flag is mapped to that volume's native "hidden" or "invisible"
1388 bit (e.g., the invisible bit from the Finder Info extended attribute).
1390 .It VOL_CAP_FMT_PATH_FROM_ID
1391 If this bit is set, the volume format supports the ability to derive a pathname
1392 to the root of the file system given only the ID of an object. This also
1393 implies that object IDs on this file system are persistent and not recycled.
1394 Most file systems will not support this capability.
1396 .It VOL_CAP_FMT_NO_VOLUME_SIZES
1397 If this bit is set the volume format does not support
1398 determining values for total data blocks, available blocks, or free blocks, as in
1407 Historically, those values were set to 0xFFFFFFFF for volumes
1408 that did not support them.
1410 Introduced with Darwin 10.0 (Mac OS X version 10.6).
1412 .It VOL_CAP_FMT_64BIT_OBJECT_IDS
1413 If this bit is set, the volume format uses object IDs that are 64-bit.
1414 This means that ATTR_CMN_FILEID and ATTR_CMN_PARENTID are the primary means of
1415 obtaining object IDs from this volume. The values returned by ATTR_CMN_OBJID,
1416 ATTR_CMN_OBJPERMANENTID, and ATTR_CMN_PAROBJID can be interpreted as 64-bit
1417 object IDs instead of fsobj_id_t.
1419 .It VOL_CAP_FMT_NO_IMMUTABLE_FILES
1420 If this bit is set, the volume format does not support setting the UF_IMMUTABLE
1422 See ATTR_CMN_FLAGS for more details.
1423 .It VOL_CAP_FMT_NO_PERMISSIONS
1424 If this bit is set, the volume format does not support setting file
1426 See ATTR_CMN_USERACCESS for more details.
1431 The following bits are defined in the second element (indexed by
1432 .Dv VOL_CAPABILITIES_INTERFACES )
1438 .Vt vol_capabilities_attr_t
1441 .Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1443 .It VOL_CAP_INT_SEARCHFS
1444 If this bit is set the volume format implementation supports
1447 .It VOL_CAP_INT_ATTRLIST
1448 If this bit is set the volume format implementation supports
1453 .It VOL_CAP_INT_NFSEXPORT
1454 If this bit is set the volume format implementation allows this volume to be exported via NFS.
1456 .It VOL_CAP_INT_READDIRATTR
1457 If this bit is set the volume format implementation supports
1458 .Xr getdirentriesattr 2 .
1460 .It VOL_CAP_INT_EXCHANGEDATA
1461 If this bit is set the volume format implementation supports
1462 .Xr exchangedata 2 .
1464 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1466 .It VOL_CAP_INT_COPYFILE
1467 If this bit is set the volume format implementation supports the (private and undocumented)
1468 copyfile() function.
1473 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1475 .It VOL_CAP_INT_ALLOCATE
1476 If this bit is set the volume format implementation supports the
1481 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1483 .It VOL_CAP_INT_VOL_RENAME
1484 If this bit is set the volume format implementation allows you to
1485 modify the volume name using
1488 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1490 .It VOL_CAP_INT_ADVLOCK
1491 If this bit is set the volume format implementation supports
1492 advisory locking, that is, the
1500 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1502 .It VOL_CAP_INT_FLOCK
1503 If this bit is set the volume format implementation supports
1514 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1516 .It VOL_CAP_INT_EXTENDED_SECURITY
1517 If this bit is set the volume format implementation supports
1518 extended security controls (ACLs).
1520 Introduced with Darwin 8.0 (Mac OS X version 10.4).
1522 .It VOL_CAP_INT_USERACCESS
1523 If this bit is set the volume format implementation supports the
1524 ATTR_CMN_USERACCESS attribute.
1526 Introduced with Darwin 8.0 (Mac OS X version 10.4).
1528 .It VOL_CAP_INT_MANLOCK
1529 If this bit is set, the volume format implementation supports
1530 AFP-style mandatory byte range locks via
1533 .It VOL_CAP_INT_EXTENDED_ATTR
1534 If this bit is set, the volume format implementation supports
1535 native extended attributes (see
1536 .Xr setxattr 2 Ns ).
1538 .It VOL_CAP_INT_CLONE
1539 If this bit is set, the file system supports cloning files and directories.
1544 .It VOL_CAP_INT_SNAPSHOT
1545 If this bit is set, the file system supports snapshots.
1547 .Xr fs_snapshot_create 2
1550 .It VOL_CAP_INT_NAMEDSTREAMS
1551 If this bit is set, the volume format implementation supports
1552 native named streams.
1554 .It VOL_CAP_INT_RENAME_SWAP
1555 If this bit is set, the file system supports swapping file system
1560 .It VOL_CAP_INT_RENAME_EXCL
1561 If this bit is set, the file system supports an exclusive rename
1569 .\" vol_attributes_attr_t
1571 A volume can also report which attributes it supports.
1572 This information is returned by the
1573 .Dv ATTR_VOL_ATTRIBUTES
1574 attribute, which returns a
1575 .Vt vol_attributes_attr_t
1576 structure (shown below).
1579 typedef struct attribute_set {
1580 attrgroup_t commonattr; /* common attribute group */
1581 attrgroup_t volattr; /* volume attribute group */
1582 attrgroup_t dirattr; /* directory attribute group */
1583 attrgroup_t fileattr; /* file attribute group */
1584 attrgroup_t forkattr; /* fork attribute group */
1588 typedef struct vol_attributes_attr {
1589 attribute_set_t validattr;
1590 attribute_set_t nativeattr;
1591 } vol_attributes_attr_t;
1597 field consists of a number of bit sets that indicate whether an attribute is
1598 supported by the volume format implementation.
1601 is similar except that the bit sets indicate whether an attribute is supported
1602 natively by the volume format.
1603 An attribute is supported natively if the volume format implementation does not have to do
1604 any complex conversions to access the attribute.
1605 For example, a volume format might support persistent object identifiers, but
1606 doing so requires a complex table lookup that is not part of the core volume
1609 .Dv ATTR_VOL_ATTRIBUTES
1610 attribute would return
1611 .Dv ATTR_CMN_OBJPERMANENTID
1615 .Vt vol_attributes_attr_t ,
1621 Upon successful completion a value of 0 is returned.
1622 Otherwise, a value of -1 is returned and
1624 is set to indicate the error.
1627 Not all volumes support
1629 The best way to test whether a volume supports this function is to
1630 simply call it and check the error result.
1634 if it is not supported on a particular volume.
1639 function has been undocumented for more than two years.
1640 In that time a number of volume format implementations have been created without
1641 a proper specification for the behaviour of this routine.
1642 You may encounter volume format implementations with slightly different
1643 behaviour than what is described here.
1644 Your program is expected to be tolerant of this variant behaviour.
1647 If you're implementing a volume format that supports
1649 you should be careful to support the behaviour specified by this document.
1659 The volume does not support the query.
1662 A component of the path prefix for
1666 .It Bq Er ENAMETOOLONG
1667 A component of a path name for
1671 characters, or an entire path name exceeded
1676 The file system object for
1681 The file descriptor argument for
1683 is not a valid file descriptor.
1686 Search permission is denied for a component of the path prefix for
1690 Too many symbolic links were encountered in translating the pathname
1699 points to an invalid address.
1703 is too small to hold a u_int32_t.
1711 .Dv ATTR_BIT_MAP_COUNT .
1714 You requested an invalid attribute.
1717 You requested an attribute that is not supported for this file system object.
1720 You requested volume attributes and directory or file attributes.
1723 You requested volume attributes but
1725 does not reference the root of the volume.
1728 The volume is read-only but must be modified in order to return this attribute.
1731 An I/O error occurred while reading from or writing to the file system.
1734 In addition to the errors returned by the
1738 function may fail if:
1743 argument does not specify an absolute path and the
1747 nor a valid file descriptor open for searching.
1751 argument is not an absolute path and
1755 nor a file descriptor associated with a directory.
1761 If you request any volume attributes, you must set
1765 field, even though it generates no result in the attribute buffer.
1768 The order that attributes are stored in the attribute buffer almost
1769 invariably matches the order of attribute mask bit values.
1772 (0x00000001) comes before
1774 (0x00000002) because its value is smaller.
1775 When ordering attributes, you should always use the order in which they
1776 are described above.
1781 structure is 64-bits (two 32-bit elements) in 32-bit code, and
1782 128-bits (two 64-bit elements) in 64-bit code; however, it is aligned
1783 on a 4-byte (32-bit) boundary, even in 64-bit code.
1785 If you use a structure
1786 for the attribute data, it must be correctly packed and aligned (see
1790 Inconsistent behavior may be observed when the ATTR_CMN_FULLPATH attribute is requested on
1791 hard-linked items, particularly when the file system does not support ATTR_CMN_PARENTID
1792 natively. Callers should be aware of this when requesting the full path of a hard-linked item, especially
1793 if the full path crosses mount points.
1796 For more caveats, see also the compatibility notes above.
1800 The following code prints the file type and creator of a file,
1801 assuming that the volume supports the required attributes.
1807 #include <sys/attr.h>
1808 #include <sys/errno.h>
1810 #include <sys/vnode.h>
1813 typedef struct attrlist attrlist_t;
1816 struct FInfoAttrBuf {
1818 fsobj_type_t objType;
1819 char finderInfo[32];
1820 } __attribute__((aligned(4), packed));
1821 typedef struct FInfoAttrBuf FInfoAttrBuf;
1824 static int FInfoDemo(const char *path)
1827 attrlist_t attrList;
1828 FInfoAttrBuf attrBuf;
1831 memset(&attrList, 0, sizeof(attrList));
1832 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
1833 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
1836 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
1843 assert(attrBuf.length == sizeof(attrBuf));
1846 printf("Finder information for %s:\en", path);
1847 switch (attrBuf.objType) {
1849 printf("file type = '%.4s'\en", &attrBuf.finderInfo[0]);
1850 printf("file creator = '%.4s'\en", &attrBuf.finderInfo[4]);
1853 printf("directory\en");
1856 printf("other object type, %d\en", attrBuf.objType);
1867 The following code is an alternative implementation that uses nested structures
1868 to group the related attributes.
1875 #include <sys/attr.h>
1876 #include <sys/errno.h>
1878 #include <sys/vnode.h>
1881 typedef struct attrlist attrlist_t;
1884 struct FInfo2CommonAttrBuf {
1885 fsobj_type_t objType;
1886 char finderInfo[32];
1887 } __attribute__((aligned(4), packed));
1888 typedef struct FInfo2CommonAttrBuf FInfo2CommonAttrBuf;
1891 struct FInfo2AttrBuf {
1893 FInfo2CommonAttrBuf common;
1894 } __attribute__((aligned(4), packed));;
1895 typedef struct FInfo2AttrBuf FInfo2AttrBuf;
1898 static int FInfo2Demo(const char *path)
1901 attrlist_t attrList;
1902 FInfo2AttrBuf attrBuf;
1905 memset(&attrList, 0, sizeof(attrList));
1906 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
1907 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
1910 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
1917 assert(attrBuf.length == sizeof(attrBuf));
1920 printf("Finder information for %s:\en", path);
1921 switch (attrBuf.common.objType) {
1924 "file type = '%.4s'\en",
1925 &attrBuf.common.finderInfo[0]
1928 "file creator = '%.4s'\en",
1929 &attrBuf.common.finderInfo[4]
1933 printf("directory\en");
1937 "other object type, %d\en",
1938 attrBuf.common.objType
1950 The following example shows how to deal with variable length attributes.
1951 It assumes that the volume specified by
1953 supports the necessary attributes.
1960 #include <sys/attr.h>
1961 #include <sys/errno.h>
1963 #include <sys/vnode.h>
1966 typedef struct attrlist attrlist_t;
1971 u_int32_t fileCount;
1973 attrreference_t mountPointRef;
1974 attrreference_t volNameRef;
1975 char mountPointSpace[MAXPATHLEN];
1976 char volNameSpace[MAXPATHLEN];
1977 } __attribute__((aligned(4), packed));
1978 typedef struct VolAttrBuf VolAttrBuf;
1981 static int VolDemo(const char *path)
1984 attrlist_t attrList;
1988 memset(&attrList, 0, sizeof(attrList));
1989 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
1990 attrList.volattr = ATTR_VOL_INFO
1991 | ATTR_VOL_FILECOUNT
1993 | ATTR_VOL_MOUNTPOINT
1997 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
2004 assert(attrBuf.length > offsetof(VolAttrBuf, mountPointSpace));
2005 assert(attrBuf.length <= sizeof(attrBuf));
2008 printf("Volume information for %s:\en", path);
2009 printf("ATTR_VOL_FILECOUNT: %u\en", attrBuf.fileCount);
2010 printf("ATTR_VOL_DIRCOUNT: %u\en", attrBuf.dirCount);
2012 "ATTR_VOL_MOUNTPOINT: %.*s\en",
2013 (int) attrBuf.mountPointRef.attr_length,
2014 ( ((char *) &attrBuf.mountPointRef)
2015 + attrBuf.mountPointRef.attr_dataoffset )
2018 "ATTR_VOL_NAME: %.*s\en",
2019 (int) attrBuf.volNameRef.attr_length,
2020 ( ((char *) &attrBuf.volNameRef)
2021 + attrBuf.volNameRef.attr_dataoffset )
2030 The following sample demonstrates the need to use packing and alignment
2031 controls; without the attribute, in 64-bit code, the fields of the structure are not
2032 placed at the locations that the kernel expects.
2041 #include <sys/attr.h>
2043 /* The alignment and packing attribute is necessary in 64-bit code */
2044 struct AttrListTimes {
2046 struct timespec st_crtime;
2047 struct timespec st_modtime;
2048 } __attribute__((aligned(4), packed));
2050 main(int argc, char **argv)
2055 for (i = 1; i < argc; i++) {
2056 struct attrlist attrList;
2057 struct AttrListTimes myStat = {0};
2058 char *path = argv[i];
2060 memset(&attrList, 0, sizeof(attrList));
2061 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
2062 attrList.commonattr = ATTR_CMN_CRTIME |
2065 rv = getattrlist(path, &attrList, &myStat, sizeof(myStat), 0);
2068 warn("getattrlist(%s)", path);
2071 printf("%s: Modification time = %s", argv[i], ctime(&myStat.st_modtime.tv_sec));
2077 The getLinkIDInfo() function determines if ATTR_CMNEXT_LINKID and ATTR_CMN_OBJID
2078 are valid to use on the file system specified by path.
2081 int getLinkIDInfo(const char *path, bool *cmnExtLinkIDValid, bool *cmnObjIDValid)
2084 struct statfs statfsBuf;
2085 struct attrlist attrList;
2086 struct volAttrsBuf {
2088 vol_capabilities_attr_t capabilities;
2089 vol_attributes_attr_t attributes;
2090 } __attribute__((aligned(4), packed));
2091 struct volAttrsBuf volAttrs;
2093 memset(&attrList, 0, sizeof(attrList));
2094 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
2095 attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_CAPABILITIES | ATTR_VOL_ATTRIBUTES;
2096 // get the file system's mount point path for the input path
2097 result = statfs(path, &statfsBuf);
2098 if ( result == 0 ) {
2099 // get the supported capabilities and attributes
2100 result = getattrlist(statfsBuf.f_mntonname, &attrList, &volAttrs, sizeof(volAttrs), FSOPT_ATTR_CMN_EXTENDED);
2101 if ( result == 0 ) {
2102 if ( volAttrs.attributes.validattr.forkattr & ATTR_CMNEXT_LINKID ) {
2103 // ATTR_CMNEXT_LINKID is available; do not use ATTR_CMN_OBJID
2104 *cmnExtLinkIDValid = true;
2105 *cmnObjIDValid = false;
2108 // ATTR_CMNEXT_LINKID is not available
2109 cmnExtLinkIDValid = false;
2110 // ATTR_CMN_OBJID can only be used if the file system does not use 64-bit object IDs
2111 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) ) {
2112 *cmnObjIDValid = false;
2115 *cmnObjIDValid = true;
2120 if ( result != 0 ) {
2121 *cmnExtLinkIDValid = *cmnObjIDValid = false;
2132 .Xr exchangedata 2 ,
2134 .Xr getattrlistbulk 2 ,
2144 function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).
2147 function call appeared in OS X 10.10 .