Subversion Repositories HelenOS

Rev

Rev 4389 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4389 Rev 4691
Line 46... Line 46...
46
#include <ipc/devmap.h>
46
#include <ipc/devmap.h>
47
#include <async.h>
47
#include <async.h>
48
#include <errno.h>
48
#include <errno.h>
49
#include <string.h>
49
#include <string.h>
50
#include <byteorder.h>
50
#include <byteorder.h>
51
#include <libadt/hash_table.h>
51
#include <adt/hash_table.h>
52
#include <libadt/list.h>
52
#include <adt/list.h>
53
#include <assert.h>
53
#include <assert.h>
54
#include <futex.h>
54
#include <fibril_sync.h>
55
#include <sys/mman.h>
55
#include <sys/mman.h>
56
#include <align.h>
56
#include <align.h>
57
 
57
 
58
#define FAT_NODE(node)  ((node) ? (fat_node_t *) (node)->data : NULL)
58
#define FAT_NODE(node)  ((node) ? (fat_node_t *) (node)->data : NULL)
59
#define FS_NODE(node)   ((node) ? (node)->bp : NULL)
59
#define FS_NODE(node)   ((node) ? (node)->bp : NULL)
60
 
60
 
61
/** Futex protecting the list of cached free FAT nodes. */
61
/** Mutex protecting the list of cached free FAT nodes. */
62
static futex_t ffn_futex = FUTEX_INITIALIZER;
62
static FIBRIL_MUTEX_INITIALIZE(ffn_mutex);
63
 
63
 
64
/** List of cached free FAT nodes. */
64
/** List of cached free FAT nodes. */
65
static LIST_INITIALIZE(ffn_head);
65
static LIST_INITIALIZE(ffn_head);
66
 
66
 
