Changeset 529edc66 in mainline


Ignore:
Timestamp:
2011-03-09T13:12:49Z (14 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
242b4bb
Parents:
df38657
Message:

Add support for reading files to ext2fs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/ext2fs/ext2fs_ops.c

    rdf38657 r529edc66  
    7474static void ext2fs_read_directory(ipc_callid_t, ipc_callid_t, aoff64_t,
    7575        size_t, ext2fs_instance_t *, ext2_inode_ref_t *);
     76static void ext2fs_read_file(ipc_callid_t, ipc_callid_t, aoff64_t,
     77        size_t, ext2fs_instance_t *, ext2_inode_ref_t *);
    7678
    7779/*
     
    596598        if (ext2_inode_is_type(inst->filesystem->superblock, inode_ref->inode,
    597599                    EXT2_INODE_MODE_FILE)) {
    598                 async_answer_0(callid, ENOTSUP);
    599                 async_answer_0(rid, ENOTSUP);
     600                ext2fs_read_file(rid, callid, pos, size, inst, inode_ref);
    600601        }
    601602        else if (ext2_inode_is_type(inst->filesystem->superblock, inode_ref->inode,
     
    700701}
    701702
     703void ext2fs_read_file(ipc_callid_t rid, ipc_callid_t callid, aoff64_t pos,
     704        size_t size, ext2fs_instance_t *inst, ext2_inode_ref_t *inode_ref)
     705{
     706        int rc;
     707        uint32_t block_size;
     708        aoff64_t file_block;
     709        uint64_t file_size;
     710        uint32_t fs_block;
     711        size_t offset_in_block;
     712        size_t bytes;
     713        block_t *block;
     714       
     715        file_size = ext2_inode_get_size(inst->filesystem->superblock,
     716                inode_ref->inode);
     717       
     718        if (pos >= file_size) {
     719                // TODO: is this OK? return EIO?
     720                async_data_read_finalize(callid, NULL, 0);
     721                async_answer_1(rid, EOK, 0);
     722                return;
     723        }
     724       
     725        // For now, we only read data from one block at a time
     726        block_size = ext2_superblock_get_block_size(inst->filesystem->superblock);
     727        file_block = pos / block_size;
     728        offset_in_block = pos % block_size;
     729        bytes = min(block_size - offset_in_block, size);
     730       
     731        rc = ext2_filesystem_get_inode_data_block_index(inst->filesystem,
     732                inode_ref->inode, file_block, &fs_block);
     733        if (rc != EOK) {
     734                async_answer_0(callid, rc);
     735                async_answer_0(rid, rc);
     736                return;
     737        }
     738       
     739        rc = block_get(&block, inst->devmap_handle, fs_block, BLOCK_FLAGS_NONE);
     740        if (rc != EOK) {
     741                async_answer_0(callid, rc);
     742                async_answer_0(rid, rc);
     743                return;
     744        }
     745       
     746        async_data_read_finalize(callid, block->data, bytes);
     747       
     748        rc = block_put(block);
     749        if (rc != EOK) {
     750                async_answer_0(rid, rc);
     751                return;
     752        }
     753               
     754        async_answer_1(rid, EOK, bytes);
     755}
     756
    702757void ext2fs_write(ipc_callid_t rid, ipc_call_t *request)
    703758{
Note: See TracChangeset for help on using the changeset viewer.