Ignore:
File:
1 edited

Legend:

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

    r4cac2d69 r1313ee9  
    147147hash_table_t nodes;
    148148
    149 #define NODES_KEY_DEV   0       
    150 #define NODES_KEY_INDEX 1
     149#define NODES_KEY_INDEX 0
     150#define NODES_KEY_DEV   1
    151151
    152152/* Implementation of hash table interface for the nodes hash table. */
     
    160160        tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t,
    161161            nh_link);
    162        
    163         switch (keys) {
    164         case 1:
    165                 return (nodep->dev_handle == key[NODES_KEY_DEV]);
    166         case 2:
    167                 return ((nodep->dev_handle == key[NODES_KEY_DEV]) &&
    168                     (nodep->index == key[NODES_KEY_INDEX]));
    169         default:
    170                 abort();
    171         }
     162        return (nodep->index == key[NODES_KEY_INDEX] &&
     163            nodep->dev_handle == key[NODES_KEY_DEV]);
    172164}
    173165
    174166static void nodes_remove_callback(link_t *item)
    175167{
    176         tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t,
    177             nh_link);
    178 
    179         while (!list_empty(&nodep->cs_head)) {
    180                 tmpfs_dentry_t *dentryp = list_get_instance(nodep->cs_head.next,
    181                     tmpfs_dentry_t, link);
    182 
    183                 assert(nodep->type == TMPFS_DIRECTORY);
    184                 list_remove(&dentryp->link);
    185                 free(dentryp);
    186         }
    187 
    188         if (nodep->data) {
    189                 assert(nodep->type == TMPFS_FILE);
    190                 free(nodep->data);
    191         }
    192         free(nodep->bp);
    193         free(nodep);
    194168}
    195169
     
    241215}
    242216
    243 static void tmpfs_instance_done(dev_handle_t dev_handle)
    244 {
    245         unsigned long key[] = {
    246                 [NODES_KEY_DEV] = dev_handle
    247         };
    248         /*
    249          * Here we are making use of one special feature of our hash table
    250          * implementation, which allows to remove more items based on a partial
    251          * key match. In the following, we are going to remove all nodes
    252          * matching our device handle. The nodes_remove_callback() function will
    253          * take care of resource deallocation.
    254          */
    255         hash_table_remove(&nodes, key, 1);
    256 }
    257 
    258217int tmpfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
    259218{
     
    278237{
    279238        unsigned long key[] = {
    280                 [NODES_KEY_DEV] = dev_handle,
    281                 [NODES_KEY_INDEX] = index
     239                [NODES_KEY_INDEX] = index,
     240                [NODES_KEY_DEV] = dev_handle
    282241        };
    283242        link_t *lnk = hash_table_find(&nodes, key);
     
    337296        /* Insert the new node into the nodes hash table. */
    338297        unsigned long key[] = {
    339                 [NODES_KEY_DEV] = nodep->dev_handle,
    340                 [NODES_KEY_INDEX] = nodep->index
     298                [NODES_KEY_INDEX] = nodep->index,
     299                [NODES_KEY_DEV] = nodep->dev_handle
    341300        };
    342301        hash_table_insert(&nodes, key, &nodep->nh_link);
     
    353312
    354313        unsigned long key[] = {
    355                 [NODES_KEY_DEV] = nodep->dev_handle,
    356                 [NODES_KEY_INDEX] = nodep->index
     314                [NODES_KEY_INDEX] = nodep->index,
     315                [NODES_KEY_DEV] = nodep->dev_handle
    357316        };
    358317        hash_table_remove(&nodes, key, 2);
    359318
    360         /*
    361          * The nodes_remove_callback() function takes care of the actual
    362          * resource deallocation.
    363          */
     319        if (nodep->type == TMPFS_FILE)
     320                free(nodep->data);
     321        free(nodep->bp);
     322        free(nodep);
    364323        return EOK;
    365324}
     
    439398{
    440399        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
    441        
    442         /* Accept the mount options */
    443         char *opts;
    444         int rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL);
    445        
    446         if (rc != EOK) {
    447                 ipc_answer_0(rid, rc);
    448                 return;
    449         }
     400        int rc;
     401
     402        /* accept the mount options */
     403        ipc_callid_t callid;
     404        size_t size;
     405        if (!async_data_write_receive(&callid, &size)) {
     406                ipc_answer_0(callid, EINVAL);
     407                ipc_answer_0(rid, EINVAL);
     408                return;
     409        }
     410        char *opts = malloc(size + 1);
     411        if (!opts) {
     412                ipc_answer_0(callid, ENOMEM);
     413                ipc_answer_0(rid, ENOMEM);
     414                return;
     415        }
     416        ipcarg_t retval = async_data_write_finalize(callid, opts, size);
     417        if (retval != EOK) {
     418                ipc_answer_0(rid, retval);
     419                free(opts);
     420                return;
     421        }
     422        opts[size] = '\0';
    450423
    451424        /* Initialize TMPFS instance. */
    452425        if (!tmpfs_instance_init(dev_handle)) {
    453                 free(opts);
    454426                ipc_answer_0(rid, ENOMEM);
    455427                return;
     
    470442                    rootp->lnkcnt);
    471443        }
    472         free(opts);
    473444}
    474445
     
    476447{
    477448        libfs_mount(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request);
    478 }
    479 
    480 void tmpfs_unmounted(ipc_callid_t rid, ipc_call_t *request)
    481 {
    482         dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
    483 
    484         tmpfs_instance_done(dev_handle);
    485         ipc_answer_0(rid, EOK);
    486 }
    487 
    488 void tmpfs_unmount(ipc_callid_t rid, ipc_call_t *request)
    489 {
    490         libfs_unmount(&tmpfs_libfs_ops, rid, request);
    491449}
    492450
     
    507465        link_t *hlp;
    508466        unsigned long key[] = {
     467                [NODES_KEY_INDEX] = index,
    509468                [NODES_KEY_DEV] = dev_handle,
    510                 [NODES_KEY_INDEX] = index
    511469        };
    512470        hlp = hash_table_find(&nodes, key);
     
    581539        link_t *hlp;
    582540        unsigned long key[] = {
    583                 [NODES_KEY_DEV] = dev_handle,
    584                 [NODES_KEY_INDEX] = index
     541                [NODES_KEY_INDEX] = index,
     542                [NODES_KEY_DEV] = dev_handle
    585543        };
    586544        hlp = hash_table_find(&nodes, key);
     
    645603        link_t *hlp;
    646604        unsigned long key[] = {
    647                 [NODES_KEY_DEV] = dev_handle,
    648                 [NODES_KEY_INDEX] = index
     605                [NODES_KEY_INDEX] = index,
     606                [NODES_KEY_DEV] = dev_handle
    649607        };
    650608        hlp = hash_table_find(&nodes, key);
     
    688646        link_t *hlp;
    689647        unsigned long key[] = {
    690                 [NODES_KEY_DEV] = dev_handle,
    691                 [NODES_KEY_INDEX] = index
     648                [NODES_KEY_INDEX] = index,
     649                [NODES_KEY_DEV] = dev_handle
    692650        };
    693651        hlp = hash_table_find(&nodes, key);
Note: See TracChangeset for help on using the changeset viewer.