add USL's copyright notice
[unix-history] / usr / src / sys / ufs / ufs / inode.h
index 794086a..039fd8c 100644 (file)
 /*
 /*
- * Copyright (c) 1982, 1989 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1982, 1989, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)inode.h     7.14 (Berkeley) %G%
+ *     @(#)inode.h     8.4 (Berkeley) %G%
  */
 
  */
 
-#ifdef KERNEL
-#include "../ufs/dinode.h"
-#else
-#include <ufs/dinode.h>
-#endif
+#include <ufs/ufs/dinode.h>
 
 /*
 
 /*
- * The I node is the focus of all file activity in UNIX.
- * There is a unique inode allocated for each active file,
- * each current directory, each mounted-on file, text file, and the root.
- * An inode is 'named' by its dev/inumber pair. (iget/iget.c)
- * Data in `struct dinode' is read in from permanent inode on volume.
+ * Theoretically, directories can be more than 2Gb in length, however, in
+ * practice this seems unlikely. So, we define the type doff_t as a long
+ * to keep down the cost of doing lookup on a 32-bit machine. If you are
+ * porting to a 64-bit architecture, you should make doff_t the same as off_t.
  */
  */
+#define        doff_t  long
 
 
+/*
+ * The inode is used to describe each active (or recently active)
+ * file in the UFS filesystem. It is composed of two types of
+ * information. The first part is the information that is needed
+ * only while the file is active (such as the identity of the file
+ * and linkage to speed its lookup). The second part is the 
+ * permannent meta-data associated with the file which is read
+ * in from the permanent dinode from long term storage when the
+ * file becomes active, and is put back when the file is no longer
+ * being used.
+ */
 struct inode {
 struct inode {
-       struct  inode *i_chain[2]; /* hash chain, MUST be first */
-       struct  vnode *i_vnode; /* vnode associated with this inode */
-       struct  vnode *i_devvp; /* vnode for block I/O */
-       u_long  i_flag;         /* see below */
-       dev_t   i_dev;          /* device where inode resides */
-       ino_t   i_number;       /* i number, 1-to-1 with device address */
-       struct  fs *i_fs;       /* file sys associated with this inode */
-       struct  dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */
-       long    i_diroff;       /* offset in dir, where we found last entry */
-       off_t   i_endoff;       /* end of useful stuff in directory */
-       long    i_spare0;
-       long    i_spare1;
-       struct  dinode i_din;   /* the on-disk inode */
+       struct  inode *i_next;  /* Hash chain forward. */
+       struct  inode **i_prev; /* Hash chain back. */
+       struct  vnode *i_vnode; /* Vnode associated with this inode. */
+       struct  vnode *i_devvp; /* Vnode for block I/O. */
+       u_long  i_flag;         /* I* flags. */
+       dev_t   i_dev;          /* Device associated with the inode. */
+       ino_t   i_number;       /* The identity of the inode. */
+       union {                 /* Associated filesystem. */
+               struct  fs *fs;         /* FFS */
+               struct  lfs *lfs;       /* LFS */
+       } inode_u;
+#define        i_fs    inode_u.fs
+#define        i_lfs   inode_u.lfs
+       struct  dquot *i_dquot[MAXQUOTAS];      /* Dquot structures. */
+       u_quad_t i_modrev;      /* Revision level for lease. */
+       struct  lockf *i_lockf; /* Head of byte-level lock list. */
+       pid_t   i_lockholder;   /* DEBUG: holder of inode lock. */
+       pid_t   i_lockwaiter;   /* DEBUG: latest blocked for inode lock. */
+       /*
+        * Side effects; used during directory lookup.
+        */
+       long    i_count;        /* Size of free slot in directory. */
+       doff_t  i_endoff;       /* End of useful stuff in directory. */
+       doff_t  i_diroff;       /* Offset in dir, where we found last entry. */
+       doff_t  i_offset;       /* Offset of free space in directory. */
+       ino_t   i_ino;          /* Inode number of found directory. */
+       u_long  i_reclen;       /* Size of found directory entry. */
+       long    i_spare[11];    /* Spares to round up to 128 bytes. */
+       /*
+        * The on-disk dinode itself.
+        */
+       struct  dinode i_din;   /* 128 bytes of the on-disk dinode. */
 };
 
 };
 
