xref: /csrg-svn/sys/ufs/ffs/inode.h (revision 48031)
123419Smckusick /*
237714Smckusick  * Copyright (c) 1982, 1989 The Regents of the University of California.
337714Smckusick  * All rights reserved.
423419Smckusick  *
541535Smckusick  * %sccs.include.redist.c%
637714Smckusick  *
7*48031Smckusick  *	@(#)inode.h	7.16 (Berkeley) 04/16/91
823419Smckusick  */
958Sbill 
1039387Smckusick #ifdef KERNEL
1139387Smckusick #include "../ufs/dinode.h"
1239387Smckusick #else
1339387Smckusick #include <ufs/dinode.h>
1439387Smckusick #endif
1539387Smckusick 
1658Sbill /*
174814Swnj  * The I node is the focus of all file activity in UNIX.
184814Swnj  * There is a unique inode allocated for each active file,
194814Swnj  * each current directory, each mounted-on file, text file, and the root.
204814Swnj  * An inode is 'named' by its dev/inumber pair. (iget/iget.c)
2139387Smckusick  * Data in `struct dinode' is read in from permanent inode on volume.
2258Sbill  */
2358Sbill 
244814Swnj struct inode {
2539387Smckusick 	struct	inode *i_chain[2]; /* hash chain, MUST be first */
2639387Smckusick 	struct	vnode *i_vnode;	/* vnode associated with this inode */
2737714Smckusick 	struct	vnode *i_devvp;	/* vnode for block I/O */
2839812Smckusick 	u_long	i_flag;		/* see below */
2958Sbill 	dev_t	i_dev;		/* device where inode resides */
3058Sbill 	ino_t	i_number;	/* i number, 1-to-1 with device address */
316565Smckusic 	struct	fs *i_fs;	/* file sys associated with this inode */
3245418Smckusick 	struct	dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */
3346202Smckusick 	struct	lockf *i_lockf;	/* Head of byte-level lock list */
3439387Smckusick 	long	i_diroff;	/* offset in dir, where we found last entry */
3537714Smckusick 	off_t	i_endoff;	/* end of useful stuff in directory */
3639812Smckusick 	long	i_spare0;
3739812Smckusick 	long	i_spare1;
3839387Smckusick 	struct	dinode i_din;	/* the on-disk inode */
3958Sbill };
4058Sbill 
4139387Smckusick #define	i_mode		i_din.di_mode
4239387Smckusick #define	i_nlink		i_din.di_nlink
4339387Smckusick #define	i_uid		i_din.di_uid
4439387Smckusick #define	i_gid		i_din.di_gid
4541535Smckusick #if BYTE_ORDER == LITTLE_ENDIAN || defined(tahoe) /* ugh! -- must be fixed */
4639387Smckusick #define	i_size		i_din.di_qsize.val[0]
4741535Smckusick #else /* BYTE_ORDER == BIG_ENDIAN */
4841535Smckusick #define	i_size		i_din.di_qsize.val[1]
499790Ssam #endif
5039387Smckusick #define	i_db		i_din.di_db
5139387Smckusick #define	i_ib		i_din.di_ib
5239387Smckusick #define	i_atime		i_din.di_atime
5339387Smckusick #define	i_mtime		i_din.di_mtime
5439387Smckusick #define	i_ctime		i_din.di_ctime
5539387Smckusick #define i_blocks	i_din.di_blocks
5639387Smckusick #define	i_rdev		i_din.di_db[0]
5739387Smckusick #define i_flags		i_din.di_flags
5839387Smckusick #define i_gen		i_din.di_gen
597333Skre #define	i_forw		i_chain[0]
607333Skre #define	i_back		i_chain[1]
616565Smckusic 
6258Sbill /* flags */
6339854Smckusick #define	ILOCKED		0x0001		/* inode is locked */
6439854Smckusick #define	IWANT		0x0002		/* some process waiting on lock */
6539854Smckusick #define	IRENAME		0x0004		/* inode is being renamed */
6639854Smckusick #define	IUPD		0x0010		/* file has been modified */
6739854Smckusick #define	IACC		0x0020		/* inode access time to be updated */
6839854Smckusick #define	ICHG		0x0040		/* inode has been changed */
6939854Smckusick #define	IMOD		0x0080		/* inode has been modified */
7039854Smckusick #define	ISHLOCK		0x0100		/* file has shared lock */
7139854Smckusick #define	IEXLOCK		0x0200		/* file has exclusive lock */
7239854Smckusick #define	ILWAIT		0x0400		/* someone waiting on file lock */
7358Sbill 
7437714Smckusick #ifdef KERNEL
7537714Smckusick /*
7637714Smckusick  * Convert between inode pointers and vnode pointers
7737714Smckusick  */
7837714Smckusick #define VTOI(vp)	((struct inode *)(vp)->v_data)
7939387Smckusick #define ITOV(ip)	((ip)->i_vnode)
8037714Smckusick 
8137714Smckusick /*
8237714Smckusick  * Convert between vnode types and inode formats
8337714Smckusick  */
8437714Smckusick extern enum vtype	iftovt_tab[];
8537714Smckusick extern int		vttoif_tab[];
8640287Smckusick #define IFTOVT(mode)	(iftovt_tab[((mode) & IFMT) >> 12])
8737714Smckusick #define VTTOIF(indx)	(vttoif_tab[(int)(indx)])
8837714Smckusick 
8937714Smckusick #define MAKEIMODE(indx, mode)	(int)(VTTOIF(indx) | (mode))
9037714Smckusick 
9139436Smckusick u_long	nextgennumber;		/* next generation number to assign */
9239436Smckusick 
9339436Smckusick extern ino_t	dirpref();
9439436Smckusick 
9537714Smckusick /*
9637714Smckusick  * Lock and unlock inodes.
9737714Smckusick  */
9839796Smckusick #ifdef notdef
998467Sroot #define	ILOCK(ip) { \
1008467Sroot 	while ((ip)->i_flag & ILOCKED) { \
1018467Sroot 		(ip)->i_flag |= IWANT; \
10237714Smckusick 		(void) sleep((caddr_t)(ip), PINOD); \
1038467Sroot 	} \
1048467Sroot 	(ip)->i_flag |= ILOCKED; \
1058467Sroot }
1068467Sroot 
1078467Sroot #define	IUNLOCK(ip) { \
1088467Sroot 	(ip)->i_flag &= ~ILOCKED; \
1098467Sroot 	if ((ip)->i_flag&IWANT) { \
1108467Sroot 		(ip)->i_flag &= ~IWANT; \
1118467Sroot 		wakeup((caddr_t)(ip)); \
1128467Sroot 	} \
1138467Sroot }
11439796Smckusick #else
11539796Smckusick #define ILOCK(ip)	ilock(ip)
11639796Smckusick #define IUNLOCK(ip)	iunlock(ip)
11739796Smckusick #endif
1188467Sroot 
1198467Sroot #define	IUPDAT(ip, t1, t2, waitfor) { \
12016057Skarels 	if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
12137714Smckusick 		(void) iupdat(ip, t1, t2, waitfor); \
1228467Sroot }
12316057Skarels 
12416057Skarels #define	ITIMES(ip, t1, t2) { \
12516057Skarels 	if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
12616057Skarels 		(ip)->i_flag |= IMOD; \
12716057Skarels 		if ((ip)->i_flag&IACC) \
12816057Skarels 			(ip)->i_atime = (t1)->tv_sec; \
12916057Skarels 		if ((ip)->i_flag&IUPD) \
13016057Skarels 			(ip)->i_mtime = (t2)->tv_sec; \
13116057Skarels 		if ((ip)->i_flag&ICHG) \
13216057Skarels 			(ip)->i_ctime = time.tv_sec; \
13316057Skarels 		(ip)->i_flag &= ~(IACC|IUPD|ICHG); \
13416057Skarels 	} \
13516057Skarels }
13637714Smckusick 
13737714Smckusick /*
13837714Smckusick  * This overlays the fid sturcture (see mount.h)
13937714Smckusick  */
14037714Smckusick struct ufid {
14139387Smckusick 	u_short	ufid_len;	/* length of structure */
14239387Smckusick 	u_short	ufid_pad;	/* force long alignment */
14339387Smckusick 	ino_t	ufid_ino;	/* file number (ino) */
14439387Smckusick 	long	ufid_gen;	/* generation number */
14537714Smckusick };
146*48031Smckusick 
147*48031Smckusick /*
148*48031Smckusick  * Prototypes for UFS vnode operations
149*48031Smckusick  */
150*48031Smckusick int	ufs_lookup __P((
151*48031Smckusick 		struct vnode *vp,
152*48031Smckusick 		struct nameidata *ndp,
153*48031Smckusick 		struct proc *p));
154*48031Smckusick int	ufs_create __P((
155*48031Smckusick 		struct nameidata *ndp,
156*48031Smckusick 		struct vattr *vap,
157*48031Smckusick 		struct proc *p));
158*48031Smckusick int	ufs_mknod __P((
159*48031Smckusick 		struct nameidata *ndp,
160*48031Smckusick 		struct vattr *vap,
161*48031Smckusick 		struct ucred *cred,
162*48031Smckusick 		struct proc *p));
163*48031Smckusick int	ufs_open __P((
164*48031Smckusick 		struct vnode *vp,
165*48031Smckusick 		int mode,
166*48031Smckusick 		struct ucred *cred,
167*48031Smckusick 		struct proc *p));
168*48031Smckusick int	ufs_close __P((
169*48031Smckusick 		struct vnode *vp,
170*48031Smckusick 		int fflag,
171*48031Smckusick 		struct ucred *cred,
172*48031Smckusick 		struct proc *p));
173*48031Smckusick int	ufs_access __P((
174*48031Smckusick 		struct vnode *vp,
175*48031Smckusick 		int mode,
176*48031Smckusick 		struct ucred *cred,
177*48031Smckusick 		struct proc *p));
178*48031Smckusick int	ufs_getattr __P((
179*48031Smckusick 		struct vnode *vp,
180*48031Smckusick 		struct vattr *vap,
181*48031Smckusick 		struct ucred *cred,
182*48031Smckusick 		struct proc *p));
183*48031Smckusick int	ufs_setattr __P((
184*48031Smckusick 		struct vnode *vp,
185*48031Smckusick 		struct vattr *vap,
186*48031Smckusick 		struct ucred *cred,
187*48031Smckusick 		struct proc *p));
188*48031Smckusick int	ufs_read __P((
189*48031Smckusick 		struct vnode *vp,
190*48031Smckusick 		struct uio *uio,
191*48031Smckusick 		int ioflag,
192*48031Smckusick 		struct ucred *cred));
193*48031Smckusick int	ufs_write __P((
194*48031Smckusick 		struct vnode *vp,
195*48031Smckusick 		struct uio *uio,
196*48031Smckusick 		int ioflag,
197*48031Smckusick 		struct ucred *cred));
198*48031Smckusick int	ufs_ioctl __P((
199*48031Smckusick 		struct vnode *vp,
200*48031Smckusick 		int command,
201*48031Smckusick 		caddr_t data,
202*48031Smckusick 		int fflag,
203*48031Smckusick 		struct ucred *cred,
204*48031Smckusick 		struct proc *p));
205*48031Smckusick int	ufs_select __P((
206*48031Smckusick 		struct vnode *vp,
207*48031Smckusick 		int which,
208*48031Smckusick 		int fflags,
209*48031Smckusick 		struct ucred *cred,
210*48031Smckusick 		struct proc *p));
211*48031Smckusick int	ufs_mmap __P((
212*48031Smckusick 		struct vnode *vp,
213*48031Smckusick 		int fflags,
214*48031Smckusick 		struct ucred *cred,
215*48031Smckusick 		struct proc *p));
216*48031Smckusick int	ufs_fsync __P((
217*48031Smckusick 		struct vnode *vp,
218*48031Smckusick 		int fflags,
219*48031Smckusick 		struct ucred *cred,
220*48031Smckusick 		int waitfor,
221*48031Smckusick 		struct proc *p));
222*48031Smckusick int	ufs_seek __P((
223*48031Smckusick 		struct vnode *vp,
224*48031Smckusick 		off_t oldoff,
225*48031Smckusick 		off_t newoff,
226*48031Smckusick 		struct ucred *cred));
227*48031Smckusick int	ufs_remove __P((
228*48031Smckusick 		struct nameidata *ndp,
229*48031Smckusick 		struct proc *p));
230*48031Smckusick int	ufs_link __P((
231*48031Smckusick 		struct vnode *vp,
232*48031Smckusick 		struct nameidata *ndp,
233*48031Smckusick 		struct proc *p));
234*48031Smckusick int	ufs_rename __P((
235*48031Smckusick 		struct nameidata *fndp,
236*48031Smckusick 		struct nameidata *tdnp,
237*48031Smckusick 		struct proc *p));
238*48031Smckusick int	ufs_mkdir __P((
239*48031Smckusick 		struct nameidata *ndp,
240*48031Smckusick 		struct vattr *vap,
241*48031Smckusick 		struct proc *p));
242*48031Smckusick int	ufs_rmdir __P((
243*48031Smckusick 		struct nameidata *ndp,
244*48031Smckusick 		struct proc *p));
245*48031Smckusick int	ufs_symlink __P((
246*48031Smckusick 		struct nameidata *ndp,
247*48031Smckusick 		struct vattr *vap,
248*48031Smckusick 		char *target,
249*48031Smckusick 		struct proc *p));
250*48031Smckusick int	ufs_readdir __P((
251*48031Smckusick 		struct vnode *vp,
252*48031Smckusick 		struct uio *uio,
253*48031Smckusick 		struct ucred *cred,
254*48031Smckusick 		int *eofflagp));
255*48031Smckusick int	ufs_readlink __P((
256*48031Smckusick 		struct vnode *vp,
257*48031Smckusick 		struct uio *uio,
258*48031Smckusick 		struct ucred *cred));
259*48031Smckusick int	ufs_abortop __P((
260*48031Smckusick 		struct nameidata *ndp));
261*48031Smckusick int	ufs_inactive __P((
262*48031Smckusick 		struct vnode *vp,
263*48031Smckusick 		struct proc *p));
264*48031Smckusick int	ufs_reclaim __P((
265*48031Smckusick 		struct vnode *vp));
266*48031Smckusick int	ufs_lock __P((
267*48031Smckusick 		struct vnode *vp));
268*48031Smckusick int	ufs_unlock __P((
269*48031Smckusick 		struct vnode *vp));
270*48031Smckusick int	ufs_bmap __P((
271*48031Smckusick 		struct vnode *vp,
272*48031Smckusick 		daddr_t bn,
273*48031Smckusick 		struct vnode **vpp,
274*48031Smckusick 		daddr_t *bnp));
275*48031Smckusick int	ufs_strategy __P((
276*48031Smckusick 		struct buf *bp));
277*48031Smckusick int	ufs_print __P((
278*48031Smckusick 		struct vnode *vp));
279*48031Smckusick int	ufs_islocked __P((
280*48031Smckusick 		struct vnode *vp));
281*48031Smckusick int	ufs_advlock __P((
282*48031Smckusick 		struct vnode *vp,
283*48031Smckusick 		caddr_t id,
284*48031Smckusick 		int op,
285*48031Smckusick 		struct flock *fl,
286*48031Smckusick 		int flags));
287*48031Smckusick #endif /* KERNEL */
288