1 /* dinode.h 6.5 84/07/26 */ 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 12 /* direct addresses in inode */ 12 #define NIADDR 3 /* 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_shlockc; /* count of shared locks on inode */ 20 u_short i_exlockc; /* count of exclusive locks on inode */ 21 ino_t i_number; /* i number, 1-to-1 with device address */ 22 long i_id; /* unique identifier */ 23 struct fs *i_fs; /* file sys associated with this inode */ 24 struct dquot *i_dquot; /* quota structure controlling this file */ 25 union { 26 daddr_t if_lastr; /* last read (read-ahead) */ 27 struct socket *is_socket; 28 struct { 29 struct inode *if_freef; /* free list forward */ 30 struct inode **if_freeb; /* free list back */ 31 } i_fr; 32 } i_un; 33 struct icommon 34 { 35 u_short ic_mode; /* 0: mode and type of file */ 36 short ic_nlink; /* 2: number of links to file */ 37 short ic_uid; /* 4: owner's user id */ 38 short ic_gid; /* 6: owner's group id */ 39 quad ic_size; /* 8: number of bytes in file */ 40 time_t ic_atime; /* 16: time last accessed */ 41 long ic_atspare; 42 time_t ic_mtime; /* 24: time last modified */ 43 long ic_mtspare; 44 time_t ic_ctime; /* 32: last time inode changed */ 45 long ic_ctspare; 46 daddr_t ic_db[NDADDR]; /* 40: disk block addresses */ 47 daddr_t ic_ib[NIADDR]; /* 88: indirect blocks */ 48 long ic_flags; /* 100: status, currently unused */ 49 long ic_blocks; /* 104: blocks actually held */ 50 long ic_spare[5]; /* 108: reserved, currently unused */ 51 } i_ic; 52 }; 53 54 struct dinode { 55 union { 56 struct icommon di_icom; 57 char di_size[128]; 58 } di_un; 59 }; 60 61 #define i_mode i_ic.ic_mode 62 #define i_nlink i_ic.ic_nlink 63 #define i_uid i_ic.ic_uid 64 #define i_gid i_ic.ic_gid 65 /* ugh! -- must be fixed */ 66 #ifdef vax 67 #define i_size i_ic.ic_size.val[0] 68 #endif 69 #define i_db i_ic.ic_db 70 #define i_ib i_ic.ic_ib 71 #define i_atime i_ic.ic_atime 72 #define i_mtime i_ic.ic_mtime 73 #define i_ctime i_ic.ic_ctime 74 #define i_blocks i_ic.ic_blocks 75 #define i_rdev i_ic.ic_db[0] 76 #define i_lastr i_un.if_lastr 77 #define i_socket i_un.is_socket 78 #define i_forw i_chain[0] 79 #define i_back i_chain[1] 80 #define i_freef i_un.i_fr.if_freef 81 #define i_freeb i_un.i_fr.if_freeb 82 83 #define di_ic di_un.di_icom 84 #define di_mode di_ic.ic_mode 85 #define di_nlink di_ic.ic_nlink 86 #define di_uid di_ic.ic_uid 87 #define di_gid di_ic.ic_gid 88 #ifdef vax 89 #define di_size di_ic.ic_size.val[0] 90 #endif 91 #define di_db di_ic.ic_db 92 #define di_ib di_ic.ic_ib 93 #define di_atime di_ic.ic_atime 94 #define di_mtime di_ic.ic_mtime 95 #define di_ctime di_ic.ic_ctime 96 #define di_rdev di_ic.ic_db[0] 97 #define di_blocks di_ic.ic_blocks 98 99 #ifdef KERNEL 100 /* 101 * Invalidate an inode. Used by the namei cache to detect stale 102 * information. At an absurd rate of 100 calls/second, the inode 103 * table invalidation should only occur once every 16 months. 104 */ 105 #define cacheinval(ip) \ 106 { \ 107 struct inode *xp; \ 108 (ip)->i_id = ++nextinodeid; \ 109 if (nextinodeid == 0) \ 110 for (nextinodeid = 0, xp = inode; xp < inodeNINODE; xp++) \ 111 xp->i_id = 0; \ 112 } 113 114 struct inode *inode; /* the inode table itself */ 115 struct inode *inodeNINODE; /* the end of the inode table */ 116 int ninode; /* number of slots in the table */ 117 long nextinodeid; /* unique id generator */ 118 119 struct inode *rootdir; /* pointer to inode of root directory */ 120 121 struct inode *ialloc(); 122 struct inode *iget(); 123 #ifdef notdef 124 struct inode *ifind(); 125 #endif 126 struct inode *owner(); 127 struct inode *maknode(); 128 struct inode *namei(); 129 130 ino_t dirpref(); 131 #endif 132 133 /* flags */ 134 #define ILOCKED 0x1 /* inode is locked */ 135 #define IUPD 0x2 /* file has been modified */ 136 #define IACC 0x4 /* inode access time to be updated */ 137 #define IMOUNT 0x8 /* inode is mounted on */ 138 #define IWANT 0x10 /* some process waiting on lock */ 139 #define ITEXT 0x20 /* inode is pure text prototype */ 140 #define ICHG 0x40 /* inode has been changed */ 141 #define ISHLOCK 0x80 /* file has shared lock */ 142 #define IEXLOCK 0x100 /* file has exclusive lock */ 143 #define ILWAIT 0x200 /* someone waiting on file lock */ 144 #define IMOD 0x400 /* inode has been modified */ 145 #define IRENAME 0x800 /* inode is being renamed */ 146 147 /* modes */ 148 #define IFMT 0170000 /* type of file */ 149 #define IFCHR 0020000 /* character special */ 150 #define IFDIR 0040000 /* directory */ 151 #define IFBLK 0060000 /* block special */ 152 #define IFREG 0100000 /* regular */ 153 #define IFLNK 0120000 /* symbolic link */ 154 #define IFSOCK 0140000 /* socket */ 155 156 #define ISUID 04000 /* set user id on execution */ 157 #define ISGID 02000 /* set group id on execution */ 158 #define ISVTX 01000 /* save swapped text even after use */ 159 #define IREAD 0400 /* read, write, execute permissions */ 160 #define IWRITE 0200 161 #define IEXEC 0100 162 163 #define ILOCK(ip) { \ 164 while ((ip)->i_flag & ILOCKED) { \ 165 (ip)->i_flag |= IWANT; \ 166 sleep((caddr_t)(ip), PINOD); \ 167 } \ 168 (ip)->i_flag |= ILOCKED; \ 169 } 170 171 #define IUNLOCK(ip) { \ 172 (ip)->i_flag &= ~ILOCKED; \ 173 if ((ip)->i_flag&IWANT) { \ 174 (ip)->i_flag &= ~IWANT; \ 175 wakeup((caddr_t)(ip)); \ 176 } \ 177 } 178 179 #define IUPDAT(ip, t1, t2, waitfor) { \ 180 if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \ 181 iupdat(ip, t1, t2, waitfor); \ 182 } 183 184 #define ITIMES(ip, t1, t2) { \ 185 if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \ 186 (ip)->i_flag |= IMOD; \ 187 if ((ip)->i_flag&IACC) \ 188 (ip)->i_atime = (t1)->tv_sec; \ 189 if ((ip)->i_flag&IUPD) \ 190 (ip)->i_mtime = (t2)->tv_sec; \ 191 if ((ip)->i_flag&ICHG) \ 192 (ip)->i_ctime = time.tv_sec; \ 193 (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ 194 } \ 195 } 196