]> git.ipfire.org Git - thirdparty/util-linux.git/blob - misc-utils/wipefs.c
Merge branch 'hardlink-import' into hardlink
[thirdparty/util-linux.git] / misc-utils / wipefs.c
1 /*
2 * wipefs - utility to wipe filesystems from device
3 *
4 * Copyright (C) 2009 Red Hat, Inc. All rights reserved.
5 * Written by Karel Zak <kzak@redhat.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it would be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21 #include <sys/stat.h>
22 #include <sys/types.h>
23 #include <ctype.h>
24 #include <errno.h>
25 #include <fcntl.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <getopt.h>
30 #include <string.h>
31 #include <limits.h>
32 #include <libgen.h>
33
34 #include <blkid.h>
35 #include <libsmartcols.h>
36
37 #include "nls.h"
38 #include "xalloc.h"
39 #include "strutils.h"
40 #include "all-io.h"
41 #include "match.h"
42 #include "c.h"
43 #include "closestream.h"
44 #include "optutils.h"
45 #include "blkdev.h"
46
47 struct wipe_desc {
48 loff_t offset; /* magic string offset */
49 size_t len; /* length of magic string */
50 unsigned char *magic; /* magic string */
51
52 char *usage; /* raid, filesystem, ... */
53 char *type; /* FS type */
54 char *label; /* FS label */
55 char *uuid; /* FS uuid */
56
57 struct wipe_desc *next;
58
59 unsigned int on_disk : 1,
60 is_parttable : 1;
61
62 };
63
64 struct wipe_control {
65 const char *devname;
66 const char *type_pattern; /* -t <pattern> */
67
68 struct libscols_table *outtab;
69 struct wipe_desc *offsets; /* -o <offset> -o <offset> ... */
70
71 unsigned int noact : 1,
72 all : 1,
73 quiet : 1,
74 backup : 1,
75 force : 1,
76 json : 1,
77 no_headings : 1,
78 parsable : 1;
79 };
80
81
82 /* column IDs */
83 enum {
84 COL_UUID = 0,
85 COL_LABEL,
86 COL_LEN,
87 COL_TYPE,
88 COL_OFFSET,
89 COL_USAGE,
90 COL_DEVICE
91 };
92
93 /* column names */
94 struct colinfo {
95 const char *name; /* header */
96 double whint; /* width hint (N < 1 is in percent of termwidth) */
97 int flags; /* SCOLS_FL_* */
98 const char *help;
99 };
100
101 /* columns descriptions */
102 static const struct colinfo infos[] = {
103 [COL_UUID] = {"UUID", 4, 0, N_("partition/filesystem UUID")},
104 [COL_LABEL] = {"LABEL", 5, 0, N_("filesystem LABEL")},
105 [COL_LEN] = {"LENGTH", 6, 0, N_("magic string length")},
106 [COL_TYPE] = {"TYPE", 4, 0, N_("superblok type")},
107 [COL_OFFSET] = {"OFFSET", 5, 0, N_("magic string offset")},
108 [COL_USAGE] = {"USAGE", 5, 0, N_("type description")},
109 [COL_DEVICE] = {"DEVICE", 5, 0, N_("block device name")}
110 };
111
112 static int columns[ARRAY_SIZE(infos) * 2];
113 static size_t ncolumns;
114
115 static int column_name_to_id(const char *name, size_t namesz)
116 {
117 size_t i;
118
119 assert(name);
120
121 for (i = 0; i < ARRAY_SIZE(infos); i++) {
122 const char *cn = infos[i].name;
123 if (!strncasecmp(name, cn, namesz) && !*(cn + namesz))
124 return i;
125 }
126 warnx(_("unknown column: %s"), name);
127 return -1;
128 }
129
130 static int get_column_id(size_t num)
131 {
132 assert(num < ncolumns);
133 assert(columns[num] < (int)ARRAY_SIZE(infos));
134 return columns[num];
135 }
136
137 static const struct colinfo *get_column_info(int num)
138 {
139 return &infos[get_column_id(num)];
140 }
141
142
143 static void init_output(struct wipe_control *ctl)
144 {
145 struct libscols_table *tb;
146 size_t i;
147
148 scols_init_debug(0);
149 tb = scols_new_table();
150 if (!tb)
151 err(EXIT_FAILURE, _("failed to allocate output table"));
152
153 if (ctl->json) {
154 scols_table_enable_json(tb, 1);
155 scols_table_set_name(tb, "signatures");
156 }
157 scols_table_enable_noheadings(tb, ctl->no_headings);
158
159 if (ctl->parsable) {
160 scols_table_enable_raw(tb, 1);
161 scols_table_set_column_separator(tb, ",");
162 }
163
164 for (i = 0; i < ncolumns; i++) {
165 const struct colinfo *col = get_column_info(i);
166 struct libscols_column *cl;
167
168 cl = scols_table_new_column(tb, col->name, col->whint,
169 col->flags);
170 if (!cl)
171 err(EXIT_FAILURE,
172 _("failed to initialize output column"));
173 if (ctl->json) {
174 int id = get_column_id(i);
175
176 if (id == COL_LEN)
177 scols_column_set_json_type(cl, SCOLS_JSON_NUMBER);
178 }
179 }
180 ctl->outtab = tb;
181 }
182
183 static void finalize_output(struct wipe_control *ctl)
184 {
185 if (ctl->parsable && !ctl->no_headings
186 && !scols_table_is_empty(ctl->outtab)) {
187 struct libscols_iter *itr = scols_new_iter(SCOLS_ITER_FORWARD);
188 struct libscols_column *cl;
189 int i = 0;
190
191 if (!itr)
192 err_oom();
193
194 fputs("# ", stdout);
195 while (scols_table_next_column(ctl->outtab, itr, &cl) == 0) {
196 struct libscols_cell *hdr = scols_column_get_header(cl);
197 const char *name = scols_cell_get_data(hdr);
198
199 if (i)
200 fputc(',', stdout);
201 fputs(name, stdout);
202 i++;
203 }
204 fputc('\n', stdout);
205 scols_free_iter(itr);
206 }
207 scols_print_table(ctl->outtab);
208 scols_unref_table(ctl->outtab);
209 }
210
211 static void fill_table_row(struct wipe_control *ctl, struct wipe_desc *wp)
212 {
213 static struct libscols_line *ln;
214 size_t i;
215
216 ln = scols_table_new_line(ctl->outtab, NULL);
217 if (!ln)
218 errx(EXIT_FAILURE, _("failed to allocate output line"));
219
220 for (i = 0; i < ncolumns; i++) {
221 char *str = NULL;
222
223 switch (get_column_id(i)) {
224 case COL_UUID:
225 if (wp->uuid)
226 str = xstrdup(wp->uuid);
227 break;
228 case COL_LABEL:
229 if (wp->label)
230 str = xstrdup(wp->label);
231 break;
232 case COL_OFFSET:
233 xasprintf(&str, "0x%jx", (intmax_t)wp->offset);
234 break;
235 case COL_LEN:
236 xasprintf(&str, "%zu", wp->len);
237 break;
238 case COL_USAGE:
239 if (wp->usage)
240 str = xstrdup(wp->usage);
241 break;
242 case COL_TYPE:
243 if (wp->type)
244 str = xstrdup(wp->type);
245 break;
246 case COL_DEVICE:
247 if (ctl->devname) {
248 char *dev = xstrdup(ctl->devname);
249 str = xstrdup(basename(dev));
250 free(dev);
251 }
252 break;
253 default:
254 abort();
255 }
256
257 if (str && scols_line_refer_data(ln, i, str))
258 errx(EXIT_FAILURE, _("failed to add output data"));
259 }
260 }
261
262 static void add_to_output(struct wipe_control *ctl, struct wipe_desc *wp)
263 {
264 for (/*nothing*/; wp; wp = wp->next)
265 fill_table_row(ctl, wp);
266 }
267
268 /* Allocates a new wipe_desc and add to the wp0 if not NULL */
269 static struct wipe_desc *add_offset(struct wipe_desc **wp0, loff_t offset)
270 {
271 struct wipe_desc *wp, *last = NULL;
272
273 if (wp0) {
274 /* check if already exists */
275 for (wp = *wp0; wp; wp = wp->next) {
276 if (wp->offset == offset)
277 return wp;
278 last = wp;
279 }
280 }
281
282 wp = xcalloc(1, sizeof(struct wipe_desc));
283 wp->offset = offset;
284 wp->next = NULL;
285
286 if (last)
287 last->next = wp;
288 if (wp0 && !*wp0)
289 *wp0 = wp;
290 return wp;
291 }
292
293 /* Read data from libblkid and if detected type pass -t and -o filters than:
294 * - allocates a new wipe_desc
295 * - add the new wipe_desc to wp0 list (if not NULL)
296 *
297 * The function always returns offset and len if libblkid detected something.
298 */
299 static struct wipe_desc *get_desc_for_probe(struct wipe_control *ctl,
300 struct wipe_desc **wp0,
301 blkid_probe pr,
302 loff_t *offset,
303 size_t *len)
304 {
305 const char *off, *type, *mag, *p, *usage = NULL;
306 struct wipe_desc *wp;
307 int rc, ispt = 0;
308
309 *len = 0;
310
311 /* superblocks */
312 if (blkid_probe_lookup_value(pr, "TYPE", &type, NULL) == 0) {
313 rc = blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL);
314 if (!rc)
315 rc = blkid_probe_lookup_value(pr, "SBMAGIC", &mag, len);
316 if (rc)
317 return NULL;
318
319 /* partitions */
320 } else if (blkid_probe_lookup_value(pr, "PTTYPE", &type, NULL) == 0) {
321 rc = blkid_probe_lookup_value(pr, "PTMAGIC_OFFSET", &off, NULL);
322 if (!rc)
323 rc = blkid_probe_lookup_value(pr, "PTMAGIC", &mag, len);
324 if (rc)
325 return NULL;
326 usage = N_("partition-table");
327 ispt = 1;
328 } else
329 return NULL;
330
331 *offset = strtoll(off, NULL, 10);
332
333 /* Filter out by -t <type> */
334 if (ctl->type_pattern && !match_fstype(type, ctl->type_pattern))
335 return NULL;
336
337 /* Filter out by -o <offset> */
338 if (ctl->offsets) {
339 struct wipe_desc *w = NULL;
340
341 for (w = ctl->offsets; w; w = w->next) {
342 if (w->offset == *offset)
343 break;
344 }
345 if (!w)
346 return NULL;
347
348 w->on_disk = 1; /* mark as "found" */
349 }
350
351 wp = add_offset(wp0, *offset);
352 if (!wp)
353 return NULL;
354
355 if (usage || blkid_probe_lookup_value(pr, "USAGE", &usage, NULL) == 0)
356 wp->usage = xstrdup(usage);
357
358 wp->type = xstrdup(type);
359 wp->on_disk = 1;
360 wp->is_parttable = ispt ? 1 : 0;
361
362 wp->magic = xmalloc(*len);
363 memcpy(wp->magic, mag, *len);
364 wp->len = *len;
365
366 if (blkid_probe_lookup_value(pr, "LABEL", &p, NULL) == 0)
367 wp->label = xstrdup(p);
368
369 if (blkid_probe_lookup_value(pr, "UUID", &p, NULL) == 0)
370 wp->uuid = xstrdup(p);
371
372 return wp;
373 }
374
375 static blkid_probe
376 new_probe(const char *devname, int mode)
377 {
378 blkid_probe pr = NULL;
379
380 if (!devname)
381 return NULL;
382
383 if (mode) {
384 int fd = open(devname, mode);
385 if (fd < 0)
386 goto error;
387
388 pr = blkid_new_probe();
389 if (!pr || blkid_probe_set_device(pr, fd, 0, 0) != 0) {
390 close(fd);
391 goto error;
392 }
393 } else
394 pr = blkid_new_probe_from_filename(devname);
395
396 if (!pr)
397 goto error;
398
399 blkid_probe_enable_superblocks(pr, 1);
400 blkid_probe_set_superblocks_flags(pr,
401 BLKID_SUBLKS_MAGIC | /* return magic string and offset */
402 BLKID_SUBLKS_TYPE | /* return superblock type */
403 BLKID_SUBLKS_USAGE | /* return USAGE= */
404 BLKID_SUBLKS_LABEL | /* return LABEL= */
405 BLKID_SUBLKS_UUID | /* return UUID= */
406 BLKID_SUBLKS_BADCSUM); /* accept bad checksums */
407
408 blkid_probe_enable_partitions(pr, 1);
409 blkid_probe_set_partitions_flags(pr, BLKID_PARTS_MAGIC |
410 BLKID_PARTS_FORCE_GPT);
411 return pr;
412 error:
413 blkid_free_probe(pr);
414 err(EXIT_FAILURE, _("error: %s: probing initialization failed"), devname);
415 }
416
417 static struct wipe_desc *read_offsets(struct wipe_control *ctl)
418 {
419 blkid_probe pr = new_probe(ctl->devname, 0);
420 struct wipe_desc *wp0 = NULL;
421
422 if (!pr)
423 return NULL;
424
425 while (blkid_do_probe(pr) == 0) {
426 size_t len = 0;
427 loff_t offset = 0;
428
429 /* add a new offset to wp0 */
430 get_desc_for_probe(ctl, &wp0, pr, &offset, &len);
431
432 /* hide last detected signature and scan again */
433 if (len) {
434 blkid_probe_hide_range(pr, offset, len);
435 blkid_probe_step_back(pr);
436 }
437 }
438
439 blkid_free_probe(pr);
440 return wp0;
441 }
442
443 static void free_wipe(struct wipe_desc *wp)
444 {
445 while (wp) {
446 struct wipe_desc *next = wp->next;
447
448 free(wp->usage);
449 free(wp->type);
450 free(wp->magic);
451 free(wp->label);
452 free(wp->uuid);
453 free(wp);
454
455 wp = next;
456 }
457 }
458
459 static void do_wipe_real(struct wipe_control *ctl, blkid_probe pr,
460 struct wipe_desc *w)
461 {
462 size_t i;
463
464 if (blkid_do_wipe(pr, ctl->noact) != 0)
465 err(EXIT_FAILURE, _("%s: failed to erase %s magic string at offset 0x%08jx"),
466 ctl->devname, w->type, (intmax_t)w->offset);
467
468 if (ctl->quiet)
469 return;
470
471 printf(P_("%s: %zd byte was erased at offset 0x%08jx (%s): ",
472 "%s: %zd bytes were erased at offset 0x%08jx (%s): ",
473 w->len),
474 ctl->devname, w->len, (intmax_t)w->offset, w->type);
475
476 for (i = 0; i < w->len; i++) {
477 printf("%02x", w->magic[i]);
478 if (i + 1 < w->len)
479 fputc(' ', stdout);
480 }
481 putchar('\n');
482 }
483
484 static void do_backup(struct wipe_desc *wp, const char *base)
485 {
486 char *fname = NULL;
487 int fd;
488
489 xasprintf(&fname, "%s0x%08jx.bak", base, (intmax_t)wp->offset);
490
491 fd = open(fname, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
492 if (fd < 0)
493 goto err;
494 if (write_all(fd, wp->magic, wp->len) != 0)
495 goto err;
496 close(fd);
497 free(fname);
498 return;
499 err:
500 err(EXIT_FAILURE, _("%s: failed to create a signature backup"), fname);
501 }
502
503 #ifdef BLKRRPART
504 static void rereadpt(int fd, const char *devname)
505 {
506 struct stat st;
507
508 if (fstat(fd, &st) || !S_ISBLK(st.st_mode))
509 return;
510
511 errno = 0;
512 ioctl(fd, BLKRRPART);
513 printf(_("%s: calling ioctl to re-read partition table: %m\n"), devname);
514 }
515 #endif
516
517 static int do_wipe(struct wipe_control *ctl)
518 {
519 int mode = O_RDWR, reread = 0, need_force = 0;
520 blkid_probe pr;
521 char *backup = NULL;
522 struct wipe_desc *w;
523
524 if (!ctl->force)
525 mode |= O_EXCL;
526
527 pr = new_probe(ctl->devname, mode);
528 if (!pr)
529 return -errno;
530
531 if (ctl->backup) {
532 const char *home = getenv ("HOME");
533 char *tmp = xstrdup(ctl->devname);
534
535 if (!home)
536 errx(EXIT_FAILURE, _("failed to create a signature backup, $HOME undefined"));
537 xasprintf (&backup, "%s/wipefs-%s-", home, basename(tmp));
538 free(tmp);
539 }
540
541 while (blkid_do_probe(pr) == 0) {
542 int wiped = 0;
543 size_t len = 0;
544 loff_t offset = 0;
545 struct wipe_desc *wp;
546
547 wp = get_desc_for_probe(ctl, NULL, pr, &offset, &len);
548 if (!wp)
549 goto done;
550
551 if (!ctl->force
552 && wp->is_parttable
553 && !blkid_probe_is_wholedisk(pr)) {
554 warnx(_("%s: ignoring nested \"%s\" partition table "
555 "on non-whole disk device"), ctl->devname, wp->type);
556 need_force = 1;
557 goto done;
558 }
559
560 if (backup)
561 do_backup(wp, backup);
562 do_wipe_real(ctl, pr, wp);
563 if (wp->is_parttable)
564 reread = 1;
565 wiped = 1;
566 done:
567 if (!wiped && len) {
568 /* if the offset has not been wiped (probably because
569 * filtered out by -t or -o) we need to hide it for
570 * libblkid to try another magic string for the same
571 * superblock, otherwise libblkid will continue with
572 * another superblock. Don't forget that the same
573 * superblock could be detected by more magic strings
574 * */
575 blkid_probe_hide_range(pr, offset, len);
576 blkid_probe_step_back(pr);
577 }
578 free_wipe(wp);
579 }
580
581 for (w = ctl->offsets; w; w = w->next) {
582 if (!w->on_disk && !ctl->quiet)
583 warnx(_("%s: offset 0x%jx not found"),
584 ctl->devname, (uintmax_t)w->offset);
585 }
586
587 if (need_force)
588 warnx(_("Use the --force option to force erase."));
589
590 fsync(blkid_probe_get_fd(pr));
591
592 #ifdef BLKRRPART
593 if (reread && (mode & O_EXCL))
594 rereadpt(blkid_probe_get_fd(pr), ctl->devname);
595 #endif
596
597 close(blkid_probe_get_fd(pr));
598 blkid_free_probe(pr);
599 free(backup);
600 return 0;
601 }
602
603
604 static void __attribute__((__noreturn__))
605 usage(void)
606 {
607 size_t i;
608
609 fputs(USAGE_HEADER, stdout);
610 printf(_(" %s [options] <device>\n"), program_invocation_short_name);
611
612 fputs(USAGE_SEPARATOR, stdout);
613 puts(_("Wipe signatures from a device."));
614
615 fputs(USAGE_OPTIONS, stdout);
616 puts(_(" -a, --all wipe all magic strings (BE CAREFUL!)"));
617 puts(_(" -b, --backup create a signature backup in $HOME"));
618 puts(_(" -f, --force force erasure"));
619 puts(_(" -i, --noheadings don't print headings"));
620 puts(_(" -J, --json use JSON output format"));
621 puts(_(" -n, --no-act do everything except the actual write() call"));
622 puts(_(" -o, --offset <num> offset to erase, in bytes"));
623 puts(_(" -O, --output <list> COLUMNS to display (see below)"));
624 puts(_(" -p, --parsable print out in parsable instead of printable format"));
625 puts(_(" -q, --quiet suppress output messages"));
626 puts(_(" -t, --types <list> limit the set of filesystem, RAIDs or partition tables"));
627
628 printf(USAGE_HELP_OPTIONS(21));
629
630 fputs(USAGE_COLUMNS, stdout);
631 for (i = 0; i < ARRAY_SIZE(infos); i++)
632 fprintf(stdout, " %8s %s\n", infos[i].name, _(infos[i].help));
633
634 printf(USAGE_MAN_TAIL("wipefs(8)"));
635 exit(EXIT_SUCCESS);
636 }
637
638
639 int
640 main(int argc, char **argv)
641 {
642 struct wipe_control ctl = { .devname = NULL };
643 int c;
644 char *outarg = NULL;
645
646 static const struct option longopts[] = {
647 { "all", no_argument, NULL, 'a' },
648 { "backup", no_argument, NULL, 'b' },
649 { "force", no_argument, NULL, 'f' },
650 { "help", no_argument, NULL, 'h' },
651 { "no-act", no_argument, NULL, 'n' },
652 { "offset", required_argument, NULL, 'o' },
653 { "parsable", no_argument, NULL, 'p' },
654 { "quiet", no_argument, NULL, 'q' },
655 { "types", required_argument, NULL, 't' },
656 { "version", no_argument, NULL, 'V' },
657 { "json", no_argument, NULL, 'J'},
658 { "noheadings",no_argument, NULL, 'i'},
659 { "output", required_argument, NULL, 'O'},
660 { NULL, 0, NULL, 0 }
661 };
662
663 static const ul_excl_t excl[] = { /* rows and cols in ASCII order */
664 { 'O','a','o' },
665 { 0 }
666 };
667 int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
668
669 setlocale(LC_ALL, "");
670 bindtextdomain(PACKAGE, LOCALEDIR);
671 textdomain(PACKAGE);
672 atexit(close_stdout);
673
674 while ((c = getopt_long(argc, argv, "abfhiJnO:o:pqt:V", longopts, NULL)) != -1) {
675
676 err_exclusive_options(c, longopts, excl, excl_st);
677
678 switch(c) {
679 case 'a':
680 ctl.all = 1;
681 break;
682 case 'b':
683 ctl.backup = 1;
684 break;
685 case 'f':
686 ctl.force = 1;
687 break;
688 case 'h':
689 usage();
690 break;
691 case 'J':
692 ctl.json = 1;
693 break;
694 case 'i':
695 ctl.no_headings = 1;
696 break;
697 case 'O':
698 outarg = optarg;
699 break;
700 case 'n':
701 ctl.noact = 1;
702 break;
703 case 'o':
704 add_offset(&ctl.offsets, strtosize_or_err(optarg,
705 _("invalid offset argument")));
706 break;
707 case 'p':
708 ctl.parsable = 1;
709 ctl.no_headings = 1;
710 break;
711 case 'q':
712 ctl.quiet = 1;
713 break;
714 case 't':
715 ctl.type_pattern = optarg;
716 break;
717 case 'V':
718 printf(UTIL_LINUX_VERSION);
719 return EXIT_SUCCESS;
720 default:
721 errtryhelp(EXIT_FAILURE);
722 }
723 }
724
725 if (optind == argc) {
726 warnx(_("no device specified"));
727 errtryhelp(EXIT_FAILURE);
728
729 }
730
731 if (ctl.backup && !(ctl.all || ctl.offsets))
732 warnx(_("The --backup option is meaningless in this context"));
733
734 if (!ctl.all && !ctl.offsets) {
735 /*
736 * Print only
737 */
738 if (ctl.parsable) {
739 /* keep it backward compatible */
740 columns[ncolumns++] = COL_OFFSET;
741 columns[ncolumns++] = COL_UUID;
742 columns[ncolumns++] = COL_LABEL;
743 columns[ncolumns++] = COL_TYPE;
744 } else {
745 /* default, may be modified by -O <list> */
746 columns[ncolumns++] = COL_DEVICE;
747 columns[ncolumns++] = COL_OFFSET;
748 columns[ncolumns++] = COL_TYPE;
749 columns[ncolumns++] = COL_UUID;
750 columns[ncolumns++] = COL_LABEL;
751 }
752
753 if (outarg
754 && string_add_to_idarray(outarg, columns, ARRAY_SIZE(columns),
755 &ncolumns, column_name_to_id) < 0)
756 return EXIT_FAILURE;
757
758 init_output(&ctl);
759
760 while (optind < argc) {
761 struct wipe_desc *wp;
762
763 ctl.devname = argv[optind++];
764 wp = read_offsets(&ctl);
765 if (wp)
766 add_to_output(&ctl, wp);
767 free_wipe(wp);
768 }
769 finalize_output(&ctl);
770 } else {
771 /*
772 * Erase
773 */
774 while (optind < argc) {
775 ctl.devname = argv[optind++];
776 do_wipe(&ctl);
777 }
778 }
779
780 return EXIT_SUCCESS;
781 }