1 /* 2 * Copyright (c) 1982, 1989 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)inode.h 7.23 (Berkeley) 03/27/92 8 */ 9 10 #include <ufs/ufs/dinode.h> 11 12 /* 13 * Theoretically, directories can be more than 2Gb in length, 14 * however, in practice this seems unlikely. So, we define 15 * the type doff_t as a long to keep down the cost of doing 16 * lookup on a 32-bit machine. If you are porting to a 64-bit 17 * architecture, you should make doff_t the same as off_t. 18 */ 19 #define doff_t long 20 21 /* 22 * The inode is used to describe each active (or recently active) 23 * file in the UFS filesystem. It is composed of two types of 24 * information. The first part is the information that is needed 25 * only while the file is active (such as the identity of the file 26 * and linkage to speed its lookup). The second part is the 27 * permannent meta-data associated with the file which is read 28 * in from the permanent dinode from long term storage when the 29 * file becomes active, and is put back when the file is no longer 30 * being used. 31 */ 32 struct inode { 33 struct inode *i_chain[2]; /* hash chain, MUST be first */ 34 struct vnode *i_vnode; /* vnode associated with this inode */ 35 struct vnode *i_devvp; /* vnode for block I/O */ 36 u_long i_flag; /* see below */ 37 dev_t i_dev; /* device where inode resides */ 38 short i_pad; 39 ino_t i_number; /* the identity of the inode */ 40 union { /* associated filesystem */ 41 struct fs *fs; /* FFS */ 42 struct lfs *lfs; /* LFS */ 43 } inode_u; 44 #define i_fs inode_u.fs 45 #define i_lfs inode_u.lfs 46 struct dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */ 47 struct lockf *i_lockf; /* head of byte-level lock list */ 48 u_quad_t i_modrev; /* revision level for lease */ 49 pid_t i_lockholder; /* DEBUG: holder of inode lock */ 50 pid_t i_lockwaiter; /* DEBUG: latest blocked for inode lock */ 51 /* 52 * Side effects; used during directory lookup. 53 */ 54 doff_t i_endoff; /* end of useful stuff in directory */ 55 doff_t i_diroff; /* offset in dir, where we found last entry */ 56 doff_t i_offset; /* offset of free space in directory */ 57 long i_count; /* size of free slot in directory */ 58 ino_t i_ino; /* inode number of found directory */ 59 u_long i_reclen; /* size of found directory entry */ 60 /* 61 * the on-disk dinode itself. 62 */ 63 struct dinode i_din; /* the on-disk dinode */ 64 long i_spare[12]; /* spares to round up to 256 bytes */ 65 }; 66 67 #define i_mode i_din.di_mode 68 #define i_nlink i_din.di_nlink 69 #define i_uid i_din.di_uid 70 #define i_gid i_din.di_gid 71 #ifdef _NOQUAD 72 #define i_size i_din.di_qsize.val[_QUAD_LOWWORD] 73 #else 74 #define i_size i_din.di_qsize 75 #endif 76 #if defined(tahoe) /* ugh! -- must be fixed */ 77 #undef i_size 78 #define i_size i_din.di_qsize.val[0] 79 #endif 80 #define i_db i_din.di_db 81 #define i_ib i_din.di_ib 82 #define i_atime i_din.di_atime 83 #define i_mtime i_din.di_mtime 84 #define i_ctime i_din.di_ctime 85 #define i_blocks i_din.di_blocks 86 #define i_rdev i_din.di_db[0] 87 #define i_flags i_din.di_flags 88 #define i_gen i_din.di_gen 89 #define i_forw i_chain[0] 90 #define i_back i_chain[1] 91 92 /* flags */ 93 #define ILOCKED 0x0001 /* inode is locked */ 94 #define IWANT 0x0002 /* some process waiting on lock */ 95 #define IRENAME 0x0004 /* inode is being renamed */ 96 #define IUPD 0x0010 /* file has been modified */ 97 #define IACC 0x0020 /* inode access time to be updated */ 98 #define ICHG 0x0040 /* inode has been changed */ 99 #define IMOD 0x0080 /* inode has been modified */ 100 #define ISHLOCK 0x0100 /* file has shared lock */ 101 #define IEXLOCK 0x0200 /* file has exclusive lock */ 102 #define ILWAIT 0x0400 /* someone waiting on file lock */ 103 104 #ifdef KERNEL 105 /* Convert between inode pointers and vnode pointers. */ 106 #define VTOI(vp) ((struct inode *)(vp)->v_data) 107 #define ITOV(ip) ((ip)->i_vnode) 108 109 /* Lock and unlock inodes. */ 110 #ifdef notdef 111 #define ILOCK(ip) { \ 112 while ((ip)->i_flag & ILOCKED) { \ 113 (ip)->i_flag |= IWANT; \ 114 (void) sleep((caddr_t)(ip), PINOD); \ 115 } \ 116 (ip)->i_flag |= ILOCKED; \ 117 } 118 119 #define IUNLOCK(ip) { \ 120 (ip)->i_flag &= ~ILOCKED; \ 121 if ((ip)->i_flag&IWANT) { \ 122 (ip)->i_flag &= ~IWANT; \ 123 wakeup((caddr_t)(ip)); \ 124 } \ 125 } 126 #else 127 #define ILOCK(ip) ufs_ilock(ip) 128 #define IUNLOCK(ip) ufs_iunlock(ip) 129 #endif 130 131 #define ITIMES(ip, t1, t2) { \ 132 if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \ 133 (ip)->i_flag |= IMOD; \ 134 if ((ip)->i_flag&IACC) \ 135 (ip)->i_atime = (t1)->tv_sec; \ 136 if ((ip)->i_flag&IUPD) { \ 137 (ip)->i_mtime = (t2)->tv_sec; \ 138 INCRQUAD((ip)->i_modrev); \ 139 } \ 140 if ((ip)->i_flag&ICHG) \ 141 (ip)->i_ctime = time.tv_sec; \ 142 (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ 143 } \ 144 } 145 146 /* This overlays the fid structure (see mount.h). */ 147 struct ufid { 148 u_short ufid_len; /* length of structure */ 149 u_short ufid_pad; /* force long alignment */ 150 ino_t ufid_ino; /* file number (ino) */ 151 long ufid_gen; /* generation number */ 152 }; 153 #endif /* KERNEL */ 154