67
static void fat_node_initialize(fat_node_t *node)
67
static void fat_node_initialize(fat_node_t *node)
68
{
68
{
69
    futex_initialize(&node->lock, 1);
69
    fibril_mutex_initialize(&node->lock);
70
    node->bp = NULL;
70
    node->bp = NULL;
71
    node->idx = NULL;
71
    node->idx = NULL;
72
    node->type = 0;
72
    node->type = 0;
73
    link_initialize(&node->ffn_link);
73
    link_initialize(&node->ffn_link);
74
    node->size = 0;
74
    node->size = 0;
Line 113... Line 113...
113
static fat_node_t *fat_node_get_new(void)
113
static fat_node_t *fat_node_get_new(void)
114
{
114
{
115
    fs_node_t *fn;
115
    fs_node_t *fn;
116
    fat_node_t *nodep;
116
    fat_node_t *nodep;
117
 
117
 
118
    futex_down(&ffn_futex);
118
    fibril_mutex_lock(&ffn_mutex);
119
    if (!list_empty(&ffn_head)) {
119
    if (!list_empty(&ffn_head)) {
120
        /* Try to use a cached free node structure. */
120
        /* Try to use a cached free node structure. */
121
        fat_idx_t *idxp_tmp;
121
        fat_idx_t *idxp_tmp;
122
        nodep = list_get_instance(ffn_head.next, fat_node_t, ffn_link);
122
        nodep = list_get_instance(ffn_head.next, fat_node_t, ffn_link);
123
        if (futex_trydown(&nodep->lock) == ESYNCH_WOULD_BLOCK)
123
        if (!fibril_mutex_trylock(&nodep->lock))
124
            goto skip_cache;
124
            goto skip_cache;
125
        idxp_tmp = nodep->idx;
125
        idxp_tmp = nodep->idx;
126
        if (futex_trydown(&idxp_tmp->lock) == ESYNCH_WOULD_BLOCK) {
126
        if (!fibril_mutex_trylock(&idxp_tmp->lock)) {
127
            futex_up(&nodep->lock);
127
            fibril_mutex_unlock(&nodep->lock);
128
            goto skip_cache;
128
            goto skip_cache;
129
        }
129
        }
130
        list_remove(&nodep->ffn_link);
130
        list_remove(&nodep->ffn_link);
131
        futex_up(&ffn_futex);
131
        fibril_mutex_unlock(&ffn_mutex);
132
        if (nodep->dirty)
132
        if (nodep->dirty)
133
            fat_node_sync(nodep);
133
            fat_node_sync(nodep);
134
        idxp_tmp->nodep = NULL;
134
        idxp_tmp->nodep = NULL;
135
        futex_up(&nodep->lock);
135
        fibril_mutex_unlock(&nodep->lock);
136
        futex_up(&idxp_tmp->lock);
136
        fibril_mutex_unlock(&idxp_tmp->lock);
137
        fn = FS_NODE(nodep);
137
        fn = FS_NODE(nodep);
138
    } else {
138
    } else {
139
skip_cache:
139
skip_cache:
140
        /* Try to allocate a new node structure. */
140
        /* Try to allocate a new node structure. */
141
        futex_up(&ffn_futex);
141
        fibril_mutex_unlock(&ffn_mutex);
142
        fn = (fs_node_t *)malloc(sizeof(fs_node_t));
142
        fn = (fs_node_t *)malloc(sizeof(fs_node_t));
143
        if (!fn)
143
        if (!fn)
144
            return NULL;
144
            return NULL;
145
        nodep = (fat_node_t *)malloc(sizeof(fat_node_t));
145
        nodep = (fat_node_t *)malloc(sizeof(fat_node_t));
146
        if (!nodep) {
146
        if (!nodep) {
147
            free(fn);
147
            free(fn);
148
            return NULL;
148
            return NULL;
149
        }
149
        }
150
    }
150
    }
151
    fat_node_initialize(nodep);
151
    fat_node_initialize(nodep);
-
 
152
    fs_node_initialize(fn);
152
    fn->data = nodep;
153
    fn->data = nodep;
153
    nodep->bp = fn;
154
    nodep->bp = fn;
154
   
155
   
155
    return nodep;
156
    return nodep;
156
}
157
}
Line 172... Line 173...
172
    if (idxp->nodep) {
173
    if (idxp->nodep) {
173
        /*
174
        /*
174
         * We are lucky.
175
         * We are lucky.
175
         * The node is already instantiated in memory.
176
         * The node is already instantiated in memory.
176
         */
177
         */
177
        futex_down(&idxp->nodep->lock);
178
        fibril_mutex_lock(&idxp->nodep->lock);
178
        if (!idxp->nodep->refcnt++)
179
        if (!idxp->nodep->refcnt++)
179
            list_remove(&idxp->nodep->ffn_link);
180
            list_remove(&idxp->nodep->ffn_link);
180
        futex_up(&idxp->nodep->lock);
181
        fibril_mutex_unlock(&idxp->nodep->lock);
181
        return idxp->nodep;
182
        return idxp->nodep;
182
    }
183
    }
183
 
184
 
184
    /*
185
    /*
185
     * We must instantiate the node from the file system.
186
     * We must instantiate the node from the file system.
Line 265... Line 266...
265
    idxp = fat_idx_get_by_index(dev_handle, index);
266
    idxp = fat_idx_get_by_index(dev_handle, index);
266
    if (!idxp)
267
    if (!idxp)
267
        return NULL;
268
        return NULL;
268
    /* idxp->lock held */
269
    /* idxp->lock held */
269
    nodep = fat_node_get_core(idxp);
270
    nodep = fat_node_get_core(idxp);
270
    futex_up(&idxp->lock);
271
    fibril_mutex_unlock(&idxp->lock);
271
    return FS_NODE(nodep);
272
    return FS_NODE(nodep);
272
}
273
}
273
 
274
 
