Merge lp:~yuningdodo/ubuntu/trusty/util-linux/util-linux.backport-wipefs-partition-table-erasing-support into lp:ubuntu/trusty-updates/util-linux
- Trusty (14.04)
- util-linux.backport-wipefs-partition-table-erasing-support
- Merge into trusty-updates
Status: | Needs review |
---|---|
Proposed branch: | lp:~yuningdodo/ubuntu/trusty/util-linux/util-linux.backport-wipefs-partition-table-erasing-support |
Merge into: | lp:ubuntu/trusty-updates/util-linux |
Diff against target: |
710 lines (+338/-140) 11 files modified
debian/changelog (+17/-0) libblkid/src/blkid.h.in (+3/-0) libblkid/src/blkid.sym (+8/-0) libblkid/src/blkidP.h (+2/-0) libblkid/src/partitions/gpt.c (+9/-0) libblkid/src/partitions/partitions.c (+12/-4) libblkid/src/partitions/ultrix.c (+10/-0) libblkid/src/probe.c (+133/-0) libblkid/src/superblocks/superblocks.c (+0/-15) libblkid/src/superblocks/superblocks.h (+0/-2) misc-utils/wipefs.c (+144/-119) |
To merge this branch: | bzr merge lp:~yuningdodo/ubuntu/trusty/util-linux/util-linux.backport-wipefs-partition-table-erasing-support |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mathieu Trudel-Lapierre | Needs Information | ||
Review via email: mp+237898@code.launchpad.net |
Commit message
Description of the change
* wipefs: backport partition table erasing support from
git:
- 6611a3dd783006f
wipefs: improve -a, use blkid_do_wipe()
- 2b89be6c802bdbd
libblkid: add blkid_do_wipe()
- 476b508e043b6b4
libblkid: add BLKID_PARTS_MAGIC to blkid_do_wipe() docs
- 3c83b3b22f33fc7
libblkid: add BLKID_PARTS_MAGIC
- 44765fdd841fb13
libblkid: export info about PT magic strings
Timo Jyrinki (timo-jyrinki) wrote : | # |
To be noted though for any core dev considering this, this version of the backport is much less invasive than the previous one https:/
Timo Jyrinki (timo-jyrinki) wrote : | # |
Hmm, reopening. As noted on the bug, the disk utility program would still need this.
Mathieu Trudel-Lapierre (cyphermox) wrote : | # |
How does this affect https:/
It also seems to me like some of these commits probably aren't strictly required to support the changes to wipefs, since that's what is at stake here. Do you have a deep enough understanding of the changes here to know exactly why each of these commits are required? It looks to me like only a subset of these changes might be required to fix the targetted bug, but I only looked really quickly.
For example, it seems to me like the fix should work without the last three commits, and just the addition of blkid_do_wipe in libblkid/
Yu Ning (yuningdodo) wrote : | # |
Thanks for the review.
I checked the ubuntu branch, lp:ubuntu/util-linux, bug #1046665 was firstly fixed in rev90 by retrying the operation several times. Later in rev110 the code was entirely merged with debian experimental, and the previous retry was now implemented by calling blkid_do_probe() multiple times until it returns false. What I proposed to do for the trusty branch is similar, first retire the previous retrying logic then introduce the new implementation, so I believe it will not regress bug #1046665. About libblkid, here is a summary of what have been changed:
* new flag: BLKID_PARTS_MAGIC.
* new public method blkid_probe_wipe().
* declaration of blkid_probe_
Besides these API changes, there are also some internal changes. I think they won't break the API backward compatibility of libblkid.
About the picked patches, I can't say I have a deep enough understanding about the patches, actually I picked them based on the test results of this simple testcase:
dd if=/dev/zero of=data bs=1M count=4
parted data --script -- mklabel msdos
parted data --script -- mkpart primary fat16 0 -0
wipefs -a data # it's expected to output "2 bytes were erased at offset 0x000001fe (dos): 55 aa"
With the first two patches it's not enough to erase the "55aa" signature. In fact the key patch is the last one, 44765fdd841fb13
Unmerged revisions
- 114. By Yu Ning
-
44765fdd841fb13
69cf68f360131ed 076f3a2771 libblkid: export info about PT magic strings - 113. By Yu Ning
-
3c83b3b22f33fc7
b17b504158e4a4d b7b567bbe8 libblkid: add BLKID_PARTS_MAGIC - 112. By Yu Ning
-
476b508e043b6b4
c71d84b4f2fdeef fa68c204b3 libblkid: add BLKID_PARTS_MAGIC to blkid_do_wipe() docs - 111. By Yu Ning
-
2b89be6c802bdbd
f6830dbd060c96e 33f179b135 libblkid: add blkid_do_wipe() - 110. By Yu Ning
-
* wipefs: backport partition table erasing support from
git://git.debian. org/git/ collab- maint/pkg- util-linux. git
- 6611a3dd783006fd8c6b924a76c482 0287278d36
wipefs: improve -a, use blkid_do_wipe()
Preview Diff
1 | === modified file 'debian/changelog' | |||
2 | --- debian/changelog 2014-06-02 13:36:20 +0000 | |||
3 | +++ debian/changelog 2014-10-10 06:30:46 +0000 | |||
4 | @@ -1,3 +1,20 @@ | |||
5 | 1 | util-linux (2.20.1-5.1ubuntu20.1~test1) UNRELEASED; urgency=medium | ||
6 | 2 | |||
7 | 3 | * wipefs: backport partition table erasing support from | ||
8 | 4 | git://git.debian.org/git/collab-maint/pkg-util-linux.git | ||
9 | 5 | - 6611a3dd783006fd8c6b924a76c4820287278d36 | ||
10 | 6 | wipefs: improve -a, use blkid_do_wipe() | ||
11 | 7 | - 2b89be6c802bdbdf6830dbd060c96e33f179b135 | ||
12 | 8 | libblkid: add blkid_do_wipe() | ||
13 | 9 | - 476b508e043b6b4c71d84b4f2fdeeffa68c204b3 | ||
14 | 10 | libblkid: add BLKID_PARTS_MAGIC to blkid_do_wipe() docs | ||
15 | 11 | - 3c83b3b22f33fc7b17b504158e4a4db7b567bbe8 | ||
16 | 12 | libblkid: add BLKID_PARTS_MAGIC | ||
17 | 13 | - 44765fdd841fb1369cf68f360131ed076f3a2771 | ||
18 | 14 | libblkid: export info about PT magic strings | ||
19 | 15 | |||
20 | 16 | -- Yu Ning <ning.yu@canonical.com> Fri, 10 Oct 2014 14:16:52 +0800 | ||
21 | 17 | |||
22 | 1 | util-linux (2.20.1-5.1ubuntu20.1) trusty-proposed; urgency=medium | 18 | util-linux (2.20.1-5.1ubuntu20.1) trusty-proposed; urgency=medium |
23 | 2 | 19 | ||
24 | 3 | * fstrim-all: Fix typo that made unwanted stderr output from hdparm appear. | 20 | * fstrim-all: Fix typo that made unwanted stderr output from hdparm appear. |
25 | 4 | 21 | ||
26 | === modified file 'libblkid/src/blkid.h.in' | |||
27 | --- libblkid/src/blkid.h.in 2011-11-03 15:38:23 +0000 | |||
28 | +++ libblkid/src/blkid.h.in 2014-10-10 06:30:46 +0000 | |||
29 | @@ -278,6 +278,7 @@ | |||
30 | 278 | /* partitions probing flags */ | 278 | /* partitions probing flags */ |
31 | 279 | #define BLKID_PARTS_FORCE_GPT (1 << 1) | 279 | #define BLKID_PARTS_FORCE_GPT (1 << 1) |
32 | 280 | #define BLKID_PARTS_ENTRY_DETAILS (1 << 2) | 280 | #define BLKID_PARTS_ENTRY_DETAILS (1 << 2) |
33 | 281 | #define BLKID_PARTS_MAGIC (1 << 3) | ||
34 | 281 | extern int blkid_probe_set_partitions_flags(blkid_probe pr, int flags); | 282 | extern int blkid_probe_set_partitions_flags(blkid_probe pr, int flags); |
35 | 282 | 283 | ||
36 | 283 | /* binary interface */ | 284 | /* binary interface */ |
37 | @@ -319,6 +320,8 @@ | |||
38 | 319 | const char **data, size_t *len); | 320 | const char **data, size_t *len); |
39 | 320 | extern int blkid_probe_has_value(blkid_probe pr, const char *name); | 321 | extern int blkid_probe_has_value(blkid_probe pr, const char *name); |
40 | 321 | 322 | ||
41 | 323 | extern int blkid_do_wipe(blkid_probe pr, int dryrun); | ||
42 | 324 | |||
43 | 322 | /* | 325 | /* |
44 | 323 | * Deprecated functions/macros | 326 | * Deprecated functions/macros |
45 | 324 | */ | 327 | */ |
46 | 325 | 328 | ||
47 | === modified file 'libblkid/src/blkid.sym' | |||
48 | --- libblkid/src/blkid.sym 2011-11-03 15:38:23 +0000 | |||
49 | +++ libblkid/src/blkid.sym 2014-10-10 06:30:46 +0000 | |||
50 | @@ -140,3 +140,11 @@ | |||
51 | 140 | blkid_superblocks_get_name; | 140 | blkid_superblocks_get_name; |
52 | 141 | } BLKID_2.18; | 141 | } BLKID_2.18; |
53 | 142 | 142 | ||
54 | 143 | /* | ||
55 | 144 | * symbols since util-linux 2.21 | ||
56 | 145 | */ | ||
57 | 146 | BLKID_2.21 { | ||
58 | 147 | global: | ||
59 | 148 | blkid_do_wipe; | ||
60 | 149 | } BLKID_2.20; | ||
61 | 150 | |||
62 | 143 | 151 | ||
63 | === modified file 'libblkid/src/blkidP.h' | |||
64 | --- libblkid/src/blkidP.h 2011-11-03 15:38:23 +0000 | |||
65 | +++ libblkid/src/blkidP.h 2014-10-10 06:30:46 +0000 | |||
66 | @@ -426,6 +426,8 @@ | |||
67 | 426 | const char *fmt, va_list ap); | 426 | const char *fmt, va_list ap); |
68 | 427 | extern int blkid_probe_sprintf_value(blkid_probe pr, const char *name, | 427 | extern int blkid_probe_sprintf_value(blkid_probe pr, const char *name, |
69 | 428 | const char *fmt, ...); | 428 | const char *fmt, ...); |
70 | 429 | extern int blkid_probe_set_magic(blkid_probe pr, blkid_loff_t offset, | ||
71 | 430 | size_t len, unsigned char *magic); | ||
72 | 429 | 431 | ||
73 | 430 | extern void blkid_unparse_uuid(const unsigned char *uuid, char *str, size_t len); | 432 | extern void blkid_unparse_uuid(const unsigned char *uuid, char *str, size_t len); |
74 | 431 | extern size_t blkid_rtrim_whitespace(unsigned char *str); | 433 | extern size_t blkid_rtrim_whitespace(unsigned char *str); |
75 | 432 | 434 | ||
76 | === modified file 'libblkid/src/partitions/gpt.c' | |||
77 | --- libblkid/src/partitions/gpt.c 2011-11-03 15:38:23 +0000 | |||
78 | +++ libblkid/src/partitions/gpt.c 2014-10-10 06:30:46 +0000 | |||
79 | @@ -26,6 +26,7 @@ | |||
80 | 26 | 26 | ||
81 | 27 | /* Signature - “EFI PART” */ | 27 | /* Signature - “EFI PART” */ |
82 | 28 | #define GPT_HEADER_SIGNATURE 0x5452415020494645ULL | 28 | #define GPT_HEADER_SIGNATURE 0x5452415020494645ULL |
83 | 29 | #define GPT_HEADER_SIGNATURE_STR "EFI PART" | ||
84 | 29 | 30 | ||
85 | 30 | /* basic types */ | 31 | /* basic types */ |
86 | 31 | typedef uint16_t efi_char16_t; | 32 | typedef uint16_t efi_char16_t; |
87 | @@ -326,6 +327,14 @@ | |||
88 | 326 | if (!tab) | 327 | if (!tab) |
89 | 327 | goto err; | 328 | goto err; |
90 | 328 | 329 | ||
91 | 330 | blkid_probe_set_magic(pr, lba << 9, | ||
92 | 331 | sizeof(GPT_HEADER_SIGNATURE_STR) - 1, | ||
93 | 332 | (unsigned char *) GPT_HEADER_SIGNATURE_STR); | ||
94 | 333 | |||
95 | 334 | blkid_probe_set_magic(pr, lba << 9, | ||
96 | 335 | sizeof(GPT_HEADER_SIGNATURE_STR) - 1, | ||
97 | 336 | (unsigned char *) GPT_HEADER_SIGNATURE_STR); | ||
98 | 337 | |||
99 | 329 | ssf = blkid_probe_get_sectorsize(pr) / 512; | 338 | ssf = blkid_probe_get_sectorsize(pr) / 512; |
100 | 330 | 339 | ||
101 | 331 | fu = le64_to_cpu(h->first_usable_lba); | 340 | fu = le64_to_cpu(h->first_usable_lba); |
102 | 332 | 341 | ||
103 | === modified file 'libblkid/src/partitions/partitions.c' | |||
104 | --- libblkid/src/partitions/partitions.c 2011-11-03 15:38:23 +0000 | |||
105 | +++ libblkid/src/partitions/partitions.c 2014-10-10 06:30:46 +0000 | |||
106 | @@ -530,15 +530,17 @@ | |||
107 | 530 | return 1; | 530 | return 1; |
108 | 531 | } | 531 | } |
109 | 532 | 532 | ||
111 | 533 | static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id) | 533 | static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id, |
112 | 534 | struct blkid_chain *chn) | ||
113 | 534 | { | 535 | { |
114 | 535 | const struct blkid_idmag *mag; | 536 | const struct blkid_idmag *mag; |
115 | 537 | blkid_loff_t off; | ||
116 | 536 | int rc = 1; /* = nothing detected */ | 538 | int rc = 1; /* = nothing detected */ |
117 | 537 | 539 | ||
118 | 538 | if (pr->size <= 0 || (id->minsz && id->minsz > pr->size)) | 540 | if (pr->size <= 0 || (id->minsz && id->minsz > pr->size)) |
119 | 539 | goto nothing; /* the device is too small */ | 541 | goto nothing; /* the device is too small */ |
120 | 540 | 542 | ||
122 | 541 | if (blkid_probe_get_idmag(pr, id, NULL, &mag)) | 543 | if (blkid_probe_get_idmag(pr, id, &off, &mag)) |
123 | 542 | goto nothing; | 544 | goto nothing; |
124 | 543 | 545 | ||
125 | 544 | /* final check by probing function */ | 546 | /* final check by probing function */ |
126 | @@ -549,9 +551,15 @@ | |||
127 | 549 | if (rc == -1) { | 551 | if (rc == -1) { |
128 | 550 | /* reset after error */ | 552 | /* reset after error */ |
129 | 551 | reset_partlist(blkid_probe_get_partlist(pr)); | 553 | reset_partlist(blkid_probe_get_partlist(pr)); |
130 | 554 | if (chn && !chn->binary) | ||
131 | 555 | blkid_probe_chain_reset_vals(pr, chn); | ||
132 | 552 | DBG(DEBUG_LOWPROBE, printf( | 556 | DBG(DEBUG_LOWPROBE, printf( |
133 | 553 | "%s probefunc failed\n", id->name)); | 557 | "%s probefunc failed\n", id->name)); |
134 | 554 | } | 558 | } |
135 | 559 | if (rc == 0 && mag && chn && !chn->binary) | ||
136 | 560 | blkid_probe_set_magic(pr, off, mag->len, | ||
137 | 561 | (unsigned char *) mag->magic); | ||
138 | 562 | |||
139 | 555 | DBG(DEBUG_LOWPROBE, printf( | 563 | DBG(DEBUG_LOWPROBE, printf( |
140 | 556 | "%s: <--- (rc = %d)\n", id->name, rc)); | 564 | "%s: <--- (rc = %d)\n", id->name, rc)); |
141 | 557 | } | 565 | } |
142 | @@ -594,7 +602,7 @@ | |||
143 | 594 | continue; | 602 | continue; |
144 | 595 | 603 | ||
145 | 596 | /* apply checks from idinfo */ | 604 | /* apply checks from idinfo */ |
147 | 597 | if (idinfo_probe(pr, idinfos[i]) != 0) | 605 | if (idinfo_probe(pr, idinfos[i], chn) != 0) |
148 | 598 | continue; | 606 | continue; |
149 | 599 | 607 | ||
150 | 600 | name = idinfos[i]->name; | 608 | name = idinfos[i]->name; |
151 | @@ -678,7 +686,7 @@ | |||
152 | 678 | 686 | ||
153 | 679 | blkid_probe_set_partlist(prc, ls); | 687 | blkid_probe_set_partlist(prc, ls); |
154 | 680 | 688 | ||
156 | 681 | rc = idinfo_probe(prc, id); | 689 | rc = idinfo_probe(prc, id, blkid_probe_get_chain(pr)); |
157 | 682 | 690 | ||
158 | 683 | blkid_probe_set_partlist(prc, NULL); | 691 | blkid_probe_set_partlist(prc, NULL); |
159 | 684 | blkid_partlist_set_parent(ls, NULL); | 692 | blkid_partlist_set_parent(ls, NULL); |
160 | 685 | 693 | ||
161 | === modified file 'libblkid/src/partitions/ultrix.c' | |||
162 | --- libblkid/src/partitions/ultrix.c 2011-11-03 15:38:23 +0000 | |||
163 | +++ libblkid/src/partitions/ultrix.c 2014-10-10 06:30:46 +0000 | |||
164 | @@ -15,7 +15,9 @@ | |||
165 | 15 | #include "partitions.h" | 15 | #include "partitions.h" |
166 | 16 | 16 | ||
167 | 17 | #define ULTRIX_MAXPARTITIONS 8 | 17 | #define ULTRIX_MAXPARTITIONS 8 |
168 | 18 | |||
169 | 18 | #define ULTRIX_MAGIC 0x032957 | 19 | #define ULTRIX_MAGIC 0x032957 |
170 | 20 | #define ULTRIX_MAGIC_STR "\x02\x29\x57" | ||
171 | 19 | 21 | ||
172 | 20 | /* sector with partition table */ | 22 | /* sector with partition table */ |
173 | 21 | #define ULTRIX_SECTOR ((16384 - sizeof(struct ultrix_disklabel)) >> 9) | 23 | #define ULTRIX_SECTOR ((16384 - sizeof(struct ultrix_disklabel)) >> 9) |
174 | @@ -62,6 +64,14 @@ | |||
175 | 62 | if (!tab) | 64 | if (!tab) |
176 | 63 | goto err; | 65 | goto err; |
177 | 64 | 66 | ||
178 | 67 | blkid_probe_set_magic(pr, (ULTRIX_SECTOR << 9) + ULTRIX_OFFSET, | ||
179 | 68 | sizeof(ULTRIX_MAGIC_STR) - 1, | ||
180 | 69 | (unsigned char *) ULTRIX_MAGIC_STR); | ||
181 | 70 | |||
182 | 71 | blkid_probe_set_magic(pr, (ULTRIX_SECTOR << 9) + ULTRIX_OFFSET, | ||
183 | 72 | sizeof(ULTRIX_MAGIC_STR) - 1, | ||
184 | 73 | (unsigned char *) ULTRIX_MAGIC_STR); | ||
185 | 74 | |||
186 | 65 | for (i = 0; i < ULTRIX_MAXPARTITIONS; i++) { | 75 | for (i = 0; i < ULTRIX_MAXPARTITIONS; i++) { |
187 | 66 | if (!l->pt_part[i].pi_nblocks) | 76 | if (!l->pt_part[i].pi_nblocks) |
188 | 67 | blkid_partlist_increment_partno(ls); | 77 | blkid_partlist_increment_partno(ls); |
189 | 68 | 78 | ||
190 | === modified file 'libblkid/src/probe.c' | |||
191 | --- libblkid/src/probe.c 2011-11-03 15:38:23 +0000 | |||
192 | +++ libblkid/src/probe.c 2014-10-10 06:30:46 +0000 | |||
193 | @@ -109,6 +109,7 @@ | |||
194 | 109 | #endif | 109 | #endif |
195 | 110 | 110 | ||
196 | 111 | #include "blkidP.h" | 111 | #include "blkidP.h" |
197 | 112 | #include "writeall.h" | ||
198 | 112 | 113 | ||
199 | 113 | /* chains */ | 114 | /* chains */ |
200 | 114 | extern const struct blkid_chaindrv superblocks_drv; | 115 | extern const struct blkid_chaindrv superblocks_drv; |
201 | @@ -914,6 +915,105 @@ | |||
202 | 914 | } | 915 | } |
203 | 915 | 916 | ||
204 | 916 | /** | 917 | /** |
205 | 918 | * blkid_do_wipe: | ||
206 | 919 | * @pr: prober | ||
207 | 920 | * @dryrun: if TRUE then don't touch the device. | ||
208 | 921 | * | ||
209 | 922 | * This function erases the current signature detected by @pr. The @pr has to | ||
210 | 923 | * be open in O_RDWR mode, BLKID_SUBLKS_MAGIC or/and BLKID_PARTS_MAGIC flags | ||
211 | 924 | * has to be enabled. | ||
212 | 925 | * | ||
213 | 926 | * After successful signature removing the @pr prober will be moved one step | ||
214 | 927 | * back and the next blkid_do_probe() call will again call previously called | ||
215 | 928 | * probing function. | ||
216 | 929 | * | ||
217 | 930 | * <example> | ||
218 | 931 | * <title>wipe all filesystems or raids from the device</title> | ||
219 | 932 | * <programlisting> | ||
220 | 933 | * fd = open(devname, O_RDWR); | ||
221 | 934 | * blkid_probe_set_device(pr, fd, 0, 0); | ||
222 | 935 | * | ||
223 | 936 | * blkid_probe_enable_superblocks(pr, 1); | ||
224 | 937 | * blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC); | ||
225 | 938 | * | ||
226 | 939 | * while (blkid_do_probe(pr) == 0) | ||
227 | 940 | * blkid_do_wipe(pr, FALSE); | ||
228 | 941 | * </programlisting> | ||
229 | 942 | * </example> | ||
230 | 943 | * | ||
231 | 944 | * Returns: 0 on success, 1 when probing is done and -1 in case of error. | ||
232 | 945 | */ | ||
233 | 946 | int blkid_do_wipe(blkid_probe pr, int dryrun) | ||
234 | 947 | { | ||
235 | 948 | const char *off = NULL; | ||
236 | 949 | size_t len = 0; | ||
237 | 950 | loff_t offset, l; | ||
238 | 951 | char buf[BUFSIZ]; | ||
239 | 952 | int fd, rc; | ||
240 | 953 | struct blkid_chain *chn; | ||
241 | 954 | |||
242 | 955 | if (!pr) | ||
243 | 956 | return -1; | ||
244 | 957 | |||
245 | 958 | chn = pr->cur_chain; | ||
246 | 959 | if (!chn) | ||
247 | 960 | return -1; | ||
248 | 961 | |||
249 | 962 | switch (chn->driver->id) { | ||
250 | 963 | case BLKID_CHAIN_SUBLKS: | ||
251 | 964 | rc = blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL); | ||
252 | 965 | if (!rc) | ||
253 | 966 | rc = blkid_probe_lookup_value(pr, "SBMAGIC", NULL, &len); | ||
254 | 967 | break; | ||
255 | 968 | case BLKID_CHAIN_PARTS: | ||
256 | 969 | rc = blkid_probe_lookup_value(pr, "PTMAGIC_OFFSET", &off, NULL); | ||
257 | 970 | if (!rc) | ||
258 | 971 | rc = blkid_probe_lookup_value(pr, "PTMAGIC", NULL, &len); | ||
259 | 972 | break; | ||
260 | 973 | default: | ||
261 | 974 | return 0; | ||
262 | 975 | } | ||
263 | 976 | |||
264 | 977 | if (rc || len == 0 || off == NULL) | ||
265 | 978 | return 0; | ||
266 | 979 | |||
267 | 980 | offset = strtoll(off, NULL, 10); | ||
268 | 981 | fd = blkid_probe_get_fd(pr); | ||
269 | 982 | if (fd < 0) | ||
270 | 983 | return -1; | ||
271 | 984 | |||
272 | 985 | if (len > sizeof(buf)) | ||
273 | 986 | len = sizeof(buf); | ||
274 | 987 | |||
275 | 988 | DBG(DEBUG_LOWPROBE, printf( | ||
276 | 989 | "wiping [offset=0x%jx, len=%zd, chain=%s, idx=%d, dryrun=%s]\n", | ||
277 | 990 | offset, len, chn->driver->name, chn->idx, dryrun ? "yes" : "not")); | ||
278 | 991 | |||
279 | 992 | l = lseek(fd, offset, SEEK_SET); | ||
280 | 993 | if (l == (off_t) -1) | ||
281 | 994 | return -1; | ||
282 | 995 | |||
283 | 996 | memset(buf, 0, len); | ||
284 | 997 | |||
285 | 998 | if (!dryrun && len) { | ||
286 | 999 | if (write_all(fd, buf, len)) | ||
287 | 1000 | return -1; | ||
288 | 1001 | fsync(fd); | ||
289 | 1002 | |||
290 | 1003 | blkid_probe_reset_buffer(pr); | ||
291 | 1004 | |||
292 | 1005 | if (chn->idx >= 0) { | ||
293 | 1006 | chn->idx--; | ||
294 | 1007 | DBG(DEBUG_LOWPROBE, | ||
295 | 1008 | printf("wipe: moving %s chain index to %d\n", | ||
296 | 1009 | chn->driver->name, | ||
297 | 1010 | chn->idx)); | ||
298 | 1011 | } | ||
299 | 1012 | } | ||
300 | 1013 | return 0; | ||
301 | 1014 | } | ||
302 | 1015 | |||
303 | 1016 | /** | ||
304 | 917 | * blkid_do_safeprobe: | 1017 | * blkid_do_safeprobe: |
305 | 918 | * @pr: prober | 1018 | * @pr: prober |
306 | 919 | * | 1019 | * |
307 | @@ -1124,6 +1224,39 @@ | |||
308 | 1124 | return rc; | 1224 | return rc; |
309 | 1125 | } | 1225 | } |
310 | 1126 | 1226 | ||
311 | 1227 | int blkid_probe_set_magic(blkid_probe pr, blkid_loff_t offset, | ||
312 | 1228 | size_t len, unsigned char *magic) | ||
313 | 1229 | { | ||
314 | 1230 | int rc = 0; | ||
315 | 1231 | struct blkid_chain *chn = blkid_probe_get_chain(pr); | ||
316 | 1232 | |||
317 | 1233 | if (!chn || !magic || !len || chn->binary) | ||
318 | 1234 | return 0; | ||
319 | 1235 | |||
320 | 1236 | switch (chn->driver->id) { | ||
321 | 1237 | case BLKID_CHAIN_SUBLKS: | ||
322 | 1238 | if (!(chn->flags & BLKID_SUBLKS_MAGIC)) | ||
323 | 1239 | return 0; | ||
324 | 1240 | rc = blkid_probe_set_value(pr, "SBMAGIC", magic, len); | ||
325 | 1241 | if (!rc) | ||
326 | 1242 | rc = blkid_probe_sprintf_value(pr, | ||
327 | 1243 | "SBMAGIC_OFFSET", "%llu", offset); | ||
328 | 1244 | break; | ||
329 | 1245 | case BLKID_CHAIN_PARTS: | ||
330 | 1246 | if (!(chn->flags & BLKID_PARTS_MAGIC)) | ||
331 | 1247 | return 0; | ||
332 | 1248 | rc = blkid_probe_set_value(pr, "PTMAGIC", magic, len); | ||
333 | 1249 | if (!rc) | ||
334 | 1250 | rc = blkid_probe_sprintf_value(pr, | ||
335 | 1251 | "PTMAGIC_OFFSET", "%llu", offset); | ||
336 | 1252 | break; | ||
337 | 1253 | default: | ||
338 | 1254 | break; | ||
339 | 1255 | } | ||
340 | 1256 | |||
341 | 1257 | return rc; | ||
342 | 1258 | } | ||
343 | 1259 | |||
344 | 1127 | /** | 1260 | /** |
345 | 1128 | * blkid_probe_get_devno: | 1261 | * blkid_probe_get_devno: |
346 | 1129 | * @pr: probe | 1262 | * @pr: probe |
347 | 1130 | 1263 | ||
348 | === modified file 'libblkid/src/superblocks/superblocks.c' | |||
349 | --- libblkid/src/superblocks/superblocks.c 2011-11-03 15:38:23 +0000 | |||
350 | +++ libblkid/src/superblocks/superblocks.c 2014-10-10 06:30:46 +0000 | |||
351 | @@ -478,21 +478,6 @@ | |||
352 | 478 | return 0; | 478 | return 0; |
353 | 479 | } | 479 | } |
354 | 480 | 480 | ||
355 | 481 | int blkid_probe_set_magic(blkid_probe pr, blkid_loff_t offset, | ||
356 | 482 | size_t len, unsigned char *magic) | ||
357 | 483 | { | ||
358 | 484 | int rc = 0; | ||
359 | 485 | struct blkid_chain *chn = blkid_probe_get_chain(pr); | ||
360 | 486 | |||
361 | 487 | if (magic && len && (chn->flags & BLKID_SUBLKS_MAGIC)) { | ||
362 | 488 | rc = blkid_probe_set_value(pr, "SBMAGIC", magic, len); | ||
363 | 489 | if (!rc) | ||
364 | 490 | rc = blkid_probe_sprintf_value(pr, "SBMAGIC_OFFSET", | ||
365 | 491 | "%llu", offset); | ||
366 | 492 | } | ||
367 | 493 | return rc; | ||
368 | 494 | } | ||
369 | 495 | |||
370 | 496 | int blkid_probe_set_version(blkid_probe pr, const char *version) | 481 | int blkid_probe_set_version(blkid_probe pr, const char *version) |
371 | 497 | { | 482 | { |
372 | 498 | struct blkid_chain *chn = blkid_probe_get_chain(pr); | 483 | struct blkid_chain *chn = blkid_probe_get_chain(pr); |
373 | 499 | 484 | ||
374 | === modified file 'libblkid/src/superblocks/superblocks.h' | |||
375 | --- libblkid/src/superblocks/superblocks.h 2011-11-03 15:38:23 +0000 | |||
376 | +++ libblkid/src/superblocks/superblocks.h 2014-10-10 06:30:46 +0000 | |||
377 | @@ -71,8 +71,6 @@ | |||
378 | 71 | /* | 71 | /* |
379 | 72 | * superblock functions | 72 | * superblock functions |
380 | 73 | */ | 73 | */ |
381 | 74 | extern int blkid_probe_set_magic(blkid_probe pr, blkid_loff_t offset, | ||
382 | 75 | size_t len, unsigned char *magic); | ||
383 | 76 | extern int blkid_probe_set_version(blkid_probe pr, const char *version); | 74 | extern int blkid_probe_set_version(blkid_probe pr, const char *version); |
384 | 77 | extern int blkid_probe_sprintf_version(blkid_probe pr, const char *fmt, ...) | 75 | extern int blkid_probe_sprintf_version(blkid_probe pr, const char *fmt, ...) |
385 | 78 | __attribute__ ((format (printf, 2, 3))); | 76 | __attribute__ ((format (printf, 2, 3))); |
386 | 79 | 77 | ||
387 | === modified file 'misc-utils/wipefs.c' | |||
388 | --- misc-utils/wipefs.c 2012-09-06 05:47:03 +0000 | |||
389 | +++ misc-utils/wipefs.c 2014-10-10 06:30:46 +0000 | |||
390 | @@ -49,6 +49,8 @@ | |||
391 | 49 | char *label; /* FS label */ | 49 | char *label; /* FS label */ |
392 | 50 | char *uuid; /* FS uuid */ | 50 | char *uuid; /* FS uuid */ |
393 | 51 | 51 | ||
394 | 52 | int on_disk; | ||
395 | 53 | |||
396 | 52 | struct wipe_desc *next; | 54 | struct wipe_desc *next; |
397 | 53 | }; | 55 | }; |
398 | 54 | 56 | ||
399 | @@ -138,73 +140,103 @@ | |||
400 | 138 | } | 140 | } |
401 | 139 | 141 | ||
402 | 140 | static struct wipe_desc * | 142 | static struct wipe_desc * |
404 | 141 | get_offset_from_probe(struct wipe_desc *wp, blkid_probe pr, int zap) | 143 | get_desc_for_probe(struct wipe_desc *wp, blkid_probe pr) |
405 | 142 | { | 144 | { |
407 | 143 | const char *off, *type, *usage, *mag; | 145 | const char *off, *type, *mag, *p, *usage = NULL; |
408 | 144 | size_t len; | 146 | size_t len; |
422 | 145 | 147 | loff_t offset; | |
423 | 146 | if (blkid_probe_lookup_value(pr, "TYPE", &type, NULL) == 0 && | 148 | int rc; |
424 | 147 | blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL) == 0 && | 149 | |
425 | 148 | blkid_probe_lookup_value(pr, "SBMAGIC", &mag, &len) == 0 && | 150 | /* superblocks */ |
426 | 149 | blkid_probe_lookup_value(pr, "USAGE", &usage, NULL) == 0) { | 151 | if (blkid_probe_lookup_value(pr, "TYPE", &type, NULL) == 0) { |
427 | 150 | 152 | rc = blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL); | |
428 | 151 | loff_t offset = strtoll(off, NULL, 10); | 153 | if (!rc) |
429 | 152 | const char *p; | 154 | rc = blkid_probe_lookup_value(pr, "SBMAGIC", &mag, &len); |
430 | 153 | 155 | if (rc) | |
431 | 154 | wp = add_offset(wp, offset, zap); | 156 | return wp; |
432 | 155 | if (!wp) | 157 | |
433 | 156 | return NULL; | 158 | /* partitions */ |
434 | 157 | 159 | } else if (blkid_probe_lookup_value(pr, "PTTYPE", &type, NULL) == 0) { | |
435 | 160 | rc = blkid_probe_lookup_value(pr, "PTMAGIC_OFFSET", &off, NULL); | ||
436 | 161 | if (!rc) | ||
437 | 162 | rc = blkid_probe_lookup_value(pr, "PTMAGIC", &mag, &len); | ||
438 | 163 | if (rc) | ||
439 | 164 | return wp; | ||
440 | 165 | usage = "partition table"; | ||
441 | 166 | } else | ||
442 | 167 | return wp; | ||
443 | 168 | |||
444 | 169 | offset = strtoll(off, NULL, 10); | ||
445 | 170 | |||
446 | 171 | wp = add_offset(wp, offset, 0); | ||
447 | 172 | if (!wp) | ||
448 | 173 | return NULL; | ||
449 | 174 | |||
450 | 175 | if (usage || blkid_probe_lookup_value(pr, "USAGE", &usage, NULL) == 0) | ||
451 | 158 | wp->usage = xstrdup(usage); | 176 | wp->usage = xstrdup(usage); |
464 | 159 | wp->type = xstrdup(type); | 177 | |
465 | 160 | 178 | wp->type = xstrdup(type); | |
466 | 161 | wp->magic = xmalloc(len); | 179 | wp->on_disk = 1; |
467 | 162 | memcpy(wp->magic, mag, len); | 180 | |
468 | 163 | wp->len = len; | 181 | wp->magic = xmalloc(len); |
469 | 164 | 182 | memcpy(wp->magic, mag, len); | |
470 | 165 | if (blkid_probe_lookup_value(pr, "LABEL", &p, NULL) == 0) | 183 | wp->len = len; |
471 | 166 | wp->label = xstrdup(p); | 184 | |
472 | 167 | 185 | if (blkid_probe_lookup_value(pr, "LABEL", &p, NULL) == 0) | |
473 | 168 | if (blkid_probe_lookup_value(pr, "UUID", &p, NULL) == 0) | 186 | wp->label = xstrdup(p); |
474 | 169 | wp->uuid = xstrdup(p); | 187 | |
475 | 170 | } | 188 | if (blkid_probe_lookup_value(pr, "UUID", &p, NULL) == 0) |
476 | 189 | wp->uuid = xstrdup(p); | ||
477 | 171 | 190 | ||
478 | 172 | return wp; | 191 | return wp; |
479 | 173 | } | 192 | } |
480 | 174 | 193 | ||
483 | 175 | static struct wipe_desc * | 194 | static blkid_probe |
484 | 176 | read_offsets(struct wipe_desc *wp, const char *fname, int zap) | 195 | new_probe(const char *devname, int mode) |
485 | 177 | { | 196 | { |
486 | 178 | blkid_probe pr; | 197 | blkid_probe pr; |
487 | 179 | int rc; | ||
488 | 180 | 198 | ||
490 | 181 | if (!fname) | 199 | if (!devname) |
491 | 182 | return NULL; | 200 | return NULL; |
492 | 183 | 201 | ||
494 | 184 | pr = blkid_new_probe_from_filename(fname); | 202 | if (mode) { |
495 | 203 | int fd = open(devname, mode); | ||
496 | 204 | if (fd < 0) | ||
497 | 205 | goto error; | ||
498 | 206 | |||
499 | 207 | pr = blkid_new_probe(); | ||
500 | 208 | if (pr && blkid_probe_set_device(pr, fd, 0, 0)) | ||
501 | 209 | goto error; | ||
502 | 210 | } else | ||
503 | 211 | pr = blkid_new_probe_from_filename(devname); | ||
504 | 212 | |||
505 | 185 | if (!pr) | 213 | if (!pr) |
520 | 186 | errx(EXIT_FAILURE, _("error: %s: probing initialization failed"), fname); | 214 | goto error; |
507 | 187 | |||
508 | 188 | blkid_probe_enable_superblocks(pr, 0); /* enabled by default ;-( */ | ||
509 | 189 | |||
510 | 190 | blkid_probe_enable_partitions(pr, 1); | ||
511 | 191 | rc = blkid_do_fullprobe(pr); | ||
512 | 192 | blkid_probe_enable_partitions(pr, 0); | ||
513 | 193 | |||
514 | 194 | if (rc == 0) { | ||
515 | 195 | const char *type = NULL; | ||
516 | 196 | blkid_probe_lookup_value(pr, "PTTYPE", &type, NULL); | ||
517 | 197 | warnx(_("WARNING: %s: appears to contain '%s' " | ||
518 | 198 | "partition table"), fname, type); | ||
519 | 199 | } | ||
521 | 200 | 215 | ||
522 | 201 | blkid_probe_enable_superblocks(pr, 1); | 216 | blkid_probe_enable_superblocks(pr, 1); |
523 | 202 | blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC | | 217 | blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC | |
524 | 203 | BLKID_SUBLKS_TYPE | BLKID_SUBLKS_USAGE | | 218 | BLKID_SUBLKS_TYPE | BLKID_SUBLKS_USAGE | |
525 | 204 | BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID); | 219 | BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID); |
526 | 205 | 220 | ||
527 | 221 | blkid_probe_enable_partitions(pr, 1); | ||
528 | 222 | blkid_probe_set_partitions_flags(pr, BLKID_PARTS_MAGIC); | ||
529 | 223 | |||
530 | 224 | return pr; | ||
531 | 225 | error: | ||
532 | 226 | err(EXIT_FAILURE, _("error: %s: probing initialization failed"), devname); | ||
533 | 227 | return NULL; | ||
534 | 228 | } | ||
535 | 229 | |||
536 | 230 | static struct wipe_desc * | ||
537 | 231 | read_offsets(struct wipe_desc *wp, const char *devname) | ||
538 | 232 | { | ||
539 | 233 | blkid_probe pr = new_probe(devname, 0); | ||
540 | 234 | |||
541 | 235 | if (!pr) | ||
542 | 236 | return NULL; | ||
543 | 237 | |||
544 | 206 | while (blkid_do_probe(pr) == 0) { | 238 | while (blkid_do_probe(pr) == 0) { |
546 | 207 | wp = get_offset_from_probe(wp, pr, zap); | 239 | wp = get_desc_for_probe(wp, pr); |
547 | 208 | if (!wp) | 240 | if (!wp) |
548 | 209 | break; | 241 | break; |
549 | 210 | } | 242 | } |
550 | @@ -213,60 +245,54 @@ | |||
551 | 213 | return wp; | 245 | return wp; |
552 | 214 | } | 246 | } |
553 | 215 | 247 | ||
608 | 216 | static int | 248 | static struct wipe_desc * |
609 | 217 | do_wipe_offset(int fd, struct wipe_desc *wp, const char *fname, int noact) | 249 | do_wipe(struct wipe_desc *wp, const char *devname, int noact, int all) |
610 | 218 | { | 250 | { |
611 | 219 | char buf[BUFSIZ]; | 251 | blkid_probe pr = new_probe(devname, O_RDWR); |
612 | 220 | off_t l; | 252 | struct wipe_desc *w; |
613 | 221 | size_t i, len; | 253 | |
614 | 222 | 254 | if (!pr) | |
615 | 223 | if (!wp->type) { | 255 | return NULL; |
616 | 224 | warnx(_("no magic string found at offset " | 256 | |
617 | 225 | "0x%jx -- ignored"), wp->offset); | 257 | while (blkid_do_probe(pr) == 0) { |
618 | 226 | return 0; | 258 | w = get_desc_for_probe(wp, pr); |
619 | 227 | } | 259 | if (!w) |
620 | 228 | 260 | break; | |
621 | 229 | l = lseek(fd, wp->offset, SEEK_SET); | 261 | wp = w; |
622 | 230 | if (l == (off_t) -1) | 262 | if (!wp->on_disk) |
623 | 231 | err(EXIT_FAILURE, _("%s: failed to seek to offset 0x%jx"), | 263 | continue; |
624 | 232 | fname, wp->offset); | 264 | wp->zap = all ? 1 : wp->zap; |
625 | 233 | 265 | if (!wp->zap) | |
626 | 234 | len = wp->len > sizeof(buf) ? sizeof(buf) : wp->len; | 266 | continue; |
627 | 235 | 267 | ||
628 | 236 | memset(buf, 0, len); | 268 | if (blkid_do_wipe(pr, noact)) |
629 | 237 | if (noact == 0 && write_all(fd, buf, len)) | 269 | warn(_("failed to erase %s magic string at offset 0x%08jx"), |
630 | 238 | err(EXIT_FAILURE, _("%s: write failed"), fname); | 270 | wp->type, wp->offset); |
631 | 239 | 271 | else { | |
632 | 240 | printf(_("%zd bytes were erased at offset 0x%jx (%s)\nthey were: "), | 272 | size_t i; |
633 | 241 | wp->len, wp->offset, wp->type); | 273 | |
634 | 242 | 274 | printf(_("%zd bytes were erased at offset 0x%08jx (%s): "), | |
635 | 243 | for (i = 0; i < len; i++) { | 275 | wp->len, wp->offset, wp->type); |
636 | 244 | printf("%02x", wp->magic[i]); | 276 | |
637 | 245 | if (i + 1 < len) | 277 | for (i = 0; i < wp->len; i++) { |
638 | 246 | fputc(' ', stdout); | 278 | printf("%02x", wp->magic[i]); |
639 | 247 | } | 279 | if (i + 1 < wp->len) |
640 | 248 | 280 | fputc(' ', stdout); | |
641 | 249 | printf("\n"); | 281 | } |
642 | 250 | return 0; | 282 | putchar('\n'); |
643 | 251 | } | 283 | } |
644 | 252 | 284 | } | |
645 | 253 | static int | 285 | |
646 | 254 | do_wipe(struct wipe_desc *wp, const char *fname, int noact) | 286 | for (w = wp; w != NULL; w = w->next) { |
647 | 255 | { | 287 | if (!w->on_disk) |
648 | 256 | int fd; | 288 | warnx(_("offset 0x%jx not found"), w->offset); |
649 | 257 | 289 | } | |
650 | 258 | fd = open(fname, O_WRONLY); | 290 | |
651 | 259 | if (fd < 0) | 291 | fsync(blkid_probe_get_fd(pr)); |
652 | 260 | err(EXIT_FAILURE, _("%s: open failed"), fname); | 292 | close(blkid_probe_get_fd(pr)); |
653 | 261 | 293 | blkid_free_probe(pr); | |
654 | 262 | while (wp) { | 294 | |
655 | 263 | if (wp->zap) | 295 | return wp; |
602 | 264 | do_wipe_offset(fd, wp, fname, noact); | ||
603 | 265 | wp = wp->next; | ||
604 | 266 | } | ||
605 | 267 | |||
606 | 268 | close(fd); | ||
607 | 269 | return 0; | ||
656 | 270 | } | 296 | } |
657 | 271 | 297 | ||
658 | 272 | static void | 298 | static void |
659 | @@ -323,7 +349,7 @@ | |||
660 | 323 | { | 349 | { |
661 | 324 | struct wipe_desc *wp = NULL; | 350 | struct wipe_desc *wp = NULL; |
662 | 325 | int c, all = 0, has_offset = 0, noact = 0, mode = 0; | 351 | int c, all = 0, has_offset = 0, noact = 0, mode = 0; |
664 | 326 | const char *fname; | 352 | const char *devname; |
665 | 327 | 353 | ||
666 | 328 | static const struct option longopts[] = { | 354 | static const struct option longopts[] = { |
667 | 329 | { "all", 0, 0, 'a' }, | 355 | { "all", 0, 0, 'a' }, |
668 | @@ -372,26 +398,25 @@ | |||
669 | 372 | if (optind == argc) | 398 | if (optind == argc) |
670 | 373 | usage(stderr); | 399 | usage(stderr); |
671 | 374 | 400 | ||
673 | 375 | fname = argv[optind++]; | 401 | devname = argv[optind++]; |
674 | 376 | 402 | ||
675 | 377 | if (optind != argc) | 403 | if (optind != argc) |
676 | 378 | errx(EXIT_FAILURE, _("only one device as argument is currently supported.")); | 404 | errx(EXIT_FAILURE, _("only one device as argument is currently supported.")); |
677 | 379 | 405 | ||
694 | 380 | /* we need to wipe several times for some file systems like VFAT, see | 406 | if (!all && !has_offset) { |
695 | 381 | * https://launchpad.net/bugs/1046665 */ | 407 | /* |
696 | 382 | do { | 408 | * Print only |
697 | 383 | wp = read_offsets(wp, fname, all); | 409 | */ |
698 | 384 | 410 | wp = read_offsets(wp, devname); | |
699 | 385 | if (wp) { | 411 | if (wp) |
700 | 386 | if (has_offset || all) | 412 | print_all(wp, mode); |
701 | 387 | do_wipe(wp, fname, noact); | 413 | } else { |
702 | 388 | else | 414 | /* |
703 | 389 | print_all(wp, mode); | 415 | * Erase |
704 | 390 | 416 | */ | |
705 | 391 | free_wipe(wp); | 417 | wp = do_wipe(wp, devname, noact, all); |
706 | 392 | wp = NULL; | 418 | } |
707 | 393 | } else | 419 | |
708 | 394 | break; | 420 | free_wipe(wp); |
693 | 395 | } while (!noact && all); | ||
709 | 396 | return EXIT_SUCCESS; | 421 | return EXIT_SUCCESS; |
710 | 397 | } | 422 | } |
I think this was workarounded in usb-creator instead, am I wrong? With the reasoning that this new feature backport would be a little too heavy in a core part like util-linux.
The latest usb-creator in 14.04 LTS is this https:/ /launchpad. net/ubuntu/ +source/ usb-creator/ 0.2.56. 3
So I'd mark this as rejected, please re-open if you think this should still be targeted towards trusty.