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