xref: /csrg-svn/sys/ufs/ffs/inode.h (revision 52021)
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*52021Smckusick  *	@(#)inode.h	7.20 (Berkeley) 12/19/91
823419Smckusick  */
958Sbill 
1051505Sbostic #include <ufs/ufs/dinode.h>
1139387Smckusick 
1258Sbill /*
1349448Smckusick  * The inode is used to describe each active (or recently active)
1449448Smckusick  * file in the UFS filesystem. It is composed of two types of
1549448Smckusick  * information. The first part is the information that is needed
1649448Smckusick  * only while the file is active (such as the identity of the file
1749448Smckusick  * and linkage to speed its lookup). The second part is the
1849448Smckusick  * permannent meta-data associated with the file which is read
1949448Smckusick  * in from the permanent dinode from long term storage when the
2049448Smckusick  * file becomes active, and is put back when the file is no longer
2149448Smckusick  * being used.
2258Sbill  */
234814Swnj struct inode {
2439387Smckusick 	struct	inode *i_chain[2]; /* hash chain, MUST be first */
2539387Smckusick 	struct	vnode *i_vnode;	/* vnode associated with this inode */
2637714Smckusick 	struct	vnode *i_devvp;	/* vnode for block I/O */
2739812Smckusick 	u_long	i_flag;		/* see below */
2858Sbill 	dev_t	i_dev;		/* device where inode resides */
2951974Smckusick 	short	i_pad;
3049448Smckusick 	ino_t	i_number;	/* the identity of the inode */
3151505Sbostic 	union {			/* associated filesystem */
3251505Sbostic 		struct	fs *fs;		/* FFS */
3351505Sbostic 		struct	lfs *lfs;	/* LFS */
3451505Sbostic 	} inode_u;
3551505Sbostic #define	i_fs	inode_u.fs
3651505Sbostic #define	i_lfs	inode_u.lfs
3745418Smckusick 	struct	dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */
3849448Smckusick 	struct	lockf *i_lockf;	/* head of byte-level lock list */
3939387Smckusick 	long	i_diroff;	/* offset in dir, where we found last entry */
4037714Smckusick 	off_t	i_endoff;	/* end of useful stuff in directory */
41*52021Smckusick 	u_quad_t i_modrev;	/* revision level for lease */
4251974Smckusick 	pid_t	i_lockholder;	/* DEBUG: holder of inode lock */
4351974Smckusick 	pid_t	i_lockwaiter;	/* DEBUG: latest blocked for inode lock */
4451974Smckusick 	long	i_spare[16];	/* spares to round up to 256 bytes */
4549448Smckusick 	struct	dinode i_din;	/* the on-disk dinode */
4658Sbill };
4758Sbill 
4839387Smckusick #define	i_mode		i_din.di_mode
4939387Smckusick #define	i_nlink		i_din.di_nlink
5039387Smckusick #define	i_uid		i_din.di_uid
5139387Smckusick #define	i_gid		i_din.di_gid
52*52021Smckusick #ifdef _NOQUAD
53*52021Smckusick #define i_size	i_din.di_qsize.val[_QUAD_LOWWORD]
54*52021Smckusick #else
55*52021Smckusick #define i_size	i_din.di_qsize
56*52021Smckusick #endif
57*52021Smckusick #if defined(tahoe) /* ugh! -- must be fixed */
58*52021Smckusick #undef i_size
5939387Smckusick #define	i_size		i_din.di_qsize.val[0]
609790Ssam #endif
6139387Smckusick #define	i_db		i_din.di_db
6239387Smckusick #define	i_ib		i_din.di_ib
6339387Smckusick #define	i_atime		i_din.di_atime
6439387Smckusick #define	i_mtime		i_din.di_mtime
6539387Smckusick #define	i_ctime		i_din.di_ctime
6639387Smckusick #define i_blocks	i_din.di_blocks
6739387Smckusick #define	i_rdev		i_din.di_db[0]
6839387Smckusick #define i_flags		i_din.di_flags
6939387Smckusick #define i_gen		i_din.di_gen
707333Skre #define	i_forw		i_chain[0]
717333Skre #define	i_back		i_chain[1]
726565Smckusic 
7358Sbill /* flags */
7439854Smckusick #define	ILOCKED		0x0001		/* inode is locked */
7539854Smckusick #define	IWANT		0x0002		/* some process waiting on lock */
7639854Smckusick #define	IRENAME		0x0004		/* inode is being renamed */
7739854Smckusick #define	IUPD		0x0010		/* file has been modified */
7839854Smckusick #define	IACC		0x0020		/* inode access time to be updated */
7939854Smckusick #define	ICHG		0x0040		/* inode has been changed */
8039854Smckusick #define	IMOD		0x0080		/* inode has been modified */
8139854Smckusick #define	ISHLOCK		0x0100		/* file has shared lock */
8239854Smckusick #define	IEXLOCK		0x0200		/* file has exclusive lock */
8339854Smckusick #define	ILWAIT		0x0400		/* someone waiting on file lock */
8458Sbill 
8537714Smckusick #ifdef KERNEL
8651505Sbostic /* Convert between inode pointers and vnode pointers. */
8737714Smckusick #define VTOI(vp)	((struct inode *)(vp)->v_data)
8839387Smckusick #define ITOV(ip)	((ip)->i_vnode)
8937714Smckusick 
9051505Sbostic /* Convert between vnode types and inode formats. */
9137714Smckusick extern enum vtype	iftovt_tab[];
9237714Smckusick extern int		vttoif_tab[];
9340287Smckusick #define IFTOVT(mode)	(iftovt_tab[((mode) & IFMT) >> 12])
9437714Smckusick #define VTTOIF(indx)	(vttoif_tab[(int)(indx)])
9537714Smckusick 
9637714Smckusick #define MAKEIMODE(indx, mode)	(int)(VTTOIF(indx) | (mode))
9737714Smckusick 
9851505Sbostic /* Lock and unlock inodes. */
9939796Smckusick #ifdef notdef
1008467Sroot #define	ILOCK(ip) { \
1018467Sroot 	while ((ip)->i_flag & ILOCKED) { \
1028467Sroot 		(ip)->i_flag |= IWANT; \
10337714Smckusick 		(void) sleep((caddr_t)(ip), PINOD); \
1048467Sroot 	} \
1058467Sroot 	(ip)->i_flag |= ILOCKED; \
1068467Sroot }
1078467Sroot 
1088467Sroot #define	IUNLOCK(ip) { \
1098467Sroot 	(ip)->i_flag &= ~ILOCKED; \
1108467Sroot 	if ((ip)->i_flag&IWANT) { \
1118467Sroot 		(ip)->i_flag &= ~IWANT; \
1128467Sroot 		wakeup((caddr_t)(ip)); \
1138467Sroot 	} \
1148467Sroot }
11539796Smckusick #else
11651505Sbostic #define ILOCK(ip)	ufs_ilock(ip)
11751505Sbostic #define IUNLOCK(ip)	ufs_iunlock(ip)
11839796Smckusick #endif
1198467Sroot 
12016057Skarels #define	ITIMES(ip, t1, t2) { \
12116057Skarels 	if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
12216057Skarels 		(ip)->i_flag |= IMOD; \
12316057Skarels 		if ((ip)->i_flag&IACC) \
12416057Skarels 			(ip)->i_atime = (t1)->tv_sec; \
125*52021Smckusick 		if ((ip)->i_flag&IUPD) { \
12616057Skarels 			(ip)->i_mtime = (t2)->tv_sec; \
127*52021Smckusick 			INCRQUAD((ip)->i_modrev); \
128*52021Smckusick 		} \
12916057Skarels 		if ((ip)->i_flag&ICHG) \
13016057Skarels 			(ip)->i_ctime = time.tv_sec; \
13116057Skarels 		(ip)->i_flag &= ~(IACC|IUPD|ICHG); \
13216057Skarels 	} \
13316057Skarels }
13437714Smckusick 
13551505Sbostic /* This overlays the fid structure (see mount.h). */
13637714Smckusick struct ufid {
13739387Smckusick 	u_short	ufid_len;	/* length of structure */
13839387Smckusick 	u_short	ufid_pad;	/* force long alignment */
13939387Smckusick 	ino_t	ufid_ino;	/* file number (ino) */
14039387Smckusick 	long	ufid_gen;	/* generation number */
14137714Smckusick };
14248031Smckusick #endif /* KERNEL */
143