Changeset 1d6f507 in mainline


Ignore:
Timestamp:
2011-02-14T22:20:09Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d241aae
Parents:
3949e8a0
Message:

Add some basic sanity checks

Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/ext2info/ext2info.c

    r3949e8a0 r1d6f507  
    8888        if (rc != EOK)  {
    8989                printf(NAME ": Error initializing libext2.\n");
     90                return 3;
     91        }
     92       
     93        rc = ext2_filesystem_check_sanity(&filesystem);
     94        if (rc != EOK) {
     95                printf(NAME ": Filesystem did not pass sanity check.\n");
    9096                return 3;
    9197        }
  • uspace/lib/ext2/libext2_filesystem.c

    r3949e8a0 r1d6f507  
    4646 * @param fs                    Pointer to ext2_filesystem_t to initialize
    4747 * @param devmap_handle Device handle of the block device
     48 *
     49 * @return              EOK on success or negative error code on failure
    4850 */
    4951int ext2_filesystem_init(ext2_filesystem_t *fs, devmap_handle_t devmap_handle)
     
    8587
    8688/**
     89 * Check filesystem for sanity
     90 *
     91 * @param fs                    Pointer to ext2_filesystem_t to check
     92 * @return              EOK on success or negative error code on failure
     93 */
     94int ext2_filesystem_check_sanity(ext2_filesystem_t *fs)
     95{
     96        int rc;
     97       
     98        rc = ext2_superblock_check_sanity(fs->superblock);
     99        if (rc != EOK) {
     100                return rc;
     101        }
     102       
     103        return EOK;
     104}
     105
     106/**
    87107 * Finalize an instance of filesystem
    88108 *
  • uspace/lib/ext2/libext2_filesystem.h

    r3949e8a0 r1d6f507  
    5151
    5252extern int ext2_filesystem_init(ext2_filesystem_t *, devmap_handle_t);
     53extern int ext2_filesystem_check_sanity(ext2_filesystem_t *);
    5354extern void ext2_filesystem_fini(ext2_filesystem_t *);
    5455
  • uspace/lib/ext2/libext2_superblock.c

    r3949e8a0 r1d6f507  
    247247}
    248248
     249/**
     250 * Get count of inodes per block group
     251 *
     252 * @param sb pointer to superblock
     253 */
     254inline uint32_t ext2_superblock_get_inodes_per_group(ext2_superblock_t *sb)
     255{
     256        return uint32_t_le2host(sb->inodes_per_group);
     257}
     258
     259/**
     260 * Compute count of block groups present in the filesystem
     261 *
     262 * @param sb pointer to superblock
     263 */
     264inline uint32_t ext2_superblock_get_block_group_count(ext2_superblock_t *sb)
     265{
     266        return ext2_superblock_get_total_block_count(sb) /
     267            ext2_superblock_get_blocks_per_group(sb);
     268}
     269
    249270/** Read a superblock directly from device (i.e. no libblock cache)
    250271 *
     
    276297}
    277298
     299/** Check a superblock for sanity
     300 *
     301 * @param sb    Pointer to superblock
     302 *
     303 * @return              EOK on success or negative error code on failure.
     304 */
     305int ext2_superblock_check_sanity(ext2_superblock_t *sb)
     306{
     307        if (ext2_superblock_get_magic(sb) != EXT2_SUPERBLOCK_MAGIC) {
     308                return ENOTSUP;
     309        }
     310       
     311        if (ext2_superblock_get_rev_major(sb) > 1) {
     312                return ENOTSUP;
     313        }
     314       
     315        if (ext2_superblock_get_total_inode_count(sb) == 0) {
     316                return ENOTSUP;
     317        }
     318       
     319        if (ext2_superblock_get_total_block_count(sb) == 0) {
     320                return ENOTSUP;
     321        }
     322       
     323        if (ext2_superblock_get_blocks_per_group(sb) == 0) {
     324                return ENOTSUP;
     325        }
     326       
     327        if (ext2_superblock_get_fragments_per_group(sb) == 0) {
     328                return ENOTSUP;
     329        }
     330       
     331        // We don't support fragments smaller than block
     332        if (ext2_superblock_get_block_size(sb) !=
     333                    ext2_superblock_get_fragment_size(sb)) {
     334                return ENOTSUP;
     335        }
     336        if (ext2_superblock_get_blocks_per_group(sb) !=
     337                    ext2_superblock_get_fragments_per_group(sb)) {
     338                return ENOTSUP;
     339        }
     340       
     341        if (ext2_superblock_get_inodes_per_group(sb) == 0) {
     342                return ENOTSUP;
     343        }
     344       
     345        if (ext2_superblock_get_inode_size(sb) < 128) {
     346                return ENOTSUP;
     347        }
     348       
     349        if (ext2_superblock_get_first_inode(sb) < 11) {
     350                return ENOTSUP;
     351        }
     352       
     353        return EOK;
     354}
     355
    278356
    279357/** @}
  • uspace/lib/ext2/libext2_superblock.h

    r3949e8a0 r1d6f507  
    9999inline uint32_t ext2_superblock_get_free_block_count(ext2_superblock_t *);
    100100inline uint32_t ext2_superblock_get_free_inode_count(ext2_superblock_t *);
     101inline uint32_t ext2_superblock_get_block_group_count(ext2_superblock_t *);
     102inline uint32_t ext2_superblock_get_inodes_per_group(ext2_superblock_t *);
    101103
    102104extern int ext2_superblock_read_direct(devmap_handle_t, ext2_superblock_t **);
     105extern int ext2_superblock_check_sanity(ext2_superblock_t *);
    103106
    104107#endif
Note: See TracChangeset for help on using the changeset viewer.