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


Ignore:
Timestamp:
2008-11-09T21:13:30Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
adb5fe3
Parents:
ac49f5d1
Message:

Move common code to dedicated functions so that it can be easily reused.

File:
1 edited

Legend:

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

    rac49f5d1 r9a3d5f0  
    339339}
    340340
     341static fat_idx_t *fat_idx_get_new_core(dev_handle_t dev_handle)
     342{
     343        fat_idx_t *fidx;
     344
     345        fidx = (fat_idx_t *) malloc(sizeof(fat_idx_t));
     346        if (!fidx)
     347                return NULL;
     348        if (!fat_idx_alloc(dev_handle, &fidx->index)) {
     349                free(fidx);
     350                return NULL;
     351        }
     352               
     353        link_initialize(&fidx->uph_link);
     354        link_initialize(&fidx->uih_link);
     355        futex_initialize(&fidx->lock, 1);
     356        fidx->dev_handle = dev_handle;
     357        fidx->pfc = FAT_CLST_RES0;      /* no parent yet */
     358        fidx->pdi = 0;
     359        fidx->nodep = NULL;
     360
     361        return fidx;
     362}
     363
     364fat_idx_t *fat_idx_get_new(dev_handle_t dev_handle)
     365{
     366        fat_idx_t *fidx;
     367
     368        futex_down(&used_futex);
     369        fidx = fat_idx_get_new_core(dev_handle);
     370        if (!fidx) {
     371                futex_up(&used_futex);
     372                return NULL;
     373        }
     374               
     375        unsigned long ikey[] = {
     376                [UIH_DH_KEY] = dev_handle,
     377                [UIH_INDEX_KEY] = fidx->index,
     378        };
     379       
     380        hash_table_insert(&ui_hash, ikey, &fidx->uih_link);
     381        futex_down(&fidx->lock);
     382        futex_up(&used_futex);
     383
     384        return fidx;
     385}
     386
    341387fat_idx_t *
    342388fat_idx_get_by_pos(dev_handle_t dev_handle, fat_cluster_t pfc, unsigned pdi)
     
    355401                fidx = hash_table_get_instance(l, fat_idx_t, uph_link);
    356402        } else {
    357                 fidx = (fat_idx_t *) malloc(sizeof(fat_idx_t));
     403                fidx = fat_idx_get_new_core(dev_handle);
    358404                if (!fidx) {
    359                         futex_up(&used_futex);
    360                         return NULL;
    361                 }
    362                 if (!fat_idx_alloc(dev_handle, &fidx->index)) {
    363                         free(fidx);
    364405                        futex_up(&used_futex);
    365406                        return NULL;
     
    371412                };
    372413       
    373                 link_initialize(&fidx->uph_link);
    374                 link_initialize(&fidx->uih_link);
    375                 futex_initialize(&fidx->lock, 1);
    376                 fidx->dev_handle = dev_handle;
    377414                fidx->pfc = pfc;
    378415                fidx->pdi = pdi;
    379                 fidx->nodep = NULL;
    380416
    381417                hash_table_insert(&up_hash, pkey, &fidx->uph_link);
Note: See TracChangeset for help on using the changeset viewer.