274
void fat_node_put(fs_node_t *fn)
275
void fat_node_put(fs_node_t *fn)
275
{
276
{
276
    fat_node_t *nodep = FAT_NODE(fn);
277
    fat_node_t *nodep = FAT_NODE(fn);
277
    bool destroy = false;
278
    bool destroy = false;
278
 
279
 
279
    futex_down(&nodep->lock);
280
    fibril_mutex_lock(&nodep->lock);
280
    if (!--nodep->refcnt) {
281
    if (!--nodep->refcnt) {
281
        if (nodep->idx) {
282
        if (nodep->idx) {
282
            futex_down(&ffn_futex);
283
            fibril_mutex_lock(&ffn_mutex);
283
            list_append(&nodep->ffn_link, &ffn_head);
284
            list_append(&nodep->ffn_link, &ffn_head);
284
            futex_up(&ffn_futex);
285
            fibril_mutex_unlock(&ffn_mutex);
285
        } else {
286
        } else {
286
            /*
287
            /*
287
             * The node does not have any index structure associated
288
             * The node does not have any index structure associated
288
             * with itself. This can only mean that we are releasing
289
             * with itself. This can only mean that we are releasing
289
             * the node after a failed attempt to allocate the index
290
             * the node after a failed attempt to allocate the index
290
             * structure for it.
291
             * structure for it.
291
             */
292
             */
292
            destroy = true;
293
            destroy = true;
293
        }
294
        }
294
    }
295
    }
295
    futex_up(&nodep->lock);
296
    fibril_mutex_unlock(&nodep->lock);
296
    if (destroy) {
297
    if (destroy) {
297
        free(nodep->bp);
298
        free(nodep->bp);
298
        free(nodep);
299
        free(nodep);
299
    }
300
    }
300
}
301
}
Line 357... Line 358...
357
    nodep->dirty = true;
358
    nodep->dirty = true;
358
 
359
 
359
    nodep->idx = idxp;
360
    nodep->idx = idxp;
360
    idxp->nodep = nodep;
361
    idxp->nodep = nodep;
361
 
362
 
362
    futex_up(&idxp->lock);
363
    fibril_mutex_unlock(&idxp->lock);
363
    return FS_NODE(nodep);
364
    return FS_NODE(nodep);
364
}
365
}
365
 
366
 
