Changeset 5f70118 in mainline for uspace/srv/fs/tmpfs/tmpfs_ops.c


Ignore:
Timestamp:
2010-01-10T12:16:59Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c77a64f
Parents:
309ede1 (diff), 1ac3a52 (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

    r309ede1 r5f70118  
    6767
    6868/* Forward declarations of static functions. */
    69 static fs_node_t *tmpfs_match(fs_node_t *, const char *);
    70 static fs_node_t *tmpfs_node_get(dev_handle_t, fs_index_t);
    71 static void tmpfs_node_put(fs_node_t *);
    72 static fs_node_t *tmpfs_create_node(dev_handle_t, int);
     69static int tmpfs_match(fs_node_t **, fs_node_t *, const char *);
     70static int tmpfs_node_get(fs_node_t **, dev_handle_t, fs_index_t);
     71static int tmpfs_node_open(fs_node_t *);
     72static int tmpfs_node_put(fs_node_t *);
     73static int tmpfs_create_node(fs_node_t **, dev_handle_t, int);
     74static int tmpfs_destroy_node(fs_node_t *);
    7375static int tmpfs_link_node(fs_node_t *, fs_node_t *, const char *);
    7476static int tmpfs_unlink_node(fs_node_t *, fs_node_t *, const char *);
    75 static int tmpfs_destroy_node(fs_node_t *);
    7677
    7778/* Implementation of helper functions. */
     79static 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);
     82}
     83
     84static int tmpfs_has_children(bool *has_children, fs_node_t *fn)
     85{
     86        *has_children = !list_empty(&TMPFS_NODE(fn)->cs_head);
     87        return EOK;
     88}
     89
    7890static fs_index_t tmpfs_index_get(fs_node_t *fn)
    7991{
     
    91103}
    92104
    93 static bool tmpfs_has_children(fs_node_t *fn)
    94 {
    95         return !list_empty(&TMPFS_NODE(fn)->cs_head);
    96 }
    97 
    98 static fs_node_t *tmpfs_root_get(dev_handle_t dev_handle)
    99 {
    100         return tmpfs_node_get(dev_handle, TMPFS_SOME_ROOT);
    101 }
    102 
    103105static char tmpfs_plb_get_char(unsigned pos)
    104106{
     
    114116{
    115117        return TMPFS_NODE(fn)->type == TMPFS_FILE;
     118}
     119
     120static dev_handle_t tmpfs_device_get(fs_node_t *fn)
     121{
     122        return 0;
    116123}
    117124
    118125/** libfs operations */
    119126libfs_ops_t tmpfs_libfs_ops = {
     127        .root_get = tmpfs_root_get,
    120128        .match = tmpfs_match,
    121129        .node_get = tmpfs_node_get,
     130        .node_open = tmpfs_node_open,
    122131        .node_put = tmpfs_node_put,
    123132        .create = tmpfs_create_node,
     
    125134        .link = tmpfs_link_node,
    126135        .unlink = tmpfs_unlink_node,
     136        .has_children = tmpfs_has_children,
    127137        .index_get = tmpfs_index_get,
    128138        .size_get = tmpfs_size_get,
    129139        .lnkcnt_get = tmpfs_lnkcnt_get,
    130         .has_children = tmpfs_has_children,
    131         .root_get = tmpfs_root_get,
    132140        .plb_get_char = tmpfs_plb_get_char,
    133141        .is_directory = tmpfs_is_directory,
    134         .is_file = tmpfs_is_file
     142        .is_file = tmpfs_is_file,
     143        .device_get = tmpfs_device_get
    135144};
    136145
     
    197206{
    198207        fs_node_t *rfn;
     208        int rc;
    199209       
    200         rfn = tmpfs_create_node(dev_handle, L_DIRECTORY);
    201         if (!rfn)
     210        rc = tmpfs_create_node(&rfn, dev_handle, L_DIRECTORY);
     211        if (rc != EOK || !rfn)
    202212                return false;
    203213        TMPFS_NODE(rfn)->lnkcnt = 0;    /* FS root is not linked */
     
    205215}
    206216
    207 fs_node_t *tmpfs_match(fs_node_t *pfn, const char *component)
     217int tmpfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
    208218{
    209219        tmpfs_node_t *parentp = TMPFS_NODE(pfn);
     
    212222        for (lnk = parentp->cs_head.next; lnk != &parentp->cs_head;
    213223            lnk = lnk->next) {
    214                 tmpfs_dentry_t *dentryp = list_get_instance(lnk, tmpfs_dentry_t,
    215                     link);
    216                 if (!str_cmp(dentryp->name, component))
    217                         return FS_NODE(dentryp->node);
    218         }
    219 
    220         return NULL;
    221 }
    222 
    223 fs_node_t *tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index)
     224                tmpfs_dentry_t *dentryp;
     225                dentryp = list_get_instance(lnk, tmpfs_dentry_t, link);
     226                if (!str_cmp(dentryp->name, component)) {
     227                        *rfn = FS_NODE(dentryp->node);
     228                        return EOK;
     229                }
     230        }
     231
     232        *rfn = NULL;
     233        return EOK;
     234}
     235
     236int tmpfs_node_get(fs_node_t **rfn, dev_handle_t dev_handle, fs_index_t index)
    224237{
    225238        unsigned long key[] = {
     
    228241        };
    229242        link_t *lnk = hash_table_find(&nodes, key);
    230         if (!lnk)
    231                 return NULL;
    232         return FS_NODE(hash_table_get_instance(lnk, tmpfs_node_t, nh_link));
    233 }
    234 
    235 void tmpfs_node_put(fs_node_t *fn)
     243        if (lnk) {
     244                tmpfs_node_t *nodep;
     245                nodep = hash_table_get_instance(lnk, tmpfs_node_t, nh_link);
     246                *rfn = FS_NODE(nodep);
     247        } else {
     248                *rfn = NULL;
     249        }
     250        return EOK;     
     251}
     252
     253int tmpfs_node_open(fs_node_t *fn)
    236254{
    237255        /* nothing to do */
    238 }
    239 
    240 fs_node_t *tmpfs_create_node(dev_handle_t dev_handle, int lflag)
    241 {
     256        return EOK;
     257}
     258
     259int tmpfs_node_put(fs_node_t *fn)
     260{
     261        /* nothing to do */
     262        return EOK;
     263}
     264
     265int tmpfs_create_node(fs_node_t **rfn, dev_handle_t dev_handle, int lflag)
     266{
     267        fs_node_t *rootfn;
     268        int rc;
     269
    242270        assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY));
    243271
    244272        tmpfs_node_t *nodep = malloc(sizeof(tmpfs_node_t));
    245273        if (!nodep)
    246                 return NULL;
     274                return ENOMEM;
    247275        tmpfs_node_initialize(nodep);
    248276        nodep->bp = malloc(sizeof(fs_node_t));
    249277        if (!nodep->bp) {
    250278                free(nodep);
    251                 return NULL;
     279                return ENOMEM;
    252280        }
    253281        fs_node_initialize(nodep->bp);
    254282        nodep->bp->data = nodep;        /* link the FS and TMPFS nodes */
    255         if (!tmpfs_root_get(dev_handle))
     283
     284        rc = tmpfs_root_get(&rootfn, dev_handle);
     285        assert(rc == EOK);
     286        if (!rootfn)
    256287                nodep->index = TMPFS_SOME_ROOT;
    257288        else
     
    269300        };
    270301        hash_table_insert(&nodes, key, &nodep->nh_link);
    271         return FS_NODE(nodep);
     302        *rfn = FS_NODE(nodep);
     303        return EOK;
     304}
     305
     306int tmpfs_destroy_node(fs_node_t *fn)
     307{
     308        tmpfs_node_t *nodep = TMPFS_NODE(fn);
     309       
     310        assert(!nodep->lnkcnt);
     311        assert(list_empty(&nodep->cs_head));
     312
     313        unsigned long key[] = {
     314                [NODES_KEY_INDEX] = nodep->index,
     315                [NODES_KEY_DEV] = nodep->dev_handle
     316        };
     317        hash_table_remove(&nodes, key, 2);
     318
     319        if (nodep->type == TMPFS_FILE)
     320                free(nodep->data);
     321        free(nodep->bp);
     322        free(nodep);
     323        return EOK;
    272324}
    273325
     
    343395}
    344396
    345 int tmpfs_destroy_node(fs_node_t *fn)
    346 {
    347         tmpfs_node_t *nodep = TMPFS_NODE(fn);
    348        
    349         assert(!nodep->lnkcnt);
    350         assert(list_empty(&nodep->cs_head));
    351 
    352         unsigned long key[] = {
    353                 [NODES_KEY_INDEX] = nodep->index,
    354                 [NODES_KEY_DEV] = nodep->dev_handle
    355         };
    356         hash_table_remove(&nodes, key, 2);
    357 
    358         if (nodep->type == TMPFS_FILE)
    359                 free(nodep->data);
    360         free(nodep->bp);
    361         free(nodep);
    362         return EOK;
    363 }
    364 
    365397void tmpfs_mounted(ipc_callid_t rid, ipc_call_t *request)
    366398{
    367399        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     400        int rc;
    368401
    369402        /* accept the mount options */
    370403        ipc_callid_t callid;
    371404        size_t size;
    372         if (!ipc_data_write_receive(&callid, &size)) {
     405        if (!async_data_write_receive(&callid, &size)) {
    373406                ipc_answer_0(callid, EINVAL);
    374407                ipc_answer_0(rid, EINVAL);
     
    381414                return;
    382415        }
    383         ipcarg_t retval = ipc_data_write_finalize(callid, opts, size);
     416        ipcarg_t retval = async_data_write_finalize(callid, opts, size);
    384417        if (retval != EOK) {
    385418                ipc_answer_0(rid, retval);
     
    395428        }
    396429
    397         tmpfs_node_t *rootp = TMPFS_NODE(tmpfs_root_get(dev_handle));
     430        fs_node_t *rootfn;
     431        rc = tmpfs_root_get(&rootfn, dev_handle);
     432        assert(rc == EOK);
     433        tmpfs_node_t *rootp = TMPFS_NODE(rootfn);
    398434        if (str_cmp(opts, "restore") == 0) {
    399435                if (tmpfs_restore(dev_handle))
     
    445481        ipc_callid_t callid;
    446482        size_t size;
    447         if (!ipc_data_read_receive(&callid, &size)) {
     483        if (!async_data_read_receive(&callid, &size)) {
    448484                ipc_answer_0(callid, EINVAL);   
    449485                ipc_answer_0(rid, EINVAL);
     
    454490        if (nodep->type == TMPFS_FILE) {
    455491                bytes = max(0, min(nodep->size - pos, size));
    456                 (void) ipc_data_read_finalize(callid, nodep->data + pos,
     492                (void) async_data_read_finalize(callid, nodep->data + pos,
    457493                    bytes);
    458494        } else {
     
    481517                dentryp = list_get_instance(lnk, tmpfs_dentry_t, link);
    482518
    483                 (void) ipc_data_read_finalize(callid, dentryp->name,
     519                (void) async_data_read_finalize(callid, dentryp->name,
    484520                    str_size(dentryp->name) + 1);
    485521                bytes = 1;
     
    519555        ipc_callid_t callid;
    520556        size_t size;
    521         if (!ipc_data_write_receive(&callid, &size)) {
     557        if (!async_data_write_receive(&callid, &size)) {
    522558                ipc_answer_0(callid, EINVAL);   
    523559                ipc_answer_0(rid, EINVAL);
     
    530566        if (pos + size <= nodep->size) {
    531567                /* The file size is not changing. */
    532                 (void) ipc_data_write_finalize(callid, nodep->data + pos, size);
     568                (void) async_data_write_finalize(callid, nodep->data + pos, size);
    533569                ipc_answer_2(rid, EOK, size, nodep->size);
    534570                return;
     
    552588        nodep->size += delta;
    553589        nodep->data = newdata;
    554         (void) ipc_data_write_finalize(callid, nodep->data + pos, size);
     590        (void) async_data_write_finalize(callid, nodep->data + pos, size);
    555591        ipc_answer_2(rid, EOK, size, nodep->size);
    556592}
Note: See TracChangeset for help on using the changeset viewer.