Subversion Repositories HelenOS

Rev

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

Rev 3009 Rev 3153
Line 110... Line 110...
110
}
110
}
111
 
111
 
112
#define FAT_BS(b)       ((fat_bs_t *)((b)->data))
112
#define FAT_BS(b)       ((fat_bs_t *)((b)->data))
113
 
113
 
114
#define FAT_CLST_RES0   0x0000
114
#define FAT_CLST_RES0   0x0000
115
#define FAT_CLST_RES1   0x0001  /* internally used to mark root directory */
115
#define FAT_CLST_RES1   0x0001
116
#define FAT_CLST_FIRST  0x0002
116
#define FAT_CLST_FIRST  0x0002
117
#define FAT_CLST_BAD    0xfff7
117
#define FAT_CLST_BAD    0xfff7
118
#define FAT_CLST_LAST1  0xfff8
118
#define FAT_CLST_LAST1  0xfff8
119
#define FAT_CLST_LAST8  0xffff
119
#define FAT_CLST_LAST8  0xffff
120
 
120
 
-
 
121
/* internally used to mark root directory's parent */
-
 
122
#define FAT_CLST_ROOTPAR    FAT_CLST_RES0
-
 
123
/* internally used to mark root directory */
-
 
124
#define FAT_CLST_ROOT       FAT_CLST_RES1
-
 
125
 
121
#define fat_block_get(np, off) \
126
#define fat_block_get(np, off) \
122
    _fat_block_get((np)->idx->dev_handle, (np)->firstc, (off))
127
    _fat_block_get((np)->idx->dev_handle, (np)->firstc, (off))
123
 
128
 
124
static block_t *
129
static block_t *
125
_fat_block_get(dev_handle_t dev_handle, fat_cluster_t firstc, off_t offset)
130
_fat_block_get(dev_handle_t dev_handle, fat_cluster_t firstc, off_t offset)
Line 149... Line 154...
149
 
154
 
150
    rds = (sizeof(fat_dentry_t) * rde) / bps;
155
    rds = (sizeof(fat_dentry_t) * rde) / bps;
151
    rds += ((sizeof(fat_dentry_t) * rde) % bps != 0);
156
    rds += ((sizeof(fat_dentry_t) * rde) % bps != 0);
152
    ssa = rscnt + fatcnt * sf + rds;
157
    ssa = rscnt + fatcnt * sf + rds;
153
 
158
 
154
    if (firstc == FAT_CLST_RES1) {
159
    if (firstc == FAT_CLST_ROOT) {
155
        /* root directory special case */
160
        /* root directory special case */
156
        assert(offset < rds);
161
        assert(offset < rds);
157
        b = block_get(dev_handle, rscnt + fatcnt * sf + offset);
162
        b = block_get(dev_handle, rscnt + fatcnt * sf + offset);
158
        return b;
163
        return b;
159
    }
164
    }
Line 519... Line 524...
519
    return false;
524
    return false;
520
}
525
}
521
 
526
 
522
static void *fat_root_get(dev_handle_t dev_handle)
527
static void *fat_root_get(dev_handle_t dev_handle)
523
{
528
{
524
    return NULL;    /* TODO */
529
    return fat_node_get(dev_handle, 0);
525
}
530
}
526
 
531
 
527
static char fat_plb_get_char(unsigned pos)
532
static char fat_plb_get_char(unsigned pos)
528
{
533
{
529
    return fat_reg.plb_ro[pos % PLB_SIZE];
534
    return fat_reg.plb_ro[pos % PLB_SIZE];
Line 556... Line 561...
556
    .plb_get_char = fat_plb_get_char,
561
    .plb_get_char = fat_plb_get_char,
557
    .is_directory = fat_is_directory,
562
    .is_directory = fat_is_directory,
558
    .is_file = fat_is_file
563
    .is_file = fat_is_file
559
};
564
};
560
 
565
 
-
 
566
void fat_mounted(ipc_callid_t rid, ipc_call_t *request)
-
 
567
{
-
 
568
    dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
-
 
569
    block_t *bb;
-
 
570
    uint16_t rde;
-
 
571
    int rc;
-
 
572
 
-
 
573
    /* Read the number of root directory entries. */
-
 
574
    bb = block_get(dev_handle, BS_BLOCK);
-
 
575
    rde = uint16_t_le2host(FAT_BS(bb)->root_ent_max);
-
 
576
    block_put(bb);
-
 
577
 
-
 
578
    rc = fat_idx_init_by_dev_handle(dev_handle);
-
 
579
    if (rc != EOK) {
-
 
580
        ipc_answer_0(rid, rc);
-
 
581
        return;
-
 
582
    }
-
 
583
 
-
 
584
    /* Initialize the root node. */
-
 
585
    fat_node_t *rootp = (fat_node_t *)malloc(sizeof(fat_node_t));
-
 
586
    if (!rootp) {
-
 
587
        fat_idx_fini_by_dev_handle(dev_handle);
-
 
588
        ipc_answer_0(rid, ENOMEM);
-
 
589
        return;
-
 
590
    }
-
 
591
    fat_node_initialize(rootp);
-
 
592
 
-
 
593
    fat_idx_t *ridxp = fat_idx_get_by_pos(dev_handle, FAT_CLST_ROOTPAR, 0);
-
 
594
    if (!ridxp) {
-
 
595
        free(rootp);
-
 
596
        fat_idx_fini_by_dev_handle(dev_handle);
-
 
597
        ipc_answer_0(rid, ENOMEM);
-
 
598
        return;
-
 
599
    }
-
 
600
    assert(ridxp->index == 0);
-
 
601
    /* ridxp->lock held */
-
 
602
 
-
 
603
    rootp->type = FAT_DIRECTORY;
-
 
604
    rootp->firstc = FAT_CLST_ROOT;
-
 
605
    rootp->refcnt = 1;
-
 
606
    rootp->size = rde * sizeof(fat_dentry_t);
-
 
607
    rootp->idx = ridxp;
-
 
608
    ridxp->nodep = rootp;
-
 
609
   
-
 
610
    futex_up(&ridxp->lock);
-
 
611
 
-
 
612
    ipc_answer_0(rid, EOK);
-
 
613
}
-
 
614
 
-
 
615
void fat_mount(ipc_callid_t rid, ipc_call_t *request)
-
 
616
{
-
 
617
    ipc_answer_0(rid, ENOTSUP);
-
 
618
}
-
 
619
 
561
void fat_lookup(ipc_callid_t rid, ipc_call_t *request)
620
void fat_lookup(ipc_callid_t rid, ipc_call_t *request)
562
{
621
{
563
    libfs_lookup(&fat_libfs_ops, fat_reg.fs_handle, rid, request);
622
    libfs_lookup(&fat_libfs_ops, fat_reg.fs_handle, rid, request);
564
}
623
}
565
 
624