summaryrefslogtreecommitdiffstats
path: root/misc-utils/wipefs.c
Commit message (Collapse)AuthorAgeFilesLines
* wipefs: fix variable / function shadowing [cppcheck]Sami Kerola2019-05-181-4/+4
| | | | | | | [misc-utils/wipefs.c:636] -> [misc-utils/wipefs.c:310]: (style) Local variable usage shadows outer function Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-6/+5Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: add missing ifdefRuediger Meier2018-06-251-2/+3
| | | | | | | | Seen on OSX: misc-utils/wipefs.c:822:5: warning: implicit declaration of function 'rereadpt' is invalid in C99 [-Wimplicit-function-declaration] rereadpt(fd, devname); Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* wipefs: postpone BLKRRPART until all is doneKarel Zak2018-06-111-6/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's possible we erase from the whole device before we erase from the partition on the same disk: # wipefs -a /dev/sdc /dev/sdc1 the current code calls re-read PT ioctl immediately after erase (so, before sdc1 is processed). The result is that sdc1 node is no more accessible: # wipefs -a /dev/sdc /dev/sdc1 /dev/sdc: 2 bytes were erased at offset 0x000001fe (dos): 55 aa /dev/sdc: calling ioctl to re-read partition table: Success wipefs: error: /dev/sdc1: probing initialization failed: No such file or directory It seems the most simple solution is to postpone the re-read ioctl and do it as the last thing. # wipefs -a /dev/sdc /dev/sdc1 /dev/sdc: 2 bytes were erased at offset 0x000001fe (dos): 55 aa /dev/sdc1: 2 bytes were erased at offset 0x00000438 (ext4): 53 ef /dev/sdc: calling ioctl to re-read partition table: Success The patch also adds a small delay before the re-read ioctl call. It's not elegant, but without the usleep(25000) the first attempt returns EBUSY. Addresses: https://github.com/karelzak/util-linux/issues/598 Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: use scols_column_set_json_type()Karel Zak2018-04-181-2/+10
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: cleanup offsets list usage, fix -t filterKarel Zak2017-08-311-110/+99Star
| | | | | | | | | | | * move list with offsets specified by -o to the wipe_control struct * don't clone the list of offsets, just keep it simple and stupid * apply all filters (-o and -t) in get_desc_for_probe() * always return offset and len by get_desc_for_probe() and apply always use libblkid hide & step-back Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1486777 Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-2/+2
| | | | | | | | | changed in include/c.h and applied via sed: sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c") sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c") Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* wipefs: improve --helpKarel Zak2017-06-291-23/+19Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: use libsmartcolsKarel Zak2017-06-291-41/+216
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The old output is horrible and useless when more devices specified. The old format is also too tricky if more signatures detected. The new output uses one line for each signature, prefixed by device name. For example my workstation: # wipefs /dev/sda* /dev/sdb* DEVICE OFFSET TYPE UUID LABEL sda 0x1fe PMBR sda 0x37e4895e00 gpt sda 0x200 gpt sda1 0x1fe vfat F2BC-BFEC EFI sda1 0x0 vfat F2BC-BFEC EFI sda1 0x36 vfat F2BC-BFEC EFI sda2 0x438 ext4 c5490147-2a6c-4c8a-aa1b-33492034f927 BOOT sda3 0x438 ext4 196972ad-3b13-4bba-ac54-4cb3f7b409a4 HOME sda4 0x438 ext4 d834bc84-0089-4be1-9013-cd8bf35d5ffa ROOT sda5 0x438 ext4 e8ce5375-29d4-4e2f-a688-d3bae4b8d162 WINE sda6 0xff6 swap 210337c6-f8b5-4d65-aab5-a0f343fa9ad4 SWAP sdb 0x200 gpt sdb 0x1fe dos sdb1 0x438 ext4 6467a684-0d10-4f61-a301-67bb26934d90 This patch add --noheadings, --json and --output. Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: try another magic strings on -o and -tKarel Zak2017-06-281-4/+20
| | | | | | | | The commit 92296e9ba2bf95259520fa7537ff8edc2aa9edbc introduces "try all permutations for the same superblock". This feature has to be also available if -o and -t is specified. Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: add control structKarel Zak2017-06-281-66/+64Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: don't do step-back if <type> does not matchKarel Zak2017-06-281-5/+14
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: print all signature permutationsKarel Zak2017-06-281-0/+4
| | | | | | | | | | | | | The same FS/RAID/PT signature may be detected by more ways and on more places on the device. The libblkid returns only the first detected signature by default. This patch use blkid_probe_hide_range() to re-scan device for all possible permutations of the same signature. For example the default wipefs(8) output as well as --no-act output will contains primary as well as backup GPT signature now. Reported-by: Ruediger Meier <sweet_f_a@gmx.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: consolidate all --help option descriptionsRuediger Meier2017-06-271-3/+2Star
| | | | | | | | Now we are always using the same text also for commands which had still hardcoded descriptions or where we can't use the standard print_usage_help_options macro. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: never use usage(stderr)Ruediger Meier2017-06-261-5/+9
| | | | | | | Here we fix all cases where we have usage(FILE*) functions. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* wipefs: exit on failed eraseKarel Zak2017-06-211-1/+1
| | | | | | | | | | | | | | | | | The current behavior is to report error and continue, it seems strange: # blockdev --setro /dev/sdc # wipefs -a /dev/sdc wipefs: /dev/sdc: failed to erase xfs magic string at offset 0x00000000: Operation not permitted /dev/sdc: 4 bytes were erased at offset 0x00000000 (xfs): 58 46 53 42 ^^^^^^^^^^^ not true The patch calls err() to exit. Reported-by: Vratislav Podzimek <vpodzime@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: do not use plain 0 as NULL [smatch scan]Sami Kerola2017-02-201-11/+11
| | | | | | | | | | text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer Since many 'struct option' has used zero as NULL make them more readable in same go by reindenting, and using named argument requirements. Reference: https://lwn.net/Articles/93577/ Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* docs: Fix word repetitionsYuri Chornoivan2017-02-131-1/+1
|
* wipefs: unused parameter [-Wunused-parameter]Karel Zak2017-01-051-2/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* Use --help suggestion on invalid optionKarel Zak2016-12-191-2/+1Star
| | | | | | | | The current default is to print all usage() output. This is overkill in many case. Addresses: https://github.com/karelzak/util-linux/issues/338 Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: force GPT detectionKarel Zak2016-04-131-2/+2
| | | | | | | | | | The library libblkid (as well as fdisks) requires protective MBR when probe for GPT by default. This is unnecessary for wipefs where we're more promiscuous and we want to delete as much as possible. This patch enables BLKID_PARTS_FORCE_GPT for wipefs. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1326474 Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: again fixing many printf format stringsRuediger Meier2016-03-071-6/+6
| | | | | | | | | | | | | | | | | | | This is again a huge patch regarding printf format strings to fix compiler warnings seen on clang/OSX. I'm trying to follow these rules strictly: #type #format #cast uintmax_t %ju - intmax_t %jd - uint64_t PRIu64 - int64_t PRId64 - size_t %zu - ssize_t %zd - ino_t %ju (uintmax_t) off_t %jd (intmax_t) Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* wipefs, sfdisk: include libgen.h for basename(3p)Ruediger Meier2016-03-071-1/+5
| | | | Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* wipefs: Allow b to be used as the short option for backupBill Pemberton2015-12-111-1/+1
| | | | | | | 'b' is documented as the short option for backup but b was not added to the optstring on the getopt_long call. Add it. Signed-off-by: Bill Pemberton <wfp5p@worldbroken.com>
* wipefs: fix FD leak on error [coverity scan]Karel Zak2015-01-291-2/+1Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* textual: add a docstring to most of the utilitiesBenno Schulenberg2015-01-061-0/+4
| | | | | | | | | This adds a concise description of a tool to its usage text. A first form of this patch was proposed by Steven Honeyman (see http://www.spinics.net/lists/util-linux-ng/msg09994.html). Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* textual: use usage() text element macrosSami Kerola2014-10-011-3/+2Star
| | | | | | | Translating these text elements should happen only once, which is more likely when the text macros are used properly. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: use manual tail usage() macroSami Kerola2014-10-011-1/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: fix some typos and inconsistencies in various messagesBenno Schulenberg2014-07-231-2/+2
| | | | | | | | Fixing plain typos, miswordings, inconsistent periods, some missing angular brackets, and a proper pluralization (even when it involves a constant, because for some languages the precise value matters). Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* Fix typo "ioclt" in various files.Lauri Nurmi2014-07-111-1/+1
|
* wipefs: don't erase nested partition tables by defaultKarel Zak2014-04-241-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | It's possible the partition contains a partition table (BSD, or hybrid boot images). It could be unexpected for users that the lost all (or another) partitions when work with non-whole disk device. Let's require --force. For example: # wipefs --all /dev/sdb erases all including partition table, but on hybrid disk where the first partition starts at first sector (so partition table is within the first partition): # wipefs --all /dev/sdb1 /dev/sdb1: ignore nested "dos" partition table on non-whole disk device wipefs: Use the --force option to force erase. asks for --force. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1077310 Signed-off-by: Karel Zak <kzak@redhat.com>
* libsmartcols: add columnsKarel Zak2014-04-031-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: call BLKRRPART when erase partition tableKarel Zak2014-01-201-8/+33
| | | | | | | | It's better to be smart than make things inconsistent (without BLKRRPART kernel still uses the erased PT and udev-db still contains obsolete information). Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: add comments to codeKarel Zak2014-01-161-4/+7
|
* wipefs: pluralize one messageBenno Schulenberg2013-10-081-2/+4
| | | | | Reported-by: Petr Písař <petr.pisar@atlas.cz> Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* wipefs: Also wipe superblocks with bad checksumsGabriel de Perthuis2013-09-111-1/+2
| | | | | | | | [kzak@redhat.com: - move BLKID_SUBLKS_BADCSUM login to blkid_probe_verify_csum()] Signed-off-by: Gabriel de Perthuis <g2p.code@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: clean up codeKarel Zak2013-04-261-28/+35
| | | | | | | This is C, use int & bits for boolean stuff rather than army of variables. Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: add --backupOndrej Oprala2013-04-261-4/+43
| | | | | | | | [kzak@redhat.com: - don't wipe if failed to create a backup file - use ts_scsi_debug_init in the regression tests] Signed-off-by: Ondrej Oprala <ooprala@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: make do_wipe() more readable [coverity scan]Karel Zak2013-03-271-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: fix memory leak [coverity scan]Karel Zak2013-03-271-2/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: add -f to getopt_long()Karel Zak2013-03-191-1/+1
| | | | | Reported-by: Dan Horák <dhorak@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* textual: use UTIL_LINUX_VERSION everywhereKarel Zak2013-01-251-2/+1Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: Add --force option to force it to erase.Richard W.M. Jones2012-11-201-4/+15
| | | | | | | | | | | | | | Commit c550f728f724360f99aae0fdb45b0589d9a347e0 added O_EXCL when opening the thing to erase. This broke the wipefs utility when used on anything which isn't an unmounted filesystem. eg. If you use it on a block device containing partitions, then it won't work because the kernel recognizes the partitions and so thinks the device is in use. This change adds the --force option which, when used, undoes the above flag change. However you still have to use --force most of the time when erasing something that isn't a plain unmounted filesystem. Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
* wipefs: use O_EXCLKarel Zak2012-10-151-1/+1
| | | | | Address: https://bugzilla.redhat.com/show_bug.cgi?id=865961 Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: use err_exclusive_options()Karel Zak2012-07-261-9/+9
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* wipefs: use exclusive_option()Sami Kerola2012-06-171-3/+10
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* wipefs: use symbolic value for markup modeSami Kerola2012-06-111-3/+8
| | | | | | In case mode value is found to be out of bounds program will crash. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc-utils: cleanup strtoxx_or_err()Karel Zak2012-05-151-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* include: rename writeall.h to all-io.hPetr Uzel2012-05-151-1/+1
| | | | Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
* misc-utils: verify writing to streams was successfulSami Kerola2012-04-041-0/+2
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>