Changeset db6e419 in mainline for uspace/srv/fs/fat/fat_idx.c


Ignore:
Timestamp:
2011-08-16T18:53:00Z (13 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
49160c4
Parents:
e0e922d (diff), 45058baa (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/fat/fat_idx.c

    re0e922d rdb6e419  
    5959typedef struct {
    6060        link_t          link;
    61         devmap_handle_t devmap_handle;
     61        service_id_t    service_id;
    6262
    6363        /** Next unassigned index. */
     
    7676static LIST_INITIALIZE(unused_list);
    7777
    78 static void unused_initialize(unused_t *u, devmap_handle_t devmap_handle)
     78static void unused_initialize(unused_t *u, service_id_t service_id)
    7979{
    8080        link_initialize(&u->link);
    81         u->devmap_handle = devmap_handle;
     81        u->service_id = service_id;
    8282        u->next = 0;
    8383        u->remaining = ((uint64_t)((fs_index_t)-1)) + 1;
     
    8585}
    8686
    87 static unused_t *unused_find(devmap_handle_t devmap_handle, bool lock)
     87static unused_t *unused_find(service_id_t service_id, bool lock)
    8888{
    8989        unused_t *u;
     
    9494        list_foreach(unused_list, l) {
    9595                u = list_get_instance(l, unused_t, link);
    96                 if (u->devmap_handle == devmap_handle)
     96                if (u->service_id == service_id)
    9797                        return u;
    9898        }
     
    108108/**
    109109 * Global hash table of all used fat_idx_t structures.
    110  * The index structures are hashed by the devmap_handle, parent node's first
     110 * The index structures are hashed by the service_id, parent node's first
    111111 * cluster and index within the parent directory.
    112112 */
     
    122122static hash_index_t pos_hash(unsigned long key[])
    123123{
    124         devmap_handle_t devmap_handle = (devmap_handle_t)key[UPH_DH_KEY];
     124        service_id_t service_id = (service_id_t)key[UPH_DH_KEY];
    125125        fat_cluster_t pfc = (fat_cluster_t)key[UPH_PFC_KEY];
    126126        unsigned pdi = (unsigned)key[UPH_PDI_KEY];
     
    142142        h |= (pdi & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
    143143            (UPH_BUCKETS_LOG / 2);
    144         h |= (devmap_handle & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
     144        h |= (service_id & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
    145145            (3 * (UPH_BUCKETS_LOG / 4));
    146146
     
    150150static int pos_compare(unsigned long key[], hash_count_t keys, link_t *item)
    151151{
    152         devmap_handle_t devmap_handle = (devmap_handle_t)key[UPH_DH_KEY];
     152        service_id_t service_id = (service_id_t)key[UPH_DH_KEY];
    153153        fat_cluster_t pfc;
    154154        unsigned pdi;
     
    157157        switch (keys) {
    158158        case 1:
    159                 return (devmap_handle == fidx->devmap_handle);
     159                return (service_id == fidx->service_id);
    160160        case 3:
    161161                pfc = (fat_cluster_t) key[UPH_PFC_KEY];
    162162                pdi = (unsigned) key[UPH_PDI_KEY];
    163                 return (devmap_handle == fidx->devmap_handle) && (pfc == fidx->pfc) &&
     163                return (service_id == fidx->service_id) && (pfc == fidx->pfc) &&
    164164                    (pdi == fidx->pdi);
    165165        default:
     
    183183/**
    184184 * Global hash table of all used fat_idx_t structures.
    185  * The index structures are hashed by the devmap_handle and index.
     185 * The index structures are hashed by the service_id and index.
    186186 */
    187187static hash_table_t ui_hash;
     
    195195static hash_index_t idx_hash(unsigned long key[])
    196196{
    197         devmap_handle_t devmap_handle = (devmap_handle_t)key[UIH_DH_KEY];
     197        service_id_t service_id = (service_id_t)key[UIH_DH_KEY];
    198198        fs_index_t index = (fs_index_t)key[UIH_INDEX_KEY];
    199199
    200200        hash_index_t h;
    201201
    202         h = devmap_handle & ((1 << (UIH_BUCKETS_LOG / 2)) - 1);
     202        h = service_id & ((1 << (UIH_BUCKETS_LOG / 2)) - 1);
    203203        h |= (index & ((1 << (UIH_BUCKETS_LOG / 2)) - 1)) <<
    204204            (UIH_BUCKETS_LOG / 2);
     
    209209static int idx_compare(unsigned long key[], hash_count_t keys, link_t *item)
    210210{
    211         devmap_handle_t devmap_handle = (devmap_handle_t)key[UIH_DH_KEY];
     211        service_id_t service_id = (service_id_t)key[UIH_DH_KEY];
    212212        fs_index_t index;
    213213        fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uih_link);
     
    215215        switch (keys) {
    216216        case 1:
    217                 return (devmap_handle == fidx->devmap_handle);
     217                return (service_id == fidx->service_id);
    218218        case 2:
    219219                index = (fs_index_t) key[UIH_INDEX_KEY];
    220                 return (devmap_handle == fidx->devmap_handle) &&
     220                return (service_id == fidx->service_id) &&
    221221                    (index == fidx->index);
    222222        default:
     
    241241
    242242/** Allocate a VFS index which is not currently in use. */
    243 static bool fat_index_alloc(devmap_handle_t devmap_handle, fs_index_t *index)
     243static bool fat_index_alloc(service_id_t service_id, fs_index_t *index)
    244244{
    245245        unused_t *u;
    246246       
    247247        assert(index);
    248         u = unused_find(devmap_handle, true);
     248        u = unused_find(service_id, true);
    249249        if (!u)
    250250                return false;   
     
    303303
    304304/** Free a VFS index, which is no longer in use. */
    305 static void fat_index_free(devmap_handle_t devmap_handle, fs_index_t index)
     305static void fat_index_free(service_id_t service_id, fs_index_t index)
    306306{
    307307        unused_t *u;
    308308
    309         u = unused_find(devmap_handle, true);
     309        u = unused_find(service_id, true);
    310310        assert(u);
    311311
     
    365365}
    366366
    367 static int fat_idx_create(fat_idx_t **fidxp, devmap_handle_t devmap_handle)
     367static int fat_idx_create(fat_idx_t **fidxp, service_id_t service_id)
    368368{
    369369        fat_idx_t *fidx;
     
    372372        if (!fidx)
    373373                return ENOMEM;
    374         if (!fat_index_alloc(devmap_handle, &fidx->index)) {
     374        if (!fat_index_alloc(service_id, &fidx->index)) {
    375375                free(fidx);
    376376                return ENOSPC;
     
    380380        link_initialize(&fidx->uih_link);
    381381        fibril_mutex_initialize(&fidx->lock);
    382         fidx->devmap_handle = devmap_handle;
     382        fidx->service_id = service_id;
    383383        fidx->pfc = FAT_CLST_RES0;      /* no parent yet */
    384384        fidx->pdi = 0;
     
    389389}
    390390
    391 int fat_idx_get_new(fat_idx_t **fidxp, devmap_handle_t devmap_handle)
     391int fat_idx_get_new(fat_idx_t **fidxp, service_id_t service_id)
    392392{
    393393        fat_idx_t *fidx;
     
    395395
    396396        fibril_mutex_lock(&used_lock);
    397         rc = fat_idx_create(&fidx, devmap_handle);
     397        rc = fat_idx_create(&fidx, service_id);
    398398        if (rc != EOK) {
    399399                fibril_mutex_unlock(&used_lock);
     
    402402               
    403403        unsigned long ikey[] = {
    404                 [UIH_DH_KEY] = devmap_handle,
     404                [UIH_DH_KEY] = service_id,
    405405                [UIH_INDEX_KEY] = fidx->index,
    406406        };
     
    415415
    416416fat_idx_t *
    417 fat_idx_get_by_pos(devmap_handle_t devmap_handle, fat_cluster_t pfc, unsigned pdi)
     417fat_idx_get_by_pos(service_id_t service_id, fat_cluster_t pfc, unsigned pdi)
    418418{
    419419        fat_idx_t *fidx;
    420420        link_t *l;
    421421        unsigned long pkey[] = {
    422                 [UPH_DH_KEY] = devmap_handle,
     422                [UPH_DH_KEY] = service_id,
    423423                [UPH_PFC_KEY] = pfc,
    424424                [UPH_PDI_KEY] = pdi,
     
    432432                int rc;
    433433
    434                 rc = fat_idx_create(&fidx, devmap_handle);
     434                rc = fat_idx_create(&fidx, service_id);
    435435                if (rc != EOK) {
    436436                        fibril_mutex_unlock(&used_lock);
     
    439439               
    440440                unsigned long ikey[] = {
    441                         [UIH_DH_KEY] = devmap_handle,
     441                        [UIH_DH_KEY] = service_id,
    442442                        [UIH_INDEX_KEY] = fidx->index,
    443443                };
     
    458458{
    459459        unsigned long pkey[] = {
    460                 [UPH_DH_KEY] = idx->devmap_handle,
     460                [UPH_DH_KEY] = idx->service_id,
    461461                [UPH_PFC_KEY] = idx->pfc,
    462462                [UPH_PDI_KEY] = idx->pdi,
     
    471471{
    472472        unsigned long pkey[] = {
    473                 [UPH_DH_KEY] = idx->devmap_handle,
     473                [UPH_DH_KEY] = idx->service_id,
    474474                [UPH_PFC_KEY] = idx->pfc,
    475475                [UPH_PDI_KEY] = idx->pdi,
     
    482482
    483483fat_idx_t *
    484 fat_idx_get_by_index(devmap_handle_t devmap_handle, fs_index_t index)
     484fat_idx_get_by_index(service_id_t service_id, fs_index_t index)
    485485{
    486486        fat_idx_t *fidx = NULL;
    487487        link_t *l;
    488488        unsigned long ikey[] = {
    489                 [UIH_DH_KEY] = devmap_handle,
     489                [UIH_DH_KEY] = service_id,
    490490                [UIH_INDEX_KEY] = index,
    491491        };
     
    509509{
    510510        unsigned long ikey[] = {
    511                 [UIH_DH_KEY] = idx->devmap_handle,
     511                [UIH_DH_KEY] = idx->service_id,
    512512                [UIH_INDEX_KEY] = idx->index,
    513513        };
    514         devmap_handle_t devmap_handle = idx->devmap_handle;
     514        service_id_t service_id = idx->service_id;
    515515        fs_index_t index = idx->index;
    516516
     
    526526        fibril_mutex_unlock(&used_lock);
    527527        /* Release the VFS index. */
    528         fat_index_free(devmap_handle, index);
     528        fat_index_free(service_id, index);
    529529        /* The index structure itself is freed in idx_remove_callback(). */
    530530}
     
    548548}
    549549
    550 int fat_idx_init_by_devmap_handle(devmap_handle_t devmap_handle)
     550int fat_idx_init_by_service_id(service_id_t service_id)
    551551{
    552552        unused_t *u;
     
    556556        if (!u)
    557557                return ENOMEM;
    558         unused_initialize(u, devmap_handle);
     558        unused_initialize(u, service_id);
    559559        fibril_mutex_lock(&unused_lock);
    560         if (!unused_find(devmap_handle, false)) {
     560        if (!unused_find(service_id, false)) {
    561561                list_append(&u->link, &unused_list);
    562562        } else {
     
    568568}
    569569
    570 void fat_idx_fini_by_devmap_handle(devmap_handle_t devmap_handle)
     570void fat_idx_fini_by_service_id(service_id_t service_id)
    571571{
    572572        unsigned long ikey[] = {
    573                 [UIH_DH_KEY] = devmap_handle
     573                [UIH_DH_KEY] = service_id
    574574        };
    575575        unsigned long pkey[] = {
    576                 [UPH_DH_KEY] = devmap_handle
     576                [UPH_DH_KEY] = service_id
    577577        };
    578578
     
    590590         * Free the unused and freed structures for this instance.
    591591         */
    592         unused_t *u = unused_find(devmap_handle, true);
     592        unused_t *u = unused_find(service_id, true);
    593593        assert(u);
    594594        list_remove(&u->link);
Note: See TracChangeset for help on using the changeset viewer.