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