-#define        i_mode          i_din.di_mode
-#define        i_nlink         i_din.di_nlink
-#define        i_uid           i_din.di_uid
-#define        i_gid           i_din.di_gid
-#if BYTE_ORDER == LITTLE_ENDIAN || defined(tahoe) /* ugh! -- must be fixed */
-#define        i_size          i_din.di_qsize.val[0]
-#else /* BYTE_ORDER == BIG_ENDIAN */
-#define        i_size          i_din.di_qsize.val[1]
-#endif
+#define        i_atime         i_din.di_atime
+#define        i_blocks        i_din.di_blocks
+#define        i_ctime         i_din.di_ctime
 #define        i_db            i_din.di_db
 #define        i_db            i_din.di_db
+#define        i_flags         i_din.di_flags
+#define        i_gen           i_din.di_gen
+#define        i_gid           i_din.di_gid
 #define        i_ib            i_din.di_ib
 #define        i_ib            i_din.di_ib
-#define        i_atime         i_din.di_atime
+#define        i_mode          i_din.di_mode
 #define        i_mtime         i_din.di_mtime
 #define        i_mtime         i_din.di_mtime
-#define        i_ctime         i_din.di_ctime
-#define i_blocks       i_din.di_blocks
-#define        i_rdev          i_din.di_db[0]
-#define i_flags                i_din.di_flags
-#define i_gen          i_din.di_gen
-#define        i_forw          i_chain[0]
-#define        i_back          i_chain[1]
+#define        i_nlink         i_din.di_nlink
+#define        i_rdev          i_din.di_rdev
+#define        i_shortlink     i_din.di_shortlink
+#define        i_size          i_din.di_size
+#define        i_uid           i_din.di_uid
 
 
-/* flags */
-#define        ILOCKED         0x0001          /* inode is locked */
-#define        IWANT           0x0002          /* some process waiting on lock */
-#define        IRENAME         0x0004          /* inode is being renamed */
-#define        IUPD            0x0010          /* file has been modified */
-#define        IACC            0x0020          /* inode access time to be updated */
-#define        ICHG            0x0040          /* inode has been changed */
-#define        IMOD            0x0080          /* inode has been modified */
-#define        ISHLOCK         0x0100          /* file has shared lock */
-#define        IEXLOCK         0x0200          /* file has exclusive lock */
-#define        ILWAIT          0x0400          /* someone waiting on file lock */
+/* These flags are kept in i_flag. */
+#define        IN_ACCESS       0x0001          /* Access time update request. */
+#define        IN_CHANGE       0x0002          /* Inode change time update request. */
+#define        IN_EXLOCK       0x0004          /* File has exclusive lock. */
+#define        IN_LOCKED       0x0008          /* Inode lock. */
+#define        IN_LWAIT        0x0010          /* Process waiting on file lock. */
+#define        IN_MODIFIED     0x0020          /* Inode has been modified. */
+#define        IN_RENAME       0x0040          /* Inode is being renamed. */
+#define        IN_SHLOCK       0x0080          /* File has shared lock. */
+#define        IN_UPDATE       0x0100          /* Modification time update request. */
+#define        IN_WANTED       0x0200          /* Inode is wanted by a process. */
 
 #ifdef KERNEL
 /*
 
 #ifdef KERNEL
 /*
- * Convert between inode pointers and vnode pointers
+ * Structure used to pass around logical block paths generated by
+ * ufs_getlbns and used by truncate and bmap code.
  */
  */
