1*8990Sroot /* dinode.h 4.18 82/10/31 */ 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 116565Smckusic #define NDADDR 8 /* direct addresses in inode */ 126565Smckusic #define NIADDR 2 /* 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 */ 197703Ssam u_short i_rdlockc; /* count of locked readers on inode */ 207703Ssam u_short i_wrlockc; /* count of locked writers 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 */ 386565Smckusic off_t ic_size; /* 8: number of bytes in file */ 396565Smckusic daddr_t ic_db[NDADDR]; /* 12: disk block addresses */ 406565Smckusic daddr_t ic_ib[NIADDR]; /* 44: indirect blocks */ 416565Smckusic time_t ic_atime; /* 52: time last accessed */ 426565Smckusic time_t ic_mtime; /* 56: time last modified */ 436565Smckusic time_t ic_ctime; /* 60: time created */ 446565Smckusic } i_ic; 4558Sbill }; 4658Sbill 476565Smckusic struct dinode { 486565Smckusic union { 496565Smckusic struct icommon di_icom; 506565Smckusic char di_size[64]; 516565Smckusic } di_un; 526565Smckusic }; 536565Smckusic 546565Smckusic #define i_mode i_ic.ic_mode 556565Smckusic #define i_nlink i_ic.ic_nlink 566565Smckusic #define i_uid i_ic.ic_uid 576565Smckusic #define i_gid i_ic.ic_gid 586565Smckusic #define i_size i_ic.ic_size 596565Smckusic #define i_db i_ic.ic_db 606565Smckusic #define i_ib i_ic.ic_ib 616565Smckusic #define i_atime i_ic.ic_atime 626565Smckusic #define i_mtime i_ic.ic_mtime 636565Smckusic #define i_ctime i_ic.ic_ctime 646565Smckusic #define i_rdev i_ic.ic_db[0] 656565Smckusic #define i_lastr i_un.if_lastr 666565Smckusic #define i_socket is_socket 677333Skre #define i_forw i_chain[0] 687333Skre #define i_back i_chain[1] 697333Skre #define i_freef i_un.i_fr.if_freef 707333Skre #define i_freeb i_un.i_fr.if_freeb 716565Smckusic 726565Smckusic #define di_ic di_un.di_icom 736565Smckusic #define di_mode di_ic.ic_mode 746565Smckusic #define di_nlink di_ic.ic_nlink 756565Smckusic #define di_uid di_ic.ic_uid 766565Smckusic #define di_gid di_ic.ic_gid 776565Smckusic #define di_size di_ic.ic_size 786565Smckusic #define di_db di_ic.ic_db 796565Smckusic #define di_ib di_ic.ic_ib 806565Smckusic #define di_atime di_ic.ic_atime 816565Smckusic #define di_mtime di_ic.ic_mtime 826565Smckusic #define di_ctime di_ic.ic_ctime 836565Smckusic #define di_rdev di_ic.ic_db[0] 846565Smckusic 8558Sbill #ifdef KERNEL 868691Sroot struct inode *inode; /* the inode table itself */ 878691Sroot struct inode *inodeNINODE; /* the end of the inode table */ 888691Sroot int ninode; /* number of slots in the table */ 8958Sbill 906565Smckusic struct inode *rootdir; /* pointer to inode of root directory */ 9158Sbill 9258Sbill struct inode *ialloc(); 9358Sbill struct inode *iget(); 9458Sbill struct inode *owner(); 9558Sbill struct inode *maknode(); 9658Sbill struct inode *namei(); 9758Sbill #endif 9858Sbill 9958Sbill /* flags */ 1008467Sroot #define ILOCKED 0x1 /* inode is locked */ 1017703Ssam #define IUPD 0x2 /* file has been modified */ 1027703Ssam #define IACC 0x4 /* inode access time to be updated */ 1037703Ssam #define IMOUNT 0x8 /* inode is mounted on */ 1047703Ssam #define IWANT 0x10 /* some process waiting on lock */ 1057703Ssam #define ITEXT 0x20 /* inode is pure text prototype */ 1067703Ssam #define ICHG 0x40 /* inode has been changed */ 1077703Ssam #define IRDLOCK 0x80 /* file is read locked */ 1087703Ssam #define IWRLOCK 0x100 /* file is write locked */ 1097703Ssam #define ILWAIT 0x200 /* someone waiting on file lock */ 11058Sbill 11158Sbill /* modes */ 1126565Smckusic #define IFMT 0170000 /* type of file */ 1136565Smckusic #define IFCHR 0020000 /* character special */ 1146565Smckusic #define IFDIR 0040000 /* directory */ 1156565Smckusic #define IFBLK 0060000 /* block special */ 1166565Smckusic #define IFREG 0100000 /* regular */ 1176565Smckusic #define IFLNK 0120000 /* symbolic link */ 118*8990Sroot #define IFSOCK 0140000 /* socket */ 119*8990Sroot 1206565Smckusic #define ISUID 04000 /* set user id on execution */ 1216565Smckusic #define ISGID 02000 /* set group id on execution */ 1226565Smckusic #define ISVTX 01000 /* save swapped text even after use */ 1236565Smckusic #define IREAD 0400 /* read, write, execute permissions */ 1246565Smckusic #define IWRITE 0200 1256565Smckusic #define IEXEC 0100 1268467Sroot 1278467Sroot #define ILOCK(ip) { \ 1288467Sroot while ((ip)->i_flag & ILOCKED) { \ 1298467Sroot (ip)->i_flag |= IWANT; \ 1308467Sroot sleep((caddr_t)(ip), PINOD); \ 1318467Sroot } \ 1328467Sroot (ip)->i_flag |= ILOCKED; \ 1338467Sroot } 1348467Sroot 1358467Sroot #define IUNLOCK(ip) { \ 1368467Sroot (ip)->i_flag &= ~ILOCKED; \ 1378467Sroot if ((ip)->i_flag&IWANT) { \ 1388467Sroot (ip)->i_flag &= ~IWANT; \ 1398467Sroot wakeup((caddr_t)(ip)); \ 1408467Sroot } \ 1418467Sroot } 1428467Sroot 1438467Sroot #define IUPDAT(ip, t1, t2, waitfor) { \ 1448467Sroot if (ip->i_flag&(IUPD|IACC|ICHG)) \ 1458467Sroot iupdat(ip, t1, t2, waitfor); \ 1468467Sroot } 147