Prex Home / Browse Source - Prex Version: 0.9.0

root/include/sys/vnode.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * Copyright (c) 2005-2007, Kohsuke Ohtani
   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. Neither the name of the author nor the names of any co-contributors
  14  *    may be used to endorse or promote products derived from this software
  15  *    without specific prior written permission.
  16  *
  17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27  * SUCH DAMAGE.
  28  */
  29 
  30 #ifndef _SYS_VNODE_H_
  31 #define _SYS_VNODE_H_
  32 
  33 #include <sys/types.h>
  34 #include <sys/stat.h>
  35 #include <sys/file.h>
  36 #include <sys/list.h>
  37 #include <sys/dirent.h>
  38 #include <sys/syslimits.h>
  39 
  40 struct vfsops;
  41 struct vnops;
  42 struct vnode;
  43 struct file;
  44 
  45 /*
  46  * Vnode types.
  47  */
  48 enum {
  49         VNON,       /* no type */
  50         VREG,       /* regular file  */
  51         VDIR,       /* directory */
  52         VBLK,       /* block device */
  53         VCHR,       /* character device */
  54         VLNK,       /* symbolic link */
  55         VSOCK,      /* socks */
  56         VFIFO       /* FIFO */
  57 };
  58 
  59 /*
  60  * Reading or writing any of these items requires holding the
  61  * appropriate lock.
  62  */
  63 struct vnode {
  64         struct list     v_link;         /* link for hash list */
  65         struct mount    *v_mount;       /* mounted vfs pointer */
  66         struct vnops    *v_op;          /* vnode operations */
  67         int             v_refcnt;       /* reference count */
  68         int             v_type;         /* vnode type */
  69         int             v_flags;        /* vnode flag */
  70         mode_t          v_mode;         /* file mode */
  71         size_t          v_size;         /* file size */
  72         mutex_t         v_lock;         /* lock for this vnode */
  73         int             v_nrlocks;      /* lock count (for debug) */
  74         int             v_blkno;        /* block number */
  75         char            *v_path;        /* pointer to path in fs */
  76         void            *v_data;        /* private data for fs */
  77 };
  78 typedef struct vnode *vnode_t;
  79 
  80 /* flags for vnode */
  81 #define VROOT           0x0001          /* root of its file system */
  82 #define VISTTY          0x0002          /* device is tty */
  83 #define VPROTDEV        0x0004          /* protected device */
  84 
  85 /*
  86  * Vnode attribute
  87  */
  88 struct vattr {
  89         int             va_type;        /* vnode type */
  90         mode_t          va_mode;        /* file access mode */
  91 };
  92 
  93 /*
  94  *  Modes.
  95  */
  96 #define VREAD   00004           /* read, write, execute permissions */
  97 #define VWRITE  00002
  98 #define VEXEC   00001
  99 
 100 /*
 101  * vnode operations
 102  */
 103 struct vnops {
 104         int (*vop_open)         (vnode_t, int);
 105         int (*vop_close)        (vnode_t, file_t);
 106         int (*vop_read)         (vnode_t, file_t, void *, size_t, size_t *);
 107         int (*vop_write)        (vnode_t, file_t, void *, size_t, size_t *);
 108         int (*vop_seek)         (vnode_t, file_t, off_t, off_t);
 109         int (*vop_ioctl)        (vnode_t, file_t, u_long, void *);
 110         int (*vop_fsync)        (vnode_t, file_t);
 111         int (*vop_readdir)      (vnode_t, file_t, struct dirent *);
 112         int (*vop_lookup)       (vnode_t, char *, vnode_t);
 113         int (*vop_create)       (vnode_t, char *, mode_t);
 114         int (*vop_remove)       (vnode_t, vnode_t, char *);
 115         int (*vop_rename)       (vnode_t, vnode_t, char *, vnode_t, vnode_t, char *);
 116         int (*vop_mkdir)        (vnode_t, char *, mode_t);
 117         int (*vop_rmdir)        (vnode_t, vnode_t, char *);
 118         int (*vop_getattr)      (vnode_t, struct vattr *);
 119         int (*vop_setattr)      (vnode_t, struct vattr *);
 120         int (*vop_inactive)     (vnode_t);
 121         int (*vop_truncate)     (vnode_t, off_t);
 122 };
 123 
 124 typedef int (*vnop_open_t)      (vnode_t, int);
 125 typedef int (*vnop_close_t)     (vnode_t, file_t);
 126 typedef int (*vnop_read_t)      (vnode_t, file_t, void *, size_t, size_t *);
 127 typedef int (*vnop_write_t)     (vnode_t, file_t, void *, size_t, size_t *);
 128 typedef int (*vnop_seek_t)      (vnode_t, file_t, off_t, off_t);
 129 typedef int (*vnop_ioctl_t)     (vnode_t, file_t, u_long, void *);
 130 typedef int (*vnop_fsync_t)     (vnode_t, file_t);
 131 typedef int (*vnop_readdir_t)   (vnode_t, file_t, struct dirent *);
 132 typedef int (*vnop_lookup_t)    (vnode_t, char *, vnode_t);
 133 typedef int (*vnop_create_t)    (vnode_t, char *, mode_t);
 134 typedef int (*vnop_remove_t)    (vnode_t, vnode_t, char *);
 135 typedef int (*vnop_rename_t)    (vnode_t, vnode_t, char *, vnode_t, vnode_t, char *);
 136 typedef int (*vnop_mkdir_t)     (vnode_t, char *, mode_t);
 137 typedef int (*vnop_rmdir_t)     (vnode_t, vnode_t, char *);
 138 typedef int (*vnop_getattr_t)   (vnode_t, struct vattr *);
 139 typedef int (*vnop_setattr_t)   (vnode_t, struct vattr *);
 140 typedef int (*vnop_inactive_t)  (vnode_t);
 141 typedef int (*vnop_truncate_t)  (vnode_t, off_t);
 142 
 143 /*
 144  * vnode interface
 145  */
 146 #define VOP_OPEN(VP, F)            ((VP)->v_op->vop_open)(VP, F)
 147 #define VOP_CLOSE(VP, FP)          ((VP)->v_op->vop_close)(VP, FP)
 148 #define VOP_READ(VP, FP, B, S, C)  ((VP)->v_op->vop_read)(VP, FP, B, S, C)
 149 #define VOP_WRITE(VP, FP, B, S, C) ((VP)->v_op->vop_write)(VP, FP, B, S, C)
 150 #define VOP_SEEK(VP, FP, OLD, NEW) ((VP)->v_op->vop_seek)(VP, FP, OLD, NEW)
 151 #define VOP_IOCTL(VP, FP, C, A)    ((VP)->v_op->vop_ioctl)(VP, FP, C, A)
 152 #define VOP_FSYNC(VP, FP)          ((VP)->v_op->vop_fsync)(VP, FP)
 153 #define VOP_READDIR(VP, FP, DIR)   ((VP)->v_op->vop_readdir)(VP, FP, DIR)
 154 #define VOP_LOOKUP(DVP, N, VP)     ((DVP)->v_op->vop_lookup)(DVP, N, VP)
 155 #define VOP_CREATE(DVP, N, M)      ((DVP)->v_op->vop_create)(DVP, N, M)
 156 #define VOP_REMOVE(DVP, VP, N)     ((DVP)->v_op->vop_remove)(DVP, VP, N)
 157 #define VOP_RENAME(DVP1, VP1, N1, DVP2, VP2, N2) \
 158                            ((DVP1)->v_op->vop_rename)(DVP1, VP1, N1, DVP2, VP2, N2)
 159 #define VOP_MKDIR(DVP, N, M)       ((DVP)->v_op->vop_mkdir)(DVP, N, M)
 160 #define VOP_RMDIR(DVP, VP, N)      ((DVP)->v_op->vop_rmdir)(DVP, VP, N)
 161 #define VOP_GETATTR(VP, VAP)       ((VP)->v_op->vop_getattr)(VP, VAP)
 162 #define VOP_SETATTR(VP, VAP)       ((VP)->v_op->vop_setattr)(VP, VAP)
 163 #define VOP_INACTIVE(VP)           ((VP)->v_op->vop_inactive)(VP)
 164 #define VOP_TRUNCATE(VP, N)        ((VP)->v_op->vop_truncate)(VP, N)
 165 
 166 __BEGIN_DECLS
 167 int      vop_nullop(void);
 168 int      vop_einval(void);
 169 vnode_t  vn_lookup(struct mount *, char *);
 170 void     vn_lock(vnode_t);
 171 void     vn_unlock(vnode_t);
 172 int      vn_stat(vnode_t, struct stat *);
 173 int      vn_access(vnode_t, int);
 174 vnode_t  vget(struct mount *, char *);
 175 void     vput(vnode_t);
 176 void     vgone(vnode_t);
 177 void     vref(vnode_t);
 178 void     vrele(vnode_t);
 179 int      vcount(vnode_t);
 180 void     vflush(struct mount *);
 181 __END_DECLS
 182 
 183 #endif /* !_SYS_VNODE_H_ */

/* [<][>][^][v][top][bottom][index][help] */