+struct indir {
+       daddr_t in_lbn;                 /* Logical block number. */
+       int     in_off;                 /* Offset in buffer. */
+       int     in_exists;              /* Flag if the block exists. */
+};
+
+/* Convert between inode pointers and vnode pointers. */
 #define VTOI(vp)       ((struct inode *)(vp)->v_data)
 #define ITOV(ip)       ((ip)->i_vnode)
 
 #define VTOI(vp)       ((struct inode *)(vp)->v_data)
 #define ITOV(ip)       ((ip)->i_vnode)
 
-/*
- * Convert between vnode types and inode formats
- */
-extern enum vtype      iftovt_tab[];
-extern int             vttoif_tab[];
-#define IFTOVT(mode)   (iftovt_tab[((mode) & IFMT) >> 12])
-#define VTTOIF(indx)   (vttoif_tab[(int)(indx)])
-
-#define MAKEIMODE(indx, mode)  (int)(VTTOIF(indx) | (mode))
-
-u_long nextgennumber;          /* next generation number to assign */
-
-extern ino_t   dirpref();
-
-/*
- * Lock and unlock inodes.
- */
-#ifdef notdef
-#define        ILOCK(ip) { \
-       while ((ip)->i_flag & ILOCKED) { \
-               (ip)->i_flag |= IWANT; \
-               (void) sleep((caddr_t)(ip), PINOD); \
-       } \
-       (ip)->i_flag |= ILOCKED; \
+#define        ITIMES(ip, t1, t2) {                                            \
+       if ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) {       \
+               (ip)->i_flag |= IN_MODIFIED;                            \
+               if ((ip)->i_flag & IN_ACCESS)                           \
+                       (ip)->i_atime.ts_sec = (t1)->tv_sec;            \
+               if ((ip)->i_flag & IN_UPDATE) {                         \
+                       (ip)->i_mtime.ts_sec = (t2)->tv_sec;            \
+                       (ip)->i_modrev++;                               \
+               }                                                       \
+               if ((ip)->i_flag & IN_CHANGE)                           \
+                       (ip)->i_ctime.ts_sec = time.tv_sec;             \
+               (ip)->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE);   \
+       }                                                               \
 }
 
 }
 
-#define        IUNLOCK(ip) { \
-       (ip)->i_flag &= ~ILOCKED; \
-       if ((ip)->i_flag&IWANT) { \
-               (ip)->i_flag &= ~IWANT; \
-               wakeup((caddr_t)(ip)); \
-       } \
-}
-#else
-#define ILOCK(ip)      ilock(ip)
-#define IUNLOCK(ip)    iunlock(ip)
-#endif
-
-#define        IUPDAT(ip, t1, t2, waitfor) { \
-       if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
-               (void) iupdat(ip, t1, t2, waitfor); \
-}
-
-#define        ITIMES(ip, t1, t2) { \
-       if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
-               (ip)->i_flag |= IMOD; \
-               if ((ip)->i_flag&IACC) \
-                       (ip)->i_atime = (t1)->tv_sec; \
-               if ((ip)->i_flag&IUPD) \
-                       (ip)->i_mtime = (t2)->tv_sec; \
-               if ((ip)->i_flag&ICHG) \
-                       (ip)->i_ctime = time.tv_sec; \
-               (ip)->i_flag &= ~(IACC|IUPD|ICHG); \
-       } \
-}
-
-/*
- * This overlays the fid sturcture (see mount.h)
- */
+/* This overlays the fid structure (see mount.h). */
 struct ufid {
 struct ufid {
-       u_short ufid_len;       /* length of structure */
-       u_short ufid_pad;       /* force long alignment */
-       ino_t   ufid_ino;       /* file number (ino) */
-       long    ufid_gen;       /* generation number */
+       u_short ufid_len;       /* Length of structure. */
+       u_short ufid_pad;       /* Force long alignment. */
+       ino_t   ufid_ino;       /* File number (ino). */
+       long    ufid_gen;       /* Generation number. */
 };
 };
-#endif
+#endif /* KERNEL */