|
|
1.1 root 1: /*
2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * The contents of this file constitute Original Code as defined in and
7: * are subject to the Apple Public Source License Version 1.1 (the
8: * "License"). You may not use this file except in compliance with the
9: * License. Please obtain a copy of the License at
10: * http://www.apple.com/publicsource and read it before using this file.
11: *
12: * This Original Code and all software distributed under the License are
13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17: * License for the specific language governing rights and limitations
18: * under the License.
19: *
20: * @APPLE_LICENSE_HEADER_END@
21: */
22: /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
23: /*
24: * Copyright (c) 1989, 1993
25: * The Regents of the University of California. All rights reserved.
26: *
27: * Redistribution and use in source and binary forms, with or without
28: * modification, are permitted provided that the following conditions
29: * are met:
30: * 1. Redistributions of source code must retain the above copyright
31: * notice, this list of conditions and the following disclaimer.
32: * 2. Redistributions in binary form must reproduce the above copyright
33: * notice, this list of conditions and the following disclaimer in the
34: * documentation and/or other materials provided with the distribution.
35: * 3. All advertising materials mentioning features or use of this software
36: * must display the following acknowledgement:
37: * This product includes software developed by the University of
38: * California, Berkeley and its contributors.
39: * 4. Neither the name of the University nor the names of its contributors
40: * may be used to endorse or promote products derived from this software
41: * without specific prior written permission.
42: *
43: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53: * SUCH DAMAGE.
54: *
55: * @(#)vnode.h 8.17 (Berkeley) 5/20/95
56: */
57: /* HISTORY
58: * 06-JUN-99 CHW Added VT_WEBDAV to vtagtype
59: * 05-Aug-98 CHW Added a new truncate option to not zero space
60: * 16-Jul-98 CHW Added a new allocate flag to allocate from PEOF
61: * 07-Jul-98 CHW Fixed flag definitions for VOP_ALLOCATE
62: * 25-May-98 CHW made changes to support VOP_ALLOCATE
63: * 04-Aug-97 Umesh Vaishampayan ([email protected])
64: * Added VT_HFS to vtagtype.
65: */
66:
67: #ifndef _VNODE_H_
68: #define _VNODE_H_
69:
70: #include <sys/cdefs.h>
71: #include <sys/queue.h>
72: #include <sys/lock.h>
73:
74: #include <sys/time.h>
75: #include <sys/uio.h>
76:
77: #include <sys/vm.h>
78: #ifdef KERNEL
79: #include <sys/systm.h>
80: #endif
81:
82: /*
83: * The vnode is the focus of all file activity in UNIX. There is a
84: * unique vnode allocated for each active file, each current directory,
85: * each mounted-on file, text file, and the root.
86: */
87:
88: /*
89: * Vnode types. VNON means no type.
90: */
91: enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD, VSTR,
92: VCPLX };
93:
94: /*
95: * Vnode tag types.
96: * These are for the benefit of external programs only (e.g., pstat)
97: * and should NEVER be inspected by the kernel.
98: */
99: enum vtagtype {
100: VT_NON, VT_UFS, VT_NFS, VT_MFS, VT_MSDOSFS, VT_LFS, VT_LOFS, VT_FDESC,
101: VT_PORTAL, VT_NULL, VT_UMAP, VT_KERNFS, VT_PROCFS, VT_AFS, VT_ISOFS,
102: VT_UNION, VT_HFS, VT_VOLFS, VT_DEVFS, VT_WEBDAV, VT_OTHER};
103:
104: /*
105: * Each underlying filesystem allocates its own private area and hangs
106: * it from v_data. If non-null, this area is freed in getnewvnode().
107: */
108: LIST_HEAD(buflists, buf);
109:
110: /*
111: * Reading or writing any of these items requires holding the appropriate lock.
112: * v_freelist is locked by the global vnode_free_list simple lock.
113: * v_mntvnodes is locked by the global mntvnodes simple lock.
114: * v_flag, v_usecount, v_holdcount and v_writecount are
115: * locked by the v_interlock simple lock.
116: */
117: struct vnode {
118: u_long v_flag; /* vnode flags (see below) */
119: long v_usecount; /* reference count of users */
120: long v_holdcnt; /* page & buffer references */
121: daddr_t v_lastr; /* last read (read-ahead) */
122: u_long v_id; /* capability identifier */
123: struct mount *v_mount; /* ptr to vfs we are in */
124: int (**v_op)(); /* vnode operations vector */
125: TAILQ_ENTRY(vnode) v_freelist; /* vnode freelist */
126: LIST_ENTRY(vnode) v_mntvnodes; /* vnodes for mount point */
127: struct buflists v_cleanblkhd; /* clean blocklist head */
128: struct buflists v_dirtyblkhd; /* dirty blocklist head */
129: long v_numoutput; /* num of writes in progress */
130: enum vtype v_type; /* vnode type */
131: union {
132: struct mount *vu_mountedhere;/* ptr to mounted vfs (VDIR) */
133: struct socket *vu_socket; /* unix ipc (VSOCK) */
134: struct vm_info *vu_vm_info; /* private data for vm (VREG) */
135: struct specinfo *vu_specinfo; /* device (VCHR, VBLK) */
136: struct fifoinfo *vu_fifoinfo; /* fifo (VFIFO) */
137: } v_un;
138: struct nqlease *v_lease; /* Soft reference to lease */
139: daddr_t v_lastw; /* last write (write cluster) */
140: daddr_t v_cstart; /* start block of cluster */
141: daddr_t v_lasta; /* last allocation */
142: int v_clen; /* length of current cluster */
143: int v_ralen; /* Read-ahead length */
144: daddr_t v_maxra; /* last readahead block */
145: simple_lock_data_t v_interlock; /* lock on usecount and flag */
146: struct lock__bsd__ *v_vnlock; /* used for non-locking fs's */
147: long v_spare[4]; /* round to 128 bytes */
148: long v_writecount; /* reference count of writers */
149: enum vtagtype v_tag; /* type of underlying data */
150: void *v_data; /* private data for fs */
151: u_long v_bread;
152: u_long v_consumed;
153: u_long v_trigger;
154: int v_power;
155: };
156: #define v_mountedhere v_un.vu_mountedhere
157: #define v_socket v_un.vu_socket
158: #define v_vm_info v_un.vu_vm_info
159: #define v_specinfo v_un.vu_specinfo
160: #define v_fifoinfo v_un.vu_fifoinfo
161:
162: /*
163: * Vnode flags.
164: */
165: #define VROOT 0x0001 /* root of its file system */
166: #define VTEXT 0x0002 /* vnode is a pure text prototype */
167: #define VSYSTEM 0x0004 /* vnode being used by kernel */
168: #define VISTTY 0x0008 /* vnode represents a tty */
169: #define VXLOCK 0x0100 /* vnode is locked to change underlying type */
170: #define VXWANT 0x0200 /* process is waiting for vnode */
171: #define VBWAIT 0x0400 /* waiting for output to complete */
172: #define VALIASED 0x0800 /* vnode has an alias */
173: #define VDIROP 0x1000 /* LFS: vnode is involved in a directory op */
174: #define VAGE 0x8000 /* Insert vnode at head of free list */
175: #define VRAOFF 0x10000 /* read ahead disabled */
176:
177: /*
178: * Vnode attributes. A field value of VNOVAL represents a field whose value
179: * is unavailable (getattr) or which is not to be changed (setattr).
180: */
181: struct vattr {
182: enum vtype va_type; /* vnode type (for create) */
183: u_short va_mode; /* files access mode and type */
184: short va_nlink; /* number of references to file */
185: uid_t va_uid; /* owner user id */
186: gid_t va_gid; /* owner group id */
187: long va_fsid; /* file system id (dev for now) */
188: long va_fileid; /* file id */
189: u_quad_t va_size; /* file size in bytes */
190: long va_blocksize; /* blocksize preferred for i/o */
191: struct timespec va_atime; /* time of last access */
192: struct timespec va_mtime; /* time of last modification */
193: struct timespec va_ctime; /* time file changed */
194: u_long va_gen; /* generation number of file */
195: u_long va_flags; /* flags defined for file */
196: dev_t va_rdev; /* device the special file represents */
197: u_quad_t va_bytes; /* bytes of disk space held by file */
198: u_quad_t va_filerev; /* file modification number */
199: u_int va_vaflags; /* operations flags, see below */
200: long va_spare; /* remain quad aligned */
201: };
202:
203: /*
204: * Flags for va_vaflags.
205: */
206: #define VA_UTIMES_NULL 0x01 /* utimes argument was NULL */
207: #define VA_EXCLUSIVE 0x02 /* exclusive create request */
208:
209: /*
210: * Flags for ioflag.
211: */
212: #define IO_UNIT 0x01 /* do I/O as atomic unit */
213: #define IO_APPEND 0x02 /* append write to end */
214: #define IO_SYNC 0x04 /* do I/O synchronously */
215: #define IO_NODELOCKED 0x08 /* underlying node already locked */
216: #define IO_NDELAY 0x10 /* FNDELAY flag set in file table */
217: #define IO_NOZEROFILL 0x20 /* F_SETSIZE fcntl uses to prevent zero filling */
218:
219: /*
220: * Modes. Some values same as Ixxx entries from inode.h for now.
221: */
222: #define VSUID 04000 /* set user id on execution */
223: #define VSGID 02000 /* set group id on execution */
224: #define VSVTX 01000 /* save swapped text even after use */
225: #define VREAD 00400 /* read, write, execute permissions */
226: #define VWRITE 00200
227: #define VEXEC 00100
228:
229: /*
230: * Token indicating no attribute value yet assigned.
231: */
232: #define VNOVAL (-1)
233:
234: #ifdef KERNEL
235: /*
236: * Convert between vnode types and inode formats (since POSIX.1
237: * defines mode word of stat structure in terms of inode formats).
238: */
239: extern enum vtype iftovt_tab[];
240: extern int vttoif_tab[];
241: #define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12])
242: #define VTTOIF(indx) (vttoif_tab[(int)(indx)])
243: #define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode))
244:
245: /*
246: * Flags to various vnode functions.
247: */
248: #define SKIPSYSTEM 0x0001 /* vflush: skip vnodes marked VSYSTEM */
249: #define FORCECLOSE 0x0002 /* vflush: force file closeure */
250: #define WRITECLOSE 0x0004 /* vflush: only close writeable files */
251: #define DOCLOSE 0x0008 /* vclean: close active files */
252: #define V_SAVE 0x0001 /* vinvalbuf: sync file first */
253: #define V_SAVEMETA 0x0002 /* vinvalbuf: leave indirect blocks */
254: #define REVOKEALL 0x0001 /* vop_revoke: revoke all aliases */
255: #define PREALLOCATE 0x00000001 /* vop_allocate: preallocate allocation blocks */
256: #define ALLOCATECONTIG 0x00000002 /* vop_allocate: allocate contigious space */
257: #define ALLOCATEALL 0x00000004 /* vop_allocate: allocate all requested space or no space at all */
258: #define FREEREMAINDER 0x00000008 /* vop_allcoate: deallocate allocated but unfilled blocks */
259: #define ALLOCATEFROMPEOF 0x00000010 /* vop_allocate: allocate from the physical eof */
260:
261:
262:
263: #if DIAGNOSTIC
264: #define HOLDRELE(vp) holdrele(vp)
265: #define VATTR_NULL(vap) vattr_null(vap)
266: #define VHOLD(vp) vhold(vp)
267: #define VREF(vp) vref(vp)
268:
269: void holdrele __P((struct vnode *));
270: void vattr_null __P((struct vattr *));
271: void vhold __P((struct vnode *));
272: void vref __P((struct vnode *));
273: #else
274: #define VATTR_NULL(vap) (*(vap) = va_null) /* initialize a vattr */
275: #define HOLDRELE(vp) holdrele(vp) /* decrease buf or page ref */
276: extern __inline void holdrele(vp)
277: struct vnode *vp;
278: {
279: simple_lock(&vp->v_interlock);
280: vp->v_holdcnt--;
281: simple_unlock(&vp->v_interlock);
282: }
283: #define VHOLD(vp) vhold(vp) /* increase buf or page ref */
284: extern __inline void vhold(vp)
285: struct vnode *vp;
286: {
287: simple_lock(&vp->v_interlock);
288: if (++vp->v_holdcnt <= 0)
289: panic("vhold: v_holdcnt");
290: simple_unlock(&vp->v_interlock);
291: }
292: #define VREF(vp) vref(vp) /* increase reference */
293: extern __inline void vref(vp)
294: struct vnode *vp;
295: {
296: simple_lock(&vp->v_interlock);
297: if (++vp->v_usecount <= 0)
298: panic("vref: v_usecount");
299: simple_unlock(&vp->v_interlock);
300: }
301: #endif /* DIAGNOSTIC */
302:
303: #define NULLVP ((struct vnode *)NULL)
304:
305: /*
306: * Global vnode data.
307: */
308: extern struct vnode *rootvnode; /* root (i.e. "/") vnode */
309: extern int desiredvnodes; /* number of vnodes desired */
310: extern struct vattr va_null; /* predefined null vattr structure */
311:
312: /*
313: * Macro/function to check for client cache inconsistency w.r.t. leasing.
314: */
315: #define LEASE_READ 0x1 /* Check lease for readers */
316: #define LEASE_WRITE 0x2 /* Check lease for modifiers */
317:
318: #endif /* KERNEL */
319:
320:
321: /*
322: * Mods for exensibility.
323: */
324:
325: /*
326: * Flags for vdesc_flags:
327: */
328: #define VDESC_MAX_VPS 16
329: /* Low order 16 flag bits are reserved for willrele flags for vp arguments. */
330: #define VDESC_VP0_WILLRELE 0x0001
331: #define VDESC_VP1_WILLRELE 0x0002
332: #define VDESC_VP2_WILLRELE 0x0004
333: #define VDESC_VP3_WILLRELE 0x0008
334: #define VDESC_NOMAP_VPP 0x0100
335: #define VDESC_VPP_WILLRELE 0x0200
336:
337: /*
338: * VDESC_NO_OFFSET is used to identify the end of the offset list
339: * and in places where no such field exists.
340: */
341: #define VDESC_NO_OFFSET -1
342:
343: /*
344: * This structure describes the vnode operation taking place.
345: */
346: struct vnodeop_desc {
347: int vdesc_offset; /* offset in vector--first for speed */
348: char *vdesc_name; /* a readable name for debugging */
349: int vdesc_flags; /* VDESC_* flags */
350:
351: /*
352: * These ops are used by bypass routines to map and locate arguments.
353: * Creds and procs are not needed in bypass routines, but sometimes
354: * they are useful to (for example) transport layers.
355: * Nameidata is useful because it has a cred in it.
356: */
357: int *vdesc_vp_offsets; /* list ended by VDESC_NO_OFFSET */
358: int vdesc_vpp_offset; /* return vpp location */
359: int vdesc_cred_offset; /* cred location, if any */
360: int vdesc_proc_offset; /* proc location, if any */
361: int vdesc_componentname_offset; /* if any */
362: /*
363: * Finally, we've got a list of private data (about each operation)
364: * for each transport layer. (Support to manage this list is not
365: * yet part of BSD.)
366: */
367: caddr_t *vdesc_transports;
368: };
369:
370: #ifdef KERNEL
371: /*
372: * A list of all the operation descs.
373: */
374: extern struct vnodeop_desc *vnodeop_descs[];
375:
376: /*
377: * Interlock for scanning list of vnodes attached to a mountpoint
378: */
379: extern struct slock mntvnode_slock;
380:
381: /*
382: * This macro is very helpful in defining those offsets in the vdesc struct.
383: *
384: * This is stolen from X11R4. I ingored all the fancy stuff for
385: * Crays, so if you decide to port this to such a serious machine,
386: * you might want to consult Intrisics.h's XtOffset{,Of,To}.
387: */
388: #define VOPARG_OFFSET(p_type,field) \
389: ((int) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
390: #define VOPARG_OFFSETOF(s_type,field) \
391: VOPARG_OFFSET(s_type*,field)
392: #define VOPARG_OFFSETTO(S_TYPE,S_OFFSET,STRUCT_P) \
393: ((S_TYPE)(((char*)(STRUCT_P))+(S_OFFSET)))
394:
395:
396: /*
397: * This structure is used to configure the new vnodeops vector.
398: */
399: struct vnodeopv_entry_desc {
400: struct vnodeop_desc *opve_op; /* which operation this is */
401: int (*opve_impl)(); /* code implementing this operation */
402: };
403: struct vnodeopv_desc {
404: /* ptr to the ptr to the vector where op should go */
405: int (***opv_desc_vector_p)();
406: struct vnodeopv_entry_desc *opv_desc_ops; /* null terminated list */
407: };
408:
409: /*
410: * A default routine which just returns an error.
411: */
412: int vn_default_error __P((void));
413:
414: /*
415: * A generic structure.
416: * This can be used by bypass routines to identify generic arguments.
417: */
418: struct vop_generic_args {
419: struct vnodeop_desc *a_desc;
420: /* other random data follows, presumably */
421: };
422:
423: /*
424: * VOCALL calls an op given an ops vector. We break it out because BSD's
425: * vclean changes the ops vector and then wants to call ops with the old
426: * vector.
427: */
428: #define VOCALL(OPSV,OFF,AP) (( *((OPSV)[(OFF)])) (AP))
429:
430: /*
431: * This call works for vnodes in the kernel.
432: */
433: #define VCALL(VP,OFF,AP) VOCALL((VP)->v_op,(OFF),(AP))
434: #define VDESC(OP) (& __CONCAT(OP,_desc))
435: #define VOFFSET(OP) (VDESC(OP)->vdesc_offset)
436:
437: /*
438: * Finally, include the default set of vnode operations.
439: */
440: #include <sys/vnode_if.h>
441:
442: /*
443: * Public vnode manipulation functions.
444: */
445: struct file;
446: struct mount;
447: struct nameidata;
448: struct ostat;
449: struct proc;
450: struct stat;
451: struct ucred;
452: struct uio;
453: struct vattr;
454: struct vnode;
455: struct vop_bwrite_args;
456:
457: int bdevvp __P((dev_t dev, struct vnode **vpp));
458: void cvtstat __P((struct stat *st, struct ostat *ost));
459: int getnewvnode __P((enum vtagtype tag,
460: struct mount *mp, int (**vops)(), struct vnode **vpp));
461: void insmntque __P((struct vnode *vp, struct mount *mp));
462: void vattr_null __P((struct vattr *vap));
463: int vcount __P((struct vnode *vp));
464: int vflush __P((struct mount *mp, struct vnode *skipvp, int flags));
465: int vget __P((struct vnode *vp, int lockflag, struct proc *p));
466: void vgone __P((struct vnode *vp));
467: int vinvalbuf __P((struct vnode *vp, int save, struct ucred *cred,
468: struct proc *p, int slpflag, int slptimeo));
469: void vprint __P((char *label, struct vnode *vp));
470: int vrecycle __P((struct vnode *vp, struct slock *inter_lkp,
471: struct proc *p));
472: int vn_bwrite __P((struct vop_bwrite_args *ap));
473: int vn_close __P((struct vnode *vp,
474: int flags, struct ucred *cred, struct proc *p));
475: int vn_closefile __P((struct file *fp, struct proc *p));
476: int vn_ioctl __P((struct file *fp, u_long com, caddr_t data,
477: struct proc *p));
478: int vn_lock __P((struct vnode *vp, int flags, struct proc *p));
479: int vn_open __P((struct nameidata *ndp, int fmode, int cmode));
480: int vn_rdwr __P((enum uio_rw rw, struct vnode *vp, caddr_t base,
481: int len, off_t offset, enum uio_seg segflg, int ioflg,
482: struct ucred *cred, int *aresid, struct proc *p));
483: int vn_read __P((struct file *fp, struct uio *uio, struct ucred *cred));
484: int vn_select __P((struct file *fp, int which, struct proc *p));
485: int vn_stat __P((struct vnode *vp, struct stat *sb, struct proc *p));
486: int vn_write __P((struct file *fp, struct uio *uio, struct ucred *cred));
487: int vop_noislocked __P((struct vop_islocked_args *));
488: int vop_nolock __P((struct vop_lock_args *));
489: int vop_nounlock __P((struct vop_unlock_args *));
490: int vop_revoke __P((struct vop_revoke_args *));
491: struct vnode *
492: checkalias __P((struct vnode *vp, dev_t nvp_rdev, struct mount *mp));
493: void vput __P((struct vnode *vp));
494: void vrele __P((struct vnode *vp));
495: int vaccess __P((mode_t file_mode, uid_t uid, gid_t gid,
496: mode_t acc_mode, struct ucred *cred));
497: int getvnode __P((struct proc *p, int fd, struct file **fpp));
498:
499: #endif /* KERNEL */
500:
501: #endif /* !_VNODE_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.