xref: /original-bsd/sys/ufs/ufs/inode.h (revision a910c8b7)
1 /*	inode.h	6.7	85/01/10	*/
2 
3 /*
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)
8  * Data in icommon is read in from permanent inode on volume.
9  */
10 
11 #define	NDADDR	12		/* direct addresses in inode */
12 #define	NIADDR	3		/* indirect addresses in inode */
13 
14 struct inode {
15 	struct	inode *i_chain[2];	/* must be first */
16 	u_short	i_flag;
17 	u_short	i_count;	/* reference count */
18 	dev_t	i_dev;		/* device where inode resides */
19 	u_short	i_shlockc;	/* count of shared locks on inode */
20 	u_short	i_exlockc;	/* count of exclusive locks on inode */
21 	ino_t	i_number;	/* i number, 1-to-1 with device address */
22 	long	i_id;		/* unique identifier */
23 	struct	fs *i_fs;	/* file sys associated with this inode */
24 	struct	dquot *i_dquot;	/* quota structure controlling this file */
25 	union {
26 		daddr_t	if_lastr;	/* last read (read-ahead) */
27 		struct	socket *is_socket;
28 		struct	{
29 			struct inode  *if_freef;	/* free list forward */
30 			struct inode **if_freeb;	/* free list back */
31 		} i_fr;
32 	} i_un;
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 */
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;
44 		time_t	ic_ctime;	/* 32: last time inode changed */
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 */
49 		long	ic_blocks;	/* 104: blocks actually held */
50 		long	ic_spare[5];	/* 108: reserved, currently unused */
51 	} i_ic;
52 };
53 
54 struct dinode {
55 	union {
56 		struct	icommon di_icom;
57 		char	di_size[128];
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
65 /* ugh! -- must be fixed */
66 #ifdef vax
67 #define	i_size		i_ic.ic_size.val[0]
68 #endif
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
74 #define i_blocks	i_ic.ic_blocks
75 #define	i_rdev		i_ic.ic_db[0]
76 #define	i_lastr		i_un.if_lastr
77 #define	i_socket	i_un.is_socket
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
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
88 #ifdef vax
89 #define	di_size		di_ic.ic_size.val[0]
90 #endif
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]
97 #define	di_blocks	di_ic.ic_blocks
98 
99 #ifdef KERNEL
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)	\
106 	(ip)->i_id = ++nextinodeid; \
107 	if (nextinodeid == 0) \
108 		cacheinvalall();
109 
110 struct inode *inode;		/* the inode table itself */
111 struct inode *inodeNINODE;	/* the end of the inode table */
112 int	ninode;			/* number of slots in the table */
113 long	nextinodeid;		/* unique id generator */
114 
115 struct	inode *rootdir;			/* pointer to inode of root directory */
116 
117 struct	inode *ialloc();
118 struct	inode *iget();
119 #ifdef notdef
120 struct	inode *ifind();
121 #endif
122 struct	inode *owner();
123 struct	inode *maknode();
124 struct	inode *namei();
125 
126 ino_t	dirpref();
127 #endif
128 
129 /* flags */
130 #define	ILOCKED		0x1		/* inode is locked */
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 */
137 #define	ISHLOCK		0x80		/* file has shared lock */
138 #define	IEXLOCK		0x100		/* file has exclusive lock */
139 #define	ILWAIT		0x200		/* someone waiting on file lock */
140 #define	IMOD		0x400		/* inode has been modified */
141 #define	IRENAME		0x800		/* inode is being renamed */
142 #define	IXMOD		0x8000		/* inode is text, but impure (XXX) */
143 
144 /* modes */
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 */
151 #define	IFSOCK		0140000		/* socket */
152 
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
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) { \
177 	if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
178 		iupdat(ip, t1, t2, waitfor); \
179 }
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 }
193