Changeset 7a35204 in mainline


Ignore:
Timestamp:
2008-08-09T09:58:06Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
619e7c9b
Parents:
11c2ae5
Message:

First attempt at delivering the FAT16 read-only support.
Needless to say it doesn't work yet, but now it's only
the lurking bugs that need to be fixed.

File:
1 edited

Legend:

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

    r11c2ae5 r7a35204  
    4040#include <libfs.h>
    4141#include <ipc/ipc.h>
     42#include <ipc/services.h>
     43#include <ipc/devmap.h>
    4244#include <async.h>
    4345#include <errno.h>
     
    4850#include <assert.h>
    4951#include <futex.h>
     52#include <sys/mman.h>
    5053
    5154#define BS_BLOCK                0
     
    9699}
    97100
     101static int dev_phone = -1;              /* FIXME */
     102static void *dev_buffer = NULL;         /* FIXME */
     103
    98104/* TODO move somewhere else */
    99105typedef struct {
    100106        void *data;
     107        size_t size;
    101108} block_t;
    102109
    103110static block_t *block_get(dev_handle_t dev_handle, off_t offset, size_t bs)
    104111{
    105         return NULL;    /* TODO */
     112        /* FIXME */
     113        block_t *b;
     114        off_t bufpos = 0;
     115        size_t buflen = 0;
     116
     117        assert(dev_phone != -1);
     118        assert(dev_buffer);
     119
     120        b = malloc(sizeof(block_t));
     121        if (!b)
     122                return NULL;
     123       
     124        b->data = malloc(bs);
     125        if (!b->data) {
     126                free(b);
     127                return NULL;
     128        }
     129        b->size = bs;
     130
     131        if (!libfs_blockread(dev_phone, dev_buffer, &bufpos, &buflen, &offset,
     132            b->data, bs, bs)) {
     133                free(b->data);
     134                free(b);
     135                return NULL;
     136        }
     137
     138        return b;
    106139}
    107140
    108141static void block_put(block_t *block)
    109142{
    110         /* TODO */
     143        /* FIXME */
     144        free(block->data);
     145        free(block);
    111146}
    112147
     
    569604        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
    570605        block_t *bb;
     606        uint16_t bps;
    571607        uint16_t rde;
    572608        int rc;
    573609
     610        /*
     611         * For now, we don't bother to remember dev_handle, dev_phone or
     612         * dev_buffer in some data structure. We use global variables because we
     613         * know there will be at most one mount on this file system.
     614         * Of course, this is a huge TODO item.
     615         */
     616        dev_buffer = mmap(NULL, BS_SIZE, PROTO_READ | PROTO_WRITE,
     617            MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
     618       
     619        if (!dev_buffer) {
     620                ipc_answer_0(rid, ENOMEM);
     621                return;
     622        }
     623
     624        dev_phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP,
     625            DEVMAP_CONNECT_TO_DEVICE, dev_handle);
     626
     627        if (dev_phone < 0) {
     628                munmap(dev_buffer, BS_SIZE);
     629                ipc_answer_0(rid, dev_phone);
     630                return;
     631        }
     632
     633        rc = ipc_share_out_start(dev_phone, dev_buffer,
     634            AS_AREA_READ | AS_AREA_WRITE);
     635        if (rc != EOK) {
     636                munmap(dev_buffer, BS_SIZE);
     637                ipc_answer_0(rid, rc);
     638                return;
     639        }
     640
    574641        /* Read the number of root directory entries. */
    575642        bb = block_get(dev_handle, BS_BLOCK, BS_SIZE);
     643        bps = uint16_t_le2host(FAT_BS(bb)->bps);
    576644        rde = uint16_t_le2host(FAT_BS(bb)->root_ent_max);
    577645        block_put(bb);
    578646
     647        if (bps != BS_SIZE) {
     648                munmap(dev_buffer, BS_SIZE);
     649                ipc_answer_0(rid, ENOTSUP);
     650                return;
     651        }
     652
    579653        rc = fat_idx_init_by_dev_handle(dev_handle);
    580654        if (rc != EOK) {
     655                munmap(dev_buffer, BS_SIZE);
    581656                ipc_answer_0(rid, rc);
    582657                return;
     
    586661        fat_node_t *rootp = (fat_node_t *)malloc(sizeof(fat_node_t));
    587662        if (!rootp) {
     663                munmap(dev_buffer, BS_SIZE);
    588664                fat_idx_fini_by_dev_handle(dev_handle);
    589665                ipc_answer_0(rid, ENOMEM);
     
    594670        fat_idx_t *ridxp = fat_idx_get_by_pos(dev_handle, FAT_CLST_ROOTPAR, 0);
    595671        if (!ridxp) {
     672                munmap(dev_buffer, BS_SIZE);
    596673                free(rootp);
    597674                fat_idx_fini_by_dev_handle(dev_handle);
Note: See TracChangeset for help on using the changeset viewer.