Changeset 36cb22f in mainline


Ignore:
Timestamp:
2011-09-27T13:01:54Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5726a1a3, 747a1e71
Parents:
1db44ea
Message:

fix a bug in the mfs_write() and mfs_read_map() functions.

  • mfs_read_map(): the inode size must be rounded up to the block size before testing

if "pos" is beyond the end of file.

  • mfs_write(): fix inode size calculation and set BLOCK_FLAGS_NOREAD when a new block is allocated.
Location:
uspace/srv/fs/mfs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/mfs/mfs_ops.c

    r1db44ea r36cb22f  
    889889        struct mfs_ino_info *ino_i = mnode->ino_i;
    890890        const size_t bs = sbi->block_size;
    891         size_t bytes = min(len, bs - pos % bs);
    892         size_t boundary = ROUND_UP(ino_i->i_size, bs);
     891        size_t bytes = min(len, bs - (pos % bs));
    893892        uint32_t block;
    894893
     
    896895                flags = BLOCK_FLAGS_NOREAD;
    897896
    898         if (pos < boundary) {
    899                 r = mfs_read_map(&block, mnode, pos);
    900                 if (r != EOK)
    901                         goto out_err;
    902 
    903                 if (block == 0) {
    904                         /*Writing in a sparse block*/
    905                         r = mfs_alloc_zone(mnode->instance, &block);
    906                         if (r != EOK)
    907                                 goto out_err;
    908                         flags = BLOCK_FLAGS_NOREAD;
    909                 }
    910         } else {
     897        r = mfs_read_map(&block, mnode, pos);
     898        if (r != EOK)
     899                goto out_err;
     900
     901        if (block == 0) {
     902                /*Writing in a sparse block*/
    911903                uint32_t dummy;
    912904
     
    914906                if (r != EOK)
    915907                        goto out_err;
    916 
     908               
    917909                r = mfs_write_map(mnode, pos, block, &dummy);
    918910                if (r != EOK)
    919911                        goto out_err;
     912
     913                flags = BLOCK_FLAGS_NOREAD;
    920914        }
    921915
     
    925919                goto out_err;
    926920
    927         async_data_write_finalize(callid, b->data + pos % bs, bytes);
     921        if (flags == BLOCK_FLAGS_NOREAD)
     922                memset(b->data, 0, sbi->block_size);
     923
     924        async_data_write_finalize(callid, b->data + (pos % bs), bytes);
    928925        b->dirty = true;
    929926
     
    934931        }
    935932
    936         ino_i->i_size = pos + bytes;
    937         ino_i->dirty = true;
     933        if (pos + bytes > ino_i->i_size) {
     934                ino_i->i_size = pos + bytes;
     935                ino_i->dirty = true;
     936        }
    938937        r = mfs_node_put(fn);
    939         *nsize = pos + bytes;
     938        *nsize = ino_i->i_size;
    940939        *wbytes = bytes;
    941940        return r;
  • uspace/srv/fs/mfs/mfs_rw.c

    r1db44ea r36cb22f  
    3131 */
    3232
     33#include <align.h>
    3334#include "mfs.h"
    3435
     
    7071        int rblock = pos / block_size;
    7172
    72         if (mnode->ino_i->i_size < pos) {
     73        if (ROUND_UP(mnode->ino_i->i_size, sbi->block_size) < pos) {
    7374                /*Trying to read beyond the end of file*/
    7475                r = EOK;
Note: See TracChangeset for help on using the changeset viewer.