Changeset fffb061 in mainline
- Timestamp:
- 2012-03-29T11:11:32Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 38384ae
- Parents:
- 47faec1
- Location:
- uspace/lib/ext4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_extent.c
r47faec1 rfffb061 149 149 } 150 150 151 /** 152 * Binary search in extent index node 153 */ 151 154 static void ext4_extent_binsearch_idx(ext4_extent_header_t *header, 152 155 ext4_extent_index_t **index, uint32_t iblock) … … 177 180 } 178 181 182 /** 183 * Binary search in extent leaf node 184 */ 179 185 static void ext4_extent_binsearch(ext4_extent_header_t *header, 180 186 ext4_extent_t **extent, uint32_t iblock) … … 212 218 } 213 219 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 214 257 static 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) 216 259 { 217 260 int rc; 218 261 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); 234 292 if (rc != EOK) { 293 // TODO cleanup 294 EXT4FS_DBG("ERRRR"); 235 295 return rc; 236 296 } 237 297 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; 245 314 246 315 return EOK; 247 316 } 317 248 318 249 319 int ext4_extent_find_block(ext4_filesystem_t *fs, … … 252 322 int rc; 253 323 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); 256 326 if (rc != EOK) { 257 327 return rc; 258 328 } 329 330 uint16_t depth = path->depth; 331 332 ext4_extent_t *extent = path[depth].extent; 259 333 260 334 uint32_t phys_block; … … 262 336 phys_block -= ext4_extent_get_first_block(extent); 263 337 264 265 338 *fblock = phys_block; 266 339 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 267 351 return EOK; 268 352 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 growing278 // 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 cleanup315 // 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 cleanup349 //// }350 //// tmp_path[pos].block = block;351 // }352 //353 // *path = tmp_path;354 //355 // return EOK;356 353 } 357 354 -
uspace/lib/ext4/libext4_filesystem.c
r47faec1 rfffb061 47 47 fs->device = service_id; 48 48 49 // TODO what does constant 2048 mean? 50 rc = block_init(EXCHANGE_SERIALIZE, fs->device, 2048); 49 rc = block_init(EXCHANGE_SERIALIZE, fs->device, 4096); 51 50 if (rc != EOK) { 52 51 return rc; … … 733 732 int rc; 734 733 735 736 /* TODO handle extents */737 738 739 734 uint32_t fblock; 735 736 /* TODO Handle extents */ 737 // if (ext4_superblock_has_feature_incompatible(fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) && 738 // ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) { 739 //// rc = ext4_extent_find_block(fs, inode_ref, iblock, ¤t_block); 740 //// 741 //// if (rc != EOK) { 742 //// return rc; 743 //// } 744 //// 745 //// *fblock = current_block; 746 // 747 // // TODO release block from extents (and return fblock) 748 // 749 // fblock = 0; 750 // 751 // if (fblock == 0) { 752 // return EOK; 753 // } 754 // 755 // return ext4_balloc_free_block(fs, inode_ref, fblock); 756 // 757 // return EOK; 758 // 759 // } 760 761 762 740 763 ext4_inode_t *inode = inode_ref->inode; 741 764
Note:
See TracChangeset
for help on using the changeset viewer.