Update to parted v3.0

This changes the spec to run autoreconf so that patches to .am files
will be picked up without having to resort to hand-patching .in files.
This should make parted more maintainable in the future.

Add patch to Fix snap radius and don't allow values < 1 (#665496)
Add tests for the snap radius fix.
This commit is contained in:
Brian C. Lane 2011-06-23 15:58:47 -07:00
parent ec61764348
commit 3cb85c39f2
9 changed files with 232 additions and 168 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@ parted-2.3.tar.xz.sig
clog
/parted-2.4.tar.xz
/parted-2.4.tar.xz.sig
/parted-3.0.tar.xz
/parted-3.0.tar.xz.sig

View File

@ -1,52 +0,0 @@
From eb5e5f9c57aa8a3f8502ea75b08e5c608f6cec2c Mon Sep 17 00:00:00 2001
From: Jim Meyering <jim@meyering.net>
Date: Sun, 5 Jun 2011 18:17:40 +0200
Subject: [PATCH] Problem with Linux "3.0"
Richard W.M. Jones wrote:
> https://bugzilla.redhat.com/show_bug.cgi?id=710882
>
> I'm fairly sure that the problem is in _get_linux_version function in
> libparted/arch/linux.c, which expects a 3 part string. In Linux 3.0
> the string is "3.0" so this fails.
>
> Sorry for not putting together a patch, but my dev machine is down at
> the moment. If no one else jumps in, I'll post a patch tomorrow.
Hi Rich,
Thanks for the report.
Here's an untested patch:
>From 2ad212ad414f96b34420ece1adc3db9f291d03c3 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Sun, 5 Jun 2011 18:15:31 +0200
Subject: [PATCH] libparted: accommodate two-component linux version number
like 3.0
* libparted/arch/linux.c (_get_linux_version): Also accept 2-component
version numbers.
Reported by Richard W.M. Jones.
---
libparted/arch/linux.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index aeaf98f..111816c 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -610,7 +610,11 @@ _get_linux_version ()
if (uname (&uts))
return kver = 0;
- if (sscanf (uts.release, "%u.%u.%u", &major, &minor, &teeny) != 3)
+ if (sscanf (uts.release, "%u.%u.%u", &major, &minor, &teeny) == 3)
+ ; /* ok */
+ else if (sscanf (uts.release, "%u.%u", &major, &minor) == 2)
+ teeny = 0;
+ else
return kver = 0;
return kver = KERNEL_VERSION (major, minor, teeny);
--
1.7.5.1

View File

