| 1 | /* dinode.h 4.20 82/11/13 */ |
| 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 | 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 | quad ic_size; /* 8: number of bytes in file */ |
| 39 | time_t ic_atime; /* 16: time last accessed */ |
| 40 | long ic_atspare; |
| 41 | time_t ic_mtime; /* 24: time last modified */ |
| 42 | long ic_mtspare; |
| 43 | time_t ic_ctime; /* 32: time created */ |
| 44 | long ic_ctspare; |
| 45 | daddr_t ic_db[NDADDR]; /* 40: disk block addresses */ |
| 46 | daddr_t ic_ib[NIADDR]; /* 88: indirect blocks */ |
| 47 | long ic_flags; /* 100: status, currently unused */ |
| 48 | long ic_spare[6]; /* 104: reserved, currently unused */ |
| 49 | } i_ic; |
| 50 | }; |
| 51 | |
| 52 | struct dinode { |
| 53 | union { |
| 54 | struct icommon di_icom; |
| 55 | char di_size[128]; |
| 56 | } di_un; |
| 57 | }; |
| 58 | |
| 59 | #define i_mode i_ic.ic_mode |
| 60 | #define i_nlink i_ic.ic_nlink |
| 61 | #define i_uid i_ic.ic_uid |
| 62 | #define i_gid i_ic.ic_gid |
| 63 | #define i_size i_ic.ic_size.val[0] |
| 64 | #define i_db i_ic.ic_db |
| 65 | #define i_ib i_ic.ic_ib |
| 66 | #define i_atime i_ic.ic_atime |
| 67 | #define i_mtime i_ic.ic_mtime |
| 68 | #define i_ctime i_ic.ic_ctime |
| 69 | #define i_rdev i_ic.ic_db[0] |
| 70 | #define i_lastr i_un.if_lastr |
| 71 | #define i_socket i_un.is_socket |
| 72 | #define i_forw i_chain[0] |
| 73 | #define i_back i_chain[1] |
| 74 | #define i_freef i_un.i_fr.if_freef |
| 75 | #define i_freeb i_un.i_fr.if_freeb |
| 76 | |
| 77 | #define di_ic di_un.di_icom |
| 78 | #define di_mode di_ic.ic_mode |
| 79 | #define di_nlink di_ic.ic_nlink |
| 80 | #define di_uid di_ic.ic_uid |
| 81 | #define di_gid di_ic.ic_gid |
| 82 | #define di_size di_ic.ic_size.val[0] |
| 83 | #define di_db di_ic.ic_db |
| 84 | #define di_ib di_ic.ic_ib |
| 85 | #define di_atime di_ic.ic_atime |
| 86 | #define di_mtime di_ic.ic_mtime |
| 87 | #define di_ctime di_ic.ic_ctime |
| 88 | #define di_rdev di_ic.ic_db[0] |
| 89 | |
| 90 | #ifdef KERNEL |
| 91 | struct inode *inode; /* the inode table itself */ |
| 92 | struct inode *inodeNINODE; /* the end of the inode table */ |
| 93 | int ninode; /* number of slots in the table */ |
| 94 | |
| 95 | struct inode *rootdir; /* pointer to inode of root directory */ |
| 96 | |
| 97 | struct inode *ialloc(); |
| 98 | struct inode *iget(); |
| 99 | #ifdef notdef |
| 100 | struct inode *ifind(); |
| 101 | #endif |
| 102 | struct inode *owner(); |
| 103 | struct inode *maknode(); |
| 104 | struct inode *namei(); |
| 105 | |
| 106 | ino_t dirpref(); |
| 107 | #endif |
| 108 | |
| 109 | /* flags */ |
| 110 | #define ILOCKED 0x1 /* inode is locked */ |
| 111 | #define IUPD 0x2 /* file has been modified */ |
| 112 | #define IACC 0x4 /* inode access time to be updated */ |
| 113 | #define IMOUNT 0x8 /* inode is mounted on */ |
| 114 | #define IWANT 0x10 /* some process waiting on lock */ |
| 115 | #define ITEXT 0x20 /* inode is pure text prototype */ |
| 116 | #define ICHG 0x40 /* inode has been changed */ |
| 117 | #define ISHLOCK 0x80 /* file has shared lock */ |
| 118 | #define IEXLOCK 0x100 /* file has exclusive lock */ |
| 119 | #define ILWAIT 0x200 /* someone waiting on file lock */ |
| 120 | |
| 121 | /* modes */ |
| 122 | #define IFMT 0170000 /* type of file */ |
| 123 | #define IFCHR 0020000 /* character special */ |
| 124 | #define IFDIR 0040000 /* directory */ |
| 125 | #define IFBLK 0060000 /* block special */ |
| 126 | #define IFREG 0100000 /* regular */ |
| 127 | #define IFLNK 0120000 /* symbolic link */ |
| 128 | #define IFSOCK 0140000 /* socket */ |
| 129 | |
| 130 | #define ISUID 04000 /* set user id on execution */ |
| 131 | #define ISGID 02000 /* set group id on execution */ |
| 132 | #define ISVTX 01000 /* save swapped text even after use */ |
| 133 | #define IREAD 0400 /* read, write, execute permissions */ |
| 134 | #define IWRITE 0200 |
| 135 | #define IEXEC 0100 |
| 136 | |
| 137 | #define ILOCK(ip) { \ |
| 138 | while ((ip)->i_flag & ILOCKED) { \ |
| 139 | (ip)->i_flag |= IWANT; \ |
| 140 | sleep((caddr_t)(ip), PINOD); \ |
| 141 | } \ |
| 142 | (ip)->i_flag |= ILOCKED; \ |
| 143 | } |
| 144 | |
| 145 | #define IUNLOCK(ip) { \ |
| 146 | (ip)->i_flag &= ~ILOCKED; \ |
| 147 | if ((ip)->i_flag&IWANT) { \ |
| 148 | (ip)->i_flag &= ~IWANT; \ |
| 149 | wakeup((caddr_t)(ip)); \ |
| 150 | } \ |
| 151 | } |
| 152 | |
| 153 | #define IUPDAT(ip, t1, t2, waitfor) { \ |
| 154 | if (ip->i_flag&(IUPD|IACC|ICHG)) \ |
| 155 | iupdat(ip, t1, t2, waitfor); \ |
| 156 | } |