Ignore:
File:
1 edited

Legend:

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

    r472c09d r0da4e41  
    6969static int tmpfs_match(fs_node_t **, fs_node_t *, const char *);
    7070static int tmpfs_node_get(fs_node_t **, dev_handle_t, fs_index_t);
    71 static int tmpfs_node_open(fs_node_t *);
    7271static int tmpfs_node_put(fs_node_t *);
    7372static int tmpfs_create_node(fs_node_t **, dev_handle_t, int);
     
    118117}
    119118
    120 static dev_handle_t tmpfs_device_get(fs_node_t *fn)
    121 {
    122         return 0;
    123 }
    124 
    125119/** libfs operations */
    126120libfs_ops_t tmpfs_libfs_ops = {
     
    128122        .match = tmpfs_match,
    129123        .node_get = tmpfs_node_get,
    130         .node_open = tmpfs_node_open,
    131124        .node_put = tmpfs_node_put,
    132125        .create = tmpfs_create_node,
     
    140133        .plb_get_char = tmpfs_plb_get_char,
    141134        .is_directory = tmpfs_is_directory,
    142         .is_file = tmpfs_is_file,
    143         .device_get = tmpfs_device_get
     135        .is_file = tmpfs_is_file
    144136};
    145137
     
    147139hash_table_t nodes;
    148140
    149 #define NODES_KEY_DEV   0       
    150 #define NODES_KEY_INDEX 1
     141#define NODES_KEY_INDEX 0
     142#define NODES_KEY_DEV   1
    151143
    152144/* Implementation of hash table interface for the nodes hash table. */
     
    160152        tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t,
    161153            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         }
     154        return (nodep->index == key[NODES_KEY_INDEX] &&
     155            nodep->dev_handle == key[NODES_KEY_DEV]);
    172156}
    173157
    174158static void nodes_remove_callback(link_t *item)
    175159{
    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);
    194160}
    195161
     
    241207}
    242208
    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 
    258209int tmpfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
    259210{
     
    278229{
    279230        unsigned long key[] = {
    280                 [NODES_KEY_DEV] = dev_handle,
    281                 [NODES_KEY_INDEX] = index
     231                [NODES_KEY_INDEX] = index,
     232                [NODES_KEY_DEV] = dev_handle
    282233        };
    283234        link_t *lnk = hash_table_find(&nodes, key);
     
    290241        }
    291242        return EOK;     
    292 }
    293 
    294 int tmpfs_node_open(fs_node_t *fn)
    295 {
    296         /* nothing to do */
    297         return EOK;
    298243}
    299244
     
    337282        /* Insert the new node into the nodes hash table. */
    338283        unsigned long key[] = {
    339                 [NODES_KEY_DEV] = nodep->dev_handle,
    340                 [NODES_KEY_INDEX] = nodep->index
     284                [NODES_KEY_INDEX] = nodep->index,
     285                [NODES_KEY_DEV] = nodep->dev_handle
    341286        };
    342287        hash_table_insert(&nodes, key, &nodep->nh_link);
     
    353298
    354299        unsigned long key[] = {
    355                 [NODES_KEY_DEV] = nodep->dev_handle,
    356                 [NODES_KEY_INDEX] = nodep->index
     300                [NODES_KEY_INDEX] = nodep->index,
     301                [NODES_KEY_DEV] = nodep->dev_handle
    357302        };
    358303        hash_table_remove(&nodes, key, 2);
    359304
    360         /*
    361          * The nodes_remove_callback() function takes care of the actual
    362          * resource deallocation.
    363          */
     305        if (nodep->type == TMPFS_FILE)
     306                free(nodep->data);
     307        free(nodep->bp);
     308        free(nodep);
    364309        return EOK;
    365310}
     
    439384{
    440385        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_string_receive(&opts, 0, NULL);
    445        
    446         if (rc != EOK) {
    447                 ipc_answer_0(rid, rc);
    448                 return;
    449         }
     386        int rc;
     387
     388        /* accept the mount options */
     389        ipc_callid_t callid;
     390        size_t size;
     391        if (!async_data_write_receive(&callid, &size)) {
     392                ipc_answer_0(callid, EINVAL);
     393                ipc_answer_0(rid, EINVAL);
     394                return;
     395        }
     396        char *opts = malloc(size + 1);
     397        if (!opts) {
     398                ipc_answer_0(callid, ENOMEM);
     399                ipc_answer_0(rid, ENOMEM);
     400                return;
     401        }
     402        ipcarg_t retval = async_data_write_finalize(callid, opts, size);
     403        if (retval != EOK) {
     404                ipc_answer_0(rid, retval);
     405                free(opts);
     406                return;
     407        }
     408        opts[size] = '\0';
    450409
    451410        /* Initialize TMPFS instance. */
    452411        if (!tmpfs_instance_init(dev_handle)) {
    453                 free(opts);
    454412                ipc_answer_0(rid, ENOMEM);
    455413                return;
     
    470428                    rootp->lnkcnt);
    471429        }
    472         free(opts);
    473430}
    474431
     
    476433{
    477434        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);
    491435}
    492436
     
    507451        link_t *hlp;
    508452        unsigned long key[] = {
     453                [NODES_KEY_INDEX] = index,
    509454                [NODES_KEY_DEV] = dev_handle,
    510                 [NODES_KEY_INDEX] = index
    511455        };
    512456        hlp = hash_table_find(&nodes, key);
     
    581525        link_t *hlp;
    582526        unsigned long key[] = {
    583                 [NODES_KEY_DEV] = dev_handle,
    584                 [NODES_KEY_INDEX] = index
     527                [NODES_KEY_INDEX] = index,
     528                [NODES_KEY_DEV] = dev_handle
    585529        };
    586530        hlp = hash_table_find(&nodes, key);
     
    645589        link_t *hlp;
    646590        unsigned long key[] = {
    647                 [NODES_KEY_DEV] = dev_handle,
    648                 [NODES_KEY_INDEX] = index
     591                [NODES_KEY_INDEX] = index,
     592                [NODES_KEY_DEV] = dev_handle
    649593        };
    650594        hlp = hash_table_find(&nodes, key);
     
    688632        link_t *hlp;
    689633        unsigned long key[] = {
    690                 [NODES_KEY_DEV] = dev_handle,
    691                 [NODES_KEY_INDEX] = index
     634                [NODES_KEY_INDEX] = index,
     635                [NODES_KEY_DEV] = dev_handle
    692636        };
    693637        hlp = hash_table_find(&nodes, key);
Note: See TracChangeset for help on using the changeset viewer.