Changeset df3caec5 in mainline


Ignore:
Timestamp:
2011-10-14T20:01:24Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3958e315, 4c3ad56
Parents:
2ac7af3
Message:

Add basic MINIX filesystem sanity check

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/mfs/mfs_ops.c

    r2ac7af3 rdf3caec5  
    6969static int mfs_instance_get(service_id_t service_id,
    7070    struct mfs_instance **instance);
    71 
     71static int mfs_check_sanity(struct mfs_sb_info *sbi);
     72static bool is_power_of_two(uint32_t n);
    7273
    7374static hash_table_t open_nodes;
     
    261262
    262263        sbi->itable_off = 2 + sbi->ibmap_blocks + sbi->zbmap_blocks;
     264        if ((rc = mfs_check_sanity(sbi)) != EOK) {
     265                fprintf(stderr, "Filesystem corrupted, invalid superblock");
     266                goto out_error;
     267        }
    263268
    264269        rc = block_cache_init(service_id, sbi->block_size, 0, cmode);
     
    10711076}
    10721077
     1078/** Filesystem sanity check
     1079 *
     1080 * @param Pointer to the MFS superblock.
     1081 *
     1082 * @return EOK on success, ENOTSUP otherwise.
     1083 */
     1084static int
     1085mfs_check_sanity(struct mfs_sb_info *sbi)
     1086{
     1087        if (!is_power_of_two(sbi->block_size) ||
     1088            sbi->block_size < MFS_MIN_BLOCKSIZE ||
     1089            sbi->block_size > MFS_MAX_BLOCKSIZE)
     1090                return ENOTSUP;
     1091        else if (sbi->ibmap_blocks == 0 || sbi->zbmap_blocks == 0)
     1092                return ENOTSUP;
     1093        else if (sbi->ninodes == 0 || sbi->nzones == 0)
     1094                return ENOTSUP;
     1095        else if (sbi->firstdatazone == 0)
     1096                return ENOTSUP;
     1097
     1098        return EOK;
     1099}
     1100
    10731101static int
    10741102mfs_close(service_id_t service_id, fs_index_t index)
     
    10911119
    10921120        return mfs_node_put(fn);
     1121}
     1122
     1123/** Check if a given number is a power of two.
     1124 *
     1125 * @param n     The number to check.
     1126 *
     1127 * @return      true if it is a power of two, false otherwise.
     1128 */
     1129static bool
     1130is_power_of_two(uint32_t n)
     1131{
     1132        if (n == 0)
     1133                return false;
     1134
     1135        return (n & (n - 1)) == 0;
    10931136}
    10941137
Note: See TracChangeset for help on using the changeset viewer.