xref: /csrg-svn/sys/ufs/ffs/inode.h (revision 16057)
1*16057Skarels /*	inode.h	6.2	84/02/15	*/
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 */
4812650Ssam 		long	ic_blocks;	/* 104: blocks actually held */
4912650Ssam 		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
686565Smckusic #define	i_db		i_ic.ic_db
696565Smckusic #define	i_ib		i_ic.ic_ib
706565Smckusic #define	i_atime		i_ic.ic_atime
716565Smckusic #define	i_mtime		i_ic.ic_mtime
726565Smckusic #define	i_ctime		i_ic.ic_ctime
7312650Ssam #define i_blocks	i_ic.ic_blocks
746565Smckusic #define	i_rdev		i_ic.ic_db[0]
756565Smckusic #define	i_lastr		i_un.if_lastr
769005Sroot #define	i_socket	i_un.is_socket
777333Skre #define	i_forw		i_chain[0]
787333Skre #define	i_back		i_chain[1]
797333Skre #define	i_freef		i_un.i_fr.if_freef
807333Skre #define	i_freeb		i_un.i_fr.if_freeb
816565Smckusic 
826565Smckusic #define di_ic		di_un.di_icom
836565Smckusic #define	di_mode		di_ic.ic_mode
846565Smckusic #define	di_nlink	di_ic.ic_nlink
856565Smckusic #define	di_uid		di_ic.ic_uid
866565Smckusic #define	di_gid		di_ic.ic_gid
879790Ssam #ifdef vax
889182Ssam #define	di_size		di_ic.ic_size.val[0]
899790Ssam #endif
906565Smckusic #define	di_db		di_ic.ic_db
916565Smckusic #define	di_ib		di_ic.ic_ib
926565Smckusic #define	di_atime	di_ic.ic_atime
936565Smckusic #define	di_mtime	di_ic.ic_mtime
946565Smckusic #define	di_ctime	di_ic.ic_ctime
956565Smckusic #define	di_rdev		di_ic.ic_db[0]
9612650Ssam #define	di_blocks	di_ic.ic_blocks
976565Smckusic 
9858Sbill #ifdef KERNEL
998691Sroot struct inode *inode;		/* the inode table itself */
1008691Sroot struct inode *inodeNINODE;	/* the end of the inode table */
1018691Sroot int	ninode;			/* number of slots in the table */
10258Sbill 
1036565Smckusic struct	inode *rootdir;			/* pointer to inode of root directory */
10458Sbill 
10558Sbill struct	inode *ialloc();
10658Sbill struct	inode *iget();
1079182Ssam #ifdef notdef
1089182Ssam struct	inode *ifind();
1099182Ssam #endif
11058Sbill struct	inode *owner();
11158Sbill struct	inode *maknode();
11258Sbill struct	inode *namei();
1139182Ssam 
1149182Ssam ino_t	dirpref();
11558Sbill #endif
11658Sbill 
11758Sbill /* flags */
1188467Sroot #define	ILOCKED		0x1		/* inode is locked */
1197703Ssam #define	IUPD		0x2		/* file has been modified */
1207703Ssam #define	IACC		0x4		/* inode access time to be updated */
1217703Ssam #define	IMOUNT		0x8		/* inode is mounted on */
1227703Ssam #define	IWANT		0x10		/* some process waiting on lock */
1237703Ssam #define	ITEXT		0x20		/* inode is pure text prototype */
1247703Ssam #define	ICHG		0x40		/* inode has been changed */
1259182Ssam #define	ISHLOCK		0x80		/* file has shared lock */
1269182Ssam #define	IEXLOCK		0x100		/* file has exclusive lock */
1277703Ssam #define	ILWAIT		0x200		/* someone waiting on file lock */
128*16057Skarels #define	IMOD		0x400		/* inode has been modified */
12958Sbill 
13058Sbill /* modes */
1316565Smckusic #define	IFMT		0170000		/* type of file */
1326565Smckusic #define	IFCHR		0020000		/* character special */
1336565Smckusic #define	IFDIR		0040000		/* directory */
1346565Smckusic #define	IFBLK		0060000		/* block special */
1356565Smckusic #define	IFREG		0100000		/* regular */
1366565Smckusic #define	IFLNK		0120000		/* symbolic link */
1378990Sroot #define	IFSOCK		0140000		/* socket */
1388990Sroot 
1396565Smckusic #define	ISUID		04000		/* set user id on execution */
1406565Smckusic #define	ISGID		02000		/* set group id on execution */
1416565Smckusic #define	ISVTX		01000		/* save swapped text even after use */
1426565Smckusic #define	IREAD		0400		/* read, write, execute permissions */
1436565Smckusic #define	IWRITE		0200
1446565Smckusic #define	IEXEC		0100
1458467Sroot 
1468467Sroot #define	ILOCK(ip) { \
1478467Sroot 	while ((ip)->i_flag & ILOCKED) { \
1488467Sroot 		(ip)->i_flag |= IWANT; \
1498467Sroot 		sleep((caddr_t)(ip), PINOD); \
1508467Sroot 	} \
1518467Sroot 	(ip)->i_flag |= ILOCKED; \
1528467Sroot }
1538467Sroot 
1548467Sroot #define	IUNLOCK(ip) { \
1558467Sroot 	(ip)->i_flag &= ~ILOCKED; \
1568467Sroot 	if ((ip)->i_flag&IWANT) { \
1578467Sroot 		(ip)->i_flag &= ~IWANT; \
1588467Sroot 		wakeup((caddr_t)(ip)); \
1598467Sroot 	} \
1608467Sroot }
1618467Sroot 
1628467Sroot #define	IUPDAT(ip, t1, t2, waitfor) { \
163*16057Skarels 	if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
1648467Sroot 		iupdat(ip, t1, t2, waitfor); \
1658467Sroot }
166*16057Skarels 
167*16057Skarels #define	ITIMES(ip, t1, t2) { \
168*16057Skarels 	if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
169*16057Skarels 		(ip)->i_flag |= IMOD; \
170*16057Skarels 		if ((ip)->i_flag&IACC) \
171*16057Skarels 			(ip)->i_atime = (t1)->tv_sec; \
172*16057Skarels 		if ((ip)->i_flag&IUPD) \
173*16057Skarels 			(ip)->i_mtime = (t2)->tv_sec; \
174*16057Skarels 		if ((ip)->i_flag&ICHG) \
175*16057Skarels 			(ip)->i_ctime = time.tv_sec; \
176*16057Skarels 		(ip)->i_flag &= ~(IACC|IUPD|ICHG); \
177*16057Skarels 	} \
178*16057Skarels }
179*16057Skarels 
180