xref: /original-bsd/sys/ufs/ffs/inode.h (revision 82ca1924)
1 /*
2  * Copyright (c) 1982, 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
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  *
17  *	@(#)inode.h	7.5 (Berkeley) 07/03/89
18  */
19 
20 /*
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)
25  * Data in icommon is read in from permanent inode on volume.
26  */
27 
28 #define	NDADDR	12		/* direct addresses in inode */
29 #define	NIADDR	3		/* indirect addresses in inode */
30 
31 struct inode {
32 	struct	inode *i_chain[2];	/* must be first */
33 	struct	vnode i_vnode;	/* vnode associated with this inode */
34 	struct	vnode *i_devvp;	/* vnode for block I/O */
35 	u_short	i_flag;
36 	dev_t	i_dev;		/* device where inode resides */
37 	ino_t	i_number;	/* i number, 1-to-1 with device address */
38 	long	i_id;		/* unique identifier */
39 	long	i_diroff;	/* offset in dir, where we found last entry */
40 	struct	fs *i_fs;	/* file sys associated with this inode */
41 	struct	dquot *i_dquot;	/* quota structure controlling this file */
42 	struct	text *i_text;	/* text entry, if any (should be region) */
43 	struct	inode *i_devlst;/* list of block device inodes */
44 	off_t	i_endoff;	/* end of useful stuff in directory */
45 	long	i_spare[4];
46 	union {
47 		daddr_t	if_lastr;	/* last read (read-ahead) */
48 		struct	socket *is_socket;
49 		struct	{
50 			struct inode  *if_freef;	/* free list forward */
51 			struct inode **if_freeb;	/* free list back */
52 		} i_fr;
53 	} i_un;
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 */
58 		uid_t	ic_uid;		/*  4: owner's user id */
59 		gid_t	ic_gid;		/*  6: owner's group id */
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;
65 		time_t	ic_ctime;	/* 32: last time inode changed */
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 */
70 		long	ic_blocks;	/* 104: blocks actually held */
71 		long	ic_gen;		/* 108: generation number */
72 		long	ic_spare[4];	/* 112: reserved, currently unused */
73 	} i_ic;
74 };
75 
76 struct dinode {
77 	union {
78 		struct	icommon di_icom;
79 		char	di_size[128];
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
87 /* ugh! -- must be fixed */
88 #if defined(vax) || defined(tahoe)
89 #define	i_size		i_ic.ic_size.val[0]
90 #endif
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
96 #define i_blocks	i_ic.ic_blocks
97 #define	i_rdev		i_ic.ic_db[0]
98 #define i_flags		i_ic.ic_flags
99 #define i_gen		i_ic.ic_gen
100 #define	i_lastr		i_un.if_lastr
101 #define	i_socket	i_un.is_socket
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
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
112 #if defined(vax) || defined(tahoe)
113 #define	di_size		di_ic.ic_size.val[0]
114 #endif
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]
121 #define	di_blocks	di_ic.ic_blocks
122 #define	di_flags	di_ic.ic_flags
123 #define	di_gen		di_ic.ic_gen
124 
125 #ifdef KERNEL
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 */
129 
130 u_long	nextgennumber;		/* next generation number to assign */
131 
132 extern struct vnodeops ufs_vnodeops;	/* vnode operations for ufs */
133 extern struct vnodeops blk_vnodeops;	/* vnode operations for blk devices */
134 
135 extern ino_t	dirpref();
136 #endif
137 
138 /* flags */
139 #define	ILOCKED		0x1		/* inode is locked */
140 #define	IUPD		0x2		/* file has been modified */
141 #define	IACC		0x4		/* inode access time to be updated */
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 */
149 
150 /* modes */
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 */
157 #define	IFSOCK		0140000		/* socket */
158 
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
165 
166 #ifdef KERNEL
167 /*
168  * Convert between inode pointers and vnode pointers
169  */
170 #define VTOI(vp)	((struct inode *)(vp)->v_data)
171 #define ITOV(ip)	(&(ip)->i_vnode)
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  */
186 #define	ILOCK(ip) { \
187 	while ((ip)->i_flag & ILOCKED) { \
188 		(ip)->i_flag |= IWANT; \
189 		(void) sleep((caddr_t)(ip), PINOD); \
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) { \
203 	if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
204 		(void) iupdat(ip, t1, t2, waitfor); \
205 }
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 }
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
229