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.27 (Berkeley) 06/20/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_db[0] 78 #define i_flags i_din.di_flags 79 #define i_gen i_din.di_gen 80 #define i_forw i_chain[0] 81 #define i_back i_chain[1] 82 83 /* flags */ 84 #define ILOCKED 0x0001 /* inode is locked */ 85 #define IWANT 0x0002 /* some process waiting on lock */ 86 #define IRENAME 0x0004 /* inode is being renamed */ 87 #define IUPD 0x0010 /* file has been modified */ 88 #define IACC 0x0020 /* inode access time to be updated */ 89 #define ICHG 0x0040 /* inode has been changed */ 90 #define IMOD 0x0080 /* inode has been modified */ 91 #define ISHLOCK 0x0100 /* file has shared lock */ 92 #define IEXLOCK 0x0200 /* file has exclusive lock */ 93 #define ILWAIT 0x0400 /* someone waiting on file lock */ 94 95 #ifdef KERNEL 96 /* Convert between inode pointers and vnode pointers. */ 97 #define VTOI(vp) ((struct inode *)(vp)->v_data) 98 #define ITOV(ip) ((ip)->i_vnode) 99 100 /* Lock and unlock inodes. */ 101 #ifdef notdef 102 #define ILOCK(ip) { \ 103 while ((ip)->i_flag & ILOCKED) { \ 104 (ip)->i_flag |= IWANT; \ 105 (void) sleep((caddr_t)(ip), PINOD); \ 106 } \ 107 (ip)->i_flag |= ILOCKED; \ 108 } 109 110 #define IUNLOCK(ip) { \ 111 (ip)->i_flag &= ~ILOCKED; \ 112 if ((ip)->i_flag&IWANT) { \ 113 (ip)->i_flag &= ~IWANT; \ 114 wakeup((caddr_t)(ip)); \ 115 } \ 116 } 117 #else 118 #define ILOCK(ip) ufs_ilock(ip) 119 #define IUNLOCK(ip) ufs_iunlock(ip) 120 #endif 121 122 #define ITIMES(ip, t1, t2) { \ 123 if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \ 124 (ip)->i_flag |= IMOD; \ 125 if ((ip)->i_flag&IACC) \ 126 (ip)->i_atime.ts_sec = (t1)->tv_sec; \ 127 if ((ip)->i_flag&IUPD) { \ 128 (ip)->i_mtime.ts_sec = (t2)->tv_sec; \ 129 (ip)->i_modrev++; \ 130 } \ 131 if ((ip)->i_flag&ICHG) \ 132 (ip)->i_ctime.ts_sec = time.tv_sec; \ 133 (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ 134 } \ 135 } 136 137 /* This overlays the fid structure (see mount.h). */ 138 struct ufid { 139 u_short ufid_len; /* length of structure */ 140 u_short ufid_pad; /* force long alignment */ 141 ino_t ufid_ino; /* file number (ino) */ 142 long ufid_gen; /* generation number */ 143 }; 144 #endif /* KERNEL */ 145