366
int fat_destroy_node(fs_node_t *fn)
367
int fat_destroy_node(fs_node_t *fn)
367
{
368
{
Line 399... Line 400...
399
    fat_node_t *parentp = FAT_NODE(pfn);
400
    fat_node_t *parentp = FAT_NODE(pfn);
400
    fat_node_t *childp = FAT_NODE(cfn);
401
    fat_node_t *childp = FAT_NODE(cfn);
401
    fat_dentry_t *d;
402
    fat_dentry_t *d;
402
    fat_bs_t *bs;
403
    fat_bs_t *bs;
403
    block_t *b;
404
    block_t *b;
404
    int i, j;
405
    unsigned i, j;
405
    uint16_t bps;
406
    uint16_t bps;
406
    unsigned dps;
407
    unsigned dps;
407
    unsigned blocks;
408
    unsigned blocks;
408
    fat_cluster_t mcl, lcl;
409
    fat_cluster_t mcl, lcl;
409
    int rc;
410
    int rc;
410
 
411
 
411
    futex_down(&childp->lock);
412
    fibril_mutex_lock(&childp->lock);
412
    if (childp->lnkcnt == 1) {
413
    if (childp->lnkcnt == 1) {
413
        /*
414
        /*
414
         * On FAT, we don't support multiple hard links.
415
         * On FAT, we don't support multiple hard links.
415
         */
416
         */
416
        futex_up(&childp->lock);
417
        fibril_mutex_unlock(&childp->lock);
417
        return EMLINK;
418
        return EMLINK;
418
    }
419
    }
419
    assert(childp->lnkcnt == 0);
420
    assert(childp->lnkcnt == 0);
420
    futex_up(&childp->lock);
421
    fibril_mutex_unlock(&childp->lock);
421
 
422
 
422
    if (!fat_dentry_name_verify(name)) {
423
    if (!fat_dentry_name_verify(name)) {
423
        /*
424
        /*
424
         * Attempt to create unsupported name.
425
         * Attempt to create unsupported name.
425
         */
426
         */
Line 429... Line 430...
429
    /*
430
    /*
430
     * Get us an unused parent node's dentry or grow the parent and allocate
431
     * Get us an unused parent node's dentry or grow the parent and allocate
431
     * a new one.
432
     * a new one.
432
     */
433
     */
433
   
434
   
434
    futex_down(&parentp->idx->lock);
435
    fibril_mutex_lock(&parentp->idx->lock);
435
    bs = block_bb_get(parentp->idx->dev_handle);
436
    bs = block_bb_get(parentp->idx->dev_handle);
436
    bps = uint16_t_le2host(bs->bps);
437
    bps = uint16_t_le2host(bs->bps);
437
    dps = bps / sizeof(fat_dentry_t);
438
    dps = bps / sizeof(fat_dentry_t);
438
 
439
 
439
    blocks = parentp->size / bps;
440
    blocks = parentp->size / bps;
Line 460... Line 461...
460
    /*
461
    /*
461
     * We need to grow the parent in order to create a new unused dentry.
462
     * We need to grow the parent in order to create a new unused dentry.
462
     */
463
     */
463
    if (parentp->idx->pfc == FAT_CLST_ROOT) {
464
    if (parentp->idx->pfc == FAT_CLST_ROOT) {
464
        /* Can't grow the root directory. */
465
        /* Can't grow the root directory. */
465
        futex_up(&parentp->idx->lock);
466
        fibril_mutex_unlock(&parentp->idx->lock);
466
        return ENOSPC;
467
        return ENOSPC;
467
    }
468
    }
468
    rc = fat_alloc_clusters(bs, parentp->idx->dev_handle, 1, &mcl, &lcl);
469
    rc = fat_alloc_clusters(bs, parentp->idx->dev_handle, 1, &mcl, &lcl);
469
    if (rc != EOK) {
470
    if (rc != EOK) {
470
        futex_up(&parentp->idx->lock);
471
        fibril_mutex_unlock(&parentp->idx->lock);
471
        return rc;
472
        return rc;
472
    }
473
    }
473
    fat_append_clusters(bs, parentp, mcl);
474
    fat_append_clusters(bs, parentp, mcl);
474
    b = fat_block_get(bs, parentp, i, BLOCK_FLAGS_NOREAD);
475
    b = fat_block_get(bs, parentp, i, BLOCK_FLAGS_NOREAD);
475
    d = (fat_dentry_t *)b->data;
476
    d = (fat_dentry_t *)b->data;
Line 488... Line 489...
488
     */
489
     */
489
    memset(d, 0, sizeof(fat_dentry_t));
490
    memset(d, 0, sizeof(fat_dentry_t));
490
    fat_dentry_name_set(d, name);
491
    fat_dentry_name_set(d, name);
491
    b->dirty = true;        /* need to sync block */
492
    b->dirty = true;        /* need to sync block */
492
    block_put(b);
493
    block_put(b);
493
    futex_up(&parentp->idx->lock);
494
    fibril_mutex_unlock(&parentp->idx->lock);
494
 
495
 
495
    futex_down(&childp->idx->lock);
496
    fibril_mutex_lock(&childp->idx->lock);
496
   
497
   
497
    /*
498
    /*
498
     * If possible, create the Sub-directory Identifier Entry and the
499
     * If possible, create the Sub-directory Identifier Entry and the
499
     * Sub-directory Parent Pointer Entry (i.e. "." and ".."). These entries
500
     * Sub-directory Parent Pointer Entry (i.e. "." and ".."). These entries
500
     * are not mandatory according to Standard ECMA-107 and HelenOS VFS does
501
     * are not mandatory according to Standard ECMA-107 and HelenOS VFS does
Line 526... Line 527...
526
    b->dirty = true;        /* need to sync block */
527
    b->dirty = true;        /* need to sync block */
527
    block_put(b);
528
    block_put(b);
528
 
529
 
529
    childp->idx->pfc = parentp->firstc;
530
    childp->idx->pfc = parentp->firstc;
530
    childp->idx->pdi = i * dps + j;
531
    childp->idx->pdi = i * dps + j;
531
    futex_up(&childp->idx->lock);
532
    fibril_mutex_unlock(&childp->idx->lock);
532
 
533
 
533
    futex_down(&childp->lock);
534
    fibril_mutex_lock(&childp->lock);
534
    childp->lnkcnt = 1;
535
    childp->lnkcnt = 1;
535
    childp->dirty = true;       /* need to sync node */
536
    childp->dirty = true;       /* need to sync node */
536
    futex_up(&childp->lock);
537
    fibril_mutex_unlock(&childp->lock);
537
 
538
 
538
    /*
539
    /*
539
     * Hash in the index structure into the position hash.
540
     * Hash in the index structure into the position hash.
540
     */
541
     */
541
    fat_idx_hashin(childp->idx);
542
    fat_idx_hashin(childp->idx);
Line 556... Line 557...
556
        return EBUSY;
557
        return EBUSY;
557
   
558
   
558
    if (fat_has_children(cfn))
559
    if (fat_has_children(cfn))
559
        return ENOTEMPTY;
560
        return ENOTEMPTY;
560
 
561
 
561
    futex_down(&parentp->lock);
562
    fibril_mutex_lock(&parentp->lock);
562
    futex_down(&childp->lock);
563
    fibril_mutex_lock(&childp->lock);
563
    assert(childp->lnkcnt == 1);
564
    assert(childp->lnkcnt == 1);
564
    futex_down(&childp->idx->lock);
565
    fibril_mutex_lock(&childp->idx->lock);
565
    bs = block_bb_get(childp->idx->dev_handle);
566
    bs = block_bb_get(childp->idx->dev_handle);
566
    bps = uint16_t_le2host(bs->bps);
567
    bps = uint16_t_le2host(bs->bps);
567
 
568
 
568
    b = _fat_block_get(bs, childp->idx->dev_handle, childp->idx->pfc,
569
    b = _fat_block_get(bs, childp->idx->dev_handle, childp->idx->pfc,
569
        (childp->idx->pdi * sizeof(fat_dentry_t)) / bps,
570
        (childp->idx->pdi * sizeof(fat_dentry_t)) / bps,
Line 578... Line 579...
578
    /* remove the index structure from the position hash */
579
    /* remove the index structure from the position hash */
579
    fat_idx_hashout(childp->idx);
580
    fat_idx_hashout(childp->idx);
580
    /* clear position information */
581
    /* clear position information */
581
    childp->idx->pfc = FAT_CLST_RES0;
582
    childp->idx->pfc = FAT_CLST_RES0;
582
    childp->idx->pdi = 0;
583
    childp->idx->pdi = 0;
583
    futex_up(&childp->idx->lock);
584
    fibril_mutex_unlock(&childp->idx->lock);
584
    childp->lnkcnt = 0;
585
    childp->lnkcnt = 0;
585
    childp->dirty = true;
586
    childp->dirty = true;
586
    futex_up(&childp->lock);
587
    fibril_mutex_unlock(&childp->lock);
587
    futex_up(&parentp->lock);
588
    fibril_mutex_unlock(&parentp->lock);
588
 
589
 
589
    return EOK;
590
    return EOK;
590
}
591
}
591
 
592
 
592
fs_node_t *fat_match(fs_node_t *pfn, const char *component)
593
fs_node_t *fat_match(fs_node_t *pfn, const char *component)
Line 599... Line 600...
599
    unsigned dps;       /* dentries per sector */
600
    unsigned dps;       /* dentries per sector */
600
    unsigned blocks;
601
    unsigned blocks;
601
    fat_dentry_t *d;
602
    fat_dentry_t *d;
602
    block_t *b;
603
    block_t *b;
603
 
604
 
604
    futex_down(&parentp->idx->lock);
605
    fibril_mutex_lock(&parentp->idx->lock);
605
    bs = block_bb_get(parentp->idx->dev_handle);
606
    bs = block_bb_get(parentp->idx->dev_handle);
606
    bps = uint16_t_le2host(bs->bps);
607
    bps = uint16_t_le2host(bs->bps);
607
    dps = bps / sizeof(fat_dentry_t);
608
    dps = bps / sizeof(fat_dentry_t);
608
    blocks = parentp->size / bps;
609
    blocks = parentp->size / bps;
609
    for (i = 0; i < blocks; i++) {
610
    for (i = 0; i < blocks; i++) {
Line 614... Line 615...
614
            case FAT_DENTRY_SKIP:
615
            case FAT_DENTRY_SKIP:
615
            case FAT_DENTRY_FREE:
616
            case FAT_DENTRY_FREE:
616
                continue;
617
                continue;
617
            case FAT_DENTRY_LAST:
618
            case FAT_DENTRY_LAST:
618
                block_put(b);
619
                block_put(b);
619
                futex_up(&parentp->idx->lock);
620
                fibril_mutex_unlock(&parentp->idx->lock);
620
                return NULL;
621
                return NULL;
621
            default:
622
            default:
622
            case FAT_DENTRY_VALID:
623
            case FAT_DENTRY_VALID:
623
                fat_dentry_name_get(d, name);
624
                fat_dentry_name_get(d, name);
624
                break;
625
                break;
Line 633... Line 634...
633
                 * order.
634
                 * order.
634
                 */
635
                 */
635
                fat_idx_t *idx = fat_idx_get_by_pos(
636
                fat_idx_t *idx = fat_idx_get_by_pos(
636
                    parentp->idx->dev_handle, parentp->firstc,
637
                    parentp->idx->dev_handle, parentp->firstc,
637
                    i * dps + j);
638
                    i * dps + j);
638
                futex_up(&parentp->idx->lock);
639
                fibril_mutex_unlock(&parentp->idx->lock);
639
                if (!idx) {
640
                if (!idx) {
640
                    /*
641
                    /*
641
                     * Can happen if memory is low or if we
642
                     * Can happen if memory is low or if we
642
                     * run out of 32-bit indices.
643
                     * run out of 32-bit indices.
643
                     */
644
                     */
644
                    block_put(b);
645
                    block_put(b);
645
                    return NULL;
646
                    return NULL;
646
                }
647
                }
647
                nodep = fat_node_get_core(idx);
648
                nodep = fat_node_get_core(idx);
648
                futex_up(&idx->lock);
649
                fibril_mutex_unlock(&idx->lock);
649
                block_put(b);
650
                block_put(b);
650
                return FS_NODE(nodep);
651
                return FS_NODE(nodep);
651
            }
652
            }
652
        }
653
        }
653
        block_put(b);
654
        block_put(b);
654
    }
655
    }
