Ignore:
File:
1 edited

Legend:

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

    rc7bbf029 r19f857a  
    4444#include <assert.h>
    4545#include <fibril_synch.h>
    46 #include <malloc.h>
    4746
    4847/** Each instance of this type describes one interval of freed VFS indices. */
     
    5958typedef struct {
    6059        link_t          link;
    61         devmap_handle_t devmap_handle;
     60        dev_handle_t    dev_handle;
    6261
    6362        /** Next unassigned index. */
     
    7675static LIST_INITIALIZE(unused_head);
    7776
    78 static void unused_initialize(unused_t *u, devmap_handle_t devmap_handle)
     77static void unused_initialize(unused_t *u, dev_handle_t dev_handle)
    7978{
    8079        link_initialize(&u->link);
    81         u->devmap_handle = devmap_handle;
     80        u->dev_handle = dev_handle;
    8281        u->next = 0;
    8382        u->remaining = ((uint64_t)((fs_index_t)-1)) + 1;
     
    8584}
    8685
    87 static unused_t *unused_find(devmap_handle_t devmap_handle, bool lock)
     86static unused_t *unused_find(dev_handle_t dev_handle, bool lock)
    8887{
    8988        unused_t *u;
     
    9493        for (l = unused_head.next; l != &unused_head; l = l->next) {
    9594                u = list_get_instance(l, unused_t, link);
    96                 if (u->devmap_handle == devmap_handle)
     95                if (u->dev_handle == dev_handle)
    9796                        return u;
    9897        }
     
    107106/**
    108107 * Global hash table of all used fat_idx_t structures.
    109  * The index structures are hashed by the devmap_handle, parent node's first
     108 * The index structures are hashed by the dev_handle, parent node's first
    110109 * cluster and index within the parent directory.
    111110 */
     
    121120static hash_index_t pos_hash(unsigned long key[])
    122121{
    123         devmap_handle_t devmap_handle = (devmap_handle_t)key[UPH_DH_KEY];
     122        dev_handle_t dev_handle = (dev_handle_t)key[UPH_DH_KEY];
    124123        fat_cluster_t pfc = (fat_cluster_t)key[UPH_PFC_KEY];
    125124        unsigned pdi = (unsigned)key[UPH_PDI_KEY];
     
    141140        h |= (pdi & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
    142141            (UPH_BUCKETS_LOG / 2);
    143         h |= (devmap_handle & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
     142        h |= (dev_handle & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
    144143            (3 * (UPH_BUCKETS_LOG / 4));
    145144
     
    149148static int pos_compare(unsigned long key[], hash_count_t keys, link_t *item)
    150149{
    151         devmap_handle_t devmap_handle = (devmap_handle_t)key[UPH_DH_KEY];
     150        dev_handle_t dev_handle = (dev_handle_t)key[UPH_DH_KEY];
    152151        fat_cluster_t pfc;
    153152        unsigned pdi;
     
    156155        switch (keys) {
    157156        case 1:
    158                 return (devmap_handle == fidx->devmap_handle);
     157                return (dev_handle == fidx->dev_handle);
    159158        case 3:
    160159                pfc = (fat_cluster_t) key[UPH_PFC_KEY];
    161160                pdi = (unsigned) key[UPH_PDI_KEY];
    162                 return (devmap_handle == fidx->devmap_handle) && (pfc == fidx->pfc) &&
     161                return (dev_handle == fidx->dev_handle) && (pfc == fidx->pfc) &&
    163162                    (pdi == fidx->pdi);
    164163        default:
     
    182181/**
    183182 * Global hash table of all used fat_idx_t structures.
    184  * The index structures are hashed by the devmap_handle and index.
     183 * The index structures are hashed by the dev_handle and index.
    185184 */
    186185static hash_table_t ui_hash;
     
    194193static hash_index_t idx_hash(unsigned long key[])
    195194{
    196         devmap_handle_t devmap_handle = (devmap_handle_t)key[UIH_DH_KEY];
     195        dev_handle_t dev_handle = (dev_handle_t)key[UIH_DH_KEY];
    197196        fs_index_t index = (fs_index_t)key[UIH_INDEX_KEY];
    198197
    199198        hash_index_t h;
    200199
    201         h = devmap_handle & ((1 << (UIH_BUCKETS_LOG / 2)) - 1);
     200        h = dev_handle & ((1 << (UIH_BUCKETS_LOG / 2)) - 1);
    202201        h |= (index & ((1 << (UIH_BUCKETS_LOG / 2)) - 1)) <<
    203202            (UIH_BUCKETS_LOG / 2);
     
    208207static int idx_compare(unsigned long key[], hash_count_t keys, link_t *item)
    209208{
    210         devmap_handle_t devmap_handle = (devmap_handle_t)key[UIH_DH_KEY];
     209        dev_handle_t dev_handle = (dev_handle_t)key[UIH_DH_KEY];
    211210        fs_index_t index;
    212211        fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uih_link);
     
    214213        switch (keys) {
    215214        case 1:
    216                 return (devmap_handle == fidx->devmap_handle);
     215                return (dev_handle == fidx->dev_handle);
    217216        case 2:
    218217                index = (fs_index_t) key[UIH_INDEX_KEY];
    219                 return (devmap_handle == fidx->devmap_handle) &&
     218                return (dev_handle == fidx->dev_handle) &&
    220219                    (index == fidx->index);
    221220        default:
     
    240239
    241240/** Allocate a VFS index which is not currently in use. */
    242 static bool fat_index_alloc(devmap_handle_t devmap_handle, fs_index_t *index)
     241static bool fat_index_alloc(dev_handle_t dev_handle, fs_index_t *index)
    243242{
    244243        unused_t *u;
    245244       
    246245        assert(index);
    247         u = unused_find(devmap_handle, true);
     246        u = unused_find(dev_handle, true);
    248247        if (!u)
    249248                return false;   
     
    302301
    303302/** Free a VFS index, which is no longer in use. */
    304 static void fat_index_free(devmap_handle_t devmap_handle, fs_index_t index)
     303static void fat_index_free(dev_handle_t dev_handle, fs_index_t index)
    305304{
    306305        unused_t *u;
    307306
    308         u = unused_find(devmap_handle, true);
     307        u = unused_find(dev_handle, true);
    309308        assert(u);
    310309
     
    364363}
    365364
    366 static int fat_idx_create(fat_idx_t **fidxp, devmap_handle_t devmap_handle)
     365static int fat_idx_create(fat_idx_t **fidxp, dev_handle_t dev_handle)
    367366{
    368367        fat_idx_t *fidx;
     
    371370        if (!fidx)
    372371                return ENOMEM;
    373         if (!fat_index_alloc(devmap_handle, &fidx->index)) {
     372        if (!fat_index_alloc(dev_handle, &fidx->index)) {
    374373                free(fidx);
    375374                return ENOSPC;
     
    379378        link_initialize(&fidx->uih_link);
    380379        fibril_mutex_initialize(&fidx->lock);
    381         fidx->devmap_handle = devmap_handle;
     380        fidx->dev_handle = dev_handle;
    382381        fidx->pfc = FAT_CLST_RES0;      /* no parent yet */
    383382        fidx->pdi = 0;
     
    388387}
    389388
    390 int fat_idx_get_new(fat_idx_t **fidxp, devmap_handle_t devmap_handle)
     389int fat_idx_get_new(fat_idx_t **fidxp, dev_handle_t dev_handle)
    391390{
    392391        fat_idx_t *fidx;
     
    394393
    395394        fibril_mutex_lock(&used_lock);
    396         rc = fat_idx_create(&fidx, devmap_handle);
     395        rc = fat_idx_create(&fidx, dev_handle);
    397396        if (rc != EOK) {
    398397                fibril_mutex_unlock(&used_lock);
     
    401400               
    402401        unsigned long ikey[] = {
    403                 [UIH_DH_KEY] = devmap_handle,
     402                [UIH_DH_KEY] = dev_handle,
    404403                [UIH_INDEX_KEY] = fidx->index,
    405404        };
     
    414413
    415414fat_idx_t *
    416 fat_idx_get_by_pos(devmap_handle_t devmap_handle, fat_cluster_t pfc, unsigned pdi)
     415fat_idx_get_by_pos(dev_handle_t dev_handle, fat_cluster_t pfc, unsigned pdi)
    417416{
    418417        fat_idx_t *fidx;
    419418        link_t *l;
    420419        unsigned long pkey[] = {
    421                 [UPH_DH_KEY] = devmap_handle,
     420                [UPH_DH_KEY] = dev_handle,
    422421                [UPH_PFC_KEY] = pfc,
    423422                [UPH_PDI_KEY] = pdi,
     
    431430                int rc;
    432431
    433                 rc = fat_idx_create(&fidx, devmap_handle);
     432                rc = fat_idx_create(&fidx, dev_handle);
    434433                if (rc != EOK) {
    435434                        fibril_mutex_unlock(&used_lock);
     
    438437               
    439438                unsigned long ikey[] = {
    440                         [UIH_DH_KEY] = devmap_handle,
     439                        [UIH_DH_KEY] = dev_handle,
    441440                        [UIH_INDEX_KEY] = fidx->index,
    442441                };
     
    457456{
    458457        unsigned long pkey[] = {
    459                 [UPH_DH_KEY] = idx->devmap_handle,
     458                [UPH_DH_KEY] = idx->dev_handle,
    460459                [UPH_PFC_KEY] = idx->pfc,
    461460                [UPH_PDI_KEY] = idx->pdi,
     
    470469{
    471470        unsigned long pkey[] = {
    472                 [UPH_DH_KEY] = idx->devmap_handle,
     471                [UPH_DH_KEY] = idx->dev_handle,
    473472                [UPH_PFC_KEY] = idx->pfc,
    474473                [UPH_PDI_KEY] = idx->pdi,
     
    481480
    482481fat_idx_t *
    483 fat_idx_get_by_index(devmap_handle_t devmap_handle, fs_index_t index)
     482fat_idx_get_by_index(dev_handle_t dev_handle, fs_index_t index)
    484483{
    485484        fat_idx_t *fidx = NULL;
    486485        link_t *l;
    487486        unsigned long ikey[] = {
    488                 [UIH_DH_KEY] = devmap_handle,
     487                [UIH_DH_KEY] = dev_handle,
    489488                [UIH_INDEX_KEY] = index,
    490489        };
     
    508507{
    509508        unsigned long ikey[] = {
    510                 [UIH_DH_KEY] = idx->devmap_handle,
     509                [UIH_DH_KEY] = idx->dev_handle,
    511510                [UIH_INDEX_KEY] = idx->index,
    512511        };
    513         devmap_handle_t devmap_handle = idx->devmap_handle;
     512        dev_handle_t dev_handle = idx->dev_handle;
    514513        fs_index_t index = idx->index;
    515514
     
    525524        fibril_mutex_unlock(&used_lock);
    526525        /* Release the VFS index. */
    527         fat_index_free(devmap_handle, index);
     526        fat_index_free(dev_handle, index);
    528527        /* The index structure itself is freed in idx_remove_callback(). */
    529528}
     
    547546}
    548547
    549 int fat_idx_init_by_devmap_handle(devmap_handle_t devmap_handle)
     548int fat_idx_init_by_dev_handle(dev_handle_t dev_handle)
    550549{
    551550        unused_t *u;
     
    555554        if (!u)
    556555                return ENOMEM;
    557         unused_initialize(u, devmap_handle);
     556        unused_initialize(u, dev_handle);
    558557        fibril_mutex_lock(&unused_lock);
    559         if (!unused_find(devmap_handle, false)) {
     558        if (!unused_find(dev_handle, false)) {
    560559                list_append(&u->link, &unused_head);
    561560        } else {
     
    567566}
    568567
    569 void fat_idx_fini_by_devmap_handle(devmap_handle_t devmap_handle)
     568void fat_idx_fini_by_dev_handle(dev_handle_t dev_handle)
    570569{
    571570        unsigned long ikey[] = {
    572                 [UIH_DH_KEY] = devmap_handle
     571                [UIH_DH_KEY] = dev_handle
    573572        };
    574573        unsigned long pkey[] = {
    575                 [UPH_DH_KEY] = devmap_handle
     574                [UPH_DH_KEY] = dev_handle
    576575        };
    577576
     
    589588         * Free the unused and freed structures for this instance.
    590589         */
    591         unused_t *u = unused_find(devmap_handle, true);
     590        unused_t *u = unused_find(dev_handle, true);
    592591        assert(u);
    593592        list_remove(&u->link);
Note: See TracChangeset for help on using the changeset viewer.