Changeset 990c70e in mainline for uspace/srv/fs/fat/fat_ops.c


Ignore:
Timestamp:
2010-01-13T21:35:15Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
aa53ee69
Parents:
fd608dc (diff), 711e1f32 (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 FAT sanity checks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/fat/fat_ops.c

    rfd608dc r990c70e  
    290290
    291291        *nodepp = nodep;
     292        return EOK;
     293}
     294
     295/** Perform basic sanity checks on the file system.
     296 *
     297 * Verify if values of boot sector fields are sane. Also verify media
     298 * descriptor. This is used to rule out cases when a device obviously
     299 * does not contain a fat file system.
     300 */
     301static int fat_sanity_check(fat_bs_t *bs, dev_handle_t dev_handle)
     302{
     303        fat_cluster_t e0, e1;
     304        unsigned fat_no;
     305        int rc;
     306
     307        printf("fatcnt\n");
     308        /* Check number of FATs. */
     309        if (bs->fatcnt == 0)
     310                return ENOTSUP;
     311
     312        /* Check total number of sectors. */
     313
     314        printf("totsec\n");
     315        if (bs->totsec16 == 0 && bs->totsec32 == 0)
     316                return ENOTSUP;
     317
     318        if (bs->totsec16 != 0 && bs->totsec32 != 0 &&
     319            bs->totsec16 != bs->totsec32)
     320                return ENOTSUP;
     321
     322        printf("mdesc\n");
     323        /* Check media descriptor. Must be between 0xf0 and 0xff. */
     324        if ((bs->mdesc & 0xf0) != 0xf0)
     325                return ENOTSUP;
     326
     327        printf("sec_per_fat\n");
     328        /* Check number of sectors per FAT. */
     329        if (bs->sec_per_fat == 0)
     330                return ENOTSUP;
     331
     332        /* Check signature of each FAT. */
     333
     334        for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) {
     335                printf("clst-read\n");
     336                rc = fat_get_cluster(bs, dev_handle, fat_no, 0, &e0);
     337                if (rc != EOK)
     338                        return EIO;
     339
     340                rc = fat_get_cluster(bs, dev_handle, fat_no, 1, &e1);
     341                if (rc != EOK)
     342                        return EIO;
     343
     344                printf("mdesc-fat\n");
     345                /* Check that first byte of FAT contains the media descriptor. */
     346                if ((e0 & 0xff) != bs->mdesc)
     347                        return ENOTSUP;
     348
     349                printf("fat-signat\n");
     350                /*
     351                 * Check that remaining bits of the first two entries are
     352                 * set to one.
     353                 */
     354                if ((e0 >> 8) != 0xff || e1 != 0xffff)
     355                        return ENOTSUP;
     356        }
     357
    292358        return EOK;
    293359}
     
    9811047        }
    9821048
     1049        /* Do some simple sanity checks on the boot blocks. */
     1050        rc = fat_sanity_check(bs, dev_handle);
     1051        if (rc != EOK) {
     1052                block_fini(dev_handle);
     1053                ipc_answer_0(rid, rc);
     1054                return;
     1055        }
     1056
    9831057        rc = fat_idx_init_by_dev_handle(dev_handle);
    9841058        if (rc != EOK) {
Note: See TracChangeset for help on using the changeset viewer.