655
 
656
 
656
    futex_up(&parentp->idx->lock);
657
    fibril_mutex_unlock(&parentp->idx->lock);
657
    return NULL;
658
    return NULL;
658
}
659
}
659
 
660
 
660
fs_index_t fat_index_get(fs_node_t *fn)
661
fs_index_t fat_index_get(fs_node_t *fn)
661
{
662
{
Line 683... Line 684...
683
    unsigned i, j;
684
    unsigned i, j;
684
 
685
 
685
    if (nodep->type != FAT_DIRECTORY)
686
    if (nodep->type != FAT_DIRECTORY)
686
        return false;
687
        return false;
687
   
688
   
688
    futex_down(&nodep->idx->lock);
689
    fibril_mutex_lock(&nodep->idx->lock);
689
    bs = block_bb_get(nodep->idx->dev_handle);
690
    bs = block_bb_get(nodep->idx->dev_handle);
690
    bps = uint16_t_le2host(bs->bps);
691
    bps = uint16_t_le2host(bs->bps);
691
    dps = bps / sizeof(fat_dentry_t);
692
    dps = bps / sizeof(fat_dentry_t);
692
 
693
 
693
    blocks = nodep->size / bps;
694
    blocks = nodep->size / bps;
Line 702... Line 703...
702
            case FAT_DENTRY_SKIP:
703
            case FAT_DENTRY_SKIP:
703
            case FAT_DENTRY_FREE:
704
            case FAT_DENTRY_FREE:
704
                continue;
705
                continue;
705
            case FAT_DENTRY_LAST:
706
            case FAT_DENTRY_LAST:
706
                block_put(b);
707
                block_put(b);
707
                futex_up(&nodep->idx->lock);
708
                fibril_mutex_unlock(&nodep->idx->lock);
708
                return false;
709
                return false;
709
            default:
710
            default:
710
            case FAT_DENTRY_VALID:
711
            case FAT_DENTRY_VALID:
711
                block_put(b);
712
                block_put(b);
712
                futex_up(&nodep->idx->lock);
713
                fibril_mutex_unlock(&nodep->idx->lock);
713
                return true;
714
                return true;
714
            }
715
            }
