Annotation of sys/sys/vnode.h, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: vnode.h,v 1.88 2007/06/14 20:36:34 otto Exp $ */
2: /* $NetBSD: vnode.h,v 1.38 1996/02/29 20:59:05 cgd Exp $ */
3:
4: /*
5: * Copyright (c) 1989, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. Neither the name of the University nor the names of its contributors
17: * may be used to endorse or promote products derived from this software
18: * without specific prior written permission.
19: *
20: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30: * SUCH DAMAGE.
31: *
32: * @(#)vnode.h 8.11 (Berkeley) 11/21/94
33: */
34:
35: #include <sys/types.h>
36: #include <sys/queue.h>
37: #include <sys/lock.h>
38: #include <sys/selinfo.h>
39:
40: #include <uvm/uvm.h>
41: #include <uvm/uvm_vnode.h>
42:
43: /*
44: * The vnode is the focus of all file activity in UNIX. There is a
45: * unique vnode allocated for each active file, each current directory,
46: * each mounted-on file, text file, and the root.
47: */
48:
49: /*
50: * Vnode types. VNON means no type.
51: */
52: enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD };
53:
54: #define VTYPE_NAMES \
55: "VNON", "VREG", "VDIR", "VBLK", "VCHR", "VLNK", "VSOCK", "VFIFO", "VBAD"
56:
57: /*
58: * Vnode tag types.
59: * These are for the benefit of external programs only (e.g., pstat)
60: * and should NEVER be inspected by the kernel.
61: *
62: * Note that v_tag is actually used to tell MFS from FFS, and EXT2FS from
63: * the rest, so don't believe the above comment!
64: */
65: enum vtagtype {
66: VT_NON, VT_UFS, VT_NFS, VT_MFS, VT_MSDOSFS,
67: VT_PORTAL, VT_PROCFS, VT_AFS, VT_ISOFS, VT_ADOSFS,
68: VT_EXT2FS, VT_VFS, VT_XFS, VT_NTFS, VT_UDF
69: };
70:
71: #define VTAG_NAMES \
72: "NON", "UFS", "NFS", "MFS", "MSDOSFS", \
73: "PORTAL", "PROCFS", "AFS", "ISOFS", "ADOSFS", \
74: "EXT2FS", "VFS", "XFS", "NTFS", "UDF"
75:
76: /*
77: * Each underlying filesystem allocates its own private area and hangs
78: * it from v_data. If non-null, this area is freed in getnewvnode().
79: */
80: LIST_HEAD(buflists, buf);
81:
82: struct vnode {
83: struct uvm_vnode v_uvm; /* uvm data */
84: int (**v_op)(void *); /* vnode operations vector */
85: enum vtype v_type; /* vnode type */
86: u_int v_flag; /* vnode flags (see below) */
87: u_int v_usecount; /* reference count of users */
88: /* reference count of writers */
89: u_int v_writecount;
90: /* Flags that can be read/written in interrupts */
91: u_int v_bioflag;
92: u_int v_holdcnt; /* buffer references */
93: u_int v_id; /* capability identifier */
94: struct mount *v_mount; /* ptr to vfs we are in */
95: TAILQ_ENTRY(vnode) v_freelist; /* vnode freelist */
96: LIST_ENTRY(vnode) v_mntvnodes; /* vnodes for mount point */
97: struct buflists v_cleanblkhd; /* clean blocklist head */
98: struct buflists v_dirtyblkhd; /* dirty blocklist head */
99: u_int v_numoutput; /* num of writes in progress */
100: LIST_ENTRY(vnode) v_synclist; /* vnode with dirty buffers */
101: union {
102: struct mount *vu_mountedhere;/* ptr to mounted vfs (VDIR) */
103: struct socket *vu_socket; /* unix ipc (VSOCK) */
104: struct specinfo *vu_specinfo; /* device (VCHR, VBLK) */
105: struct fifoinfo *vu_fifoinfo; /* fifo (VFIFO) */
106: } v_un;
107:
108: enum vtagtype v_tag; /* type of underlying data */
109: void *v_data; /* private data for fs */
110: struct selinfo v_selectinfo; /* identity of poller(s) */
111: };
112: #define v_mountedhere v_un.vu_mountedhere
113: #define v_socket v_un.vu_socket
114: #define v_specinfo v_un.vu_specinfo
115: #define v_fifoinfo v_un.vu_fifoinfo
116:
117: /*
118: * Vnode flags.
119: */
120: #define VROOT 0x0001 /* root of its file system */
121: #define VTEXT 0x0002 /* vnode is a pure text prototype */
122: #define VSYSTEM 0x0004 /* vnode being used by kernel */
123: #define VISTTY 0x0008 /* vnode represents a tty */
124: #define VXLOCK 0x0100 /* vnode is locked to change underlying type */
125: #define VXWANT 0x0200 /* process is waiting for vnode */
126: #define VCLONED 0x0400 /* vnode was cloned */
127: #define VALIASED 0x0800 /* vnode has an alias */
128: #define VLOCKSWORK 0x4000 /* FS supports locking discipline */
129: #define VBITS "\010\001ROOT\002TEXT\003SYSTEM\004ISTTY\010XLOCK" \
130: "\011XWANT\013ALIASED\016LOCKSWORK"
131:
132: /*
133: * (v_bioflag) Flags that may be manipulated by interrupt handlers
134: */
135: #define VBIOWAIT 0x0001 /* waiting for output to complete */
136: #define VBIOONSYNCLIST 0x0002 /* Vnode is on syncer worklist */
137: #define VBIOONFREELIST 0x0004 /* Vnode is on a free list */
138:
139: /*
140: * Vnode attributes. A field value of VNOVAL represents a field whose value
141: * is unavailable (getattr) or which is not to be changed (setattr).
142: */
143: struct vattr {
144: enum vtype va_type; /* vnode type (for create) */
145: mode_t va_mode; /* files access mode and type */
146: nlink_t va_nlink; /* number of references to file */
147: uid_t va_uid; /* owner user id */
148: gid_t va_gid; /* owner group id */
149: long va_fsid; /* file system id (dev for now) */
150: long va_fileid; /* file id */
151: u_quad_t va_size; /* file size in bytes */
152: long va_blocksize; /* blocksize preferred for i/o */
153: struct timespec va_atime; /* time of last access */
154: struct timespec va_mtime; /* time of last modification */
155: struct timespec va_ctime; /* time file changed */
156: u_long va_gen; /* generation number of file */
157: u_long va_flags; /* flags defined for file */
158: dev_t va_rdev; /* device the special file represents */
159: u_quad_t va_bytes; /* bytes of disk space held by file */
160: u_quad_t va_filerev; /* file modification number */
161: u_int va_vaflags; /* operations flags, see below */
162: long va_spare; /* remain quad aligned */
163: };
164:
165: /*
166: * Flags for va_cflags.
167: */
168: #define VA_UTIMES_NULL 0x01 /* utimes argument was NULL */
169: #define VA_EXCLUSIVE 0x02 /* exclusive create request */
170: /*
171: * Flags for ioflag.
172: */
173: #define IO_UNIT 0x01 /* do I/O as atomic unit */
174: #define IO_APPEND 0x02 /* append write to end */
175: #define IO_SYNC 0x04 /* do I/O synchronously */
176: #define IO_NODELOCKED 0x08 /* underlying node already locked */
177: #define IO_NDELAY 0x10 /* FNDELAY flag set in file table */
178: #define IO_NOLIMIT 0x20 /* don't enforce limits on i/o */
179:
180: /*
181: * Modes. Some values same as Ixxx entries from inode.h for now.
182: */
183: #define VSUID 04000 /* set user id on execution */
184: #define VSGID 02000 /* set group id on execution */
185: #define VSVTX 01000 /* save swapped text even after use */
186: #define VREAD 00400 /* read, write, execute permissions */
187: #define VWRITE 00200
188: #define VEXEC 00100
189:
190: /*
191: * Token indicating no attribute value yet assigned.
192: */
193: #define VNOVAL (-1)
194:
195: /*
196: * Structure returned by the KERN_VNODE sysctl
197: */
198: struct e_vnode {
199: struct vnode *vptr;
200: struct vnode vnode;
201: };
202:
203: #ifdef _KERNEL
204: /*
205: * Convert between vnode types and inode formats (since POSIX.1
206: * defines mode word of stat structure in terms of inode formats).
207: */
208: extern enum vtype iftovt_tab[];
209: extern int vttoif_tab[];
210: #define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12])
211: #define VTTOIF(indx) (vttoif_tab[(int)(indx)])
212: #define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode))
213:
214: /*
215: * Flags to various vnode functions.
216: */
217: #define SKIPSYSTEM 0x0001 /* vflush: skip vnodes marked VSYSTEM */
218: #define FORCECLOSE 0x0002 /* vflush: force file closeure */
219: #define WRITECLOSE 0x0004 /* vflush: only close writeable files */
220: #define DOCLOSE 0x0008 /* vclean: close active files */
221: #define V_SAVE 0x0001 /* vinvalbuf: sync file first */
222: #define V_SAVEMETA 0x0002 /* vinvalbuf: leave indirect blocks */
223:
224: #define REVOKEALL 0x0001 /* vop_revoke: revoke all aliases */
225:
226:
227: TAILQ_HEAD(freelst, vnode);
228: extern struct freelst vnode_hold_list; /* free vnodes referencing buffers */
229: extern struct freelst vnode_free_list; /* vnode free list */
230:
231: #define VATTR_NULL(vap) vattr_null(vap)
232: #define VREF(vp) vref(vp) /* increase reference */
233: #define NULLVP ((struct vnode *)NULL)
234: #define VN_KNOTE(vp, b) \
235: KNOTE(&vp->v_selectinfo.si_note, (b))
236:
237: /*
238: * Global vnode data.
239: */
240: extern struct vnode *rootvnode; /* root (i.e. "/") vnode */
241: extern int desiredvnodes; /* XXX number of vnodes desired */
242: extern int maxvnodes; /* XXX number of vnodes to allocate */
243: extern time_t syncdelay; /* time to delay syncing vnodes */
244: extern int rushjob; /* # of slots syncer should run ASAP */
245: #endif /* _KERNEL */
246:
247:
248: /*
249: * Mods for exensibility.
250: */
251:
252: /*
253: * Flags for vdesc_flags:
254: */
255: #define VDESC_MAX_VPS 16
256: /* Low order 16 flag bits are reserved for willrele flags for vp arguments. */
257: #define VDESC_VP0_WILLRELE 0x00000001
258: #define VDESC_VP1_WILLRELE 0x00000002
259: #define VDESC_VP2_WILLRELE 0x00000004
260: #define VDESC_VP3_WILLRELE 0x00000008
261: #define VDESC_VP0_WILLUNLOCK 0x00000100
262: #define VDESC_VP1_WILLUNLOCK 0x00000200
263: #define VDESC_VP2_WILLUNLOCK 0x00000400
264: #define VDESC_VP3_WILLUNLOCK 0x00000800
265: #define VDESC_VP0_WILLPUT 0x00000101
266: #define VDESC_VP1_WILLPUT 0x00000202
267: #define VDESC_VP2_WILLPUT 0x00000404
268: #define VDESC_VP3_WILLPUT 0x00000808
269: #define VDESC_NOMAP_VPP 0x00010000
270: #define VDESC_VPP_WILLRELE 0x00020000
271:
272: /*
273: * VDESC_NO_OFFSET is used to identify the end of the offset list
274: * and in places where no such field exists.
275: */
276: #define VDESC_NO_OFFSET -1
277:
278: /*
279: * This structure describes the vnode operation taking place.
280: */
281: struct vnodeop_desc {
282: int vdesc_offset; /* offset in vector--first for speed */
283: char *vdesc_name; /* a readable name for debugging */
284: int vdesc_flags; /* VDESC_* flags */
285:
286: /*
287: * These ops are used by bypass routines to map and locate arguments.
288: * Creds and procs are not needed in bypass routines, but sometimes
289: * they are useful to (for example) transport layers.
290: * Nameidata is useful because it has a cred in it.
291: */
292: int *vdesc_vp_offsets; /* list ended by VDESC_NO_OFFSET */
293: int vdesc_vpp_offset; /* return vpp location */
294: int vdesc_cred_offset; /* cred location, if any */
295: int vdesc_proc_offset; /* proc location, if any */
296: int vdesc_componentname_offset; /* if any */
297: /*
298: * Finally, we've got a list of private data (about each operation)
299: * for each transport layer. (Support to manage this list is not
300: * yet part of BSD.)
301: */
302: caddr_t *vdesc_transports;
303: };
304:
305: #ifdef _KERNEL
306: /*
307: * A list of all the operation descs.
308: */
309: extern struct vnodeop_desc *vnodeop_descs[];
310:
311:
312: /*
313: * This macro is very helpful in defining those offsets in the vdesc struct.
314: *
315: * This is stolen from X11R4. I ingored all the fancy stuff for
316: * Crays, so if you decide to port this to such a serious machine,
317: * you might want to consult Intrisics.h's XtOffset{,Of,To}.
318: */
319: #define VOPARG_OFFSET(p_type,field) \
320: ((int) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
321: #define VOPARG_OFFSETOF(s_type,field) \
322: VOPARG_OFFSET(s_type*,field)
323: #define VOPARG_OFFSETTO(S_TYPE,S_OFFSET,STRUCT_P) \
324: ((S_TYPE)(((char *)(STRUCT_P))+(S_OFFSET)))
325:
326:
327: /*
328: * This structure is used to configure the new vnodeops vector.
329: */
330: struct vnodeopv_entry_desc {
331: struct vnodeop_desc *opve_op; /* which operation this is */
332: int (*opve_impl)(void *); /* code implementing this operation */
333: };
334: struct vnodeopv_desc {
335: /* ptr to the ptr to the vector where op should go */
336: int (***opv_desc_vector_p)(void *);
337: struct vnodeopv_entry_desc *opv_desc_ops; /* null terminated list */
338: };
339:
340: /*
341: * A default routine which just returns an error.
342: */
343: int vn_default_error(void *);
344:
345: /*
346: * A generic structure.
347: * This can be used by bypass routines to identify generic arguments.
348: */
349: struct vop_generic_args {
350: struct vnodeop_desc *a_desc;
351: /* other random data follows, presumably */
352: };
353:
354: /*
355: * VOCALL calls an op given an ops vector. We break it out because BSD's
356: * vclean changes the ops vector and then wants to call ops with the old
357: * vector.
358: */
359: #define VOCALL(OPSV,OFF,AP) (( *((OPSV)[(OFF)])) (AP))
360:
361: /*
362: * This call works for vnodes in the kernel.
363: */
364: #define VCALL(VP,OFF,AP) VOCALL((VP)->v_op,(OFF),(AP))
365: #define VDESC(OP) (& __CONCAT(OP,_desc))
366: #define VOFFSET(OP) (VDESC(OP)->vdesc_offset)
367:
368: /*
369: * Finally, include the default set of vnode operations.
370: */
371: #include <sys/vnode_if.h>
372:
373: /*
374: * Public vnode manipulation functions.
375: */
376: struct file;
377: struct filedesc;
378: struct mount;
379: struct nameidata;
380: struct proc;
381: struct stat;
382: struct ucred;
383: struct uio;
384: struct vattr;
385: struct vnode;
386:
387: /* vfs_subr */
388: int bdevvp(dev_t, struct vnode **);
389: int cdevvp(dev_t, struct vnode **);
390: struct vnode *checkalias(struct vnode *, dev_t, struct mount *);
391: int getnewvnode(enum vtagtype, struct mount *, int (**vops)(void *),
392: struct vnode **);
393: int vaccess(mode_t, uid_t, gid_t, mode_t, struct ucred *);
394: void vattr_null(struct vattr *);
395: void vdevgone(int, int, int, enum vtype);
396: int vcount(struct vnode *);
397: int vfinddev(dev_t, enum vtype, struct vnode **);
398: void vflushbuf(struct vnode *, int);
399: int vflush(struct mount *, struct vnode *, int);
400: int vget(struct vnode *, int, struct proc *);
401: void vgone(struct vnode *);
402: void vgonel(struct vnode *, struct proc *);
403: int vinvalbuf(struct vnode *, int, struct ucred *, struct proc *,
404: int, int);
405: void vntblinit(void);
406: int vwaitforio(struct vnode *, int, char *, int);
407: void vwakeup(struct vnode *);
408: void vput(struct vnode *);
409: int vrecycle(struct vnode *, struct proc *);
410: void vrele(struct vnode *);
411: void vref(struct vnode *);
412: void vprint(char *, struct vnode *);
413:
414: /* vfs_getcwd.c */
415: int vfs_getcwd_scandir(struct vnode **, struct vnode **, char **, char *,
416: struct proc *);
417: int vfs_getcwd_common(struct vnode *, struct vnode *, char **, char *, int,
418: int, struct proc *);
419: int vfs_getcwd_getcache(struct vnode **, struct vnode **, char **, char *);
420:
421: /* vfs_default.c */
422: int vop_generic_abortop(void *);
423: int vop_generic_bwrite(void *);
424: int vop_generic_islocked(void *);
425: int vop_generic_lock(void *);
426: int vop_generic_unlock(void *);
427: int vop_generic_revoke(void *);
428: int vop_generic_kqfilter(void *);
429:
430: /* vfs_vnops.c */
431: int vn_isunder(struct vnode *, struct vnode *, struct proc *);
432: int vn_close(struct vnode *, int, struct ucred *, struct proc *);
433: int vn_open(struct nameidata *, int, int);
434: int vn_rdwr(enum uio_rw, struct vnode *, caddr_t, int, off_t,
435: enum uio_seg, int, struct ucred *, size_t *, struct proc *);
436: int vn_stat(struct vnode *, struct stat *, struct proc *);
437: int vn_statfile(struct file *, struct stat *, struct proc *);
438: int vn_lock(struct vnode *, int, struct proc *);
439: int vn_writechk(struct vnode *);
440: int vn_ioctl(struct file *, u_long, caddr_t, struct proc *);
441: void vn_marktext(struct vnode *);
442:
443: /* vfs_sync.c */
444: void sched_sync(struct proc *);
445: void vn_initialize_syncerd(void);
446: void vn_syncer_add_to_worklist(struct vnode *, int);
447:
448: /* misc */
449: int vn_isdisk(struct vnode *, int *);
450: int softdep_fsync(struct vnode *);
451: int getvnode(struct filedesc *, int, struct file **);
452:
453: #endif /* _KERNEL */
CVSweb