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*39796Smckusick * @(#)inode.h 7.8 (Berkeley) 12/29/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 */ 3839387Smckusick u_short 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 */ 4325456Skarels struct text *i_text; /* text entry, if any (should be region) */ 4439387Smckusick long i_diroff; /* offset in dir, where we found last entry */ 4537714Smckusick off_t i_endoff; /* end of useful stuff in directory */ 4639436Smckusick long i_spare[5]; 4758Sbill union { 486565Smckusic daddr_t if_lastr; /* last read (read-ahead) */ 496565Smckusic struct socket *is_socket; 5058Sbill } i_un; 5139387Smckusick struct dinode i_din; /* the on-disk inode */ 5258Sbill }; 5358Sbill 5439387Smckusick #define i_mode i_din.di_mode 5539387Smckusick #define i_nlink i_din.di_nlink 5639387Smckusick #define i_uid i_din.di_uid 5739387Smckusick #define i_gid i_din.di_gid 589790Ssam /* ugh! -- must be fixed */ 5929855Skarels #if defined(vax) || defined(tahoe) 6039387Smckusick #define i_size i_din.di_qsize.val[0] 619790Ssam #endif 6239387Smckusick #define i_db i_din.di_db 6339387Smckusick #define i_ib i_din.di_ib 6439387Smckusick #define i_atime i_din.di_atime 6539387Smckusick #define i_mtime i_din.di_mtime 6639387Smckusick #define i_ctime i_din.di_ctime 6739387Smckusick #define i_blocks i_din.di_blocks 6839387Smckusick #define i_rdev i_din.di_db[0] 6939387Smckusick #define i_flags i_din.di_flags 7039387Smckusick #define i_gen i_din.di_gen 716565Smckusic #define i_lastr i_un.if_lastr 729005Sroot #define i_socket i_un.is_socket 737333Skre #define i_forw i_chain[0] 747333Skre #define i_back i_chain[1] 756565Smckusic 7658Sbill /* flags */ 778467Sroot #define ILOCKED 0x1 /* inode is locked */ 787703Ssam #define IUPD 0x2 /* file has been modified */ 797703Ssam #define IACC 0x4 /* inode access time to be updated */ 8037714Smckusick #define IWANT 0x8 /* some process waiting on lock */ 8137714Smckusick #define ICHG 0x10 /* inode has been changed */ 8237714Smckusick #define ISHLOCK 0x20 /* file has shared lock */ 8337714Smckusick #define IEXLOCK 0x40 /* file has exclusive lock */ 8437714Smckusick #define ILWAIT 0x80 /* someone waiting on file lock */ 8537714Smckusick #define IMOD 0x100 /* inode has been modified */ 8637714Smckusick #define IRENAME 0x200 /* inode is being renamed */ 8758Sbill 8837714Smckusick #ifdef KERNEL 8937714Smckusick /* 9037714Smckusick * Convert between inode pointers and vnode pointers 9137714Smckusick */ 9237714Smckusick #define VTOI(vp) ((struct inode *)(vp)->v_data) 9339387Smckusick #define ITOV(ip) ((ip)->i_vnode) 9437714Smckusick 9537714Smckusick /* 9637714Smckusick * Convert between vnode types and inode formats 9737714Smckusick */ 9837714Smckusick extern enum vtype iftovt_tab[]; 9937714Smckusick extern int vttoif_tab[]; 10037714Smckusick #define IFTOVT(mode) (iftovt_tab[((mode) & IFMT) >> 13]) 10137714Smckusick #define VTTOIF(indx) (vttoif_tab[(int)(indx)]) 10237714Smckusick 10337714Smckusick #define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode)) 10437714Smckusick 10539436Smckusick u_long nextgennumber; /* next generation number to assign */ 10639436Smckusick 10739436Smckusick extern ino_t dirpref(); 10839436Smckusick 10937714Smckusick /* 11037714Smckusick * Lock and unlock inodes. 11137714Smckusick */ 112*39796Smckusick #ifdef notdef 1138467Sroot #define ILOCK(ip) { \ 1148467Sroot while ((ip)->i_flag & ILOCKED) { \ 1158467Sroot (ip)->i_flag |= IWANT; \ 11637714Smckusick (void) sleep((caddr_t)(ip), PINOD); \ 1178467Sroot } \ 1188467Sroot (ip)->i_flag |= ILOCKED; \ 1198467Sroot } 1208467Sroot 1218467Sroot #define IUNLOCK(ip) { \ 1228467Sroot (ip)->i_flag &= ~ILOCKED; \ 1238467Sroot if ((ip)->i_flag&IWANT) { \ 1248467Sroot (ip)->i_flag &= ~IWANT; \ 1258467Sroot wakeup((caddr_t)(ip)); \ 1268467Sroot } \ 1278467Sroot } 128*39796Smckusick #else 129*39796Smckusick #define ILOCK(ip) ilock(ip) 130*39796Smckusick #define IUNLOCK(ip) iunlock(ip) 131*39796Smckusick #endif 1328467Sroot 1338467Sroot #define IUPDAT(ip, t1, t2, waitfor) { \ 13416057Skarels if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \ 13537714Smckusick (void) iupdat(ip, t1, t2, waitfor); \ 1368467Sroot } 13716057Skarels 13816057Skarels #define ITIMES(ip, t1, t2) { \ 13916057Skarels if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \ 14016057Skarels (ip)->i_flag |= IMOD; \ 14116057Skarels if ((ip)->i_flag&IACC) \ 14216057Skarels (ip)->i_atime = (t1)->tv_sec; \ 14316057Skarels if ((ip)->i_flag&IUPD) \ 14416057Skarels (ip)->i_mtime = (t2)->tv_sec; \ 14516057Skarels if ((ip)->i_flag&ICHG) \ 14616057Skarels (ip)->i_ctime = time.tv_sec; \ 14716057Skarels (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ 14816057Skarels } \ 14916057Skarels } 15037714Smckusick 15137714Smckusick /* 15237714Smckusick * This overlays the fid sturcture (see mount.h) 15337714Smckusick */ 15437714Smckusick struct ufid { 15539387Smckusick u_short ufid_len; /* length of structure */ 15639387Smckusick u_short ufid_pad; /* force long alignment */ 15739387Smckusick ino_t ufid_ino; /* file number (ino) */ 15839387Smckusick long ufid_gen; /* generation number */ 15937714Smckusick }; 16037714Smckusick #endif 161