Commit | Line | Data |
---|---|---|
d40d445c | 1 | /* inode.h 6.3 84/06/27 */ |
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 */ |
d40d445c | 22 | long i_id; /* unique identifier */ |
ad30fb67 | 23 | struct fs *i_fs; /* file sys associated with this inode */ |
3e27ef55 | 24 | struct dquot *i_dquot; /* quota structure controlling this file */ |
d0064d3a | 25 | union { |
ad30fb67 KM |
26 | daddr_t if_lastr; /* last read (read-ahead) */ |
27 | struct socket *is_socket; | |
69bd12a8 RE |
28 | struct { |
29 | struct inode *if_freef; /* free list forward */ | |
30 | struct inode **if_freeb; /* free list back */ | |
31 | } i_fr; | |
d0064d3a | 32 | } i_un; |
ad30fb67 KM |
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 */ | |
af0b24db SL |
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; | |
6c33754a | 44 | time_t ic_ctime; /* 32: last time inode changed */ |
af0b24db SL |
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 */ | |
f2f6c990 SL |
49 | long ic_blocks; /* 104: blocks actually held */ |
50 | long ic_spare[5]; /* 108: reserved, currently unused */ | |
ad30fb67 | 51 | } i_ic; |
d0064d3a BJ |
52 | }; |
53 | ||
ad30fb67 KM |
54 | struct dinode { |
55 | union { | |
56 | struct icommon di_icom; | |
af0b24db | 57 | char di_size[128]; |
ad30fb67 KM |
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 | |
961945a8 SL |
65 | /* ugh! -- must be fixed */ |
66 | #ifdef vax | |
af0b24db | 67 | #define i_size i_ic.ic_size.val[0] |
961945a8 | 68 | #endif |
ad30fb67 KM |
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 | |
f2f6c990 | 74 | #define i_blocks i_ic.ic_blocks |
ad30fb67 KM |
75 | #define i_rdev i_ic.ic_db[0] |
76 | #define i_lastr i_un.if_lastr | |
7ef603f5 | 77 | #define i_socket i_un.is_socket |
69bd12a8 RE |
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 | |
ad30fb67 KM |
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 | |
961945a8 | 88 | #ifdef vax |
af0b24db | 89 | #define di_size di_ic.ic_size.val[0] |
961945a8 | 90 | #endif |
ad30fb67 KM |
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] | |
f2f6c990 | 97 | #define di_blocks di_ic.ic_blocks |
ad30fb67 | 98 | |
d0064d3a | 99 | #ifdef KERNEL |
6e7edb25 BJ |
100 | struct inode *inode; /* the inode table itself */ |
101 | struct inode *inodeNINODE; /* the end of the inode table */ | |
102 | int ninode; /* number of slots in the table */ | |
d40d445c | 103 | long nextinodeid; /* unique id generator */ |
d0064d3a | 104 | |
ad30fb67 | 105 | struct inode *rootdir; /* pointer to inode of root directory */ |
d0064d3a BJ |
106 | |
107 | struct inode *ialloc(); | |
d0064d3a | 108 | struct inode *iget(); |
af0b24db SL |
109 | #ifdef notdef |
110 | struct inode *ifind(); | |
111 | #endif | |
d0064d3a BJ |
112 | struct inode *owner(); |
113 | struct inode *maknode(); | |
114 | struct inode *namei(); | |
af0b24db SL |
115 | |
116 | ino_t dirpref(); | |
d0064d3a BJ |
117 | #endif |
118 | ||
119 | /* flags */ | |
02dd5a44 | 120 | #define ILOCKED 0x1 /* inode is locked */ |
b0954044 SL |
121 | #define IUPD 0x2 /* file has been modified */ |
122 | #define IACC 0x4 /* inode access time to be updated */ | |
123 | #define IMOUNT 0x8 /* inode is mounted on */ | |
124 | #define IWANT 0x10 /* some process waiting on lock */ | |
125 | #define ITEXT 0x20 /* inode is pure text prototype */ | |
126 | #define ICHG 0x40 /* inode has been changed */ | |
af0b24db SL |
127 | #define ISHLOCK 0x80 /* file has shared lock */ |
128 | #define IEXLOCK 0x100 /* file has exclusive lock */ | |
b0954044 | 129 | #define ILWAIT 0x200 /* someone waiting on file lock */ |
232d0cb7 | 130 | #define IMOD 0x400 /* inode has been modified */ |
d0064d3a BJ |
131 | |
132 | /* modes */ | |
ad30fb67 KM |
133 | #define IFMT 0170000 /* type of file */ |
134 | #define IFCHR 0020000 /* character special */ | |
135 | #define IFDIR 0040000 /* directory */ | |
136 | #define IFBLK 0060000 /* block special */ | |
137 | #define IFREG 0100000 /* regular */ | |
138 | #define IFLNK 0120000 /* symbolic link */ | |
dc9a2d80 BJ |
139 | #define IFSOCK 0140000 /* socket */ |
140 | ||
ad30fb67 KM |
141 | #define ISUID 04000 /* set user id on execution */ |
142 | #define ISGID 02000 /* set group id on execution */ | |
143 | #define ISVTX 01000 /* save swapped text even after use */ | |
144 | #define IREAD 0400 /* read, write, execute permissions */ | |
145 | #define IWRITE 0200 | |
146 | #define IEXEC 0100 | |
02dd5a44 BJ |
147 | |
148 | #define ILOCK(ip) { \ | |
149 | while ((ip)->i_flag & ILOCKED) { \ | |
150 | (ip)->i_flag |= IWANT; \ | |
151 | sleep((caddr_t)(ip), PINOD); \ | |
152 | } \ | |
153 | (ip)->i_flag |= ILOCKED; \ | |
154 | } | |
155 | ||
156 | #define IUNLOCK(ip) { \ | |
157 | (ip)->i_flag &= ~ILOCKED; \ | |
158 | if ((ip)->i_flag&IWANT) { \ | |
159 | (ip)->i_flag &= ~IWANT; \ | |
160 | wakeup((caddr_t)(ip)); \ | |
161 | } \ | |
162 | } | |
163 | ||
164 | #define IUPDAT(ip, t1, t2, waitfor) { \ | |
232d0cb7 | 165 | if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \ |
02dd5a44 BJ |
166 | iupdat(ip, t1, t2, waitfor); \ |
167 | } | |
232d0cb7 MK |
168 | |
169 | #define ITIMES(ip, t1, t2) { \ | |
170 | if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \ | |
171 | (ip)->i_flag |= IMOD; \ | |
172 | if ((ip)->i_flag&IACC) \ | |
173 | (ip)->i_atime = (t1)->tv_sec; \ | |
174 | if ((ip)->i_flag&IUPD) \ | |
175 | (ip)->i_mtime = (t2)->tv_sec; \ | |
176 | if ((ip)->i_flag&ICHG) \ | |
177 | (ip)->i_ctime = time.tv_sec; \ | |
178 | (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ | |
179 | } \ | |
180 | } |