reverse sense of pid/pgrp for fcntl, SIOCSPGRP (pgrp is negative)
[unix-history] / usr / src / sys / ufs / ffs / inode.h
CommitLineData
a6e2ac2d 1/* inode.h 6.7 85/01/10 */
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 14struct 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
54struct 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
f7a08d25
KM
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) \
f7a08d25
KM
106 (ip)->i_id = ++nextinodeid; \
107 if (nextinodeid == 0) \
a6e2ac2d 108 cacheinvalall();
f7a08d25 109
6e7edb25
BJ
110struct inode *inode; /* the inode table itself */
111struct inode *inodeNINODE; /* the end of the inode table */
112int ninode; /* number of slots in the table */
d40d445c 113long nextinodeid; /* unique id generator */
d0064d3a 114
ad30fb67 115struct inode *rootdir; /* pointer to inode of root directory */
d0064d3a
BJ
116
117struct inode *ialloc();
d0064d3a 118struct inode *iget();
af0b24db
SL
119#ifdef notdef
120struct inode *ifind();
121#endif
d0064d3a
BJ
122struct inode *owner();
123struct inode *maknode();
124struct inode *namei();
af0b24db
SL
125
126ino_t dirpref();
d0064d3a
BJ
127#endif
128
129/* flags */
02dd5a44 130#define ILOCKED 0x1 /* inode is locked */
b0954044
SL
131#define IUPD 0x2 /* file has been modified */
132#define IACC 0x4 /* inode access time to be updated */
133#define IMOUNT 0x8 /* inode is mounted on */
134#define IWANT 0x10 /* some process waiting on lock */
135#define ITEXT 0x20 /* inode is pure text prototype */
136#define ICHG 0x40 /* inode has been changed */
af0b24db
SL
137#define ISHLOCK 0x80 /* file has shared lock */
138#define IEXLOCK 0x100 /* file has exclusive lock */
b0954044 139#define ILWAIT 0x200 /* someone waiting on file lock */
232d0cb7 140#define IMOD 0x400 /* inode has been modified */
64f84549 141#define IRENAME 0x800 /* inode is being renamed */
223b747e 142#define IXMOD 0x8000 /* inode is text, but impure (XXX) */
d0064d3a
BJ
143
144/* modes */
ad30fb67
KM
145#define IFMT 0170000 /* type of file */
146#define IFCHR 0020000 /* character special */
147#define IFDIR 0040000 /* directory */
148#define IFBLK 0060000 /* block special */
149#define IFREG 0100000 /* regular */
150#define IFLNK 0120000 /* symbolic link */
dc9a2d80
BJ
151#define IFSOCK 0140000 /* socket */
152
ad30fb67
KM
153#define ISUID 04000 /* set user id on execution */
154#define ISGID 02000 /* set group id on execution */
155#define ISVTX 01000 /* save swapped text even after use */
156#define IREAD 0400 /* read, write, execute permissions */
157#define IWRITE 0200
158#define IEXEC 0100
02dd5a44
BJ
159
160#define ILOCK(ip) { \
161 while ((ip)->i_flag & ILOCKED) { \
162 (ip)->i_flag |= IWANT; \
163 sleep((caddr_t)(ip), PINOD); \
164 } \
165 (ip)->i_flag |= ILOCKED; \
166}
167
168#define IUNLOCK(ip) { \
169 (ip)->i_flag &= ~ILOCKED; \
170 if ((ip)->i_flag&IWANT) { \
171 (ip)->i_flag &= ~IWANT; \
172 wakeup((caddr_t)(ip)); \
173 } \
174}
175
176#define IUPDAT(ip, t1, t2, waitfor) { \
232d0cb7 177 if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
02dd5a44
BJ
178 iupdat(ip, t1, t2, waitfor); \
179}
232d0cb7
MK
180
181#define ITIMES(ip, t1, t2) { \
182 if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
183 (ip)->i_flag |= IMOD; \
184 if ((ip)->i_flag&IACC) \
185 (ip)->i_atime = (t1)->tv_sec; \
186 if ((ip)->i_flag&IUPD) \
187 (ip)->i_mtime = (t2)->tv_sec; \
188 if ((ip)->i_flag&ICHG) \
189 (ip)->i_ctime = time.tv_sec; \
190 (ip)->i_flag &= ~(IACC|IUPD|ICHG); \
191 } \
192}