1 /* 2 * Copyright (c) 1982, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)inode.h 8.3 (Berkeley) 09/23/93 8 */ 9 10 #include <ufs/ufs/dinode.h> 11 12 /* 13 * Theoretically, directories can be more than 2Gb in length, however, in 14 * practice this seems unlikely. So, we define the type doff_t as a long 15 * to keep down the cost of doing lookup on a 32-bit machine. If you are 16 * porting to a 64-bit architecture, you should make doff_t the same as off_t. 17 */ 18 #define doff_t long 19 20 /* 21 * The inode is used to describe each active (or recently active) 22 * file in the UFS filesystem. It is composed of two types of 23 * information. The first part is the information that is needed 24 * only while the file is active (such as the identity of the file 25 * and linkage to speed its lookup). The second part is the 26 * permannent meta-data associated with the file which is read 27 * in from the permanent dinode from long term storage when the 28 * file becomes active, and is put back when the file is no longer 29 * being used. 30 */ 31 struct inode { 32 struct inode *i_next; /* Hash chain forward. */ 33 struct inode **i_prev; /* Hash chain back. */ 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; /* I* flags. */ 37 dev_t i_dev; /* Device associated with the inode. */ 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]; /* 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 long i_count; /* Size of free slot in directory. */ 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 ino_t i_ino; /* Inode number of found directory. */ 58 u_long i_reclen; /* Size of found directory entry. */ 59 long i_spare[11]; /* Spares to round up to 128 bytes. */ 60 /* 61 * The on-disk dinode itself. 62 */ 63 struct dinode i_din; /* 128 bytes of the on-disk dinode. */ 64 }; 65 66 #define i_atime i_din.di_atime 67 #define i_blocks i_din.di_blocks 68 #define i_ctime i_din.di_ctime 69 #define i_db i_din.di_db 70 #define i_flags i_din.di_flags 71 #define i_gen i_din.di_gen 72 #define i_gid i_din.di_gid 73 #define i_ib i_din.di_ib 74 #define i_mode i_din.di_mode 75 #define i_mtime i_din.di_mtime 76 #define i_nlink i_din.di_nlink 77 #define i_rdev i_din.di_rdev 78 #define i_shortlink i_din.di_shortlink 79 #define i_size i_din.di_size 80 #define i_uid i_din.di_uid 81 82 /* These flags are kept in i_flag. */ 83 #define IN_ACCESS 0x0001 /* Access time update request. */ 84 #define IN_CHANGE 0x0002 /* Inode change time update request. */ 85 #define IN_EXLOCK 0x0004 /* File has exclusive lock. */ 86 #define IN_LOCKED 0x0008 /* Inode lock. */ 87 #define IN_LWAIT 0x0010 /* Process waiting on file lock. */ 88 #define IN_MODIFIED 0x0020 /* Inode has been modified. */ 89 #define IN_RENAME 0x0040 /* Inode is being renamed. */ 90 #define IN_SHLOCK 0x0080 /* File has shared lock. */ 91 #define IN_UPDATE 0x0100 /* Modification time update request. */ 92 #define IN_WANTED 0x0200 /* Inode is wanted by a process. */ 93 94 #ifdef KERNEL 95 /* 96 * Structure used to pass around logical block paths generated by 97 * ufs_getlbns and used by truncate and bmap code. 98 */ 99 struct indir { 100 daddr_t in_lbn; /* Logical block number. */ 101 int in_off; /* Offset in buffer. */ 102 int in_exists; /* Flag if the block exists. */ 103 }; 104 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 #define ITIMES(ip, t1, t2) { \ 110 if ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) { \ 111 (ip)->i_flag |= IN_MODIFIED; \ 112 if ((ip)->i_flag & IN_ACCESS) \ 113 (ip)->i_atime.ts_sec = (t1)->tv_sec; \ 114 if ((ip)->i_flag & IN_UPDATE) { \ 115 (ip)->i_mtime.ts_sec = (t2)->tv_sec; \ 116 (ip)->i_modrev++; \ 117 } \ 118 if ((ip)->i_flag & IN_CHANGE) \ 119 (ip)->i_ctime.ts_sec = time.tv_sec; \ 120 (ip)->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE); \ 121 } \ 122 } 123 124 /* This overlays the fid structure (see mount.h). */ 125 struct ufid { 126 u_short ufid_len; /* Length of structure. */ 127 u_short ufid_pad; /* Force long alignment. */ 128 ino_t ufid_ino; /* File number (ino). */ 129 long ufid_gen; /* Generation number. */ 130 }; 131 #endif /* KERNEL */ 132