715
            block_put(b);
716
            block_put(b);
716
            futex_up(&nodep->idx->lock);
717
            fibril_mutex_unlock(&nodep->idx->lock);
717
            return true;
718
            return true;
718
        }
719
        }
719
        block_put(b);
720
        block_put(b);
720
    }
721
    }
721
 
722
 
722
    futex_up(&nodep->idx->lock);
723
    fibril_mutex_unlock(&nodep->idx->lock);
723
    return false;
724
    return false;
724
}
725
}
725
 
726
 
726
fs_node_t *fat_root_get(dev_handle_t dev_handle)
727
fs_node_t *fat_root_get(dev_handle_t dev_handle)
727
{
728
{
Line 767... Line 768...
767
 */
768
 */
768
 
769
 
769
void fat_mounted(ipc_callid_t rid, ipc_call_t *request)
770
void fat_mounted(ipc_callid_t rid, ipc_call_t *request)
770
{
771
{
771
    dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
772
    dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
-
 
773
    enum cache_mode cmode;
772
    fat_bs_t *bs;
774
    fat_bs_t *bs;
773
    uint16_t bps;
775
    uint16_t bps;
774
    uint16_t rde;
776
    uint16_t rde;
775
    int rc;
777
    int rc;
776
 
778
 
Line 794... Line 796...
794
        free(opts);
796
        free(opts);
795
        return;
797
        return;
796
    }
798
    }
797
    opts[size] = '\0';
799
    opts[size] = '\0';
798
 
800
 
-
 
801
    /* Check for option enabling write through. */
-
 
802
    if (str_cmp(opts, "wtcache") == 0)
-
 
803
        cmode = CACHE_MODE_WT;
-
 
804
    else
-
 
805
        cmode = CACHE_MODE_WB;
-
 
806
 
799
    /* initialize libblock */
807
    /* initialize libblock */
800
    rc = block_init(dev_handle, BS_SIZE);
808
    rc = block_init(dev_handle, BS_SIZE);
801
    if (rc != EOK) {
809
    if (rc != EOK) {
802
        ipc_answer_0(rid, rc);
810
        ipc_answer_0(rid, rc);
803
        return;
811
        return;
Line 823... Line 831...
823
        ipc_answer_0(rid, ENOTSUP);
831
        ipc_answer_0(rid, ENOTSUP);
824
        return;
832
        return;
825
    }
833
    }
826
 
834
 
827
    /* Initialize the block cache */
835
    /* Initialize the block cache */
828
    rc = block_cache_init(dev_handle, bps, 0 /* XXX */);
836
    rc = block_cache_init(dev_handle, bps, 0 /* XXX */, cmode);
829
    if (rc != EOK) {
837
    if (rc != EOK) {
830
        block_fini(dev_handle);
838
        block_fini(dev_handle);
831
        ipc_answer_0(rid, rc);
839
        ipc_answer_0(rid, rc);
832
        return;
840
        return;
833
    }
841
    }
Line 845... Line 853...
845
        block_fini(dev_handle);
853
        block_fini(dev_handle);
846
        fat_idx_fini_by_dev_handle(dev_handle);
854
        fat_idx_fini_by_dev_handle(dev_handle);
847
        ipc_answer_0(rid, ENOMEM);
855
        ipc_answer_0(rid, ENOMEM);
848
        return;
856
        return;
849
    }
857
    }
