]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/attr.h
xnu-1504.9.26.tar.gz
[apple/xnu.git] / bsd / sys / attr.h
1 /*
2 * Copyright (c) 2000-2008 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 /*
30 * attr.h - attribute data structures and interfaces
31 *
32 * Copyright (c) 1998, Apple Computer, Inc. All Rights Reserved.
33 */
34
35 #ifndef _SYS_ATTR_H_
36 #define _SYS_ATTR_H_
37
38 #include <sys/appleapiopts.h>
39
40 #ifdef __APPLE_API_UNSTABLE
41 #include <sys/types.h>
42 #include <sys/ucred.h>
43 #include <sys/time.h>
44 #include <sys/cdefs.h>
45
46 #define FSOPT_NOFOLLOW 0x00000001
47 #define FSOPT_NOINMEMUPDATE 0x00000002
48 #define FSOPT_REPORT_FULLSIZE 0x00000004
49 /* The following option only valid when requesting ATTR_CMN_RETURNED_ATTRS */
50 #define FSOPT_PACK_INVAL_ATTRS 0x00000008
51
52 /* we currently aren't anywhere near this amount for a valid
53 * fssearchblock.sizeofsearchparams1 or fssearchblock.sizeofsearchparams2
54 * but we put a sanity check in to avoid abuse of the value passed in from
55 * user land.
56 */
57 #define SEARCHFS_MAX_SEARCHPARMS 4096
58
59 typedef u_int32_t text_encoding_t;
60
61 typedef u_int32_t fsobj_type_t;
62
63 typedef u_int32_t fsobj_tag_t;
64
65 typedef u_int32_t fsfile_type_t;
66
67 typedef u_int32_t fsvolid_t;
68
69 typedef struct fsobj_id {
70 u_int32_t fid_objno;
71 u_int32_t fid_generation;
72 } fsobj_id_t;
73
74 typedef u_int32_t attrgroup_t;
75
76 struct attrlist {
77 u_short bitmapcount; /* number of attr. bit sets in list (should be 5) */
78 u_int16_t reserved; /* (to maintain 4-byte alignment) */
79 attrgroup_t commonattr; /* common attribute group */
80 attrgroup_t volattr; /* Volume attribute group */
81 attrgroup_t dirattr; /* directory attribute group */
82 attrgroup_t fileattr; /* file attribute group */
83 attrgroup_t forkattr; /* fork attribute group */
84 };
85 #define ATTR_BIT_MAP_COUNT 5
86
87 typedef struct attribute_set {
88 attrgroup_t commonattr; /* common attribute group */
89 attrgroup_t volattr; /* Volume attribute group */
90 attrgroup_t dirattr; /* directory attribute group */
91 attrgroup_t fileattr; /* file attribute group */
92 attrgroup_t forkattr; /* fork attribute group */
93 } attribute_set_t;
94
95 typedef struct attrreference {
96 int32_t attr_dataoffset;
97 u_int32_t attr_length;
98 } attrreference_t;
99
100 /* XXX PPD This is derived from HFSVolumePriv.h and should perhaps be referenced from there? */
101
102 struct diskextent {
103 u_int32_t startblock; /* first block allocated */
104 u_int32_t blockcount; /* number of blocks allocated */
105 };
106
107 typedef struct diskextent extentrecord[8];
108
109 typedef u_int32_t vol_capabilities_set_t[4];
110
111 #define VOL_CAPABILITIES_FORMAT 0
112 #define VOL_CAPABILITIES_INTERFACES 1
113 #define VOL_CAPABILITIES_RESERVED1 2
114 #define VOL_CAPABILITIES_RESERVED2 3
115
116 typedef struct vol_capabilities_attr {
117 vol_capabilities_set_t capabilities;
118 vol_capabilities_set_t valid;
119 } vol_capabilities_attr_t;
120
121 /*
122 * XXX this value needs to be raised - 3893388
123 */
124 #define ATTR_MAX_BUFFER 8192
125
126 /*
127 * VOL_CAP_FMT_PERSISTENTOBJECTIDS: When set, the volume has object IDs
128 * that are persistent (retain their values even when the volume is
129 * unmounted and remounted), and a file or directory can be looked up
130 * by ID. Volumes that support VolFS and can support Carbon File ID
131 * references should set this bit.
132 *
133 * VOL_CAP_FMT_SYMBOLICLINKS: When set, the volume supports symbolic
134 * links. The symlink(), readlink(), and lstat() calls all use this
135 * symbolic link.
136 *
137 * VOL_CAP_FMT_HARDLINKS: When set, the volume supports hard links.
138 * The link() call creates hard links.
139 *
140 * VOL_CAP_FMT_JOURNAL: When set, the volume is capable of supporting
141 * a journal used to speed recovery in case of unplanned shutdown
142 * (such as a power outage or crash). This bit does not necessarily
143 * mean the volume is actively using a journal for recovery.
144 *
145 * VOL_CAP_FMT_JOURNAL_ACTIVE: When set, the volume is currently using
146 * a journal for use in speeding recovery after an unplanned shutdown.
147 * This bit can be set only if VOL_CAP_FMT_JOURNAL is also set.
148 *
149 * VOL_CAP_FMT_NO_ROOT_TIMES: When set, the volume format does not
150 * store reliable times for the root directory, so you should not
151 * depend on them to detect changes, etc.
152 *
153 * VOL_CAP_FMT_SPARSE_FILES: When set, the volume supports sparse files.
154 * That is, files which can have "holes" that have never been written
155 * to, and are not allocated on disk. Sparse files may have an
156 * allocated size that is less than the file's logical length.
157 *
158 * VOL_CAP_FMT_ZERO_RUNS: For security reasons, parts of a file (runs)
159 * that have never been written to must appear to contain zeroes. When
160 * this bit is set, the volume keeps track of allocated but unwritten
161 * runs of a file so that it can substitute zeroes without actually
162 * writing zeroes to the media. This provides performance similar to
163 * sparse files, but not the space savings.
164 *
165 * VOL_CAP_FMT_CASE_SENSITIVE: When set, file and directory names are
166 * case sensitive (upper and lower case are different). When clear,
167 * an upper case character is equivalent to a lower case character,
168 * and you can't have two names that differ solely in the case of
169 * the characters.
170 *
171 * VOL_CAP_FMT_CASE_PRESERVING: When set, file and directory names
172 * preserve the difference between upper and lower case. If clear,
173 * the volume may change the case of some characters (typically
174 * making them all upper or all lower case). A volume that sets
175 * VOL_CAP_FMT_CASE_SENSITIVE should also set VOL_CAP_FMT_CASE_PRESERVING.
176 *
177 * VOL_CAP_FMT_FAST_STATFS: This bit is used as a hint to upper layers
178 * (especially Carbon) that statfs() is fast enough that its results
179 * need not be cached by those upper layers. A volume that caches
180 * the statfs information in its in-memory structures should set this bit.
181 * A volume that must always read from disk or always perform a network
182 * transaction should not set this bit.
183 *
184 * VOL_CAP_FMT_2TB_FILESIZE: If this bit is set the volume format supports
185 * file sizes larger than 4GB, and potentially up to 2TB; it does not
186 * indicate whether the filesystem supports files larger than that.
187 *
188 * VOL_CAP_FMT_OPENDENYMODES: When set, the volume supports open deny
189 * modes (e.g. "open for read write, deny write"; effectively, mandatory
190 * file locking based on open modes).
191 *
192 * VOL_CAP_FMT_HIDDEN_FILES: When set, the volume supports the UF_HIDDEN
193 * file flag, and the UF_HIDDEN flag is mapped to that volume's native
194 * "hidden" or "invisible" bit (which may be the invisible bit from the
195 * Finder Info extended attribute).
196 *
197 * VOL_CAP_FMT_PATH_FROM_ID: When set, the volume supports the ability
198 * to derive a pathname to the root of the file system given only the
199 * id of an object. This also implies that object ids on this file
200 * system are persistent and not recycled. This is a very specialized
201 * capability and it is assumed that most file systems will not support
202 * it. Its use is for legacy non-posix APIs like ResolveFileIDRef.
203 *
204 * VOL_CAP_FMT_NO_VOLUME_SIZES: When set, the volume does not support
205 * returning values for total data blocks, available blocks, or free blocks
206 * (as in f_blocks, f_bavail, or f_bfree in "struct statfs"). Historically,
207 * those values were set to 0xFFFFFFFF for volumes that did not support them.
208 *
209 * VOL_CAP_FMT_DECMPFS_COMPRESSION: When set, the volume supports transparent
210 * decompression of compressed files using decmpfs.
211 */
212 #define VOL_CAP_FMT_PERSISTENTOBJECTIDS 0x00000001
213 #define VOL_CAP_FMT_SYMBOLICLINKS 0x00000002
214 #define VOL_CAP_FMT_HARDLINKS 0x00000004
215 #define VOL_CAP_FMT_JOURNAL 0x00000008
216 #define VOL_CAP_FMT_JOURNAL_ACTIVE 0x00000010
217 #define VOL_CAP_FMT_NO_ROOT_TIMES 0x00000020
218 #define VOL_CAP_FMT_SPARSE_FILES 0x00000040
219 #define VOL_CAP_FMT_ZERO_RUNS 0x00000080
220 #define VOL_CAP_FMT_CASE_SENSITIVE 0x00000100
221 #define VOL_CAP_FMT_CASE_PRESERVING 0x00000200
222 #define VOL_CAP_FMT_FAST_STATFS 0x00000400
223 #define VOL_CAP_FMT_2TB_FILESIZE 0x00000800
224 #define VOL_CAP_FMT_OPENDENYMODES 0x00001000
225 #define VOL_CAP_FMT_HIDDEN_FILES 0x00002000
226 #define VOL_CAP_FMT_PATH_FROM_ID 0x00004000
227 #define VOL_CAP_FMT_NO_VOLUME_SIZES 0x00008000
228 #define VOL_CAP_FMT_DECMPFS_COMPRESSION 0x00010000
229
230
231 /*
232 * VOL_CAP_INT_SEARCHFS: When set, the volume implements the
233 * searchfs() system call (the vnop_searchfs vnode operation).
234 *
235 * VOL_CAP_INT_ATTRLIST: When set, the volume implements the
236 * getattrlist() and setattrlist() system calls (vnop_getattrlist
237 * and vnop_setattrlist vnode operations) for the volume, files,
238 * and directories. The volume may or may not implement the
239 * readdirattr() system call. XXX Is there any minimum set
240 * of attributes that should be supported? To determine the
241 * set of supported attributes, get the ATTR_VOL_ATTRIBUTES
242 * attribute of the volume.
243 *
244 * VOL_CAP_INT_NFSEXPORT: When set, the volume implements exporting
245 * of NFS volumes.
246 *
247 * VOL_CAP_INT_READDIRATTR: When set, the volume implements the
248 * readdirattr() system call (vnop_readdirattr vnode operation).
249 *
250 * VOL_CAP_INT_EXCHANGEDATA: When set, the volume implements the
251 * exchangedata() system call (VNOP_EXCHANGE vnode operation).
252 *
253 * VOL_CAP_INT_COPYFILE: When set, the volume implements the
254 * VOP_COPYFILE vnode operation. (XXX There should be a copyfile()
255 * system call in <unistd.h>.)
256 *
257 * VOL_CAP_INT_ALLOCATE: When set, the volume implements the
258 * VNOP_ALLOCATE vnode operation, which means it implements the
259 * F_PREALLOCATE selector of fcntl(2).
260 *
261 * VOL_CAP_INT_VOL_RENAME: When set, the volume implements the
262 * ATTR_VOL_NAME attribute for both getattrlist() and setattrlist().
263 * The volume can be renamed by setting ATTR_VOL_NAME with setattrlist().
264 *
265 * VOL_CAP_INT_ADVLOCK: When set, the volume implements POSIX style
266 * byte range locks via vnop_advlock (accessible from fcntl(2)).
267 *
268 * VOL_CAP_INT_FLOCK: When set, the volume implements whole-file flock(2)
269 * style locks via vnop_advlock. This includes the O_EXLOCK and O_SHLOCK
270 * flags of the open(2) call.
271 *
272 * VOL_CAP_INT_EXTENDED_SECURITY: When set, the volume implements
273 * extended security (ACLs).
274 *
275 * VOL_CAP_INT_USERACCESS: When set, the volume supports the
276 * ATTR_CMN_USERACCESS attribute (used to get the user's access
277 * mode to the file).
278 *
279 * VOL_CAP_INT_MANLOCK: When set, the volume supports AFP-style
280 * mandatory byte range locks via an ioctl().
281 *
282 * VOL_CAP_INT_EXTENDED_ATTR: When set, the volume implements
283 * native extended attribues.
284 *
285 * VOL_CAP_INT_NAMEDSTREAMS: When set, the volume supports
286 * native named streams.
287 */
288 #define VOL_CAP_INT_SEARCHFS 0x00000001
289 #define VOL_CAP_INT_ATTRLIST 0x00000002
290 #define VOL_CAP_INT_NFSEXPORT 0x00000004
291 #define VOL_CAP_INT_READDIRATTR 0x00000008
292 #define VOL_CAP_INT_EXCHANGEDATA 0x00000010
293 #define VOL_CAP_INT_COPYFILE 0x00000020
294 #define VOL_CAP_INT_ALLOCATE 0x00000040
295 #define VOL_CAP_INT_VOL_RENAME 0x00000080
296 #define VOL_CAP_INT_ADVLOCK 0x00000100
297 #define VOL_CAP_INT_FLOCK 0x00000200
298 #define VOL_CAP_INT_EXTENDED_SECURITY 0x00000400
299 #define VOL_CAP_INT_USERACCESS 0x00000800
300 #define VOL_CAP_INT_MANLOCK 0x00001000
301 #define VOL_CAP_INT_NAMEDSTREAMS 0x00002000
302 #define VOL_CAP_INT_EXTENDED_ATTR 0x00004000
303 #ifdef PRIVATE
304 /* Volume supports kqueue notifications for remote events */
305 #define VOL_CAP_INT_REMOTE_EVENT 0x00008000
306 #endif /* PRIVATE */
307
308 typedef struct vol_attributes_attr {
309 attribute_set_t validattr;
310 attribute_set_t nativeattr;
311 } vol_attributes_attr_t;
312
313 #define ATTR_CMN_NAME 0x00000001
314 #define ATTR_CMN_DEVID 0x00000002
315 #define ATTR_CMN_FSID 0x00000004
316 #define ATTR_CMN_OBJTYPE 0x00000008
317 #define ATTR_CMN_OBJTAG 0x00000010
318 #define ATTR_CMN_OBJID 0x00000020
319 #define ATTR_CMN_OBJPERMANENTID 0x00000040
320 #define ATTR_CMN_PAROBJID 0x00000080
321 #define ATTR_CMN_SCRIPT 0x00000100
322 #define ATTR_CMN_CRTIME 0x00000200
323 #define ATTR_CMN_MODTIME 0x00000400
324 #define ATTR_CMN_CHGTIME 0x00000800
325 #define ATTR_CMN_ACCTIME 0x00001000
326 #define ATTR_CMN_BKUPTIME 0x00002000
327 #define ATTR_CMN_FNDRINFO 0x00004000
328 #define ATTR_CMN_OWNERID 0x00008000
329 #define ATTR_CMN_GRPID 0x00010000
330 #define ATTR_CMN_ACCESSMASK 0x00020000
331 #define ATTR_CMN_FLAGS 0x00040000
332 /* #define ATTR_CMN_NAMEDATTRCOUNT 0x00080000 not implemented */
333 /* #define ATTR_CMN_NAMEDATTRLIST 0x00100000 not implemented */
334 #define ATTR_CMN_USERACCESS 0x00200000
335 #define ATTR_CMN_EXTENDED_SECURITY 0x00400000
336 #define ATTR_CMN_UUID 0x00800000
337 #define ATTR_CMN_GRPUUID 0x01000000
338 #define ATTR_CMN_FILEID 0x02000000
339 #define ATTR_CMN_PARENTID 0x04000000
340 #define ATTR_CMN_FULLPATH 0x08000000
341 /*
342 * ATTR_CMN_RETURNED_ATTRS is only valid with getattrlist(2).
343 * It is always the first attribute in the return buffer.
344 */
345 #define ATTR_CMN_RETURNED_ATTRS 0x80000000
346
347 #define ATTR_CMN_VALIDMASK 0x8FE7FFFF
348 #define ATTR_CMN_SETMASK 0x01C7FF00
349 #define ATTR_CMN_VOLSETMASK 0x00006700
350
351 #define ATTR_VOL_FSTYPE 0x00000001
352 #define ATTR_VOL_SIGNATURE 0x00000002
353 #define ATTR_VOL_SIZE 0x00000004
354 #define ATTR_VOL_SPACEFREE 0x00000008
355 #define ATTR_VOL_SPACEAVAIL 0x00000010
356 #define ATTR_VOL_MINALLOCATION 0x00000020
357 #define ATTR_VOL_ALLOCATIONCLUMP 0x00000040
358 #define ATTR_VOL_IOBLOCKSIZE 0x00000080
359 #define ATTR_VOL_OBJCOUNT 0x00000100
360 #define ATTR_VOL_FILECOUNT 0x00000200
361 #define ATTR_VOL_DIRCOUNT 0x00000400
362 #define ATTR_VOL_MAXOBJCOUNT 0x00000800
363 #define ATTR_VOL_MOUNTPOINT 0x00001000
364 #define ATTR_VOL_NAME 0x00002000
365 #define ATTR_VOL_MOUNTFLAGS 0x00004000
366 #define ATTR_VOL_MOUNTEDDEVICE 0x00008000
367 #define ATTR_VOL_ENCODINGSUSED 0x00010000
368 #define ATTR_VOL_CAPABILITIES 0x00020000
369 #define ATTR_VOL_UUID 0x00040000
370 #define ATTR_VOL_ATTRIBUTES 0x40000000
371 #define ATTR_VOL_INFO 0x80000000
372
373 #define ATTR_VOL_VALIDMASK 0xC007FFFF
374 #define ATTR_VOL_SETMASK 0x80002000
375
376
377 /* File/directory attributes: */
378 #define ATTR_DIR_LINKCOUNT 0x00000001
379 #define ATTR_DIR_ENTRYCOUNT 0x00000002
380 #define ATTR_DIR_MOUNTSTATUS 0x00000004
381 #define DIR_MNTSTATUS_MNTPOINT 0x00000001
382
383 #define ATTR_DIR_VALIDMASK 0x00000007
384 #define ATTR_DIR_SETMASK 0x00000000
385
386 #define ATTR_FILE_LINKCOUNT 0x00000001
387 #define ATTR_FILE_TOTALSIZE 0x00000002
388 #define ATTR_FILE_ALLOCSIZE 0x00000004
389 #define ATTR_FILE_IOBLOCKSIZE 0x00000008
390 #define ATTR_FILE_DEVTYPE 0x00000020
391 #define ATTR_FILE_FORKCOUNT 0x00000080
392 #define ATTR_FILE_FORKLIST 0x00000100
393 #define ATTR_FILE_DATALENGTH 0x00000200
394 #define ATTR_FILE_DATAALLOCSIZE 0x00000400
395 #define ATTR_FILE_RSRCLENGTH 0x00001000
396 #define ATTR_FILE_RSRCALLOCSIZE 0x00002000
397 /* Only used when CONFIG_PROTECT is ON */
398 #define ATTR_FILE_PROTECTION_CLASS 0x00004000
399
400 #define ATTR_FILE_VALIDMASK 0x000077FF
401 #define ATTR_FILE_SETMASK 0x00004020
402
403 #define ATTR_FORK_TOTALSIZE 0x00000001
404 #define ATTR_FORK_ALLOCSIZE 0x00000002
405
406 #define ATTR_FORK_VALIDMASK 0x00000003
407 #define ATTR_FORK_SETMASK 0x00000000
408
409 /* Obsolete, implemented, not supported */
410 #define ATTR_CMN_NAMEDATTRCOUNT 0x00080000 /* not implemented */
411 #define ATTR_CMN_NAMEDATTRLIST 0x00100000 /* not implemented */
412 #define ATTR_FILE_CLUMPSIZE 0x00000010 /* obsolete */
413 #define ATTR_FILE_FILETYPE 0x00000040 /* always zero */
414 #define ATTR_FILE_DATAEXTENTS 0x00000800 /* obsolete, HFS-specific */
415 #define ATTR_FILE_RSRCEXTENTS 0x00004000 /* obsolete, HFS-specific */
416
417 /*
418 * Searchfs
419 */
420 #define SRCHFS_START 0x00000001
421 #define SRCHFS_MATCHPARTIALNAMES 0x00000002
422 #define SRCHFS_MATCHDIRS 0x00000004
423 #define SRCHFS_MATCHFILES 0x00000008
424 #define SRCHFS_SKIPLINKS 0x00000010
425 #define SRCHFS_SKIPINVISIBLE 0x00000020
426 #define SRCHFS_SKIPPACKAGES 0x00000040
427 #define SRCHFS_SKIPINAPPROPRIATE 0x00000080
428
429 #define SRCHFS_NEGATEPARAMS 0x80000000
430 #define SRCHFS_VALIDOPTIONSMASK 0x800000FF
431
432 struct fssearchblock {
433 struct attrlist *returnattrs;
434 void *returnbuffer;
435 size_t returnbuffersize;
436 u_long maxmatches;
437 struct timeval timelimit;
438 void *searchparams1;
439 size_t sizeofsearchparams1;
440 void *searchparams2;
441 size_t sizeofsearchparams2;
442 struct attrlist searchattrs;
443 };
444
445 #ifdef KERNEL
446 /* LP64 version of fssearchblock. all pointers and longs
447 * grow when we're dealing with a 64-bit process.
448 * WARNING - keep in sync with fssearchblock
449 */
450
451 struct user64_fssearchblock {
452 user64_addr_t returnattrs;
453 user64_addr_t returnbuffer;
454 user64_size_t returnbuffersize;
455 user64_ulong_t maxmatches;
456 struct user64_timeval timelimit;
457 user64_addr_t searchparams1;
458 user64_size_t sizeofsearchparams1;
459 user64_addr_t searchparams2;
460 user64_size_t sizeofsearchparams2;
461 struct attrlist searchattrs;
462 };
463
464 struct user32_fssearchblock {
465 user32_addr_t returnattrs;
466 user32_addr_t returnbuffer;
467 user32_size_t returnbuffersize;
468 user32_ulong_t maxmatches;
469 struct user32_timeval timelimit;
470 user32_addr_t searchparams1;
471 user32_size_t sizeofsearchparams1;
472 user32_addr_t searchparams2;
473 user32_size_t sizeofsearchparams2;
474 struct attrlist searchattrs;
475 };
476
477 #endif /* KERNEL */
478
479
480 struct searchstate {
481 u_char reserved[556]; // sizeof( SearchState )
482 };
483
484
485 #define FST_EOF (-1) /* end-of-file offset */
486
487 #endif /* __APPLE_API_UNSTABLE */
488 #endif /* !_SYS_ATTR_H_ */