xref: /csrg-svn/sys/ufs/ffs/inode.h (revision 9182)
1*9182Ssam /*	inode.h	4.20	82/11/13	*/
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 
11*9182Ssam #define	NDADDR	12		/* direct addresses in inode */
12*9182Ssam #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 */
19*9182Ssam 	u_short	i_shlockc;	/* count of shared locks on inode */
20*9182Ssam 	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 */
38*9182Ssam 		quad	ic_size;	/*  8: number of bytes in file */
39*9182Ssam 		time_t	ic_atime;	/* 16: time last accessed */
40*9182Ssam 		long	ic_atspare;
41*9182Ssam 		time_t	ic_mtime;	/* 24: time last modified */
42*9182Ssam 		long	ic_mtspare;
43*9182Ssam 		time_t	ic_ctime;	/* 32: time created */
44*9182Ssam 		long	ic_ctspare;
45*9182Ssam 		daddr_t	ic_db[NDADDR];	/* 40: disk block addresses */
46*9182Ssam 		daddr_t	ic_ib[NIADDR];	/* 88: indirect blocks */
47*9182Ssam 		long	ic_flags;	/* 100: status, currently unused */
48*9182Ssam 		long	ic_spare[6];	/* 104: reserved, currently unused */
496565Smckusic 	} i_ic;
5058Sbill };
5158Sbill 
526565Smckusic struct dinode {
536565Smckusic 	union {
546565Smckusic 		struct	icommon di_icom;
55*9182Ssam 		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*9182Ssam #define	i_size		i_ic.ic_size.val[0]
646565Smckusic #define	i_db		i_ic.ic_db
656565Smckusic #define	i_ib		i_ic.ic_ib
666565Smckusic #define	i_atime		i_ic.ic_atime
676565Smckusic #define	i_mtime		i_ic.ic_mtime
686565Smckusic #define	i_ctime		i_ic.ic_ctime
696565Smckusic #define	i_rdev		i_ic.ic_db[0]
706565Smckusic #define	i_lastr		i_un.if_lastr
719005Sroot #define	i_socket	i_un.is_socket
727333Skre #define	i_forw		i_chain[0]
737333Skre #define	i_back		i_chain[1]
747333Skre #define	i_freef		i_un.i_fr.if_freef
757333Skre #define	i_freeb		i_un.i_fr.if_freeb
766565Smckusic 
776565Smckusic #define di_ic		di_un.di_icom
786565Smckusic #define	di_mode		di_ic.ic_mode
796565Smckusic #define	di_nlink	di_ic.ic_nlink
806565Smckusic #define	di_uid		di_ic.ic_uid
816565Smckusic #define	di_gid		di_ic.ic_gid
82*9182Ssam #define	di_size		di_ic.ic_size.val[0]
836565Smckusic #define	di_db		di_ic.ic_db
846565Smckusic #define	di_ib		di_ic.ic_ib
856565Smckusic #define	di_atime	di_ic.ic_atime
866565Smckusic #define	di_mtime	di_ic.ic_mtime
876565Smckusic #define	di_ctime	di_ic.ic_ctime
886565Smckusic #define	di_rdev		di_ic.ic_db[0]
896565Smckusic 
9058Sbill #ifdef KERNEL
918691Sroot struct inode *inode;		/* the inode table itself */
928691Sroot struct inode *inodeNINODE;	/* the end of the inode table */
938691Sroot int	ninode;			/* number of slots in the table */
9458Sbill 
956565Smckusic struct	inode *rootdir;			/* pointer to inode of root directory */
9658Sbill 
9758Sbill struct	inode *ialloc();
9858Sbill struct	inode *iget();
99*9182Ssam #ifdef notdef
100*9182Ssam struct	inode *ifind();
101*9182Ssam #endif
10258Sbill struct	inode *owner();
10358Sbill struct	inode *maknode();
10458Sbill struct	inode *namei();
105*9182Ssam 
106*9182Ssam ino_t	dirpref();
10758Sbill #endif
10858Sbill 
10958Sbill /* flags */
1108467Sroot #define	ILOCKED		0x1		/* inode is locked */
1117703Ssam #define	IUPD		0x2		/* file has been modified */
1127703Ssam #define	IACC		0x4		/* inode access time to be updated */
1137703Ssam #define	IMOUNT		0x8		/* inode is mounted on */
1147703Ssam #define	IWANT		0x10		/* some process waiting on lock */
1157703Ssam #define	ITEXT		0x20		/* inode is pure text prototype */
1167703Ssam #define	ICHG		0x40		/* inode has been changed */
117*9182Ssam #define	ISHLOCK		0x80		/* file has shared lock */
118*9182Ssam #define	IEXLOCK		0x100		/* file has exclusive lock */
1197703Ssam #define	ILWAIT		0x200		/* someone waiting on file lock */
12058Sbill 
12158Sbill /* modes */
1226565Smckusic #define	IFMT		0170000		/* type of file */
1236565Smckusic #define	IFCHR		0020000		/* character special */
1246565Smckusic #define	IFDIR		0040000		/* directory */
1256565Smckusic #define	IFBLK		0060000		/* block special */
1266565Smckusic #define	IFREG		0100000		/* regular */
1276565Smckusic #define	IFLNK		0120000		/* symbolic link */
1288990Sroot #define	IFSOCK		0140000		/* socket */
1298990Sroot 
1306565Smckusic #define	ISUID		04000		/* set user id on execution */
1316565Smckusic #define	ISGID		02000		/* set group id on execution */
1326565Smckusic #define	ISVTX		01000		/* save swapped text even after use */
1336565Smckusic #define	IREAD		0400		/* read, write, execute permissions */
1346565Smckusic #define	IWRITE		0200
1356565Smckusic #define	IEXEC		0100
1368467Sroot 
1378467Sroot #define	ILOCK(ip) { \
1388467Sroot 	while ((ip)->i_flag & ILOCKED) { \
1398467Sroot 		(ip)->i_flag |= IWANT; \
1408467Sroot 		sleep((caddr_t)(ip), PINOD); \
1418467Sroot 	} \
1428467Sroot 	(ip)->i_flag |= ILOCKED; \
1438467Sroot }
1448467Sroot 
1458467Sroot #define	IUNLOCK(ip) { \
1468467Sroot 	(ip)->i_flag &= ~ILOCKED; \
1478467Sroot 	if ((ip)->i_flag&IWANT) { \
1488467Sroot 		(ip)->i_flag &= ~IWANT; \
1498467Sroot 		wakeup((caddr_t)(ip)); \
1508467Sroot 	} \
1518467Sroot }
1528467Sroot 
1538467Sroot #define	IUPDAT(ip, t1, t2, waitfor) { \
1548467Sroot 	if (ip->i_flag&(IUPD|IACC|ICHG)) \
1558467Sroot 		iupdat(ip, t1, t2, waitfor); \
1568467Sroot }
157