Subversion Repositories HelenOS

Rev

Rev 3588 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3588 Rev 3674
Line 212... Line 212...
212
    .compare = idx_compare,
212
    .compare = idx_compare,
213
    .remove_callback = idx_remove_callback,
213
    .remove_callback = idx_remove_callback,
214
};
214
};
215
 
215
 
216
/** Allocate a VFS index which is not currently in use. */
216
/** Allocate a VFS index which is not currently in use. */
217
static bool fat_idx_alloc(dev_handle_t dev_handle, fs_index_t *index)
217
static bool fat_index_alloc(dev_handle_t dev_handle, fs_index_t *index)
218
{
218
{
219
    unused_t *u;
219
    unused_t *u;
220
   
220
   
221
    assert(index);
221
    assert(index);
222
    u = unused_find(dev_handle, true);
222
    u = unused_find(dev_handle, true);
Line 274... Line 274...
274
        }
274
        }
275
    }
275
    }
276
}
276
}
277
 
277
 
278
/** Free a VFS index, which is no longer in use. */
278
/** Free a VFS index, which is no longer in use. */
279
static void fat_idx_free(dev_handle_t dev_handle, fs_index_t index)
279
static void fat_index_free(dev_handle_t dev_handle, fs_index_t index)
280
{
280
{
281
    unused_t *u;
281
    unused_t *u;
282
 
282
 
283
    u = unused_find(dev_handle, true);
283
    u = unused_find(dev_handle, true);
284
    assert(u);
284
    assert(u);
Line 336... Line 336...
336
        list_append(&n->link, &u->freed_head);
336
        list_append(&n->link, &u->freed_head);
337
    }
337
    }
338
    futex_up(&unused_futex);
338
    futex_up(&unused_futex);
339
}
339
}
340
 
340
 
