Subversion Repositories HelenOS

Rev

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

Rev 3536 Rev 3597
Line 87... Line 87...
87
    bps = uint16_t_le2host(bs->bps);
87
    bps = uint16_t_le2host(bs->bps);
88
    dps = bps / sizeof(fat_dentry_t);
88
    dps = bps / sizeof(fat_dentry_t);
89
   
89
   
90
    /* Read the block that contains the dentry of interest. */
90
    /* Read the block that contains the dentry of interest. */
91
    b = _fat_block_get(bs, node->idx->dev_handle, node->idx->pfc,
91
    b = _fat_block_get(bs, node->idx->dev_handle, node->idx->pfc,
92
        (node->idx->pdi * sizeof(fat_dentry_t)) / bps);
92
        (node->idx->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE);
93
 
93
 
94
    d = ((fat_dentry_t *)b->data) + (node->idx->pdi % dps);
94
    d = ((fat_dentry_t *)b->data) + (node->idx->pdi % dps);
95
 
95
 
96
    d->firstc = host2uint16_t_le(node->firstc);
96
    d->firstc = host2uint16_t_le(node->firstc);
97
    if (node->type == FAT_FILE)
97
    if (node->type == FAT_FILE)
Line 100... Line 100...
100
   
100
   
101
    b->dirty = true;        /* need to sync block */
101
    b->dirty = true;        /* need to sync block */
102
    block_put(b);
102
    block_put(b);
103
}
103
}
104
 
104
 
-
 
105
static fat_node_t *fat_node_get_new(void)
-
 
106
{
-
 
107
    fat_node_t *nodep;
-
 
108
 
-
 
109
    futex_down(&ffn_futex);
-
 
110
    if (!list_empty(&ffn_head)) {
-
 
111
        /* Try to use a cached free node structure. */
-
 
112
        fat_idx_t *idxp_tmp;
-
 
113
        nodep = list_get_instance(ffn_head.next, fat_node_t, ffn_link);
-
 
114
        if (futex_trydown(&nodep->lock) == ESYNCH_WOULD_BLOCK)
-
 
115
            goto skip_cache;
-
 
116
        idxp_tmp = nodep->idx;
-
 
117
        if (futex_trydown(&idxp_tmp->lock) == ESYNCH_WOULD_BLOCK) {
-
 
118
            futex_up(&nodep->lock);
-
 
119
            goto skip_cache;
-
 
120
        }
-
 
121
        list_remove(&nodep->ffn_link);
-
 
122
        futex_up(&ffn_futex);
-
 
123
        if (nodep->dirty)
-
 
124
            fat_node_sync(nodep);
-
 
125
        idxp_tmp->nodep = NULL;
-
 
126
        futex_up(&nodep->lock);
-
 
127
        futex_up(&idxp_tmp->lock);
-
 
128
    } else {
-
 
129
skip_cache:
-
 
130
        /* Try to allocate a new node structure. */
-
 
131
        futex_up(&ffn_futex);
-
 
132
        nodep = (fat_node_t *)malloc(sizeof(fat_node_t));
-
 
133
        if (!nodep)
-
 
134
            return NULL;
-
 
135
    }
-
 
136
    fat_node_initialize(nodep);
-
 
137
   
-
 
138
    return nodep;
-
 
139
}
-
 
140
 
105
/** Internal version of fat_node_get().
141
/** Internal version of fat_node_get().
106
 *
142
 *
107
 * @param idxp      Locked index structure.
143
 * @param idxp      Locked index structure.
108
 */
144
 */
109
static void *fat_node_get_core(fat_idx_t *idxp)
145
static void *fat_node_get_core(fat_idx_t *idxp)
Line 111... Line 147...
111
    block_t *b;
147
    block_t *b;
112
    fat_bs_t *bs;
148
    fat_bs_t *bs;
113
    fat_dentry_t *d;
149
    fat_dentry_t *d;
114
    fat_node_t *nodep = NULL;
150
    fat_node_t *nodep = NULL;
115
    unsigned bps;
151
    unsigned bps;
-
 
152
    unsigned spc;
116
    unsigned dps;
153
    unsigned dps;
117
 
154
 
