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