home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / os / bsdss4.tz / bsdss4 / bsdss / server / sys / vnode.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-22  |  15.0 KB  |  368 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1992 Carnegie Mellon University
  4.  * All Rights Reserved.
  5.  * 
  6.  * Permission to use, copy, modify and distribute this software and its
  7.  * documentation is hereby granted, provided that both the copyright
  8.  * notice and this permission notice appear in all copies of the
  9.  * software, derivative works or modified versions, and any portions
  10.  * thereof, and that both notices appear in supporting documentation.
  11.  * 
  12.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  13.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15.  * 
  16.  * Carnegie Mellon requests users of this software to return to
  17.  * 
  18.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  19.  *  School of Computer Science
  20.  *  Carnegie Mellon University
  21.  *  Pittsburgh PA 15213-3890
  22.  * 
  23.  * any improvements or extensions that they make and grant Carnegie Mellon 
  24.  * the rights to redistribute these changes.
  25.  */
  26. /*
  27.  * HISTORY
  28.  * $Log:    vnode.h,v $
  29.  * Revision 2.1  92/04/21  17:17:44  rwd
  30.  * BSDSS
  31.  * 
  32.  *
  33.  */
  34.  
  35. /*
  36.  * Copyright (c) 1989 The Regents of the University of California.
  37.  * All rights reserved.
  38.  *
  39.  * Redistribution and use in source and binary forms, with or without
  40.  * modification, are permitted provided that the following conditions
  41.  * are met:
  42.  * 1. Redistributions of source code must retain the above copyright
  43.  *    notice, this list of conditions and the following disclaimer.
  44.  * 2. Redistributions in binary form must reproduce the above copyright
  45.  *    notice, this list of conditions and the following disclaimer in the
  46.  *    documentation and/or other materials provided with the distribution.
  47.  * 3. All advertising materials mentioning features or use of this software
  48.  *    must display the following acknowledgement:
  49.  *    This product includes software developed by the University of
  50.  *    California, Berkeley and its contributors.
  51.  * 4. Neither the name of the University nor the names of its contributors
  52.  *    may be used to endorse or promote products derived from this software
  53.  *    without specific prior written permission.
  54.  *
  55.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  56.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  57.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  58.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  59.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  60.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  61.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  62.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  63.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  64.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  65.  * SUCH DAMAGE.
  66.  *
  67.  *    @(#)vnode.h    7.39 (Berkeley) 6/27/91
  68.  */
  69.  
  70. #ifndef KERNEL
  71. #include <machine/endian.h>
  72. #endif
  73.  
  74. /*
  75.  * The vnode is the focus of all file activity in UNIX.
  76.  * There is a unique vnode allocated for each active file,
  77.  * each current directory, each mounted-on file, text file, and the root.
  78.  */
  79.  
  80. /*
  81.  * vnode types. VNON means no type.
  82.  */
  83. enum vtype     { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD };
  84.  
  85. /*
  86.  * Vnode tag types.
  87.  * These are for the benefit of external programs only (e.g., pstat)
  88.  * and should NEVER be inspected inside the kernel.
  89.  */
  90. enum vtagtype    { VT_NON, VT_UFS, VT_NFS, VT_MFS };
  91.  
  92. /*
  93.  * This defines the maximum size of the private data area
  94.  * permitted for any file system type. A defined constant 
  95.  * is used rather than a union structure to cut down on the
  96.  * number of header files that must be included.
  97.  */
  98. #define    VN_MAXPRIVATE    188
  99.  
  100. struct vnode {
  101.     u_long        v_flag;            /* vnode flags (see below) */
  102.     short        v_usecount;        /* reference count of users */
  103.     short        v_writecount;        /* reference count of writers */
  104.     long        v_holdcnt;        /* page & buffer references */
  105.     off_t        v_lastr;        /* last read (read-ahead) */
  106.     u_long        v_id;            /* capability identifier */
  107.     struct mount    *v_mount;        /* ptr to vfs we are in */
  108.     struct vnodeops    *v_op;            /* vnode operations */
  109.     struct vnode    *v_freef;        /* vnode freelist forward */
  110.     struct vnode    **v_freeb;        /* vnode freelist back */
  111.     struct vnode    *v_mountf;        /* vnode mountlist forward */
  112.     struct vnode    **v_mountb;        /* vnode mountlist back */
  113.     struct buf    *v_cleanblkhd;        /* clean blocklist head */
  114.     struct buf    *v_dirtyblkhd;        /* dirty blocklist head */
  115.     long        v_numoutput;        /* num of writes in progress */
  116.     enum vtype    v_type;            /* vnode type */
  117.     union {
  118.         struct mount    *vu_mountedhere;/* ptr to mounted vfs (VDIR) */
  119.         struct socket    *vu_socket;    /* unix ipc (VSOCK) */
  120.         caddr_t        vu_vmdata;    /* private data for vm (VREG) */
  121.         struct specinfo    *vu_specinfo;    /* device (VCHR, VBLK) */
  122.         struct fifoinfo    *vu_fifoinfo;    /* fifo (VFIFO) */
  123.     } v_un;
  124.     enum vtagtype    v_tag;            /* type of underlying data */
  125.     char v_data[VN_MAXPRIVATE];        /* private data for fs */
  126. };
  127. #define    v_mountedhere    v_un.vu_mountedhere
  128. #define    v_socket    v_un.vu_socket
  129. #define    v_vmdata    v_un.vu_vmdata
  130. #define    v_specinfo    v_un.vu_specinfo
  131. #define    v_fifoinfo    v_un.vu_fifoinfo
  132.  
  133. /*
  134.  * vnode flags.
  135.  */
  136. #define    VROOT        0x0001    /* root of its file system */
  137. #define    VTEXT        0x0002    /* vnode is a pure text prototype */
  138. #define    VSYSTEM        0x0004    /* vnode being used by kernel */
  139. #define    VXLOCK        0x0100    /* vnode is locked to change underlying type */
  140. #define    VXWANT        0x0200    /* process is waiting for vnode */
  141. #define    VBWAIT        0x0400    /* waiting for output to complete */
  142. #define    VALIASED    0x0800    /* vnode has an alias */
  143.  
  144. /*
  145.  * Vnode attributes.  A field value of VNOVAL
  146.  * represents a field whose value is unavailable
  147.  * (getattr) or which is not to be changed (setattr).
  148.  */
  149. struct vattr {
  150.     enum vtype    va_type;    /* vnode type (for create) */
  151.     u_short        va_mode;    /* files access mode and type */
  152.     short        va_nlink;    /* number of references to file */
  153.     uid_t        va_uid;        /* owner user id */
  154.     gid_t        va_gid;        /* owner group id */
  155.     long        va_fsid;    /* file system id (dev for now) */
  156.     long        va_fileid;    /* file id */
  157.     u_quad        va_qsize;    /* file size in bytes */
  158.     long        va_blocksize;    /* blocksize preferred for i/o */
  159.     struct timeval    va_atime;    /* time of last access */
  160.     struct timeval    va_mtime;    /* time of last modification */
  161.     struct timeval    va_ctime;    /* time file changed */
  162.     u_long        va_gen;        /* generation number of file */
  163.     u_long        va_flags;    /* flags defined for file */
  164.     dev_t        va_rdev;    /* device the special file represents */
  165.     u_quad        va_qbytes;    /* bytes of disk space held by file */
  166. };
  167. #if BYTE_ORDER == LITTLE_ENDIAN
  168. #define    va_size        va_qsize.val[0]
  169. #define    va_size_rsv    va_qsize.val[1]
  170. #define    va_bytes    va_qbytes.val[0]
  171. #define    va_bytes_rsv    va_qbytes.val[1]
  172. #else
  173. #define    va_size        va_qsize.val[1]
  174. #define    va_size_rsv    va_qsize.val[0]
  175. #define    va_bytes    va_qbytes.val[1]
  176. #define    va_bytes_rsv    va_qbytes.val[0]
  177. #endif
  178.  
  179. /*
  180.  * Operations on vnodes.
  181.  */
  182. #ifdef __STDC__
  183. struct flock;
  184. struct nameidata;
  185. #endif
  186.  
  187. struct vnodeops {
  188.     int    (*vop_lookup)    __P((struct vnode *vp, struct nameidata *ndp,
  189.                     struct proc *p));
  190.     int    (*vop_create)    __P((struct nameidata *ndp, struct vattr *vap,
  191.                     struct proc *p));
  192.     int    (*vop_mknod)    __P((struct nameidata *ndp, struct vattr *vap,
  193.                     struct ucred *cred, struct proc *p));
  194.     int    (*vop_open)    __P((struct vnode *vp, int mode,
  195.                     struct ucred *cred, struct proc *p));
  196.     int    (*vop_close)    __P((struct vnode *vp, int fflag,
  197.                     struct ucred *cred, struct proc *p));
  198.     int    (*vop_access)    __P((struct vnode *vp, int mode,
  199.                     struct ucred *cred, struct proc *p));
  200.     int    (*vop_getattr)    __P((struct vnode *vp, struct vattr *vap,
  201.                     struct ucred *cred, struct proc *p));
  202.     int    (*vop_setattr)    __P((struct vnode *vp, struct vattr *vap,
  203.                     struct ucred *cred, struct proc *p));
  204.     int    (*vop_read)    __P((struct vnode *vp, struct uio *uio,
  205.                     int ioflag, struct ucred *cred));
  206.     int    (*vop_write)    __P((struct vnode *vp, struct uio *uio,
  207.                     int ioflag, struct ucred *cred));
  208.     int    (*vop_ioctl)    __P((struct vnode *vp, int command,
  209.                     caddr_t data, int fflag,
  210.                     struct ucred *cred, struct proc *p));
  211.     int    (*vop_select)    __P((struct vnode *vp, int which, int fflags,
  212.                     struct ucred *cred, struct proc *p));
  213.     int    (*vop_mmap)    __P((struct vnode *vp, int fflags,
  214.                     struct ucred *cred, struct proc *p));
  215.     int    (*vop_fsync)    __P((struct vnode *vp, int fflags,
  216.                     struct ucred *cred, int waitfor,
  217.                     struct proc *p));
  218.     int    (*vop_seek)    __P((struct vnode *vp, off_t oldoff,
  219.                     off_t newoff, struct ucred *cred));
  220.     int    (*vop_remove)    __P((struct nameidata *ndp, struct proc *p));
  221.     int    (*vop_link)    __P((struct vnode *vp, struct nameidata *ndp,
  222.                     struct proc *p));
  223.     int    (*vop_rename)    __P((struct nameidata *fndp,
  224.                     struct nameidata *tdnp, struct proc *p));
  225.     int    (*vop_mkdir)    __P((struct nameidata *ndp, struct vattr *vap,
  226.                     struct proc *p));
  227.     int    (*vop_rmdir)    __P((struct nameidata *ndp, struct proc *p));
  228.     int    (*vop_symlink)    __P((struct nameidata *ndp, struct vattr *vap,
  229.                     char *target, struct proc *p));
  230.     int    (*vop_readdir)    __P((struct vnode *vp, struct uio *uio,
  231.                     struct ucred *cred, int *eofflagp));
  232.     int    (*vop_readlink)    __P((struct vnode *vp, struct uio *uio,
  233.                     struct ucred *cred));
  234.     int    (*vop_abortop)    __P((struct nameidata *ndp));
  235.     int    (*vop_inactive)    __P((struct vnode *vp, struct proc *p));
  236.     int    (*vop_reclaim)    __P((struct vnode *vp));
  237.     int    (*vop_lock)    __P((struct vnode *vp));
  238.     int    (*vop_unlock)    __P((struct vnode *vp));
  239.     int    (*vop_bmap)    __P((struct vnode *vp, daddr_t bn,
  240.                     struct vnode **vpp, daddr_t *bnp));
  241.     int    (*vop_strategy)    __P((struct buf *bp));
  242.     int    (*vop_print)    __P((struct vnode *vp));
  243.     int    (*vop_islocked)    __P((struct vnode *vp));
  244.     int    (*vop_advlock)    __P((struct vnode *vp, caddr_t id, int op,
  245.                     struct flock *fl, int flags));
  246. };
  247.  
  248. /* Macros to call the vnode ops */
  249. #define    VOP_LOOKUP(v,n,p)    (*((v)->v_op->vop_lookup))(v,n,p)
  250. #define    VOP_CREATE(n,a,p)    (*((n)->ni_dvp->v_op->vop_create))(n,a,p)
  251. #define    VOP_MKNOD(n,a,c,p)    (*((n)->ni_dvp->v_op->vop_mknod))(n,a,c,p)
  252. #define    VOP_OPEN(v,f,c,p)    (*((v)->v_op->vop_open))(v,f,c,p)
  253. #define    VOP_CLOSE(v,f,c,p)    (*((v)->v_op->vop_close))(v,f,c,p)
  254. #define    VOP_ACCESS(v,f,c,p)    (*((v)->v_op->vop_access))(v,f,c,p)
  255. #define    VOP_GETATTR(v,a,c,p)    (*((v)->v_op->vop_getattr))(v,a,c,p)
  256. #define    VOP_SETATTR(v,a,c,p)    (*((v)->v_op->vop_setattr))(v,a,c,p)
  257. #define    VOP_READ(v,u,i,c)    (*((v)->v_op->vop_read))(v,u,i,c)
  258. #define    VOP_WRITE(v,u,i,c)    (*((v)->v_op->vop_write))(v,u,i,c)
  259. #define    VOP_IOCTL(v,o,d,f,c,p)    (*((v)->v_op->vop_ioctl))(v,o,d,f,c,p)
  260. #define    VOP_SELECT(v,w,f,c,p)    (*((v)->v_op->vop_select))(v,w,f,c,p)
  261. #define    VOP_MMAP(v,c,p)        (*((v)->v_op->vop_mmap))(v,c,p)
  262. #define    VOP_FSYNC(v,f,c,w,p)    (*((v)->v_op->vop_fsync))(v,f,c,w,p)
  263. #define    VOP_SEEK(v,p,o,w)    (*((v)->v_op->vop_seek))(v,p,o,w)
  264. #define    VOP_REMOVE(n,p)        (*((n)->ni_dvp->v_op->vop_remove))(n,p)
  265. #define    VOP_LINK(v,n,p)        (*((n)->ni_dvp->v_op->vop_link))(v,n,p)
  266. #define    VOP_RENAME(s,t,p)    (*((s)->ni_dvp->v_op->vop_rename))(s,t,p)
  267. #define    VOP_MKDIR(n,a,p)    (*((n)->ni_dvp->v_op->vop_mkdir))(n,a,p)
  268. #define    VOP_RMDIR(n,p)        (*((n)->ni_dvp->v_op->vop_rmdir))(n,p)
  269. #define    VOP_SYMLINK(n,a,m,p)    (*((n)->ni_dvp->v_op->vop_symlink))(n,a,m,p)
  270. #define    VOP_READDIR(v,u,c,e)    (*((v)->v_op->vop_readdir))(v,u,c,e)
  271. #define    VOP_READLINK(v,u,c)    (*((v)->v_op->vop_readlink))(v,u,c)
  272. #define    VOP_ABORTOP(n)        (*((n)->ni_dvp->v_op->vop_abortop))(n)
  273. #define    VOP_INACTIVE(v,p)    (*((v)->v_op->vop_inactive))(v,p)
  274. #define    VOP_RECLAIM(v)        (*((v)->v_op->vop_reclaim))(v)
  275. #define    VOP_LOCK(v)        (*((v)->v_op->vop_lock))(v)
  276. #define    VOP_UNLOCK(v)        (*((v)->v_op->vop_unlock))(v)
  277. #define    VOP_BMAP(v,s,p,n)    (*((v)->v_op->vop_bmap))(v,s,p,n)
  278. #define    VOP_STRATEGY(b)        (*((b)->b_vp->v_op->vop_strategy))(b)
  279. #define    VOP_PRINT(v)        (*((v)->v_op->vop_print))(v)
  280. #define    VOP_ISLOCKED(v)        (((v)->v_flag & VXLOCK) || \
  281.                 (*((v)->v_op->vop_islocked))(v))
  282. #define    VOP_ADVLOCK(v,p,o,l,f)    (*((v)->v_op->vop_advlock))(v,p,o,l,f)
  283.  
  284. /*
  285.  * flags for ioflag
  286.  */
  287. #define    IO_UNIT        0x01        /* do I/O as atomic unit */
  288. #define    IO_APPEND    0x02        /* append write to end */
  289. #define    IO_SYNC        0x04        /* do I/O synchronously */
  290. #define    IO_NODELOCKED    0x08        /* underlying node already locked */
  291. #define    IO_NDELAY    0x10        /* FNDELAY flag set in file table */
  292.  
  293. /*
  294.  *  Modes. Some values same as Ixxx entries from inode.h for now
  295.  */
  296. #define    VSUID    04000        /* set user id on execution */
  297. #define    VSGID    02000        /* set group id on execution */
  298. #define    VSVTX    01000        /* save swapped text even after use */
  299. #define    VREAD    0400        /* read, write, execute permissions */
  300. #define    VWRITE    0200
  301. #define    VEXEC    0100
  302.  
  303. /*
  304.  * Token indicating no attribute value yet assigned
  305.  */
  306. #define    VNOVAL    ((unsigned)0xffffffff)
  307.  
  308. #ifdef KERNEL
  309. /*
  310.  * public vnode manipulation functions
  311.  */
  312. int     vn_open __P((struct nameidata *ndp, struct proc *p, int fmode,
  313.         int cmode));
  314. int     vn_close __P((struct vnode *vp, int flags, struct ucred *cred,
  315.         struct proc *p));
  316. int     vn_rdwr __P((enum uio_rw rw, struct vnode *vp, caddr_t base,
  317.         int len, off_t offset, enum uio_seg segflg, int ioflg,
  318.         struct ucred *cred, int *aresid, struct proc *p));
  319. int    vn_read __P((struct file *fp, struct uio *uio, struct ucred *cred));
  320. int    vn_write __P((struct file *fp, struct uio *uio, struct ucred *cred));
  321. int    vn_ioctl __P((struct file *fp, int com, caddr_t data, struct proc *p));
  322. int    vn_select __P((struct file *fp, int which, struct proc *p));
  323. int     vn_closefile __P((struct file *fp, struct proc *p));
  324. int     getnewvnode __P((enum vtagtype tag, struct mount *mp,
  325.         struct vnodeops *vops, struct vnode **vpp));
  326. int     bdevvp __P((int dev, struct vnode **vpp));
  327.     /* check for special device aliases */
  328.     /* XXX nvp_rdev should be type dev_t, not int */
  329. struct     vnode *checkalias __P((struct vnode *vp, int nvp_rdev,
  330.         struct mount *mp));
  331. void     vattr_null __P((struct vattr *vap));
  332. int     vcount __P((struct vnode *vp));    /* total references to a device */
  333. int     vget __P((struct vnode *vp));    /* get first reference to a vnode */
  334. void     vref __P((struct vnode *vp));    /* increase reference to a vnode */
  335. void     vput __P((struct vnode *vp));    /* unlock and release vnode */
  336. void     vrele __P((struct vnode *vp));    /* release vnode */
  337. void     vgone __P((struct vnode *vp));    /* completely recycle vnode */
  338. void     vgoneall __P((struct vnode *vp));/* recycle vnode and all its aliases */
  339.  
  340. /*
  341.  * Flags to various vnode functions.
  342.  */
  343. #define    SKIPSYSTEM    0x0001        /* vflush: skip vnodes marked VSYSTEM */
  344. #define    FORCECLOSE    0x0002        /* vflush: force file closeure */
  345. #define    DOCLOSE        0x0004        /* vclean: close active files */
  346.  
  347. #ifndef DIAGNOSTIC
  348. #define    VREF(vp)    (vp)->v_usecount++    /* increase reference */
  349. #define    VHOLD(vp)    (vp)->v_holdcnt++    /* increase buf or page ref */
  350. #define    HOLDRELE(vp)    (vp)->v_holdcnt--    /* decrease buf or page ref */
  351. #define    VATTR_NULL(vap)    (*(vap) = va_null)    /* initialize a vattr */
  352. #else /* DIAGNOSTIC */
  353. #define    VREF(vp)    vref(vp)
  354. #define    VHOLD(vp)    vhold(vp)
  355. #define    HOLDRELE(vp)    holdrele(vp)
  356. #define    VATTR_NULL(vap)    vattr_null(vap)
  357. #endif
  358.  
  359. #define    NULLVP    ((struct vnode *)NULL)
  360.  
  361. /*
  362.  * Global vnode data.
  363.  */
  364. extern    struct vnode *rootdir;        /* root (i.e. "/") vnode */
  365. extern    long desiredvnodes;        /* number of vnodes desired */
  366. extern    struct vattr va_null;        /* predefined null vattr structure */
  367. #endif
  368.