118
    if (idxp->nodep) {
155
    if (idxp->nodep) {
119
        /*
156
        /*
120
         * We are lucky.
157
         * We are lucky.
Line 131... Line 168...
131
     * We must instantiate the node from the file system.
168
     * We must instantiate the node from the file system.
132
     */
169
     */
133
   
170
   
134
    assert(idxp->pfc);
171
    assert(idxp->pfc);
135
 
172
 
136
    futex_down(&ffn_futex);
-
 
137
    if (!list_empty(&ffn_head)) {
-
 
138
        /* Try to use a cached free node structure. */
-
 
139
        fat_idx_t *idxp_tmp;
-
 
140
        nodep = list_get_instance(ffn_head.next, fat_node_t, ffn_link);
-
 
141
        if (futex_trydown(&nodep->lock) == ESYNCH_WOULD_BLOCK)
-
 
142
            goto skip_cache;
-
 
143
        idxp_tmp = nodep->idx;
-
 
144
        if (futex_trydown(&idxp_tmp->lock) == ESYNCH_WOULD_BLOCK) {
-
 
145
            futex_up(&nodep->lock);
-
 
146
            goto skip_cache;
-
 
147
        }
-
 
148
        list_remove(&nodep->ffn_link);
-
 
149
        futex_up(&ffn_futex);
-
 
150
        if (nodep->dirty)
-
 
151
            fat_node_sync(nodep);
173
    nodep = fat_node_get_new();
152
        idxp_tmp->nodep = NULL;
-
 
153
        futex_up(&nodep->lock);
-
 
154
        futex_up(&idxp_tmp->lock);
-
 
155
    } else {
-
 
156
skip_cache:
-
 
157
        /* Try to allocate a new node structure. */
-
 
158
        futex_up(&ffn_futex);
-
 
159
        nodep = (fat_node_t *)malloc(sizeof(fat_node_t));
-
 
160
        if (!nodep)
174
    if (!nodep)
161
            return NULL;
175
        return NULL;
162
    }
-
 
163
    fat_node_initialize(nodep);
-
 
164
 
176
 
165
    bs = block_bb_get(idxp->dev_handle);
177
    bs = block_bb_get(idxp->dev_handle);
166
    bps = uint16_t_le2host(bs->bps);
178
    bps = uint16_t_le2host(bs->bps);
-
 
179
    spc = bs->spc;
167
    dps = bps / sizeof(fat_dentry_t);
180
    dps = bps / sizeof(fat_dentry_t);
168
 
181
 
169
    /* Read the block that contains the dentry of interest. */
182
    /* Read the block that contains the dentry of interest. */
170
    b = _fat_block_get(bs, idxp->dev_handle, idxp->pfc,
183
    b = _fat_block_get(bs, idxp->dev_handle, idxp->pfc,
171
        (idxp->pdi * sizeof(fat_dentry_t)) / bps);
184
        (idxp->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE);
172
    assert(b);
185
    assert(b);
173
 
186
 
174
    d = ((fat_dentry_t *)b->data) + (idxp->pdi % dps);
187
    d = ((fat_dentry_t *)b->data) + (idxp->pdi % dps);
175
    if (d->attr & FAT_ATTR_SUBDIR) {
188
    if (d->attr & FAT_ATTR_SUBDIR) {
176
        /*
189
        /*
Line 182... Line 195...
182
        /*
195
        /*
183
         * Unfortunately, the 'size' field of the FAT dentry is not
196
         * Unfortunately, the 'size' field of the FAT dentry is not
184
         * defined for the directory entry type. We must determine the
197
         * defined for the directory entry type. We must determine the
185
         * size of the directory by walking the FAT.
198
         * size of the directory by walking the FAT.
186
         */
199
         */
187
        nodep->size = bps * _fat_blcks_get(bs, idxp->dev_handle,
200
        nodep->size = bps * spc * fat_clusters_get(bs, idxp->dev_handle,
188
            uint16_t_le2host(d->firstc), NULL);
201
            uint16_t_le2host(d->firstc));
189
    } else {
202
    } else {
190
        nodep->type = FAT_FILE;
203
        nodep->type = FAT_FILE;
191
        nodep->size = uint32_t_le2host(d->size);
204
        nodep->size = uint32_t_le2host(d->size);
192
    }
205
    }
193
    nodep->firstc = uint16_t_le2host(d->firstc);
206
    nodep->firstc = uint16_t_le2host(d->firstc);
Line 229... Line 242...
229
        futex_up(&ffn_futex);
242
        futex_up(&ffn_futex);
230
    }
243
    }
231
    futex_up(&nodep->lock);
244
    futex_up(&nodep->lock);
232
}
245
}
233
 
246
 
