1*9790Ssam /* inode.h 4.21 82/12/17 */ 258Sbill 358Sbill /* 44814Swnj * The I node is the focus of all file activity in UNIX. 54814Swnj * There is a unique inode allocated for each active file, 64814Swnj * each current directory, each mounted-on file, text file, and the root. 74814Swnj * An inode is 'named' by its dev/inumber pair. (iget/iget.c) 86565Smckusic * Data in icommon is read in from permanent inode on volume. 958Sbill */ 1058Sbill 119182Ssam #define NDADDR 12 /* direct addresses in inode */ 129182Ssam #define NIADDR 3 /* indirect addresses in inode */ 136565Smckusic 144814Swnj struct inode { 157333Skre struct inode *i_chain[2]; /* must be first */ 167703Ssam u_short i_flag; 177452Skre u_short i_count; /* reference count */ 1858Sbill dev_t i_dev; /* device where inode resides */ 199182Ssam u_short i_shlockc; /* count of shared locks on inode */ 209182Ssam u_short i_exlockc; /* count of exclusive locks on inode */ 2158Sbill ino_t i_number; /* i number, 1-to-1 with device address */ 226565Smckusic struct fs *i_fs; /* file sys associated with this inode */ 237452Skre struct dquot *i_dquot; /* quota structure controlling this file */ 2458Sbill union { 256565Smckusic daddr_t if_lastr; /* last read (read-ahead) */ 266565Smckusic struct socket *is_socket; 277333Skre struct { 287333Skre struct inode *if_freef; /* free list forward */ 297333Skre struct inode **if_freeb; /* free list back */ 307333Skre } i_fr; 3158Sbill } i_un; 326565Smckusic struct icommon 336565Smckusic { 346565Smckusic u_short ic_mode; /* 0: mode and type of file */ 356565Smckusic short ic_nlink; /* 2: number of links to file */ 366565Smckusic short ic_uid; /* 4: owner's user id */ 376565Smckusic short ic_gid; /* 6: owner's group id */ 389182Ssam quad ic_size; /* 8: number of bytes in file */ 399182Ssam time_t ic_atime; /* 16: time last accessed */ 409182Ssam long ic_atspare; 419182Ssam time_t ic_mtime; /* 24: time last modified */ 429182Ssam long ic_mtspare; 439182Ssam time_t ic_ctime; /* 32: time created */ 449182Ssam long ic_ctspare; 459182Ssam daddr_t ic_db[NDADDR]; /* 40: disk block addresses */ 469182Ssam daddr_t ic_ib[NIADDR]; /* 88: indirect blocks */ 479182Ssam long ic_flags; /* 100: status, currently unused */ 489182Ssam long ic_spare[6]; /* 104: reserved, currently unused */ 496565Smckusic } i_ic; 5058Sbill }; 5158Sbill 526565Smckusic struct dinode { 536565Smckusic union { 546565Smckusic struct icommon di_icom; 559182Ssam char di_size[128]; 566565Smckusic } di_un; 576565Smckusic }; 586565Smckusic 596565Smckusic #define i_mode i_ic.ic_mode 606565Smckusic #define i_nlink i_ic.ic_nlink 616565Smckusic #define i_uid i_ic.ic_uid 626565Smckusic #define i_gid i_ic.ic_gid 63*9790Ssam /* ugh! -- must be fixed */ 64*9790Ssam #ifdef vax 659182Ssam #define i_size i_ic.ic_size.val[0] 66*9790Ssam #endif 67*9790Ssam #ifdef sun 68*9790Ssam #define i_size i_ic.ic_size.val[1] 69*9790Ssam #endif 706565Smckusic #define i_db i_ic.ic_db 716565Smckusic #define i_ib i_ic.ic_ib 726565Smckusic #define i_atime i_ic.ic_atime 736565Smckusic #define i_mtime i_ic.ic_mtime 746565Smckusic #define i_ctime i_ic.ic_ctime 756565Smckusic #define i_rdev i_ic.ic_db[0] 766565Smckusic #define i_lastr i_un.if_lastr 779005Sroot #define i_socket i_un.is_socket 787333Skre #define i_forw i_chain[0] 797333Skre #define i_back i_chain[1] 807333Skre #define i_freef i_un.i_fr.if_freef 817333Skre #define i_freeb i_un.i_fr.if_freeb 826565Smckusic 836565Smckusic #define di_ic di_un.di_icom 846565Smckusic #define di_mode di_ic.ic_mode 856565Smckusic #define di_nlink di_ic.ic_nlink 866565Smckusic #define di_uid di_ic.ic_uid 876565Smckusic #define di_gid di_ic.ic_gid 88*9790Ssam #ifdef vax 899182Ssam #define di_size di_ic.ic_size.val[0] 90*9790Ssam #endif 91*9790Ssam #ifdef sun 92*9790Ssam #define di_size di_ic.ic_size.val[1] 93*9790Ssam #endif 946565Smckusic #define di_db di_ic.ic_db 956565Smckusic #define di_ib di_ic.ic_ib 966565Smckusic #define di_atime di_ic.ic_atime 976565Smckusic #define di_mtime di_ic.ic_mtime 986565Smckusic #define di_ctime di_ic.ic_ctime 996565Smckusic #define di_rdev di_ic.ic_db[0] 1006565Smckusic 10158Sbill #ifdef KERNEL 1028691Sroot struct inode *inode; /* the inode table itself */ 1038691Sroot struct inode *inodeNINODE; /* the end of the inode table */ 1048691Sroot int ninode; /* number of slots in the table */ 10558Sbill 1066565Smckusic struct inode *rootdir; /* pointer to inode of root directory */ 10758Sbill 10858Sbill struct inode *ialloc(); 10958Sbill struct inode *iget(); 1109182Ssam #ifdef notdef 1119182Ssam struct inode *ifind(); 1129182Ssam #endif 11358Sbill struct inode *owner(); 11458Sbill struct inode *maknode(); 11558Sbill struct inode *namei(); 1169182Ssam 1179182Ssam ino_t dirpref(); 11858Sbill #endif 11958Sbill 12058Sbill /* flags */ 1218467Sroot #define ILOCKED 0x1 /* inode is locked */ 1227703Ssam #define IUPD 0x2 /* file has been modified */ 1237703Ssam #define IACC 0x4 /* inode access time to be updated */ 1247703Ssam #define IMOUNT 0x8 /* inode is mounted on */ 1257703Ssam #define IWANT 0x10 /* some process waiting on lock */ 1267703Ssam #define ITEXT 0x20 /* inode is pure text prototype */ 1277703Ssam #define ICHG 0x40 /* inode has been changed */ 1289182Ssam #define ISHLOCK 0x80 /* file has shared lock */ 1299182Ssam #define IEXLOCK 0x100 /* file has exclusive lock */ 1307703Ssam #define ILWAIT 0x200 /* someone waiting on file lock */ 13158Sbill 13258Sbill /* modes */ 1336565Smckusic #define IFMT 0170000 /* type of file */ 1346565Smckusic #define IFCHR 0020000 /* character special */ 1356565Smckusic #define IFDIR 0040000 /* directory */ 1366565Smckusic #define IFBLK 0060000 /* block special */ 1376565Smckusic #define IFREG 0100000 /* regular */ 1386565Smckusic #define IFLNK 0120000 /* symbolic link */ 1398990Sroot #define IFSOCK 0140000 /* socket */ 1408990Sroot 1416565Smckusic #define ISUID 04000 /* set user id on execution */ 1426565Smckusic #define ISGID 02000 /* set group id on execution */ 1436565Smckusic #define ISVTX 01000 /* save swapped text even after use */ 1446565Smckusic #define IREAD 0400 /* read, write, execute permissions */ 1456565Smckusic #define IWRITE 0200 1466565Smckusic #define IEXEC 0100 1478467Sroot 1488467Sroot #define ILOCK(ip) { \ 1498467Sroot while ((ip)->i_flag & ILOCKED) { \ 1508467Sroot (ip)->i_flag |= IWANT; \ 1518467Sroot sleep((caddr_t)(ip), PINOD); \ 1528467Sroot } \ 1538467Sroot (ip)->i_flag |= ILOCKED; \ 1548467Sroot } 1558467Sroot 1568467Sroot #define IUNLOCK(ip) { \ 1578467Sroot (ip)->i_flag &= ~ILOCKED; \ 1588467Sroot if ((ip)->i_flag&IWANT) { \ 1598467Sroot (ip)->i_flag &= ~IWANT; \ 1608467Sroot wakeup((caddr_t)(ip)); \ 1618467Sroot } \ 1628467Sroot } 1638467Sroot 1648467Sroot #define IUPDAT(ip, t1, t2, waitfor) { \ 1658467Sroot if (ip->i_flag&(IUPD|IACC|ICHG)) \ 1668467Sroot iupdat(ip, t1, t2, waitfor); \ 1678467Sroot } 168