xref: /minix/sys/ufs/ufs/inode.h (revision 0a6a1f1d)
1 /*	$NetBSD: inode.h,v 1.71 2014/05/26 19:16:39 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 	TAILQ_ENTRY(inode) i_nextsnap; /* snapshot file list. */
97 	struct	vnode *i_vnode;	/* Vnode associated with this inode. */
98 	struct  ufsmount *i_ump; /* Mount point associated with this inode. */
99 	struct	vnode *i_devvp;	/* Vnode for block I/O. */
100 	u_int32_t i_flag;	/* flags, see below */
101 	dev_t	  i_dev;	/* Device associated with the inode. */
102 	ino_t	  i_number;	/* The identity of the inode. */
103 
104 	union {			/* Associated filesystem. */
105 		struct	fs *fs;		/* FFS */
106 		struct	lfs *lfs;	/* LFS */
107 		struct	m_ext2fs *e2fs;	/* EXT2FS */
108 	} inode_u;
109 #define	i_fs	inode_u.fs
110 #define	i_lfs	inode_u.lfs
111 #define	i_e2fs	inode_u.e2fs
112 
113 	void	*i_unused1;	/* Unused. */
114 	struct	 dquot *i_dquot[MAXQUOTAS]; /* Dquot structures. */
115 	u_quad_t i_modrev;	/* Revision level for NFS lease. */
116 	struct	 lockf *i_lockf;/* Head of byte-level lock list. */
117 
118 	/*
119 	 * Side effects; used during (and after) directory lookup.
120 	 * XXX should not be here.
121 	 */
122 	struct ufs_lookup_results i_crap;
123 	unsigned i_crapcounter;	/* serial number for i_crap */
124 
125 	/*
126 	 * Inode extensions
127 	 */
128 	union {
129 		/* Other extensions could go here... */
130 		struct	ffs_inode_ext ffs;
131 		struct	ext2fs_inode_ext e2fs;
132 		struct  lfs_inode_ext *lfs;
133 	} inode_ext;
134 #define	i_snapblklist		inode_ext.ffs.ffs_snapblklist
135 #define	i_ffs_first_data_blk	inode_ext.ffs.ffs_first_data_blk
136 #define	i_ffs_first_indir_blk	inode_ext.ffs.ffs_first_indir_blk
137 #define	i_e2fs_last_lblk	inode_ext.e2fs.ext2fs_last_lblk
138 #define	i_e2fs_last_blk		inode_ext.e2fs.ext2fs_last_blk
139 	/*
140 	 * Copies from the on-disk dinode itself.
141 	 *
142 	 * These fields are currently only used by FFS and LFS,
143 	 * do NOT use them with ext2fs.
144 	 */
145 	u_int16_t i_mode;	/* IFMT, permissions; see below. */
146 	int16_t   i_nlink;	/* File link count. */
147 	u_int64_t i_size;	/* File byte count. */
148 	u_int32_t i_flags;	/* Status flags (chflags). */
149 	int32_t   i_gen;	/* Generation number. */
150 	u_int32_t i_uid;	/* File owner. */
151 	u_int32_t i_gid;	/* File group. */
152 	u_int16_t i_omode;	/* Old mode, for ufs_reclaim. */
153 
154 	struct dirhash *i_dirhash;	/* Hashing for large directories */
155 
156 	/*
157 	 * The on-disk dinode itself.
158 	 */
159 	union {
160 		struct	ufs1_dinode *ffs1_din;	/* 128 bytes of the on-disk dinode. */
161 		struct	ufs2_dinode *ffs2_din;
162 		struct	ext2fs_dinode *e2fs_din; /* 128 bytes of the on-disk
163 						   dinode. */
164 	} i_din;
165 };
166 
167 #define	i_ffs1_atime		i_din.ffs1_din->di_atime
168 #define	i_ffs1_atimensec	i_din.ffs1_din->di_atimensec
169 #define	i_ffs1_blocks		i_din.ffs1_din->di_blocks
170 #define	i_ffs1_ctime		i_din.ffs1_din->di_ctime
171 #define	i_ffs1_ctimensec	i_din.ffs1_din->di_ctimensec
172 #define	i_ffs1_db		i_din.ffs1_din->di_db
173 #define	i_ffs1_flags		i_din.ffs1_din->di_flags
174 #define	i_ffs1_gen		i_din.ffs1_din->di_gen
175 #define	i_ffs1_gid		i_din.ffs1_din->di_gid
176 #define	i_ffs1_ib		i_din.ffs1_din->di_ib
177 #define	i_ffs1_mode		i_din.ffs1_din->di_mode
178 #define	i_ffs1_mtime		i_din.ffs1_din->di_mtime
179 #define	i_ffs1_mtimensec	i_din.ffs1_din->di_mtimensec
180 #define	i_ffs1_nlink		i_din.ffs1_din->di_nlink
181 #define	i_ffs1_rdev		i_din.ffs1_din->di_rdev
182 #define	i_ffs1_size		i_din.ffs1_din->di_size
183 #define	i_ffs1_uid		i_din.ffs1_din->di_uid
184 #define	i_ffs1_ouid		i_din.ffs1_din->di_oldids[0]
185 #define	i_ffs1_ogid		i_din.ffs1_din->di_oldids[1]
186 
187 #define	i_ffs2_atime		i_din.ffs2_din->di_atime
188 #define	i_ffs2_atimensec	i_din.ffs2_din->di_atimensec
189 #define	i_ffs2_birthtime	i_din.ffs2_din->di_birthtime
190 #define	i_ffs2_birthnsec	i_din.ffs2_din->di_birthnsec
191 #define	i_ffs2_blocks		i_din.ffs2_din->di_blocks
192 #define	i_ffs2_blksize		i_din.ffs2_din->di_blksize
193 #define	i_ffs2_ctime		i_din.ffs2_din->di_ctime
194 #define	i_ffs2_ctimensec	i_din.ffs2_din->di_ctimensec
195 #define	i_ffs2_db		i_din.ffs2_din->di_db
196 #define	i_ffs2_flags		i_din.ffs2_din->di_flags
197 #define	i_ffs2_gen		i_din.ffs2_din->di_gen
198 #define	i_ffs2_gid		i_din.ffs2_din->di_gid
199 #define	i_ffs2_ib		i_din.ffs2_din->di_ib
200 #define	i_ffs2_mode		i_din.ffs2_din->di_mode
201 #define	i_ffs2_mtime		i_din.ffs2_din->di_mtime
202 #define	i_ffs2_mtimensec	i_din.ffs2_din->di_mtimensec
203 #define	i_ffs2_nlink		i_din.ffs2_din->di_nlink
204 #define	i_ffs2_rdev		i_din.ffs2_din->di_rdev
205 #define	i_ffs2_size		i_din.ffs2_din->di_size
206 #define	i_ffs2_uid		i_din.ffs2_din->di_uid
207 #define	i_ffs2_kernflags	i_din.ffs2_din->di_kernflags
208 #define	i_ffs2_extsize		i_din.ffs2_din->di_extsize
209 #define	i_ffs2_extb		i_din.ffs2_din->di_extb
210 
211 #define	i_e2fs_mode		i_din.e2fs_din->e2di_mode
212 #define	i_e2fs_uid		i_din.e2fs_din->e2di_uid
213 #define	i_e2fs_size		i_din.e2fs_din->e2di_size
214 #define	i_e2fs_atime		i_din.e2fs_din->e2di_atime
215 #define	i_e2fs_ctime		i_din.e2fs_din->e2di_ctime
216 #define	i_e2fs_mtime		i_din.e2fs_din->e2di_mtime
217 #define	i_e2fs_dtime		i_din.e2fs_din->e2di_dtime
218 #define	i_e2fs_gid		i_din.e2fs_din->e2di_gid
219 #define	i_e2fs_nlink		i_din.e2fs_din->e2di_nlink
220 #define	i_e2fs_nblock		i_din.e2fs_din->e2di_nblock
221 #define	i_e2fs_flags		i_din.e2fs_din->e2di_flags
222 #define	i_e2fs_version		i_din.e2fs_din->e2di_version
223 #define	i_e2fs_blocks		i_din.e2fs_din->e2di_blocks
224 #define	i_e2fs_rdev		i_din.e2fs_din->e2di_rdev
225 #define	i_e2fs_gen		i_din.e2fs_din->e2di_gen
226 #define	i_e2fs_facl		i_din.e2fs_din->e2di_facl
227 #define	i_e2fs_dacl		i_din.e2fs_din->e2di_dacl
228 #define	i_e2fs_faddr		i_din.e2fs_din->e2di_faddr
229 #define	i_e2fs_nblock_high	i_din.e2fs_din->e2di_nblock_high
230 #define	i_e2fs_facl_high	i_din.e2fs_din->e2di_facl_high
231 #define	i_e2fs_uid_high		i_din.e2fs_din->e2di_uid_high
232 #define	i_e2fs_gid_high		i_din.e2fs_din->e2di_gid_high
233 
234 /* These flags are kept in i_flag. */
235 #define	IN_ACCESS	0x0001		/* Access time update request. */
236 #define	IN_CHANGE	0x0002		/* Inode change time update request. */
237 #define	IN_UPDATE	0x0004		/* Inode was written to; update mtime. */
238 #define	IN_MODIFY	0x2000		/* Modification time update request. */
239 #define	IN_MODIFIED	0x0008		/* Inode has been modified. */
240 #define	IN_ACCESSED	0x0010		/* Inode has been accessed. */
241 /* 	   unused	0x0020 */	/* was IN_RENAME */
242 #define	IN_SHLOCK	0x0040		/* File has shared lock. */
243 #define	IN_EXLOCK	0x0080		/* File has exclusive lock. */
244 /*	   unused	0x0100 */	/* was LFS-only IN_CLEANING */
245 /*	   unused	0x0200 */	/* was LFS-only IN_ADIROP */
246 #define	IN_SPACECOUNTED	0x0400		/* Blocks to be freed in free count. */
247 /*	   unused       0x1000 */	/* was LFS-only IN_PAGING */
248 /*	   unused	0x4000 */	/* was LFS-only IN_CDIROP */
249 #if defined(_KERNEL)
250 
251 /*
252  * The DIP macro is used to access fields in the dinode that are
253  * not cached in the inode itself.
254  */
255 #define	DIP(ip, field) \
256 	(((ip)->i_ump->um_fstype == UFS1) ? \
257 	(ip)->i_ffs1_##field : (ip)->i_ffs2_##field)
258 
259 #define	DIP_ASSIGN(ip, field, value)					\
260 	do {								\
261 		if ((ip)->i_ump->um_fstype == UFS1)			\
262 			(ip)->i_ffs1_##field = (value);			\
263 		else							\
264 			(ip)->i_ffs2_##field = (value);			\
265 	} while(0)
266 
267 #define	DIP_ADD(ip, field, value)					\
268 	do {								\
269 		if ((ip)->i_ump->um_fstype == UFS1)			\
270 			(ip)->i_ffs1_##field += (value);		\
271 		else							\
272 			(ip)->i_ffs2_##field += (value);		\
273 	} while(0)
274 
275 #define	 SHORTLINK(ip) \
276 	(((ip)->i_ump->um_fstype == UFS1) ? \
277 	(void *)(ip)->i_ffs1_db : (void *)(ip)->i_ffs2_db)
278 
279 
280 /*
281  * Structure used to pass around logical block paths generated by
282  * ufs_getlbns and used by truncate and bmap code.
283  */
284 struct indir {
285 	daddr_t in_lbn;		/* Logical block number. */
286 	int	in_off;			/* Offset in buffer. */
287 	int	in_exists;		/* Flag if the block exists. */
288 };
289 
290 /* Convert between inode pointers and vnode pointers. */
291 #define	VTOI(vp)	((struct inode *)(vp)->v_data)
292 #define	ITOV(ip)	((ip)->i_vnode)
293 
294 /* This overlays the fid structure (see fstypes.h). */
295 struct ufid {
296 	u_int16_t ufid_len;	/* Length of structure. */
297 	u_int16_t ufid_pad;	/* Force 32-bit alignment. */
298 	int32_t	  ufid_gen;	/* Generation number. */
299 	ino_t     ufid_ino;	/* File number (ino). */
300 };
301 #endif /* _KERNEL */
302 
303 #endif /* !_UFS_UFS_INODE_H_ */
304