xref: /original-bsd/sys/ufs/ffs/inode.h (revision 73949c1b)
1 /*
2  * Copyright (c) 1982, 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)inode.h	7.15 (Berkeley) 02/01/91
8  */
9 
10 #ifdef KERNEL
11 #include "../ufs/dinode.h"
12 #else
13 #include <ufs/dinode.h>
14 #endif
15 
16 /*
17  * The I node is the focus of all file activity in UNIX.
18  * There is a unique inode allocated for each active file,
19  * each current directory, each mounted-on file, text file, and the root.
20  * An inode is 'named' by its dev/inumber pair. (iget/iget.c)
21  * Data in `struct dinode' is read in from permanent inode on volume.
22  */
23 
24 struct inode {
25 	struct	inode *i_chain[2]; /* hash chain, MUST be first */
26 	struct	vnode *i_vnode;	/* vnode associated with this inode */
27 	struct	vnode *i_devvp;	/* vnode for block I/O */
28 	u_long	i_flag;		/* see below */
29 	dev_t	i_dev;		/* device where inode resides */
30 	ino_t	i_number;	/* i number, 1-to-1 with device address */
31 	struct	fs *i_fs;	/* file sys associated with this inode */
32 	struct	dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */
33 	struct	lockf *i_lockf;	/* Head of byte-level lock list */
34 	long	i_diroff;	/* offset in dir, where we found last entry */
35 	off_t	i_endoff;	/* end of useful stuff in directory */
36 	long	i_spare0;
37 	long	i_spare1;
38 	struct	dinode i_din;	/* the on-disk inode */
39 };
40 
41 #define	i_mode		i_din.di_mode
42 #define	i_nlink		i_din.di_nlink
43 #define	i_uid		i_din.di_uid
44 #define	i_gid		i_din.di_gid
45 #if BYTE_ORDER == LITTLE_ENDIAN || defined(tahoe) /* ugh! -- must be fixed */
46 #define	i_size		i_din.di_qsize.val[0]
47 #else /* BYTE_ORDER == BIG_ENDIAN */
48 #define	i_size		i_din.di_qsize.val[1]
49 #endif
50 #define	i_db		i_din.di_db
51 #define	i_ib		i_din.di_ib
52 #define	i_atime		i_din.di_atime
53 #define	i_mtime		i_din.di_mtime
54 #define	i_ctime		i_din.di_ctime
55 #define i_blocks	i_din.di_blocks
56 #define	i_rdev		i_din.di_db[0]
57 #define i_flags		i_din.di_flags
58 #define i_gen		i_din.di_gen
59 #define	i_forw		i_chain[0]
60 #define	i_back		i_chain[1]
61 
62 /* flags */
63 #define	ILOCKED		0x0001		/* inode is locked */
64 #define	IWANT		0x0002		/* some process waiting on lock */
65 #define	IRENAME		0x0004		/* inode is being renamed */
66 #define	IUPD		0x0010		/* file has been modified */
67 #define	IACC		0x0020		/* inode access time to be updated */
68 #define	ICHG		0x0040		/* inode has been changed */
69 #define	IMOD		0x0080		/* inode has been modified */
70 #define	ISHLOCK		0x0100		/* file has shared lock */
71 #define	IEXLOCK		0x0200		/* file has exclusive lock */
72 #define	ILWAIT		0x0400		/* someone waiting on file lock */
73 
74 #ifdef KERNEL
75 /*
76  * Convert between inode pointers and vnode pointers
77  */
78 #define VTOI(vp)	((struct inode *)(vp)->v_data)
79 #define ITOV(ip)	((ip)->i_vnode)
80 
81 /*
82  * Convert between vnode types and inode formats
83  */
84 extern enum vtype	iftovt_tab[];
85 extern int		vttoif_tab[];
86 #define IFTOVT(mode)	(iftovt_tab[((mode) & IFMT) >> 12])
87 #define VTTOIF(indx)	(vttoif_tab[(int)(indx)])
88 
89 #define MAKEIMODE(indx, mode)	(int)(VTTOIF(indx) | (mode))
90 
91 u_long	nextgennumber;		/* next generation number to assign */
92 
93 extern ino_t	dirpref();
94 
95 /*
96  * Lock and unlock inodes.
97  */
98 #ifdef notdef
99 #define	ILOCK(ip) { \
100 	while ((ip)->i_flag & ILOCKED) { \
101 		(ip)->i_flag |= IWANT; \
102 		(void) sleep((caddr_t)(ip), PINOD); \
103 	} \
104 	(ip)->i_flag |= ILOCKED; \
105 }
106 
107 #define	IUNLOCK(ip) { \
108 	(ip)->i_flag &= ~ILOCKED; \
109 	if ((ip)->i_flag&IWANT) { \
110 		(ip)->i_flag &= ~IWANT; \
111 		wakeup((caddr_t)(ip)); \
112 	} \
113 }
114 #else
115 #define ILOCK(ip)	ilock(ip)
116 #define IUNLOCK(ip)	iunlock(ip)
117 #endif
118 
119 #define	IUPDAT(ip, t1, t2, waitfor) { \
120 	if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
121 		(void) iupdat(ip, t1, t2, waitfor); \
122 }
123 
124 #define	ITIMES(ip, t1, t2) { \
125 	if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
126 		(ip)->i_flag |= IMOD; \
127 		if ((ip)->i_flag&IACC) \
128 			(ip)->i_atime = (t1)->tv_sec; \
129 		if ((ip)->i_flag&IUPD) \
130 			(ip)->i_mtime = (t2)->tv_sec; \
131 		if ((ip)->i_flag&ICHG) \
132 			(ip)->i_ctime = time.tv_sec; \
133 		(ip)->i_flag &= ~(IACC|IUPD|ICHG); \
134 	} \
135 }
136 
137 /*
138  * This overlays the fid sturcture (see mount.h)
139  */
140 struct ufid {
141 	u_short	ufid_len;	/* length of structure */
142 	u_short	ufid_pad;	/* force long alignment */
143 	ino_t	ufid_ino;	/* file number (ino) */
144 	long	ufid_gen;	/* generation number */
145 };
146 #endif
147