[Parted-commits] GNU Parted Official Repository: Changes to 'master'
Jim Meyering
meyering at alioth.debian.org
Thu May 24 18:00:28 UTC 2007
libparted/fs/ext2/ext2_mkfs.c | 4 ++
tests/Makefile.am | 3 +-
tests/t3000-constraints.sh | 61 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 66 insertions(+), 2 deletions(-)
New commits:
commit 32c069f0b2404cbc75eff3f729207bf9193979d0
Author: Jim Meyering <jim at meyering.net>
Date: Thu May 24 20:00:22 2007 +0200
Diagnose "ext2 FS too small" rather than triggering an assertion.
* libparted/fs/ext2/ext2_mkfs.c (ext2_mkfs): An overlapping ext2
partition request could still lead to a bug: constraint-resolution
code would produce a single-sector candidate "range", and that
would cause the ext2 fs-creation code to misbehave. Now, it
properly detects and reports the FS as being too small.
* tests/t3000-constraints.sh: New test for the above.
* tests/Makefile.am (TESTS): Add t3000-constraints.sh.
diff --git a/libparted/fs/ext2/ext2_mkfs.c b/libparted/fs/ext2/ext2_mkfs.c
index 8f74a45..92261f6 100644
--- a/libparted/fs/ext2/ext2_mkfs.c
+++ b/libparted/fs/ext2/ext2_mkfs.c
@@ -542,7 +542,8 @@ struct ext2_fs *ext2_mkfs(struct ext2_dev_handle *handle,
if (numblocks == 0)
numblocks = handle->ops->get_size(handle->cookie);
- PED_ASSERT(numblocks != 0, return NULL);
+ if (numblocks == 0)
+ goto diagnose_fs_too_small;
if (blocks_per_group == (unsigned int) 0)
blocks_per_group = 8 << log_block_size;
@@ -589,6 +590,7 @@ struct ext2_fs *ext2_mkfs(struct ext2_dev_handle *handle,
fs_too_small = 1;
if (fs_too_small) {
+ diagnose_fs_too_small:
ped_exception_throw (
PED_EXCEPTION_ERROR,
PED_EXCEPTION_CANCEL,
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 59d38e5..27689c9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -3,7 +3,8 @@ TESTS = \
t1000-mkpartfs.sh \
t1100-busy-label.sh \
t1500-small-ext2.sh \
- t2000-mkfs.sh
+ t2000-mkfs.sh \
+ t3000-constraints.sh
EXTRA_DIST = \
$(TESTS) test-lib.sh mkdtemp
diff --git a/tests/t3000-constraints.sh b/tests/t3000-constraints.sh
new file mode 100755
index 0000000..07fe1b3
--- /dev/null
+++ b/tests/t3000-constraints.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+
+# Copyright (C) 2007 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+test_description="exercise Parted's constraint-management code"
+
+. ./init.sh
+
+# FIXME: move this to test-lib.sh, and use it in t0000*.sh
+emit_superuser_warning()
+{
+ uid=`id -u` || uid=1
+ test "$uid" != 0 &&
+ echo 'WARNING: You are not superuser. Watch out for permissions.'
+}
+
+dev=loop-file
+N=2
+t=ext2
+
+test_expect_success \
+ "setup: label and create a small $t partition" \
+ 'dd if=/dev/zero of=$dev bs=${N}M count=1 2>/dev/null &&
+ { echo y; echo c; } > in &&
+ { emit_superuser_warning
+ echo "Warning: You requested a partition from 1000kB to 2000kB."
+ echo "The closest location we can manage is 15.9kB to 15.9kB." \
+ " Is this still acceptable to you?"
+ echo "Yes/No? y"
+ echo "Error: File system too small for ext2."; } > exp &&
+ parted -s $dev mklabel msdos &&
+ parted -s $dev mkpartfs primary $t 1 $N'
+
+# Before parted-1.9, this would fail with a buffer overrun
+# leading to a segfault.
+test_expect_failure \
+ 'try to create another partition in the same place' \
+ 'parted ---pretend-input-tty $dev mkpartfs primary $t 1 $N <in >out 2>&1'
+
+test_expect_success \
+ 'normalize the actual output' \
+ 'sed "s,
*
,,;s, $,," out > o2 && mv -f o2 out'
+
+test_expect_success 'check for expected output' '$compare out exp'
+
+test_done
More information about the Parted-commits
mailing list