1*84d9c625SLionel Sambuc /* $NetBSD: ext2fs_dinode.h,v 1.26 2013/01/22 09:39:15 dholland Exp $ */ 2d65f6f70SBen Gras 3d65f6f70SBen Gras /* 4d65f6f70SBen Gras * Copyright (c) 1982, 1989, 1993 5d65f6f70SBen Gras * The Regents of the University of California. All rights reserved. 6d65f6f70SBen Gras * (c) UNIX System Laboratories, Inc. 7d65f6f70SBen Gras * All or some portions of this file are derived from material licensed 8d65f6f70SBen Gras * to the University of California by American Telephone and Telegraph 9d65f6f70SBen Gras * Co. or Unix System Laboratories, Inc. and are reproduced herein with 10d65f6f70SBen Gras * the permission of UNIX System Laboratories, Inc. 11d65f6f70SBen Gras * 12d65f6f70SBen Gras * Redistribution and use in source and binary forms, with or without 13d65f6f70SBen Gras * modification, are permitted provided that the following conditions 14d65f6f70SBen Gras * are met: 15d65f6f70SBen Gras * 1. Redistributions of source code must retain the above copyright 16d65f6f70SBen Gras * notice, this list of conditions and the following disclaimer. 17d65f6f70SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 18d65f6f70SBen Gras * notice, this list of conditions and the following disclaimer in the 19d65f6f70SBen Gras * documentation and/or other materials provided with the distribution. 20d65f6f70SBen Gras * 3. Neither the name of the University nor the names of its contributors 21d65f6f70SBen Gras * may be used to endorse or promote products derived from this software 22d65f6f70SBen Gras * without specific prior written permission. 23d65f6f70SBen Gras * 24d65f6f70SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25d65f6f70SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26d65f6f70SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27d65f6f70SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28d65f6f70SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29d65f6f70SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30d65f6f70SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31d65f6f70SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32d65f6f70SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33d65f6f70SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34d65f6f70SBen Gras * SUCH DAMAGE. 35d65f6f70SBen Gras * 36d65f6f70SBen Gras * @(#)dinode.h 8.6 (Berkeley) 9/13/94 37d65f6f70SBen Gras * Modified for ext2fs by Manuel Bouyer. 38d65f6f70SBen Gras */ 39d65f6f70SBen Gras 40d65f6f70SBen Gras /* 41d65f6f70SBen Gras * Copyright (c) 1997 Manuel Bouyer. 42d65f6f70SBen Gras * 43d65f6f70SBen Gras * Redistribution and use in source and binary forms, with or without 44d65f6f70SBen Gras * modification, are permitted provided that the following conditions 45d65f6f70SBen Gras * are met: 46d65f6f70SBen Gras * 1. Redistributions of source code must retain the above copyright 47d65f6f70SBen Gras * notice, this list of conditions and the following disclaimer. 48d65f6f70SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 49d65f6f70SBen Gras * notice, this list of conditions and the following disclaimer in the 50d65f6f70SBen Gras * documentation and/or other materials provided with the distribution. 51d65f6f70SBen Gras * 52d65f6f70SBen Gras * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 53d65f6f70SBen Gras * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 54d65f6f70SBen Gras * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 55d65f6f70SBen Gras * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 56d65f6f70SBen Gras * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 57d65f6f70SBen Gras * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 58d65f6f70SBen Gras * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 59d65f6f70SBen Gras * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 60d65f6f70SBen Gras * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 61d65f6f70SBen Gras * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62d65f6f70SBen Gras * 63d65f6f70SBen Gras * @(#)dinode.h 8.6 (Berkeley) 9/13/94 64d65f6f70SBen Gras * Modified for ext2fs by Manuel Bouyer. 65d65f6f70SBen Gras */ 66d65f6f70SBen Gras 67d65f6f70SBen Gras #ifndef _UFS_EXT2FS_EXT2FS_DINODE_H_ 68d65f6f70SBen Gras #define _UFS_EXT2FS_EXT2FS_DINODE_H_ 69d65f6f70SBen Gras 70d65f6f70SBen Gras #include <sys/stat.h> 71d65f6f70SBen Gras 72d65f6f70SBen Gras /* 73d65f6f70SBen Gras * The root inode is the root of the file system. Inode 0 can't be used for 74d65f6f70SBen Gras * normal purposes and bad blocks are normally linked to inode 1, thus 75d65f6f70SBen Gras * the root inode is 2. 76d65f6f70SBen Gras * Inode 3 to 10 are reserved in ext2fs. 77d65f6f70SBen Gras */ 78d65f6f70SBen Gras #define EXT2_BADBLKINO ((ino_t)1) 79d65f6f70SBen Gras #define EXT2_ROOTINO ((ino_t)2) 80d65f6f70SBen Gras #define EXT2_ACLIDXINO ((ino_t)3) 81d65f6f70SBen Gras #define EXT2_ACLDATAINO ((ino_t)4) 82d65f6f70SBen Gras #define EXT2_BOOTLOADERINO ((ino_t)5) 83d65f6f70SBen Gras #define EXT2_UNDELDIRINO ((ino_t)6) 84d65f6f70SBen Gras #define EXT2_RESIZEINO ((ino_t)7) 85d65f6f70SBen Gras #define EXT2_JOURNALINO ((ino_t)8) 86d65f6f70SBen Gras #define EXT2_FIRSTINO ((ino_t)11) 87d65f6f70SBen Gras 88d65f6f70SBen Gras /* 89d65f6f70SBen Gras * A dinode contains all the meta-data associated with a UFS file. 90d65f6f70SBen Gras * This structure defines the on-disk format of a dinode. Since 91d65f6f70SBen Gras * this structure describes an on-disk structure, all its fields 92d65f6f70SBen Gras * are defined by types with precise widths. 93d65f6f70SBen Gras */ 94d65f6f70SBen Gras 95*84d9c625SLionel Sambuc /* 96*84d9c625SLionel Sambuc * XXX these are the same values as UFS_NDADDR/UFS_NIADDR and it is 97*84d9c625SLionel Sambuc * far from clear that there isn't code that relies on them being the 98*84d9c625SLionel Sambuc * same. 99*84d9c625SLionel Sambuc */ 100*84d9c625SLionel Sambuc #define EXT2FS_NDADDR 12 /* Direct addresses in inode. */ 101*84d9c625SLionel Sambuc #define EXT2FS_NIADDR 3 /* Indirect addresses in inode. */ 102d65f6f70SBen Gras 103*84d9c625SLionel Sambuc #define EXT2_MAXSYMLINKLEN ((EXT2FS_NDADDR+EXT2FS_NIADDR) * sizeof (uint32_t)) 104d65f6f70SBen Gras 105d65f6f70SBen Gras struct ext2fs_dinode { 106d65f6f70SBen Gras uint16_t e2di_mode; /* 0: IFMT, permissions; see below. */ 107d65f6f70SBen Gras uint16_t e2di_uid; /* 2: Owner UID */ 108d65f6f70SBen Gras uint32_t e2di_size; /* 4: Size (in bytes) */ 109*84d9c625SLionel Sambuc uint32_t e2di_atime; /* 8: Access time */ 110d65f6f70SBen Gras uint32_t e2di_ctime; /* 12: Create time */ 111d65f6f70SBen Gras uint32_t e2di_mtime; /* 16: Modification time */ 112d65f6f70SBen Gras uint32_t e2di_dtime; /* 20: Deletion time */ 113d65f6f70SBen Gras uint16_t e2di_gid; /* 24: Owner GID */ 114d65f6f70SBen Gras uint16_t e2di_nlink; /* 26: File link count */ 115d65f6f70SBen Gras uint32_t e2di_nblock; /* 28: Blocks count */ 116d65f6f70SBen Gras uint32_t e2di_flags; /* 32: Status flags (chflags) */ 117*84d9c625SLionel Sambuc uint32_t e2di_version; /* 36: was reserved1 */ 118*84d9c625SLionel Sambuc uint32_t e2di_blocks[EXT2FS_NDADDR+EXT2FS_NIADDR]; 119*84d9c625SLionel Sambuc /* 40: disk blocks */ 120d65f6f70SBen Gras uint32_t e2di_gen; /* 100: generation number */ 121d65f6f70SBen Gras uint32_t e2di_facl; /* 104: file ACL (not implemented) */ 122d65f6f70SBen Gras uint32_t e2di_dacl; /* 108: dir ACL (not implemented) */ 123d65f6f70SBen Gras uint32_t e2di_faddr; /* 112: fragment address */ 124*84d9c625SLionel Sambuc uint16_t e2di_nblock_high; /* 116: Blocks count bits 47:32 */ 125*84d9c625SLionel Sambuc uint16_t e2di_facl_high; /* 118: file ACL bits 47:32 */ 126d65f6f70SBen Gras uint16_t e2di_uid_high; /* 120: Owner UID top 16 bits */ 127d65f6f70SBen Gras uint16_t e2di_gid_high; /* 122: Owner GID top 16 bits */ 128d65f6f70SBen Gras uint32_t e2di_linux_reserved3; /* 124 */ 129d65f6f70SBen Gras }; 130d65f6f70SBen Gras 131d65f6f70SBen Gras 132*84d9c625SLionel Sambuc /* XXX how does this differ from EXT2_MAXSYMLINKLEN above? */ 133*84d9c625SLionel Sambuc #define E2MAXSYMLINKLEN ((EXT2FS_NDADDR + EXT2FS_NIADDR) * sizeof(uint32_t)) 134d65f6f70SBen Gras 135d65f6f70SBen Gras /* File permissions. */ 136d65f6f70SBen Gras #define EXT2_IEXEC 0000100 /* Executable. */ 137d65f6f70SBen Gras #define EXT2_IWRITE 0000200 /* Writable. */ 138d65f6f70SBen Gras #define EXT2_IREAD 0000400 /* Readable. */ 139d65f6f70SBen Gras #define EXT2_ISVTX 0001000 /* Sticky bit. */ 140d65f6f70SBen Gras #define EXT2_ISGID 0002000 /* Set-gid. */ 141d65f6f70SBen Gras #define EXT2_ISUID 0004000 /* Set-uid. */ 142d65f6f70SBen Gras 143d65f6f70SBen Gras /* File types. */ 144d65f6f70SBen Gras #define EXT2_IFMT 0170000 /* Mask of file type. */ 145d65f6f70SBen Gras #define EXT2_IFIFO 0010000 /* Named pipe (fifo). */ 146d65f6f70SBen Gras #define EXT2_IFCHR 0020000 /* Character device. */ 147d65f6f70SBen Gras #define EXT2_IFDIR 0040000 /* Directory file. */ 148d65f6f70SBen Gras #define EXT2_IFBLK 0060000 /* Block device. */ 149d65f6f70SBen Gras #define EXT2_IFREG 0100000 /* Regular file. */ 150d65f6f70SBen Gras #define EXT2_IFLNK 0120000 /* Symbolic link. */ 151d65f6f70SBen Gras #define EXT2_IFSOCK 0140000 /* UNIX domain socket. */ 152d65f6f70SBen Gras 153d65f6f70SBen Gras /* file flags */ 154d65f6f70SBen Gras #define EXT2_SECRM 0x00000001 /* Secure deletion */ 155d65f6f70SBen Gras #define EXT2_UNRM 0x00000002 /* Undelete */ 156d65f6f70SBen Gras #define EXT2_COMPR 0x00000004 /* Compress file */ 157d65f6f70SBen Gras #define EXT2_SYNC 0x00000008 /* Synchronous updates */ 158d65f6f70SBen Gras #define EXT2_IMMUTABLE 0x00000010 /* Immutable file */ 159d65f6f70SBen Gras #define EXT2_APPEND 0x00000020 /* writes to file may only append */ 160d65f6f70SBen Gras #define EXT2_NODUMP 0x00000040 /* do not dump file */ 161*84d9c625SLionel Sambuc #define EXT2_NOATIME 0x00000080 /* do not update atime */ 162*84d9c625SLionel Sambuc #define EXT2_INDEX 0x00001000 /* hash-indexed directory */ 163*84d9c625SLionel Sambuc #define EXT2_IMAGIC 0x00002000 /* AFS directory */ 164*84d9c625SLionel Sambuc #define EXT2_JOURNAL_DATA 0x00004000 /* file data should be journaled */ 165*84d9c625SLionel Sambuc #define EXT2_NOTAIL 0x00008000 /* file tail should not be merged */ 166*84d9c625SLionel Sambuc #define EXT2_DIRSYNC 0x00010000 /* dirsync behaviour */ 167*84d9c625SLionel Sambuc #define EXT2_TOPDIR 0x00020000 /* Top of directory hierarchies*/ 168*84d9c625SLionel Sambuc #define EXT2_HUGE_FILE 0x00040000 /* Set to each huge file */ 169*84d9c625SLionel Sambuc #define EXT2_EXTENTS 0x00080000 /* Inode uses extents */ 170*84d9c625SLionel Sambuc #define EXT2_EOFBLOCKS 0x00400000 /* Blocks allocated beyond EOF */ 171d65f6f70SBen Gras 172d65f6f70SBen Gras /* Size of on-disk inode. */ 173d65f6f70SBen Gras #define EXT2_REV0_DINODE_SIZE sizeof(struct ext2fs_dinode) 174d65f6f70SBen Gras #define EXT2_DINODE_SIZE(fs) ((fs)->e2fs.e2fs_rev > E2FS_REV0 ? \ 175d65f6f70SBen Gras (fs)->e2fs.e2fs_inode_size : \ 176d65f6f70SBen Gras EXT2_REV0_DINODE_SIZE) 177d65f6f70SBen Gras 178d65f6f70SBen Gras /* 179d65f6f70SBen Gras * The e2di_blocks fields may be overlaid with other information for 180d65f6f70SBen Gras * file types that do not have associated disk storage. Block 181d65f6f70SBen Gras * and character devices overlay the first data block with their 182d65f6f70SBen Gras * dev_t value. Short symbolic links place their path in the 183d65f6f70SBen Gras * di_db area. 184d65f6f70SBen Gras */ 185d65f6f70SBen Gras 186d65f6f70SBen Gras #define e2di_rdev e2di_blocks[0] 187d65f6f70SBen Gras #define e2di_shortlink e2di_blocks 188d65f6f70SBen Gras 189d65f6f70SBen Gras /* e2fs needs byte swapping on big-endian systems */ 190d65f6f70SBen Gras #if BYTE_ORDER == LITTLE_ENDIAN 191d65f6f70SBen Gras # define e2fs_iload(old, new) \ 192d65f6f70SBen Gras memcpy((new),(old),sizeof(struct ext2fs_dinode)) 193d65f6f70SBen Gras # define e2fs_isave(old, new) \ 194d65f6f70SBen Gras memcpy((new),(old),sizeof(struct ext2fs_dinode)) 195d65f6f70SBen Gras #else 196d65f6f70SBen Gras void e2fs_i_bswap(struct ext2fs_dinode *, struct ext2fs_dinode *); 197d65f6f70SBen Gras # define e2fs_iload(old, new) e2fs_i_bswap((old), (new)) 198d65f6f70SBen Gras # define e2fs_isave(old, new) e2fs_i_bswap((old), (new)) 199d65f6f70SBen Gras #endif 200d65f6f70SBen Gras 201d65f6f70SBen Gras #endif /* !_UFS_EXT2FS_EXT2FS_DINODE_H_ */ 202