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