| 1 | /* |
| 2 | * Copyright (c) 1982, 1989 The Regents of the University of California. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms are permitted |
| 6 | * provided that the above copyright notice and this paragraph are |
| 7 | * duplicated in all such forms and that any documentation, |
| 8 | * advertising materials, and other materials related to such |
| 9 | * distribution and use acknowledge that the software was developed |
| 10 | * by the University of California, Berkeley. The name of the |
| 11 | * University may not be used to endorse or promote products derived |
| 12 | * from this software without specific prior written permission. |
| 13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
| 14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
| 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 16 | * |
| 17 | * @(#)inode.h 7.3 (Berkeley) %G% |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * The I node is the focus of all file activity in UNIX. |
| 22 | * There is a unique inode allocated for each active file, |
| 23 | * each current directory, each mounted-on file, text file, and the root. |
| 24 | * An inode is 'named' by its dev/inumber pair. (iget/iget.c) |
| 25 | * Data in icommon is read in from permanent inode on volume. |
| 26 | */ |
| 27 | |
| 28 | #define NDADDR 12 /* direct addresses in inode */ |
| 29 | #define NIADDR 3 /* indirect addresses in inode */ |
| 30 | |
| 31 | struct inode { |
| 32 | struct inode *i_chain[2]; /* must be first */ |
| 33 | struct vnode i_vnode; /* vnode associated with this inode */ |
| 34 | struct vnode *i_devvp; /* vnode for block I/O */ |
| 35 | u_short i_flag; |
| 36 | dev_t i_dev; /* device where inode resides */ |
| 37 | ino_t i_number; /* i number, 1-to-1 with device address */ |
| 38 | long i_id; /* unique identifier */ |
| 39 | long i_diroff; /* offset in dir, where we found last entry */ |
| 40 | struct fs *i_fs; /* file sys associated with this inode */ |
| 41 | struct dquot *i_dquot; /* quota structure controlling this file */ |
| 42 | struct text *i_text; /* text entry, if any (should be region) */ |
| 43 | struct inode *i_devlst;/* list of block device inodes */ |
| 44 | off_t i_endoff; /* end of useful stuff in directory */ |
| 45 | union { |
| 46 | daddr_t if_lastr; /* last read (read-ahead) */ |
| 47 | struct socket *is_socket; |
| 48 | struct { |
| 49 | struct inode *if_freef; /* free list forward */ |
| 50 | struct inode **if_freeb; /* free list back */ |
| 51 | } i_fr; |
| 52 | } i_un; |
| 53 | struct icommon |
| 54 | { |
| 55 | u_short ic_mode; /* 0: mode and type of file */ |
| 56 | short ic_nlink; /* 2: number of links to file */ |
| 57 | uid_t ic_uid; /* 4: owner's user id */ |
| 58 | gid_t ic_gid; /* 6: owner's group id */ |
| 59 | quad ic_size; /* 8: number of bytes in file */ |
| 60 | time_t ic_atime; /* 16: time last accessed */ |
| 61 | long ic_atspare; |
| 62 | time_t ic_mtime; /* 24: time last modified */ |
| 63 | long ic_mtspare; |
| 64 | time_t ic_ctime; /* 32: last time inode changed */ |
| 65 | long ic_ctspare; |
| 66 | daddr_t ic_db[NDADDR]; /* 40: disk block addresses */ |
| 67 | daddr_t ic_ib[NIADDR]; /* 88: indirect blocks */ |
| 68 | long ic_flags; /* 100: status, currently unused */ |
| 69 | long ic_blocks; /* 104: blocks actually held */ |
| 70 | long ic_gen; /* 108: generation number */ |
| 71 | long ic_spare[4]; /* 112: reserved, currently unused */ |
| 72 | } i_ic; |
| 73 | }; |
| 74 | |
| 75 | struct dinode { |
| 76 | union { |
| 77 | struct icommon di_icom; |
| 78 | char di_size[128]; |
| 79 | } di_un; |
| 80 | }; |
| 81 | |
| 82 | #define i_mode i_ic.ic_mode |
| 83 | #define i_nlink i_ic.ic_nlink |
| 84 | #define i_uid i_ic.ic_uid |
| 85 | #define i_gid i_ic.ic_gid |
| 86 | /* ugh! -- must be fixed */ |
| 87 | #if defined(vax) || defined(tahoe) |
| 88 | #define i_size i_ic.ic_size.val[0] |
| 89 | #endif |
| 90 | #define i_db i_ic.ic_db |
| 91 | #define i_ib i_ic.ic_ib |
| 92 | #define i_atime i_ic.ic_atime |
| 93 | #define i_mtime i_ic.ic_mtime |
| 94 | #define i_ctime i_ic.ic_ctime |
| 95 | #define i_blocks i_ic.ic_blocks |
| 96 | #define i_rdev i_ic.ic_db[0] |
| 97 | #define i_gen i_ic.ic_gen |
| 98 | #define i_lastr i_un.if_lastr |
| 99 | #define i_socket i_un.is_socket |
| 100 | #define i_forw i_chain[0] |
| 101 | #define i_back i_chain[1] |
| 102 | #define i_freef i_un.i_fr.if_freef |
| 103 | #define i_freeb i_un.i_fr.if_freeb |
| 104 | |
| 105 | #define di_ic di_un.di_icom |
| 106 | #define di_mode di_ic.ic_mode |
| 107 | #define di_nlink di_ic.ic_nlink |
| 108 | #define di_uid di_ic.ic_uid |
| 109 | #define di_gid di_ic.ic_gid |
| 110 | #if defined(vax) || defined(tahoe) |
| 111 | #define di_size di_ic.ic_size.val[0] |
| 112 | #endif |
| 113 | #define di_db di_ic.ic_db |
| 114 | #define di_ib di_ic.ic_ib |
| 115 | #define di_atime di_ic.ic_atime |
| 116 | #define di_mtime di_ic.ic_mtime |
| 117 | #define di_ctime di_ic.ic_ctime |
| 118 | #define di_rdev di_ic.ic_db[0] |
| 119 | #define di_blocks di_ic.ic_blocks |
| 120 | #define di_gen di_ic.ic_gen |
| 121 | |
| 122 | #ifdef KERNEL |
| 123 | struct inode *inode; /* the inode table itself */ |
| 124 | struct inode *inodeNINODE; /* the end of the inode table */ |
| 125 | int ninode; /* number of slots in the table */ |
| 126 | |
| 127 | extern struct vnodeops ufs_vnodeops; /* vnode operations for ufs */ |
| 128 | extern struct vnodeops blk_vnodeops; /* vnode operations for blk devices */ |
| 129 | |
| 130 | extern ino_t dirpref(); |
| 131 | #endif |
| 132 | |
| 133 | /* flags */ |
| 134 | #define ILOCKED 0x1 /* inode is locked */ |
| 135 | #define IUPD 0x2 /* file has been modified */ |
| 136 | #define IACC 0x4 /* inode access time to be updated */ |
| 137 | #define IWANT 0x8 /* some process waiting on lock */ |
| 138 | #define ICHG 0x10 /* inode has been changed */ |
| 139 | #define ISHLOCK 0x20 /* file has shared lock */ |
| 140 | #define IEXLOCK 0x40 /* file has exclusive lock */ |
| 141 | #define ILWAIT 0x80 /* someone waiting on file lock */ |
| 142 | #define IMOD 0x100 /* inode has been modified */ |
| 143 | #define IRENAME 0x200 /* inode is being renamed */ |
| 144 | |
| 145 | /* modes */ |
| 146 | #define IFMT 0170000 /* type of file */ |
| 147 | #define IFCHR 0020000 /* character special */ |
| 148 | #define IFDIR 0040000 /* directory */ |
| 149 | #define IFBLK 0060000 /* block special */ |
| 150 | #define IFREG 0100000 /* regular */ |
| 151 | #define IFLNK 0120000 /* symbolic link */ |
| 152 | #define IFSOCK 0140000 /* socket */ |
| 153 | |
| 154 | #define ISUID 04000 /* set user id on execution */ |
| 155 | #define ISGID 02000 /* set group id on execution */ |
| 156 | #define ISVTX 01000 /* save swapped text even after use */ |
| 157 | #define IREAD 0400 /* read, write, execute permissions */ |
| 158 | #define IWRITE 0200 |
| 159 | #define IEXEC 0100 |
| 160 | |
| 161 | #ifdef KERNEL |
| 162 | /* |
| 163 | * Convert between inode pointers and vnode pointers |
| 164 | */ |
| 165 | #define VTOI(vp) ((struct inode *)(vp)->v_data) |
| 166 | #define ITOV(ip) ((struct vnode *)&(ip)->i_vnode) |
| 167 | |
| 168 | /* |
| 169 | * Convert between vnode types and inode formats |
| 170 | */ |
| 171 | extern enum vtype iftovt_tab[]; |
| 172 | extern int vttoif_tab[]; |
| 173 | #define IFTOVT(mode) (iftovt_tab[((mode) & IFMT) >> 13]) |
| 174 | #define VTTOIF(indx) (vttoif_tab[(int)(indx)]) |
| 175 | |
| 176 | #define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode)) |
| 177 | |
| 178 | /* |
| 179 | * Lock and unlock inodes. |
| 180 | */ |
| 181 | #define ILOCK(ip) { \ |
| 182 | while ((ip)->i_flag & ILOCKED) { \ |
| 183 | (ip)->i_flag |= IWANT; \ |
| 184 | (void) sleep((caddr_t)(ip), PINOD); \ |
| 185 | } \ |
| 186 | (ip)->i_flag |= ILOCKED; \ |
| 187 | } |
| 188 | |
| 189 | #define IUNLOCK(ip) { \ |
| 190 | (ip)->i_flag &= ~ILOCKED; \ |
| 191 | if ((ip)->i_flag&IWANT) { \ |
| 192 | (ip)->i_flag &= ~IWANT; \ |
| 193 | wakeup((caddr_t)(ip)); \ |
| 194 | } \ |
| 195 | } |
| 196 | |
| 197 | #define IUPDAT(ip, t1, t2, waitfor) { \ |
| 198 | if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \ |
| 199 | (void) iupdat(ip, t1, t2, waitfor); \ |
| 200 | } |
| 201 | |
| 202 | #define ITIMES(ip, t1, t2) { \ |
| 203 | if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \ |
| 204 | (ip)->i_flag |= IMOD; \ |
| 205 | if ((ip)->i_flag&IACC) \ |
| 206 | (ip)->i_atime = (t1)->tv_sec; \ |
| 207 | if ((ip)->i_flag&IUPD) \ |
| 208 | (ip)->i_mtime = (t2)->tv_sec; \ |
| 209 | if ((ip)->i_flag&ICHG) \ |
| 210 | (ip)->i_ctime = time.tv_sec; \ |
| 211 | (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ |
| 212 | } \ |
| 213 | } |
| 214 | |
| 215 | /* |
| 216 | * This overlays the fid sturcture (see mount.h) |
| 217 | */ |
| 218 | struct ufid { |
| 219 | u_short ufid_len; |
| 220 | ino_t ufid_ino; |
| 221 | long ufid_gen; |
| 222 | }; |
| 223 | #endif |