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