1139778Simp/*-
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 * 4. Neither the name of the University nor the names of its contributors
191541Srgrimes *    may be used to endorse or promote products derived from this software
201541Srgrimes *    without specific prior written permission.
211541Srgrimes *
221541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321541Srgrimes * SUCH DAMAGE.
331541Srgrimes *
3422521Sdyson *	@(#)inode.h	8.9 (Berkeley) 5/14/95
3550477Speter * $FreeBSD: releng/11.0/sys/fs/ext2fs/inode.h 294655 2016-01-24 04:30:30Z pfg $
361541Srgrimes */
371541Srgrimes
38202283Slulf#ifndef _FS_EXT2FS_INODE_H_
39202283Slulf#define	_FS_EXT2FS_INODE_H_
402177Spaul
41254260Spfg#include <sys/param.h>
4231557Sjkh#include <sys/lock.h>
43254260Spfg#include <sys/mutex.h>
4444512Sbde#include <sys/queue.h>
451541Srgrimes
46254260Spfg#include <fs/ext2fs/ext2_extents.h>
47254260Spfg
4834266Sjulian/*
4924477Sbde * This must agree with the definition in <ufs/ufs/dir.h>.
5024477Sbde */
5124477Sbde#define	doff_t		int32_t
5224477Sbde
53251809Spfg#define	NDADDR	12			/* Direct addresses in inode. */
54251809Spfg#define	NIADDR	3			/* Indirect addresses in inode. */
55251809Spfg
5624477Sbde/*
57254283Spfg * The size of physical and logical block numbers in EXT2FS.
58252103Spfg */
59254283Spfgtypedef	uint32_t e2fs_daddr_t;
60254283Spfgtypedef	int64_t	e2fs_lbn_t;
61254283Spfgtypedef	int64_t e4fs_daddr_t;
62252103Spfg
63252103Spfg/*
6422521Sdyson * The inode is used to describe each active (or recently active) file in the
6596596Siedowse * EXT2FS filesystem. It is composed of two types of information. The first
6696596Siedowse * part is the information that is needed only while the file is active (such
6796596Siedowse * as the identity of the file and linkage to speed its lookup). The second
6896596Siedowse * part is the permanent meta-data associated with the file which is read in
6922521Sdyson * from the permanent dinode from long term storage when the file becomes
7022521Sdyson * active, and is put back when the file is no longer being used.
711541Srgrimes */
7222521Sdysonstruct inode {
7322521Sdyson	struct	vnode  *i_vnode;/* Vnode associated with this inode. */
74202283Slulf	struct	ext2mount *i_ump;
75221126Sjhb	uint32_t i_flag;	/* flags, see below */
7622521Sdyson	ino_t	  i_number;	/* The identity of the inode. */
771541Srgrimes
78202283Slulf	struct	m_ext2fs *i_e2fs;	/* EXT2FS */
7922521Sdyson	u_quad_t i_modrev;	/* Revision level for NFS lease. */
801541Srgrimes	/*
811541Srgrimes	 * Side effects; used during directory lookup.
821541Srgrimes	 */
83221126Sjhb	int32_t	 i_count;	/* Size of free slot in directory. */
84221126Sjhb	doff_t	 i_endoff;	/* End of useful stuff in directory. */
85221126Sjhb	doff_t	 i_diroff;	/* Offset in dir, where we found last entry. */
86221126Sjhb	doff_t	 i_offset;	/* Offset of free space in directory. */
8779561Siedowse
88221126Sjhb	uint32_t i_block_group;
89221126Sjhb	uint32_t i_next_alloc_block;
90221126Sjhb	uint32_t i_next_alloc_goal;
9196596Siedowse
9296596Siedowse	/* Fields from struct dinode in UFS. */
93221126Sjhb	uint16_t	i_mode;		/* IFMT, permissions; see below. */
9496596Siedowse	int16_t		i_nlink;	/* File link count. */
95254260Spfg	uint32_t	i_uid;		/* File owner. */
96254260Spfg	uint32_t	i_gid;		/* File group. */
97221126Sjhb	uint64_t	i_size;		/* File byte count. */
98254260Spfg	uint64_t	i_blocks;	/* Blocks actually held. */
9996596Siedowse	int32_t		i_atime;	/* Last access time. */
10096596Siedowse	int32_t		i_mtime;	/* Last modified time. */
101231168Spfg	int32_t		i_ctime;	/* Last inode change time. */
102231168Spfg	int32_t		i_birthtime;	/* Inode creation time. */
10396596Siedowse	int32_t		i_mtimensec;	/* Last modified time. */
104231168Spfg	int32_t		i_atimensec;	/* Last access time. */
10596596Siedowse	int32_t		i_ctimensec;	/* Last inode change time. */
106231168Spfg	int32_t		i_birthnsec;	/* Inode creation time. */
107254260Spfg	uint32_t	i_gen;		/* Generation number. */
108254260Spfg	uint32_t	i_flags;	/* Status flags (chflags). */
109245820Spfg	uint32_t	i_db[NDADDR];	/* Direct disk blocks. */
110245820Spfg	uint32_t	i_ib[NIADDR];	/* Indirect disk blocks. */
111254260Spfg
112254260Spfg	struct ext4_extent_cache i_ext_cache; /* cache for ext4 extent */
1131541Srgrimes};
1141541Srgrimes
11596596Siedowse/*
11696596Siedowse * The di_db fields may be overlaid with other information for
11796596Siedowse * file types that do not have associated disk storage. Block
11896596Siedowse * and character devices overlay the first data block with their
119130763Sbde * dev_t value. Short symbolic links place their path in the
12096596Siedowse * di_db area.
12196596Siedowse */
12296596Siedowse#define	i_shortlink	i_db
12396596Siedowse#define	i_rdev		i_db[0]
1241541Srgrimes
12596596Siedowse/* File permissions. */
12696596Siedowse#define	IEXEC		0000100		/* Executable. */
12796596Siedowse#define	IWRITE		0000200		/* Writeable. */
12896596Siedowse#define	IREAD		0000400		/* Readable. */
12996596Siedowse#define	ISVTX		0001000		/* Sticky bit. */
13096596Siedowse#define	ISGID		0002000		/* Set-gid. */
13196596Siedowse#define	ISUID		0004000		/* Set-uid. */
13296596Siedowse
13396596Siedowse/* File types. */
13496596Siedowse#define	IFMT		0170000		/* Mask of file type. */
13596596Siedowse#define	IFIFO		0010000		/* Named pipe (fifo). */
13696596Siedowse#define	IFCHR		0020000		/* Character device. */
13796596Siedowse#define	IFDIR		0040000		/* Directory file. */
13896596Siedowse#define	IFBLK		0060000		/* Block device. */
13996596Siedowse#define	IFREG		0100000		/* Regular file. */
14096596Siedowse#define	IFLNK		0120000		/* Symbolic link. */
14196596Siedowse#define	IFSOCK		0140000		/* UNIX domain socket. */
14296596Siedowse#define	IFWHT		0160000		/* Whiteout. */
14396596Siedowse
1441541Srgrimes/* These flags are kept in i_flag. */
1451541Srgrimes#define	IN_ACCESS	0x0001		/* Access time update request. */
1461541Srgrimes#define	IN_CHANGE	0x0002		/* Inode change time update request. */
14722521Sdyson#define	IN_UPDATE	0x0004		/* Modification time update request. */
14822521Sdyson#define	IN_MODIFIED	0x0008		/* Inode has been modified. */
14922521Sdyson#define	IN_RENAME	0x0010		/* Inode is being renamed. */
15076357Smckusick#define	IN_HASHED	0x0020		/* Inode is on hash list */
15176357Smckusick#define	IN_LAZYMOD	0x0040		/* Modified, but don't write yet. */
15276357Smckusick#define	IN_SPACECOUNTED	0x0080		/* Blocks to be freed in free count. */
153262623Spfg#define	IN_LAZYACCESS   0x0100		/* Process IN_ACCESS after the
154202283Slulf					    suspension finished */
155217582Sjhb
156260988Spfg/*
157260988Spfg * These are translation flags for some attributes that Ext4
158260988Spfg * passes as inode flags but that we cannot pass directly.
159260988Spfg */
160294655Spfg#define	IN_E3INDEX	0x010000
161261235Spfg#define	IN_E4EXTENTS	0x020000
162260988Spfg
163217582Sjhb#define i_devvp i_ump->um_devvp
164217582Sjhb
16555206Speter#ifdef _KERNEL
1661541Srgrimes/*
1671541Srgrimes * Structure used to pass around logical block paths generated by
16896877Siedowse * ext2_getlbns and used by truncate and bmap code.
1691541Srgrimes */
1701541Srgrimesstruct indir {
171252103Spfg	e2fs_lbn_t in_lbn;		/* Logical block number. */
1721541Srgrimes	int	in_off;			/* Offset in buffer. */
1731541Srgrimes};
1741541Srgrimes
1751541Srgrimes/* Convert between inode pointers and vnode pointers. */
1761541Srgrimes#define VTOI(vp)	((struct inode *)(vp)->v_data)
1771541Srgrimes#define ITOV(ip)	((ip)->i_vnode)
1781541Srgrimes
1791541Srgrimes/* This overlays the fid structure (see mount.h). */
1801541Srgrimesstruct ufid {
181221126Sjhb	uint16_t ufid_len;	/* Length of structure. */
182221126Sjhb	uint16_t ufid_pad;	/* Force 32-bit alignment. */
183221126Sjhb	ino_t	 ufid_ino;	/* File number (ino). */
184245820Spfg	uint32_t ufid_gen;	/* Generation number. */
1851541Srgrimes};
18655206Speter#endif /* _KERNEL */
1872177Spaul
188202283Slulf#endif /* !_FS_EXT2FS_INODE_H_ */
189