xref: /csrg-svn/sys/ufs/ffs/inode.h (revision 55410)
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*55410Smckusick  *	@(#)inode.h	7.29 (Berkeley) 07/20/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 {
33*55410Smckusick 	struct	inode *i_next;	/* hash chain forward */
34*55410Smckusick 	struct	inode **i_prev;	/* hash chain back */
3539387Smckusick 	struct	vnode *i_vnode;	/* vnode associated with this inode */
3637714Smckusick 	struct	vnode *i_devvp;	/* vnode for block I/O */
3739812Smckusick 	u_long	i_flag;		/* see below */
3858Sbill 	dev_t	i_dev;		/* device where inode resides */
3949448Smckusick 	ino_t	i_number;	/* the identity of the inode */
4051505Sbostic 	union {			/* associated filesystem */
4151505Sbostic 		struct	fs *fs;		/* FFS */
4251505Sbostic 		struct	lfs *lfs;	/* LFS */
4351505Sbostic 	} inode_u;
4451505Sbostic #define	i_fs	inode_u.fs
4551505Sbostic #define	i_lfs	inode_u.lfs
4645418Smckusick 	struct	dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */
4753764Smckusick 	u_quad_t i_modrev;	/* revision level for lease */
4849448Smckusick 	struct	lockf *i_lockf;	/* head of byte-level lock list */
4951974Smckusick 	pid_t	i_lockholder;	/* DEBUG: holder of inode lock */
5051974Smckusick 	pid_t	i_lockwaiter;	/* DEBUG: latest blocked for inode lock */
5152334Smckusick 	/*
5252334Smckusick 	 * Side effects; used during directory lookup.
5352334Smckusick 	 */
5453061Smckusick 	doff_t	i_endoff;	/* end of useful stuff in directory */
5553061Smckusick 	doff_t	i_diroff;	/* offset in dir, where we found last entry */
5653061Smckusick 	doff_t	i_offset;	/* offset of free space in directory */
5752334Smckusick 	long	i_count;	/* size of free slot in directory */
5852334Smckusick 	ino_t	i_ino;		/* inode number of found directory */
5952334Smckusick 	u_long	i_reclen;	/* size of found directory entry */
6052334Smckusick 	/*
6152334Smckusick 	 * the on-disk dinode itself.
6252334Smckusick 	 */
6349448Smckusick 	struct	dinode i_din;	/* the on-disk dinode */
6452334Smckusick 	long	i_spare[12];	/* spares to round up to 256 bytes */
6558Sbill };
6658Sbill 
6739387Smckusick #define	i_mode		i_din.di_mode
6839387Smckusick #define	i_nlink		i_din.di_nlink
6939387Smckusick #define	i_uid		i_din.di_uid
7039387Smckusick #define	i_gid		i_din.di_gid
7154126Smckusick #define i_size		i_din.di_size
7239387Smckusick #define	i_db		i_din.di_db
7339387Smckusick #define	i_ib		i_din.di_ib
7439387Smckusick #define	i_atime		i_din.di_atime
7539387Smckusick #define	i_mtime		i_din.di_mtime
7639387Smckusick #define	i_ctime		i_din.di_ctime
7739387Smckusick #define i_blocks	i_din.di_blocks
7854302Smckusick #define	i_rdev		i_din.di_rdev
7954302Smckusick #define	i_shortlink	i_din.di_shortlink
8039387Smckusick #define i_flags		i_din.di_flags
8139387Smckusick #define i_gen		i_din.di_gen
826565Smckusic 
8358Sbill /* flags */
8439854Smckusick #define	ILOCKED		0x0001		/* inode is locked */
8539854Smckusick #define	IWANT		0x0002		/* some process waiting on lock */
8639854Smckusick #define	IRENAME		0x0004		/* inode is being renamed */
8739854Smckusick #define	IUPD		0x0010		/* file has been modified */
8839854Smckusick #define	IACC		0x0020		/* inode access time to be updated */
8939854Smckusick #define	ICHG		0x0040		/* inode has been changed */
9039854Smckusick #define	IMOD		0x0080		/* inode has been modified */
9139854Smckusick #define	ISHLOCK		0x0100		/* file has shared lock */
9239854Smckusick #define	IEXLOCK		0x0200		/* file has exclusive lock */
9339854Smckusick #define	ILWAIT		0x0400		/* someone waiting on file lock */
9458Sbill 
9537714Smckusick #ifdef KERNEL
9651505Sbostic /* Convert between inode pointers and vnode pointers. */
9737714Smckusick #define VTOI(vp)	((struct inode *)(vp)->v_data)
9839387Smckusick #define ITOV(ip)	((ip)->i_vnode)
9937714Smckusick 
10051505Sbostic /* Lock and unlock inodes. */
10139796Smckusick #ifdef notdef
1028467Sroot #define	ILOCK(ip) { \
1038467Sroot 	while ((ip)->i_flag & ILOCKED) { \
1048467Sroot 		(ip)->i_flag |= IWANT; \
10537714Smckusick 		(void) sleep((caddr_t)(ip), PINOD); \
1068467Sroot 	} \
1078467Sroot 	(ip)->i_flag |= ILOCKED; \
1088467Sroot }
1098467Sroot 
1108467Sroot #define	IUNLOCK(ip) { \
1118467Sroot 	(ip)->i_flag &= ~ILOCKED; \
1128467Sroot 	if ((ip)->i_flag&IWANT) { \
1138467Sroot 		(ip)->i_flag &= ~IWANT; \
1148467Sroot 		wakeup((caddr_t)(ip)); \
1158467Sroot 	} \
1168467Sroot }
11739796Smckusick #else
11851505Sbostic #define ILOCK(ip)	ufs_ilock(ip)
11951505Sbostic #define IUNLOCK(ip)	ufs_iunlock(ip)
12039796Smckusick #endif
1218467Sroot 
12216057Skarels #define	ITIMES(ip, t1, t2) { \
12316057Skarels 	if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
12416057Skarels 		(ip)->i_flag |= IMOD; \
12516057Skarels 		if ((ip)->i_flag&IACC) \
12654102Smckusick 			(ip)->i_atime.ts_sec = (t1)->tv_sec; \
12752021Smckusick 		if ((ip)->i_flag&IUPD) { \
12854102Smckusick 			(ip)->i_mtime.ts_sec = (t2)->tv_sec; \
12954126Smckusick 			(ip)->i_modrev++; \
13052021Smckusick 		} \
13116057Skarels 		if ((ip)->i_flag&ICHG) \
13254102Smckusick 			(ip)->i_ctime.ts_sec = time.tv_sec; \
13316057Skarels 		(ip)->i_flag &= ~(IACC|IUPD|ICHG); \
13416057Skarels 	} \
13516057Skarels }
13637714Smckusick 
13751505Sbostic /* This overlays the fid structure (see mount.h). */
13837714Smckusick struct ufid {
13939387Smckusick 	u_short	ufid_len;	/* length of structure */
14039387Smckusick 	u_short	ufid_pad;	/* force long alignment */
14139387Smckusick 	ino_t	ufid_ino;	/* file number (ino) */
14239387Smckusick 	long	ufid_gen;	/* generation number */
14337714Smckusick };
14448031Smckusick #endif /* KERNEL */
145