xref: /original-bsd/sys/ufs/ufs/inode.h (revision fac0c393)
1 /*
2  * Copyright (c) 1982, 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  * (c) UNIX System Laboratories, Inc.
5  * All or some portions of this file are derived from material licensed
6  * to the University of California by American Telephone and Telegraph
7  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8  * the permission of UNIX System Laboratories, Inc.
9  *
10  * %sccs.include.redist.c%
11  *
12  *	@(#)inode.h	8.6 (Berkeley) 03/21/95
13  */
14 
15 #include <ufs/ufs/dinode.h>
16 
17 /*
18  * Theoretically, directories can be more than 2Gb in length, however, in
19  * practice this seems unlikely. So, we define the type doff_t as a 32-bit
20  * quantity to keep down the cost of doing lookup on a 32-bit machine.
21  */
22 #define	doff_t	int32_t
23 
24 /*
25  * The inode is used to describe each active (or recently active) file in the
26  * UFS filesystem. It is composed of two types of information. The first part
27  * is the information that is needed only while the file is active (such as
28  * the identity of the file and linkage to speed its lookup). The second part
29  * is * the permanent meta-data associated with the file which is read in
30  * from the permanent dinode from long term storage when the file becomes
31  * active, and is put back when the file is no longer being used.
32  */
33 struct inode {
34 	LIST_ENTRY(inode) i_hash;/* Hash chain. */
35 	struct	vnode  *i_vnode;/* Vnode associated with this inode. */
36 	struct	vnode  *i_devvp;/* Vnode for block I/O. */
37 	u_int32_t i_flag;	/* flags, see below */
38 	dev_t	  i_dev;	/* Device associated with the inode. */
39 	ino_t	  i_number;	/* The identity of the inode. */
40 
41 	union {			/* Associated filesystem. */
42 		struct	fs *fs;		/* FFS */
43 		struct	lfs *lfs;	/* LFS */
44 	} inode_u;
45 #define	i_fs	inode_u.fs
46 #define	i_lfs	inode_u.lfs
47 
48 	struct	 dquot *i_dquot[MAXQUOTAS]; /* Dquot structures. */
49 	u_quad_t i_modrev;	/* Revision level for NFS lease. */
50 	struct	 lockf *i_lockf;/* Head of byte-level lock list. */
51 	pid_t	 i_lockholder;	/* DEBUG: holder of inode lock. */
52 	pid_t	 i_lockwaiter;	/* DEBUG: latest blocked for inode lock. */
53 	/*
54 	 * Side effects; used during directory lookup.
55 	 */
56 	int32_t	  i_count;	/* Size of free slot in directory. */
57 	doff_t	  i_endoff;	/* End of useful stuff in directory. */
58 	doff_t	  i_diroff;	/* Offset in dir, where we found last entry. */
59 	doff_t	  i_offset;	/* Offset of free space in directory. */
60 	ino_t	  i_ino;	/* Inode number of found directory. */
61 	u_int32_t i_reclen;	/* Size of found directory entry. */
62 	/*
63 	 * The on-disk dinode itself.
64 	 */
65 	struct	dinode i_din;	/* 128 bytes of the on-disk dinode. */
66 };
67 
68 #define	i_atime		i_din.di_atime
69 #define	i_atimensec	i_din.di_atimensec
70 #define	i_blocks	i_din.di_blocks
71 #define	i_ctime		i_din.di_ctime
72 #define	i_ctimensec	i_din.di_ctimensec
73 #define	i_db		i_din.di_db
74 #define	i_flags		i_din.di_flags
75 #define	i_gen		i_din.di_gen
76 #define	i_gid		i_din.di_gid
77 #define	i_ib		i_din.di_ib
78 #define	i_mode		i_din.di_mode
79 #define	i_mtime		i_din.di_mtime
80 #define	i_mtimensec	i_din.di_mtimensec
81 #define	i_nlink		i_din.di_nlink
82 #define	i_rdev		i_din.di_rdev
83 #define	i_shortlink	i_din.di_shortlink
84 #define	i_size		i_din.di_size
85 #define	i_uid		i_din.di_uid
86 
87 /* These flags are kept in i_flag. */
88 #define	IN_ACCESS	0x0001		/* Access time update request. */
89 #define	IN_CHANGE	0x0002		/* Inode change time update request. */
90 #define	IN_EXLOCK	0x0004		/* File has exclusive lock. */
91 #define	IN_LOCKED	0x0008		/* Inode lock. */
92 #define	IN_LWAIT	0x0010		/* Process waiting on file lock. */
93 #define	IN_MODIFIED	0x0020		/* Inode has been modified. */
94 #define	IN_RENAME	0x0040		/* Inode is being renamed. */
95 #define	IN_SHLOCK	0x0080		/* File has shared lock. */
96 #define	IN_UPDATE	0x0100		/* Modification time update request. */
97 #define	IN_WANTED	0x0200		/* Inode is wanted by a process. */
98 
99 #ifdef KERNEL
100 /*
101  * Structure used to pass around logical block paths generated by
102  * ufs_getlbns and used by truncate and bmap code.
103  */
104 struct indir {
105 	ufs_daddr_t in_lbn;		/* Logical block number. */
106 	int	in_off;			/* Offset in buffer. */
107 	int	in_exists;		/* Flag if the block exists. */
108 };
109 
110 /* Convert between inode pointers and vnode pointers. */
111 #define VTOI(vp)	((struct inode *)(vp)->v_data)
112 #define ITOV(ip)	((ip)->i_vnode)
113 
114 #define	ITIMES(ip, t1, t2) {						\
115 	if ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) {	\
116 		(ip)->i_flag |= IN_MODIFIED;				\
117 		if ((ip)->i_flag & IN_ACCESS)				\
118 			(ip)->i_atime = (t1)->tv_sec;			\
119 		if ((ip)->i_flag & IN_UPDATE) {				\
120 			(ip)->i_mtime = (t2)->tv_sec;			\
121 			(ip)->i_modrev++;				\
122 		}							\
123 		if ((ip)->i_flag & IN_CHANGE)				\
124 			(ip)->i_ctime = time.tv_sec;			\
125 		(ip)->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE);	\
126 	}								\
127 }
128 
129 /* This overlays the fid structure (see mount.h). */
130 struct ufid {
131 	u_int16_t ufid_len;	/* Length of structure. */
132 	u_int16_t ufid_pad;	/* Force 32-bit alignment. */
133 	ino_t	  ufid_ino;	/* File number (ino). */
134 	int32_t	  ufid_gen;	/* Generation number. */
135 };
136 #endif /* KERNEL */
137