All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: ext4 development <linux-ext4@vger.kernel.org>
Subject: [PATCH e2fsprogs] fix extent_goto for non-0 leaf levels
Date: Mon, 12 May 2008 18:13:49 -0500	[thread overview]
Message-ID: <4828CF2D.9010804@redhat.com> (raw)

The logic for stopping at the right level in extent_goto was wrong,
so if you asked it to go to any level other than 0 (the leaf
level) it would fail.

Also add this argument to the tst_extents goto command to test it.

(I thought this was a failure in my split code but it was this
helper that was causing problems...)

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

Index: e2fsprogs/lib/ext2fs/extent.c
===================================================================
--- e2fsprogs.orig/lib/ext2fs/extent.c	2008-05-12 17:25:04.000000000 -0500
+++ e2fsprogs/lib/ext2fs/extent.c	2008-05-12 18:06:16.997505603 -0500
@@ -556,6 +556,9 @@ errcode_t ext2fs_extent_free_path(ext2_e
 /*
  * Go to the node at leaf_level which contains logical block blk.
  *
+ * leaf_level is height from the leaf node level, i.e.
+ * leaf_level 0 is at leaf node, leaf_level 1 is 1 above etc.
+ *
  * If "blk" has no mapping (hole) then handle is left at last
  * extent before blk.
  */
@@ -569,9 +572,15 @@ static errcode_t extent_goto(ext2_extent
 	if (retval)
 		return retval;
 
+	if (leaf_level > handle->max_depth) {
+		dbg_printf("leaf level %d greater than tree depth %d\n",
+			leaf_level, handle->max_depth);
+		return EXT2_ET_OP_NOT_SUPPORTED;
+	}
+
 	dbg_print_extent("root", &extent);
 	while (1) {
-		if (handle->level - leaf_level == handle->max_depth) {
+		if (handle->max_depth - handle->level == leaf_level) {
 			/* block is in this &extent */
 			if ((blk >= extent.e_lblk) &&
 			    (blk < extent.e_lblk + extent.e_len))
@@ -1140,6 +1149,7 @@ void do_goto_block(int argc, char **argv
 	errcode_t		retval;
 	int			op = EXT2_EXTENT_NEXT_LEAF;
 	blk_t			blk;
+	int			level = 0;
 
 	if (check_fs_open(argv[0]))
 		return;
@@ -1149,18 +1159,23 @@ void do_goto_block(int argc, char **argv
 		return;
 	}
 
-	if (argc != 2) {
-		fprintf(stderr, "%s block\n", argv[0]);
+	if (argc < 2 || argc > 3) {
+		fprintf(stderr, "%s block [level]\n", argv[0]);
 		return;
 	}
 
 	if (strtoblk(argv[0], argv[1], &blk))
 		return;
 
-	retval = ext2fs_extent_goto(current_handle, (blk64_t) blk);
+	if (argc == 3)
+		if (strtoblk(argv[0], argv[2], &level))
+			return;
+
+	retval = extent_goto(current_handle, level, (blk64_t) blk);
+
 	if (retval) {
-		com_err(argv[0], retval, "while trying to go to block %lu",
-			blk);
+		com_err(argv[0], retval, "while trying to go to block %lu, level %d",
+			blk, level);
 		return;
 	}
 


             reply	other threads:[~2008-05-12 23:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-12 23:13 Eric Sandeen [this message]
2008-05-14 17:32 ` [PATCH e2fsprogs] fix extent_goto for non-0 leaf levels Theodore Tso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4828CF2D.9010804@redhat.com \
    --to=sandeen@redhat.com \
    --cc=linux-ext4@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.