now can use XTRC again instead of IXMOD
[unix-history] / usr / src / sys / ufs / ffs / inode.h
CommitLineData
da7c5cc6
KM
1/*
2 * Copyright (c) 1982 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 *
cdb14d96 6 * @(#)inode.h 6.11 (Berkeley) %G%
da7c5cc6 7 */
d0064d3a
BJ
8
9/*
a59abf09
BJ
10 * The I node is the focus of all file activity in UNIX.
11 * There is a unique inode allocated for each active file,
12 * each current directory, each mounted-on file, text file, and the root.
13 * An inode is 'named' by its dev/inumber pair. (iget/iget.c)
ad30fb67 14 * Data in icommon is read in from permanent inode on volume.
d0064d3a 15 */
ad30fb67 16
af0b24db
SL
17#define NDADDR 12 /* direct addresses in inode */
18#define NIADDR 3 /* indirect addresses in inode */
d0064d3a 19
a59abf09 20struct inode {
69bd12a8 21 struct inode *i_chain[2]; /* must be first */
b0954044 22 u_short i_flag;
3e27ef55 23 u_short i_count; /* reference count */
d0064d3a 24 dev_t i_dev; /* device where inode resides */
af0b24db
SL
25 u_short i_shlockc; /* count of shared locks on inode */
26 u_short i_exlockc; /* count of exclusive locks on inode */
d0064d3a 27 ino_t i_number; /* i number, 1-to-1 with device address */
d40d445c 28 long i_id; /* unique identifier */
ad30fb67 29 struct fs *i_fs; /* file sys associated with this inode */
3e27ef55 30 struct dquot *i_dquot; /* quota structure controlling this file */
68dc14d7 31 struct text *i_text; /* text entry, if any (should be region) */
d0064d3a 32 union {
ad30fb67
KM
33 daddr_t if_lastr; /* last read (read-ahead) */
34 struct socket *is_socket;
69bd12a8
RE
35 struct {
36 struct inode *if_freef; /* free list forward */
37 struct inode **if_freeb; /* free list back */
38 } i_fr;
d0064d3a 39 } i_un;
ad30fb67
KM
40 struct icommon
41 {
42 u_short ic_mode; /* 0: mode and type of file */
43 short ic_nlink; /* 2: number of links to file */
adc65074
MK
44 uid_t ic_uid; /* 4: owner's user id */
45 gid_t ic_gid; /* 6: owner's group id */
af0b24db
SL
46 quad ic_size; /* 8: number of bytes in file */
47 time_t ic_atime; /* 16: time last accessed */
48 long ic_atspare;
49 time_t ic_mtime; /* 24: time last modified */
50 long ic_mtspare;
6c33754a 51 time_t ic_ctime; /* 32: last time inode changed */
af0b24db
SL
52 long ic_ctspare;
53 daddr_t ic_db[NDADDR]; /* 40: disk block addresses */
54 daddr_t ic_ib[NIADDR]; /* 88: indirect blocks */
55 long ic_flags; /* 100: status, currently unused */
f2f6c990
SL
56 long ic_blocks; /* 104: blocks actually held */
57 long ic_spare[5]; /* 108: reserved, currently unused */
ad30fb67 58 } i_ic;
d0064d3a
BJ
59};
60
ad30fb67
KM
61struct dinode {
62 union {
63 struct icommon di_icom;
af0b24db 64 char di_size[128];
ad30fb67
KM
65 } di_un;
66};
67
68#define i_mode i_ic.ic_mode
69#define i_nlink i_ic.ic_nlink
70#define i_uid i_ic.ic_uid
71#define i_gid i_ic.ic_gid
961945a8
SL
72/* ugh! -- must be fixed */
73#ifdef vax
af0b24db 74#define i_size i_ic.ic_size.val[0]
961945a8 75#endif
ad30fb67
KM
76#define i_db i_ic.ic_db
77#define i_ib i_ic.ic_ib
78#define i_atime i_ic.ic_atime
79#define i_mtime i_ic.ic_mtime
80#define i_ctime i_ic.ic_ctime
f2f6c990 81#define i_blocks i_ic.ic_blocks
ad30fb67
KM
82#define i_rdev i_ic.ic_db[0]
83#define i_lastr i_un.if_lastr
7ef603f5 84#define i_socket i_un.is_socket
69bd12a8
RE
85#define i_forw i_chain[0]
86#define i_back i_chain[1]
87#define i_freef i_un.i_fr.if_freef
88#define i_freeb i_un.i_fr.if_freeb
ad30fb67
KM
89
90#define di_ic di_un.di_icom
91#define di_mode di_ic.ic_mode
92#define di_nlink di_ic.ic_nlink
93#define di_uid di_ic.ic_uid
94#define di_gid di_ic.ic_gid
961945a8 95#ifdef vax
af0b24db 96#define di_size di_ic.ic_size.val[0]
961945a8 97#endif
ad30fb67
KM
98#define di_db di_ic.ic_db
99#define di_ib di_ic.ic_ib
100#define di_atime di_ic.ic_atime
101#define di_mtime di_ic.ic_mtime
102#define di_ctime di_ic.ic_ctime
103#define di_rdev di_ic.ic_db[0]
f2f6c990 104#define di_blocks di_ic.ic_blocks
ad30fb67 105
d0064d3a 106#ifdef KERNEL
f7a08d25
KM
107/*
108 * Invalidate an inode. Used by the namei cache to detect stale
109 * information. At an absurd rate of 100 calls/second, the inode
110 * table invalidation should only occur once every 16 months.
111 */
112#define cacheinval(ip) \
f7a08d25
KM
113 (ip)->i_id = ++nextinodeid; \
114 if (nextinodeid == 0) \
a6e2ac2d 115 cacheinvalall();
f7a08d25 116
6e7edb25
BJ
117struct inode *inode; /* the inode table itself */
118struct inode *inodeNINODE; /* the end of the inode table */
119int ninode; /* number of slots in the table */
d40d445c 120long nextinodeid; /* unique id generator */
d0064d3a 121
ad30fb67 122struct inode *rootdir; /* pointer to inode of root directory */
d0064d3a
BJ
123
124struct inode *ialloc();
d0064d3a 125struct inode *iget();
af0b24db
SL
126#ifdef notdef
127struct inode *ifind();
128#endif
d0064d3a
BJ
129struct inode *owner();
130struct inode *maknode();
131struct inode *namei();
af0b24db
SL
132
133ino_t dirpref();
d0064d3a
BJ
134#endif
135
136/* flags */
02dd5a44 137#define ILOCKED 0x1 /* inode is locked */
b0954044
SL
138#define IUPD 0x2 /* file has been modified */
139#define IACC 0x4 /* inode access time to be updated */
140#define IMOUNT 0x8 /* inode is mounted on */
141#define IWANT 0x10 /* some process waiting on lock */
142#define ITEXT 0x20 /* inode is pure text prototype */
143#define ICHG 0x40 /* inode has been changed */
af0b24db
SL
144#define ISHLOCK 0x80 /* file has shared lock */
145#define IEXLOCK 0x100 /* file has exclusive lock */
b0954044 146#define ILWAIT 0x200 /* someone waiting on file lock */
232d0cb7 147#define IMOD 0x400 /* inode has been modified */
64f84549 148#define IRENAME 0x800 /* 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
BJ
165
166#define ILOCK(ip) { \
167 while ((ip)->i_flag & ILOCKED) { \
168 (ip)->i_flag |= IWANT; \
169 sleep((caddr_t)(ip), PINOD); \
170 } \
171 (ip)->i_flag |= ILOCKED; \
172}
173
174#define IUNLOCK(ip) { \
175 (ip)->i_flag &= ~ILOCKED; \
176 if ((ip)->i_flag&IWANT) { \
177 (ip)->i_flag &= ~IWANT; \
178 wakeup((caddr_t)(ip)); \
179 } \
180}
181
182#define IUPDAT(ip, t1, t2, waitfor) { \
232d0cb7 183 if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
02dd5a44
BJ
184 iupdat(ip, t1, t2, waitfor); \
185}
232d0cb7
MK
186
187#define ITIMES(ip, t1, t2) { \
188 if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
189 (ip)->i_flag |= IMOD; \
190 if ((ip)->i_flag&IACC) \
191 (ip)->i_atime = (t1)->tv_sec; \
192 if ((ip)->i_flag&IUPD) \
193 (ip)->i_mtime = (t2)->tv_sec; \
194 if ((ip)->i_flag&ICHG) \
195 (ip)->i_ctime = time.tv_sec; \
196 (ip)->i_flag &= ~(IACC|IUPD|ICHG); \
197 } \
198}