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