123419Smckusick /* 237714Smckusick * Copyright (c) 1982, 1989 The Regents of the University of California. 337714Smckusick * All rights reserved. 423419Smckusick * 541535Smckusick * %sccs.include.redist.c% 637714Smckusick * 7*54302Smckusick * @(#)inode.h 7.28 (Berkeley) 06/23/92 823419Smckusick */ 958Sbill 1051505Sbostic #include <ufs/ufs/dinode.h> 1139387Smckusick 1258Sbill /* 1353061Smckusick * Theoretically, directories can be more than 2Gb in length, 1453061Smckusick * however, in practice this seems unlikely. So, we define 1553061Smckusick * the type doff_t as a long to keep down the cost of doing 1653061Smckusick * lookup on a 32-bit machine. If you are porting to a 64-bit 1753061Smckusick * architecture, you should make doff_t the same as off_t. 1853061Smckusick */ 1953061Smckusick #define doff_t long 2053061Smckusick 2153061Smckusick /* 2249448Smckusick * The inode is used to describe each active (or recently active) 2349448Smckusick * file in the UFS filesystem. It is composed of two types of 2449448Smckusick * information. The first part is the information that is needed 2549448Smckusick * only while the file is active (such as the identity of the file 2649448Smckusick * and linkage to speed its lookup). The second part is the 2749448Smckusick * permannent meta-data associated with the file which is read 2849448Smckusick * in from the permanent dinode from long term storage when the 2949448Smckusick * file becomes active, and is put back when the file is no longer 3049448Smckusick * being used. 3158Sbill */ 324814Swnj struct inode { 3339387Smckusick struct inode *i_chain[2]; /* hash chain, MUST be first */ 3439387Smckusick struct vnode *i_vnode; /* vnode associated with this inode */ 3537714Smckusick struct vnode *i_devvp; /* vnode for block I/O */ 3639812Smckusick u_long i_flag; /* see below */ 3758Sbill dev_t i_dev; /* device where inode resides */ 3849448Smckusick ino_t i_number; /* the identity of the inode */ 3951505Sbostic union { /* associated filesystem */ 4051505Sbostic struct fs *fs; /* FFS */ 4151505Sbostic struct lfs *lfs; /* LFS */ 4251505Sbostic } inode_u; 4351505Sbostic #define i_fs inode_u.fs 4451505Sbostic #define i_lfs inode_u.lfs 4545418Smckusick struct dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */ 4653764Smckusick u_quad_t i_modrev; /* revision level for lease */ 4749448Smckusick struct lockf *i_lockf; /* head of byte-level lock list */ 4851974Smckusick pid_t i_lockholder; /* DEBUG: holder of inode lock */ 4951974Smckusick pid_t i_lockwaiter; /* DEBUG: latest blocked for inode lock */ 5052334Smckusick /* 5152334Smckusick * Side effects; used during directory lookup. 5252334Smckusick */ 5353061Smckusick doff_t i_endoff; /* end of useful stuff in directory */ 5453061Smckusick doff_t i_diroff; /* offset in dir, where we found last entry */ 5553061Smckusick doff_t i_offset; /* offset of free space in directory */ 5652334Smckusick long i_count; /* size of free slot in directory */ 5752334Smckusick ino_t i_ino; /* inode number of found directory */ 5852334Smckusick u_long i_reclen; /* size of found directory entry */ 5952334Smckusick /* 6052334Smckusick * the on-disk dinode itself. 6152334Smckusick */ 6249448Smckusick struct dinode i_din; /* the on-disk dinode */ 6352334Smckusick long i_spare[12]; /* spares to round up to 256 bytes */ 6458Sbill }; 6558Sbill 6639387Smckusick #define i_mode i_din.di_mode 6739387Smckusick #define i_nlink i_din.di_nlink 6839387Smckusick #define i_uid i_din.di_uid 6939387Smckusick #define i_gid i_din.di_gid 7054126Smckusick #define i_size i_din.di_size 7139387Smckusick #define i_db i_din.di_db 7239387Smckusick #define i_ib i_din.di_ib 7339387Smckusick #define i_atime i_din.di_atime 7439387Smckusick #define i_mtime i_din.di_mtime 7539387Smckusick #define i_ctime i_din.di_ctime 7639387Smckusick #define i_blocks i_din.di_blocks 77*54302Smckusick #define i_rdev i_din.di_rdev 78*54302Smckusick #define i_shortlink i_din.di_shortlink 7939387Smckusick #define i_flags i_din.di_flags 8039387Smckusick #define i_gen i_din.di_gen 817333Skre #define i_forw i_chain[0] 827333Skre #define i_back i_chain[1] 836565Smckusic 8458Sbill /* flags */ 8539854Smckusick #define ILOCKED 0x0001 /* inode is locked */ 8639854Smckusick #define IWANT 0x0002 /* some process waiting on lock */ 8739854Smckusick #define IRENAME 0x0004 /* inode is being renamed */ 8839854Smckusick #define IUPD 0x0010 /* file has been modified */ 8939854Smckusick #define IACC 0x0020 /* inode access time to be updated */ 9039854Smckusick #define ICHG 0x0040 /* inode has been changed */ 9139854Smckusick #define IMOD 0x0080 /* inode has been modified */ 9239854Smckusick #define ISHLOCK 0x0100 /* file has shared lock */ 9339854Smckusick #define IEXLOCK 0x0200 /* file has exclusive lock */ 9439854Smckusick #define ILWAIT 0x0400 /* someone waiting on file lock */ 9558Sbill 9637714Smckusick #ifdef KERNEL 9751505Sbostic /* Convert between inode pointers and vnode pointers. */ 9837714Smckusick #define VTOI(vp) ((struct inode *)(vp)->v_data) 9939387Smckusick #define ITOV(ip) ((ip)->i_vnode) 10037714Smckusick 10151505Sbostic /* Lock and unlock inodes. */ 10239796Smckusick #ifdef notdef 1038467Sroot #define ILOCK(ip) { \ 1048467Sroot while ((ip)->i_flag & ILOCKED) { \ 1058467Sroot (ip)->i_flag |= IWANT; \ 10637714Smckusick (void) sleep((caddr_t)(ip), PINOD); \ 1078467Sroot } \ 1088467Sroot (ip)->i_flag |= ILOCKED; \ 1098467Sroot } 1108467Sroot 1118467Sroot #define IUNLOCK(ip) { \ 1128467Sroot (ip)->i_flag &= ~ILOCKED; \ 1138467Sroot if ((ip)->i_flag&IWANT) { \ 1148467Sroot (ip)->i_flag &= ~IWANT; \ 1158467Sroot wakeup((caddr_t)(ip)); \ 1168467Sroot } \ 1178467Sroot } 11839796Smckusick #else 11951505Sbostic #define ILOCK(ip) ufs_ilock(ip) 12051505Sbostic #define IUNLOCK(ip) ufs_iunlock(ip) 12139796Smckusick #endif 1228467Sroot 12316057Skarels #define ITIMES(ip, t1, t2) { \ 12416057Skarels if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \ 12516057Skarels (ip)->i_flag |= IMOD; \ 12616057Skarels if ((ip)->i_flag&IACC) \ 12754102Smckusick (ip)->i_atime.ts_sec = (t1)->tv_sec; \ 12852021Smckusick if ((ip)->i_flag&IUPD) { \ 12954102Smckusick (ip)->i_mtime.ts_sec = (t2)->tv_sec; \ 13054126Smckusick (ip)->i_modrev++; \ 13152021Smckusick } \ 13216057Skarels if ((ip)->i_flag&ICHG) \ 13354102Smckusick (ip)->i_ctime.ts_sec = time.tv_sec; \ 13416057Skarels (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ 13516057Skarels } \ 13616057Skarels } 13737714Smckusick 13851505Sbostic /* This overlays the fid structure (see mount.h). */ 13937714Smckusick struct ufid { 14039387Smckusick u_short ufid_len; /* length of structure */ 14139387Smckusick u_short ufid_pad; /* force long alignment */ 14239387Smckusick ino_t ufid_ino; /* file number (ino) */ 14339387Smckusick long ufid_gen; /* generation number */ 14437714Smckusick }; 14548031Smckusick #endif /* KERNEL */ 146