home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 9.ddi / usr / include / sys / vnode.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  11.0 KB  |  356 lines

  1. /*    Copyright (c) 1990 UNIX System Laboratories, Inc.    */
  2. /*    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T    */
  3. /*      All Rights Reserved      */
  4.  
  5. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF         */
  6. /*    UNIX System Laboratories, Inc.                         */
  7. /*    The copyright notice above does not evidence any       */
  8. /*    actual or intended publication of such source code.    */
  9.  
  10. /*
  11.  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  12.  *         PROPRIETARY NOTICE (Combined)
  13.  * 
  14.  * This source code is unpublished proprietary information
  15.  * constituting, or derived under license from AT&T's UNIX(r) System V.
  16.  * In addition, portions of such source code were derived from Berkeley
  17.  * 4.3 BSD under license from the Regents of the University of
  18.  * California.
  19.  * 
  20.  * 
  21.  * 
  22.  *         Copyright Notice 
  23.  * 
  24.  * Notice of copyright on this source code product does not indicate 
  25.  * publication.
  26.  * 
  27.  *     (c) 1986,1987,1988,1989  Sun Microsystems, Inc
  28.  *     (c) 1983,1984,1985,1986,1987,1988,1989  AT&T.
  29.  *               All rights reserved.
  30.  *  
  31.  */
  32.  
  33. #ifndef _SYS_VNODE_H
  34. #define _SYS_VNODE_H
  35.  
  36. #ident  "@(#)/usr/include/sys/vnode.h.sl 1.1 4.0 12/08/90 46667 AT&T-USL"
  37.  
  38. #include <sys/time.h>
  39.  
  40. /*
  41.  * The vnode is the focus of all file activity in UNIX.
  42.  * A vnode is allocated for each active file, each current
  43.  * directory, each mounted-on file, and the root.
  44.  */
  45.  
  46. /*
  47.  * vnode types.  VNON means no type.  These values are unrelated to
  48.  * values in on-disk inodes.
  49.  */
  50. typedef enum vtype {
  51.     VNON    = 0,
  52.     VREG    = 1,
  53.     VDIR    = 2,
  54.     VBLK    = 3,
  55.     VCHR    = 4,
  56.     VLNK    = 5,
  57.     VFIFO    = 6,
  58.     VXNAM    = 7,
  59.     VBAD    = 8
  60. } vtype_t;
  61.  
  62. typedef struct vnode {
  63.     u_short        v_flag;            /* vnode flags (see below) */
  64.     u_short        v_count;        /* reference count */
  65.     struct vfs    *v_vfsmountedhere;    /* ptr to vfs mounted here */
  66.     struct vnodeops    *v_op;            /* vnode operations */
  67.     struct vfs    *v_vfsp;        /* ptr to containing VFS */
  68.     struct stdata    *v_stream;        /* associated stream */
  69.     struct page    *v_pages;        /* vnode pages list */
  70.     enum vtype    v_type;            /* vnode type */
  71.     dev_t        v_rdev;            /* device (VCHR, VBLK) */
  72.     caddr_t        v_data;            /* private data for fs */
  73.     struct filock    *v_filocks;        /* ptr to filock list */
  74.     long        v_filler[8];        /* padding */
  75. } vnode_t;
  76.  
  77. /*
  78.  * vnode flags.
  79.  */
  80. #define    VROOT    0x01    /* root of its file system */
  81. #define VNOMAP    0x04    /* file cannot be mapped/faulted */
  82. #define    VDUP    0x08    /* file should be dup'ed rather then opened */
  83. #define VNOMOUNT 0x20   /* file cannot be covered by mount */
  84. #define VNOSWAP    0x10    /* file cannot be used as virtual swap device */
  85. #define VISSWAP    0x40    /* vnode is part of virtual swap device */
  86. /* XENIX Support */
  87. #define VXLOCKED 0x8000    /* Xenix frlock */
  88. /* End XENIX Support */
  89.  
  90. /*
  91.  * Operations on vnodes.
  92.  */
  93. typedef struct vnodeops {
  94.     int    (*vop_open)();
  95.     int    (*vop_close)();
  96.     int    (*vop_read)();
  97.     int    (*vop_write)();
  98.     int    (*vop_ioctl)();
  99.     int    (*vop_setfl)();
  100.     int    (*vop_getattr)();
  101.     int    (*vop_setattr)();
  102.     int    (*vop_access)();
  103.     int    (*vop_lookup)();
  104.     int    (*vop_create)();
  105.     int    (*vop_remove)();
  106.     int    (*vop_link)();
  107.     int    (*vop_rename)();
  108.     int    (*vop_mkdir)();
  109.     int    (*vop_rmdir)();
  110.     int    (*vop_readdir)();
  111.     int    (*vop_symlink)();
  112.     int    (*vop_readlink)();
  113.     int    (*vop_fsync)();
  114.     void    (*vop_inactive)();
  115.     int    (*vop_fid)();
  116.     void    (*vop_rwlock)();
  117.     void    (*vop_rwunlock)();
  118.     int    (*vop_seek)();
  119.     int    (*vop_cmp)();
  120.     int    (*vop_frlock)();
  121.     int    (*vop_space)();
  122.     int    (*vop_realvp)();
  123.     int    (*vop_getpage)();
  124.     int    (*vop_putpage)();
  125.     int    (*vop_map)();
  126.     int    (*vop_addmap)();
  127.     int    (*vop_delmap)();
  128.     int    (*vop_poll)();
  129.     int    (*vop_dump)();
  130.     int    (*vop_pathconf)();
  131.     int    (*vop_allocstore)();
  132.     int    (*vop_filler[31])();
  133. } vnodeops_t;
  134.  
  135. #define    VOP_OPEN(vpp, mode, cr) (*(*(vpp))->v_op->vop_open)(vpp, mode, cr)
  136. #define    VOP_CLOSE(vp, f, c, o, cr) (*(vp)->v_op->vop_close)(vp, f, c, o, cr)
  137. #define    VOP_READ(vp,uiop,iof,cr) (*(vp)->v_op->vop_read)(vp,uiop,iof,cr)
  138. #define    VOP_WRITE(vp,uiop,iof,cr) (*(vp)->v_op->vop_write)(vp,uiop,iof,cr)
  139. #define    VOP_IOCTL(vp,cmd,a,f,cr,rvp) (*(vp)->v_op->vop_ioctl)(vp,cmd,a,f,cr,rvp)
  140. #define    VOP_SETFL(vp, f, a, cr) (*(vp)->v_op->vop_setfl)(vp, f, a, cr)
  141. #define    VOP_GETATTR(vp, vap, f, cr) (*(vp)->v_op->vop_getattr)(vp, vap, f, cr)
  142. #define    VOP_SETATTR(vp, vap, f, cr) (*(vp)->v_op->vop_setattr)(vp, vap, f, cr)
  143. #define    VOP_ACCESS(vp, mode, f, cr) (*(vp)->v_op->vop_access)(vp, mode, f, cr)
  144. #define    VOP_LOOKUP(vp,cp,vpp,pnp,f,rdir,cr) \
  145.         (*(vp)->v_op->vop_lookup)(vp,cp,vpp,pnp,f,rdir,cr)
  146. #define    VOP_CREATE(dvp,p,vap,ex,mode,vpp,cr) \
  147.         (*(dvp)->v_op->vop_create)(dvp,p,vap,ex,mode,vpp,cr)
  148. #define    VOP_REMOVE(dvp,p,cr) (*(dvp)->v_op->vop_remove)(dvp,p,cr)
  149. #define    VOP_LINK(tdvp,fvp,p,cr) (*(tdvp)->v_op->vop_link)(tdvp,fvp,p,cr)
  150. #define    VOP_RENAME(fvp,fnm,tdvp,tnm,cr) \
  151.         (*(fvp)->v_op->vop_rename)(fvp,fnm,tdvp,tnm,cr)
  152. #define    VOP_MKDIR(dp,p,vap,vpp,cr) (*(dp)->v_op->vop_mkdir)(dp,p,vap,vpp,cr)
  153. #define    VOP_RMDIR(dp,p,cdir,cr) (*(dp)->v_op->vop_rmdir)(dp,p,cdir,cr)
  154. #define    VOP_READDIR(vp,uiop,cr,eofp) (*(vp)->v_op->vop_readdir)(vp,uiop,cr,eofp)
  155. #define    VOP_SYMLINK(dvp,lnm,vap,tnm,cr) \
  156.         (*(dvp)->v_op->vop_symlink) (dvp,lnm,vap,tnm,cr)
  157. #define    VOP_READLINK(vp, uiop, cr) (*(vp)->v_op->vop_readlink)(vp, uiop, cr)
  158. #define    VOP_FSYNC(vp, cr) (*(vp)->v_op->vop_fsync)(vp, cr)
  159. #define    VOP_INACTIVE(vp, cr) (*(vp)->v_op->vop_inactive)(vp, cr)
  160. #define    VOP_FID(vp, fidpp) (*(vp)->v_op->vop_fid)(vp, fidpp)
  161. #define    VOP_RWLOCK(vp) (*(vp)->v_op->vop_rwlock)(vp)
  162. #define    VOP_RWUNLOCK(vp) (*(vp)->v_op->vop_rwunlock)(vp)
  163. #define    VOP_SEEK(vp, ooff, noffp) (*(vp)->v_op->vop_seek)(vp, ooff, noffp)
  164. #define    VOP_CMP(vp1, vp2) (*(vp1)->v_op->vop_cmp)(vp1, vp2)
  165. #define    VOP_FRLOCK(vp,cmd,a,f,o,cr) (*(vp)->v_op->vop_frlock)(vp,cmd,a,f,o,cr)
  166. #define    VOP_SPACE(vp,cmd,a,f,o,cr) (*(vp)->v_op->vop_space)(vp,cmd,a,f,o,cr)
  167. #define    VOP_REALVP(vp1, vp2) (*(vp1)->v_op->vop_realvp)(vp1, vp2)
  168. #define    VOP_GETPAGE(vp,of,sz,pr,pl,ps,sg,a,rw,cr)\
  169.         (*(vp)->v_op->vop_getpage) (vp,of,sz,pr,pl,ps,sg,a,rw,cr)
  170. #define    VOP_PUTPAGE(vp,of,sz,fl,cr) (*(vp)->v_op->vop_putpage)(vp,of,sz,fl,cr)
  171. #define    VOP_ALLOCSTORE(vp,off,len,cr) \
  172.         (*(vp)->v_op->vop_allocstore) (vp,off,len,cr)
  173. #define    VOP_MAP(vp,of,as,a,sz,p,mp,fl,cr) \
  174.         (*(vp)->v_op->vop_map) (vp,of,as,a,sz,p,mp,fl,cr)
  175. #define    VOP_ADDMAP(vp,of,as,a,sz,p,mp,fl,cr) \
  176.         (*(vp)->v_op->vop_addmap) (vp,of,as,a,sz,p,mp,fl,cr)
  177. #define    VOP_DELMAP(vp,of,as,a,sz,p,mp,fl,cr) \
  178.         (*(vp)->v_op->vop_delmap) (vp,of,as,a,sz,p,mp,fl,cr)
  179. #define    VOP_POLL(vp, events, anyyet, reventsp, phpp) \
  180.         (*(vp)->v_op->vop_poll)(vp, events, anyyet, reventsp, phpp)
  181. #define    VOP_DUMP(vp,addr,bn,count) (*(vp)->v_op->vop_dump)(vp,addr,bn,count)
  182. #define    VOP_PATHCONF(vp, cmd, valp, cr) \
  183.         (*(vp)->v_op->vop_pathconf)(vp, cmd, valp, cr)
  184.  
  185. /*
  186.  * I/O flags for VOP_READ and VOP_WRITE.
  187.  */
  188. #define IO_APPEND    0x01    /* append write (VOP_WRITE) */
  189. #define IO_SYNC        0x02    /* sync I/O (VOP_WRITE) */
  190.  
  191. /*
  192.  * Flags for VOP_LOOKUP.
  193.  */
  194. #define LOOKUP_DIR    0x01    /* want parent dir vp */
  195.  
  196. /*
  197.  * Vnode attributes.  A bit-mask is supplied as part of the
  198.  * structure to indicate the attributes the caller wants to
  199.  * set (setattr) or extract (getattr).
  200.  */
  201. typedef struct vattr {
  202.     long        va_mask;    /* bit-mask of attributes */
  203.     vtype_t        va_type;    /* vnode type (for create) */
  204.     mode_t        va_mode;    /* file access mode */
  205.     uid_t        va_uid;        /* owner user id */
  206.     gid_t        va_gid;        /* owner group id */
  207.     dev_t        va_fsid;    /* file system id (dev for now) */
  208.     ino_t        va_nodeid;    /* node id */
  209.     nlink_t        va_nlink;    /* number of references to file */
  210.     u_long        va_size0;    /* file size pad (for future use) */
  211.     u_long        va_size;    /* file size in bytes */
  212.     timestruc_t    va_atime;    /* time of last access */
  213.     timestruc_t    va_mtime;    /* time of last modification */
  214.     timestruc_t    va_ctime;    /* time file ``created'' */
  215.     dev_t        va_rdev;    /* device the file represents */
  216.     u_long        va_blksize;    /* fundamental block size */
  217.     u_long        va_nblocks;    /* # of blocks allocated */
  218.     u_long        va_vcode;    /* version code */
  219.     long        va_filler[8];    /* padding */
  220. } vattr_t;
  221.  
  222. /*
  223.  * Attributes of interest to the caller of setattr or getattr.
  224.  */
  225. #define    AT_TYPE        0x0001
  226. #define    AT_MODE        0x0002
  227. #define    AT_UID        0x0004
  228. #define    AT_GID        0x0008
  229. #define    AT_FSID        0x0010
  230. #define    AT_NODEID    0x0020
  231. #define    AT_NLINK    0x0040
  232. #define    AT_SIZE        0x0080
  233. #define    AT_ATIME    0x0100
  234. #define    AT_MTIME    0x0200
  235. #define    AT_CTIME    0x0400
  236. #define    AT_RDEV        0x0800
  237. #define AT_BLKSIZE    0x1000
  238. #define AT_NBLOCKS    0x2000
  239. #define AT_VCODE    0x4000
  240.  
  241. #define    AT_ALL    (AT_TYPE|AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|\
  242.         AT_NLINK|AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|\
  243.         AT_RDEV|AT_BLKSIZE|AT_NBLOCKS|AT_VCODE)
  244.  
  245. #define    AT_STAT    (AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\
  246.         AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|AT_RDEV)
  247.  
  248. #define    AT_TIMES (AT_ATIME|AT_MTIME|AT_CTIME)
  249.  
  250. #define    AT_NOSET (AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\
  251.          AT_BLKSIZE|AT_NBLOCKS|AT_VCODE)
  252.     
  253. /*
  254.  *  Modes.  Some values same as S_xxx entries from stat.h for convenience.
  255.  */
  256. #define    VSUID        04000        /* set user id on execution */
  257. #define    VSGID        02000        /* set group id on execution */
  258. #define VSVTX        01000        /* save swapped text even after use */
  259.  
  260. /*
  261.  * Permissions.
  262.  */
  263. #define    VREAD        00400
  264. #define    VWRITE        00200
  265. #define    VEXEC        00100
  266.  
  267. #define    MODEMASK    07777        /* mode bits plus permission bits */
  268. #define    PERMMASK    00777        /* permission bits */
  269.  
  270. /*
  271.  * Check whether mandatory file locking is enabled.
  272.  */
  273.  
  274. /* XENIX Support */
  275. #define MANDLOCK(vp, mode)    \
  276.     ((vp)->v_type == VREG && ((((mode) & (VSGID|(VEXEC>>3))) == VSGID) \
  277.       || ((vp)->v_flag & VXLOCKED) == VXLOCKED))
  278. /* End XENIX Support */
  279.  
  280. /*
  281.  * Public vnode manipulation functions.
  282.  */
  283. extern int vn_open();
  284. extern int vn_create();
  285. extern int vn_rdwr();
  286. extern int vn_close();
  287. extern void vn_rele();
  288. extern int vn_link();
  289. extern int vn_rename();
  290. extern int vn_remove();
  291. extern vnode_t *specvp();
  292. extern vnode_t *makespecvp();
  293.  
  294. /* XENIX Support */
  295. extern int fifo_rdchk();
  296. extern int spec_rdchk();
  297. /* End XENIX Support */
  298.  
  299. #define VN_HOLD(vp)    { \
  300.     (vp)->v_count++; \
  301. }
  302.  
  303. #define VN_RELE(vp)    { \
  304.     vn_rele(vp); \
  305. }
  306.  
  307. #define VN_INIT(vp, vfsp, type, dev)    { \
  308.     (vp)->v_flag = 0; \
  309.     (vp)->v_count = 1; \
  310.     (vp)->v_vfsp = (vfsp); \
  311.     (vp)->v_type = (type); \
  312.     (vp)->v_rdev = (dev); \
  313.     (vp)->v_pages = NULL; \
  314.     (vp)->v_stream = NULL; \
  315. }
  316.  
  317. /*
  318.  * Compare two vnodes for equality.  In general this macro should be used
  319.  * in preference to calling VOP_CMP directly.
  320.  */
  321. #define VN_CMP(VP1,VP2)    ((VP1) == (VP2) ? 1 :     \
  322.     ((VP1) && (VP2) && ((VP1)->v_op == (VP2)->v_op) ? VOP_CMP(VP1,VP2) : 0))
  323.  
  324. /*
  325.  * Flags for vnode operations.
  326.  */
  327. enum rm        { RMFILE, RMDIRECTORY };    /* rm or rmdir (remove) */
  328. enum symfollow    { NO_FOLLOW, FOLLOW };        /* follow symlinks (or not) */
  329. enum vcexcl    { NONEXCL, EXCL };        /* (non)excl create */
  330. enum create    { CRCREAT, CRMKNOD, CRMKDIR, CRCORE }; /* reason for create */
  331.  
  332. typedef enum rm        rm_t;
  333. typedef enum symfollow    symfollow_t;
  334. typedef enum vcexcl    vcexcl_t;
  335. typedef enum create    create_t;
  336.  
  337. /*
  338.  * Flags to VOP_SETATTR/VOP_GETATTR.
  339.  */
  340. #define    ATTR_UTIME    0x01    /* non-default utime(2) request */
  341. #define    ATTR_EXEC    0x02    /* invocation from exec(2) */
  342. #define    ATTR_COMM    0x04    /* yield common vp attributes */
  343.  
  344. /*
  345.  * Generally useful macros.
  346.  */
  347. #define    VBSIZE(vp)    ((vp)->v_vfsp->vfs_bsize)
  348. #define    NULLVP        ((struct vnode *)0)
  349. #define    NULLVPP        ((struct vnode **)0)
  350.  
  351. #ifdef _KERNEL
  352. extern int lookupname();
  353. #endif
  354.  
  355. #endif    /* _SYS_VNODE_H */
  356.