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