Changeset 46c20c8 in mainline for uspace/srv/fs/tmpfs/tmpfs_ops.c


Ignore:
Timestamp:
2010-11-26T20:08:10Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
45df59a
Parents:
fb150d78 (diff), ffdd2b9 (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

    rfb150d78 r46c20c8  
    2929/** @addtogroup fs
    3030 * @{
    31  */ 
     31 */
    3232
    3333/**
     
    4040#include "../../vfs/vfs.h"
    4141#include <ipc/ipc.h>
     42#include <macros.h>
     43#include <stdint.h>
    4244#include <async.h>
    4345#include <errno.h>
    4446#include <atomic.h>
    4547#include <stdlib.h>
    46 #include <string.h>
     48#include <str.h>
    4749#include <stdio.h>
    4850#include <assert.h>
     
    6870/* Forward declarations of static functions. */
    6971static int tmpfs_match(fs_node_t **, fs_node_t *, const char *);
    70 static int tmpfs_node_get(fs_node_t **, dev_handle_t, fs_index_t);
     72static int tmpfs_node_get(fs_node_t **, devmap_handle_t, fs_index_t);
    7173static int tmpfs_node_open(fs_node_t *);
    7274static int tmpfs_node_put(fs_node_t *);
    73 static int tmpfs_create_node(fs_node_t **, dev_handle_t, int);
     75static int tmpfs_create_node(fs_node_t **, devmap_handle_t, int);
    7476static int tmpfs_destroy_node(fs_node_t *);
    7577static int tmpfs_link_node(fs_node_t *, fs_node_t *, const char *);
     
    7779
    7880/* Implementation of helper functions. */
    79 static int tmpfs_root_get(fs_node_t **rfn, dev_handle_t dev_handle)
    80 {
    81         return tmpfs_node_get(rfn, dev_handle, TMPFS_SOME_ROOT);
     81static int tmpfs_root_get(fs_node_t **rfn, devmap_handle_t devmap_handle)
     82{
     83        return tmpfs_node_get(rfn, devmap_handle, TMPFS_SOME_ROOT);
    8284}
    8385
     
    9395}
    9496
    95 static size_t tmpfs_size_get(fs_node_t *fn)
     97static aoff64_t tmpfs_size_get(fs_node_t *fn)
    9698{
    9799        return TMPFS_NODE(fn)->size;
     
    118120}
    119121
    120 static dev_handle_t tmpfs_device_get(fs_node_t *fn)
     122static devmap_handle_t tmpfs_device_get(fs_node_t *fn)
    121123{
    122124        return 0;
     
    163165        switch (keys) {
    164166        case 1:
    165                 return (nodep->dev_handle == key[NODES_KEY_DEV]);
     167                return (nodep->devmap_handle == key[NODES_KEY_DEV]);
    166168        case 2:
    167                 return ((nodep->dev_handle == key[NODES_KEY_DEV]) &&
     169                return ((nodep->devmap_handle == key[NODES_KEY_DEV]) &&
    168170                    (nodep->index == key[NODES_KEY_INDEX]));
    169171        default:
     
    207209        nodep->bp = NULL;
    208210        nodep->index = 0;
    209         nodep->dev_handle = 0;
     211        nodep->devmap_handle = 0;
    210212        nodep->type = TMPFS_NONE;
    211213        nodep->lnkcnt = 0;
     
    231233}
    232234
    233 static bool tmpfs_instance_init(dev_handle_t dev_handle)
     235static bool tmpfs_instance_init(devmap_handle_t devmap_handle)
    234236{
    235237        fs_node_t *rfn;
    236238        int rc;
    237239       
    238         rc = tmpfs_create_node(&rfn, dev_handle, L_DIRECTORY);
     240        rc = tmpfs_create_node(&rfn, devmap_handle, L_DIRECTORY);
    239241        if (rc != EOK || !rfn)
    240242                return false;
     
    243245}
    244246
    245 static void tmpfs_instance_done(dev_handle_t dev_handle)
     247static void tmpfs_instance_done(devmap_handle_t devmap_handle)
    246248{
    247249        unsigned long key[] = {
    248                 [NODES_KEY_DEV] = dev_handle
     250                [NODES_KEY_DEV] = devmap_handle
    249251        };
    250252        /*
     
    277279}
    278280
    279 int tmpfs_node_get(fs_node_t **rfn, dev_handle_t dev_handle, fs_index_t index)
     281int tmpfs_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle, fs_index_t index)
    280282{
    281283        unsigned long key[] = {
    282                 [NODES_KEY_DEV] = dev_handle,
     284                [NODES_KEY_DEV] = devmap_handle,
    283285                [NODES_KEY_INDEX] = index
    284286        };
     
    306308}
    307309
    308 int tmpfs_create_node(fs_node_t **rfn, dev_handle_t dev_handle, int lflag)
     310int tmpfs_create_node(fs_node_t **rfn, devmap_handle_t devmap_handle, int lflag)
    309311{
    310312        fs_node_t *rootfn;
     
    325327        nodep->bp->data = nodep;        /* link the FS and TMPFS nodes */
    326328
    327         rc = tmpfs_root_get(&rootfn, dev_handle);
     329        rc = tmpfs_root_get(&rootfn, devmap_handle);
    328330        assert(rc == EOK);
    329331        if (!rootfn)
     
    331333        else
    332334                nodep->index = tmpfs_next_index++;
    333         nodep->dev_handle = dev_handle;
     335        nodep->devmap_handle = devmap_handle;
    334336        if (lflag & L_DIRECTORY)
    335337                nodep->type = TMPFS_DIRECTORY;
     
    339341        /* Insert the new node into the nodes hash table. */
    340342        unsigned long key[] = {
    341                 [NODES_KEY_DEV] = nodep->dev_handle,
     343                [NODES_KEY_DEV] = nodep->devmap_handle,
    342344                [NODES_KEY_INDEX] = nodep->index
    343345        };
     
    355357
    356358        unsigned long key[] = {
    357                 [NODES_KEY_DEV] = nodep->dev_handle,
     359                [NODES_KEY_DEV] = nodep->devmap_handle,
    358360                [NODES_KEY_INDEX] = nodep->index
    359361        };
     
    440442void tmpfs_mounted(ipc_callid_t rid, ipc_call_t *request)
    441443{
    442         dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     444        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    443445        fs_node_t *rootfn;
    444446        int rc;
     
    453455
    454456        /* Check if this device is not already mounted. */
    455         rc = tmpfs_root_get(&rootfn, dev_handle);
     457        rc = tmpfs_root_get(&rootfn, devmap_handle);
    456458        if ((rc == EOK) && (rootfn)) {
    457459                (void) tmpfs_node_put(rootfn);
     
    462464
    463465        /* Initialize TMPFS instance. */
    464         if (!tmpfs_instance_init(dev_handle)) {
     466        if (!tmpfs_instance_init(devmap_handle)) {
    465467                free(opts);
    466468                ipc_answer_0(rid, ENOMEM);
     
    468470        }
    469471
    470         rc = tmpfs_root_get(&rootfn, dev_handle);
     472        rc = tmpfs_root_get(&rootfn, devmap_handle);
    471473        assert(rc == EOK);
    472474        tmpfs_node_t *rootp = TMPFS_NODE(rootfn);
    473475        if (str_cmp(opts, "restore") == 0) {
    474                 if (tmpfs_restore(dev_handle))
     476                if (tmpfs_restore(devmap_handle))
    475477                        ipc_answer_3(rid, EOK, rootp->index, rootp->size,
    476478                            rootp->lnkcnt);
     
    491493void tmpfs_unmounted(ipc_callid_t rid, ipc_call_t *request)
    492494{
    493         dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
    494 
    495         tmpfs_instance_done(dev_handle);
     495        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
     496
     497        tmpfs_instance_done(devmap_handle);
    496498        ipc_answer_0(rid, EOK);
    497499}
     
    509511void tmpfs_read(ipc_callid_t rid, ipc_call_t *request)
    510512{
    511         dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
    512         fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    513         off_t pos = (off_t)IPC_GET_ARG3(*request);
    514 
     513        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
     514        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
     515        aoff64_t pos =
     516            (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
     517       
    515518        /*
    516519         * Lookup the respective TMPFS node.
     
    518521        link_t *hlp;
    519522        unsigned long key[] = {
    520                 [NODES_KEY_DEV] = dev_handle,
     523                [NODES_KEY_DEV] = devmap_handle,
    521524                [NODES_KEY_INDEX] = index
    522525        };
     
    528531        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
    529532            nh_link);
    530 
     533       
    531534        /*
    532535         * Receive the read request.
     
    535538        size_t size;
    536539        if (!async_data_read_receive(&callid, &size)) {
    537                 ipc_answer_0(callid, EINVAL);   
     540                ipc_answer_0(callid, EINVAL);
    538541                ipc_answer_0(rid, EINVAL);
    539542                return;
     
    542545        size_t bytes;
    543546        if (nodep->type == TMPFS_FILE) {
    544                 bytes = max(0, min(nodep->size - pos, size));
     547                bytes = min(nodep->size - pos, size);
    545548                (void) async_data_read_finalize(callid, nodep->data + pos,
    546549                    bytes);
     
    548551                tmpfs_dentry_t *dentryp;
    549552                link_t *lnk;
    550                 int i;
     553                aoff64_t i;
    551554               
    552555                assert(nodep->type == TMPFS_DIRECTORY);
     
    558561                 */
    559562                for (i = 0, lnk = nodep->cs_head.next;
    560                     i < pos && lnk != &nodep->cs_head;
     563                    (i < pos) && (lnk != &nodep->cs_head);
    561564                    i++, lnk = lnk->next)
    562565                        ;
     
    583586void tmpfs_write(ipc_callid_t rid, ipc_call_t *request)
    584587{
    585         dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
    586         fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    587         off_t pos = (off_t)IPC_GET_ARG3(*request);
    588 
     588        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
     589        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
     590        aoff64_t pos =
     591            (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
     592       
    589593        /*
    590594         * Lookup the respective TMPFS node.
     
    592596        link_t *hlp;
    593597        unsigned long key[] = {
    594                 [NODES_KEY_DEV] = dev_handle,
     598                [NODES_KEY_DEV] = devmap_handle,
    595599                [NODES_KEY_INDEX] = index
    596600        };
     
    647651void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request)
    648652{
    649         dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
     653        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
     654        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
     655        aoff64_t size =
     656            (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
     657       
     658        /*
     659         * Lookup the respective TMPFS node.
     660         */
     661        unsigned long key[] = {
     662                [NODES_KEY_DEV] = devmap_handle,
     663                [NODES_KEY_INDEX] = index
     664        };
     665        link_t *hlp = hash_table_find(&nodes, key);
     666        if (!hlp) {
     667                ipc_answer_0(rid, ENOENT);
     668                return;
     669        }
     670        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
     671            nh_link);
     672       
     673        if (size == nodep->size) {
     674                ipc_answer_0(rid, EOK);
     675                return;
     676        }
     677       
     678        if (size > SIZE_MAX) {
     679                ipc_answer_0(rid, ENOMEM);
     680                return;
     681        }
     682       
     683        void *newdata = realloc(nodep->data, size);
     684        if (!newdata) {
     685                ipc_answer_0(rid, ENOMEM);
     686                return;
     687        }
     688       
     689        if (size > nodep->size) {
     690                size_t delta = size - nodep->size;
     691                memset(newdata + nodep->size, 0, delta);
     692        }
     693       
     694        nodep->size = size;
     695        nodep->data = newdata;
     696        ipc_answer_0(rid, EOK);
     697}
     698
     699void tmpfs_close(ipc_callid_t rid, ipc_call_t *request)
     700{
     701        ipc_answer_0(rid, EOK);
     702}
     703
     704void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request)
     705{
     706        devmap_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request);
    650707        fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    651         size_t size = (off_t)IPC_GET_ARG3(*request);
    652 
    653         /*
    654          * Lookup the respective TMPFS node.
    655          */
     708        int rc;
     709
    656710        link_t *hlp;
    657711        unsigned long key[] = {
    658                 [NODES_KEY_DEV] = dev_handle,
     712                [NODES_KEY_DEV] = devmap_handle,
    659713                [NODES_KEY_INDEX] = index
    660714        };
     
    666720        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
    667721            nh_link);
    668 
    669         if (size == nodep->size) {
    670                 ipc_answer_0(rid, EOK);
    671                 return;
    672         }
    673 
    674         void *newdata = realloc(nodep->data, size);
    675         if (!newdata) {
    676                 ipc_answer_0(rid, ENOMEM);
    677                 return;
    678         }
    679         if (size > nodep->size) {
    680                 size_t delta = size - nodep->size;
    681                 memset(newdata + nodep->size, 0, delta);
    682         }
    683         nodep->size = size;
    684         nodep->data = newdata;
    685         ipc_answer_0(rid, EOK);
    686 }
    687 
    688 void tmpfs_close(ipc_callid_t rid, ipc_call_t *request)
    689 {
    690         ipc_answer_0(rid, EOK);
    691 }
    692 
    693 void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request)
    694 {
    695         dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
    696         fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    697         int rc;
    698 
    699         link_t *hlp;
    700         unsigned long key[] = {
    701                 [NODES_KEY_DEV] = dev_handle,
    702                 [NODES_KEY_INDEX] = index
    703         };
    704         hlp = hash_table_find(&nodes, key);
    705         if (!hlp) {
    706                 ipc_answer_0(rid, ENOENT);
    707                 return;
    708         }
    709         tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
    710             nh_link);
    711722        rc = tmpfs_destroy_node(FS_NODE(nodep));
    712723        ipc_answer_0(rid, rc);
     
    725736void tmpfs_sync(ipc_callid_t rid, ipc_call_t *request)
    726737{
    727         /* Dummy implementation */
     738        /*
     739         * TMPFS keeps its data structures always consistent,
     740         * thus the sync operation is a no-op.
     741         */
    728742        ipc_answer_0(rid, EOK);
    729743}
Note: See TracChangeset for help on using the changeset viewer.