xref: /minix/sys/ufs/ufs/inode.h (revision 84d9c625)
1 /*	$NetBSD: inode.h,v 1.65 2013/06/09 17:55:46 dholland Exp $	*/
2 
3 /*
4  * Copyright (c) 1982, 1989, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  * (c) UNIX System Laboratories, Inc.
7  * All or some portions of this file are derived from material licensed
8  * to the University of California by American Telephone and Telegraph
9  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10  * the permission of UNIX System Laboratories, Inc.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  *	@(#)inode.h	8.9 (Berkeley) 5/14/95
37  */
38 
39 #ifndef _UFS_UFS_INODE_H_
40 #define	_UFS_UFS_INODE_H_
41 
42 #include <sys/vnode.h>
43 #include <ufs/ufs/dinode.h>
44 #include <ufs/ufs/dir.h>
45 #include <ufs/ufs/quota.h>
46 #include <ufs/ext2fs/ext2fs_dinode.h>
47 #include <miscfs/genfs/genfs_node.h>
48 
49 /*
50  * Lookup result state (other than the result inode). This is
51  * currently stashed in the vnode between VOP_LOOKUP and directory
52  * operation VOPs, which is gross.
53  *
54  * XXX ulr_diroff is a lookup hint from the previos call of VOP_LOOKUP.
55  * probably it should not be here.
56  */
57 struct ufs_lookup_results {
58 	int32_t	  ulr_count;	/* Size of free slot in directory. */
59 	doff_t	  ulr_endoff;	/* End of useful stuff in directory. */
60 	doff_t	  ulr_diroff;	/* Offset in dir, where we found last entry. */
61 	doff_t	  ulr_offset;	/* Offset of free space in directory. */
62 	u_int32_t ulr_reclen;	/* Size of found directory entry. */
63 };
64 
65 /* notyet XXX */
66 #define UFS_CHECK_CRAPCOUNTER(dp) ((void)(dp)->i_crapcounter)
67 
68 /*
69  * Per-filesystem inode extensions.
70  */
71 struct ffs_inode_ext {
72 	daddr_t *ffs_snapblklist;	/* Collect expunged snapshot blocks. */
73 	/* follow two fields are used by contiguous allocation code only. */
74 	daddr_t ffs_first_data_blk;	/* first data block on disk. */
75 	daddr_t ffs_first_indir_blk;	/* first indirect block on disk. */
76 };
77 
78 struct ext2fs_inode_ext {
79 	daddr_t ext2fs_last_lblk;	/* last logical block allocated */
80 	daddr_t ext2fs_last_blk;	/* last block allocated on disk */
81 };
82 
83 struct lfs_inode_ext;
84 
85 /*
86  * The inode is used to describe each active (or recently active) file in the
87  * UFS filesystem. It is composed of two types of information. The first part
88  * is the information that is needed only while the file is active (such as
89  * the identity of the file and linkage to speed its lookup). The second part
90  * is the permanent meta-data associated with the file which is read in
91  * from the permanent dinode from long term storage when the file becomes
92  * active, and is put back when the file is no longer being used.
93  */
94 struct inode {
95 	struct genfs_node i_gnode;
96 	LIST_ENTRY(inode) i_hash;/* Hash chain. */
97 	TAILQ_ENTRY(inode) i_nextsnap; /* snapshot file list. */
98 	struct	vnode *i_vnode;	/* Vnode associated with this inode. */
99 	struct  ufsmount *i_ump; /* Mount point associated with this inode. */
100 	struct	vnode *i_devvp;	/* Vnode for block I/O. */
101 	u_int32_t i_flag;	/* flags, see below */
102 	dev_t	  i_dev;	/* Device associated with the inode. */
103 	ino_t	  i_number;	/* The identity of the inode. */
104 
105 	union {			/* Associated filesystem. */
106 		struct	fs *fs;		/* FFS */
107 		struct	lfs *lfs;	/* LFS */
108 		struct	m_ext2fs *e2fs;	/* EXT2FS */
109 	} inode_u;
110 #define	i_fs	inode_u.fs
111 #define	i_lfs	inode_u.lfs
112 #define	i_e2fs	inode_u.e2fs
113 
114 	void	*i_unused1;	/* Unused. */
115 	struct	 dquot *i_dquot[MAXQUOTAS]; /* Dquot structures. */
116 	u_quad_t i_modrev;	/* Revision level for NFS lease. */
117 	struct	 lockf *i_lockf;/* Head of byte-level lock list. */
118 
119 	/*
120 	 * Side effects; used during (and after) directory lookup.
121 	 * XXX should not be here.
122 	 */
123 	struct ufs_lookup_results i_crap;
124 	unsigned i_crapcounter;	/* serial number for i_crap */
125 
126 	/*
127 	 * Inode extensions
128 	 */
129 	union {
130 		/* Other extensions could go here... */
131 		struct	ffs_inode_ext ffs;
132 		struct	ext2fs_inode_ext e2fs;
133 		struct  lfs_inode_ext *lfs;
134 	} inode_ext;
135 #define	i_snapblklist		inode_ext.ffs.ffs_snapblklist
136 #define	i_ffs_first_data_blk	inode_ext.ffs.ffs_first_data_blk
137 #define	i_ffs_first_indir_blk	inode_ext.ffs.ffs_first_indir_blk
138 #define	i_e2fs_last_lblk	inode_ext.e2fs.ext2fs_last_lblk
139 #define	i_e2fs_last_blk		inode_ext.e2fs.ext2fs_last_blk
140 	/*
141 	 * Copies from the on-disk dinode itself.
142 	 *
143 	 * These fields are currently only used by FFS and LFS,
144 	 * do NOT use them with ext2fs.
145 	 */
146 	u_int16_t i_mode;	/* IFMT, permissions; see below. */
147 	int16_t   i_nlink;	/* File link count. */
148 	u_int64_t i_size;	/* File byte count. */
149 	u_int32_t i_flags;	/* Status flags (chflags). */
150 	int32_t   i_gen;	/* Generation number. */
151 	u_int32_t i_uid;	/* File owner. */
152 	u_int32_t i_gid;	/* File group. */
153 	u_int16_t i_omode;	/* Old mode, for ufs_reclaim. */
154 
155 	struct dirhash *i_dirhash;	/* Hashing for large directories */
156 
157 	/*
158 	 * The on-disk dinode itself.
159 	 */
160 	union {
161 		struct	ufs1_dinode *ffs1_din;	/* 128 bytes of the on-disk dinode. */
162 		struct	ufs2_dinode *ffs2_din;
163 		struct	ext2fs_dinode *e2fs_din; /* 128 bytes of the on-disk
164 						   dinode. */
165 	} i_din;
166 };
167 
168 #define	i_ffs1_atime		i_din.ffs1_din->di_atime
169 #define	i_ffs1_atimensec	i_din.ffs1_din->di_atimensec
170 #define	i_ffs1_blocks		i_din.ffs1_din->di_blocks
171 #define	i_ffs1_ctime		i_din.ffs1_din->di_ctime
172 #define	i_ffs1_ctimensec	i_din.ffs1_din->di_ctimensec
173 #define	i_ffs1_db		i_din.ffs1_din->di_db
174 #define	i_ffs1_flags		i_din.ffs1_din->di_flags
175 #define	i_ffs1_gen		i_din.ffs1_din->di_gen
176 #define	i_ffs1_gid		i_din.ffs1_din->di_gid
177 #define	i_ffs1_ib		i_din.ffs1_din->di_ib
178 #define	i_ffs1_mode		i_din.ffs1_din->di_mode
179 #define	i_ffs1_mtime		i_din.ffs1_din->di_mtime
180 #define	i_ffs1_mtimensec	i_din.ffs1_din->di_mtimensec
181 #define	i_ffs1_nlink		i_din.ffs1_din->di_nlink
182 #define	i_ffs1_rdev		i_din.ffs1_din->di_rdev
183 #define	i_ffs1_size		i_din.ffs1_din->di_size
184 #define	i_ffs1_uid		i_din.ffs1_din->di_uid
185 #define	i_ffs1_ouid		i_din.ffs1_din->di_oldids[0]
186 #define	i_ffs1_ogid		i_din.ffs1_din->di_oldids[1]
187 
188 #define	i_ffs2_atime		i_din.ffs2_din->di_atime
189 #define	i_ffs2_atimensec	i_din.ffs2_din->di_atimensec
190 #define	i_ffs2_birthtime	i_din.ffs2_din->di_birthtime
191 #define	i_ffs2_birthnsec	i_din.ffs2_din->di_birthnsec
192 #define	i_ffs2_blocks		i_din.ffs2_din->di_blocks
193 #define	i_ffs2_blksize		i_din.ffs2_din->di_blksize
194 #define	i_ffs2_ctime		i_din.ffs2_din->di_ctime
195 #define	i_ffs2_ctimensec	i_din.ffs2_din->di_ctimensec
196 #define	i_ffs2_db		i_din.ffs2_din->di_db
197 #define	i_ffs2_flags		i_din.ffs2_din->di_flags
198 #define	i_ffs2_gen		i_din.ffs2_din->di_gen
199 #define	i_ffs2_gid		i_din.ffs2_din->di_gid
200 #define	i_ffs2_ib		i_din.ffs2_din->di_ib
201 #define	i_ffs2_mode		i_din.ffs2_din->di_mode
202 #define	i_ffs2_mtime		i_din.ffs2_din->di_mtime
203 #define	i_ffs2_mtimensec	i_din.ffs2_din->di_mtimensec
204 #define	i_ffs2_nlink		i_din.ffs2_din->di_nlink
205 #define	i_ffs2_rdev		i_din.ffs2_din->di_rdev
206 #define	i_ffs2_size		i_din.ffs2_din->di_size
207 #define	i_ffs2_uid		i_din.ffs2_din->di_uid
208 #define	i_ffs2_kernflags	i_din.ffs2_din->di_kernflags
209 #define	i_ffs2_extsize		i_din.ffs2_din->di_extsize
210 #define	i_ffs2_extb		i_din.ffs2_din->di_extb
211 
212 #define	i_e2fs_mode		i_din.e2fs_din->e2di_mode
213 #define	i_e2fs_uid		i_din.e2fs_din->e2di_uid
214 #define	i_e2fs_size		i_din.e2fs_din->e2di_size
215 #define	i_e2fs_atime		i_din.e2fs_din->e2di_atime
216 #define	i_e2fs_ctime		i_din.e2fs_din->e2di_ctime
217 #define	i_e2fs_mtime		i_din.e2fs_din->e2di_mtime
218 #define	i_e2fs_dtime		i_din.e2fs_din->e2di_dtime
219 #define	i_e2fs_gid		i_din.e2fs_din->e2di_gid
220 #define	i_e2fs_nlink		i_din.e2fs_din->e2di_nlink
221 #define	i_e2fs_nblock		i_din.e2fs_din->e2di_nblock
222 #define	i_e2fs_flags		i_din.e2fs_din->e2di_flags
223 #define	i_e2fs_version		i_din.e2fs_din->e2di_version
224 #define	i_e2fs_blocks		i_din.e2fs_din->e2di_blocks
225 #define	i_e2fs_rdev		i_din.e2fs_din->e2di_rdev
226 #define	i_e2fs_gen		i_din.e2fs_din->e2di_gen
227 #define	i_e2fs_facl		i_din.e2fs_din->e2di_facl
228 #define	i_e2fs_dacl		i_din.e2fs_din->e2di_dacl
229 #define	i_e2fs_faddr		i_din.e2fs_din->e2di_faddr
230 #define	i_e2fs_nblock_high	i_din.e2fs_din->e2di_nblock_high
231 #define	i_e2fs_facl_high	i_din.e2fs_din->e2di_facl_high
232 #define	i_e2fs_uid_high		i_din.e2fs_din->e2di_uid_high
233 #define	i_e2fs_gid_high		i_din.e2fs_din->e2di_gid_high
234 
235 /* These flags are kept in i_flag. */
236 #define	IN_ACCESS	0x0001		/* Access time update request. */
237 #define	IN_CHANGE	0x0002		/* Inode change time update request. */
238 #define	IN_UPDATE	0x0004		/* Inode was written to; update mtime. */
239 #define	IN_MODIFY	0x2000		/* Modification time update request. */
240 #define	IN_MODIFIED	0x0008		/* Inode has been modified. */
241 #define	IN_ACCESSED	0x0010		/* Inode has been accessed. */
242 /* #define	IN_UNUSED	0x0020 */	/* unused, was IN_RENAME */
243 #define	IN_SHLOCK	0x0040		/* File has shared lock. */
244 #define	IN_EXLOCK	0x0080		/* File has exclusive lock. */
245 #define	IN_CLEANING	0x0100		/* LFS: file is being cleaned */
246 #define	IN_ADIROP	0x0200		/* LFS: dirop in progress */
247 #define	IN_SPACECOUNTED	0x0400		/* Blocks to be freed in free count. */
248 #define	IN_PAGING       0x1000		/* LFS: file is on paging queue */
249 #define IN_CDIROP       0x4000          /* LFS: dirop completed pending i/o */
250 #if defined(_KERNEL)
251 
252 /*
253  * The DIP macro is used to access fields in the dinode that are
254  * not cached in the inode itself.
255  */
256 #define	DIP(ip, field) \
257 	(((ip)->i_ump->um_fstype == UFS1) ? \
258 	(ip)->i_ffs1_##field : (ip)->i_ffs2_##field)
259 
260 #define	DIP_ASSIGN(ip, field, value)					\
261 	do {								\
262 		if ((ip)->i_ump->um_fstype == UFS1)			\
263 			(ip)->i_ffs1_##field = (value);			\
264 		else							\
265 			(ip)->i_ffs2_##field = (value);			\
266 	} while(0)
267 
268 #define	DIP_ADD(ip, field, value)					\
269 	do {								\
270 		if ((ip)->i_ump->um_fstype == UFS1)			\
271 			(ip)->i_ffs1_##field += (value);		\
272 		else							\
273 			(ip)->i_ffs2_##field += (value);		\
274 	} while(0)
275 
276 #define	 SHORTLINK(ip) \
277 	(((ip)->i_ump->um_fstype == UFS1) ? \
278 	(void *)(ip)->i_ffs1_db : (void *)(ip)->i_ffs2_db)
279 
280 
281 /*
282  * Structure used to pass around logical block paths generated by
283  * ufs_getlbns and used by truncate and bmap code.
284  */
285 struct indir {
286 	daddr_t in_lbn;		/* Logical block number. */
287 	int	in_off;			/* Offset in buffer. */
288 	int	in_exists;		/* Flag if the block exists. */
289 };
290 
291 /* Convert between inode pointers and vnode pointers. */
292 #define	VTOI(vp)	((struct inode *)(vp)->v_data)
293 #define	ITOV(ip)	((ip)->i_vnode)
294 
295 /* This overlays the fid structure (see fstypes.h). */
296 struct ufid {
297 	u_int16_t ufid_len;	/* Length of structure. */
298 	u_int16_t ufid_pad;	/* Force 32-bit alignment. */
299 	u_int32_t ufid_ino;	/* File number (ino). */
300 	int32_t	  ufid_gen;	/* Generation number. */
301 };
302 #endif /* _KERNEL */
303 
304 #endif /* !_UFS_UFS_INODE_H_ */
305