move IFMT => VTYPE and VTYPE => IFMT to vnode since stat requires it
[unix-history] / usr / src / sys / ufs / ffs / inode.h
index 1d8ec92..ae06ac2 100644 (file)
-/*     inode.h 6.2     84/02/15        */
-
 /*
 /*
- * 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 icommon 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.22 (Berkeley) %G%
  */
 
  */
 
-#define        NDADDR  12              /* direct addresses in inode */
-#define        NIADDR  3               /* indirect addresses in inode */
+#include <ufs/ufs/dinode.h>
 
 
+/*
+ * 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];      /* must be first */
-       u_short i_flag;
-       u_short i_count;        /* reference count */
+       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 */
        dev_t   i_dev;          /* device where inode resides */
-       u_short i_shlockc;      /* count of shared locks on inode */
-       u_short i_exlockc;      /* count of exclusive locks on inode */
-       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; /* quota structure controlling this file */
-       union {
-               daddr_t if_lastr;       /* last read (read-ahead) */
-               struct  socket *is_socket;
-               struct  {
-                       struct inode  *if_freef;        /* free list forward */
-                       struct inode **if_freeb;        /* free list back */
-               } i_fr;
-       } i_un;
-       struct  icommon
-       {
-               u_short ic_mode;        /*  0: mode and type of file */
-               short   ic_nlink;       /*  2: number of links to file */
-               short   ic_uid;         /*  4: owner's user id */
-               short   ic_gid;         /*  6: owner's group id */
-               quad    ic_size;        /*  8: number of bytes in file */
-               time_t  ic_atime;       /* 16: time last accessed */
-               long    ic_atspare;
-               time_t  ic_mtime;       /* 24: time last modified */
-               long    ic_mtspare;
-               time_t  ic_ctime;       /* 32: last time inode changed */
-               long    ic_ctspare;
-               daddr_t ic_db[NDADDR];  /* 40: disk block addresses */
-               daddr_t ic_ib[NIADDR];  /* 88: indirect blocks */
-               long    ic_flags;       /* 100: status, currently unused */
-               long    ic_blocks;      /* 104: blocks actually held */
-               long    ic_spare[5];    /* 108: reserved, currently unused */
-       } i_ic;
+       short   i_pad;
+       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 */
+       struct  lockf *i_lockf; /* head of byte-level lock list */
+       u_quad_t i_modrev;      /* revision level for lease */
+       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.
+        */
+       off_t   i_endoff;       /* end of useful stuff in directory */
+       long    i_diroff;       /* offset in dir, where we found last entry */
+       long    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 */
 };
 
 };
 
-struct dinode {
-       union {
-               struct  icommon di_icom;
-               char    di_size[128];
-       } di_un;
-};
-
-#define        i_mode          i_ic.ic_mode
-#define        i_nlink         i_ic.ic_nlink
-#define        i_uid           i_ic.ic_uid
-#define        i_gid           i_ic.ic_gid
-/* ugh! -- must be fixed */
-#ifdef vax
-#define        i_size          i_ic.ic_size.val[0]
+#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
+#ifdef _NOQUAD
+#define i_size i_din.di_qsize.val[_QUAD_LOWWORD]
+#else
+#define i_size i_din.di_qsize
+#endif
+#if defined(tahoe) /* ugh! -- must be fixed */
+#undef i_size
+#define        i_size          i_din.di_qsize.val[0]
 #endif
 #endif
-#define        i_db            i_ic.ic_db
-#define        i_ib            i_ic.ic_ib
-#define        i_atime         i_ic.ic_atime
-#define        i_mtime         i_ic.ic_mtime
-#define        i_ctime         i_ic.ic_ctime
-#define i_blocks       i_ic.ic_blocks
-#define        i_rdev          i_ic.ic_db[0]
-#define        i_lastr         i_un.if_lastr
-#define        i_socket        i_un.is_socket
+#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_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_forw          i_chain[0]
 #define        i_back          i_chain[1]
