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