add USL's copyright notice
[unix-history] / usr / src / sys / ufs / ufs / inode.h
index c5a1c2f..039fd8c 100644 (file)
-/*     inode.h 4.1     %G%     */
-
 /*
 /*
- * 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, 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%
+ *
+ *     @(#)inode.h     8.4 (Berkeley) %G%
  */
 
  */
 
-#define        NADDR   13
+#include <ufs/ufs/dinode.h>
 
 
-#define        NINDEX          15
-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 */
-       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) */
+/*
+ * 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;         /* 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. */
 };
 
 };
 
-#ifdef KERNEL
-extern struct inode inode[];   /* The inode table itself */
+#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_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_mode          i_din.di_mode
+#define        i_mtime         i_din.di_mtime
+#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
 
 
-struct inode *rootdir;         /* pointer to inode of root directory */
-struct inode *mpxip;           /* mpx virtual inode */
+/* 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. */
 
 
-struct inode *ialloc();
-struct inode *ifind();
-struct inode *iget();
-struct inode *owner();
-struct inode *maknode();
-struct inode *namei();
-#endif
+#ifdef KERNEL
+/*
+ * 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)
 
 
-/* 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 & (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);   \
+       }                                                               \
+}
 
 
-/* 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 */