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