Commit | Line | Data |
---|---|---|
da7c5cc6 | 1 | /* |
6d0f0ece KM |
2 | * Copyright (c) 1982, 1989 The Regents of the University of California. |
3 | * All rights reserved. | |
da7c5cc6 | 4 | * |
6d0f0ece KM |
5 | * Redistribution and use in source and binary forms are permitted |
6 | * provided that the above copyright notice and this paragraph are | |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
16 | * | |
1806caca | 17 | * @(#)dinode.h 7.5 (Berkeley) %G% |
da7c5cc6 | 18 | */ |
d0064d3a BJ |
19 | |
20 | /* | |
a59abf09 BJ |
21 | * The I node is the focus of all file activity in UNIX. |
22 | * There is a unique inode allocated for each active file, | |
23 | * each current directory, each mounted-on file, text file, and the root. | |
24 | * An inode is 'named' by its dev/inumber pair. (iget/iget.c) | |
ad30fb67 | 25 | * Data in icommon is read in from permanent inode on volume. |
d0064d3a | 26 | */ |
ad30fb67 | 27 | |
af0b24db SL |
28 | #define NDADDR 12 /* direct addresses in inode */ |
29 | #define NIADDR 3 /* indirect addresses in inode */ | |
d0064d3a | 30 | |
a59abf09 | 31 | struct inode { |
69bd12a8 | 32 | struct inode *i_chain[2]; /* must be first */ |
6d0f0ece KM |
33 | struct vnode i_vnode; /* vnode associated with this inode */ |
34 | struct vnode *i_devvp; /* vnode for block I/O */ | |
b0954044 | 35 | u_short i_flag; |
d0064d3a BJ |
36 | dev_t i_dev; /* device where inode resides */ |
37 | ino_t i_number; /* i number, 1-to-1 with device address */ | |
d40d445c | 38 | long i_id; /* unique identifier */ |
6d0f0ece | 39 | long i_diroff; /* offset in dir, where we found last entry */ |
ad30fb67 | 40 | struct fs *i_fs; /* file sys associated with this inode */ |
3e27ef55 | 41 | struct dquot *i_dquot; /* quota structure controlling this file */ |
68dc14d7 | 42 | struct text *i_text; /* text entry, if any (should be region) */ |
6d0f0ece KM |
43 | struct inode *i_devlst;/* list of block device inodes */ |
44 | off_t i_endoff; /* end of useful stuff in directory */ | |
1806caca | 45 | long i_spare[4]; |
d0064d3a | 46 | union { |
ad30fb67 KM |
47 | daddr_t if_lastr; /* last read (read-ahead) */ |
48 | struct socket *is_socket; | |
69bd12a8 RE |
49 | struct { |
50 | struct inode *if_freef; /* free list forward */ | |
51 | struct inode **if_freeb; /* free list back */ | |
52 | } i_fr; | |
d0064d3a | 53 | } i_un; |
ad30fb67 KM |
54 | struct icommon |
55 | { | |
56 | u_short ic_mode; /* 0: mode and type of file */ | |
57 | short ic_nlink; /* 2: number of links to file */ | |
adc65074 MK |
58 | uid_t ic_uid; /* 4: owner's user id */ |
59 | gid_t ic_gid; /* 6: owner's group id */ | |
af0b24db SL |
60 | quad ic_size; /* 8: number of bytes in file */ |
61 | time_t ic_atime; /* 16: time last accessed */ | |
62 | long ic_atspare; | |
63 | time_t ic_mtime; /* 24: time last modified */ | |
64 | long ic_mtspare; | |
6c33754a | 65 | time_t ic_ctime; /* 32: last time inode changed */ |
af0b24db SL |
66 | long ic_ctspare; |
67 | daddr_t ic_db[NDADDR]; /* 40: disk block addresses */ | |
68 | daddr_t ic_ib[NIADDR]; /* 88: indirect blocks */ | |
69 | long ic_flags; /* 100: status, currently unused */ | |
f2f6c990 | 70 | long ic_blocks; /* 104: blocks actually held */ |
6d0f0ece KM |
71 | long ic_gen; /* 108: generation number */ |
72 | long ic_spare[4]; /* 112: reserved, currently unused */ | |
ad30fb67 | 73 | } i_ic; |
d0064d3a BJ |
74 | }; |
75 | ||
ad30fb67 KM |
76 | struct dinode { |
77 | union { | |
78 | struct icommon di_icom; | |
af0b24db | 79 | char di_size[128]; |
ad30fb67 KM |
80 | } di_un; |
81 | }; | |
82 | ||
83 | #define i_mode i_ic.ic_mode | |
84 | #define i_nlink i_ic.ic_nlink | |
85 | #define i_uid i_ic.ic_uid | |
86 | #define i_gid i_ic.ic_gid | |
961945a8 | 87 | /* ugh! -- must be fixed */ |
22a22bd0 | 88 | #if defined(vax) || defined(tahoe) |
af0b24db | 89 | #define i_size i_ic.ic_size.val[0] |
961945a8 | 90 | #endif |
ad30fb67 KM |
91 | #define i_db i_ic.ic_db |
92 | #define i_ib i_ic.ic_ib | |
93 | #define i_atime i_ic.ic_atime | |
94 | #define i_mtime i_ic.ic_mtime | |
95 | #define i_ctime i_ic.ic_ctime | |
f2f6c990 | 96 | #define i_blocks i_ic.ic_blocks |
ad30fb67 | 97 | #define i_rdev i_ic.ic_db[0] |
f96164be | 98 | #define i_flags i_ic.ic_flags |
6d0f0ece | 99 | #define i_gen i_ic.ic_gen |
ad30fb67 | 100 | #define i_lastr i_un.if_lastr |
7ef603f5 | 101 | #define i_socket i_un.is_socket |
69bd12a8 RE |
102 | #define i_forw i_chain[0] |
103 | #define i_back i_chain[1] | |
104 | #define i_freef i_un.i_fr.if_freef | |
105 | #define i_freeb i_un.i_fr.if_freeb | |
ad30fb67 KM |
106 | |
107 | #define di_ic di_un.di_icom | |
108 | #define di_mode di_ic.ic_mode | |
109 | #define di_nlink di_ic.ic_nlink | |
110 | #define di_uid di_ic.ic_uid | |
111 | #define di_gid di_ic.ic_gid | |
22a22bd0 | 112 | #if defined(vax) || defined(tahoe) |
af0b24db | 113 | #define di_size di_ic.ic_size.val[0] |
961945a8 | 114 | #endif |
ad30fb67 KM |
115 | #define di_db di_ic.ic_db |
116 | #define di_ib di_ic.ic_ib | |
117 | #define di_atime di_ic.ic_atime | |
118 | #define di_mtime di_ic.ic_mtime | |
119 | #define di_ctime di_ic.ic_ctime | |
120 | #define di_rdev di_ic.ic_db[0] | |
f2f6c990 | 121 | #define di_blocks di_ic.ic_blocks |
f96164be | 122 | #define di_flags di_ic.ic_flags |
6d0f0ece | 123 | #define di_gen di_ic.ic_gen |
ad30fb67 | 124 | |
d0064d3a | 125 | #ifdef KERNEL |
6e7edb25 BJ |
126 | struct inode *inode; /* the inode table itself */ |
127 | struct inode *inodeNINODE; /* the end of the inode table */ | |
128 | int ninode; /* number of slots in the table */ | |
d0064d3a | 129 | |
f96164be KM |
130 | u_long nextgennumber; /* next generation number to assign */ |
131 | ||
6d0f0ece KM |
132 | extern struct vnodeops ufs_vnodeops; /* vnode operations for ufs */ |
133 | extern struct vnodeops blk_vnodeops; /* vnode operations for blk devices */ | |
af0b24db | 134 | |
6d0f0ece | 135 | extern ino_t dirpref(); |
d0064d3a BJ |
136 | #endif |
137 | ||
138 | /* flags */ | |
02dd5a44 | 139 | #define ILOCKED 0x1 /* inode is locked */ |
b0954044 SL |
140 | #define IUPD 0x2 /* file has been modified */ |
141 | #define IACC 0x4 /* inode access time to be updated */ | |
6d0f0ece KM |
142 | #define IWANT 0x8 /* some process waiting on lock */ |
143 | #define ICHG 0x10 /* inode has been changed */ | |
144 | #define ISHLOCK 0x20 /* file has shared lock */ | |
145 | #define IEXLOCK 0x40 /* file has exclusive lock */ | |
146 | #define ILWAIT 0x80 /* someone waiting on file lock */ | |
147 | #define IMOD 0x100 /* inode has been modified */ | |
148 | #define IRENAME 0x200 /* inode is being renamed */ | |
d0064d3a BJ |
149 | |
150 | /* modes */ | |
ad30fb67 KM |
151 | #define IFMT 0170000 /* type of file */ |
152 | #define IFCHR 0020000 /* character special */ | |
153 | #define IFDIR 0040000 /* directory */ | |
154 | #define IFBLK 0060000 /* block special */ | |
155 | #define IFREG 0100000 /* regular */ | |
156 | #define IFLNK 0120000 /* symbolic link */ | |
dc9a2d80 BJ |
157 | #define IFSOCK 0140000 /* socket */ |
158 | ||
ad30fb67 KM |
159 | #define ISUID 04000 /* set user id on execution */ |
160 | #define ISGID 02000 /* set group id on execution */ | |
161 | #define ISVTX 01000 /* save swapped text even after use */ | |
162 | #define IREAD 0400 /* read, write, execute permissions */ | |
163 | #define IWRITE 0200 | |
164 | #define IEXEC 0100 | |
02dd5a44 | 165 | |
6d0f0ece KM |
166 | #ifdef KERNEL |
167 | /* | |
168 | * Convert between inode pointers and vnode pointers | |
169 | */ | |
170 | #define VTOI(vp) ((struct inode *)(vp)->v_data) | |
f96164be | 171 | #define ITOV(ip) (&(ip)->i_vnode) |
6d0f0ece KM |
172 | |
173 | /* | |
174 | * Convert between vnode types and inode formats | |
175 | */ | |
176 | extern enum vtype iftovt_tab[]; | |
177 | extern int vttoif_tab[]; | |
178 | #define IFTOVT(mode) (iftovt_tab[((mode) & IFMT) >> 13]) | |
179 | #define VTTOIF(indx) (vttoif_tab[(int)(indx)]) | |
180 | ||
181 | #define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode)) | |
182 | ||
183 | /* | |
184 | * Lock and unlock inodes. | |
185 | */ | |
02dd5a44 BJ |
186 | #define ILOCK(ip) { \ |
187 | while ((ip)->i_flag & ILOCKED) { \ | |
188 | (ip)->i_flag |= IWANT; \ | |
6d0f0ece | 189 | (void) sleep((caddr_t)(ip), PINOD); \ |
02dd5a44 BJ |
190 | } \ |
191 | (ip)->i_flag |= ILOCKED; \ | |
192 | } | |
193 | ||
194 | #define IUNLOCK(ip) { \ | |
195 | (ip)->i_flag &= ~ILOCKED; \ | |
196 | if ((ip)->i_flag&IWANT) { \ | |
197 | (ip)->i_flag &= ~IWANT; \ | |
198 | wakeup((caddr_t)(ip)); \ | |
199 | } \ | |
200 | } | |
201 | ||
202 | #define IUPDAT(ip, t1, t2, waitfor) { \ | |
232d0cb7 | 203 | if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \ |
6d0f0ece | 204 | (void) iupdat(ip, t1, t2, waitfor); \ |
02dd5a44 | 205 | } |
232d0cb7 MK |
206 | |
207 | #define ITIMES(ip, t1, t2) { \ | |
208 | if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \ | |
209 | (ip)->i_flag |= IMOD; \ | |
210 | if ((ip)->i_flag&IACC) \ | |
211 | (ip)->i_atime = (t1)->tv_sec; \ | |
212 | if ((ip)->i_flag&IUPD) \ | |
213 | (ip)->i_mtime = (t2)->tv_sec; \ | |
214 | if ((ip)->i_flag&ICHG) \ | |
215 | (ip)->i_ctime = time.tv_sec; \ | |
216 | (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ | |
217 | } \ | |
218 | } | |
6d0f0ece KM |
219 | |
220 | /* | |
221 | * This overlays the fid sturcture (see mount.h) | |
222 | */ | |
223 | struct ufid { | |
224 | u_short ufid_len; | |
225 | ino_t ufid_ino; | |
226 | long ufid_gen; | |
227 | }; | |
228 | #endif |