home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / sys / ufs / inode.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-08  |  8.4 KB  |  231 lines

  1. /*
  2.  * Copyright (c) 1982, 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.  *
  33.  *    @(#)inode.h    7.17 (Berkeley) 5/8/91
  34.  */
  35.  
  36. #ifdef KERNEL
  37. #include "../ufs/dinode.h"
  38. #else
  39. #include <ufs/dinode.h>
  40. #endif
  41.  
  42. /*
  43.  * The inode is used to describe each active (or recently active)
  44.  * file in the UFS filesystem. It is composed of two types of
  45.  * information. The first part is the information that is needed
  46.  * only while the file is active (such as the identity of the file
  47.  * and linkage to speed its lookup). The second part is the 
  48.  * permannent meta-data associated with the file which is read
  49.  * in from the permanent dinode from long term storage when the
  50.  * file becomes active, and is put back when the file is no longer
  51.  * being used.
  52.  */
  53. struct inode {
  54.     struct    inode *i_chain[2]; /* hash chain, MUST be first */
  55.     struct    vnode *i_vnode;    /* vnode associated with this inode */
  56.     struct    vnode *i_devvp;    /* vnode for block I/O */
  57.     u_long    i_flag;        /* see below */
  58.     dev_t    i_dev;        /* device where inode resides */
  59.     ino_t    i_number;    /* the identity of the inode */
  60.     struct    fs *i_fs;    /* filesystem associated with this inode */
  61.     struct    dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */
  62.     struct    lockf *i_lockf;    /* head of byte-level lock list */
  63.     long    i_diroff;    /* offset in dir, where we found last entry */
  64.     off_t    i_endoff;    /* end of useful stuff in directory */
  65.     long    i_spare0;
  66.     long    i_spare1;
  67.     struct    dinode i_din;    /* the on-disk dinode */
  68. };
  69.  
  70. #define    i_mode        i_din.di_mode
  71. #define    i_nlink        i_din.di_nlink
  72. #define    i_uid        i_din.di_uid
  73. #define    i_gid        i_din.di_gid
  74. #if BYTE_ORDER == LITTLE_ENDIAN || defined(tahoe) /* ugh! -- must be fixed */
  75. #define    i_size        i_din.di_qsize.val[0]
  76. #else /* BYTE_ORDER == BIG_ENDIAN */
  77. #define    i_size        i_din.di_qsize.val[1]
  78. #endif
  79. #define    i_db        i_din.di_db
  80. #define    i_ib        i_din.di_ib
  81. #define    i_atime        i_din.di_atime
  82. #define    i_mtime        i_din.di_mtime
  83. #define    i_ctime        i_din.di_ctime
  84. #define i_blocks    i_din.di_blocks
  85. #define    i_rdev        i_din.di_db[0]
  86. #define i_flags        i_din.di_flags
  87. #define i_gen        i_din.di_gen
  88. #define    i_forw        i_chain[0]
  89. #define    i_back        i_chain[1]
  90.  
  91. /* flags */
  92. #define    ILOCKED        0x0001        /* inode is locked */
  93. #define    IWANT        0x0002        /* some process waiting on lock */
  94. #define    IRENAME        0x0004        /* inode is being renamed */
  95. #define    IUPD        0x0010        /* file has been modified */
  96. #define    IACC        0x0020        /* inode access time to be updated */
  97. #define    ICHG        0x0040        /* inode has been changed */
  98. #define    IMOD        0x0080        /* inode has been modified */
  99. #define    ISHLOCK        0x0100        /* file has shared lock */
  100. #define    IEXLOCK        0x0200        /* file has exclusive lock */
  101. #define    ILWAIT        0x0400        /* someone waiting on file lock */
  102.  
  103. #ifdef KERNEL
  104. /*
  105.  * Convert between inode pointers and vnode pointers
  106.  */
  107. #define VTOI(vp)    ((struct inode *)(vp)->v_data)
  108. #define ITOV(ip)    ((ip)->i_vnode)
  109.  
  110. /*
  111.  * Convert between vnode types and inode formats
  112.  */
  113. extern enum vtype    iftovt_tab[];
  114. extern int        vttoif_tab[];
  115. #define IFTOVT(mode)    (iftovt_tab[((mode) & IFMT) >> 12])
  116. #define VTTOIF(indx)    (vttoif_tab[(int)(indx)])
  117.  
  118. #define MAKEIMODE(indx, mode)    (int)(VTTOIF(indx) | (mode))
  119.  
  120. u_long    nextgennumber;        /* next generation number to assign */
  121.  
  122. extern ino_t    dirpref();
  123.  
  124. /*
  125.  * Lock and unlock inodes.
  126.  */
  127. #ifdef notdef
  128. #define    ILOCK(ip) { \
  129.     while ((ip)->i_flag & ILOCKED) { \
  130.         (ip)->i_flag |= IWANT; \
  131.         (void) sleep((caddr_t)(ip), PINOD); \
  132.     } \
  133.     (ip)->i_flag |= ILOCKED; \
  134. }
  135.  
  136. #define    IUNLOCK(ip) { \
  137.     (ip)->i_flag &= ~ILOCKED; \
  138.     if ((ip)->i_flag&IWANT) { \
  139.         (ip)->i_flag &= ~IWANT; \
  140.         wakeup((caddr_t)(ip)); \
  141.     } \
  142. }
  143. #else
  144. #define ILOCK(ip)    ilock(ip)
  145. #define IUNLOCK(ip)    iunlock(ip)
  146. #endif
  147.  
  148. #define    IUPDAT(ip, t1, t2, waitfor) { \
  149.     if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
  150.         (void) iupdat(ip, t1, t2, waitfor); \
  151. }
  152.  
  153. #define    ITIMES(ip, t1, t2) { \
  154.     if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
  155.         (ip)->i_flag |= IMOD; \
  156.         if ((ip)->i_flag&IACC) \
  157.             (ip)->i_atime = (t1)->tv_sec; \
  158.         if ((ip)->i_flag&IUPD) \
  159.             (ip)->i_mtime = (t2)->tv_sec; \
  160.         if ((ip)->i_flag&ICHG) \
  161.             (ip)->i_ctime = time.tv_sec; \
  162.         (ip)->i_flag &= ~(IACC|IUPD|ICHG); \
  163.     } \
  164. }
  165.  
  166. /*
  167.  * This overlays the fid sturcture (see mount.h)
  168.  */
  169. struct ufid {
  170.     u_short    ufid_len;    /* length of structure */
  171.     u_short    ufid_pad;    /* force long alignment */
  172.     ino_t    ufid_ino;    /* file number (ino) */
  173.     long    ufid_gen;    /* generation number */
  174. };
  175.  
  176. /*
  177.  * Prototypes for UFS vnode operations
  178.  */
  179. int ufs_lookup __P((struct vnode *vp, struct nameidata *ndp, struct proc *p));
  180. int ufs_create __P((struct nameidata *ndp, struct vattr *vap, struct proc *p));
  181. int ufs_mknod __P((struct nameidata *ndp, struct vattr *vap, struct ucred *cred,
  182.     struct proc *p));
  183. int ufs_open __P((struct vnode *vp, int mode, struct ucred *cred,
  184.     struct proc *p));
  185. int ufs_close __P((struct vnode *vp, int fflag, struct ucred *cred,
  186.     struct proc *p));
  187. int ufs_access __P((struct vnode *vp, int mode, struct ucred *cred,
  188.     struct proc *p));
  189. int ufs_getattr __P((struct vnode *vp, struct vattr *vap, struct ucred *cred,
  190.     struct proc *p));
  191. int ufs_setattr __P((struct vnode *vp, struct vattr *vap, struct ucred *cred,
  192.     struct proc *p));
  193. int ufs_read __P((struct vnode *vp, struct uio *uio, int ioflag,
  194.     struct ucred *cred));
  195. int ufs_write __P((struct vnode *vp, struct uio *uio, int ioflag,
  196.     struct ucred *cred));
  197. int ufs_ioctl __P((struct vnode *vp, int command, caddr_t data, int fflag,
  198.     struct ucred *cred, struct proc *p));
  199. int ufs_select __P((struct vnode *vp, int which, int fflags, struct ucred *cred,
  200.     struct proc *p));
  201. int ufs_mmap __P((struct vnode *vp, int fflags, struct ucred *cred,
  202.     struct proc *p));
  203. int ufs_fsync __P((struct vnode *vp, int fflags, struct ucred *cred,
  204.     int waitfor, struct proc *p));
  205. int ufs_seek __P((struct vnode *vp, off_t oldoff, off_t newoff,
  206.     struct ucred *cred));
  207. int ufs_remove __P((struct nameidata *ndp, struct proc *p));
  208. int ufs_link __P((struct vnode *vp, struct nameidata *ndp, struct proc *p));
  209. int ufs_rename __P((struct nameidata *fndp, struct nameidata *tdnp,
  210.     struct proc *p));
  211. int ufs_mkdir __P((struct nameidata *ndp, struct vattr *vap, struct proc *p));
  212. int ufs_rmdir __P((struct nameidata *ndp, struct proc *p));
  213. int ufs_symlink __P((struct nameidata *ndp, struct vattr *vap, char *target,
  214.     struct proc *p));
  215. int ufs_readdir __P((struct vnode *vp, struct uio *uio, struct ucred *cred,
  216.     int *eofflagp));
  217. int ufs_readlink __P((struct vnode *vp, struct uio *uio, struct ucred *cred));
  218. int ufs_abortop __P((struct nameidata *ndp));
  219. int ufs_inactive __P((struct vnode *vp, struct proc *p));
  220. int ufs_reclaim __P((struct vnode *vp));
  221. int ufs_lock __P((struct vnode *vp));
  222. int ufs_unlock __P((struct vnode *vp));
  223. int ufs_bmap __P((struct vnode *vp, daddr_t bn, struct vnode **vpp,
  224.     daddr_t *bnp));
  225. int ufs_strategy __P((struct buf *bp));
  226. int ufs_print __P((struct vnode *vp));
  227. int ufs_islocked __P((struct vnode *vp));
  228. int ufs_advlock __P((struct vnode *vp, caddr_t id, int op, struct flock *fl,
  229.     int flags));
  230. #endif /* KERNEL */
  231.