xref: /original-bsd/sys/ufs/ffs/inode.h (revision d4dfefc4)
1 /*
2  * Copyright (c) 1982, 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)inode.h	7.32 (Berkeley) 11/14/92
8  */
9 
10 #include <ufs/ufs/dinode.h>
11 
12 /*
13  * Theoretically, directories can be more than 2Gb in length,
14  * however, in practice this seems unlikely. So, we define
15  * the type doff_t as a long to keep down the cost of doing
16  * lookup on a 32-bit machine. If you are porting to a 64-bit
17  * architecture, you should make doff_t the same as off_t.
18  */
19 #define doff_t	long
20 
21 /*
22  * The inode is used to describe each active (or recently active)
23  * file in the UFS filesystem. It is composed of two types of
24  * information. The first part is the information that is needed
25  * only while the file is active (such as the identity of the file
26  * and linkage to speed its lookup). The second part is the
27  * permannent meta-data associated with the file which is read
28  * in from the permanent dinode from long term storage when the
29  * file becomes active, and is put back when the file is no longer
30  * being used.
31  */
32 struct inode {
33 	struct	inode *i_next;	/* hash chain forward */
34 	struct	inode **i_prev;	/* hash chain back */
35 	struct	vnode *i_vnode;	/* vnode associated with this inode */
36 	struct	vnode *i_devvp;	/* vnode for block I/O */
37 	u_long	i_flag;		/* see below */
38 	dev_t	i_dev;		/* device where inode resides */
39 	ino_t	i_number;	/* the identity of the inode */
40 	union {			/* associated filesystem */
41 		struct	fs *fs;		/* FFS */
42 		struct	lfs *lfs;	/* LFS */
43 	} inode_u;
44 #define	i_fs	inode_u.fs
45 #define	i_lfs	inode_u.lfs
46 	struct	dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */
47 	u_quad_t i_modrev;	/* revision level for lease */
48 	struct	lockf *i_lockf;	/* head of byte-level lock list */
49 	pid_t	i_lockholder;	/* DEBUG: holder of inode lock */
50 	pid_t	i_lockwaiter;	/* DEBUG: latest blocked for inode lock */
51 	/*
52 	 * Side effects; used during directory lookup.
53 	 */
54 	doff_t	i_endoff;	/* end of useful stuff in directory */
55 	doff_t	i_diroff;	/* offset in dir, where we found last entry */
56 	doff_t	i_offset;	/* offset of free space in directory */
57 	long	i_count;	/* size of free slot in directory */
58 	ino_t	i_ino;		/* inode number of found directory */
59 	u_long	i_reclen;	/* size of found directory entry */
60 	/*
61 	 * the on-disk dinode itself.
62 	 */
63 	struct	dinode i_din;	/* the on-disk dinode */
64 	long	i_spare[12];	/* spares to round up to 256 bytes */
65 };
66 
67 #define	i_mode		i_din.di_mode
68 #define	i_nlink		i_din.di_nlink
69 #define	i_uid		i_din.di_uid
70 #define	i_gid		i_din.di_gid
71 #define i_size		i_din.di_size
72 #define	i_db		i_din.di_db
73 #define	i_ib		i_din.di_ib
74 #define	i_atime		i_din.di_atime
75 #define	i_mtime		i_din.di_mtime
76 #define	i_ctime		i_din.di_ctime
77 #define i_blocks	i_din.di_blocks
78 #define	i_rdev		i_din.di_rdev
79 #define	i_shortlink	i_din.di_shortlink
80 #define i_flags		i_din.di_flags
81 #define i_gen		i_din.di_gen
82 
83 /* flags */
84 #define	ILOCKED		0x0001		/* inode is locked */
85 #define	IWANT		0x0002		/* some process waiting on lock */
86 #define	IRENAME		0x0004		/* inode is being renamed */
87 #define	IUPD		0x0010		/* file has been modified */
88 #define	IACC		0x0020		/* inode access time to be updated */
89 #define	ICHG		0x0040		/* inode has been changed */
90 #define	IMOD		0x0080		/* inode has been modified */
91 #define	ISHLOCK		0x0100		/* file has shared lock */
92 #define	IEXLOCK		0x0200		/* file has exclusive lock */
93 #define	ILWAIT		0x0400		/* someone waiting on file lock */
94 
95 #ifdef KERNEL
96 /*
97  * Structure used to pass around logical block paths generated by
98  * ufs_getlbns and used by truncate and bmap code.
99  */
100 struct indir {
101 	daddr_t	in_lbn;			/* logical block number */
102 	int	in_off;			/* offset in buffer */
103 	int	in_exists;		/* does this block exist yet */
104 };
105 
106 /* Convert between inode pointers and vnode pointers. */
107 #define VTOI(vp)	((struct inode *)(vp)->v_data)
108 #define ITOV(ip)	((ip)->i_vnode)
109 
110 #define	ITIMES(ip, t1, t2) { \
111 	if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
112 		(ip)->i_flag |= IMOD; \
113 		if ((ip)->i_flag&IACC) \
114 			(ip)->i_atime.ts_sec = (t1)->tv_sec; \
115 		if ((ip)->i_flag&IUPD) { \
116 			(ip)->i_mtime.ts_sec = (t2)->tv_sec; \
117 			(ip)->i_modrev++; \
118 		} \
119 		if ((ip)->i_flag&ICHG) \
120 			(ip)->i_ctime.ts_sec = time.tv_sec; \
121 		(ip)->i_flag &= ~(IACC|IUPD|ICHG); \
122 	} \
123 }
124 
125 /* This overlays the fid structure (see mount.h). */
126 struct ufid {
127 	u_short	ufid_len;	/* length of structure */
128 	u_short	ufid_pad;	/* force long alignment */
129 	ino_t	ufid_ino;	/* file number (ino) */
130 	long	ufid_gen;	/* generation number */
131 };
132 #endif /* KERNEL */
133