Changeset 89c57b6 in mainline for uspace/srv/fs/tmpfs/tmpfs_ops.c


Ignore:
Timestamp:
2011-04-13T14:45:41Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
88634420
Parents:
cefb126 (diff), 17279ead (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/tmpfs/tmpfs_ops.c

    rcefb126 r89c57b6  
    3939#include "tmpfs.h"
    4040#include "../../vfs/vfs.h"
    41 #include <ipc/ipc.h>
    4241#include <macros.h>
    4342#include <stdint.h>
     
    7069/* Forward declarations of static functions. */
    7170static int tmpfs_match(fs_node_t **, fs_node_t *, const char *);
    72 static int tmpfs_node_get(fs_node_t **, dev_handle_t, fs_index_t);
     71static int tmpfs_node_get(fs_node_t **, devmap_handle_t, fs_index_t);
    7372static int tmpfs_node_open(fs_node_t *);
    7473static int tmpfs_node_put(fs_node_t *);
    75 static int tmpfs_create_node(fs_node_t **, dev_handle_t, int);
     74static int tmpfs_create_node(fs_node_t **, devmap_handle_t, int);
    7675static int tmpfs_destroy_node(fs_node_t *);
    7776static int tmpfs_link_node(fs_node_t *, fs_node_t *, const char *);
     
    7978
    8079/* Implementation of helper functions. */
    81 static int tmpfs_root_get(fs_node_t **rfn, dev_handle_t dev_handle)
    82 {
    83         return tmpfs_node_get(rfn, dev_handle, TMPFS_SOME_ROOT);
     80static int tmpfs_root_get(fs_node_t **rfn, devmap_handle_t devmap_handle)
     81{
     82        return tmpfs_node_get(rfn, devmap_handle, TMPFS_SOME_ROOT);
    8483}
    8584
     
    120119}
    121120
    122 static dev_handle_t tmpfs_device_get(fs_node_t *fn)
     121static devmap_handle_t tmpfs_device_get(fs_node_t *fn)
    123122{
    124123        return 0;
     
    165164        switch (keys) {
    166165        case 1:
    167                 return (nodep->dev_handle == key[NODES_KEY_DEV]);
     166                return (nodep->devmap_handle == key[NODES_KEY_DEV]);
    168167        case 2:
    169                 return ((nodep->dev_handle == key[NODES_KEY_DEV]) &&
     168                return ((nodep->devmap_handle == key[NODES_KEY_DEV]) &&
    170169                    (nodep->index == key[NODES_KEY_INDEX]));
    171170        default:
     
    209208        nodep->bp = NULL;
    210209        nodep->index = 0;
    211         nodep->dev_handle = 0;
     210        nodep->devmap_handle = 0;
    212211        nodep->type = TMPFS_NONE;
    213212        nodep->lnkcnt = 0;
     
    233232}
    234233
    235 static bool tmpfs_instance_init(dev_handle_t dev_handle)
     234static bool tmpfs_instance_init(devmap_handle_t devmap_handle)
    236235{
    237236        fs_node_t *rfn;
    238237        int rc;
    239238       
    240         rc = tmpfs_create_node(&rfn, dev_handle, L_DIRECTORY);
     239        rc = tmpfs_create_node(&rfn, devmap_handle, L_DIRECTORY);
    241240        if (rc != EOK || !rfn)
    242241                return false;
     
    245244}
    246245
    247 static void tmpfs_instance_done(dev_handle_t dev_handle)
     246static void tmpfs_instance_done(devmap_handle_t devmap_handle)
    248247{
    249248        unsigned long key[] = {
    250                 [NODES_KEY_DEV] = dev_handle
     249                [NODES_KEY_DEV] = devmap_handle
    251250        };
    252251        /*
     
    279278}
    280279
    281 int tmpfs_node_get(fs_node_t **rfn, dev_handle_t dev_handle, fs_index_t index)
     280int tmpfs_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle, fs_index_t index)
    282281{
    283282        unsigned long key[] = {
    284                 [NODES_KEY_DEV] = dev_handle,
     283                [NODES_KEY_DEV] = devmap_handle,
    285284                [NODES_KEY_INDEX] = index
    286285        };
     
    308307}
    309308
    310 int tmpfs_create_node(fs_node_t **rfn, dev_handle_t dev_handle, int lflag)
     309int tmpfs_create_node(fs_node_t **rfn, devmap_handle_t devmap_handle, int lflag)
    311310{
    312311        fs_node_t *rootfn;
     
    327326        nodep->bp->data = nodep;        /* link the FS and TMPFS nodes */
    328327
    329         rc = tmpfs_root_get(&rootfn, dev_handle);
     328        rc = tmpfs_root_get(&rootfn, devmap_handle);
    330329        assert(rc == EOK);
    331330        if (!rootfn)
     
    333332        else
    334333                nodep->index = tmpfs_next_index++;
    335         nodep->dev_handle = dev_handle;
     334        nodep->devmap_handle = devmap_handle;
    336335        if (lflag & L_DIRECTORY)
    337336                nodep->type = TMPFS_DIRECTORY;
     
    341340        /* Insert the new node into the nodes hash table. */
    342341        unsigned long key[] = {
    343                 [NODES_KEY_DEV] = nodep->dev_handle,
     342                [NODES_KEY_DEV] = nodep->devmap_handle,
    344343                [NODES_KEY_INDEX] = nodep->index
    345344        };
     
    357356
    358357        unsigned long key[] = {
    359                 [NODES_KEY_DEV] = nodep->dev_handle,
     358                [NODES_KEY_DEV] = nodep->devmap_handle,
    360359                [NODES_KEY_INDEX] = nodep->index
    361360        };
     
    442441void tmpfs_mounted(ipc_callid_t rid, ipc_call_t *request)
    443442{
    444         dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     443        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    445444        fs_node_t *rootfn;
    446445        int rc;
     
    450449        rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL);
    451450        if (rc != EOK) {
    452                 ipc_answer_0(rid, rc);
     451                async_answer_0(rid, rc);
    453452                return;
    454453        }
    455454
    456455        /* Check if this device is not already mounted. */
    457         rc = tmpfs_root_get(&rootfn, dev_handle);
     456        rc = tmpfs_root_get(&rootfn, devmap_handle);
    458457        if ((rc == EOK) && (rootfn)) {
    459458                (void) tmpfs_node_put(rootfn);
    460459                free(opts);
    461                 ipc_answer_0(rid, EEXIST);
     460                async_answer_0(rid, EEXIST);
    462461                return;
    463462        }
    464463
    465464        /* Initialize TMPFS instance. */
    466         if (!tmpfs_instance_init(dev_handle)) {
     465        if (!tmpfs_instance_init(devmap_handle)) {
    467466                free(opts);
    468                 ipc_answer_0(rid, ENOMEM);
    469                 return;
    470         }
    471 
    472         rc = tmpfs_root_get(&rootfn, dev_handle);
     467                async_answer_0(rid, ENOMEM);
     468                return;
     469        }
     470
     471        rc = tmpfs_root_get(&rootfn, devmap_handle);
    473472        assert(rc == EOK);
    474473        tmpfs_node_t *rootp = TMPFS_NODE(rootfn);
    475474        if (str_cmp(opts, "restore") == 0) {
    476                 if (tmpfs_restore(dev_handle))
    477                         ipc_answer_3(rid, EOK, rootp->index, rootp->size,
     475                if (tmpfs_restore(devmap_handle))
     476                        async_answer_3(rid, EOK, rootp->index, rootp->size,
    478477                            rootp->lnkcnt);
    479478                else
    480                         ipc_answer_0(rid, ELIMIT);
     479                        async_answer_0(rid, ELIMIT);
    481480        } else {
    482                 ipc_answer_3(rid, EOK, rootp->index, rootp->size,
     481                async_answer_3(rid, EOK, rootp->index, rootp->size,
    483482                    rootp->lnkcnt);
    484483        }
     
    493492void tmpfs_unmounted(ipc_callid_t rid, ipc_call_t *request)
    494493{
    495         dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
    496 
    497         tmpfs_instance_done(dev_handle);
    498         ipc_answer_0(rid, EOK);
     494        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
     495
     496        tmpfs_instance_done(devmap_handle);
     497        async_answer_0(rid, EOK);
    499498}
    500499
     
    511510void tmpfs_read(ipc_callid_t rid, ipc_call_t *request)
    512511{
    513         dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     512        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    514513        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    515514        aoff64_t pos =
     
    521520        link_t *hlp;
    522521        unsigned long key[] = {
    523                 [NODES_KEY_DEV] = dev_handle,
     522                [NODES_KEY_DEV] = devmap_handle,
    524523                [NODES_KEY_INDEX] = index
    525524        };
    526525        hlp = hash_table_find(&nodes, key);
    527526        if (!hlp) {
    528                 ipc_answer_0(rid, ENOENT);
     527                async_answer_0(rid, ENOENT);
    529528                return;
    530529        }
     
    538537        size_t size;
    539538        if (!async_data_read_receive(&callid, &size)) {
    540                 ipc_answer_0(callid, EINVAL);
    541                 ipc_answer_0(rid, EINVAL);
     539                async_answer_0(callid, EINVAL);
     540                async_answer_0(rid, EINVAL);
    542541                return;
    543542        }
     
    566565
    567566                if (lnk == &nodep->cs_head) {
    568                         ipc_answer_0(callid, ENOENT);
    569                         ipc_answer_1(rid, ENOENT, 0);
     567                        async_answer_0(callid, ENOENT);
     568                        async_answer_1(rid, ENOENT, 0);
    570569                        return;
    571570                }
     
    581580         * Answer the VFS_READ call.
    582581         */
    583         ipc_answer_1(rid, EOK, bytes);
     582        async_answer_1(rid, EOK, bytes);
    584583}
    585584
    586585void tmpfs_write(ipc_callid_t rid, ipc_call_t *request)
    587586{
    588         dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     587        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    589588        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    590589        aoff64_t pos =
     
    596595        link_t *hlp;
    597596        unsigned long key[] = {
    598                 [NODES_KEY_DEV] = dev_handle,
     597                [NODES_KEY_DEV] = devmap_handle,
    599598                [NODES_KEY_INDEX] = index
    600599        };
    601600        hlp = hash_table_find(&nodes, key);
    602601        if (!hlp) {
    603                 ipc_answer_0(rid, ENOENT);
     602                async_answer_0(rid, ENOENT);
    604603                return;
    605604        }
     
    613612        size_t size;
    614613        if (!async_data_write_receive(&callid, &size)) {
    615                 ipc_answer_0(callid, EINVAL);   
    616                 ipc_answer_0(rid, EINVAL);
     614                async_answer_0(callid, EINVAL);
     615                async_answer_0(rid, EINVAL);
    617616                return;
    618617        }
     
    624623                /* The file size is not changing. */
    625624                (void) async_data_write_finalize(callid, nodep->data + pos, size);
    626                 ipc_answer_2(rid, EOK, size, nodep->size);
     625                async_answer_2(rid, EOK, size, nodep->size);
    627626                return;
    628627        }
     
    637636        void *newdata = realloc(nodep->data, nodep->size + delta);
    638637        if (!newdata) {
    639                 ipc_answer_0(callid, ENOMEM);
    640                 ipc_answer_2(rid, EOK, 0, nodep->size);
     638                async_answer_0(callid, ENOMEM);
     639                async_answer_2(rid, EOK, 0, nodep->size);
    641640                return;
    642641        }
     
    646645        nodep->data = newdata;
    647646        (void) async_data_write_finalize(callid, nodep->data + pos, size);
    648         ipc_answer_2(rid, EOK, size, nodep->size);
     647        async_answer_2(rid, EOK, size, nodep->size);
    649648}
    650649
    651650void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request)
    652651{
    653         dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     652        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    654653        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    655654        aoff64_t size =
     
    660659         */
    661660        unsigned long key[] = {
    662                 [NODES_KEY_DEV] = dev_handle,
     661                [NODES_KEY_DEV] = devmap_handle,
    663662                [NODES_KEY_INDEX] = index
    664663        };
    665664        link_t *hlp = hash_table_find(&nodes, key);
    666665        if (!hlp) {
    667                 ipc_answer_0(rid, ENOENT);
     666                async_answer_0(rid, ENOENT);
    668667                return;
    669668        }
     
    672671       
    673672        if (size == nodep->size) {
    674                 ipc_answer_0(rid, EOK);
     673                async_answer_0(rid, EOK);
    675674                return;
    676675        }
    677676       
    678677        if (size > SIZE_MAX) {
    679                 ipc_answer_0(rid, ENOMEM);
     678                async_answer_0(rid, ENOMEM);
    680679                return;
    681680        }
     
    683682        void *newdata = realloc(nodep->data, size);
    684683        if (!newdata) {
    685                 ipc_answer_0(rid, ENOMEM);
     684                async_answer_0(rid, ENOMEM);
    686685                return;
    687686        }
     
    694693        nodep->size = size;
    695694        nodep->data = newdata;
    696         ipc_answer_0(rid, EOK);
     695        async_answer_0(rid, EOK);
    697696}
    698697
    699698void tmpfs_close(ipc_callid_t rid, ipc_call_t *request)
    700699{
    701         ipc_answer_0(rid, EOK);
     700        async_answer_0(rid, EOK);
    702701}
    703702
    704703void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request)
    705704{
    706         dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
     705        devmap_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request);
    707706        fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    708707        int rc;
     
    710709        link_t *hlp;
    711710        unsigned long key[] = {
    712                 [NODES_KEY_DEV] = dev_handle,
     711                [NODES_KEY_DEV] = devmap_handle,
    713712                [NODES_KEY_INDEX] = index
    714713        };
    715714        hlp = hash_table_find(&nodes, key);
    716715        if (!hlp) {
    717                 ipc_answer_0(rid, ENOENT);
     716                async_answer_0(rid, ENOENT);
    718717                return;
    719718        }
     
    721720            nh_link);
    722721        rc = tmpfs_destroy_node(FS_NODE(nodep));
    723         ipc_answer_0(rid, rc);
     722        async_answer_0(rid, rc);
    724723}
    725724
     
    736735void tmpfs_sync(ipc_callid_t rid, ipc_call_t *request)
    737736{
    738         /* Dummy implementation */
    739         ipc_answer_0(rid, EOK);
     737        /*
     738         * TMPFS keeps its data structures always consistent,
     739         * thus the sync operation is a no-op.
     740         */
     741        async_answer_0(rid, EOK);
    740742}
    741743
Note: See TracChangeset for help on using the changeset viewer.