xref: /csrg-svn/sys/ufs/ffs/inode.h (revision 17703)
1*17703Smckusick /*	inode.h	6.7	85/01/10	*/
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 */
2216646Ssam 	long	i_id;		/* unique identifier */
236565Smckusic 	struct	fs *i_fs;	/* file sys associated with this inode */
247452Skre 	struct	dquot *i_dquot;	/* quota structure controlling this file */
2558Sbill 	union {
266565Smckusic 		daddr_t	if_lastr;	/* last read (read-ahead) */
276565Smckusic 		struct	socket *is_socket;
287333Skre 		struct	{
297333Skre 			struct inode  *if_freef;	/* free list forward */
307333Skre 			struct inode **if_freeb;	/* free list back */
317333Skre 		} i_fr;
3258Sbill 	} i_un;
336565Smckusic 	struct 	icommon
346565Smckusic 	{
356565Smckusic 		u_short	ic_mode;	/*  0: mode and type of file */
366565Smckusic 		short	ic_nlink;	/*  2: number of links to file */
376565Smckusic 		short	ic_uid;		/*  4: owner's user id */
386565Smckusic 		short	ic_gid;		/*  6: owner's group id */
399182Ssam 		quad	ic_size;	/*  8: number of bytes in file */
409182Ssam 		time_t	ic_atime;	/* 16: time last accessed */
419182Ssam 		long	ic_atspare;
429182Ssam 		time_t	ic_mtime;	/* 24: time last modified */
439182Ssam 		long	ic_mtspare;
4410854Ssam 		time_t	ic_ctime;	/* 32: last time inode changed */
459182Ssam 		long	ic_ctspare;
469182Ssam 		daddr_t	ic_db[NDADDR];	/* 40: disk block addresses */
479182Ssam 		daddr_t	ic_ib[NIADDR];	/* 88: indirect blocks */
489182Ssam 		long	ic_flags;	/* 100: status, currently unused */
4912650Ssam 		long	ic_blocks;	/* 104: blocks actually held */
5012650Ssam 		long	ic_spare[5];	/* 108: reserved, currently unused */
516565Smckusic 	} i_ic;
5258Sbill };
5358Sbill 
546565Smckusic struct dinode {
556565Smckusic 	union {
566565Smckusic 		struct	icommon di_icom;
579182Ssam 		char	di_size[128];
586565Smckusic 	} di_un;
596565Smckusic };
606565Smckusic 
616565Smckusic #define	i_mode		i_ic.ic_mode
626565Smckusic #define	i_nlink		i_ic.ic_nlink
636565Smckusic #define	i_uid		i_ic.ic_uid
646565Smckusic #define	i_gid		i_ic.ic_gid
659790Ssam /* ugh! -- must be fixed */
669790Ssam #ifdef vax
679182Ssam #define	i_size		i_ic.ic_size.val[0]
689790Ssam #endif
696565Smckusic #define	i_db		i_ic.ic_db
706565Smckusic #define	i_ib		i_ic.ic_ib
716565Smckusic #define	i_atime		i_ic.ic_atime
726565Smckusic #define	i_mtime		i_ic.ic_mtime
736565Smckusic #define	i_ctime		i_ic.ic_ctime
7412650Ssam #define i_blocks	i_ic.ic_blocks
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
889790Ssam #ifdef vax
899182Ssam #define	di_size		di_ic.ic_size.val[0]
909790Ssam #endif
916565Smckusic #define	di_db		di_ic.ic_db
926565Smckusic #define	di_ib		di_ic.ic_ib
936565Smckusic #define	di_atime	di_ic.ic_atime
946565Smckusic #define	di_mtime	di_ic.ic_mtime
956565Smckusic #define	di_ctime	di_ic.ic_ctime
966565Smckusic #define	di_rdev		di_ic.ic_db[0]
9712650Ssam #define	di_blocks	di_ic.ic_blocks
986565Smckusic 
9958Sbill #ifdef KERNEL
10016737Smckusick /*
10116737Smckusick  * Invalidate an inode. Used by the namei cache to detect stale
10216737Smckusick  * information. At an absurd rate of 100 calls/second, the inode
10316737Smckusick  * table invalidation should only occur once every 16 months.
10416737Smckusick  */
10516737Smckusick #define cacheinval(ip)	\
10616737Smckusick 	(ip)->i_id = ++nextinodeid; \
10716737Smckusick 	if (nextinodeid == 0) \
108*17703Smckusick 		cacheinvalall();
10916737Smckusick 
1108691Sroot struct inode *inode;		/* the inode table itself */
1118691Sroot struct inode *inodeNINODE;	/* the end of the inode table */
1128691Sroot int	ninode;			/* number of slots in the table */
11316646Ssam long	nextinodeid;		/* unique id generator */
11458Sbill 
1156565Smckusic struct	inode *rootdir;			/* pointer to inode of root directory */
11658Sbill 
11758Sbill struct	inode *ialloc();
11858Sbill struct	inode *iget();
1199182Ssam #ifdef notdef
1209182Ssam struct	inode *ifind();
1219182Ssam #endif
12258Sbill struct	inode *owner();
12358Sbill struct	inode *maknode();
12458Sbill struct	inode *namei();
1259182Ssam 
1269182Ssam ino_t	dirpref();
12758Sbill #endif
12858Sbill 
12958Sbill /* flags */
1308467Sroot #define	ILOCKED		0x1		/* inode is locked */
1317703Ssam #define	IUPD		0x2		/* file has been modified */
1327703Ssam #define	IACC		0x4		/* inode access time to be updated */
1337703Ssam #define	IMOUNT		0x8		/* inode is mounted on */
1347703Ssam #define	IWANT		0x10		/* some process waiting on lock */
1357703Ssam #define	ITEXT		0x20		/* inode is pure text prototype */
1367703Ssam #define	ICHG		0x40		/* inode has been changed */
1379182Ssam #define	ISHLOCK		0x80		/* file has shared lock */
1389182Ssam #define	IEXLOCK		0x100		/* file has exclusive lock */
1397703Ssam #define	ILWAIT		0x200		/* someone waiting on file lock */
14016057Skarels #define	IMOD		0x400		/* inode has been modified */
14116775Smckusick #define	IRENAME		0x800		/* inode is being renamed */
14217555Skarels #define	IXMOD		0x8000		/* inode is text, but impure (XXX) */
14358Sbill 
14458Sbill /* modes */
1456565Smckusic #define	IFMT		0170000		/* type of file */
1466565Smckusic #define	IFCHR		0020000		/* character special */
1476565Smckusic #define	IFDIR		0040000		/* directory */
1486565Smckusic #define	IFBLK		0060000		/* block special */
1496565Smckusic #define	IFREG		0100000		/* regular */
1506565Smckusic #define	IFLNK		0120000		/* symbolic link */
1518990Sroot #define	IFSOCK		0140000		/* socket */
1528990Sroot 
1536565Smckusic #define	ISUID		04000		/* set user id on execution */
1546565Smckusic #define	ISGID		02000		/* set group id on execution */
1556565Smckusic #define	ISVTX		01000		/* save swapped text even after use */
1566565Smckusic #define	IREAD		0400		/* read, write, execute permissions */
1576565Smckusic #define	IWRITE		0200
1586565Smckusic #define	IEXEC		0100
1598467Sroot 
1608467Sroot #define	ILOCK(ip) { \
1618467Sroot 	while ((ip)->i_flag & ILOCKED) { \
1628467Sroot 		(ip)->i_flag |= IWANT; \
1638467Sroot 		sleep((caddr_t)(ip), PINOD); \
1648467Sroot 	} \
1658467Sroot 	(ip)->i_flag |= ILOCKED; \
1668467Sroot }
1678467Sroot 
1688467Sroot #define	IUNLOCK(ip) { \
1698467Sroot 	(ip)->i_flag &= ~ILOCKED; \
1708467Sroot 	if ((ip)->i_flag&IWANT) { \
1718467Sroot 		(ip)->i_flag &= ~IWANT; \
1728467Sroot 		wakeup((caddr_t)(ip)); \
1738467Sroot 	} \
1748467Sroot }
1758467Sroot 
1768467Sroot #define	IUPDAT(ip, t1, t2, waitfor) { \
17716057Skarels 	if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
1788467Sroot 		iupdat(ip, t1, t2, waitfor); \
1798467Sroot }
18016057Skarels 
18116057Skarels #define	ITIMES(ip, t1, t2) { \
18216057Skarels 	if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
18316057Skarels 		(ip)->i_flag |= IMOD; \
18416057Skarels 		if ((ip)->i_flag&IACC) \
18516057Skarels 			(ip)->i_atime = (t1)->tv_sec; \
18616057Skarels 		if ((ip)->i_flag&IUPD) \
18716057Skarels 			(ip)->i_mtime = (t2)->tv_sec; \
18816057Skarels 		if ((ip)->i_flag&ICHG) \
18916057Skarels 			(ip)->i_ctime = time.tv_sec; \
19016057Skarels 		(ip)->i_flag &= ~(IACC|IUPD|ICHG); \
19116057Skarels 	} \
19216057Skarels }
193