Subversion Repositories HelenOS

Rev

Rev 3597 | Rev 3675 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3597 Rev 3623
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 442... Line 442...
442
    futex_up(&used_futex);
442
    futex_up(&used_futex);
443
 
443
 
444
    return fidx;
444
    return fidx;
445
}
445
}
446
 
446
 
-
 
447
/** Destroy the index structure.
-
 
448
 *
-
 
449
 * @param idx       The index structure to be destroyed.
-
 
450
 */
-
 
451
void fat_idx_destroy(fat_idx_t *idx)
-
 
452
{
-
 
453
    unsigned long ikey[] = {
-
 
454
        [UIH_DH_KEY] = idx->dev_handle,
-
 
455
        [UIH_INDEX_KEY] = idx->index,
-
 
456
    };
-
 
457
 
-
 
458
    assert(idx->pfc == FAT_CLST_RES0);
-
 
459
 
-
 
460
    futex_down(&used_futex);
-
 
461
    /*
-
 
462
     * Since we can only free unlinked nodes, the index structure is not
-
 
463
     * present in the position hash (uph). We therefore hash it out from
-
 
464
     * the index hash only.
-
 
465
     */
-
 
466
    hash_table_remove(&ui_hash, ikey, 2);
-
 
467
    futex_up(&used_futex);
-
 
468
    /* Release the VFS index. */
-
 
469
    fat_index_free(idx->dev_handle, idx->index);
-
 
470
    /* Deallocate the structure. */
-
 
471
    free(idx);
-
 
472
}
-
 
473
 
447
int fat_idx_init(void)
474
int fat_idx_init(void)
448
{
475
{
449
    if (!hash_table_create(&up_hash, UPH_BUCKETS, 3, &uph_ops))
476
    if (!hash_table_create(&up_hash, UPH_BUCKETS, 3, &uph_ops))
450
        return ENOMEM;
477
        return ENOMEM;
451
    if (!hash_table_create(&ui_hash, UIH_BUCKETS, 2, &uih_ops)) {
478
    if (!hash_table_create(&ui_hash, UIH_BUCKETS, 2, &uih_ops)) {