Changeset 61c0402 in mainline for uspace/srv/fs/fat/fat_ops.c


Ignore:
Timestamp:
2010-01-15T19:36:53Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
92bee46
Parents:
50f9c3a (diff), 963462af (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_ops.c

    r50f9c3a r61c0402  
    5252#include <adt/list.h>
    5353#include <assert.h>
    54 #include <fibril_sync.h>
     54#include <fibril_synch.h>
    5555#include <sys/mman.h>
    5656#include <align.h>
     
    7171static int fat_match(fs_node_t **, fs_node_t *, const char *);
    7272static int fat_node_get(fs_node_t **, dev_handle_t, fs_index_t);
     73static int fat_node_open(fs_node_t *);
    7374static int fat_node_put(fs_node_t *);
    7475static int fat_create_node(fs_node_t **, dev_handle_t, int);
     
    8384static bool fat_is_directory(fs_node_t *);
    8485static bool fat_is_file(fs_node_t *node);
     86static dev_handle_t fat_device_get(fs_node_t *node);
    8587
    8688/*
     
    288290
    289291        *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        /* Check signature of each FAT. */
     329
     330        for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) {
     331                rc = fat_get_cluster(bs, dev_handle, fat_no, 0, &e0);
     332                if (rc != EOK)
     333                        return EIO;
     334
     335                rc = fat_get_cluster(bs, dev_handle, fat_no, 1, &e1);
     336                if (rc != EOK)
     337                        return EIO;
     338
     339                /* Check that first byte of FAT contains the media descriptor. */
     340                if ((e0 & 0xff) != bs->mdesc)
     341                        return ENOTSUP;
     342
     343                /*
     344                 * Check that remaining bits of the first two entries are
     345                 * set to one.
     346                 */
     347                if ((e0 >> 8) != 0xff || e1 != 0xffff)
     348                        return ENOTSUP;
     349        }
     350
    290351        return EOK;
    291352}
     
    407468}
    408469
     470int fat_node_open(fs_node_t *fn)
     471{
     472        /*
     473         * Opening a file is stateless, nothing
     474         * to be done here.
     475         */
     476        return EOK;
     477}
     478
    409479int fat_node_put(fs_node_t *fn)
    410480{
     
    867937}
    868938
     939dev_handle_t fat_device_get(fs_node_t *node)
     940{
     941        return 0;
     942}
     943
    869944/** libfs operations */
    870945libfs_ops_t fat_libfs_ops = {
     
    872947        .match = fat_match,
    873948        .node_get = fat_node_get,
     949        .node_open = fat_node_open,
    874950        .node_put = fat_node_put,
    875951        .create = fat_create_node,
     
    881957        .size_get = fat_size_get,
    882958        .lnkcnt_get = fat_lnkcnt_get,
    883         .plb_get_char = fat_plb_get_char,
     959        .plb_get_char = fat_plb_get_char,
    884960        .is_directory = fat_is_directory,
    885         .is_file = fat_is_file
     961        .is_file = fat_is_file,
     962        .device_get = fat_device_get
    886963};
    887964
     
    9571034        /* Initialize the block cache */
    9581035        rc = block_cache_init(dev_handle, bps, 0 /* XXX */, cmode);
     1036        if (rc != EOK) {
     1037                block_fini(dev_handle);
     1038                ipc_answer_0(rid, rc);
     1039                return;
     1040        }
     1041
     1042        /* Do some simple sanity checks on the file system. */
     1043        rc = fat_sanity_check(bs, dev_handle);
    9591044        if (rc != EOK) {
    9601045                block_fini(dev_handle);
Note: See TracChangeset for help on using the changeset viewer.