xref: /csrg-svn/sys/ufs/ffs/inode.h (revision 54102)
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*54102Smckusick  *	@(#)inode.h	7.26 (Berkeley) 06/19/92
823419Smckusick  */
958Sbill 
1051505Sbostic #include <ufs/ufs/dinode.h>
1139387Smckusick 
1258Sbill /*
1353061Smckusick  * Theoretically, directories can be more than 2Gb in length,
1453061Smckusick  * however, in practice this seems unlikely. So, we define
1553061Smckusick  * the type doff_t as a long to keep down the cost of doing
1653061Smckusick  * lookup on a 32-bit machine. If you are porting to a 64-bit
1753061Smckusick  * architecture, you should make doff_t the same as off_t.
1853061Smckusick  */
1953061Smckusick #define doff_t	long
2053061Smckusick 
2153061Smckusick /*
2249448Smckusick  * The inode is used to describe each active (or recently active)
2349448Smckusick  * file in the UFS filesystem. It is composed of two types of
2449448Smckusick  * information. The first part is the information that is needed
2549448Smckusick  * only while the file is active (such as the identity of the file
2649448Smckusick  * and linkage to speed its lookup). The second part is the
2749448Smckusick  * permannent meta-data associated with the file which is read
2849448Smckusick  * in from the permanent dinode from long term storage when the
2949448Smckusick  * file becomes active, and is put back when the file is no longer
3049448Smckusick  * being used.
3158Sbill  */
324814Swnj struct inode {
3339387Smckusick 	struct	inode *i_chain[2]; /* hash chain, MUST be first */
3439387Smckusick 	struct	vnode *i_vnode;	/* vnode associated with this inode */
3537714Smckusick 	struct	vnode *i_devvp;	/* vnode for block I/O */
3639812Smckusick 	u_long	i_flag;		/* see below */
3758Sbill 	dev_t	i_dev;		/* device where inode resides */
3849448Smckusick 	ino_t	i_number;	/* the identity of the inode */
3951505Sbostic 	union {			/* associated filesystem */
4051505Sbostic 		struct	fs *fs;		/* FFS */
4151505Sbostic 		struct	lfs *lfs;	/* LFS */
4251505Sbostic 	} inode_u;
4351505Sbostic #define	i_fs	inode_u.fs
4451505Sbostic #define	i_lfs	inode_u.lfs
4545418Smckusick 	struct	dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */
4653764Smckusick 	u_quad_t i_modrev;	/* revision level for lease */
4749448Smckusick 	struct	lockf *i_lockf;	/* head of byte-level lock list */
4851974Smckusick 	pid_t	i_lockholder;	/* DEBUG: holder of inode lock */
4951974Smckusick 	pid_t	i_lockwaiter;	/* DEBUG: latest blocked for inode lock */
5052334Smckusick 	/*
5152334Smckusick 	 * Side effects; used during directory lookup.
5252334Smckusick 	 */
5353061Smckusick 	doff_t	i_endoff;	/* end of useful stuff in directory */
5453061Smckusick 	doff_t	i_diroff;	/* offset in dir, where we found last entry */
5553061Smckusick 	doff_t	i_offset;	/* offset of free space in directory */
5652334Smckusick 	long	i_count;	/* size of free slot in directory */
5752334Smckusick 	ino_t	i_ino;		/* inode number of found directory */
5852334Smckusick 	u_long	i_reclen;	/* size of found directory entry */
5952334Smckusick 	/*
6052334Smckusick 	 * the on-disk dinode itself.
6152334Smckusick 	 */
6249448Smckusick 	struct	dinode i_din;	/* the on-disk dinode */
6352334Smckusick 	long	i_spare[12];	/* spares to round up to 256 bytes */
6458Sbill };
6558Sbill 
6639387Smckusick #define	i_mode		i_din.di_mode
6739387Smckusick #define	i_nlink		i_din.di_nlink
6839387Smckusick #define	i_uid		i_din.di_uid
6939387Smckusick #define	i_gid		i_din.di_gid
7052021Smckusick #ifdef _NOQUAD
7152021Smckusick #define i_size	i_din.di_qsize.val[_QUAD_LOWWORD]
7252021Smckusick #else
7352021Smckusick #define i_size	i_din.di_qsize
7452021Smckusick #endif
7552021Smckusick #if defined(tahoe) /* ugh! -- must be fixed */
7652021Smckusick #undef i_size
7739387Smckusick #define	i_size		i_din.di_qsize.val[0]
789790Ssam #endif
7939387Smckusick #define	i_db		i_din.di_db
8039387Smckusick #define	i_ib		i_din.di_ib
8139387Smckusick #define	i_atime		i_din.di_atime
8239387Smckusick #define	i_mtime		i_din.di_mtime
8339387Smckusick #define	i_ctime		i_din.di_ctime
8439387Smckusick #define i_blocks	i_din.di_blocks
8539387Smckusick #define	i_rdev		i_din.di_db[0]
8639387Smckusick #define i_flags		i_din.di_flags
8739387Smckusick #define i_gen		i_din.di_gen
887333Skre #define	i_forw		i_chain[0]
897333Skre #define	i_back		i_chain[1]
906565Smckusic 
9158Sbill /* flags */
9239854Smckusick #define	ILOCKED		0x0001		/* inode is locked */
9339854Smckusick #define	IWANT		0x0002		/* some process waiting on lock */
9439854Smckusick #define	IRENAME		0x0004		/* inode is being renamed */
9539854Smckusick #define	IUPD		0x0010		/* file has been modified */
9639854Smckusick #define	IACC		0x0020		/* inode access time to be updated */
9739854Smckusick #define	ICHG		0x0040		/* inode has been changed */
9839854Smckusick #define	IMOD		0x0080		/* inode has been modified */
9939854Smckusick #define	ISHLOCK		0x0100		/* file has shared lock */
10039854Smckusick #define	IEXLOCK		0x0200		/* file has exclusive lock */
10139854Smckusick #define	ILWAIT		0x0400		/* someone waiting on file lock */
10258Sbill 
10337714Smckusick #ifdef KERNEL
10451505Sbostic /* Convert between inode pointers and vnode pointers. */
10537714Smckusick #define VTOI(vp)	((struct inode *)(vp)->v_data)
10639387Smckusick #define ITOV(ip)	((ip)->i_vnode)
10737714Smckusick 
10851505Sbostic /* Lock and unlock inodes. */
10939796Smckusick #ifdef notdef
1108467Sroot #define	ILOCK(ip) { \
1118467Sroot 	while ((ip)->i_flag & ILOCKED) { \
1128467Sroot 		(ip)->i_flag |= IWANT; \
11337714Smckusick 		(void) sleep((caddr_t)(ip), PINOD); \
1148467Sroot 	} \
1158467Sroot 	(ip)->i_flag |= ILOCKED; \
1168467Sroot }
1178467Sroot 
1188467Sroot #define	IUNLOCK(ip) { \
1198467Sroot 	(ip)->i_flag &= ~ILOCKED; \
1208467Sroot 	if ((ip)->i_flag&IWANT) { \
1218467Sroot 		(ip)->i_flag &= ~IWANT; \
1228467Sroot 		wakeup((caddr_t)(ip)); \
1238467Sroot 	} \
1248467Sroot }
12539796Smckusick #else
12651505Sbostic #define ILOCK(ip)	ufs_ilock(ip)
12751505Sbostic #define IUNLOCK(ip)	ufs_iunlock(ip)
12839796Smckusick #endif
1298467Sroot 
13016057Skarels #define	ITIMES(ip, t1, t2) { \
13116057Skarels 	if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
13216057Skarels 		(ip)->i_flag |= IMOD; \
13316057Skarels 		if ((ip)->i_flag&IACC) \
134*54102Smckusick 			(ip)->i_atime.ts_sec = (t1)->tv_sec; \
13552021Smckusick 		if ((ip)->i_flag&IUPD) { \
136*54102Smckusick 			(ip)->i_mtime.ts_sec = (t2)->tv_sec; \
13752021Smckusick 			INCRQUAD((ip)->i_modrev); \
13852021Smckusick 		} \
13916057Skarels 		if ((ip)->i_flag&ICHG) \
140*54102Smckusick 			(ip)->i_ctime.ts_sec = time.tv_sec; \
14116057Skarels 		(ip)->i_flag &= ~(IACC|IUPD|ICHG); \
14216057Skarels 	} \
14316057Skarels }
14437714Smckusick 
14551505Sbostic /* This overlays the fid structure (see mount.h). */
14637714Smckusick struct ufid {
14739387Smckusick 	u_short	ufid_len;	/* length of structure */
14839387Smckusick 	u_short	ufid_pad;	/* force long alignment */
14939387Smckusick 	ino_t	ufid_ino;	/* file number (ino) */
15039387Smckusick 	long	ufid_gen;	/* generation number */
15137714Smckusick };
15248031Smckusick #endif /* KERNEL */
153