2 * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
6 * Copyright (c) 2012 Martin Sucha
7 * Copyright (c) 2012 Frantisek Princ
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * - Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * - The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 /** @addtogroup lwext4
39 * @brief More complex filesystem functions.
42 #include "ext4_config.h"
43 #include "ext4_extent.h"
44 #include "ext4_inode.h"
45 #include "ext4_super.h"
46 #include "ext4_blockdev.h"
47 #include "ext4_balloc.h"
53 #if !CONFIG_EXTENT_FULL
55 /**@brief Binary search in extent index node.
56 * @param header Extent header of index node
57 * @param index Output value - found index will be set here
58 * @param iblock Logical block number to find in index node */
59 static void ext4_extent_binsearch_idx(struct ext4_extent_header *header,
60 struct ext4_extent_index **index,
63 struct ext4_extent_index *r;
64 struct ext4_extent_index *l;
65 struct ext4_extent_index *m;
67 uint16_t entries_count = ext4_extent_header_get_entries_count(header);
69 /* Initialize bounds */
70 l = EXT4_EXTENT_FIRST_INDEX(header) + 1;
71 r = EXT4_EXTENT_FIRST_INDEX(header) + entries_count - 1;
73 /* Do binary search */
76 uint32_t first_block = ext4_extent_index_get_first_block(m);
78 if (iblock < first_block)
84 /* Set output value */
88 /**@brief Binary search in extent leaf node.
89 * @param header Extent header of leaf node
90 * @param extent Output value - found extent will be set here,
91 * or NULL if node is empty
92 * @param iblock Logical block number to find in leaf node */
93 static void ext4_extent_binsearch(struct ext4_extent_header *header,
94 struct ext4_extent **extent, uint32_t iblock)
96 struct ext4_extent *r;
97 struct ext4_extent *l;
98 struct ext4_extent *m;
100 uint16_t entries_count = ext4_extent_header_get_entries_count(header);
102 if (entries_count == 0) {
103 /* this leaf is empty */
108 /* Initialize bounds */
109 l = EXT4_EXTENT_FIRST(header) + 1;
110 r = EXT4_EXTENT_FIRST(header) + entries_count - 1;
112 /* Do binary search */
115 uint32_t first_block = ext4_extent_get_first_block(m);
117 if (iblock < first_block)
123 /* Set output value */
127 /**@brief Get physical block in the extent tree by logical block number.
128 * There is no need to save path in the tree during this algorithm.
129 * @param inode_ref I-node to load block from
130 * @param iblock Logical block number to find
131 * @param fblock Output value for physical block number
132 * @return Error code*/
134 ext4_extent_find_block(struct ext4_inode_ref *inode_ref, uint32_t iblock,
135 ext4_fsblk_t *fblock)
138 /* Compute bound defined by i-node size */
139 uint64_t inode_size =
140 ext4_inode_get_size(&inode_ref->fs->sb, inode_ref->inode);
142 uint32_t block_size = ext4_sb_get_block_size(&inode_ref->fs->sb);
144 uint32_t last_idx = (inode_size - 1) / block_size;
146 /* Check if requested iblock is not over size of i-node */
147 if (iblock > last_idx) {
152 struct ext4_block block;
155 /* Walk through extent tree */
156 struct ext4_extent_header *header =
157 ext4_inode_get_extent_header(inode_ref->inode);
159 while (ext4_extent_header_get_depth(header) != 0) {
160 /* Search index in node */
161 struct ext4_extent_index *index;
162 ext4_extent_binsearch_idx(header, &index, iblock);
164 /* Load child node and set values for the next iteration */
165 uint64_t child = ext4_extent_index_get_leaf(index);
168 rc = ext4_block_set(inode_ref->fs->bdev, &block);
173 int rc = ext4_block_get(inode_ref->fs->bdev, &block, child);
177 header = (struct ext4_extent_header *)block.data;
180 /* Search extent in the leaf block */
181 struct ext4_extent *extent = NULL;
182 ext4_extent_binsearch(header, &extent, iblock);
184 /* Prevent empty leaf */
185 if (extent == NULL) {
188 /* Compute requested physical block address */
189 ext4_fsblk_t phys_block;
190 uint32_t first = ext4_extent_get_first_block(extent);
191 phys_block = ext4_extent_get_start(extent) + iblock - first;
193 *fblock = phys_block;
198 rc = ext4_block_set(inode_ref->fs->bdev, &block);
206 /**@brief Find extent for specified iblock.
207 * This function is used for finding block in the extent tree with
208 * saving the path through the tree for possible future modifications.
209 * @param inode_ref I-node to read extent tree from
210 * @param iblock Iblock to find extent for
211 * @param ret_path Output value for loaded path from extent tree
212 * @return Error code */
213 static int ext4_extent_find_extent(struct ext4_inode_ref *inode_ref,
215 struct ext4_extent_path **ret_path)
217 struct ext4_extent_header *eh =
218 ext4_inode_get_extent_header(inode_ref->inode);
220 uint16_t depth = ext4_extent_header_get_depth(eh);
222 struct ext4_extent_path *tmp_path;
224 /* Added 2 for possible tree growing */
225 tmp_path = malloc(sizeof(struct ext4_extent_path) * (depth + 2));
226 if (tmp_path == NULL)
229 /* Initialize structure for algorithm start */
230 tmp_path[0].block = inode_ref->block;
231 tmp_path[0].header = eh;
233 /* Walk through the extent tree */
236 while (ext4_extent_header_get_depth(eh) != 0) {
237 /* Search index in index node by iblock */
238 ext4_extent_binsearch_idx(tmp_path[pos].header,
239 &tmp_path[pos].index, iblock);
241 tmp_path[pos].depth = depth;
242 tmp_path[pos].extent = NULL;
244 ext4_assert(tmp_path[pos].index != 0);
246 /* Load information for the next iteration */
248 ext4_extent_index_get_leaf(tmp_path[pos].index);
250 struct ext4_block block;
251 rc = ext4_block_get(inode_ref->fs->bdev, &block, fblock);
257 eh = (struct ext4_extent_header *)block.data;
258 tmp_path[pos].block = block;
259 tmp_path[pos].header = eh;
262 tmp_path[pos].depth = 0;
263 tmp_path[pos].extent = NULL;
264 tmp_path[pos].index = NULL;
266 /* Find extent in the leaf node */
267 ext4_extent_binsearch(tmp_path[pos].header, &tmp_path[pos].extent,
269 *ret_path = tmp_path;
276 * From 1: 0 is a block with inode data
278 for (i = 1; i < tmp_path->depth; ++i) {
279 if (tmp_path[i].block.lb_id) {
280 int r = ext4_block_set(inode_ref->fs->bdev,
287 /* Destroy temporary data structure */
293 /**@brief Release extent and all data blocks covered by the extent.
294 * @param inode_ref I-node to release extent and block from
295 * @param extent Extent to release
296 * @return Error code */
297 static int ext4_extent_release(struct ext4_inode_ref *inode_ref,
298 struct ext4_extent *extent)
300 /* Compute number of the first physical block to release */
301 uint64_t start = ext4_extent_get_start(extent);
302 uint16_t block_count = ext4_extent_get_block_count(extent);
304 return ext4_balloc_free_blocks(inode_ref, start, block_count);
307 /** Recursively release the whole branch of the extent tree.
308 * For each entry of the node release the subbranch and finally release
309 * the node. In the leaf node all extents will be released.
310 * @param inode_ref I-node where the branch is released
311 * @param index Index in the non-leaf node to be released
312 * with the whole subtree
313 * @return Error code */
314 static int ext4_extent_release_branch(struct ext4_inode_ref *inode_ref,
315 struct ext4_extent_index *index)
317 ext4_fsblk_t fblock = ext4_extent_index_get_leaf(index);
319 struct ext4_block block;
320 int rc = ext4_block_get(inode_ref->fs->bdev, &block, fblock);
324 struct ext4_extent_header *header = (void *)block.data;
326 if (ext4_extent_header_get_depth(header)) {
327 /* The node is non-leaf, do recursion */
328 struct ext4_extent_index *idx = EXT4_EXTENT_FIRST_INDEX(header);
330 /* Release all subbranches */
331 for (i = 0; i < ext4_extent_header_get_entries_count(header);
333 rc = ext4_extent_release_branch(inode_ref, idx);
338 /* Leaf node reached */
339 struct ext4_extent *ext = EXT4_EXTENT_FIRST(header);
341 /* Release all extents and stop recursion */
342 for (i = 0; i < ext4_extent_header_get_entries_count(header);
344 rc = ext4_extent_release(inode_ref, ext);
350 /* Release data block where the node was stored */
352 rc = ext4_block_set(inode_ref->fs->bdev, &block);
356 return ext4_balloc_free_block(inode_ref, fblock);
359 int ext4_extent_remove_space(struct ext4_inode_ref *inode_ref, ext4_lblk_t from,
362 if (to != EXT_MAX_BLOCKS)
365 /* Find the first extent to modify */
366 struct ext4_extent_path *path;
368 int rc = ext4_extent_find_extent(inode_ref, from, &path);
372 /* Jump to last item of the path (extent) */
373 struct ext4_extent_path *path_ptr = path;
374 while (path_ptr->depth != 0)
377 ext4_assert(path_ptr->extent != NULL);
379 /* First extent maybe released partially */
380 uint32_t first_iblock = ext4_extent_get_first_block(path_ptr->extent);
381 ext4_fsblk_t first_fblock = ext4_extent_get_start(path_ptr->extent) +
384 uint16_t block_count = ext4_extent_get_block_count(path_ptr->extent);
386 uint16_t delete_count =
388 (ext4_extent_get_start(path_ptr->extent) - first_fblock);
390 /* Release all blocks */
391 rc = ext4_balloc_free_blocks(inode_ref, first_fblock, delete_count);
395 /* Correct counter */
396 block_count -= delete_count;
397 ext4_extent_set_block_count(path_ptr->extent, block_count,
398 EXT4_EXT_IS_UNWRITTEN(path_ptr->extent));
400 /* Initialize the following loop */
402 ext4_extent_header_get_entries_count(path_ptr->header);
403 struct ext4_extent *tmp_ext = path_ptr->extent + 1;
404 struct ext4_extent *stop_ext =
405 EXT4_EXTENT_FIRST(path_ptr->header) + entries;
407 /* If first extent empty, release it */
408 if (block_count == 0)
411 /* Release all successors of the first extent in the same node */
412 while (tmp_ext < stop_ext) {
413 first_fblock = ext4_extent_get_start(tmp_ext);
414 delete_count = ext4_extent_get_block_count(tmp_ext);
416 rc = ext4_balloc_free_blocks(inode_ref, first_fblock,
425 ext4_extent_header_set_entries_count(path_ptr->header, entries);
426 path_ptr->block.dirty = true;
428 /* If leaf node is empty, parent entry must be modified */
429 bool remove_parent_record = false;
431 /* Don't release root block (including inode data) !!! */
432 if ((path_ptr != path) && (entries == 0)) {
433 rc = ext4_balloc_free_block(inode_ref, path_ptr->block.lb_id);
437 remove_parent_record = true;
440 /* Jump to the parent */
443 /* Release all successors in all tree levels */
444 while (path_ptr >= path) {
446 ext4_extent_header_get_entries_count(path_ptr->header);
447 struct ext4_extent_index *index = path_ptr->index + 1;
448 struct ext4_extent_index *stop =
449 EXT4_EXTENT_FIRST_INDEX(path_ptr->header) + entries;
451 /* Correct entries count because of changes in the previous
453 if (remove_parent_record)
456 /* Iterate over all entries and release the whole subtrees */
457 while (index < stop) {
458 rc = ext4_extent_release_branch(inode_ref, index);
466 ext4_extent_header_set_entries_count(path_ptr->header, entries);
467 path_ptr->block.dirty = true;
469 /* Free the node if it is empty */
470 if ((entries == 0) && (path_ptr != path)) {
471 rc = ext4_balloc_free_block(inode_ref,
472 path_ptr->block.lb_id);
476 /* Mark parent to be checked */
477 remove_parent_record = true;
479 remove_parent_record = false;
485 ext4_extent_header_set_depth(path->header, 0);
490 * starting from 1: 0 is a block with inode data
492 for (i = 1; i <= path->depth; ++i) {
493 if (path[i].block.lb_id) {
495 ext4_block_set(inode_ref->fs->bdev, &path[i].block);
501 /* Destroy temporary data structure */
507 /**@brief Append new extent to the i-node and do some splitting if necessary.
508 * @param inode_ref I-node to append extent to
509 * @param path Path in the extent tree for possible splitting
510 * @param last_path_item Input/output parameter for pointer to the last
511 * valid item in the extent tree path
512 * @param iblock Logical index of block to append extent for
513 * @return Error code */
514 static int ext4_extent_append_extent(struct ext4_inode_ref *inode_ref,
515 struct ext4_extent_path *path,
518 struct ext4_extent_path *path_ptr = path + path->depth;
520 uint32_t block_size = ext4_sb_get_block_size(&inode_ref->fs->sb);
522 /* Start splitting */
523 while (path_ptr > path) {
525 ext4_extent_header_get_entries_count(path_ptr->header);
527 ext4_extent_header_get_max_entries_count(path_ptr->header);
529 if (entries == limit) {
530 /* Full node - allocate block for new one */
531 ext4_fsblk_t goal, fblock;
532 int rc = ext4_fs_indirect_find_goal(inode_ref, &goal);
536 rc = ext4_balloc_alloc_block(inode_ref, goal, &fblock);
540 struct ext4_block block;
542 ext4_block_get(inode_ref->fs->bdev, &block, fblock);
544 ext4_balloc_free_block(inode_ref, fblock);
548 /* Put back not modified old block */
549 rc = ext4_block_set(inode_ref->fs->bdev,
552 ext4_balloc_free_block(inode_ref, fblock);
556 /* Initialize newly allocated block and remember it */
557 memset(block.data, 0, block_size);
558 path_ptr->block = block;
560 /* Update pointers in extent path structure */
561 path_ptr->header = (void *)block.data;
562 if (path_ptr->depth) {
564 EXT4_EXTENT_FIRST_INDEX(path_ptr->header);
565 ext4_extent_index_set_first_block(
566 path_ptr->index, iblock);
567 ext4_extent_index_set_leaf(
569 (path_ptr + 1)->block.lb_id);
570 limit = (block_size -
571 sizeof(struct ext4_extent_header)) /
572 sizeof(struct ext4_extent_index);
575 EXT4_EXTENT_FIRST(path_ptr->header);
576 ext4_extent_set_first_block(path_ptr->extent,
578 limit = (block_size -
579 sizeof(struct ext4_extent_header)) /
580 sizeof(struct ext4_extent);
583 /* Initialize on-disk structure (header) */
584 ext4_extent_header_set_entries_count(path_ptr->header,
586 ext4_extent_header_set_max_entries_count(
587 path_ptr->header, limit);
588 ext4_extent_header_set_magic(path_ptr->header,
590 ext4_extent_header_set_depth(path_ptr->header,
592 ext4_extent_header_set_generation(path_ptr->header, 0);
594 path_ptr->block.dirty = true;
596 /* Jump to the preceding item */
599 /* Node with free space */
600 if (path_ptr->depth) {
602 EXT4_EXTENT_FIRST_INDEX(path_ptr->header) +
604 ext4_extent_index_set_first_block(
605 path_ptr->index, iblock);
606 ext4_extent_index_set_leaf(
608 (path_ptr + 1)->block.lb_id);
611 EXT4_EXTENT_FIRST(path_ptr->header) +
613 ext4_extent_set_first_block(path_ptr->extent,
617 ext4_extent_header_set_entries_count(path_ptr->header,
619 path_ptr->block.dirty = true;
621 /* No more splitting needed */
626 ext4_assert(path_ptr == path);
628 /* Should be the root split too? */
630 uint16_t entries = ext4_extent_header_get_entries_count(path->header);
631 uint16_t limit = ext4_extent_header_get_max_entries_count(path->header);
633 if (entries == limit) {
634 ext4_fsblk_t goal, new_fblock;
635 int rc = ext4_fs_indirect_find_goal(inode_ref, &goal);
639 rc = ext4_balloc_alloc_block(inode_ref, goal, &new_fblock);
643 struct ext4_block block;
644 rc = ext4_block_get(inode_ref->fs->bdev, &block, new_fblock);
648 /* Initialize newly allocated block */
649 memset(block.data, 0, block_size);
651 /* Move data from root to the new block */
652 memcpy(block.data, inode_ref->inode->blocks,
653 EXT4_INODE_BLOCKS * sizeof(uint32_t));
655 /* Data block is initialized */
657 struct ext4_block *root_block = &path->block;
658 uint16_t root_depth = path->depth;
659 struct ext4_extent_header *root_header = path->header;
661 /* Make space for tree growing */
662 struct ext4_extent_path *new_root = path;
663 struct ext4_extent_path *old_root = path + 1;
666 sizeof(struct ext4_extent_path) * (path->depth + 1);
667 memmove(old_root, new_root, nbytes);
668 memset(new_root, 0, sizeof(struct ext4_extent_path));
670 /* Update old root structure */
671 old_root->block = block;
672 old_root->header = (struct ext4_extent_header *)block.data;
674 /* Add new entry and update limit for entries */
675 if (old_root->depth) {
677 (block_size - sizeof(struct ext4_extent_header)) /
678 sizeof(struct ext4_extent_index);
680 EXT4_EXTENT_FIRST_INDEX(old_root->header) + entries;
681 ext4_extent_index_set_first_block(old_root->index,
683 ext4_extent_index_set_leaf(old_root->index,
684 (old_root + 1)->block.lb_id);
685 old_root->extent = NULL;
688 (block_size - sizeof(struct ext4_extent_header)) /
689 sizeof(struct ext4_extent);
691 EXT4_EXTENT_FIRST(old_root->header) + entries;
692 ext4_extent_set_first_block(old_root->extent, iblock);
693 old_root->index = NULL;
696 ext4_extent_header_set_entries_count(old_root->header,
698 ext4_extent_header_set_max_entries_count(old_root->header,
701 old_root->block.dirty = true;
703 /* Re-initialize new root metadata */
704 new_root->depth = root_depth + 1;
705 new_root->block = *root_block;
706 new_root->header = root_header;
707 new_root->extent = NULL;
708 new_root->index = EXT4_EXTENT_FIRST_INDEX(new_root->header);
710 ext4_extent_header_set_depth(new_root->header, new_root->depth);
712 /* Create new entry in root */
713 ext4_extent_header_set_entries_count(new_root->header, 1);
714 ext4_extent_index_set_first_block(new_root->index, 0);
715 ext4_extent_index_set_leaf(new_root->index, new_fblock);
717 new_root->block.dirty = true;
721 EXT4_EXTENT_FIRST_INDEX(path->header) + entries;
722 ext4_extent_index_set_first_block(path->index, iblock);
723 ext4_extent_index_set_leaf(path->index,
724 (path + 1)->block.lb_id);
727 EXT4_EXTENT_FIRST(path->header) + entries;
728 ext4_extent_set_first_block(path->extent, iblock);
731 ext4_extent_header_set_entries_count(path->header, entries + 1);
732 path->block.dirty = true;
738 /**@brief Append data block to the i-node.
739 * This function allocates data block, tries to append it
740 * to some existing extent or creates new extents.
741 * It includes possible extent tree modifications (splitting).
742 * @param inode_ref I-node to append block to
743 * @param iblock Output logical number of newly allocated block
744 * @param fblock Output physical block address of newly allocated block
746 * @return Error code*/
748 ext4_extent_append_block(struct ext4_inode_ref *inode_ref, uint32_t *iblock,
749 ext4_fsblk_t *fblock, bool update_size)
753 struct ext4_sblock *sb = &inode_ref->fs->sb;
754 uint64_t inode_size = ext4_inode_get_size(sb, inode_ref->inode);
755 uint32_t block_size = ext4_sb_get_block_size(sb);
757 /* Calculate number of new logical block */
758 uint32_t new_block_idx = 0;
759 if (inode_size > 0) {
760 if ((inode_size % block_size) != 0)
761 inode_size += block_size - (inode_size % block_size);
763 new_block_idx = inode_size / block_size;
766 /* Load the nearest leaf (with extent) */
767 struct ext4_extent_path *path;
768 int rc = ext4_extent_find_extent(inode_ref, new_block_idx, &path);
772 /* Jump to last item of the path (extent) */
773 struct ext4_extent_path *path_ptr = path;
774 while (path_ptr->depth != 0)
777 /* Add new extent to the node if not present */
778 if (path_ptr->extent == NULL)
781 uint16_t block_count = ext4_extent_get_block_count(path_ptr->extent);
782 uint16_t block_limit = (1 << 15);
784 ext4_fsblk_t phys_block = 0;
785 if (block_count < block_limit) {
786 /* There is space for new block in the extent */
787 if (block_count == 0) {
788 int rc = ext4_fs_indirect_find_goal(inode_ref, &goal);
792 /* Existing extent is empty */
793 rc = ext4_balloc_alloc_block(inode_ref, goal, &phys_block);
797 /* Initialize extent */
798 ext4_extent_set_first_block(path_ptr->extent,
800 ext4_extent_set_start(path_ptr->extent, phys_block);
801 ext4_extent_set_block_count(path_ptr->extent, 1,
806 ext4_inode_set_size(inode_ref->inode,
807 inode_size + block_size);
808 inode_ref->dirty = true;
811 path_ptr->block.dirty = true;
816 int rc = ext4_fs_indirect_find_goal(inode_ref, &goal);
820 /* Existing extent contains some blocks */
821 phys_block = ext4_extent_get_start(path_ptr->extent);
823 ext4_extent_get_block_count(path_ptr->extent);
825 /* Check if the following block is free for allocation
828 rc = ext4_balloc_try_alloc_block(inode_ref, phys_block,
834 /* Target is not free, new block must be
835 * appended to new extent
841 ext4_extent_set_block_count(path_ptr->extent,
847 ext4_inode_set_size(inode_ref->inode,
848 inode_size + block_size);
849 inode_ref->dirty = true;
852 path_ptr->block.dirty = true;
859 /* Append new extent to the tree */
862 rc = ext4_fs_indirect_find_goal(inode_ref, &goal);
866 /* Allocate new data block */
867 rc = ext4_balloc_alloc_block(inode_ref, goal, &phys_block);
871 /* Append extent for new block (includes tree splitting if needed) */
872 rc = ext4_extent_append_extent(inode_ref, path, new_block_idx);
874 ext4_balloc_free_block(inode_ref, phys_block);
878 uint32_t tree_depth = ext4_extent_header_get_depth(path->header);
879 path_ptr = path + tree_depth;
881 /* Initialize newly created extent */
882 ext4_extent_set_block_count(path_ptr->extent, 1, false);
883 ext4_extent_set_first_block(path_ptr->extent, new_block_idx);
884 ext4_extent_set_start(path_ptr->extent, phys_block);
888 ext4_inode_set_size(inode_ref->inode, inode_size + block_size);
889 inode_ref->dirty = true;
892 path_ptr->block.dirty = true;
895 /* Set return values */
896 *iblock = new_block_idx;
897 *fblock = phys_block;
901 * starting from 1: 0 is a block with inode data
903 for (i = 1; i <= path->depth; ++i) {
904 if (path[i].block.lb_id) {
906 ext4_block_set(inode_ref->fs->bdev, &path[i].block);
912 /* Destroy temporary data structure */
918 int ext4_extent_get_blocks(struct ext4_inode_ref *inode_ref, ext4_fsblk_t iblock,
919 ext4_lblk_t max_blocks, ext4_fsblk_t *result, bool create,
920 ext4_lblk_t *blocks_count)
922 uint32_t iblk = iblock;
923 ext4_fsblk_t fblk = 0;
932 r = ext4_extent_find_block(inode_ref, iblk, &fblk);
934 r = ext4_extent_append_block(inode_ref, &iblk, &fblk, false);