xref: /original-bsd/sys/ufs/ffs/inode.h (revision 0bda13ee)
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.17 (Berkeley) 05/08/91
8  */
9 
10 #ifdef KERNEL
11 #include "../ufs/dinode.h"
12 #else
13 #include <ufs/dinode.h>
14 #endif
15 
16 /*
17  * The inode is used to describe each active (or recently active)
18  * file in the UFS filesystem. It is composed of two types of
19  * information. The first part is the information that is needed
20  * only while the file is active (such as the identity of the file
21  * and linkage to speed its lookup). The second part is the
22  * permannent meta-data associated with the file which is read
23  * in from the permanent dinode from long term storage when the
24  * file becomes active, and is put back when the file is no longer
25  * being used.
26  */
27 struct inode {
28 	struct	inode *i_chain[2]; /* hash chain, MUST be first */
29 	struct	vnode *i_vnode;	/* vnode associated with this inode */
30 	struct	vnode *i_devvp;	/* vnode for block I/O */
31 	u_long	i_flag;		/* see below */
32 	dev_t	i_dev;		/* device where inode resides */
33 	ino_t	i_number;	/* the identity of the inode */
34 	struct	fs *i_fs;	/* filesystem associated with this inode */
35 	struct	dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */
36 	struct	lockf *i_lockf;	/* head of byte-level lock list */
37 	long	i_diroff;	/* offset in dir, where we found last entry */
38 	off_t	i_endoff;	/* end of useful stuff in directory */
39 	long	i_spare0;
40 	long	i_spare1;
41 	struct	dinode i_din;	/* the on-disk dinode */
42 };
43 
44 #define	i_mode		i_din.di_mode
45 #define	i_nlink		i_din.di_nlink
46 #define	i_uid		i_din.di_uid
47 #define	i_gid		i_din.di_gid
48 #if BYTE_ORDER == LITTLE_ENDIAN || defined(tahoe) /* ugh! -- must be fixed */
49 #define	i_size		i_din.di_qsize.val[0]
50 #else /* BYTE_ORDER == BIG_ENDIAN */
51 #define	i_size		i_din.di_qsize.val[1]
52 #endif
53 #define	i_db		i_din.di_db
54 #define	i_ib		i_din.di_ib
55 #define	i_atime		i_din.di_atime
56 #define	i_mtime		i_din.di_mtime
57 #define	i_ctime		i_din.di_ctime
58 #define i_blocks	i_din.di_blocks
59 #define	i_rdev		i_din.di_db[0]
60 #define i_flags		i_din.di_flags
61 #define i_gen		i_din.di_gen
62 #define	i_forw		i_chain[0]
63 #define	i_back		i_chain[1]
64 
65 /* flags */
66 #define	ILOCKED		0x0001		/* inode is locked */
67 #define	IWANT		0x0002		/* some process waiting on lock */
68 #define	IRENAME		0x0004		/* inode is being renamed */
69 #define	IUPD		0x0010		/* file has been modified */
70 #define	IACC		0x0020		/* inode access time to be updated */
71 #define	ICHG		0x0040		/* inode has been changed */
72 #define	IMOD		0x0080		/* inode has been modified */
73 #define	ISHLOCK		0x0100		/* file has shared lock */
74 #define	IEXLOCK		0x0200		/* file has exclusive lock */
75 #define	ILWAIT		0x0400		/* someone waiting on file lock */
76 
77 #ifdef KERNEL
78 /*
79  * Convert between inode pointers and vnode pointers
80  */
81 #define VTOI(vp)	((struct inode *)(vp)->v_data)
82 #define ITOV(ip)	((ip)->i_vnode)
83 
84 /*
85  * Convert between vnode types and inode formats
86  */
87 extern enum vtype	iftovt_tab[];
88 extern int		vttoif_tab[];
89 #define IFTOVT(mode)	(iftovt_tab[((mode) & IFMT) >> 12])
90 #define VTTOIF(indx)	(vttoif_tab[(int)(indx)])
91 
92 #define MAKEIMODE(indx, mode)	(int)(VTTOIF(indx) | (mode))
93 
94 u_long	nextgennumber;		/* next generation number to assign */
95 
96 extern ino_t	dirpref();
97 
98 /*
99  * Lock and unlock inodes.
100  */
101 #ifdef notdef
102 #define	ILOCK(ip) { \
103 	while ((ip)->i_flag & ILOCKED) { \
104 		(ip)->i_flag |= IWANT; \
105 		(void) sleep((caddr_t)(ip), PINOD); \
106 	} \
107 	(ip)->i_flag |= ILOCKED; \
108 }
109 
110 #define	IUNLOCK(ip) { \
111 	(ip)->i_flag &= ~ILOCKED; \
112 	if ((ip)->i_flag&IWANT) { \
113 		(ip)->i_flag &= ~IWANT; \
114 		wakeup((caddr_t)(ip)); \
115 	} \
116 }
117 #else
118 #define ILOCK(ip)	ilock(ip)
119 #define IUNLOCK(ip)	iunlock(ip)
120 #endif
121 
122 #define	IUPDAT(ip, t1, t2, waitfor) { \
123 	if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
124 		(void) iupdat(ip, t1, t2, waitfor); \
125 }
126 
127 #define	ITIMES(ip, t1, t2) { \
128 	if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
129 		(ip)->i_flag |= IMOD; \
130 		if ((ip)->i_flag&IACC) \
131 			(ip)->i_atime = (t1)->tv_sec; \
132 		if ((ip)->i_flag&IUPD) \
133 			(ip)->i_mtime = (t2)->tv_sec; \
134 		if ((ip)->i_flag&ICHG) \
135 			(ip)->i_ctime = time.tv_sec; \
136 		(ip)->i_flag &= ~(IACC|IUPD|ICHG); \
137 	} \
138 }
139 
140 /*
141  * This overlays the fid sturcture (see mount.h)
142  */
143 struct ufid {
144 	u_short	ufid_len;	/* length of structure */
145 	u_short	ufid_pad;	/* force long alignment */
146 	ino_t	ufid_ino;	/* file number (ino) */
147 	long	ufid_gen;	/* generation number */
148 };
149 
150 /*
151  * Prototypes for UFS vnode operations
152  */
153 int ufs_lookup __P((struct vnode *vp, struct nameidata *ndp, struct proc *p));
154 int ufs_create __P((struct nameidata *ndp, struct vattr *vap, struct proc *p));
155 int ufs_mknod __P((struct nameidata *ndp, struct vattr *vap, struct ucred *cred,
156 	struct proc *p));
157 int ufs_open __P((struct vnode *vp, int mode, struct ucred *cred,
158 	struct proc *p));
159 int ufs_close __P((struct vnode *vp, int fflag, struct ucred *cred,
160 	struct proc *p));
161 int ufs_access __P((struct vnode *vp, int mode, struct ucred *cred,
162 	struct proc *p));
163 int ufs_getattr __P((struct vnode *vp, struct vattr *vap, struct ucred *cred,
164 	struct proc *p));
165 int ufs_setattr __P((struct vnode *vp, struct vattr *vap, struct ucred *cred,
166 	struct proc *p));
167 int ufs_read __P((struct vnode *vp, struct uio *uio, int ioflag,
168 	struct ucred *cred));
169 int ufs_write __P((struct vnode *vp, struct uio *uio, int ioflag,
170 	struct ucred *cred));
171 int ufs_ioctl __P((struct vnode *vp, int command, caddr_t data, int fflag,
172 	struct ucred *cred, struct proc *p));
173 int ufs_select __P((struct vnode *vp, int which, int fflags, struct ucred *cred,
174 	struct proc *p));
175 int ufs_mmap __P((struct vnode *vp, int fflags, struct ucred *cred,
176 	struct proc *p));
177 int ufs_fsync __P((struct vnode *vp, int fflags, struct ucred *cred,
178 	int waitfor, struct proc *p));
179 int ufs_seek __P((struct vnode *vp, off_t oldoff, off_t newoff,
180 	struct ucred *cred));
181 int ufs_remove __P((struct nameidata *ndp, struct proc *p));
182 int ufs_link __P((struct vnode *vp, struct nameidata *ndp, struct proc *p));
183 int ufs_rename __P((struct nameidata *fndp, struct nameidata *tdnp,
184 	struct proc *p));
185 int ufs_mkdir __P((struct nameidata *ndp, struct vattr *vap, struct proc *p));
186 int ufs_rmdir __P((struct nameidata *ndp, struct proc *p));
187 int ufs_symlink __P((struct nameidata *ndp, struct vattr *vap, char *target,
188 	struct proc *p));
189 int ufs_readdir __P((struct vnode *vp, struct uio *uio, struct ucred *cred,
190 	int *eofflagp));
191 int ufs_readlink __P((struct vnode *vp, struct uio *uio, struct ucred *cred));
192 int ufs_abortop __P((struct nameidata *ndp));
193 int ufs_inactive __P((struct vnode *vp, struct proc *p));
194 int ufs_reclaim __P((struct vnode *vp));
195 int ufs_lock __P((struct vnode *vp));
196 int ufs_unlock __P((struct vnode *vp));
197 int ufs_bmap __P((struct vnode *vp, daddr_t bn, struct vnode **vpp,
198 	daddr_t *bnp));
199 int ufs_strategy __P((struct buf *bp));
200 int ufs_print __P((struct vnode *vp));
201 int ufs_islocked __P((struct vnode *vp));
202 int ufs_advlock __P((struct vnode *vp, caddr_t id, int op, struct flock *fl,
203 	int flags));
204 #endif /* KERNEL */
205