xref: /original-bsd/sys/ufs/ffs/inode.h (revision e59fb703)
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.20 (Berkeley) 12/19/91
8  */
9 
10 #include <ufs/ufs/dinode.h>
11 
12 /*
13  * The inode is used to describe each active (or recently active)
14  * file in the UFS filesystem. It is composed of two types of
15  * information. The first part is the information that is needed
16  * only while the file is active (such as the identity of the file
17  * and linkage to speed its lookup). The second part is the
18  * permannent meta-data associated with the file which is read
19  * in from the permanent dinode from long term storage when the
20  * file becomes active, and is put back when the file is no longer
21  * being used.
22  */
23 struct inode {
24 	struct	inode *i_chain[2]; /* hash chain, MUST be first */
25 	struct	vnode *i_vnode;	/* vnode associated with this inode */
26 	struct	vnode *i_devvp;	/* vnode for block I/O */
27 	u_long	i_flag;		/* see below */
28 	dev_t	i_dev;		/* device where inode resides */
29 	short	i_pad;
30 	ino_t	i_number;	/* the identity of the inode */
31 	union {			/* associated filesystem */
32 		struct	fs *fs;		/* FFS */
33 		struct	lfs *lfs;	/* LFS */
34 	} inode_u;
35 #define	i_fs	inode_u.fs
36 #define	i_lfs	inode_u.lfs
37 	struct	dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */
38 	struct	lockf *i_lockf;	/* head of byte-level lock list */
39 	long	i_diroff;	/* offset in dir, where we found last entry */
40 	off_t	i_endoff;	/* end of useful stuff in directory */
41 	u_quad_t i_modrev;	/* revision level for lease */
42 	pid_t	i_lockholder;	/* DEBUG: holder of inode lock */
43 	pid_t	i_lockwaiter;	/* DEBUG: latest blocked for inode lock */
44 	long	i_spare[16];	/* spares to round up to 256 bytes */
45 	struct	dinode i_din;	/* the on-disk dinode */
46 };
47 
48 #define	i_mode		i_din.di_mode
49 #define	i_nlink		i_din.di_nlink
50 #define	i_uid		i_din.di_uid
51 #define	i_gid		i_din.di_gid
52 #ifdef _NOQUAD
53 #define i_size	i_din.di_qsize.val[_QUAD_LOWWORD]
54 #else
55 #define i_size	i_din.di_qsize
56 #endif
57 #if defined(tahoe) /* ugh! -- must be fixed */
58 #undef i_size
59 #define	i_size		i_din.di_qsize.val[0]
60 #endif
61 #define	i_db		i_din.di_db
62 #define	i_ib		i_din.di_ib
63 #define	i_atime		i_din.di_atime
64 #define	i_mtime		i_din.di_mtime
65 #define	i_ctime		i_din.di_ctime
66 #define i_blocks	i_din.di_blocks
67 #define	i_rdev		i_din.di_db[0]
68 #define i_flags		i_din.di_flags
69 #define i_gen		i_din.di_gen
70 #define	i_forw		i_chain[0]
71 #define	i_back		i_chain[1]
72 
73 /* flags */
74 #define	ILOCKED		0x0001		/* inode is locked */
75 #define	IWANT		0x0002		/* some process waiting on lock */
76 #define	IRENAME		0x0004		/* inode is being renamed */
77 #define	IUPD		0x0010		/* file has been modified */
78 #define	IACC		0x0020		/* inode access time to be updated */
79 #define	ICHG		0x0040		/* inode has been changed */
80 #define	IMOD		0x0080		/* inode has been modified */
81 #define	ISHLOCK		0x0100		/* file has shared lock */
82 #define	IEXLOCK		0x0200		/* file has exclusive lock */
83 #define	ILWAIT		0x0400		/* someone waiting on file lock */
84 
85 #ifdef KERNEL
86 /* Convert between inode pointers and vnode pointers. */
87 #define VTOI(vp)	((struct inode *)(vp)->v_data)
88 #define ITOV(ip)	((ip)->i_vnode)
89 
90 /* Convert between vnode types and inode formats. */
91 extern enum vtype	iftovt_tab[];
92 extern int		vttoif_tab[];
93 #define IFTOVT(mode)	(iftovt_tab[((mode) & IFMT) >> 12])
94 #define VTTOIF(indx)	(vttoif_tab[(int)(indx)])
95 
96 #define MAKEIMODE(indx, mode)	(int)(VTTOIF(indx) | (mode))
97 
98 /* Lock and unlock inodes. */
99 #ifdef notdef
100 #define	ILOCK(ip) { \
101 	while ((ip)->i_flag & ILOCKED) { \
102 		(ip)->i_flag |= IWANT; \
103 		(void) sleep((caddr_t)(ip), PINOD); \
104 	} \
105 	(ip)->i_flag |= ILOCKED; \
106 }
107 
108 #define	IUNLOCK(ip) { \
109 	(ip)->i_flag &= ~ILOCKED; \
110 	if ((ip)->i_flag&IWANT) { \
111 		(ip)->i_flag &= ~IWANT; \
112 		wakeup((caddr_t)(ip)); \
113 	} \
114 }
115 #else
116 #define ILOCK(ip)	ufs_ilock(ip)
117 #define IUNLOCK(ip)	ufs_iunlock(ip)
118 #endif
119 
120 #define	ITIMES(ip, t1, t2) { \
121 	if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
122 		(ip)->i_flag |= IMOD; \
123 		if ((ip)->i_flag&IACC) \
124 			(ip)->i_atime = (t1)->tv_sec; \
125 		if ((ip)->i_flag&IUPD) { \
126 			(ip)->i_mtime = (t2)->tv_sec; \
127 			INCRQUAD((ip)->i_modrev); \
128 		} \
129 		if ((ip)->i_flag&ICHG) \
130 			(ip)->i_ctime = time.tv_sec; \
131 		(ip)->i_flag &= ~(IACC|IUPD|ICHG); \
132 	} \
133 }
134 
135 /* This overlays the fid structure (see mount.h). */
136 struct ufid {
137 	u_short	ufid_len;	/* length of structure */
138 	u_short	ufid_pad;	/* force long alignment */
139 	ino_t	ufid_ino;	/* file number (ino) */
140 	long	ufid_gen;	/* generation number */
141 };
142 #endif /* KERNEL */
143