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*39812Smckusick * @(#)inode.h 7.9 (Berkeley) 12/30/89 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 */ 38*39812Smckusick 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 */ 427452Skre struct dquot *i_dquot; /* quota structure controlling this file */ 4339387Smckusick long i_diroff; /* offset in dir, where we found last entry */ 4437714Smckusick off_t i_endoff; /* end of useful stuff in directory */ 45*39812Smckusick long i_spare0; 46*39812Smckusick long i_spare1; 47*39812Smckusick long i_spare2; 4839387Smckusick struct dinode i_din; /* the on-disk inode */ 4958Sbill }; 5058Sbill 5139387Smckusick #define i_mode i_din.di_mode 5239387Smckusick #define i_nlink i_din.di_nlink 5339387Smckusick #define i_uid i_din.di_uid 5439387Smckusick #define i_gid i_din.di_gid 559790Ssam /* ugh! -- must be fixed */ 5629855Skarels #if defined(vax) || defined(tahoe) 5739387Smckusick #define i_size i_din.di_qsize.val[0] 589790Ssam #endif 5939387Smckusick #define i_db i_din.di_db 6039387Smckusick #define i_ib i_din.di_ib 6139387Smckusick #define i_atime i_din.di_atime 6239387Smckusick #define i_mtime i_din.di_mtime 6339387Smckusick #define i_ctime i_din.di_ctime 6439387Smckusick #define i_blocks i_din.di_blocks 6539387Smckusick #define i_rdev i_din.di_db[0] 6639387Smckusick #define i_flags i_din.di_flags 6739387Smckusick #define i_gen i_din.di_gen 687333Skre #define i_forw i_chain[0] 697333Skre #define i_back i_chain[1] 706565Smckusic 7158Sbill /* flags */ 728467Sroot #define ILOCKED 0x1 /* inode is locked */ 737703Ssam #define IUPD 0x2 /* file has been modified */ 747703Ssam #define IACC 0x4 /* inode access time to be updated */ 7537714Smckusick #define IWANT 0x8 /* some process waiting on lock */ 7637714Smckusick #define ICHG 0x10 /* inode has been changed */ 7737714Smckusick #define ISHLOCK 0x20 /* file has shared lock */ 7837714Smckusick #define IEXLOCK 0x40 /* file has exclusive lock */ 7937714Smckusick #define ILWAIT 0x80 /* someone waiting on file lock */ 8037714Smckusick #define IMOD 0x100 /* inode has been modified */ 8137714Smckusick #define IRENAME 0x200 /* inode is being renamed */ 8258Sbill 8337714Smckusick #ifdef KERNEL 8437714Smckusick /* 8537714Smckusick * Convert between inode pointers and vnode pointers 8637714Smckusick */ 8737714Smckusick #define VTOI(vp) ((struct inode *)(vp)->v_data) 8839387Smckusick #define ITOV(ip) ((ip)->i_vnode) 8937714Smckusick 9037714Smckusick /* 9137714Smckusick * Convert between vnode types and inode formats 9237714Smckusick */ 9337714Smckusick extern enum vtype iftovt_tab[]; 9437714Smckusick extern int vttoif_tab[]; 9537714Smckusick #define IFTOVT(mode) (iftovt_tab[((mode) & IFMT) >> 13]) 9637714Smckusick #define VTTOIF(indx) (vttoif_tab[(int)(indx)]) 9737714Smckusick 9837714Smckusick #define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode)) 9937714Smckusick 10039436Smckusick u_long nextgennumber; /* next generation number to assign */ 10139436Smckusick 10239436Smckusick extern ino_t dirpref(); 10339436Smckusick 10437714Smckusick /* 10537714Smckusick * Lock and unlock inodes. 10637714Smckusick */ 10739796Smckusick #ifdef notdef 1088467Sroot #define ILOCK(ip) { \ 1098467Sroot while ((ip)->i_flag & ILOCKED) { \ 1108467Sroot (ip)->i_flag |= IWANT; \ 11137714Smckusick (void) sleep((caddr_t)(ip), PINOD); \ 1128467Sroot } \ 1138467Sroot (ip)->i_flag |= ILOCKED; \ 1148467Sroot } 1158467Sroot 1168467Sroot #define IUNLOCK(ip) { \ 1178467Sroot (ip)->i_flag &= ~ILOCKED; \ 1188467Sroot if ((ip)->i_flag&IWANT) { \ 1198467Sroot (ip)->i_flag &= ~IWANT; \ 1208467Sroot wakeup((caddr_t)(ip)); \ 1218467Sroot } \ 1228467Sroot } 12339796Smckusick #else 12439796Smckusick #define ILOCK(ip) ilock(ip) 12539796Smckusick #define IUNLOCK(ip) iunlock(ip) 12639796Smckusick #endif 1278467Sroot 1288467Sroot #define IUPDAT(ip, t1, t2, waitfor) { \ 12916057Skarels if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \ 13037714Smckusick (void) iupdat(ip, t1, t2, waitfor); \ 1318467Sroot } 13216057Skarels 13316057Skarels #define ITIMES(ip, t1, t2) { \ 13416057Skarels if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \ 13516057Skarels (ip)->i_flag |= IMOD; \ 13616057Skarels if ((ip)->i_flag&IACC) \ 13716057Skarels (ip)->i_atime = (t1)->tv_sec; \ 13816057Skarels if ((ip)->i_flag&IUPD) \ 13916057Skarels (ip)->i_mtime = (t2)->tv_sec; \ 14016057Skarels if ((ip)->i_flag&ICHG) \ 14116057Skarels (ip)->i_ctime = time.tv_sec; \ 14216057Skarels (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ 14316057Skarels } \ 14416057Skarels } 14537714Smckusick 14637714Smckusick /* 14737714Smckusick * This overlays the fid sturcture (see mount.h) 14837714Smckusick */ 14937714Smckusick struct ufid { 15039387Smckusick u_short ufid_len; /* length of structure */ 15139387Smckusick u_short ufid_pad; /* force long alignment */ 15239387Smckusick ino_t ufid_ino; /* file number (ino) */ 15339387Smckusick long ufid_gen; /* generation number */ 15437714Smckusick }; 15537714Smckusick #endif 156