Changeset 875edff6 in mainline


Ignore:
Timestamp:
2011-04-30T11:22:28Z (13 years ago)
Author:
Oleg Romanenko <romanenko.oleg@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
aa2ea13
Parents:
cb052b4
Message:

It is possible to mount FAT32 file system.
Changes:

  1. 32bit fat_cluster_t
  2. Change macros SF(bs) to add support FAT32 sectors per fat value
  3. New macros (FAT_CLST_SIZE) for determining size of FAT cluster (2 or 4 bytes)
  4. New macros (FAT_MASK) for determining necessary mask for cluster value depending on FAT type
  5. fat_get_cluster support FAT32 and correctly return cluster value
  6. Change fat_sanity_check() to add support FAT32. Wrapping explicit use of br→(value) with macros.

TODO: need to wrap all explicit use of br→() with appropriated macros.

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

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/fat/fat.h

    rcb052b4 r875edff6  
    5555#define RSCNT(bs)       uint16_t_le2host((bs)->rscnt)
    5656#define FATCNT(bs)      (bs)->fatcnt
    57 #define SF(bs)          uint16_t_le2host((bs)->sec_per_fat)
     57#define SF(bs)          (uint16_t_le2host((bs)->sec_per_fat) !=0 ? \
     58    uint16_t_le2host((bs)->sec_per_fat) : \
     59    uint32_t_le2host(bs->fat32.sectors_per_fat))
    5860#define RDE(bs)         uint16_t_le2host((bs)->root_ent_max)
    5961#define TS(bs)          (uint16_t_le2host((bs)->totsec16) != 0 ? \
  • uspace/srv/fs/fat/fat_fat.c

    rcb052b4 r875edff6  
    301301
    302302        assert(fatno < FATCNT(bs));
     303       
     304        *value = 0;
    303305
    304306        if (FAT_IS_FAT12(bs))
    305307                offset = (clst + clst/2);
    306308        else
    307                 offset = (clst * sizeof(fat_cluster_t));
     309                offset = (clst * FAT_CLST_SIZE(bs));
    308310
    309311        rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +
     
    313315
    314316        /* This cluster access spans a sector boundary. Check only for FAT12 */
    315         if (FAT_IS_FAT12(bs) && (offset % BPS(bs)+1 == BPS(bs))) {
    316                 /* Is it last sector of FAT? */
    317                 if (offset / BPS(bs) < SF(bs)) {
    318                         /* No. Reading next sector */
    319                         rc = block_get(&b1, devmap_handle, 1 + RSCNT(bs) +
    320                             SF(bs)*fatno + offset / BPS(bs), BLOCK_FLAGS_NONE);
    321                         if (rc != EOK) {
     317        if (FAT_IS_FAT12(bs)) {
     318                if ((offset % BPS(bs) + 1 == BPS(bs))) {
     319                        /* Is it last sector of FAT? */
     320                        if (offset / BPS(bs) < SF(bs)) {
     321                                /* No. Reading next sector */
     322                                rc = block_get(&b1, devmap_handle, 1 + RSCNT(bs) +
     323                                        SF(bs)*fatno + offset / BPS(bs), BLOCK_FLAGS_NONE);
     324                                if (rc != EOK) {
     325                                        block_put(b);
     326                                        return rc;
     327                                }
     328                                /*
     329                                * Combining value with last byte of current sector and
     330                                * first byte of next sector
     331                                */
     332                                *value  = *(uint8_t *)(b->data + BPS(bs) - 1);
     333                                *value |= *(uint8_t *)(b1->data);
     334
     335                                rc = block_put(b1);
     336                                if (rc != EOK) {
     337                                        block_put(b);
     338                                        return rc;
     339                                }
     340                        }
     341                        else {
     342                                /* Yes. It is last sector of FAT */
    322343                                block_put(b);
    323                                 return rc;
     344                                return ERANGE;
    324345                        }
    325                         /*
    326                          * Combining value with last byte of current sector and
    327                          * first byte of next sector
    328                          */
    329                         *value  = *(uint8_t *)(b->data + BPS(bs) - 1);
    330                         *value |= *(uint8_t *)(b1->data);
    331 
    332                         rc = block_put(b1);
    333                         if (rc != EOK) {
    334                                 block_put(b);
    335                                 return rc;
    336                         }
    337                 }
    338                 else {
    339                         /* Yes. It is last sector of FAT */
    340                         block_put(b);
    341                         return ERANGE;
    342                 }
    343         }
    344         else
    345                 *value = *(fat_cluster_t *)(b->data + offset % BPS(bs));
    346 
    347         if (FAT_IS_FAT12(bs)) {
     346                }
     347
    348348                if (clst & 0x0001)
    349                 *value = (*value) >> 4;
     349                        *value = (*value) >> 4;
    350350                else
    351                 *value = (*value) & 0x0fff;
     351                        *value = (*value) & FAT12_MASK;
     352        }
     353        else {
     354                if (FAT_IS_FAT32(bs))
     355                        *value = *(uint32_t *)(b->data + offset % BPS(bs)) & FAT32_MASK;
     356                else
     357                        *value = *(uint16_t *)(b->data + offset % BPS(bs));
    352358        }
    353359
     
    383389                offset = (clst + clst/2);
    384390        else
    385                 offset = (clst * sizeof(fat_cluster_t));
     391                offset = (clst * FAT_CLST_SIZE(bs));
    386392
    387393        rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +
     
    734740
    735741        /* Check number of FATs. */
    736         if (bs->fatcnt == 0)
     742        if (FATCNT(bs) == 0)
    737743                return ENOTSUP;
    738744
    739745        /* Check total number of sectors. */
    740         if (bs->totsec16 == 0 && bs->totsec32 == 0)
     746        if (TS(bs) == 0)
    741747                return ENOTSUP;
    742748
     
    750756
    751757        /* Check number of sectors per FAT. */
    752         if (bs->sec_per_fat == 0)
     758        if (SF(bs) == 0)
    753759                return ENOTSUP;
    754760
     
    760766         * sanitized to support file systems with this property.
    761767         */
    762         if ((uint16_t_le2host(bs->root_ent_max) * sizeof(fat_dentry_t)) %
    763             uint16_t_le2host(bs->bps) != 0)
     768        if (!FAT_IS_FAT32(bs) && (RDE(bs) * sizeof(fat_dentry_t)) % BPS(bs) != 0)
    764769                return ENOTSUP;
    765770
    766771        /* Check signature of each FAT. */
    767         for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) {
     772        for (fat_no = 0; fat_no < FATCNT(bs); fat_no++) {
    768773                rc = fat_get_cluster(bs, devmap_handle, fat_no, 0, &e0);
    769774                if (rc != EOK)
     
    782787                 * set to one.
    783788                 */
    784                 if (!FAT_IS_FAT12(bs) && ((e0 >> 8) != 0xff || e1 != 0xffff))
     789                if (!FAT_IS_FAT12(bs) && ((e0 >> 8) != (FAT_MASK(bs) >> 8) || e1 != FAT_MASK(bs)))
    785790                        return ENOTSUP;
    786791        }
  • uspace/srv/fs/fat/fat_fat.h

    rcb052b4 r875edff6  
    5454#define FAT32_CLST_LAST8  0x0fffffff
    5555
     56#define FAT12_MASK                0x0fff
     57#define FAT16_MASK                0xffff
     58#define FAT32_MASK                0x0fffffff
     59
    5660#define FAT12_CLST_MAX    4085
    5761#define FAT16_CLST_MAX    65525
     62
     63/* Size in bytes for cluster value of FAT */
     64#define FAT12_CLST_SIZE   2
     65#define FAT16_CLST_SIZE   2
     66#define FAT32_CLST_SIZE   4
    5867
    5968/* internally used to mark root directory's parent */
     
    8493    (FAT_IS_FAT12(bs) ? FAT12_CLST_BAD : (FAT_IS_FAT32(bs) ? FAT32_CLST_BAD : FAT16_CLST_BAD))
    8594
     95#define FAT_CLST_SIZE(bs)       (FAT_IS_FAT32(bs) ? FAT32_CLST_SIZE : FAT16_CLST_SIZE)
     96
     97#define FAT_MASK(bs) \
     98    (FAT_IS_FAT12(bs) ? FAT12_MASK : (FAT_IS_FAT32(bs) ? FAT32_MASK : FAT16_MASK))
     99
    86100/* forward declarations */
    87101struct block;
     
    89103struct fat_bs;
    90104
    91 typedef uint16_t fat_cluster_t;
     105typedef uint32_t fat_cluster_t;
    92106
    93107#define fat_clusters_get(numc, bs, dh, fc) \
Note: See TracChangeset for help on using the changeset viewer.