123419Smckusick /* 237714Smckusick * Copyright (c) 1982, 1989 The Regents of the University of California. 337714Smckusick * All rights reserved. 423419Smckusick * 5*41535Smckusick * %sccs.include.redist.c% 637714Smckusick * 7*41535Smckusick * @(#)inode.h 7.13 (Berkeley) 05/10/90 823419Smckusick */ 958Sbill 1039387Smckusick #ifdef KERNEL 1139387Smckusick #include "../ufs/dinode.h" 1239387Smckusick #else 1339387Smckusick #include <ufs/dinode.h> 1439387Smckusick #endif 1539387Smckusick 1658Sbill /* 174814Swnj * The I node is the focus of all file activity in UNIX. 184814Swnj * There is a unique inode allocated for each active file, 194814Swnj * each current directory, each mounted-on file, text file, and the root. 204814Swnj * An inode is 'named' by its dev/inumber pair. (iget/iget.c) 2139387Smckusick * Data in `struct dinode' is read in from permanent inode on volume. 2258Sbill */ 2358Sbill 244814Swnj struct inode { 2539387Smckusick struct inode *i_chain[2]; /* hash chain, MUST be first */ 2639387Smckusick struct vnode *i_vnode; /* vnode associated with this inode */ 2737714Smckusick struct vnode *i_devvp; /* vnode for block I/O */ 2839812Smckusick u_long i_flag; /* see below */ 2958Sbill dev_t i_dev; /* device where inode resides */ 3058Sbill ino_t i_number; /* i number, 1-to-1 with device address */ 316565Smckusic struct fs *i_fs; /* file sys associated with this inode */ 3241305Smckusick struct dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot strauctures */ 3339387Smckusick long i_diroff; /* offset in dir, where we found last entry */ 3437714Smckusick off_t i_endoff; /* end of useful stuff in directory */ 3539812Smckusick long i_spare0; 3639812Smckusick long i_spare1; 3739387Smckusick struct dinode i_din; /* the on-disk inode */ 3858Sbill }; 3958Sbill 4039387Smckusick #define i_mode i_din.di_mode 4139387Smckusick #define i_nlink i_din.di_nlink 4239387Smckusick #define i_uid i_din.di_uid 4339387Smckusick #define i_gid i_din.di_gid 44*41535Smckusick #if BYTE_ORDER == LITTLE_ENDIAN || defined(tahoe) /* ugh! -- must be fixed */ 4539387Smckusick #define i_size i_din.di_qsize.val[0] 46*41535Smckusick #else /* BYTE_ORDER == BIG_ENDIAN */ 47*41535Smckusick #define i_size i_din.di_qsize.val[1] 489790Ssam #endif 4939387Smckusick #define i_db i_din.di_db 5039387Smckusick #define i_ib i_din.di_ib 5139387Smckusick #define i_atime i_din.di_atime 5239387Smckusick #define i_mtime i_din.di_mtime 5339387Smckusick #define i_ctime i_din.di_ctime 5439387Smckusick #define i_blocks i_din.di_blocks 5539387Smckusick #define i_rdev i_din.di_db[0] 5639387Smckusick #define i_flags i_din.di_flags 5739387Smckusick #define i_gen i_din.di_gen 587333Skre #define i_forw i_chain[0] 597333Skre #define i_back i_chain[1] 606565Smckusic 6158Sbill /* flags */ 6239854Smckusick #define ILOCKED 0x0001 /* inode is locked */ 6339854Smckusick #define IWANT 0x0002 /* some process waiting on lock */ 6439854Smckusick #define IRENAME 0x0004 /* inode is being renamed */ 6539854Smckusick #define IUPD 0x0010 /* file has been modified */ 6639854Smckusick #define IACC 0x0020 /* inode access time to be updated */ 6739854Smckusick #define ICHG 0x0040 /* inode has been changed */ 6839854Smckusick #define IMOD 0x0080 /* inode has been modified */ 6939854Smckusick #define ISHLOCK 0x0100 /* file has shared lock */ 7039854Smckusick #define IEXLOCK 0x0200 /* file has exclusive lock */ 7139854Smckusick #define ILWAIT 0x0400 /* someone waiting on file lock */ 7258Sbill 7337714Smckusick #ifdef KERNEL 7437714Smckusick /* 7537714Smckusick * Convert between inode pointers and vnode pointers 7637714Smckusick */ 7737714Smckusick #define VTOI(vp) ((struct inode *)(vp)->v_data) 7839387Smckusick #define ITOV(ip) ((ip)->i_vnode) 7937714Smckusick 8037714Smckusick /* 8137714Smckusick * Convert between vnode types and inode formats 8237714Smckusick */ 8337714Smckusick extern enum vtype iftovt_tab[]; 8437714Smckusick extern int vttoif_tab[]; 8540287Smckusick #define IFTOVT(mode) (iftovt_tab[((mode) & IFMT) >> 12]) 8637714Smckusick #define VTTOIF(indx) (vttoif_tab[(int)(indx)]) 8737714Smckusick 8837714Smckusick #define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode)) 8937714Smckusick 9039436Smckusick u_long nextgennumber; /* next generation number to assign */ 9139436Smckusick 9239436Smckusick extern ino_t dirpref(); 9339436Smckusick 9437714Smckusick /* 9537714Smckusick * Lock and unlock inodes. 9637714Smckusick */ 9739796Smckusick #ifdef notdef 988467Sroot #define ILOCK(ip) { \ 998467Sroot while ((ip)->i_flag & ILOCKED) { \ 1008467Sroot (ip)->i_flag |= IWANT; \ 10137714Smckusick (void) sleep((caddr_t)(ip), PINOD); \ 1028467Sroot } \ 1038467Sroot (ip)->i_flag |= ILOCKED; \ 1048467Sroot } 1058467Sroot 1068467Sroot #define IUNLOCK(ip) { \ 1078467Sroot (ip)->i_flag &= ~ILOCKED; \ 1088467Sroot if ((ip)->i_flag&IWANT) { \ 1098467Sroot (ip)->i_flag &= ~IWANT; \ 1108467Sroot wakeup((caddr_t)(ip)); \ 1118467Sroot } \ 1128467Sroot } 11339796Smckusick #else 11439796Smckusick #define ILOCK(ip) ilock(ip) 11539796Smckusick #define IUNLOCK(ip) iunlock(ip) 11639796Smckusick #endif 1178467Sroot 1188467Sroot #define IUPDAT(ip, t1, t2, waitfor) { \ 11916057Skarels if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \ 12037714Smckusick (void) iupdat(ip, t1, t2, waitfor); \ 1218467Sroot } 12216057Skarels 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) \ 12716057Skarels (ip)->i_atime = (t1)->tv_sec; \ 12816057Skarels if ((ip)->i_flag&IUPD) \ 12916057Skarels (ip)->i_mtime = (t2)->tv_sec; \ 13016057Skarels if ((ip)->i_flag&ICHG) \ 13116057Skarels (ip)->i_ctime = time.tv_sec; \ 13216057Skarels (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ 13316057Skarels } \ 13416057Skarels } 13537714Smckusick 13637714Smckusick /* 13737714Smckusick * This overlays the fid sturcture (see mount.h) 13837714Smckusick */ 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 }; 14537714Smckusick #endif 146