Annotation of src/sys/ufs/ufs/inode.h, Revision 1.35
1.35 ! kristerw 1: /* $NetBSD: inode.h,v 1.34 2003/04/02 10:39:43 fvdl Exp $ */
1.6 mycroft 2:
1.1 mycroft 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. All advertising materials mentioning features or use of this software
21: * must display the following acknowledgement:
22: * This product includes software developed by the University of
23: * California, Berkeley and its contributors.
24: * 4. Neither the name of the University nor the names of its contributors
25: * may be used to endorse or promote products derived from this software
26: * without specific prior written permission.
27: *
28: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38: * SUCH DAMAGE.
39: *
1.11 fvdl 40: * @(#)inode.h 8.9 (Berkeley) 5/14/95
1.1 mycroft 41: */
42:
1.31 matt 43: #ifndef _UFS_UFS_INODE_H_
44: #define _UFS_UFS_INODE_H_
45:
1.23 chs 46: #include <sys/vnode.h>
1.1 mycroft 47: #include <ufs/ufs/dinode.h>
1.8 cgd 48: #include <ufs/ufs/dir.h>
1.26 lukem 49: #include <ufs/ufs/quota.h>
1.10 bouyer 50: #include <ufs/ext2fs/ext2fs_dinode.h>
1.25 chs 51: #include <miscfs/genfs/genfs_node.h>
1.10 bouyer 52:
53: /*
54: * Per-filesystem inode extensions.
55: */
56: struct ext2fs_inode_ext {
1.32 fvdl 57: daddr_t ext2fs_last_lblk; /* last logical block allocated */
58: daddr_t ext2fs_last_blk; /* last block allocated on disk */
1.14 fvdl 59: };
60:
1.33 perseant 61: struct lfs_inode_ext;
1.1 mycroft 62:
63: /*
1.5 mycroft 64: * The inode is used to describe each active (or recently active) file in the
65: * UFS filesystem. It is composed of two types of information. The first part
66: * is the information that is needed only while the file is active (such as
67: * the identity of the file and linkage to speed its lookup). The second part
1.20 perseant 68: * is the permanent meta-data associated with the file which is read in
1.5 mycroft 69: * from the permanent dinode from long term storage when the file becomes
70: * active, and is put back when the file is no longer being used.
1.1 mycroft 71: */
72: struct inode {
1.25 chs 73: struct genfs_node i_gnode;
1.11 fvdl 74: LIST_ENTRY(inode) i_hash;/* Hash chain. */
1.15 enami 75: struct vnode *i_vnode; /* Vnode associated with this inode. */
1.34 fvdl 76: struct ufsmount *i_ump; /* Mount point associated with this inode. */
1.15 enami 77: struct vnode *i_devvp; /* Vnode for block I/O. */
1.5 mycroft 78: u_int32_t i_flag; /* flags, see below */
79: dev_t i_dev; /* Device associated with the inode. */
80: ino_t i_number; /* The identity of the inode. */
1.4 cgd 81:
1.1 mycroft 82: union { /* Associated filesystem. */
1.5 mycroft 83: struct fs *fs; /* FFS */
84: struct lfs *lfs; /* LFS */
1.15 enami 85: struct m_ext2fs *e2fs; /* EXT2FS */
1.1 mycroft 86: } inode_u;
87: #define i_fs inode_u.fs
88: #define i_lfs inode_u.lfs
1.15 enami 89: #define i_e2fs inode_u.e2fs
1.4 cgd 90:
1.23 chs 91: struct buflists i_pcbufhd; /* softdep pagecache buffer head */
1.5 mycroft 92: struct dquot *i_dquot[MAXQUOTAS]; /* Dquot structures. */
1.4 cgd 93: u_quad_t i_modrev; /* Revision level for NFS lease. */
1.5 mycroft 94: struct lockf *i_lockf;/* Head of byte-level lock list. */
1.25 chs 95:
1.5 mycroft 96: /*
97: * Side effects; used during directory lookup.
98: */
99: int32_t i_count; /* Size of free slot in directory. */
100: doff_t i_endoff; /* End of useful stuff in directory. */
101: doff_t i_diroff; /* Offset in dir, where we found last entry. */
102: doff_t i_offset; /* Offset of free space in directory. */
103: u_int32_t i_reclen; /* Size of found directory entry. */
1.20 perseant 104: int i_ffs_effnlink; /* i_nlink when I/O completes */
1.5 mycroft 105: /*
1.10 bouyer 106: * Inode extensions
107: */
108: union {
109: /* Other extensions could go here... */
1.15 enami 110: struct ext2fs_inode_ext e2fs;
1.33 perseant 111: struct lfs_inode_ext *lfs;
1.10 bouyer 112: } inode_ext;
1.15 enami 113: #define i_e2fs_last_lblk inode_ext.e2fs.ext2fs_last_lblk
114: #define i_e2fs_last_blk inode_ext.e2fs.ext2fs_last_blk
1.10 bouyer 115: /*
1.34 fvdl 116: * Copies from the on-disk dinode itself.
117: *
118: * These fields are currently only used by FFS and LFS,
119: * do NOT use them with ext2fs.
120: */
121: u_int16_t i_mode; /* IFMT, permissions; see below. */
122: int16_t i_nlink; /* File link count. */
123: u_int64_t i_size; /* File byte count. */
124: u_int32_t i_flags; /* Status flags (chflags). */
125: int32_t i_gen; /* Generation number. */
126: u_int32_t i_uid; /* File owner. */
127: u_int32_t i_gid; /* File group. */
128:
129: /*
1.5 mycroft 130: * The on-disk dinode itself.
131: */
1.10 bouyer 132: union {
1.34 fvdl 133: struct ufs1_dinode *ffs1_din; /* 128 bytes of the on-disk dinode. */
134: struct ufs2_dinode *ffs2_din;
135: struct ext2fs_dinode *e2fs_din; /* 128 bytes of the on-disk
1.16 enami 136: dinode. */
1.10 bouyer 137: } i_din;
1.1 mycroft 138: };
139:
1.34 fvdl 140: #define i_ffs1_atime i_din.ffs1_din->di_atime
141: #define i_ffs1_atimensec i_din.ffs1_din->di_atimensec
142: #define i_ffs1_blocks i_din.ffs1_din->di_blocks
143: #define i_ffs1_ctime i_din.ffs1_din->di_ctime
144: #define i_ffs1_ctimensec i_din.ffs1_din->di_ctimensec
145: #define i_ffs1_db i_din.ffs1_din->di_db
146: #define i_ffs1_flags i_din.ffs1_din->di_flags
147: #define i_ffs1_gen i_din.ffs1_din->di_gen
148: #define i_ffs1_gid i_din.ffs1_din->di_gid
149: #define i_ffs1_ib i_din.ffs1_din->di_ib
150: #define i_ffs1_mode i_din.ffs1_din->di_mode
151: #define i_ffs1_mtime i_din.ffs1_din->di_mtime
152: #define i_ffs1_mtimensec i_din.ffs1_din->di_mtimensec
153: #define i_ffs1_nlink i_din.ffs1_din->di_nlink
154: #define i_ffs1_rdev i_din.ffs1_din->di_rdev
155: #define i_ffs1_size i_din.ffs1_din->di_size
156: #define i_ffs1_uid i_din.ffs1_din->di_uid
157: #define i_ffs1_ouid i_din.ffs1_din->di_u.oldids[0]
158: #define i_ffs1_ogid i_din.ffs1_din->di_u.oldids[1]
159:
160: #define i_ffs2_atime i_din.ffs2_din->di_atime
161: #define i_ffs2_atimensec i_din.ffs2_din->di_atimensec
162: #define i_ffs2_birthtime i_din.ffs2_din->di_birthtime
163: #define i_ffs2_birthnsec i_din.ffs2_din->di_birthnsec
164: #define i_ffs2_blocks i_din.ffs2_din->di_blocks
165: #define i_ffs2_blksize i_din.ffs2_din->di_blksize
166: #define i_ffs2_ctime i_din.ffs2_din->di_ctime
167: #define i_ffs2_ctimensec i_din.ffs2_din->di_ctimensec
168: #define i_ffs2_db i_din.ffs2_din->di_db
169: #define i_ffs2_flags i_din.ffs2_din->di_flags
170: #define i_ffs2_gen i_din.ffs2_din->di_gen
171: #define i_ffs2_gid i_din.ffs2_din->di_gid
172: #define i_ffs2_ib i_din.ffs2_din->di_ib
173: #define i_ffs2_mode i_din.ffs2_din->di_mode
174: #define i_ffs2_mtime i_din.ffs2_din->di_mtime
175: #define i_ffs2_mtimensec i_din.ffs2_din->di_mtimensec
176: #define i_ffs2_nlink i_din.ffs2_din->di_nlink
177: #define i_ffs2_rdev i_din.ffs2_din->di_rdev
178: #define i_ffs2_size i_din.ffs2_din->di_size
179: #define i_ffs2_uid i_din.ffs2_din->di_uid
180: #define i_ffs2_kernflags i_din.ffs2_din->di_kernflags
181: #define i_ffs2_extsize i_din.ffs2_din->di_extsize
182: #define i_ffs2_extb i_din.ffs2_din->di_extb
183:
184: #define i_e2fs_mode i_din.e2fs_din->e2di_mode
185: #define i_e2fs_uid i_din.e2fs_din->e2di_uid
186: #define i_e2fs_size i_din.e2fs_din->e2di_size
187: #define i_e2fs_atime i_din.e2fs_din->e2di_atime
188: #define i_e2fs_ctime i_din.e2fs_din->e2di_ctime
189: #define i_e2fs_mtime i_din.e2fs_din->e2di_mtime
190: #define i_e2fs_dtime i_din.e2fs_din->e2di_dtime
191: #define i_e2fs_gid i_din.e2fs_din->e2di_gid
192: #define i_e2fs_nlink i_din.e2fs_din->e2di_nlink
193: #define i_e2fs_nblock i_din.e2fs_din->e2di_nblock
194: #define i_e2fs_flags i_din.e2fs_din->e2di_flags
195: #define i_e2fs_blocks i_din.e2fs_din->e2di_blocks
196: #define i_e2fs_gen i_din.e2fs_din->e2di_gen
197: #define i_e2fs_facl i_din.e2fs_din->e2di_facl
198: #define i_e2fs_dacl i_din.e2fs_din->e2di_dacl
199: #define i_e2fs_faddr i_din.e2fs_din->e2di_faddr
200: #define i_e2fs_nfrag i_din.e2fs_din->e2di_nfrag
201: #define i_e2fs_fsize i_din.e2fs_din->e2di_fsize
202: #define i_e2fs_rdev i_din.e2fs_din->e2di_rdev
1.1 mycroft 203:
1.5 mycroft 204: /* These flags are kept in i_flag. */
205: #define IN_ACCESS 0x0001 /* Access time update request. */
206: #define IN_CHANGE 0x0002 /* Inode change time update request. */
1.11 fvdl 207: #define IN_UPDATE 0x0004 /* Modification time update request. */
208: #define IN_MODIFIED 0x0008 /* Inode has been modified. */
1.18 mycroft 209: #define IN_ACCESSED 0x0010 /* Inode has been accessed. */
210: #define IN_RENAME 0x0020 /* Inode is being renamed. */
211: #define IN_SHLOCK 0x0040 /* File has shared lock. */
212: #define IN_EXLOCK 0x0080 /* File has exclusive lock. */
213: #define IN_CLEANING 0x0100 /* LFS: file is being cleaned */
214: #define IN_ADIROP 0x0200 /* LFS: dirop in progress */
1.27 fvdl 215: #define IN_SPACECOUNTED 0x0400 /* Blocks to be freed in free count. */
1.33 perseant 216: #define IN_PAGING 0x1000 /* LFS: file is on paging queue */
1.5 mycroft 217:
1.24 mrg 218: #if defined(_KERNEL)
1.34 fvdl 219:
220: /*
221: * The DIP macro is used to access fields in the dinode that are
222: * not cached in the inode itself.
223: */
224: #define DIP(ip, field) \
225: (((ip)->i_ump->um_fstype == UFS1) ? \
226: (ip)->i_ffs1_##field : (ip)->i_ffs2_##field)
227:
1.35 ! kristerw 228: #define DIP_ASSIGN(ip, field, value) \
! 229: do { \
! 230: if ((ip)->i_ump->um_fstype == UFS1) \
! 231: (ip)->i_ffs1_##field = (value); \
! 232: else \
! 233: (ip)->i_ffs2_##field = (value); \
! 234: } while(0)
! 235:
! 236: #define DIP_ADD(ip, field, value) \
! 237: do { \
! 238: if ((ip)->i_ump->um_fstype == UFS1) \
! 239: (ip)->i_ffs1_##field += (value); \
! 240: else \
! 241: (ip)->i_ffs2_##field += (value); \
! 242: } while(0)
! 243:
1.34 fvdl 244: #define SHORTLINK(ip) \
245: (((ip)->i_ump->um_fstype == UFS1) ? \
246: (caddr_t)(ip)->i_ffs1_db : (caddr_t)(ip)->i_ffs2_db)
247:
248:
1.1 mycroft 249: /*
250: * Structure used to pass around logical block paths generated by
251: * ufs_getlbns and used by truncate and bmap code.
252: */
253: struct indir {
1.32 fvdl 254: daddr_t in_lbn; /* Logical block number. */
1.1 mycroft 255: int in_off; /* Offset in buffer. */
256: int in_exists; /* Flag if the block exists. */
257: };
258:
259: /* Convert between inode pointers and vnode pointers. */
1.8 cgd 260: #define VTOI(vp) ((struct inode *)(vp)->v_data)
261: #define ITOV(ip) ((ip)->i_vnode)
1.1 mycroft 262:
1.10 bouyer 263: #define FFS_ITIMES(ip, acc, mod, cre) { \
264: if ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) { \
265: if ((ip)->i_flag & IN_ACCESS) { \
1.35 ! kristerw 266: DIP_ASSIGN(ip, atime, (acc)->tv_sec); \
! 267: DIP_ASSIGN(ip, atimensec, (acc)->tv_nsec); \
1.18 mycroft 268: (ip)->i_flag |= IN_ACCESSED; \
1.10 bouyer 269: } \
270: if ((ip)->i_flag & IN_UPDATE) { \
1.35 ! kristerw 271: DIP_ASSIGN(ip, mtime, (mod)->tv_sec); \
! 272: DIP_ASSIGN(ip, mtimensec, (mod)->tv_nsec); \
1.10 bouyer 273: (ip)->i_modrev++; \
1.18 mycroft 274: (ip)->i_flag |= IN_MODIFIED; \
1.10 bouyer 275: } \
276: if ((ip)->i_flag & IN_CHANGE) { \
1.35 ! kristerw 277: DIP_ASSIGN(ip, ctime, (cre)->tv_sec); \
! 278: DIP_ASSIGN(ip, ctimensec, (cre)->tv_nsec); \
1.18 mycroft 279: (ip)->i_flag |= IN_MODIFIED; \
1.10 bouyer 280: } \
281: (ip)->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE); \
282: } \
283: }
284:
1.15 enami 285: #define EXT2FS_ITIMES(ip, acc, mod, cre) { \
1.1 mycroft 286: if ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) { \
1.9 mycroft 287: if ((ip)->i_flag & IN_ACCESS) { \
1.15 enami 288: (ip)->i_e2fs_atime = (acc)->tv_sec; \
1.19 mycroft 289: (ip)->i_flag |= IN_ACCESSED; \
1.9 mycroft 290: } \
1.1 mycroft 291: if ((ip)->i_flag & IN_UPDATE) { \
1.15 enami 292: (ip)->i_e2fs_mtime = (mod)->tv_sec; \
1.1 mycroft 293: (ip)->i_modrev++; \
1.19 mycroft 294: (ip)->i_flag |= IN_MODIFIED; \
1.1 mycroft 295: } \
1.9 mycroft 296: if ((ip)->i_flag & IN_CHANGE) { \
1.15 enami 297: (ip)->i_e2fs_ctime = (cre)->tv_sec; \
1.19 mycroft 298: (ip)->i_flag |= IN_MODIFIED; \
1.9 mycroft 299: } \
1.1 mycroft 300: (ip)->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE); \
301: } \
1.10 bouyer 302: }
303:
1.15 enami 304: #define ITIMES(ip, acc, mod, cre) { \
305: if (IS_EXT2_VNODE((ip)->i_vnode)) \
306: EXT2FS_ITIMES(ip, acc, mod, cre) \
307: else \
308: FFS_ITIMES(ip, acc, mod, cre) \
1.1 mycroft 309: }
1.14 fvdl 310:
311: /* Determine if soft dependencies are being done */
1.15 enami 312: #define DOINGSOFTDEP(vp) ((vp)->v_mount->mnt_flag & MNT_SOFTDEP)
1.1 mycroft 313:
314: /* This overlays the fid structure (see mount.h). */
315: struct ufid {
1.5 mycroft 316: u_int16_t ufid_len; /* Length of structure. */
317: u_int16_t ufid_pad; /* Force 32-bit alignment. */
318: ino_t ufid_ino; /* File number (ino). */
319: int32_t ufid_gen; /* Generation number. */
1.1 mycroft 320: };
1.7 jtc 321: #endif /* _KERNEL */
1.31 matt 322:
323: #endif /* !_UFS_UFS_INODE_H_ */
CVSweb <webmaster@jp.NetBSD.org>