Changeset fffb061 in mainline for uspace/lib/ext4/libext4_extent.c


Ignore:
Timestamp:
2012-03-29T11:11:32Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
38384ae
Parents:
47faec1
Message:

find extent procedure with path saving (it's slow), for loading block will be probably used not saving variant

File:
1 edited

Legend:

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

    r47faec1 rfffb061  
    149149}
    150150
     151/**
     152 * Binary search in extent index node
     153 */
    151154static void ext4_extent_binsearch_idx(ext4_extent_header_t *header,
    152155        ext4_extent_index_t **index, uint32_t iblock)
     
    177180}
    178181
     182/**
     183 * Binary search in extent leaf node
     184 */
    179185static void ext4_extent_binsearch(ext4_extent_header_t *header,
    180186                ext4_extent_t **extent, uint32_t iblock)
     
    212218}
    213219
     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
    214257static int ext4_extent_find_extent(ext4_filesystem_t *fs,
    215                 ext4_inode_ref_t *inode_ref, uint32_t iblock, ext4_extent_t **ret_extent)
     258                ext4_inode_ref_t *inode_ref, uint32_t iblock, ext4_extent_path_t **ret_path)
    216259{
    217260        int rc;
    218261
    219         block_t* block = NULL;
    220 
    221         ext4_extent_header_t *header = ext4_inode_get_extent_header(inode_ref->inode);
    222         while (ext4_extent_header_get_depth(header) != 0) {
    223 
    224                 ext4_extent_index_t *index;
    225                 ext4_extent_binsearch_idx(header, &index, iblock);
    226 
    227                 uint64_t child = ext4_extent_index_get_leaf(index);
    228 
    229                 if (block != NULL) {
    230                         block_put(block);
    231                 }
    232 
    233                 rc = block_get(&block, fs->device, child, BLOCK_FLAGS_NONE);
     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);
    234292                if (rc != EOK) {
     293                        // TODO cleanup
     294                        EXT4FS_DBG("ERRRR");
    235295                        return rc;
    236296                }
    237297
    238                 header = (ext4_extent_header_t *)block->data;
    239         }
    240 
    241 
    242         ext4_extent_t *extent = NULL;
    243         ext4_extent_binsearch(header, &extent, iblock);
    244         *ret_extent = extent;
     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;
    245314
    246315        return EOK;
    247316}
     317
    248318
    249319int ext4_extent_find_block(ext4_filesystem_t *fs,
     
    252322        int rc;
    253323
    254         ext4_extent_t *extent = NULL;
    255         rc = ext4_extent_find_extent(fs, inode_ref, iblock, &extent);
     324        ext4_extent_path_t *path;
     325        rc = ext4_extent_find_extent(fs, inode_ref, iblock, &path);
    256326        if (rc != EOK) {
    257327                return rc;
    258328        }
     329
     330        uint16_t depth = path->depth;
     331
     332        ext4_extent_t *extent = path[depth].extent;
    259333
    260334        uint32_t phys_block;
     
    262336        phys_block -= ext4_extent_get_first_block(extent);
    263337
    264 
    265338        *fblock = phys_block;
    266339
     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);
     350
    267351        return EOK;
    268352
    269 
    270 //      ext4_extent_header_t *eh =
    271 //                      ext4_inode_get_extent_header(inode_ref->inode);
    272 //
    273 //      uint16_t depth = ext4_extent_header_get_depth(eh);
    274 //
    275 //      ext4_extent_path_t *tmp_path;
    276 //
    277 //      // Added 2 for possible tree growing
    278 //      tmp_path = malloc(sizeof(ext4_extent_path_t) * (depth + 2));
    279 //      if (tmp_path == NULL) {
    280 //              *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 //              EXT4FS_DBG("count == \%u", ext4_extent_header_get_entries_count(eh));
    291 //
    292 //              ext4_extent_binsearch_idx(tmp_path + pos, iblock);
    293 //
    294 //              uint32_t offset = (void *)tmp_path[pos].index - (void *)EXT4_EXTENT_FIRST_INDEX(eh);
    295 //
    296 //              EXT4FS_DBG("offset = \%u", offset);
    297 //
    298 //              EXT4FS_DBG("first block = \%u, leaf = \%u",
    299 //                              ext4_extent_index_get_first_block(tmp_path[pos].index),
    300 //                              (uint32_t)ext4_extent_index_get_leaf(tmp_path[pos].index));
    301 //
    302 //              tmp_path[pos].depth = depth;
    303 //              tmp_path[pos].extent = NULL;
    304 //
    305 //              assert(tmp_path[pos].index != NULL);
    306 //
    307 //              uint64_t fblock = ext4_extent_index_get_leaf(tmp_path[pos].index);
    308 //
    309 //              EXT4FS_DBG("fblock = \%u", (uint32_t)fblock);
    310 //
    311 //              block_t *block;
    312 //              rc = block_get(&block, fs->device, fblock, BLOCK_FLAGS_NONE);
    313 //              if (rc != EOK) {
    314 //                      // TODO cleanup
    315 //                      EXT4FS_DBG("ERRRR");
    316 //                      return rc;
    317 //              }
    318 //
    319 //              EXT4FS_DBG("block loaded");
    320 //
    321 //              pos++;
    322 //
    323 //              eh = (ext4_extent_header_t *)block->data;
    324 //              tmp_path[pos].block = block;
    325 //              tmp_path[pos].header = eh;
    326 //
    327 //      }
    328 //
    329 //      tmp_path[pos].depth = 0;
    330 //      tmp_path[pos].extent = NULL;
    331 //      tmp_path[pos].index = NULL;
    332 //
    333 //      EXT4FS_DBG("pos = \%u", pos);
    334 //
    335 //    /* find extent */
    336 //      ext4_extent_binsearch(tmp_path + pos, iblock);
    337 //
    338 //      EXT4FS_DBG("after binsearch in extent");
    339 //
    340 //      /* if not an empty leaf */
    341 //      if (tmp_path[pos].extent) {
    342 //              EXT4FS_DBG("nonempty leaf");
    343 //
    344 ////            uint64_t fblock = ext4_extent_get_start(tmp_path[pos].extent);
    345 ////            block_t *block;
    346 ////            rc = block_get(&block, fs->device, fblock, BLOCK_FLAGS_NONE);
    347 ////            if (rc != EOK) {
    348 ////                    // TODO cleanup
    349 ////            }
    350 ////            tmp_path[pos].block = block;
    351 //      }
    352 //
    353 //      *path = tmp_path;
    354 //
    355 //      return EOK;
    356353}
    357354
Note: See TracChangeset for help on using the changeset viewer.