]> git.saurik.com Git - apple/xnu.git/blame - bsd/man/man2/getattrlist.2
xnu-6153.101.6.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 .
ea3f0419
A
1225.
1226.It ATTR_CMNEXT_CLONEID
1227A
1228.Vt u_int64_t
1229that uniquely identifies the data stream associated with the file
1230system object. Useful for finding which files are pure clones of each
1231other (as they will have the same clone-id).
1232.
1233.It ATTR_CMNEXT_EXT_FLAGS
1234A
1235.Vt u_int64_t
1236that contains additional flags with information about the file. The
1237flags are:
1238.
1239.Bl -tag -width EF_MAY_SHARE_BLOCKS
1240.
1241.It EF_MAY_SHARE_BLOCKS
1242If this bit is set then the file may share blocks with another file
1243(i.e. it is a clone of another file).
1244.
1245.It EF_NO_XATTRS
1246If this bit is set then the file has no extended attributes. Useful
1247for avoiding a call to listxattr().
1248.
1249.It EF_IS_SYNC_ROOT
1250If this bit is set the directory is a "sync root". This bit will
1251never be set for regular files.
1252.
1253.It EF_IS_PURGEABLE
1254If this bit is set the item is a "purgeable" item that can be deleted
1255by the file system when asked to free space.
1256.
1257.It EF_IS_SPARSE
1258If this bit is set the item has sparse regions.
1259.
1260.El
813fb2f6 1261.El
ea3f0419 1262.Pp
813fb2f6 1263.
91447636
A
1264.Sh VOLUME CAPABILITIES
1265.
1266.\" vol_capabilities_attr_t
1267.
2d21ac55
A
1268Not all volumes support all features.
1269The
1270.Dv ATTR_VOL_CAPABILITIES
1271attribute returns a
1272.Vt vol_capabilities_attr_t
91447636
A
1273structure (shown below) that indicates which features are supported by the volume.
1274.
1275.Bd -literal
1276typedef u_int32_t vol_capabilities_set_t[4];
1277.Pp
1278.
1279#define VOL_CAPABILITIES_FORMAT 0
1280#define VOL_CAPABILITIES_INTERFACES 1
1281#define VOL_CAPABILITIES_RESERVED1 2
1282#define VOL_CAPABILITIES_RESERVED2 3
1283.Pp
1284.
1285typedef struct vol_capabilities_attr {
1286 vol_capabilities_set_t capabilities;
1287 vol_capabilities_set_t valid;
1288} vol_capabilities_attr_t;
1289.Ed
1290.Pp
1291.
2d21ac55
A
1292The structure contains two fields,
1293.Fa capabilities
1294and
91447636 1295.Fa valid .
2d21ac55 1296Each consists of an array of four elements.
91447636
A
1297The arrays are indexed by the following values.
1298.
1299.Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1300.
1301.It VOL_CAPABILITIES_FORMAT
2d21ac55
A
1302This element contains information about the volume format.
1303See
1304.Dv VOL_CAP_FMT_PERSISTENTOBJECTIDS
91447636
A
1305and so on, below.
1306.
1307.It VOL_CAPABILITIES_INTERFACES
2d21ac55 1308This element contains information about which optional functions are
91447636 1309supported by the volume format implementation.
2d21ac55
A
1310See
1311.Dv VOL_CAP_INT_SEARCHFS
91447636
A
1312and so on, below.
1313.
1314.It VOL_CAPABILITIES_RESERVED1
2d21ac55
A
1315Reserved.
1316A file system implementation should set this element to zero.
91447636
A
1317A client program should ignore this element.
1318.
1319.It VOL_CAPABILITIES_RESERVED2
2d21ac55
A
1320Reserved.
1321A file system implementation should set this element to zero.
91447636
A
1322A client program should ignore this element.
1323.
1324.El
1325.Pp
1326.
2d21ac55
A
1327The
1328.Fa valid
1329field contains bit sets that indicate which flags are known to the volume format
1330implementation.
1331Each bit indicates whether the contents of the corresponding bit in the
1332.Fa capabilities
91447636
A
1333field is valid.
1334.Pp
1335.
2d21ac55
A
1336The
1337.Fa capabilities
1338field contains bit sets that indicate whether a particular feature is implemented
1339by this volume format.
91447636
A
1340.Pp
1341.
2d21ac55
A
1342The following bits are defined in the first element (indexed by
1343.Dv VOL_CAPABILITIES_FORMAT )
1344of the
1345.Fa capabilities
1346and
1347.Fa valid
1348fields of the
1349.Vt vol_capabilities_attr_t
91447636
A
1350structure.
1351.
1352.Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1353.
1354.It VOL_CAP_FMT_PERSISTENTOBJECTIDS
2d21ac55 1355If this bit is set the volume format supports persistent object identifiers
91447636 1356and can look up file system objects by their IDs.
2d21ac55
A
1357See
1358.Dv ATTR_CMN_OBJPERMANENTID
91447636
A
1359for details about how to obtain these identifiers.
1360.
1361.It VOL_CAP_FMT_SYMBOLICLINKS
2d21ac55 1362If this bit is set the volume format supports symbolic links.
91447636
A
1363.
1364.It VOL_CAP_FMT_HARDLINKS
2d21ac55 1365If this bit is set the volume format supports hard links.
91447636
A
1366.
1367.It VOL_CAP_FMT_JOURNAL
2d21ac55
A
1368If this bit is set the volume format supports a journal used to
1369speed recovery in case of unplanned restart (such as a power outage
91447636
A
1370or crash).
1371This does not necessarily mean the volume is actively using a journal.
1372.Pp
1373Introduced with Darwin 7.0 (Mac OS X version 10.3).
1374.
1375.It VOL_CAP_FMT_JOURNAL_ACTIVE
2d21ac55 1376If this bit is set the volume is currently using a journal for
91447636 1377speedy recovery after an unplanned restart.
2d21ac55 1378This bit can be set only if
91447636
A
1379.Dv VOL_CAP_FMT_JOURNAL
1380is also set.
1381.Pp
1382Introduced with Darwin 7.0 (Mac OS X version 10.3).
1383.
1384.It VOL_CAP_FMT_NO_ROOT_TIMES
2d21ac55
A
1385If this bit is set the volume format does not store reliable times for
1386the root directory, so you should not depend on them to detect changes,
91447636
A
1387identify volumes across unmount/mount, and so on.
1388.Pp
1389Introduced with Darwin 7.0 (Mac OS X version 10.3).
1390.
1391.It VOL_CAP_FMT_SPARSE_FILES
1392If this bit is set the volume format supports sparse files,
1393that is, files which can have 'holes' that have never been written
2d21ac55 1394to, and thus do not consume space on disk.
91447636 1395A sparse file may have an allocated size on disk that is less than its logical length (that is,
2d21ac55 1396.Dv ATTR_FILE_ALLOCSIZE
91447636
A
1397<
1398.Dv ATTR_FILE_TOTALSIZE ).
1399.
1400.Pp
1401Introduced with Darwin 7.0 (Mac OS X version 10.3).
1402.
1403.It VOL_CAP_FMT_ZERO_RUNS
2d21ac55
A
1404For security reasons, parts of a file (runs) that have never been
1405written to must appear to contain zeroes.
91447636
A
1406When this bit is set, the volume keeps track of allocated but unwritten
1407runs of a file so that it can substitute zeroes without actually
2d21ac55 1408writing zeroes to the media.
91447636
A
1409This provides performance similar to sparse files, but not the space savings.
1410.Pp
1411Introduced with Darwin 7.0 (Mac OS X version 10.3).
1412.
1413.It VOL_CAP_FMT_CASE_SENSITIVE
2d21ac55
A
1414If this bit is set the volume format treats upper and lower case
1415characters in file and directory names as different.
1416Otherwise an upper case character is equivalent to a lower case character,
91447636
A
1417and you can't have two names that differ solely in the case of
1418the characters.
1419.Pp
1420Introduced with Darwin 7.0 (Mac OS X version 10.3).
1421.
1422.It VOL_CAP_FMT_CASE_PRESERVING
2d21ac55
A
1423If this bit is set the volume format preserves the case of
1424file and directory names.
1425Otherwise the volume may change the case of some characters
91447636 1426(typically making them all upper or all lower case).
2d21ac55 1427A volume that sets
91447636 1428.Dv VOL_CAP_FMT_CASE_SENSITIVE
2d21ac55 1429must also set
91447636
A
1430.Dv VOL_CAP_FMT_CASE_PRESERVING .
1431.Pp
1432Introduced with Darwin 7.0 (Mac OS X version 10.3).
1433.
1434.It VOL_CAP_FMT_FAST_STATFS
fe8ab488 1435This bit is used as a hint to upper layers to
2d21ac55
A
1436indicate that
1437.Xr statfs 2
1438is fast enough that its results need not be cached by the caller.
1439A volume format implementation that caches the
91447636 1440.Xr statfs 2
91447636 1441information in memory should set this bit.
2d21ac55
A
1442An implementation that must always read from disk or always perform a network
1443transaction to satisfy
91447636
A
1444.Xr statfs 2
1445should not set this bit.
1446.Pp
1447Introduced with Darwin 7.0 (Mac OS X version 10.3).
1448.
1449.It VOL_CAP_FMT_2TB_FILESIZE
b0d623f7
A
1450If this bit is set the volume format supports file sizes larger
1451than 4GB, and potentially up to 2TB; it does not indicate
1452whether the file system supports files larger than that.
91447636
A
1453.Pp
1454Introduced with Darwin 8.0 (Mac OS X version 10.4).
1455.
b0d623f7
A
1456.It VOL_CAP_FMT_OPENDENYMODES
1457If this bit is set, the volume format supports open deny modes
1458(e.g., "open for read write, deny write").
1459.
1460.It VOL_CAP_FMT_HIDDEN_FILES
1461If this bit is set, the volume format supports the
1462.Dv UF_HIDDEN
1463file flag, and the
1464.Dv UF_HIDDEN
1465flag is mapped to that volume's native "hidden" or "invisible"
1466bit (e.g., the invisible bit from the Finder Info extended attribute).
1467.
1468.It VOL_CAP_FMT_PATH_FROM_ID
1469If this bit is set, the volume format supports the ability to derive a pathname
1470to the root of the file system given only the ID of an object. This also
1471implies that object IDs on this file system are persistent and not recycled.
1472Most file systems will not support this capability.
1473.
1474.It VOL_CAP_FMT_NO_VOLUME_SIZES
1475If this bit is set the volume format does not support
1476determining values for total data blocks, available blocks, or free blocks, as in
1477.Fa f_blocks,
1478.Fa f_bavail,
1479and
1480.Fa f_bfree
1481in the
1482.Fa struct statfs
1483returned by
1484.Xr statfs 2 .
1485Historically, those values were set to 0xFFFFFFFF for volumes
1486that did not support them.
1487.Pp
1488Introduced with Darwin 10.0 (Mac OS X version 10.6).
1489.
6d2010ae
A
1490.It VOL_CAP_FMT_64BIT_OBJECT_IDS
1491If this bit is set, the volume format uses object IDs that are 64-bit.
39037602
A
1492This means that ATTR_CMN_FILEID and ATTR_CMN_PARENTID are the primary means of
1493obtaining object IDs from this volume. The values returned by ATTR_CMN_OBJID,
1494ATTR_CMN_OBJPERMANENTID, and ATTR_CMN_PAROBJID can be interpreted as 64-bit
1495object IDs instead of fsobj_id_t.
6d2010ae 1496.
813fb2f6
A
1497.It VOL_CAP_FMT_NO_IMMUTABLE_FILES
1498If this bit is set, the volume format does not support setting the UF_IMMUTABLE
1499flag.
1500See ATTR_CMN_FLAGS for more details.
1501.It VOL_CAP_FMT_NO_PERMISSIONS
1502If this bit is set, the volume format does not support setting file
1503permissions.
1504See ATTR_CMN_USERACCESS for more details.
cb323159
A
1505.It VOL_CAP_FMT_SHARED_SPACE
1506If this bit is set, the volume format supports having multiple logical filesystems
1507in a single "partition" which share space.
1508.It VOL_CAP_FMT_VOL_GROUPS
1509If this bit is set, the volume format supports having multiple logical filesystems
1510which may be mounted and unmounted together and may present common filesystem
1511identifier information.
1512.
813fb2f6 1513.
91447636
A
1514.El
1515.Pp
1516.
2d21ac55
A
1517The following bits are defined in the second element (indexed by
1518.Dv VOL_CAPABILITIES_INTERFACES )
1519of the
1520.Fa capabilities
1521and
1522.Fa valid
1523fields of the
1524.Vt vol_capabilities_attr_t
91447636
A
1525structure.
1526.
1527.Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
1528.
1529.It VOL_CAP_INT_SEARCHFS
2d21ac55 1530If this bit is set the volume format implementation supports
91447636
A
1531.Xr searchfs 2 .
1532.
1533.It VOL_CAP_INT_ATTRLIST
2d21ac55
A
1534If this bit is set the volume format implementation supports
1535.Fn getattrlist
1536and
91447636
A
1537.Xr setattrlist 2 .
1538.
1539.It VOL_CAP_INT_NFSEXPORT
2d21ac55 1540If this bit is set the volume format implementation allows this volume to be exported via NFS.
91447636
A
1541.
1542.It VOL_CAP_INT_READDIRATTR
2d21ac55 1543If this bit is set the volume format implementation supports
91447636
A
1544.Xr getdirentriesattr 2 .
1545.
1546.It VOL_CAP_INT_EXCHANGEDATA
2d21ac55 1547If this bit is set the volume format implementation supports
91447636
A
1548.Xr exchangedata 2 .
1549.Pp
1550Introduced with Darwin 7.0 (Mac OS X version 10.3).
1551.
1552.It VOL_CAP_INT_COPYFILE
1553If this bit is set the volume format implementation supports the (private and undocumented)
1554copyfile() function.
b0d623f7
A
1555(This is not the
1556.Xr copyfile 3
1557function.)
91447636
A
1558.Pp
1559Introduced with Darwin 7.0 (Mac OS X version 10.3).
1560.
1561.It VOL_CAP_INT_ALLOCATE
2d21ac55
A
1562If this bit is set the volume format implementation supports the
1563.Dv F_PREALLOCATE
1564selector of
91447636
A
1565.Xr fcntl 2 .
1566.Pp
1567Introduced with Darwin 7.0 (Mac OS X version 10.3).
1568.
1569.It VOL_CAP_INT_VOL_RENAME
2d21ac55
A
1570If this bit is set the volume format implementation allows you to
1571modify the volume name using
91447636
A
1572.Xr setattrlist 2 .
1573.Pp
1574Introduced with Darwin 7.0 (Mac OS X version 10.3).
1575.
1576.It VOL_CAP_INT_ADVLOCK
2d21ac55
A
1577If this bit is set the volume format implementation supports
1578advisory locking, that is, the
91447636 1579.Dv F_GETLK ,
2d21ac55
A
1580.Dv F_SETLK ,
1581and
1582.Dv F_SETLKW
1583selectors to
91447636
A
1584.Xr fcntl 2 .
1585.Pp
1586Introduced with Darwin 7.0 (Mac OS X version 10.3).
1587.
1588.It VOL_CAP_INT_FLOCK
2d21ac55
A
1589If this bit is set the volume format implementation supports
1590whole file locks.
1591This includes
1592.Xr flock 2
1593and the
1594.Dv O_EXLOCK
1595and
1596.Dv O_SHLOCK
1597flags to
91447636
A
1598.Xr open 2 .
1599.Pp
1600Introduced with Darwin 7.0 (Mac OS X version 10.3).
1601.
2d21ac55
A
1602.It VOL_CAP_INT_EXTENDED_SECURITY
1603If this bit is set the volume format implementation supports
1604extended security controls (ACLs).
1605.Pp
1606Introduced with Darwin 8.0 (Mac OS X version 10.4).
1607.
1608.It VOL_CAP_INT_USERACCESS
1609If this bit is set the volume format implementation supports the
1610ATTR_CMN_USERACCESS attribute.
1611.Pp
1612Introduced with Darwin 8.0 (Mac OS X version 10.4).
1613.
b0d623f7
A
1614.It VOL_CAP_INT_MANLOCK
1615If this bit is set, the volume format implementation supports
1616AFP-style mandatory byte range locks via
1617.Xr ioctl 2 .
1618.
1619.It VOL_CAP_INT_EXTENDED_ATTR
1620If this bit is set, the volume format implementation supports
1621native extended attributes (see
39037602 1622.Xr setxattr 2 Ns ).
b0d623f7 1623.
813fb2f6
A
1624.It VOL_CAP_INT_CLONE
1625If this bit is set, the file system supports cloning files and directories.
1626See
1627.Xr clonefileat 2
1628for more details.
1629.
5ba3f43e
A
1630.It VOL_CAP_INT_SNAPSHOT
1631If this bit is set, the file system supports snapshots.
1632See
1633.Xr fs_snapshot_create 2
1634for more details.
1635.
b0d623f7
A
1636.It VOL_CAP_INT_NAMEDSTREAMS
1637If this bit is set, the volume format implementation supports
1638native named streams.
1639.
39037602
A
1640.It VOL_CAP_INT_RENAME_SWAP
1641If this bit is set, the file system supports swapping file system
1642objects. See
1643.Xr rename 2
1644for more details.
1645.
1646.It VOL_CAP_INT_RENAME_EXCL
1647If this bit is set, the file system supports an exclusive rename
1648operation. See
1649.Xr rename 2
1650for more details.
1651.
cb323159
A
1652.It VOL_CAP_INT_RENAME_OPENFAIL
1653If this bit is set, the file system may fail a rename operation
1654of a directory if one of its descendents is open.
1655See
1656.Xr rename 2
1657for more details.
1658.
91447636
A
1659.El
1660.Pp
1661.
1662.\" vol_attributes_attr_t
1663.
2d21ac55 1664A volume can also report which attributes it supports.
91447636 1665This information is returned by the
2d21ac55
A
1666.Dv ATTR_VOL_ATTRIBUTES
1667attribute, which returns a
1668.Vt vol_attributes_attr_t
91447636
A
1669structure (shown below).
1670.
1671.Bd -literal
1672typedef struct attribute_set {
1673 attrgroup_t commonattr; /* common attribute group */
1674 attrgroup_t volattr; /* volume attribute group */
1675 attrgroup_t dirattr; /* directory attribute group */
1676 attrgroup_t fileattr; /* file attribute group */
1677 attrgroup_t forkattr; /* fork attribute group */
1678} attribute_set_t;
1679.Pp
1680.
1681typedef struct vol_attributes_attr {
1682 attribute_set_t validattr;
1683 attribute_set_t nativeattr;
1684} vol_attributes_attr_t;
1685.Ed
1686.Pp
1687.
2d21ac55
A
1688The
1689.Fa validattr
1690field consists of a number of bit sets that indicate whether an attribute is
1691supported by the volume format implementation.
1692The
1693.Fa nativeattr
1694is similar except that the bit sets indicate whether an attribute is supported
1695natively by the volume format.
1696An attribute is supported natively if the volume format implementation does not have to do
1697any complex conversions to access the attribute.
1698For example, a volume format might support persistent object identifiers, but
1699doing so requires a complex table lookup that is not part of the core volume
1700format.
1701In that case, the
1702.Dv ATTR_VOL_ATTRIBUTES
1703attribute would return
1704.Dv ATTR_CMN_OBJPERMANENTID
1705set in the
1706.Fa validattr
1707field of the
91447636 1708.Vt vol_attributes_attr_t ,
2d21ac55
A
1709but not in the
1710.Fa nativeattr
91447636
A
1711field.
1712.
1713.Sh RETURN VALUES
1714Upon successful completion a value of 0 is returned.
1715Otherwise, a value of -1 is returned and
1716.Va errno
1717is set to indicate the error.
1718.
1719.Sh COMPATIBILITY
2d21ac55 1720Not all volumes support
91447636 1721.Fn getattrlist .
2d21ac55 1722The best way to test whether a volume supports this function is to
91447636 1723simply call it and check the error result.
2d21ac55
A
1724.Fn getattrlist
1725will return
91447636
A
1726.Dv ENOTSUP
1727if it is not supported on a particular volume.
1728.Pp
1729.
2d21ac55
A
1730The
1731.Fn getattrlist
1732function has been undocumented for more than two years.
1733In that time a number of volume format implementations have been created without
1734a proper specification for the behaviour of this routine.
1735You may encounter volume format implementations with slightly different
1736behaviour than what is described here.
91447636
A
1737Your program is expected to be tolerant of this variant behaviour.
1738.Pp
1739.
2d21ac55 1740If you're implementing a volume format that supports
91447636
A
1741.Fn getattrlist ,
1742you should be careful to support the behaviour specified by this document.
1743.
1744.Sh ERRORS
1745.Fn getattrlist
b0d623f7
A
1746and
1747.Fn fgetattrlist
91447636
A
1748will fail if:
1749.Bl -tag -width Er
1750.
1751.It Bq Er ENOTSUP
b0d623f7 1752The volume does not support the query.
91447636
A
1753.
1754.It Bq Er ENOTDIR
b0d623f7
A
1755A component of the path prefix for
1756.Fn getattrlist
1757is not a directory.
91447636
A
1758.
1759.It Bq Er ENAMETOOLONG
b0d623f7
A
1760A component of a path name for
1761.Fn getattrlist
1762exceeded
91447636 1763.Dv NAME_MAX
2d21ac55 1764characters, or an entire path name exceeded
91447636
A
1765.Dv PATH_MAX
1766characters.
1767.
1768.It Bq Er ENOENT
b0d623f7
A
1769The file system object for
1770.Fn getattrlist
1771does not exist.
1772.
1773.It Bq Er EBADF
1774The file descriptor argument for
1775.Fn fgetattrlist
1776is not a valid file descriptor.
91447636
A
1777.
1778.It Bq Er EACCES
b0d623f7
A
1779Search permission is denied for a component of the path prefix for
1780.Fn getattrlist .
91447636
A
1781.
1782.It Bq Er ELOOP
b0d623f7
A
1783Too many symbolic links were encountered in translating the pathname
1784for
1785.Fn getattrlist .
91447636
A
1786.
1787.It Bq Er EFAULT
1788.Fa path ,
1789.Fa attrList
1790or
1791.Em attrBuf
1792points to an invalid address.
1793.
9d749ea3
A
1794.It Bq Er ERANGE
1795.Fa attrBufSize
1796is too small to hold a u_int32_t.
1797.
91447636 1798.It Bq Er EINVAL
2d21ac55
A
1799The
1800.Fa bitmapcount
1801field of
1802.Fa attrList
1803is not
91447636
A
1804.Dv ATTR_BIT_MAP_COUNT .
1805.
1806.It Bq Er EINVAL
1807You requested an invalid attribute.
1808.
1809.It Bq Er EINVAL
1810You requested an attribute that is not supported for this file system object.
1811.
1812.It Bq Er EINVAL
1813You requested volume attributes and directory or file attributes.
1814.
1815.It Bq Er EINVAL
2d21ac55
A
1816You requested volume attributes but
1817.Fa path
91447636
A
1818does not reference the root of the volume.
1819.
1820.It Bq Er EROFS
1821The volume is read-only but must be modified in order to return this attribute.
1822.
1823.It Bq Er EIO
1824An I/O error occurred while reading from or writing to the file system.
1825.El
1826.Pp
fe8ab488
A
1827In addition to the errors returned by the
1828.Fn getattrlist ,
1829the
1830.Fn getattrlistat
1831function may fail if:
1832.Bl -tag -width Er
1833.It Bq Er EBADF
1834The
1835.Fa path
1836argument does not specify an absolute path and the
1837.Fa fd
1838argument is neither
1839.Dv AT_FDCWD
1840nor a valid file descriptor open for searching.
1841.It Bq Er ENOTDIR
1842The
1843.Fa path
1844argument is not an absolute path and
1845.Fa fd
1846is neither
1847.Dv AT_FDCWD
1848nor a file descriptor associated with a directory.
1849.El
1850.Pp
91447636
A
1851.
1852.Sh CAVEATS
1853.
2d21ac55
A
1854If you request any volume attributes, you must set
1855.Dv ATTR_VOL_INFO
1856in the
91447636
A
1857.Fa volattr
1858field, even though it generates no result in the attribute buffer.
1859.Pp
1860.
2d21ac55 1861The order that attributes are stored in the attribute buffer almost
91447636 1862invariably matches the order of attribute mask bit values.
2d21ac55
A
1863For example,
1864.Dv ATTR_CMN_NAME
1865(0x00000001) comes before
1866.Dv ATTR_CMN_DEVID
91447636 1867(0x00000002) because its value is smaller.
2d21ac55 1868When ordering attributes, you should always use the order in which they
91447636
A
1869are described above.
1870.Pp
1871.
b0d623f7
A
1872The
1873.Vt timespec
1874structure is 64-bits (two 32-bit elements) in 32-bit code, and
1875128-bits (two 64-bit elements) in 64-bit code; however, it is aligned
1876on a 4-byte (32-bit) boundary, even in 64-bit code.
1877.Pp
6d2010ae
A
1878If you use a structure
1879for the attribute data, it must be correctly packed and aligned (see
1880examples).
1881.Pp
b0d623f7
A
1882.
1883Inconsistent behavior may be observed when the ATTR_CMN_FULLPATH attribute is requested on
1884hard-linked items, particularly when the file system does not support ATTR_CMN_PARENTID
1885natively. Callers should be aware of this when requesting the full path of a hard-linked item, especially
1886if the full path crosses mount points.
1887.Pp
1888.
91447636
A
1889For more caveats, see also the compatibility notes above.
1890.
1891.Sh EXAMPLES
1892.
2d21ac55 1893The following code prints the file type and creator of a file,
91447636
A
1894assuming that the volume supports the required attributes.
1895.
1896.Bd -literal
1897#include <assert.h>
1898#include <stdio.h>
1899#include <string.h>
1900#include <sys/attr.h>
1901#include <sys/errno.h>
1902#include <unistd.h>
1903#include <sys/vnode.h>
1904.Pp
1905.
1906typedef struct attrlist attrlist_t;
1907.Pp
1908.
1909struct FInfoAttrBuf {
2d21ac55 1910 u_int32_t length;
91447636
A
1911 fsobj_type_t objType;
1912 char finderInfo[32];
6d2010ae 1913} __attribute__((aligned(4), packed));
91447636
A
1914typedef struct FInfoAttrBuf FInfoAttrBuf;
1915.Pp
1916.
1917static int FInfoDemo(const char *path)
1918{
1919 int err;
1920 attrlist_t attrList;
1921 FInfoAttrBuf attrBuf;
1922.Pp
1923.
1924 memset(&attrList, 0, sizeof(attrList));
1925 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
1926 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
1927.Pp
2d21ac55 1928
91447636
A
1929 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
1930 if (err != 0) {
1931 err = errno;
1932 }
1933.Pp
2d21ac55 1934
91447636
A
1935 if (err == 0) {
1936 assert(attrBuf.length == sizeof(attrBuf));
1937.Pp
2d21ac55 1938
91447636
A
1939 printf("Finder information for %s:\en", path);
1940 switch (attrBuf.objType) {
1941 case VREG:
1942 printf("file type = '%.4s'\en", &attrBuf.finderInfo[0]);
1943 printf("file creator = '%.4s'\en", &attrBuf.finderInfo[4]);
1944 break;
1945 case VDIR:
1946 printf("directory\en");
1947 break;
1948 default:
1949 printf("other object type, %d\en", attrBuf.objType);
1950 break;
1951 }
1952 }
1953.Pp
1954.
1955 return err;
1956}
1957.Ed
1958.Pp
1959.
2d21ac55 1960The following code is an alternative implementation that uses nested structures
91447636
A
1961to group the related attributes.
1962.
1963.Bd -literal
1964#include <assert.h>
1965#include <stdio.h>
1966#include <stddef.h>
1967#include <string.h>
1968#include <sys/attr.h>
1969#include <sys/errno.h>
1970#include <unistd.h>
1971#include <sys/vnode.h>
1972.Pp
1973.
1974typedef struct attrlist attrlist_t;
1975.Pp
1976.
1977struct FInfo2CommonAttrBuf {
1978 fsobj_type_t objType;
1979 char finderInfo[32];
6d2010ae 1980} __attribute__((aligned(4), packed));
91447636
A
1981typedef struct FInfo2CommonAttrBuf FInfo2CommonAttrBuf;
1982.Pp
1983.
1984struct FInfo2AttrBuf {
2d21ac55 1985 u_int32_t length;
91447636 1986 FInfo2CommonAttrBuf common;
6d2010ae 1987} __attribute__((aligned(4), packed));;
91447636
A
1988typedef struct FInfo2AttrBuf FInfo2AttrBuf;
1989.Pp
1990.
1991static int FInfo2Demo(const char *path)
1992{
1993 int err;
1994 attrlist_t attrList;
1995 FInfo2AttrBuf attrBuf;
1996.Pp
1997.
1998 memset(&attrList, 0, sizeof(attrList));
1999 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
2000 attrList.commonattr = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
2001.Pp
2002.
2003 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
2004 if (err != 0) {
2005 err = errno;
2006 }
2007.Pp
2008.
2009 if (err == 0) {
2010 assert(attrBuf.length == sizeof(attrBuf));
2011.Pp
2012.
2013 printf("Finder information for %s:\en", path);
2014 switch (attrBuf.common.objType) {
2015 case VREG:
2016 printf(
2d21ac55 2017 "file type = '%.4s'\en",
91447636
A
2018 &attrBuf.common.finderInfo[0]
2019 );
2020 printf(
2d21ac55 2021 "file creator = '%.4s'\en",
91447636
A
2022 &attrBuf.common.finderInfo[4]
2023 );
2024 break;
2025 case VDIR:
2026 printf("directory\en");
2027 break;
2028 default:
2029 printf(
2d21ac55 2030 "other object type, %d\en",
91447636
A
2031 attrBuf.common.objType
2032 );
2033 break;
2034 }
2035 }
2036.Pp
2037.
2038 return err;
2039}
2040.Ed
2041.Pp
2042.
2d21ac55
A
2043The following example shows how to deal with variable length attributes.
2044It assumes that the volume specified by
2045.Fa path
91447636
A
2046supports the necessary attributes.
2047.
2048.Bd -literal
2049#include <assert.h>
2050#include <stdio.h>
2051#include <stddef.h>
2052#include <string.h>
2053#include <sys/attr.h>
2054#include <sys/errno.h>
2055#include <unistd.h>
2056#include <sys/vnode.h>
2057.Pp
2058.
2059typedef struct attrlist attrlist_t;
2060.Pp
2061.
2062struct VolAttrBuf {
2d21ac55
A
2063 u_int32_t length;
2064 u_int32_t fileCount;
2065 u_int32_t dirCount;
91447636
A
2066 attrreference_t mountPointRef;
2067 attrreference_t volNameRef;
2068 char mountPointSpace[MAXPATHLEN];
2069 char volNameSpace[MAXPATHLEN];
6d2010ae 2070} __attribute__((aligned(4), packed));
91447636
A
2071typedef struct VolAttrBuf VolAttrBuf;
2072.Pp
2073.
2074static int VolDemo(const char *path)
2075{
2076 int err;
2077 attrlist_t attrList;
2078 VolAttrBuf attrBuf;
2079.Pp
2080.
2081 memset(&attrList, 0, sizeof(attrList));
2082 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
2d21ac55
A
2083 attrList.volattr = ATTR_VOL_INFO
2084 | ATTR_VOL_FILECOUNT
2085 | ATTR_VOL_DIRCOUNT
2086 | ATTR_VOL_MOUNTPOINT
91447636
A
2087 | ATTR_VOL_NAME;
2088.Pp
2d21ac55 2089
91447636
A
2090 err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
2091 if (err != 0) {
2092 err = errno;
2093 }
2094.Pp
2d21ac55 2095
91447636
A
2096 if (err == 0) {
2097 assert(attrBuf.length > offsetof(VolAttrBuf, mountPointSpace));
2098 assert(attrBuf.length <= sizeof(attrBuf));
2099.Pp
2d21ac55 2100
91447636 2101 printf("Volume information for %s:\en", path);
b0d623f7
A
2102 printf("ATTR_VOL_FILECOUNT: %u\en", attrBuf.fileCount);
2103 printf("ATTR_VOL_DIRCOUNT: %u\en", attrBuf.dirCount);
91447636 2104 printf(
2d21ac55 2105 "ATTR_VOL_MOUNTPOINT: %.*s\en",
91447636 2106 (int) attrBuf.mountPointRef.attr_length,
2d21ac55 2107 ( ((char *) &attrBuf.mountPointRef)
91447636
A
2108 + attrBuf.mountPointRef.attr_dataoffset )
2109 );
2110 printf(
2d21ac55 2111 "ATTR_VOL_NAME: %.*s\en",
91447636 2112 (int) attrBuf.volNameRef.attr_length,
2d21ac55 2113 ( ((char *) &attrBuf.volNameRef)
91447636
A
2114 + attrBuf.volNameRef.attr_dataoffset )
2115 );
2116 }
2117.Pp
2118.
2119 return err;
2120}
2121.Ed
2122.Pp
6d2010ae
A
2123The following sample demonstrates the need to use packing and alignment
2124controls; without the attribute, in 64-bit code, the fields of the structure are not
2125placed at the locations that the kernel expects.
2126.
2127.Bd -literal
2128#include <stdio.h>
2129#include <stdlib.h>
2130#include <unistd.h>
2131#include <string.h>
2132#include <err.h>
2133#include <time.h>
2134#include <sys/attr.h>
2135.Pp
2136/* The alignment and packing attribute is necessary in 64-bit code */
2137struct AttrListTimes {
2138 u_int32_t length;
2139 struct timespec st_crtime;
2140 struct timespec st_modtime;
2141} __attribute__((aligned(4), packed));
2142.Pp
2143main(int argc, char **argv)
2144{
2145 int rv;
2146 int i;
2147.Pp
2148 for (i = 1; i < argc; i++) {
2149 struct attrlist attrList;
2150 struct AttrListTimes myStat = {0};
2151 char *path = argv[i];
2152.Pp
2153 memset(&attrList, 0, sizeof(attrList));
2154 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
2155 attrList.commonattr = ATTR_CMN_CRTIME |
2156 ATTR_CMN_MODTIME;
2157.Pp
2158 rv = getattrlist(path, &attrList, &myStat, sizeof(myStat), 0);
2159.Pp
2160 if (rv == -1) {
2161 warn("getattrlist(%s)", path);
2162 continue;
2163 }
2164 printf("%s: Modification time = %s", argv[i], ctime(&myStat.st_modtime.tv_sec));
2165 }
2166 return 0;
2167}
2168.Ed
5ba3f43e
A
2169.Pp
2170 The getLinkIDInfo() function determines if ATTR_CMNEXT_LINKID and ATTR_CMN_OBJID
2171 are valid to use on the file system specified by path.
2172.
2173.Bd -literal
2174int getLinkIDInfo(const char *path, bool *cmnExtLinkIDValid, bool *cmnObjIDValid)
2175{
2176 int result;
2177 struct statfs statfsBuf;
2178 struct attrlist attrList;
2179 struct volAttrsBuf {
2180 u_int32_t length;
2181 vol_capabilities_attr_t capabilities;
2182 vol_attributes_attr_t attributes;
2183 } __attribute__((aligned(4), packed));
2184 struct volAttrsBuf volAttrs;
2185.Pp
2186 memset(&attrList, 0, sizeof(attrList));
2187 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
2188 attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_CAPABILITIES | ATTR_VOL_ATTRIBUTES;
2189 // get the file system's mount point path for the input path
2190 result = statfs(path, &statfsBuf);
2191 if ( result == 0 ) {
2192 // get the supported capabilities and attributes
2193 result = getattrlist(statfsBuf.f_mntonname, &attrList, &volAttrs, sizeof(volAttrs), FSOPT_ATTR_CMN_EXTENDED);
2194 if ( result == 0 ) {
2195 if ( volAttrs.attributes.validattr.forkattr & ATTR_CMNEXT_LINKID ) {
2196 // ATTR_CMNEXT_LINKID is available; do not use ATTR_CMN_OBJID
2197 *cmnExtLinkIDValid = true;
2198 *cmnObjIDValid = false;
2199 }
2200 else {
2201 // ATTR_CMNEXT_LINKID is not available
2202 cmnExtLinkIDValid = false;
2203 // ATTR_CMN_OBJID can only be used if the file system does not use 64-bit object IDs
2204 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) ) {
2205 *cmnObjIDValid = false;
2206 }
2207 else {
2208 *cmnObjIDValid = true;
2209 }
2210 }
2211 }
2212 }
2213 if ( result != 0 ) {
2214 *cmnExtLinkIDValid = *cmnObjIDValid = false;
2215 }
2216 return result;
2217}
2218.Ed
6d2010ae 2219.Pp
91447636
A
2220.
2221.Sh SEE ALSO
2222.
2223.Xr access 2 ,
2224.Xr chflags 2 ,
2225.Xr exchangedata 2 ,
2226.Xr fcntl 2 ,
fe8ab488 2227.Xr getattrlistbulk 2 ,
91447636
A
2228.Xr mount 2 ,
2229.Xr searchfs 2 ,
2230.Xr setattrlist 2 ,
2231.Xr stat 2 ,
2232.Xr statfs 2
2233.
2234.Sh HISTORY
2d21ac55 2235A
91447636
A
2236.Fn getattrlist
2237function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).
fe8ab488
A
2238The
2239.Fn getattrlistat
2240function call appeared in OS X 10.10 .