1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1982, 1989, 1993
5 *	The Regents of the University of California.  All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 *    may be used to endorse or promote products derived from this software
22 *    without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 *	@(#)inode.h	8.9 (Berkeley) 5/14/95
37 * $FreeBSD$
38 */
39
40#ifndef _FS_EXT2FS_INODE_H_
41#define	_FS_EXT2FS_INODE_H_
42
43#include <sys/param.h>
44#include <sys/lock.h>
45#include <sys/mutex.h>
46#include <sys/queue.h>
47
48#include <fs/ext2fs/ext2_extents.h>
49
50/*
51 * This must agree with the definition in <ufs/ufs/dir.h>.
52 */
53#define	doff_t		int32_t
54
55#define	EXT2_NDADDR	12		/* Direct addresses in inode. */
56#define	EXT2_NIADDR	3		/* Indirect addresses in inode. */
57
58/*
59 * The size of physical and logical block numbers in EXT2FS.
60 */
61typedef uint32_t e2fs_daddr_t;
62typedef int64_t e2fs_lbn_t;
63typedef int64_t e4fs_daddr_t;
64
65/*
66 * The inode is used to describe each active (or recently active) file in the
67 * EXT2FS filesystem. It is composed of two types of information. The first
68 * part is the information that is needed only while the file is active (such
69 * as the identity of the file and linkage to speed its lookup). The second
70 * part is the permanent meta-data associated with the file which is read in
71 * from the permanent dinode from long term storage when the file becomes
72 * active, and is put back when the file is no longer being used.
73 */
74struct inode {
75	struct	vnode  *i_vnode;/* Vnode associated with this inode. */
76	struct	ext2mount *i_ump;
77	uint32_t i_flag;	/* flags, see below */
78	ino_t	  i_number;	/* The identity of the inode. */
79
80	struct	m_ext2fs *i_e2fs;	/* EXT2FS */
81	u_quad_t i_modrev;	/* Revision level for NFS lease. */
82	/*
83	 * Side effects; used during directory lookup.
84	 */
85	int32_t	 i_count;	/* Size of free slot in directory. */
86	doff_t	 i_endoff;	/* End of useful stuff in directory. */
87	doff_t	 i_diroff;	/* Offset in dir, where we found last entry. */
88	doff_t	 i_offset;	/* Offset of free space in directory. */
89
90	uint32_t i_block_group;
91	uint32_t i_next_alloc_block;
92	uint32_t i_next_alloc_goal;
93
94	/* Fields from struct dinode in UFS. */
95	uint16_t	i_mode;		/* IFMT, permissions; see below. */
96	int32_t		i_nlink;	/* File link count. */
97	uint32_t	i_uid;		/* File owner. */
98	uint32_t	i_gid;		/* File group. */
99	uint64_t	i_size;		/* File byte count. */
100	uint64_t	i_blocks;	/* Blocks actually held. */
101	int32_t		i_atime;	/* Last access time. */
102	int32_t		i_mtime;	/* Last modified time. */
103	int32_t		i_ctime;	/* Last inode change time. */
104	int32_t		i_birthtime;	/* Inode creation time. */
105	int32_t		i_mtimensec;	/* Last modified time. */
106	int32_t		i_atimensec;	/* Last access time. */
107	int32_t		i_ctimensec;	/* Last inode change time. */
108	int32_t		i_birthnsec;	/* Inode creation time. */
109	uint32_t	i_gen;		/* Generation number. */
110	uint64_t	i_facl;		/* EA block number. */
111	uint32_t	i_flags;	/* Status flags (chflags). */
112	union {
113		struct {
114			uint32_t i_db[EXT2_NDADDR]; /* Direct disk blocks. */
115			uint32_t i_ib[EXT2_NIADDR]; /* Indirect disk blocks. */
116		};
117		uint32_t i_data[EXT2_NDADDR + EXT2_NIADDR];
118	};
119
120	struct ext4_extent_cache i_ext_cache; /* cache for ext4 extent */
121};
122
123/*
124 * The di_db fields may be overlaid with other information for
125 * file types that do not have associated disk storage. Block
126 * and character devices overlay the first data block with their
127 * dev_t value. Short symbolic links place their path in the
128 * di_db area.
129 */
130#define	i_shortlink	i_db
131#define	i_rdev		i_db[0]
132
133/* File permissions. */
134#define	IEXEC		0000100		/* Executable. */
135#define	IWRITE		0000200		/* Writeable. */
136#define	IREAD		0000400		/* Readable. */
137#define	ISVTX		0001000		/* Sticky bit. */
138#define	ISGID		0002000		/* Set-gid. */
139#define	ISUID		0004000		/* Set-uid. */
140
141/* File types. */
142#define	IFMT		0170000		/* Mask of file type. */
143#define	IFIFO		0010000		/* Named pipe (fifo). */
144#define	IFCHR		0020000		/* Character device. */
145#define	IFDIR		0040000		/* Directory file. */
146#define	IFBLK		0060000		/* Block device. */
147#define	IFREG		0100000		/* Regular file. */
148#define	IFLNK		0120000		/* Symbolic link. */
149#define	IFSOCK		0140000		/* UNIX domain socket. */
150#define	IFWHT		0160000		/* Whiteout. */
151
152/* These flags are kept in i_flag. */
153#define	IN_ACCESS	0x0001		/* Access time update request. */
154#define	IN_CHANGE	0x0002		/* Inode change time update request. */
155#define	IN_UPDATE	0x0004		/* Modification time update request. */
156#define	IN_MODIFIED	0x0008		/* Inode has been modified. */
157#define	IN_RENAME	0x0010		/* Inode is being renamed. */
158#define	IN_HASHED	0x0020		/* Inode is on hash list */
159#define	IN_LAZYMOD	0x0040		/* Modified, but don't write yet. */
160#define	IN_SPACECOUNTED	0x0080		/* Blocks to be freed in free count. */
161#define	IN_LAZYACCESS   0x0100		/* Process IN_ACCESS after the
162					    suspension finished */
163
164/*
165 * These are translation flags for some attributes that Ext4
166 * passes as inode flags but that we cannot pass directly.
167 */
168#define	IN_E3INDEX	0x010000
169#define	IN_E4EXTENTS	0x020000
170
171#define i_devvp i_ump->um_devvp
172
173#ifdef _KERNEL
174/*
175 * Structure used to pass around logical block paths generated by
176 * ext2_getlbns and used by truncate and bmap code.
177 */
178struct indir {
179	e2fs_lbn_t in_lbn;		/* Logical block number. */
180	int	in_off;			/* Offset in buffer. */
181};
182
183/* Convert between inode pointers and vnode pointers. */
184#define VTOI(vp)	((struct inode *)(vp)->v_data)
185#define ITOV(ip)	((ip)->i_vnode)
186
187/* This overlays the fid structure (see mount.h). */
188struct ufid {
189	uint16_t ufid_len;		/* Length of structure. */
190	uint16_t ufid_pad;		/* Force 32-bit alignment. */
191	ino_t	ufid_ino;		/* File number (ino). */
192	uint32_t ufid_gen;		/* Generation number. */
193};
194#endif	/* _KERNEL */
195
196#endif	/* !_FS_EXT2FS_INODE_H_ */
197