Changeset 711e1f32 in mainline


Ignore:
Timestamp:
2010-01-13T21:33:58Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2ffaab5, 990c70e
Parents:
65737d4
Message:

Do some sanity checks when mounting a fat file system.

Location:
uspace/srv/fs/fat
Files:
3 edited

Legend:

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

    r65737d4 r711e1f32  
    247247 */
    248248int
    249 fat_get_cluster(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t clst,
    250     fat_cluster_t *value)
     249fat_get_cluster(fat_bs_t *bs, dev_handle_t dev_handle, unsigned fatno,
     250    fat_cluster_t clst, fat_cluster_t *value)
    251251{
    252252        block_t *b;
    253253        uint16_t bps;
    254254        uint16_t rscnt;
     255        uint16_t sf;
    255256        fat_cluster_t *cp;
    256257        int rc;
     
    258259        bps = uint16_t_le2host(bs->bps);
    259260        rscnt = uint16_t_le2host(bs->rscnt);
    260 
    261         rc = block_get(&b, dev_handle, rscnt +
     261        sf = uint16_t_le2host(bs->sec_per_fat);
     262
     263        rc = block_get(&b, dev_handle, rscnt + sf * fatno +
    262264            (clst * sizeof(fat_cluster_t)) / bps, BLOCK_FLAGS_NONE);
    263265        if (rc != EOK)
     
    480482        while (firstc < FAT_CLST_LAST1) {
    481483                assert(firstc >= FAT_CLST_FIRST && firstc < FAT_CLST_BAD);
    482                 rc = fat_get_cluster(bs, dev_handle, firstc, &nextc);
     484                rc = fat_get_cluster(bs, dev_handle, FAT1, firstc, &nextc);
    483485                if (rc != EOK)
    484486                        return rc;
     
    560562                unsigned fatno;
    561563
    562                 rc = fat_get_cluster(bs, dev_handle, lastc, &nextc);
     564                rc = fat_get_cluster(bs, dev_handle, FAT1, lastc, &nextc);
    563565                if (rc != EOK)
    564566                        return rc;
  • uspace/srv/fs/fat/fat_fat.h

    r65737d4 r711e1f32  
    8080extern int fat_alloc_shadow_clusters(struct fat_bs *, dev_handle_t,
    8181    fat_cluster_t *, unsigned);
    82 extern int fat_get_cluster(struct fat_bs *, dev_handle_t, fat_cluster_t,
    83     fat_cluster_t *);
     82extern int fat_get_cluster(struct fat_bs *, dev_handle_t, unsigned,
     83    fat_cluster_t, fat_cluster_t *);
    8484extern int fat_set_cluster(struct fat_bs *, dev_handle_t, unsigned,
    8585    fat_cluster_t, fat_cluster_t);
  • uspace/srv/fs/fat/fat_ops.c

    r65737d4 r711e1f32  
    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.