Annotation of Net2/sys/vnode.h, revision 1.1.1.3

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.