| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 Frantisek Princ
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup libext4
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 |
|
|---|
| 33 | #ifndef LIBEXT4_LIBEXT4_TYPES_H_
|
|---|
| 34 | #define LIBEXT4_LIBEXT4_TYPES_H_
|
|---|
| 35 |
|
|---|
| 36 | #include <libblock.h>
|
|---|
| 37 |
|
|---|
| 38 | /*
|
|---|
| 39 | * Structure of the super block
|
|---|
| 40 | */
|
|---|
| 41 | typedef struct ext4_superblock {
|
|---|
| 42 | uint32_t inodes_count; // Inodes count
|
|---|
| 43 | uint32_t blocks_count_lo; // Blocks count
|
|---|
| 44 | uint32_t reserved_blocks_count_lo; // Reserved blocks count
|
|---|
| 45 | uint32_t free_blocks_count_lo; // Free blocks count
|
|---|
| 46 | uint32_t free_inodes_count; // Free inodes count
|
|---|
| 47 | uint32_t first_data_block; // First Data Block
|
|---|
| 48 | uint32_t log_block_size; // Block size
|
|---|
| 49 | uint32_t obso_log_frag_size; // Obsoleted fragment size
|
|---|
| 50 | uint32_t blocks_per_group; // Number of blocks per group
|
|---|
| 51 | uint32_t obso_frags_per_group; // Obsoleted fragments per group
|
|---|
| 52 | uint32_t inodes_per_group; // Number of inodes per group
|
|---|
| 53 | uint32_t mount_time; // Mount time
|
|---|
| 54 | uint32_t write_time; // Write time
|
|---|
| 55 | uint16_t mount_count; // Mount count
|
|---|
| 56 | uint16_t max_mount_count; // Maximal mount count
|
|---|
| 57 | uint16_t magic; // Magic signature
|
|---|
| 58 | uint16_t state; // File system state
|
|---|
| 59 | uint16_t errors; // Behaviour when detecting errors
|
|---|
| 60 | uint16_t minor_rev_level; // Minor revision level
|
|---|
| 61 | uint32_t last_check_time; // Time of last check
|
|---|
| 62 | uint32_t check_interval; // Maximum time between checks
|
|---|
| 63 | uint32_t creator_os; // Creator OS
|
|---|
| 64 | uint32_t rev_level; // Revision level
|
|---|
| 65 | uint16_t def_resuid; // Default uid for reserved blocks
|
|---|
| 66 | uint16_t def_resgid; // Default gid for reserved blocks
|
|---|
| 67 |
|
|---|
| 68 | // Fields for EXT4_DYNAMIC_REV superblocks only.
|
|---|
| 69 | uint32_t first_inode; // First non-reserved inode
|
|---|
| 70 | uint16_t inode_size; // Size of inode structure
|
|---|
| 71 | uint16_t block_group_number; // Block group number of this superblock
|
|---|
| 72 | uint32_t features_compatible; // Compatible feature set
|
|---|
| 73 | uint32_t features_incompatible; // Incompatible feature set
|
|---|
| 74 | uint32_t features_read_only; // Readonly-compatible feature set
|
|---|
| 75 | uint8_t uuid[16]; // 128-bit uuid for volume
|
|---|
| 76 | char volume_name[16]; // Volume name
|
|---|
| 77 | char last_mounted[64]; // Directory where last mounted
|
|---|
| 78 | uint32_t algorithm_usage_bitmap; // For compression
|
|---|
| 79 |
|
|---|
| 80 | /*
|
|---|
| 81 | * Performance hints. Directory preallocation should only
|
|---|
| 82 | * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on.
|
|---|
| 83 | */
|
|---|
| 84 | uint8_t s_prealloc_blocks; // Number of blocks to try to preallocate
|
|---|
| 85 | uint8_t s_prealloc_dir_blocks; // Number to preallocate for dirs
|
|---|
| 86 | uint16_t s_reserved_gdt_blocks; // Per group desc for online growth
|
|---|
| 87 |
|
|---|
| 88 | /*
|
|---|
| 89 | * Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set.
|
|---|
| 90 | */
|
|---|
| 91 | uint8_t journal_uuid[16]; // UUID of journal superblock
|
|---|
| 92 | uint32_t journal_inode_number; // Inode number of journal file
|
|---|
| 93 | uint32_t journal_dev; // Device number of journal file
|
|---|
| 94 | uint32_t last_orphan; // Head of list of inodes to delete
|
|---|
| 95 | uint32_t hash_seed[4]; // HTREE hash seed
|
|---|
| 96 | uint8_t default_hash_version; // Default hash version to use
|
|---|
| 97 | uint8_t journal_backup_type;
|
|---|
| 98 | uint16_t desc_size; // Size of group descriptor
|
|---|
| 99 | uint32_t default_mount_opts; // Default mount options
|
|---|
| 100 | uint32_t first_meta_bg; // First metablock block group
|
|---|
| 101 | uint32_t mkfs_time; // When the filesystem was created
|
|---|
| 102 | uint32_t journal_blocks[17]; // Backup of the journal inode
|
|---|
| 103 |
|
|---|
| 104 | /* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */
|
|---|
| 105 | uint32_t blocks_count_hi; // Blocks count
|
|---|
| 106 | uint32_t reserved_blocks_count_hi; // Reserved blocks count
|
|---|
| 107 | uint32_t free_blocks_count_hi; // Free blocks count
|
|---|
| 108 | uint16_t min_extra_isize; // All inodes have at least # bytes
|
|---|
| 109 | uint16_t want_extra_isize; // New inodes should reserve # bytes
|
|---|
| 110 | uint32_t flags; // Miscellaneous flags
|
|---|
| 111 | uint16_t raid_stride; // RAID stride
|
|---|
| 112 | uint16_t mmp_interval; // # seconds to wait in MMP checking
|
|---|
| 113 | uint64_t mmp_block; // Block for multi-mount protection
|
|---|
| 114 | uint32_t raid_stripe_width; // blocks on all data disks (N*stride)
|
|---|
| 115 | uint8_t log_groups_per_flex; // FLEX_BG group size
|
|---|
| 116 | uint8_t reserved_char_pad;
|
|---|
| 117 | uint16_t reserved_pad;
|
|---|
| 118 | uint64_t kbytes_written; // Number of lifetime kilobytes written
|
|---|
| 119 | uint32_t snapshot_inum; // Inode number of active snapshot
|
|---|
| 120 | uint32_t snapshot_id; // Sequential ID of active snapshot
|
|---|
| 121 | uint64_t snapshot_r_blocks_count; /* reserved blocks for active snapshot's future use */
|
|---|
| 122 | uint32_t snapshot_list; // inode number of the head of the on-disk snapshot list
|
|---|
| 123 | uint32_t error_count; // number of fs errors
|
|---|
| 124 | uint32_t first_error_time; // First time an error happened
|
|---|
| 125 | uint32_t first_error_ino; // Inode involved in first error
|
|---|
| 126 | uint64_t first_error_block; // block involved of first error
|
|---|
| 127 | uint8_t first_error_func[32]; // Function where the error happened
|
|---|
| 128 | uint32_t first_error_line; // Line number where error happened
|
|---|
| 129 | uint32_t last_error_time; // Most recent time of an error
|
|---|
| 130 | uint32_t last_error_ino; // Inode involved in last error
|
|---|
| 131 | uint32_t last_error_line; // Line number where error happened
|
|---|
| 132 | uint64_t last_error_block; // Block involved of last error
|
|---|
| 133 | uint8_t last_error_func[32]; // Function where the error happened
|
|---|
| 134 | uint8_t mount_opts[64];
|
|---|
| 135 | uint32_t padding[112]; // Padding to the end of the block
|
|---|
| 136 | } __attribute__((packed)) ext4_superblock_t;
|
|---|
| 137 |
|
|---|
| 138 | #define EXT4_SUPERBLOCK_MAGIC 0xEF53
|
|---|
| 139 | #define EXT4_SUPERBLOCK_SIZE 1024
|
|---|
| 140 | #define EXT4_SUPERBLOCK_OFFSET 1024
|
|---|
| 141 |
|
|---|
| 142 | #define EXT4_SUPERBLOCK_OS_LINUX 0
|
|---|
| 143 | #define EXT4_SUPERBLOCK_OS_HURD 1
|
|---|
| 144 |
|
|---|
| 145 | /*
|
|---|
| 146 | * Misc. filesystem flags
|
|---|
| 147 | */
|
|---|
| 148 | #define EXT4_SUPERBLOCK_FLAGS_SIGNED_HASH 0x0001 /* Signed dirhash in use */
|
|---|
| 149 | #define EXT4_SUPERBLOCK_FLAGS_UNSIGNED_HASH 0x0002 /* Unsigned dirhash in use */
|
|---|
| 150 | #define EXT4_SUPERBLOCK_FLAGS_TEST_FILESYS 0x0004 /* to test development code */
|
|---|
| 151 |
|
|---|
| 152 | /* Compatible features */
|
|---|
| 153 | #define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001
|
|---|
| 154 | #define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002
|
|---|
| 155 | #define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004
|
|---|
| 156 | #define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008
|
|---|
| 157 | #define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010
|
|---|
| 158 | #define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020
|
|---|
| 159 |
|
|---|
| 160 | /* Read-only compatible features */
|
|---|
| 161 | #define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
|
|---|
| 162 | #define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
|
|---|
| 163 | #define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
|
|---|
| 164 | #define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008
|
|---|
| 165 | #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
|
|---|
| 166 | #define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020
|
|---|
| 167 | #define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040
|
|---|
| 168 |
|
|---|
| 169 | /* Incompatible features */
|
|---|
| 170 | #define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001
|
|---|
| 171 | #define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002
|
|---|
| 172 | #define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
|
|---|
| 173 | #define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
|
|---|
| 174 | #define EXT4_FEATURE_INCOMPAT_META_BG 0x0010
|
|---|
| 175 | #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */
|
|---|
| 176 | #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
|
|---|
| 177 | #define EXT4_FEATURE_INCOMPAT_MMP 0x0100
|
|---|
| 178 | #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
|
|---|
| 179 | #define EXT4_FEATURE_INCOMPAT_EA_INODE 0x0400 /* EA in inode */
|
|---|
| 180 | #define EXT4_FEATURE_INCOMPAT_DIRDATA 0x1000 /* data in dirent */
|
|---|
| 181 |
|
|---|
| 182 | // TODO MODIFY features corresponding with implementation
|
|---|
| 183 | #define EXT4_FEATURE_COMPAT_SUPP (EXT4_FEATURE_COMPAT_DIR_INDEX)
|
|---|
| 184 |
|
|---|
| 185 | #define EXT4_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE | \
|
|---|
| 186 | EXT4_FEATURE_INCOMPAT_EXTENTS | \
|
|---|
| 187 | EXT4_FEATURE_INCOMPAT_64BIT | \
|
|---|
| 188 | EXT4_FEATURE_INCOMPAT_FLEX_BG)
|
|---|
| 189 |
|
|---|
| 190 | #define EXT4_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER | \
|
|---|
| 191 | EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \
|
|---|
| 192 | EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 | /*****************************************************************************/
|
|---|
| 196 |
|
|---|
| 197 | typedef struct ext4_filesystem {
|
|---|
| 198 | service_id_t device;
|
|---|
| 199 | ext4_superblock_t * superblock;
|
|---|
| 200 | aoff64_t inode_block_limits[4];
|
|---|
| 201 | aoff64_t inode_blocks_per_level[4];
|
|---|
| 202 | } ext4_filesystem_t;
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 | /*****************************************************************************/
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 | /*
|
|---|
| 209 | * Structure of a blocks group descriptor
|
|---|
| 210 | */
|
|---|
| 211 | typedef struct ext4_block_group {
|
|---|
| 212 | uint32_t block_bitmap_lo; // Blocks bitmap block
|
|---|
| 213 | uint32_t inode_bitmap_lo; // Inodes bitmap block
|
|---|
| 214 | uint32_t inode_table_first_block_lo; // Inodes table block
|
|---|
| 215 | uint16_t free_blocks_count_lo; // Free blocks count
|
|---|
| 216 | uint16_t free_inodes_count_lo; // Free inodes count
|
|---|
| 217 | uint16_t used_dirs_count_lo; // Directories count
|
|---|
| 218 | uint16_t flags; // EXT4_BG_flags (INODE_UNINIT, etc)
|
|---|
| 219 | uint32_t reserved[2]; // Likely block/inode bitmap checksum
|
|---|
| 220 | uint16_t itable_unused_lo; // Unused inodes count
|
|---|
| 221 | uint16_t checksum; // crc16(sb_uuid+group+desc)
|
|---|
| 222 | /* -------------- */
|
|---|
| 223 | uint32_t block_bitmap_hi; // Blocks bitmap block MSB
|
|---|
| 224 | uint32_t inode_bitmap_hi; // Inodes bitmap block MSB
|
|---|
| 225 | uint32_t inode_table_first_block_hi; // Inodes table block MSB
|
|---|
| 226 | uint16_t free_blocks_count_hi; // Free blocks count MSB
|
|---|
| 227 | uint16_t free_inodes_count_hi; // Free inodes count MSB
|
|---|
| 228 | uint16_t used_dirs_count_hi; // Directories count MSB
|
|---|
| 229 | uint16_t itable_unused_hi; // Unused inodes count MSB
|
|---|
| 230 | uint32_t reserved2[3]; // Padding
|
|---|
| 231 | } ext4_block_group_t;
|
|---|
| 232 |
|
|---|
| 233 | typedef struct ext4_block_group_ref {
|
|---|
| 234 | block_t *block; // Reference to a block containing this block group descr
|
|---|
| 235 | ext4_block_group_t *block_group;
|
|---|
| 236 | ext4_filesystem_t *fs;
|
|---|
| 237 | uint32_t index;
|
|---|
| 238 | bool dirty;
|
|---|
| 239 | } ext4_block_group_ref_t;
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 | #define EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE 32
|
|---|
| 243 | #define EXT4_BLOCK_MAX_GROUP_DESCRIPTOR_SIZE 64
|
|---|
| 244 |
|
|---|
| 245 | /*****************************************************************************/
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 | #define EXT4_MIN_BLOCK_SIZE 1024 //1 KiB
|
|---|
| 249 | #define EXT4_MAX_BLOCK_SIZE 65536 //64 KiB
|
|---|
| 250 | #define EXT4_REV0_INODE_SIZE 128
|
|---|
| 251 |
|
|---|
| 252 | #define EXT4_INODE_BLOCK_SIZE 512
|
|---|
| 253 |
|
|---|
| 254 | #define EXT4_INODE_DIRECT_BLOCK_COUNT 12
|
|---|
| 255 | #define EXT4_INODE_INDIRECT_BLOCK EXT4_INODE_DIRECT_BLOCK_COUNT
|
|---|
| 256 | #define EXT4_INODE_DOUBLE_INDIRECT_BLOCK (EXT4_INODE_INDIRECT_BLOCK + 1)
|
|---|
| 257 | #define EXT4_INODE_TRIPPLE_INDIRECT_BLOCK (EXT4_INODE_DOUBLE_INDIRECT_BLOCK + 1)
|
|---|
| 258 | #define EXT4_INODE_BLOCKS (EXT4_INODE_TRIPPLE_INDIRECT_BLOCK + 1)
|
|---|
| 259 | #define EXT4_INODE_INDIRECT_BLOCK_COUNT (EXT4_INODE_BLOCKS - EXT4_INODE_DIRECT_BLOCK_COUNT)
|
|---|
| 260 |
|
|---|
| 261 | /*
|
|---|
| 262 | * Structure of an inode on the disk
|
|---|
| 263 | */
|
|---|
| 264 | typedef struct ext4_inode {
|
|---|
| 265 | uint16_t mode; // File mode
|
|---|
| 266 | uint16_t uid; // Low 16 bits of owner uid
|
|---|
| 267 | uint32_t size_lo; // Size in bytes
|
|---|
| 268 | uint32_t access_time; // Access time
|
|---|
| 269 | uint32_t change_inode_time; // Inode change time
|
|---|
| 270 | uint32_t modification_time; // Modification time
|
|---|
| 271 | uint32_t deletion_time; // Deletion time
|
|---|
| 272 | uint16_t gid; // Low 16 bits of group id
|
|---|
| 273 | uint16_t links_count; // Links count
|
|---|
| 274 | uint32_t blocks_count_lo; // Blocks count
|
|---|
| 275 | uint32_t flags; // File flags
|
|---|
| 276 | uint32_t unused_osd1; // OS dependent - not used in HelenOS
|
|---|
| 277 | uint32_t blocks[EXT4_INODE_BLOCKS]; // Pointers to blocks
|
|---|
| 278 | uint32_t generation; // File version (for NFS)
|
|---|
| 279 | uint32_t file_acl_lo; // File ACL
|
|---|
| 280 | uint32_t size_hi;
|
|---|
| 281 | uint32_t obso_faddr; // Obsoleted fragment address
|
|---|
| 282 | union {
|
|---|
| 283 | struct {
|
|---|
| 284 | uint16_t blocks_high; /* were l_i_reserved1 */
|
|---|
| 285 | uint16_t file_acl_high;
|
|---|
| 286 | uint16_t uid_high; /* these 2 fields */
|
|---|
| 287 | uint16_t gid_high; /* were reserved2[0] */
|
|---|
| 288 | uint32_t reserved2;
|
|---|
| 289 | } linux2;
|
|---|
| 290 | struct {
|
|---|
| 291 | uint16_t reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
|
|---|
| 292 | uint16_t mode_high;
|
|---|
| 293 | uint16_t uid_high;
|
|---|
| 294 | uint16_t gid_high;
|
|---|
| 295 | uint32_t author;
|
|---|
| 296 | } hurd2;
|
|---|
| 297 | } __attribute__ ((packed)) osd2;
|
|---|
| 298 |
|
|---|
| 299 | uint16_t extra_isize;
|
|---|
| 300 | uint16_t pad1;
|
|---|
| 301 | uint32_t ctime_extra; // Extra change time (nsec << 2 | epoch)
|
|---|
| 302 | uint32_t mtime_extra; // Extra Modification time (nsec << 2 | epoch)
|
|---|
| 303 | uint32_t atime_extra; // Extra Access time (nsec << 2 | epoch)
|
|---|
| 304 | uint32_t crtime; // File creation time
|
|---|
| 305 | uint32_t crtime_extra; // Extra file creation time (nsec << 2 | epoch)
|
|---|
| 306 | uint32_t version_hi; // High 32 bits for 64-bit version
|
|---|
| 307 | } __attribute__ ((packed)) ext4_inode_t;
|
|---|
| 308 |
|
|---|
| 309 | #define EXT4_INODE_MODE_FIFO 0x1000
|
|---|
| 310 | #define EXT4_INODE_MODE_CHARDEV 0x2000
|
|---|
| 311 | #define EXT4_INODE_MODE_DIRECTORY 0x4000
|
|---|
| 312 | #define EXT4_INODE_MODE_BLOCKDEV 0x6000
|
|---|
| 313 | #define EXT4_INODE_MODE_FILE 0x8000
|
|---|
| 314 | #define EXT4_INODE_MODE_SOFTLINK 0xA000
|
|---|
| 315 | #define EXT4_INODE_MODE_SOCKET 0xC000
|
|---|
| 316 | #define EXT4_INODE_MODE_TYPE_MASK 0xF000
|
|---|
| 317 |
|
|---|
| 318 | /*
|
|---|
| 319 | * Inode flags
|
|---|
| 320 | */
|
|---|
| 321 | #define EXT4_INODE_FLAG_SECRM 0x00000001 // Secure deletion
|
|---|
| 322 | #define EXT4_INODE_FLAG_UNRM 0x00000002 // Undelete
|
|---|
| 323 | #define EXT4_INODE_FLAG_COMPR 0x00000004 // Compress file
|
|---|
| 324 | #define EXT4_INODE_FLAG_SYNC 0x00000008 // Synchronous updates
|
|---|
| 325 | #define EXT4_INODE_FLAG_IMMUTABLE 0x00000010 // Immutable file
|
|---|
| 326 | #define EXT4_INODE_FLAG_APPEND 0x00000020 // writes to file may only append
|
|---|
| 327 | #define EXT4_INODE_FLAG_NODUMP 0x00000040 // do not dump file
|
|---|
| 328 | #define EXT4_INODE_FLAG_NOATIME 0x00000080 // do not update atime
|
|---|
| 329 | /* Compression flags */
|
|---|
| 330 | #define EXT4_INODE_FLAG_DIRTY 0x00000100
|
|---|
| 331 | #define EXT4_INODE_FLAG_COMPRBLK 0x00000200 // One or more compressed clusters
|
|---|
| 332 | #define EXT4_INODE_FLAG_NOCOMPR 0x00000400 // Don't compress
|
|---|
| 333 | #define EXT4_INODE_FLAG_ECOMPR 0x00000800 // Compression error
|
|---|
| 334 | /* End compression flags --- maybe not all used */
|
|---|
| 335 | #define EXT4_INODE_FLAG_INDEX 0x00001000 // hash-indexed directory
|
|---|
| 336 | #define EXT4_INODE_FLAG_IMAGIC 0x00002000 // AFS directory */
|
|---|
| 337 | #define EXT4_INODE_FLAG_JOURNAL_DATA 0x00004000 // File data should be journaled
|
|---|
| 338 | #define EXT4_INODE_FLAG_NOTAIL 0x00008000 // File tail should not be merged
|
|---|
| 339 | #define EXT4_INODE_FLAG_DIRSYNC 0x00010000 // Dirsync behaviour (directories only)
|
|---|
| 340 | #define EXT4_INODE_FLAG_TOPDIR 0x00020000 // Top of directory hierarchies
|
|---|
| 341 | #define EXT4_INODE_FLAG_HUGE_FILE 0x00040000 // Set to each huge file
|
|---|
| 342 | #define EXT4_INODE_FLAG_EXTENTS 0x00080000 // Inode uses extents
|
|---|
| 343 | #define EXT4_INODE_FLAG_EA_INODE 0x00200000 // Inode used for large EA
|
|---|
| 344 | #define EXT4_INODE_FLAG_EOFBLOCKS 0x00400000 // Blocks allocated beyond EOF
|
|---|
| 345 | #define EXT4_INODE_FLAG_RESERVED 0x80000000 // reserved for ext4 lib
|
|---|
| 346 |
|
|---|
| 347 | #define EXT4_INODE_ROOT_INDEX 2
|
|---|
| 348 |
|
|---|
| 349 | typedef struct ext4_inode_ref {
|
|---|
| 350 | block_t *block; // Reference to a block containing this inode
|
|---|
| 351 | ext4_inode_t *inode;
|
|---|
| 352 | ext4_filesystem_t *fs;
|
|---|
| 353 | uint32_t index; // Index number of this inode
|
|---|
| 354 | bool dirty;
|
|---|
| 355 | } ext4_inode_ref_t;
|
|---|
| 356 |
|
|---|
| 357 | /*****************************************************************************/
|
|---|
| 358 |
|
|---|
| 359 | #define EXT4_DIRECTORY_FILENAME_LEN 255
|
|---|
| 360 |
|
|---|
| 361 | #define EXT4_DIRECTORY_FILETYPE_UNKNOWN 0
|
|---|
| 362 | #define EXT4_DIRECTORY_FILETYPE_REG_FILE 1
|
|---|
| 363 | #define EXT4_DIRECTORY_FILETYPE_DIR 2
|
|---|
| 364 | #define EXT4_DIRECTORY_FILETYPE_CHRDEV 3
|
|---|
| 365 | #define EXT4_DIRECTORY_FILETYPE_BLKDEV 4
|
|---|
| 366 | #define EXT4_DIRECTORY_FILETYPE_FIFO 5
|
|---|
| 367 | #define EXT4_DIRECTORY_FILETYPE_SOCK 6
|
|---|
| 368 | #define EXT4_DIRECTORY_FILETYPE_SYMLINK 7
|
|---|
| 369 |
|
|---|
| 370 | /**
|
|---|
| 371 | * Linked list directory entry structure
|
|---|
| 372 | */
|
|---|
| 373 | typedef struct ext4_directory_entry_ll {
|
|---|
| 374 | uint32_t inode; // Inode for the entry
|
|---|
| 375 | uint16_t entry_length; // Distance to the next directory entry
|
|---|
| 376 | uint8_t name_length; // Lower 8 bits of name length
|
|---|
| 377 | union {
|
|---|
| 378 | uint8_t name_length_high; // Higher 8 bits of name length
|
|---|
| 379 | uint8_t inode_type; // Type of referenced inode (in rev >= 0.5)
|
|---|
| 380 | } __attribute__ ((packed));
|
|---|
| 381 | uint8_t name[EXT4_DIRECTORY_FILENAME_LEN]; // Entry name
|
|---|
| 382 | } __attribute__ ((packed)) ext4_directory_entry_ll_t;
|
|---|
| 383 |
|
|---|
| 384 | typedef struct ext4_directory_iterator {
|
|---|
| 385 | ext4_filesystem_t *fs;
|
|---|
| 386 | ext4_inode_ref_t *inode_ref;
|
|---|
| 387 | block_t *current_block;
|
|---|
| 388 | aoff64_t current_offset;
|
|---|
| 389 | ext4_directory_entry_ll_t *current;
|
|---|
| 390 | } ext4_directory_iterator_t;
|
|---|
| 391 |
|
|---|
| 392 | typedef struct ext4_directory_search_result {
|
|---|
| 393 | block_t *block;
|
|---|
| 394 | ext4_directory_entry_ll_t *dentry;
|
|---|
| 395 | } ext4_directory_search_result_t;
|
|---|
| 396 |
|
|---|
| 397 |
|
|---|
| 398 | /*****************************************************************************/
|
|---|
| 399 |
|
|---|
| 400 | /* Structures for indexed directory */
|
|---|
| 401 |
|
|---|
| 402 | typedef struct ext4_directory_dx_countlimit {
|
|---|
| 403 | uint16_t limit;
|
|---|
| 404 | uint16_t count;
|
|---|
| 405 | } ext4_directory_dx_countlimit_t;
|
|---|
| 406 |
|
|---|
| 407 | typedef struct ext4_directory_dx_dot_entry {
|
|---|
| 408 | uint32_t inode;
|
|---|
| 409 | uint16_t entry_length;
|
|---|
| 410 | uint8_t name_length;
|
|---|
| 411 | uint8_t inode_type;
|
|---|
| 412 | uint8_t name[4];
|
|---|
| 413 | } ext4_directory_dx_dot_entry_t;
|
|---|
| 414 |
|
|---|
| 415 | typedef struct ext4_directory_dx_root_info {
|
|---|
| 416 | uint32_t reserved_zero;
|
|---|
| 417 | uint8_t hash_version;
|
|---|
| 418 | uint8_t info_length;
|
|---|
| 419 | uint8_t indirect_levels;
|
|---|
| 420 | uint8_t unused_flags;
|
|---|
| 421 | } ext4_directory_dx_root_info_t;
|
|---|
| 422 |
|
|---|
| 423 | typedef struct ext4_directory_dx_entry {
|
|---|
| 424 | uint32_t hash;
|
|---|
| 425 | uint32_t block;
|
|---|
| 426 | } ext4_directory_dx_entry_t;
|
|---|
| 427 |
|
|---|
| 428 | typedef struct ext4_directory_dx_root {
|
|---|
| 429 | ext4_directory_dx_dot_entry_t dots[2];
|
|---|
| 430 | ext4_directory_dx_root_info_t info;
|
|---|
| 431 | ext4_directory_dx_entry_t entries[0];
|
|---|
| 432 | } ext4_directory_dx_root_t;
|
|---|
| 433 |
|
|---|
| 434 | typedef struct ext4_fake_directory_entry {
|
|---|
| 435 | uint32_t inode;
|
|---|
| 436 | uint16_t entry_length;
|
|---|
| 437 | uint8_t name_length;
|
|---|
| 438 | uint8_t inode_type;
|
|---|
| 439 | } ext4_fake_directory_entry_t;
|
|---|
| 440 |
|
|---|
| 441 | typedef struct ext4_directory_dx_node {
|
|---|
| 442 | ext4_fake_directory_entry_t fake;
|
|---|
| 443 | ext4_directory_dx_entry_t entries[0];
|
|---|
| 444 | } ext4_directory_dx_node_t;
|
|---|
| 445 |
|
|---|
| 446 |
|
|---|
| 447 | typedef struct ext4_directory_dx_block {
|
|---|
| 448 | block_t *block;
|
|---|
| 449 | ext4_directory_dx_entry_t *entries;
|
|---|
| 450 | ext4_directory_dx_entry_t *position;
|
|---|
| 451 | } ext4_directory_dx_block_t;
|
|---|
| 452 |
|
|---|
| 453 |
|
|---|
| 454 |
|
|---|
| 455 | #define EXT4_ERR_BAD_DX_DIR (-75000)
|
|---|
| 456 | #define EXT4_DIRECTORY_HTREE_EOF (uint32_t)0x7fffffff
|
|---|
| 457 |
|
|---|
| 458 | /*****************************************************************************/
|
|---|
| 459 |
|
|---|
| 460 | /*
|
|---|
| 461 | * This is the extent on-disk structure.
|
|---|
| 462 | * It's used at the bottom of the tree.
|
|---|
| 463 | */
|
|---|
| 464 | typedef struct ext4_extent {
|
|---|
| 465 | uint32_t first_block; // First logical block extent covers
|
|---|
| 466 | uint16_t block_count; // Number of blocks covered by extent
|
|---|
| 467 | uint16_t start_hi; // High 16 bits of physical block
|
|---|
| 468 | uint32_t start_lo; // Low 32 bits of physical block
|
|---|
| 469 | } ext4_extent_t;
|
|---|
| 470 |
|
|---|
| 471 | /*
|
|---|
| 472 | * This is index on-disk structure.
|
|---|
| 473 | * It's used at all the levels except the bottom.
|
|---|
| 474 | */
|
|---|
| 475 | typedef struct ext4_extent_index {
|
|---|
| 476 | uint32_t first_block; // Index covers logical blocks from 'block'
|
|---|
| 477 | uint32_t leaf_lo; /* Pointer to the physical block of the next
|
|---|
| 478 | * level. leaf or next index could be there */
|
|---|
| 479 | uint16_t leaf_hi; /* high 16 bits of physical block */
|
|---|
| 480 | uint16_t padding;
|
|---|
| 481 | } ext4_extent_index_t;
|
|---|
| 482 |
|
|---|
| 483 | /*
|
|---|
| 484 | * Each block (leaves and indexes), even inode-stored has header.
|
|---|
| 485 | */
|
|---|
| 486 | typedef struct ext4_extent_header {
|
|---|
| 487 | uint16_t magic;
|
|---|
| 488 | uint16_t entries_count; // Number of valid entries
|
|---|
| 489 | uint16_t max_entries_count; // Capacity of store in entries
|
|---|
| 490 | uint16_t depth; // Has tree real underlying blocks?
|
|---|
| 491 | uint32_t generation; // generation of the tree
|
|---|
| 492 | } ext4_extent_header_t;
|
|---|
| 493 |
|
|---|
| 494 | typedef struct ext4_extent_path {
|
|---|
| 495 | block_t *block;
|
|---|
| 496 | uint16_t depth;
|
|---|
| 497 | ext4_extent_header_t *header;
|
|---|
| 498 | ext4_extent_index_t *index;
|
|---|
| 499 | ext4_extent_t *extent;
|
|---|
| 500 | } ext4_extent_path_t;
|
|---|
| 501 |
|
|---|
| 502 | #define EXT4_EXTENT_MAGIC 0xF30A
|
|---|
| 503 | #define EXT4_EXTENT_FIRST(header) \
|
|---|
| 504 | ((ext4_extent_t *) (((void *) (header)) + sizeof(ext4_extent_header_t)))
|
|---|
| 505 | #define EXT4_EXTENT_FIRST_INDEX(header) \
|
|---|
| 506 | ((ext4_extent_index_t *) (((void *) (header)) + sizeof(ext4_extent_header_t)))
|
|---|
| 507 |
|
|---|
| 508 | /*****************************************************************************/
|
|---|
| 509 |
|
|---|
| 510 | #define EXT4_HASH_VERSION_LEGACY 0
|
|---|
| 511 | #define EXT4_HASH_VERSION_HALF_MD4 1
|
|---|
| 512 | #define EXT4_HASH_VERSION_TEA 2
|
|---|
| 513 | #define EXT4_HASH_VERSION_LEGACY_UNSIGNED 3
|
|---|
| 514 | #define EXT4_HASH_VERSION_HALF_MD4_UNSIGNED 4
|
|---|
| 515 | #define EXT4_HASH_VERSION_TEA_UNSIGNED 5
|
|---|
| 516 |
|
|---|
| 517 | typedef struct ext4_hash_info {
|
|---|
| 518 | uint32_t hash;
|
|---|
| 519 | uint32_t minor_hash;
|
|---|
| 520 | uint32_t hash_version;
|
|---|
| 521 | uint32_t *seed;
|
|---|
| 522 | } ext4_hash_info_t;
|
|---|
| 523 |
|
|---|
| 524 | #endif
|
|---|
| 525 |
|
|---|
| 526 | /**
|
|---|
| 527 | * @}
|
|---|
| 528 | */
|
|---|