BSD 4_4 release
[unix-history] / usr / src / sys / ufs / ufs / dinode.h
index de9b853..47a1ffc 100644 (file)
-/*     dinode.h        4.20    82/11/13        */
+/*
+ * Copyright (c) 1982, 1989, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)dinode.h    8.1 (Berkeley) 6/11/93
+ */
+
+/*
+ * The root inode is the root of the file system.  Inode 0 can't be used for
+ * normal purposes and historically bad blocks were linked to inode 1, thus
+ * the root inode is 2.  (Inode 1 is no longer used for this purpose, however
+ * numerous dump tapes make this assumption, so we are stuck with it).
+ */
+#define        ROOTINO ((ino_t)2)
 
 /*
 
 /*
- * 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.
+ * A dinode contains all the meta-data associated with a UFS file.
+ * This structure defines the on-disk format of a dinode.
  */
 
 #define        NDADDR  12              /* direct addresses in inode */
 #define        NIADDR  3               /* indirect addresses in inode */
 
  */
 
 #define        NDADDR  12              /* direct addresses in inode */
 #define        NIADDR  3               /* indirect addresses in inode */
 
-struct inode {
-       struct  inode *i_chain[2];      /* must be first */
-       u_short i_flag;
-       u_short i_count;        /* reference count */
-       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: time created */
-               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_spare[6];    /* 104: reserved, currently unused */
-       } i_ic;
-};
-
 struct dinode {
 struct dinode {
+       u_short         di_mode;        /*   0: mode and type of file */
+       short           di_nlink;       /*   2: number of links to file */
        union {
        union {
-               struct  icommon di_icom;
-               char    di_size[128];
-       } di_un;
+               u_short oldids[2];      /*   4: ffs: old user and group ids */
+               ino_t   inumber;        /*   4: lfs: inode number */
+       } di_u;
+       u_quad_t        di_size;        /*   8: number of bytes in file */
+       struct timespec di_atime;       /*  16: time last accessed */
+       struct timespec di_mtime;       /*  24: time last modified */
+       struct timespec di_ctime;       /*  32: last time inode changed */
+       daddr_t         di_db[NDADDR];  /*  40: disk block addresses */
+       daddr_t         di_ib[NIADDR];  /*  88: indirect blocks */
+       u_long          di_flags;       /* 100: status flags */
+       long            di_blocks;      /* 104: blocks actually held */
+       long            di_gen;         /* 108: generation number */
+       u_long          di_uid;         /* 112: owner's user id */
+       u_long          di_gid;         /* 116: owner's group id */
+       long            di_spare[2];    /* 120: reserved, currently unused */
 };
 
 };
 
-#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
-#define        i_size          i_ic.ic_size.val[0]
-#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_rdev          i_ic.ic_db[0]
-#define        i_lastr         i_un.if_lastr
-#define        i_socket        i_un.is_socket
-#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
-#define        di_size         di_ic.ic_size.val[0]
-#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]
-
-#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 */
-
-struct inode *ialloc();
-struct inode *iget();
-#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 */
-
-/* modes */
-#define        IFMT            0170000         /* type of file */
-#define        IFCHR           0020000         /* character special */
+/*
+ * The di_db fields may be overlaid with other information for
+ * file types that do not have associated disk storage. Block
+ * and character devices overlay the first data block with their
+ * dev_t value. Short symbolic links place their path in the
+ * di_db area.
+ */
+#define        di_ouid         di_u.oldids[0]
+#define        di_ogid         di_u.oldids[1]
+#define        di_inumber      di_u.inumber
+#define        di_rdev         di_db[0]
+#define di_shortlink   di_db
+#define        MAXSYMLINKLEN   ((NDADDR + NIADDR) * sizeof(daddr_t))
+
+/* file modes */
+#define        IFMT            0170000         /* mask of file type */
+#define        IFIFO           0010000         /* named pipe (fifo) */
+#define        IFCHR           0020000         /* character special device */
 #define        IFDIR           0040000         /* directory */
 #define        IFDIR           0040000         /* directory */
-#define        IFBLK           0060000         /* block special */
-#define        IFREG           0100000         /* regular */
+#define        IFBLK           0060000         /* block special device */
+#define        IFREG           0100000         /* regular file */
 #define        IFLNK           0120000         /* symbolic link */
 #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; \
-               sleep((caddr_t)(ip), PINOD); \
-       } \
-       (ip)->i_flag |= ILOCKED; \
-}
-
-#define        IUNLOCK(ip) { \
-       (ip)->i_flag &= ~ILOCKED; \
-       if ((ip)->i_flag&IWANT) { \
-               (ip)->i_flag &= ~IWANT; \
-               wakeup((caddr_t)(ip)); \
-       } \
-}
-
-#define        IUPDAT(ip, t1, t2, waitfor) { \
-       if (ip->i_flag&(IUPD|IACC|ICHG)) \
-               iupdat(ip, t1, t2, waitfor); \
-}
+#define        IFSOCK          0140000         /* UNIX domain socket */
+
+#define        ISUID           04000           /* set user identifier when exec'ing */
+#define        ISGID           02000           /* set group identifier when exec'ing */
+#define        ISVTX           01000           /* save execution information on exit */
+#define        IREAD           0400            /* read permission */
+#define        IWRITE          0200            /* write permission */
+#define        IEXEC           0100            /* execute permission */