Changeset beb9336 in mainline for uspace/lib/ext4/libext4_types.h


Ignore:
Timestamp:
2012-08-24T14:07:52Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
041ab64
Parents:
bd29f9c9 (diff), db81577 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with mainline

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/libext4_types.h

    rbd29f9c9 rbeb9336  
    2929/** @addtogroup libext4
    3030 * @{
    31  */ 
     31 */
    3232
    3333#ifndef LIBEXT4_LIBEXT4_TYPES_H_
    3434#define LIBEXT4_LIBEXT4_TYPES_H_
    3535
    36 #include <libblock.h>
     36#include <block.h>
    3737
    3838/*
     
    4040 */
    4141typedef 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 log_frag_size; // Obsoleted fragment size
    50         uint32_t blocks_per_group; // Number of blocks per group
    51         uint32_t 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; // Filesystem 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_index; // Block group index 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 
     42        uint32_t inodes_count;              /* I-nodes 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 log_frag_size;             /* Obsoleted fragment size */
     50        uint32_t blocks_per_group;          /* Number of blocks per group */
     51        uint32_t 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_index;       /* Block group index 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       
    8080        /*
    8181         * Performance hints. Directory preallocation should only
    8282         * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on.
    8383         */
    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 
     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       
    8888        /*
    8989         * Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set.
    9090         */
    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
     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 */
    9797        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
     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 */
    103103
    104104        /* 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
     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 */
    116116        uint8_t reserved_char_pad;
    117117        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
     118        uint64_t kbytes_written;            /* Number of lifetime kilobytes written */
     119        uint32_t snapshot_inum;             /* I-node 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;             /* I-node number of the head of the on-disk snapshot list */
     123        uint32_t error_count;               /* Number of file system errors */
     124        uint32_t first_error_time;          /* First time an error happened */
     125        uint32_t first_error_ino;           /* I-node 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;            /* I-node 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 */
    134134        uint8_t mount_opts[64];
    135         uint32_t padding[112]; // Padding to the end of the block
     135        uint32_t padding[112];              /* Padding to the end of the block */
    136136} __attribute__((packed)) ext4_superblock_t;
    137137
    138138
    139 #define EXT4_SUPERBLOCK_MAGIC           0xEF53
    140 #define EXT4_SUPERBLOCK_SIZE            1024
    141 #define EXT4_SUPERBLOCK_OFFSET          1024
    142 
    143 #define EXT4_SUPERBLOCK_OS_LINUX        0
    144 #define EXT4_SUPERBLOCK_OS_HURD         1
     139#define EXT4_SUPERBLOCK_MAGIC   0xEF53
     140#define EXT4_SUPERBLOCK_SIZE    1024
     141#define EXT4_SUPERBLOCK_OFFSET  1024
     142
     143#define EXT4_SUPERBLOCK_OS_LINUX  0
     144#define EXT4_SUPERBLOCK_OS_HURD   1
    145145
    146146/*
    147147 * Misc. filesystem flags
    148148 */
    149 #define EXT4_SUPERBLOCK_FLAGS_SIGNED_HASH       0x0001  // Signed dirhash in use
    150 #define EXT4_SUPERBLOCK_FLAGS_UNSIGNED_HASH     0x0002  // Unsigned dirhash in use
    151 #define EXT4_SUPERBLOCK_FLAGS_TEST_FILESYS      0x0004  // to test development code
     149#define EXT4_SUPERBLOCK_FLAGS_SIGNED_HASH    0x0001  /* Signed dirhash in use */
     150#define EXT4_SUPERBLOCK_FLAGS_UNSIGNED_HASH  0x0002  /* Unsigned dirhash in use */
     151#define EXT4_SUPERBLOCK_FLAGS_TEST_FILESYS   0x0004  /* to test development code */
    152152
    153153/*
    154154 * Filesystem states
    155155 */
    156 #define EXT4_SUPERBLOCK_STATE_VALID_FS          0x0001  // Unmounted cleanly
    157 #define EXT4_SUPERBLOCK_STATE_ERROR_FS          0x0002  // Errors detected
    158 #define EXT4_SUPERBLOCK_STATE_ORPHAN_FS         0x0004  // Orphans being recovered
     156#define EXT4_SUPERBLOCK_STATE_VALID_FS   0x0001  /* Unmounted cleanly */
     157#define EXT4_SUPERBLOCK_STATE_ERROR_FS   0x0002  /* Errors detected */
     158#define EXT4_SUPERBLOCK_STATE_ORPHAN_FS  0x0004  /* Orphans being recovered */
    159159
    160160/*
    161161 * Behaviour when errors detected
    162162 */
    163 #define EXT4_SUPERBLOCK_ERRORS_CONTINUE         1 // Continue execution
    164 #define EXT4_SUPERBLOCK_ERRORS_RO                       2 // Remount fs read-only
    165 #define EXT4_SUPERBLOCK_ERRORS_PANIC            3 // Panic
    166 #define EXT4_SUPERBLOCK_ERRORS_DEFAULT          EXT4_ERRORS_CONTINUE
     163#define EXT4_SUPERBLOCK_ERRORS_CONTINUE  1  /* Continue execution */
     164#define EXT4_SUPERBLOCK_ERRORS_RO        2  /* Remount fs read-only */
     165#define EXT4_SUPERBLOCK_ERRORS_PANIC     3  /* Panic */
     166#define EXT4_SUPERBLOCK_ERRORS_DEFAULT   EXT4_ERRORS_CONTINUE
    167167
    168168/*
    169169 * Compatible features
    170170 */
    171 #define EXT4_FEATURE_COMPAT_DIR_PREALLOC        0x0001
    172 #define EXT4_FEATURE_COMPAT_IMAGIC_INODES       0x0002
    173 #define EXT4_FEATURE_COMPAT_HAS_JOURNAL         0x0004
    174 #define EXT4_FEATURE_COMPAT_EXT_ATTR            0x0008
    175 #define EXT4_FEATURE_COMPAT_RESIZE_INODE        0x0010
    176 #define EXT4_FEATURE_COMPAT_DIR_INDEX           0x0020
     171#define EXT4_FEATURE_COMPAT_DIR_PREALLOC   0x0001
     172#define EXT4_FEATURE_COMPAT_IMAGIC_INODES  0x0002
     173#define EXT4_FEATURE_COMPAT_HAS_JOURNAL    0x0004
     174#define EXT4_FEATURE_COMPAT_EXT_ATTR       0x0008
     175#define EXT4_FEATURE_COMPAT_RESIZE_INODE   0x0010
     176#define EXT4_FEATURE_COMPAT_DIR_INDEX      0x0020
    177177
    178178/*
    179179 * Read-only compatible features
    180180 */
    181 #define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER     0x0001
    182 #define EXT4_FEATURE_RO_COMPAT_LARGE_FILE       0x0002
    183 #define EXT4_FEATURE_RO_COMPAT_BTREE_DIR        0x0004
    184 #define EXT4_FEATURE_RO_COMPAT_HUGE_FILE        0x0008
    185 #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM         0x0010
    186 #define EXT4_FEATURE_RO_COMPAT_DIR_NLINK        0x0020
    187 #define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE      0x0040
     181#define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER  0x0001
     182#define EXT4_FEATURE_RO_COMPAT_LARGE_FILE    0x0002
     183#define EXT4_FEATURE_RO_COMPAT_BTREE_DIR     0x0004
     184#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE     0x0008
     185#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM      0x0010
     186#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK     0x0020
     187#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE   0x0040
    188188
    189189/*
    190190 * Incompatible features
    191191 */
    192 #define EXT4_FEATURE_INCOMPAT_COMPRESSION       0x0001
    193 #define EXT4_FEATURE_INCOMPAT_FILETYPE          0x0002
    194 #define EXT4_FEATURE_INCOMPAT_RECOVER           0x0004 /* Needs recovery */
    195 #define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV       0x0008 /* Journal device */
    196 #define EXT4_FEATURE_INCOMPAT_META_BG           0x0010
    197 #define EXT4_FEATURE_INCOMPAT_EXTENTS           0x0040 /* extents support */
    198 #define EXT4_FEATURE_INCOMPAT_64BIT             0x0080
    199 #define EXT4_FEATURE_INCOMPAT_MMP               0x0100
    200 #define EXT4_FEATURE_INCOMPAT_FLEX_BG           0x0200
    201 #define EXT4_FEATURE_INCOMPAT_EA_INODE          0x0400 /* EA in inode */
    202 #define EXT4_FEATURE_INCOMPAT_DIRDATA           0x1000 /* data in dirent */
    203 
    204 #define EXT4_FEATURE_COMPAT_SUPP                (EXT4_FEATURE_COMPAT_DIR_INDEX)
    205 
    206 #define EXT4_FEATURE_INCOMPAT_SUPP      (EXT4_FEATURE_INCOMPAT_FILETYPE | \
    207                                          EXT4_FEATURE_INCOMPAT_EXTENTS | \
    208                                          EXT4_FEATURE_INCOMPAT_64BIT)
    209 
    210 #define EXT4_FEATURE_RO_COMPAT_SUPP     (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER | \
    211                                                                                  EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \
    212                                                                                  EXT4_FEATURE_RO_COMPAT_HUGE_FILE | \
    213                                                                                  EXT4_FEATURE_RO_COMPAT_LARGE_FILE | \
    214                                                                                  EXT4_FEATURE_RO_COMPAT_GDT_CSUM | \
    215                                                                                  EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)
    216 
    217 
    218 /*****************************************************************************/
     192#define EXT4_FEATURE_INCOMPAT_COMPRESSION  0x0001
     193#define EXT4_FEATURE_INCOMPAT_FILETYPE     0x0002
     194#define EXT4_FEATURE_INCOMPAT_RECOVER      0x0004  /* Needs recovery */
     195#define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV  0x0008  /* Journal device */
     196#define EXT4_FEATURE_INCOMPAT_META_BG      0x0010
     197#define EXT4_FEATURE_INCOMPAT_EXTENTS      0x0040  /* extents support */
     198#define EXT4_FEATURE_INCOMPAT_64BIT        0x0080
     199#define EXT4_FEATURE_INCOMPAT_MMP          0x0100
     200#define EXT4_FEATURE_INCOMPAT_FLEX_BG      0x0200
     201#define EXT4_FEATURE_INCOMPAT_EA_INODE     0x0400  /* EA in inode */
     202#define EXT4_FEATURE_INCOMPAT_DIRDATA      0x1000  /* data in dirent */
     203
     204#define EXT4_FEATURE_COMPAT_SUPP  (EXT4_FEATURE_COMPAT_DIR_INDEX)
     205
     206#define EXT4_FEATURE_INCOMPAT_SUPP \
     207        (EXT4_FEATURE_INCOMPAT_FILETYPE | \
     208        EXT4_FEATURE_INCOMPAT_EXTENTS | \
     209        EXT4_FEATURE_INCOMPAT_64BIT)
     210
     211#define EXT4_FEATURE_RO_COMPAT_SUPP \
     212        (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER | \
     213        EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \
     214        EXT4_FEATURE_RO_COMPAT_HUGE_FILE | \
     215        EXT4_FEATURE_RO_COMPAT_LARGE_FILE | \
     216        EXT4_FEATURE_RO_COMPAT_GDT_CSUM | \
     217        EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)
    219218
    220219typedef struct ext4_filesystem {
    221220        service_id_t device;
    222         ext4_superblock_t *     superblock;
     221        ext4_superblock_t *superblock;
    223222        aoff64_t inode_block_limits[4];
    224223        aoff64_t inode_blocks_per_level[4];
     
    226225
    227226
    228 /*****************************************************************************/
    229 
    230 #define EXT4_BLOCK_GROUP_INODE_UNINIT   0x0001 /* Inode table/bitmap not in use */
    231 #define EXT4_BLOCK_GROUP_BLOCK_UNINIT   0x0002 /* Block bitmap not in use */
    232 #define EXT4_BLOCK_GROUP_ITABLE_ZEROED  0x0004 /* On-disk itable initialized to zero */
     227#define EXT4_BLOCK_GROUP_INODE_UNINIT   0x0001  /* Inode table/bitmap not in use */
     228#define EXT4_BLOCK_GROUP_BLOCK_UNINIT   0x0002  /* Block bitmap not in use */
     229#define EXT4_BLOCK_GROUP_ITABLE_ZEROED  0x0004  /* On-disk itable initialized to zero */
    233230
    234231/*
     
    236233 */
    237234typedef struct ext4_block_group {
    238         uint32_t block_bitmap_lo; // Blocks bitmap block
    239         uint32_t inode_bitmap_lo; // Inodes bitmap block
    240         uint32_t inode_table_first_block_lo; // Inodes table block
    241         uint16_t free_blocks_count_lo; // Free blocks count
    242         uint16_t free_inodes_count_lo; // Free inodes count
    243         uint16_t used_dirs_count_lo; // Directories count
    244         uint16_t flags; // EXT4_BG_flags (INODE_UNINIT, etc)
    245         uint32_t reserved[2]; // Likely block/inode bitmap checksum
    246         uint16_t itable_unused_lo; // Unused inodes count
    247         uint16_t checksum; // crc16(sb_uuid+group+desc)
    248         /* -------------- */
    249         uint32_t block_bitmap_hi; // Blocks bitmap block MSB
    250         uint32_t inode_bitmap_hi; // Inodes bitmap block MSB
    251         uint32_t inode_table_first_block_hi; // Inodes table block MSB
    252         uint16_t free_blocks_count_hi; // Free blocks count MSB
    253         uint16_t free_inodes_count_hi; // Free inodes count MSB
    254         uint16_t used_dirs_count_hi; // Directories count MSB
    255         uint16_t itable_unused_hi;  // Unused inodes count MSB
    256         uint32_t reserved2[3]; // Padding
     235        uint32_t block_bitmap_lo;             /* Blocks bitmap block */
     236        uint32_t inode_bitmap_lo;             /* Inodes bitmap block */
     237        uint32_t inode_table_first_block_lo;  /* Inodes table block */
     238        uint16_t free_blocks_count_lo;        /* Free blocks count */
     239        uint16_t free_inodes_count_lo;        /* Free inodes count */
     240        uint16_t used_dirs_count_lo;          /* Directories count */
     241        uint16_t flags;                       /* EXT4_BG_flags (INODE_UNINIT, etc) */
     242        uint32_t reserved[2];                 /* Likely block/inode bitmap checksum */
     243        uint16_t itable_unused_lo;            /* Unused inodes count */
     244        uint16_t checksum;                    /* crc16(sb_uuid+group+desc) */
     245       
     246        uint32_t block_bitmap_hi;             /* Blocks bitmap block MSB */
     247        uint32_t inode_bitmap_hi;             /* I-nodes bitmap block MSB */
     248        uint32_t inode_table_first_block_hi;  /* I-nodes table block MSB */
     249        uint16_t free_blocks_count_hi;        /* Free blocks count MSB */
     250        uint16_t free_inodes_count_hi;        /* Free i-nodes count MSB */
     251        uint16_t used_dirs_count_hi;          /* Directories count MSB */
     252        uint16_t itable_unused_hi;            /* Unused inodes count MSB */
     253        uint32_t reserved2[3];                /* Padding */
    257254} ext4_block_group_t;
    258255
    259256typedef struct ext4_block_group_ref {
    260         block_t *block; // Reference to a block containing this block group descr
     257        block_t *block;                   /* Reference to a block containing this block group descr */
    261258        ext4_block_group_t *block_group;
    262259        ext4_filesystem_t *fs;
     
    265262} ext4_block_group_ref_t;
    266263
    267 
    268 #define EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE 32
    269 #define EXT4_MAX_BLOCK_GROUP_DESCRIPTOR_SIZE 64
    270 
    271 /*****************************************************************************/
    272 
    273 
    274 #define EXT4_MIN_BLOCK_SIZE             1024  //1 KiB
    275 #define EXT4_MAX_BLOCK_SIZE     65536 //64 KiB
    276 #define EXT4_REV0_INODE_SIZE    128
    277 
    278 #define EXT4_INODE_BLOCK_SIZE                           512
    279 
    280 #define EXT4_INODE_DIRECT_BLOCK_COUNT           12
    281 #define EXT4_INODE_INDIRECT_BLOCK                       EXT4_INODE_DIRECT_BLOCK_COUNT
    282 #define EXT4_INODE_DOUBLE_INDIRECT_BLOCK        (EXT4_INODE_INDIRECT_BLOCK + 1)
    283 #define EXT4_INODE_TRIPPLE_INDIRECT_BLOCK       (EXT4_INODE_DOUBLE_INDIRECT_BLOCK + 1)
    284 #define EXT4_INODE_BLOCKS                                       (EXT4_INODE_TRIPPLE_INDIRECT_BLOCK + 1)
    285 #define EXT4_INODE_INDIRECT_BLOCK_COUNT         (EXT4_INODE_BLOCKS - EXT4_INODE_DIRECT_BLOCK_COUNT)
     264#define EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE  32
     265#define EXT4_MAX_BLOCK_GROUP_DESCRIPTOR_SIZE  64
     266
     267#define EXT4_MIN_BLOCK_SIZE   1024   /* 1 KiB */
     268#define EXT4_MAX_BLOCK_SIZE   65536  /* 64 KiB */
     269#define EXT4_REV0_INODE_SIZE  128
     270
     271#define EXT4_INODE_BLOCK_SIZE  512
     272
     273#define EXT4_INODE_DIRECT_BLOCK_COUNT      12
     274#define EXT4_INODE_INDIRECT_BLOCK          EXT4_INODE_DIRECT_BLOCK_COUNT
     275#define EXT4_INODE_DOUBLE_INDIRECT_BLOCK   (EXT4_INODE_INDIRECT_BLOCK + 1)
     276#define EXT4_INODE_TRIPPLE_INDIRECT_BLOCK  (EXT4_INODE_DOUBLE_INDIRECT_BLOCK + 1)
     277#define EXT4_INODE_BLOCKS                  (EXT4_INODE_TRIPPLE_INDIRECT_BLOCK + 1)
     278#define EXT4_INODE_INDIRECT_BLOCK_COUNT    (EXT4_INODE_BLOCKS - EXT4_INODE_DIRECT_BLOCK_COUNT)
    286279
    287280/*
     
    289282 */
    290283typedef struct ext4_inode {
    291         uint16_t mode; // File mode
    292         uint16_t uid; // Low 16 bits of owner uid
    293         uint32_t size_lo; // Size in bytes
    294         uint32_t access_time; // Access time
    295         uint32_t change_inode_time; // Inode change time
    296         uint32_t modification_time; // Modification time
    297         uint32_t deletion_time; // Deletion time
    298         uint16_t gid; // Low 16 bits of group id
    299         uint16_t links_count; // Links count
    300         uint32_t blocks_count_lo; // Blocks count
    301         uint32_t flags; // File flags
    302         uint32_t unused_osd1; // OS dependent - not used in HelenOS
    303     uint32_t blocks[EXT4_INODE_BLOCKS]; // Pointers to blocks
    304     uint32_t generation; // File version (for NFS)
    305     uint32_t file_acl_lo; // File ACL
    306     uint32_t size_hi;
    307     uint32_t obso_faddr; // Obsoleted fragment address
    308     union {
    309         struct {
    310                 uint16_t blocks_high; /* were l_i_reserved1 */
    311                 uint16_t file_acl_high;
    312                 uint16_t uid_high;   /* these 2 fields */
    313                 uint16_t gid_high;   /* were reserved2[0] */
    314                 uint32_t reserved2;
    315         } linux2;
    316         struct {
    317                 uint16_t reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
    318                 uint16_t mode_high;
    319                 uint16_t uid_high;
    320                 uint16_t gid_high;
    321                 uint32_t author;
    322         } hurd2;
    323     } __attribute__ ((packed)) osd2;
    324 
    325     uint16_t extra_isize;
    326     uint16_t pad1;
    327     uint32_t ctime_extra; // Extra change time (nsec << 2 | epoch)
    328     uint32_t mtime_extra; // Extra Modification time (nsec << 2 | epoch)
    329     uint32_t atime_extra; // Extra Access time (nsec << 2 | epoch)
    330     uint32_t crtime; // File creation time
    331     uint32_t crtime_extra; // Extra file creation time (nsec << 2 | epoch)
    332     uint32_t version_hi;   // High 32 bits for 64-bit version
     284        uint16_t mode;                       /* File mode */
     285        uint16_t uid;                        /* Low 16 bits of owner uid */
     286        uint32_t size_lo;                    /* Size in bytes */
     287        uint32_t access_time;                /* Access time */
     288        uint32_t change_inode_time;          /* I-node change time */
     289        uint32_t modification_time;          /* Modification time */
     290        uint32_t deletion_time;              /* Deletion time */
     291        uint16_t gid;                        /* Low 16 bits of group id */
     292        uint16_t links_count;                /* Links count */
     293        uint32_t blocks_count_lo;            /* Blocks count */
     294        uint32_t flags;                      /* File flags */
     295        uint32_t unused_osd1;                /* OS dependent - not used in HelenOS */
     296        uint32_t blocks[EXT4_INODE_BLOCKS];  /* Pointers to blocks */
     297        uint32_t generation;                 /* File version (for NFS) */
     298        uint32_t file_acl_lo;                /* File ACL */
     299        uint32_t size_hi;
     300        uint32_t obso_faddr;                 /* Obsoleted fragment address */
     301       
     302        union {
     303                struct {
     304                        uint16_t blocks_high;
     305                        uint16_t file_acl_high;
     306                        uint16_t uid_high;
     307                        uint16_t gid_high;
     308                        uint32_t reserved2;
     309                } linux2;
     310                struct {
     311                        uint16_t reserved1;
     312                        uint16_t mode_high;
     313                        uint16_t uid_high;
     314                        uint16_t gid_high;
     315                        uint32_t author;
     316                } hurd2;
     317        } __attribute__ ((packed)) osd2;
     318       
     319        uint16_t extra_isize;
     320        uint16_t pad1;
     321        uint32_t ctime_extra;   /* Extra change time (nsec << 2 | epoch) */
     322        uint32_t mtime_extra;   /* Extra Modification time (nsec << 2 | epoch) */
     323        uint32_t atime_extra;   /* Extra Access time (nsec << 2 | epoch) */
     324        uint32_t crtime;        /* File creation time */
     325        uint32_t crtime_extra;  /* Extra file creation time (nsec << 2 | epoch) */
     326        uint32_t version_hi;    /* High 32 bits for 64-bit version */
    333327} __attribute__ ((packed)) ext4_inode_t;
    334328
    335 #define EXT4_INODE_MODE_FIFO            0x1000
    336 #define EXT4_INODE_MODE_CHARDEV         0x2000
    337 #define EXT4_INODE_MODE_DIRECTORY       0x4000
    338 #define EXT4_INODE_MODE_BLOCKDEV        0x6000
    339 #define EXT4_INODE_MODE_FILE            0x8000
    340 #define EXT4_INODE_MODE_SOFTLINK        0xA000
    341 #define EXT4_INODE_MODE_SOCKET          0xC000
    342 #define EXT4_INODE_MODE_TYPE_MASK       0xF000
     329#define EXT4_INODE_MODE_FIFO       0x1000
     330#define EXT4_INODE_MODE_CHARDEV    0x2000
     331#define EXT4_INODE_MODE_DIRECTORY  0x4000
     332#define EXT4_INODE_MODE_BLOCKDEV   0x6000
     333#define EXT4_INODE_MODE_FILE       0x8000
     334#define EXT4_INODE_MODE_SOFTLINK   0xA000
     335#define EXT4_INODE_MODE_SOCKET     0xC000
     336#define EXT4_INODE_MODE_TYPE_MASK  0xF000
    343337
    344338/*
    345339 * Inode flags
    346340 */
    347 #define EXT4_INODE_FLAG_SECRM           0x00000001 // Secure deletion
    348 #define EXT4_INODE_FLAG_UNRM            0x00000002 // Undelete
    349 #define EXT4_INODE_FLAG_COMPR           0x00000004 // Compress file
    350 #define EXT4_INODE_FLAG_SYNC            0x00000008 // Synchronous updates
    351 #define EXT4_INODE_FLAG_IMMUTABLE   0x00000010 // Immutable file
    352 #define EXT4_INODE_FLAG_APPEND          0x00000020 // writes to file may only append
    353 #define EXT4_INODE_FLAG_NODUMP          0x00000040 // do not dump file
    354 #define EXT4_INODE_FLAG_NOATIME         0x00000080 // do not update atime
     341#define EXT4_INODE_FLAG_SECRM      0x00000001  /* Secure deletion */
     342#define EXT4_INODE_FLAG_UNRM       0x00000002  /* Undelete */
     343#define EXT4_INODE_FLAG_COMPR      0x00000004  /* Compress file */
     344#define EXT4_INODE_FLAG_SYNC       0x00000008  /* Synchronous updates */
     345#define EXT4_INODE_FLAG_IMMUTABLE  0x00000010  /* Immutable file */
     346#define EXT4_INODE_FLAG_APPEND     0x00000020  /* writes to file may only append */
     347#define EXT4_INODE_FLAG_NODUMP     0x00000040  /* do not dump file */
     348#define EXT4_INODE_FLAG_NOATIME    0x00000080  /* do not update atime */
     349
    355350/* Compression flags */
    356 #define EXT4_INODE_FLAG_DIRTY           0x00000100
    357 #define EXT4_INODE_FLAG_COMPRBLK        0x00000200 // One or more compressed clusters
    358 #define EXT4_INODE_FLAG_NOCOMPR         0x00000400 // Don't compress
    359 #define EXT4_INODE_FLAG_ECOMPR          0x00000800 // Compression error
    360 /* End compression flags --- maybe not all used */
    361 #define EXT4_INODE_FLAG_INDEX           0x00001000 // hash-indexed directory
    362 #define EXT4_INODE_FLAG_IMAGIC          0x00002000 // AFS directory */
    363 #define EXT4_INODE_FLAG_JOURNAL_DATA    0x00004000 // File data should be journaled
    364 #define EXT4_INODE_FLAG_NOTAIL          0x00008000 // File tail should not be merged
    365 #define EXT4_INODE_FLAG_DIRSYNC         0x00010000 // Dirsync behaviour (directories only)
    366 #define EXT4_INODE_FLAG_TOPDIR          0x00020000 // Top of directory hierarchies
    367 #define EXT4_INODE_FLAG_HUGE_FILE       0x00040000 // Set to each huge file
    368 #define EXT4_INODE_FLAG_EXTENTS         0x00080000 // Inode uses extents
    369 #define EXT4_INODE_FLAG_EA_INODE        0x00200000 // Inode used for large EA
    370 #define EXT4_INODE_FLAG_EOFBLOCKS       0x00400000 // Blocks allocated beyond EOF
    371 #define EXT4_INODE_FLAG_RESERVED        0x80000000 // reserved for ext4 lib
    372 
    373 #define EXT4_INODE_ROOT_INDEX   2
     351#define EXT4_INODE_FLAG_DIRTY     0x00000100
     352#define EXT4_INODE_FLAG_COMPRBLK  0x00000200  /* One or more compressed clusters */
     353#define EXT4_INODE_FLAG_NOCOMPR   0x00000400  /* Don't compress */
     354#define EXT4_INODE_FLAG_ECOMPR    0x00000800  /* Compression error */
     355
     356#define EXT4_INODE_FLAG_INDEX         0x00001000  /* hash-indexed directory */
     357#define EXT4_INODE_FLAG_IMAGIC        0x00002000  /* AFS directory */
     358#define EXT4_INODE_FLAG_JOURNAL_DATA  0x00004000  /* File data should be journaled */
     359#define EXT4_INODE_FLAG_NOTAIL        0x00008000  /* File tail should not be merged */
     360#define EXT4_INODE_FLAG_DIRSYNC       0x00010000  /* Dirsync behaviour (directories only) */
     361#define EXT4_INODE_FLAG_TOPDIR        0x00020000  /* Top of directory hierarchies */
     362#define EXT4_INODE_FLAG_HUGE_FILE     0x00040000  /* Set to each huge file */
     363#define EXT4_INODE_FLAG_EXTENTS       0x00080000  /* Inode uses extents */
     364#define EXT4_INODE_FLAG_EA_INODE      0x00200000  /* Inode used for large EA */
     365#define EXT4_INODE_FLAG_EOFBLOCKS     0x00400000  /* Blocks allocated beyond EOF */
     366#define EXT4_INODE_FLAG_RESERVED      0x80000000  /* reserved for ext4 lib */
     367
     368#define EXT4_INODE_ROOT_INDEX  2
    374369
    375370typedef struct ext4_inode_ref {
    376         block_t *block; // Reference to a block containing this inode
     371        block_t *block;         /* Reference to a block containing this inode */
    377372        ext4_inode_t *inode;
    378373        ext4_filesystem_t *fs;
    379         uint32_t index; // Index number of this inode
     374        uint32_t index;         /* Index number of this inode */
    380375        bool dirty;
    381376} ext4_inode_ref_t;
    382377
    383 /*****************************************************************************/
    384 
    385 #define EXT4_DIRECTORY_FILENAME_LEN     255
    386 
    387 #define EXT4_DIRECTORY_FILETYPE_UNKNOWN         0
    388 #define EXT4_DIRECTORY_FILETYPE_REG_FILE        1
    389 #define EXT4_DIRECTORY_FILETYPE_DIR             2
    390 #define EXT4_DIRECTORY_FILETYPE_CHRDEV          3
    391 #define EXT4_DIRECTORY_FILETYPE_BLKDEV          4
    392 #define EXT4_DIRECTORY_FILETYPE_FIFO            5
    393 #define EXT4_DIRECTORY_FILETYPE_SOCK            6
    394 #define EXT4_DIRECTORY_FILETYPE_SYMLINK         7
     378
     379#define EXT4_DIRECTORY_FILENAME_LEN  255
     380
     381#define EXT4_DIRECTORY_FILETYPE_UNKNOWN   0
     382#define EXT4_DIRECTORY_FILETYPE_REG_FILE  1
     383#define EXT4_DIRECTORY_FILETYPE_DIR       2
     384#define EXT4_DIRECTORY_FILETYPE_CHRDEV    3
     385#define EXT4_DIRECTORY_FILETYPE_BLKDEV    4
     386#define EXT4_DIRECTORY_FILETYPE_FIFO      5
     387#define EXT4_DIRECTORY_FILETYPE_SOCK      6
     388#define EXT4_DIRECTORY_FILETYPE_SYMLINK   7
    395389
    396390/**
     
    398392 */
    399393typedef struct ext4_directory_entry_ll {
    400         uint32_t inode; // Inode for the entry
    401         uint16_t entry_length; // Distance to the next directory entry
    402         uint8_t name_length; // Lower 8 bits of name length
     394        uint32_t inode;         /* I-node for the entry */
     395        uint16_t entry_length;  /* Distance to the next directory entry */
     396        uint8_t name_length;    /* Lower 8 bits of name length */
     397       
    403398        union {
    404                 uint8_t name_length_high; // Higher 8 bits of name length
    405                 uint8_t inode_type; // Type of referenced inode (in rev >= 0.5)
     399                uint8_t name_length_high;  /* Higher 8 bits of name length */
     400                uint8_t inode_type;        /* Type of referenced inode (in rev >= 0.5) */
    406401        } __attribute__ ((packed));
    407         uint8_t name[EXT4_DIRECTORY_FILENAME_LEN]; // Entry name
    408 } __attribute__ ((packed)) ext4_directory_entry_ll_t;
     402       
     403        uint8_t name[EXT4_DIRECTORY_FILENAME_LEN];  /* Entry name */
     404} __attribute__((packed)) ext4_directory_entry_ll_t;
    409405
    410406typedef struct ext4_directory_iterator {
     
    420416} ext4_directory_search_result_t;
    421417
    422 
    423 /*****************************************************************************/
    424 
    425418/* Structures for indexed directory */
    426419
    427420typedef struct ext4_directory_dx_countlimit {
    428421        uint16_t limit;
    429     uint16_t count;
     422        uint16_t count;
    430423} ext4_directory_dx_countlimit_t;
    431424
     
    433426        uint32_t inode;
    434427        uint16_t entry_length;
    435     uint8_t name_length;
    436     uint8_t inode_type;
    437     uint8_t name[4];
     428        uint8_t name_length;
     429        uint8_t inode_type;
     430        uint8_t name[4];
    438431} ext4_directory_dx_dot_entry_t;
    439432
     
    452445
    453446typedef struct ext4_directory_dx_root {
    454                 ext4_directory_dx_dot_entry_t dots[2];
    455                 ext4_directory_dx_root_info_t info;
    456                 ext4_directory_dx_entry_t entries[0];
     447        ext4_directory_dx_dot_entry_t dots[2];
     448        ext4_directory_dx_root_info_t info;
     449        ext4_directory_dx_entry_t entries[0];
    457450} ext4_directory_dx_root_t;
    458451
     
    469462} ext4_directory_dx_node_t;
    470463
    471 
    472464typedef struct ext4_directory_dx_block {
    473465        block_t *block;
     
    476468} ext4_directory_dx_block_t;
    477469
    478 
    479 
    480 #define EXT4_ERR_BAD_DX_DIR                     (-75000)
    481 #define EXT4_DIRECTORY_HTREE_EOF        (uint32_t)0x7fffffff
    482 
    483 /*****************************************************************************/
     470#define EXT4_ERR_BAD_DX_DIR       (-75000)
     471#define EXT4_DIRECTORY_HTREE_EOF  UINT32_C(0x7fffffff)
    484472
    485473/*
     
    488476 */
    489477typedef struct ext4_extent {
    490         uint32_t first_block; // First logical block extent covers
    491         uint16_t block_count; // Number of blocks covered by extent
    492         uint16_t start_hi;    // High 16 bits of physical block
    493         uint32_t start_lo;    // Low 32 bits of physical block
     478        uint32_t first_block;  /* First logical block extent covers */
     479        uint16_t block_count;  /* Number of blocks covered by extent */
     480        uint16_t start_hi;     /* High 16 bits of physical block */
     481        uint32_t start_lo;     /* Low 32 bits of physical block */
    494482} ext4_extent_t;
    495483
     
    499487 */
    500488typedef struct ext4_extent_index {
    501         uint32_t first_block; // Index covers logical blocks from 'block'
    502         uint32_t leaf_lo; /* Pointer to the physical block of the next
    503                                            * level. leaf or next index could be there */
    504         uint16_t leaf_hi;     /* high 16 bits of physical block */
     489        uint32_t first_block;  /* Index covers logical blocks from 'block' */
     490       
     491        /**
     492         * Pointer to the physical block of the next
     493         * level. leaf or next index could be there
     494         * high 16 bits of physical block
     495         */
     496        uint32_t leaf_lo;
     497        uint16_t leaf_hi;
    505498        uint16_t padding;
    506499} ext4_extent_index_t;
     
    511504typedef struct ext4_extent_header {
    512505        uint16_t magic;
    513         uint16_t entries_count; // Number of valid entries
    514         uint16_t max_entries_count; // Capacity of store in entries
    515         uint16_t depth; // Has tree real underlying blocks?
    516         uint32_t generation; // generation of the tree
     506        uint16_t entries_count;      /* Number of valid entries */
     507        uint16_t max_entries_count;  /* Capacity of store in entries */
     508        uint16_t depth;              /* Has tree real underlying blocks? */
     509        uint32_t generation;         /* generation of the tree */
    517510} ext4_extent_header_t;
    518511
     
    525518} ext4_extent_path_t;
    526519
    527 #define EXT4_EXTENT_MAGIC       0xF30A
    528 #define EXT4_EXTENT_FIRST(header)       \
    529                 ((ext4_extent_t *) (((void *) (header)) + sizeof(ext4_extent_header_t)))
    530 #define EXT4_EXTENT_FIRST_INDEX(header) \
    531                 ((ext4_extent_index_t *) (((void *) (header)) + sizeof(ext4_extent_header_t)))
    532 
    533 /*****************************************************************************/
    534 
    535 #define EXT4_HASH_VERSION_LEGACY                        0
    536 #define EXT4_HASH_VERSION_HALF_MD4                      1
    537 #define EXT4_HASH_VERSION_TEA                           2
    538 #define EXT4_HASH_VERSION_LEGACY_UNSIGNED       3
    539 #define EXT4_HASH_VERSION_HALF_MD4_UNSIGNED     4
    540 #define EXT4_HASH_VERSION_TEA_UNSIGNED          5
     520#define EXT4_EXTENT_MAGIC  0xF30A
     521
     522#define EXT4_EXTENT_FIRST(header) \
     523        ((ext4_extent_t *) (((void *) (header)) + sizeof(ext4_extent_header_t)))
     524
     525#define EXT4_EXTENT_FIRST_INDEX(header) \
     526        ((ext4_extent_index_t *) (((void *) (header)) + sizeof(ext4_extent_header_t)))
     527
     528#define EXT4_HASH_VERSION_LEGACY             0
     529#define EXT4_HASH_VERSION_HALF_MD4           1
     530#define EXT4_HASH_VERSION_TEA                2
     531#define EXT4_HASH_VERSION_LEGACY_UNSIGNED    3
     532#define EXT4_HASH_VERSION_HALF_MD4_UNSIGNED  4
     533#define EXT4_HASH_VERSION_TEA_UNSIGNED       5
    541534
    542535typedef struct ext4_hash_info {
Note: See TracChangeset for help on using the changeset viewer.