summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhillip Susi <psusi@ubuntu.com>2014-05-02 21:18:55 -0400
committerPhillip Susi <psusi@ubuntu.com>2014-05-22 19:56:37 -0400
commit1be70093eb937f34388e06ce3731e5f56f217950 (patch)
treefca9e8d4cf1904755e03aad7568fd1260ab93549
parent7cde99849ed321da2712248bc27c14a954d6b481 (diff)
downloadparted-1be70093eb937f34388e06ce3731e5f56f217950.tar.gz
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.
-rw-r--r--libparted/labels/loop.c3
1 files changed, 2 insertions, 1 deletions
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);