1 /* dinode.h 4.17 82/10/20 */ 2 3 /* 4 * The I node is the focus of all file activity in UNIX. 5 * There is a unique inode allocated for each active file, 6 * each current directory, each mounted-on file, text file, and the root. 7 * An inode is 'named' by its dev/inumber pair. (iget/iget.c) 8 * Data in icommon is read in from permanent inode on volume. 9 */ 10 11 #define NDADDR 8 /* direct addresses in inode */ 12 #define NIADDR 2 /* indirect addresses in inode */ 13 14 struct inode { 15 struct inode *i_chain[2]; /* must be first */ 16 u_short i_flag; 17 u_short i_count; /* reference count */ 18 dev_t i_dev; /* device where inode resides */ 19 u_short i_rdlockc; /* count of locked readers on inode */ 20 u_short i_wrlockc; /* count of locked writers on inode */ 21 ino_t i_number; /* i number, 1-to-1 with device address */ 22 struct fs *i_fs; /* file sys associated with this inode */ 23 struct dquot *i_dquot; /* quota structure controlling this file */ 24 union { 25 daddr_t if_lastr; /* last read (read-ahead) */ 26 struct socket *is_socket; 27 struct { 28 struct inode *if_freef; /* free list forward */ 29 struct inode **if_freeb; /* free list back */ 30 } i_fr; 31 } i_un; 32 struct icommon 33 { 34 u_short ic_mode; /* 0: mode and type of file */ 35 short ic_nlink; /* 2: number of links to file */ 36 short ic_uid; /* 4: owner's user id */ 37 short ic_gid; /* 6: owner's group id */ 38 off_t ic_size; /* 8: number of bytes in file */ 39 daddr_t ic_db[NDADDR]; /* 12: disk block addresses */ 40 daddr_t ic_ib[NIADDR]; /* 44: indirect blocks */ 41 time_t ic_atime; /* 52: time last accessed */ 42 time_t ic_mtime; /* 56: time last modified */ 43 time_t ic_ctime; /* 60: time created */ 44 } i_ic; 45 }; 46 47 struct dinode { 48 union { 49 struct icommon di_icom; 50 char di_size[64]; 51 } di_un; 52 }; 53 54 #define i_mode i_ic.ic_mode 55 #define i_nlink i_ic.ic_nlink 56 #define i_uid i_ic.ic_uid 57 #define i_gid i_ic.ic_gid 58 #define i_size i_ic.ic_size 59 #define i_db i_ic.ic_db 60 #define i_ib i_ic.ic_ib 61 #define i_atime i_ic.ic_atime 62 #define i_mtime i_ic.ic_mtime 63 #define i_ctime i_ic.ic_ctime 64 #define i_rdev i_ic.ic_db[0] 65 #define i_lastr i_un.if_lastr 66 #define i_socket is_socket 67 #define i_forw i_chain[0] 68 #define i_back i_chain[1] 69 #define i_freef i_un.i_fr.if_freef 70 #define i_freeb i_un.i_fr.if_freeb 71 72 #define di_ic di_un.di_icom 73 #define di_mode di_ic.ic_mode 74 #define di_nlink di_ic.ic_nlink 75 #define di_uid di_ic.ic_uid 76 #define di_gid di_ic.ic_gid 77 #define di_size di_ic.ic_size 78 #define di_db di_ic.ic_db 79 #define di_ib di_ic.ic_ib 80 #define di_atime di_ic.ic_atime 81 #define di_mtime di_ic.ic_mtime 82 #define di_ctime di_ic.ic_ctime 83 #define di_rdev di_ic.ic_db[0] 84 85 #ifdef KERNEL 86 struct inode *inode; /* the inode table itself */ 87 struct inode *inodeNINODE; /* the end of the inode table */ 88 int ninode; /* number of slots in the table */ 89 90 struct inode *rootdir; /* pointer to inode of root directory */ 91 92 struct inode *ialloc(); 93 struct inode *iget(); 94 struct inode *owner(); 95 struct inode *maknode(); 96 struct inode *namei(); 97 #endif 98 99 /* flags */ 100 #define ILOCKED 0x1 /* inode is locked */ 101 #define IUPD 0x2 /* file has been modified */ 102 #define IACC 0x4 /* inode access time to be updated */ 103 #define IMOUNT 0x8 /* inode is mounted on */ 104 #define IWANT 0x10 /* some process waiting on lock */ 105 #define ITEXT 0x20 /* inode is pure text prototype */ 106 #define ICHG 0x40 /* inode has been changed */ 107 #define IRDLOCK 0x80 /* file is read locked */ 108 #define IWRLOCK 0x100 /* file is write locked */ 109 #define ILWAIT 0x200 /* someone waiting on file lock */ 110 111 /* modes */ 112 #define IFMT 0170000 /* type of file */ 113 #define IFCHR 0020000 /* character special */ 114 #define IFDIR 0040000 /* directory */ 115 #define IFBLK 0060000 /* block special */ 116 #define IFREG 0100000 /* regular */ 117 #define IFLNK 0120000 /* symbolic link */ 118 #define IFPORTAL 0140000 /* portal */ 119 #define ISUID 04000 /* set user id on execution */ 120 #define ISGID 02000 /* set group id on execution */ 121 #define ISVTX 01000 /* save swapped text even after use */ 122 #define IREAD 0400 /* read, write, execute permissions */ 123 #define IWRITE 0200 124 #define IEXEC 0100 125 126 #define ILOCK(ip) { \ 127 while ((ip)->i_flag & ILOCKED) { \ 128 (ip)->i_flag |= IWANT; \ 129 sleep((caddr_t)(ip), PINOD); \ 130 } \ 131 (ip)->i_flag |= ILOCKED; \ 132 } 133 134 #define IUNLOCK(ip) { \ 135 (ip)->i_flag &= ~ILOCKED; \ 136 if ((ip)->i_flag&IWANT) { \ 137 (ip)->i_flag &= ~IWANT; \ 138 wakeup((caddr_t)(ip)); \ 139 } \ 140 } 141 142 #define IUPDAT(ip, t1, t2, waitfor) { \ 143 if (ip->i_flag&(IUPD|IACC|ICHG)) \ 144 iupdat(ip, t1, t2, waitfor); \ 145 } 146