Subversion Repositories HelenOS

Rev

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

Rev 3111 Rev 3574
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)
-
 
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
 
-
 
364
fat_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
 
341
fat_idx_t *
387
fat_idx_t *
342
fat_idx_get_by_pos(dev_handle_t dev_handle, fat_cluster_t pfc, unsigned pdi)
388
fat_idx_get_by_pos(dev_handle_t dev_handle, fat_cluster_t pfc, unsigned pdi)
343
{
389
{
344
    fat_idx_t *fidx;
390
    fat_idx_t *fidx;
345
    link_t *l;
391
    link_t *l;
Line 352... Line 398...
352
    futex_down(&used_futex);
398
    futex_down(&used_futex);
353
    l = hash_table_find(&up_hash, pkey);
399
    l = hash_table_find(&up_hash, pkey);
354
    if (l) {
400
    if (l) {
355
        fidx = hash_table_get_instance(l, fat_idx_t, uph_link);
401
        fidx = hash_table_get_instance(l, fat_idx_t, uph_link);
356
    } else {
402
    } else {
357
        fidx = (fat_idx_t *) malloc(sizeof(fat_idx_t));
403
        fidx = fat_idx_get_new_core(dev_handle);
358
        if (!fidx) {
404
        if (!fidx) {
359
            futex_up(&used_futex);
405
            futex_up(&used_futex);
360
            return NULL;
406
            return NULL;
361
        }
407
        }
362
        if (!fat_idx_alloc(dev_handle, &fidx->index)) {
-
 
363
            free(fidx);
-
 
364
            futex_up(&used_futex);
-
 
365
            return NULL;
-
 
366
        }
-
 
367
       
408
       
368
        unsigned long ikey[] = {
409
        unsigned long ikey[] = {
369
            [UIH_DH_KEY] = dev_handle,
410
            [UIH_DH_KEY] = dev_handle,
370
            [UIH_INDEX_KEY] = fidx->index,
411
            [UIH_INDEX_KEY] = fidx->index,
371
        };
412
        };
372
   
413
   
373
        link_initialize(&fidx->uph_link);
-
 
374
        link_initialize(&fidx->uih_link);
-
 
375
        futex_initialize(&fidx->lock, 1);
-
 
376
        fidx->dev_handle = dev_handle;
-
 
377
        fidx->pfc = pfc;
414
        fidx->pfc = pfc;
378
        fidx->pdi = pdi;
415
        fidx->pdi = pdi;
379
        fidx->nodep = NULL;
-
 
380
 
416
 
381
        hash_table_insert(&up_hash, pkey, &fidx->uph_link);
417
        hash_table_insert(&up_hash, pkey, &fidx->uph_link);
382
        hash_table_insert(&ui_hash, ikey, &fidx->uih_link);
418
        hash_table_insert(&ui_hash, ikey, &fidx->uih_link);
383
    }
419
    }
384
    futex_down(&fidx->lock);
420
    futex_down(&fidx->lock);