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.
24 .Nd get file system attributes
26 .Fd #include <sys/attr.h>
27 .Fd #include <unistd.h>
29 .Fn getattrlist "const char* path" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned long options"
34 function returns attributes (that is, metadata) of file system objects.
37 as a seriously enhanced version of
39 The function returns attributes about the file system object specified by
41 in the buffer specified by
47 parameter determines what attributes are returned.
50 parameter lets you control specific aspects of the function's behavior.
55 function is only supported by certain volume format implementations.
56 For maximum compatibility, client programs should use high-level APIs
57 (such as the Carbon File Manager) to access file system attributes.
58 These high-level APIs include logic to emulate file system attributes
59 on volumes that don't support
63 Not all volumes support all attributes.
65 .Dv ATTR_VOL_ATTRIBUTES
66 for a discussion of how to determine whether a particular volume supports a
69 Furthermore, you should only request the attributes that you need.
70 Some attributes are expensive to calculate on some volume formats.
72 .Dv ATTR_DIR_ENTRYCOUNT
73 is usually expensive to calculate on non-HFS [Plus] volumes.
74 If you don't need a particular attribute, you should not ask for it.
81 parameter must reference a valid file system object.
82 Read, write or execute permission of the object itself is not required, but
83 all directories listed in the path name leading to the object must be
87 .\" attrList parameter
91 parameter is a pointer to an
93 structure, as defined by
96 It determines what attributes are returned by the function.
97 You are responsible for filling out all fields of this structure before calling the function.
99 typedef u_int32_t attrgroup_t;
102 u_short bitmapcount; /* number of attr. bit sets in list */
103 u_int16_t reserved; /* (to maintain 4-byte alignment) */
104 attrgroup_t commonattr; /* common attribute group */
105 attrgroup_t volattr; /* volume attribute group */
106 attrgroup_t dirattr; /* directory attribute group */
107 attrgroup_t fileattr; /* file attribute group */
108 attrgroup_t forkattr; /* fork attribute group */
110 #define ATTR_BIT_MAP_COUNT 5
114 .\" attrlist elements
118 structure are defined as follows.
119 .Bl -tag -width XXXbitmapcount
122 Number of attribute bit sets in the structure.
123 In current systems you must set this to
124 .Dv ATTR_BIT_MAP_COUNT .
128 You must set this to 0.
131 A bit set that specifies the common attributes that you require.
132 Common attributes relate to all types of file system objects.
133 See below for a description of these attributes.
136 A bit set that specifies the volume attributes that you require.
137 Volume attributes relate to volumes (that is, mounted file systems).
138 See below for a description of these attributes.
139 If you request volume attributes,
141 must reference the root of a volume.
142 In addition, you can't request volume attributes if you also request
143 file or directory attributes.
146 A bit set that specifies the directory attributes that you require.
147 See below for a description of these attributes.
150 A bit set that specifies the file attributes that you require.
151 See below for a description of these attributes.
154 A bit set that specifies the fork attributes that you require.
155 Fork attributes relate to the actual data in the file,
156 which can be held in multiple named contiguous ranges, or forks.
157 See below for a description of these attributes.
162 Unless otherwise noted in the lists below, attributes are read-only.
163 Attributes labelled as read/write can be set using
167 .\" attrBuf and attrBufSize parameters
173 parameters specify a buffer into which the function places attribute values.
174 The format of this buffer is sufficiently complex that its description
175 requires a separate section (see below).
176 The initial contents of this buffer are ignored.
183 parameter is a bit set that controls the behaviour of
185 The following option bits are defined.
187 .Bl -tag -width XXXbitmapcount
192 will not follow a symlink if it occurs as
193 the last component of
200 The data returned in the buffer described by
204 is formatted as follows.
210 The first element of the buffer is a
212 that contains the overall length, in bytes, of the attributes returned.
213 This size includes the length field itself.
216 Following the length field is a list of attributes.
217 Each attribute is represented by a field of its type,
218 where the type is given as part of the attribute description (below).
221 The attributes are placed into the attribute buffer in the order
222 that they are described below.
227 If the attribute is of variable length, it is represented
230 structure, as defined by
235 typedef struct attrreference {
236 long attr_dataoffset;
242 This structure contains a 'pointer' to the variable length attribute data.
245 field is the length of the attribute data (in bytes).
248 field is the offset in bytes from the
251 to the attribute data.
252 This offset will always be a multiple of sizeof(unsigned long) bytes,
253 so you can safely access common data types without fear of alignment
259 function will silently truncate attribute data if
262 The length field at the front of the attribute list always represents
263 the length of the data actually copied into the attribute buffer.
264 If the data is truncated, there is no easy way to determine the
265 buffer size that's required to get all of the requested attributes.
266 You should always pass an
268 that is large enough to accommodate the known size of the attributes
269 in the attribute list (including the leading length field).
272 Because the returned attributes are simply truncated if the buffer is
273 too small, it's possible for a variable length attribute to reference
274 data beyond the end of the attribute buffer. That is, it's possible
275 for the attribute data to start beyond the end of the attribute buffer
279 .Vt attrreference_t ,
288 ) ) or, indeed, for the attribute data to extend beyond the end of the attribute buffer (that is,
300 If this happens you must increase the size of the buffer and call
302 to get an accurate copy of the attribute.
304 .Sh COMMON ATTRIBUTES
306 Common attributes relate to all types of file system objects.
307 The following common attributes are defined.
309 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
314 structure containing the name of the file system object as
315 UTF-8 encoded, null terminated C string.
316 The attribute data length will not be greater than
324 containing the device number of the device on which this
325 file system object's volume is mounted.
330 structure returned by
336 structure containing the file system identifier for the volume on which
337 the file system object resides.
342 structure returned by
346 This value is not related to the file system ID from traditional Mac OS (for example,
351 structure returned by Carbon's FSGetVolumeInfo() function).
352 On current versions of Mac OS X that value is synthesised by the Carbon File Manager.
357 that identifies the type of file system object.
358 The values are taken from
366 that identifies the type of file system containing the object.
367 The values are taken from
375 structure that uniquely identifies the file system object
377 The fid_generation field of this structure will be zero for all non-root callers
378 (effective UID not 0).
379 This identifier need not be persistent across an unmount/mount sequence.
382 Some volume formats use well known values for the
384 field for the root directory (2) and the parent of root directory (1).
385 This is not a required behaviour of this attribute.
387 .It ATTR_CMN_OBJPERMANENTID
390 structure that uniquely identifies the file system object
392 The fid_generation field of this structure will be zero for all non-root callers
393 (effective UID not 0).
394 This identifier should be persistent across an unmount/mount sequence.
396 Some file systems (for example, original HFS) may need to modify the on-disk
397 structure to return a persistent identifier.
398 If such a file system is mounted read-only, an attempt to get this attribute
399 will fail with the error
402 .It ATTR_CMN_PAROBJID
405 structure that identifies the parent directory of the file system object.
406 The fid_generation field of this structure will be zero for all non-root callers
407 (effective UID not 0).
408 Equivalent to the ATTR_CMN_OBJID attribute of the parent directory.
409 This identifier need not be persistent across an unmount/mount sequence.
412 On a volume that supports hard links, a multiply linked file has no unique parent.
413 This attribute will return an unspecified parent.
416 For some volume formats this attribute is very expensive to calculate.
421 containing a text encoding hint for
422 the file system object's name.
423 It is included to facilitate the lossless round trip conversion of names between
424 Unicode and traditional Mac OS script encodings.
425 The values are defined in
426 .Aq Pa CarbonCore/TextCommon.h .
427 File systems that do not have an appropriate text encoding value should return
428 kTextEncodingMacUnicode.
429 See DTS Q&A 1173 "File Manager Text Encoding Hints".
434 structure containing the time that the file system object
440 structure containing the time that the file system object
446 structure returned by
452 structure containing the time that the file system object's
453 attributes were last modified.
458 structure returned by
464 structure containing the time that the file system object
470 structure returned by
473 .It ATTR_CMN_BKUPTIME
476 structure containing the time that the file system object was
478 This value is for use by backup utilities.
479 The file system stores but does not interpret the value.
481 .It ATTR_CMN_FNDRINFO
482 (read/write) 32 bytes of data for use by the Finder.
483 Equivalent to the concatenation of a
488 (or, for directories, a
491 .Vt ExtendedFolderInfo
493 These structures are defined in
494 .Aq Pa CarbonCore/Finder.h .
496 This attribute is not byte swapped by the file system.
497 The value of multibyte fields on disk is always big endian.
498 When running on a little endian system (such as Darwin on x86),
499 you must byte swap any multibyte fields.
504 containing the owner of the file system object.
509 structure returned by
515 containing the group of the file system object.
520 structure returned by
523 .It ATTR_CMN_ACCESSMASK
526 containing the access permissions of the file system object.
531 structure returned by
534 .It ATTR_CMN_NAMEDATTRCOUNT
537 containing the number of named attributes of the file system object.
539 .It ATTR_CMN_NAMEDATTRLIST
542 structure containing a list of named attributes of the file system object.
543 No built-in file systems on Mac OS X currently support named attributes.
544 Because of this, the structure of this attribute's value is not yet defined.
549 containing file flags.
554 structure returned by
556 For more information about these flags, see
560 The order that attributes are placed into the attribute buffer
561 almost invariably matches the order of the attribute mask bit values.
564 If its order was based on its bit position, it would be before
566 .Dv ATTR_CMN_NAMEDATTRCOUNT
568 .Dv ATTR_CMN_NAMEDATTRLIST
570 it is placed in the buffer after them.
572 .It ATTR_CMN_USERACCESS
575 containing the effective permissions of the current user
576 (the calling process's effective UID) for this file system object.
577 You can test for read, write, and execute permission using
590 that uniquely identifies the file system object within its volume.
592 .It ATTR_CMN_PARENTID
595 that identifies the parent directory of the file system object.
599 .Sh VOLUME ATTRIBUTES
601 Volume attributes relate to volumes (that is, mounted file systems).
602 The following volume attributes are defined.
604 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
607 For reasons that are not at all obvious, you must set
611 field if you request any other volume attributes.
612 This does not result in any attribute data being added to the attribute buffer.
617 containing the file system type.
622 structure returned by
624 Generally not a useful value.
626 .It ATTR_VOL_SIGNATURE
629 containing the volume signature word.
630 This value is unique within a given file system type and lets you
631 distinguish between different volume formats handled by the same file system.
633 .Aq Pa CarbonCore/Files.h
639 containing the total size of the volume in bytes.
641 .It ATTR_VOL_SPACEFREE
644 containing the free space on the volume in bytes.
646 .It ATTR_VOL_SPACEAVAIL
649 containing the space, in bytes, on the volume available to non-privileged processes.
650 This is the free space minus the amount of space reserved by the system to prevent critical
651 disk exhaustion errors.
652 Non-privileged programs, like a disk management tool, should use this value to display the
653 space available to the user.
655 .Dv ATTR_VOL_SPACEAVAIL
657 .Dv ATTR_VOL_SPACEFREE
665 .It ATTR_VOL_MINALLOCATION
668 containing the minimum allocation size on the volume in bytes.
669 If you create a file containing one byte, it will consume this much space.
671 .It ATTR_VOL_ALLOCATIONCLUMP
674 containing the allocation clump size on the volume, in bytes.
675 As a file is extended, the file system will attempt to allocate
676 this much space each time in order to reduce fragmentation.
678 .It ATTR_VOL_IOBLOCKSIZE
681 containing the optimal block size when reading or writing data.
686 structure returned by
689 .It ATTR_VOL_OBJCOUNT
692 containing the number of file system objects on the volume.
694 .It ATTR_VOL_FILECOUNT
697 containing the number of files on the volume.
699 .It ATTR_VOL_DIRCOUNT
702 containing the number of directories on the volume.
704 .It ATTR_VOL_MAXOBJCOUNT
707 containing the maximum number of file system objects that can be stored on the volume.
709 .It ATTR_VOL_MOUNTPOINT
712 structure containing the path to the volume's mount point as a
713 UTF-8 encoded, null terminated C string.
714 The attribute data length will not be greater than
720 structure returned by
726 structure containing the name of the volume as a
727 UTF-8 encoded, null terminated C string.
728 The attribute data length will not be greater than
733 This attribute is only read/write if the
734 .Dv VOL_CAP_INT_VOL_RENAME
735 bit is set in the volume capabilities (see below).
738 .It ATTR_VOL_MOUNTFLAGS
741 containing the volume mount flags.
742 This is a copy of the value passed to the
746 when the volume was mounted.
751 structure returned by
754 .It ATTR_VOL_MOUNTEDDEVICE
757 structure that returns the same value as the
761 structure returned by
763 For local volumes this is the path to the device on which the volume is mounted as a
764 UTF-8 encoded, null terminated C string.
765 For network volumes, this is a unique string that identifies the mount.
766 The attribute data length will not be greater than
770 .It ATTR_VOL_ENCODINGSUSED
772 .Vt unsigned long long
773 containing a bitmap of the text encodings used on this volume.
774 For more information about this, see the discussion of
776 in DTS Technote 1150 "HFS Plus Volume Format".
778 .It ATTR_VOL_CAPABILITIES
780 .Vt vol_capabilities_attr_t
781 structure describing the optional features supported by this volume.
782 See below for a discussion of volume capabilities.
784 .It ATTR_VOL_ATTRIBUTES
786 .Vt vol_attributes_attr_t
787 structure describing the attributes supported by this volume.
788 This structure is discussed below, along with volume capabilities.
792 .Sh DIRECTORY ATTRIBUTES
794 The following directory attributes are defined.
796 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
798 .It ATTR_DIR_LINKCOUNT
801 containing the number of hard links to the directory;
802 this does not include the historical "." and ".." entries.
803 For filesystems that do not support hard links to directories,
804 this value will be 1.
806 .It ATTR_DIR_ENTRYCOUNT
809 containing the number of file system objects in the directory, not including
812 .It ATTR_DIR_MOUNTSTATUS
815 containing flags describing what's mounted on the directory.
816 Currently the only flag defined is
817 .Dv DIR_MNTSTATUS_MNTPOINT,
818 which indicates that there is a file system mounted on this directory.
819 Due to a bug (r. 3502822), this flag is never set on current system.
825 The following file attributes are defined.
827 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
829 .It ATTR_FILE_LINKCOUNT
832 containing the number of hard links to this file.
837 structure returned by
840 .It ATTR_FILE_TOTALSIZE
843 containing the total number of bytes in all forks of the file (the logical size).
845 .It ATTR_FILE_ALLOCSIZE
848 containing a count of the bytes on disk used by all of the file's forks (the physical size).
850 .It ATTR_FILE_IOBLOCKSIZE
853 containing the optimal block size when reading or writing this file's data.
855 .It ATTR_FILE_CLUMPSIZE
858 containing the allocation clump size for this file, in bytes.
859 As the file is extended, the file system will attempt to allocate
860 this much space each time in order to reduce fragmentation.
861 This value applies to the data fork.
863 .It ATTR_FILE_DEVTYPE
866 containing the device type for a special device file.
871 structure returned by
874 .It ATTR_FILE_FILETYPE
877 that whose value is reserved.
878 Clients should ignore its value.
879 New volume format implementations should not support this attribute.
881 .It ATTR_FILE_FORKCOUNT
884 containing the number of forks in the file.
885 No built-in file systems on Mac OS X currently support forks other
886 than the data and resource fork.
888 .It ATTR_FILE_FORKLIST
891 structure containing a list of named forks of the file.
892 No built-in file systems on Mac OS X currently support forks
893 other than the data and resource fork.
894 Because of this, the structure of this attribute's value is not yet defined.
896 .It ATTR_FILE_DATALENGTH
899 containing the length of the data fork in bytes (the logical size).
901 .It ATTR_FILE_DATAALLOCSIZE
904 containing a count of the bytes on disk used by the data fork (the physical size).
906 .It ATTR_FILE_DATAEXTENTS
909 array for the data fork.
910 The array contains eight
912 structures which represent the first
913 eight extents of the fork.
915 This attributes exists for compatibility reasons.
916 New clients should not use this attribute.
917 Rather, they should use the
923 In current implementations the value may not be entirely accurate for
924 a variety of reasons.
926 .It ATTR_FILE_RSRCLENGTH
929 containing the length of the resource fork in bytes (the logical size).
931 .It ATTR_FILE_RSRCALLOCSIZE
934 containing a count of the bytes on disk used by the resource fork (the physical size).
936 .It ATTR_FILE_RSRCEXTENTS
939 array for the resource fork.
940 The array contains eight
942 structures which represent the first
943 eight extents of the fork.
946 .Dv ATTR_FILE_DATAEXTENTS .
952 Fork attributes relate to the actual data in the file,
953 which can be held in multiple named contiguous ranges, or forks.
954 The following fork attributes are defined.
956 .Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
958 .It ATTR_FORK_TOTALSIZE
961 containing the length of the fork in bytes (the logical size).
963 .It ATTR_FORK_ALLOCSIZE
966 containing a count of the bytes on disk used by the fork (the physical size).
971 Fork attributes are not properly implemented by any current Mac OS X
972 volume format implementation.
973 We strongly recommend that client programs do not request fork attributes.
974 If you are implementing a volume format, you should not support these attributes.
976 .Sh VOLUME CAPABILITIES
978 .\" vol_capabilities_attr_t
980 Not all volumes support all features.
982 .Dv ATTR_VOL_CAPABILITIES
984 .Vt vol_capabilities_attr_t
985 structure (shown below) that indicates which features are supported by the volume.
988 typedef u_int32_t vol_capabilities_set_t[4];
991 #define VOL_CAPABILITIES_FORMAT 0
992 #define VOL_CAPABILITIES_INTERFACES 1
993 #define VOL_CAPABILITIES_RESERVED1 2
994 #define VOL_CAPABILITIES_RESERVED2 3
997 typedef struct vol_capabilities_attr {
998 vol_capabilities_set_t capabilities;
999 vol_capabilities_set_t valid;
1000 } vol_capabilities_attr_t;
1004 The structure contains two fields,
1008 Each consists of an array of four elements.
1009 The arrays are indexed by the following values.
1011 .Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1013 .It VOL_CAPABILITIES_FORMAT
1014 This element contains information about the volume format.
1016 .Dv VOL_CAP_FMT_PERSISTENTOBJECTIDS
1019 .It VOL_CAPABILITIES_INTERFACES
1020 This element contains information about which optional functions are
1021 supported by the volume format implementation.
1023 .Dv VOL_CAP_INT_SEARCHFS
1026 .It VOL_CAPABILITIES_RESERVED1
1028 A file system implementation should set this element to zero.
1029 A client program should ignore this element.
1031 .It VOL_CAPABILITIES_RESERVED2
1033 A file system implementation should set this element to zero.
1034 A client program should ignore this element.
1041 field contains bit sets that indicate which flags are known to the volume format
1043 Each bit indicates whether the contents of the corresponding bit in the
1050 field contains bit sets that indicate whether a particular feature is implemented
1051 by this volume format.
1054 The following bits are defined in the first element (indexed by
1055 .Dv VOL_CAPABILITIES_FORMAT )
1061 .Vt vol_capabilities_attr_t
1064 .Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1066 .It VOL_CAP_FMT_PERSISTENTOBJECTIDS
1067 If this bit is set the volume format supports persistent object identifiers
1068 and can look up file system objects by their IDs.
1070 .Dv ATTR_CMN_OBJPERMANENTID
1071 for details about how to obtain these identifiers.
1073 .It VOL_CAP_FMT_SYMBOLICLINKS
1074 If this bit is set the volume format supports symbolic links.
1076 .It VOL_CAP_FMT_HARDLINKS
1077 If this bit is set the volume format supports hard links.
1079 .It VOL_CAP_FMT_JOURNAL
1080 If this bit is set the volume format supports a journal used to
1081 speed recovery in case of unplanned restart (such as a power outage
1083 This does not necessarily mean the volume is actively using a journal.
1085 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1087 .It VOL_CAP_FMT_JOURNAL_ACTIVE
1088 If this bit is set the volume is currently using a journal for
1089 speedy recovery after an unplanned restart.
1090 This bit can be set only if
1091 .Dv VOL_CAP_FMT_JOURNAL
1094 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1096 .It VOL_CAP_FMT_NO_ROOT_TIMES
1097 If this bit is set the volume format does not store reliable times for
1098 the root directory, so you should not depend on them to detect changes,
1099 identify volumes across unmount/mount, and so on.
1101 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1103 .It VOL_CAP_FMT_SPARSE_FILES
1104 If this bit is set the volume format supports sparse files,
1105 that is, files which can have 'holes' that have never been written
1106 to, and thus do not consume space on disk.
1107 A sparse file may have an allocated size on disk that is less than its logical length (that is,
1108 .Dv ATTR_FILE_ALLOCSIZE
1110 .Dv ATTR_FILE_TOTALSIZE ).
1113 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1115 .It VOL_CAP_FMT_ZERO_RUNS
1116 For security reasons, parts of a file (runs) that have never been
1117 written to must appear to contain zeroes.
1118 When this bit is set, the volume keeps track of allocated but unwritten
1119 runs of a file so that it can substitute zeroes without actually
1120 writing zeroes to the media.
1121 This provides performance similar to sparse files, but not the space savings.
1123 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1125 .It VOL_CAP_FMT_CASE_SENSITIVE
1126 If this bit is set the volume format treats upper and lower case
1127 characters in file and directory names as different.
1128 Otherwise an upper case character is equivalent to a lower case character,
1129 and you can't have two names that differ solely in the case of
1132 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1134 .It VOL_CAP_FMT_CASE_PRESERVING
1135 If this bit is set the volume format preserves the case of
1136 file and directory names.
1137 Otherwise the volume may change the case of some characters
1138 (typically making them all upper or all lower case).
1140 .Dv VOL_CAP_FMT_CASE_SENSITIVE
1142 .Dv VOL_CAP_FMT_CASE_PRESERVING .
1144 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1146 .It VOL_CAP_FMT_FAST_STATFS
1147 This bit is used as a hint to upper layers (specifically the Carbon File Manager) to
1150 is fast enough that its results need not be cached by the caller.
1151 A volume format implementation that caches the
1153 information in memory should set this bit.
1154 An implementation that must always read from disk or always perform a network
1155 transaction to satisfy
1157 should not set this bit.
1159 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1161 .It VOL_CAP_FMT_2TB_FILESIZE
1162 If this bit is set the volume format supports file
1163 sizes upto 2TB. This bit does not necessarily mean that the file
1164 system does not support file size more than 2TB.
1165 This bit does not mean that the currently available space on the volume is 2TB.
1167 Introduced with Darwin 8.0 (Mac OS X version 10.4).
1172 The following bits are defined in the second element (indexed by
1173 .Dv VOL_CAPABILITIES_INTERFACES )
1179 .Vt vol_capabilities_attr_t
1182 .Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1184 .It VOL_CAP_INT_SEARCHFS
1185 If this bit is set the volume format implementation supports
1188 .It VOL_CAP_INT_ATTRLIST
1189 If this bit is set the volume format implementation supports
1194 .It VOL_CAP_INT_NFSEXPORT
1195 If this bit is set the volume format implementation allows this volume to be exported via NFS.
1197 .It VOL_CAP_INT_READDIRATTR
1198 If this bit is set the volume format implementation supports
1199 .Xr getdirentriesattr 2 .
1201 .It VOL_CAP_INT_EXCHANGEDATA
1202 If this bit is set the volume format implementation supports
1203 .Xr exchangedata 2 .
1205 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1207 .It VOL_CAP_INT_COPYFILE
1208 If this bit is set the volume format implementation supports the (private and undocumented)
1209 copyfile() function.
1211 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1213 .It VOL_CAP_INT_ALLOCATE
1214 If this bit is set the volume format implementation supports the
1219 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1221 .It VOL_CAP_INT_VOL_RENAME
1222 If this bit is set the volume format implementation allows you to
1223 modify the volume name using
1226 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1228 .It VOL_CAP_INT_ADVLOCK
1229 If this bit is set the volume format implementation supports
1230 advisory locking, that is, the
1238 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1240 .It VOL_CAP_INT_FLOCK
1241 If this bit is set the volume format implementation supports
1252 Introduced with Darwin 7.0 (Mac OS X version 10.3).
1254 .It VOL_CAP_INT_EXTENDED_SECURITY
1255 If this bit is set the volume format implementation supports
1256 extended security controls (ACLs).
1258 Introduced with Darwin 8.0 (Mac OS X version 10.4).
1260 .It VOL_CAP_INT_USERACCESS
1261 If this bit is set the volume format implementation supports the
1262 ATTR_CMN_USERACCESS attribute.
1264 Introduced with Darwin 8.0 (Mac OS X version 10.4).
1269 .\" vol_attributes_attr_t
1271 A volume can also report which attributes it supports.
1272 This information is returned by the
1273 .Dv ATTR_VOL_ATTRIBUTES
1274 attribute, which returns a
1275 .Vt vol_attributes_attr_t
1276 structure (shown below).
1279 typedef struct attribute_set {
1280 attrgroup_t commonattr; /* common attribute group */
1281 attrgroup_t volattr; /* volume attribute group */
1282 attrgroup_t dirattr; /* directory attribute group */
1283 attrgroup_t fileattr; /* file attribute group */
1284 attrgroup_t forkattr; /* fork attribute group */
1288 typedef struct vol_attributes_attr {
1289 attribute_set_t validattr;
1290 attribute_set_t nativeattr;
1291 } vol_attributes_attr_t;
1297 field consists of a number of bit sets that indicate whether an attribute is
1298 supported by the volume format implementation.
1301 is similar except that the bit sets indicate whether an attribute is supported
1302 natively by the volume format.
1303 An attribute is supported natively if the volume format implementation does not have to do
1304 any complex conversions to access the attribute.
1305 For example, a volume format might support persistent object identifiers, but
1306 doing so requires a complex table lookup that is not part of the core volume
1309 .Dv ATTR_VOL_ATTRIBUTES
1310 attribute would return
1311 .Dv ATTR_CMN_OBJPERMANENTID
1315 .Vt vol_attributes_attr_t ,
1321 Upon successful completion a value of 0 is returned.
1322 Otherwise, a value of -1 is returned and
1324 is set to indicate the error.
1327 Not all volumes support
1329 The best way to test whether a volume supports this function is to
1330 simply call it and check the error result.
1334 if it is not supported on a particular volume.
1339 function has been undocumented for more than two years.
1340 In that time a number of volume format implementations have been created without
1341 a proper specification for the behaviour of this routine.
1342 You may encounter volume format implementations with slightly different
1343 behaviour than what is described here.
1344 Your program is expected to be tolerant of this variant behaviour.
1347 If you're implementing a volume format that supports
1349 you should be careful to support the behaviour specified by this document.
1357 The volume does not support
1361 A component of the path prefix is not a directory.
1363 .It Bq Er ENAMETOOLONG
1364 A component of a path name exceeded
1366 characters, or an entire path name exceeded
1371 The file system object does not exist.
1374 Search permission is denied for a component of the path prefix.
1377 Too many symbolic links were encountered in translating the pathname.
1384 points to an invalid address.
1392 .Dv ATTR_BIT_MAP_COUNT .
1395 You requested an invalid attribute.
1398 You requested an attribute that is not supported for this file system object.
1401 You requested volume attributes and directory or file attributes.
1404 You requested volume attributes but
1406 does not reference the root of the volume.
1409 The volume is read-only but must be modified in order to return this attribute.
1412 An I/O error occurred while reading from or writing to the file system.
1418 If you request any volume attributes, you must set
1422 field, even though it generates no result in the attribute buffer.
1425 The order that attributes are stored in the attribute buffer almost
1426 invariably matches the order of attribute mask bit values.
1429 (0x00000001) comes before
1431 (0x00000002) because its value is smaller.
1432 However, you can not rely on this ordering because there is one key exception:
1435 .Dv ATTR_CMN_NAMEDATTRCOUNT
1437 .Dv ATTR_CMN_NAMEDATTRLIST
1438 pair, even though its bit position indicates that it should come before.
1439 This is due to a bug in an early version of Mac OS X that can't be fixed for
1440 binary compatibility reasons.
1441 When ordering attributes, you should always use the order in which they
1442 are described above.
1445 For more caveats, see also the compatibility notes above.
1449 The following code prints the file type and creator of a file,
1450 assuming that the volume supports the required attributes.
1456 #include <sys/attr.h>
1457 #include <sys/errno.h>
1459 #include <sys/vnode.h>
1462 typedef struct attrlist attrlist_t;
1465 struct FInfoAttrBuf {
1467 fsobj_type_t objType;
1468 char finderInfo[32];
1470 typedef struct FInfoAttrBuf FInfoAttrBuf;
1473 static int FInfoDemo(const char *path)
1476 attrlist_t attrList;
1477 FInfoAttrBuf attrBuf;
1480 memset(&attrList, 0, sizeof(attrList));
1481 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
1482 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
1485 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
1492 assert(attrBuf.length == sizeof(attrBuf));
1495 printf("Finder information for %s:\en", path);
1496 switch (attrBuf.objType) {
1498 printf("file type = '%.4s'\en", &attrBuf.finderInfo[0]);
1499 printf("file creator = '%.4s'\en", &attrBuf.finderInfo[4]);
1502 printf("directory\en");
1505 printf("other object type, %d\en", attrBuf.objType);
1516 The following code is an alternative implementation that uses nested structures
1517 to group the related attributes.
1524 #include <sys/attr.h>
1525 #include <sys/errno.h>
1527 #include <sys/vnode.h>
1530 typedef struct attrlist attrlist_t;
1533 struct FInfo2CommonAttrBuf {
1534 fsobj_type_t objType;
1535 char finderInfo[32];
1537 typedef struct FInfo2CommonAttrBuf FInfo2CommonAttrBuf;
1540 struct FInfo2AttrBuf {
1542 FInfo2CommonAttrBuf common;
1544 typedef struct FInfo2AttrBuf FInfo2AttrBuf;
1547 static int FInfo2Demo(const char *path)
1550 attrlist_t attrList;
1551 FInfo2AttrBuf attrBuf;
1554 memset(&attrList, 0, sizeof(attrList));
1555 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
1556 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
1559 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
1566 assert(attrBuf.length == sizeof(attrBuf));
1569 printf("Finder information for %s:\en", path);
1570 switch (attrBuf.common.objType) {
1573 "file type = '%.4s'\en",
1574 &attrBuf.common.finderInfo[0]
1577 "file creator = '%.4s'\en",
1578 &attrBuf.common.finderInfo[4]
1582 printf("directory\en");
1586 "other object type, %d\en",
1587 attrBuf.common.objType
1599 The following example shows how to deal with variable length attributes.
1600 It assumes that the volume specified by
1602 supports the necessary attributes.
1609 #include <sys/attr.h>
1610 #include <sys/errno.h>
1612 #include <sys/vnode.h>
1615 typedef struct attrlist attrlist_t;
1620 u_int32_t fileCount;
1622 attrreference_t mountPointRef;
1623 attrreference_t volNameRef;
1624 char mountPointSpace[MAXPATHLEN];
1625 char volNameSpace[MAXPATHLEN];
1627 typedef struct VolAttrBuf VolAttrBuf;
1630 static int VolDemo(const char *path)
1633 attrlist_t attrList;
1637 memset(&attrList, 0, sizeof(attrList));
1638 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
1639 attrList.volattr = ATTR_VOL_INFO
1640 | ATTR_VOL_FILECOUNT
1642 | ATTR_VOL_MOUNTPOINT
1646 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
1653 assert(attrBuf.length > offsetof(VolAttrBuf, mountPointSpace));
1654 assert(attrBuf.length <= sizeof(attrBuf));
1657 printf("Volume information for %s:\en", path);
1658 printf("ATTR_VOL_FILECOUNT: %lu\en", attrBuf.fileCount);
1659 printf("ATTR_VOL_DIRCOUNT: %lu\en", attrBuf.dirCount);
1661 "ATTR_VOL_MOUNTPOINT: %.*s\en",
1662 (int) attrBuf.mountPointRef.attr_length,
1663 ( ((char *) &attrBuf.mountPointRef)
1664 + attrBuf.mountPointRef.attr_dataoffset )
1667 "ATTR_VOL_NAME: %.*s\en",
1668 (int) attrBuf.volNameRef.attr_length,
1669 ( ((char *) &attrBuf.volNameRef)
1670 + attrBuf.volNameRef.attr_dataoffset )
1684 .Xr exchangedata 2 ,
1686 .Xr getdirentriesattr 2 ,
1696 function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).