← Back to team overview

usb-creator-hackers team mailing list archive

[Merge] lp:~dmitrij.ledkov/usb-creator/wipeout into lp:usb-creator

 

Dmitrijs Ledkovs has proposed merging lp:~dmitrij.ledkov/usb-creator/wipeout into lp:usb-creator.

Requested reviews:
  usb-creator hackers (usb-creator-hackers)
  Evan Dandrea (ev)
Related bugs:
  Bug #484252 in usb-creator (Ubuntu): "Format action wipes all partitions"
  https://bugs.launchpad.net/ubuntu/+source/usb-creator/+bug/484252

For more details, see:
https://code.launchpad.net/~dmitrij.ledkov/usb-creator/wipeout/+merge/106592

Merge a (modified) patch from bug #484252. This changes the format button to erase selected partition, instead of wiping the whole drive (potential data loss).
-- 
https://code.launchpad.net/~dmitrij.ledkov/usb-creator/wipeout/+merge/106592
Your team usb-creator hackers is requested to review the proposed merge of lp:~dmitrij.ledkov/usb-creator/wipeout into lp:usb-creator.
=== modified file 'bin/usb-creator-helper'
--- bin/usb-creator-helper	2012-05-04 10:43:38 +0000
+++ bin/usb-creator-helper	2012-05-21 08:57:17 +0000
@@ -214,18 +214,29 @@
                                    '/org/freedesktop/UDisks')
         device = udisks.FindDeviceByDeviceFile(device, dbus_interface=DISKS_IFACE)
         dev = bus.get_object(DISKS_IFACE, device)
-        # Use the disk if asked to format a partition.
-        if dev.Get(device, 'device-is-partition', dbus_interface=PROPS_IFACE):
-            device = dev.Get(device, 'partition-slave', dbus_interface=PROPS_IFACE)
-            dev = bus.get_object(DISKS_IFACE, device)
-        dev_file = dev.Get(device, 'device-file', dbus_interface=PROPS_IFACE)
+
         # TODO LOCK
         unmount_all(device)
-        size = dev.Get(device, 'device-size', dbus_interface=PROPS_IFACE)
-        dev.PartitionTableCreate('mbr', [], dbus_interface=DEVICE_IFACE, timeout=600)
-        dev.PartitionCreate(0, size, '0x0c', '', ['boot'], [], 'vfat', [],
-                            dbus_interface=DEVICE_IFACE)
+        # Do NOT use the disk if asked to format a partition.
+        # We still need to obtain the disk device name to zero out the MBR
+        if dev.Get(device, 'device-is-partition', dbus_interface=PROPS_IFACE):
+            # Create the partition
+            dev.PartitionModify('0x0c', '', ['boot'], dbus_interface=DEVICE_IFACE)
+            dev.FilesystemCreate('vfat', [], dbus_interface=DEVICE_IFACE)
+
+            # Get the master device
+            device = dev.Get(device, 'partition-slave', dbus_interface=PROPS_IFACE)
+            dev = bus.get_object(DISKS_IFACE, device)
+        else:
+            # Create a new partition table and a FAT partition.
+            size = dev.Get(device, 'device-size', dbus_interface=PROPS_IFACE)
+            dev.PartitionTableCreate('mbr', [], dbus_interface=DEVICE_IFACE,
+                timeout=600)
+            dev.PartitionCreate(0, size, '0x0c', '', ['boot'], [], 'vfat', [],
+                                dbus_interface=DEVICE_IFACE)
+
         # Zero out the MBR.  Will require fancy privileges.
+        dev_file = dev.Get(device, 'device-file', dbus_interface=PROPS_IFACE)
         popen(['dd', 'if=/dev/zero', 'of=%s' % dev_file, 'bs=446', 'count=1'])
         # TODO UNLOCK
 

=== modified file 'usbcreator/backends/udisks/backend.py'
--- usbcreator/backends/udisks/backend.py	2012-05-04 10:33:25 +0000
+++ usbcreator/backends/udisks/backend.py	2012-05-21 08:57:17 +0000
@@ -284,10 +284,6 @@
         try:
             dk = self.bus.get_object(DISKS_IFACE, device)
             dev = dk.Get(device, 'device-file', dbus_interface=PROPS_IFACE)
-            if dk.Get(dev, 'device-is-partition', dbus_interface=PROPS_IFACE):
-                dev = dk.Get(dev, 'partition-slave', dbus_interface=PROPS_IFACE)
-                dk = self.bus.get_object(DISKS_IFACE, dev)
-                dev = dk.Get(device, 'device-file', dbus_interface=PROPS_IFACE)
             p = self.targets[device]['parent']
             if p and p in self.targets:
                 self.formatting.append(p)


Follow ups