Ignore:
File:
1 edited

Legend:

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

    r3f93cdbe r50f9c3a  
    4646#include <align.h>
    4747#include <assert.h>
    48 #include <fibril_synch.h>
     48#include <fibril_sync.h>
    4949#include <mem.h>
    5050
     
    247247 */
    248248int
    249 fat_get_cluster(fat_bs_t *bs, dev_handle_t dev_handle, unsigned fatno,
    250     fat_cluster_t clst, fat_cluster_t *value)
     249fat_get_cluster(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t clst,
     250    fat_cluster_t *value)
    251251{
    252252        block_t *b;
    253253        uint16_t bps;
    254254        uint16_t rscnt;
    255         uint16_t sf;
    256255        fat_cluster_t *cp;
    257256        int rc;
     
    259258        bps = uint16_t_le2host(bs->bps);
    260259        rscnt = uint16_t_le2host(bs->rscnt);
    261         sf = uint16_t_le2host(bs->sec_per_fat);
    262 
    263         rc = block_get(&b, dev_handle, rscnt + sf * fatno +
     260
     261        rc = block_get(&b, dev_handle, rscnt +
    264262            (clst * sizeof(fat_cluster_t)) / bps, BLOCK_FLAGS_NONE);
    265263        if (rc != EOK)
     
    361359        uint16_t rscnt;
    362360        uint16_t sf;
    363         uint32_t ts;
     361        uint16_t ts;
    364362        unsigned rde;
    365363        unsigned rds;
     
    379377        sf = uint16_t_le2host(bs->sec_per_fat);
    380378        rde = uint16_t_le2host(bs->root_ent_max);
    381         ts = (uint32_t) uint16_t_le2host(bs->totsec16);
    382         if (ts == 0)
    383                 ts = uint32_t_le2host(bs->totsec32);
     379        ts = uint16_t_le2host(bs->totsec16);
    384380
    385381        rds = (sizeof(fat_dentry_t) * rde) / bps;
     
    484480        while (firstc < FAT_CLST_LAST1) {
    485481                assert(firstc >= FAT_CLST_FIRST && firstc < FAT_CLST_BAD);
    486                 rc = fat_get_cluster(bs, dev_handle, FAT1, firstc, &nextc);
     482                rc = fat_get_cluster(bs, dev_handle, firstc, &nextc);
    487483                if (rc != EOK)
    488484                        return rc;
     
    564560                unsigned fatno;
    565561
    566                 rc = fat_get_cluster(bs, dev_handle, FAT1, lastc, &nextc);
     562                rc = fat_get_cluster(bs, dev_handle, lastc, &nextc);
    567563                if (rc != EOK)
    568564                        return rc;
     
    610606}
    611607
    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  */
    618 int 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 
    682608/**
    683609 * @}
Note: See TracChangeset for help on using the changeset viewer.