Subversion Repositories HelenOS

Rev

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

Rev 3521 Rev 3542
Line 93... Line 93...
93
    ssa = rscnt + fatcnt * sf + rds;
93
    ssa = rscnt + fatcnt * sf + rds;
94
 
94
 
95
    if (firstc == FAT_CLST_ROOT) {
95
    if (firstc == FAT_CLST_ROOT) {
96
        /* root directory special case */
96
        /* root directory special case */
97
        assert(offset < rds);
97
        assert(offset < rds);
98
        b = block_get(dev_handle, rscnt + fatcnt * sf + offset, bps);
98
        b = block_get(dev_handle, rscnt + fatcnt * sf + offset);
99
        return b;
99
        return b;
100
    }
100
    }
101
 
101
 
102
    clusters = offset / spc;
102
    clusters = offset / spc;
103
    for (i = 0; i < clusters; i++) {
103
    for (i = 0; i < clusters; i++) {
Line 106... Line 106...
106
 
106
 
107
        assert(clst >= FAT_CLST_FIRST && clst < FAT_CLST_BAD);
107
        assert(clst >= FAT_CLST_FIRST && clst < FAT_CLST_BAD);
108
        fsec = (clst * sizeof(fat_cluster_t)) / bps;
108
        fsec = (clst * sizeof(fat_cluster_t)) / bps;
109
        fidx = clst % (bps / sizeof(fat_cluster_t));
109
        fidx = clst % (bps / sizeof(fat_cluster_t));
110
        /* read FAT1 */
110
        /* read FAT1 */
111
        b = block_get(dev_handle, rscnt + fsec, bps);
111
        b = block_get(dev_handle, rscnt + fsec);
112
        clst = uint16_t_le2host(((fat_cluster_t *)b->data)[fidx]);
112
        clst = uint16_t_le2host(((fat_cluster_t *)b->data)[fidx]);
113
        assert(clst != FAT_CLST_BAD);
113
        assert(clst != FAT_CLST_BAD);
114
        assert(clst < FAT_CLST_LAST1);
114
        assert(clst < FAT_CLST_LAST1);
115
        block_put(b);
115
        block_put(b);
116
    }
116
    }
117
 
117
 
118
    b = block_get(dev_handle, ssa + (clst - FAT_CLST_FIRST) * spc +
118
    b = block_get(dev_handle, ssa + (clst - FAT_CLST_FIRST) * spc +
119
        offset % spc, bps);
119
        offset % spc);
120
 
120
 
121
    return b;
121
    return b;
122
}
122
}
123
 
123
 
124
/** Return number of blocks allocated to a file.
124
/** Return number of blocks allocated to a file.
Line 161... Line 161...
161
        if (lastc)
161
        if (lastc)
162
            *lastc = clst;      /* remember the last cluster */
162
            *lastc = clst;      /* remember the last cluster */
163
        fsec = (clst * sizeof(fat_cluster_t)) / bps;
163
        fsec = (clst * sizeof(fat_cluster_t)) / bps;
164
        fidx = clst % (bps / sizeof(fat_cluster_t));
164
        fidx = clst % (bps / sizeof(fat_cluster_t));
165
        /* read FAT1 */
165
        /* read FAT1 */
166
        b = block_get(dev_handle, rscnt + fsec, bps);
166
        b = block_get(dev_handle, rscnt + fsec);
167
        clst = uint16_t_le2host(((fat_cluster_t *)b->data)[fidx]);
167
        clst = uint16_t_le2host(((fat_cluster_t *)b->data)[fidx]);
168
        assert(clst != FAT_CLST_BAD);
168
        assert(clst != FAT_CLST_BAD);
169
        block_put(b);
169
        block_put(b);
170
        clusters++;
170
        clusters++;
171
    }
171
    }
Line 241... Line 241...
241
    rscnt = uint16_t_le2host(bs->rscnt);
241
    rscnt = uint16_t_le2host(bs->rscnt);
242
    sf = uint16_t_le2host(bs->sec_per_fat);
242
    sf = uint16_t_le2host(bs->sec_per_fat);
243
 
243
 
244
    assert(fatno < bs->fatcnt);
244
    assert(fatno < bs->fatcnt);
245
    b = block_get(dev_handle, rscnt + sf * fatno +
245
    b = block_get(dev_handle, rscnt + sf * fatno +
246
        (clst * sizeof(fat_cluster_t)) / bps, bps);
246
        (clst * sizeof(fat_cluster_t)) / bps);
247
    cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t));
247
    cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t));
248
    *cp = host2uint16_t_le(value);
248
    *cp = host2uint16_t_le(value);
249
    b->dirty = true;        /* need to sync block */
249
    b->dirty = true;        /* need to sync block */
250
    block_put(b);
250
    block_put(b);
251
}
251
}
Line 311... Line 311...
311
    /*
311
    /*
312
     * Search FAT1 for unused clusters.
312
     * Search FAT1 for unused clusters.
313
     */
313
     */
314
    futex_down(&fat_alloc_lock);
314
    futex_down(&fat_alloc_lock);
315
    for (b = 0, cl = 0; b < sf; blk++) {
315
    for (b = 0, cl = 0; b < sf; blk++) {
316
        blk = block_get(dev_handle, rscnt + b, bps);
316
        blk = block_get(dev_handle, rscnt + b);
317
        for (c = 0; c < bps / sizeof(fat_cluster_t); c++, cl++) {
317
        for (c = 0; c < bps / sizeof(fat_cluster_t); c++, cl++) {
318
            fat_cluster_t *clst = (fat_cluster_t *)blk->data + c;
318
            fat_cluster_t *clst = (fat_cluster_t *)blk->data + c;
319
            if (uint16_t_le2host(*clst) == FAT_CLST_RES0) {
319
            if (uint16_t_le2host(*clst) == FAT_CLST_RES0) {
320
                /*
320
                /*
321
                 * The cluster is free. Put it into our stack
321
                 * The cluster is free. Put it into our stack