123419Smckusick /* 237714Smckusick * Copyright (c) 1982, 1989 The Regents of the University of California. 337714Smckusick * All rights reserved. 423419Smckusick * 537714Smckusick * Redistribution and use in source and binary forms are permitted 637714Smckusick * provided that the above copyright notice and this paragraph are 737714Smckusick * duplicated in all such forms and that any documentation, 837714Smckusick * advertising materials, and other materials related to such 937714Smckusick * distribution and use acknowledge that the software was developed 1037714Smckusick * by the University of California, Berkeley. The name of the 1137714Smckusick * University may not be used to endorse or promote products derived 1237714Smckusick * from this software without specific prior written permission. 1337714Smckusick * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1437714Smckusick * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1537714Smckusick * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1637714Smckusick * 17*41305Smckusick * @(#)inode.h 7.12 (Berkeley) 05/02/90 1823419Smckusick */ 1958Sbill 2039387Smckusick #ifdef KERNEL 2139387Smckusick #include "../ufs/dinode.h" 2239387Smckusick #else 2339387Smckusick #include <ufs/dinode.h> 2439387Smckusick #endif 2539387Smckusick 2658Sbill /* 274814Swnj * The I node is the focus of all file activity in UNIX. 284814Swnj * There is a unique inode allocated for each active file, 294814Swnj * each current directory, each mounted-on file, text file, and the root. 304814Swnj * An inode is 'named' by its dev/inumber pair. (iget/iget.c) 3139387Smckusick * Data in `struct dinode' is read in from permanent inode on volume. 3258Sbill */ 3358Sbill 344814Swnj struct inode { 3539387Smckusick struct inode *i_chain[2]; /* hash chain, MUST be first */ 3639387Smckusick struct vnode *i_vnode; /* vnode associated with this inode */ 3737714Smckusick struct vnode *i_devvp; /* vnode for block I/O */ 3839812Smckusick u_long i_flag; /* see below */ 3958Sbill dev_t i_dev; /* device where inode resides */ 4058Sbill ino_t i_number; /* i number, 1-to-1 with device address */ 416565Smckusic struct fs *i_fs; /* file sys associated with this inode */ 42*41305Smckusick struct dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot strauctures */ 4339387Smckusick long i_diroff; /* offset in dir, where we found last entry */ 4437714Smckusick off_t i_endoff; /* end of useful stuff in directory */ 4539812Smckusick long i_spare0; 4639812Smckusick long i_spare1; 4739387Smckusick struct dinode i_din; /* the on-disk inode */ 4858Sbill }; 4958Sbill 5039387Smckusick #define i_mode i_din.di_mode 5139387Smckusick #define i_nlink i_din.di_nlink 5239387Smckusick #define i_uid i_din.di_uid 5339387Smckusick #define i_gid i_din.di_gid 549790Ssam /* ugh! -- must be fixed */ 5529855Skarels #if defined(vax) || defined(tahoe) 5639387Smckusick #define i_size i_din.di_qsize.val[0] 579790Ssam #endif 5839387Smckusick #define i_db i_din.di_db 5939387Smckusick #define i_ib i_din.di_ib 6039387Smckusick #define i_atime i_din.di_atime 6139387Smckusick #define i_mtime i_din.di_mtime 6239387Smckusick #define i_ctime i_din.di_ctime 6339387Smckusick #define i_blocks i_din.di_blocks 6439387Smckusick #define i_rdev i_din.di_db[0] 6539387Smckusick #define i_flags i_din.di_flags 6639387Smckusick #define i_gen i_din.di_gen 677333Skre #define i_forw i_chain[0] 687333Skre #define i_back i_chain[1] 696565Smckusic 7058Sbill /* flags */ 7139854Smckusick #define ILOCKED 0x0001 /* inode is locked */ 7239854Smckusick #define IWANT 0x0002 /* some process waiting on lock */ 7339854Smckusick #define IRENAME 0x0004 /* inode is being renamed */ 7439854Smckusick #define IUPD 0x0010 /* file has been modified */ 7539854Smckusick #define IACC 0x0020 /* inode access time to be updated */ 7639854Smckusick #define ICHG 0x0040 /* inode has been changed */ 7739854Smckusick #define IMOD 0x0080 /* inode has been modified */ 7839854Smckusick #define ISHLOCK 0x0100 /* file has shared lock */ 7939854Smckusick #define IEXLOCK 0x0200 /* file has exclusive lock */ 8039854Smckusick #define ILWAIT 0x0400 /* someone waiting on file lock */ 8158Sbill 8237714Smckusick #ifdef KERNEL 8337714Smckusick /* 8437714Smckusick * Convert between inode pointers and vnode pointers 8537714Smckusick */ 8637714Smckusick #define VTOI(vp) ((struct inode *)(vp)->v_data) 8739387Smckusick #define ITOV(ip) ((ip)->i_vnode) 8837714Smckusick 8937714Smckusick /* 9037714Smckusick * Convert between vnode types and inode formats 9137714Smckusick */ 9237714Smckusick extern enum vtype iftovt_tab[]; 9337714Smckusick extern int vttoif_tab[]; 9440287Smckusick #define IFTOVT(mode) (iftovt_tab[((mode) & IFMT) >> 12]) 9537714Smckusick #define VTTOIF(indx) (vttoif_tab[(int)(indx)]) 9637714Smckusick 9737714Smckusick #define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode)) 9837714Smckusick 9939436Smckusick u_long nextgennumber; /* next generation number to assign */ 10039436Smckusick 10139436Smckusick extern ino_t dirpref(); 10239436Smckusick 10337714Smckusick /* 10437714Smckusick * Lock and unlock inodes. 10537714Smckusick */ 10639796Smckusick #ifdef notdef 1078467Sroot #define ILOCK(ip) { \ 1088467Sroot while ((ip)->i_flag & ILOCKED) { \ 1098467Sroot (ip)->i_flag |= IWANT; \ 11037714Smckusick (void) sleep((caddr_t)(ip), PINOD); \ 1118467Sroot } \ 1128467Sroot (ip)->i_flag |= ILOCKED; \ 1138467Sroot } 1148467Sroot 1158467Sroot #define IUNLOCK(ip) { \ 1168467Sroot (ip)->i_flag &= ~ILOCKED; \ 1178467Sroot if ((ip)->i_flag&IWANT) { \ 1188467Sroot (ip)->i_flag &= ~IWANT; \ 1198467Sroot wakeup((caddr_t)(ip)); \ 1208467Sroot } \ 1218467Sroot } 12239796Smckusick #else 12339796Smckusick #define ILOCK(ip) ilock(ip) 12439796Smckusick #define IUNLOCK(ip) iunlock(ip) 12539796Smckusick #endif 1268467Sroot 1278467Sroot #define IUPDAT(ip, t1, t2, waitfor) { \ 12816057Skarels if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \ 12937714Smckusick (void) iupdat(ip, t1, t2, waitfor); \ 1308467Sroot } 13116057Skarels 13216057Skarels #define ITIMES(ip, t1, t2) { \ 13316057Skarels if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \ 13416057Skarels (ip)->i_flag |= IMOD; \ 13516057Skarels if ((ip)->i_flag&IACC) \ 13616057Skarels (ip)->i_atime = (t1)->tv_sec; \ 13716057Skarels if ((ip)->i_flag&IUPD) \ 13816057Skarels (ip)->i_mtime = (t2)->tv_sec; \ 13916057Skarels if ((ip)->i_flag&ICHG) \ 14016057Skarels (ip)->i_ctime = time.tv_sec; \ 14116057Skarels (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ 14216057Skarels } \ 14316057Skarels } 14437714Smckusick 14537714Smckusick /* 14637714Smckusick * This overlays the fid sturcture (see mount.h) 14737714Smckusick */ 14837714Smckusick struct ufid { 14939387Smckusick u_short ufid_len; /* length of structure */ 15039387Smckusick u_short ufid_pad; /* force long alignment */ 15139387Smckusick ino_t ufid_ino; /* file number (ino) */ 15239387Smckusick long ufid_gen; /* generation number */ 15337714Smckusick }; 15437714Smckusick #endif 155