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


Ignore:
Timestamp:
2011-07-26T21:17:29Z (13 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
051e6ac, 0837ab4
Parents:
2f02ee25 (diff), 75aa59a (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

    r2f02ee25 r056d6821  
    104104}
    105105
    106 static char tmpfs_plb_get_char(unsigned pos)
    107 {
    108         return tmpfs_reg.plb_ro[pos % PLB_SIZE];
    109 }
    110 
    111106static bool tmpfs_is_directory(fs_node_t *fn)
    112107{
     
    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,
     
    433427}
    434428
    435 void tmpfs_mounted(ipc_callid_t rid, ipc_call_t *request)
    436 {
    437         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{
    438437        fs_node_t *rootfn;
    439438        int rc;
    440439       
    441         /* Accept the mount options. */
    442         char *opts;
    443         rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL);
    444         if (rc != EOK) {
    445                 async_answer_0(rid, rc);
    446                 return;
    447         }
    448 
    449440        /* Check if this device is not already mounted. */
    450441        rc = tmpfs_root_get(&rootfn, devmap_handle);
    451442        if ((rc == EOK) && (rootfn)) {
    452443                (void) tmpfs_node_put(rootfn);
    453                 free(opts);
    454                 async_answer_0(rid, EEXIST);
    455                 return;
     444                return EEXIST;
    456445        }
    457446
    458447        /* Initialize TMPFS instance. */
    459         if (!tmpfs_instance_init(devmap_handle)) {
    460                 free(opts);
    461                 async_answer_0(rid, ENOMEM);
    462                 return;
    463         }
     448        if (!tmpfs_instance_init(devmap_handle))
     449                return ENOMEM;
    464450
    465451        rc = tmpfs_root_get(&rootfn, devmap_handle);
     
    467453        tmpfs_node_t *rootp = TMPFS_NODE(rootfn);
    468454        if (str_cmp(opts, "restore") == 0) {
    469                 if (tmpfs_restore(devmap_handle))
    470                         async_answer_3(rid, EOK, rootp->index, rootp->size,
    471                             rootp->lnkcnt);
    472                 else
    473                         async_answer_0(rid, ELIMIT);
    474         } else {
    475                 async_answer_3(rid, EOK, rootp->index, rootp->size,
    476                     rootp->lnkcnt);
    477         }
    478         free(opts);
    479 }
    480 
    481 void tmpfs_mount(ipc_callid_t rid, ipc_call_t *request)
    482 {
    483         libfs_mount(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request);
    484 }
    485 
    486 void tmpfs_unmounted(ipc_callid_t rid, ipc_call_t *request)
    487 {
    488         devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    489 
     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{
    490468        tmpfs_instance_done(devmap_handle);
    491         async_answer_0(rid, EOK);
    492 }
    493 
    494 void tmpfs_unmount(ipc_callid_t rid, ipc_call_t *request)
    495 {
    496         libfs_unmount(&tmpfs_libfs_ops, rid, request);
    497 }
    498 
    499 void tmpfs_lookup(ipc_callid_t rid, ipc_call_t *request)
    500 {
    501         libfs_lookup(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request);
    502 }
    503 
    504 void tmpfs_read(ipc_callid_t rid, ipc_call_t *request)
    505 {
    506         devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    507         fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    508         aoff64_t pos =
    509             (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
    510        
     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{
    511475        /*
    512476         * Lookup the respective TMPFS node.
     
    518482        };
    519483        hlp = hash_table_find(&nodes, key);
    520         if (!hlp) {
    521                 async_answer_0(rid, ENOENT);
    522                 return;
    523         }
     484        if (!hlp)
     485                return ENOENT;
    524486        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
    525487            nh_link);
     
    532494        if (!async_data_read_receive(&callid, &size)) {
    533495                async_answer_0(callid, EINVAL);
    534                 async_answer_0(rid, EINVAL);
    535                 return;
     496                return EINVAL;
    536497        }
    537498
     
    556517                if (lnk == NULL) {
    557518                        async_answer_0(callid, ENOENT);
    558                         async_answer_1(rid, ENOENT, 0);
    559                         return;
     519                        return ENOENT;
    560520                }
    561521
     
    567527        }
    568528
    569         /*
    570          * Answer the VFS_READ call.
    571          */
    572         async_answer_1(rid, EOK, bytes);
    573 }
    574 
    575 void tmpfs_write(ipc_callid_t rid, ipc_call_t *request)
    576 {
    577         devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    578         fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    579         aoff64_t pos =
    580             (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
    581        
     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{
    582537        /*
    583538         * Lookup the respective TMPFS node.
     
    589544        };
    590545        hlp = hash_table_find(&nodes, key);
    591         if (!hlp) {
    592                 async_answer_0(rid, ENOENT);
    593                 return;
    594         }
     546        if (!hlp)
     547                return ENOENT;
    595548        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
    596549            nh_link);
     
    603556        if (!async_data_write_receive(&callid, &size)) {
    604557                async_answer_0(callid, EINVAL);
    605                 async_answer_0(rid, EINVAL);
    606                 return;
     558                return EINVAL;
    607559        }
    608560
     
    612564        if (pos + size <= nodep->size) {
    613565                /* The file size is not changing. */
    614                 (void) async_data_write_finalize(callid, nodep->data + pos, size);
    615                 async_answer_2(rid, EOK, size, nodep->size);
    616                 return;
     566                (void) async_data_write_finalize(callid, nodep->data + pos,
     567                    size);
     568                goto out;
    617569        }
    618570        size_t delta = (pos + size) - nodep->size;
     
    627579        if (!newdata) {
    628580                async_answer_0(callid, ENOMEM);
    629                 async_answer_2(rid, EOK, 0, nodep->size);
    630                 return;
     581                size = 0;
     582                goto out;
    631583        }
    632584        /* Clear any newly allocated memory in order to emulate gaps. */
     
    635587        nodep->data = newdata;
    636588        (void) async_data_write_finalize(callid, nodep->data + pos, size);
    637         async_answer_2(rid, EOK, size, nodep->size);
    638 }
    639 
    640 void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request)
    641 {
    642         devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    643         fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    644         aoff64_t size =
    645             (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
    646        
     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{
    647599        /*
    648600         * Lookup the respective TMPFS node.
     
    653605        };
    654606        link_t *hlp = hash_table_find(&nodes, key);
    655         if (!hlp) {
    656                 async_answer_0(rid, ENOENT);
    657                 return;
    658         }
    659         tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
    660             nh_link);
    661        
    662         if (size == nodep->size) {
    663                 async_answer_0(rid, EOK);
    664                 return;
    665         }
    666        
    667         if (size > SIZE_MAX) {
    668                 async_answer_0(rid, ENOMEM);
    669                 return;
    670         }
     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;
    671616       
    672617        void *newdata = realloc(nodep->data, size);
    673         if (!newdata) {
    674                 async_answer_0(rid, ENOMEM);
    675                 return;
    676         }
     618        if (!newdata)
     619                return ENOMEM;
    677620       
    678621        if (size > nodep->size) {
     
    683626        nodep->size = size;
    684627        nodep->data = newdata;
    685         async_answer_0(rid, EOK);
    686 }
    687 
    688 void tmpfs_close(ipc_callid_t rid, ipc_call_t *request)
    689 {
    690         async_answer_0(rid, EOK);
    691 }
    692 
    693 void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request)
    694 {
    695         devmap_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request);
    696         fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    697         int rc;
    698 
     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{
    699638        link_t *hlp;
    700639        unsigned long key[] = {
     
    703642        };
    704643        hlp = hash_table_find(&nodes, key);
    705         if (!hlp) {
    706                 async_answer_0(rid, ENOENT);
    707                 return;
    708         }
     644        if (!hlp)
     645                return ENOENT;
    709646        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
    710647            nh_link);
    711         rc = tmpfs_destroy_node(FS_NODE(nodep));
    712         async_answer_0(rid, rc);
    713 }
    714 
    715 void tmpfs_open_node(ipc_callid_t rid, ipc_call_t *request)
    716 {
    717         libfs_open_node(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request);
    718 }
    719 
    720 void tmpfs_stat(ipc_callid_t rid, ipc_call_t *request)
    721 {
    722         libfs_stat(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request);
    723 }
    724 
    725 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)
    726652{
    727653        /*
     
    729655         * thus the sync operation is a no-op.
    730656         */
    731         async_answer_0(rid, EOK);
    732 }
     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};
    733670
    734671/**
    735672 * @}
    736673 */
     674
Note: See TracChangeset for help on using the changeset viewer.