Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset fb04cd90 in mainline


Ignore:
Timestamp:
2012-05-28T09:56:44Z (9 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
master
Children:
4585bda
Parents:
d0c9b4b
Message:

checks by mount operation

Location:
uspace
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/libext4_block_group.c

    rd0c9b4b rfb04cd90  
    4848                ext4_superblock_t *sb)
    4949{
    50         if (ext4_superblock_get_desc_size(sb) > EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
     50        if (ext4_superblock_get_desc_size(sb) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
    5151                return ((uint64_t)uint32_t_le2host(bg->block_bitmap_hi) << 32) |
    5252                        uint32_t_le2host(bg->block_bitmap_lo);
     
    6767        bg->block_bitmap_lo = host2uint32_t_le((block_bitmap << 32) >> 32);
    6868
    69         if (ext4_superblock_get_desc_size(sb) > EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
     69        if (ext4_superblock_get_desc_size(sb) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
    7070                bg->block_bitmap_hi = host2uint32_t_le(block_bitmap >> 32);
    7171        }
     
    8181                ext4_superblock_t *sb)
    8282{
    83         if (ext4_superblock_get_desc_size(sb) > EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
     83        if (ext4_superblock_get_desc_size(sb) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
    8484                return ((uint64_t)uint32_t_le2host(bg->inode_bitmap_hi) << 32) |
    8585                        uint32_t_le2host(bg->inode_bitmap_lo);
     
    101101        bg->inode_bitmap_lo = host2uint32_t_le((inode_bitmap << 32) >> 32);
    102102
    103         if (ext4_superblock_get_desc_size(sb) > EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
     103        if (ext4_superblock_get_desc_size(sb) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
    104104                bg->inode_bitmap_hi = host2uint32_t_le(inode_bitmap >> 32);
    105105        }
     
    115115                ext4_superblock_t *sb)
    116116{
    117         if (ext4_superblock_get_desc_size(sb) > EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
     117        if (ext4_superblock_get_desc_size(sb) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
    118118                return ((uint64_t)uint32_t_le2host(bg->inode_table_first_block_hi) << 32) |
    119119                        uint32_t_le2host(bg->inode_table_first_block_lo);
     
    136136
    137137        if (ext4_superblock_get_desc_size(sb) >
    138                         EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
     138                        EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
    139139
    140140                bg->inode_table_first_block_hi =
     
    153153{
    154154        if (ext4_superblock_get_desc_size(sb) >
    155                         EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
     155                        EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
    156156
    157157                return ((uint32_t)uint16_t_le2host(bg->free_blocks_count_hi) << 16) |
     
    172172{
    173173        bg->free_blocks_count_lo = host2uint16_t_le((value << 16) >> 16);
    174         if (ext4_superblock_get_desc_size(sb) > EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
     174        if (ext4_superblock_get_desc_size(sb) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
    175175                bg->free_blocks_count_hi = host2uint16_t_le(value >> 16);
    176176        }
     
    186186                ext4_superblock_t *sb)
    187187{
    188         if (ext4_superblock_get_desc_size(sb) > EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
     188        if (ext4_superblock_get_desc_size(sb) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
    189189                return ((uint32_t)uint16_t_le2host(bg->free_inodes_count_hi) << 16) |
    190190                        uint16_t_le2host(bg->free_inodes_count_lo);
     
    204204{
    205205        bg->free_inodes_count_lo = host2uint16_t_le((value << 16) >> 16);
    206         if (ext4_superblock_get_desc_size(sb) > EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
     206        if (ext4_superblock_get_desc_size(sb) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
    207207                bg->free_inodes_count_hi = host2uint16_t_le(value >> 16);
    208208        }
     
    218218                ext4_superblock_t *sb)
    219219{
    220         if (ext4_superblock_get_desc_size(sb) > EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
     220        if (ext4_superblock_get_desc_size(sb) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
    221221                return ((uint32_t)uint16_t_le2host(bg->used_dirs_count_hi) << 16) |
    222222                        uint16_t_le2host(bg->used_dirs_count_lo);
     
    236236{
    237237        bg->used_dirs_count_lo = host2uint16_t_le((count << 16) >> 16);
    238         if (ext4_superblock_get_desc_size(sb) > EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
     238        if (ext4_superblock_get_desc_size(sb) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
    239239                bg->used_dirs_count_hi = host2uint16_t_le(count >> 16);
    240240        }
     
    270270                ext4_superblock_t *sb)
    271271{
    272         if (ext4_superblock_get_desc_size(sb) > EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
     272        if (ext4_superblock_get_desc_size(sb) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
    273273                return ((uint32_t)uint16_t_le2host(bg->itable_unused_hi) << 16) |
    274274                        uint16_t_le2host(bg->itable_unused_lo);
     
    288288{
    289289        bg->itable_unused_lo = host2uint16_t_le((value << 16) >> 16);
    290         if (ext4_superblock_get_desc_size(sb) > EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
     290        if (ext4_superblock_get_desc_size(sb) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
    291291                bg->itable_unused_hi = host2uint16_t_le(value >> 16);
    292292        }
  • uspace/lib/ext4/libext4_filesystem.c

    rd0c9b4b rfb04cd90  
    9595        fs->superblock = temp_superblock;
    9696
     97        uint16_t state = ext4_superblock_get_state(fs->superblock);
     98
     99        if (state != EXT4_SUPERBLOCK_STATE_VALID_FS) {
     100                return ENOTSUP;
     101        }
     102
     103        // Mark system as mounted
     104        ext4_superblock_set_state(fs->superblock, EXT4_SUPERBLOCK_STATE_ERROR_FS);
     105        rc = ext4_superblock_write_direct(fs->device, fs->superblock);
     106        if (rc != EOK) {
     107                return rc;
     108        }
     109
    97110        return EOK;
    98111}
     
    104117 * @return                      error code
    105118 */
    106 int ext4_filesystem_fini(ext4_filesystem_t *fs, bool write_sb)
     119int ext4_filesystem_fini(ext4_filesystem_t *fs)
    107120{
    108121        int rc = EOK;
    109122
    110         // If needed, write the superblock to the device
    111         if (write_sb) {
    112                 rc = ext4_superblock_write_direct(fs->device, fs->superblock);
    113         }
     123        // Write the superblock to the device
     124        ext4_superblock_set_state(fs->superblock, EXT4_SUPERBLOCK_STATE_VALID_FS);
     125        rc = ext4_superblock_write_direct(fs->device, fs->superblock);
    114126
    115127        // Release memory space for superblock
  • uspace/lib/ext4/libext4_filesystem.h

    rd0c9b4b rfb04cd90  
    3838
    3939extern int ext4_filesystem_init(ext4_filesystem_t *, service_id_t);
    40 extern int ext4_filesystem_fini(ext4_filesystem_t *fs, bool);
     40extern int ext4_filesystem_fini(ext4_filesystem_t *fs);
    4141extern int ext4_filesystem_check_sanity(ext4_filesystem_t *fs);
    4242extern int ext4_filesystem_check_features(ext4_filesystem_t *, bool *);
  • uspace/lib/ext4/libext4_superblock.c

    rd0c9b4b rfb04cd90  
    217217}
    218218
     219/** Get logarithmic fragment size (1024 << size)
     220 *
     221 * @param sb            superblock
     222 * @return                      logarithmic fragment size
     223 */
     224uint32_t ext4_superblock_get_log_frag_size(ext4_superblock_t *sb)
     225{
     226        return uint32_t_le2host(sb->log_frag_size);
     227}
     228
     229/** Set logarithmic fragment size (1024 << size)
     230 *
     231 * @param sb            superblock
     232 * @return                      logarithmic fragment size
     233 */
     234
     235void ext4_superblock_set_log_frag_size(ext4_superblock_t *sb, uint32_t frag_size)
     236{
     237        sb->log_frag_size = host2uint32_t_le(frag_size);
     238}
     239
     240/** Get size of fragment (in bytes).
     241 *
     242 * @param sb            superblock
     243 * @return                      size of fragment
     244 */
     245uint32_t ext4_superblock_get_frag_size(ext4_superblock_t *sb)
     246{
     247        return 1024 << ext4_superblock_get_log_frag_size(sb);
     248}
     249
     250/** Set size of fragment (in bytes).
     251 *
     252 * @param sb            superblock
     253 * @param size          size of fragment (must be power of 2, at least 1024)
     254 */
     255void ext4_superblock_set_frag_size(ext4_superblock_t *sb, uint32_t size)
     256{
     257        uint32_t log = 0;
     258        uint32_t tmp = size / EXT4_MIN_BLOCK_SIZE;
     259
     260        tmp >>= 1;
     261        while (tmp) {
     262                log++;
     263                tmp >>= 1;
     264        }
     265
     266        ext4_superblock_set_log_frag_size(sb, log);
     267}
     268
    219269/** Get number of data blocks per block group (except last BG)
    220270 *
     
    236286        sb->blocks_per_group = host2uint32_t_le(blocks);
    237287}
     288
     289/** Get number of fragments per block group (except last BG)
     290 *
     291 * @param sb            superblock
     292 * @return                      fragments per block group
     293 */
     294uint32_t ext4_superblock_get_frags_per_group(ext4_superblock_t *sb)
     295{
     296        return uint32_t_le2host(sb->frags_per_group);
     297}
     298
     299/** Set number of fragment per block group (except last BG)
     300 *
     301 * @param sb            superblock
     302 * @param frags         fragments per block group
     303 */
     304void ext4_superblock_set_frags_per_group(ext4_superblock_t *sb, uint32_t frags)
     305{
     306        sb->frags_per_group = host2uint32_t_le(frags);
     307}
     308
    238309
    239310/** Get number of i-nodes per block group (except last BG)
     
    796867        uint16_t size = uint16_t_le2host(sb->desc_size);
    797868
    798         if (size < EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
    799                 size = EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE;
     869        if (size < EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
     870                size = EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE;
    800871        }
    801872
     
    812883void ext4_superblock_set_desc_size(ext4_superblock_t *sb, uint16_t size)
    813884{
    814         if (size < EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE) {
    815                 sb->desc_size = host2uint16_t_le(EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE);
     885        if (size < EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
     886                sb->desc_size = host2uint16_t_le(EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE);
    816887        }
    817888
     
    9781049        }
    9791050
    980         // block size
    981         // desc size
    982 
     1051        if (ext4_superblock_get_inodes_count(sb) == 0) {
     1052                return ENOTSUP;
     1053        }
     1054
     1055        if (ext4_superblock_get_blocks_count(sb) == 0) {
     1056                return ENOTSUP;
     1057        }
     1058
     1059        if (ext4_superblock_get_blocks_per_group(sb) == 0) {
     1060                return ENOTSUP;
     1061        }
     1062
     1063        if (ext4_superblock_get_inodes_per_group(sb) == 0) {
     1064                return ENOTSUP;
     1065        }
     1066
     1067        if (ext4_superblock_get_inode_size(sb) < 128) {
     1068                return ENOTSUP;
     1069        }
     1070
     1071        if (ext4_superblock_get_first_inode(sb) < 11) {
     1072                return ENOTSUP;
     1073        }
     1074
     1075        if (ext4_superblock_get_desc_size(sb) < EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
     1076                return ENOTSUP;
     1077        }
     1078
     1079        if (ext4_superblock_get_desc_size(sb) > EXT4_MAX_BLOCK_GROUP_DESCRIPTOR_SIZE) {
     1080                return ENOTSUP;
     1081        }
    9831082
    9841083        // TODO more checks !!!
  • uspace/lib/ext4/libext4_superblock.h

    rd0c9b4b rfb04cd90  
    5555extern uint32_t ext4_superblock_get_block_size(ext4_superblock_t *);
    5656extern void ext4_superblock_set_block_size(ext4_superblock_t *, uint32_t);
     57extern uint32_t ext4_superblock_get_log_frag_size(ext4_superblock_t *);
     58extern void ext4_superblock_set_log_frag_size(ext4_superblock_t *, uint32_t);
     59extern uint32_t ext4_superblock_get_frag_size(ext4_superblock_t *);
     60extern void ext4_superblock_set_frag_size(ext4_superblock_t *, uint32_t);
    5761extern uint32_t ext4_superblock_get_blocks_per_group(ext4_superblock_t *);
    5862extern void ext4_superblock_set_blocks_per_group(ext4_superblock_t *, uint32_t);
     63extern uint32_t ext4_superblock_get_frags_per_group(ext4_superblock_t *);
     64extern void ext4_superblock_set_frags_per_group(ext4_superblock_t *, uint32_t);
    5965extern uint32_t ext4_superblock_get_inodes_per_group(ext4_superblock_t *);
    6066extern void ext4_superblock_set_inodes_per_group(ext4_superblock_t *, uint32_t);
  • uspace/lib/ext4/libext4_types.h

    rd0c9b4b rfb04cd90  
    4747        uint32_t first_data_block; // First Data Block
    4848        uint32_t log_block_size; // Block size
    49         uint32_t obso_log_frag_size; // Obsoleted fragment size
     49        uint32_t log_frag_size; // Obsoleted fragment size
    5050        uint32_t blocks_per_group; // Number of blocks per group
    51         uint32_t obso_frags_per_group; // Obsoleted fragments per group
     51        uint32_t frags_per_group; // Obsoleted fragments per group
    5252        uint32_t inodes_per_group; // Number of inodes per group
    5353        uint32_t mount_time; // Mount time
     
    265265
    266266
    267 #define EXT4_BLOCK_MIN_GROUP_DESCRIPTOR_SIZE 32
    268 #define EXT4_BLOCK_MAX_GROUP_DESCRIPTOR_SIZE 64
     267#define EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE 32
     268#define EXT4_MAX_BLOCK_GROUP_DESCRIPTOR_SIZE 64
    269269
    270270/*****************************************************************************/
  • uspace/srv/fs/ext4fs/ext4fs_ops.c

    rd0c9b4b rfb04cd90  
    936936        rc = ext4_filesystem_check_sanity(fs);
    937937        if (rc != EOK) {
    938                 ext4_filesystem_fini(fs, false);
     938                ext4_filesystem_fini(fs);
    939939                free(fs);
    940940                free(inst);
     
    946946        rc = ext4_filesystem_check_features(fs, &read_only);
    947947        if (rc != EOK) {
    948                 ext4_filesystem_fini(fs, false);
     948                ext4_filesystem_fini(fs);
    949949                free(fs);
    950950                free(inst);
     
    962962        rc = ext4fs_node_get_core(&root_node, inst, EXT4_INODE_ROOT_INDEX);
    963963        if (rc != EOK) {
    964                 ext4_filesystem_fini(fs, false);
     964                ext4_filesystem_fini(fs);
    965965                free(fs);
    966966                free(inst);
     
    10151015        fibril_mutex_unlock(&open_nodes_lock);
    10161016
    1017         return ext4_filesystem_fini(inst->filesystem, true);
     1017        return ext4_filesystem_fini(inst->filesystem);
    10181018}
    10191019
Note: See TracChangeset for help on using the changeset viewer.