Changeset e27cf669 in mainline for uspace/srv/fs/fat/fat_fat.c


Ignore:
Timestamp:
2010-02-09T20:19:23Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fb150d78
Parents:
975e7e9 (diff), eb73a50 (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 mainline changes.

File:
1 edited

Legend:

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

    r975e7e9 re27cf669  
    361361        uint16_t rscnt;
    362362        uint16_t sf;
    363         uint16_t ts;
     363        uint32_t ts;
    364364        unsigned rde;
    365365        unsigned rds;
     
    379379        sf = uint16_t_le2host(bs->sec_per_fat);
    380380        rde = uint16_t_le2host(bs->root_ent_max);
    381         ts = uint16_t_le2host(bs->totsec16);
     381        ts = (uint32_t) uint16_t_le2host(bs->totsec16);
     382        if (ts == 0)
     383                ts = uint32_t_le2host(bs->totsec32);
    382384
    383385        rds = (sizeof(fat_dentry_t) * rde) / bps;
     
    608610}
    609611
     612/** Perform basic sanity checks on the file system.
     613 *
     614 * Verify if values of boot sector fields are sane. Also verify media
     615 * descriptor. This is used to rule out cases when a device obviously
     616 * does not contain a fat file system.
     617 */
     618int fat_sanity_check(fat_bs_t *bs, dev_handle_t dev_handle)
     619{
     620        fat_cluster_t e0, e1;
     621        unsigned fat_no;
     622        int rc;
     623
     624        /* Check number of FATs. */
     625        if (bs->fatcnt == 0)
     626                return ENOTSUP;
     627
     628        /* Check total number of sectors. */
     629
     630        if (bs->totsec16 == 0 && bs->totsec32 == 0)
     631                return ENOTSUP;
     632
     633        if (bs->totsec16 != 0 && bs->totsec32 != 0 &&
     634            bs->totsec16 != bs->totsec32)
     635                return ENOTSUP;
     636
     637        /* Check media descriptor. Must be between 0xf0 and 0xff. */
     638        if ((bs->mdesc & 0xf0) != 0xf0)
     639                return ENOTSUP;
     640
     641        /* Check number of sectors per FAT. */
     642        if (bs->sec_per_fat == 0)
     643                return ENOTSUP;
     644
     645        /*
     646         * Check that the root directory entries take up whole blocks.
     647         * This check is rather strict, but it allows us to treat the root
     648         * directory and non-root directories uniformly in some places.
     649         * It can be removed provided that functions such as fat_read() are
     650         * sanitized to support file systems with this property.
     651         */
     652        if ((uint16_t_le2host(bs->root_ent_max) * sizeof(fat_dentry_t)) %
     653            uint16_t_le2host(bs->bps) != 0)
     654                return ENOTSUP;
     655
     656        /* Check signature of each FAT. */
     657
     658        for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) {
     659                rc = fat_get_cluster(bs, dev_handle, fat_no, 0, &e0);
     660                if (rc != EOK)
     661                        return EIO;
     662
     663                rc = fat_get_cluster(bs, dev_handle, fat_no, 1, &e1);
     664                if (rc != EOK)
     665                        return EIO;
     666
     667                /* Check that first byte of FAT contains the media descriptor. */
     668                if ((e0 & 0xff) != bs->mdesc)
     669                        return ENOTSUP;
     670
     671                /*
     672                 * Check that remaining bits of the first two entries are
     673                 * set to one.
     674                 */
     675                if ((e0 >> 8) != 0xff || e1 != 0xffff)
     676                        return ENOTSUP;
     677        }
     678
     679        return EOK;
     680}
     681
    610682/**
    611683 * @}
Note: See TracChangeset for help on using the changeset viewer.