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