xref: /csrg-svn/sys/ufs/ffs/inode.h (revision 25456)
123419Smckusick /*
223419Smckusick  * Copyright (c) 1982 Regents of the University of California.
323419Smckusick  * All rights reserved.  The Berkeley software License Agreement
423419Smckusick  * specifies the terms and conditions for redistribution.
523419Smckusick  *
6*25456Skarels  *	@(#)inode.h	6.10 (Berkeley) 11/09/85
723419Smckusick  */
858Sbill 
958Sbill /*
104814Swnj  * The I node is the focus of all file activity in UNIX.
114814Swnj  * There is a unique inode allocated for each active file,
124814Swnj  * each current directory, each mounted-on file, text file, and the root.
134814Swnj  * An inode is 'named' by its dev/inumber pair. (iget/iget.c)
146565Smckusic  * Data in icommon is read in from permanent inode on volume.
1558Sbill  */
1658Sbill 
179182Ssam #define	NDADDR	12		/* direct addresses in inode */
189182Ssam #define	NIADDR	3		/* indirect addresses in inode */
196565Smckusic 
204814Swnj struct inode {
217333Skre 	struct	inode *i_chain[2];	/* must be first */
227703Ssam 	u_short	i_flag;
237452Skre 	u_short	i_count;	/* reference count */
2458Sbill 	dev_t	i_dev;		/* device where inode resides */
259182Ssam 	u_short	i_shlockc;	/* count of shared locks on inode */
269182Ssam 	u_short	i_exlockc;	/* count of exclusive locks on inode */
2758Sbill 	ino_t	i_number;	/* i number, 1-to-1 with device address */
2816646Ssam 	long	i_id;		/* unique identifier */
296565Smckusic 	struct	fs *i_fs;	/* file sys associated with this inode */
307452Skre 	struct	dquot *i_dquot;	/* quota structure controlling this file */
31*25456Skarels 	struct	text *i_text;	/* text entry, if any (should be region) */
3258Sbill 	union {
336565Smckusic 		daddr_t	if_lastr;	/* last read (read-ahead) */
346565Smckusic 		struct	socket *is_socket;
357333Skre 		struct	{
367333Skre 			struct inode  *if_freef;	/* free list forward */
377333Skre 			struct inode **if_freeb;	/* free list back */
387333Skre 		} i_fr;
3958Sbill 	} i_un;
406565Smckusic 	struct 	icommon
416565Smckusic 	{
426565Smckusic 		u_short	ic_mode;	/*  0: mode and type of file */
436565Smckusic 		short	ic_nlink;	/*  2: number of links to file */
4425318Skarels 		uid_t	ic_uid;		/*  4: owner's user id */
4525318Skarels 		gid_t	ic_gid;		/*  6: owner's group id */
469182Ssam 		quad	ic_size;	/*  8: number of bytes in file */
479182Ssam 		time_t	ic_atime;	/* 16: time last accessed */
489182Ssam 		long	ic_atspare;
499182Ssam 		time_t	ic_mtime;	/* 24: time last modified */
509182Ssam 		long	ic_mtspare;
5110854Ssam 		time_t	ic_ctime;	/* 32: last time inode changed */
529182Ssam 		long	ic_ctspare;
539182Ssam 		daddr_t	ic_db[NDADDR];	/* 40: disk block addresses */
549182Ssam 		daddr_t	ic_ib[NIADDR];	/* 88: indirect blocks */
559182Ssam 		long	ic_flags;	/* 100: status, currently unused */
5612650Ssam 		long	ic_blocks;	/* 104: blocks actually held */
5712650Ssam 		long	ic_spare[5];	/* 108: reserved, currently unused */
586565Smckusic 	} i_ic;
5958Sbill };
6058Sbill 
616565Smckusic struct dinode {
626565Smckusic 	union {
636565Smckusic 		struct	icommon di_icom;
649182Ssam 		char	di_size[128];
656565Smckusic 	} di_un;
666565Smckusic };
676565Smckusic 
686565Smckusic #define	i_mode		i_ic.ic_mode
696565Smckusic #define	i_nlink		i_ic.ic_nlink
706565Smckusic #define	i_uid		i_ic.ic_uid
716565Smckusic #define	i_gid		i_ic.ic_gid
729790Ssam /* ugh! -- must be fixed */
739790Ssam #ifdef vax
749182Ssam #define	i_size		i_ic.ic_size.val[0]
759790Ssam #endif
766565Smckusic #define	i_db		i_ic.ic_db
776565Smckusic #define	i_ib		i_ic.ic_ib
786565Smckusic #define	i_atime		i_ic.ic_atime
796565Smckusic #define	i_mtime		i_ic.ic_mtime
806565Smckusic #define	i_ctime		i_ic.ic_ctime
8112650Ssam #define i_blocks	i_ic.ic_blocks
826565Smckusic #define	i_rdev		i_ic.ic_db[0]
836565Smckusic #define	i_lastr		i_un.if_lastr
849005Sroot #define	i_socket	i_un.is_socket
857333Skre #define	i_forw		i_chain[0]
867333Skre #define	i_back		i_chain[1]
877333Skre #define	i_freef		i_un.i_fr.if_freef
887333Skre #define	i_freeb		i_un.i_fr.if_freeb
896565Smckusic 
906565Smckusic #define di_ic		di_un.di_icom
916565Smckusic #define	di_mode		di_ic.ic_mode
926565Smckusic #define	di_nlink	di_ic.ic_nlink
936565Smckusic #define	di_uid		di_ic.ic_uid
946565Smckusic #define	di_gid		di_ic.ic_gid
959790Ssam #ifdef vax
969182Ssam #define	di_size		di_ic.ic_size.val[0]
979790Ssam #endif
986565Smckusic #define	di_db		di_ic.ic_db
996565Smckusic #define	di_ib		di_ic.ic_ib
1006565Smckusic #define	di_atime	di_ic.ic_atime
1016565Smckusic #define	di_mtime	di_ic.ic_mtime
1026565Smckusic #define	di_ctime	di_ic.ic_ctime
1036565Smckusic #define	di_rdev		di_ic.ic_db[0]
10412650Ssam #define	di_blocks	di_ic.ic_blocks
1056565Smckusic 
10658Sbill #ifdef KERNEL
10716737Smckusick /*
10816737Smckusick  * Invalidate an inode. Used by the namei cache to detect stale
10916737Smckusick  * information. At an absurd rate of 100 calls/second, the inode
11016737Smckusick  * table invalidation should only occur once every 16 months.
11116737Smckusick  */
11216737Smckusick #define cacheinval(ip)	\
11316737Smckusick 	(ip)->i_id = ++nextinodeid; \
11416737Smckusick 	if (nextinodeid == 0) \
11517703Smckusick 		cacheinvalall();
11616737Smckusick 
1178691Sroot struct inode *inode;		/* the inode table itself */
1188691Sroot struct inode *inodeNINODE;	/* the end of the inode table */
1198691Sroot int	ninode;			/* number of slots in the table */
12016646Ssam long	nextinodeid;		/* unique id generator */
12158Sbill 
1226565Smckusic struct	inode *rootdir;			/* pointer to inode of root directory */
12358Sbill 
12458Sbill struct	inode *ialloc();
12558Sbill struct	inode *iget();
1269182Ssam #ifdef notdef
1279182Ssam struct	inode *ifind();
1289182Ssam #endif
12958Sbill struct	inode *owner();
13058Sbill struct	inode *maknode();
13158Sbill struct	inode *namei();
1329182Ssam 
1339182Ssam ino_t	dirpref();
13458Sbill #endif
13558Sbill 
13658Sbill /* flags */
1378467Sroot #define	ILOCKED		0x1		/* inode is locked */
1387703Ssam #define	IUPD		0x2		/* file has been modified */
1397703Ssam #define	IACC		0x4		/* inode access time to be updated */
1407703Ssam #define	IMOUNT		0x8		/* inode is mounted on */
1417703Ssam #define	IWANT		0x10		/* some process waiting on lock */
1427703Ssam #define	ITEXT		0x20		/* inode is pure text prototype */
1437703Ssam #define	ICHG		0x40		/* inode has been changed */
1449182Ssam #define	ISHLOCK		0x80		/* file has shared lock */
1459182Ssam #define	IEXLOCK		0x100		/* file has exclusive lock */
1467703Ssam #define	ILWAIT		0x200		/* someone waiting on file lock */
14716057Skarels #define	IMOD		0x400		/* inode has been modified */
14816775Smckusick #define	IRENAME		0x800		/* inode is being renamed */
14917555Skarels #define	IXMOD		0x8000		/* inode is text, but impure (XXX) */
15058Sbill 
15158Sbill /* modes */
1526565Smckusic #define	IFMT		0170000		/* type of file */
1536565Smckusic #define	IFCHR		0020000		/* character special */
1546565Smckusic #define	IFDIR		0040000		/* directory */
1556565Smckusic #define	IFBLK		0060000		/* block special */
1566565Smckusic #define	IFREG		0100000		/* regular */
1576565Smckusic #define	IFLNK		0120000		/* symbolic link */
1588990Sroot #define	IFSOCK		0140000		/* socket */
1598990Sroot 
1606565Smckusic #define	ISUID		04000		/* set user id on execution */
1616565Smckusic #define	ISGID		02000		/* set group id on execution */
1626565Smckusic #define	ISVTX		01000		/* save swapped text even after use */
1636565Smckusic #define	IREAD		0400		/* read, write, execute permissions */
1646565Smckusic #define	IWRITE		0200
1656565Smckusic #define	IEXEC		0100
1668467Sroot 
1678467Sroot #define	ILOCK(ip) { \
1688467Sroot 	while ((ip)->i_flag & ILOCKED) { \
1698467Sroot 		(ip)->i_flag |= IWANT; \
1708467Sroot 		sleep((caddr_t)(ip), PINOD); \
1718467Sroot 	} \
1728467Sroot 	(ip)->i_flag |= ILOCKED; \
1738467Sroot }
1748467Sroot 
1758467Sroot #define	IUNLOCK(ip) { \
1768467Sroot 	(ip)->i_flag &= ~ILOCKED; \
1778467Sroot 	if ((ip)->i_flag&IWANT) { \
1788467Sroot 		(ip)->i_flag &= ~IWANT; \
1798467Sroot 		wakeup((caddr_t)(ip)); \
1808467Sroot 	} \
1818467Sroot }
1828467Sroot 
1838467Sroot #define	IUPDAT(ip, t1, t2, waitfor) { \
18416057Skarels 	if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
1858467Sroot 		iupdat(ip, t1, t2, waitfor); \
1868467Sroot }
18716057Skarels 
18816057Skarels #define	ITIMES(ip, t1, t2) { \
18916057Skarels 	if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
19016057Skarels 		(ip)->i_flag |= IMOD; \
19116057Skarels 		if ((ip)->i_flag&IACC) \
19216057Skarels 			(ip)->i_atime = (t1)->tv_sec; \
19316057Skarels 		if ((ip)->i_flag&IUPD) \
19416057Skarels 			(ip)->i_mtime = (t2)->tv_sec; \
19516057Skarels 		if ((ip)->i_flag&ICHG) \
19616057Skarels 			(ip)->i_ctime = time.tv_sec; \
19716057Skarels 		(ip)->i_flag &= ~(IACC|IUPD|ICHG); \
19816057Skarels 	} \
19916057Skarels }
200