Subversion Repositories HelenOS

Rev

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

Rev 3119 Rev 3253
Line 47... Line 47...
47
#include <libadt/list.h>
47
#include <libadt/list.h>
48
#include <assert.h>
48
#include <assert.h>
49
#include <futex.h>
49
#include <futex.h>
50
 
50
 
51
#define BS_BLOCK        0
51
#define BS_BLOCK        0
-
 
52
#define BS_SIZE         512
52
 
53
 
53
/** Futex protecting the list of cached free FAT nodes. */
54
/** Futex protecting the list of cached free FAT nodes. */
54
static futex_t ffn_futex = FUTEX_INITIALIZER;
55
static futex_t ffn_futex = FUTEX_INITIALIZER;
55
 
56
 
56
/** List of cached free FAT nodes. */
57
/** List of cached free FAT nodes. */
Line 97... Line 98...
97
/* TODO move somewhere else */
98
/* TODO move somewhere else */
98
typedef struct {
99
typedef struct {
99
    void *data;
100
    void *data;
100
} block_t;
101
} block_t;
101
 
102
 
102
static block_t *block_get(dev_handle_t dev_handle, off_t offset)
103
static block_t *block_get(dev_handle_t dev_handle, off_t offset, size_t bs)
103
{
104
{
104
    return NULL;    /* TODO */
105
    return NULL;    /* TODO */
105
}
106
}
106
 
107
 
107
static void block_put(block_t *block)
108
static void block_put(block_t *block)
Line 141... Line 142...
141
    unsigned ssa;       /* size of the system area */
142
    unsigned ssa;       /* size of the system area */
142
    unsigned clusters;
143
    unsigned clusters;
143
    fat_cluster_t clst = firstc;
144
    fat_cluster_t clst = firstc;
144
    unsigned i;
145
    unsigned i;
145
 
146
 
146
    bb = block_get(dev_handle, BS_BLOCK);
147
    bb = block_get(dev_handle, BS_BLOCK, BS_SIZE);
147
    bps = uint16_t_le2host(FAT_BS(bb)->bps);
148
    bps = uint16_t_le2host(FAT_BS(bb)->bps);
148
    spc = FAT_BS(bb)->spc;
149
    spc = FAT_BS(bb)->spc;
149
    rscnt = uint16_t_le2host(FAT_BS(bb)->rscnt);
150
    rscnt = uint16_t_le2host(FAT_BS(bb)->rscnt);
150
    fatcnt = FAT_BS(bb)->fatcnt;
151
    fatcnt = FAT_BS(bb)->fatcnt;
151
    rde = uint16_t_le2host(FAT_BS(bb)->root_ent_max);
152
    rde = uint16_t_le2host(FAT_BS(bb)->root_ent_max);
Line 157... Line 158...
157
    ssa = rscnt + fatcnt * sf + rds;
158
    ssa = rscnt + fatcnt * sf + rds;
158
 
159
 
159
    if (firstc == FAT_CLST_ROOT) {
160
    if (firstc == FAT_CLST_ROOT) {
160
        /* root directory special case */
161
        /* root directory special case */
161
        assert(offset < rds);
162
        assert(offset < rds);
162
        b = block_get(dev_handle, rscnt + fatcnt * sf + offset);
163
        b = block_get(dev_handle, rscnt + fatcnt * sf + offset, bps);
163
        return b;
164
        return b;
164
    }
165
    }
165
 
166
 
166
    clusters = offset / spc;
167
    clusters = offset / spc;
167
    for (i = 0; i < clusters; i++) {
168
    for (i = 0; i < clusters; i++) {
Line 170... Line 171...
170
 
171
 
171
        assert(clst >= FAT_CLST_FIRST && clst < FAT_CLST_BAD);
172
        assert(clst >= FAT_CLST_FIRST && clst < FAT_CLST_BAD);
172
        fsec = (clst * sizeof(fat_cluster_t)) / bps;
173
        fsec = (clst * sizeof(fat_cluster_t)) / bps;
173
        fidx = clst % (bps / sizeof(fat_cluster_t));
174
        fidx = clst % (bps / sizeof(fat_cluster_t));
174
        /* read FAT1 */
175
        /* read FAT1 */
175
        b = block_get(dev_handle, rscnt + fsec);
176
        b = block_get(dev_handle, rscnt + fsec, bps);
176
        clst = uint16_t_le2host(((fat_cluster_t *)b->data)[fidx]);
177
        clst = uint16_t_le2host(((fat_cluster_t *)b->data)[fidx]);
177
        assert(clst != FAT_CLST_BAD);
178
        assert(clst != FAT_CLST_BAD);
178
        assert(clst < FAT_CLST_LAST1);
179
        assert(clst < FAT_CLST_LAST1);
179
        block_put(b);
180
        block_put(b);
180
    }
181
    }
181
 
182
 
182
    b = block_get(dev_handle, ssa + (clst - FAT_CLST_FIRST) * spc +
183
    b = block_get(dev_handle, ssa + (clst - FAT_CLST_FIRST) * spc +
183
        offset % spc);
184
        offset % spc, bps);
184
 
185
 
185
    return b;
186
    return b;
186
}
187
}
187
 
188
 
188
static void fat_node_initialize(fat_node_t *node)
189
static void fat_node_initialize(fat_node_t *node)
Line 200... Line 201...
200
static uint16_t fat_bps_get(dev_handle_t dev_handle)
201
static uint16_t fat_bps_get(dev_handle_t dev_handle)
201
{
202
{
202
    block_t *bb;
203
    block_t *bb;
203
    uint16_t bps;
204
    uint16_t bps;
204
   
205
   
205
    bb = block_get(dev_handle, BS_BLOCK);
206
    bb = block_get(dev_handle, BS_BLOCK, BS_SIZE);
206
    assert(bb != NULL);
207
    assert(bb != NULL);
207
    bps = uint16_t_le2host(FAT_BS(bb)->bps);
208
    bps = uint16_t_le2host(FAT_BS(bb)->bps);
208
    block_put(bb);
209
    block_put(bb);
209
 
210
 
210
    return bps;
211
    return bps;
Line 569... Line 570...
569
    block_t *bb;
570
    block_t *bb;
570
    uint16_t rde;
571
    uint16_t rde;
571
    int rc;
572
    int rc;
572
 
573
 
573
    /* Read the number of root directory entries. */
574
    /* Read the number of root directory entries. */
574
    bb = block_get(dev_handle, BS_BLOCK);
575
    bb = block_get(dev_handle, BS_BLOCK, BS_SIZE);
575
    rde = uint16_t_le2host(FAT_BS(bb)->root_ent_max);
576
    rde = uint16_t_le2host(FAT_BS(bb)->root_ent_max);
576
    block_put(bb);
577
    block_put(bb);
577
 
578
 
578
    rc = fat_idx_init_by_dev_handle(dev_handle);
579
    rc = fat_idx_init_by_dev_handle(dev_handle);
579
    if (rc != EOK) {
580
    if (rc != EOK) {