Changeset 35f48f2 in mainline


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, topic/simplify-dev-export
Children:
1e65444
Parents:
0f09d4ea
Message:

succesful writing (only for direct block)

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/libext4_bitmap.c

    r0f09d4ea r35f48f2  
    167167        rc = ext4_bitmap_find_free_bit_and_set(block->data, &rel_block_idx, block_size);
    168168
    169         // if ENOSPC - try next block group - try next block groups
    170169
     170        if (rc != EOK) {
     171                EXT4FS_DBG("no block found");
     172                // TODO if ENOSPC - try next block group - try next block groups
     173        }
    171174
     175        // TODO decrement superblock free blocks count
     176        //uint32_t sb_free_blocks = ext4_superblock_get_free_blocks_count(sb);
     177        //sb_free_blocks--;
     178        //ext4_superblock_set_free_blocks_count(sb, sb_free_blocks);
    172179
    173 
    174         // TODO decrement superblock & block group free blocks count
     180        uint32_t bg_free_blocks = ext4_block_group_get_free_blocks_count(bg_ref->block_group);
     181        bg_free_blocks++;
     182        ext4_block_group_set_free_blocks_count(bg_ref->block_group, bg_free_blocks);
     183        bg_ref->dirty = true;
    175184
    176185        // return
  • uspace/lib/ext4/libext4_filesystem.c

    r0f09d4ea r35f48f2  
    363363
    364364
     365int ext4_filesystem_set_inode_data_block_index(ext4_filesystem_t *fs,
     366                ext4_inode_t *inode, aoff64_t iblock, uint32_t fblock)
     367{
     368
     369//      int rc;
     370//      uint32_t offset_in_block;
     371//      uint32_t current_block;
     372//      aoff64_t block_offset_in_level;
     373//      int i;
     374//      int level;
     375//      block_t *block;
     376
     377        /* Handle inode using extents */
     378        if (ext4_superblock_has_feature_compatible(fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) &&
     379                        ext4_inode_has_flag(inode, EXT4_INODE_FLAG_EXTENTS)) {
     380                // TODO
     381                return ENOTSUP;
     382
     383        }
     384
     385        /* Handle simple case when we are dealing with direct reference */
     386        if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
     387                ext4_inode_set_direct_block(inode, (uint32_t)iblock, fblock);
     388                return EOK;
     389        }
     390
     391//      /* Determine the indirection level needed to get the desired block */
     392//      level = -1;
     393//      for (i = 1; i < 4; i++) {
     394//              if (iblock < fs->inode_block_limits[i]) {
     395//                      level = i;
     396//                      break;
     397//              }
     398//      }
     399//
     400//      if (level == -1) {
     401//              return EIO;
     402//      }
     403//
     404//      /* Compute offsets for the topmost level */
     405//      block_offset_in_level = iblock - fs->inode_block_limits[level-1];
     406//      current_block = ext4_inode_get_indirect_block(inode, level-1);
     407//      offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
     408//
     409//      /* Navigate through other levels, until we find the block number
     410//       * or find null reference meaning we are dealing with sparse file
     411//       */
     412//      while (level > 0) {
     413//              rc = block_get(&block, fs->device, current_block, 0);
     414//              if (rc != EOK) {
     415//                      return rc;
     416//              }
     417//
     418//              current_block = uint32_t_le2host(((uint32_t*)block->data)[offset_in_block]);
     419//
     420//              rc = block_put(block);
     421//              if (rc != EOK) {
     422//                      return rc;
     423//              }
     424//
     425//              if (current_block == 0) {
     426//                      /* This is a sparse file */
     427//                      *fblock = 0;
     428//                      return EOK;
     429//              }
     430//
     431//              level -= 1;
     432//
     433//              /* If we are on the last level, break here as
     434//               * there is no next level to visit
     435//               */
     436//              if (level == 0) {
     437//                      break;
     438//              }
     439//
     440//              /* Visit the next level */
     441//              block_offset_in_level %= fs->inode_blocks_per_level[level];
     442//              offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
     443//      }
     444//
     445//      *fblock = current_block;
     446//
     447//      return EOK;
     448//
     449//
     450
     451        return EOK;
     452}
     453
    365454int ext4_filesystem_release_inode_block(ext4_filesystem_t *fs,
    366455                ext4_inode_ref_t *inode_ref, uint32_t iblock)
  • uspace/lib/ext4/libext4_filesystem.h

    r0f09d4ea r35f48f2  
    6262extern int ext4_filesystem_get_inode_data_block_index(ext4_filesystem_t *,
    6363        ext4_inode_t *, aoff64_t iblock, uint32_t *);
     64extern int ext4_filesystem_set_inode_data_block_index(ext4_filesystem_t *,
     65                ext4_inode_t *, aoff64_t, uint32_t);
    6466extern int ext4_filesystem_release_inode_block(ext4_filesystem_t *,
    6567                ext4_inode_ref_t *, uint32_t);
  • 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.