FreeBSD/Linux Kernel Cross Reference
sys/ufs/ufs/inode.h
1 /* $NetBSD: inode.h,v 1.36 2003/08/07 16:34:44 agc 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 * Per-filesystem inode extensions.
51 */
52 struct ext2fs_inode_ext {
53 daddr_t ext2fs_last_lblk; /* last logical block allocated */
54 daddr_t ext2fs_last_blk; /* last block allocated on disk */
55 };
56
57 struct lfs_inode_ext;
58
59 /*
60 * The inode is used to describe each active (or recently active) file in the
61 * UFS filesystem. It is composed of two types of information. The first part
62 * is the information that is needed only while the file is active (such as
63 * the identity of the file and linkage to speed its lookup). The second part
64 * is the permanent meta-data associated with the file which is read in
65 * from the permanent dinode from long term storage when the file becomes
66 * active, and is put back when the file is no longer being used.
67 */
68 struct inode {
69 struct genfs_node i_gnode;
70 LIST_ENTRY(inode) i_hash;/* Hash chain. */
71 struct vnode *i_vnode; /* Vnode associated with this inode. */
72 struct ufsmount *i_ump; /* Mount point associated with this inode. */
73 struct vnode *i_devvp; /* Vnode for block I/O. */
74 u_int32_t i_flag; /* flags, see below */
75 dev_t i_dev; /* Device associated with the inode. */
76 ino_t i_number; /* The identity of the inode. */
77
78 union { /* Associated filesystem. */
79 struct fs *fs; /* FFS */
80 struct lfs *lfs; /* LFS */
81 struct m_ext2fs *e2fs; /* EXT2FS */
82 } inode_u;
83 #define i_fs inode_u.fs
84 #define i_lfs inode_u.lfs
85 #define i_e2fs inode_u.e2fs
86
87 struct buflists i_pcbufhd; /* softdep pagecache buffer head */
88 struct dquot *i_dquot[MAXQUOTAS]; /* Dquot structures. */
89 u_quad_t i_modrev; /* Revision level for NFS lease. */
90 struct lockf *i_lockf;/* Head of byte-level lock list. */
91
92 /*
93 * Side effects; used during directory lookup.
94 */
95 int32_t i_count; /* Size of free slot in directory. */
96 doff_t i_endoff; /* End of useful stuff in directory. */
97 doff_t i_diroff; /* Offset in dir, where we found last entry. */
98 doff_t i_offset; /* Offset of free space in directory. */
99 u_int32_t i_reclen; /* Size of found directory entry. */
100 int i_ffs_effnlink; /* i_nlink when I/O completes */
101 /*
102 * Inode extensions
103 */
104 union {
105 /* Other extensions could go here... */
106 struct ext2fs_inode_ext e2fs;
107 struct lfs_inode_ext *lfs;
108 } inode_ext;
109 #define i_e2fs_last_lblk inode_ext.e2fs.ext2fs_last_lblk
110 #define i_e2fs_last_blk inode_ext.e2fs.ext2fs_last_blk
111 /*
112 * Copies from the on-disk dinode itself.
113 *
114 * These fields are currently only used by FFS and LFS,
115 * do NOT use them with ext2fs.
116 */
117 u_int16_t i_mode; /* IFMT, permissions; see below. */
118 int16_t i_nlink; /* File link count. */
119 u_int64_t i_size; /* File byte count. */
120 u_int32_t i_flags; /* Status flags (chflags). */
121 int32_t i_gen; /* Generation number. */
122 u_int32_t i_uid; /* File owner. */
123 u_int32_t i_gid; /* File group. */
124
125 /*
126 * The on-disk dinode itself.
127 */
128 union {
129 struct ufs1_dinode *ffs1_din; /* 128 bytes of the on-disk dinode. */
130 struct ufs2_dinode *ffs2_din;
131 struct ext2fs_dinode *e2fs_din; /* 128 bytes of the on-disk
132 dinode. */
133 } i_din;
134 };
135
136 #define i_ffs1_atime i_din.ffs1_din->di_atime
137 #define i_ffs1_atimensec i_din.ffs1_din->di_atimensec
138 #define i_ffs1_blocks i_din.ffs1_din->di_blocks
139 #define i_ffs1_ctime i_din.ffs1_din->di_ctime
140 #define i_ffs1_ctimensec i_din.ffs1_din->di_ctimensec
141 #define i_ffs1_db i_din.ffs1_din->di_db
142 #define i_ffs1_flags i_din.ffs1_din->di_flags
143 #define i_ffs1_gen i_din.ffs1_din->di_gen
144 #define i_ffs1_gid i_din.ffs1_din->di_gid
145 #define i_ffs1_ib i_din.ffs1_din->di_ib
146 #define i_ffs1_mode i_din.ffs1_din->di_mode
147 #define i_ffs1_mtime i_din.ffs1_din->di_mtime
148 #define i_ffs1_mtimensec i_din.ffs1_din->di_mtimensec
149 #define i_ffs1_nlink i_din.ffs1_din->di_nlink
150 #define i_ffs1_rdev i_din.ffs1_din->di_rdev
151 #define i_ffs1_size i_din.ffs1_din->di_size
152 #define i_ffs1_uid i_din.ffs1_din->di_uid
153 #define i_ffs1_ouid i_din.ffs1_din->di_u.oldids[0]
154 #define i_ffs1_ogid i_din.ffs1_din->di_u.oldids[1]
155
156 #define i_ffs2_atime i_din.ffs2_din->di_atime
157 #define i_ffs2_atimensec i_din.ffs2_din->di_atimensec
158 #define i_ffs2_birthtime i_din.ffs2_din->di_birthtime
159 #define i_ffs2_birthnsec i_din.ffs2_din->di_birthnsec
160 #define i_ffs2_blocks i_din.ffs2_din->di_blocks
161 #define i_ffs2_blksize i_din.ffs2_din->di_blksize
162 #define i_ffs2_ctime i_din.ffs2_din->di_ctime
163 #define i_ffs2_ctimensec i_din.ffs2_din->di_ctimensec
164 #define i_ffs2_db i_din.ffs2_din->di_db
165 #define i_ffs2_flags i_din.ffs2_din->di_flags
166 #define i_ffs2_gen i_din.ffs2_din->di_gen
167 #define i_ffs2_gid i_din.ffs2_din->di_gid
168 #define i_ffs2_ib i_din.ffs2_din->di_ib
169 #define i_ffs2_mode i_din.ffs2_din->di_mode
170 #define i_ffs2_mtime i_din.ffs2_din->di_mtime
171 #define i_ffs2_mtimensec i_din.ffs2_din->di_mtimensec
172 #define i_ffs2_nlink i_din.ffs2_din->di_nlink
173 #define i_ffs2_rdev i_din.ffs2_din->di_rdev
174 #define i_ffs2_size i_din.ffs2_din->di_size
175 #define i_ffs2_uid i_din.ffs2_din->di_uid
176 #define i_ffs2_kernflags i_din.ffs2_din->di_kernflags
177 #define i_ffs2_extsize i_din.ffs2_din->di_extsize
178 #define i_ffs2_extb i_din.ffs2_din->di_extb
179
180 #define i_e2fs_mode i_din.e2fs_din->e2di_mode
181 #define i_e2fs_uid i_din.e2fs_din->e2di_uid
182 #define i_e2fs_size i_din.e2fs_din->e2di_size
183 #define i_e2fs_atime i_din.e2fs_din->e2di_atime
184 #define i_e2fs_ctime i_din.e2fs_din->e2di_ctime
185 #define i_e2fs_mtime i_din.e2fs_din->e2di_mtime
186 #define i_e2fs_dtime i_din.e2fs_din->e2di_dtime
187 #define i_e2fs_gid i_din.e2fs_din->e2di_gid
188 #define i_e2fs_nlink i_din.e2fs_din->e2di_nlink
189 #define i_e2fs_nblock i_din.e2fs_din->e2di_nblock
190 #define i_e2fs_flags i_din.e2fs_din->e2di_flags
191 #define i_e2fs_blocks i_din.e2fs_din->e2di_blocks
192 #define i_e2fs_gen i_din.e2fs_din->e2di_gen
193 #define i_e2fs_facl i_din.e2fs_din->e2di_facl
194 #define i_e2fs_dacl i_din.e2fs_din->e2di_dacl
195 #define i_e2fs_faddr i_din.e2fs_din->e2di_faddr
196 #define i_e2fs_nfrag i_din.e2fs_din->e2di_nfrag
197 #define i_e2fs_fsize i_din.e2fs_din->e2di_fsize
198 #define i_e2fs_rdev i_din.e2fs_din->e2di_rdev
199
200 /* These flags are kept in i_flag. */
201 #define IN_ACCESS 0x0001 /* Access time update request. */
202 #define IN_CHANGE 0x0002 /* Inode change time update request. */
203 #define IN_UPDATE 0x0004 /* Modification time update request. */
204 #define IN_MODIFIED 0x0008 /* Inode has been modified. */
205 #define IN_ACCESSED 0x0010 /* Inode has been accessed. */
206 #define IN_RENAME 0x0020 /* Inode is being renamed. */
207 #define IN_SHLOCK 0x0040 /* File has shared lock. */
208 #define IN_EXLOCK 0x0080 /* File has exclusive lock. */
209 #define IN_CLEANING 0x0100 /* LFS: file is being cleaned */
210 #define IN_ADIROP 0x0200 /* LFS: dirop in progress */
211 #define IN_SPACECOUNTED 0x0400 /* Blocks to be freed in free count. */
212 #define IN_PAGING 0x1000 /* LFS: file is on paging queue */
213
214 #if defined(_KERNEL)
215
216 /*
217 * The DIP macro is used to access fields in the dinode that are
218 * not cached in the inode itself.
219 */
220 #define DIP(ip, field) \
221 (((ip)->i_ump->um_fstype == UFS1) ? \
222 (ip)->i_ffs1_##field : (ip)->i_ffs2_##field)
223
224 #define DIP_ASSIGN(ip, field, value) \
225 do { \
226 if ((ip)->i_ump->um_fstype == UFS1) \
227 (ip)->i_ffs1_##field = (value); \
228 else \
229 (ip)->i_ffs2_##field = (value); \
230 } while(0)
231
232 #define DIP_ADD(ip, field, value) \
233 do { \
234 if ((ip)->i_ump->um_fstype == UFS1) \
235 (ip)->i_ffs1_##field += (value); \
236 else \
237 (ip)->i_ffs2_##field += (value); \
238 } while(0)
239
240 #define SHORTLINK(ip) \
241 (((ip)->i_ump->um_fstype == UFS1) ? \
242 (caddr_t)(ip)->i_ffs1_db : (caddr_t)(ip)->i_ffs2_db)
243
244
245 /*
246 * Structure used to pass around logical block paths generated by
247 * ufs_getlbns and used by truncate and bmap code.
248 */
249 struct indir {
250 daddr_t in_lbn; /* Logical block number. */
251 int in_off; /* Offset in buffer. */
252 int in_exists; /* Flag if the block exists. */
253 };
254
255 /* Convert between inode pointers and vnode pointers. */
256 #define VTOI(vp) ((struct inode *)(vp)->v_data)
257 #define ITOV(ip) ((ip)->i_vnode)
258
259 #define FFS_ITIMES(ip, acc, mod, cre) { \
260 if ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) { \
261 if ((ip)->i_flag & IN_ACCESS) { \
262 DIP_ASSIGN(ip, atime, (acc)->tv_sec); \
263 DIP_ASSIGN(ip, atimensec, (acc)->tv_nsec); \
264 (ip)->i_flag |= IN_ACCESSED; \
265 } \
266 if ((ip)->i_flag & IN_UPDATE) { \
267 DIP_ASSIGN(ip, mtime, (mod)->tv_sec); \
268 DIP_ASSIGN(ip, mtimensec, (mod)->tv_nsec); \
269 (ip)->i_modrev++; \
270 (ip)->i_flag |= IN_MODIFIED; \
271 } \
272 if ((ip)->i_flag & IN_CHANGE) { \
273 DIP_ASSIGN(ip, ctime, (cre)->tv_sec); \
274 DIP_ASSIGN(ip, ctimensec, (cre)->tv_nsec); \
275 (ip)->i_flag |= IN_MODIFIED; \
276 } \
277 (ip)->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE); \
278 } \
279 }
280
281 #define EXT2FS_ITIMES(ip, acc, mod, cre) { \
282 if ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) { \
283 if ((ip)->i_flag & IN_ACCESS) { \
284 (ip)->i_e2fs_atime = (acc)->tv_sec; \
285 (ip)->i_flag |= IN_ACCESSED; \
286 } \
287 if ((ip)->i_flag & IN_UPDATE) { \
288 (ip)->i_e2fs_mtime = (mod)->tv_sec; \
289 (ip)->i_modrev++; \
290 (ip)->i_flag |= IN_MODIFIED; \
291 } \
292 if ((ip)->i_flag & IN_CHANGE) { \
293 (ip)->i_e2fs_ctime = (cre)->tv_sec; \
294 (ip)->i_flag |= IN_MODIFIED; \
295 } \
296 (ip)->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE); \
297 } \
298 }
299
300 #define ITIMES(ip, acc, mod, cre) { \
301 if (IS_EXT2_VNODE((ip)->i_vnode)) \
302 EXT2FS_ITIMES(ip, acc, mod, cre) \
303 else \
304 FFS_ITIMES(ip, acc, mod, cre) \
305 }
306
307 /* Determine if soft dependencies are being done */
308 #define DOINGSOFTDEP(vp) ((vp)->v_mount->mnt_flag & MNT_SOFTDEP)
309
310 /* This overlays the fid structure (see mount.h). */
311 struct ufid {
312 u_int16_t ufid_len; /* Length of structure. */
313 u_int16_t ufid_pad; /* Force 32-bit alignment. */
314 ino_t ufid_ino; /* File number (ino). */
315 int32_t ufid_gen; /* Generation number. */
316 };
317 #endif /* _KERNEL */
318
319 #endif /* !_UFS_UFS_INODE_H_ */
Cache object: f1149422e068e07361fa94ffd43b756d
|