inode.h revision 30418
1285809Sscottl/*
2285809Sscottl * Copyright (c) 1982, 1989, 1993
3285809Sscottl *	The Regents of the University of California.  All rights reserved.
4285809Sscottl * (c) UNIX System Laboratories, Inc.
5285809Sscottl * All or some portions of this file are derived from material licensed
6285809Sscottl * to the University of California by American Telephone and Telegraph
7285809Sscottl * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8285809Sscottl * the permission of UNIX System Laboratories, Inc.
9285809Sscottl *
10285809Sscottl * Redistribution and use in source and binary forms, with or without
11285809Sscottl * modification, are permitted provided that the following conditions
12285809Sscottl * are met:
13285809Sscottl * 1. Redistributions of source code must retain the above copyright
14285809Sscottl *    notice, this list of conditions and the following disclaimer.
15285809Sscottl * 2. Redistributions in binary form must reproduce the above copyright
16285809Sscottl *    notice, this list of conditions and the following disclaimer in the
17285809Sscottl *    documentation and/or other materials provided with the distribution.
18285809Sscottl * 3. All advertising materials mentioning features or use of this software
19285809Sscottl *    must display the following acknowledgement:
20285809Sscottl *	This product includes software developed by the University of
21285809Sscottl *	California, Berkeley and its contributors.
22285809Sscottl * 4. Neither the name of the University nor the names of its contributors
23285809Sscottl *    may be used to endorse or promote products derived from this software
24285809Sscottl *    without specific prior written permission.
25285809Sscottl *
26285809Sscottl * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27285809Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28285809Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29285809Sscottl * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30285809Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31285809Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32285809Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33285809Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34285809Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35285809Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36285809Sscottl * SUCH DAMAGE.
37285809Sscottl *
38285809Sscottl *	@(#)inode.h	8.9 (Berkeley) 5/14/95
39285809Sscottl * $Id: inode.h,v 1.16 1997/07/13 15:40:31 bde Exp $
40285809Sscottl */
41285809Sscottl
42285809Sscottl#ifndef _UFS_UFS_INODE_H_
43285809Sscottl#define	_UFS_UFS_INODE_H_
44285809Sscottl
45285809Sscottl#include <ufs/ufs/dinode.h>
46285809Sscottl
47285809Sscottl/*
48285809Sscottl * This must agree with the definition in <ufs/ufs/dir.h>.
49285809Sscottl */
50285809Sscottl#define	doff_t		int32_t
51285809Sscottl
52285809Sscottl/*
53285809Sscottl * The inode is used to describe each active (or recently active) file in the
54285809Sscottl * UFS filesystem. It is composed of two types of information. The first part
55285809Sscottl * is the information that is needed only while the file is active (such as
56285809Sscottl * the identity of the file and linkage to speed its lookup). The second part
57285809Sscottl * is the permanent meta-data associated with the file which is read in
58285809Sscottl * from the permanent dinode from long term storage when the file becomes
59285809Sscottl * active, and is put back when the file is no longer being used.
60285809Sscottl */
61285809Sscottlstruct inode {
62285809Sscottl	LIST_ENTRY(inode) i_hash;/* Hash chain. */
63285809Sscottl	struct	vnode  *i_vnode;/* Vnode associated with this inode. */
64285809Sscottl	struct	vnode  *i_devvp;/* Vnode for block I/O. */
65285809Sscottl	u_int32_t i_flag;	/* flags, see below */
66285809Sscottl	dev_t	  i_dev;	/* Device associated with the inode. */
67285809Sscottl	ino_t	  i_number;	/* The identity of the inode. */
68285809Sscottl
69285809Sscottl	union {			/* Associated filesystem. */
70285809Sscottl		struct	fs *fs;		/* FFS */
71285809Sscottl		struct	lfs *lfs;	/* LFS */
72285809Sscottl		struct	ext2_sb_info *e2fs;	/* EXT2FS */
73285809Sscottl	} inode_u;
74285809Sscottl#define	i_fs	inode_u.fs
75285809Sscottl#define	i_lfs	inode_u.lfs
76285809Sscottl#define	i_e2fs	inode_u.e2fs
77285809Sscottl	struct	 dquot *i_dquot[MAXQUOTAS]; /* Dquot structures. */
78285809Sscottl	u_quad_t i_modrev;	/* Revision level for NFS lease. */
79285809Sscottl	struct	 lockf *i_lockf;/* Head of byte-level lock list. */
80285809Sscottl	struct	 lock i_lock;	/* Inode lock. */
81285809Sscottl	/*
82285809Sscottl	 * Side effects; used during directory lookup.
83285809Sscottl	 */
84285809Sscottl	int32_t	  i_count;	/* Size of free slot in directory. */
85285809Sscottl	doff_t	  i_endoff;	/* End of useful stuff in directory. */
86285809Sscottl	doff_t	  i_diroff;	/* Offset in dir, where we found last entry. */
87285809Sscottl	doff_t	  i_offset;	/* Offset of free space in directory. */
88285809Sscottl	ino_t	  i_ino;	/* Inode number of found directory. */
89285809Sscottl	u_int32_t i_reclen;	/* Size of found directory entry. */
90285809Sscottl	int	  i_spare[5];	/* XXX actually non-spare (for ext2fs). */
91285809Sscottl	/*
92285809Sscottl	 * The on-disk dinode itself.
93285809Sscottl	 */
94285809Sscottl	struct	dinode i_din;	/* 128 bytes of the on-disk dinode. */
95285809Sscottl};
96285809Sscottl
97285809Sscottl#define	i_atime		i_din.di_atime
98285809Sscottl#define	i_atimensec	i_din.di_atimensec
99285809Sscottl#define	i_blocks	i_din.di_blocks
100285809Sscottl#define	i_ctime		i_din.di_ctime
101285809Sscottl#define	i_ctimensec	i_din.di_ctimensec
102285809Sscottl#define	i_db		i_din.di_db
103285809Sscottl#define	i_flags		i_din.di_flags
104285809Sscottl#define	i_gen		i_din.di_gen
105285809Sscottl#define	i_gid		i_din.di_gid
106285809Sscottl#define	i_ib		i_din.di_ib
107285809Sscottl#define	i_mode		i_din.di_mode
108285809Sscottl#define	i_mtime		i_din.di_mtime
109285809Sscottl#define	i_mtimensec	i_din.di_mtimensec
110285809Sscottl#define	i_nlink		i_din.di_nlink
111285809Sscottl#define	i_rdev		i_din.di_rdev
112285809Sscottl#define	i_shortlink	i_din.di_shortlink
113285809Sscottl#define	i_size		i_din.di_size
114285809Sscottl#define	i_uid		i_din.di_uid
115285809Sscottl
116285809Sscottl/* These flags are kept in i_flag. */
117285809Sscottl#define	IN_ACCESS	0x0001		/* Access time update request. */
118285809Sscottl#define	IN_CHANGE	0x0002		/* Inode change time update request. */
119285809Sscottl#define	IN_UPDATE	0x0004		/* Modification time update request. */
120285809Sscottl#define	IN_MODIFIED	0x0008		/* Inode has been modified. */
121285809Sscottl#define	IN_RENAME	0x0010		/* Inode is being renamed. */
122285809Sscottl#define	IN_SHLOCK	0x0020		/* File has shared lock. */
123285809Sscottl#define	IN_EXLOCK	0x0040		/* File has exclusive lock. */
124285809Sscottl#define	IN_HASHED	0x0080		/* Inode is on hash list */
125285809Sscottl
126285809Sscottl#ifdef KERNEL
127285809Sscottl/*
128285809Sscottl * Structure used to pass around logical block paths generated by
129285809Sscottl * ufs_getlbns and used by truncate and bmap code.
130285809Sscottl */
131285809Sscottlstruct indir {
132285809Sscottl	ufs_daddr_t in_lbn;		/* Logical block number. */
133285809Sscottl	int	in_off;			/* Offset in buffer. */
134285809Sscottl	int	in_exists;		/* Flag if the block exists. */
135285809Sscottl};
136285809Sscottl
137285809Sscottl/* Convert between inode pointers and vnode pointers. */
138285809Sscottl#define VTOI(vp)	((struct inode *)(vp)->v_data)
139285809Sscottl#define ITOV(ip)	((ip)->i_vnode)
140285809Sscottl
141285809Sscottl/*
142285809Sscottl * XXX this is too long to be a macro, and isn't used in any time-critical
143285809Sscottl * place; in fact it is only used in ufs_vnops.c so it shouldn't be in a
144285809Sscottl * header file.
145285809Sscottl */
146285809Sscottl#define	ITIMES(ip, t1, t2) {						\
147285809Sscottl	long tv_sec = time.tv_sec;					\
148285809Sscottl	if ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) {	\
149285809Sscottl		(ip)->i_flag |= IN_MODIFIED;				\
150285809Sscottl		if ((ip)->i_flag & IN_ACCESS)				\
151285809Sscottl			(ip)->i_atime					\
152285809Sscottl			= ((t1) == &time ? tv_sec : (t1)->tv_sec);	\
153285809Sscottl		if ((ip)->i_flag & IN_UPDATE) {				\
154285809Sscottl			(ip)->i_mtime					\
155285809Sscottl			= ((t2) == &time ? tv_sec : (t2)->tv_sec);	\
156285809Sscottl			(ip)->i_modrev++;				\
157285809Sscottl		}							\
158285809Sscottl		if ((ip)->i_flag & IN_CHANGE)				\
159285809Sscottl			(ip)->i_ctime = tv_sec;				\
160285809Sscottl		(ip)->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE);	\
161285809Sscottl	}								\
162285809Sscottl}
163285809Sscottl
164285809Sscottl/* This overlays the fid structure (see mount.h). */
165285809Sscottlstruct ufid {
166285809Sscottl	u_int16_t ufid_len;	/* Length of structure. */
167285809Sscottl	u_int16_t ufid_pad;	/* Force 32-bit alignment. */
168285809Sscottl	ino_t	  ufid_ino;	/* File number (ino). */
169285809Sscottl	int32_t	  ufid_gen;	/* Generation number. */
170285809Sscottl};
171285809Sscottl#endif /* KERNEL */
172285809Sscottl
173285809Sscottl#endif /* !_UFS_UFS_INODE_H_ */
174285809Sscottl