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