Ignore:
Timestamp:
2012-05-28T09:56:44Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4585bda
Parents:
d0c9b4b
Message:

checks by mount operation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 !!!
Note: See TracChangeset for help on using the changeset viewer.