123419Smckusick /* 2*37714Smckusick * Copyright (c) 1982, 1989 The Regents of the University of California. 3*37714Smckusick * All rights reserved. 423419Smckusick * 5*37714Smckusick * Redistribution and use in source and binary forms are permitted 6*37714Smckusick * provided that the above copyright notice and this paragraph are 7*37714Smckusick * duplicated in all such forms and that any documentation, 8*37714Smckusick * advertising materials, and other materials related to such 9*37714Smckusick * distribution and use acknowledge that the software was developed 10*37714Smckusick * by the University of California, Berkeley. The name of the 11*37714Smckusick * University may not be used to endorse or promote products derived 12*37714Smckusick * from this software without specific prior written permission. 13*37714Smckusick * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*37714Smckusick * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*37714Smckusick * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16*37714Smckusick * 17*37714Smckusick * @(#)inode.h 7.3 (Berkeley) 05/09/89 1823419Smckusick */ 1958Sbill 2058Sbill /* 214814Swnj * The I node is the focus of all file activity in UNIX. 224814Swnj * There is a unique inode allocated for each active file, 234814Swnj * each current directory, each mounted-on file, text file, and the root. 244814Swnj * An inode is 'named' by its dev/inumber pair. (iget/iget.c) 256565Smckusic * Data in icommon is read in from permanent inode on volume. 2658Sbill */ 2758Sbill 289182Ssam #define NDADDR 12 /* direct addresses in inode */ 299182Ssam #define NIADDR 3 /* indirect addresses in inode */ 306565Smckusic 314814Swnj struct inode { 327333Skre struct inode *i_chain[2]; /* must be first */ 33*37714Smckusick struct vnode i_vnode; /* vnode associated with this inode */ 34*37714Smckusick struct vnode *i_devvp; /* vnode for block I/O */ 357703Ssam u_short i_flag; 3658Sbill dev_t i_dev; /* device where inode resides */ 3758Sbill ino_t i_number; /* i number, 1-to-1 with device address */ 3816646Ssam long i_id; /* unique identifier */ 39*37714Smckusick long i_diroff; /* offset in dir, where we found last entry */ 406565Smckusic struct fs *i_fs; /* file sys associated with this inode */ 417452Skre struct dquot *i_dquot; /* quota structure controlling this file */ 4225456Skarels struct text *i_text; /* text entry, if any (should be region) */ 43*37714Smckusick struct inode *i_devlst;/* list of block device inodes */ 44*37714Smckusick off_t i_endoff; /* end of useful stuff in directory */ 4558Sbill union { 466565Smckusic daddr_t if_lastr; /* last read (read-ahead) */ 476565Smckusic struct socket *is_socket; 487333Skre struct { 497333Skre struct inode *if_freef; /* free list forward */ 507333Skre struct inode **if_freeb; /* free list back */ 517333Skre } i_fr; 5258Sbill } i_un; 536565Smckusic struct icommon 546565Smckusic { 556565Smckusic u_short ic_mode; /* 0: mode and type of file */ 566565Smckusic short ic_nlink; /* 2: number of links to file */ 5725318Skarels uid_t ic_uid; /* 4: owner's user id */ 5825318Skarels gid_t ic_gid; /* 6: owner's group id */ 599182Ssam quad ic_size; /* 8: number of bytes in file */ 609182Ssam time_t ic_atime; /* 16: time last accessed */ 619182Ssam long ic_atspare; 629182Ssam time_t ic_mtime; /* 24: time last modified */ 639182Ssam long ic_mtspare; 6410854Ssam time_t ic_ctime; /* 32: last time inode changed */ 659182Ssam long ic_ctspare; 669182Ssam daddr_t ic_db[NDADDR]; /* 40: disk block addresses */ 679182Ssam daddr_t ic_ib[NIADDR]; /* 88: indirect blocks */ 689182Ssam long ic_flags; /* 100: status, currently unused */ 6912650Ssam long ic_blocks; /* 104: blocks actually held */ 70*37714Smckusick long ic_gen; /* 108: generation number */ 71*37714Smckusick long ic_spare[4]; /* 112: reserved, currently unused */ 726565Smckusic } i_ic; 7358Sbill }; 7458Sbill 756565Smckusic struct dinode { 766565Smckusic union { 776565Smckusic struct icommon di_icom; 789182Ssam char di_size[128]; 796565Smckusic } di_un; 806565Smckusic }; 816565Smckusic 826565Smckusic #define i_mode i_ic.ic_mode 836565Smckusic #define i_nlink i_ic.ic_nlink 846565Smckusic #define i_uid i_ic.ic_uid 856565Smckusic #define i_gid i_ic.ic_gid 869790Ssam /* ugh! -- must be fixed */ 8729855Skarels #if defined(vax) || defined(tahoe) 889182Ssam #define i_size i_ic.ic_size.val[0] 899790Ssam #endif 906565Smckusic #define i_db i_ic.ic_db 916565Smckusic #define i_ib i_ic.ic_ib 926565Smckusic #define i_atime i_ic.ic_atime 936565Smckusic #define i_mtime i_ic.ic_mtime 946565Smckusic #define i_ctime i_ic.ic_ctime 9512650Ssam #define i_blocks i_ic.ic_blocks 966565Smckusic #define i_rdev i_ic.ic_db[0] 97*37714Smckusick #define i_gen i_ic.ic_gen 986565Smckusic #define i_lastr i_un.if_lastr 999005Sroot #define i_socket i_un.is_socket 1007333Skre #define i_forw i_chain[0] 1017333Skre #define i_back i_chain[1] 1027333Skre #define i_freef i_un.i_fr.if_freef 1037333Skre #define i_freeb i_un.i_fr.if_freeb 1046565Smckusic 1056565Smckusic #define di_ic di_un.di_icom 1066565Smckusic #define di_mode di_ic.ic_mode 1076565Smckusic #define di_nlink di_ic.ic_nlink 1086565Smckusic #define di_uid di_ic.ic_uid 1096565Smckusic #define di_gid di_ic.ic_gid 11029855Skarels #if defined(vax) || defined(tahoe) 1119182Ssam #define di_size di_ic.ic_size.val[0] 1129790Ssam #endif 1136565Smckusic #define di_db di_ic.ic_db 1146565Smckusic #define di_ib di_ic.ic_ib 1156565Smckusic #define di_atime di_ic.ic_atime 1166565Smckusic #define di_mtime di_ic.ic_mtime 1176565Smckusic #define di_ctime di_ic.ic_ctime 1186565Smckusic #define di_rdev di_ic.ic_db[0] 11912650Ssam #define di_blocks di_ic.ic_blocks 120*37714Smckusick #define di_gen di_ic.ic_gen 1216565Smckusic 12258Sbill #ifdef KERNEL 1238691Sroot struct inode *inode; /* the inode table itself */ 1248691Sroot struct inode *inodeNINODE; /* the end of the inode table */ 1258691Sroot int ninode; /* number of slots in the table */ 12658Sbill 127*37714Smckusick extern struct vnodeops ufs_vnodeops; /* vnode operations for ufs */ 128*37714Smckusick extern struct vnodeops blk_vnodeops; /* vnode operations for blk devices */ 12958Sbill 130*37714Smckusick extern ino_t dirpref(); 1319182Ssam #endif 1329182Ssam 13358Sbill /* flags */ 1348467Sroot #define ILOCKED 0x1 /* inode is locked */ 1357703Ssam #define IUPD 0x2 /* file has been modified */ 1367703Ssam #define IACC 0x4 /* inode access time to be updated */ 137*37714Smckusick #define IWANT 0x8 /* some process waiting on lock */ 138*37714Smckusick #define ICHG 0x10 /* inode has been changed */ 139*37714Smckusick #define ISHLOCK 0x20 /* file has shared lock */ 140*37714Smckusick #define IEXLOCK 0x40 /* file has exclusive lock */ 141*37714Smckusick #define ILWAIT 0x80 /* someone waiting on file lock */ 142*37714Smckusick #define IMOD 0x100 /* inode has been modified */ 143*37714Smckusick #define IRENAME 0x200 /* inode is being renamed */ 14458Sbill 14558Sbill /* modes */ 1466565Smckusic #define IFMT 0170000 /* type of file */ 1476565Smckusic #define IFCHR 0020000 /* character special */ 1486565Smckusic #define IFDIR 0040000 /* directory */ 1496565Smckusic #define IFBLK 0060000 /* block special */ 1506565Smckusic #define IFREG 0100000 /* regular */ 1516565Smckusic #define IFLNK 0120000 /* symbolic link */ 1528990Sroot #define IFSOCK 0140000 /* socket */ 1538990Sroot 1546565Smckusic #define ISUID 04000 /* set user id on execution */ 1556565Smckusic #define ISGID 02000 /* set group id on execution */ 1566565Smckusic #define ISVTX 01000 /* save swapped text even after use */ 1576565Smckusic #define IREAD 0400 /* read, write, execute permissions */ 1586565Smckusic #define IWRITE 0200 1596565Smckusic #define IEXEC 0100 1608467Sroot 161*37714Smckusick #ifdef KERNEL 162*37714Smckusick /* 163*37714Smckusick * Convert between inode pointers and vnode pointers 164*37714Smckusick */ 165*37714Smckusick #define VTOI(vp) ((struct inode *)(vp)->v_data) 166*37714Smckusick #define ITOV(ip) ((struct vnode *)&(ip)->i_vnode) 167*37714Smckusick 168*37714Smckusick /* 169*37714Smckusick * Convert between vnode types and inode formats 170*37714Smckusick */ 171*37714Smckusick extern enum vtype iftovt_tab[]; 172*37714Smckusick extern int vttoif_tab[]; 173*37714Smckusick #define IFTOVT(mode) (iftovt_tab[((mode) & IFMT) >> 13]) 174*37714Smckusick #define VTTOIF(indx) (vttoif_tab[(int)(indx)]) 175*37714Smckusick 176*37714Smckusick #define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode)) 177*37714Smckusick 178*37714Smckusick /* 179*37714Smckusick * Lock and unlock inodes. 180*37714Smckusick */ 1818467Sroot #define ILOCK(ip) { \ 1828467Sroot while ((ip)->i_flag & ILOCKED) { \ 1838467Sroot (ip)->i_flag |= IWANT; \ 184*37714Smckusick (void) sleep((caddr_t)(ip), PINOD); \ 1858467Sroot } \ 1868467Sroot (ip)->i_flag |= ILOCKED; \ 1878467Sroot } 1888467Sroot 1898467Sroot #define IUNLOCK(ip) { \ 1908467Sroot (ip)->i_flag &= ~ILOCKED; \ 1918467Sroot if ((ip)->i_flag&IWANT) { \ 1928467Sroot (ip)->i_flag &= ~IWANT; \ 1938467Sroot wakeup((caddr_t)(ip)); \ 1948467Sroot } \ 1958467Sroot } 1968467Sroot 1978467Sroot #define IUPDAT(ip, t1, t2, waitfor) { \ 19816057Skarels if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \ 199*37714Smckusick (void) iupdat(ip, t1, t2, waitfor); \ 2008467Sroot } 20116057Skarels 20216057Skarels #define ITIMES(ip, t1, t2) { \ 20316057Skarels if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \ 20416057Skarels (ip)->i_flag |= IMOD; \ 20516057Skarels if ((ip)->i_flag&IACC) \ 20616057Skarels (ip)->i_atime = (t1)->tv_sec; \ 20716057Skarels if ((ip)->i_flag&IUPD) \ 20816057Skarels (ip)->i_mtime = (t2)->tv_sec; \ 20916057Skarels if ((ip)->i_flag&ICHG) \ 21016057Skarels (ip)->i_ctime = time.tv_sec; \ 21116057Skarels (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ 21216057Skarels } \ 21316057Skarels } 214*37714Smckusick 215*37714Smckusick /* 216*37714Smckusick * This overlays the fid sturcture (see mount.h) 217*37714Smckusick */ 218*37714Smckusick struct ufid { 219*37714Smckusick u_short ufid_len; 220*37714Smckusick ino_t ufid_ino; 221*37714Smckusick long ufid_gen; 222*37714Smckusick }; 223*37714Smckusick #endif 224