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


Ignore:
Timestamp:
2011-08-03T17:34:57Z (14 years ago)
Author:
Oleg Romanenko <romanenko.oleg@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1940326
Parents:
52a79081 (diff), 3fab770 (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 from mainline

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    r52a79081 ra33f0a6  
    8585static int tmpfs_has_children(bool *has_children, fs_node_t *fn)
    8686{
    87         *has_children = !list_empty(&TMPFS_NODE(fn)->cs_head);
     87        *has_children = !list_empty(&TMPFS_NODE(fn)->cs_list);
    8888        return EOK;
    8989}
     
    102102{
    103103        return TMPFS_NODE(fn)->lnkcnt;
    104 }
    105 
    106 static char tmpfs_plb_get_char(unsigned pos)
    107 {
    108         return tmpfs_reg.plb_ro[pos % PLB_SIZE];
    109104}
    110105
     
    139134        .size_get = tmpfs_size_get,
    140135        .lnkcnt_get = tmpfs_lnkcnt_get,
    141         .plb_get_char = tmpfs_plb_get_char,
    142136        .is_directory = tmpfs_is_directory,
    143137        .is_file = tmpfs_is_file,
     
    180174            nh_link);
    181175
    182         while (!list_empty(&nodep->cs_head)) {
    183                 tmpfs_dentry_t *dentryp = list_get_instance(nodep->cs_head.next,
    184                     tmpfs_dentry_t, link);
     176        while (!list_empty(&nodep->cs_list)) {
     177                tmpfs_dentry_t *dentryp = list_get_instance(
     178                    list_first(&nodep->cs_list), tmpfs_dentry_t, link);
    185179
    186180                assert(nodep->type == TMPFS_DIRECTORY);
     
    214208        nodep->data = NULL;
    215209        link_initialize(&nodep->nh_link);
    216         list_initialize(&nodep->cs_head);
     210        list_initialize(&nodep->cs_list);
    217211}
    218212
     
    262256{
    263257        tmpfs_node_t *parentp = TMPFS_NODE(pfn);
    264         link_t *lnk;
    265 
    266         for (lnk = parentp->cs_head.next; lnk != &parentp->cs_head;
    267             lnk = lnk->next) {
     258
     259        list_foreach(parentp->cs_list, lnk) {
    268260                tmpfs_dentry_t *dentryp;
    269261                dentryp = list_get_instance(lnk, tmpfs_dentry_t, link);
     
    353345       
    354346        assert(!nodep->lnkcnt);
    355         assert(list_empty(&nodep->cs_head));
     347        assert(list_empty(&nodep->cs_list));
    356348
    357349        unsigned long key[] = {
     
    373365        tmpfs_node_t *childp = TMPFS_NODE(cfn);
    374366        tmpfs_dentry_t *dentryp;
    375         link_t *lnk;
    376367
    377368        assert(parentp->type == TMPFS_DIRECTORY);
    378369
    379370        /* Check for duplicit entries. */
    380         for (lnk = parentp->cs_head.next; lnk != &parentp->cs_head;
    381             lnk = lnk->next) {
     371        list_foreach(parentp->cs_list, lnk) {
    382372                dentryp = list_get_instance(lnk, tmpfs_dentry_t, link);
    383373                if (!str_cmp(dentryp->name, nm))
     
    401391        dentryp->node = childp;
    402392        childp->lnkcnt++;
    403         list_append(&dentryp->link, &parentp->cs_head);
     393        list_append(&dentryp->link, &parentp->cs_list);
    404394
    405395        return EOK;
     
    411401        tmpfs_node_t *childp = NULL;
    412402        tmpfs_dentry_t *dentryp;
    413         link_t *lnk;
    414403
    415404        if (!parentp)
    416405                return EBUSY;
    417406       
    418         for (lnk = parentp->cs_head.next; lnk != &parentp->cs_head;
    419             lnk = lnk->next) {
     407        list_foreach(parentp->cs_list, lnk) {
    420408                dentryp = list_get_instance(lnk, tmpfs_dentry_t, link);
    421409                if (!str_cmp(dentryp->name, nm)) {
     
    423411                        assert(FS_NODE(childp) == cfn);
    424412                        break;
    425                 }       
     413                }
    426414        }
    427415
     
    429417                return ENOENT;
    430418               
    431         if ((childp->lnkcnt == 1) && !list_empty(&childp->cs_head))
     419        if ((childp->lnkcnt == 1) && !list_empty(&childp->cs_list))
    432420                return ENOTEMPTY;
    433421
     
    439427}
    440428
    441 void tmpfs_mounted(ipc_callid_t rid, ipc_call_t *request)
    442 {
    443         devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
     429/*
     430 * Implementation of the VFS_OUT interface.
     431 */
     432
     433static int
     434tmpfs_mounted(devmap_handle_t devmap_handle, const char *opts,
     435    fs_index_t *index, aoff64_t *size, unsigned *lnkcnt)
     436{
    444437        fs_node_t *rootfn;
    445438        int rc;
    446439       
    447         /* Accept the mount options. */
    448         char *opts;
    449         rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL);
    450         if (rc != EOK) {
    451                 async_answer_0(rid, rc);
    452                 return;
    453         }
    454 
    455440        /* Check if this device is not already mounted. */
    456441        rc = tmpfs_root_get(&rootfn, devmap_handle);
    457442        if ((rc == EOK) && (rootfn)) {
    458443                (void) tmpfs_node_put(rootfn);
    459                 free(opts);
    460                 async_answer_0(rid, EEXIST);
    461                 return;
     444                return EEXIST;
    462445        }
    463446
    464447        /* Initialize TMPFS instance. */
    465         if (!tmpfs_instance_init(devmap_handle)) {
    466                 free(opts);
    467                 async_answer_0(rid, ENOMEM);
    468                 return;
    469         }
     448        if (!tmpfs_instance_init(devmap_handle))
     449                return ENOMEM;
    470450
    471451        rc = tmpfs_root_get(&rootfn, devmap_handle);
     
    473453        tmpfs_node_t *rootp = TMPFS_NODE(rootfn);
    474454        if (str_cmp(opts, "restore") == 0) {
    475                 if (tmpfs_restore(devmap_handle))
    476                         async_answer_3(rid, EOK, rootp->index, rootp->size,
    477                             rootp->lnkcnt);
    478                 else
    479                         async_answer_0(rid, ELIMIT);
    480         } else {
    481                 async_answer_3(rid, EOK, rootp->index, rootp->size,
    482                     rootp->lnkcnt);
    483         }
    484         free(opts);
    485 }
    486 
    487 void tmpfs_mount(ipc_callid_t rid, ipc_call_t *request)
    488 {
    489         libfs_mount(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request);
    490 }
    491 
    492 void tmpfs_unmounted(ipc_callid_t rid, ipc_call_t *request)
    493 {
    494         devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    495 
     455                if (!tmpfs_restore(devmap_handle))
     456                        return ELIMIT;
     457        }
     458
     459        *index = rootp->index;
     460        *size = rootp->size;
     461        *lnkcnt = rootp->lnkcnt;
     462
     463        return EOK;
     464}
     465
     466static int tmpfs_unmounted(devmap_handle_t devmap_handle)
     467{
    496468        tmpfs_instance_done(devmap_handle);
    497         async_answer_0(rid, EOK);
    498 }
    499 
    500 void tmpfs_unmount(ipc_callid_t rid, ipc_call_t *request)
    501 {
    502         libfs_unmount(&tmpfs_libfs_ops, rid, request);
    503 }
    504 
    505 void tmpfs_lookup(ipc_callid_t rid, ipc_call_t *request)
    506 {
    507         libfs_lookup(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request);
    508 }
    509 
    510 void tmpfs_read(ipc_callid_t rid, ipc_call_t *request)
    511 {
    512         devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    513         fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    514         aoff64_t pos =
    515             (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
    516        
     469        return EOK;
     470}
     471
     472static int tmpfs_read(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t pos,
     473    size_t *rbytes)
     474{
    517475        /*
    518476         * Lookup the respective TMPFS node.
     
    524482        };
    525483        hlp = hash_table_find(&nodes, key);
    526         if (!hlp) {
    527                 async_answer_0(rid, ENOENT);
    528                 return;
    529         }
     484        if (!hlp)
     485                return ENOENT;
    530486        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
    531487            nh_link);
     
    538494        if (!async_data_read_receive(&callid, &size)) {
    539495                async_answer_0(callid, EINVAL);
    540                 async_answer_0(rid, EINVAL);
    541                 return;
     496                return EINVAL;
    542497        }
    543498
     
    550505                tmpfs_dentry_t *dentryp;
    551506                link_t *lnk;
    552                 aoff64_t i;
    553507               
    554508                assert(nodep->type == TMPFS_DIRECTORY);
     
    559513                 * hash table.
    560514                 */
    561                 for (i = 0, lnk = nodep->cs_head.next;
    562                     (i < pos) && (lnk != &nodep->cs_head);
    563                     i++, lnk = lnk->next)
    564                         ;
    565 
    566                 if (lnk == &nodep->cs_head) {
     515                lnk = list_nth(&nodep->cs_list, pos);
     516               
     517                if (lnk == NULL) {
    567518                        async_answer_0(callid, ENOENT);
    568                         async_answer_1(rid, ENOENT, 0);
    569                         return;
     519                        return ENOENT;
    570520                }
    571521
     
    577527        }
    578528
    579         /*
    580          * Answer the VFS_READ call.
    581          */
    582         async_answer_1(rid, EOK, bytes);
    583 }
    584 
    585 void tmpfs_write(ipc_callid_t rid, ipc_call_t *request)
    586 {
    587         devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    588         fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    589         aoff64_t pos =
    590             (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
    591        
     529        *rbytes = bytes;
     530        return EOK;
     531}
     532
     533static int
     534tmpfs_write(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t pos,
     535    size_t *wbytes, aoff64_t *nsize)
     536{
    592537        /*
    593538         * Lookup the respective TMPFS node.
     
    599544        };
    600545        hlp = hash_table_find(&nodes, key);
    601         if (!hlp) {
    602                 async_answer_0(rid, ENOENT);
    603                 return;
    604         }
     546        if (!hlp)
     547                return ENOENT;
    605548        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
    606549            nh_link);
     
    613556        if (!async_data_write_receive(&callid, &size)) {
    614557                async_answer_0(callid, EINVAL);
    615                 async_answer_0(rid, EINVAL);
    616                 return;
     558                return EINVAL;
    617559        }
    618560
     
    622564        if (pos + size <= nodep->size) {
    623565                /* The file size is not changing. */
    624                 (void) async_data_write_finalize(callid, nodep->data + pos, size);
    625                 async_answer_2(rid, EOK, size, nodep->size);
    626                 return;
     566                (void) async_data_write_finalize(callid, nodep->data + pos,
     567                    size);
     568                goto out;
    627569        }
    628570        size_t delta = (pos + size) - nodep->size;
     
    637579        if (!newdata) {
    638580                async_answer_0(callid, ENOMEM);
    639                 async_answer_2(rid, EOK, 0, nodep->size);
    640                 return;
     581                size = 0;
     582                goto out;
    641583        }
    642584        /* Clear any newly allocated memory in order to emulate gaps. */
     
    645587        nodep->data = newdata;
    646588        (void) async_data_write_finalize(callid, nodep->data + pos, size);
    647         async_answer_2(rid, EOK, size, nodep->size);
    648 }
    649 
    650 void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request)
    651 {
    652         devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    653         fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    654         aoff64_t size =
    655             (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
    656        
     589
     590out:
     591        *wbytes = size;
     592        *nsize = nodep->size;
     593        return EOK;
     594}
     595
     596static int tmpfs_truncate(devmap_handle_t devmap_handle, fs_index_t index,
     597    aoff64_t size)
     598{
    657599        /*
    658600         * Lookup the respective TMPFS node.
     
    663605        };
    664606        link_t *hlp = hash_table_find(&nodes, key);
    665         if (!hlp) {
    666                 async_answer_0(rid, ENOENT);
    667                 return;
    668         }
    669         tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
    670             nh_link);
    671        
    672         if (size == nodep->size) {
    673                 async_answer_0(rid, EOK);
    674                 return;
    675         }
    676        
    677         if (size > SIZE_MAX) {
    678                 async_answer_0(rid, ENOMEM);
    679                 return;
    680         }
     607        if (!hlp)
     608                return ENOENT;
     609        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, nh_link);
     610       
     611        if (size == nodep->size)
     612                return EOK;
     613       
     614        if (size > SIZE_MAX)
     615                return ENOMEM;
    681616       
    682617        void *newdata = realloc(nodep->data, size);
    683         if (!newdata) {
    684                 async_answer_0(rid, ENOMEM);
    685                 return;
    686         }
     618        if (!newdata)
     619                return ENOMEM;
    687620       
    688621        if (size > nodep->size) {
     
    693626        nodep->size = size;
    694627        nodep->data = newdata;
    695         async_answer_0(rid, EOK);
    696 }
    697 
    698 void tmpfs_close(ipc_callid_t rid, ipc_call_t *request)
    699 {
    700         async_answer_0(rid, EOK);
    701 }
    702 
    703 void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request)
    704 {
    705         devmap_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request);
    706         fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    707         int rc;
    708 
     628        return EOK;
     629}
     630
     631static int tmpfs_close(devmap_handle_t devmap_handle, fs_index_t index)
     632{
     633        return EOK;
     634}
     635
     636static int tmpfs_destroy(devmap_handle_t devmap_handle, fs_index_t index)
     637{
    709638        link_t *hlp;
    710639        unsigned long key[] = {
     
    713642        };
    714643        hlp = hash_table_find(&nodes, key);
    715         if (!hlp) {
    716                 async_answer_0(rid, ENOENT);
    717                 return;
    718         }
     644        if (!hlp)
     645                return ENOENT;
    719646        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
    720647            nh_link);
    721         rc = tmpfs_destroy_node(FS_NODE(nodep));
    722         async_answer_0(rid, rc);
    723 }
    724 
    725 void tmpfs_open_node(ipc_callid_t rid, ipc_call_t *request)
    726 {
    727         libfs_open_node(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request);
    728 }
    729 
    730 void tmpfs_stat(ipc_callid_t rid, ipc_call_t *request)
    731 {
    732         libfs_stat(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request);
    733 }
    734 
    735 void tmpfs_sync(ipc_callid_t rid, ipc_call_t *request)
     648        return tmpfs_destroy_node(FS_NODE(nodep));
     649}
     650
     651static int tmpfs_sync(devmap_handle_t devmap_handle, fs_index_t index)
    736652{
    737653        /*
     
    739655         * thus the sync operation is a no-op.
    740656         */
    741         async_answer_0(rid, EOK);
    742 }
     657        return EOK;
     658}
     659
     660vfs_out_ops_t tmpfs_ops = {
     661        .mounted = tmpfs_mounted,
     662        .unmounted = tmpfs_unmounted,
     663        .read = tmpfs_read,
     664        .write = tmpfs_write,
     665        .truncate = tmpfs_truncate,
     666        .close = tmpfs_close,
     667        .destroy = tmpfs_destroy,
     668        .sync = tmpfs_sync,
     669};
    743670
    744671/**
    745672 * @}
    746673 */
     674
Note: See TracChangeset for help on using the changeset viewer.