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