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.
25 .Nd get file system attributes
27 .Fd #include <sys/attr.h>
28 .Fd #include <unistd.h>
30 .Fn getattrlist "const char* path" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned long options"
33 .Fn fgetattrlist "int fd" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned long options"
37 function returns attributes (that is, metadata) of file system objects.
39 works on the file system object named by
43 works on the provided file descriptor
47 as a seriously enhanced version of
49 The functions return attributes about the specified file system object
50 into the buffer specified by
56 parameter determines what attributes are returned.
59 parameter lets you control specific aspects of the function's behavior.
66 functions are only supported by certain volume format implementations.
67 For maximum compatibility, client programs should use high-level APIs
68 (such as the Carbon File Manager) to access file system attributes.
69 These high-level APIs include logic to emulate file system attributes
70 on volumes that don't support
74 Not all volumes support all attributes.
76 .Dv ATTR_VOL_ATTRIBUTES
77 for a discussion of how to determine whether a particular volume supports a
80 Furthermore, you should only request the attributes that you need.
81 Some attributes are expensive to calculate on some volume formats.
83 .Dv ATTR_DIR_ENTRYCOUNT
84 is usually expensive to calculate on non-HFS [Plus] volumes.
85 If you don't need a particular attribute, you should not ask for it.
92 parameter must reference a valid file system object.
93 Read, write or execute permission of the object itself is not required, but
94 all directories listed in the path name leading to the object must be
98 .\" attrList parameter
102 parameter is a pointer to an
104 structure, as defined by
107 It determines what attributes are returned by the function.
108 You are responsible for filling out all fields of this structure before calling the function.
110 typedef u_int32_t attrgroup_t;
113 u_short bitmapcount; /* number of attr. bit sets in list */
114 u_int16_t reserved; /* (to maintain 4-byte alignment) */
115 attrgroup_t commonattr; /* common attribute group */
116 attrgroup_t volattr; /* volume attribute group */
117 attrgroup_t dirattr; /* directory attribute group */
118 attrgroup_t fileattr; /* file attribute group */
119 attrgroup_t forkattr; /* fork attribute group */
121 #define ATTR_BIT_MAP_COUNT 5
125 .\" attrlist elements
129 structure are defined as follows.
130 .Bl -tag -width XXXbitmapcount
133 Number of attribute bit sets in the structure.
134 In current systems you must set this to
135 .Dv ATTR_BIT_MAP_COUNT .
139 You must set this to 0.
142 A bit set that specifies the common attributes that you require.
143 Common attributes relate to all types of file system objects.
144 See below for a description of these attributes.
147 A bit set that specifies the volume attributes that you require.
148 Volume attributes relate to volumes (that is, mounted file systems).
149 See below for a description of these attributes.
150 If you request volume attributes,
152 must reference the root of a volume.
153 In addition, you can't request volume attributes if you also request
154 file or directory attributes.
157 A bit set that specifies the directory attributes that you require.
158 See below for a description of these attributes.
161 A bit set that specifies the file attributes that you require.
162 See below for a description of these attributes.
165 A bit set that specifies the fork attributes that you require.
166 Fork attributes relate to the actual data in the file,
167 which can be held in multiple named contiguous ranges, or forks.
168 See below for a description of these attributes.
173 Unless otherwise noted in the lists below, attributes are read-only.
174 Attributes labelled as read/write can be set using
178 .\" attrBuf and attrBufSize parameters
184 parameters specify a buffer into which the function places attribute values.
185 The format of this buffer is sufficiently complex that its description
186 requires a separate section (see below).
187 The initial contents of this buffer are ignored.
194 parameter is a bit set that controls the behaviour of
196 The following option bits are defined.
198 .Bl -tag -width FSOPT_PACK_INVAL_ATTRS
203 will not follow a symlink if it occurs as
204 the last component of
207 .It FSOPT_REPORT_FULLSIZE
208 The size of the attributes reported (in the first
210 field in the attribute buffer) will be the size needed to hold all the
211 requested attributes; if not set, only the attributes actually returned
212 will be reported. This allows the caller to determine if any truncation
215 .It FSOPT_PACK_INVAL_ATTRS
216 If this is bit is set, then all requested attributes, even ones that are
217 not supported by the object or file system, will be returned. Default values
218 will be used for the invalid ones. Requires that
219 .Dv ATTR_CMN_RETURNED_ATTRS
226 The data returned in the buffer described by
230 is formatted as follows.
236 The first element of the buffer is a
238 that contains the overall length, in bytes, of the attributes returned.
239 This size includes the length field itself.
242 Following the length field is a list of attributes.
243 Each attribute is represented by a field of its type,
244 where the type is given as part of the attribute description (below).
247 The attributes are placed into the attribute buffer in the order
248 that they are described below.
251 Each attribute is aligned to a 4-byte boundary (including 64-bit data types).
255 If the attribute is of variable length, it is represented
258 structure, as defined by
263 typedef struct attrreference {
264 int32_t attr_dataoffset;
265 u_int32_t attr_length;
270 This structure contains a 'pointer' to the variable length attribute data.
273 field is the length of the attribute data (in bytes).
276 field is the offset in bytes from the
279 to the attribute data.
280 This offset will always be a multiple of sizeof(u_int32_t) bytes,
281 so you can safely access common data types without fear of alignment
287 function will silently truncate attribute data if
290 The length field at the front of the attribute list always represents
291 the length of the data actually copied into the attribute buffer.
292 If the data is truncated, there is no easy way to determine the
293 buffer size that's required to get all of the requested attributes.
294 You should always pass an
296 that is large enough to accommodate the known size of the attributes
297 in the attribute list (including the leading length field).
300 Because the returned attributes are simply truncated if the buffer is
301 too small, it's possible for a variable length attribute to reference
302 data beyond the end of the attribute buffer. That is, it's possible
303 for the attribute data to start beyond the end of the attribute buffer
307 .Vt attrreference_t ,
316 ) ) or, indeed, for the attribute data to extend beyond the end of the attribute buffer (that is,
328 If this happens you must increase the size of the buffer and call
330 to get an accurate copy of the attribute.
332 .Sh COMMON ATTRIBUTES
334 Common attributes relate to all types of file system objects.
335 The following common attributes are defined.
337 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
339 .It ATTR_CMN_RETURNED_ATTRS
342 structure which is used to report which of the requested attributes
343 were actually returned. This attribute, when requested, will always
344 be the first attribute returned. By default, unsupported attributes
345 will be skipped (i.e. not packed into the output buffer). This behavior
346 can be over-ridden using the FSOPT_PACK_INVAL_ATTRS option flag. Only
347 .Xr getattrlist 2 supports this attribute (
348 .Xr getdirentriesattr 2 and
349 .Xr searchfs 2 do not support it ).
354 structure containing the name of the file system object as
355 UTF-8 encoded, null terminated C string.
356 The attribute data length will not be greater than
358 + 1 characters, which is
360 * 3 + 1 bytes (as one UTF-8-encoded character may
361 take up to three bytes).
367 containing the device number of the device on which this
368 file system object's volume is mounted.
373 structure returned by
379 structure containing the file system identifier for the volume on which
380 the file system object resides.
385 structure returned by
389 This value is not related to the file system ID from traditional Mac OS (for example,
394 structure returned by Carbon's FSGetVolumeInfo() function).
395 On current versions of Mac OS X that value is synthesised by the Carbon File Manager.
400 that identifies the type of file system object.
401 The values are taken from
409 that identifies the type of file system containing the object.
410 The values are taken from
418 structure that uniquely identifies the file system object
420 The fid_generation field of this structure will be zero for all non-root callers
421 (effective UID not 0).
422 This identifier need not be persistent across an unmount/mount sequence.
425 Some volume formats use well known values for the
427 field for the root directory (2) and the parent of root directory (1).
428 This is not a required behaviour of this attribute.
430 .It ATTR_CMN_OBJPERMANENTID
433 structure that uniquely identifies the file system object
435 The fid_generation field of this structure will be zero for all non-root callers
436 (effective UID not 0).
437 This identifier should be persistent across an unmount/mount sequence.
439 Some file systems (for example, original HFS) may need to modify the on-disk
440 structure to return a persistent identifier.
441 If such a file system is mounted read-only, an attempt to get this attribute
442 will fail with the error
445 .It ATTR_CMN_PAROBJID
448 structure that identifies the parent directory of the file system object.
449 The fid_generation field of this structure will be zero for all non-root callers
450 (effective UID not 0).
451 Equivalent to the ATTR_CMN_OBJID attribute of the parent directory.
452 This identifier need not be persistent across an unmount/mount sequence.
455 On a volume that supports hard links, a multiply linked file has no unique parent.
456 This attribute will return an unspecified parent.
459 For some volume formats this attribute is very expensive to calculate.
464 containing a text encoding hint for
465 the file system object's name.
466 It is included to facilitate the lossless round trip conversion of names between
467 Unicode and traditional Mac OS script encodings.
468 The values are defined in
469 .Aq Pa CarbonCore/TextCommon.h .
470 File systems that do not have an appropriate text encoding value should return
471 kTextEncodingMacUnicode.
472 See DTS Q&A 1173 "File Manager Text Encoding Hints".
477 structure containing the time that the file system object
483 structure containing the time that the file system object
489 structure returned by
495 structure containing the time that the file system object's
496 attributes were last modified.
501 structure returned by
507 structure containing the time that the file system object
513 structure returned by
516 .It ATTR_CMN_BKUPTIME
519 structure containing the time that the file system object was
521 This value is for use by backup utilities.
522 The file system stores but does not interpret the value.
524 .It ATTR_CMN_FNDRINFO
525 (read/write) 32 bytes of data for use by the Finder.
526 Equivalent to the concatenation of a
531 (or, for directories, a
534 .Vt ExtendedFolderInfo
536 These structures are defined in
537 .Aq Pa CarbonCore/Finder.h .
539 This attribute is not byte swapped by the file system.
540 The value of multibyte fields on disk is always big endian.
541 When running on a little endian system (such as Darwin on x86),
542 you must byte swap any multibyte fields.
547 containing the owner of the file system object.
552 structure returned by
558 containing the group of the file system object.
563 structure returned by
566 .It ATTR_CMN_ACCESSMASK
569 containing the access permissions of the file system object.
574 structure returned by
576 Only the permission bits of
578 are valid; other bits should be ignored,
579 e.g., by masking with
582 .It ATTR_CMN_NAMEDATTRCOUNT
585 containing the number of named attributes of the file system object.
587 .It ATTR_CMN_NAMEDATTRLIST
590 structure containing a list of named attributes of the file system object.
591 No built-in file systems on Mac OS X currently support named attributes.
592 Because of this, the structure of this attribute's value is not yet defined.
597 containing file flags.
602 structure returned by
604 For more information about these flags, see
608 The order that attributes are placed into the attribute buffer
609 almost invariably matches the order of the attribute mask bit values.
612 If its order was based on its bit position, it would be before
614 .Dv ATTR_CMN_NAMEDATTRCOUNT
616 .Dv ATTR_CMN_NAMEDATTRLIST
618 it is placed in the buffer after them.
620 .It ATTR_CMN_USERACCESS
623 containing the effective permissions of the current user
624 (the calling process's effective UID) for this file system object.
625 You can test for read, write, and execute permission using
635 .It ATTR_CMN_EXTENDED_SECURITY
636 A variable-length object (thus an
638 structure) containing a
640 structure, of which only the ACL entry is used.
645 of the owner of the file system object. Analoguous to
646 .Dv ATTR_CMN_OWNERID .
651 of the group to which the file system object belongs.
658 that uniquely identifies the file system object within its volume.
660 .It ATTR_CMN_PARENTID
663 that identifies the parent directory of the file system object.
665 .It ATTR_CMN_FULLPATH
668 structure containing the full path (resolving all symlinks) to
669 the file system object as
670 a UTF-8 encoded, null terminated C string.
671 The attribute data length will not be greater than
673 Inconsistent behavior may be observed when this attribute is requested on
674 hard-linked items, particularly when the file system does not support ATTR_CMN_PARENTID
675 natively. Callers should be aware of this when requesting the full path of a hard-linked item.
677 .It ATTR_CMN_ADDEDTIME
680 that contains the time that the file system object was created or renamed into
681 its containing directory. Note that inconsistent behavior may be observed
682 when this attribute is requested on hard-linked items.
687 .Sh VOLUME ATTRIBUTES
689 Volume attributes relate to volumes (that is, mounted file systems).
690 The following volume attributes are defined.
692 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
695 For reasons that are not at all obvious, you must set
699 field if you request any other volume attributes.
700 This does not result in any attribute data being added to the attribute buffer.
705 containing the file system type.
710 structure returned by
712 Generally not a useful value.
714 .It ATTR_VOL_SIGNATURE
717 containing the volume signature word.
718 This value is unique within a given file system type and lets you
719 distinguish between different volume formats handled by the same file system.
721 .Aq Pa CarbonCore/Files.h
727 containing the total size of the volume in bytes.
729 .It ATTR_VOL_SPACEFREE
732 containing the free space on the volume in bytes.
734 .It ATTR_VOL_SPACEAVAIL
737 containing the space, in bytes, on the volume available to non-privileged processes.
738 This is the free space minus the amount of space reserved by the system to prevent critical
739 disk exhaustion errors.
740 Non-privileged programs, like a disk management tool, should use this value to display the
741 space available to the user.
743 .Dv ATTR_VOL_SPACEAVAIL
745 .Dv ATTR_VOL_SPACEFREE
753 .It ATTR_VOL_MINALLOCATION
756 containing the minimum allocation size on the volume in bytes.
757 If you create a file containing one byte, it will consume this much space.
759 .It ATTR_VOL_ALLOCATIONCLUMP
762 containing the allocation clump size on the volume, in bytes.
763 As a file is extended, the file system will attempt to allocate
764 this much space each time in order to reduce fragmentation.
766 .It ATTR_VOL_IOBLOCKSIZE
769 containing the optimal block size when reading or writing data.
774 structure returned by
777 .It ATTR_VOL_OBJCOUNT
780 containing the number of file system objects on the volume.
782 .It ATTR_VOL_FILECOUNT
785 containing the number of files on the volume.
787 .It ATTR_VOL_DIRCOUNT
790 containing the number of directories on the volume.
792 .It ATTR_VOL_MAXOBJCOUNT
795 containing the maximum number of file system objects that can be stored on the volume.
797 .It ATTR_VOL_MOUNTPOINT
800 structure containing the path to the volume's mount point as a
801 UTF-8 encoded, null terminated C string.
802 The attribute data length will not be greater than
808 structure returned by
814 structure containing the name of the volume as a
815 UTF-8 encoded, null terminated C string.
816 The attribute data length will not be greater than
821 This attribute is only read/write if the
822 .Dv VOL_CAP_INT_VOL_RENAME
823 bit is set in the volume capabilities (see below).
826 .It ATTR_VOL_MOUNTFLAGS
829 containing the volume mount flags.
830 This is a copy of the value passed to the
834 when the volume was mounted.
839 structure returned by
842 .It ATTR_VOL_MOUNTEDDEVICE
845 structure that returns the same value as the
849 structure returned by
851 For local volumes this is the path to the device on which the volume is mounted as a
852 UTF-8 encoded, null terminated C string.
853 For network volumes, this is a unique string that identifies the mount.
854 The attribute data length will not be greater than
858 .It ATTR_VOL_ENCODINGSUSED
860 .Vt unsigned long long
861 containing a bitmap of the text encodings used on this volume.
862 For more information about this, see the discussion of
864 in DTS Technote 1150 "HFS Plus Volume Format".
866 .It ATTR_VOL_CAPABILITIES
868 .Vt vol_capabilities_attr_t
869 structure describing the optional features supported by this volume.
870 See below for a discussion of volume capabilities.
875 containing the file system UUID. Typically this will be a
878 .It ATTR_VOL_ATTRIBUTES
880 .Vt vol_attributes_attr_t
881 structure describing the attributes supported by this volume.
882 This structure is discussed below, along with volume capabilities.
886 .Sh DIRECTORY ATTRIBUTES
888 The following directory attributes are defined.
890 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
892 .It ATTR_DIR_LINKCOUNT
895 containing the number of hard links to the directory;
896 this does not include the historical "." and ".." entries.
897 For file systems that do not support hard links to directories,
898 this value will be 1.
900 .It ATTR_DIR_ENTRYCOUNT
903 containing the number of file system objects in the directory, not including
904 any synthetic items. The historical "." and ".." entries are also
905 excluded from this count.
907 .It ATTR_DIR_MOUNTSTATUS
910 containing flags describing what's mounted on the directory.
911 Currently the only flag defined is
912 .Dv DIR_MNTSTATUS_MNTPOINT,
913 which indicates that there is a file system mounted on this directory.
918 Requested directory attributes are not returned for file system objects that
923 The following file attributes are defined.
925 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
927 .It ATTR_FILE_LINKCOUNT
930 containing the number of hard links to this file.
935 structure returned by
938 .It ATTR_FILE_TOTALSIZE
941 containing the total number of bytes in all forks of the file (the logical size).
943 .It ATTR_FILE_ALLOCSIZE
946 containing a count of the bytes on disk used by all of the file's forks (the physical size).
948 .It ATTR_FILE_IOBLOCKSIZE
951 containing the optimal block size when reading or writing this file's data.
953 .It ATTR_FILE_CLUMPSIZE
956 containing the allocation clump size for this file, in bytes.
957 As the file is extended, the file system will attempt to allocate
958 this much space each time in order to reduce fragmentation.
959 This value applies to the data fork.
961 .It ATTR_FILE_DEVTYPE
964 containing the device type for a special device file.
969 structure returned by
972 .It ATTR_FILE_FILETYPE
975 that whose value is reserved.
976 Clients should ignore its value.
977 New volume format implementations should not support this attribute.
979 .It ATTR_FILE_FORKCOUNT
982 containing the number of forks in the file.
983 No built-in file systems on Mac OS X currently support forks other
984 than the data and resource fork.
986 .It ATTR_FILE_FORKLIST
989 structure containing a list of named forks of the file.
990 No built-in file systems on Mac OS X currently support forks
991 other than the data and resource fork.
992 Because of this, the structure of this attribute's value is not yet defined.
994 .It ATTR_FILE_DATALENGTH
997 containing the length of the data fork in bytes (the logical size).
999 .It ATTR_FILE_DATAALLOCSIZE
1002 containing a count of the bytes on disk used by the data fork (the physical size).
1004 .It ATTR_FILE_DATAEXTENTS
1007 array for the data fork.
1008 The array contains eight
1010 structures which represent the first
1011 eight extents of the fork.
1013 This attributes exists for compatibility reasons.
1014 New clients should not use this attribute.
1015 Rather, they should use the
1021 In current implementations the value may not be entirely accurate for
1022 a variety of reasons.
1024 .It ATTR_FILE_RSRCLENGTH
1027 containing the length of the resource fork in bytes (the logical size).
1029 .It ATTR_FILE_RSRCALLOCSIZE
1032 containing a count of the bytes on disk used by the resource fork (the physical size).
1034 .It ATTR_FILE_RSRCEXTENTS
1037 array for the resource fork.
1038 The array contains eight
1040 structures which represent the first
1041 eight extents of the fork.
1044 .Dv ATTR_FILE_DATAEXTENTS .
1049 File attributes are used for any file system object that is not a directory,
1050 not just ordinary files.
1051 Requested file attributes are not returned for file system objects that
1056 Fork attributes relate to the actual data in the file,
1057 which can be held in multiple named contiguous ranges, or forks.
1058 The following fork attributes are defined.
1060 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
1062 .It ATTR_FORK_TOTALSIZE
1065 containing the length of the fork in bytes (the logical size).
1067 .It ATTR_FORK_ALLOCSIZE
1070 containing a count of the bytes on disk used by the fork (the physical size).
1075 Fork attributes are not properly implemented by any current Mac OS X
1076 volume format implementation.
1077 We strongly recommend that client programs do not request fork attributes.
1078 If you are implementing a volume format, you should not support these attributes.
1080 .Sh VOLUME CAPABILITIES
1082 .\" vol_capabilities_attr_t
1084 Not all volumes support all features.
1086 .Dv ATTR_VOL_CAPABILITIES
1088 .Vt vol_capabilities_attr_t
1089 structure (shown below) that indicates which features are supported by the volume.
1092 typedef u_int32_t vol_capabilities_set_t[4];
1095 #define VOL_CAPABILITIES_FORMAT 0
1096 #define VOL_CAPABILITIES_INTERFACES 1
1097 #define VOL_CAPABILITIES_RESERVED1 2
1098 #define VOL_CAPABILITIES_RESERVED2 3
1101 typedef struct vol_capabilities_attr {
1102 vol_capabilities_set_t capabilities;
1103 vol_capabilities_set_t valid;
1104 } vol_capabilities_attr_t;
1108 The structure contains two fields,
1112 Each consists of an array of four elements.
1113 The arrays are indexed by the following values.
1115 .Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1117 .It VOL_CAPABILITIES_FORMAT
1118 This element contains information about the volume format.
1120 .Dv VOL_CAP_FMT_PERSISTENTOBJECTIDS
1123 .It VOL_CAPABILITIES_INTERFACES
1124 This element contains information about which optional functions are
1125 supported by the volume format implementation.
1127 .Dv VOL_CAP_INT_SEARCHFS
1130 .It VOL_CAPABILITIES_RESERVED1
1132 A file system implementation should set this element to zero.
1133 A client program should ignore this element.
1135 .It VOL_CAPABILITIES_RESERVED2
1137 A file system implementation should set this element to zero.
1138 A client program should ignore this element.
1145 field contains bit sets that indicate which flags are known to the volume format
1147 Each bit indicates whether the contents of the corresponding bit in the
1154 field contains bit sets that indicate whether a particular feature is implemented
1155 by this volume format.
1158 The following bits are defined in the first element (indexed by
1159 .Dv VOL_CAPABILITIES_FORMAT )
1165 .Vt vol_capabilities_attr_t
1168 .Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1170 .It VOL_CAP_FMT_PERSISTENTOBJECTIDS
1171 If this bit is set the volume format supports persistent object identifiers
1172 and can look up file system objects by their IDs.
1174 .Dv ATTR_CMN_OBJPERMANENTID
1175 for details about how to obtain these identifiers.
1177 .It VOL_CAP_FMT_SYMBOLICLINKS
1178 If this bit is set the volume format supports symbolic links.
1180 .It VOL_CAP_FMT_HARDLINKS
1181 If this bit is set the volume format supports hard links.
1183 .It VOL_CAP_FMT_JOURNAL
1184 If this bit is set the volume format supports a journal used to
1185 speed recovery in case of unplanned restart (such as a power outage
1187 This does not necessarily mean the volume is actively using a journal.
1189 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1191 .It VOL_CAP_FMT_JOURNAL_ACTIVE
1192 If this bit is set the volume is currently using a journal for
1193 speedy recovery after an unplanned restart.
1194 This bit can be set only if
1195 .Dv VOL_CAP_FMT_JOURNAL
1198 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1200 .It VOL_CAP_FMT_NO_ROOT_TIMES
1201 If this bit is set the volume format does not store reliable times for
1202 the root directory, so you should not depend on them to detect changes,
1203 identify volumes across unmount/mount, and so on.
1205 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1207 .It VOL_CAP_FMT_SPARSE_FILES
1208 If this bit is set the volume format supports sparse files,
1209 that is, files which can have 'holes' that have never been written
1210 to, and thus do not consume space on disk.
1211 A sparse file may have an allocated size on disk that is less than its logical length (that is,
1212 .Dv ATTR_FILE_ALLOCSIZE
1214 .Dv ATTR_FILE_TOTALSIZE ).
1217 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1219 .It VOL_CAP_FMT_ZERO_RUNS
1220 For security reasons, parts of a file (runs) that have never been
1221 written to must appear to contain zeroes.
1222 When this bit is set, the volume keeps track of allocated but unwritten
1223 runs of a file so that it can substitute zeroes without actually
1224 writing zeroes to the media.
1225 This provides performance similar to sparse files, but not the space savings.
1227 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1229 .It VOL_CAP_FMT_CASE_SENSITIVE
1230 If this bit is set the volume format treats upper and lower case
1231 characters in file and directory names as different.
1232 Otherwise an upper case character is equivalent to a lower case character,
1233 and you can't have two names that differ solely in the case of
1236 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1238 .It VOL_CAP_FMT_CASE_PRESERVING
1239 If this bit is set the volume format preserves the case of
1240 file and directory names.
1241 Otherwise the volume may change the case of some characters
1242 (typically making them all upper or all lower case).
1244 .Dv VOL_CAP_FMT_CASE_SENSITIVE
1246 .Dv VOL_CAP_FMT_CASE_PRESERVING .
1248 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1250 .It VOL_CAP_FMT_FAST_STATFS
1251 This bit is used as a hint to upper layers (specifically the Carbon File Manager) to
1254 is fast enough that its results need not be cached by the caller.
1255 A volume format implementation that caches the
1257 information in memory should set this bit.
1258 An implementation that must always read from disk or always perform a network
1259 transaction to satisfy
1261 should not set this bit.
1263 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1265 .It VOL_CAP_FMT_2TB_FILESIZE
1266 If this bit is set the volume format supports file sizes larger
1267 than 4GB, and potentially up to 2TB; it does not indicate
1268 whether the file system supports files larger than that.
1270 Introduced with Darwin 8.0 (Mac OS X version 10.4).
1272 .It VOL_CAP_FMT_OPENDENYMODES
1273 If this bit is set, the volume format supports open deny modes
1274 (e.g., "open for read write, deny write").
1276 .It VOL_CAP_FMT_HIDDEN_FILES
1277 If this bit is set, the volume format supports the
1281 flag is mapped to that volume's native "hidden" or "invisible"
1282 bit (e.g., the invisible bit from the Finder Info extended attribute).
1284 .It VOL_CAP_FMT_PATH_FROM_ID
1285 If this bit is set, the volume format supports the ability to derive a pathname
1286 to the root of the file system given only the ID of an object. This also
1287 implies that object IDs on this file system are persistent and not recycled.
1288 Most file systems will not support this capability.
1290 .It VOL_CAP_FMT_NO_VOLUME_SIZES
1291 If this bit is set the volume format does not support
1292 determining values for total data blocks, available blocks, or free blocks, as in
1301 Historically, those values were set to 0xFFFFFFFF for volumes
1302 that did not support them.
1304 Introduced with Darwin 10.0 (Mac OS X version 10.6).
1306 .It VOL_CAP_FMT_64BIT_OBJECT_IDS
1307 If this bit is set, the volume format uses object IDs that are 64-bit.
1308 This means that ATTR_CMN_FILEID and ATTR_CMN_PARENTID are the only
1309 legitimate attributes for obtaining object IDs from this volume and the
1310 32-bit fid_objno fields of the fsobj_id_t returned by ATTR_CMN_OBJID,
1311 ATTR_CMN_OBJPERMANENTID, and ATTR_CMN_PAROBJID are undefined.
1316 The following bits are defined in the second element (indexed by
1317 .Dv VOL_CAPABILITIES_INTERFACES )
1323 .Vt vol_capabilities_attr_t
1326 .Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1328 .It VOL_CAP_INT_SEARCHFS
1329 If this bit is set the volume format implementation supports
1332 .It VOL_CAP_INT_ATTRLIST
1333 If this bit is set the volume format implementation supports
1338 .It VOL_CAP_INT_NFSEXPORT
1339 If this bit is set the volume format implementation allows this volume to be exported via NFS.
1341 .It VOL_CAP_INT_READDIRATTR
1342 If this bit is set the volume format implementation supports
1343 .Xr getdirentriesattr 2 .
1345 .It VOL_CAP_INT_EXCHANGEDATA
1346 If this bit is set the volume format implementation supports
1347 .Xr exchangedata 2 .
1349 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1351 .It VOL_CAP_INT_COPYFILE
1352 If this bit is set the volume format implementation supports the (private and undocumented)
1353 copyfile() function.
1358 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1360 .It VOL_CAP_INT_ALLOCATE
1361 If this bit is set the volume format implementation supports the
1366 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1368 .It VOL_CAP_INT_VOL_RENAME
1369 If this bit is set the volume format implementation allows you to
1370 modify the volume name using
1373 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1375 .It VOL_CAP_INT_ADVLOCK
1376 If this bit is set the volume format implementation supports
1377 advisory locking, that is, the
1385 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1387 .It VOL_CAP_INT_FLOCK
1388 If this bit is set the volume format implementation supports
1399 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1401 .It VOL_CAP_INT_EXTENDED_SECURITY
1402 If this bit is set the volume format implementation supports
1403 extended security controls (ACLs).
1405 Introduced with Darwin 8.0 (Mac OS X version 10.4).
1407 .It VOL_CAP_INT_USERACCESS
1408 If this bit is set the volume format implementation supports the
1409 ATTR_CMN_USERACCESS attribute.
1411 Introduced with Darwin 8.0 (Mac OS X version 10.4).
1413 .It VOL_CAP_INT_MANLOCK
1414 If this bit is set, the volume format implementation supports
1415 AFP-style mandatory byte range locks via
1418 .It VOL_CAP_INT_EXTENDED_ATTR
1419 If this bit is set, the volume format implementation supports
1420 native extended attributes (see
1423 .It VOL_CAP_INT_NAMEDSTREAMS
1424 If this bit is set, the volume format implementation supports
1425 native named streams.
1430 .\" vol_attributes_attr_t
1432 A volume can also report which attributes it supports.
1433 This information is returned by the
1434 .Dv ATTR_VOL_ATTRIBUTES
1435 attribute, which returns a
1436 .Vt vol_attributes_attr_t
1437 structure (shown below).
1440 typedef struct attribute_set {
1441 attrgroup_t commonattr; /* common attribute group */
1442 attrgroup_t volattr; /* volume attribute group */
1443 attrgroup_t dirattr; /* directory attribute group */
1444 attrgroup_t fileattr; /* file attribute group */
1445 attrgroup_t forkattr; /* fork attribute group */
1449 typedef struct vol_attributes_attr {
1450 attribute_set_t validattr;
1451 attribute_set_t nativeattr;
1452 } vol_attributes_attr_t;
1458 field consists of a number of bit sets that indicate whether an attribute is
1459 supported by the volume format implementation.
1462 is similar except that the bit sets indicate whether an attribute is supported
1463 natively by the volume format.
1464 An attribute is supported natively if the volume format implementation does not have to do
1465 any complex conversions to access the attribute.
1466 For example, a volume format might support persistent object identifiers, but
1467 doing so requires a complex table lookup that is not part of the core volume
1470 .Dv ATTR_VOL_ATTRIBUTES
1471 attribute would return
1472 .Dv ATTR_CMN_OBJPERMANENTID
1476 .Vt vol_attributes_attr_t ,
1482 Upon successful completion a value of 0 is returned.
1483 Otherwise, a value of -1 is returned and
1485 is set to indicate the error.
1488 Not all volumes support
1490 The best way to test whether a volume supports this function is to
1491 simply call it and check the error result.
1495 if it is not supported on a particular volume.
1500 function has been undocumented for more than two years.
1501 In that time a number of volume format implementations have been created without
1502 a proper specification for the behaviour of this routine.
1503 You may encounter volume format implementations with slightly different
1504 behaviour than what is described here.
1505 Your program is expected to be tolerant of this variant behaviour.
1508 If you're implementing a volume format that supports
1510 you should be careful to support the behaviour specified by this document.
1520 The volume does not support the query.
1523 A component of the path prefix for
1527 .It Bq Er ENAMETOOLONG
1528 A component of a path name for
1532 characters, or an entire path name exceeded
1537 The file system object for
1542 The file descriptor argument for
1544 is not a valid file descriptor.
1547 Search permission is denied for a component of the path prefix for
1551 Too many symbolic links were encountered in translating the pathname
1560 points to an invalid address.
1568 .Dv ATTR_BIT_MAP_COUNT .
1571 You requested an invalid attribute.
1574 You requested an attribute that is not supported for this file system object.
1577 You requested volume attributes and directory or file attributes.
1580 You requested volume attributes but
1582 does not reference the root of the volume.
1585 The volume is read-only but must be modified in order to return this attribute.
1588 An I/O error occurred while reading from or writing to the file system.
1594 If you request any volume attributes, you must set
1598 field, even though it generates no result in the attribute buffer.
1601 The order that attributes are stored in the attribute buffer almost
1602 invariably matches the order of attribute mask bit values.
1605 (0x00000001) comes before
1607 (0x00000002) because its value is smaller.
1608 However, you can not rely on this ordering because there is one key exception:
1611 .Dv ATTR_CMN_NAMEDATTRCOUNT
1613 .Dv ATTR_CMN_NAMEDATTRLIST
1614 pair, even though its bit position indicates that it should come before.
1615 This is due to a bug in an early version of Mac OS X that can't be fixed for
1616 binary compatibility reasons.
1617 When ordering attributes, you should always use the order in which they
1618 are described above.
1623 structure is 64-bits (two 32-bit elements) in 32-bit code, and
1624 128-bits (two 64-bit elements) in 64-bit code; however, it is aligned
1625 on a 4-byte (32-bit) boundary, even in 64-bit code.
1627 If you use a structure
1628 for the attribute data, it must be correctly packed and aligned (see
1632 Inconsistent behavior may be observed when the ATTR_CMN_FULLPATH attribute is requested on
1633 hard-linked items, particularly when the file system does not support ATTR_CMN_PARENTID
1634 natively. Callers should be aware of this when requesting the full path of a hard-linked item, especially
1635 if the full path crosses mount points.
1638 For more caveats, see also the compatibility notes above.
1642 The following code prints the file type and creator of a file,
1643 assuming that the volume supports the required attributes.
1649 #include <sys/attr.h>
1650 #include <sys/errno.h>
1652 #include <sys/vnode.h>
1655 typedef struct attrlist attrlist_t;
1658 struct FInfoAttrBuf {
1660 fsobj_type_t objType;
1661 char finderInfo[32];
1662 } __attribute__((aligned(4), packed));
1663 typedef struct FInfoAttrBuf FInfoAttrBuf;
1666 static int FInfoDemo(const char *path)
1669 attrlist_t attrList;
1670 FInfoAttrBuf attrBuf;
1673 memset(&attrList, 0, sizeof(attrList));
1674 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
1675 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
1678 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
1685 assert(attrBuf.length == sizeof(attrBuf));
1688 printf("Finder information for %s:\en", path);
1689 switch (attrBuf.objType) {
1691 printf("file type = '%.4s'\en", &attrBuf.finderInfo[0]);
1692 printf("file creator = '%.4s'\en", &attrBuf.finderInfo[4]);
1695 printf("directory\en");
1698 printf("other object type, %d\en", attrBuf.objType);
1709 The following code is an alternative implementation that uses nested structures
1710 to group the related attributes.
1717 #include <sys/attr.h>
1718 #include <sys/errno.h>
1720 #include <sys/vnode.h>
1723 typedef struct attrlist attrlist_t;
1726 struct FInfo2CommonAttrBuf {
1727 fsobj_type_t objType;
1728 char finderInfo[32];
1729 } __attribute__((aligned(4), packed));
1730 typedef struct FInfo2CommonAttrBuf FInfo2CommonAttrBuf;
1733 struct FInfo2AttrBuf {
1735 FInfo2CommonAttrBuf common;
1736 } __attribute__((aligned(4), packed));;
1737 typedef struct FInfo2AttrBuf FInfo2AttrBuf;
1740 static int FInfo2Demo(const char *path)
1743 attrlist_t attrList;
1744 FInfo2AttrBuf attrBuf;
1747 memset(&attrList, 0, sizeof(attrList));
1748 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
1749 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
1752 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
1759 assert(attrBuf.length == sizeof(attrBuf));
1762 printf("Finder information for %s:\en", path);
1763 switch (attrBuf.common.objType) {
1766 "file type = '%.4s'\en",
1767 &attrBuf.common.finderInfo[0]
1770 "file creator = '%.4s'\en",
1771 &attrBuf.common.finderInfo[4]
1775 printf("directory\en");
1779 "other object type, %d\en",
1780 attrBuf.common.objType
1792 The following example shows how to deal with variable length attributes.
1793 It assumes that the volume specified by
1795 supports the necessary attributes.
1802 #include <sys/attr.h>
1803 #include <sys/errno.h>
1805 #include <sys/vnode.h>
1808 typedef struct attrlist attrlist_t;
1813 u_int32_t fileCount;
1815 attrreference_t mountPointRef;
1816 attrreference_t volNameRef;
1817 char mountPointSpace[MAXPATHLEN];
1818 char volNameSpace[MAXPATHLEN];
1819 } __attribute__((aligned(4), packed));
1820 typedef struct VolAttrBuf VolAttrBuf;
1823 static int VolDemo(const char *path)
1826 attrlist_t attrList;
1830 memset(&attrList, 0, sizeof(attrList));
1831 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
1832 attrList.volattr = ATTR_VOL_INFO
1833 | ATTR_VOL_FILECOUNT
1835 | ATTR_VOL_MOUNTPOINT
1839 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
1846 assert(attrBuf.length > offsetof(VolAttrBuf, mountPointSpace));
1847 assert(attrBuf.length <= sizeof(attrBuf));
1850 printf("Volume information for %s:\en", path);
1851 printf("ATTR_VOL_FILECOUNT: %u\en", attrBuf.fileCount);
1852 printf("ATTR_VOL_DIRCOUNT: %u\en", attrBuf.dirCount);
1854 "ATTR_VOL_MOUNTPOINT: %.*s\en",
1855 (int) attrBuf.mountPointRef.attr_length,
1856 ( ((char *) &attrBuf.mountPointRef)
1857 + attrBuf.mountPointRef.attr_dataoffset )
1860 "ATTR_VOL_NAME: %.*s\en",
1861 (int) attrBuf.volNameRef.attr_length,
1862 ( ((char *) &attrBuf.volNameRef)
1863 + attrBuf.volNameRef.attr_dataoffset )
1872 The following sample demonstrates the need to use packing and alignment
1873 controls; without the attribute, in 64-bit code, the fields of the structure are not
1874 placed at the locations that the kernel expects.
1883 #include <sys/attr.h>
1885 /* The alignment and packing attribute is necessary in 64-bit code */
1886 struct AttrListTimes {
1888 struct timespec st_crtime;
1889 struct timespec st_modtime;
1890 } __attribute__((aligned(4), packed));
1892 main(int argc, char **argv)
1897 for (i = 1; i < argc; i++) {
1898 struct attrlist attrList;
1899 struct AttrListTimes myStat = {0};
1900 char *path = argv[i];
1902 memset(&attrList, 0, sizeof(attrList));
1903 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
1904 attrList.commonattr = ATTR_CMN_CRTIME |
1907 rv = getattrlist(path, &attrList, &myStat, sizeof(myStat), 0);
1910 warn("getattrlist(%s)", path);
1913 printf("%s: Modification time = %s", argv[i], ctime(&myStat.st_modtime.tv_sec));
1924 .Xr exchangedata 2 ,
1926 .Xr getdirentriesattr 2 ,
1936 function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).