xref: /csrg-svn/sys/ufs/ffs/inode.h (revision 64596)
123419Smckusick /*
263376Sbostic  * Copyright (c) 1982, 1989, 1993
363376Sbostic  *	The Regents of the University of California.  All rights reserved.
423419Smckusick  *
541535Smckusick  * %sccs.include.redist.c%
637714Smckusick  *
7*64596Sbostic  *	@(#)inode.h	8.3 (Berkeley) 09/23/93
823419Smckusick  */
958Sbill 
1051505Sbostic #include <ufs/ufs/dinode.h>
1139387Smckusick 
1258Sbill /*
1364513Sbostic  * Theoretically, directories can be more than 2Gb in length, however, in
1464513Sbostic  * practice this seems unlikely. So, we define the type doff_t as a long
1564513Sbostic  * to keep down the cost of doing lookup on a 32-bit machine. If you are
1664513Sbostic  * porting to a 64-bit architecture, you should make doff_t the same as off_t.
1753061Smckusick  */
1864513Sbostic #define	doff_t	long
1953061Smckusick 
2053061Smckusick /*
2149448Smckusick  * The inode is used to describe each active (or recently active)
2249448Smckusick  * file in the UFS filesystem. It is composed of two types of
2349448Smckusick  * information. The first part is the information that is needed
2449448Smckusick  * only while the file is active (such as the identity of the file
2549448Smckusick  * and linkage to speed its lookup). The second part is the
2649448Smckusick  * permannent meta-data associated with the file which is read
2749448Smckusick  * in from the permanent dinode from long term storage when the
2849448Smckusick  * file becomes active, and is put back when the file is no longer
2949448Smckusick  * being used.
3058Sbill  */
314814Swnj struct inode {
3264513Sbostic 	struct	inode *i_next;	/* Hash chain forward. */
3364513Sbostic 	struct	inode **i_prev;	/* Hash chain back. */
3464513Sbostic 	struct	vnode *i_vnode;	/* Vnode associated with this inode. */
3564513Sbostic 	struct	vnode *i_devvp;	/* Vnode for block I/O. */
3664513Sbostic 	u_long	i_flag;		/* I* flags. */
3764513Sbostic 	dev_t	i_dev;		/* Device associated with the inode. */
3864513Sbostic 	ino_t	i_number;	/* The identity of the inode. */
3964513Sbostic 	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
4564513Sbostic 	struct	dquot *i_dquot[MAXQUOTAS];	/* Dquot structures. */
4664513Sbostic 	u_quad_t i_modrev;	/* Revision level for lease. */
4764513Sbostic 	struct	lockf *i_lockf;	/* Head of byte-level lock list. */
4864513Sbostic 	pid_t	i_lockholder;	/* DEBUG: holder of inode lock. */
4964513Sbostic 	pid_t	i_lockwaiter;	/* DEBUG: latest blocked for inode lock. */
5052334Smckusick 	/*
5152334Smckusick 	 * Side effects; used during directory lookup.
5252334Smckusick 	 */
5364513Sbostic 	long	i_count;	/* Size of free slot in directory. */
5464513Sbostic 	doff_t	i_endoff;	/* End of useful stuff in directory. */
5564513Sbostic 	doff_t	i_diroff;	/* Offset in dir, where we found last entry. */
5664513Sbostic 	doff_t	i_offset;	/* Offset of free space in directory. */
5764513Sbostic 	ino_t	i_ino;		/* Inode number of found directory. */
5864513Sbostic 	u_long	i_reclen;	/* Size of found directory entry. */
5964513Sbostic 	long	i_spare[11];	/* Spares to round up to 128 bytes. */
6052334Smckusick 	/*
6164513Sbostic 	 * The on-disk dinode itself.
6252334Smckusick 	 */
6364513Sbostic 	struct	dinode i_din;	/* 128 bytes of the on-disk dinode. */
6458Sbill };
6558Sbill 
6664513Sbostic #define	i_atime		i_din.di_atime
6764513Sbostic #define	i_blocks	i_din.di_blocks
6864513Sbostic #define	i_ctime		i_din.di_ctime
6964513Sbostic #define	i_db		i_din.di_db
7064513Sbostic #define	i_flags		i_din.di_flags
7164513Sbostic #define	i_gen		i_din.di_gen
7239387Smckusick #define	i_gid		i_din.di_gid
7339387Smckusick #define	i_ib		i_din.di_ib
7464513Sbostic #define	i_mode		i_din.di_mode
7539387Smckusick #define	i_mtime		i_din.di_mtime
7664513Sbostic #define	i_nlink		i_din.di_nlink
7754302Smckusick #define	i_rdev		i_din.di_rdev
7854302Smckusick #define	i_shortlink	i_din.di_shortlink
7964513Sbostic #define	i_size		i_din.di_size
8064513Sbostic #define	i_uid		i_din.di_uid
816565Smckusic 
8264513Sbostic /* These flags are kept in i_flag. */
83*64596Sbostic #define	IN_ACCESS	0x0001		/* Access time update request. */
84*64596Sbostic #define	IN_CHANGE	0x0002		/* Inode change time update request. */
85*64596Sbostic #define	IN_EXLOCK	0x0004		/* File has exclusive lock. */
86*64596Sbostic #define	IN_LOCKED	0x0008		/* Inode lock. */
87*64596Sbostic #define	IN_LWAIT	0x0010		/* Process waiting on file lock. */
88*64596Sbostic #define	IN_MODIFIED	0x0020		/* Inode has been modified. */
89*64596Sbostic #define	IN_RENAME	0x0040		/* Inode is being renamed. */
90*64596Sbostic #define	IN_SHLOCK	0x0080		/* File has shared lock. */
91*64596Sbostic #define	IN_UPDATE	0x0100		/* Modification time update request. */
92*64596Sbostic #define	IN_WANTED	0x0200		/* Inode is wanted by a process. */
9358Sbill 
9437714Smckusick #ifdef KERNEL
9556449Smargo /*
9656449Smargo  * Structure used to pass around logical block paths generated by
9756449Smargo  * ufs_getlbns and used by truncate and bmap code.
9856449Smargo  */
9956449Smargo struct indir {
10064513Sbostic 	daddr_t	in_lbn;			/* Logical block number. */
10164513Sbostic 	int	in_off;			/* Offset in buffer. */
10264513Sbostic 	int	in_exists;		/* Flag if the block exists. */
10356449Smargo };
10456449Smargo 
10551505Sbostic /* Convert between inode pointers and vnode pointers. */
10637714Smckusick #define VTOI(vp)	((struct inode *)(vp)->v_data)
10739387Smckusick #define ITOV(ip)	((ip)->i_vnode)
10837714Smckusick 
10964513Sbostic #define	ITIMES(ip, t1, t2) {						\
110*64596Sbostic 	if ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) {	\
111*64596Sbostic 		(ip)->i_flag |= IN_MODIFIED;				\
112*64596Sbostic 		if ((ip)->i_flag & IN_ACCESS)				\
11364513Sbostic 			(ip)->i_atime.ts_sec = (t1)->tv_sec;		\
114*64596Sbostic 		if ((ip)->i_flag & IN_UPDATE) {				\
11564513Sbostic 			(ip)->i_mtime.ts_sec = (t2)->tv_sec;		\
11664513Sbostic 			(ip)->i_modrev++;				\
11764513Sbostic 		}							\
118*64596Sbostic 		if ((ip)->i_flag & IN_CHANGE)				\
11964513Sbostic 			(ip)->i_ctime.ts_sec = time.tv_sec;		\
120*64596Sbostic 		(ip)->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE);	\
12164513Sbostic 	}								\
12216057Skarels }
12337714Smckusick 
12451505Sbostic /* This overlays the fid structure (see mount.h). */
12537714Smckusick struct ufid {
12664513Sbostic 	u_short	ufid_len;	/* Length of structure. */
12764513Sbostic 	u_short	ufid_pad;	/* Force long alignment. */
12864513Sbostic 	ino_t	ufid_ino;	/* File number (ino). */
12964513Sbostic 	long	ufid_gen;	/* Generation number. */
13037714Smckusick };
13148031Smckusick #endif /* KERNEL */
132