Changeset 35f48f2 in mainline for uspace/srv/fs/ext4fs/ext4fs_ops.c


Ignore:
Timestamp:
2011-11-09T08:48:06Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade
Children:
1e65444
Parents:
0f09d4ea
Message:

succesful writing (only for direct block)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/ext4fs/ext4fs_ops.c

    r0f09d4ea r35f48f2  
    929929
    930930        int rc;
     931        int flags = BLOCK_FLAGS_NONE;
    931932        fs_node_t *fn;
    932933        ext4fs_node_t *enode;
     
    937938        block_t *write_block;
    938939        uint32_t fblock, iblock;
     940        uint32_t old_inode_size;
    939941
    940942        rc = ext4fs_node_get(&fn, service_id, index);
     
    960962        bytes = min(len, block_size - (pos % block_size));
    961963
     964        if (bytes == block_size) {
     965                flags = BLOCK_FLAGS_NOREAD;
     966        }
     967
    962968        EXT4FS_DBG("bytes == \%u", bytes);
    963969
     
    966972        rc = ext4_filesystem_get_inode_data_block_index(fs, inode_ref->inode, iblock, &fblock);
    967973
    968 
    969         // TODO allocation if fblock == 0
    970974        if (fblock == 0) {
    971975                EXT4FS_DBG("Allocate block !!!");
    972 
    973                 return ENOTSUP;
    974         }
    975 
    976         // TODO flags
    977         rc = block_get(&write_block, service_id, fblock, 0);
     976                rc =  ext4_bitmap_alloc_block(fs, inode_ref, &fblock);
     977                if (rc != EOK) {
     978                        ext4fs_node_put(fn);
     979                        async_answer_0(callid, rc);
     980                        return rc;
     981                }
     982
     983                ext4_filesystem_set_inode_data_block_index(fs, inode_ref->inode, iblock, fblock);
     984                inode_ref->dirty = true;
     985
     986                flags = BLOCK_FLAGS_NOREAD;
     987
     988                EXT4FS_DBG("block \%u allocated", fblock);
     989        }
     990
     991        rc = block_get(&write_block, service_id, fblock, flags);
    978992        if (rc != EOK) {
    979993                ext4fs_node_put(fn);
     
    982996        }
    983997
    984         /*
    985         if (flags == BLOCK_FLAGS_NOREAD)
    986                 memset(b->data, 0, sbi->block_size);
    987         */
    988 
    989         async_data_write_finalize(callid, write_block->data + (pos % block_size), bytes);
     998        EXT4FS_DBG("block loaded");
     999
     1000        if (flags == BLOCK_FLAGS_NOREAD) {
     1001                EXT4FS_DBG("fill block with zeros");
     1002                memset(write_block->data, 0, block_size);
     1003        }
     1004
     1005        rc = async_data_write_finalize(callid, write_block->data + (pos % block_size), bytes);
     1006        if (rc != EOK) {
     1007                EXT4FS_DBG("error in write finalize \%d", rc);
     1008        }
     1009
     1010        char *data = write_block->data + (pos % block_size);
     1011        for (uint32_t x = 0; x < bytes; ++x) {
     1012                printf("%c", data[x]);
     1013        }
     1014        printf("\n");
     1015
    9901016        write_block->dirty = true;
    9911017
     
    9961022        }
    9971023
    998         /*
    999         if (pos + bytes > ino_i->i_size) {
    1000                 ino_i->i_size = pos + bytes;
    1001                 ino_i->dirty = true;
    1002         }
    1003         *nsize = ino_i->i_size;
     1024        EXT4FS_DBG("writing finished");
     1025
     1026        old_inode_size = ext4_inode_get_size(fs->superblock, inode_ref->inode);
     1027        if (pos + bytes > old_inode_size) {
     1028                ext4_inode_set_size(inode_ref->inode, pos + bytes);
     1029                inode_ref->dirty = true;
     1030        }
     1031
     1032        *nsize = ext4_inode_get_size(fs->superblock, inode_ref->inode);
    10041033        *wbytes = bytes;
    1005         */
     1034
    10061035        return ext4fs_node_put(fn);
    10071036}
     
    11051134static int ext4fs_sync(service_id_t service_id, fs_index_t index)
    11061135{
    1107         EXT4FS_DBG("not supported");
    1108 
    1109         // TODO
    1110         return ENOTSUP;
     1136        EXT4FS_DBG("");
     1137
     1138        int rc;
     1139        fs_node_t *fn;
     1140        ext4fs_node_t *enode;
     1141
     1142        rc = ext4fs_node_get(&fn, service_id, index);
     1143        if (rc != EOK) {
     1144                return rc;
     1145        }
     1146
     1147        enode = EXT4FS_NODE(fn);
     1148        enode->inode_ref->dirty = true;
     1149
     1150        return ext4fs_node_put(fn);
    11111151}
    11121152
Note: See TracChangeset for help on using the changeset viewer.