Commit | Line | Data |
---|---|---|
232d0cb7 | 1 | /* inode.h 6.2 84/02/15 */ |
d0064d3a BJ |
2 | |
3 | /* | |
a59abf09 BJ |
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) | |
ad30fb67 | 8 | * Data in icommon is read in from permanent inode on volume. |
d0064d3a | 9 | */ |
ad30fb67 | 10 | |
af0b24db SL |
11 | #define NDADDR 12 /* direct addresses in inode */ |
12 | #define NIADDR 3 /* indirect addresses in inode */ | |
d0064d3a | 13 | |
a59abf09 | 14 | struct inode { |
69bd12a8 | 15 | struct inode *i_chain[2]; /* must be first */ |
b0954044 | 16 | u_short i_flag; |
3e27ef55 | 17 | u_short i_count; /* reference count */ |
d0064d3a | 18 | dev_t i_dev; /* device where inode resides */ |
af0b24db SL |
19 | u_short i_shlockc; /* count of shared locks on inode */ |
20 | u_short i_exlockc; /* count of exclusive locks on inode */ | |
d0064d3a | 21 | ino_t i_number; /* i number, 1-to-1 with device address */ |
ad30fb67 | 22 | struct fs *i_fs; /* file sys associated with this inode */ |
3e27ef55 | 23 | struct dquot *i_dquot; /* quota structure controlling this file */ |
d0064d3a | 24 | union { |
ad30fb67 KM |
25 | daddr_t if_lastr; /* last read (read-ahead) */ |
26 | struct socket *is_socket; | |
69bd12a8 RE |
27 | struct { |
28 | struct inode *if_freef; /* free list forward */ | |
29 | struct inode **if_freeb; /* free list back */ | |
30 | } i_fr; | |
d0064d3a | 31 | } i_un; |
ad30fb67 KM |
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 */ | |
af0b24db SL |
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; | |
6c33754a | 43 | time_t ic_ctime; /* 32: last time inode changed */ |
af0b24db SL |
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 */ | |
f2f6c990 SL |
48 | long ic_blocks; /* 104: blocks actually held */ |
49 | long ic_spare[5]; /* 108: reserved, currently unused */ | |
ad30fb67 | 50 | } i_ic; |
d0064d3a BJ |
51 | }; |
52 | ||
ad30fb67 KM |
53 | struct dinode { |
54 | union { | |
55 | struct icommon di_icom; | |
af0b24db | 56 | char di_size[128]; |
ad30fb67 KM |
57 | } di_un; |
58 | }; | |
59 | ||
60 | #define i_mode i_ic.ic_mode | |
61 | #define i_nlink i_ic.ic_nlink | |
62 | #define i_uid i_ic.ic_uid | |
63 | #define i_gid i_ic.ic_gid | |
961945a8 SL |
64 | /* ugh! -- must be fixed */ |
65 | #ifdef vax | |
af0b24db | 66 | #define i_size i_ic.ic_size.val[0] |
961945a8 | 67 | #endif |
ad30fb67 KM |
68 | #define i_db i_ic.ic_db |
69 | #define i_ib i_ic.ic_ib | |
70 | #define i_atime i_ic.ic_atime | |
71 | #define i_mtime i_ic.ic_mtime | |
72 | #define i_ctime i_ic.ic_ctime | |
f2f6c990 | 73 | #define i_blocks i_ic.ic_blocks |
ad30fb67 KM |
74 | #define i_rdev i_ic.ic_db[0] |
75 | #define i_lastr i_un.if_lastr | |
7ef603f5 | 76 | #define i_socket i_un.is_socket |
69bd12a8 RE |
77 | #define i_forw i_chain[0] |
78 | #define i_back i_chain[1] | |
79 | #define i_freef i_un.i_fr.if_freef | |
80 | #define i_freeb i_un.i_fr.if_freeb | |
ad30fb67 KM |
81 | |
82 | #define di_ic di_un.di_icom | |
83 | #define di_mode di_ic.ic_mode | |
84 | #define di_nlink di_ic.ic_nlink | |
85 | #define di_uid di_ic.ic_uid | |
86 | #define di_gid di_ic.ic_gid | |
961945a8 | 87 | #ifdef vax |
af0b24db | 88 | #define di_size di_ic.ic_size.val[0] |
961945a8 | 89 | #endif |
ad30fb67 KM |
90 | #define di_db di_ic.ic_db |
91 | #define di_ib di_ic.ic_ib | |
92 | #define di_atime di_ic.ic_atime | |
93 | #define di_mtime di_ic.ic_mtime | |
94 | #define di_ctime di_ic.ic_ctime | |
95 | #define di_rdev di_ic.ic_db[0] | |
f2f6c990 | 96 | #define di_blocks di_ic.ic_blocks |
ad30fb67 | 97 | |
d0064d3a | 98 | #ifdef KERNEL |
6e7edb25 BJ |
99 | struct inode *inode; /* the inode table itself */ |
100 | struct inode *inodeNINODE; /* the end of the inode table */ | |
101 | int ninode; /* number of slots in the table */ | |
d0064d3a | 102 | |
ad30fb67 | 103 | struct inode *rootdir; /* pointer to inode of root directory */ |
d0064d3a BJ |
104 | |
105 | struct inode *ialloc(); | |
d0064d3a | 106 | struct inode *iget(); |
af0b24db SL |
107 | #ifdef notdef |
108 | struct inode *ifind(); | |
109 | #endif | |
d0064d3a BJ |
110 | struct inode *owner(); |
111 | struct inode *maknode(); | |
112 | struct inode *namei(); | |
af0b24db SL |
113 | |
114 | ino_t dirpref(); | |
d0064d3a BJ |
115 | #endif |
116 | ||
117 | /* flags */ | |
02dd5a44 | 118 | #define ILOCKED 0x1 /* inode is locked */ |
b0954044 SL |
119 | #define IUPD 0x2 /* file has been modified */ |
120 | #define IACC 0x4 /* inode access time to be updated */ | |
121 | #define IMOUNT 0x8 /* inode is mounted on */ | |
122 | #define IWANT 0x10 /* some process waiting on lock */ | |
123 | #define ITEXT 0x20 /* inode is pure text prototype */ | |
124 | #define ICHG 0x40 /* inode has been changed */ | |
af0b24db SL |
125 | #define ISHLOCK 0x80 /* file has shared lock */ |
126 | #define IEXLOCK 0x100 /* file has exclusive lock */ | |
b0954044 | 127 | #define ILWAIT 0x200 /* someone waiting on file lock */ |
232d0cb7 | 128 | #define IMOD 0x400 /* inode has been modified */ |
d0064d3a BJ |
129 | |
130 | /* modes */ | |
ad30fb67 KM |
131 | #define IFMT 0170000 /* type of file */ |
132 | #define IFCHR 0020000 /* character special */ | |
133 | #define IFDIR 0040000 /* directory */ | |
134 | #define IFBLK 0060000 /* block special */ | |
135 | #define IFREG 0100000 /* regular */ | |
136 | #define IFLNK 0120000 /* symbolic link */ | |
dc9a2d80 BJ |
137 | #define IFSOCK 0140000 /* socket */ |
138 | ||
ad30fb67 KM |
139 | #define ISUID 04000 /* set user id on execution */ |
140 | #define ISGID 02000 /* set group id on execution */ | |
141 | #define ISVTX 01000 /* save swapped text even after use */ | |
142 | #define IREAD 0400 /* read, write, execute permissions */ | |
143 | #define IWRITE 0200 | |
144 | #define IEXEC 0100 | |
02dd5a44 BJ |
145 | |
146 | #define ILOCK(ip) { \ | |
147 | while ((ip)->i_flag & ILOCKED) { \ | |
148 | (ip)->i_flag |= IWANT; \ | |
149 | sleep((caddr_t)(ip), PINOD); \ | |
150 | } \ | |
151 | (ip)->i_flag |= ILOCKED; \ | |
152 | } | |
153 | ||
154 | #define IUNLOCK(ip) { \ | |
155 | (ip)->i_flag &= ~ILOCKED; \ | |
156 | if ((ip)->i_flag&IWANT) { \ | |
157 | (ip)->i_flag &= ~IWANT; \ | |
158 | wakeup((caddr_t)(ip)); \ | |
159 | } \ | |
160 | } | |
161 | ||
162 | #define IUPDAT(ip, t1, t2, waitfor) { \ | |
232d0cb7 | 163 | if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \ |
02dd5a44 BJ |
164 | iupdat(ip, t1, t2, waitfor); \ |
165 | } | |
232d0cb7 MK |
166 | |
167 | #define ITIMES(ip, t1, t2) { \ | |
168 | if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \ | |
169 | (ip)->i_flag |= IMOD; \ | |
170 | if ((ip)->i_flag&IACC) \ | |
171 | (ip)->i_atime = (t1)->tv_sec; \ | |
172 | if ((ip)->i_flag&IUPD) \ | |
173 | (ip)->i_mtime = (t2)->tv_sec; \ | |
174 | if ((ip)->i_flag&ICHG) \ | |
175 | (ip)->i_ctime = time.tv_sec; \ | |
176 | (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ | |
177 | } \ | |
178 | } | |
179 |