HelenOS sources
#ifndef LIBEXT4_TYPES_H_
#define LIBEXT4_TYPES_H_
#include <block.h>
typedef struct ext4_superblock {
uint32_t inodes_count;
uint32_t blocks_count_lo;
uint32_t reserved_blocks_count_lo;
uint32_t free_blocks_count_lo;
uint32_t free_inodes_count;
uint32_t first_data_block;
uint32_t log_block_size;
uint32_t log_frag_size;
uint32_t blocks_per_group;
uint32_t frags_per_group;
uint32_t inodes_per_group;
uint32_t mount_time;
uint32_t write_time;
uint16_t mount_count;
uint16_t max_mount_count;
uint16_t magic;
uint16_t state;
uint16_t errors;
uint16_t minor_rev_level;
uint32_t last_check_time;
uint32_t check_interval;
uint32_t creator_os;
uint32_t rev_level;
uint16_t def_resuid;
uint16_t def_resgid;
uint32_t first_inode;
uint16_t inode_size;
uint16_t block_group_index;
uint32_t features_compatible;
uint32_t features_incompatible;
uint32_t features_read_only;
uint8_t uuid[16];
char volume_name[16];
char last_mounted[64];
uint32_t algorithm_usage_bitmap;
uint8_t prealloc_blocks;
uint8_t prealloc_dir_blocks;
uint16_t reserved_gdt_blocks;
uint8_t journal_uuid[16];
uint32_t journal_inode_number;
uint32_t journal_dev;
uint32_t last_orphan;
uint32_t hash_seed[4];
uint8_t default_hash_version;
uint8_t journal_backup_type;
uint16_t desc_size;
uint32_t default_mount_opts;
uint32_t first_meta_bg;
uint32_t mkfs_time;
uint32_t journal_blocks[17];
uint32_t blocks_count_hi;
uint32_t reserved_blocks_count_hi;
uint32_t free_blocks_count_hi;
uint16_t min_extra_isize;
uint16_t want_extra_isize;
uint32_t flags;
uint16_t raid_stride;
uint16_t mmp_interval;
uint64_t mmp_block;
uint32_t raid_stripe_width;
uint8_t log_groups_per_flex;
uint8_t reserved_char_pad;
uint16_t reserved_pad;
uint64_t kbytes_written;
uint32_t snapshot_inum;
uint32_t snapshot_id;
uint64_t snapshot_r_blocks_count;
uint32_t snapshot_list;
uint32_t error_count;
uint32_t first_error_time;
uint32_t first_error_ino;
uint64_t first_error_block;
uint8_t first_error_func[32];
uint32_t first_error_line;
uint32_t last_error_time;
uint32_t last_error_ino;
uint32_t last_error_line;
uint64_t last_error_block;
uint8_t last_error_func[32];
uint8_t mount_opts[64];
uint32_t usr_quota_inum;
uint32_t grp_quota_inum;
uint32_t overhead_blocks;
uint32_t backup_bgs[2];
uint32_t encrypt_algos;
uint32_t padding[105];
} ext4_superblock_t;
#define EXT4_GOOD_OLD_REV 0
#define EXT4_DYNAMIC_REV 1
#define EXT4_SUPERBLOCK_MAGIC 0xEF53
#define EXT4_SUPERBLOCK_SIZE 1024
#define EXT4_SUPERBLOCK_OFFSET 1024
#define EXT4_SUPERBLOCK_OS_LINUX 0
#define EXT4_SUPERBLOCK_OS_HURD 1
#define EXT4_SUPERBLOCK_FLAGS_SIGNED_HASH 0x0001
#define EXT4_SUPERBLOCK_FLAGS_UNSIGNED_HASH 0x0002
#define EXT4_SUPERBLOCK_FLAGS_TEST_FILESYS 0x0004
#define EXT4_SUPERBLOCK_STATE_VALID_FS 0x0001
#define EXT4_SUPERBLOCK_STATE_ERROR_FS 0x0002
#define EXT4_SUPERBLOCK_STATE_ORPHAN_FS 0x0004
#define EXT4_SUPERBLOCK_ERRORS_CONTINUE 1
#define EXT4_SUPERBLOCK_ERRORS_RO 2
#define EXT4_SUPERBLOCK_ERRORS_PANIC 3
#define EXT4_SUPERBLOCK_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE
#define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001
#define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002
#define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004
#define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008
#define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010
#define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020
#define EXT4_FEATURE_COMPAT_SPARSE_SUPER2 0x0200
#define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
#define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
#define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008
#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020
#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040
#define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001
#define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002
#define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004
#define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008
#define EXT4_FEATURE_INCOMPAT_META_BG 0x0010
#define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040
#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
#define EXT4_FEATURE_INCOMPAT_MMP 0x0100
#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
#define EXT4_FEATURE_INCOMPAT_EA_INODE 0x0400
#define EXT4_FEATURE_INCOMPAT_DIRDATA 0x1000
#define EXT4_FEATURE_COMPAT_SUPP (EXT4_FEATURE_COMPAT_DIR_INDEX)
#define EXT4_FEATURE_INCOMPAT_SUPP \
(EXT4_FEATURE_INCOMPAT_FILETYPE | \
EXT4_FEATURE_INCOMPAT_EXTENTS | \
EXT4_FEATURE_INCOMPAT_64BIT | \
EXT4_FEATURE_INCOMPAT_FLEX_BG)
#define EXT4_FEATURE_RO_COMPAT_SUPP \
(EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER | \
EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \
EXT4_FEATURE_RO_COMPAT_HUGE_FILE | \
EXT4_FEATURE_RO_COMPAT_LARGE_FILE | \
EXT4_FEATURE_RO_COMPAT_GDT_CSUM | \
EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)
typedef struct ext4_filesystem {
service_id_t device;
ext4_superblock_t *superblock;
aoff64_t inode_block_limits[4];
aoff64_t inode_blocks_per_level[4];
} ext4_filesystem_t;
#define EXT4_VOL_NAME_BYTES 33
typedef struct {
char vol_name[EXT4_VOL_NAME_BYTES];
} ext4_fs_probe_info_t;
#define EXT4_BLOCK_GROUP_INODE_UNINIT 0x0001
#define EXT4_BLOCK_GROUP_BLOCK_UNINIT 0x0002
#define EXT4_BLOCK_GROUP_ITABLE_ZEROED 0x0004
typedef struct ext4_block_group {
uint32_t block_bitmap_lo;
uint32_t inode_bitmap_lo;
uint32_t inode_table_first_block_lo;
uint16_t free_blocks_count_lo;
uint16_t free_inodes_count_lo;
uint16_t used_dirs_count_lo;
uint16_t flags;
uint32_t reserved[2];
uint16_t itable_unused_lo;
uint16_t checksum;
uint32_t block_bitmap_hi;
uint32_t inode_bitmap_hi;
uint32_t inode_table_first_block_hi;
uint16_t free_blocks_count_hi;
uint16_t free_inodes_count_hi;
uint16_t used_dirs_count_hi;
uint16_t itable_unused_hi;
uint32_t reserved2[3];
} ext4_block_group_t;
typedef struct ext4_block_group_ref {
block_t *block;
ext4_block_group_t *block_group;
ext4_filesystem_t *fs;
uint32_t index;
bool dirty;
} ext4_block_group_ref_t;
#define EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE 32
#define EXT4_MAX_BLOCK_GROUP_DESCRIPTOR_SIZE 64
#define EXT4_MIN_BLOCK_SIZE 1024
#define EXT4_MAX_BLOCK_SIZE 65536
#define EXT4_REV0_INODE_SIZE 128
#define EXT4_REV0_FIRST_INO 11
#define EXT4_INODE_BLOCK_SIZE 512
#define EXT4_INODE_DIRECT_BLOCK_COUNT 12
#define EXT4_INODE_INDIRECT_BLOCK EXT4_INODE_DIRECT_BLOCK_COUNT
#define EXT4_INODE_DOUBLE_INDIRECT_BLOCK (EXT4_INODE_INDIRECT_BLOCK + 1)
#define EXT4_INODE_TRIPPLE_INDIRECT_BLOCK (EXT4_INODE_DOUBLE_INDIRECT_BLOCK + 1)
#define EXT4_INODE_BLOCKS (EXT4_INODE_TRIPPLE_INDIRECT_BLOCK + 1)
#define EXT4_INODE_INDIRECT_BLOCK_COUNT (EXT4_INODE_BLOCKS - EXT4_INODE_DIRECT_BLOCK_COUNT)
typedef struct ext4_inode {
uint16_t mode;
uint16_t uid;
uint32_t size_lo;
uint32_t access_time;
uint32_t change_inode_time;
uint32_t modification_time;
uint32_t deletion_time;
uint16_t gid;
uint16_t links_count;
uint32_t blocks_count_lo;
uint32_t flags;
uint32_t unused_osd1;
uint32_t blocks[EXT4_INODE_BLOCKS];
uint32_t generation;
uint32_t file_acl_lo;
uint32_t size_hi;
uint32_t obso_faddr;
union {
struct {
uint16_t blocks_high;
uint16_t file_acl_high;
uint16_t uid_high;
uint16_t gid_high;
uint32_t reserved2;
} linux2;
struct {
uint16_t reserved1;
uint16_t mode_high;
uint16_t uid_high;
uint16_t gid_high;
uint32_t author;
} hurd2;
} osd2;
uint16_t extra_isize;
uint16_t pad1;
uint32_t ctime_extra;
uint32_t mtime_extra;
uint32_t atime_extra;
uint32_t crtime;
uint32_t crtime_extra;
uint32_t version_hi;
} ext4_inode_t;
#define EXT4_INODE_MODE_FIFO 0x1000
#define EXT4_INODE_MODE_CHARDEV 0x2000
#define EXT4_INODE_MODE_DIRECTORY 0x4000
#define EXT4_INODE_MODE_BLOCKDEV 0x6000
#define EXT4_INODE_MODE_FILE 0x8000
#define EXT4_INODE_MODE_SOFTLINK 0xA000
#define EXT4_INODE_MODE_SOCKET 0xC000
#define EXT4_INODE_MODE_TYPE_MASK 0xF000
#define EXT4_INODE_FLAG_SECRM 0x00000001
#define EXT4_INODE_FLAG_UNRM 0x00000002
#define EXT4_INODE_FLAG_COMPR 0x00000004
#define EXT4_INODE_FLAG_SYNC 0x00000008
#define EXT4_INODE_FLAG_IMMUTABLE 0x00000010
#define EXT4_INODE_FLAG_APPEND 0x00000020
#define EXT4_INODE_FLAG_NODUMP 0x00000040
#define EXT4_INODE_FLAG_NOATIME 0x00000080
#define EXT4_INODE_FLAG_DIRTY 0x00000100
#define EXT4_INODE_FLAG_COMPRBLK 0x00000200
#define EXT4_INODE_FLAG_NOCOMPR 0x00000400
#define EXT4_INODE_FLAG_ECOMPR 0x00000800
#define EXT4_INODE_FLAG_INDEX 0x00001000
#define EXT4_INODE_FLAG_IMAGIC 0x00002000
#define EXT4_INODE_FLAG_JOURNAL_DATA 0x00004000
#define EXT4_INODE_FLAG_NOTAIL 0x00008000
#define EXT4_INODE_FLAG_DIRSYNC 0x00010000
#define EXT4_INODE_FLAG_TOPDIR 0x00020000
#define EXT4_INODE_FLAG_HUGE_FILE 0x00040000
#define EXT4_INODE_FLAG_EXTENTS 0x00080000
#define EXT4_INODE_FLAG_EA_INODE 0x00200000
#define EXT4_INODE_FLAG_EOFBLOCKS 0x00400000
#define EXT4_INODE_FLAG_RESERVED 0x80000000
#define EXT4_INODE_ROOT_INDEX 2
typedef struct ext4_inode_ref {
block_t *block;
ext4_inode_t *inode;
ext4_filesystem_t *fs;
uint32_t index;
bool dirty;
} ext4_inode_ref_t;
#define EXT4_DIRECTORY_FILENAME_LEN 255
#define EXT4_DIRECTORY_FILETYPE_UNKNOWN 0
#define EXT4_DIRECTORY_FILETYPE_REG_FILE 1
#define EXT4_DIRECTORY_FILETYPE_DIR 2
#define EXT4_DIRECTORY_FILETYPE_CHRDEV 3
#define EXT4_DIRECTORY_FILETYPE_BLKDEV 4
#define EXT4_DIRECTORY_FILETYPE_FIFO 5
#define EXT4_DIRECTORY_FILETYPE_SOCK 6
#define EXT4_DIRECTORY_FILETYPE_SYMLINK 7
typedef struct ext4_directory_entry_ll {
uint32_t inode;
uint16_t entry_length;
uint8_t name_length;
union {
uint8_t name_length_high;
uint8_t inode_type;
};
uint8_t name[EXT4_DIRECTORY_FILENAME_LEN];
} ext4_directory_entry_ll_t;
typedef struct ext4_directory_iterator {
ext4_inode_ref_t *inode_ref;
block_t *current_block;
aoff64_t current_offset;
ext4_directory_entry_ll_t *current;
} ext4_directory_iterator_t;
typedef struct ext4_directory_search_result {
block_t *block;
ext4_directory_entry_ll_t *dentry;
} ext4_directory_search_result_t;
typedef struct ext4_directory_dx_countlimit {
uint16_t limit;
uint16_t count;
} ext4_directory_dx_countlimit_t;
typedef struct ext4_directory_dx_dot_entry {
uint32_t inode;
uint16_t entry_length;
uint8_t name_length;
uint8_t inode_type;
uint8_t name[4];
} ext4_directory_dx_dot_entry_t;
typedef struct ext4_directory_dx_root_info {
uint32_t reserved_zero;
uint8_t hash_version;
uint8_t info_length;
uint8_t indirect_levels;
uint8_t unused_flags;
} ext4_directory_dx_root_info_t;
typedef struct ext4_directory_dx_entry {
uint32_t hash;
uint32_t block;
} ext4_directory_dx_entry_t;
typedef struct ext4_directory_dx_root {
ext4_directory_dx_dot_entry_t dots[2];
ext4_directory_dx_root_info_t info;
ext4_directory_dx_entry_t entries[0];
} ext4_directory_dx_root_t;
typedef struct ext4_fake_directory_entry {
uint32_t inode;
uint16_t entry_length;
uint8_t name_length;
uint8_t inode_type;
} ext4_fake_directory_entry_t;
typedef struct ext4_directory_dx_node {
ext4_fake_directory_entry_t fake;
ext4_directory_dx_entry_t entries[0];
} ext4_directory_dx_node_t;
typedef struct ext4_directory_dx_block {
block_t *block;
ext4_directory_dx_entry_t *entries;
ext4_directory_dx_entry_t *position;
} ext4_directory_dx_block_t;
#define EXT4_DIRECTORY_HTREE_EOF UINT32_C(0x7fffffff)
typedef struct ext4_extent {
uint32_t first_block;
uint16_t block_count;
uint16_t start_hi;
uint32_t start_lo;
} ext4_extent_t;
typedef struct ext4_extent_index {
uint32_t first_block;
uint32_t leaf_lo;
uint16_t leaf_hi;
uint16_t padding;
} ext4_extent_index_t;
typedef struct ext4_extent_header {
uint16_t magic;
uint16_t entries_count;
uint16_t max_entries_count;
uint16_t depth;
uint32_t generation;
} ext4_extent_header_t;
typedef struct ext4_extent_path {
block_t *block;
uint16_t depth;
ext4_extent_header_t *header;
ext4_extent_index_t *index;
ext4_extent_t *extent;
} ext4_extent_path_t;
#define EXT4_EXTENT_MAGIC 0xF30A
#define EXT4_EXTENT_FIRST(header) \
((ext4_extent_t *) (((void *) (header)) + sizeof(ext4_extent_header_t)))
#define EXT4_EXTENT_FIRST_INDEX(header) \
((ext4_extent_index_t *) (((void *) (header)) + sizeof(ext4_extent_header_t)))
#define EXT4_HASH_VERSION_LEGACY 0
#define EXT4_HASH_VERSION_HALF_MD4 1
#define EXT4_HASH_VERSION_TEA 2
#define EXT4_HASH_VERSION_LEGACY_UNSIGNED 3
#define EXT4_HASH_VERSION_HALF_MD4_UNSIGNED 4
#define EXT4_HASH_VERSION_TEA_UNSIGNED 5
typedef struct ext4_hash_info {
uint32_t hash;
uint32_t minor_hash;
uint32_t hash_version;
const uint32_t *seed;
} ext4_hash_info_t;
#endif
HelenOS homepage, sources at GitHub