1*12650Ssam /* inode.h 4.23 83/05/21 */ 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; 4310854Ssam time_t ic_ctime; /* 32: last time inode changed */ 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 */ 48*12650Ssam long ic_blocks; /* 104: blocks actually held */ 49*12650Ssam long ic_spare[5]; /* 108: reserved, currently unused */ 506565Smckusic } i_ic; 5158Sbill }; 5258Sbill 536565Smckusic struct dinode { 546565Smckusic union { 556565Smckusic struct icommon di_icom; 569182Ssam char di_size[128]; 576565Smckusic } di_un; 586565Smckusic }; 596565Smckusic 606565Smckusic #define i_mode i_ic.ic_mode 616565Smckusic #define i_nlink i_ic.ic_nlink 626565Smckusic #define i_uid i_ic.ic_uid 636565Smckusic #define i_gid i_ic.ic_gid 649790Ssam /* ugh! -- must be fixed */ 659790Ssam #ifdef vax 669182Ssam #define i_size i_ic.ic_size.val[0] 679790Ssam #endif 689790Ssam #ifdef sun 699790Ssam #define i_size i_ic.ic_size.val[1] 709790Ssam #endif 716565Smckusic #define i_db i_ic.ic_db 726565Smckusic #define i_ib i_ic.ic_ib 736565Smckusic #define i_atime i_ic.ic_atime 746565Smckusic #define i_mtime i_ic.ic_mtime 756565Smckusic #define i_ctime i_ic.ic_ctime 76*12650Ssam #define i_blocks i_ic.ic_blocks 776565Smckusic #define i_rdev i_ic.ic_db[0] 786565Smckusic #define i_lastr i_un.if_lastr 799005Sroot #define i_socket i_un.is_socket 807333Skre #define i_forw i_chain[0] 817333Skre #define i_back i_chain[1] 827333Skre #define i_freef i_un.i_fr.if_freef 837333Skre #define i_freeb i_un.i_fr.if_freeb 846565Smckusic 856565Smckusic #define di_ic di_un.di_icom 866565Smckusic #define di_mode di_ic.ic_mode 876565Smckusic #define di_nlink di_ic.ic_nlink 886565Smckusic #define di_uid di_ic.ic_uid 896565Smckusic #define di_gid di_ic.ic_gid 909790Ssam #ifdef vax 919182Ssam #define di_size di_ic.ic_size.val[0] 929790Ssam #endif 939790Ssam #ifdef sun 949790Ssam #define di_size di_ic.ic_size.val[1] 959790Ssam #endif 966565Smckusic #define di_db di_ic.ic_db 976565Smckusic #define di_ib di_ic.ic_ib 986565Smckusic #define di_atime di_ic.ic_atime 996565Smckusic #define di_mtime di_ic.ic_mtime 1006565Smckusic #define di_ctime di_ic.ic_ctime 1016565Smckusic #define di_rdev di_ic.ic_db[0] 102*12650Ssam #define di_blocks di_ic.ic_blocks 1036565Smckusic 10458Sbill #ifdef KERNEL 1058691Sroot struct inode *inode; /* the inode table itself */ 1068691Sroot struct inode *inodeNINODE; /* the end of the inode table */ 1078691Sroot int ninode; /* number of slots in the table */ 10858Sbill 1096565Smckusic struct inode *rootdir; /* pointer to inode of root directory */ 11058Sbill 11158Sbill struct inode *ialloc(); 11258Sbill struct inode *iget(); 1139182Ssam #ifdef notdef 1149182Ssam struct inode *ifind(); 1159182Ssam #endif 11658Sbill struct inode *owner(); 11758Sbill struct inode *maknode(); 11858Sbill struct inode *namei(); 1199182Ssam 1209182Ssam ino_t dirpref(); 12158Sbill #endif 12258Sbill 12358Sbill /* flags */ 1248467Sroot #define ILOCKED 0x1 /* inode is locked */ 1257703Ssam #define IUPD 0x2 /* file has been modified */ 1267703Ssam #define IACC 0x4 /* inode access time to be updated */ 1277703Ssam #define IMOUNT 0x8 /* inode is mounted on */ 1287703Ssam #define IWANT 0x10 /* some process waiting on lock */ 1297703Ssam #define ITEXT 0x20 /* inode is pure text prototype */ 1307703Ssam #define ICHG 0x40 /* inode has been changed */ 1319182Ssam #define ISHLOCK 0x80 /* file has shared lock */ 1329182Ssam #define IEXLOCK 0x100 /* file has exclusive lock */ 1337703Ssam #define ILWAIT 0x200 /* someone waiting on file lock */ 13458Sbill 13558Sbill /* modes */ 1366565Smckusic #define IFMT 0170000 /* type of file */ 1376565Smckusic #define IFCHR 0020000 /* character special */ 1386565Smckusic #define IFDIR 0040000 /* directory */ 1396565Smckusic #define IFBLK 0060000 /* block special */ 1406565Smckusic #define IFREG 0100000 /* regular */ 1416565Smckusic #define IFLNK 0120000 /* symbolic link */ 1428990Sroot #define IFSOCK 0140000 /* socket */ 1438990Sroot 1446565Smckusic #define ISUID 04000 /* set user id on execution */ 1456565Smckusic #define ISGID 02000 /* set group id on execution */ 1466565Smckusic #define ISVTX 01000 /* save swapped text even after use */ 1476565Smckusic #define IREAD 0400 /* read, write, execute permissions */ 1486565Smckusic #define IWRITE 0200 1496565Smckusic #define IEXEC 0100 1508467Sroot 1518467Sroot #define ILOCK(ip) { \ 1528467Sroot while ((ip)->i_flag & ILOCKED) { \ 1538467Sroot (ip)->i_flag |= IWANT; \ 1548467Sroot sleep((caddr_t)(ip), PINOD); \ 1558467Sroot } \ 1568467Sroot (ip)->i_flag |= ILOCKED; \ 1578467Sroot } 1588467Sroot 1598467Sroot #define IUNLOCK(ip) { \ 1608467Sroot (ip)->i_flag &= ~ILOCKED; \ 1618467Sroot if ((ip)->i_flag&IWANT) { \ 1628467Sroot (ip)->i_flag &= ~IWANT; \ 1638467Sroot wakeup((caddr_t)(ip)); \ 1648467Sroot } \ 1658467Sroot } 1668467Sroot 1678467Sroot #define IUPDAT(ip, t1, t2, waitfor) { \ 1688467Sroot if (ip->i_flag&(IUPD|IACC|ICHG)) \ 1698467Sroot iupdat(ip, t1, t2, waitfor); \ 1708467Sroot } 171