Ignore:
File:
1 edited

Legend:

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

    r1313ee9 r3c11713  
    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        /* Check number of FATs. */
     308        if (bs->fatcnt == 0)
     309                return ENOTSUP;
     310
     311        /* Check total number of sectors. */
     312
     313        if (bs->totsec16 == 0 && bs->totsec32 == 0)
     314                return ENOTSUP;
     315
     316        if (bs->totsec16 != 0 && bs->totsec32 != 0 &&
     317            bs->totsec16 != bs->totsec32)
     318                return ENOTSUP;
     319
     320        /* Check media descriptor. Must be between 0xf0 and 0xff. */
     321        if ((bs->mdesc & 0xf0) != 0xf0)
     322                return ENOTSUP;
     323
     324        /* Check number of sectors per FAT. */
     325        if (bs->sec_per_fat == 0)
     326                return ENOTSUP;
     327
     328        /*
     329         * Check that the root directory entries take up whole blocks.
     330         * This check is rather strict, but it allows us to treat the root
     331         * directory and non-root directories uniformly in some places.
     332         * It can be removed provided that functions such as fat_read() are
     333         * sanitized to support file systems with this property.
     334         */
     335        if ((uint16_t_le2host(bs->root_ent_max) * sizeof(fat_dentry_t)) %
     336            uint16_t_le2host(bs->bps) != 0)
     337                return ENOTSUP;
     338
     339        /* Check signature of each FAT. */
     340
     341        for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) {
     342                rc = fat_get_cluster(bs, dev_handle, fat_no, 0, &e0);
     343                if (rc != EOK)
     344                        return EIO;
     345
     346                rc = fat_get_cluster(bs, dev_handle, fat_no, 1, &e1);
     347                if (rc != EOK)
     348                        return EIO;
     349
     350                /* Check that first byte of FAT contains the media descriptor. */
     351                if ((e0 & 0xff) != bs->mdesc)
     352                        return ENOTSUP;
     353
     354                /*
     355                 * Check that remaining bits of the first two entries are
     356                 * set to one.
     357                 */
     358                if ((e0 >> 8) != 0xff || e1 != 0xffff)
     359                        return ENOTSUP;
     360        }
     361
    292362        return EOK;
    293363}
     
    9811051        }
    9821052
     1053        /* Do some simple sanity checks on the file system. */
     1054        rc = fat_sanity_check(bs, dev_handle);
     1055        if (rc != EOK) {
     1056                block_fini(dev_handle);
     1057                ipc_answer_0(rid, rc);
     1058                return;
     1059        }
     1060
    9831061        rc = fat_idx_init_by_dev_handle(dev_handle);
    9841062        if (rc != EOK) {
     
    10371115{
    10381116        libfs_mount(&fat_libfs_ops, fat_reg.fs_handle, rid, request);
     1117}
     1118
     1119void fat_unmounted(ipc_callid_t rid, ipc_call_t *request)
     1120{
     1121        ipc_answer_0(rid, ENOTSUP);
     1122}
     1123
     1124void fat_unmount(ipc_callid_t rid, ipc_call_t *request)
     1125{
     1126        libfs_unmount(&fat_libfs_ops, rid, request);
    10391127}
    10401128
Note: See TracChangeset for help on using the changeset viewer.