Changeset 913a821c in mainline for uspace/srv/fs/fat/fat_ops.c


Ignore:
Timestamp:
2008-11-09T17:23:53Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ac49f5d1
Parents:
6c8d267
Message:

Finish implementation of fat_truncate() and fix several warnings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/fat/fat_ops.c

    r6c8d267 r913a821c  
    635635        uint16_t bps;
    636636        unsigned spc;
     637        unsigned bpc;           /* bytes per cluster */
    637638        off_t boundary;
    638639       
     
    650651                return;
    651652        }
     653
     654        bs = block_bb_get(dev_handle);
     655        bps = uint16_t_le2host(bs->bps);
     656        spc = bs->spc;
     657        bpc = bps * spc;
    652658
    653659        /*
     
    659665         */
    660666        bytes = min(len, bps - pos % bps);
    661 
    662         bs = block_bb_get(dev_handle);
    663         bps = uint16_t_le2host(bs->bps);
    664         spc = bs->spc;
    665        
    666         boundary = ROUND_UP(nodep->size, bps * spc);
     667       
     668        boundary = ROUND_UP(nodep->size, bpc);
    667669        if (pos < boundary) {
    668670                /*
     
    694696                fat_cluster_t mcl, lcl;
    695697 
    696                 nclsts = (ROUND_UP(pos + bytes, bps * spc) - boundary) /
    697                     bps * spc;
     698                nclsts = (ROUND_UP(pos + bytes, bpc) - boundary) / bpc;
    698699                /* create an independent chain of nclsts clusters in all FATs */
    699                 status = fat_alloc_clusters(bs, dev_handle, nclsts, &mcl,
    700                     &lcl);
     700                status = fat_alloc_clusters(bs, dev_handle, nclsts, &mcl, &lcl);
    701701                if (status != EOK) {
    702702                        /* could not allocate a chain of nclsts clusters */
     
    732732        size_t size = (off_t)IPC_GET_ARG3(*request);
    733733        fat_node_t *nodep = (fat_node_t *)fat_node_get(dev_handle, index);
     734        fat_bs_t *bs;
     735        uint16_t bps;
     736        uint8_t spc;
     737        unsigned bpc;   /* bytes per cluster */
    734738        int rc;
    735739
     
    738742                return;
    739743        }
     744
     745        bs = block_bb_get(dev_handle);
     746        bps = uint16_t_le2host(bs->bps);
     747        spc = bs->spc;
     748        bpc = bps * spc;
    740749
    741750        if (nodep->size == size) {
     
    743752        } else if (nodep->size < size) {
    744753                /*
    745                  * TODO: the standard says we have the freedom to grow the file.
     754                 * The standard says we have the freedom to grow the node.
    746755                 * For now, we simply return an error.
    747756                 */
    748757                rc = EINVAL;
     758        } else if (ROUND_UP(nodep->size, bpc) == ROUND_UP(size, bpc)) {
     759                /*
     760                 * The node will be shrunk, but no clusters will be deallocated.
     761                 */
     762                nodep->size = size;
     763                nodep->dirty = true;            /* need to sync node */
     764                rc = EOK;       
    749765        } else {
    750766                /*
    751                  * The file is to be shrunk.
    752                  */
    753                 rc = ENOTSUP;   /* XXX */
     767                 * The node will be shrunk, clusters will be deallocated.
     768                 */
     769                if (size == 0) {
     770                        fat_chop_clusters(bs, nodep, FAT_CLST_RES0);
     771                } else {
     772                        fat_cluster_t lastc;
     773                        (void) fat_cluster_walk(bs, dev_handle, nodep->firstc,
     774                            &lastc, (size - 1) / bpc);
     775                        fat_chop_clusters(bs, nodep, lastc);
     776                }
     777                nodep->size = size;
     778                nodep->dirty = true;            /* need to sync node */
     779                rc = EOK;       
    754780        }
    755781        fat_node_put(nodep);
    756782        ipc_answer_0(rid, rc);
    757783        return;
    758 
    759784}
    760785
Note: See TracChangeset for help on using the changeset viewer.