]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/vnode.h
xnu-1228.7.58.tar.gz
[apple/xnu.git] / bsd / sys / vnode.h
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
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
9bccf70c 67#include <sys/appleapiopts.h>
1c79356b 68#include <sys/cdefs.h>
1c79356b 69#ifdef KERNEL
91447636
A
70#include <sys/kernel_types.h>
71#include <sys/signal.h>
72#endif
1c79356b
A
73
74/*
75 * The vnode is the focus of all file activity in UNIX. There is a
76 * unique vnode allocated for each active file, each current directory,
77 * each mounted-on file, text file, and the root.
78 */
79
80/*
81 * Vnode types. VNON means no type.
82 */
83enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD, VSTR,
84 VCPLX };
85
86/*
87 * Vnode tag types.
88 * These are for the benefit of external programs only (e.g., pstat)
89 * and should NEVER be inspected by the kernel.
90 */
91enum vtagtype {
92 VT_NON, VT_UFS, VT_NFS, VT_MFS, VT_MSDOSFS, VT_LFS, VT_LOFS, VT_FDESC,
93 VT_PORTAL, VT_NULL, VT_UMAP, VT_KERNFS, VT_PROCFS, VT_AFS, VT_ISOFS,
2d21ac55
A
94 VT_UNION, VT_HFS, VT_ZFS, VT_DEVFS, VT_WEBDAV, VT_UDF, VT_AFP,
95 VT_CDDA, VT_CIFS, VT_OTHER};
1c79356b 96
91447636 97
1c79356b 98/*
91447636 99 * flags for VNOP_BLOCKMAP
1c79356b 100 */
91447636
A
101#define VNODE_READ 0x01
102#define VNODE_WRITE 0x02
1c79356b 103
9bccf70c 104
9bccf70c 105
91447636
A
106/* flags for VNOP_ALLOCATE */
107#define PREALLOCATE 0x00000001 /* preallocate allocation blocks */
108#define ALLOCATECONTIG 0x00000002 /* allocate contigious space */
109#define ALLOCATEALL 0x00000004 /* allocate all requested space */
110 /* or no space at all */
111#define FREEREMAINDER 0x00000008 /* deallocate allocated but */
112 /* unfilled blocks */
113#define ALLOCATEFROMPEOF 0x00000010 /* allocate from the physical eof */
114#define ALLOCATEFROMVOL 0x00000020 /* allocate from the volume offset */
9bccf70c 115
1c79356b 116/*
91447636 117 * Token indicating no attribute value yet assigned. some user source uses this
1c79356b 118 */
91447636 119#define VNOVAL (-1)
1c79356b 120
91447636 121#ifdef KERNEL
55e303ae 122
91447636
A
123/*
124 * Flags for ioflag.
125 */
126#define IO_UNIT 0x0001 /* do I/O as atomic unit */
127#define IO_APPEND 0x0002 /* append write to end */
128#define IO_SYNC 0x0004 /* do I/O synchronously */
129#define IO_NODELOCKED 0x0008 /* underlying node already locked */
130#define IO_NDELAY 0x0010 /* FNDELAY flag set in file table */
131#define IO_NOZEROFILL 0x0020 /* F_SETSIZE fcntl uses to prevent zero filling */
2d21ac55
A
132#ifdef XNU_KERNEL_PRIVATE
133#define IO_REVOKE IO_NOZEROFILL /* revoked close for tty, will Not be used in conjunction */
134#endif /* XNU_KERNEL_PRIVATE */
91447636
A
135#define IO_TAILZEROFILL 0x0040 /* zero fills at the tail of write */
136#define IO_HEADZEROFILL 0x0080 /* zero fills at the head of write */
137#define IO_NOZEROVALID 0x0100 /* do not zero fill if valid page */
138#define IO_NOZERODIRTY 0x0200 /* do not zero fill if page is dirty */
139#define IO_CLOSE 0x0400 /* I/O issued from close path */
140#define IO_NOCACHE 0x0800 /* same effect as VNOCACHE_DATA, but only for this 1 I/O */
141#define IO_RAOFF 0x1000 /* same effect as VRAOFF, but only for this 1 I/O */
142#define IO_DEFWRITE 0x2000 /* defer write if vfs.defwrite is set */
2d21ac55
A
143#define IO_PASSIVE 0x4000 /* this I/O is marked as background I/O so it won't throttle Throttleable I/O */
144#define IO_BACKGROUND IO_PASSIVE /* used for backward compatibility. to be removed after IO_BACKGROUND is no longer
145 * used by DiskImages in-kernel mode */
146#define IO_NOAUTH 0x8000 /* No authorization checks. */
147
55e303ae 148
1c79356b 149/*
91447636
A
150 * Component Name: this structure describes the pathname
151 * information that is passed through the VNOP interface.
1c79356b 152 */
91447636
A
153struct componentname {
154 /*
155 * Arguments to lookup.
156 */
157 u_long cn_nameiop; /* lookup operation */
158 u_long cn_flags; /* flags (see below) */
159#ifdef BSD_KERNEL_PRIVATE
160 vfs_context_t cn_context;
161 void * pad_obsolete2;
162
163/* XXX use of these defines are deprecated */
164#define cn_proc (cn_context->vc_proc + 0) /* non-lvalue */
165#define cn_cred (cn_context->vc_ucred + 0) /* non-lvalue */
166
167#else
168 void * obsolete1; /* use vfs_context_t */
169 void * obsolete2; /* use vfs_context_t */
170#endif
171 /*
172 * Shared between lookup and commit routines.
173 */
174 char *cn_pnbuf; /* pathname buffer */
175 long cn_pnlen; /* length of allocated buffer */
176 char *cn_nameptr; /* pointer to looked up name */
177 long cn_namelen; /* length of looked up component */
178 u_long cn_hash; /* hash value of looked up name */
179 long cn_consume; /* chars to consume in lookup() */
180};
0b4e3aa0 181
1c79356b 182/*
91447636 183 * component name operations (for VNOP_LOOKUP)
1c79356b 184 */
91447636
A
185#define LOOKUP 0 /* perform name lookup only */
186#define CREATE 1 /* setup for file creation */
187#define DELETE 2 /* setup for file deletion */
188#define RENAME 3 /* setup for file renaming */
189#define OPMASK 3 /* mask for operation */
190
191/*
192 * component name operational modifier flags
193 */
2d21ac55
A
194#define FOLLOW 0x00000040 /* follow symbolic links */
195#define NOTRIGGER 0x10000000 /* don't trigger automounts */
91447636
A
196
197/*
198 * component name parameter descriptors.
199 */
2d21ac55
A
200#define ISDOTDOT 0x00002000 /* current component name is .. */
201#define MAKEENTRY 0x00004000 /* entry is to be added to name cache */
202#define ISLASTCN 0x00008000 /* this is last component of pathname */
203#define ISWHITEOUT 0x00020000 /* found whiteout */
204#define DOWHITEOUT 0x00040000 /* do whiteouts */
91447636
A
205
206
207
208/* The following structure specifies a vnode for creation */
209struct vnode_fsparam {
210 struct mount * vnfs_mp; /* mount point to which this vnode_t is part of */
211 enum vtype vnfs_vtype; /* vnode type */
212 const char * vnfs_str; /* File system Debug aid */
213 struct vnode * vnfs_dvp; /* The parent vnode */
214 void * vnfs_fsnode; /* inode */
215 int (**vnfs_vops)(void *); /* vnode dispatch table */
216 int vnfs_markroot; /* is this a root vnode in FS (not a system wide one) */
217 int vnfs_marksystem; /* is a system vnode */
218 dev_t vnfs_rdev; /* dev_t for block or char vnodes */
219 off_t vnfs_filesize; /* that way no need for getattr in UBC */
220 struct componentname * vnfs_cnp; /* component name to add to namecache */
221 uint32_t vnfs_flags; /* flags */
1c79356b
A
222};
223
91447636
A
224#define VNFS_NOCACHE 0x01 /* do not add to name cache at this time */
225#define VNFS_CANTCACHE 0x02 /* never add this instance to the name cache */
2d21ac55 226#define VNFS_ADDFSREF 0x04 /* take fs (named) reference */
91447636
A
227
228#define VNCREATE_FLAVOR 0
229#define VCREATESIZE sizeof(struct vnode_fsparam)
230
1c79356b 231/*
91447636
A
232 * Vnode attributes, new-style.
233 *
234 * The vnode_attr structure is used to transact attribute changes and queries
235 * with the filesystem.
236 *
237 * Note that this structure may be extended, but existing fields must not move.
1c79356b 238 */
91447636
A
239
240#define VATTR_INIT(v) do {(v)->va_supported = (v)->va_active = 0ll; (v)->va_vaflags = 0;} while(0)
241#define VATTR_SET_ACTIVE(v, a) ((v)->va_active |= VNODE_ATTR_ ## a)
242#define VATTR_SET_SUPPORTED(v, a) ((v)->va_supported |= VNODE_ATTR_ ## a)
243#define VATTR_IS_SUPPORTED(v, a) ((v)->va_supported & VNODE_ATTR_ ## a)
244#define VATTR_CLEAR_ACTIVE(v, a) ((v)->va_active &= ~VNODE_ATTR_ ## a)
245#define VATTR_CLEAR_SUPPORTED(v, a) ((v)->va_supported &= ~VNODE_ATTR_ ## a)
246#define VATTR_IS_ACTIVE(v, a) ((v)->va_active & VNODE_ATTR_ ## a)
247#define VATTR_ALL_SUPPORTED(v) (((v)->va_active & (v)->va_supported) == (v)->va_active)
248#define VATTR_INACTIVE_SUPPORTED(v) do {(v)->va_active &= ~(v)->va_supported; (v)->va_supported = 0;} while(0)
249#define VATTR_SET(v, a, x) do { (v)-> a = (x); VATTR_SET_ACTIVE(v, a);} while(0)
250#define VATTR_WANTED(v, a) VATTR_SET_ACTIVE(v, a)
251#define VATTR_RETURN(v, a, x) do { (v)-> a = (x); VATTR_SET_SUPPORTED(v, a);} while(0)
252#define VATTR_NOT_RETURNED(v, a) (VATTR_IS_ACTIVE(v, a) && !VATTR_IS_SUPPORTED(v, a))
1c79356b
A
253
254/*
91447636
A
255 * Two macros to simplify conditional checking in kernel code.
256 */
257#define VATTR_IS(v, a, x) (VATTR_IS_SUPPORTED(v, a) && (v)-> a == (x))
258#define VATTR_IS_NOT(v, a, x) (VATTR_IS_SUPPORTED(v, a) && (v)-> a != (x))
259
260#define VNODE_ATTR_va_rdev (1LL<< 0) /* 00000001 */
261#define VNODE_ATTR_va_nlink (1LL<< 1) /* 00000002 */
262#define VNODE_ATTR_va_total_size (1LL<< 2) /* 00000004 */
263#define VNODE_ATTR_va_total_alloc (1LL<< 3) /* 00000008 */
264#define VNODE_ATTR_va_data_size (1LL<< 4) /* 00000010 */
265#define VNODE_ATTR_va_data_alloc (1LL<< 5) /* 00000020 */
266#define VNODE_ATTR_va_iosize (1LL<< 6) /* 00000040 */
267#define VNODE_ATTR_va_uid (1LL<< 7) /* 00000080 */
268#define VNODE_ATTR_va_gid (1LL<< 8) /* 00000100 */
269#define VNODE_ATTR_va_mode (1LL<< 9) /* 00000200 */
270#define VNODE_ATTR_va_flags (1LL<<10) /* 00000400 */
271#define VNODE_ATTR_va_acl (1LL<<11) /* 00000800 */
272#define VNODE_ATTR_va_create_time (1LL<<12) /* 00001000 */
273#define VNODE_ATTR_va_access_time (1LL<<13) /* 00002000 */
274#define VNODE_ATTR_va_modify_time (1LL<<14) /* 00004000 */
275#define VNODE_ATTR_va_change_time (1LL<<15) /* 00008000 */
276#define VNODE_ATTR_va_backup_time (1LL<<16) /* 00010000 */
277#define VNODE_ATTR_va_fileid (1LL<<17) /* 00020000 */
278#define VNODE_ATTR_va_linkid (1LL<<18) /* 00040000 */
279#define VNODE_ATTR_va_parentid (1LL<<19) /* 00080000 */
280#define VNODE_ATTR_va_fsid (1LL<<20) /* 00100000 */
281#define VNODE_ATTR_va_filerev (1LL<<21) /* 00200000 */
282#define VNODE_ATTR_va_gen (1LL<<22) /* 00400000 */
283#define VNODE_ATTR_va_encoding (1LL<<23) /* 00800000 */
284#define VNODE_ATTR_va_type (1LL<<24) /* 01000000 */
285#define VNODE_ATTR_va_name (1LL<<25) /* 02000000 */
286#define VNODE_ATTR_va_uuuid (1LL<<26) /* 04000000 */
287#define VNODE_ATTR_va_guuid (1LL<<27) /* 08000000 */
288#define VNODE_ATTR_va_nchildren (1LL<<28) /* 10000000 */
2d21ac55 289#define VNODE_ATTR_va_dirlinkcount (1LL<<29) /* 20000000 */
91447636
A
290
291#define VNODE_ATTR_BIT(n) (VNODE_ATTR_ ## n)
292/*
293 * Read-only attributes.
294 */
295#define VNODE_ATTR_RDONLY (VNODE_ATTR_BIT(va_rdev) | \
296 VNODE_ATTR_BIT(va_nlink) | \
297 VNODE_ATTR_BIT(va_total_size) | \
298 VNODE_ATTR_BIT(va_total_alloc) | \
299 VNODE_ATTR_BIT(va_data_alloc) | \
300 VNODE_ATTR_BIT(va_iosize) | \
301 VNODE_ATTR_BIT(va_fileid) | \
302 VNODE_ATTR_BIT(va_linkid) | \
303 VNODE_ATTR_BIT(va_parentid) | \
304 VNODE_ATTR_BIT(va_fsid) | \
305 VNODE_ATTR_BIT(va_filerev) | \
306 VNODE_ATTR_BIT(va_gen) | \
307 VNODE_ATTR_BIT(va_name) | \
308 VNODE_ATTR_BIT(va_type) | \
2d21ac55
A
309 VNODE_ATTR_BIT(va_nchildren) | \
310 VNODE_ATTR_BIT(va_dirlinkcount))
91447636
A
311/*
312 * Attributes that can be applied to a new file object.
1c79356b 313 */
91447636
A
314#define VNODE_ATTR_NEWOBJ (VNODE_ATTR_BIT(va_rdev) | \
315 VNODE_ATTR_BIT(va_uid) | \
316 VNODE_ATTR_BIT(va_gid) | \
317 VNODE_ATTR_BIT(va_mode) | \
318 VNODE_ATTR_BIT(va_flags) | \
319 VNODE_ATTR_BIT(va_acl) | \
320 VNODE_ATTR_BIT(va_create_time) | \
321 VNODE_ATTR_BIT(va_modify_time) | \
322 VNODE_ATTR_BIT(va_change_time) | \
323 VNODE_ATTR_BIT(va_encoding) | \
324 VNODE_ATTR_BIT(va_type) | \
325 VNODE_ATTR_BIT(va_uuuid) | \
326 VNODE_ATTR_BIT(va_guuid))
327
328struct vnode_attr {
329 /* bitfields */
330 uint64_t va_supported;
331 uint64_t va_active;
332
333 /*
334 * Control flags. The low 16 bits are reserved for the
335 * ioflags being passed for truncation operations.
336 */
337 int va_vaflags;
338
339 /* traditional stat(2) parameter fields */
340 dev_t va_rdev; /* device id (device nodes only) */
341 uint64_t va_nlink; /* number of references to this file */
342 uint64_t va_total_size; /* size in bytes of all forks */
343 uint64_t va_total_alloc; /* disk space used by all forks */
344 uint64_t va_data_size; /* size in bytes of the main(data) fork */
345 uint64_t va_data_alloc; /* disk space used by the main(data) fork */
346 uint32_t va_iosize; /* optimal I/O blocksize */
347
348 /* file security information */
349 uid_t va_uid; /* owner UID */
350 gid_t va_gid; /* owner GID */
351 mode_t va_mode; /* posix permissions */
352 uint32_t va_flags; /* file flags */
353 struct kauth_acl *va_acl; /* access control list */
354
355 /* timestamps */
356 struct timespec va_create_time; /* time of creation */
357 struct timespec va_access_time; /* time of last access */
358 struct timespec va_modify_time; /* time of last data modification */
359 struct timespec va_change_time; /* time of last metadata change */
360 struct timespec va_backup_time; /* time of last backup */
361
362 /* file parameters */
363 uint64_t va_fileid; /* file unique ID in filesystem */
364 uint64_t va_linkid; /* file link unique ID */
365 uint64_t va_parentid; /* parent ID */
366 uint32_t va_fsid; /* filesystem ID */
367 uint64_t va_filerev; /* file revision counter */ /* XXX */
368 uint32_t va_gen; /* file generation count */ /* XXX - relationship of
369 * these two? */
370 /* misc parameters */
371 uint32_t va_encoding; /* filename encoding script */
372
373 enum vtype va_type; /* file type (create only) */
374 char * va_name; /* Name for ATTR_CMN_NAME; MAXPATHLEN bytes */
375 guid_t va_uuuid; /* file owner UUID */
376 guid_t va_guuid; /* file group UUID */
377
2d21ac55
A
378 /* Meaningful for directories only */
379 uint64_t va_nchildren; /* Number of items in a directory */
380 uint64_t va_dirlinkcount; /* Real references to dir (i.e. excluding "." and ".." refs) */
91447636
A
381
382 /* add new fields here only */
383};
1c79356b
A
384
385/*
91447636 386 * Flags for va_vaflags.
1c79356b 387 */
91447636
A
388#define VA_UTIMES_NULL 0x010000 /* utimes argument was NULL */
389#define VA_EXCLUSIVE 0x020000 /* exclusive create request */
390
391
1c79356b
A
392
393/*
91447636 394 * Modes. Some values same as Ixxx entries from inode.h for now.
1c79356b 395 */
91447636
A
396#define VSUID 0x800 /*04000*/ /* set user id on execution */
397#define VSGID 0x400 /*02000*/ /* set group id on execution */
398#define VSVTX 0x200 /*01000*/ /* save swapped text even after use */
399#define VREAD 0x100 /*00400*/ /* read, write, execute permissions */
400#define VWRITE 0x080 /*00200*/
401#define VEXEC 0x040 /*00100*/
402
1c79356b 403
1c79356b
A
404/*
405 * Convert between vnode types and inode formats (since POSIX.1
406 * defines mode word of stat structure in terms of inode formats).
407 */
408extern enum vtype iftovt_tab[];
409extern int vttoif_tab[];
410#define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12])
411#define VTTOIF(indx) (vttoif_tab[(int)(indx)])
412#define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode))
413
91447636 414
1c79356b
A
415/*
416 * Flags to various vnode functions.
417 */
418#define SKIPSYSTEM 0x0001 /* vflush: skip vnodes marked VSYSTEM */
419#define FORCECLOSE 0x0002 /* vflush: force file closeure */
420#define WRITECLOSE 0x0004 /* vflush: only close writeable files */
421#define SKIPSWAP 0x0008 /* vflush: skip vnodes marked VSWAP */
91447636 422#define SKIPROOT 0x0010 /* vflush: skip root vnodes marked VROOT */
1c79356b
A
423
424#define DOCLOSE 0x0008 /* vclean: close active files */
425
426#define V_SAVE 0x0001 /* vinvalbuf: sync file first */
427#define V_SAVEMETA 0x0002 /* vinvalbuf: leave indirect blocks */
428
91447636 429#define REVOKEALL 0x0001 /* vnop_revoke: revoke all aliases */
1c79356b 430
91447636
A
431/* VNOP_REMOVE: do not delete busy files (Carbon remove file semantics) */
432#define VNODE_REMOVE_NODELETEBUSY 0x0001
1c79356b 433
91447636
A
434/* VNOP_READDIR flags: */
435#define VNODE_READDIR_EXTENDED 0x0001 /* use extended directory entries */
436#define VNODE_READDIR_REQSEEKOFF 0x0002 /* requires seek offset (cookies) */
3a60a9f5 437#define VNODE_READDIR_SEEKOFF32 0x0004 /* seek offset values should fit in 32 bits */
1c79356b 438
1c79356b 439
91447636 440#define NULLVP ((struct vnode *)NULL)
1c79356b
A
441
442/*
443 * Macro/function to check for client cache inconsistency w.r.t. leasing.
444 */
445#define LEASE_READ 0x1 /* Check lease for readers */
446#define LEASE_WRITE 0x2 /* Check lease for modifiers */
1c79356b 447
1c79356b 448
91447636
A
449#ifndef BSD_KERNEL_PRIVATE
450struct vnodeop_desc;
451#endif
1c79356b 452
91447636 453extern int desiredvnodes; /* number of vnodes desired */
1c79356b
A
454
455
456/*
457 * This structure is used to configure the new vnodeops vector.
458 */
459struct vnodeopv_entry_desc {
460 struct vnodeop_desc *opve_op; /* which operation this is */
461 int (*opve_impl)(void *); /* code implementing this operation */
462};
463struct vnodeopv_desc {
464 /* ptr to the ptr to the vector where op should go */
465 int (***opv_desc_vector_p)(void *);
466 struct vnodeopv_entry_desc *opv_desc_ops; /* null terminated list */
467};
468
469/*
470 * A default routine which just returns an error.
471 */
91447636 472int vn_default_error(void);
1c79356b
A
473
474/*
475 * A generic structure.
476 * This can be used by bypass routines to identify generic arguments.
477 */
91447636 478struct vnop_generic_args {
1c79356b
A
479 struct vnodeop_desc *a_desc;
480 /* other random data follows, presumably */
481};
482
91447636
A
483#ifndef _KAUTH_ACTION_T
484typedef int kauth_action_t;
485# define _KAUTH_ACTION_T
486#endif
487
488#include <sys/vnode_if.h>
489
490__BEGIN_DECLS
491
492errno_t vnode_create(int, size_t, void *, vnode_t *);
493int vnode_addfsref(vnode_t);
494int vnode_removefsref(vnode_t);
495
496int vnode_hasdirtyblks(vnode_t);
497int vnode_hascleanblks(vnode_t);
2d21ac55 498#define VNODE_ASYNC_THROTTLE 15
91447636 499/* timeout is in 10 msecs and not hz tick based */
2d21ac55 500int vnode_waitforwrites(vnode_t, int, int, int, const char *);
91447636
A
501void vnode_startwrite(vnode_t);
502void vnode_writedone(vnode_t);
503
504enum vtype vnode_vtype(vnode_t);
505uint32_t vnode_vid(vnode_t);
506mount_t vnode_mountedhere(vnode_t vp);
507mount_t vnode_mount(vnode_t);
2d21ac55
A
508errno_t vfs_mountref(mount_t);
509errno_t vfs_mountrele(mount_t);
91447636
A
510dev_t vnode_specrdev(vnode_t);
511void * vnode_fsnode(vnode_t);
512void vnode_clearfsnode(vnode_t);
513
514int vnode_isvroot(vnode_t);
515int vnode_issystem(vnode_t);
2d21ac55 516int vnode_isswap(vnode_t vp);
91447636
A
517int vnode_ismount(vnode_t);
518int vnode_isreg(vnode_t);
519int vnode_isdir(vnode_t);
520int vnode_islnk(vnode_t);
521int vnode_isfifo(vnode_t);
522int vnode_isblk(vnode_t);
523int vnode_ischr(vnode_t);
524
2d21ac55
A
525#ifdef __APPLE_API_UNSTABLE
526int vnode_isnamedstream(vnode_t);
527#endif
528
529enum vtype vnode_iftovt(int);
530int vnode_vttoif(enum vtype);
531int vnode_makeimode(int, int);
532
91447636
A
533int vnode_ismountedon(vnode_t);
534void vnode_setmountedon(vnode_t);
535void vnode_clearmountedon(vnode_t);
536
2d21ac55 537int vnode_isrecycled(vnode_t);
91447636
A
538int vnode_isnocache(vnode_t);
539void vnode_setnocache(vnode_t);
540void vnode_clearnocache(vnode_t);
541int vnode_isnoreadahead(vnode_t);
2d21ac55 542int vnode_isstandard(vnode_t);
91447636
A
543void vnode_setnoreadahead(vnode_t);
544void vnode_clearnoreadahead(vnode_t);
2d21ac55
A
545
546int vnode_is_openevt(vnode_t);
547void vnode_set_openevt(vnode_t);
548void vnode_clear_openevt(vnode_t);
549
91447636
A
550/* left only for compat reasons as User code depends on this from getattrlist, for ex */
551void vnode_settag(vnode_t, int);
552int vnode_tag(vnode_t);
553int vnode_getattr(vnode_t vp, struct vnode_attr *vap, vfs_context_t ctx);
554int vnode_setattr(vnode_t vp, struct vnode_attr *vap, vfs_context_t ctx);
555
2d21ac55
A
556vnode_t vfs_rootvnode(void);
557uint32_t vnode_vfsvisflags(vnode_t);
558uint32_t vnode_vfscmdflags(vnode_t);
559struct vfsstatfs *vnode_vfsstatfs(vnode_t);
560void *vnode_vfsfsprivate(vnode_t);
561vnode_t current_workingdir(void);
562vnode_t current_rootdir(void);
563
564void vnode_uncache_credentials(vnode_t vp);
565void vnode_setmultipath(vnode_t vp);
566
91447636
A
567#ifdef BSD_KERNEL_PRIVATE
568
1c79356b 569/*
91447636
A
570 * Indicate that a file has multiple hard links. VFS will always call
571 * VNOP_LOOKUP on this vnode. Volfs will always ask for it's parent
572 * object ID (instead of using the v_parent pointer).
1c79356b 573 */
91447636
A
574
575vnode_t vnode_parent(vnode_t);
576void vnode_setparent(vnode_t, vnode_t);
2d21ac55 577const char * vnode_name(vnode_t);
91447636
A
578void vnode_setname(vnode_t, char *);
579int vnode_isnoflush(vnode_t);
580void vnode_setnoflush(vnode_t);
581void vnode_clearnoflush(vnode_t);
2d21ac55
A
582/* XXX temporary until we can arrive at a KPI for NFS, Seatbelt */
583thread_t vfs_context_thread(vfs_context_t);
91447636
A
584#endif
585
586uint32_t vnode_vfsmaxsymlen(vnode_t);
587int vnode_vfsisrdonly(vnode_t);
588int vnode_vfstypenum(vnode_t);
589void vnode_vfsname(vnode_t, char *);
590int vnode_vfs64bitready(vnode_t);
591
2d21ac55
A
592int vfs_context_get_special_port(vfs_context_t, int, ipc_port_t *);
593int vfs_context_set_special_port(vfs_context_t, int, ipc_port_t);
91447636 594proc_t vfs_context_proc(vfs_context_t);
2d21ac55
A
595vnode_t vfs_context_cwd(vfs_context_t);
596kauth_cred_t vfs_context_ucred(vfs_context_t);
91447636
A
597int vfs_context_issuser(vfs_context_t);
598int vfs_context_pid(vfs_context_t);
599int vfs_context_issignal(vfs_context_t, sigset_t);
600int vfs_context_suser(vfs_context_t);
601int vfs_context_is64bit(vfs_context_t);
602vfs_context_t vfs_context_create(vfs_context_t);
603int vfs_context_rele(vfs_context_t);
2d21ac55
A
604vfs_context_t vfs_context_current(void); /* get from current uthread */
605#ifdef __APPLE_API_UNSTABLE
606vfs_context_t vfs_context_kernel(void); /* get from 1st kernel thread */
607#endif
91447636
A
608
609
610int vflush(struct mount *mp, struct vnode *skipvp, int flags);
611int vnode_get(vnode_t);
612int vnode_getwithvid(vnode_t, int);
613int vnode_put(vnode_t);
614int vnode_ref(vnode_t);
615void vnode_rele(vnode_t);
616int vnode_isinuse(vnode_t, int);
617void vnode_lock(vnode_t);
618void vnode_unlock(vnode_t);
619int vnode_recycle(vnode_t);
620void vnode_reclaim(vnode_t);
621
622#define VNODE_UPDATE_PARENT 0x01
623#define VNODE_UPDATE_NAME 0x02
624#define VNODE_UPDATE_CACHE 0x04
2d21ac55 625void vnode_update_identity(vnode_t vp, vnode_t dvp, const char *name, int name_len, int name_hashval, int flags);
91447636
A
626
627int vn_bwrite(struct vnop_bwrite_args *ap);
628
629int vnode_authorize(vnode_t /*vp*/, vnode_t /*dvp*/, kauth_action_t, vfs_context_t);
630int vnode_authattr(vnode_t, struct vnode_attr *, kauth_action_t *, vfs_context_t);
631int vnode_authattr_new(vnode_t /*dvp*/, struct vnode_attr *, int /*noauth*/, vfs_context_t);
632errno_t vnode_close(vnode_t, int, vfs_context_t);
633
634int vn_getpath(struct vnode *vp, char *pathbuf, int *len);
2d21ac55 635int vn_getcdhash(struct vnode *vp, off_t offset, unsigned char *cdhash);
1c79356b
A
636
637/*
91447636 638 * Flags for the vnode_lookup and vnode_open
1c79356b 639 */
91447636
A
640#define VNODE_LOOKUP_NOFOLLOW 0x01
641#define VNODE_LOOKUP_NOCROSSMOUNT 0x02
642#define VNODE_LOOKUP_DOWHITEOUT 0x04
1c79356b 643
91447636
A
644errno_t vnode_lookup(const char *, int, vnode_t *, vfs_context_t);
645errno_t vnode_open(const char *, int, int, int, vnode_t *, vfs_context_t);
9bccf70c 646
1c79356b 647/*
91447636 648 * exported vnode operations
1c79356b 649 */
1c79356b 650
91447636 651int vnode_iterate(struct mount *, int, int (*)(struct vnode *, void *), void *);
1c79356b 652/*
91447636 653 * flags passed into vnode_iterate
1c79356b 654 */
91447636
A
655#define VNODE_RELOAD 0x01
656#define VNODE_WAIT 0x02
657#define VNODE_WRITEABLE 0x04
658#define VNODE_WITHID 0x08
659#define VNODE_NOLOCK_INTERNAL 0x10
660#define VNODE_NODEAD 0x20
661#define VNODE_NOSUSPEND 0x40
662#define VNODE_ITERATE_ALL 0x80
663#define VNODE_ITERATE_ACTIVE 0x100
664#define VNODE_ITERATE_INACTIVE 0x200
665
666/*
667 * return values from callback
668 */
669#define VNODE_RETURNED 0 /* done with vnode, reference can be dropped */
670#define VNODE_RETURNED_DONE 1 /* done with vnode, reference can be dropped, terminate iteration */
671#define VNODE_CLAIMED 2 /* don't drop reference */
672#define VNODE_CLAIMED_DONE 3 /* don't drop reference, terminate iteration */
673
674
2d21ac55
A
675#ifdef BSD_KERNEL_PRIVATE
676/* Not in export list so can be private */
1c79356b 677struct stat;
2d21ac55
A
678int vn_stat(struct vnode *vp, void * sb, kauth_filesec_t *xsec, int isstat64, vfs_context_t ctx);
679int vn_stat_noauth(struct vnode *vp, void * sb, kauth_filesec_t *xsec, int isstat64, vfs_context_t ctx);
91447636 680int vaccess(mode_t file_mode, uid_t uid, gid_t gid,
2d21ac55
A
681 mode_t acc_mode, kauth_cred_t cred);
682#endif /* BSD_KERNEL_PRIVATE */
683
684int vn_revoke(vnode_t vp, int flags, vfs_context_t);
91447636
A
685
686
687/* namecache function prototypes */
688int cache_lookup(vnode_t dvp, vnode_t *vpp, struct componentname *cnp);
689void cache_enter(vnode_t dvp, vnode_t vp, struct componentname *cnp);
690void cache_purge(vnode_t vp);
691void cache_purge_negatives(vnode_t vp);
692
693/*
694 * Global string-cache routines. You can pass zero for nc_hash
695 * if you don't know it (add_name() will then compute the hash).
696 * There are no flags for now but maybe someday.
697 */
2d21ac55 698const char *vfs_addname(const char *name, size_t len, u_int nc_hash, u_int flags);
91447636
A
699int vfs_removename(const char *name);
700
2d21ac55
A
701int check_mountedon(dev_t dev, enum vtype type, int *errorp);
702int vcount(vnode_t vp);
703
91447636 704__END_DECLS
1c79356b
A
705
706#endif /* KERNEL */
707
708#endif /* !_VNODE_H_ */