234
static void *fat_create(int flags)
247
static void *fat_create(dev_handle_t dev_handle, int flags)
235
{
248
{
236
    return NULL;    /* not supported at the moment */
249
    return NULL;    /* not supported at the moment */
237
}
250
}
238
 
251
 
239
static int fat_destroy(void *node)
252
static int fat_destroy(void *node)
Line 267... Line 280...
267
    bs = block_bb_get(parentp->idx->dev_handle);
280
    bs = block_bb_get(parentp->idx->dev_handle);
268
    bps = uint16_t_le2host(bs->bps);
281
    bps = uint16_t_le2host(bs->bps);
269
    dps = bps / sizeof(fat_dentry_t);
282
    dps = bps / sizeof(fat_dentry_t);
270
    blocks = parentp->size / bps;
283
    blocks = parentp->size / bps;
271
    for (i = 0; i < blocks; i++) {
284
    for (i = 0; i < blocks; i++) {
272
        b = fat_block_get(bs, parentp, i);
285
        b = fat_block_get(bs, parentp, i, BLOCK_FLAGS_NONE);
273
        for (j = 0; j < dps; j++) {
286
        for (j = 0; j < dps; j++) {
274
            d = ((fat_dentry_t *)b->data) + j;
287
            d = ((fat_dentry_t *)b->data) + j;
275
            switch (fat_classify_dentry(d)) {
288
            switch (fat_classify_dentry(d)) {
276
            case FAT_DENTRY_SKIP:
289
            case FAT_DENTRY_SKIP:
277
                continue;
290
                continue;
Line 357... Line 370...
357
    blocks = nodep->size / bps;
370
    blocks = nodep->size / bps;
358
 
371
 
359
    for (i = 0; i < blocks; i++) {
372
    for (i = 0; i < blocks; i++) {
360
        fat_dentry_t *d;
373
        fat_dentry_t *d;
361
   
374
   
362
        b = fat_block_get(bs, nodep, i);
375
        b = fat_block_get(bs, nodep, i, BLOCK_FLAGS_NONE);
363
        for (j = 0; j < dps; j++) {
376
        for (j = 0; j < dps; j++) {
364
            d = ((fat_dentry_t *)b->data) + j;
377
            d = ((fat_dentry_t *)b->data) + j;
365
            switch (fat_classify_dentry(d)) {
378
            switch (fat_classify_dentry(d)) {
366
            case FAT_DENTRY_SKIP:
379
            case FAT_DENTRY_SKIP:
367
                continue;
380
                continue;
Line 432... Line 445...
432
    uint16_t bps;
445
    uint16_t bps;
433
    uint16_t rde;
446
    uint16_t rde;
434
    int rc;
447
    int rc;
435
 
448
 
436
    /* initialize libblock */
449
    /* initialize libblock */
-
 
450
    rc = block_init(dev_handle, BS_SIZE);
-
 
451
    if (rc != EOK) {
-
 
452
        ipc_answer_0(rid, rc);
-
 
453
        return;
-
 
454
    }
-
 
455
 
-
 
456
    /* prepare the boot block */
437
    rc = block_init(dev_handle, BS_SIZE, BS_BLOCK * BS_SIZE, BS_SIZE);
457
    rc = block_bb_read(dev_handle, BS_BLOCK * BS_SIZE, BS_SIZE);
438
    if (rc != EOK) {
458
    if (rc != EOK) {
-
 
459
        block_fini(dev_handle);
439
        ipc_answer_0(rid, 0);
460
        ipc_answer_0(rid, rc);
440
        return;
461
        return;
441
    }
462
    }
442
 
463
 
443
    /* get the buffer with the boot sector */
464
    /* get the buffer with the boot sector */
444
    bs = block_bb_get(dev_handle);
465
    bs = block_bb_get(dev_handle);
Line 451... Line 472...
451
        block_fini(dev_handle);
472
        block_fini(dev_handle);
452
        ipc_answer_0(rid, ENOTSUP);
473
        ipc_answer_0(rid, ENOTSUP);
453
        return;
474
        return;
454
    }
475
    }
455
 
476
 
-
 
477
    /* Initialize the block cache */
-
 
478
    rc = block_cache_init(dev_handle, bps, 0 /* XXX */);
-
 
479
    if (rc != EOK) {
-
 
480
        block_fini(dev_handle);
-
 
481
        ipc_answer_0(rid, rc);
-
 
482
        return;
-
 
483
    }
-
 
484
 
456
    rc = fat_idx_init_by_dev_handle(dev_handle);
485
    rc = fat_idx_init_by_dev_handle(dev_handle);
457
    if (rc != EOK) {
486
    if (rc != EOK) {
458
        block_fini(dev_handle);
487
        block_fini(dev_handle);
459
        ipc_answer_0(rid, rc);
488
        ipc_answer_0(rid, rc);
460
        return;
489
        return;
Line 543... Line 572...
543
            bytes = 0;
572
            bytes = 0;
544
            (void) ipc_data_read_finalize(callid, NULL, 0);
573
            (void) ipc_data_read_finalize(callid, NULL, 0);
545
        } else {
574
        } else {
546
            bytes = min(len, bps - pos % bps);
575
            bytes = min(len, bps - pos % bps);
547
            bytes = min(bytes, nodep->size - pos);
576
            bytes = min(bytes, nodep->size - pos);
548
            b = fat_block_get(bs, nodep, pos / bps);
577
            b = fat_block_get(bs, nodep, pos / bps,
-
 
578
                BLOCK_FLAGS_NONE);
549
            (void) ipc_data_read_finalize(callid, b->data + pos % bps,
579
            (void) ipc_data_read_finalize(callid, b->data + pos % bps,
550
                bytes);
580
                bytes);
551
            block_put(b);
581
            block_put(b);
552
        }
582
        }
553
    } else {
583
    } else {
Line 568... Line 598...
568
         */
598
         */
569
        bnum = (pos * sizeof(fat_dentry_t)) / bps;
599
        bnum = (pos * sizeof(fat_dentry_t)) / bps;
570
        while (bnum < nodep->size / bps) {
600
        while (bnum < nodep->size / bps) {
571
            off_t o;
601
            off_t o;
572
 
602
 
573
            b = fat_block_get(bs, nodep, bnum);
603
            b = fat_block_get(bs, nodep, bnum, BLOCK_FLAGS_NONE);
574
            for (o = pos % (bps / sizeof(fat_dentry_t));
604
            for (o = pos % (bps / sizeof(fat_dentry_t));
575
                o < bps / sizeof(fat_dentry_t);
605
                o < bps / sizeof(fat_dentry_t);
576
                o++, pos++) {
606
                o++, pos++) {
577
                d = ((fat_dentry_t *)b->data) + o;
607
                d = ((fat_dentry_t *)b->data) + o;
578
                switch (fat_classify_dentry(d)) {
608
                switch (fat_classify_dentry(d)) {
Line 614... Line 644...
614
    fat_bs_t *bs;
644
    fat_bs_t *bs;
615
    size_t bytes;
645
    size_t bytes;
616
    block_t *b;
646
    block_t *b;
617
    uint16_t bps;
647
    uint16_t bps;
618
    unsigned spc;
648
    unsigned spc;
-
 
649
    unsigned bpc;       /* bytes per cluster */
619
    off_t boundary;
650
    off_t boundary;
-
 
651
    int flags = BLOCK_FLAGS_NONE;
620
   
652
   
621
    if (!nodep) {
653
    if (!nodep) {
622
        ipc_answer_0(rid, ENOENT);
654
        ipc_answer_0(rid, ENOENT);
623
        return;
655
        return;
624
    }
656
    }
625
   
657
   
626
    /* XXX remove me when you are ready */
-
 
627
    {
-
 
628
        ipc_answer_0(rid, ENOTSUP);
-
 
629
        fat_node_put(nodep);
-
 
630
        return;
-
 
631
    }
-
 
632
 
-
 
633
    ipc_callid_t callid;
658
    ipc_callid_t callid;
634
    size_t len;
659
    size_t len;
635
    if (!ipc_data_write_receive(&callid, &len)) {
660
    if (!ipc_data_write_receive(&callid, &len)) {
636
        fat_node_put(nodep);
661
        fat_node_put(nodep);
637
        ipc_answer_0(callid, EINVAL);
662
        ipc_answer_0(callid, EINVAL);
638
        ipc_answer_0(rid, EINVAL);
663
        ipc_answer_0(rid, EINVAL);
639
        return;
664
        return;
640
    }
665
    }
641
 
666
 
-
 
667
    bs = block_bb_get(dev_handle);
-
 
668
    bps = uint16_t_le2host(bs->bps);
-
 
669
    spc = bs->spc;
-
 
670
    bpc = bps * spc;
-
 
671
 
642
    /*
672
    /*
643
     * In all scenarios, we will attempt to write out only one block worth
673
     * In all scenarios, we will attempt to write out only one block worth
644
     * of data at maximum. There might be some more efficient approaches,
674
     * of data at maximum. There might be some more efficient approaches,
645
     * but this one greatly simplifies fat_write(). Note that we can afford
675
     * but this one greatly simplifies fat_write(). Note that we can afford
646
     * to do this because the client must be ready to handle the return
676
     * to do this because the client must be ready to handle the return
647
     * value signalizing a smaller number of bytes written.
677
     * value signalizing a smaller number of bytes written.
648
     */
678
     */
649
    bytes = min(len, bps - pos % bps);
679
    bytes = min(len, bps - pos % bps);
650
 
-
 
651
    bs = block_bb_get(dev_handle);
680
    if (bytes == bps)
652
    bps = uint16_t_le2host(bs->bps);
681
        flags |= BLOCK_FLAGS_NOREAD;
653
    spc = bs->spc;
-
 
654
   
682
   
655
    boundary = ROUND_UP(nodep->size, bps * spc);
683
    boundary = ROUND_UP(nodep->size, bpc);
656
    if (pos < boundary) {
684
    if (pos < boundary) {
657
        /*
685
        /*
658
         * This is the easier case - we are either overwriting already
686
         * This is the easier case - we are either overwriting already
659
         * existing contents or writing behind the EOF, but still within
687
         * existing contents or writing behind the EOF, but still within
660
         * the limits of the last cluster. The node size may grow to the
688
         * the limits of the last cluster. The node size may grow to the
661
         * next block size boundary.
689
         * next block size boundary.
662
         */
690
         */
663
        fat_fill_gap(bs, nodep, FAT_CLST_RES0, pos);
691
        fat_fill_gap(bs, nodep, FAT_CLST_RES0, pos);
664
        b = fat_block_get(bs, nodep, pos / bps);
692
        b = fat_block_get(bs, nodep, pos / bps, flags);
665
        (void) ipc_data_write_finalize(callid, b->data + pos % bps,
693
        (void) ipc_data_write_finalize(callid, b->data + pos % bps,
666
            bytes);
694
            bytes);
667
        b->dirty = true;        /* need to sync block */
695
        b->dirty = true;        /* need to sync block */
668
        block_put(b);
696
        block_put(b);
669
        if (pos + bytes > nodep->size) {
697
        if (pos + bytes > nodep->size) {
670
            nodep->size = pos + bytes;
698
            nodep->size = pos + bytes;
671
            nodep->dirty = true;    /* need to sync node */
699
            nodep->dirty = true;    /* need to sync node */
672
        }
700
        }
-
 
701
        ipc_answer_2(rid, EOK, bytes, nodep->size);
673
        fat_node_put(nodep);
702
        fat_node_put(nodep);
674
        ipc_answer_1(rid, EOK, bytes); 
-
 
675
        return;
703
        return;
676
    } else {
704
    } else {
677
        /*
705
        /*
678
         * This is the more difficult case. We must allocate new
706
         * This is the more difficult case. We must allocate new
679
         * clusters for the node and zero them out.
707
         * clusters for the node and zero them out.
680
         */
708
         */
681
        int status;
709
        int status;
682
        unsigned nclsts;
710
        unsigned nclsts;
683
        fat_cluster_t mcl, lcl;
711
        fat_cluster_t mcl, lcl;
684
   
712
 
685
        nclsts = (ROUND_UP(pos + bytes, bps * spc) - boundary) /
713
        nclsts = (ROUND_UP(pos + bytes, bpc) - boundary) / bpc;
686
            bps * spc;
-
 
687
        /* create an independent chain of nclsts clusters in all FATs */
714
        /* create an independent chain of nclsts clusters in all FATs */
688
        status = fat_alloc_clusters(bs, dev_handle, nclsts, &mcl,
715
        status = fat_alloc_clusters(bs, dev_handle, nclsts, &mcl, &lcl);
689
            &lcl);
-
 
690
        if (status != EOK) {
716
        if (status != EOK) {
691
            /* could not allocate a chain of nclsts clusters */
717
            /* could not allocate a chain of nclsts clusters */
692
            fat_node_put(nodep);
718
            fat_node_put(nodep);
693
            ipc_answer_0(callid, status);
719
            ipc_answer_0(callid, status);
694
            ipc_answer_0(rid, status);
720
            ipc_answer_0(rid, status);
695
            return;
721
            return;
696
        }
722
        }
697
        /* zero fill any gaps */
723
        /* zero fill any gaps */
698
        fat_fill_gap(bs, nodep, mcl, pos);
724
        fat_fill_gap(bs, nodep, mcl, pos);
699
        b = _fat_block_get(bs, dev_handle, lcl,
725
        b = _fat_block_get(bs, dev_handle, lcl, (pos / bps) % spc,
700
            (pos / bps) % spc);
726
            flags);
701
        (void) ipc_data_write_finalize(callid, b->data + pos % bps,
727
        (void) ipc_data_write_finalize(callid, b->data + pos % bps,
702
            bytes);
728
            bytes);
703
        b->dirty = true;        /* need to sync block */
729
        b->dirty = true;        /* need to sync block */
704
        block_put(b);
730
        block_put(b);
705
        /*
731
        /*
Line 707... Line 733...
707
         * node's cluster chain.
733
         * node's cluster chain.
708
         */
734
         */
709
        fat_append_clusters(bs, nodep, mcl);
735
        fat_append_clusters(bs, nodep, mcl);
710
        nodep->size = pos + bytes;
736
        nodep->size = pos + bytes;
711
        nodep->dirty = true;        /* need to sync node */
737
        nodep->dirty = true;        /* need to sync node */
-
 
738
        ipc_answer_2(rid, EOK, bytes, nodep->size);
712
        fat_node_put(nodep);
739
        fat_node_put(nodep);
713
        ipc_answer_1(rid, EOK, bytes);
-
 
714
        return;
740
        return;
715
    }
741
    }
716
}
742
}
717
 
743
 
-
 
744
void fat_truncate(ipc_callid_t rid, ipc_call_t *request)
-
 
745
{
-
 
746
    dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
-
 
747
    fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
-
 
748
    size_t size = (off_t)IPC_GET_ARG3(*request);
-
 
749
    fat_node_t *nodep = (fat_node_t *)fat_node_get(dev_handle, index);
-
 
750
    fat_bs_t *bs;
-
 
751
    uint16_t bps;
-
 
752
    uint8_t spc;
-
 
753
    unsigned bpc;   /* bytes per cluster */
-
 
754
    int rc;
-
 
755
 
-
 
756
    if (!nodep) {
-
 
757
        ipc_answer_0(rid, ENOENT);
-
 
758
        return;
-
 
759
    }
-
 
760
 
-
 
761
    bs = block_bb_get(dev_handle);
-
 
762
    bps = uint16_t_le2host(bs->bps);
-
 
763
    spc = bs->spc;
-
 
764
    bpc = bps * spc;
-
 
765
 
-
 
766
    if (nodep->size == size) {
-
 
767
        rc = EOK;
-
 
768
    } else if (nodep->size < size) {
-
 
769
        /*
-
 
770
         * The standard says we have the freedom to grow the node.
-
 
771
         * For now, we simply return an error.
-
 
772
         */
-
 
773
        rc = EINVAL;
-
 
774
    } else if (ROUND_UP(nodep->size, bpc) == ROUND_UP(size, bpc)) {
-
 
775
        /*
-
 
776
         * The node will be shrunk, but no clusters will be deallocated.
-
 
777
         */
-
 
778
        nodep->size = size;
-
 
779
        nodep->dirty = true;        /* need to sync node */
-
 
780
        rc = EOK;  
-
 
781
    } else {
-
 
782
        /*
-
 
783
         * The node will be shrunk, clusters will be deallocated.
-
 
784
         */
-
 
785
        if (size == 0) {
-
 
786
            fat_chop_clusters(bs, nodep, FAT_CLST_RES0);
-
 
787
        } else {
-
 
788
            fat_cluster_t lastc;
-
 
789
            (void) fat_cluster_walk(bs, dev_handle, nodep->firstc,
-
 
790
                &lastc, (size - 1) / bpc);
-
 
791
            fat_chop_clusters(bs, nodep, lastc);
-
 
792
        }
-
 
793
        nodep->size = size;
-
 
794
        nodep->dirty = true;        /* need to sync node */
-
 
795
        rc = EOK;  
-
 
796
    }
-
 
797
    fat_node_put(nodep);
-
 
798
    ipc_answer_0(rid, rc);
-
 
799
    return;
-
 
800
}
-
 
801
 
718
/**
802
/**
719
 * @}
803
 * @}
720
 */
804
 */