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*56449Smargo * @(#)inode.h 7.30 (Berkeley) 10/07/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 { 3355410Smckusick struct inode *i_next; /* hash chain forward */ 3455410Smckusick struct inode **i_prev; /* hash chain back */ 3539387Smckusick struct vnode *i_vnode; /* vnode associated with this inode */ 3637714Smckusick struct vnode *i_devvp; /* vnode for block I/O */ 3739812Smckusick u_long i_flag; /* see below */ 3858Sbill dev_t i_dev; /* device where inode resides */ 3949448Smckusick ino_t i_number; /* the identity of the inode */ 4051505Sbostic union { /* associated filesystem */ 4151505Sbostic struct fs *fs; /* FFS */ 4251505Sbostic struct lfs *lfs; /* LFS */ 4351505Sbostic } inode_u; 4451505Sbostic #define i_fs inode_u.fs 4551505Sbostic #define i_lfs inode_u.lfs 4645418Smckusick struct dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */ 4753764Smckusick u_quad_t i_modrev; /* revision level for lease */ 4849448Smckusick struct lockf *i_lockf; /* head of byte-level lock list */ 4951974Smckusick pid_t i_lockholder; /* DEBUG: holder of inode lock */ 5051974Smckusick pid_t i_lockwaiter; /* DEBUG: latest blocked for inode lock */ 5152334Smckusick /* 5252334Smckusick * Side effects; used during directory lookup. 5352334Smckusick */ 5453061Smckusick doff_t i_endoff; /* end of useful stuff in directory */ 5553061Smckusick doff_t i_diroff; /* offset in dir, where we found last entry */ 5653061Smckusick doff_t i_offset; /* offset of free space in directory */ 5752334Smckusick long i_count; /* size of free slot in directory */ 5852334Smckusick ino_t i_ino; /* inode number of found directory */ 5952334Smckusick u_long i_reclen; /* size of found directory entry */ 6052334Smckusick /* 6152334Smckusick * the on-disk dinode itself. 6252334Smckusick */ 6349448Smckusick struct dinode i_din; /* the on-disk dinode */ 6452334Smckusick long i_spare[12]; /* spares to round up to 256 bytes */ 6558Sbill }; 6658Sbill 6739387Smckusick #define i_mode i_din.di_mode 6839387Smckusick #define i_nlink i_din.di_nlink 6939387Smckusick #define i_uid i_din.di_uid 7039387Smckusick #define i_gid i_din.di_gid 7154126Smckusick #define i_size i_din.di_size 7239387Smckusick #define i_db i_din.di_db 7339387Smckusick #define i_ib i_din.di_ib 7439387Smckusick #define i_atime i_din.di_atime 7539387Smckusick #define i_mtime i_din.di_mtime 7639387Smckusick #define i_ctime i_din.di_ctime 7739387Smckusick #define i_blocks i_din.di_blocks 7854302Smckusick #define i_rdev i_din.di_rdev 7954302Smckusick #define i_shortlink i_din.di_shortlink 8039387Smckusick #define i_flags i_din.di_flags 8139387Smckusick #define i_gen i_din.di_gen 826565Smckusic 8358Sbill /* flags */ 8439854Smckusick #define ILOCKED 0x0001 /* inode is locked */ 8539854Smckusick #define IWANT 0x0002 /* some process waiting on lock */ 8639854Smckusick #define IRENAME 0x0004 /* inode is being renamed */ 8739854Smckusick #define IUPD 0x0010 /* file has been modified */ 8839854Smckusick #define IACC 0x0020 /* inode access time to be updated */ 8939854Smckusick #define ICHG 0x0040 /* inode has been changed */ 9039854Smckusick #define IMOD 0x0080 /* inode has been modified */ 9139854Smckusick #define ISHLOCK 0x0100 /* file has shared lock */ 9239854Smckusick #define IEXLOCK 0x0200 /* file has exclusive lock */ 9339854Smckusick #define ILWAIT 0x0400 /* someone waiting on file lock */ 9458Sbill 9537714Smckusick #ifdef KERNEL 96*56449Smargo /* 97*56449Smargo * Structure used to pass around logical block paths generated by 98*56449Smargo * ufs_getlbns and used by truncate and bmap code. 99*56449Smargo */ 100*56449Smargo struct indir { 101*56449Smargo long in_lbn; /* logical block number */ 102*56449Smargo int in_off; /* offset in buffer */ 103*56449Smargo }; 104*56449Smargo 10551505Sbostic /* Convert between inode pointers and vnode pointers. */ 10637714Smckusick #define VTOI(vp) ((struct inode *)(vp)->v_data) 10739387Smckusick #define ITOV(ip) ((ip)->i_vnode) 10837714Smckusick 10951505Sbostic /* Lock and unlock inodes. */ 11039796Smckusick #ifdef notdef 1118467Sroot #define ILOCK(ip) { \ 1128467Sroot while ((ip)->i_flag & ILOCKED) { \ 1138467Sroot (ip)->i_flag |= IWANT; \ 11437714Smckusick (void) sleep((caddr_t)(ip), PINOD); \ 1158467Sroot } \ 1168467Sroot (ip)->i_flag |= ILOCKED; \ 1178467Sroot } 1188467Sroot 1198467Sroot #define IUNLOCK(ip) { \ 1208467Sroot (ip)->i_flag &= ~ILOCKED; \ 1218467Sroot if ((ip)->i_flag&IWANT) { \ 1228467Sroot (ip)->i_flag &= ~IWANT; \ 1238467Sroot wakeup((caddr_t)(ip)); \ 1248467Sroot } \ 1258467Sroot } 12639796Smckusick #else 12751505Sbostic #define ILOCK(ip) ufs_ilock(ip) 12851505Sbostic #define IUNLOCK(ip) ufs_iunlock(ip) 12939796Smckusick #endif 1308467Sroot 13116057Skarels #define ITIMES(ip, t1, t2) { \ 13216057Skarels if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \ 13316057Skarels (ip)->i_flag |= IMOD; \ 13416057Skarels if ((ip)->i_flag&IACC) \ 13554102Smckusick (ip)->i_atime.ts_sec = (t1)->tv_sec; \ 13652021Smckusick if ((ip)->i_flag&IUPD) { \ 13754102Smckusick (ip)->i_mtime.ts_sec = (t2)->tv_sec; \ 13854126Smckusick (ip)->i_modrev++; \ 13952021Smckusick } \ 14016057Skarels if ((ip)->i_flag&ICHG) \ 14154102Smckusick (ip)->i_ctime.ts_sec = time.tv_sec; \ 14216057Skarels (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ 14316057Skarels } \ 14416057Skarels } 14537714Smckusick 14651505Sbostic /* This overlays the fid structure (see mount.h). */ 14737714Smckusick struct ufid { 14839387Smckusick u_short ufid_len; /* length of structure */ 14939387Smckusick u_short ufid_pad; /* force long alignment */ 15039387Smckusick ino_t ufid_ino; /* file number (ino) */ 15139387Smckusick long ufid_gen; /* generation number */ 15237714Smckusick }; 15348031Smckusick #endif /* KERNEL */ 154