Merge lp:~yuningdodo/usb-creator/usb-creator.lp1300361-format-parent-device-to-erase-correctly into lp:usb-creator

Proposed by Yu Ning
Status: Rejected
Rejected by: Mathieu Trudel-Lapierre
Proposed branch: lp:~yuningdodo/usb-creator/usb-creator.lp1300361-format-parent-device-to-erase-correctly
Merge into: lp:usb-creator
Diff against target: 96 lines (+33/-26)
2 files modified
bin/usb-creator-helper (+26/-26)
debian/changelog (+7/-0)
To merge this branch: bzr merge lp:~yuningdodo/usb-creator/usb-creator.lp1300361-format-parent-device-to-erase-correctly
Reviewer Review Type Date Requested Status
Yu Ning (community) Disapprove
usb-creator hackers Pending
Review via email: mp+225799@code.launchpad.net

Description of the change

* usb-creator-helper: Always format the parent device to fix the issue that
  usb stick fail to be erased if there is no partition table. (LP: #1300361)

To verify this patch, create an empty usb stick with dd:

    sudo dd if=/dev/zero of=/dev/sdb bs=1M count=1

Then erase it with usb-creator, the operation should complete successfully. However there is also bug #1318954 that would disturb the erase operation, on my own box I have to modify util-linux to ignore bug #1318954 to verify this patch.

To post a comment you must log in.
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

I thought that resolution of bug #1318954 would be sufficient.

From reading below, I'm not sure we are not going to regress the following past regression:
given a usb-stick with two partitions, formatting one of the partitions, should preserve all data on the other partition.

Will test that when I get my hands on a usb-stick tomorrow.

Thanks for this patch.

Revision history for this message
Yu Ning (yuningdodo) wrote :

Thanks for the comments. So if I understand correctly it's designed to format only the selected partition but not the whole disk? Personally I thought the "format the whole disk" is a useful feature to some people like me, could we add an GUI option to set what to format, the partition or the disk?

Revision history for this message
Yu Ning (yuningdodo) wrote :

This patch is no longer needed since the issue is already fixed.

review: Disapprove

Unmerged revisions

443. By Yu Ning

usb-creator-helper: Always format the parent device to fix the issue that
usb stick fail to be erased if there is no partition table. (LP: #1300361)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/usb-creator-helper'
2--- bin/usb-creator-helper 2014-06-16 09:26:40 +0000
3+++ bin/usb-creator-helper 2014-07-07 10:12:25 +0000
4@@ -43,11 +43,13 @@
5
6 def _get_parent_object(udisks, device_name):
7 obj = udisks.get_object(_get_object_path_from_device(device_name))
8- if obj.get_partition_table():
9+ partition = obj.get_partition()
10+ if not partition:
11 return obj
12- partition = obj.get_partition()
13 parent = partition.get_cached_property('Table').get_string()
14- return udisks.get_object(parent)
15+ if udisks.get_object(parent):
16+ return udisks.get_object(parent)
17+ return obj
18
19 def unmount_all(udisks, parent):
20 '''Unmounts the device or any partitions of the device.'''
21@@ -214,8 +216,7 @@
22 # TODO evand 2009-08-25: Needs a confirmation dialog.
23 # XXX test with a device that doesn't have a partition table.
24 udisks = UDisks.Client.new_sync(None)
25- dev = udisks.get_object(device)
26- parent_dev = _get_parent_object(udisks, device)
27+ dev = _get_parent_object(udisks, device)
28
29 if not allow_system_internal:
30 check_system_internal(dev)
31@@ -224,30 +225,29 @@
32 unmount_all(udisks, dev)
33 # Do NOT use the disk if asked to format a partition.
34 # We still need to obtain the disk device name to zero out the MBR
35- part = dev.get_partition()
36 block = dev.get_block()
37- if part:
38- # Create the partition
39- #type, label, flags
40- boot_dos_flag=64
41- part.call_set_type_sync('0x0c', no_options, None)
42- part.call_set_flags_sync(boot_dos_flag, no_options, None)
43- block.call_format_sync('vfat', GLib.Variant('a{sv}', {'label': GLib.Variant('s', '')}), None)
44- else:
45- # Create a new partition table and a FAT partition.
46- # Is this correct call to create partition table ?!
47- block.call_format_sync('dos', GLib.Variant('a{sv}', {'erase': GLib.Variant('s', 'zero')}), None)
48- size = block.get_cached_property('Size').get_uint64()
49- table = dev.get_partition_table()
50- partition = table.call_create_partition_sync(0, size, '0x0c', '', no_options, None)
51- obj = udisks.get_object(partition)
52- block = obj.get_block()
53- block.call_format_sync('vfat', GLib.Variant('a{sv}', {'label': GLib.Variant('s', '')}), None)
54+ device = block.get_cached_property('Device').get_bytestring().decode('utf-8')
55+
56+ # Create a new partition table and a FAT partition.
57+ # Is this correct call to create partition table ?!
58+ block.call_format_sync('dos', no_options, None)
59+ size = block.get_cached_property('Size').get_uint64()
60+
61+ # FIXME: dev.get_partition_table() will return None unless we get dev
62+ # with a new client. Is there any better way for it?
63+ udisks = UDisks.Client.new_sync(None)
64+ dev = _get_parent_object(udisks, device)
65+
66+ table = dev.get_partition_table()
67+ partition = table.call_create_partition_sync(0, size, '0x0c', '', no_options, None)
68+
69+ udisks = UDisks.Client.new_sync(None)
70+ obj = udisks.get_object(partition)
71+ block = obj.get_block()
72+ block.call_format_sync('vfat', GLib.Variant('a{sv}', {'label': GLib.Variant('s', '')}), None)
73
74 # Zero out the MBR. Will require fancy privileges.
75- parent_block = parent_dev.get_block()
76- parent_file = parent_block.get_cached_property('Device').get_bytestring().decode('utf-8')
77- popen(['dd', 'if=/dev/zero', 'of=%s' % parent_file, 'bs=446', 'count=1'])
78+ popen(['dd', 'if=/dev/zero', 'of=%s' % device, 'bs=446', 'count=1'])
79 # TODO UNLOCK
80
81 @dbus.service.method(USBCREATOR_IFACE, in_signature='ssb', out_signature='',
82
83=== modified file 'debian/changelog'
84--- debian/changelog 2014-06-16 09:26:56 +0000
85+++ debian/changelog 2014-07-07 10:12:25 +0000
86@@ -1,3 +1,10 @@
87+usb-creator (0.2.59) UNRELEASED; urgency=medium
88+
89+ * usb-creator-helper: Always format the parent device to fix the issue that
90+ usb stick fail to be erased if there is no partition table. (LP: #1300361)
91+
92+ -- Yu Ning <ning.yu@canonical.com> Mon, 07 Jul 2014 17:53:07 +0800
93+
94 usb-creator (0.2.58) utopic; urgency=medium
95
96 * Use "zero" erase type instead of the invalid "". (LP: #1294877)

Subscribers

People subscribed via source and target branches

to all changes: