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.28 (Berkeley) 06/23/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 ino_t i_number; /* the identity of the inode */ 39 union { /* associated filesystem */ 40 struct fs *fs; /* FFS */ 41 struct lfs *lfs; /* LFS */ 42 } inode_u; 43 #define i_fs inode_u.fs 44 #define i_lfs inode_u.lfs 45 struct dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */ 46 u_quad_t i_modrev; /* revision level for lease */ 47 struct lockf *i_lockf; /* head of byte-level lock list */ 48 pid_t i_lockholder; /* DEBUG: holder of inode lock */ 49 pid_t i_lockwaiter; /* DEBUG: latest blocked for inode lock */ 50 /* 51 * Side effects; used during directory lookup. 52 */ 53 doff_t i_endoff; /* end of useful stuff in directory */ 54 doff_t i_diroff; /* offset in dir, where we found last entry */ 55 doff_t i_offset; /* offset of free space in directory */ 56 long i_count; /* size of free slot in directory */ 57 ino_t i_ino; /* inode number of found directory */ 58 u_long i_reclen; /* size of found directory entry */ 59 /* 60 * the on-disk dinode itself. 61 */ 62 struct dinode i_din; /* the on-disk dinode */ 63 long i_spare[12]; /* spares to round up to 256 bytes */ 64 }; 65 66 #define i_mode i_din.di_mode 67 #define i_nlink i_din.di_nlink 68 #define i_uid i_din.di_uid 69 #define i_gid i_din.di_gid 70 #define i_size i_din.di_size 71 #define i_db i_din.di_db 72 #define i_ib i_din.di_ib 73 #define i_atime i_din.di_atime 74 #define i_mtime i_din.di_mtime 75 #define i_ctime i_din.di_ctime 76 #define i_blocks i_din.di_blocks 77 #define i_rdev i_din.di_rdev 78 #define i_shortlink i_din.di_shortlink 79 #define i_flags i_din.di_flags 80 #define i_gen i_din.di_gen 81 #define i_forw i_chain[0] 82 #define i_back i_chain[1] 83 84 /* flags */ 85 #define ILOCKED 0x0001 /* inode is locked */ 86 #define IWANT 0x0002 /* some process waiting on lock */ 87 #define IRENAME 0x0004 /* inode is being renamed */ 88 #define IUPD 0x0010 /* file has been modified */ 89 #define IACC 0x0020 /* inode access time to be updated */ 90 #define ICHG 0x0040 /* inode has been changed */ 91 #define IMOD 0x0080 /* inode has been modified */ 92 #define ISHLOCK 0x0100 /* file has shared lock */ 93 #define IEXLOCK 0x0200 /* file has exclusive lock */ 94 #define ILWAIT 0x0400 /* someone waiting on file lock */ 95 96 #ifdef KERNEL 97 /* Convert between inode pointers and vnode pointers. */ 98 #define VTOI(vp) ((struct inode *)(vp)->v_data) 99 #define ITOV(ip) ((ip)->i_vnode) 100 101 /* Lock and unlock inodes. */ 102 #ifdef notdef 103 #define ILOCK(ip) { \ 104 while ((ip)->i_flag & ILOCKED) { \ 105 (ip)->i_flag |= IWANT; \ 106 (void) sleep((caddr_t)(ip), PINOD); \ 107 } \ 108 (ip)->i_flag |= ILOCKED; \ 109 } 110 111 #define IUNLOCK(ip) { \ 112 (ip)->i_flag &= ~ILOCKED; \ 113 if ((ip)->i_flag&IWANT) { \ 114 (ip)->i_flag &= ~IWANT; \ 115 wakeup((caddr_t)(ip)); \ 116 } \ 117 } 118 #else 119 #define ILOCK(ip) ufs_ilock(ip) 120 #define IUNLOCK(ip) ufs_iunlock(ip) 121 #endif 122 123 #define ITIMES(ip, t1, t2) { \ 124 if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \ 125 (ip)->i_flag |= IMOD; \ 126 if ((ip)->i_flag&IACC) \ 127 (ip)->i_atime.ts_sec = (t1)->tv_sec; \ 128 if ((ip)->i_flag&IUPD) { \ 129 (ip)->i_mtime.ts_sec = (t2)->tv_sec; \ 130 (ip)->i_modrev++; \ 131 } \ 132 if ((ip)->i_flag&ICHG) \ 133 (ip)->i_ctime.ts_sec = time.tv_sec; \ 134 (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ 135 } \ 136 } 137 138 /* This overlays the fid structure (see mount.h). */ 139 struct ufid { 140 u_short ufid_len; /* length of structure */ 141 u_short ufid_pad; /* force long alignment */ 142 ino_t ufid_ino; /* file number (ino) */ 143 long ufid_gen; /* generation number */ 144 }; 145 #endif /* KERNEL */ 146