-#define        i_freef         i_un.i_fr.if_freef
-#define        i_freeb         i_un.i_fr.if_freeb
 
 
-#define di_ic          di_un.di_icom
-#define        di_mode         di_ic.ic_mode
-#define        di_nlink        di_ic.ic_nlink
-#define        di_uid          di_ic.ic_uid
-#define        di_gid          di_ic.ic_gid
-#ifdef vax
-#define        di_size         di_ic.ic_size.val[0]
-#endif
-#define        di_db           di_ic.ic_db
-#define        di_ib           di_ic.ic_ib
-#define        di_atime        di_ic.ic_atime
-#define        di_mtime        di_ic.ic_mtime
-#define        di_ctime        di_ic.ic_ctime
-#define        di_rdev         di_ic.ic_db[0]
-#define        di_blocks       di_ic.ic_blocks
+/* 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
-struct inode *inode;           /* the inode table itself */
-struct inode *inodeNINODE;     /* the end of the inode table */
-int    ninode;                 /* number of slots in the table */
-
-struct inode *rootdir;                 /* pointer to inode of root directory */
+/* Convert between inode pointers and vnode pointers. */
+#define VTOI(vp)       ((struct inode *)(vp)->v_data)
+#define ITOV(ip)       ((ip)->i_vnode)
 
 
-struct inode *ialloc();
-struct inode *iget();
+/* Lock and unlock inodes. */
 #ifdef notdef
 #ifdef notdef
-struct inode *ifind();
-#endif
-struct inode *owner();
-struct inode *maknode();
-struct inode *namei();
-
-ino_t  dirpref();
-#endif
-
-/* flags */
-#define        ILOCKED         0x1             /* inode is locked */
-#define        IUPD            0x2             /* file has been modified */
-#define        IACC            0x4             /* inode access time to be updated */
-#define        IMOUNT          0x8             /* inode is mounted on */
-#define        IWANT           0x10            /* some process waiting on lock */
-#define        ITEXT           0x20            /* inode is pure text prototype */
-#define        ICHG            0x40            /* inode has been changed */
-#define        ISHLOCK         0x80            /* file has shared lock */
-#define        IEXLOCK         0x100           /* file has exclusive lock */
-#define        ILWAIT          0x200           /* someone waiting on file lock */
-#define        IMOD            0x400           /* inode has been modified */
-
-/* modes */
-#define        IFMT            0170000         /* type of file */
-#define        IFCHR           0020000         /* character special */
-#define        IFDIR           0040000         /* directory */
-#define        IFBLK           0060000         /* block special */
-#define        IFREG           0100000         /* regular */
-#define        IFLNK           0120000         /* symbolic link */
-#define        IFSOCK          0140000         /* socket */
-
-#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
-
 #define        ILOCK(ip) { \
        while ((ip)->i_flag & ILOCKED) { \
                (ip)->i_flag |= IWANT; \
 #define        ILOCK(ip) { \
        while ((ip)->i_flag & ILOCKED) { \
                (ip)->i_flag |= IWANT; \
-               sleep((caddr_t)(ip), PINOD); \
+               (void) sleep((caddr_t)(ip), PINOD); \
        } \
        (ip)->i_flag |= ILOCKED; \
 }
        } \
        (ip)->i_flag |= ILOCKED; \
 }
@@ -158,22 +114,31 @@ ino_t     dirpref();
                wakeup((caddr_t)(ip)); \
        } \
 }
                wakeup((caddr_t)(ip)); \
        } \
 }
-
-#define        IUPDAT(ip, t1, t2, waitfor) { \
-       if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
-               iupdat(ip, t1, t2, waitfor); \
-}
+#else
+#define ILOCK(ip)      ufs_ilock(ip)
+#define IUNLOCK(ip)    ufs_iunlock(ip)
+#endif
 
 #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; \
 
 #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) \
+               if ((ip)->i_flag&IUPD) \
                        (ip)->i_mtime = (t2)->tv_sec; \
                        (ip)->i_mtime = (t2)->tv_sec; \
+                       INCRQUAD((ip)->i_modrev); \
+               } \
                if ((ip)->i_flag&ICHG) \
                        (ip)->i_ctime = time.tv_sec; \
                (ip)->i_flag &= ~(IACC|IUPD|ICHG); \
        } \
 }
 
                if ((ip)->i_flag&ICHG) \
                        (ip)->i_ctime = time.tv_sec; \
                (ip)->i_flag &= ~(IACC|IUPD|ICHG); \
        } \
 }
 
+/* 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 */