Changeset 7ea69a6 in mainline


Ignore:
Timestamp:
2011-03-23T10:40:17Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6f50bb0
Parents:
f2d665b4
Message:

Support for sparse files and fixed handling of end of file

Location:
uspace
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext2/libext2_filesystem.c

    rf2d665b4 r7ea69a6  
    297297 * of the given inode is located.
    298298 *
     299 * @param fblock the number of filesystem block, or 0 if no such block is allocated yet
     300 *
    299301 * @return              EOK on success or negative error code on failure
    300302 */
     
    315317        if (iblock < EXT2_INODE_DIRECT_BLOCKS) {
    316318                current_block = ext2_inode_get_direct_block(inode, (uint32_t)iblock);
    317                 if (current_block == 0) {
    318                         return EIO;
    319                 }
    320319                *fblock = current_block;
    321320                return EOK;
     
    365364               
    366365                if (current_block == 0) {
    367                         return EIO;
     366                        *fblock = 0;
     367                        return EOK;
    368368                }
    369369               
  • uspace/srv/fs/ext2fs/ext2fs_ops.c

    rf2d665b4 r7ea69a6  
    5656#include <align.h>
    5757#include <adt/hash_table.h>
     58#include <sys/typefmt.h>
    5859
    5960#define EXT2FS_NODE(node)       ((node) ? (ext2fs_node_t *) (node)->data : NULL)
     
    760761        size_t bytes;
    761762        block_t *block;
     763        uint8_t *buffer;
    762764       
    763765        file_size = ext2_inode_get_size(inst->filesystem->superblock,
     
    777779        bytes = min(block_size - offset_in_block, size);
    778780       
     781        // Handle end of file
     782        if (pos + bytes > file_size) {
     783                bytes = file_size - pos;
     784        }
     785       
    779786        rc = ext2_filesystem_get_inode_data_block_index(inst->filesystem,
    780787                inode_ref->inode, file_block, &fs_block);
     
    785792        }
    786793       
     794        // Check for sparse file
     795        // If ext2_filesystem_get_inode_data_block_index returned
     796        // fs_block == 0, it means that the given block is not allocated for the
     797        // file and we need to return a buffer of zeros
     798        if (fs_block == 0) {
     799                buffer = malloc(bytes);
     800                if (buffer == NULL) {
     801                        async_answer_0(callid, ENOMEM);
     802                        async_answer_0(rid, ENOMEM);
     803                        return;
     804                }
     805               
     806                memset(buffer, 0, bytes);
     807               
     808                async_data_read_finalize(callid, buffer, bytes);
     809                async_answer_1(rid, EOK, bytes);
     810               
     811                free(buffer);
     812               
     813                return;
     814        }
     815       
     816        // Usual case - we need to read a block from device
    787817        rc = block_get(&block, inst->devmap_handle, fs_block, BLOCK_FLAGS_NONE);
    788818        if (rc != EOK) {
     
    792822        }
    793823       
    794         async_data_read_finalize(callid, block->data, bytes);
     824        assert(offset_in_block + bytes <= block_size);
     825        async_data_read_finalize(callid, block->data + offset_in_block, bytes);
    795826       
    796827        rc = block_put(block);
Note: See TracChangeset for help on using the changeset viewer.