341
static fat_idx_t *fat_idx_get_new_core(dev_handle_t dev_handle)
341
static fat_idx_t *fat_idx_create(dev_handle_t dev_handle)
342
{
342
{
343
    fat_idx_t *fidx;
343
    fat_idx_t *fidx;
344
 
344
 
345
    fidx = (fat_idx_t *) malloc(sizeof(fat_idx_t));
345
    fidx = (fat_idx_t *) malloc(sizeof(fat_idx_t));
346
    if (!fidx)
346
    if (!fidx)
347
        return NULL;
347
        return NULL;
348
    if (!fat_idx_alloc(dev_handle, &fidx->index)) {
348
    if (!fat_index_alloc(dev_handle, &fidx->index)) {
349
        free(fidx);
349
        free(fidx);
350
        return NULL;
350
        return NULL;
351
    }
351
    }
352
       
352
       
353
    link_initialize(&fidx->uph_link);
353
    link_initialize(&fidx->uph_link);
Line 364... Line 364...
364
fat_idx_t *fat_idx_get_new(dev_handle_t dev_handle)
364
fat_idx_t *fat_idx_get_new(dev_handle_t dev_handle)
365
{
365
{
366
    fat_idx_t *fidx;
366
    fat_idx_t *fidx;
367
 
367
 
368
    futex_down(&used_futex);
368
    futex_down(&used_futex);
369
    fidx = fat_idx_get_new_core(dev_handle);
369
    fidx = fat_idx_create(dev_handle);
370
    if (!fidx) {
370
    if (!fidx) {
371
        futex_up(&used_futex);
371
        futex_up(&used_futex);
372
        return NULL;
372
        return NULL;
373
    }
373
    }
374
       
374
       
Line 398... Line 398...
398
    futex_down(&used_futex);
398
    futex_down(&used_futex);
399
    l = hash_table_find(&up_hash, pkey);
399
    l = hash_table_find(&up_hash, pkey);
400
    if (l) {
400
    if (l) {
401
        fidx = hash_table_get_instance(l, fat_idx_t, uph_link);
401
        fidx = hash_table_get_instance(l, fat_idx_t, uph_link);
402
    } else {
402
    } else {
403
        fidx = fat_idx_get_new_core(dev_handle);
403
        fidx = fat_idx_create(dev_handle);
404
        if (!fidx) {
404
        if (!fidx) {
405
            futex_up(&used_futex);
405
            futex_up(&used_futex);
406
            return NULL;
406
            return NULL;
407
        }
407
        }
408
       
408
       
Line 421... Line 421...
421
    futex_up(&used_futex);
421
    futex_up(&used_futex);
422
 
422
 
423
    return fidx;
423
    return fidx;
424
}
424
}
425
 
425
 
-
 
426
void fat_idx_hashin(fat_idx_t *idx)
-
 
427
{
-
 
428
    unsigned long pkey[] = {
-
 
429
        [UPH_DH_KEY] = idx->dev_handle,
-
 
430
        [UPH_PFC_KEY] = idx->pfc,
-
 
431
        [UPH_PDI_KEY] = idx->pdi,
-
 
432
    };
-
 
433
 
-
 
434
    futex_down(&used_futex);
-
 
435
    hash_table_insert(&up_hash, pkey, &idx->uph_link);
-
 
436
    futex_up(&used_futex);
-
 
437
}
-
 
438
 
-
 
439
void fat_idx_hashout(fat_idx_t *idx)
-
 
440
{
-
 
441
    unsigned long pkey[] = {
-
 
442
        [UPH_DH_KEY] = idx->dev_handle,
-
 
443
        [UPH_PFC_KEY] = idx->pfc,
-
 
444
        [UPH_PDI_KEY] = idx->pdi,
-
 
445
    };
-
 
446
 
-
 
447
    futex_down(&used_futex);
-
 
448
    hash_table_remove(&up_hash, pkey, 3);
-
 
449
    futex_up(&used_futex);
-
 
450
}
-
 
451
 
426
fat_idx_t *
452
fat_idx_t *
427
fat_idx_get_by_index(dev_handle_t dev_handle, fs_index_t index)
453
fat_idx_get_by_index(dev_handle_t dev_handle, fs_index_t index)
428
{
454
{
429
    fat_idx_t *fidx = NULL;
455
    fat_idx_t *fidx = NULL;
430
    link_t *l;
456
    link_t *l;
Line 442... Line 468...
442
    futex_up(&used_futex);
468
    futex_up(&used_futex);
443
 
469
 
444
    return fidx;
470
    return fidx;
445
}
471
}
446
 
472
 
-
 
473
/** Destroy the index structure.
-
 
474
 *
-
 
475
 * @param idx       The index structure to be destroyed.
-
 
476
 */
-
 
477
void fat_idx_destroy(fat_idx_t *idx)
-
 
478
{
-
 
479
    unsigned long ikey[] = {
-
 
480
        [UIH_DH_KEY] = idx->dev_handle,
-
 
481
        [UIH_INDEX_KEY] = idx->index,
-
 
482
    };
-
 
483
 
-
 
484
    assert(idx->pfc == FAT_CLST_RES0);
-
 
485
 
-
 
486
    futex_down(&used_futex);
-
 
487
    /*
-
 
488
     * Since we can only free unlinked nodes, the index structure is not
-
 
489
     * present in the position hash (uph). We therefore hash it out from
-
 
490
     * the index hash only.
-
 
491
     */
-
 
492
    hash_table_remove(&ui_hash, ikey, 2);
-
 
493
    futex_up(&used_futex);
-
 
494
    /* Release the VFS index. */
-
 
495
    fat_index_free(idx->dev_handle, idx->index);
-
 
496
    /* Deallocate the structure. */
-
 
497
    free(idx);
-
 
498
}
-
 
499
 
447
int fat_idx_init(void)
500
int fat_idx_init(void)
448
{
501
{
449
    if (!hash_table_create(&up_hash, UPH_BUCKETS, 3, &uph_ops))
502
    if (!hash_table_create(&up_hash, UPH_BUCKETS, 3, &uph_ops))
450
        return ENOMEM;
503
        return ENOMEM;
451
    if (!hash_table_create(&ui_hash, UIH_BUCKETS, 2, &uih_ops)) {
504
    if (!hash_table_create(&ui_hash, UIH_BUCKETS, 2, &uih_ops)) {