delete VERBOSE #ifdef's
[unix-history] / usr / src / sys / ufs / ffs / inode.h
index 84e6b2e..6b56de2 100644 (file)
-/*     inode.h 4.4     81/02/27        */
-
 /*
 /*
- * 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, from mode on, is read in
- * from permanent inode on volume.
+ * Copyright (c) 1982, 1989 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)inode.h     7.29 (Berkeley) %G%
  */
 
  */
 
-#define        NADDR   13
+#include <ufs/ufs/dinode.h>
 
 
-#define        NINDEX          6
-struct group
-{
-       short   g_state;
-       char    g_index;
-       char    g_rot;
-       struct  group   *g_group;
-       struct  inode   *g_inode;
-       struct  file    *g_file;
-       short   g_rotmask;
-       short   g_datq;
-       struct  chan *g_chans[NINDEX];
-};
-struct inode
-{
-       char    i_flag;
-       char    i_count;        /* reference count */
+/*
+ * 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 *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;         /* see below */
        dev_t   i_dev;          /* device where inode resides */
        dev_t   i_dev;          /* device where inode resides */
-       ino_t   i_number;       /* i number, 1-to-1 with device address */
-       unsigned short i_mode;
-       short   i_nlink;        /* directory entries */
-       short   i_uid;          /* owner */
-       short   i_gid;          /* group of owner */
-       off_t   i_size;         /* size of file */
-       union {
-               struct {
-                       daddr_t I_addr[NADDR];  /* if normal file/directory */
-                       daddr_t I_lastr;        /* last read (for read-ahead) */
-               } i_f;
-#define        i_addr  i_f.I_addr
-#define        i_lastr i_f.I_lastr
-               struct {
-                       daddr_t I_rdev;         /* i_addr[0] */
-                       struct  group I_group;  /* multiplexor group file */
-               } i_d;
-#define        i_rdev  i_d.I_rdev
-#define        i_group i_d.I_group
-       } i_un;
-       short   i_vfdcnt;       /* number of fd's vreading this inode */
-       short   i_hlink;        /* link in hash chain (iget/iput/ifind) */
+       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]; /* pointer to 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.
+        */
+       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 */
+       long    i_count;        /* size of free slot in directory */
+       ino_t   i_ino;          /* inode number of found directory */
+       u_long  i_reclen;       /* size of found directory entry */
+       /*
+        * the on-disk dinode itself.
+        */
+       struct  dinode i_din;   /* the on-disk dinode */
+       long    i_spare[12];    /* spares to round up to 256 bytes */
 };
 
 };
 
+#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
+#define i_size         i_din.di_size
+#define        i_db            i_din.di_db
+#define        i_ib            i_din.di_ib
+#define        i_atime         i_din.di_atime
+#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_rdev
+#define        i_shortlink     i_din.di_shortlink
+#define i_flags                i_din.di_flags
+#define i_gen          i_din.di_gen
+
+/* 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 */
+
 #ifdef KERNEL
 #ifdef KERNEL
-extern struct inode *inode, *inodeNINODE;/* The inode table itself */
-extern int ninode;
+/* Convert between inode pointers and vnode pointers. */
+#define VTOI(vp)       ((struct inode *)(vp)->v_data)
+#define ITOV(ip)       ((ip)->i_vnode)
 
 
-struct inode *rootdir;         /* pointer to inode of root directory */
-struct inode *mpxip;           /* mpx virtual inode */
+/* 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; \
+}
 
 
-struct inode *ialloc();
-struct inode *ifind();
-struct inode *iget();
-struct inode *owner();
-struct inode *maknode();
-struct inode *namei();
+#define        IUNLOCK(ip) { \
+       (ip)->i_flag &= ~ILOCKED; \
+       if ((ip)->i_flag&IWANT) { \
+               (ip)->i_flag &= ~IWANT; \
+               wakeup((caddr_t)(ip)); \
+       } \
+}
+#else
+#define ILOCK(ip)      ufs_ilock(ip)
+#define IUNLOCK(ip)    ufs_iunlock(ip)
 #endif
 
 #endif
 
-/* flags */
-#define        ILOCK   01              /* inode is locked */
-#define        IUPD    02              /* file has been modified */
-#define        IACC    04              /* inode access time to be updated */
-#define        IMOUNT  010             /* inode is mounted on */
-#define        IWANT   020             /* some process waiting on lock */
-#define        ITEXT   040             /* inode is pure text prototype */
-#define        ICHG    0100            /* inode has been changed */
-#define        IPIPE   0200            /* inode is a pipe */
+#define        ITIMES(ip, t1, t2) { \
+       if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
+               (ip)->i_flag |= IMOD; \
+               if ((ip)->i_flag&IACC) \
+                       (ip)->i_atime.ts_sec = (t1)->tv_sec; \
+               if ((ip)->i_flag&IUPD) { \
+                       (ip)->i_mtime.ts_sec = (t2)->tv_sec; \
+                       (ip)->i_modrev++; \
+               } \
+               if ((ip)->i_flag&ICHG) \
+                       (ip)->i_ctime.ts_sec = time.tv_sec; \
+               (ip)->i_flag &= ~(IACC|IUPD|ICHG); \
+       } \
+}
 
 
-/* modes */
-#define        IFMT    0170000         /* type of file */
-#define                IFDIR   0040000 /* directory */
-#define                IFCHR   0020000 /* character special */
-#define                IFBLK   0060000 /* block special */
-#define                IFREG   0100000 /* regular */
-#define                IFMPC   0030000 /* multiplexed char special */
-#define                IFMPB   0070000 /* multiplexed block special */
-#define        ISUID   04000           /* set user id on execution */
-#define        ISGID   02000           /* set group id on execution */
-#define        ISVTX   01000           /* save swapped text even after use */
-#define        IREAD   0400            /* read, write, execute permissions */
-#define        IWRITE  0200
-#define        IEXEC   0100
+/* This overlays the fid structure (see mount.h). */
+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 */
+};
+#endif /* KERNEL */