1 | /* |
2 | * Copyright (c) 2000-2024 Apple 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 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ |
29 | /* |
30 | * Copyright (c) 1989, 1993 |
31 | * The Regents of the University of California. All rights reserved. |
32 | * |
33 | * Redistribution and use in source and binary forms, with or without |
34 | * modification, are permitted provided that the following conditions |
35 | * are met: |
36 | * 1. Redistributions of source code must retain the above copyright |
37 | * notice, this list of conditions and the following disclaimer. |
38 | * 2. Redistributions in binary form must reproduce the above copyright |
39 | * notice, this list of conditions and the following disclaimer in the |
40 | * documentation and/or other materials provided with the distribution. |
41 | * 3. All advertising materials mentioning features or use of this software |
42 | * must display the following acknowledgement: |
43 | * This product includes software developed by the University of |
44 | * California, Berkeley and its contributors. |
45 | * 4. Neither the name of the University nor the names of its contributors |
46 | * may be used to endorse or promote products derived from this software |
47 | * without specific prior written permission. |
48 | * |
49 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
50 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
51 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
59 | * SUCH DAMAGE. |
60 | * |
61 | * @(#)vnode.h 8.17 (Berkeley) 5/20/95 |
62 | */ |
63 | |
64 | #ifndef _VNODE_H_ |
65 | #define _VNODE_H_ |
66 | |
67 | #include <stdint.h> |
68 | #include <sys/appleapiopts.h> |
69 | #include <sys/cdefs.h> |
70 | #ifdef KERNEL |
71 | #include <sys/kernel_types.h> |
72 | #include <sys/param.h> |
73 | #include <sys/signal.h> |
74 | #ifdef KERNEL_PRIVATE |
75 | #include <mach/mach_types.h> |
76 | #endif /* KERNEL_PRIVATE */ |
77 | #else |
78 | #include <stdint.h> |
79 | #endif /* KERNEL */ |
80 | |
81 | /* |
82 | * The vnode is the focus of all file activity in UNIX. There is a |
83 | * unique vnode allocated for each active file, each current directory, |
84 | * each mounted-on file, text file, and the root. |
85 | */ |
86 | |
87 | /* |
88 | * Vnode types. VNON means no type. |
89 | */ |
90 | enum vtype { |
91 | /* 0 */ |
92 | VNON, |
93 | /* 1 - 5 */ |
94 | VREG, VDIR, VBLK, VCHR, VLNK, |
95 | /* 6 - 10 */ |
96 | VSOCK, VFIFO, VBAD, VSTR, VCPLX |
97 | }; |
98 | |
99 | /* |
100 | * Vnode tag types. |
101 | * These are for the benefit of external programs only (e.g., pstat) |
102 | * and should NEVER be inspected by the kernel. |
103 | */ |
104 | enum vtagtype { |
105 | /* 0 */ |
106 | VT_NON, |
107 | /* 1 reserved, overlaps with (CTL_VFS, VFS_NUMMNTOPS) */ |
108 | VT_UFS, |
109 | /* 2 - 5 */ |
110 | VT_NFS, VT_MFS, VT_MSDOSFS, VT_LFS, |
111 | /* 6 - 10 */ |
112 | VT_LOFS, VT_FDESC, VT_PORTAL, VT_NULL, VT_UMAP, |
113 | /* 11 - 15 */ |
114 | VT_KERNFS, VT_PROCFS, VT_AFS, VT_ISOFS, VT_MOCKFS, |
115 | /* 16 - 20 */ |
116 | VT_HFS, VT_ZFS, VT_DEVFS, VT_WEBDAV, VT_UDF, |
117 | /* 21 - 25 */ |
118 | VT_AFP, VT_CDDA, VT_CIFS, VT_OTHER, VT_APFS, |
119 | /* 26 - 27*/ |
120 | VT_LOCKERFS, VT_BINDFS, |
121 | }; |
122 | |
123 | #define HAVE_VT_LOCKERFS 1 |
124 | |
125 | /* |
126 | * flags for VNOP_BLOCKMAP |
127 | */ |
128 | #define VNODE_READ 0x01 |
129 | #define VNODE_WRITE 0x02 |
130 | #define VNODE_BLOCKMAP_NO_TRACK 0x04 // APFS Fusion: Do not track this request |
131 | #define VNODE_CLUSTER_VERIFY 0x08 // Verification will be performed in the cluster layer |
132 | |
133 | |
134 | /* flags for VNOP_ALLOCATE */ |
135 | #define PREALLOCATE 0x00000001 /* preallocate allocation blocks */ |
136 | #define ALLOCATECONTIG 0x00000002 /* allocate contigious space */ |
137 | #define ALLOCATEALL 0x00000004 /* allocate all requested space */ |
138 | /* or no space at all */ |
139 | #define ALLOCATEPERSIST 0x00000008 /* do not deallocate allocated but unfilled blocks at close(2) */ |
140 | #define ALLOCATEFROMPEOF 0x00000010 /* allocate from the physical eof */ |
141 | #define ALLOCATEFROMVOL 0x00000020 /* allocate from the volume offset */ |
142 | |
143 | /* |
144 | * Token indicating no attribute value yet assigned. some user source uses this |
145 | */ |
146 | #define VNOVAL (-1) |
147 | |
148 | |
149 | #ifdef KERNEL |
150 | |
151 | /* |
152 | * Flags for ioflag. |
153 | */ |
154 | #define IO_UNIT 0x0001 /* do I/O as atomic unit */ |
155 | #define IO_APPEND 0x0002 /* append write to end */ |
156 | #define IO_SYNC 0x0004 /* do I/O synchronously */ |
157 | #define IO_NODELOCKED 0x0008 /* underlying node already locked */ |
158 | #define IO_NDELAY 0x0010 /* FNDELAY flag set in file table */ |
159 | #define IO_NOZEROFILL 0x0020 /* F_SETSIZE fcntl uses to prevent zero filling */ |
160 | #ifdef XNU_KERNEL_PRIVATE |
161 | #define IO_REVOKE IO_NOZEROFILL /* revoked close for tty, will Not be used in conjunction */ |
162 | #endif /* XNU_KERNEL_PRIVATE */ |
163 | #define IO_TAILZEROFILL 0x0040 /* zero fills at the tail of write */ |
164 | #define IO_HEADZEROFILL 0x0080 /* zero fills at the head of write */ |
165 | #define IO_NOZEROVALID 0x0100 /* do not zero fill if valid page */ |
166 | #define IO_NOZERODIRTY 0x0200 /* do not zero fill if page is dirty */ |
167 | #define IO_CLOSE 0x0400 /* I/O issued from close path */ |
168 | #define IO_NOCACHE 0x0800 /* same effect as VNOCACHE_DATA, but only for this 1 I/O */ |
169 | #define IO_RAOFF 0x1000 /* same effect as VRAOFF, but only for this 1 I/O */ |
170 | #define IO_DEFWRITE 0x2000 /* defer write if vfs.defwrite is set */ |
171 | #define IO_PASSIVE 0x4000 /* this I/O is marked as background I/O so it won't throttle Throttleable I/O */ |
172 | #define IO_BACKGROUND IO_PASSIVE /* used for backward compatibility. to be removed after IO_BACKGROUND is no longer |
173 | * used by DiskImages in-kernel mode */ |
174 | #define IO_NOAUTH 0x8000 /* No authorization checks. */ |
175 | #define IO_NODIRECT 0x10000 /* don't use direct synchronous writes if IO_NOCACHE is specified */ |
176 | #define IO_ENCRYPTED 0x20000 /* Retrieve encrypted blocks from the filesystem */ |
177 | #define IO_RETURN_ON_THROTTLE 0x40000 |
178 | #define IO_SINGLE_WRITER 0x80000 |
179 | #define IO_SYSCALL_DISPATCH 0x100000 /* I/O was originated from a file table syscall */ |
180 | #define IO_SWAP_DISPATCH 0x200000 /* I/O was originated from the swap layer */ |
181 | #define IO_SKIP_ENCRYPTION 0x400000 /* Skips en(de)cryption on the IO. Must be initiated from kernel */ |
182 | #define IO_EVTONLY 0x800000 /* the i/o is being done on an fd that's marked O_EVTONLY */ |
183 | |
184 | /* |
185 | * Component Name: this structure describes the pathname |
186 | * information that is passed through the VNOP interface. |
187 | */ |
188 | struct componentname { |
189 | /* |
190 | * Arguments to lookup. |
191 | */ |
192 | uint32_t cn_nameiop; /* lookup operation */ |
193 | uint32_t cn_flags; /* flags (see below) */ |
194 | #ifdef BSD_KERNEL_PRIVATE |
195 | vfs_context_t cn_context; |
196 | struct nameidata *cn_ndp; /* pointer back to nameidata */ |
197 | |
198 | /* XXX use of these defines are deprecated */ |
199 | #define cn_proc (cn_context->vc_proc + 0) /* non-lvalue */ |
200 | #define cn_cred (cn_context->vc_ucred + 0) /* non-lvalue */ |
201 | |
202 | #else |
203 | void * cn_reserved1; /* use vfs_context_t */ |
204 | void * cn_reserved2; /* use vfs_context_t */ |
205 | #endif |
206 | /* |
207 | * Shared between lookup and commit routines. |
208 | */ |
209 | char *cn_pnbuf; /* pathname buffer */ |
210 | int cn_pnlen; /* length of allocated buffer */ |
211 | char *cn_nameptr; /* pointer to looked up name */ |
212 | int cn_namelen; /* length of looked up component */ |
213 | uint32_t cn_hash; /* hash value of looked up name */ |
214 | uint32_t cn_consume; /* chars to consume in lookup() */ |
215 | }; |
216 | |
217 | /* |
218 | * component name operations (for VNOP_LOOKUP) |
219 | */ |
220 | #define LOOKUP 0 /* perform name lookup only */ |
221 | #define CREATE 1 /* setup for file creation */ |
222 | #define DELETE 2 /* setup for file deletion */ |
223 | #define RENAME 3 /* setup for file renaming */ |
224 | #define OPMASK 3 /* mask for operation */ |
225 | |
226 | /* |
227 | * component name operational modifier flags |
228 | */ |
229 | #define FOLLOW 0x00000040 /* follow symbolic links */ |
230 | |
231 | /* |
232 | * component name parameter descriptors. |
233 | */ |
234 | #define ISDOTDOT 0x00002000 /* current component name is .. */ |
235 | #define MAKEENTRY 0x00004000 /* entry is to be added to name cache */ |
236 | #define ISLASTCN 0x00008000 /* this is last component of pathname */ |
237 | |
238 | /* The following structure specifies a vnode for creation */ |
239 | struct vnode_fsparam { |
240 | struct mount * vnfs_mp; /* mount point to which this vnode_t is part of */ |
241 | enum vtype vnfs_vtype; /* vnode type */ |
242 | const char * vnfs_str; /* File system Debug aid */ |
243 | struct vnode * vnfs_dvp; /* The parent vnode */ |
244 | void * vnfs_fsnode; /* inode */ |
245 | int(**vnfs_vops)(void *); /* vnode dispatch table */ |
246 | int vnfs_markroot; /* is this a root vnode in FS (not a system wide one) */ |
247 | int vnfs_marksystem; /* is a system vnode */ |
248 | dev_t vnfs_rdev; /* dev_t for block or char vnodes */ |
249 | off_t vnfs_filesize; /* that way no need for getattr in UBC */ |
250 | struct componentname * vnfs_cnp; /* component name to add to namecache */ |
251 | uint32_t vnfs_flags; /* flags */ |
252 | }; |
253 | |
254 | #define VNFS_NOCACHE 0x01 /* do not add to name cache at this time */ |
255 | #define VNFS_CANTCACHE 0x02 /* never add this instance to the name cache */ |
256 | #define VNFS_ADDFSREF 0x04 /* take fs (named) reference */ |
257 | |
258 | #define VNCREATE_FLAVOR 0 |
259 | #define VCREATESIZE sizeof(struct vnode_fsparam) |
260 | #ifdef KERNEL_PRIVATE |
261 | /* |
262 | * For use with SPI to create trigger vnodes. |
263 | */ |
264 | struct vnode_trigger_param; |
265 | #define VNCREATE_TRIGGER (('T' << 8) + ('V')) |
266 | #define VNCREATE_TRIGGER_SIZE sizeof(struct vnode_trigger_param) |
267 | #endif /* KERNEL_PRIVATE */ |
268 | |
269 | |
270 | #ifdef KERNEL_PRIVATE |
271 | /* |
272 | * Resolver callback SPI for trigger vnodes |
273 | * |
274 | * Only available from kernels built with CONFIG_TRIGGERS option |
275 | */ |
276 | |
277 | /*! |
278 | * @enum Pathname Lookup Operations |
279 | * @abstract Constants defining pathname operations (passed to resolver callbacks) |
280 | */ |
281 | enum path_operation { |
282 | OP_LOOKUP, |
283 | OP_MOUNT, |
284 | OP_UNMOUNT, |
285 | OP_STATFS, |
286 | OP_OPEN, |
287 | OP_LINK, |
288 | OP_UNLINK, |
289 | OP_RENAME, |
290 | OP_CHDIR, |
291 | OP_CHROOT, |
292 | OP_MKNOD, |
293 | OP_MKFIFO, |
294 | OP_SYMLINK, |
295 | OP_ACCESS, |
296 | OP_PATHCONF, |
297 | OP_READLINK, |
298 | OP_GETATTR, |
299 | OP_SETATTR, |
300 | OP_TRUNCATE, |
301 | OP_COPYFILE, |
302 | OP_MKDIR, |
303 | OP_RMDIR, |
304 | OP_REVOKE, |
305 | OP_EXCHANGEDATA, |
306 | OP_SEARCHFS, |
307 | OP_FSCTL, |
308 | OP_GETXATTR, |
309 | OP_SETXATTR, |
310 | OP_REMOVEXATTR, |
311 | OP_LISTXATTR, |
312 | OP_MAXOP /* anything beyond previous entry is invalid */ |
313 | }; |
314 | |
315 | /*! |
316 | * @enum resolver status |
317 | * @abstract Constants defining resolver status |
318 | * @constant RESOLVER_RESOLVED the resolver has finished (typically means a successful mount) |
319 | * @constant RESOLVER_NOCHANGE the resolver status didn't change |
320 | * @constant RESOLVER_UNRESOLVED the resolver has finished (typically means a successful unmount) |
321 | * @constant RESOLVER_ERROR the resolver encountered an error (errno passed in aux value) |
322 | * @constant RESOLVER_STOP a request to destroy trigger XXX do we need this??? |
323 | */ |
324 | enum resolver_status { |
325 | RESOLVER_RESOLVED, |
326 | RESOLVER_NOCHANGE, |
327 | RESOLVER_UNRESOLVED, |
328 | RESOLVER_ERROR, |
329 | RESOLVER_STOP |
330 | }; |
331 | |
332 | typedef uint64_t resolver_result_t; |
333 | |
334 | /* |
335 | * Compound resolver result |
336 | * |
337 | * The trigger vnode callbacks use a compound result value. In addition |
338 | * to the resolver status, it contains a sequence number and an auxiliary |
339 | * value. |
340 | * |
341 | * The sequence value is used by VFS to sequence-stamp trigger vnode |
342 | * state transitions. It is expected to be incremented each time a |
343 | * resolver changes state (ie resolved or unresolved). A result |
344 | * containing a stale sequence (older than a trigger vnode's current |
345 | * value) will be ignored by VFS. |
346 | * |
347 | * The auxiliary value is currently only used to deliver the errno |
348 | * value for RESOLVER_ERROR status conditions. When a RESOLVER_ERROR |
349 | * occurs, VFS will propagate this error back to the syscall that |
350 | * encountered the trigger vnode. |
351 | */ |
352 | extern resolver_result_t vfs_resolver_result(uint32_t seq, enum resolver_status stat, int aux); |
353 | |
354 | /* |
355 | * Extract values from a compound resolver result |
356 | */ |
357 | extern enum resolver_status vfs_resolver_status(resolver_result_t); |
358 | extern uint32_t vfs_resolver_sequence(resolver_result_t); |
359 | extern int vfs_resolver_auxiliary(resolver_result_t); |
360 | |
361 | |
362 | /*! |
363 | * @typedef trigger_vnode_resolve_callback_t |
364 | * @abstract function prototype for a trigger vnode resolve callback |
365 | * @discussion This function is associated with a trigger vnode during a vnode create. It is |
366 | * typically called when a lookup operation occurs for a trigger vnode |
367 | * @param vp The trigger vnode which needs resolving |
368 | * @param cnp Various data about lookup, e.g. filename and state flags |
369 | * @param pop The pathname operation that initiated the lookup (see enum path_operation). |
370 | * @param flags resolve flags |
371 | * @param data Arbitrary data supplied by vnode trigger creator |
372 | * @param ctx Context for authentication. |
373 | * @return RESOLVER_RESOLVED, RESOLVER_NOCHANGE, RESOLVER_UNRESOLVED or RESOLVER_ERROR |
374 | */ |
375 | typedef resolver_result_t (* trigger_vnode_resolve_callback_t)( |
376 | vnode_t vp, |
377 | const struct componentname * cnp, |
378 | enum path_operation pop, |
379 | int flags, |
380 | void * data, |
381 | vfs_context_t ctx); |
382 | |
383 | /*! |
384 | * @typedef trigger_vnode_unresolve_callback_t |
385 | * @abstract function prototype for a trigger vnode unresolve callback |
386 | * @discussion This function is associated with a trigger vnode during a vnode create. It is |
387 | * called to unresolve a trigger vnode (typically this means unmount). |
388 | * @param vp The trigger vnode which needs unresolving |
389 | * @param flags Unmount flags |
390 | * @param data Arbitrary data supplied by vnode trigger creator |
391 | * @param ctx Context for authentication. |
392 | * @return RESOLVER_NOCHANGE, RESOLVER_UNRESOLVED or RESOLVER_ERROR |
393 | */ |
394 | typedef resolver_result_t (* trigger_vnode_unresolve_callback_t)( |
395 | vnode_t vp, |
396 | int flags, |
397 | void * data, |
398 | vfs_context_t ctx); |
399 | |
400 | /*! |
401 | * @typedef trigger_vnode_rearm_callback_t |
402 | * @abstract function prototype for a trigger vnode rearm callback |
403 | * @discussion This function is associated with a trigger vnode during a vnode create. It is |
404 | * called to verify a rearm from VFS (i.e. should VFS rearm the trigger?). |
405 | * @param vp The trigger vnode which needs rearming |
406 | * @param flags rearm flags |
407 | * @param data Arbitrary data supplied by vnode trigger creator |
408 | * @param ctx Context for authentication. |
409 | * @return RESOLVER_NOCHANGE or RESOLVER_ERROR |
410 | */ |
411 | typedef resolver_result_t (* trigger_vnode_rearm_callback_t)( |
412 | vnode_t vp, |
413 | int flags, |
414 | void * data, |
415 | vfs_context_t ctx); |
416 | |
417 | /*! |
418 | * @typedef trigger_vnode_reclaim_callback_t |
419 | * @abstract function prototype for a trigger vnode reclaim callback |
420 | * @discussion This function is associated with a trigger vnode during a vnode create. It is |
421 | * called to deallocate private callback argument data |
422 | * @param vp The trigger vnode associated with the data |
423 | * @param data The arbitrary data supplied by vnode trigger creator |
424 | */ |
425 | typedef void (* trigger_vnode_reclaim_callback_t)( |
426 | vnode_t vp, |
427 | void * data); |
428 | |
429 | /*! |
430 | * @function vnode_trigger_update |
431 | * @abstract Update a trigger vnode's state. |
432 | * @discussion This allows a resolver to notify VFS of a state change in a trigger vnode. |
433 | * @param vp The trigger vnode whose information to update. |
434 | * @param result A compound resolver result value |
435 | * @return EINVAL if result value is invalid or vp isn't a trigger vnode |
436 | */ |
437 | extern int vnode_trigger_update(vnode_t vp, resolver_result_t result); |
438 | |
439 | struct vnode_trigger_info { |
440 | trigger_vnode_resolve_callback_t vti_resolve_func; |
441 | trigger_vnode_unresolve_callback_t vti_unresolve_func; |
442 | trigger_vnode_rearm_callback_t vti_rearm_func; |
443 | trigger_vnode_reclaim_callback_t vti_reclaim_func; |
444 | void * vti_data; /* auxiliary data (optional) */ |
445 | uint32_t vti_flags; /* optional flags (see below) */ |
446 | }; |
447 | |
448 | /* |
449 | * SPI for creating a trigger vnode |
450 | * |
451 | * Uses the VNCREATE_TRIGGER flavor with existing vnode_create() KPI |
452 | * |
453 | * Only one resolver per vnode. |
454 | * |
455 | * ERRORS (in addition to vnode_create errors): |
456 | * EINVAL (invalid resolver info, like invalid flags) |
457 | * ENOTDIR (only directories can have a resolver) |
458 | * EPERM (vnode cannot be a trigger - eg root dir of a file system) |
459 | * ENOMEM |
460 | */ |
461 | struct vnode_trigger_param { |
462 | struct vnode_fsparam vnt_params; /* same as for VNCREATE_FLAVOR */ |
463 | trigger_vnode_resolve_callback_t vnt_resolve_func; |
464 | trigger_vnode_unresolve_callback_t vnt_unresolve_func; |
465 | trigger_vnode_rearm_callback_t vnt_rearm_func; |
466 | trigger_vnode_reclaim_callback_t vnt_reclaim_func; |
467 | void * vnt_data; /* auxiliary data (optional) */ |
468 | uint32_t vnt_flags; /* optional flags (see below) */ |
469 | }; |
470 | |
471 | /* |
472 | * vnode trigger flags (vnt_flags) |
473 | * |
474 | * VNT_AUTO_REARM: |
475 | * On unmounts of a trigger mount, automatically re-arm the trigger. |
476 | * |
477 | * VNT_NO_DIRECT_MOUNT: |
478 | * A trigger vnode instance that doesn't directly trigger a mount, |
479 | * instead it triggers the mounting of sub-trigger nodes. |
480 | * |
481 | * VNT_KERN_RESOLVE: |
482 | * A trigger vnode where all parameters have been set by the kernel, |
483 | * such as NFS mirror mounts. |
484 | */ |
485 | #define VNT_AUTO_REARM (1 << 0) |
486 | #define VNT_NO_DIRECT_MOUNT (1 << 1) |
487 | #define VNT_KERN_RESOLVE (1 << 2) |
488 | #define VNT_VALID_MASK (VNT_AUTO_REARM | VNT_NO_DIRECT_MOUNT | \ |
489 | VNT_KERN_RESOLVE) |
490 | |
491 | #endif /* KERNEL_PRIVATE */ |
492 | |
493 | |
494 | /* |
495 | * Vnode attributes, new-style. |
496 | * |
497 | * The vnode_attr structure is used to transact attribute changes and queries |
498 | * with the filesystem. |
499 | * |
500 | * Note that this structure may be extended, but existing fields must not move. |
501 | */ |
502 | |
503 | #define VATTR_INIT(v) do {(v)->va_supported = (v)->va_active = 0ll; (v)->va_vaflags = 0; } while(0) |
504 | #define VATTR_SET_ACTIVE(v, a) ((v)->va_active |= VNODE_ATTR_ ## a) |
505 | #define VATTR_SET_SUPPORTED(v, a) ((v)->va_supported |= VNODE_ATTR_ ## a) |
506 | #define VATTR_IS_SUPPORTED(v, a) ((v)->va_supported & VNODE_ATTR_ ## a) |
507 | #define VATTR_CLEAR_ACTIVE(v, a) ((v)->va_active &= ~VNODE_ATTR_ ## a) |
508 | #define VATTR_CLEAR_SUPPORTED(v, a) ((v)->va_supported &= ~VNODE_ATTR_ ## a) |
509 | #define VATTR_CLEAR_SUPPORTED_ALL(v) ((v)->va_supported = 0) |
510 | #define VATTR_IS_ACTIVE(v, a) ((v)->va_active & VNODE_ATTR_ ## a) |
511 | #define VATTR_ALL_SUPPORTED(v) (((v)->va_active & (v)->va_supported) == (v)->va_active) |
512 | #define VATTR_INACTIVE_SUPPORTED(v) do {(v)->va_active &= ~(v)->va_supported; (v)->va_supported = 0;} while(0) |
513 | #define VATTR_SET(v, a, x) do { (v)-> a = (x); VATTR_SET_ACTIVE(v, a);} while(0) |
514 | #define VATTR_WANTED(v, a) VATTR_SET_ACTIVE(v, a) |
515 | #define VATTR_RETURN(v, a, x) do { (v)-> a = (x); VATTR_SET_SUPPORTED(v, a);} while(0) |
516 | #define VATTR_NOT_RETURNED(v, a) (VATTR_IS_ACTIVE(v, a) && !VATTR_IS_SUPPORTED(v, a)) |
517 | |
518 | /* |
519 | * Two macros to simplify conditional checking in kernel code. |
520 | */ |
521 | #define VATTR_IS(v, a, x) (VATTR_IS_SUPPORTED(v, a) && (v)-> a == (x)) |
522 | #define VATTR_IS_NOT(v, a, x) (VATTR_IS_SUPPORTED(v, a) && (v)-> a != (x)) |
523 | |
524 | #define VNODE_ATTR_va_rdev (1LL<< 0) /* 00000001 */ |
525 | #define VNODE_ATTR_va_nlink (1LL<< 1) /* 00000002 */ |
526 | #define VNODE_ATTR_va_total_size (1LL<< 2) /* 00000004 */ |
527 | #define VNODE_ATTR_va_total_alloc (1LL<< 3) /* 00000008 */ |
528 | #define VNODE_ATTR_va_data_size (1LL<< 4) /* 00000010 */ |
529 | #define VNODE_ATTR_va_data_alloc (1LL<< 5) /* 00000020 */ |
530 | #define VNODE_ATTR_va_iosize (1LL<< 6) /* 00000040 */ |
531 | #define VNODE_ATTR_va_uid (1LL<< 7) /* 00000080 */ |
532 | #define VNODE_ATTR_va_gid (1LL<< 8) /* 00000100 */ |
533 | #define VNODE_ATTR_va_mode (1LL<< 9) /* 00000200 */ |
534 | #define VNODE_ATTR_va_flags (1LL<<10) /* 00000400 */ |
535 | #define VNODE_ATTR_va_acl (1LL<<11) /* 00000800 */ |
536 | #define VNODE_ATTR_va_create_time (1LL<<12) /* 00001000 */ |
537 | #define VNODE_ATTR_va_access_time (1LL<<13) /* 00002000 */ |
538 | #define VNODE_ATTR_va_modify_time (1LL<<14) /* 00004000 */ |
539 | #define VNODE_ATTR_va_change_time (1LL<<15) /* 00008000 */ |
540 | #define VNODE_ATTR_va_backup_time (1LL<<16) /* 00010000 */ |
541 | #define VNODE_ATTR_va_fileid (1LL<<17) /* 00020000 */ |
542 | #define VNODE_ATTR_va_linkid (1LL<<18) /* 00040000 */ |
543 | #define VNODE_ATTR_va_parentid (1LL<<19) /* 00080000 */ |
544 | #define VNODE_ATTR_va_fsid (1LL<<20) /* 00100000 */ |
545 | #define VNODE_ATTR_va_filerev (1LL<<21) /* 00200000 */ |
546 | #define VNODE_ATTR_va_gen (1LL<<22) /* 00400000 */ |
547 | #define VNODE_ATTR_va_encoding (1LL<<23) /* 00800000 */ |
548 | #define VNODE_ATTR_va_type (1LL<<24) /* 01000000 */ |
549 | #define VNODE_ATTR_va_name (1LL<<25) /* 02000000 */ |
550 | #define VNODE_ATTR_va_uuuid (1LL<<26) /* 04000000 */ |
551 | #define VNODE_ATTR_va_guuid (1LL<<27) /* 08000000 */ |
552 | #define VNODE_ATTR_va_nchildren (1LL<<28) /* 10000000 */ |
553 | #define VNODE_ATTR_va_dirlinkcount (1LL<<29) /* 20000000 */ |
554 | #define VNODE_ATTR_va_addedtime (1LL<<30) /* 40000000 */ |
555 | #define VNODE_ATTR_va_dataprotect_class (1LL<<31) /* 80000000 */ |
556 | #define VNODE_ATTR_va_dataprotect_flags (1LL<<32) /* 100000000 */ |
557 | #define VNODE_ATTR_va_document_id (1LL<<33) /* 200000000 */ |
558 | #define VNODE_ATTR_va_devid (1LL<<34) /* 400000000 */ |
559 | #define VNODE_ATTR_va_objtype (1LL<<35) /* 800000000 */ |
560 | #define VNODE_ATTR_va_objtag (1LL<<36) /* 1000000000 */ |
561 | #define VNODE_ATTR_va_user_access (1LL<<37) /* 2000000000 */ |
562 | #define VNODE_ATTR_va_finderinfo (1LL<<38) /* 4000000000 */ |
563 | #define VNODE_ATTR_va_rsrc_length (1LL<<39) /* 8000000000 */ |
564 | #define VNODE_ATTR_va_rsrc_alloc (1LL<<40) /* 10000000000 */ |
565 | #define VNODE_ATTR_va_fsid64 (1LL<<41) /* 20000000000 */ |
566 | #define VNODE_ATTR_va_write_gencount (1LL<<42) /* 40000000000 */ |
567 | #define VNODE_ATTR_va_private_size (1LL<<43) /* 80000000000 */ |
568 | #define VNODE_ATTR_va_clone_id (1LL<<44) /* 100000000000 */ |
569 | #define VNODE_ATTR_va_extflags (1LL<<45) /* 200000000000 */ |
570 | #define VNODE_ATTR_va_recursive_gencount (1LL<<46) /* 400000000000 */ |
571 | #define VNODE_ATTR_va_attribution_tag (1LL<<47) /* 800000000000 */ |
572 | #define VNODE_ATTR_va_clone_refcnt (1LL<<48) /* 1000000000000 */ |
573 | |
574 | #define VNODE_ATTR_BIT(n) (VNODE_ATTR_ ## n) |
575 | |
576 | /* |
577 | * ALL of the attributes. |
578 | */ |
579 | #define VNODE_ATTR_ALL (VNODE_ATTR_BIT(va_rdev) | \ |
580 | VNODE_ATTR_BIT(va_nlink) | \ |
581 | VNODE_ATTR_BIT(va_total_size) | \ |
582 | VNODE_ATTR_BIT(va_total_alloc) | \ |
583 | VNODE_ATTR_BIT(va_data_size) | \ |
584 | VNODE_ATTR_BIT(va_data_alloc) | \ |
585 | VNODE_ATTR_BIT(va_iosize) | \ |
586 | VNODE_ATTR_BIT(va_uid) | \ |
587 | VNODE_ATTR_BIT(va_gid) | \ |
588 | VNODE_ATTR_BIT(va_mode) | \ |
589 | VNODE_ATTR_BIT(va_flags) | \ |
590 | VNODE_ATTR_BIT(va_acl) | \ |
591 | VNODE_ATTR_BIT(va_create_time) | \ |
592 | VNODE_ATTR_BIT(va_access_time) | \ |
593 | VNODE_ATTR_BIT(va_modify_time) | \ |
594 | VNODE_ATTR_BIT(va_change_time) | \ |
595 | VNODE_ATTR_BIT(va_backup_time) | \ |
596 | VNODE_ATTR_BIT(va_fileid) | \ |
597 | VNODE_ATTR_BIT(va_linkid) | \ |
598 | VNODE_ATTR_BIT(va_parentid) | \ |
599 | VNODE_ATTR_BIT(va_fsid) | \ |
600 | VNODE_ATTR_BIT(va_filerev) | \ |
601 | VNODE_ATTR_BIT(va_gen) | \ |
602 | VNODE_ATTR_BIT(va_encoding) | \ |
603 | VNODE_ATTR_BIT(va_type) | \ |
604 | VNODE_ATTR_BIT(va_name) | \ |
605 | VNODE_ATTR_BIT(va_uuuid) | \ |
606 | VNODE_ATTR_BIT(va_guuid) | \ |
607 | VNODE_ATTR_BIT(va_nchildren) | \ |
608 | VNODE_ATTR_BIT(va_dirlinkcount) | \ |
609 | VNODE_ATTR_BIT(va_addedtime) | \ |
610 | VNODE_ATTR_BIT(va_dataprotect_class) | \ |
611 | VNODE_ATTR_BIT(va_dataprotect_flags) | \ |
612 | VNODE_ATTR_BIT(va_document_id) | \ |
613 | VNODE_ATTR_BIT(va_devid) | \ |
614 | VNODE_ATTR_BIT(va_objtype) | \ |
615 | VNODE_ATTR_BIT(va_objtag) | \ |
616 | VNODE_ATTR_BIT(va_user_access) | \ |
617 | VNODE_ATTR_BIT(va_finderinfo) | \ |
618 | VNODE_ATTR_BIT(va_rsrc_length) | \ |
619 | VNODE_ATTR_BIT(va_rsrc_alloc) | \ |
620 | VNODE_ATTR_BIT(va_fsid64) | \ |
621 | VNODE_ATTR_BIT(va_write_gencount) | \ |
622 | VNODE_ATTR_BIT(va_private_size) | \ |
623 | VNODE_ATTR_BIT(va_clone_id) | \ |
624 | VNODE_ATTR_BIT(va_extflags) | \ |
625 | VNODE_ATTR_BIT(va_recursive_gencount) | \ |
626 | VNODE_ATTR_BIT(va_attribution_tag) | \ |
627 | VNODE_ATTR_BIT(va_clone_refcnt)) |
628 | |
629 | |
630 | /* |
631 | * Read-only attributes. |
632 | */ |
633 | #define VNODE_ATTR_RDONLY (VNODE_ATTR_BIT(va_rdev) | \ |
634 | VNODE_ATTR_BIT(va_nlink) | \ |
635 | VNODE_ATTR_BIT(va_total_size) | \ |
636 | VNODE_ATTR_BIT(va_total_alloc) | \ |
637 | VNODE_ATTR_BIT(va_data_alloc) | \ |
638 | VNODE_ATTR_BIT(va_iosize) | \ |
639 | VNODE_ATTR_BIT(va_fileid) | \ |
640 | VNODE_ATTR_BIT(va_linkid) | \ |
641 | VNODE_ATTR_BIT(va_parentid) | \ |
642 | VNODE_ATTR_BIT(va_fsid) | \ |
643 | VNODE_ATTR_BIT(va_filerev) | \ |
644 | VNODE_ATTR_BIT(va_gen) | \ |
645 | VNODE_ATTR_BIT(va_name) | \ |
646 | VNODE_ATTR_BIT(va_type) | \ |
647 | VNODE_ATTR_BIT(va_nchildren) | \ |
648 | VNODE_ATTR_BIT(va_dirlinkcount) | \ |
649 | VNODE_ATTR_BIT(va_devid) | \ |
650 | VNODE_ATTR_BIT(va_objtype) | \ |
651 | VNODE_ATTR_BIT(va_objtag) | \ |
652 | VNODE_ATTR_BIT(va_user_access) | \ |
653 | VNODE_ATTR_BIT(va_finderinfo) | \ |
654 | VNODE_ATTR_BIT(va_rsrc_length) | \ |
655 | VNODE_ATTR_BIT(va_rsrc_alloc) | \ |
656 | VNODE_ATTR_BIT(va_fsid64) | \ |
657 | VNODE_ATTR_BIT(va_write_gencount) | \ |
658 | VNODE_ATTR_BIT(va_private_size) | \ |
659 | VNODE_ATTR_BIT(va_clone_id) | \ |
660 | VNODE_ATTR_BIT(va_extflags) | \ |
661 | VNODE_ATTR_BIT(va_recursive_gencount) | \ |
662 | VNODE_ATTR_BIT(va_attribution_tag) | \ |
663 | VNODE_ATTR_BIT(va_clone_refcnt)) |
664 | |
665 | /* |
666 | * Attributes that can be applied to a new file object. |
667 | */ |
668 | #define VNODE_ATTR_NEWOBJ (VNODE_ATTR_BIT(va_rdev) | \ |
669 | VNODE_ATTR_BIT(va_uid) | \ |
670 | VNODE_ATTR_BIT(va_gid) | \ |
671 | VNODE_ATTR_BIT(va_mode) | \ |
672 | VNODE_ATTR_BIT(va_flags) | \ |
673 | VNODE_ATTR_BIT(va_acl) | \ |
674 | VNODE_ATTR_BIT(va_create_time) | \ |
675 | VNODE_ATTR_BIT(va_modify_time) | \ |
676 | VNODE_ATTR_BIT(va_change_time) | \ |
677 | VNODE_ATTR_BIT(va_encoding) | \ |
678 | VNODE_ATTR_BIT(va_type) | \ |
679 | VNODE_ATTR_BIT(va_uuuid) | \ |
680 | VNODE_ATTR_BIT(va_guuid) | \ |
681 | VNODE_ATTR_BIT(va_dataprotect_class) | \ |
682 | VNODE_ATTR_BIT(va_dataprotect_flags) | \ |
683 | VNODE_ATTR_BIT(va_document_id)) |
684 | |
685 | #include <sys/_types/_fsid_t.h> |
686 | |
687 | struct vnode_attr { |
688 | /* bitfields */ |
689 | uint64_t va_supported; |
690 | uint64_t va_active; |
691 | |
692 | /* |
693 | * Control flags. The low 16 bits are reserved for the |
694 | * ioflags being passed for truncation operations. |
695 | */ |
696 | int va_vaflags; |
697 | |
698 | /* traditional stat(2) parameter fields */ |
699 | dev_t va_rdev; /* device id (device nodes only) */ |
700 | uint64_t va_nlink; /* number of references to this file */ |
701 | uint64_t va_total_size; /* size in bytes of all forks */ |
702 | uint64_t va_total_alloc; /* disk space used by all forks */ |
703 | uint64_t va_data_size; /* size in bytes of the fork managed by current vnode */ |
704 | uint64_t va_data_alloc; /* disk space used by the fork managed by current vnode */ |
705 | uint32_t va_iosize; /* optimal I/O blocksize */ |
706 | |
707 | /* file security information */ |
708 | uid_t va_uid; /* owner UID */ |
709 | gid_t va_gid; /* owner GID */ |
710 | mode_t va_mode; /* posix permissions */ |
711 | uint32_t va_flags; /* file flags */ |
712 | struct kauth_acl *va_acl; /* access control list */ |
713 | |
714 | /* timestamps */ |
715 | struct timespec va_create_time; /* time of creation */ |
716 | struct timespec va_access_time; /* time of last access */ |
717 | struct timespec va_modify_time; /* time of last data modification */ |
718 | struct timespec va_change_time; /* time of last metadata change */ |
719 | struct timespec va_backup_time; /* time of last backup */ |
720 | |
721 | /* file parameters */ |
722 | uint64_t va_fileid; /* file unique ID in filesystem */ |
723 | uint64_t va_linkid; /* file link unique ID */ |
724 | uint64_t va_parentid; /* parent ID */ |
725 | uint32_t va_fsid; /* filesystem ID */ |
726 | uint64_t va_filerev; /* file revision counter */ /* XXX */ |
727 | uint32_t va_gen; /* file generation count */ /* XXX - relationship of |
728 | * these two? */ |
729 | /* misc parameters */ |
730 | uint32_t va_encoding; /* filename encoding script */ |
731 | |
732 | enum vtype va_type; /* file type */ |
733 | char * va_name; /* Name for ATTR_CMN_NAME; MAXPATHLEN bytes */ |
734 | guid_t va_uuuid; /* file owner UUID */ |
735 | guid_t va_guuid; /* file group UUID */ |
736 | |
737 | /* Meaningful for directories only */ |
738 | uint64_t va_nchildren; /* Number of items in a directory */ |
739 | uint64_t va_dirlinkcount; /* Real references to dir (i.e. excluding "." and ".." refs) */ |
740 | |
741 | #ifdef BSD_KERNEL_PRIVATE |
742 | struct kauth_acl *va_base_acl; |
743 | #else |
744 | void * va_reserved1; |
745 | #endif /* BSD_KERNEL_PRIVATE */ |
746 | struct timespec va_addedtime; /* timestamp when item was added to parent directory */ |
747 | |
748 | /* Data Protection fields */ |
749 | uint32_t va_dataprotect_class; /* class specified for this file if it didn't exist */ |
750 | uint32_t va_dataprotect_flags; /* flags from NP open(2) to the filesystem */ |
751 | |
752 | /* Document revision tracking */ |
753 | uint32_t va_document_id; |
754 | |
755 | /* Fields for Bulk args */ |
756 | uint32_t va_devid; /* devid of filesystem */ |
757 | uint32_t va_objtype; /* type of object */ |
758 | uint32_t va_objtag; /* vnode tag of filesystem */ |
759 | uint32_t va_user_access; /* access for user */ |
760 | uint8_t va_finderinfo[32]; /* Finder Info */ |
761 | uint64_t va_rsrc_length; /* Resource Fork length */ |
762 | uint64_t va_rsrc_alloc; /* Resource Fork allocation size */ |
763 | fsid_t va_fsid64; /* fsid, of the correct type */ |
764 | |
765 | uint32_t va_write_gencount; /* counter that increments each time the file changes */ |
766 | |
767 | uint64_t va_private_size; /* If the file were deleted, how many bytes would be freed immediately */ |
768 | uint64_t va_clone_id; /* If a file is cloned this is a unique id shared by all "perfect" clones */ |
769 | uint64_t va_extflags; /* extended file/directory flags */ |
770 | uint64_t va_recursive_gencount; /* for dir-stats enabled directories */ |
771 | uint64_t va_attribution_tag; /* a 64 bit hash of the bundle name associated with this file */ |
772 | uint32_t va_clone_refcnt; /* the number of "perfect" clones sharing the same clone_id */ |
773 | |
774 | /* add new fields here only */ |
775 | }; |
776 | |
777 | #ifdef BSD_KERNEL_PRIVATE |
778 | /* |
779 | * Flags for va_dataprotect_flags |
780 | */ |
781 | #define VA_DP_RAWENCRYPTED 0x0001 |
782 | #define VA_DP_RAWUNENCRYPTED 0x0002 |
783 | #define VA_DP_AUTHENTICATE 0x0004 |
784 | |
785 | #endif |
786 | |
787 | /* |
788 | * Flags for va_vaflags. |
789 | */ |
790 | #define VA_UTIMES_NULL 0x010000 /* utimes argument was NULL */ |
791 | #define VA_EXCLUSIVE 0x020000 /* exclusive create request */ |
792 | #define VA_NOINHERIT 0x040000 /* Don't inherit ACLs from parent */ |
793 | #define VA_NOAUTH 0x080000 |
794 | #define VA_64BITOBJIDS 0x100000 /* fileid/linkid/parentid are 64 bit */ |
795 | #define VA_REALFSID 0x200000 /* Return real fsid */ |
796 | #define VA_USEFSID 0x400000 /* Use fsid from filesystem */ |
797 | #define VA_FILESEC_ACL 0x800000 /* ACL is interior to filesec */ |
798 | |
799 | /* |
800 | * Modes. Some values same as Ixxx entries from inode.h for now. |
801 | */ |
802 | #define VSUID 0x800 /*04000*/ /* set user id on execution */ |
803 | #define VSGID 0x400 /*02000*/ /* set group id on execution */ |
804 | #define VSVTX 0x200 /*01000*/ /* save swapped text even after use */ |
805 | #define VREAD 0x100 /*00400*/ /* read, write, execute permissions */ |
806 | #define VWRITE 0x080 /*00200*/ |
807 | #define VEXEC 0x040 /*00100*/ |
808 | |
809 | /* |
810 | * Convert between vnode types and inode formats (since POSIX.1 |
811 | * defines mode word of stat structure in terms of inode formats). |
812 | */ |
813 | extern enum vtype iftovt_tab[]; |
814 | extern int vttoif_tab[]; |
815 | #define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12]) |
816 | #define VTTOIF(indx) (vttoif_tab[(int)(indx)]) |
817 | #define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode)) |
818 | |
819 | /* |
820 | * Flags to various vnode functions. |
821 | */ |
822 | #define SKIPSYSTEM 0x0001 /* vflush: skip vnodes marked VSYSTEM */ |
823 | #define FORCECLOSE 0x0002 /* vflush: force file closeure */ |
824 | #define WRITECLOSE 0x0004 /* vflush: only close writeable files */ |
825 | #define SKIPSWAP 0x0008 /* vflush: skip vnodes marked VSWAP */ |
826 | #define SKIPROOT 0x0010 /* vflush: skip root vnodes marked VROOT */ |
827 | |
828 | #define DOCLOSE 0x0008 /* vclean: close active files */ |
829 | |
830 | #define V_SAVE 0x0001 /* vinvalbuf: sync file first */ |
831 | #define V_SAVEMETA 0x0002 /* vinvalbuf: leave indirect blocks */ |
832 | |
833 | #define REVOKEALL 0x0001 /* vnop_revoke: revoke all aliases */ |
834 | |
835 | /* VNOP_REMOVE/unlink flags */ |
836 | #define VNODE_REMOVE_NODELETEBUSY 0x0001 /* Don't delete busy files (Carbon) */ |
837 | #define VNODE_REMOVE_SKIP_NAMESPACE_EVENT 0x0002 /* Do not upcall to userland handlers */ |
838 | #define VNODE_REMOVE_NO_AUDIT_PATH 0x0004 /* Do not audit the path */ |
839 | #define VNODE_REMOVE_DATALESS_DIR 0x0008 /* Special handling for removing a dataless directory without materialization */ |
840 | #ifdef BSD_KERNEL_PRIVATE |
841 | #define VNODE_REMOVE_NOFOLLOW_ANY 0x0010 |
842 | #endif |
843 | |
844 | /* VNOP_READDIR flags: */ |
845 | #define VNODE_READDIR_EXTENDED 0x0001 /* use extended directory entries */ |
846 | #define VNODE_READDIR_REQSEEKOFF 0x0002 /* requires seek offset (cookies) */ |
847 | #define VNODE_READDIR_SEEKOFF32 0x0004 /* seek offset values should fit in 32 bits */ |
848 | #define VNODE_READDIR_NAMEMAX 0x0008 /* For extended readdir, try to limit names to NAME_MAX bytes */ |
849 | |
850 | /* VNOP_CLONEFILE flags: */ |
851 | #define VNODE_CLONEFILE_DEFAULT 0x0000 |
852 | #define VNODE_CLONEFILE_NOOWNERCOPY 0x0001 /* Don't copy ownership information */ |
853 | |
854 | |
855 | #define NULLVP ((struct vnode *)NULL) |
856 | |
857 | #ifndef BSD_KERNEL_PRIVATE |
858 | struct vnodeop_desc; |
859 | #endif |
860 | |
861 | extern int desiredvnodes; /* number of vnodes desired */ |
862 | |
863 | |
864 | /* |
865 | * This structure is used to configure the new vnodeops vector. |
866 | */ |
867 | struct vnodeopv_entry_desc { |
868 | struct vnodeop_desc *opve_op; /* which operation this is */ |
869 | int (*opve_impl)(void *); /* code implementing this operation */ |
870 | }; |
871 | struct vnodeopv_desc { |
872 | /* ptr to the ptr to the vector where op should go */ |
873 | int(***opv_desc_vector_p)(void *); |
874 | const struct vnodeopv_entry_desc *opv_desc_ops; /* null terminated list */ |
875 | }; |
876 | |
877 | /*! |
878 | * @function vn_default_error |
879 | * @abstract Default vnode operation to fill unsupported slots in vnode operation vectors. |
880 | * @return ENOTSUP |
881 | */ |
882 | int vn_default_error(void); |
883 | |
884 | /* |
885 | * A generic structure. |
886 | * This can be used by bypass routines to identify generic arguments. |
887 | */ |
888 | struct vnop_generic_args { |
889 | struct vnodeop_desc *a_desc; |
890 | /* other random data follows, presumably */ |
891 | }; |
892 | |
893 | #include <sys/vnode_if.h> |
894 | |
895 | __BEGIN_DECLS |
896 | |
897 | /*! |
898 | * @function vnode_create |
899 | * @abstract Create and initialize a vnode. |
900 | * @discussion Returns wth an iocount held on the vnode which must eventually be dropped with vnode_put(). |
901 | * @param flavor Should be VNCREATE_FLAVOR. |
902 | * @param size Size of the struct vnode_fsparam in "data". |
903 | * @param data Pointer to a struct vnode_fsparam containing initialization information. |
904 | * @param vpp Pointer to a vnode pointer, to be filled in with newly created vnode. |
905 | * @return 0 for success, error code otherwise. |
906 | */ |
907 | errno_t vnode_create(uint32_t flavor, uint32_t size, void *data, vnode_t *vpp); |
908 | |
909 | #ifdef KERNEL_PRIVATE |
910 | |
911 | __options_decl(vnode_create_options_t, uint32_t, { |
912 | VNODE_CREATE_DEFAULT = 0, |
913 | VNODE_CREATE_EMPTY = 1, |
914 | VNODE_CREATE_NODEALLOC = 2 |
915 | }); |
916 | |
917 | #define VNODE_CREATE_DEFAULT VNODE_CREATE_DEFAULT |
918 | |
919 | /*! |
920 | * @function vnode_create_ext |
921 | * @abstract Create and initialize a vnode. |
922 | * @discussion Returns wth an iocount held on the vnode which must eventually be dropped with vnode_put(). |
923 | * @param flavor Should be VNCREATE_FLAVOR. |
924 | * @param size Size of the struct vnode_fsparam in "data". |
925 | * @param data Pointer to a struct vnode_fsparam containing initialization information. |
926 | * @param vpp Pointer to a vnode pointer, to be filled in with newly created vnode. |
927 | * @param vc_options options for vnode creation, by default a vnode that can be deallocated is created, |
928 | * use VNODE_CREATE_NODEALLOC to override the default behavior. |
929 | * @return 0 for success, error code otherwise. |
930 | */ |
931 | errno_t vnode_create_ext(uint32_t flavor, uint32_t size, void *data, vnode_t *vpp, vnode_create_options_t vc_options); |
932 | |
933 | /* |
934 | * vnode create options (vc_options) |
935 | * |
936 | * VNODE_CREATE_EMPTY: |
937 | * An "empty" vnode( i.e. a vnode not initialized with filesystem information) is returned |
938 | * This results in the flavor, size and data arguments to vnode_create_ext getting ignored. |
939 | * |
940 | * VNODE_CREATE_NODEALLOC: |
941 | * The filesystem does not support vnodes that can be deallocated. By default, vnodes |
942 | * that are created by using vnode_create_ext can be deallocated and the calling filesytem |
943 | * uses vnode_hold and vnode_drop approrpiately. This flag should be be used to override |
944 | * the default behavior. |
945 | * |
946 | */ |
947 | |
948 | /*! |
949 | * @function vnode_create_empty |
950 | * @abstract Create an empty, uninitialized vnode. |
951 | * @discussion Returns with an iocount held on the vnode which must eventually be |
952 | * dropped with vnode_put(). The next operation performed on the vnode must be |
953 | * vnode_initialize (or vnode_put if the vnode is not needed anymore). |
954 | * This interface is provided as a mechanism to pre-flight obtaining a vnode for |
955 | * certain filesystem operations which may need to get a vnode without filesystem |
956 | * locks held. It is imperative that nothing be done with the vnode till the |
957 | * succeeding vnode_initialize (or vnode_put as the case may be) call. |
958 | * @param vpp Pointer to a vnode pointer, to be filled in with newly created vnode. |
959 | * @return 0 for success, error code otherwise. |
960 | */ |
961 | errno_t vnode_create_empty(vnode_t *vpp); |
962 | |
963 | /*! |
964 | * @function vnode_initialize |
965 | * @abstract Initialize a vnode obtained by vnode_create_empty |
966 | * @discussion Does not drop iocount held on the vnode which must eventually be |
967 | * dropped with vnode_put(). In case of an error however, the vnode's iocount is |
968 | * dropped and the vnode must not be referenced again by the caller. |
969 | * @param flavor Should be VNCREATE_FLAVOR. |
970 | * @param size Size of the struct vnode_fsparam in "data". |
971 | * @param data Pointer to a struct vnode_fsparam containing initialization information. |
972 | * @param vpp Pointer to a vnode pointer, to be filled in with newly created vnode. |
973 | * @return 0 for success, error code otherwise. |
974 | */ |
975 | errno_t vnode_initialize(uint32_t flavor, uint32_t size, void *data, vnode_t *vpp); |
976 | #endif /* KERNEL_PRIVATE */ |
977 | |
978 | /*! |
979 | * @function vnode_addfsref |
980 | * @abstract Mark a vnode as being stored in a filesystem hash. |
981 | * @discussion Should only be called once on a vnode, and never if that vnode was created with VNFS_ADDFSREF. |
982 | * There should be a corresponding call to vnode_removefsref() when the vnode is reclaimed; VFS assumes that a |
983 | * n unused vnode will not be marked as referenced by a filesystem. |
984 | * @param vp The vnode to mark. |
985 | * @return Always 0. |
986 | */ |
987 | int vnode_addfsref(vnode_t vp); |
988 | |
989 | /*! |
990 | * @function vnode_removefsref |
991 | * @abstract Mark a vnode as no longer being stored in a filesystem hash. |
992 | * @discussion Should only be called once on a vnode (during a reclaim), and only after the vnode has either been created with VNFS_ADDFSREF or marked by vnode_addfsref(). |
993 | * @param vp The vnode to unmark. |
994 | * @return Always 0. |
995 | */ |
996 | int vnode_removefsref(vnode_t vp); |
997 | |
998 | /*! |
999 | * @function vnode_hasdirtyblks |
1000 | * @abstract Check if a vnode has dirty data waiting to be written to disk. |
1001 | * @discussion Note that this routine is unsynchronized; it is only a snapshot and its result may cease to be true at the moment it is returned.. |
1002 | * @param vp The vnode to test. |
1003 | * @return Nonzero if there are dirty blocks, 0 otherwise |
1004 | */ |
1005 | int vnode_hasdirtyblks(vnode_t vp); |
1006 | |
1007 | /*! |
1008 | * @function vnode_hascleanblks |
1009 | * @abstract Check if a vnode has clean buffers associated with it. |
1010 | * @discussion Note that this routine is unsynchronized; it is only a snapshot and its result may cease to be true at the moment it is returned.. |
1011 | * @param vp The vnode to test. |
1012 | * @return Nonzero if there are clean blocks, 0 otherwise. |
1013 | */ |
1014 | int vnode_hascleanblks(vnode_t vp); |
1015 | |
1016 | #define VNODE_ASYNC_THROTTLE 15 |
1017 | /*! |
1018 | * @function vnode_waitforwrites |
1019 | * @abstract Wait for the number of pending writes on a vnode to drop below a target. |
1020 | * @param vp The vnode to monitor. |
1021 | * @param output_target Max pending write count with which to return. |
1022 | * @param slpflag Flags for msleep(). |
1023 | * @param slptimeout Frequency with which to force a check for completion; increments of 10 ms. |
1024 | * @param msg String to pass msleep() . |
1025 | * @return 0 for success, or an error value from msleep(). |
1026 | */ |
1027 | int vnode_waitforwrites(vnode_t vp, int output_target, int slpflag, int slptimeout, const char *msg); |
1028 | |
1029 | /*! |
1030 | * @function vnode_startwrite |
1031 | * @abstract Increment the count of pending writes on a vnode. |
1032 | * @param vp The vnode whose count to increment. |
1033 | */ |
1034 | void vnode_startwrite(vnode_t vp); |
1035 | |
1036 | /*! |
1037 | * @function vnode_startwrite |
1038 | * @abstract Decrement the count of pending writes on a vnode . |
1039 | * @discussion Also wakes up threads waiting for the write count to drop, as in vnode_waitforwrites. |
1040 | * @param vp The vnode whose count to decrement. |
1041 | */ |
1042 | void vnode_writedone(vnode_t vp); |
1043 | |
1044 | /*! |
1045 | * @function vnode_vtype |
1046 | * @abstract Return a vnode's type. |
1047 | * @param vp The vnode whose type to grab. |
1048 | * @return The vnode's type. |
1049 | */ |
1050 | enum vtype vnode_vtype(vnode_t vp); |
1051 | |
1052 | /*! |
1053 | * @function vnode_vid |
1054 | * @abstract Return a vnode's vid (generation number), which is constant from creation until reclaim. |
1055 | * @param vp The vnode whose vid to grab. |
1056 | * @return The vnode's vid. |
1057 | */ |
1058 | uint32_t vnode_vid(vnode_t vp); |
1059 | |
1060 | /*! |
1061 | * @function vnode_isonexternalstorage |
1062 | * @abstract Return whether or not the storage device backing a vnode is external or not. |
1063 | * @param vp The vnode whose physical location is to be determined. |
1064 | * @return TRUE if storage device is external, FALSE if otherwise. |
1065 | */ |
1066 | boolean_t vnode_isonexternalstorage(vnode_t vp); |
1067 | |
1068 | /*! |
1069 | * @function vnode_mountedhere |
1070 | * @abstract Returns a pointer to a mount placed on top of a vnode, should it exist. |
1071 | * @param vp The vnode from whom to take the covering mount. |
1072 | * @return Pointer to mount covering a vnode, or NULL if none exists. |
1073 | */ |
1074 | mount_t vnode_mountedhere(vnode_t vp); |
1075 | |
1076 | /*! |
1077 | * @function vnode_mount |
1078 | * @abstract Get the mount structure for the filesystem that a vnode belongs to. |
1079 | * @param vp The vnode whose mount to grab. |
1080 | * @return The mount, directly. |
1081 | */ |
1082 | mount_t vnode_mount(vnode_t vp); |
1083 | |
1084 | /*! |
1085 | * @function vnode_specrdev |
1086 | * @abstract Return the device id of the device associated with a special file. |
1087 | * @param vp The vnode whose device id to extract--vnode must be a special file. |
1088 | * @return The device id. |
1089 | */ |
1090 | dev_t vnode_specrdev(vnode_t vp); |
1091 | |
1092 | /*! |
1093 | * @function vnode_fsnode |
1094 | * @abstract Gets the filesystem-specific data associated with a vnode. |
1095 | * @param vp The vnode whose data to grab. |
1096 | * @return The filesystem-specific data, directly. |
1097 | */ |
1098 | void * vnode_fsnode(vnode_t vp); |
1099 | |
1100 | /*! |
1101 | * @function vnode_clearfsnode |
1102 | * @abstract Sets a vnode's filesystem-specific data to be NULL. |
1103 | * @discussion This routine should only be called when a vnode is no longer in use, i.e. during a VNOP_RECLAIM. |
1104 | * @param vp The vnode whose data to clear out. |
1105 | */ |
1106 | void vnode_clearfsnode(vnode_t vp); |
1107 | |
1108 | /*! |
1109 | * @function vnode_isvroot |
1110 | * @abstract Determine if a vnode is the root of its filesystem. |
1111 | * @param vp The vnode to test. |
1112 | * @return Nonzero if the vnode is the root, 0 if it is not. |
1113 | */ |
1114 | int vnode_isvroot(vnode_t vp); |
1115 | |
1116 | /*! |
1117 | * @function vnode_issystem |
1118 | * @abstract Determine if a vnode is marked as a System vnode. |
1119 | * @param vp The vnode to test. |
1120 | * @return Nonzero if the vnode is a system vnode, 0 if it is not. |
1121 | */ |
1122 | int vnode_issystem(vnode_t vp); |
1123 | |
1124 | /*! |
1125 | * @function vnode_ismount |
1126 | * @abstract Determine if there is currently a mount occurring which will cover this vnode. |
1127 | * @discussion Note that this is only a snapshot; a mount may begin or end at any time. |
1128 | * @param vp The vnode to test. |
1129 | * @return Nonzero if there is a mount in progress, 0 otherwise. |
1130 | */ |
1131 | int vnode_ismount(vnode_t vp); |
1132 | |
1133 | /*! |
1134 | * @function vnode_isreg |
1135 | * @abstract Determine if a vnode is a regular file. |
1136 | * @param vp The vnode to test. |
1137 | * @return Nonzero if the vnode is of type VREG, 0 otherwise. |
1138 | */ |
1139 | int vnode_isreg(vnode_t vp); |
1140 | |
1141 | /*! |
1142 | * @function vnode_isdir |
1143 | * @abstract Determine if a vnode is a directory. |
1144 | * @param vp The vnode to test. |
1145 | * @return Nonzero if the vnode is of type VDIR, 0 otherwise. |
1146 | */ |
1147 | int vnode_isdir(vnode_t vp); |
1148 | |
1149 | /*! |
1150 | * @function vnode_islnk |
1151 | * @abstract Determine if a vnode is a symbolic link. |
1152 | * @param vp The vnode to test. |
1153 | * @return Nonzero if the vnode is of type VLNK, 0 otherwise. |
1154 | */ |
1155 | int vnode_islnk(vnode_t vp); |
1156 | |
1157 | /*! |
1158 | * @function vnode_isfifo |
1159 | * @abstract Determine if a vnode is a named pipe. |
1160 | * @param vp The vnode to test. |
1161 | * @return Nonzero if the vnode is of type VFIFO, 0 otherwise. |
1162 | */ |
1163 | int vnode_isfifo(vnode_t vp); |
1164 | |
1165 | /*! |
1166 | * @function vnode_isblk |
1167 | * @abstract Determine if a vnode is a block device special file. |
1168 | * @param vp The vnode to test. |
1169 | * @return Nonzero if the vnode is of type VBLK, 0 otherwise. |
1170 | */ |
1171 | int vnode_isblk(vnode_t vp); |
1172 | |
1173 | /*! |
1174 | * @function vnode_ischr |
1175 | * @abstract Determine if a vnode is a character device special file. |
1176 | * @param vp The vnode to test. |
1177 | * @return Nonzero if the vnode is of type VCHR, 0 otherwise. |
1178 | */ |
1179 | int vnode_ischr(vnode_t vp); |
1180 | |
1181 | /*! |
1182 | * @function vnode_isswap |
1183 | * @abstract Determine if a vnode is being used as a swap file. |
1184 | * @param vp The vnode to test. |
1185 | * @return Nonzero if the vnode is being used as swap, 0 otherwise. |
1186 | */ |
1187 | int vnode_isswap(vnode_t vp); |
1188 | |
1189 | /*! |
1190 | * @function vnode_isnamedstream |
1191 | * @abstract Determine if a vnode is a named stream. |
1192 | * @param vp The vnode to test. |
1193 | * @return Nonzero if the vnode is a named stream, 0 otherwise. |
1194 | */ |
1195 | int vnode_isnamedstream(vnode_t vp); |
1196 | |
1197 | #ifdef KERNEL_PRIVATE |
1198 | /*! |
1199 | * @function vnode_setasnamedstream |
1200 | * @abstract Set svp as a named stream of vp and take appropriate references. |
1201 | * @param vp The vnode whose namedstream has to be set. |
1202 | * @param svp The namedstream vnode. |
1203 | * @return 0 if the operation is successful, an error otherwise. |
1204 | */ |
1205 | errno_t vnode_setasnamedstream(vnode_t vp, vnode_t svp); |
1206 | |
1207 | /*! |
1208 | * @function vnode_setasfirmlink |
1209 | * @abstract Set a vnode to act as a firmlink i.e. point to a target vnode. |
1210 | * @param vp The vnode which is to be acted on as a firmlink. |
1211 | * @param target_vp The vnode which will be the target of the firmlink. |
1212 | * @return 0 if the operation is successful, an error otherwise. |
1213 | */ |
1214 | errno_t vnode_setasfirmlink(vnode_t vp, vnode_t target_vp); |
1215 | |
1216 | /*! |
1217 | * @function vnode_getfirmlink |
1218 | * @abstract If a vnode is a firmlink, get its target vnode. |
1219 | * @param vp The firmlink vnode. |
1220 | * @param target_vp The firmlink traget vnode. This vnode is returned with an iocount. |
1221 | * @return 0 if the operation is successful, an error otherwise. |
1222 | */ |
1223 | errno_t vnode_getfirmlink(vnode_t vp, vnode_t *target_vp); |
1224 | |
1225 | #endif /* KERNEL_PRIVATE */ |
1226 | |
1227 | /*! |
1228 | * @function vnode_ismountedon |
1229 | * @abstract Determine if a vnode is a block device on which a filesystem has been mounted. |
1230 | * @discussion A block device marked as being mounted on cannot be opened. |
1231 | * @param vp The vnode to test. |
1232 | * @return Nonzero if the vnode is a block device on which an filesystem is mounted, 0 otherwise. |
1233 | */ |
1234 | int vnode_ismountedon(vnode_t vp); |
1235 | |
1236 | /*! |
1237 | * @function vnode_setmountedon |
1238 | * @abstract Set flags indicating that a block device vnode has been mounted as a filesystem. |
1239 | * @discussion A block device marked as being mounted on cannot be opened. |
1240 | * @param vp The vnode to set flags on, a block device. |
1241 | */ |
1242 | void vnode_setmountedon(vnode_t vp); |
1243 | |
1244 | /*! |
1245 | * @function vnode_clearmountedon |
1246 | * @abstract Clear flags indicating that a block device vnode has been mounted as a filesystem. |
1247 | * @param vp The vnode to clear flags on, a block device. |
1248 | */ |
1249 | void vnode_clearmountedon(vnode_t vp); |
1250 | |
1251 | /*! |
1252 | * @function vnode_isrecycled |
1253 | * @abstract Check if a vnode is dead or in the process of being killed (recycled). |
1254 | * @discussion This is only a snapshot: a vnode may start to be recycled, or go from dead to in use, at any time. |
1255 | * @param vp The vnode to test. |
1256 | * @return Nonzero if vnode is dead or being recycled, 0 otherwise. |
1257 | */ |
1258 | int vnode_isrecycled(vnode_t vp); |
1259 | |
1260 | /*! |
1261 | * @function vnode_willberecycled |
1262 | * @abstract Check if a vnode is marked for recycling when the last reference to it is released. |
1263 | * @discussion This is only a snapshot: a vnode may start to be recycled, or go from dead to in use, at any time. |
1264 | * @param vp The vnode to test. |
1265 | * @return Nonzero if vnode is marked for recycling, 0 otherwise. |
1266 | */ |
1267 | int vnode_willberecycled(vnode_t vp); |
1268 | |
1269 | /*! |
1270 | * @function vnode_isnocache |
1271 | * @abstract Check if a vnode is set to not have its data cached in memory (i.e. we write-through to disk and always read from disk). |
1272 | * @param vp The vnode to test. |
1273 | * @return Nonzero if vnode is set to not have data chached, 0 otherwise. |
1274 | */ |
1275 | int vnode_isnocache(vnode_t vp); |
1276 | |
1277 | /*! |
1278 | * @function vnode_israge |
1279 | * @abstract Check if a vnode is marked for rapid aging |
1280 | * @param vp The vnode to test. |
1281 | * @return Nonzero if vnode is marked for rapid aging, 0 otherwise |
1282 | */ |
1283 | int vnode_israge(vnode_t vp); |
1284 | |
1285 | /*! |
1286 | * @function vnode_needssnapshots |
1287 | * @abstract Check if a vnode needs snapshots events (regardless of its ctime status) |
1288 | * @param vp The vnode to test. |
1289 | * @return Nonzero if vnode needs snapshot events, 0 otherwise |
1290 | */ |
1291 | int vnode_needssnapshots(vnode_t vp); |
1292 | |
1293 | /*! |
1294 | * @function vnode_setnocache |
1295 | * @abstract Set a vnode to not have its data cached in memory (i.e. we write-through to disk and always read from disk). |
1296 | * @param vp The vnode whose flags to set. |
1297 | */ |
1298 | void vnode_setnocache(vnode_t vp); |
1299 | |
1300 | /*! |
1301 | * @function vnode_clearnocache |
1302 | * @abstract Clear the flag on a vnode indicating that data should not be cached in memory (i.e. we write-through to disk and always read from disk). |
1303 | * @param vp The vnode whose flags to clear. |
1304 | */ |
1305 | void vnode_clearnocache(vnode_t vp); |
1306 | |
1307 | /*! |
1308 | * @function vnode_isnoreadahead |
1309 | * @abstract Check if a vnode is set to not have data speculatively read in in hopes of future cache hits. |
1310 | * @param vp The vnode to test. |
1311 | * @return Nonzero if readahead is disabled, 0 otherwise. |
1312 | */ |
1313 | int vnode_isnoreadahead(vnode_t vp); |
1314 | |
1315 | /*! |
1316 | * @function vnode_setnoreadahead |
1317 | * @abstract Set a vnode to not have data speculatively read in in hopes of hitting in cache. |
1318 | * @param vp The vnode on which to prevent readahead. |
1319 | */ |
1320 | void vnode_setnoreadahead(vnode_t vp); |
1321 | |
1322 | /*! |
1323 | * @function vnode_clearnoreadahead |
1324 | * @abstract Clear the flag indicating that a vnode should not have data speculatively read in. |
1325 | * @param vp The vnode whose flag to clear. |
1326 | */ |
1327 | void vnode_clearnoreadahead(vnode_t vp); |
1328 | |
1329 | /*! |
1330 | * @function vnode_isfastdevicecandidate |
1331 | * @abstract Check if a vnode is a candidate to store on the fast device of a composite disk system |
1332 | * @param vp The vnode which you want to test. |
1333 | * @return Nonzero if the vnode is marked as a fast-device candidate |
1334 | */ |
1335 | int vnode_isfastdevicecandidate(vnode_t vp); |
1336 | |
1337 | /*! |
1338 | * @function vnode_setfastdevicecandidate |
1339 | * @abstract Mark a vnode as a candidate to store on the fast device of a composite disk system |
1340 | * @discussion If the vnode is a directory, all its children will inherit this bit. |
1341 | * @param vp The vnode which you want marked. |
1342 | */ |
1343 | void vnode_setfastdevicecandidate(vnode_t vp); |
1344 | |
1345 | /*! |
1346 | * @function vnode_clearfastdevicecandidate |
1347 | * @abstract Clear the status of a vnode being a candidate to store on the fast device of a composite disk system. |
1348 | * @param vp The vnode whose flag to clear. |
1349 | */ |
1350 | void vnode_clearfastdevicecandidate(vnode_t vp); |
1351 | |
1352 | /*! |
1353 | * @function vnode_isautocandidate |
1354 | * @abstract Check if a vnode was automatically selected to be fast-dev candidate (see vnode_setfastdevicecandidate) |
1355 | * @param vp The vnode which you want to test. |
1356 | * @return Nonzero if the vnode was automatically marked as a fast-device candidate |
1357 | */ |
1358 | int vnode_isautocandidate(vnode_t vp); |
1359 | |
1360 | /*! |
1361 | * @function vnode_setfastdevicecandidate |
1362 | * @abstract Mark a vnode as an automatically selected candidate for storing on the fast device of a composite disk system |
1363 | * @discussion If the vnode is a directory, all its children will inherit this bit. |
1364 | * @param vp The vnode which you want marked. |
1365 | */ |
1366 | void vnode_setautocandidate(vnode_t vp); |
1367 | |
1368 | /*! |
1369 | * @function vnode_clearautocandidate |
1370 | * @abstract Clear the status of a vnode being an automatic candidate (see above) |
1371 | * @param vp The vnode whose flag to clear. |
1372 | */ |
1373 | void vnode_clearautocandidate(vnode_t vp); |
1374 | |
1375 | /* left only for compat reasons as User code depends on this from getattrlist, for ex */ |
1376 | |
1377 | /*! |
1378 | * @function vnode_settag |
1379 | * @abstract Set a vnode filesystem-specific "tag." |
1380 | * @discussion Sets a tag indicating which filesystem a vnode belongs to, e.g. VT_HFS, VT_UDF, VT_ZFS. The kernel never inspects this data, though the filesystem tags are defined in vnode.h; it is for the benefit of user programs via getattrlist. |
1381 | * @param vp The vnode whose tag to set. |
1382 | */ |
1383 | void vnode_settag(vnode_t vp, int tag); |
1384 | |
1385 | /*! |
1386 | * @function vnode_tag |
1387 | * @abstract Get the vnode filesystem-specific "tag." |
1388 | * @discussion Gets the tag indicating which filesystem a vnode belongs to, e.g. VT_HFS, VT_UDF, VT_ZFS. The kernel never inspects this data, though the filesystem tags are defined in vnode.h; it is for the benefit of user programs via getattrlist. |
1389 | * @param vp The vnode whose tag to grab. |
1390 | * @return The tag. |
1391 | */ |
1392 | int vnode_tag(vnode_t vp); |
1393 | |
1394 | /*! |
1395 | * @function vnode_getattr |
1396 | * @abstract Get vnode attributes. |
1397 | * @discussion Desired attributes are set with VATTR_SET_ACTIVE and VNODE_ATTR* macros. Supported attributes are determined after call with VATTR_IS_SUPPORTED. |
1398 | * @param vp The vnode whose attributes to grab. |
1399 | * @param vap Structure containing: 1) A list of requested attributes 2) Space to indicate which attributes are supported and being returned 3) Space to return attributes. |
1400 | * @param ctx Context for authentication. |
1401 | * @return 0 for success or an error code. |
1402 | */ |
1403 | int vnode_getattr(vnode_t vp, struct vnode_attr *vap, vfs_context_t ctx); |
1404 | |
1405 | /* |
1406 | * Utility function to deal with 32/64 bit fsid |
1407 | */ |
1408 | extern uint64_t vnode_get_va_fsid(struct vnode_attr *vap); |
1409 | |
1410 | /*! |
1411 | * @function vnode_setattr |
1412 | * @abstract Set vnode attributes. |
1413 | * @discussion Attributes to set are marked with VATTR_SET_ACTIVE and VNODE_ATTR* macros. Attributes successfully set are determined after call with VATTR_IS_SUPPORTED. |
1414 | * @param vp The vnode whose attributes to set. |
1415 | * @param vap Structure containing: 1) A list of attributes to set 2) Space for values for those attributes 3) Space to indicate which attributes were set. |
1416 | * @param ctx Context for authentication. |
1417 | * @return 0 for success or an error code. |
1418 | */ |
1419 | int vnode_setattr(vnode_t vp, struct vnode_attr *vap, vfs_context_t ctx); |
1420 | |
1421 | /*! |
1422 | * @function vfs_rootvnode |
1423 | * @abstract Returns the root vnode with an iocount. |
1424 | * @discussion Caller must vnode_put() the root node when done. |
1425 | * @return Pointer to root vnode if successful; error code if there is a problem taking an iocount. |
1426 | */ |
1427 | vnode_t vfs_rootvnode(void); |
1428 | |
1429 | /*! |
1430 | * @function vnode_uncache_credentials |
1431 | * @abstract Clear out cached credentials on a vnode. |
1432 | * @discussion When we authorize an action on a vnode, we cache the credential that was authorized and the actions it was authorized for in case a similar request follows. This function destroys that caching. |
1433 | * @param vp The vnode whose cache to clear. |
1434 | */ |
1435 | void vnode_uncache_credentials(vnode_t vp); |
1436 | |
1437 | /*! |
1438 | * @function vnode_setmultipath |
1439 | * @abstract Mark a vnode as being reachable by multiple paths, i.e. as a hard link. |
1440 | * @discussion "Multipath" vnodes can be reached through more than one entry in the filesystem, and so must be handled differently for caching and event notification purposes. A filesystem should mark a vnode with multiple hardlinks this way. |
1441 | * @param vp The vnode to mark. |
1442 | */ |
1443 | void vnode_setmultipath(vnode_t vp); |
1444 | |
1445 | /*! |
1446 | * @function vnode_vfsmaxsymlen |
1447 | * @abstract Determine the maximum length of a symbolic link for the filesystem on which a vnode resides. |
1448 | * @param vp The vnode for which to get filesystem symlink size cap. |
1449 | * @return Max symlink length. |
1450 | */ |
1451 | uint32_t vnode_vfsmaxsymlen(vnode_t vp); |
1452 | |
1453 | /*! |
1454 | * @function vnode_vfsisrdonly |
1455 | * @abstract Determine if the filesystem to which a vnode belongs is mounted read-only. |
1456 | * @param vp The vnode for which to get filesystem writeability. |
1457 | * @return Nonzero if the filesystem is read-only, 0 otherwise. |
1458 | */ |
1459 | int vnode_vfsisrdonly(vnode_t vp); |
1460 | |
1461 | /*! |
1462 | * @function vnode_vfstypenum |
1463 | * @abstract Get the "type number" of the filesystem to which a vnode belongs. |
1464 | * @discussion This is an archaic construct; most filesystems are assigned a type number based on the order in which they are registered with the system. |
1465 | * @param vp The vnode whose filesystem to examine. |
1466 | * @return The type number of the fileystem to which the vnode belongs. |
1467 | */ |
1468 | int vnode_vfstypenum(vnode_t vp); |
1469 | |
1470 | /*! |
1471 | * @function vnode_vfsname |
1472 | * @abstract Get the name of the filesystem to which a vnode belongs. |
1473 | * @param vp The vnode whose filesystem to examine. |
1474 | * @param buf Destination for vfs name: should have size MFSNAMELEN or greater. |
1475 | */ |
1476 | void vnode_vfsname(vnode_t vp, char *buf); |
1477 | |
1478 | /*! |
1479 | * @function vnode_vfs64bitready |
1480 | * @abstract Determine if the filesystem to which a vnode belongs is marked as ready to interact with 64-bit user processes. |
1481 | * @param vp The vnode whose filesystem to examine. |
1482 | * @return Nonzero if filesystem is marked ready for 64-bit interactions; 0 otherwise. |
1483 | */ |
1484 | int vnode_vfs64bitready(vnode_t vp); |
1485 | |
1486 | /* These should move to private ... not documenting for now */ |
1487 | int vfs_context_get_special_port(vfs_context_t, int, ipc_port_t *); |
1488 | int vfs_context_set_special_port(vfs_context_t, int, ipc_port_t); |
1489 | |
1490 | /*! |
1491 | * @function vfs_context_proc |
1492 | * @abstract Get the BSD process structure associated with a vfs_context_t. |
1493 | * @param ctx Context whose associated process to find. |
1494 | * @return Process if available, NULL otherwise. |
1495 | */ |
1496 | proc_t vfs_context_proc(vfs_context_t ctx); |
1497 | |
1498 | /*! |
1499 | * @function vfs_context_ucred |
1500 | * @abstract Get the credential associated with a vfs_context_t. |
1501 | * @discussion Succeeds if and only if the context has a thread, the thread has a task, and the task has a BSD proc. |
1502 | * @param ctx Context whose associated process to find. |
1503 | * @returns credential if process available; NULL otherwise |
1504 | */ |
1505 | kauth_cred_t vfs_context_ucred(vfs_context_t ctx); |
1506 | |
1507 | /*! |
1508 | * @function vfs_context_pid |
1509 | * @abstract Get the process id of the BSD process associated with a vfs_context_t. |
1510 | * @param ctx Context whose associated process to find. |
1511 | * @return Process id. |
1512 | */ |
1513 | int vfs_context_pid(vfs_context_t ctx); |
1514 | |
1515 | #ifdef KERNEL_PRIVATE |
1516 | /*! |
1517 | * @function vfs_context_copy_audit_token |
1518 | * @abstract Copy the audit token of the BSD process associated with a vfs_context_t. |
1519 | * @param ctx Context whose associated process to find. |
1520 | * @param token Pointer to audit token buffer which will receive a copy of the audit token |
1521 | * @return 0 on success, non-zero if there was a problem obtaining the token |
1522 | */ |
1523 | int vfs_context_copy_audit_token(vfs_context_t ctx, audit_token_t *token); |
1524 | |
1525 | #endif /* KERNEL_PRIVATE */ |
1526 | |
1527 | /*! |
1528 | * @function vfs_context_issignal |
1529 | * @abstract Get a bitfield of pending signals for the BSD process associated with a vfs_context_t. |
1530 | * @discussion The bitfield is constructed using the sigmask() macro, in the sense of bits |= sigmask(SIGSEGV). |
1531 | * @param ctx Context whose associated process to find. |
1532 | * @return Bitfield of pending signals. |
1533 | */ |
1534 | int vfs_context_issignal(vfs_context_t ctx, sigset_t mask); |
1535 | |
1536 | /*! |
1537 | * @function vfs_context_suser |
1538 | * @abstract Determine if a vfs_context_t corresponds to the superuser. |
1539 | * @param ctx Context to examine. |
1540 | * @return 0 if context belongs to superuser, EPERM otherwise. |
1541 | */ |
1542 | int vfs_context_suser(vfs_context_t ctx); |
1543 | |
1544 | /*! |
1545 | * @function vfs_context_is64bit |
1546 | * @abstract Determine if a vfs_context_t corresponds to a 64-bit user process. |
1547 | * @param ctx Context to examine. |
1548 | * @return Nonzero if context is of 64-bit process, 0 otherwise. |
1549 | */ |
1550 | int vfs_context_is64bit(vfs_context_t ctx); |
1551 | |
1552 | /*! |
1553 | * @function vfs_context_create |
1554 | * @abstract Create a new vfs_context_t with appropriate references held. |
1555 | * @discussion The context must be released with vfs_context_rele() when no longer in use. |
1556 | * @param ctx Context to copy, or NULL to use information from running thread. |
1557 | * @return The new context, or NULL in the event of failure. |
1558 | */ |
1559 | vfs_context_t vfs_context_create(vfs_context_t ctx); |
1560 | |
1561 | #ifdef KERNEL_PRIVATE |
1562 | /*! |
1563 | * @function vfs_context_create_with_proc |
1564 | * @abstract Create a new vfs_context_t with appropriate references held, using the specified proc as a template. |
1565 | * discussion The context must be released with vfs_context_rele() when no longer in use. |
1566 | * @param proc Process to use as a template for the new context. |
1567 | * @return The new context, or NULL in the event of failure. |
1568 | */ |
1569 | vfs_context_t vfs_context_create_with_proc(proc_t proc); |
1570 | #endif /* KERNEL_PRIVATE */ |
1571 | |
1572 | /*! |
1573 | * @function vfs_context_rele |
1574 | * @abstract Release references on components of a context and deallocate it. |
1575 | * @discussion A context should not be referenced after vfs_context_rele has been called. |
1576 | * @param ctx Context to release. |
1577 | * @return Always 0. |
1578 | */ |
1579 | int vfs_context_rele(vfs_context_t ctx); |
1580 | |
1581 | /*! |
1582 | * @function vfs_context_current |
1583 | * @abstract Get the vfs_context for the current thread, or the kernel context if there is no context for current thread. |
1584 | * @discussion Kexts should not use this function--it is preferred to use vfs_context_create(NULL) and vfs_context_rele(), which ensure proper reference counting of underlying structures. |
1585 | * @return Context for current thread, or kernel context if thread context is unavailable. |
1586 | */ |
1587 | vfs_context_t vfs_context_current(void) __pure2; |
1588 | #ifdef KERNEL_PRIVATE |
1589 | int vfs_context_bind(vfs_context_t); |
1590 | |
1591 | /*! |
1592 | * @function vfs_ctx_skipatime |
1593 | * @abstract Check to see if this context should skip updating a vnode's access times. |
1594 | * @discussion This is currently tied to the vnode rapid aging process. If the process is marked for rapid aging, |
1595 | * then the kernel should not update vnodes it touches for access time purposes. This will check to see if the |
1596 | * specified process and/or thread is marked for rapid aging when it manipulates vnodes. |
1597 | * @param ctx The context being investigated. |
1598 | * @return 1 if we should skip access time updates. |
1599 | * @return 0 if we should NOT skip access time updates. |
1600 | */ |
1601 | |
1602 | int vfs_ctx_skipatime(vfs_context_t ctx); |
1603 | |
1604 | #endif |
1605 | |
1606 | /* Supported filesystem tags for vfs_[set|get]_thread_fs_private */ |
1607 | #define FS_PRIVATE_TAG_APFS (1) |
1608 | |
1609 | /*! |
1610 | * @function vfs_set_thread_fs_private |
1611 | * @abstract Set the per-thread filesystem private data field. |
1612 | * @discussion Allows a filesystem to store an implementation specific value in the thread struct. |
1613 | * Note that this field is common to all filesystems thus re-entrancy should be taken into consideration. |
1614 | * @param tag Filesystem identification tag. |
1615 | * @param fs_private The value to be set. |
1616 | * @return 0 for success, ENOTSUP if the filesystem tag is not supported. |
1617 | */ |
1618 | int vfs_set_thread_fs_private(uint8_t tag, uint64_t fs_private); |
1619 | |
1620 | /*! |
1621 | * @function vfs_get_thread_fs_private |
1622 | * @abstract Return the per-thread filesystem private data field. |
1623 | * @discussion Returns the per-thread value that was set by vfs_set_thread_fs_private(). |
1624 | * @param tag Filesystem identification tag. |
1625 | * @param fs_private The stored per-thread value. |
1626 | * @return 0 for success, ENOTSUP if the filesystem tag is not supported. |
1627 | */ |
1628 | int vfs_get_thread_fs_private(uint8_t tag, uint64_t *fs_private); |
1629 | |
1630 | /*! |
1631 | * @function vflush |
1632 | * @abstract Reclaim the vnodes associated with a mount. |
1633 | * @param mp The mount whose vnodes to kill. |
1634 | * @param skipvp A specific vnode to not reclaim or to let interrupt an un-forced flush |
1635 | * @param flags Control which |
1636 | * @discussion This function is used to clear out the vnodes associated with a mount as part of the unmount process. |
1637 | * Its parameters can determine which vnodes to skip in the process and whether in-use vnodes should be forcibly reclaimed. |
1638 | * Filesystems should call this function from their unmount code, because VFS code will always call it with SKIPROOT | SKIPSWAP | SKIPSYSTEM; filesystems |
1639 | * must take care of such vnodes themselves. |
1640 | * SKIPSYSTEM skip vnodes marked VSYSTEM |
1641 | * FORCECLOSE force file closeure |
1642 | * WRITECLOSE only close writeable files |
1643 | * SKIPSWAP skip vnodes marked VSWAP |
1644 | * SKIPROOT skip root vnodes marked VROOT |
1645 | * @return 0 for success, EBUSY if vnodes were busy and FORCECLOSE was not set. |
1646 | */ |
1647 | int vflush(struct mount *mp, struct vnode *skipvp, int flags); |
1648 | |
1649 | /*! |
1650 | * @function vnode_get |
1651 | * @abstract Increase the iocount on a vnode. |
1652 | * @discussion If vnode_get() succeeds, the resulting io-reference must be dropped with vnode_put(). |
1653 | * This function succeeds unless the vnode in question is dead or in the process of dying AND the current iocount is zero. |
1654 | * This means that it can block an ongoing reclaim which is blocked behind some other iocount. |
1655 | * |
1656 | * On success, vnode_get() returns with an iocount held on the vnode; this type of reference is intended to be held only for short periods of time (e.g. |
1657 | * across a function call) and provides a strong guarantee about the life of the vnode; vnodes with positive iocounts cannot be |
1658 | * recycled, and an iocount is required for any operation on a vnode. However, vnode_get() does not provide any guarantees |
1659 | * about the identity of the vnode it is called on; unless there is a known existing iocount on the vnode at time the call is made, |
1660 | * it could be recycled and put back in use before the vnode_get() succeeds, so the caller may be referencing a |
1661 | * completely different vnode than was intended. vnode_getwithref() and vnode_getwithvid() |
1662 | * provide guarantees about vnode identity. |
1663 | * |
1664 | * @return 0 for success, ENOENT if the vnode is dead and without existing io-reference. |
1665 | */ |
1666 | int vnode_get(vnode_t); |
1667 | |
1668 | /*! |
1669 | * @function vnode_getwithvid |
1670 | * @abstract Increase the iocount on a vnode, checking that the vnode is alive and has not changed vid (i.e. been recycled) |
1671 | * @discussion If vnode_getwithvid() succeeds, the resulting io-reference must be dropped with vnode_put(). |
1672 | * This function succeeds unless the vnode in question is dead, in the process of dying, or has been recycled (and given a different vnode id). |
1673 | * The intended usage is that a vnode is stored and its vid (vnode_vid(vp)) recorded while an iocount is held (example: a filesystem hash). The |
1674 | * iocount is then dropped, and time passes (perhaps locks are dropped and picked back up). Subsequently, vnode_getwithvid() is called to get an iocount, |
1675 | * but we are alerted if the vnode has been recycled. |
1676 | * |
1677 | * On success, vnode_getwithvid() returns with an iocount held on the vnode; this type of reference is intended to be held only for short periods of time (e.g. |
1678 | * across a function call) and provides a strong guarantee about the life of the vnode. vnodes with positive iocounts cannot be |
1679 | * recycled. An iocount is required for any operation on a vnode. |
1680 | * @return 0 for success, ENOENT if the vnode is dead, in the process of being reclaimed, or has been recycled and reused. |
1681 | */ |
1682 | int vnode_getwithvid(vnode_t, uint32_t); |
1683 | |
1684 | #ifdef BSD_KERNEL_PRIVATE |
1685 | int vnode_getwithvid_drainok(vnode_t, uint32_t); |
1686 | #endif /* BSD_KERNEL_PRIVATE */ |
1687 | |
1688 | /*! |
1689 | * @function vnode_getwithref |
1690 | * @abstract Increase the iocount on a vnode on which a usecount (persistent reference) is held. |
1691 | * @discussion If vnode_getwithref() succeeds, the resulting io-reference must be dropped with vnode_put(). |
1692 | * vnode_getwithref() will succeed on dead vnodes; it should fail with ENOENT on vnodes which are in the process of being reclaimed. |
1693 | * Because it is only called with a usecount on the vnode, the caller is guaranteed that the vnode has not been |
1694 | * reused for a different file, though it may now be dead and have deadfs vnops (which return errors like EIO, ENXIO, ENOTDIR). |
1695 | * On success, vnode_getwithref() returns with an iocount held on the vnode; this type of reference is intended to be held only for short periods of time (e.g. |
1696 | * across a function call) and provides a strong guarantee about the life of the vnode. vnodes with positive iocounts cannot be |
1697 | * recycled. An iocount is required for any operation on a vnode. |
1698 | * @return 0 for success, ENOENT if the vnode is dead, in the process of being reclaimed, or has been recycled and reused. |
1699 | */ |
1700 | int vnode_getwithref(vnode_t vp); |
1701 | |
1702 | #ifdef BSD_KERNEL_PRIVATE |
1703 | int vnode_getwithref_noblock(vnode_t vp); |
1704 | #endif /* BSD_KERNEL_PRIVATE */ |
1705 | |
1706 | /*! |
1707 | * @function vnode_put |
1708 | * @abstract Decrement the iocount on a vnode. |
1709 | * @discussion vnode_put() is called to indicate that a vnode is no longer in active use. It removes the guarantee that a |
1710 | * vnode will not be recycled. This routine should be used to release io references no matter how they were obtained. |
1711 | * @param vp The vnode whose iocount to drop. |
1712 | * @return Always 0. |
1713 | */ |
1714 | int vnode_put(vnode_t vp); |
1715 | |
1716 | /*! |
1717 | * @function vnode_ref |
1718 | * @abstract Increment the usecount on a vnode. |
1719 | * @discussion If vnode_ref() succeeds, the resulting usecount must be released with vnode_rele(). vnode_ref() is called to obtain |
1720 | * a persistent reference on a vnode. This type of reference does not provide the same strong guarantee that a vnode will persist |
1721 | * as does an iocount--it merely ensures that a vnode will not be reused to represent a different file. However, a usecount may be |
1722 | * held for extended periods of time, whereas an iocount is intended to be obtained and released quickly as part of performing a |
1723 | * vnode operation. A holder of a usecount must call vnode_getwithref()/vnode_put() in order to perform any operations on that vnode. |
1724 | * @param vp The vnode on which to obtain a persistent reference. |
1725 | * @return 0 for success; ENOENT if the vnode is dead or in the process of being recycled AND the calling thread is not the vnode owner. |
1726 | */ |
1727 | int vnode_ref(vnode_t vp); |
1728 | |
1729 | /*! |
1730 | * @function vnode_rele |
1731 | * @abstract Decrement the usecount on a vnode. |
1732 | * @discussion vnode_rele() is called to relese a persistent reference on a vnode. Releasing the last usecount |
1733 | * opens the door for a vnode to be reused as a new file; it also triggers a VNOP_INACTIVE call to the filesystem, |
1734 | * though that will not happen immediately if there are outstanding iocount references. |
1735 | * @param vp The vnode whose usecount to drop. |
1736 | */ |
1737 | void vnode_rele(vnode_t vp); |
1738 | |
1739 | /*! |
1740 | * @function vnode_isinuse |
1741 | * @abstract Determine if the number of persistent (usecount) references on a vnode is greater than a given count. |
1742 | * @discussion vnode_isinuse() compares a vnode's usecount (corresponding to vnode_ref() calls) to its refcnt parameter |
1743 | * (the number of references the caller expects to be on the vnode). Note that "kusecount" references, corresponding |
1744 | * to parties interested only in event notifications, e.g. open(..., O_EVTONLY), are not counted towards the total; the comparison is |
1745 | * (usecount - kusecount > recnt). It is |
1746 | * also important to note that the result is only a snapshot; usecounts can change from moment to moment, and the result of vnode_isinuse |
1747 | * may no longer be correct the very moment that the caller receives it. |
1748 | * @param vp The vnode whose use-status to check. |
1749 | * @param refcnt The threshold for saying that a vnode is in use. |
1750 | */ |
1751 | int vnode_isinuse(vnode_t vp, int refcnt); |
1752 | |
1753 | /*! |
1754 | * @function vnode_hold |
1755 | * @abstract Increase the holdcount on a vnode. |
1756 | * @discussion the resulting hold must be dropped with vnode_drop(). |
1757 | * This function always succeeds and does not block but it can only be used in a context which already has a iocount or a usecount |
1758 | * or under a synchronization primitive which can block the reclaim (for example a filesystem hash table lock which is also taken in the |
1759 | * VNOP_RECLAIM implementation for that filesystem.) |
1760 | * A holdcount only prevents the vnode from being freed and provides no other guarantees. It allows safe access to vnode pointer |
1761 | * when the vnode access is no longer protected by an iocount, usecount or other sysnchronization primitive. |
1762 | * @param vp The vnode whose holdcount has to be incremented. |
1763 | * |
1764 | */ |
1765 | void vnode_hold(vnode_t vp); |
1766 | |
1767 | /*! |
1768 | * @function vnode_drop |
1769 | * @abstract decrease the holdcount on vnode. |
1770 | * @discussion If the holdcount goes to zero and the vnode has been reclaimed, the vnode may also be freed. |
1771 | * Any access to the vnode after calling vnode_drop is unsafe unless it is a under a iocount or a usecount which has |
1772 | * been acquired prior to calling vnode_drop. |
1773 | * @param vp The vnode whose holdcount has to be decremented. |
1774 | * @return vnode passed and NULLVP if the vnode was freed. |
1775 | */ |
1776 | vnode_t vnode_drop(vnode_t vp); |
1777 | |
1778 | /*! |
1779 | * @function vnode_recycle |
1780 | * @abstract Cause a vnode to be reclaimed and prepared for reuse. |
1781 | * @discussion Like all vnode KPIs, must be called with an iocount on the target vnode. |
1782 | * vnode_recycle() will mark that vnode for reclaim when all existing references are dropped. |
1783 | * @param vp The vnode to recycle. |
1784 | * @return 1 if the vnode was reclaimed (i.e. there were no existing references), 0 if it was only marked for future reclaim. |
1785 | */ |
1786 | int vnode_recycle(vnode_t vp); |
1787 | |
1788 | #ifdef KERNEL_PRIVATE |
1789 | |
1790 | #define VNODE_EVENT_DELETE 0x00000001 /* file was removed */ |
1791 | #define VNODE_EVENT_WRITE 0x00000002 /* file or directory contents changed */ |
1792 | #define VNODE_EVENT_EXTEND 0x00000004 /* ubc size increased */ |
1793 | #define VNODE_EVENT_ATTRIB 0x00000008 /* attributes changed (suitable for permission changes if type unknown)*/ |
1794 | #define VNODE_EVENT_LINK 0x00000010 /* link count changed */ |
1795 | #define VNODE_EVENT_RENAME 0x00000020 /* vnode was renamed */ |
1796 | #define VNODE_EVENT_PERMS 0x00000040 /* permissions changed: will cause a NOTE_ATTRIB */ |
1797 | #define VNODE_EVENT_FILE_CREATED 0x00000080 /* file created in directory: will cause NOTE_WRITE */ |
1798 | #define VNODE_EVENT_DIR_CREATED 0x00000100 /* directory created inside this directory: will cause NOTE_WRITE */ |
1799 | #define VNODE_EVENT_FILE_REMOVED 0x00000200 /* file removed from this directory: will cause NOTE_WRITE */ |
1800 | #define VNODE_EVENT_DIR_REMOVED 0x00000400 /* subdirectory from this directory: will cause NOTE_WRITE */ |
1801 | |
1802 | #ifdef BSD_KERNEL_PRIVATE |
1803 | #define VNODE_NOTIFY_ATTRS (VNODE_ATTR_BIT(va_fsid) | \ |
1804 | VNODE_ATTR_BIT(va_fileid)| \ |
1805 | VNODE_ATTR_BIT(va_mode) | \ |
1806 | VNODE_ATTR_BIT(va_uid) | \ |
1807 | VNODE_ATTR_BIT(va_document_id) | \ |
1808 | VNODE_ATTR_BIT(va_dirlinkcount) | \ |
1809 | VNODE_ATTR_BIT(va_nlink)) |
1810 | |
1811 | |
1812 | |
1813 | #endif /* BSD_KERNEL_PRIVATE */ |
1814 | |
1815 | /*! |
1816 | * @function vnode_ismonitored |
1817 | * @abstract Check whether a file has watchers that would make it useful to query a server |
1818 | * for file changes. |
1819 | * @param vp Vnode to examine. |
1820 | * @discussion Will not reenter the filesystem. |
1821 | * @return Zero if not monitored, nonzero if monitored. |
1822 | */ |
1823 | int vnode_ismonitored(vnode_t vp); |
1824 | |
1825 | |
1826 | /*! |
1827 | * @function vnode_isdyldsharedcache |
1828 | * @abstract Check whether a file is a dyld shared cache file. |
1829 | * @param vp Vnode to examine. |
1830 | * @discussion Will not reenter the filesystem. |
1831 | * @return nonzero if a dyld shared cache file, zero otherwise. |
1832 | */ |
1833 | int vnode_isdyldsharedcache(vnode_t vp); |
1834 | |
1835 | |
1836 | /*! |
1837 | * @function vn_authorize_unlink |
1838 | * @abstract Authorize an unlink operation given the vfs_context_t |
1839 | * @discussion Check if the context assocated with vfs_context_t is allowed to unlink the vnode vp in directory dvp. |
1840 | * @param dvp Parent vnode of the file to be unlinked |
1841 | * @param vp The vnode to be unlinked |
1842 | * @param cnp A componentname containing the name of the file to be unlinked. May be NULL. |
1843 | * @param reserved Pass NULL |
1844 | * @return returns zero if the operation is allowed, non-zero indicates the unlink is not authorized. |
1845 | */ |
1846 | int vn_authorize_unlink(vnode_t dvp, vnode_t vp, struct componentname *cnp, vfs_context_t ctx, void *reserved); |
1847 | |
1848 | |
1849 | /*! |
1850 | * @function vn_authorize_rmdir |
1851 | * @abstract Authorize an rmdir operation given the vfs_context_t |
1852 | * @discussion Check if the context assocated with vfs_context_t is allowed to rmdir the vnode vp in directory dvp. |
1853 | * @param dvp Parent vnode of the directory to be rmdir'ed |
1854 | * @param vp The vnode to be rmdir'ed |
1855 | * @param cnp A componentname containing the name of the file to be rmdir'ed. May be NULL. |
1856 | * @param reserved Pass NULL |
1857 | * @return returns zero if the operation is allowed, non-zero indicates the rmdir is not authorized. |
1858 | */ |
1859 | int vn_authorize_rmdir(vnode_t dvp, vnode_t vp, struct componentname *cnp, vfs_context_t ctx, void *reserved); |
1860 | |
1861 | /*! |
1862 | * @function vn_getpath_fsenter |
1863 | * @abstract Attempt to get a vnode's path, willing to enter the filesystem. |
1864 | * @discussion Paths to vnodes are not always straightforward: a file with multiple hard-links will have multiple pathnames, |
1865 | * and it is sometimes impossible to determine a vnode's full path. vn_getpath_fsenter() may enter the filesystem |
1866 | * to try to construct a path, so filesystems should be wary of calling it. |
1867 | * @param vp Vnode whose path to get |
1868 | * @param pathbuf Buffer in which to store path. |
1869 | * @param len Destination for length of resulting path string. Result will include NULL-terminator in count--that is, "len" |
1870 | * will be strlen(pathbuf) + 1. |
1871 | * @return 0 for success or an error. |
1872 | */ |
1873 | int vn_getpath_fsenter(struct vnode *vp, char *pathbuf, int *len); |
1874 | |
1875 | /*! |
1876 | * @function vn_getpath_no_firmlink |
1877 | * @abstract Attempt to get a vnode's path without a firm-link translation. |
1878 | * @discussion Paths to vnodes are not always straightforward: a file with multiple hard-links will have multiple pathnames, |
1879 | * and it is sometimes impossible to determine a vnode's full path. Like vn_getpath, it will not reenter the filesystem. |
1880 | * @param vp Vnode whose path to get |
1881 | * @param pathbuf Buffer in which to store path. |
1882 | * @param len Destination for length of resulting path string. Result will include NULL-terminator in count--that is, "len" |
1883 | * will be strlen(pathbuf) + 1. |
1884 | * @return 0 for success or an error. |
1885 | */ |
1886 | int vn_getpath_no_firmlink(struct vnode *vp, char *pathbuf, int *len); |
1887 | |
1888 | /*! |
1889 | * @function vn_getpath_fsenter_with_parent |
1890 | * @abstract Attempt to get a vnode's path by entering the file system if needed given a vnode and it's directory vnode. |
1891 | * @discussion Same as vn_getpath_fsenter but is given the directory vnode as well as the target vnode. Used |
1892 | * to get the path from the vnode while performing rename, rmdir, and unlink. This is done to avoid potential |
1893 | * dead lock if another thread is doing a forced unmount. |
1894 | * @param dvp Containing directory vnode. Must be holding an IO count. |
1895 | * @param vp Vnode whose path to get. Must be holding an IO count. |
1896 | * @param pathbuf Buffer in which to store path. |
1897 | * @param len Destination for length of resulting path string. Result will include NULL-terminator in count--that is, "len" |
1898 | * will be strlen(pathbuf) + 1. |
1899 | * @return 0 for success or an error. |
1900 | */ |
1901 | int vn_getpath_fsenter_with_parent(struct vnode *dvp, struct vnode *vp, char *pathbuf, int *len); |
1902 | |
1903 | /*! |
1904 | * @function vn_getpath_ext |
1905 | * @abstract Attempt to get a vnode's path without rentering filesystem (unless passed an option to allow) |
1906 | * @discussion Paths to vnodes are not always straightforward: a file with multiple hard-links will have multiple pathnames, |
1907 | * and it is sometimes impossible to determine a vnode's full path. vn_getpath_fsenter() may enter the filesystem |
1908 | * to try to construct a path, so filesystems should be wary of calling it. |
1909 | * @param vp Vnode whose path to get |
1910 | * @param dvp parent vnode of vnode whose path to get, can be NULL if not available. |
1911 | * @param pathbuf Buffer in which to store path. |
1912 | * @param len Destination for length of resulting path string. Result will include NULL-terminator in count--that is, "len" |
1913 | * will be strlen(pathbuf) + 1. |
1914 | * @param flags flags for controlling behavior. |
1915 | * @return 0 for success or an error. |
1916 | */ |
1917 | #define VN_GETPATH_NEW 0x0 |
1918 | int vn_getpath_ext(struct vnode *vp, struct vnode *dvp, char *pathbuf, size_t *len, int flags); |
1919 | |
1920 | /*! |
1921 | * @function vn_getpath_ext_with_mntlen |
1922 | * @abstract Attempt to get a vnode's path without rentering filesystem (unless passed an option to allow) |
1923 | * @discussion Paths to vnodes are not always straightforward: a file with multiple hard-links will have multiple pathnames, |
1924 | * and it is sometimes impossible to determine a vnode's full path. vn_getpath_fsenter() may enter the filesystem |
1925 | * to try to construct a path, so filesystems should be wary of calling it. |
1926 | * @param vp Vnode whose path to get |
1927 | * @param dvp parent vnode of vnode whose path to get, can be NULL if not available. |
1928 | * @param pathbuf Buffer in which to store path. |
1929 | * @param len Destination for length of resulting path string. Result will include NULL-terminator in count--that is, "len" |
1930 | * will be strlen(pathbuf) + 1. |
1931 | * @param mntlen Destination for length of path that is the mount point for the returned path. Will always be less than or equal to len. |
1932 | * will be strlen(pathbuf) + 1. |
1933 | * @param flags flags for controlling behavior. |
1934 | * @return 0 for success or an error. |
1935 | */ |
1936 | int vn_getpath_ext_with_mntlen(struct vnode *vp, struct vnode *dvp, char *pathbuf, size_t *len, size_t *mntlen, int flags); |
1937 | |
1938 | /* supported flags for vn_getpath_ext */ |
1939 | #define VN_GETPATH_FSENTER 0x0001 /* Can re-enter filesystem */ |
1940 | #define VN_GETPATH_NO_FIRMLINK 0x0002 |
1941 | #define VN_GETPATH_VOLUME_RELATIVE 0x0004 /* also implies VN_GETPATH_NO_FIRMLINK */ |
1942 | #define VN_GETPATH_NO_PROCROOT 0x0008 /* Give the non chrooted path for a process */ |
1943 | #define VN_GETPATH_CHECK_MOVED 0x0010 /* Return EAGAIN if the parent hierarchy is modified */ |
1944 | |
1945 | #endif /* KERNEL_PRIVATE */ |
1946 | |
1947 | #define VNODE_UPDATE_PARENT 0x01 |
1948 | #define VNODE_UPDATE_NAMEDSTREAM_PARENT VNODE_UPDATE_PARENT |
1949 | #define VNODE_UPDATE_NAME 0x02 |
1950 | #define VNODE_UPDATE_CACHE 0x04 |
1951 | #define VNODE_UPDATE_PURGE 0x08 |
1952 | #ifdef BSD_KERNEL_PRIVATE |
1953 | #define VNODE_UPDATE_PURGEFIRMLINK 0x10 |
1954 | #endif |
1955 | /*! |
1956 | * @function vnode_update_identity |
1957 | * @abstract Update vnode data associated with the vfs cache. |
1958 | * @discussion The vfs namecache is central to tracking vnode-identifying data and to locating files on the system. vnode_update_identity() |
1959 | * is used to update vnode data associated with the cache. It can set a vnode's parent and/or name (also potentially set by vnode_create()) |
1960 | * or flush cache data. |
1961 | * @param vp The vnode whose information to update. |
1962 | * @param dvp Parent to set on the vnode if VNODE_UPDATE_PARENT is used. |
1963 | * @param name Name to set in the cache for the vnode if VNODE_UPDATE_NAME is used. The buffer passed in can be subsequently freed, as the cache |
1964 | * does its own name storage. String should be NULL-terminated unless length and hash value are specified. |
1965 | * @param name_len Length of name, if known. Passing 0 causes the cache to determine the length itself. |
1966 | * @param name_hashval Hash value of name, if known. Passing 0 causes the cache to hash the name itself. |
1967 | * @param flags VNODE_UPDATE_PARENT: set parent. VNODE_UPDATE_NAME: set name. VNODE_UPDATE_CACHE: flush cache entries for hard links |
1968 | * associated with this file. VNODE_UPDATE_PURGE: flush cache entries for hard links and children of this file. |
1969 | */ |
1970 | void vnode_update_identity(vnode_t vp, vnode_t dvp, const char *name, int name_len, uint32_t name_hashval, int flags); |
1971 | |
1972 | /*! |
1973 | * @function vn_bwrite |
1974 | * @abstract System-provided implementation of "bwrite" vnop. |
1975 | * @discussion This routine is available for filesystems which do not want to implement their own "bwrite" vnop. It just calls |
1976 | * buf_bwrite() without modifying its arguments. |
1977 | * @param ap Standard parameters to a bwrite vnop. |
1978 | * @return Results of buf_bwrite directly. |
1979 | */ |
1980 | int vn_bwrite(struct vnop_bwrite_args *ap); |
1981 | |
1982 | /*! |
1983 | * @function vnode_authorize |
1984 | * @abstract Authorize a kauth-style action on a vnode. |
1985 | * @discussion Operations on dead vnodes are always allowed (though never do anything). |
1986 | * @param vp Vnode on which to authorize action. |
1987 | * @param dvp Parent of "vp," can be NULL. |
1988 | * @param action Action to authorize, e.g. KAUTH_VNODE_READ_DATA. See bsd/sys/kauth.h. |
1989 | * @param ctx Context for which to authorize actions. |
1990 | * @return EACCESS if permission is denied. 0 if operation allowed. Various errors from lower layers. |
1991 | */ |
1992 | int vnode_authorize(vnode_t vp, vnode_t dvp, kauth_action_t action, vfs_context_t ctx); |
1993 | |
1994 | #ifdef KERNEL_PRIVATE |
1995 | /*! |
1996 | * @function vnode_attr_authorize_init |
1997 | * @abstract Initialize attributes for authorization of a kauth-style action on a file system object based on its attributes. |
1998 | * @discussion This function tells the caller what attributes may be required for a authorizing |
1999 | * a kauth style action. |
2000 | * @param vap attributes of file system object on which to authorize action. |
2001 | * @param dvap attributes of parent of file system object, can be NULL. |
2002 | * @param action Action to authorize, e.g. KAUTH_VNODE_READ_DATA. See bsd/sys/kauth.h. |
2003 | * @param ctx Context for which to authorize actions. |
2004 | * @return EINVAL if a required parameters are not passed (for eg. not passing dvap when the action is KAUTH_ACTION_DELETE), 0 otherwise. |
2005 | */ |
2006 | #define VNODE_ATTR_AUTHORIZE_AVAILABLE 0x01 |
2007 | int vnode_attr_authorize_init(struct vnode_attr *vap, struct vnode_attr *dvap, kauth_action_t action, vfs_context_t ctx); |
2008 | |
2009 | /*! |
2010 | * @function vnode_attr_authorize |
2011 | * @abstract Authorize a kauth-style action on a file system object based on its attributes. |
2012 | * @discussion This function should be preceded by a call to vnode_attr_authorize_init to get what attributes are required. |
2013 | * @param vap attributes of file system object on which to authorize action. |
2014 | * @param dvap attributes of parent of file system object, can be NULL. |
2015 | * @param mp mountpoint to which file system object belongs, can be NULL. |
2016 | * @param action Action to authorize, e.g. KAUTH_VNODE_READ_DATA. See bsd/sys/kauth.h. |
2017 | * @param ctx Context for which to authorize actions. |
2018 | * @return EACCESS if permission is denied. 0 if operation allowed. Various errors from lower layers. |
2019 | */ |
2020 | int vnode_attr_authorize(struct vnode_attr *vap, struct vnode_attr *dvap, mount_t mp, kauth_action_t action, vfs_context_t ctx); |
2021 | #endif /* KERNEL_PRIVATE */ |
2022 | |
2023 | /*! |
2024 | * @function vnode_authattr |
2025 | * @abstract Given a vnode_attr structure, determine what kauth-style actions must be authorized in order to set those attributes. |
2026 | * @discussion vnode_authorize requires kauth-style actions; if we want to set a vnode_attr structure on a vnode, we need to translate |
2027 | * the set of attributes to a set of kauth-style actions. This routine will return errors for certain obviously disallowed, or |
2028 | * incoherent, actions. |
2029 | * @param vp The vnode on which to authorize action. |
2030 | * @param vap Pointer to vnode_attr struct containing desired attributes to set and their values. |
2031 | * @param actionp Destination for set of actions to authorize |
2032 | * @param ctx Context for which to authorize actions. |
2033 | * @return 0 (and a result in "actionp" for success. Otherwise, an error code. |
2034 | */ |
2035 | int vnode_authattr(vnode_t vp, struct vnode_attr *vap, kauth_action_t *actionp, vfs_context_t ctx); |
2036 | |
2037 | /*! |
2038 | * @function vnode_authattr_new |
2039 | * @abstract Initialize and validate file creation parameters with respect to the current context. |
2040 | * @discussion vnode_authattr_new() will fill in unitialized values in the vnode_attr struct with defaults, and will validate the structure |
2041 | * with respect to the current context for file creation. |
2042 | * @param dvp The directory in which creation will occur. |
2043 | * @param vap Pointer to vnode_attr struct containing desired attributes to set and their values. |
2044 | * @param noauth If 1, treat the caller as the superuser, i.e. do not check permissions. |
2045 | * @param ctx Context for which to authorize actions. |
2046 | * @return KAUTH_RESULT_ALLOW for success, an error to indicate invalid or disallowed attributes. |
2047 | */ |
2048 | int vnode_authattr_new(vnode_t dvp, struct vnode_attr *vap, int noauth, vfs_context_t ctx); |
2049 | |
2050 | /*! |
2051 | * @function vnode_close |
2052 | * @abstract Close a file as opened with vnode_open(). |
2053 | * @discussion vnode_close() drops the refcount (persistent reference) picked up in vnode_open() and calls down to the filesystem with VNOP_CLOSE. It should |
2054 | * be called with both an iocount and a refcount on the vnode and will drop both. |
2055 | * @param vp The vnode to close. |
2056 | * @param flags Flags to close: FWASWRITTEN indicates that the file was written to. |
2057 | * @param ctx Context against which to validate operation. |
2058 | * @return 0 for success or an error from the filesystem. |
2059 | */ |
2060 | errno_t vnode_close(vnode_t vp, int flags, vfs_context_t ctx); |
2061 | |
2062 | /*! |
2063 | * @function vn_getpath |
2064 | * @abstract Construct the path to a vnode. |
2065 | * @discussion Paths to vnodes are not always straightforward: a file with multiple hard-links will have multiple pathnames, |
2066 | * and it is sometimes impossible to determine a vnode's full path. vn_getpath() will not enter the filesystem. |
2067 | * @param vp The vnode whose path to obtain. |
2068 | * @param pathbuf Destination for pathname; should be of size MAXPATHLEN |
2069 | * @param len Destination for length of resulting path string. Result will include NULL-terminator in count--that is, "len" |
2070 | * will be strlen(pathbuf) + 1. |
2071 | * @return 0 for success or an error code. |
2072 | */ |
2073 | int vn_getpath(struct vnode *vp, char *pathbuf, int *len); |
2074 | |
2075 | /*! |
2076 | * @function vnode_notify |
2077 | * @abstract Send a notification up to VFS. |
2078 | * @param vp Vnode for which to provide notification. |
2079 | * @param vap Attributes for that vnode, to be passed to fsevents. |
2080 | * @discussion Filesystem determines which attributes to pass up using |
2081 | * vfs_get_notify_attributes(&vap). The most specific events possible should be passed, |
2082 | * e.g. VNODE_EVENT_FILE_CREATED on a directory rather than just VNODE_EVENT_WRITE, but |
2083 | * a less specific event can be passed up if more specific information is not available. |
2084 | * Will not reenter the filesystem. |
2085 | * @return 0 for success, else an error code. |
2086 | */ |
2087 | int vnode_notify(vnode_t vp, uint32_t events, struct vnode_attr *vap); |
2088 | |
2089 | /*! |
2090 | * @function vfs_get_notify_attributes |
2091 | * @abstract Determine what attributes are required to send up a notification with vnode_notify(). |
2092 | * @param vap Structure to initialize and activate required attributes on. |
2093 | * @discussion Will not reenter the filesystem. |
2094 | * @return 0 for success, nonzero for error (currently always succeeds). |
2095 | */ |
2096 | int vfs_get_notify_attributes(struct vnode_attr *vap); |
2097 | |
2098 | /* |
2099 | * Flags for the vnode_lookup and vnode_open |
2100 | */ |
2101 | #define VNODE_LOOKUP_NOFOLLOW 0x01 |
2102 | #define VNODE_LOOKUP_NOCROSSMOUNT 0x02 |
2103 | #define VNODE_LOOKUP_CROSSMOUNTNOWAIT 0x04 |
2104 | /*! |
2105 | * @function vnode_lookup |
2106 | * @abstract Convert a path into a vnode. |
2107 | * @discussion This routine is a thin wrapper around xnu-internal lookup routines; if successful, |
2108 | * it returns with an iocount held on the resulting vnode which must be dropped with vnode_put(). |
2109 | * @param path Path to look up. |
2110 | * @param flags VNODE_LOOKUP_NOFOLLOW: do not follow symbolic links. VNODE_LOOKUP_NOCROSSMOUNT: do not cross mount points. |
2111 | * @return Results 0 for success or an error code. |
2112 | */ |
2113 | errno_t vnode_lookup(const char *path, int flags, vnode_t *vpp, vfs_context_t ctx); |
2114 | |
2115 | #ifdef KERNEL_PRIVATE |
2116 | /*! |
2117 | * @function vnode_lookup starting from a directory vnode (only if path is relative) |
2118 | * @abstract Convert a path into a vnode. |
2119 | * @discussion This routine is a thin wrapper around xnu-internal lookup routines; if successful, |
2120 | * it returns with an iocount held on the resulting vnode which must be dropped with vnode_put(). |
2121 | * @param path Path to look up. |
2122 | * @param flags VNODE_LOOKUP_NOFOLLOW: do not follow symbolic links. VNODE_LOOKUP_NOCROSSMOUNT: do not cross mount points. |
2123 | * @param start_dvp vnode of directory to start lookup from. This parameter is ignored if path is absolute. start_dvp should |
2124 | * have an iocount on it. |
2125 | * @return Results 0 for success or an error code. |
2126 | */ |
2127 | errno_t vnode_lookupat(const char *path, int flags, vnode_t *vpp, vfs_context_t ctx, vnode_t start_dvp); |
2128 | #endif |
2129 | |
2130 | /*! |
2131 | * @function vnode_open |
2132 | * @abstract Open a file identified by a path--roughly speaking an in-kernel open(2). |
2133 | * @discussion If vnode_open() succeeds, it returns with both an iocount and a usecount on the |
2134 | * returned vnode. Both will be release once vnode_close is called. |
2135 | * @param path Path to look up. |
2136 | * @param fmode e.g. O_NONBLOCK, O_APPEND; see bsd/sys/fcntl.h. |
2137 | * @param cmode Permissions with which to create file if it does not exist. |
2138 | * @param flags Same as vnode_lookup(). |
2139 | * @param vpp Destination for vnode. |
2140 | * @param ctx Context with which to authorize open/creation. |
2141 | * @return 0 for success or an error code. |
2142 | */ |
2143 | errno_t vnode_open(const char *path, int fmode, int cmode, int flags, vnode_t *vpp, vfs_context_t ctx); |
2144 | |
2145 | /* |
2146 | * exported vnode operations |
2147 | */ |
2148 | |
2149 | /*! |
2150 | * @function vnode_iterate |
2151 | * @abstract Perform an operation on (almost) all vnodes from a given mountpoint. |
2152 | * @param mp Mount whose vnodes to operate on. |
2153 | * @param flags |
2154 | * VNODE_RELOAD Mark inactive vnodes for recycle. |
2155 | * VNODE_WAIT |
2156 | * VNODE_WRITEABLE Only examine vnodes with writes in progress. |
2157 | * VNODE_WITHID No effect. |
2158 | * VNODE_NOLOCK_INTERNAL No effect. |
2159 | * VNODE_NODEAD No effect. |
2160 | * VNODE_NOSUSPEND No effect. |
2161 | * VNODE_ITERATE_ALL No effect. |
2162 | * VNODE_ITERATE_ACTIVE No effect. |
2163 | * VNODE_ITERATE_INACTIVE No effect. |
2164 | * |
2165 | * @param callout Function to call on each vnode. |
2166 | * @param arg Argument which will be passed to callout along with each vnode. |
2167 | * @return Zero for success, else an error code. Will return 0 immediately if there are no vnodes hooked into the mount. |
2168 | * @discussion Skips vnodes which are dead, in the process of reclaim, suspended, or of type VNON. |
2169 | */ |
2170 | int vnode_iterate(struct mount *mp, int flags, int (*callout)(struct vnode *, void *), void *arg); |
2171 | |
2172 | /* |
2173 | * flags passed into vnode_iterate |
2174 | */ |
2175 | #define VNODE_RELOAD 0x01 |
2176 | #define VNODE_WAIT 0x02 |
2177 | #define VNODE_WRITEABLE 0x04 |
2178 | #define VNODE_WITHID 0x08 |
2179 | #define VNODE_NOLOCK_INTERNAL 0x10 |
2180 | #define VNODE_NODEAD 0x20 |
2181 | #define VNODE_NOSUSPEND 0x40 |
2182 | #define VNODE_ITERATE_ALL 0x80 |
2183 | #define VNODE_ITERATE_ACTIVE 0x100 |
2184 | #define VNODE_ITERATE_INACTIVE 0x200 |
2185 | #ifdef BSD_KERNEL_PRIVATE |
2186 | #define VNODE_ALWAYS 0x400 |
2187 | #define VNODE_DRAINO 0x800 |
2188 | #define VNODE_PAGER 0x1000 |
2189 | #define VNODE_NOBLOCK 0x2000 |
2190 | #endif /* BSD_KERNEL_PRIVATE */ |
2191 | |
2192 | /* |
2193 | * return values from callback |
2194 | */ |
2195 | #define VNODE_RETURNED 0 /* done with vnode, reference can be dropped */ |
2196 | #define VNODE_RETURNED_DONE 1 /* done with vnode, reference can be dropped, terminate iteration */ |
2197 | #define VNODE_CLAIMED 2 /* don't drop reference */ |
2198 | #define VNODE_CLAIMED_DONE 3 /* don't drop reference, terminate iteration */ |
2199 | |
2200 | /*! |
2201 | * @function vn_revoke |
2202 | * @abstract Invalidate all references to a vnode. |
2203 | * @discussion Reclaims the vnode, giving it deadfs vnops (though not halting operations which are already in progress). |
2204 | * Also reclaims all aliased vnodes (important for devices). People holding usecounts on the vnode, e.g. processes |
2205 | * with the file open, will find that all subsequent operations but closing the file fail. |
2206 | * @param vp The vnode to revoke. |
2207 | * @param flags Unused. |
2208 | * @param ctx Context against which to validate operation. |
2209 | * @return 0 always. |
2210 | */ |
2211 | int vn_revoke(vnode_t vp, int flags, vfs_context_t ctx); |
2212 | |
2213 | /* namecache function prototypes */ |
2214 | /*! |
2215 | * @function cache_lookup |
2216 | * @abstract Check for a filename in a directory using the VFS name cache. |
2217 | * @discussion cache_lookup() will flush negative cache entries and return 0 if the operation of the cn_nameiop is CREATE or RENAME. |
2218 | * Often used from the filesystem during a lookup vnop. The filesystem will be called to if there is a negative cache entry for a file, |
2219 | * so it can make sense to initially check for negative entries (and possibly lush them). |
2220 | * @param dvp Directory in which lookup is occurring. |
2221 | * @param vpp Destination for vnode pointer. |
2222 | * @param cnp Various data about lookup, e.g. filename and intended operation. |
2223 | * @return ENOENT: the filesystem has previously added a negative entry with cache_enter() to indicate that there is no |
2224 | * file of the given name in "dp." -1: successfully found a cached vnode (vpp is set). 0: No data in the cache, or operation is CREATE/RENAME. |
2225 | */ |
2226 | int cache_lookup(vnode_t dvp, vnode_t *vpp, struct componentname *cnp); |
2227 | |
2228 | /*! |
2229 | * @function cache_enter |
2230 | * @abstract Add a (name,vnode) entry to the VFS namecache. |
2231 | * @discussion Generally used to add a cache entry after a successful filesystem-level lookup or to add a |
2232 | * negative entry after one which did not find its target. |
2233 | * @param dvp Directory in which file lives. |
2234 | * @param vp File to add to cache. A non-NULL vp is stored for rapid access; a NULL vp indicates |
2235 | * that there is no such file in the directory and speeds future failed lookups. |
2236 | * @param cnp Various data about lookup, e.g. filename and intended operation. |
2237 | */ |
2238 | void cache_enter(vnode_t dvp, vnode_t vp, struct componentname *cnp); |
2239 | |
2240 | /*! |
2241 | * @function cache_purge |
2242 | * @abstract Remove all data relating to a vnode from the namecache. |
2243 | * @discussion Will flush all hardlinks to the vnode as well as all children (should any exist). Logical |
2244 | * to use when cached data about a vnode becomes invalid, for instance in an unlink. |
2245 | * @param vp The vnode to purge. |
2246 | */ |
2247 | void cache_purge(vnode_t vp); |
2248 | |
2249 | /*! |
2250 | * @function cache_purge_negatives |
2251 | * @abstract Remove all negative cache entries which are children of a given vnode. |
2252 | * @discussion Appropriate to use when negative cache information for a directory could have |
2253 | * become invalid, e.g. after file creation. |
2254 | * @param vp The vnode whose negative children to purge. |
2255 | */ |
2256 | void cache_purge_negatives(vnode_t vp); |
2257 | |
2258 | |
2259 | /* |
2260 | * Global string-cache routines. You can pass zero for nc_hash |
2261 | * if you don't know it (add_name() will then compute the hash). |
2262 | * There are no flags for now but maybe someday. |
2263 | */ |
2264 | /*! |
2265 | * @function vfs_addname |
2266 | * @abstract Deprecated |
2267 | * @discussion vnode_update_identity() and vnode_create() make vfs_addname() unnecessary for kexts. |
2268 | */ |
2269 | const char *vfs_addname(const char *name, uint32_t len, uint32_t nc_hash, uint32_t flags); |
2270 | |
2271 | /*! |
2272 | * @function vfs_removename |
2273 | * @abstract Deprecated |
2274 | * @discussion vnode_update_identity() and vnode_create() make vfs_addname() unnecessary for kexts. |
2275 | */ |
2276 | int vfs_removename(const char *name); |
2277 | |
2278 | /*! |
2279 | * @function vcount |
2280 | * @abstract Count total references to a given file, disregarding "kusecount" (event listener, as with O_EVTONLY) references. |
2281 | * @discussion For a regular file, just return (usecount-kusecount); for device files, return the sum over all |
2282 | * vnodes 'v' which reference that device of (usecount(v) - kusecount(v)). Note that this is merely a snapshot and could be |
2283 | * invalid by the time the caller checks the result. |
2284 | * @param vp The vnode whose references to count. |
2285 | * @return Count of references. |
2286 | */ |
2287 | int vcount(vnode_t vp); |
2288 | |
2289 | /*! |
2290 | * @function vn_path_package_check |
2291 | * @abstract Figure out if a path corresponds to a Mac OS X package. |
2292 | * @discussion Determines if the extension on a path is a known OS X extension type. |
2293 | * @param vp Unused. |
2294 | * @param path Path to check. |
2295 | * @param pathlen Size of path buffer. |
2296 | * @param component Set to index of start of last path component if the path is found to be a package. Set to -1 if |
2297 | * the path is not a known package type. |
2298 | * @return 0 unless some parameter was invalid, in which case EINVAL is returned. Determine package-ness by checking |
2299 | * what *component is set to. |
2300 | */ |
2301 | int vn_path_package_check(vnode_t vp, char *path, int pathlen, int *component); |
2302 | |
2303 | #ifdef KERNEL_PRIVATE |
2304 | /*! |
2305 | * @function vn_searchfs_inappropriate_name |
2306 | * @abstract Figure out if the component is inappropriate for a SearchFS query. |
2307 | * @param name component to check |
2308 | * @param len length of component. |
2309 | * @return 0 if no match, 1 if inappropriate. |
2310 | */ |
2311 | int vn_searchfs_inappropriate_name(const char *name, int len); |
2312 | #endif |
2313 | |
2314 | /*! |
2315 | * @function vn_rdwr |
2316 | * @abstract Read from or write to a file. |
2317 | * @discussion vn_rdwr() abstracts the details of constructing a uio and picking a vnode operation to allow |
2318 | * simple in-kernel file I/O. |
2319 | * @param rw UIO_READ for a read, UIO_WRITE for a write. |
2320 | * @param vp The vnode on which to perform I/O. |
2321 | * @param base Start of buffer into which to read or from which to write data. |
2322 | * @param len Length of buffer. |
2323 | * @param offset Offset within the file at which to start I/O. |
2324 | * @param segflg What kind of address "base" is. See uio_seg definition in sys/uio.h. UIO_SYSSPACE for kernelspace, UIO_USERSPACE for userspace. |
2325 | * UIO_USERSPACE32 and UIO_USERSPACE64 are in general preferred, but vn_rdwr will make sure that has the correct address sizes. |
2326 | * @param ioflg Defined in vnode.h, e.g. IO_NOAUTH, IO_NOCACHE. |
2327 | * @param cred Credential to pass down to filesystem for authentication. |
2328 | * @param aresid Destination for amount of requested I/O which was not completed, as with uio_resid(). |
2329 | * @param p Process requesting I/O. |
2330 | * @return 0 for success; errors from filesystem, and EIO if did not perform all requested I/O and the "aresid" parameter is NULL. |
2331 | */ |
2332 | int vn_rdwr(enum uio_rw rw, struct vnode *vp, caddr_t base, int len, off_t offset, enum uio_seg segflg, int ioflg, kauth_cred_t cred, int *aresid, proc_t p); |
2333 | |
2334 | /*! |
2335 | * @function vnode_getname |
2336 | * @abstract Get the name of a vnode from the VFS namecache. |
2337 | * @discussion Not all vnodes have names, and vnode names can change (notably, hardlinks). Use this routine at your own risk. |
2338 | * The string is returned with a refcount incremented in the cache; callers must call vnode_putname() to release that reference. |
2339 | * @param vp The vnode whose name to grab. |
2340 | * @return The name, or NULL if unavailable. |
2341 | */ |
2342 | const char *vnode_getname(vnode_t vp); |
2343 | |
2344 | /*! |
2345 | * @function vnode_putname |
2346 | * @abstract Release a reference on a name from the VFS cache. |
2347 | * @discussion Should be called on a string obtained with vnode_getname(). |
2348 | * @param name String to release. |
2349 | */ |
2350 | void vnode_putname(const char *name); |
2351 | |
2352 | /*! |
2353 | * @function vnode_getparent |
2354 | * @abstract Get an iocount on the parent of a vnode. |
2355 | * @discussion A vnode's parent may change over time or be reclaimed, so vnode_getparent() may return different |
2356 | * results at different times (e.g. a multiple-hardlink file). The parent is returned with an iocount which must |
2357 | * subsequently be dropped with vnode_put(). |
2358 | * @param vp The vnode whose parent to grab. |
2359 | * @return Parent if available, else NULL. |
2360 | */ |
2361 | vnode_t vnode_getparent(vnode_t vp); |
2362 | |
2363 | /*! |
2364 | * @function vnode_setdirty |
2365 | * @abstract Mark the vnode as having data or metadata that needs to be written out during reclaim |
2366 | * @discussion The vnode should be marked as dirty anytime a file system defers flushing of data or meta-data associated with it. |
2367 | * @param vp the vnode to mark as dirty |
2368 | * @return 0 if successful else an error code. |
2369 | */ |
2370 | int vnode_setdirty(vnode_t vp); |
2371 | |
2372 | /*! |
2373 | * @function vnode_cleardirty |
2374 | * @abstract Mark the vnode as clean i.e. all its data or metadata has been flushed |
2375 | * @discussion The vnode should be marked as clean whenever the file system is done flushing data or meta-data associated with it. |
2376 | * @param vp the vnode to clear as being dirty |
2377 | * @return 0 if successful else an error code. |
2378 | */ |
2379 | int vnode_cleardirty(vnode_t vp); |
2380 | |
2381 | /*! |
2382 | * @function vnode_isdirty |
2383 | * @abstract Determine if a vnode is marked dirty. |
2384 | * @discussion The vnode should be marked as clean whenever the file system is done flushing data or meta-data associated with it. |
2385 | * @param vp the vnode to test. |
2386 | * @return Non-zero if the vnode is dirty, 0 otherwise. |
2387 | */ |
2388 | int vnode_isdirty(vnode_t vp); |
2389 | |
2390 | #ifdef KERNEL_PRIVATE |
2391 | /*! |
2392 | * @function vnode_lookup_continue_needed |
2393 | * @abstract Determine whether vnode needs additional processing in VFS before being opened. |
2394 | * @discussion If result is zero, filesystem can open this vnode. If result is nonzero, |
2395 | * additional processing is needed in VFS (e.g. symlink, mountpoint). Nonzero results should |
2396 | * be passed up to VFS. |
2397 | * @param vp Vnode to consider opening (found by filesystem). |
2398 | * @param cnp Componentname as passed to filesystem from VFS. |
2399 | * @result 0 to indicate that a vnode can be opened, or an error that should be passed up to VFS. |
2400 | */ |
2401 | int vnode_lookup_continue_needed(vnode_t vp, struct componentname *cnp); |
2402 | |
2403 | /*! |
2404 | * @function vnode_isonssd |
2405 | * @abstract Return whether or not the storage device backing a vnode is a solid state drive |
2406 | * @param vp The vnode whose backing store properties are to be queried |
2407 | * @return TRUE if storage device is an SSD, FALSE if otherwise. |
2408 | */ |
2409 | boolean_t vnode_isonssd(vnode_t vp); |
2410 | |
2411 | /*! |
2412 | * @function vnode_istty |
2413 | * @abstract Determine if the given vnode represents a tty device. |
2414 | * @param vp Vnode to examine. |
2415 | * @result Non-zero to indicate that the vnode represents a tty device. Zero otherwise. |
2416 | */ |
2417 | int vnode_istty(vnode_t vp); |
2418 | |
2419 | /*! |
2420 | * @function bdevvp |
2421 | * @abstract create a vnode for a given dev_t |
2422 | * @result non-zero to indicate failure, vnode provided in *vpp arg |
2423 | */ |
2424 | int bdevvp(dev_t dev, struct vnode **vpp); |
2425 | |
2426 | /* |
2427 | * @function vnode_getfromfd |
2428 | * @abstract get a vnode from a file descriptor |
2429 | * @result non-zero to indicate failure, vnode provided in *vpp arg |
2430 | */ |
2431 | int vnode_getfromfd(vfs_context_t ctx, int fd, vnode_t *vpp); |
2432 | |
2433 | /* |
2434 | * @function vnode_parent |
2435 | * @abstract Get the parent of a vnode. |
2436 | * @param vp The vnode whose parent to grab. |
2437 | * @return Parent if available, else NULL. |
2438 | */ |
2439 | vnode_t vnode_parent(vnode_t vp); |
2440 | |
2441 | /* |
2442 | * @function vnode_getparent_and_name |
2443 | * @abstract Get an iocount on the parent of a vnode and the name of a vnode from the VFS namecache. |
2444 | * @discussion Combined version of vnode_getparent() and vnode_getname() to acquire both vnode name and parent |
2445 | * without releasing the name cache lock in interim. The parent is returned with an iocount which must |
2446 | * subsequently be dropped with vnode_put(). callers must call vnode_putname() to release the name reference. |
2447 | * @param vp The vnode whose parent and name to grab. |
2448 | * @param out_pvp A pointer to the output vnode parent. |
2449 | * @param out_name A pointer to the output vnode name. |
2450 | */ |
2451 | void vnode_getparent_and_name(vnode_t vp, vnode_t *out_pvp, const char **out_name); |
2452 | |
2453 | /* |
2454 | * @function vfs_context_thread |
2455 | * @abstract Return the Mach thread associated with a vfs_context_t. |
2456 | * @param ctx The context to use. |
2457 | * @return The thread for this context, or NULL, if there is not one. |
2458 | */ |
2459 | thread_t vfs_context_thread(vfs_context_t ctx); |
2460 | |
2461 | /* |
2462 | * @function vfs_context_task |
2463 | * @abstract Return the Mach task associated with a vfs_context_t. |
2464 | * @param ctx The context to use. |
2465 | * @return The task for this context, or NULL, if there is not one. |
2466 | */ |
2467 | task_t vfs_context_task(vfs_context_t ctx); |
2468 | |
2469 | /*! |
2470 | * @function vnode_isauthfs |
2471 | * @abstract Determine if the given vnode is on an authenticated volume. |
2472 | * @param vp Vnode to examine. |
2473 | * @result Non-zero to indicate that the vnode is on an authenticated volume. Zero otherwise. |
2474 | */ |
2475 | int vnode_isauthfs(vnode_t vp); |
2476 | |
2477 | #endif /* KERNEL_PRIVATE */ |
2478 | |
2479 | #ifdef BSD_KERNEL_PRIVATE |
2480 | /* Not in export list so can be private */ |
2481 | struct stat; |
2482 | int vn_stat(struct vnode *vp, void * sb, kauth_filesec_t *xsec, int isstat64, int needsrealdev, |
2483 | vfs_context_t ctx); |
2484 | int vn_stat_noauth(struct vnode *vp, void * sb, kauth_filesec_t *xsec, int isstat64, int needsrealdev, |
2485 | vfs_context_t ctx, struct ucred *file_cred); |
2486 | int vaccess(mode_t file_mode, uid_t uid, gid_t gid, |
2487 | mode_t acc_mode, kauth_cred_t cred); |
2488 | int check_mountedon(dev_t dev, enum vtype type, int *errorp); |
2489 | int vn_getcdhash(struct vnode *vp, off_t offset, unsigned char *cdhash); |
2490 | void vnode_reclaim(vnode_t); |
2491 | vnode_t current_workingdir(void); |
2492 | void *vnode_vfsfsprivate(vnode_t); |
2493 | struct vfsstatfs *vnode_vfsstatfs(vnode_t); |
2494 | uint32_t vnode_vfsvisflags(vnode_t); |
2495 | uint32_t vnode_vfscmdflags(vnode_t); |
2496 | int vnode_is_openevt(vnode_t); |
2497 | void vnode_set_openevt(vnode_t); |
2498 | void vnode_clear_openevt(vnode_t); |
2499 | int vnode_isstandard(vnode_t); |
2500 | int vnode_makeimode(int, int); |
2501 | enum vtype vnode_iftovt(int); |
2502 | int vnode_vttoif(enum vtype); |
2503 | int vnode_isshadow(vnode_t); |
2504 | boolean_t vnode_on_reliable_media(vnode_t); |
2505 | /* |
2506 | * Indicate that a file has multiple hard links. VFS will always call |
2507 | * VNOP_LOOKUP on this vnode. Volfs will always ask for it's parent |
2508 | * object ID (instead of using the v_parent pointer). |
2509 | */ |
2510 | void vnode_setparent(vnode_t, vnode_t); |
2511 | void vnode_setname(vnode_t, char *); |
2512 | #if CONFIG_IOSCHED |
2513 | vnode_t vnode_mountdevvp(vnode_t); |
2514 | #endif |
2515 | #endif /* BSD_KERNEL_PRIVATE */ |
2516 | |
2517 | #ifdef KERNEL_PRIVATE |
2518 | /*! |
2519 | * @function vnode_getname_printable |
2520 | * @abstract Get a non-null printable name of a vnode. |
2521 | * @Used to make sure a printable name is returned for all vnodes. If a name exists or can be artificially created, the routine creates a new entry in the VFS namecache. Otherwise, the function returns an artificially created vnode name which is safer and easier to use. vnode_putname_printable() should be used to release names obtained by this routine. |
2522 | * @param vp The vnode whose name to grab. |
2523 | * @return The printable name. |
2524 | */ |
2525 | const char *vnode_getname_printable(vnode_t vp); |
2526 | /*! |
2527 | * @function vnode_putname_printable |
2528 | * @abstract Release a reference on a name from the VFS cache if it was added by the matching vnode_getname_printable() call. |
2529 | * @param name String to release. |
2530 | */ |
2531 | void vnode_putname_printable(const char *name); |
2532 | #endif // KERNEL_PRIVATE |
2533 | |
2534 | /*! |
2535 | * @function vnode_getbackingvnode |
2536 | * @abstract If the input vnode is a NULLFS mirrored vnode, then return the vnode it wraps. |
2537 | * @Used to un-mirror files, primarily for security purposes. On success, out_vp is always set to a vp with an iocount. The caller must release the iocount. |
2538 | * @param in_vp The vnode being asked about |
2539 | * @param out_vpp A pointer to the output vnode, unchanged on error |
2540 | * @return 0 on Success, ENOENT if in_vp doesn't mirror anything, EINVAL on parameter errors. |
2541 | */ |
2542 | int vnode_getbackingvnode(vnode_t in_vp, vnode_t* out_vpp); |
2543 | |
2544 | /* |
2545 | * Helper functions for implementing VNOP_GETATTRLISTBULK for a filesystem |
2546 | */ |
2547 | |
2548 | /*! |
2549 | * @function vfs_setup_vattr_from_attrlist |
2550 | * @abstract Setup a vnode_attr structure given an attrlist structure. |
2551 | * @Used by a VNOP_GETATTRLISTBULK implementation to setup a vnode_attr structure from a attribute list. It also returns the fixed size of the attribute buffer required. |
2552 | * @warning this forces new fork attr behavior, i.e. reinterpret forkattr bits as ATTR_CMNEXT |
2553 | * @param alp Pointer to attribute list structure. |
2554 | * @param vap Pointer to vnode_attr structure. |
2555 | * @param obj_vtype Type of object - If VNON is passed, then the type is ignored and common, file and dir attrs are used to initialise the vattrs. If set to VDIR, only common and directory attributes are used. For all other types, only common and file attrbutes are used. |
2556 | * @param attr_fixed_sizep Returns the fixed length required in the attrbute buffer for the object. NULL should be passed if it is not required. |
2557 | * @param ctx vfs context of caller. |
2558 | * @return error. |
2559 | */ |
2560 | errno_t vfs_setup_vattr_from_attrlist(struct attrlist *alp, struct vnode_attr *vap, enum vtype obj_vtype, ssize_t *attr_fixed_sizep, vfs_context_t ctx); |
2561 | |
2562 | /*! |
2563 | * @function vfs_attr_pack |
2564 | * @abstract Pack a vnode_attr structure into a buffer in the same format as getattrlist(2). |
2565 | * @Used by a VNOP_GETATTRLISTBULK implementation to pack data provided into a vnode_attr structure into a buffer the way getattrlist(2) does. |
2566 | * @param vp If available, the vnode for which the attributes are being given, NULL if vnode is not available (which will usually be the case for a VNOP_GETATTRLISTBULK implementation. |
2567 | * @param uio - a uio_t initialised with one iovec.. |
2568 | * @param alp - Pointer to an attrlist structure. |
2569 | * @param options - options for call (same as options for getattrlistbulk(2)). |
2570 | * @param vap Pointer to a filled in vnode_attr structure. Data from the vnode_attr structure will be used to copy and lay out the data in the required format for getatrlistbulk(2) by this function. |
2571 | * @param fndesc Currently unused |
2572 | * @param ctx vfs context of caller. |
2573 | * @return error. |
2574 | */ |
2575 | errno_t vfs_attr_pack(vnode_t vp, uio_t uio, struct attrlist *alp, uint64_t options, struct vnode_attr *vap, void *fndesc, vfs_context_t ctx); |
2576 | |
2577 | /*! |
2578 | * @function vfs_attr_pack_ex |
2579 | * @abstract Pack a vnode_attr structure into a buffer in the same format as getattrlist(2). |
2580 | * @Used by a VNOP_GETATTRLISTBULK implementation to pack data provided into a vnode_attr structure into a buffer the way getattrlist(2) does. |
2581 | * @param mp the mount structure for the filesystem the packing operation is happening on. |
2582 | * @param vp If available, the vnode for which the attributes are being given, NULL if vnode is not available (which will usually be the case for a VNOP_GETATTRLISTBULK implementation. |
2583 | * @param uio - a uio_t initialised with one iovec.. |
2584 | * @param alp - Pointer to an attrlist structure. |
2585 | * @param options - options for call (same as options for getattrlistbulk(2)). |
2586 | * @param vap Pointer to a filled in vnode_attr structure. Data from the vnode_attr structure will be used to copy and lay out the data in the required format for getatrlistbulk(2) by this function. |
2587 | * @param fndesc Currently unused |
2588 | * @param ctx vfs context of caller. |
2589 | * @return error. |
2590 | */ |
2591 | errno_t vfs_attr_pack_ext(mount_t mp, vnode_t vp, uio_t uio, struct attrlist *alp, uint64_t options, struct vnode_attr *vap, void *fndesc, vfs_context_t ctx); |
2592 | |
2593 | #ifdef KERNEL_PRIVATE |
2594 | |
2595 | /* vnode manipulations for devices */ |
2596 | int vnode_cmp_chrtoblk(vnode_t vp, vnode_t blk_vp); |
2597 | |
2598 | // Returns a value suitable, safe and consistent for tracing and logging |
2599 | vm_offset_t kdebug_vnode(vnode_t vp); |
2600 | int vn_pathconf(vnode_t, int, int32_t *, vfs_context_t); |
2601 | int vnode_should_flush_after_write(vnode_t vp, int ioflag); |
2602 | void vfs_setowner(mount_t mp, uid_t uid, gid_t gid); |
2603 | uint64_t vfs_idle_time(mount_t mp); |
2604 | // Required until XsanFS is fixed... |
2605 | #ifndef vnode_usecount |
2606 | int vnode_usecount(vnode_t vp); |
2607 | #endif |
2608 | int vnode_writecount(vnode_t vp); |
2609 | int vnode_iocount(vnode_t vp); |
2610 | void vnode_rele_ext(vnode_t, int, int); |
2611 | int is_package_name(const char *name, int len); |
2612 | int vfs_context_issuser(vfs_context_t); |
2613 | int vfs_context_iskernel(vfs_context_t); |
2614 | vfs_context_t vfs_context_kernel(void) __pure2; /* get from 1st kernel thread */ |
2615 | vnode_t vfs_context_cwd(vfs_context_t); |
2616 | vnode_t vfs_context_get_cwd(vfs_context_t); /* get cwd with iocount */ |
2617 | int vnode_isnoflush(vnode_t); |
2618 | void vnode_setnoflush(vnode_t); |
2619 | void vnode_clearnoflush(vnode_t); |
2620 | #if CONFIG_IO_COMPRESSION_STATS |
2621 | void vnode_iocs_record_and_free(vnode_t); |
2622 | #endif /* CONFIG_IO_COMPRESSION_STATS */ |
2623 | |
2624 | #define BUILDPATH_NO_FS_ENTER 0x1 /* Use cache values, do not enter file system */ |
2625 | #define BUILDPATH_CHECKACCESS 0x2 /* Check if parents have search rights */ |
2626 | #define BUILDPATH_CHECK_MOVED 0x4 /* Return EAGAIN if the parent hierarchy is modified */ |
2627 | #define BUILDPATH_VOLUME_RELATIVE 0x8 /* Return path relative to the nearest mount point */ |
2628 | #define BUILDPATH_NO_FIRMLINK 0x10 /* Return non-firmlinked path */ |
2629 | #define BUILDPATH_NO_PROCROOT 0x20 /* Return path relative to system root, not the process root */ |
2630 | |
2631 | int vnode_issubdir(vnode_t vp, vnode_t dvp, int *is_subdir, vfs_context_t ctx); |
2632 | |
2633 | struct vniodesc; |
2634 | typedef struct vniodesc *vniodesc_t; |
2635 | |
2636 | #define VNIO_SUPPORT_PRESENT |
2637 | errno_t vnio_openfd(int fd, vniodesc_t *vniop); |
2638 | errno_t vnio_close(vniodesc_t); |
2639 | errno_t vnio_read(vniodesc_t, uio_t); |
2640 | vnode_t vnio_vnode(vniodesc_t); |
2641 | |
2642 | #endif // KERNEL_PRIVATE |
2643 | |
2644 | #ifdef XNU_KERNEL_PRIVATE |
2645 | int build_path(vnode_t first_vp, char *buff, int buflen, int *outlen, int flags, vfs_context_t ctx); |
2646 | #endif |
2647 | |
2648 | __END_DECLS |
2649 | |
2650 | #endif /* KERNEL */ |
2651 | |
2652 | /* |
2653 | * Structure for vnode level IO compression stats |
2654 | */ |
2655 | |
2656 | #define IOCS_BUFFER_NUM_SIZE_BUCKETS 10 |
2657 | #define IOCS_BUFFER_MAX_BUCKET 9 |
2658 | #define IOCS_BUFFER_NUM_COMPRESSION_BUCKETS 7 |
2659 | #define IOCS_BLOCK_NUM_SIZE_BUCKETS 16 |
2660 | |
2661 | struct io_compression_stats { |
2662 | uint64_t uncompressed_size; |
2663 | uint64_t compressed_size; |
2664 | uint32_t buffer_size_compression_dist[IOCS_BUFFER_NUM_SIZE_BUCKETS][IOCS_BUFFER_NUM_COMPRESSION_BUCKETS]; |
2665 | uint32_t block_compressed_size_dist[IOCS_BLOCK_NUM_SIZE_BUCKETS]; |
2666 | }; |
2667 | typedef struct io_compression_stats *io_compression_stats_t; |
2668 | |
2669 | #define IOCS_SBE_PATH_LEN 128 |
2670 | #define IOCS_PATH_START_BYTES_TO_COPY 108 |
2671 | #define IOCS_PATH_END_BYTES_TO_COPY 20 /* Includes null termination */ |
2672 | |
2673 | #define IOCS_SYSCTL_LIVE 0x00000001 |
2674 | #define IOCS_SYSCTL_STORE_BUFFER_RD_ONLY 0x00000002 |
2675 | #define IOCS_SYSCTL_STORE_BUFFER_MARK 0x00000004 |
2676 | |
2677 | struct iocs_store_buffer_entry { |
2678 | char path_name[IOCS_SBE_PATH_LEN]; |
2679 | struct io_compression_stats iocs; |
2680 | }; |
2681 | |
2682 | #ifdef KERNEL_PRIVATE |
2683 | boolean_t vnode_is_rsr(vnode_t); |
2684 | #endif |
2685 | |
2686 | #endif /* !_VNODE_H_ */ |
2687 | |