xref: /original-bsd/sys/ufs/ffs/inode.h (revision 95b555db)
1 /*
2  * Copyright (c) 1982, 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)inode.h	7.16 (Berkeley) 04/16/91
8  */
9 
10 #ifdef KERNEL
11 #include "../ufs/dinode.h"
12 #else
13 #include <ufs/dinode.h>
14 #endif
15 
16 /*
17  * The I node is the focus of all file activity in UNIX.
18  * There is a unique inode allocated for each active file,
19  * each current directory, each mounted-on file, text file, and the root.
20  * An inode is 'named' by its dev/inumber pair. (iget/iget.c)
21  * Data in `struct dinode' is read in from permanent inode on volume.
22  */
23 
24 struct inode {
25 	struct	inode *i_chain[2]; /* hash chain, MUST be first */
26 	struct	vnode *i_vnode;	/* vnode associated with this inode */
27 	struct	vnode *i_devvp;	/* vnode for block I/O */
28 	u_long	i_flag;		/* see below */
29 	dev_t	i_dev;		/* device where inode resides */
30 	ino_t	i_number;	/* i number, 1-to-1 with device address */
31 	struct	fs *i_fs;	/* file sys associated with this inode */
32 	struct	dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */
33 	struct	lockf *i_lockf;	/* Head of byte-level lock list */
34 	long	i_diroff;	/* offset in dir, where we found last entry */
35 	off_t	i_endoff;	/* end of useful stuff in directory */
36 	long	i_spare0;
37 	long	i_spare1;
38 	struct	dinode i_din;	/* the on-disk inode */
39 };
40 
41 #define	i_mode		i_din.di_mode
42 #define	i_nlink		i_din.di_nlink
43 #define	i_uid		i_din.di_uid
44 #define	i_gid		i_din.di_gid
45 #if BYTE_ORDER == LITTLE_ENDIAN || defined(tahoe) /* ugh! -- must be fixed */
46 #define	i_size		i_din.di_qsize.val[0]
47 #else /* BYTE_ORDER == BIG_ENDIAN */
48 #define	i_size		i_din.di_qsize.val[1]
49 #endif
50 #define	i_db		i_din.di_db
51 #define	i_ib		i_din.di_ib
52 #define	i_atime		i_din.di_atime
53 #define	i_mtime		i_din.di_mtime
54 #define	i_ctime		i_din.di_ctime
55 #define i_blocks	i_din.di_blocks
56 #define	i_rdev		i_din.di_db[0]
57 #define i_flags		i_din.di_flags
58 #define i_gen		i_din.di_gen
59 #define	i_forw		i_chain[0]
60 #define	i_back		i_chain[1]
61 
62 /* flags */
63 #define	ILOCKED		0x0001		/* inode is locked */
64 #define	IWANT		0x0002		/* some process waiting on lock */
65 #define	IRENAME		0x0004		/* inode is being renamed */
66 #define	IUPD		0x0010		/* file has been modified */
67 #define	IACC		0x0020		/* inode access time to be updated */
68 #define	ICHG		0x0040		/* inode has been changed */
69 #define	IMOD		0x0080		/* inode has been modified */
70 #define	ISHLOCK		0x0100		/* file has shared lock */
71 #define	IEXLOCK		0x0200		/* file has exclusive lock */
72 #define	ILWAIT		0x0400		/* someone waiting on file lock */
73 
74 #ifdef KERNEL
75 /*
76  * Convert between inode pointers and vnode pointers
77  */
78 #define VTOI(vp)	((struct inode *)(vp)->v_data)
79 #define ITOV(ip)	((ip)->i_vnode)
80 
81 /*
82  * Convert between vnode types and inode formats
83  */
84 extern enum vtype	iftovt_tab[];
85 extern int		vttoif_tab[];
86 #define IFTOVT(mode)	(iftovt_tab[((mode) & IFMT) >> 12])
87 #define VTTOIF(indx)	(vttoif_tab[(int)(indx)])
88 
89 #define MAKEIMODE(indx, mode)	(int)(VTTOIF(indx) | (mode))
90 
91 u_long	nextgennumber;		/* next generation number to assign */
92 
93 extern ino_t	dirpref();
94 
95 /*
96  * Lock and unlock inodes.
97  */
98 #ifdef notdef
99 #define	ILOCK(ip) { \
100 	while ((ip)->i_flag & ILOCKED) { \
101 		(ip)->i_flag |= IWANT; \
102 		(void) sleep((caddr_t)(ip), PINOD); \
103 	} \
104 	(ip)->i_flag |= ILOCKED; \
105 }
106 
107 #define	IUNLOCK(ip) { \
108 	(ip)->i_flag &= ~ILOCKED; \
109 	if ((ip)->i_flag&IWANT) { \
110 		(ip)->i_flag &= ~IWANT; \
111 		wakeup((caddr_t)(ip)); \
112 	} \
113 }
114 #else
115 #define ILOCK(ip)	ilock(ip)
116 #define IUNLOCK(ip)	iunlock(ip)
117 #endif
118 
119 #define	IUPDAT(ip, t1, t2, waitfor) { \
120 	if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
121 		(void) iupdat(ip, t1, t2, waitfor); \
122 }
123 
124 #define	ITIMES(ip, t1, t2) { \
125 	if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
126 		(ip)->i_flag |= IMOD; \
127 		if ((ip)->i_flag&IACC) \
128 			(ip)->i_atime = (t1)->tv_sec; \
129 		if ((ip)->i_flag&IUPD) \
130 			(ip)->i_mtime = (t2)->tv_sec; \
131 		if ((ip)->i_flag&ICHG) \
132 			(ip)->i_ctime = time.tv_sec; \
133 		(ip)->i_flag &= ~(IACC|IUPD|ICHG); \
134 	} \
135 }
136 
137 /*
138  * This overlays the fid sturcture (see mount.h)
139  */
140 struct ufid {
141 	u_short	ufid_len;	/* length of structure */
142 	u_short	ufid_pad;	/* force long alignment */
143 	ino_t	ufid_ino;	/* file number (ino) */
144 	long	ufid_gen;	/* generation number */
145 };
146 
147 /*
148  * Prototypes for UFS vnode operations
149  */
150 int	ufs_lookup __P((
151 		struct vnode *vp,
152 		struct nameidata *ndp,
153 		struct proc *p));
154 int	ufs_create __P((
155 		struct nameidata *ndp,
156 		struct vattr *vap,
157 		struct proc *p));
158 int	ufs_mknod __P((
159 		struct nameidata *ndp,
160 		struct vattr *vap,
161 		struct ucred *cred,
162 		struct proc *p));
163 int	ufs_open __P((
164 		struct vnode *vp,
165 		int mode,
166 		struct ucred *cred,
167 		struct proc *p));
168 int	ufs_close __P((
169 		struct vnode *vp,
170 		int fflag,
171 		struct ucred *cred,
172 		struct proc *p));
173 int	ufs_access __P((
174 		struct vnode *vp,
175 		int mode,
176 		struct ucred *cred,
177 		struct proc *p));
178 int	ufs_getattr __P((
179 		struct vnode *vp,
180 		struct vattr *vap,
181 		struct ucred *cred,
182 		struct proc *p));
183 int	ufs_setattr __P((
184 		struct vnode *vp,
185 		struct vattr *vap,
186 		struct ucred *cred,
187 		struct proc *p));
188 int	ufs_read __P((
189 		struct vnode *vp,
190 		struct uio *uio,
191 		int ioflag,
192 		struct ucred *cred));
193 int	ufs_write __P((
194 		struct vnode *vp,
195 		struct uio *uio,
196 		int ioflag,
197 		struct ucred *cred));
198 int	ufs_ioctl __P((
199 		struct vnode *vp,
200 		int command,
201 		caddr_t data,
202 		int fflag,
203 		struct ucred *cred,
204 		struct proc *p));
205 int	ufs_select __P((
206 		struct vnode *vp,
207 		int which,
208 		int fflags,
209 		struct ucred *cred,
210 		struct proc *p));
211 int	ufs_mmap __P((
212 		struct vnode *vp,
213 		int fflags,
214 		struct ucred *cred,
215 		struct proc *p));
216 int	ufs_fsync __P((
217 		struct vnode *vp,
218 		int fflags,
219 		struct ucred *cred,
220 		int waitfor,
221 		struct proc *p));
222 int	ufs_seek __P((
223 		struct vnode *vp,
224 		off_t oldoff,
225 		off_t newoff,
226 		struct ucred *cred));
227 int	ufs_remove __P((
228 		struct nameidata *ndp,
229 		struct proc *p));
230 int	ufs_link __P((
231 		struct vnode *vp,
232 		struct nameidata *ndp,
233 		struct proc *p));
234 int	ufs_rename __P((
235 		struct nameidata *fndp,
236 		struct nameidata *tdnp,
237 		struct proc *p));
238 int	ufs_mkdir __P((
239 		struct nameidata *ndp,
240 		struct vattr *vap,
241 		struct proc *p));
242 int	ufs_rmdir __P((
243 		struct nameidata *ndp,
244 		struct proc *p));
245 int	ufs_symlink __P((
246 		struct nameidata *ndp,
247 		struct vattr *vap,
248 		char *target,
249 		struct proc *p));
250 int	ufs_readdir __P((
251 		struct vnode *vp,
252 		struct uio *uio,
253 		struct ucred *cred,
254 		int *eofflagp));
255 int	ufs_readlink __P((
256 		struct vnode *vp,
257 		struct uio *uio,
258 		struct ucred *cred));
259 int	ufs_abortop __P((
260 		struct nameidata *ndp));
261 int	ufs_inactive __P((
262 		struct vnode *vp,
263 		struct proc *p));
264 int	ufs_reclaim __P((
265 		struct vnode *vp));
266 int	ufs_lock __P((
267 		struct vnode *vp));
268 int	ufs_unlock __P((
269 		struct vnode *vp));
270 int	ufs_bmap __P((
271 		struct vnode *vp,
272 		daddr_t bn,
273 		struct vnode **vpp,
274 		daddr_t *bnp));
275 int	ufs_strategy __P((
276 		struct buf *bp));
277 int	ufs_print __P((
278 		struct vnode *vp));
279 int	ufs_islocked __P((
280 		struct vnode *vp));
281 int	ufs_advlock __P((
282 		struct vnode *vp,
283 		caddr_t id,
284 		int op,
285 		struct flock *fl,
286 		int flags));
287 #endif /* KERNEL */
288