- Fix ped_disk_duplicate on GPT so that it copies the partition flags (#747947)

- Add new test to check ped_disk_duplicate on msdos, gpt, bsd disk labels
- Add e2fsprogs and dosfstools so that skipped tests will be run
This commit is contained in:
Brian C. Lane 2011-10-31 14:56:09 -07:00
parent 8e3b457f0f
commit 68bb9e0f50
3 changed files with 274 additions and 1 deletions

View File

@ -0,0 +1,53 @@
From e356e46263c93f0ffdcd830d9f4d051fc961067e Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Thu, 27 Oct 2011 16:29:15 -0700
Subject: [PATCH 1/2] libparted: copy flags when duplicating GPT partitions
* libparted/labels/gpt.c (gpt_partition_duplicate): copy flags to new
partition.
* NEWS: Mention this fix.
---
NEWS | 3 +++
libparted/labels/gpt.c | 12 ++++++++++++
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/NEWS b/NEWS
index b7fb56b..915b5ff 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,9 @@ GNU parted NEWS -*- outline -*-
** Bug fixes
+ libparted: gpt_disk_duplicate now copies the flags over to the new
+ disk object. Previously the flags would be undefined.
+
libparted: no longer aborts (failed assertion) due to a nilfs2_probe bug
[bug introduced in parted-2.4 with the addition of nilfs2 support]
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 8c9816f..7b4e014 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -1365,6 +1365,18 @@ gpt_partition_duplicate (const PedPartition *part)
result_data->type = part_data->type;
result_data->uuid = part_data->uuid;
strcpy (result_data->name, part_data->name);
+
+ /* Copy over all the flags */
+ result_data->lvm = part_data->lvm;
+ result_data->raid = part_data->raid;
+ result_data->boot = part_data->boot;
+ result_data->bios_grub = part_data->bios_grub;
+ result_data->hp_service = part_data->hp_service;
+ result_data->hidden = part_data->hidden;
+ result_data->msftres = part_data->msftres;
+ result_data->atvrecv = part_data->atvrecv;
+ result_data->msftrecv = part_data->msftrecv;
+ result_data->legacy_boot = part_data->legacy_boot;
return result;
error_free_part:
--
1.7.6.4

View File

@ -0,0 +1,210 @@
From 1fad3afd9587de566b2f3b451ed4de2fc409ad21 Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Mon, 31 Oct 2011 14:30:12 -0700
Subject: [PATCH 2/2] tests: add new test to check ped_disk_duplicate
* tests/duplicate.c: New test
* tests/t0501-duplicate.sh: New test program
* tests/Makefile.am (TEST): Add new test
(check_PROGRAMS): Add new test program
---
tests/Makefile.am | 3 +-
tests/duplicate.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++
tests/t0501-duplicate.sh | 28 ++++++++++
3 files changed, 159 insertions(+), 1 deletions(-)
create mode 100644 tests/duplicate.c
create mode 100644 tests/t0501-duplicate.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5a8a539..ae4c5f4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -24,6 +24,7 @@ TESTS = \
t0300-dos-on-gpt.sh \
t0400-loop-clobber-infloop.sh \
t0500-dup-clobber.sh \
+ t0501-duplicate.sh \
t1100-busy-label.sh \
t1101-busy-partition.sh \
t1700-probe-fs.sh \
@@ -62,7 +63,7 @@ EXTRA_DIST = \
$(TESTS) lvm-utils.sh t-local.sh t-lvm.sh \
init.cfg init.sh t-lib-helpers.sh
-check_PROGRAMS = print-align print-max dup-clobber
+check_PROGRAMS = print-align print-max dup-clobber duplicate
LDADD = \
$(top_builddir)/libparted/libparted.la
AM_CPPFLAGS = \
diff --git a/tests/duplicate.c b/tests/duplicate.c
new file mode 100644
index 0000000..5af8543
--- /dev/null
+++ b/tests/duplicate.c
@@ -0,0 +1,129 @@
+/* Demonstrate that ped_disk_duplicate is working correctly.
+*/
+#include <config.h>
+#include <parted/parted.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+
+#include "closeout.h"
+#include "progname.h"
+
+int
+main (int argc, char **argv)
+{
+ atexit (close_stdout);
+ set_program_name (argv[0]);
+
+ if (argc != 2)
+ return EXIT_FAILURE;
+
+ char const *dev_name = "dev-file";
+
+ /* Create a file. */
+ int fd = open (dev_name, O_CREAT|O_TRUNC|O_WRONLY, 0644);
+ assert (0 <= fd);
+ off_t size = 8 * 1024 * 1024;
+ assert (ftruncate (fd, size) == 0);
+ assert (close (fd) == 0);
+
+ PedDevice *dev = ped_device_get (dev_name);
+ assert (dev);
+
+ PedDisk *disk = ped_disk_new_fresh (dev, ped_disk_type_get (argv[1]));
+ assert (disk);
+ assert (ped_disk_commit(disk));
+ ped_disk_destroy (disk);
+
+ /* re-open the disk */
+ disk = ped_disk_new (dev);
+ assert (disk);
+
+ /* Create a partition */
+ const PedFileSystemType *fs_type = ped_file_system_type_get ("ext2");
+ assert (fs_type);
+ PedPartitionType part_type = PED_PARTITION_NORMAL;
+ const PedGeometry *geometry = ped_geometry_new (dev, 34, 1024);
+ assert (geometry);
+ PedPartition *part = ped_partition_new (disk, part_type, fs_type, geometry->start, geometry->end);
+ assert (part);
+ PedConstraint *constraint = ped_constraint_exact (geometry);
+ assert (constraint);
+
+ if (ped_partition_is_flag_available (part, PED_PARTITION_BOOT))
+ assert (ped_partition_set_flag (part, PED_PARTITION_BOOT, 1));
+
+ assert (ped_disk_add_partition (disk, part, constraint));
+ ped_constraint_destroy (constraint);
+
+ assert (ped_partition_set_system (part, fs_type));
+ if (ped_partition_is_flag_available (part, PED_PARTITION_LBA))
+ ped_partition_set_flag (part, PED_PARTITION_LBA, 1);
+
+ assert (ped_disk_commit(disk));
+
+ /* Duplicate it */
+ PedDisk *copy = ped_disk_duplicate (disk);
+ assert (ped_disk_commit(copy));
+
+ /* Compare the two copies */
+
+ /* Check the device */
+ assert (strcmp (disk->dev->model, copy->dev->model) == 0);
+ assert (strcmp (disk->dev->path, copy->dev->path) == 0);
+ assert (disk->dev->sector_size == copy->dev->sector_size);
+ assert (disk->dev->phys_sector_size == copy->dev->phys_sector_size);
+ assert (disk->dev->length == copy->dev->length);
+
+ /* Check the type */
+ assert (strcmp (disk->type->name, copy->type->name) == 0);
+ assert (disk->type->features == copy->type->features);
+
+ /* Check the flags */
+ for (PedDiskFlag flag = PED_DISK_FIRST_FLAG; flag <= PED_DISK_LAST_FLAG; flag++) {
+ if (!ped_disk_is_flag_available(disk, flag))
+ continue;
+ assert (ped_disk_get_flag (disk, flag) == ped_disk_get_flag (copy, flag));
+ }
+
+ /* Check the partitions */
+ PedPartition *disk_part, *copy_part;
+ for ( disk_part = disk->part_list, copy_part = copy->part_list;
+ disk_part && copy_part;
+ disk_part = disk_part->next, copy_part = copy_part->next)
+ {
+ /* Only active partitions are duplicated */
+ if (!ped_partition_is_active (disk_part))
+ continue;
+
+ assert (disk_part->geom.start == copy_part->geom.start);
+ assert (disk_part->geom.end == copy_part->geom.end);
+ assert (disk_part->geom.length == copy_part->geom.length);
+ assert (disk_part->num == copy_part->num);
+ assert (disk_part->type == copy_part->type);
+
+ if (disk_part->fs_type && disk_part->fs_type->name) {
+ assert (strcmp (disk_part->fs_type->name, copy_part->fs_type->name) == 0);
+ }
+
+ /* Check the flags */
+ for (PedPartitionFlag flag = PED_PARTITION_FIRST_FLAG; flag <= PED_PARTITION_LAST_FLAG; flag++) {
+ if (!ped_partition_is_flag_available(disk_part, flag))
+ continue;
+ fprintf (stderr, "Checking partition flag %d\n", flag);
+ fprintf (stderr, "%d ? %d\n", ped_partition_get_flag (disk_part, flag), ped_partition_get_flag (copy_part, flag));
+ assert (ped_partition_get_flag (disk_part, flag) == ped_partition_get_flag (copy_part, flag));
+ }
+ }
+
+ /* Cleanup the mess */
+ ped_disk_destroy (copy);
+ ped_disk_destroy (disk);
+ ped_device_destroy (dev);
+
+ return EXIT_SUCCESS;
+}
diff --git a/tests/t0501-duplicate.sh b/tests/t0501-duplicate.sh
new file mode 100644
index 0000000..0585a95
--- /dev/null
+++ b/tests/t0501-duplicate.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+# Drive the dup-clobber program.
+
+# 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
+
+PATH="..:$PATH"
+export PATH
+
+for t in msdos gpt bsd; do
+ duplicate $t || fail=1
+done
+
+Exit $fail
--
1.7.6.4

View File

@ -4,7 +4,7 @@
Summary: The GNU disk partition manipulation program
Name: parted
Version: 3.0
Release: 3%{?dist}
Release: 4%{?dist}
License: GPLv3+
Group: Applications/System
URL: http://www.gnu.org/software/parted
@ -30,6 +30,9 @@ Patch9: parted-3.0-tests-test-for-the-nilfs2-bug.patch
Patch10: parted-3.0-libparted-Fix-a-bug-in-the-hfs-probe-functions-71475.patch
Patch11: parted-3.0-libparted-make-pc98-detection-depend-on-signatures.patch
Patch12: parted-3.0-tests-add-tests-for-new-pc98-signatures-646053.patch
Patch13: parted-3.0-libparted-copy-flags-when-duplicating-GPT-partitions.patch
Patch14: parted-3.0-tests-add-new-test-to-check-ped_disk_duplicate.patch
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: e2fsprogs-devel
@ -44,6 +47,8 @@ BuildRequires: libblkid-devel >= 2.17
BuildRequires: gnupg
BuildRequires: git
BuildRequires: autoconf automake
BuildRequires: e2fsprogs
BuildRequires: dosfstools
Requires(post): /sbin/ldconfig
Requires(post): /sbin/install-info
@ -158,6 +163,11 @@ fi
%changelog
* Mon Oct 31 2011 Brian C. Lane <bcl@redht.com> - 3.0-4
- Fix ped_disk_duplicate on GPT so that it copies the partition flags (#747947)
- Add new test to check ped_disk_duplicate on msdos, gpt, bsd disk labels
- Add e2fsprogs and dosfstools so that skipped tests will be run
* Fri Oct 07 2011 Brian C. Lane <bcl@redhat.com> - 3.0-3
- Fix handling of zero-length gpt partitions (#728949)
- Fix bug in nilfs2 probe with short partitions (#728949)