[PATCH] [parted] Fix ped exception handling in mkpart and mkpartfs
Flavio Leitner
flavio.leitner at gmail.com
Sun May 13 17:29:57 UTC 2007
Parted mkpart and mkpartfs commands does:
...
ped_exception_fetch_all();
if (!ped_disk_add_partition (disk, part, final_constraint)) {
ped_exception_leave_all();
...
}
...
In mkpart if the ped_disk_add_partition() returns true it skips
ped_exception_leave_all() leaving ex_fetch_count = 1.
In mkpartfs if the ped_disk_add_partition() returns false it will
call ped_exception_leave_all() leaving ex_fetch_count negative.
The wrong count in ex_fetch_count will prevent next commands to
correctly handle exceptions, failing to prompt users for example.
Note: test script t2000-mkfs.sh improved to verify against this issue.
Signed-off-by: Flavio Leitner <flavio.leitner at gmail.com>
---
parted/parted.c | 5 ++++-
tests/t2000-mkfs.sh | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 1 deletions(-)
diff --git a/parted/parted.c b/parted/parted.c
index c7b3e22..202558a 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -784,6 +784,8 @@ do_mkpart (PedDevice** dev)
} else {
goto error_remove_part;
}
+ } else {
+ ped_exception_leave_all();
}
ped_exception_catch();
@@ -952,9 +954,10 @@ do_mkpartfs (PedDevice** dev)
} else {
goto error_remove_part;
}
+ } else {
+ ped_exception_leave_all();
}
ped_exception_catch();
- ped_exception_leave_all();
/* set LBA flag automatically if available */
if (ped_partition_is_flag_available (part, PED_PARTITION_LBA))
diff --git a/tests/t2000-mkfs.sh b/tests/t2000-mkfs.sh
index 14140f6..862ff21 100755
--- a/tests/t2000-mkfs.sh
+++ b/tests/t2000-mkfs.sh
@@ -42,4 +42,43 @@ test_expect_success \
test_expect_success 'expect no output' '$compare out /dev/null'
+N=10M
+test_expect_success \
+ 'create a file large enough to hold a fat32 file system' \
+ 'dd if=/dev/zero of=$dev bs=$N count=1 2> /dev/null'
+
+test_expect_success \
+ 'label the test disk' \
+ 'parted -s $dev mklabel msdos > out 2>&1'
+test_expect_success 'expect no output' '$compare out /dev/null'
+
+# test if can create a partition and a filesystem in the same session.
+fail=0
+cat <<EOF >in || fail=1
+mkpart
+primary
+ext2
+0
+10
+mkfs
+No
+quit
+EOF
+
+# create output with expected prompt
+cat <<EOF > exp || fail=1
+Warning: The existing file system will be destroyed and all data on the partition will be lost. Do you want to continue?
+EOF
+
+test_expect_success \
+ 'create a partition and a filesystem in the same session' \
+ 'parted ---pretend-input-tty $dev < in > out 2>&1'
+
+test_expect_success \
+ 'normalize the actual output' \
+ 'sed -n "s/.*\(Warning: The existing.*\)$/\1/p" out > out2'
+
+test_expect_success \
+ 'check for expected prompt' '$compare out2 exp'
+
test_done
--
1.5.0.6
More information about the parted-devel
mailing list