Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/fat/fat_idx.c

    r19f857a rc7bbf029  
    4444#include <assert.h>
    4545#include <fibril_synch.h>
     46#include <malloc.h>
    4647
    4748/** Each instance of this type describes one interval of freed VFS indices. */
     
    5859typedef struct {
    5960        link_t          link;
    60         dev_handle_t    dev_handle;
     61        devmap_handle_t devmap_handle;
    6162
    6263        /** Next unassigned index. */
     
    7576static LIST_INITIALIZE(unused_head);
    7677
    77 static void unused_initialize(unused_t *u, dev_handle_t dev_handle)
     78static void unused_initialize(unused_t *u, devmap_handle_t devmap_handle)
    7879{
    7980        link_initialize(&u->link);
    80         u->dev_handle = dev_handle;
     81        u->devmap_handle = devmap_handle;
    8182        u->next = 0;
    8283        u->remaining = ((uint64_t)((fs_index_t)-1)) + 1;
     
    8485}
    8586
    86 static unused_t *unused_find(dev_handle_t dev_handle, bool lock)
     87static unused_t *unused_find(devmap_handle_t devmap_handle, bool lock)
    8788{
    8889        unused_t *u;
     
    9394        for (l = unused_head.next; l != &unused_head; l = l->next) {
    9495                u = list_get_instance(l, unused_t, link);
    95                 if (u->dev_handle == dev_handle)
     96                if (u->devmap_handle == devmap_handle)
    9697                        return u;
    9798        }
     
    106107/**
    107108 * Global hash table of all used fat_idx_t structures.
    108  * The index structures are hashed by the dev_handle, parent node's first
     109 * The index structures are hashed by the devmap_handle, parent node's first
    109110 * cluster and index within the parent directory.
    110111 */
     
    120121static hash_index_t pos_hash(unsigned long key[])
    121122{
    122         dev_handle_t dev_handle = (dev_handle_t)key[UPH_DH_KEY];
     123        devmap_handle_t devmap_handle = (devmap_handle_t)key[UPH_DH_KEY];
    123124        fat_cluster_t pfc = (fat_cluster_t)key[UPH_PFC_KEY];
    124125        unsigned pdi = (unsigned)key[UPH_PDI_KEY];
     
    140141        h |= (pdi & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
    141142            (UPH_BUCKETS_LOG / 2);
    142         h |= (dev_handle & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
     143        h |= (devmap_handle & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
    143144            (3 * (UPH_BUCKETS_LOG / 4));
    144145
     
    148149static int pos_compare(unsigned long key[], hash_count_t keys, link_t *item)
    149150{
    150         dev_handle_t dev_handle = (dev_handle_t)key[UPH_DH_KEY];
     151        devmap_handle_t devmap_handle = (devmap_handle_t)key[UPH_DH_KEY];
    151152        fat_cluster_t pfc;
    152153        unsigned pdi;
     
    155156        switch (keys) {
    156157        case 1:
    157                 return (dev_handle == fidx->dev_handle);
     158                return (devmap_handle == fidx->devmap_handle);
    158159        case 3:
    159160                pfc = (fat_cluster_t) key[UPH_PFC_KEY];
    160161                pdi = (unsigned) key[UPH_PDI_KEY];
    161                 return (dev_handle == fidx->dev_handle) && (pfc == fidx->pfc) &&
     162                return (devmap_handle == fidx->devmap_handle) && (pfc == fidx->pfc) &&
    162163                    (pdi == fidx->pdi);
    163164        default:
     
    181182/**
    182183 * Global hash table of all used fat_idx_t structures.
    183  * The index structures are hashed by the dev_handle and index.
     184 * The index structures are hashed by the devmap_handle and index.
    184185 */
    185186static hash_table_t ui_hash;
     
    193194static hash_index_t idx_hash(unsigned long key[])
    194195{
    195         dev_handle_t dev_handle = (dev_handle_t)key[UIH_DH_KEY];
     196        devmap_handle_t devmap_handle = (devmap_handle_t)key[UIH_DH_KEY];
    196197        fs_index_t index = (fs_index_t)key[UIH_INDEX_KEY];
    197198
    198199        hash_index_t h;
    199200
    200         h = dev_handle & ((1 << (UIH_BUCKETS_LOG / 2)) - 1);
     201        h = devmap_handle & ((1 << (UIH_BUCKETS_LOG / 2)) - 1);
    201202        h |= (index & ((1 << (UIH_BUCKETS_LOG / 2)) - 1)) <<
    202203            (UIH_BUCKETS_LOG / 2);
     
    207208static int idx_compare(unsigned long key[], hash_count_t keys, link_t *item)
    208209{
    209         dev_handle_t dev_handle = (dev_handle_t)key[UIH_DH_KEY];
     210        devmap_handle_t devmap_handle = (devmap_handle_t)key[UIH_DH_KEY];
    210211        fs_index_t index;
    211212        fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uih_link);
     
    213214        switch (keys) {
    214215        case 1:
    215                 return (dev_handle == fidx->dev_handle);
     216                return (devmap_handle == fidx->devmap_handle);
    216217        case 2:
    217218                index = (fs_index_t) key[UIH_INDEX_KEY];
    218                 return (dev_handle == fidx->dev_handle) &&
     219                return (devmap_handle == fidx->devmap_handle) &&
    219220                    (index == fidx->index);
    220221        default:
     
    239240
    240241/** Allocate a VFS index which is not currently in use. */
    241 static bool fat_index_alloc(dev_handle_t dev_handle, fs_index_t *index)
     242static bool fat_index_alloc(devmap_handle_t devmap_handle, fs_index_t *index)
    242243{
    243244        unused_t *u;
    244245       
    245246        assert(index);
    246         u = unused_find(dev_handle, true);
     247        u = unused_find(devmap_handle, true);
    247248        if (!u)
    248249                return false;   
     
    301302
    302303/** Free a VFS index, which is no longer in use. */
    303 static void fat_index_free(dev_handle_t dev_handle, fs_index_t index)
     304static void fat_index_free(devmap_handle_t devmap_handle, fs_index_t index)
    304305{
    305306        unused_t *u;
    306307
    307         u = unused_find(dev_handle, true);
     308        u = unused_find(devmap_handle, true);
    308309        assert(u);
    309310
     
    363364}
    364365
    365 static int fat_idx_create(fat_idx_t **fidxp, dev_handle_t dev_handle)
     366static int fat_idx_create(fat_idx_t **fidxp, devmap_handle_t devmap_handle)
    366367{
    367368        fat_idx_t *fidx;
     
    370371        if (!fidx)
    371372                return ENOMEM;
    372         if (!fat_index_alloc(dev_handle, &fidx->index)) {
     373        if (!fat_index_alloc(devmap_handle, &fidx->index)) {
    373374                free(fidx);
    374375                return ENOSPC;
     
    378379        link_initialize(&fidx->uih_link);
    379380        fibril_mutex_initialize(&fidx->lock);
    380         fidx->dev_handle = dev_handle;
     381        fidx->devmap_handle = devmap_handle;
    381382        fidx->pfc = FAT_CLST_RES0;      /* no parent yet */
    382383        fidx->pdi = 0;
     
    387388}
    388389
    389 int fat_idx_get_new(fat_idx_t **fidxp, dev_handle_t dev_handle)
     390int fat_idx_get_new(fat_idx_t **fidxp, devmap_handle_t devmap_handle)
    390391{
    391392        fat_idx_t *fidx;
     
    393394
    394395        fibril_mutex_lock(&used_lock);
    395         rc = fat_idx_create(&fidx, dev_handle);
     396        rc = fat_idx_create(&fidx, devmap_handle);
    396397        if (rc != EOK) {
    397398                fibril_mutex_unlock(&used_lock);
     
    400401               
    401402        unsigned long ikey[] = {
    402                 [UIH_DH_KEY] = dev_handle,
     403                [UIH_DH_KEY] = devmap_handle,
    403404                [UIH_INDEX_KEY] = fidx->index,
    404405        };
     
    413414
    414415fat_idx_t *
    415 fat_idx_get_by_pos(dev_handle_t dev_handle, fat_cluster_t pfc, unsigned pdi)
     416fat_idx_get_by_pos(devmap_handle_t devmap_handle, fat_cluster_t pfc, unsigned pdi)
    416417{
    417418        fat_idx_t *fidx;
    418419        link_t *l;
    419420        unsigned long pkey[] = {
    420                 [UPH_DH_KEY] = dev_handle,
     421                [UPH_DH_KEY] = devmap_handle,
    421422                [UPH_PFC_KEY] = pfc,
    422423                [UPH_PDI_KEY] = pdi,
     
    430431                int rc;
    431432
    432                 rc = fat_idx_create(&fidx, dev_handle);
     433                rc = fat_idx_create(&fidx, devmap_handle);
    433434                if (rc != EOK) {
    434435                        fibril_mutex_unlock(&used_lock);
     
    437438               
    438439                unsigned long ikey[] = {
    439                         [UIH_DH_KEY] = dev_handle,
     440                        [UIH_DH_KEY] = devmap_handle,
    440441                        [UIH_INDEX_KEY] = fidx->index,
    441442                };
     
    456457{
    457458        unsigned long pkey[] = {
    458                 [UPH_DH_KEY] = idx->dev_handle,
     459                [UPH_DH_KEY] = idx->devmap_handle,
    459460                [UPH_PFC_KEY] = idx->pfc,
    460461                [UPH_PDI_KEY] = idx->pdi,
     
    469470{
    470471        unsigned long pkey[] = {
    471                 [UPH_DH_KEY] = idx->dev_handle,
     472                [UPH_DH_KEY] = idx->devmap_handle,
    472473                [UPH_PFC_KEY] = idx->pfc,
    473474                [UPH_PDI_KEY] = idx->pdi,
     
    480481
    481482fat_idx_t *
    482 fat_idx_get_by_index(dev_handle_t dev_handle, fs_index_t index)
     483fat_idx_get_by_index(devmap_handle_t devmap_handle, fs_index_t index)
    483484{
    484485        fat_idx_t *fidx = NULL;
    485486        link_t *l;
    486487        unsigned long ikey[] = {
    487                 [UIH_DH_KEY] = dev_handle,
     488                [UIH_DH_KEY] = devmap_handle,
    488489                [UIH_INDEX_KEY] = index,
    489490        };
     
    507508{
    508509        unsigned long ikey[] = {
    509                 [UIH_DH_KEY] = idx->dev_handle,
     510                [UIH_DH_KEY] = idx->devmap_handle,
    510511                [UIH_INDEX_KEY] = idx->index,
    511512        };
    512         dev_handle_t dev_handle = idx->dev_handle;
     513        devmap_handle_t devmap_handle = idx->devmap_handle;
    513514        fs_index_t index = idx->index;
    514515
     
    524525        fibril_mutex_unlock(&used_lock);
    525526        /* Release the VFS index. */
    526         fat_index_free(dev_handle, index);
     527        fat_index_free(devmap_handle, index);
    527528        /* The index structure itself is freed in idx_remove_callback(). */
    528529}
     
    546547}
    547548
    548 int fat_idx_init_by_dev_handle(dev_handle_t dev_handle)
     549int fat_idx_init_by_devmap_handle(devmap_handle_t devmap_handle)
    549550{
    550551        unused_t *u;
     
    554555        if (!u)
    555556                return ENOMEM;
    556         unused_initialize(u, dev_handle);
     557        unused_initialize(u, devmap_handle);
    557558        fibril_mutex_lock(&unused_lock);
    558         if (!unused_find(dev_handle, false)) {
     559        if (!unused_find(devmap_handle, false)) {
    559560                list_append(&u->link, &unused_head);
    560561        } else {
     
    566567}
    567568
    568 void fat_idx_fini_by_dev_handle(dev_handle_t dev_handle)
     569void fat_idx_fini_by_devmap_handle(devmap_handle_t devmap_handle)
    569570{
    570571        unsigned long ikey[] = {
    571                 [UIH_DH_KEY] = dev_handle
     572                [UIH_DH_KEY] = devmap_handle
    572573        };
    573574        unsigned long pkey[] = {
    574                 [UPH_DH_KEY] = dev_handle
     575                [UPH_DH_KEY] = devmap_handle
    575576        };
    576577
     
    588589         * Free the unused and freed structures for this instance.
    589590         */
    590         unused_t *u = unused_find(dev_handle, true);
     591        unused_t *u = unused_find(devmap_handle, true);
    591592        assert(u);
    592593        list_remove(&u->link);
Note: See TracChangeset for help on using the changeset viewer.