Changeset 1ac1ab4 in mainline for uspace/lib/ext4/libext4_extent.c


Ignore:
Timestamp:
2012-03-31T20:00:15Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a2fa350
Parents:
38384ae
Message:

simplied headers of more functions, improved bg_ref and inode_ref structures, added block group checksumming and fixed bug in block_group values updating

File:
1 edited

Legend:

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

    r38384ae r1ac1ab4  
    218218}
    219219
    220 // Reading routine without saving blocks to path
    221 //static int ext4_extent_find_extent(ext4_filesystem_t *fs,
    222 //              ext4_inode_ref_t *inode_ref, uint32_t iblock, ext4_extent_t *extent)
    223 //{
    224 //      int rc;
    225 //
    226 //      block_t* block = NULL;
    227 //
    228 //      ext4_extent_header_t *header = ext4_inode_get_extent_header(inode_ref->inode);
    229 //      while (ext4_extent_header_get_depth(header) != 0) {
    230 //
    231 //              ext4_extent_index_t *index;
    232 //              ext4_extent_binsearch_idx(header, &index, iblock);
    233 //
    234 //              uint64_t child = ext4_extent_index_get_leaf(index);
    235 //
    236 //              if (block != NULL) {
    237 //                      block_put(block);
    238 //              }
    239 //
    240 //              rc = block_get(&block, fs->device, child, BLOCK_FLAGS_NONE);
    241 //              if (rc != EOK) {
    242 //                      return rc;
    243 //              }
    244 //
    245 //              header = (ext4_extent_header_t *)block->data;
    246 //      }
    247 //
    248 //
    249 //      ext4_extent_t* tmp_extent;
    250 //      ext4_extent_binsearch(header, &tmp_extent, iblock);
    251 //
    252 //      memcpy(extent, tmp_extent, sizeof(ext4_extent_t));
    253 //
    254 //      return EOK;
    255 //}
    256 
    257 static int ext4_extent_find_extent(ext4_filesystem_t *fs,
    258                 ext4_inode_ref_t *inode_ref, uint32_t iblock, ext4_extent_path_t **ret_path)
     220// Reading routine without saving blocks to path - for saving memory during finding block
     221int ext4_extent_find_block(ext4_inode_ref_t *inode_ref, uint32_t iblock, uint32_t *fblock)
    259222{
    260223        int rc;
    261224
    262         ext4_extent_header_t *eh =
    263                         ext4_inode_get_extent_header(inode_ref->inode);
    264 
    265         uint16_t depth = ext4_extent_header_get_depth(eh);
    266 
    267         ext4_extent_path_t *tmp_path;
    268 
    269         // Added 2 for possible tree growing
    270         tmp_path = malloc(sizeof(ext4_extent_path_t) * (depth + 2));
    271         if (tmp_path == NULL) {
    272                 return ENOMEM;
    273         }
    274 
    275         tmp_path[0].block = inode_ref->block;
    276         tmp_path[0].header = eh;
    277 
    278         uint16_t pos = 0;
    279         while (ext4_extent_header_get_depth(eh) != 0) {
    280 
    281                 ext4_extent_binsearch_idx(tmp_path[pos].header, &tmp_path[pos].index, iblock);
    282 
    283                 tmp_path[pos].depth = depth;
    284                 tmp_path[pos].extent = NULL;
    285 
    286                 assert(tmp_path[pos].index != NULL);
    287 
    288                 uint64_t fblock = ext4_extent_index_get_leaf(tmp_path[pos].index);
    289 
    290                 block_t *block;
    291                 rc = block_get(&block, fs->device, fblock, BLOCK_FLAGS_NONE);
     225        block_t* block = NULL;
     226
     227        ext4_extent_header_t *header = ext4_inode_get_extent_header(inode_ref->inode);
     228        while (ext4_extent_header_get_depth(header) != 0) {
     229
     230                ext4_extent_index_t *index;
     231                ext4_extent_binsearch_idx(header, &index, iblock);
     232
     233                uint64_t child = ext4_extent_index_get_leaf(index);
     234
     235                if (block != NULL) {
     236                        block_put(block);
     237                }
     238
     239                rc = block_get(&block, inode_ref->fs->device, child, BLOCK_FLAGS_NONE);
    292240                if (rc != EOK) {
    293                         // TODO cleanup
    294                         EXT4FS_DBG("ERRRR");
    295241                        return rc;
    296242                }
    297243
    298                 pos++;
    299 
    300                 eh = (ext4_extent_header_t *)block->data;
    301                 tmp_path[pos].block = block;
    302                 tmp_path[pos].header = eh;
    303 
    304         }
    305 
    306         tmp_path[pos].depth = 0;
    307         tmp_path[pos].extent = NULL;
    308         tmp_path[pos].index = NULL;
    309 
    310     /* find extent */
    311         ext4_extent_binsearch(tmp_path[pos].header, &tmp_path[pos].extent, iblock);
    312 
    313         *ret_path = tmp_path;
    314 
    315         return EOK;
    316 }
    317 
    318 
    319 int ext4_extent_find_block(ext4_filesystem_t *fs,
    320                 ext4_inode_ref_t *inode_ref, uint32_t iblock, uint32_t *fblock)
    321 {
    322         int rc;
    323 
    324         ext4_extent_path_t *path;
    325         rc = ext4_extent_find_extent(fs, inode_ref, iblock, &path);
    326         if (rc != EOK) {
    327                 return rc;
    328         }
    329 
    330         uint16_t depth = path->depth;
    331 
    332         ext4_extent_t *extent = path[depth].extent;
     244                header = (ext4_extent_header_t *)block->data;
     245        }
     246
     247
     248        ext4_extent_t* extent;
     249        ext4_extent_binsearch(header, &extent, iblock);
     250
    333251
    334252        uint32_t phys_block;
     
    338256        *fblock = phys_block;
    339257
    340         // Put loaded blocks
    341         // From 1 -> 0 is a block with inode data
    342         for (uint16_t i = 1; i < depth; ++i) {
    343                 if (path[i].block) {
    344                         block_put(path[i].block);
    345                 }
    346         }
    347 
    348         // Destroy temporary data structure
    349         free(path);
     258        if (block != NULL) {
     259                block_put(block);
     260        }
     261
    350262
    351263        return EOK;
    352 
    353 }
     264}
     265
     266//static int ext4_extent_find_extent(ext4_filesystem_t *fs,
     267//              ext4_inode_ref_t *inode_ref, uint32_t iblock, ext4_extent_path_t **ret_path)
     268//{
     269//      int rc;
     270//
     271//      ext4_extent_header_t *eh =
     272//                      ext4_inode_get_extent_header(inode_ref->inode);
     273//
     274//      uint16_t depth = ext4_extent_header_get_depth(eh);
     275//
     276//      ext4_extent_path_t *tmp_path;
     277//
     278//      // Added 2 for possible tree growing
     279//      tmp_path = malloc(sizeof(ext4_extent_path_t) * (depth + 2));
     280//      if (tmp_path == NULL) {
     281//              return ENOMEM;
     282//      }
     283//
     284//      tmp_path[0].block = inode_ref->block;
     285//      tmp_path[0].header = eh;
     286//
     287//      uint16_t pos = 0;
     288//      while (ext4_extent_header_get_depth(eh) != 0) {
     289//
     290//              ext4_extent_binsearch_idx(tmp_path[pos].header, &tmp_path[pos].index, iblock);
     291//
     292//              tmp_path[pos].depth = depth;
     293//              tmp_path[pos].extent = NULL;
     294//
     295//              assert(tmp_path[pos].index != NULL);
     296//
     297//              uint64_t fblock = ext4_extent_index_get_leaf(tmp_path[pos].index);
     298//
     299//              block_t *block;
     300//              rc = block_get(&block, fs->device, fblock, BLOCK_FLAGS_NONE);
     301//              if (rc != EOK) {
     302//                      // TODO cleanup
     303//                      EXT4FS_DBG("ERRRR");
     304//                      return rc;
     305//              }
     306//
     307//              pos++;
     308//
     309//              eh = (ext4_extent_header_t *)block->data;
     310//              tmp_path[pos].block = block;
     311//              tmp_path[pos].header = eh;
     312//
     313//      }
     314//
     315//      tmp_path[pos].depth = 0;
     316//      tmp_path[pos].extent = NULL;
     317//      tmp_path[pos].index = NULL;
     318//
     319//    /* find extent */
     320//      ext4_extent_binsearch(tmp_path[pos].header, &tmp_path[pos].extent, iblock);
     321//
     322//      *ret_path = tmp_path;
     323//
     324//      return EOK;
     325//}
     326
     327
     328//int ext4_extent_find_block(ext4_filesystem_t *fs,
     329//              ext4_inode_ref_t *inode_ref, uint32_t iblock, uint32_t *fblock)
     330//{
     331//      int rc;
     332//
     333//      ext4_extent_path_t *path;
     334//      rc = ext4_extent_find_extent(fs, inode_ref, iblock, &path);
     335//      if (rc != EOK) {
     336//              return rc;
     337//      }
     338//
     339//      uint16_t depth = path->depth;
     340//
     341//      ext4_extent_t *extent = path[depth].extent;
     342//
     343//      uint32_t phys_block;
     344//      phys_block = ext4_extent_get_start(extent) + iblock;
     345//      phys_block -= ext4_extent_get_first_block(extent);
     346//
     347//      *fblock = phys_block;
     348//
     349//      // Put loaded blocks
     350//      // From 1 -> 0 is a block with inode data
     351//      for (uint16_t i = 1; i < depth; ++i) {
     352//              if (path[i].block) {
     353//                      block_put(path[i].block);
     354//              }
     355//      }
     356//
     357//      // Destroy temporary data structure
     358//      free(path);
     359//
     360//      return EOK;
     361//
     362//}
    354363
    355364/**
Note: See TracChangeset for help on using the changeset viewer.