- Add some missing patches from master and the loop label fixes

- tests: test loop labels (psusi)
- libparted: don't trash filesystem when writing loop label (psusi)
- libparted: give correct partition device name on loop labels (psusi)
- partprobe: do not skip loop labels (psusi)
- libparted: don't create partition on loop label (psusi)
- libparted: fix loop labels to not vanish (psusi)
- libparted: remove all old partitions, even if new label allows less (psusi)
- libparted: remove old partitions *first* before adding new ones (psusi)
- libparted: don't detect fat and ntfs boot sectors as dos MBR (psusi)
- Fix filesystem detection on non 512 byte sectors (psusi)
- tests: fix t2310-dos-extended-2-sector-min-offset.sh (psusi)
- libparted: remove last_usable_if_grown (psusi)
This commit is contained in:
Brian C. Lane 2014-05-22 15:03:30 -07:00
parent 3e3c91556c
commit 5dcb73843d
13 changed files with 2233 additions and 1 deletions

View File

@ -0,0 +1,28 @@
From 6aa11c2e96499a4a620b54433fd064961d1cbf66 Mon Sep 17 00:00:00 2001
From: Phillip Susi <psusi@ubuntu.com>
Date: Fri, 18 Apr 2014 11:01:03 -0400
Subject: [PATCH 101/103] libparted: remove last_usable_if_grown
Commit 3398e82a: "libparted: Use common function to calculate PTE sectors"
removed usage of the last_usable_if_grown variable, resulting in an error
because it is now unused but still defined.
---
libparted/labels/gpt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index e1113ac..b7291a8 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -723,7 +723,7 @@ _parse_header (PedDisk *disk, const GuidPartitionTableHeader_t *gpt,
GPTDiskData *gpt_disk_data = disk->disk_specific;
PedSector first_usable;
PedSector last_usable;
- PedSector last_usable_if_grown, last_usable_min_default;
+ PedSector last_usable_if_grown;
static int asked_already;
#ifndef DISCOVER_ONLY
--
1.9.0

View File

@ -0,0 +1,45 @@
From d68ca7fe15915849629c85f5a5476b2173b3af2c Mon Sep 17 00:00:00 2001
From: Phillip Susi <psusi@ubuntu.com>
Date: Sat, 29 Mar 2014 16:29:06 -0400
Subject: [PATCH 102/103] tests: fix t2310-dos-extended-2-sector-min-offset.sh
This test was ignoring the requested sector size and always using
512 bytes per sector. Fix it to use the requested sector size.
---
tests/t2310-dos-extended-2-sector-min-offset.sh | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/tests/t2310-dos-extended-2-sector-min-offset.sh b/tests/t2310-dos-extended-2-sector-min-offset.sh
index f74cba5..53843ab 100644
--- a/tests/t2310-dos-extended-2-sector-min-offset.sh
+++ b/tests/t2310-dos-extended-2-sector-min-offset.sh
@@ -23,7 +23,8 @@ require_root_
require_scsi_debug_module_
# create memory-backed device
-scsi_debug_setup_ dev_size_mb=1 > dev-name ||
+ss=$sector_size_
+scsi_debug_setup_ sector_size=$ss dev_size_mb=1 > dev-name ||
skip_ 'failed to create scsi_debug device'
scsi_dev=$(cat dev-name)
p1=${scsi_dev}1
@@ -31,15 +32,11 @@ p5=${scsi_dev}5
cat <<EOF > exp || framework_failure
BYT;
-$scsi_dev:2048s:scsi:512:512:msdos:Linux scsi_debug:;
+$scsi_dev:$((2048*512/$ss))s:scsi:$ss:$ss:msdos:Linux scsi_debug:;
1:64s:128s:65s:::lba;
5:65s:128s:64s:::;
EOF
-cat <<EOF > err.exp || framework_failure
-Error: Partition(s) 5 on $scsi_dev have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes.
-EOF
-
# Create a DOS label with an extended partition starting at sector 64.
parted -s $scsi_dev mklabel msdos || fail=1
parted --align=min -s $scsi_dev mkpart extended 64s 128s> out 2>&1 || fail=1
--
1.9.0

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,107 @@
From 9f4d2b7c87f99f1dec592111a6a6d267949a2c33 Mon Sep 17 00:00:00 2001
From: Phillip Susi <psusi@ubuntu.com>
Date: Fri, 2 May 2014 21:50:43 -0400
Subject: [PATCH 200/208] libparted: don't detect fat and ntfs boot sectors as
dos MBR
fat and ntfs boot sectors are very similar to an MBR so if you had one of
these filesystems on an unpartitioned disk, parted detected them as a dos
partition table. Have the dos label code call the fat and ntfs filesystem
probes and if they recognize the sector ( their tests are more stringent )
then don't claim it as a dos label.
---
NEWS | 3 +++
libparted/fs/ntfs/ntfs.c | 2 +-
libparted/labels/dos.c | 29 +++++++++++++++++++++++++++++
3 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/NEWS b/NEWS
index ae65106..0c3bad5 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,9 @@ GNU parted NEWS -*- outline -*-
Fix filesystem detection on non 512 byte sector sizes
+ libparted: fat and ntfs boot sectors were misdetected as dos
+ partition tables instead of being treated as a loop label.
+
Fix linux partition sync code to flush partitions > 16
Do not reject a FAT boot sector as invalid because it has no
diff --git a/libparted/fs/ntfs/ntfs.c b/libparted/fs/ntfs/ntfs.c
index 3ba2683..4c154fd 100644
--- a/libparted/fs/ntfs/ntfs.c
+++ b/libparted/fs/ntfs/ntfs.c
@@ -32,7 +32,7 @@
#define NTFS_SIGNATURE "NTFS"
-static PedGeometry*
+PedGeometry*
ntfs_probe (PedGeometry* geom)
{
char *buf = alloca (geom->dev->sector_size);
diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index eff1c03..295fcf3 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -235,12 +235,23 @@ maybe_FAT (unsigned char const *s)
return true;
}
+PedGeometry*
+fat_probe_fat16 (PedGeometry* geom);
+
+PedGeometry*
+fat_probe_fat32 (PedGeometry* geom);
+
+PedGeometry*
+ntfs_probe (PedGeometry* geom);
+
static int
msdos_probe (const PedDevice *dev)
{
PedDiskType* disk_type;
DosRawTable* part_table;
int i;
+ PedGeometry *geom = NULL;
+ PedGeometry *fsgeom = NULL;
PED_ASSERT (dev != NULL);
@@ -257,6 +268,20 @@ msdos_probe (const PedDevice *dev)
if (PED_LE16_TO_CPU (part_table->magic) != MSDOS_MAGIC)
goto probe_fail;
+ geom = ped_geometry_new (dev, 0, dev->length);
+ PED_ASSERT (geom);
+ fsgeom = fat_probe_fat16 (geom);
+ if (fsgeom)
+ goto probe_fail; /* fat fs looks like dos mbr */
+ fsgeom = fat_probe_fat32 (geom);
+ if (fsgeom)
+ goto probe_fail; /* fat fs looks like dos mbr */
+ fsgeom = ntfs_probe (geom);
+ if (fsgeom)
+ goto probe_fail; /* ntfs fs looks like dos mbr */
+ ped_geometry_destroy (geom);
+ geom = NULL;
+
/* If this is a FAT fs, fail here. Checking for the FAT signature
* has some false positives; instead, do what the Linux kernel does
* and ensure that each partition has a boot indicator that is
@@ -303,6 +328,10 @@ msdos_probe (const PedDevice *dev)
return 1;
probe_fail:
+ if (geom)
+ ped_geometry_destroy (geom);
+ if (fsgeom)
+ ped_geometry_destroy (fsgeom);
free (label);
return 0;
}
--
1.9.0

View File

@ -0,0 +1,151 @@
From 36f74e81b1da1ecadc071b3bd2f3a13db0161897 Mon Sep 17 00:00:00 2001
From: Phillip Susi <psusi@ubuntu.com>
Date: Fri, 2 May 2014 21:50:44 -0400
Subject: [PATCH 201/208] libparted: remove old partitions *first* before
adding new ones
"libparted: avoid disturbing partitions" put the remove of the old
partition in second pass. If you simultaneously removed partitions 1
and 2, and created a new partition #1 that overlapped the previous second
partition, the sync would fail because it would try to create the new,
larger partition #1 before removing the old partition #2.
---
libparted/arch/linux.c | 43 ++++++++++++++--------------
tests/Makefile.am | 1 +
tests/t1104-remove-and-add-partition.sh | 50 +++++++++++++++++++++++++++++++++
3 files changed, 72 insertions(+), 22 deletions(-)
create mode 100644 tests/t1104-remove-and-add-partition.sh
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 71f5034..ced06a3 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2855,23 +2855,8 @@ _disk_sync_part_table (PedDisk* disk)
&& start == part->geom.start
&& length == part->geom.length)
{
- ok[i - 1] = 1;
- continue;
- }
- }
- }
- for (i = 1; i <= lpn; i++) {
- PedPartition *part = ped_disk_get_partition (disk, i);
- if (part) {
- unsigned long long length;
- unsigned long long start;
- /* get start and length of existing partition */
- if (get_partition_start_and_length(part,
- &start, &length)
- && start == part->geom.start
- && length == part->geom.length) {
- ok[i - 1] = 1;
/* partition is unchanged, so nothing to do */
+ ok[i - 1] = 1;
continue;
}
}
@@ -2890,12 +2875,26 @@ _disk_sync_part_table (PedDisk* disk)
} while (n_sleep--);
if (!ok[i - 1] && errnums[i - 1] == ENXIO)
ok[i - 1] = 1; /* it already doesn't exist */
- if (part && ok[i - 1]) {
- /* add the (possibly modified or new) partition */
- if (!add_partition (disk, part)) {
- ok[i - 1] = 0;
- errnums[i - 1] = errno;
- }
+ }
+ for (i = 1; i <= lpn; i++) {
+ PedPartition *part = ped_disk_get_partition (disk, i);
+ if (!part)
+ continue;
+ unsigned long long length;
+ unsigned long long start;
+ /* get start and length of existing partition */
+ if (get_partition_start_and_length(part,
+ &start, &length)
+ && start == part->geom.start
+ && length == part->geom.length) {
+ ok[i - 1] = 1;
+ /* partition is unchanged, so nothing to do */
+ continue;
+ }
+ /* add the (possibly modified or new) partition */
+ if (!add_partition (disk, part)) {
+ ok[i - 1] = 0;
+ errnums[i - 1] = errno;
}
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9100a81..e064b8f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -40,6 +40,7 @@ TESTS = \
t0501-duplicate.sh \
t1100-busy-label.sh \
t1101-busy-partition.sh \
+ t1104-remove-and-add-partition.sh \
t1700-probe-fs.sh \
t2200-dos-label-recog.sh \
t2201-pc98-label-recog.sh \
diff --git a/tests/t1104-remove-and-add-partition.sh b/tests/t1104-remove-and-add-partition.sh
new file mode 100644
index 0000000..61cc392
--- /dev/null
+++ b/tests/t1104-remove-and-add-partition.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+# make sure that removing a higher numbered partition and adding a lower
+# one using that space at the same time works
+
+# Copyright (C) 2014 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_prepend_ ../partprobe
+require_root_
+ss=$sector_size_
+
+d1= f1=
+cleanup_fn_()
+{
+ test -n "$d1" && losetup -d "$d1"
+ rm -f "$f1"
+}
+
+f1=$(pwd)/1; d1=$(loop_setup_ "$f1") \
+ || skip_ "is this partition mounted with 'nodev'?"
+
+require_partitionable_loop_device_ $d1
+
+# create one big partition
+parted -s $d1 mklabel msdos mkpart primary ext2 1m 10m || fail=1
+
+# save this table
+dd if=$d1 of=saved count=1 || fail=1
+
+# create two small partitions
+parted -s $d1 mklabel msdos mkpart primary ext2 1m 5m mkpart primary ext2 5m 10m || fail=1
+
+# restore first table and make sure partprobe works
+dd if=saved of=$d1 || fail=1
+partprobe $d1 || fail=1
+
+Exit $fail
--
1.9.0

View File

@ -0,0 +1,63 @@
From dc291e101cf20c6493c262124debab92427c83d9 Mon Sep 17 00:00:00 2001
From: Phillip Susi <psusi@ubuntu.com>
Date: Fri, 2 May 2014 21:50:45 -0400
Subject: [PATCH 202/208] libparted: remove all old partitions, even if new
label allows less
We were limiting partition sync operations to the lesser number allowed
by the device, or the label. This meant that when creating a new label
over an old label that had more partitions than the new one allows, the
higher partitions would not be removed. Use the greater of the two values
for the remove pass, and the lesser for the add.
---
NEWS | 3 +++
libparted/arch/linux.c | 11 +++++++++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/NEWS b/NEWS
index 0c3bad5..a81c049 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,9 @@ GNU parted NEWS -*- outline -*-
Fix filesystem detection on non 512 byte sector sizes
+ libparted: remove all old partitions, even if new label does not allow
+ as many.
+
libparted: fat and ntfs boot sectors were misdetected as dos
partition tables instead of being treated as a loop label.
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index ced06a3..4cbe49b 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2823,9 +2823,10 @@ _disk_sync_part_table (PedDisk* disk)
get_partition_start_and_length = _kernel_get_partition_start_and_length;
}
- /* lpn = largest partition number. */
+ /* lpn = largest partition number.
+ * for remove pass, use greater of device or label limit */
if (ped_disk_get_max_supported_partition_count(disk, &lpn))
- lpn = PED_MIN(lpn, part_range);
+ lpn = PED_MAX(lpn, part_range);
else
lpn = part_range;
@@ -2876,6 +2877,12 @@ _disk_sync_part_table (PedDisk* disk)
if (!ok[i - 1] && errnums[i - 1] == ENXIO)
ok[i - 1] = 1; /* it already doesn't exist */
}
+ /* lpn = largest partition number.
+ * for add pass, use lesser of device or label limit */
+ if (ped_disk_get_max_supported_partition_count(disk, &lpn))
+ lpn = PED_MIN(lpn, part_range);
+ else
+ lpn = part_range;
for (i = 1; i <= lpn; i++) {
PedPartition *part = ped_disk_get_partition (disk, i);
if (!part)
--
1.9.0

View File

@ -0,0 +1,143 @@
From 1707f92e281f226463c39941471e04c55078615b Mon Sep 17 00:00:00 2001
From: Phillip Susi <psusi@ubuntu.com>
Date: Fri, 2 May 2014 21:50:46 -0400
Subject: [PATCH 203/208] libparted: fix loop labels to not vanish
The loop label type was using the existence of a partition as a proxy for
a filesystem being detected, and loop_write() would try to write a loop
signature if there was no filesystem, and erase it if there was. Because
of this, creating a partition without writing a filesystem to it caused
loop_write to erase the loop label.
There seems to be no reason to bother erasing the loop label if it is still
present along with a filesystem signature, so don't bother with this, and
actually check to see if a filesystem is detected in the partition rather
than using the existence of a partition to decide if writing the loop
signature is needed. Finally, since there is no way to preserve the
existence of a partition with no filesystem in it, have loop_read() always
create a partition, even if no filesystem is detected.
---
NEWS | 6 ++++++
libparted/labels/loop.c | 53 ++++++++++++++++++++++---------------------------
2 files changed, 30 insertions(+), 29 deletions(-)
diff --git a/NEWS b/NEWS
index a81c049..3154ef5 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,9 @@ GNU parted NEWS -*- outline -*-
Fix filesystem detection on non 512 byte sector sizes
+ libparted: fix loop labels to not vanish if you don't create
+ a filesystem, and to not return an error syncing when you do.
+
libparted: remove all old partitions, even if new label does not allow
as many.
@@ -105,6 +108,9 @@ GNU parted NEWS -*- outline -*-
** Changes in behavior
+ When creating a loop label, it automatically comes with a partition
+ using the whole disk.
+
parted -l no longer lists device-mapper devices other than
dmraid whole disks.
diff --git a/libparted/labels/loop.c b/libparted/labels/loop.c
index ea8f007..8ebb1f4 100644
--- a/libparted/labels/loop.c
+++ b/libparted/labels/loop.c
@@ -80,7 +80,23 @@ loop_alloc (const PedDevice* dev)
if (dev->length < 256)
return NULL;
- return _ped_disk_alloc ((PedDevice*)dev, &loop_disk_type);
+ PedDisk *disk = _ped_disk_alloc ((PedDevice*)dev, &loop_disk_type);
+ PED_ASSERT (disk != NULL);
+ PedGeometry *geom = ped_geometry_new (dev, 0, dev->length);
+ PED_ASSERT (geom != NULL);
+ PedPartition *part = ped_partition_new (disk, PED_PARTITION_NORMAL,
+ NULL, geom->start, geom->end);
+ PED_ASSERT (part != NULL);
+ ped_geometry_destroy (geom);
+ PedConstraint *constraint_any = ped_constraint_any (dev);
+ if (!ped_disk_add_partition (disk, part, constraint_any))
+ goto error;
+ ped_constraint_destroy (constraint_any);
+ return disk;
+ error:
+ ped_constraint_destroy (constraint_any);
+ ped_disk_destroy (disk);
+ return NULL;
}
static PedDisk*
@@ -118,18 +134,12 @@ loop_read (PedDisk* disk)
int found_sig = !strncmp (buf, LOOP_SIGNATURE, strlen (LOOP_SIGNATURE));
free (buf);
-
- if (found_sig) {
- ped_constraint_destroy (constraint_any);
- return 1;
- }
-
geom = ped_geometry_new (dev, 0, dev->length);
if (!geom)
goto error;
fs_type = ped_file_system_probe (geom);
- if (!fs_type)
+ if (!fs_type && !found_sig)
goto error_free_geom;
part = ped_partition_new (disk, PED_PARTITION_NORMAL,
@@ -137,7 +147,6 @@ loop_read (PedDisk* disk)
ped_geometry_destroy (geom);
if (!part)
goto error;
- part->fs_type = fs_type;
if (!ped_disk_add_partition (disk, part, constraint_any))
goto error;
@@ -156,29 +165,15 @@ static int
loop_write (const PedDisk* disk)
{
size_t buflen = disk->dev->sector_size;
- char *buf = ped_malloc (buflen);
- if (buf == NULL)
- return 0;
-
- if (ped_disk_get_partition (disk, 1)) {
- if (!ped_device_read (disk->dev, buf, 0, 1)) {
- free (buf);
- return 0;
- }
- if (strncmp (buf, LOOP_SIGNATURE, strlen (LOOP_SIGNATURE)) != 0) {
- free (buf);
- return 1;
- }
- memset (buf, 0, strlen (LOOP_SIGNATURE));
- return ped_device_write (disk->dev, buf, 0, 1);
- }
-
+ char *buf = alloca (buflen);
+ PedPartition *part = ped_disk_get_partition (disk, 1);
+ /* if there is already a filesystem on the disk, we don't need to write the signature */
+ if (part && part->fs_type)
+ return 1;
memset (buf, 0, buflen);
strcpy (buf, LOOP_SIGNATURE);
- int write_ok = ped_device_write (disk->dev, buf, 0, 1);
- free (buf);
- return write_ok;
+ return ped_device_write (disk->dev, buf, 0, 1);
}
#endif /* !DISCOVER_ONLY */
--
1.9.0

View File

@ -0,0 +1,45 @@
From a00b5dd9e33241904b01f7b375da57ccd6e777b5 Mon Sep 17 00:00:00 2001
From: Phillip Susi <psusi@ubuntu.com>
Date: Fri, 2 May 2014 21:50:47 -0400
Subject: [PATCH 204/208] libparted: don't create partition on loop label
The loop label represents an unpartitioned disk, but creates
a dummy partition to represent the whole disk. This dummy partition
was actually being loaded into the kernel. Don't do that.
---
NEWS | 4 ++++
libparted/arch/linux.c | 3 +++
2 files changed, 7 insertions(+)
diff --git a/NEWS b/NEWS
index 3154ef5..77cffea 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,10 @@ GNU parted NEWS -*- outline -*-
Fix filesystem detection on non 512 byte sector sizes
+ libparted: The loop label represents an unpartitioned disk, but creates
+ a dummy partition to represent the whole disk. This dummy partition
+ was actually being loaded into the kernel. Don't do that.
+
libparted: fix loop labels to not vanish if you don't create
a filesystem, and to not return an error syncing when you do.
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 4cbe49b..9ae6d64 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2883,6 +2883,9 @@ _disk_sync_part_table (PedDisk* disk)
lpn = PED_MIN(lpn, part_range);
else
lpn = part_range;
+ /* don't actually add partitions for loop */
+ if (strcmp (disk->type->name, "loop") == 0)
+ lpn = 0;
for (i = 1; i <= lpn; i++) {
PedPartition *part = ped_disk_get_partition (disk, i);
if (!part)
--
1.9.0

View File

@ -0,0 +1,44 @@
From 7127a356f205af5ca97370fe6b3674f55c5ec700 Mon Sep 17 00:00:00 2001
From: Phillip Susi <psusi@ubuntu.com>
Date: Fri, 2 May 2014 21:50:48 -0400
Subject: [PATCH 205/208] partprobe: do not skip loop labels
Partprobe was not syncing loop labels. This resulted it failing to remove
existing partitions when switching to a loop label.
---
NEWS | 3 +++
partprobe/partprobe.c | 4 +---
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/NEWS b/NEWS
index 77cffea..d79292f 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,9 @@ GNU parted NEWS -*- outline -*-
Fix filesystem detection on non 512 byte sector sizes
+ partprobe: when called on a disk that has become a loop label,
+ remove any partitions left over from a previous label.
+
libparted: The loop label represents an unpartitioned disk, but creates
a dummy partition to represent the whole disk. This dummy partition
was actually being loaded into the kernel. Don't do that.
diff --git a/partprobe/partprobe.c b/partprobe/partprobe.c
index 4da4fb7..8b744b5 100644
--- a/partprobe/partprobe.c
+++ b/partprobe/partprobe.c
@@ -106,9 +106,7 @@ process_dev (PedDevice* dev)
PedDisk* disk;
disk_type = ped_disk_probe (dev);
- if (disk_type && !strcmp (disk_type->name, "loop"))
- return 1;
- else if (!disk_type) {
+ if (!disk_type) {
/* Partition table not found, so create dummy,
empty one */
disk_type = ped_disk_type_get("msdos");
--
1.9.0

View File

@ -0,0 +1,80 @@
From 998e09d5698777cfbb9b7aacc9059209c7816d60 Mon Sep 17 00:00:00 2001
From: Phillip Susi <psusi@ubuntu.com>
Date: Fri, 2 May 2014 21:50:49 -0400
Subject: [PATCH 206/208] libparted: give correct partition device name on loop
labels
ped_partition_get_path() was returning "/dev/foo1" instead of
"/dev/foo" on loop labels. This caused gparted to run tools like mkfs on
a device node that did not actually exist.
---
NEWS | 3 +++
libparted/arch/linux.c | 10 ++++++++--
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/NEWS b/NEWS
index d79292f..0a04942 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,9 @@ GNU parted NEWS -*- outline -*-
Fix filesystem detection on non 512 byte sector sizes
+ libparted: ped_partition_get_path() was returning "/dev/foo1" instead
+ of "/dev/foo" for loop labels.
+
partprobe: when called on a disk that has become a loop label,
remove any partitions left over from a previous label.
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 9ae6d64..f2e2abc 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -48,6 +48,7 @@
#include "../architecture.h"
#include "dirname.h"
#include "xstrtol.h"
+#include "xalloc.h"
#if ENABLE_NLS
# include <libintl.h>
@@ -2356,6 +2357,9 @@ _device_get_part_path (PedDevice const *dev, int num)
static char*
linux_partition_get_path (const PedPartition* part)
{
+ /* loop label means use the whole disk */
+ if (strcmp (part->disk->type->name, "loop") == 0)
+ return xstrdup (part->disk->dev->path);
return _device_get_part_path (part->disk->dev, part->num);
}
@@ -2424,6 +2428,8 @@ linux_partition_is_busy (const PedPartition* part)
PED_ASSERT (part != NULL);
+ if (strcmp (part->disk->type->name, "loop") == 0)
+ return linux_is_busy (part->disk->dev);
if (_partition_is_mounted (part))
return 1;
if (part->type == PED_PARTITION_EXTENDED) {
@@ -2546,7 +2552,7 @@ _sysfs_ull_entry_from_part(PedPartition const* part, const char *entry,
unsigned long long *val)
{
char path[128];
- char *part_name = linux_partition_get_path(part);
+ char *part_name = _device_get_part_path (part->disk->dev, part->num);
if (!part_name)
return false;
@@ -2581,7 +2587,7 @@ _kernel_get_partition_start_and_length(PedPartition const *part,
PED_ASSERT(start);
PED_ASSERT(length);
- char *dev_name = linux_partition_get_path (part);
+ char *dev_name = _device_get_part_path (part->disk->dev, part->num);
if (!dev_name)
return false;
--
1.9.0

View File

@ -0,0 +1,33 @@
From b83ac74a8b87a770bdd78c7c23731bcc252393e4 Mon Sep 17 00:00:00 2001
From: Phillip Susi <psusi@ubuntu.com>
Date: Fri, 2 May 2014 21:50:50 -0400
Subject: [PATCH 207/208] libparted: don't trash filesystem when writing loop
label
If you deleted the fake partition on a loop label, loop_write() would write
the loop signature to the device, zeroing out all other bytes in the first
sector. When the disk contained an ext[234] filesystem and was using 2k
sectors, this would trash the super block residing in the 1-2kb part of the
sector causing the disk to become unrecognized. Instead, read the existing
sector and only modify the first few bytes that contain the loop label.
---
libparted/labels/loop.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libparted/labels/loop.c b/libparted/labels/loop.c
index 8ebb1f4..98f9f23 100644
--- a/libparted/labels/loop.c
+++ b/libparted/labels/loop.c
@@ -170,7 +170,8 @@ loop_write (const PedDisk* disk)
/* if there is already a filesystem on the disk, we don't need to write the signature */
if (part && part->fs_type)
return 1;
- memset (buf, 0, buflen);
+ if (!ped_device_read (disk->dev, buf, 0, 1))
+ return 0;
strcpy (buf, LOOP_SIGNATURE);
return ped_device_write (disk->dev, buf, 0, 1);
--
1.9.0

View File

@ -0,0 +1,137 @@
From bd4574d9b49ec3e2d73c59dcab7c5f22c2e85c4a Mon Sep 17 00:00:00 2001
From: Phillip Susi <psusi@ubuntu.com>
Date: Fri, 2 May 2014 21:50:51 -0400
Subject: [PATCH 208/208] tests: test loop labels
Verify previous fixes to loop labels.
---
tests/Makefile.am | 1 +
tests/t1102-loop-label.sh | 104 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 105 insertions(+)
create mode 100644 tests/t1102-loop-label.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e064b8f..26226cf 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -40,6 +40,7 @@ TESTS = \
t0501-duplicate.sh \
t1100-busy-label.sh \
t1101-busy-partition.sh \
+ t1102-loop-label.sh \
t1104-remove-and-add-partition.sh \
t1700-probe-fs.sh \
t2200-dos-label-recog.sh \
diff --git a/tests/t1102-loop-label.sh b/tests/t1102-loop-label.sh
new file mode 100644
index 0000000..f5701a3
--- /dev/null
+++ b/tests/t1102-loop-label.sh
@@ -0,0 +1,104 @@
+#!/bin/sh
+# make sure that loop labels work correctly
+# create an actual partition
+
+# Copyright (C) 2013 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_prepend_ ../partprobe
+require_root_
+require_scsi_debug_module_
+ss=$sector_size_
+
+scsi_debug_setup_ sector_size=$ss dev_size_mb=90 > dev-name ||
+ skip_ 'failed to create scsi_debug device'
+dev=$(cat dev-name)
+
+mke2fs -F $dev
+parted -s "$dev" print > out 2>&1 || fail=1
+cat <<EOF > exp
+Model: Linux scsi_debug (scsi)
+Disk DEVICE: 94.4MB
+Sector size (logical/physical): ${ss}B/${ss}B
+Partition Table: loop
+Disk Flags:
+
+Number Start End Size File system Flags
+ 1 0.00B 94.4MB 94.4MB ext2
+
+EOF
+mv out o2 && sed -e "s,$dev,DEVICE,;" o2 > out
+
+compare exp out || fail=1
+parted -s $dev rm 1 || fail=1
+if [ -e ${dev}1 ]; then
+ echo "Partition should not exist on loop device"
+ fail=1
+fi
+partprobe $dev || fail=1
+if [ -e ${dev}1 ]; then
+ echo "Partition should not exist on loop device"
+ fail=1
+fi
+
+mount_point="`pwd`/mnt"
+
+# Be sure to unmount upon interrupt, failure, etc.
+cleanup_fn_() { umount "$mount_point" > /dev/null 2>&1; }
+
+# create mount point dir. and mount the just-created partition on it
+mkdir $mount_point || fail=1
+mount -t ext2 "${dev}" $mount_point || fail=1
+
+# now that a partition is mounted, mklabel attempt must fail
+parted -s "$dev" mklabel msdos > out 2>&1; test $? = 1 || fail=1
+
+# create expected output file
+echo "Error: Partition(s) on $dev are being used." > exp
+compare exp out || fail=1
+
+# make sure partition busy check works ( mklabel checks whole disk )
+parted -s "$dev" rm 1 > out 2>&1; test $? = 1 || fail=1
+# create expected output file
+echo "Error: Partition $dev is being used. You must unmount it before you modify \
+it with Parted." > exp
+compare exp out || fail=1
+
+umount "$mount_point"
+
+# make sure partprobe cleans up stale partition devices
+parted -s $dev mklabel msdos mkpart primary ext2 0% 100% || fail=1
+if [ ! -e ${dev}1 ]; then
+ echo "Partition doesn't exist on loop device"
+ fail=1
+fi
+
+mke2fs -F $dev
+partprobe $dev || fail=1
+if [ -e ${dev}1 ]; then
+ echo "Partition should not exist on loop device"
+ fail=1
+fi
+
+# make sure new loop label removes old partitions > 1
+parted -s $dev mklabel msdos mkpart primary ext2 0% 50% mkpart primary ext2 50% 100% || fail=1
+parted -s $dev mklabel loop || fail=1
+if [ -e ${dev}2 ]; then
+ echo "Partition 2 not removed"
+ fail=1
+fi
+
+Exit $fail
--
1.9.0

View File

@ -4,7 +4,7 @@
Summary: The GNU disk partition manipulation program
Name: parted
Version: 3.1
Release: 23%{?dist}
Release: 24%{?dist}
License: GPLv3+
Group: Applications/System
URL: http://www.gnu.org/software/parted
@ -123,6 +123,18 @@ Patch0097: 0097-libparted-Fix-part-dupe-with-empty-name.patch
Patch0098: 0098-tests-check-name-when-duplicating.patch
Patch0099: 0099-tests-Add-ntfs-vfat-hfsplus-to-t1700-probe-test.patch
Patch0100: 0100-GPT-strings-are-UCS-2LE-not-UTF-16.patch
Patch0101: 0101-libparted-remove-last_usable_if_grown.patch
Patch0102: 0102-tests-fix-t2310-dos-extended-2-sector-min-offset.sh.patch
Patch0103: 0103-Fix-filesystem-detection-on-non-512-byte-sectors.patch
Patch0200: 0104-libparted-don-t-detect-fat-and-ntfs-boot-sectors-as-.patch
Patch0201: 0105-libparted-remove-old-partitions-first-before-adding-.patch
Patch0202: 0106-libparted-remove-all-old-partitions-even-if-new-labe.patch
Patch0203: 0107-libparted-fix-loop-labels-to-not-vanish.patch
Patch0204: 0108-libparted-don-t-create-partition-on-loop-label.patch
Patch0205: 0109-partprobe-do-not-skip-loop-labels.patch
Patch0206: 0110-libparted-give-correct-partition-device-name-on-loop.patch
Patch0207: 0111-libparted-don-t-trash-filesystem-when-writing-loop-l.patch
Patch0208: 0112-tests-test-loop-labels.patch
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: e2fsprogs-devel
@ -261,6 +273,21 @@ fi
%changelog
* Thu May 22 2014 Brian C. Lane <bcl@redhat.com> 3.1-24
- Add some missing patches from master and the loop label fixes
- tests: test loop labels (psusi)
- libparted: don't trash filesystem when writing loop label (psusi)
- libparted: give correct partition device name on loop labels (psusi)
- partprobe: do not skip loop labels (psusi)
- libparted: don't create partition on loop label (psusi)
- libparted: fix loop labels to not vanish (psusi)
- libparted: remove all old partitions, even if new label allows less (psusi)
- libparted: remove old partitions *first* before adding new ones (psusi)
- libparted: don't detect fat and ntfs boot sectors as dos MBR (psusi)
- Fix filesystem detection on non 512 byte sectors (psusi)
- tests: fix t2310-dos-extended-2-sector-min-offset.sh (psusi)
- libparted: remove last_usable_if_grown (psusi)
* Fri May 16 2014 Brian C. Lane <bcl@redhat.com> 3.1-23
- Fix partition naming patch for big endian systems.