-
 
858
    fs_node_initialize(rfn);
850
    fat_node_t *rootp = (fat_node_t *)malloc(sizeof(fat_node_t));
859
    fat_node_t *rootp = (fat_node_t *)malloc(sizeof(fat_node_t));
851
    if (!rootp) {
860
    if (!rootp) {
852
        free(rfn);
861
        free(rfn);
853
        block_fini(dev_handle);
862
        block_fini(dev_handle);
854
        fat_idx_fini_by_dev_handle(dev_handle);
863
        fat_idx_fini_by_dev_handle(dev_handle);
Line 877... Line 886...
877
    rootp->idx = ridxp;
886
    rootp->idx = ridxp;
878
    ridxp->nodep = rootp;
887
    ridxp->nodep = rootp;
879
    rootp->bp = rfn;
888
    rootp->bp = rfn;
880
    rfn->data = rootp;
889
    rfn->data = rootp;
881
   
890
   
882
    futex_up(&ridxp->lock);
891
    fibril_mutex_unlock(&ridxp->lock);
883
 
892
 
884
    ipc_answer_3(rid, EOK, ridxp->index, rootp->size, rootp->lnkcnt);
893
    ipc_answer_3(rid, EOK, ridxp->index, rootp->size, rootp->lnkcnt);
885
}
894
}
886
 
