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