]> git.saurik.com Git - apple/xnu.git/blame - bsd/man/man2/getattrlist.2
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / man / man2 / getattrlist.2
CommitLineData
91447636 1.\" Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
2d21ac55 2.\"
91447636
A
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.
2d21ac55 8.\"
91447636
A
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.
2d21ac55 16.\"
91447636
A
17.\" @(#)getattrlist.2
18.
f427ee49 19.Dd February 11, 2020
91447636
A
20.Dt GETATTRLIST 2
21.Os Darwin
22.Sh NAME
b0d623f7 23.Nm getattrlist ,
fe8ab488
A
24.Nm fgetattrlist ,
25.Nm getattrlistat
91447636
A
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.
b0d623f7
A
33.Ft int
34.Fn fgetattrlist "int fd" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned long options"
fe8ab488
A
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
91447636
A
40.Sh DESCRIPTION
41The
42.Fn getattrlist
43function returns attributes (that is, metadata) of file system objects.
b0d623f7
A
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 .
fe8ab488
A
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
2d21ac55 73You can think of
91447636
A
74.Fn getattrlist
75as a seriously enhanced version of
76.Xr stat 2 .
b0d623f7
A
77The functions return attributes about the specified file system object
78into the buffer specified by
91447636
A
79.Fa attrBuf
80and
81.Fa attrBufSize .
2d21ac55
A
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.
91447636 90Not all volumes support all attributes.
2d21ac55
A
91See the discussion of
92.Dv ATTR_VOL_ATTRIBUTES
93for a discussion of how to determine whether a particular volume supports a
91447636
A
94particular attribute.
95.Pp
2d21ac55
A
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
91447636
A
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.
2d21ac55
A
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
91447636
A
111searchable.
112.Pp
113.
114.\" attrList parameter
115.
116The
117.Fa attrList
2d21ac55
A
118parameter is a pointer to an
119.Vt attrlist
91447636
A
120structure, as defined by
121.Aq Pa sys/attr.h
122(shown below).
123It determines what attributes are returned by the function.
2d21ac55 124You are responsible for filling out all fields of this structure before calling the function.
91447636
A
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.
2d21ac55 143The fields of the
91447636
A
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.
2d21ac55 150In current systems you must set this to
91447636
A
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.
2d21ac55 159Common attributes relate to all types of file system objects.
91447636
A
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.
2d21ac55 166If you request volume attributes,
91447636
A
167.Fa path
168must reference the root of a volume.
f427ee49
A
169You must set ATTR_VOL_INFO in the volattr field if you request any
170other volume attributes.
2d21ac55 171In addition, you can't request volume attributes if you also request
f427ee49
A
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.
91447636
A
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.
2d21ac55 187Fork attributes relate to the actual data in the file,
91447636
A
188which can be held in multiple named contiguous ranges, or forks.
189See below for a description of these attributes.
813fb2f6
A
190If the FSOPT_ATTR_CMN_EXTENDED option is given, this bit set is reinterpreted
191as extended common attributes attributes, also described below.
91447636
A
192.
193.El
194.Pp
195.
2d21ac55
A
196Unless otherwise noted in the lists below, attributes are read-only.
197Attributes labelled as read/write can be set using
91447636
A
198.Xr setattrlist 2 .
199.Pp
200.
201.\" attrBuf and attrBufSize parameters
202.
203The
204.Fa attrBuf
2d21ac55 205and
91447636 206.Fa attrBufSize
2d21ac55
A
207parameters specify a buffer into which the function places attribute values.
208The format of this buffer is sufficiently complex that its description
91447636
A
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
b0d623f7 218the functions.
91447636
A
219The following option bits are defined.
220.
b0d623f7 221.Bl -tag -width FSOPT_PACK_INVAL_ATTRS
91447636
A
222.
223.It FSOPT_NOFOLLOW
2d21ac55
A
224If this bit is set,
225.Fn getattrlist
226will not follow a symlink if it occurs as
91447636
A
227the last component of
228.Fa path .
229.
b0d623f7
A
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.
fe8ab488
A
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
813fb2f6
A
250can be requested. When this option is used, forkattrs are reinterpreted as a
251set of extended common attributes.
fe8ab488 252.
cb323159
A
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.
91447636
A
259.El
260.
261.Sh ATTRIBUTE BUFFER
262.
2d21ac55
A
263The data returned in the buffer described by
264.Fa attrBuf
265and
266.Fa attrBufSize
91447636
A
267is formatted as follows.
268.Pp
269.
270.Bl -enum
271.
272.It
2d21ac55
A
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.
91447636
A
277.
278.It
2d21ac55
A
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).
91447636
A
282.
283.It
2d21ac55 284The attributes are placed into the attribute buffer in the order
91447636
A
285that they are described below.
286.
b0d623f7
A
287.It
288Each attribute is aligned to a 4-byte boundary (including 64-bit data types).
91447636
A
289.El
290.Pp
291.
2d21ac55
A
292If the attribute is of variable length, it is represented
293in the list by an
294.Vt attrreference
295structure, as defined by
91447636
A
296.Aq Pa sys/attr.h
297(shown below).
298.
299.Bd -literal
300typedef struct attrreference {
b0d623f7
A
301 int32_t attr_dataoffset;
302 u_int32_t attr_length;
91447636
A
303} attrreference_t;
304.Ed
305.Pp
306.
307This structure contains a 'pointer' to the variable length attribute data.
2d21ac55
A
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.
b0d623f7 317This offset will always be a multiple of sizeof(u_int32_t) bytes,
2d21ac55 318so you can safely access common data types without fear of alignment
91447636
A
319exceptions.
320.Pp
321.
2d21ac55
A
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
91447636
A
334in the attribute list (including the leading length field).
335.Pp
336.
2d21ac55
A
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
91447636 344.Vt attrreference_t ,
2d21ac55
A
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
91447636 364) ).
2d21ac55
A
365If this happens you must increase the size of the buffer and call
366.Fn getattrlist
91447636
A
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.
b0d623f7
A
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
fe8ab488
A
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.
b0d623f7 387.
91447636 388.It ATTR_CMN_NAME
2d21ac55
A
389An
390.Vt attrreference
391structure containing the name of the file system object as
91447636 392UTF-8 encoded, null terminated C string.
2d21ac55 393The attribute data length will not be greater than
6d2010ae
A
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).
91447636
A
399.Pp
400.
401.It ATTR_CMN_DEVID
2d21ac55
A
402A
403.Vt dev_t
404containing the device number of the device on which this
91447636 405file system object's volume is mounted.
2d21ac55
A
406Equivalent to the
407.Fa st_dev
408field of the
409.Vt stat
410structure returned by
91447636
A
411.Xr stat 2 .
412.
413.It ATTR_CMN_FSID
2d21ac55
A
414An
415.Vt fsid_t
416structure containing the file system identifier for the volume on which
91447636 417the file system object resides.
2d21ac55
A
418Equivalent to the
419.Fa f_fsid
420field of the
421.Vt statfs
422structure returned by
91447636
A
423.Xr statfs 2 .
424.
91447636 425.It ATTR_CMN_OBJTYPE
2d21ac55
A
426An
427.Vt fsobj_type_t
428that identifies the type of file system object.
429The values are taken from
430.Vt enum vtype
431in
91447636
A
432.Aq Pa sys/vnode.h .
433.
434.It ATTR_CMN_OBJTAG
2d21ac55
A
435An
436.Vt fsobj_tag_t
91447636 437that identifies the type of file system containing the object.
2d21ac55
A
438The values are taken from
439.Vt enum vtagtype
91447636
A
440in
441.Aq Pa sys/vnode.h .
442.
443.It ATTR_CMN_OBJID
2d21ac55
A
444An
445.Vt fsobj_id_t
fe8ab488 446structure that uniquely identifies the file system object within a mounted
cb323159 447volume for the duration of its mount; this identifier is not guaranteed to be
fe8ab488 448persistent for the volume and may change every time the volume is mounted.
91447636 449.Pp
fe8ab488
A
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
5ba3f43e
A
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.
91447636
A
462.
463.It ATTR_CMN_OBJPERMANENTID
2d21ac55
A
464An
465.Vt fsobj_id_t
fe8ab488
A
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.)
91447636
A
476.
477.It ATTR_CMN_PAROBJID
2d21ac55
A
478An
479.Vt fsobj_id_t
fe8ab488
A
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.
91447636
A
484.Pp
485.
fe8ab488
A
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.
91447636 489.
fe8ab488
A
490For some volume formats the computing cost for this attribute is significant;
491developers are advised to request this attribute sparingly.
91447636
A
492.
493.It ATTR_CMN_SCRIPT
2d21ac55
A
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
91447636 499Unicode and traditional Mac OS script encodings.
2d21ac55
A
500File systems that do not have an appropriate text encoding value should return
501kTextEncodingMacUnicode.
91447636
A
502.
503.It ATTR_CMN_CRTIME
2d21ac55
A
504(read/write) A
505.Vt timespec
506structure containing the time that the file system object
507was created.
91447636
A
508.
509.It ATTR_CMN_MODTIME
2d21ac55
A
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
91447636
A
519.Xr stat 2 .
520.
521.It ATTR_CMN_CHGTIME
39037602 522A
2d21ac55
A
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
91447636
A
531.Xr stat 2 .
532.
533.It ATTR_CMN_ACCTIME
2d21ac55
A
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
91447636
A
543.Xr stat 2 .
544.
545.It ATTR_CMN_BKUPTIME
2d21ac55
A
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.
91447636
A
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.
2d21ac55
A
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
91447636 564structure).
91447636
A
565.Pp
566This attribute is not byte swapped by the file system.
2d21ac55
A
567The value of multibyte fields on disk is always big endian.
568When running on a little endian system (such as Darwin on x86),
91447636
A
569you must byte swap any multibyte fields.
570.
571.It ATTR_CMN_OWNERID
2d21ac55
A
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
91447636
A
580.Xr stat 2 .
581.
582.It ATTR_CMN_GRPID
2d21ac55
A
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
91447636
A
591.Xr stat 2 .
592.
593.It ATTR_CMN_ACCESSMASK
2d21ac55
A
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
91447636 602.Xr stat 2 .
6d2010ae
A
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 .
91447636 608.
91447636 609.It ATTR_CMN_FLAGS
2d21ac55
A
610(read/write) A
611.Vt u_int32_t
91447636 612containing file flags.
2d21ac55
A
613Equivalent to the
614.Fa st_flags
615field of the
616.Vt stat
617structure returned by
91447636 618.Xr stat 2 .
2d21ac55 619For more information about these flags, see
91447636 620.Xr chflags 2 .
fe8ab488
A
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.
91447636
A
634.Pp
635.
fe8ab488
A
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.
91447636
A
653.
654.It ATTR_CMN_USERACCESS
2d21ac55
A
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
91447636
A
660.Dv R_OK ,
661.Dv W_OK ,
662and
2d21ac55
A
663.Dv X_OK ,
664respectively.
665See
666.Xr access 2
91447636
A
667for more details.
668.
b0d623f7
A
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.
2d21ac55
A
689.It ATTR_CMN_FILEID
690A
691.Vt u_int64_t
5ba3f43e 692that uniquely identifies the file system object within its mounted volume.
fe8ab488
A
693Equivalent to
694.Fa st_ino
695field of the
696.Vt stat
697structure returned by
698.Xr stat 2 .
2d21ac55
A
699.
700.It ATTR_CMN_PARENTID
701A
702.Vt u_int64_t
703that identifies the parent directory of the file system object.
704.
b0d623f7
A
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.
6d2010ae
A
716.
717.It ATTR_CMN_ADDEDTIME
718A
719.Vt timespec
720that contains the time that the file system object was created or renamed into
316670eb 721its containing directory. Note that inconsistent behavior may be observed
6d2010ae 722when this attribute is requested on hard-linked items.
fe8ab488
A
723.
724.It ATTR_CMN_DATA_PROTECT_FLAGS
725A
726.Vt u_int32_t
727that contains the file or directory's data protection class.
b0d623f7
A
728.Pp
729.
91447636
A
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
f427ee49 740For historical reasons you must set
2d21ac55
A
741.Dv ATTR_VOL_INFO
742in the
91447636
A
743.Fa volattr
744field if you request any other volume attributes.
91447636
A
745.
746.It ATTR_VOL_FSTYPE
2d21ac55
A
747A
748.Vt u_int32_t
91447636 749containing the file system type.
2d21ac55
A
750Equivalent to the
751.Fa f_type
752field of the
753.Vt statfs
754structure returned by
91447636
A
755.Xr statfs 2 .
756Generally not a useful value.
757.
758.It ATTR_VOL_SIGNATURE
2d21ac55
A
759A
760.Vt u_int32_t
761containing the volume signature word.
762This value is unique within a given file system type and lets you
91447636 763distinguish between different volume formats handled by the same file system.
91447636
A
764.
765.It ATTR_VOL_SIZE
2d21ac55 766An
91447636
A
767.Vt off_t
768containing the total size of the volume in bytes.
769.
770.It ATTR_VOL_SPACEFREE
2d21ac55 771An
91447636
A
772.Vt off_t
773containing the free space on the volume in bytes.
774.
775.It ATTR_VOL_SPACEAVAIL
2d21ac55 776An
91447636 777.Vt off_t
2d21ac55
A
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
91447636
A
782space available to the user.
783.Pp
2d21ac55
A
784.Dv ATTR_VOL_SPACEAVAIL
785is to
786.Dv ATTR_VOL_SPACEFREE
787as
788.Fa f_bavail
789is to
790.Fa f_bfree
791in
91447636
A
792.Xr statfs 2 .
793.
794.It ATTR_VOL_MINALLOCATION
2d21ac55 795An
91447636 796.Vt off_t
2d21ac55 797containing the minimum allocation size on the volume in bytes.
91447636
A
798If you create a file containing one byte, it will consume this much space.
799.
800.It ATTR_VOL_ALLOCATIONCLUMP
2d21ac55 801An
91447636 802.Vt off_t
2d21ac55
A
803containing the allocation clump size on the volume, in bytes.
804As a file is extended, the file system will attempt to allocate
91447636
A
805this much space each time in order to reduce fragmentation.
806.
807.It ATTR_VOL_IOBLOCKSIZE
2d21ac55
A
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
91447636
A
816.Xr statfs 2 .
817.
818.It ATTR_VOL_OBJCOUNT
2d21ac55
A
819A
820.Vt u_int32_t
91447636
A
821containing the number of file system objects on the volume.
822.
823.It ATTR_VOL_FILECOUNT
2d21ac55
A
824A
825.Vt u_int32_t
91447636
A
826containing the number of files on the volume.
827.
828.It ATTR_VOL_DIRCOUNT
2d21ac55
A
829A
830.Vt u_int32_t
91447636
A
831containing the number of directories on the volume.
832.
833.It ATTR_VOL_MAXOBJCOUNT
2d21ac55
A
834A
835.Vt u_int32_t
91447636
A
836containing the maximum number of file system objects that can be stored on the volume.
837.
838.It ATTR_VOL_MOUNTPOINT
2d21ac55 839An
91447636 840.Vt attrreference
2d21ac55 841structure containing the path to the volume's mount point as a
91447636 842UTF-8 encoded, null terminated C string.
2d21ac55 843The attribute data length will not be greater than
91447636 844.Dv MAXPATHLEN .
2d21ac55
A
845Equivalent to the
846.Fa f_mntonname
847field of the
848.Vt statfs
849structure returned by
91447636
A
850.Xr statfs 2 .
851.
852.It ATTR_VOL_NAME
2d21ac55 853(read/write) An
91447636 854.Vt attrreference
2d21ac55 855structure containing the name of the volume as a
91447636 856UTF-8 encoded, null terminated C string.
2d21ac55 857The attribute data length will not be greater than
91447636
A
858.Dv NAME_MAX +
8591.
860.Pp
861.
2d21ac55 862This attribute is only read/write if the
91447636
A
863.Dv VOL_CAP_INT_VOL_RENAME
864bit is set in the volume capabilities (see below).
865.Pp
866.
867.It ATTR_VOL_MOUNTFLAGS
2d21ac55
A
868A
869.Vt u_int32_t
870containing the volume mount flags.
871This is a copy of the value passed to the
91447636 872.Fa flags
2d21ac55 873parameter of
91447636
A
874.Xr mount 2
875when the volume was mounted.
2d21ac55
A
876Equivalent to the
877.Fa f_flags
878field of the
879.Vt statfs
880structure returned by
91447636
A
881.Xr statfs 2 .
882.
883.It ATTR_VOL_MOUNTEDDEVICE
2d21ac55 884An
91447636 885.Vt attrreference
2d21ac55
A
886structure that returns the same value as the
887.Fa f_mntfromname
888field of the
889.Vt statfs
890structure returned by
91447636 891.Xr statfs 2 .
2d21ac55 892For local volumes this is the path to the device on which the volume is mounted as a
91447636
A
893UTF-8 encoded, null terminated C string.
894For network volumes, this is a unique string that identifies the mount.
2d21ac55 895The attribute data length will not be greater than
91447636
A
896.Dv MAXPATHLEN .
897.Pp
898.
899.It ATTR_VOL_ENCODINGSUSED
2d21ac55 900An
91447636 901.Vt unsigned long long
2d21ac55
A
902containing a bitmap of the text encodings used on this volume.
903For more information about this, see the discussion of
904.Fa encodingsBitmap
91447636
A
905in DTS Technote 1150 "HFS Plus Volume Format".
906.
907.It ATTR_VOL_CAPABILITIES
908A
909.Vt vol_capabilities_attr_t
2d21ac55 910structure describing the optional features supported by this volume.
91447636
A
911See below for a discussion of volume capabilities.
912.
b0d623f7
A
913.It ATTR_VOL_UUID
914A
915.Vt uuid_t
916containing the file system UUID. Typically this will be a
917version 5 UUID.
918.
813fb2f6
A
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.
91447636
A
929.It ATTR_VOL_ATTRIBUTES
930A
931.Vt vol_attributes_attr_t
2d21ac55 932structure describing the attributes supported by this volume.
91447636
A
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
2d21ac55
A
944A
945.Vt u_int32_t
946containing the number of hard links to the directory;
947this does not include the historical "." and ".." entries.
b0d623f7 948For file systems that do not support hard links to directories,
2d21ac55 949this value will be 1.
91447636
A
950.
951.It ATTR_DIR_ENTRYCOUNT
2d21ac55
A
952A
953.Vt u_int32_t
954containing the number of file system objects in the directory, not including
b0d623f7
A
955any synthetic items. The historical "." and ".." entries are also
956excluded from this count.
91447636
A
957.
958.It ATTR_DIR_MOUNTSTATUS
2d21ac55
A
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,
91447636 964which indicates that there is a file system mounted on this directory.
91447636 965.
813fb2f6
A
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).
91447636
A
981.El
982.
b0d623f7
A
983.Pp
984Requested directory attributes are not returned for file system objects that
985are not directories.
986.
91447636
A
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
2d21ac55
A
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
91447636
A
1002.Xr stat 2 .
1003.
1004.It ATTR_FILE_TOTALSIZE
2d21ac55 1005An
91447636
A
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
2d21ac55 1010An
91447636
A
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
2d21ac55
A
1015A
1016.Vt u_int32_t
1017containing the optimal block size when reading or writing this file's data.
91447636
A
1018.
1019.It ATTR_FILE_CLUMPSIZE
2d21ac55
A
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.
91447636
A
1025This value applies to the data fork.
1026.
1027.It ATTR_FILE_DEVTYPE
2d21ac55
A
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
91447636
A
1036.Xr stat 2 .
1037.
1038.It ATTR_FILE_FILETYPE
1039A
2d21ac55 1040.Vt u_int32_t
91447636
A
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
2d21ac55 1047.Vt u_int32_t
91447636 1048containing the number of forks in the file.
2d21ac55 1049No built-in file systems on Mac OS X currently support forks other
91447636
A
1050than the data and resource fork.
1051.
1052.It ATTR_FILE_FORKLIST
2d21ac55 1053An
91447636
A
1054.Vt attrreference
1055structure containing a list of named forks of the file.
2d21ac55 1056No built-in file systems on Mac OS X currently support forks
91447636
A
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
2d21ac55
A
1073array for the data fork.
1074The array contains eight
1075.Vt diskextent
1076structures which represent the first
91447636
A
1077eight extents of the fork.
1078.Pp
2d21ac55 1079This attributes exists for compatibility reasons.
91447636 1080New clients should not use this attribute.
2d21ac55
A
1081Rather, they should use the
1082.Dv F_LOG2PHYS
1083command in
91447636
A
1084.Xr fcntl 2 .
1085.Pp
1086.
2d21ac55 1087In current implementations the value may not be entirely accurate for
91447636
A
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
2d21ac55
A
1103array for the resource fork.
1104The array contains eight
1105.Vt diskextent
1106structures which represent the first
91447636
A
1107eight extents of the fork.
1108.Pp
2d21ac55 1109See also
91447636
A
1110.Dv ATTR_FILE_DATAEXTENTS .
1111.
1112.El
1113.
b0d623f7
A
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.
91447636
A
1120.Sh FORK ATTRIBUTES
1121.
2d21ac55 1122Fork attributes relate to the actual data in the file,
91447636 1123which can be held in multiple named contiguous ranges, or forks.
813fb2f6 1124These cannot be used if the FSOPT_ATTR_CMN_EXTENDED is given.
91447636
A
1125The following fork attributes are defined.
1126.
1127.Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
1128.
1129.It ATTR_FORK_TOTALSIZE
39037602 1130Deprecated.
91447636
A
1131An
1132.Vt off_t
1133containing the length of the fork in bytes (the logical size).
1134.
1135.It ATTR_FORK_ALLOCSIZE
39037602 1136Deprecated.
91447636
A
1137An
1138.Vt off_t
1139containing a count of the bytes on disk used by the fork (the physical size).
1140.
39037602
A
1141.It ATTR_FORK_RESERVED
1142Reserved.
1143You must set this to 0.
1144.
91447636
A
1145.El
1146.Pp
1147.
39037602
A
1148Fork attributes are deprecated and all bits are reserved.
1149They are not properly implemented by any current Mac OS X
2d21ac55
A
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.
91447636 1153.
813fb2f6
A
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.
5ba3f43e
A
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.
cb323159
A
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 .
ea3f0419
A
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.
f427ee49
A
1264.It EF_IS_SYNTHETIC
1265If this bit is set the item is a synthetic directory/symlink.
1266.
ea3f0419 1267.El
f427ee49
A
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.
813fb2f6 1278.El
ea3f0419 1279.Pp
813fb2f6 1280.
91447636
A
1281.Sh VOLUME CAPABILITIES
1282.
1283.\" vol_capabilities_attr_t
1284.
2d21ac55
A
1285Not all volumes support all features.
1286The
1287.Dv ATTR_VOL_CAPABILITIES
1288attribute returns a
1289.Vt vol_capabilities_attr_t
91447636
A
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.
2d21ac55
A
1309The structure contains two fields,
1310.Fa capabilities
1311and
91447636 1312.Fa valid .
2d21ac55 1313Each consists of an array of four elements.
91447636
A
1314The arrays are indexed by the following values.
1315.
1316.Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1317.
1318.It VOL_CAPABILITIES_FORMAT
2d21ac55
A
1319This element contains information about the volume format.
1320See
1321.Dv VOL_CAP_FMT_PERSISTENTOBJECTIDS
91447636
A
1322and so on, below.
1323.
1324.It VOL_CAPABILITIES_INTERFACES
2d21ac55 1325This element contains information about which optional functions are
91447636 1326supported by the volume format implementation.
2d21ac55
A
1327See
1328.Dv VOL_CAP_INT_SEARCHFS
91447636
A
1329and so on, below.
1330.
1331.It VOL_CAPABILITIES_RESERVED1
2d21ac55
A
1332Reserved.
1333A file system implementation should set this element to zero.
91447636
A
1334A client program should ignore this element.
1335.
1336.It VOL_CAPABILITIES_RESERVED2
2d21ac55
A
1337Reserved.
1338A file system implementation should set this element to zero.
91447636
A
1339A client program should ignore this element.
1340.
1341.El
1342.Pp
1343.
2d21ac55
A
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
91447636
A
1350field is valid.
1351.Pp
1352.
2d21ac55
A
1353The
1354.Fa capabilities
1355field contains bit sets that indicate whether a particular feature is implemented
1356by this volume format.
91447636
A
1357.Pp
1358.
2d21ac55
A
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
91447636
A
1367structure.
1368.
1369.Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1370.
1371.It VOL_CAP_FMT_PERSISTENTOBJECTIDS
2d21ac55 1372If this bit is set the volume format supports persistent object identifiers
91447636 1373and can look up file system objects by their IDs.
2d21ac55
A
1374See
1375.Dv ATTR_CMN_OBJPERMANENTID
91447636
A
1376for details about how to obtain these identifiers.
1377.
1378.It VOL_CAP_FMT_SYMBOLICLINKS
2d21ac55 1379If this bit is set the volume format supports symbolic links.
91447636
A
1380.
1381.It VOL_CAP_FMT_HARDLINKS
2d21ac55 1382If this bit is set the volume format supports hard links.
91447636
A
1383.
1384.It VOL_CAP_FMT_JOURNAL
2d21ac55
A
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
91447636
A
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
2d21ac55 1393If this bit is set the volume is currently using a journal for
91447636 1394speedy recovery after an unplanned restart.
2d21ac55 1395This bit can be set only if
91447636
A
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
2d21ac55
A
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,
91447636
A
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
2d21ac55 1411to, and thus do not consume space on disk.
91447636 1412A sparse file may have an allocated size on disk that is less than its logical length (that is,
2d21ac55 1413.Dv ATTR_FILE_ALLOCSIZE
91447636
A
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
2d21ac55
A
1421For security reasons, parts of a file (runs) that have never been
1422written to must appear to contain zeroes.
91447636
A
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
2d21ac55 1425writing zeroes to the media.
91447636
A
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
2d21ac55
A
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,
91447636
A
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
2d21ac55
A
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
91447636 1443(typically making them all upper or all lower case).
2d21ac55 1444A volume that sets
91447636 1445.Dv VOL_CAP_FMT_CASE_SENSITIVE
2d21ac55 1446must also set
91447636
A
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
fe8ab488 1452This bit is used as a hint to upper layers to
2d21ac55
A
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
91447636 1457.Xr statfs 2
91447636 1458information in memory should set this bit.
2d21ac55
A
1459An implementation that must always read from disk or always perform a network
1460transaction to satisfy
91447636
A
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
b0d623f7
A
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.
91447636
A
1470.Pp
1471Introduced with Darwin 8.0 (Mac OS X version 10.4).
1472.
b0d623f7
A
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.
6d2010ae
A
1507.It VOL_CAP_FMT_64BIT_OBJECT_IDS
1508If this bit is set, the volume format uses object IDs that are 64-bit.
39037602
A
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.
6d2010ae 1513.
813fb2f6
A
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.
cb323159
A
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.
f427ee49
A
1529.It VOL_CAP_FMT_SEALED
1530If this bit is set, the volume is cryptographically sealed and any modifications
1531may render the volume unusable.
cb323159 1532.
813fb2f6 1533.
91447636
A
1534.El
1535.Pp
1536.
2d21ac55
A
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
91447636
A
1545structure.
1546.
1547.Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1548.
1549.It VOL_CAP_INT_SEARCHFS
2d21ac55 1550If this bit is set the volume format implementation supports
91447636
A
1551.Xr searchfs 2 .
1552.
1553.It VOL_CAP_INT_ATTRLIST
2d21ac55
A
1554If this bit is set the volume format implementation supports
1555.Fn getattrlist
1556and
91447636
A
1557.Xr setattrlist 2 .
1558.
1559.It VOL_CAP_INT_NFSEXPORT
2d21ac55 1560If this bit is set the volume format implementation allows this volume to be exported via NFS.
91447636
A
1561.
1562.It VOL_CAP_INT_READDIRATTR
2d21ac55 1563If this bit is set the volume format implementation supports
91447636
A
1564.Xr getdirentriesattr 2 .
1565.
1566.It VOL_CAP_INT_EXCHANGEDATA
2d21ac55 1567If this bit is set the volume format implementation supports
91447636
A
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.
b0d623f7
A
1575(This is not the
1576.Xr copyfile 3
1577function.)
91447636
A
1578.Pp
1579Introduced with Darwin 7.0 (Mac OS X version 10.3).
1580.
1581.It VOL_CAP_INT_ALLOCATE
2d21ac55
A
1582If this bit is set the volume format implementation supports the
1583.Dv F_PREALLOCATE
1584selector of
91447636
A
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
2d21ac55
A
1590If this bit is set the volume format implementation allows you to
1591modify the volume name using
91447636
A
1592.Xr setattrlist 2 .
1593.Pp
1594Introduced with Darwin 7.0 (Mac OS X version 10.3).
1595.
1596.It VOL_CAP_INT_ADVLOCK
2d21ac55
A
1597If this bit is set the volume format implementation supports
1598advisory locking, that is, the
91447636 1599.Dv F_GETLK ,
2d21ac55
A
1600.Dv F_SETLK ,
1601and
1602.Dv F_SETLKW
1603selectors to
91447636
A
1604.Xr fcntl 2 .
1605.Pp
1606Introduced with Darwin 7.0 (Mac OS X version 10.3).
1607.
1608.It VOL_CAP_INT_FLOCK
2d21ac55
A
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
91447636
A
1618.Xr open 2 .
1619.Pp
1620Introduced with Darwin 7.0 (Mac OS X version 10.3).
1621.
2d21ac55
A
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.
b0d623f7
A
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
39037602 1642.Xr setxattr 2 Ns ).
b0d623f7 1643.
813fb2f6
A
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.
5ba3f43e
A
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.
b0d623f7
A
1656.It VOL_CAP_INT_NAMEDSTREAMS
1657If this bit is set, the volume format implementation supports
1658native named streams.
1659.
39037602
A
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.
cb323159
A
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.
91447636
A
1679.El
1680.Pp
1681.
1682.\" vol_attributes_attr_t
1683.
2d21ac55 1684A volume can also report which attributes it supports.
91447636 1685This information is returned by the
2d21ac55
A
1686.Dv ATTR_VOL_ATTRIBUTES
1687attribute, which returns a
1688.Vt vol_attributes_attr_t
91447636
A
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.
2d21ac55
A
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
91447636 1728.Vt vol_attributes_attr_t ,
2d21ac55
A
1729but not in the
1730.Fa nativeattr
91447636
A
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
2d21ac55 1740Not all volumes support
91447636 1741.Fn getattrlist .
2d21ac55 1742The best way to test whether a volume supports this function is to
91447636 1743simply call it and check the error result.
2d21ac55
A
1744.Fn getattrlist
1745will return
91447636
A
1746.Dv ENOTSUP
1747if it is not supported on a particular volume.
1748.Pp
1749.
2d21ac55
A
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.
91447636
A
1757Your program is expected to be tolerant of this variant behaviour.
1758.Pp
1759.
2d21ac55 1760If you're implementing a volume format that supports
91447636
A
1761.Fn getattrlist ,
1762you should be careful to support the behaviour specified by this document.
1763.
1764.Sh ERRORS
1765.Fn getattrlist
b0d623f7
A
1766and
1767.Fn fgetattrlist
91447636
A
1768will fail if:
1769.Bl -tag -width Er
1770.
1771.It Bq Er ENOTSUP
b0d623f7 1772The volume does not support the query.
91447636
A
1773.
1774.It Bq Er ENOTDIR
b0d623f7
A
1775A component of the path prefix for
1776.Fn getattrlist
1777is not a directory.
91447636
A
1778.
1779.It Bq Er ENAMETOOLONG
b0d623f7
A
1780A component of a path name for
1781.Fn getattrlist
1782exceeded
91447636 1783.Dv NAME_MAX
2d21ac55 1784characters, or an entire path name exceeded
91447636
A
1785.Dv PATH_MAX
1786characters.
1787.
1788.It Bq Er ENOENT
b0d623f7
A
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.
91447636
A
1797.
1798.It Bq Er EACCES
b0d623f7
A
1799Search permission is denied for a component of the path prefix for
1800.Fn getattrlist .
91447636
A
1801.
1802.It Bq Er ELOOP
b0d623f7
A
1803Too many symbolic links were encountered in translating the pathname
1804for
1805.Fn getattrlist .
91447636
A
1806.
1807.It Bq Er EFAULT
1808.Fa path ,
1809.Fa attrList
1810or
1811.Em attrBuf
1812points to an invalid address.
1813.
9d749ea3
A
1814.It Bq Er ERANGE
1815.Fa attrBufSize
1816is too small to hold a u_int32_t.
1817.
91447636 1818.It Bq Er EINVAL
2d21ac55
A
1819The
1820.Fa bitmapcount
1821field of
1822.Fa attrList
1823is not
91447636
A
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
2d21ac55
A
1836You requested volume attributes but
1837.Fa path
91447636
A
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
fe8ab488
A
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
91447636
A
1871.
1872.Sh CAVEATS
1873.
2d21ac55
A
1874If you request any volume attributes, you must set
1875.Dv ATTR_VOL_INFO
1876in the
91447636
A
1877.Fa volattr
1878field, even though it generates no result in the attribute buffer.
1879.Pp
1880.
2d21ac55 1881The order that attributes are stored in the attribute buffer almost
91447636 1882invariably matches the order of attribute mask bit values.
2d21ac55
A
1883For example,
1884.Dv ATTR_CMN_NAME
1885(0x00000001) comes before
1886.Dv ATTR_CMN_DEVID
91447636 1887(0x00000002) because its value is smaller.
2d21ac55 1888When ordering attributes, you should always use the order in which they
91447636
A
1889are described above.
1890.Pp
1891.
b0d623f7
A
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
6d2010ae
A
1898If you use a structure
1899for the attribute data, it must be correctly packed and aligned (see
1900examples).
1901.Pp
b0d623f7
A
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.
91447636
A
1909For more caveats, see also the compatibility notes above.
1910.
1911.Sh EXAMPLES
1912.
2d21ac55 1913The following code prints the file type and creator of a file,
91447636
A
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 {
2d21ac55 1930 u_int32_t length;
91447636
A
1931 fsobj_type_t objType;
1932 char finderInfo[32];
6d2010ae 1933} __attribute__((aligned(4), packed));
91447636
A
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
2d21ac55 1948
91447636
A
1949 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
1950 if (err != 0) {
1951 err = errno;
1952 }
1953.Pp
2d21ac55 1954
91447636
A
1955 if (err == 0) {
1956 assert(attrBuf.length == sizeof(attrBuf));
1957.Pp
2d21ac55 1958
91447636
A
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.
2d21ac55 1980The following code is an alternative implementation that uses nested structures
91447636
A
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];
6d2010ae 2000} __attribute__((aligned(4), packed));
91447636
A
2001typedef struct FInfo2CommonAttrBuf FInfo2CommonAttrBuf;
2002.Pp
2003.
2004struct FInfo2AttrBuf {
2d21ac55 2005 u_int32_t length;
91447636 2006 FInfo2CommonAttrBuf common;
6d2010ae 2007} __attribute__((aligned(4), packed));;
91447636
A
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(
2d21ac55 2037 "file type = '%.4s'\en",
91447636
A
2038 &attrBuf.common.finderInfo[0]
2039 );
2040 printf(
2d21ac55 2041 "file creator = '%.4s'\en",
91447636
A
2042 &attrBuf.common.finderInfo[4]
2043 );
2044 break;
2045 case VDIR:
2046 printf("directory\en");
2047 break;
2048 default:
2049 printf(
2d21ac55 2050 "other object type, %d\en",
91447636
A
2051 attrBuf.common.objType
2052 );
2053 break;
2054 }
2055 }
2056.Pp
2057.
2058 return err;
2059}
2060.Ed
2061.Pp
2062.
2d21ac55
A
2063The following example shows how to deal with variable length attributes.
2064It assumes that the volume specified by
2065.Fa path
91447636
A
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 {
2d21ac55
A
2083 u_int32_t length;
2084 u_int32_t fileCount;
2085 u_int32_t dirCount;
91447636
A
2086 attrreference_t mountPointRef;
2087 attrreference_t volNameRef;
2088 char mountPointSpace[MAXPATHLEN];
2089 char volNameSpace[MAXPATHLEN];
6d2010ae 2090} __attribute__((aligned(4), packed));
91447636
A
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;
2d21ac55
A
2103 attrList.volattr = ATTR_VOL_INFO
2104 | ATTR_VOL_FILECOUNT
2105 | ATTR_VOL_DIRCOUNT
2106 | ATTR_VOL_MOUNTPOINT
91447636
A
2107 | ATTR_VOL_NAME;
2108.Pp
2d21ac55 2109
91447636
A
2110 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
2111 if (err != 0) {
2112 err = errno;
2113 }
2114.Pp
2d21ac55 2115
91447636
A
2116 if (err == 0) {
2117 assert(attrBuf.length > offsetof(VolAttrBuf, mountPointSpace));
2118 assert(attrBuf.length <= sizeof(attrBuf));
2119.Pp
2d21ac55 2120
91447636 2121 printf("Volume information for %s:\en", path);
b0d623f7
A
2122 printf("ATTR_VOL_FILECOUNT: %u\en", attrBuf.fileCount);
2123 printf("ATTR_VOL_DIRCOUNT: %u\en", attrBuf.dirCount);
91447636 2124 printf(
2d21ac55 2125 "ATTR_VOL_MOUNTPOINT: %.*s\en",
91447636 2126 (int) attrBuf.mountPointRef.attr_length,
2d21ac55 2127 ( ((char *) &attrBuf.mountPointRef)
91447636
A
2128 + attrBuf.mountPointRef.attr_dataoffset )
2129 );
2130 printf(
2d21ac55 2131 "ATTR_VOL_NAME: %.*s\en",
91447636 2132 (int) attrBuf.volNameRef.attr_length,
2d21ac55 2133 ( ((char *) &attrBuf.volNameRef)
91447636
A
2134 + attrBuf.volNameRef.attr_dataoffset )
2135 );
2136 }
2137.Pp
2138.
2139 return err;
2140}
2141.Ed
2142.Pp
6d2010ae
A
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
5ba3f43e
A
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
6d2010ae 2239.Pp
91447636
A
2240.
2241.Sh SEE ALSO
2242.
2243.Xr access 2 ,
2244.Xr chflags 2 ,
2245.Xr exchangedata 2 ,
2246.Xr fcntl 2 ,
fe8ab488 2247.Xr getattrlistbulk 2 ,
91447636
A
2248.Xr mount 2 ,
2249.Xr searchfs 2 ,
2250.Xr setattrlist 2 ,
2251.Xr stat 2 ,
2252.Xr statfs 2
2253.
2254.Sh HISTORY
2d21ac55 2255A
91447636
A
2256.Fn getattrlist
2257function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).
fe8ab488
A
2258The
2259.Fn getattrlistat
2260function call appeared in OS X 10.10 .