1 /* $NetBSD: inode.h,v 1.27 2001/12/18 10:57:23 fvdl 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. 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 * 40 * @(#)inode.h 8.9 (Berkeley) 5/14/95 41 */ 42 43 #include <sys/vnode.h> 44 #include <ufs/ufs/dinode.h> 45 #include <ufs/ufs/dir.h> 46 #include <ufs/ufs/quota.h> 47 #include <ufs/ext2fs/ext2fs_dinode.h> 48 #include <ufs/lfs/lfs_extern.h> 49 #include <miscfs/genfs/genfs_node.h> 50 51 /* 52 * Per-filesystem inode extensions. 53 */ 54 struct ext2fs_inode_ext { 55 ufs_daddr_t ext2fs_last_lblk; /* last logical block allocated */ 56 ufs_daddr_t ext2fs_last_blk; /* last block allocated on disk */ 57 }; 58 59 struct lfs_inode_ext { 60 u_int32_t lfs_effnblocks; /* number of blocks when i/o completes */ 61 }; 62 63 /* 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 68 * is the permanent meta-data associated with the file which is read in 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. 71 */ 72 struct inode { 73 struct genfs_node i_gnode; 74 LIST_ENTRY(inode) i_hash;/* Hash chain. */ 75 struct vnode *i_vnode; /* Vnode associated with this inode. */ 76 struct vnode *i_devvp; /* Vnode for block I/O. */ 77 u_int32_t i_flag; /* flags, see below */ 78 dev_t i_dev; /* Device associated with the inode. */ 79 ino_t i_number; /* The identity of the inode. */ 80 81 union { /* Associated filesystem. */ 82 struct fs *fs; /* FFS */ 83 struct lfs *lfs; /* LFS */ 84 struct m_ext2fs *e2fs; /* EXT2FS */ 85 } inode_u; 86 #define i_fs inode_u.fs 87 #define i_lfs inode_u.lfs 88 #define i_e2fs inode_u.e2fs 89 90 struct buflists i_pcbufhd; /* softdep pagecache buffer head */ 91 struct dquot *i_dquot[MAXQUOTAS]; /* Dquot structures. */ 92 u_quad_t i_modrev; /* Revision level for NFS lease. */ 93 struct lockf *i_lockf;/* Head of byte-level lock list. */ 94 95 /* 96 * Side effects; used during directory lookup. 97 */ 98 int32_t i_count; /* Size of free slot in directory. */ 99 doff_t i_endoff; /* End of useful stuff in directory. */ 100 doff_t i_diroff; /* Offset in dir, where we found last entry. */ 101 doff_t i_offset; /* Offset of free space in directory. */ 102 ino_t i_ino; /* Inode number of found directory. */ 103 u_int32_t i_reclen; /* Size of found directory entry. */ 104 int i_ffs_effnlink; /* i_nlink when I/O completes */ 105 /* 106 * Inode extensions 107 */ 108 union { 109 /* Other extensions could go here... */ 110 struct ext2fs_inode_ext e2fs; 111 struct lfs_inode_ext lfs; 112 } inode_ext; 113 #define i_e2fs_last_lblk inode_ext.e2fs.ext2fs_last_lblk 114 #define i_e2fs_last_blk inode_ext.e2fs.ext2fs_last_blk 115 #define i_lfs_effnblks inode_ext.lfs.lfs_effnblocks 116 /* 117 * The on-disk dinode itself. 118 */ 119 union { 120 struct dinode ffs_din; /* 128 bytes of the on-disk dinode. */ 121 struct ext2fs_dinode e2fs_din; /* 128 bytes of the on-disk 122 dinode. */ 123 } i_din; 124 }; 125 126 #define i_ffs_atime i_din.ffs_din.di_atime 127 #define i_ffs_atimensec i_din.ffs_din.di_atimensec 128 #define i_ffs_blocks i_din.ffs_din.di_blocks 129 #define i_ffs_ctime i_din.ffs_din.di_ctime 130 #define i_ffs_ctimensec i_din.ffs_din.di_ctimensec 131 #define i_ffs_db i_din.ffs_din.di_db 132 #define i_ffs_flags i_din.ffs_din.di_flags 133 #define i_ffs_gen i_din.ffs_din.di_gen 134 #define i_ffs_gid i_din.ffs_din.di_gid 135 #define i_ffs_ib i_din.ffs_din.di_ib 136 #define i_ffs_mode i_din.ffs_din.di_mode 137 #define i_ffs_mtime i_din.ffs_din.di_mtime 138 #define i_ffs_mtimensec i_din.ffs_din.di_mtimensec 139 #define i_ffs_nlink i_din.ffs_din.di_nlink 140 #define i_ffs_rdev i_din.ffs_din.di_rdev 141 #define i_ffs_shortlink i_din.ffs_din.di_shortlink 142 #define i_ffs_size i_din.ffs_din.di_size 143 #define i_ffs_uid i_din.ffs_din.di_uid 144 145 #define i_e2fs_mode i_din.e2fs_din.e2di_mode 146 #define i_e2fs_uid i_din.e2fs_din.e2di_uid 147 #define i_e2fs_size i_din.e2fs_din.e2di_size 148 #define i_e2fs_atime i_din.e2fs_din.e2di_atime 149 #define i_e2fs_ctime i_din.e2fs_din.e2di_ctime 150 #define i_e2fs_mtime i_din.e2fs_din.e2di_mtime 151 #define i_e2fs_dtime i_din.e2fs_din.e2di_dtime 152 #define i_e2fs_gid i_din.e2fs_din.e2di_gid 153 #define i_e2fs_nlink i_din.e2fs_din.e2di_nlink 154 #define i_e2fs_nblock i_din.e2fs_din.e2di_nblock 155 #define i_e2fs_flags i_din.e2fs_din.e2di_flags 156 #define i_e2fs_blocks i_din.e2fs_din.e2di_blocks 157 #define i_e2fs_gen i_din.e2fs_din.e2di_gen 158 #define i_e2fs_facl i_din.e2fs_din.e2di_facl 159 #define i_e2fs_dacl i_din.e2fs_din.e2di_dacl 160 #define i_e2fs_faddr i_din.e2fs_din.e2di_faddr 161 #define i_e2fs_nfrag i_din.e2fs_din.e2di_nfrag 162 #define i_e2fs_fsize i_din.e2fs_din.e2di_fsize 163 #define i_e2fs_rdev i_din.e2fs_din.e2di_rdev 164 165 /* These flags are kept in i_flag. */ 166 #define IN_ACCESS 0x0001 /* Access time update request. */ 167 #define IN_CHANGE 0x0002 /* Inode change time update request. */ 168 #define IN_UPDATE 0x0004 /* Modification time update request. */ 169 #define IN_MODIFIED 0x0008 /* Inode has been modified. */ 170 #define IN_ACCESSED 0x0010 /* Inode has been accessed. */ 171 #define IN_RENAME 0x0020 /* Inode is being renamed. */ 172 #define IN_SHLOCK 0x0040 /* File has shared lock. */ 173 #define IN_EXLOCK 0x0080 /* File has exclusive lock. */ 174 #define IN_CLEANING 0x0100 /* LFS: file is being cleaned */ 175 #define IN_ADIROP 0x0200 /* LFS: dirop in progress */ 176 #define IN_SPACECOUNTED 0x0400 /* Blocks to be freed in free count. */ 177 178 #if defined(_KERNEL) 179 #if defined(_KERNEL_OPT) 180 #include "fs_lfs.h" /* for ITIMES */ 181 #endif /* _KERNEL_OPT */ 182 /* 183 * Structure used to pass around logical block paths generated by 184 * ufs_getlbns and used by truncate and bmap code. 185 */ 186 struct indir { 187 ufs_daddr_t in_lbn; /* Logical block number. */ 188 int in_off; /* Offset in buffer. */ 189 int in_exists; /* Flag if the block exists. */ 190 }; 191 192 /* Convert between inode pointers and vnode pointers. */ 193 #define VTOI(vp) ((struct inode *)(vp)->v_data) 194 #define ITOV(ip) ((ip)->i_vnode) 195 196 #define FFS_ITIMES(ip, acc, mod, cre) { \ 197 if ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) { \ 198 if ((ip)->i_flag & IN_ACCESS) { \ 199 (ip)->i_ffs_atime = (acc)->tv_sec; \ 200 (ip)->i_ffs_atimensec = (acc)->tv_nsec; \ 201 (ip)->i_flag |= IN_ACCESSED; \ 202 } \ 203 if ((ip)->i_flag & IN_UPDATE) { \ 204 (ip)->i_ffs_mtime = (mod)->tv_sec; \ 205 (ip)->i_ffs_mtimensec = (mod)->tv_nsec; \ 206 (ip)->i_modrev++; \ 207 (ip)->i_flag |= IN_MODIFIED; \ 208 } \ 209 if ((ip)->i_flag & IN_CHANGE) { \ 210 (ip)->i_ffs_ctime = (cre)->tv_sec; \ 211 (ip)->i_ffs_ctimensec = (cre)->tv_nsec; \ 212 (ip)->i_flag |= IN_MODIFIED; \ 213 } \ 214 (ip)->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE); \ 215 } \ 216 } 217 218 #define EXT2FS_ITIMES(ip, acc, mod, cre) { \ 219 if ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) { \ 220 if ((ip)->i_flag & IN_ACCESS) { \ 221 (ip)->i_e2fs_atime = (acc)->tv_sec; \ 222 (ip)->i_flag |= IN_ACCESSED; \ 223 } \ 224 if ((ip)->i_flag & IN_UPDATE) { \ 225 (ip)->i_e2fs_mtime = (mod)->tv_sec; \ 226 (ip)->i_modrev++; \ 227 (ip)->i_flag |= IN_MODIFIED; \ 228 } \ 229 if ((ip)->i_flag & IN_CHANGE) { \ 230 (ip)->i_e2fs_ctime = (cre)->tv_sec; \ 231 (ip)->i_flag |= IN_MODIFIED; \ 232 } \ 233 (ip)->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE); \ 234 } \ 235 } 236 237 #ifdef LFS 238 #define ITIMES(ip, acc, mod, cre) { \ 239 if (IS_EXT2_VNODE((ip)->i_vnode)) \ 240 EXT2FS_ITIMES(ip, acc, mod, cre) \ 241 else if(IS_LFS_VNODE((ip)->i_vnode)) \ 242 lfs_itimes(ip, acc, mod, cre); \ 243 else \ 244 FFS_ITIMES(ip, acc, mod, cre) \ 245 } 246 #else /* ! LFS */ 247 #define ITIMES(ip, acc, mod, cre) { \ 248 if (IS_EXT2_VNODE((ip)->i_vnode)) \ 249 EXT2FS_ITIMES(ip, acc, mod, cre) \ 250 else \ 251 FFS_ITIMES(ip, acc, mod, cre) \ 252 } 253 #endif /* ! LFS */ 254 255 /* Determine if soft dependencies are being done */ 256 #define DOINGSOFTDEP(vp) ((vp)->v_mount->mnt_flag & MNT_SOFTDEP) 257 258 /* This overlays the fid structure (see mount.h). */ 259 struct ufid { 260 u_int16_t ufid_len; /* Length of structure. */ 261 u_int16_t ufid_pad; /* Force 32-bit alignment. */ 262 ino_t ufid_ino; /* File number (ino). */ 263 int32_t ufid_gen; /* Generation number. */ 264 }; 265 #endif /* _KERNEL */ 266