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.13 (Berkeley) 05/10/90 8 */ 9 10 #ifdef KERNEL 11 #include "../ufs/dinode.h" 12 #else 13 #include <ufs/dinode.h> 14 #endif 15 16 /* 17 * The I node is the focus of all file activity in UNIX. 18 * There is a unique inode allocated for each active file, 19 * each current directory, each mounted-on file, text file, and the root. 20 * An inode is 'named' by its dev/inumber pair. (iget/iget.c) 21 * Data in `struct dinode' is read in from permanent inode on volume. 22 */ 23 24 struct inode { 25 struct inode *i_chain[2]; /* hash chain, MUST be first */ 26 struct vnode *i_vnode; /* vnode associated with this inode */ 27 struct vnode *i_devvp; /* vnode for block I/O */ 28 u_long i_flag; /* see below */ 29 dev_t i_dev; /* device where inode resides */ 30 ino_t i_number; /* i number, 1-to-1 with device address */ 31 struct fs *i_fs; /* file sys associated with this inode */ 32 struct dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot strauctures */ 33 long i_diroff; /* offset in dir, where we found last entry */ 34 off_t i_endoff; /* end of useful stuff in directory */ 35 long i_spare0; 36 long i_spare1; 37 struct dinode i_din; /* the on-disk inode */ 38 }; 39 40 #define i_mode i_din.di_mode 41 #define i_nlink i_din.di_nlink 42 #define i_uid i_din.di_uid 43 #define i_gid i_din.di_gid 44 #if BYTE_ORDER == LITTLE_ENDIAN || defined(tahoe) /* ugh! -- must be fixed */ 45 #define i_size i_din.di_qsize.val[0] 46 #else /* BYTE_ORDER == BIG_ENDIAN */ 47 #define i_size i_din.di_qsize.val[1] 48 #endif 49 #define i_db i_din.di_db 50 #define i_ib i_din.di_ib 51 #define i_atime i_din.di_atime 52 #define i_mtime i_din.di_mtime 53 #define i_ctime i_din.di_ctime 54 #define i_blocks i_din.di_blocks 55 #define i_rdev i_din.di_db[0] 56 #define i_flags i_din.di_flags 57 #define i_gen i_din.di_gen 58 #define i_forw i_chain[0] 59 #define i_back i_chain[1] 60 61 /* flags */ 62 #define ILOCKED 0x0001 /* inode is locked */ 63 #define IWANT 0x0002 /* some process waiting on lock */ 64 #define IRENAME 0x0004 /* inode is being renamed */ 65 #define IUPD 0x0010 /* file has been modified */ 66 #define IACC 0x0020 /* inode access time to be updated */ 67 #define ICHG 0x0040 /* inode has been changed */ 68 #define IMOD 0x0080 /* inode has been modified */ 69 #define ISHLOCK 0x0100 /* file has shared lock */ 70 #define IEXLOCK 0x0200 /* file has exclusive lock */ 71 #define ILWAIT 0x0400 /* someone waiting on file lock */ 72 73 #ifdef KERNEL 74 /* 75 * Convert between inode pointers and vnode pointers 76 */ 77 #define VTOI(vp) ((struct inode *)(vp)->v_data) 78 #define ITOV(ip) ((ip)->i_vnode) 79 80 /* 81 * Convert between vnode types and inode formats 82 */ 83 extern enum vtype iftovt_tab[]; 84 extern int vttoif_tab[]; 85 #define IFTOVT(mode) (iftovt_tab[((mode) & IFMT) >> 12]) 86 #define VTTOIF(indx) (vttoif_tab[(int)(indx)]) 87 88 #define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode)) 89 90 u_long nextgennumber; /* next generation number to assign */ 91 92 extern ino_t dirpref(); 93 94 /* 95 * Lock and unlock inodes. 96 */ 97 #ifdef notdef 98 #define ILOCK(ip) { \ 99 while ((ip)->i_flag & ILOCKED) { \ 100 (ip)->i_flag |= IWANT; \ 101 (void) sleep((caddr_t)(ip), PINOD); \ 102 } \ 103 (ip)->i_flag |= ILOCKED; \ 104 } 105 106 #define IUNLOCK(ip) { \ 107 (ip)->i_flag &= ~ILOCKED; \ 108 if ((ip)->i_flag&IWANT) { \ 109 (ip)->i_flag &= ~IWANT; \ 110 wakeup((caddr_t)(ip)); \ 111 } \ 112 } 113 #else 114 #define ILOCK(ip) ilock(ip) 115 #define IUNLOCK(ip) iunlock(ip) 116 #endif 117 118 #define IUPDAT(ip, t1, t2, waitfor) { \ 119 if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \ 120 (void) iupdat(ip, t1, t2, waitfor); \ 121 } 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 = (t1)->tv_sec; \ 128 if ((ip)->i_flag&IUPD) \ 129 (ip)->i_mtime = (t2)->tv_sec; \ 130 if ((ip)->i_flag&ICHG) \ 131 (ip)->i_ctime = time.tv_sec; \ 132 (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ 133 } \ 134 } 135 136 /* 137 * This overlays the fid sturcture (see mount.h) 138 */ 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 146