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