Changeset b4b7187 in mainline


Ignore:
Timestamp:
2008-10-25T19:38:38Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8b0bc1f
Parents:
6f2dfd1
Message:

Implementation of fat_fill_gap().

File:
1 edited

Legend:

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

    r6f2dfd1 rb4b7187  
    850850}
    851851
     852/** Fill the gap between EOF and a new file position.
     853 *
     854 * @param nodep         FAT node with the gap.
     855 * @param mcl           First cluster in an independent cluster chain that will
     856 *                      be later appended to the end of the node's own cluster
     857 *                      chain. If pos is still in the last allocated cluster,
     858 *                      this argument is ignored.
     859 * @param pos           Position in the last node block.
     860 */
    852861static void
    853 fat_fill_gap(fat_node_t *nodep, fat_cluster_t mclst, off_t pos)
    854 {
    855         /* TODO */
     862fat_fill_gap(fat_node_t *nodep, fat_cluster_t mcl, off_t pos)
     863{
     864        uint16_t bps;
     865        unsigned spc;
     866        block_t *bb, *b;
     867        off_t o, boundary;
     868
     869        bb = block_get(nodep->idx->dev_handle, BS_BLOCK, BS_SIZE);
     870        bps = uint16_t_le2host(FAT_BS(bb)->bps);
     871        spc = FAT_BS(bb)->spc;
     872        block_put(bb);
     873       
     874        boundary = ROUND_UP(nodep->size, bps * spc);
     875
     876        /* zero out already allocated space */
     877        for (o = nodep->size - 1; o < pos && o < boundary;
     878            o = ALIGN_DOWN(o + bps, bps)) {
     879                b = fat_block_get(nodep, o / bps);
     880                memset(b->data + o % bps, 0, bps - o % bps);
     881                b->dirty = true;                /* need to sync node */
     882                block_put(b);
     883        }
     884       
     885        if (o >= pos)
     886                return;
     887       
     888        /* zero out the initial part of the new cluster chain */
     889        for (o = boundary; o < pos; o += bps) {
     890                b = _fat_block_get(nodep->idx->dev_handle, mcl,
     891                    (o - boundary) / bps);
     892                memset(b->data, 0, min(bps, pos - o));
     893                b->dirty = true;
     894                block_put(b);
     895        }
    856896}
    857897
     
    877917        uint16_t bps;
    878918        unsigned spc;
    879         off_t clst_boundary;
     919        off_t boundary;
    880920       
    881921        if (!nodep) {
     
    914954        block_put(bb);
    915955       
    916         clst_boundary = ROUND_UP(nodep->size, bps * spc);
    917         if (pos < clst_boundary) {
     956        boundary = ROUND_UP(nodep->size, bps * spc);
     957        if (pos < boundary) {
    918958                /*
    919959                 * This is the easier case - we are either overwriting already
     
    944984                fat_cluster_t mcl, lcl;
    945985       
    946                 nclsts = (ROUND_UP(pos + bytes, bps * spc) - clst_boundary) /
     986                nclsts = (ROUND_UP(pos + bytes, bps * spc) - boundary) /
    947987                    bps * spc;
    948988                /* create an independent chain of nclsts clusters in all FATs */
     
    9601000                (void) ipc_data_write_finalize(callid, b->data + pos % bps,
    9611001                    bytes);
    962                 b->dirty = true;
     1002                b->dirty = true;                /* need to sync block */
    9631003                block_put(b);
    9641004                /*
     
    9681008                fat_append_clusters(nodep, mcl);
    9691009                nodep->size = pos + bytes;
    970                 nodep->dirty = true;
     1010                nodep->dirty = true;            /* need to sync node */
    9711011                fat_node_put(nodep);
    9721012                ipc_answer_1(rid, EOK, bytes);
Note: See TracChangeset for help on using the changeset viewer.