@ -1,106 +0,0 @@
From 325b06dae4dff1751d6c5f28506def0786a1a1c9 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 16 Dec 2010 15:37:32 -0500
Subject: [PATCH] Improve support for mac partition tables with logical sector size != 512
On mac partition tables which specify a sector size larger than the
physical sector size, we need to reallocate the buffer after we
determine the correct sector size.
This is a normal condition when CD is used with Apple partitions (for
example, the USB rescue stick for the MacBookAir3,1), and then an image
(analogous to an .iso image) is created, so also don't raise an exception in
_disk_analyse_block_size() when we find that.
Also simplify the code in _disk_analyse_block_size() a bit since there's no
reason to ever do the byteswapping more than once or convert everything to
512-byte multiples since we neither load nor store it that way.
---
libparted/labels/mac.c | 44 ++++++++++++++++++++++++++------------------
1 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/libparted/labels/mac.c b/libparted/labels/mac.c
index 49a236e..418343e 100644
--- a/libparted/labels/mac.c
+++ b/libparted/labels/mac.c
@@ -643,35 +643,22 @@ _rawpart_get_partmap_size (MacRawPartition* raw_part, PedDisk* disk)
static int
_disk_analyse_block_size (PedDisk* disk, MacRawDisk* raw_disk)
{
- PedSector block_size;
+ PedSector block_size = PED_BE16_TO_CPU(raw_disk->block_size);
- if (PED_BE16_TO_CPU (raw_disk->block_size) % 512) {
+ if (block_size % 512) {
#ifndef DISCOVER_ONLY
ped_exception_throw (
PED_EXCEPTION_ERROR,
PED_EXCEPTION_CANCEL,
_("Weird block size on device descriptor: %d bytes is "
"not divisible by 512."),
- (int) PED_BE16_TO_CPU (raw_disk->block_size));
+ (int) block_size);
#endif
goto error;
}
- block_size = PED_BE16_TO_CPU (raw_disk->block_size) / 512;
- if (block_size != disk->dev->sector_size / 512) {
-#ifndef DISCOVER_ONLY
- if (ped_exception_throw (
- PED_EXCEPTION_WARNING,
- PED_EXCEPTION_IGNORE_CANCEL,
- _("The driver descriptor says the physical block size "
- "is %d bytes, but Linux says it is %d bytes."),
- (int) block_size * 512,
- (int) disk->dev->sector_size)
- != PED_EXCEPTION_IGNORE)
- goto error;
-#endif
- disk->dev->sector_size = block_size * 512;
- }
+ if (block_size != disk->dev->sector_size)
+ disk->dev->sector_size = block_size;
return 1;
@@ -729,6 +716,7 @@ mac_read (PedDisk* disk)
PedPartition* part;
int num;
PedSector ghost_size;
+ PedSector sector_size;
PedConstraint* constraint_exact;
int last_part_entry_num = 0;
@@ -746,8 +734,28 @@ mac_read (PedDisk* disk)
if (!_check_signature (raw_disk))
goto error;
+ sector_size = disk->dev->sector_size;
if (!_disk_analyse_block_size (disk, raw_disk))
goto error;
+
+ /* If dev->sector_size changed when we did ptt_read_sector(),
+ then the buffer size is wrong and we'll take a segfault
+ down the line unless we re-allocate it here. */
+ if (disk->dev->sector_size != sector_size) {
+ free(buf);
+ buf = 0;
+ if (!ptt_read_sector(disk->dev, 0, &buf))
+ return 0;
+
+ MacRawDisk *raw_disk = (MacRawDisk *) buf;
+
+ if (!_check_signature (raw_disk))
+ goto error;
+
+ if (!_disk_analyse_block_size (disk, raw_disk))
+ goto error;
+ }
+
if (!_disk_analyse_ghost_size (disk))
goto error;
ghost_size = mac_disk_data->ghost_size;
--
1.7.3.1

View File

@ -0,0 +1,35 @@
From bca7bb94e16acb1e88df97a5ce2c38adb76b072d Mon Sep 17 00:00:00 2001
From: Brian C. Lane <bcl@redhat.com>
Date: Tue, 21 Jun 2011 10:44:16 -0700
Subject: [PATCH 2/4] libparted: don't allow values less than 1 (#665496)
When a value < 1 is used there is the possibility that the range can
overlap sector 0. The user should use smaller units instead. 0 is a
special case and is still allowed.
* libparted/unit.c (ped_unit_parse_custom): Throw error if a value
between 0 and 1 is used.
---
libparted/unit.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/libparted/unit.c b/libparted/unit.c
index c2921e3..232f81b 100644
--- a/libparted/unit.c
+++ b/libparted/unit.c
@@ -531,6 +531,12 @@ ped_unit_parse_custom (const char* str, const PedDevice* dev, PedUnit unit,
_("Invalid number."));
goto error_free_copy;
}
+ if (num > 0 && num < 1) {
+ ped_exception_throw (
+ PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Use a smaller unit instead of a value < 1"));
+ goto error_free_copy;
+ }
unit_size = ped_unit_get_size (dev, unit);
radius = (ped_div_round_up (unit_size, dev->sector_size) / 2) - 1;
--
1.7.4.4

View File

@ -0,0 +1,34 @@
From 18e727d492933ae1ebb16961e1df553f9299af8b Mon Sep 17 00:00:00 2001
From: Brian C. Lane <bcl@redhat.com>
Date: Tue, 21 Jun 2011 10:44:15 -0700
Subject: [PATCH 1/4] libparted: fix snap radius so that it is using half
(#665496)
The snap radius didn't match the documentation, it has been using +/-
unit size instead +/- 0.5 * unit (eg. 500KB for a MB unit). This caused
problems when specifying 1MB, 1GB, etc. as a partition start or end
resulting in partitions being created that were nowhere near the
specified size.
* libparted/unit.c (ped_unit_parse_custom): divide radius by 2
This addresses http://bugzilla.redhat.com/665496
---
libparted/unit.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/libparted/unit.c b/libparted/unit.c
index dc4205b..c2921e3 100644
--- a/libparted/unit.c
+++ b/libparted/unit.c
@@ -533,7 +533,7 @@ ped_unit_parse_custom (const char* str, const PedDevice* dev, PedUnit unit,
}
unit_size = ped_unit_get_size (dev, unit);
- radius = ped_div_round_up (unit_size, dev->sector_size) - 1;
+ radius = (ped_div_round_up (unit_size, dev->sector_size) / 2) - 1;
if (radius < 0)
radius = 0;
/* If the user specifies units in a power of 2, e.g., 4MiB, as in
--
1.7.4.4

View File

@ -0,0 +1,76 @@
From 801a0d9957116757dddc4e62abe62a403d22c9b2 Mon Sep 17 00:00:00 2001
From: Brian C. Lane <bcl@redhat.com>
Date: Tue, 21 Jun 2011 10:44:17 -0700
Subject: [PATCH 3/4] tests: add test for radius divide by 2 fix
* tests/t9022-one-unit-snap.sh: New file.
* tests/Makefile.am (TESTS): Add it.
---
tests/Makefile.am | 1 +
tests/t9022-one-unit-snap.sh | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 0 deletions(-)
create mode 100644 tests/t9022-one-unit-snap.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4ea08f3..7487a5d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -44,6 +44,7 @@ TESTS = \
t9010-big-sector.sh \
t9020-alignment.sh \
t9021-maxima.sh \
+ t9022-one-unit-snap.sh \
t9030-align-check.sh \
t9040-many-partitions.sh \
t9041-undetected-in-use-16th-partition.sh \
diff --git a/tests/t9022-one-unit-snap.sh b/tests/t9022-one-unit-snap.sh
new file mode 100644
index 0000000..ce903a5
--- /dev/null
+++ b/tests/t9022-one-unit-snap.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+# Confirm that specifying 1 unit snaps to the correct value
+
+# Copyright (C) 2011 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 3 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, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+
+ss=$sector_size_
+n_sectors=3000
+dev=dev-file
+
+# Create an example of what the result should look like
+# start should be at 1 sector.
+dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1
+parted --align=none -s $dev mklabel msdos mkpart pri 1s $((1000*1000))B \
+ > err 2>&1 || fail=1
+compare err /dev/null || fail=1
+parted -m -s $dev u s p > exp || fail=1
+
+rm $dev
+dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1
+parted --align=none -s $dev mklabel msdos mkpart pri 0 1MB \
+ > err 2>&1 || fail=1
+compare err /dev/null || fail=1
+parted -m -s $dev u s p > out || fail=1
+
+compare out exp || fail=1
+
+Exit $fail
--
1.7.4.4

View File

@ -0,0 +1,66 @@
From b8f017f18fa99f9377ef461cbbd3264c7878a9aa Mon Sep 17 00:00:00 2001
From: Brian C. Lane <bcl@redhat.com>
Date: Tue, 21 Jun 2011 10:44:18 -0700
Subject: [PATCH 4/4] tests: add test for value less than 1
* tests/t9023-value-lt-one.sh: New file.
* tests/Makefile.am (TESTS): Add it.
---
tests/Makefile.am | 1 +
tests/t9023-value-lt-one.sh | 32 ++++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 0 deletions(-)
create mode 100644 tests/t9023-value-lt-one.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7487a5d..b57142b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -45,6 +45,7 @@ TESTS = \
t9020-alignment.sh \
t9021-maxima.sh \
t9022-one-unit-snap.sh \
+ t9023-value-lt-one.sh \
t9030-align-check.sh \
t9040-many-partitions.sh \
t9041-undetected-in-use-16th-partition.sh \
diff --git a/tests/t9023-value-lt-one.sh b/tests/t9023-value-lt-one.sh
new file mode 100644
index 0000000..67be8d6
--- /dev/null
+++ b/tests/t9023-value-lt-one.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# Confirm that a value between 0 and 1 throws an error
+
+# Copyright (C) 2011 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 3 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, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+
+ss=$sector_size_
+n_sectors=3000
+dev=dev-file
+
+echo 'Error: Use a smaller unit instead of a value < 1' > exp
+
+dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1
+parted --align=none -s $dev mklabel msdos mkpart pri 0 0.5MB \
+ > err 2>&1
+compare err exp || fail=1
+
+Exit $fail
--
1.7.4.4

View File

@ -3,8 +3,8 @@
Summary: The GNU disk partition manipulation program
Name: parted
Version: 2.4
Release: 2%{?dist}
Version: 3.0
Release: 1%{?dist}
License: GPLv3+
Group: Applications/System
URL: http://www.gnu.org/software/parted
@ -16,13 +16,12 @@ Source2: pubkey.jim.meyering
# Report partitions changes when using blkext major numbers
Patch0: parted-2.3-lpn.patch
# Handle mac labels with differing physical/logical sector sizes better
Patch1: parted-2.3-mac-logical-sector-size.patch
# Document the align-check command
Patch2: parted-2.3-Document-align-check-642476.patch
# Patch that may fix Linux "3.0" problem.
Patch3: 0001-Problem-with-Linux-3.0.patch
Patch1: parted-2.3-Document-align-check-642476.patch
Patch2: parted-3.0-libparted-fix-snap-radius-so-that-it-is-using-half.patch
Patch3: parted-3.0-libparted-don-t-allow-values-less-than-1.patch
Patch4: parted-3.0-tests-add-test-for-radius-divide-by-2-fix.patch
Patch5: parted-3.0-tests-add-test-for-value-less-than-1.patch
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: e2fsprogs-devel
@ -36,6 +35,7 @@ BuildRequires: libuuid-devel
BuildRequires: libblkid-devel >= 2.17
BuildRequires: gnupg
BuildRequires: git
BuildRequires: autoconf automake
Requires(post): /sbin/ldconfig
Requires(post): /sbin/install-info
@ -76,6 +76,8 @@ iconv -f ISO-8859-1 -t UTF8 AUTHORS > tmp; touch -r AUTHORS tmp; mv tmp AUTHORS
git commit -a -m "run iconv"
%build
autoreconf
autoconf
CFLAGS="$RPM_OPT_FLAGS -Wno-unused-but-set-variable"; export CFLAGS
%configure --enable-selinux --disable-static
# Don't use rpath!
@ -148,6 +150,13 @@ fi
%changelog
* Tue Jun 28 2011 Brian C. Lane <bcl@redhat.com> - 3.0-1
- Update to parted v3.0
- Run autoreconf so that patches to .am files will work
- Add patch to Fix snap radius and don't allow values < 1 (#665496)
- Add tests for the snap radius fix.
- Drop patches included in upstream release
* Sun Jun 5 2011 Richard W.M. Jones <rjones@redhat.com> - 2.4-2
- Apply patch which may fix Linux "3.0" problem.

View File

@ -1,2 +1,2 @@
b6cc55fd6e04b37b1745bc2e10d1a888 parted-2.4.tar.xz
423f9aba38b63305141151a9473c1deb parted-2.4.tar.xz.sig
c415e5c97f86b5ff65a2d925e5a3feb7 parted-3.0.tar.xz
41839de7a7fbd408cd2ada64d174c006 parted-3.0.tar.xz.sig