inode.h revision 30418
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1982, 1989, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes * (c) UNIX System Laboratories, Inc.
51541Srgrimes * All or some portions of this file are derived from material licensed
61541Srgrimes * to the University of California by American Telephone and Telegraph
71541Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with
81541Srgrimes * the permission of UNIX System Laboratories, Inc.
91541Srgrimes *
101541Srgrimes * Redistribution and use in source and binary forms, with or without
111541Srgrimes * modification, are permitted provided that the following conditions
121541Srgrimes * are met:
131541Srgrimes * 1. Redistributions of source code must retain the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer.
151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
161541Srgrimes *    notice, this list of conditions and the following disclaimer in the
171541Srgrimes *    documentation and/or other materials provided with the distribution.
181541Srgrimes * 3. All advertising materials mentioning features or use of this software
191541Srgrimes *    must display the following acknowledgement:
201541Srgrimes *	This product includes software developed by the University of
211541Srgrimes *	California, Berkeley and its contributors.
221541Srgrimes * 4. Neither the name of the University nor the names of its contributors
231541Srgrimes *    may be used to endorse or promote products derived from this software
241541Srgrimes *    without specific prior written permission.
251541Srgrimes *
261541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
271541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
291541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
301541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
311541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
321541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
331541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
341541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
351541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
361541Srgrimes * SUCH DAMAGE.
371541Srgrimes *
3822521Sdyson *	@(#)inode.h	8.9 (Berkeley) 5/14/95
3930418Sphk * $Id: inode.h,v 1.16 1997/07/13 15:40:31 bde Exp $
401541Srgrimes */
411541Srgrimes
422177Spaul#ifndef _UFS_UFS_INODE_H_
435247Sbde#define	_UFS_UFS_INODE_H_
442177Spaul
451541Srgrimes#include <ufs/ufs/dinode.h>
461541Srgrimes
471541Srgrimes/*
4824477Sbde * This must agree with the definition in <ufs/ufs/dir.h>.
4924477Sbde */
5024477Sbde#define	doff_t		int32_t
5124477Sbde
5224477Sbde/*
5322521Sdyson * The inode is used to describe each active (or recently active) file in the
5422521Sdyson * UFS filesystem. It is composed of two types of information. The first part
5522521Sdyson * is the information that is needed only while the file is active (such as
5622521Sdyson * the identity of the file and linkage to speed its lookup). The second part
5722521Sdyson * is the permanent meta-data associated with the file which is read in
5822521Sdyson * from the permanent dinode from long term storage when the file becomes
5922521Sdyson * active, and is put back when the file is no longer being used.
601541Srgrimes */
6122521Sdysonstruct inode {
6222521Sdyson	LIST_ENTRY(inode) i_hash;/* Hash chain. */
6322521Sdyson	struct	vnode  *i_vnode;/* Vnode associated with this inode. */
6422521Sdyson	struct	vnode  *i_devvp;/* Vnode for block I/O. */
6522521Sdyson	u_int32_t i_flag;	/* flags, see below */
6622521Sdyson	dev_t	  i_dev;	/* Device associated with the inode. */
6722521Sdyson	ino_t	  i_number;	/* The identity of the inode. */
681541Srgrimes
691541Srgrimes	union {			/* Associated filesystem. */
701541Srgrimes		struct	fs *fs;		/* FFS */
711541Srgrimes		struct	lfs *lfs;	/* LFS */
7212117Sdyson		struct	ext2_sb_info *e2fs;	/* EXT2FS */
731541Srgrimes	} inode_u;
741541Srgrimes#define	i_fs	inode_u.fs
751541Srgrimes#define	i_lfs	inode_u.lfs
7612117Sdyson#define	i_e2fs	inode_u.e2fs
7722521Sdyson	struct	 dquot *i_dquot[MAXQUOTAS]; /* Dquot structures. */
7822521Sdyson	u_quad_t i_modrev;	/* Revision level for NFS lease. */
7922521Sdyson	struct	 lockf *i_lockf;/* Head of byte-level lock list. */
8022521Sdyson	struct	 lock i_lock;	/* Inode lock. */
811541Srgrimes	/*
821541Srgrimes	 * Side effects; used during directory lookup.
831541Srgrimes	 */
8422521Sdyson	int32_t	  i_count;	/* Size of free slot in directory. */
8522521Sdyson	doff_t	  i_endoff;	/* End of useful stuff in directory. */
8622521Sdyson	doff_t	  i_diroff;	/* Offset in dir, where we found last entry. */
8722521Sdyson	doff_t	  i_offset;	/* Offset of free space in directory. */
8822521Sdyson	ino_t	  i_ino;	/* Inode number of found directory. */
8922521Sdyson	u_int32_t i_reclen;	/* Size of found directory entry. */
9027375Sbde	int	  i_spare[5];	/* XXX actually non-spare (for ext2fs). */
911541Srgrimes	/*
921541Srgrimes	 * The on-disk dinode itself.
931541Srgrimes	 */
941541Srgrimes	struct	dinode i_din;	/* 128 bytes of the on-disk dinode. */
951541Srgrimes};
961541Srgrimes
971541Srgrimes#define	i_atime		i_din.di_atime
9822521Sdyson#define	i_atimensec	i_din.di_atimensec
991541Srgrimes#define	i_blocks	i_din.di_blocks
1001541Srgrimes#define	i_ctime		i_din.di_ctime
10122521Sdyson#define	i_ctimensec	i_din.di_ctimensec
1021541Srgrimes#define	i_db		i_din.di_db
1031541Srgrimes#define	i_flags		i_din.di_flags
1041541Srgrimes#define	i_gen		i_din.di_gen
1051541Srgrimes#define	i_gid		i_din.di_gid
1061541Srgrimes#define	i_ib		i_din.di_ib
1071541Srgrimes#define	i_mode		i_din.di_mode
1081541Srgrimes#define	i_mtime		i_din.di_mtime
10922521Sdyson#define	i_mtimensec	i_din.di_mtimensec
1101541Srgrimes#define	i_nlink		i_din.di_nlink
1111541Srgrimes#define	i_rdev		i_din.di_rdev
1121541Srgrimes#define	i_shortlink	i_din.di_shortlink
1131541Srgrimes#define	i_size		i_din.di_size
1141541Srgrimes#define	i_uid		i_din.di_uid
1151541Srgrimes
1161541Srgrimes/* These flags are kept in i_flag. */
1171541Srgrimes#define	IN_ACCESS	0x0001		/* Access time update request. */
1181541Srgrimes#define	IN_CHANGE	0x0002		/* Inode change time update request. */
11922521Sdyson#define	IN_UPDATE	0x0004		/* Modification time update request. */
12022521Sdyson#define	IN_MODIFIED	0x0008		/* Inode has been modified. */
12122521Sdyson#define	IN_RENAME	0x0010		/* Inode is being renamed. */
12222521Sdyson#define	IN_SHLOCK	0x0020		/* File has shared lock. */
12322521Sdyson#define	IN_EXLOCK	0x0040		/* File has exclusive lock. */
12430418Sphk#define	IN_HASHED	0x0080		/* Inode is on hash list */
1251541Srgrimes
1261541Srgrimes#ifdef KERNEL
1271541Srgrimes/*
1281541Srgrimes * Structure used to pass around logical block paths generated by
1291541Srgrimes * ufs_getlbns and used by truncate and bmap code.
1301541Srgrimes */
1311541Srgrimesstruct indir {
13222521Sdyson	ufs_daddr_t in_lbn;		/* Logical block number. */
1331541Srgrimes	int	in_off;			/* Offset in buffer. */
1341541Srgrimes	int	in_exists;		/* Flag if the block exists. */
1351541Srgrimes};
1361541Srgrimes
1371541Srgrimes/* Convert between inode pointers and vnode pointers. */
1381541Srgrimes#define VTOI(vp)	((struct inode *)(vp)->v_data)
1391541Srgrimes#define ITOV(ip)	((ip)->i_vnode)
1401541Srgrimes
1415247Sbde/*
1425247Sbde * XXX this is too long to be a macro, and isn't used in any time-critical
1435247Sbde * place; in fact it is only used in ufs_vnops.c so it shouldn't be in a
1445247Sbde * header file.
1455247Sbde */
1461541Srgrimes#define	ITIMES(ip, t1, t2) {						\
1475247Sbde	long tv_sec = time.tv_sec;					\
1481541Srgrimes	if ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) {	\
1491541Srgrimes		(ip)->i_flag |= IN_MODIFIED;				\
1501541Srgrimes		if ((ip)->i_flag & IN_ACCESS)				\
15122521Sdyson			(ip)->i_atime					\
1525247Sbde			= ((t1) == &time ? tv_sec : (t1)->tv_sec);	\
1531541Srgrimes		if ((ip)->i_flag & IN_UPDATE) {				\
15422521Sdyson			(ip)->i_mtime					\
1555247Sbde			= ((t2) == &time ? tv_sec : (t2)->tv_sec);	\
1561541Srgrimes			(ip)->i_modrev++;				\
1571541Srgrimes		}							\
1581541Srgrimes		if ((ip)->i_flag & IN_CHANGE)				\
15922521Sdyson			(ip)->i_ctime = tv_sec;				\
1601541Srgrimes		(ip)->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE);	\
1611541Srgrimes	}								\
1621541Srgrimes}
1631541Srgrimes
1641541Srgrimes/* This overlays the fid structure (see mount.h). */
1651541Srgrimesstruct ufid {
16622521Sdyson	u_int16_t ufid_len;	/* Length of structure. */
16722521Sdyson	u_int16_t ufid_pad;	/* Force 32-bit alignment. */
16822521Sdyson	ino_t	  ufid_ino;	/* File number (ino). */
16922521Sdyson	int32_t	  ufid_gen;	/* Generation number. */
1701541Srgrimes};
1715247Sbde#endif /* KERNEL */
1722177Spaul
1735247Sbde#endif /* !_UFS_UFS_INODE_H_ */
174