895
 
887
void fat_mount(ipc_callid_t rid, ipc_call_t *request)
896
void fat_mount(ipc_callid_t rid, ipc_call_t *request)
888
{
897
{
889
    ipc_answer_0(rid, ENOTSUP);
898
    libfs_mount(&fat_libfs_ops, fat_reg.fs_handle, rid, request);
890
}
899
}
891
 
900
 
892
void fat_lookup(ipc_callid_t rid, ipc_call_t *request)
901
void fat_lookup(ipc_callid_t rid, ipc_call_t *request)
893
{
902
{
894
    libfs_lookup(&fat_libfs_ops, fat_reg.fs_handle, rid, request);
903
    libfs_lookup(&fat_libfs_ops, fat_reg.fs_handle, rid, request);
Line 1165... Line 1174...
1165
    fat_node_put(fn);
1174
    fat_node_put(fn);
1166
    ipc_answer_0(rid, rc);
1175
    ipc_answer_0(rid, rc);
1167
    return;
1176
    return;
1168
}
1177
}
1169
 
1178
 
-
 
1179
void fat_close(ipc_callid_t rid, ipc_call_t *request)
-
 
1180
{
-
 
1181
    ipc_answer_0(rid, EOK);
-
 
1182
}
-
 
1183
 
1170
void fat_destroy(ipc_callid_t rid, ipc_call_t *request)
1184
void fat_destroy(ipc_callid_t rid, ipc_call_t *request)
1171
{
1185
{
1172
    dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
1186
    dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
1173
    fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
1187
    fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
1174
    int rc;
1188
    int rc;
Line 1181... Line 1195...
1181
 
1195
 
1182
    rc = fat_destroy_node(fn);
1196
    rc = fat_destroy_node(fn);
1183
    ipc_answer_0(rid, rc);
1197
    ipc_answer_0(rid, rc);
1184
}
1198
}
1185
 
1199
 
-
 
1200
void fat_open_node(ipc_callid_t rid, ipc_call_t *request)
-
 
1201
{
-
 
1202
    libfs_open_node(&fat_libfs_ops, fat_reg.fs_handle, rid, request);
-
 
1203
}
-
 
1204
 
-
 
1205
void fat_stat(ipc_callid_t rid, ipc_call_t *request)
-
 
1206
{
-
 
1207
    libfs_stat(&fat_libfs_ops, fat_reg.fs_handle, rid, request);
-
 
1208
}
-
 
1209
 
-
 
1210
void fat_sync(ipc_callid_t rid, ipc_call_t *request)
-
 
1211
{
-
 
1212
    /* Dummy implementation */
-
 
1213
    ipc_answer_0(rid, EOK);
-
 
1214
}
-
 
1215
 
1186
/**
1216
/**
1187
 * @}
1217
 * @}
1188
 */
1218
 */