Commit Graph

165 Commits

Author SHA1 Message Date
Karel Zak ee5a160250 sfdisk: add --relocate command
This command allows to relocate GPT backup header behind last
partition (--relocate gpt-bak-mini) or to standard position
(--relocate gpt-bak-std).

Hint: use "fdisk --list-details" to see "Alternative LBA".

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-05 14:40:45 +01:00
Karel Zak da0debad53 sfdisk: fix ref-counting for the script
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-04 15:54:53 +01:00
Karel Zak d8c68b52cc libfdisk: (script) accept sector-size, ignore unknown headers
- add sector-size between supported headers (already in --dump output)

- report unknown headers by -ENOTSUP

- ignore ENOTSUP in sfdisk (but print warning) and in fdisk_script_read_file()

Addresses: https://github.com/karelzak/util-linux/issues/949
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-04 15:11:19 +01:00
Karel Zak 65e27d545c sfdisk: add --disk-id to change disk UUID/ID
Addresses: https://github.com/karelzak/util-linux/issues/916
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-23 15:50:28 +01:00
Karel Zak 9fabc6d5fa sfdisk: remove broken step alignment for --move
* remove unnecessary and broken step alignment
* improve reported information in move log
* improve final progress bar update

Addresses: https://github.com/karelzak/util-linux/issues/938
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-23 15:07:32 +01:00
Karel Zak 2b26438c4b sfdisk: make sure we do not overlap on --move
The area we need to move does not have to be aligned to optimal I/O
size (step size) -- we need to be sure we do not move data
after/before the area.

Addresses: https://github.com/karelzak/util-linux/issues/938
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-23 12:44:58 +01:00
Karel Zak 319029e8b4 sfdisk: remove never read value [clang scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-15 12:38:19 +01:00
Karel Zak e1d7c65a5c sfdisk: check fdisk_script_set_header() return code [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-15 12:35:38 +01:00
Karel Zak bb607cb3b2 docs: fix typos [fossies codespell scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-09 10:18:16 +01:00
Karel Zak 980a25f9c4 sfdisk: (move-data) improve MiB/s progress bar
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-30 12:25:17 +02:00
Karel Zak 925f2d4f4f sfdisk: (--move-data) add speed to progress bar, don't use POSIX_FADV_DONTNEED
posix_fadvise() in the loop is pretty expensive.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-06 16:57:40 +02:00
Karel Zak 4bf424188d sfdisk: (--move-data) add simple progress bar
Addresses: https://github.com/karelzak/util-linux/issues/848
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-06 15:07:59 +02:00
Karel Zak 7942ba8a79 sfdisk: add --move-use-fsync, disable fsync() by default
It's slow, so slooow...

Addresses: https://github.com/karelzak/util-linux/issues/848
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-06 15:07:43 +02:00
Karel Zak 69f30c3126 sfdisk: (--move-data) make log optional
The log may be pretty huge and very probably not used by many users.
Let's make it optional.

The patch also clean up move-data output messages.

Addresses: https://github.com/karelzak/util-linux/issues/848
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-06 15:07:30 +02:00
Karel Zak 4ce4675cce sfdisk: (--move-data) keep step size based on optimal I/O
The current implementation is too paranoid and tries to keep in
memory only data which are on disk too. It means very small step size
when move partition only a few sectors left/right.

This patch enlarge the buffer to at least 1MiB and aligned to optimal
I/O.

Addresses: https://github.com/karelzak/util-linux/issues/848
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-06 15:05:59 +02:00
Karel Zak 45aaa8f3db sfdisk: make --no-act usable for --move-data too
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-06 12:37:26 +02:00
Karel Zak 91099dea35 tests: update sfdisk wipe output
- stderr is used for the warning (like in fdisk)

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-05 16:46:14 +02:00
Karel Zak 6cd671d427 fdisk: cleanup wipe warning
Let's remove 'old' from the sentence, add man page reference to
sfdisk.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-04 14:54:54 +02:00
Karel Zak 03154d2cf2 sfdisk: add -J between mutually exclusive options
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-03 16:22:21 +02:00
Karel Zak eabcbfc449 sfdisk: mark --dump and --list-free as mutually exclusive
Reported-by: Bertrand Jacquin <bertrand@jacquin.bzh>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-02 13:10:44 +02:00
Karel Zak 7837cd491a sfdisk: write all message to stdout
The code writes message to stdout and \n to stderr.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-30 15:40:06 +02:00
Sami Kerola a7466bdcbe
po: remove possibility to translate static option arguments
These strings are expected to be wrote exactly as they are parsed, so make
translating them impossible.  Since mkfs.cramfs -N option arguments need
this treatment use opportunity to slice usage() output to multiple lines.

Addresses: https://bugs.debian.org/907568
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-08-24 09:29:52 +01:00
Karel Zak 9f34182d53 sfdisk: use xstrcpy()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-20 12:42:43 +02:00
Sami Kerola 84f46d1f67
sfdisk: remove unnecessary size check [cppcheck]
Following warning is false positive.  Size of the buffer is defined using
BUFSIZ, and so the strncpy() will never overwrite the last byte that is
initialized to zero in get_user_reply().

[disk-utils/sfdisk.c:137] -> [disk-utils/sfdisk.c:136]: (warning) Either the
condition 'bufsz!=0' is redundant or strncpy() argument nr 3 can have
invalid value.  The value is -1 but the valid values are '0:'.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-18 22:07:20 +01:00
Karel Zak 89770db4ef fdisk: initialize buffers for get_user_reply() [coverity scan]
It's probably unnecessary, but better be safe than sorry.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-14 15:00:01 +02:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Sami Kerola 4813a5210f various: fix 'uninitialized when used' warnings [clang]
This change fixes "warning: variable 'var' may be uninitialized when used
here [-Wconditional-uninitialized]" warnings reported in various files.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-02-18 13:19:24 +01:00
Tobias Stoeckmann a6fb1ce79d sfdisk: Avoid out of boundary read with readline
It is not guaranteed that the returned string of readline() actually
contains as many bytes as buf can contain.

If bufsz is larger than the allocated memory by readline, an out of
boundary read occurs and leads to undefined behaviour. Most likely
that will be a crash.

This can be reproduced when readline-support is compiled in and when
you directly enter "quit" and "n" (to not write changes back to disk)
when sfdisk was called with any given device.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2019-02-18 13:05:14 +01:00
Karel Zak a77bd80d5a sfdisk: disable --activate for Hybrid GPT/MBR
Addresses: https://github.com/karelzak/util-linux/issues/699
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-04 14:06:45 +02:00
Karel Zak 49032ef7a4 sfdisk: be more verbose about PMBR on --activate
Addresses: https://github.com/karelzak/util-linux/issues/699
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-04 12:40:10 +02:00
Karel Zak a15dca2f6d include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()
Let's make it possible to use debug.h without environment variables.

Suggested-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-17 13:58:29 +01:00
Karel Zak 6ebc37854d libfdisk: (script) support R (RAID) and V (LVM) shortcuts
Addresses: https://github.com/karelzak/util-linux/issues/560
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-09 12:12:50 +01:00
Karel Zak a60d6b5217 sfdisk: wait before re-read
The original old (v2.13) fdisk had sleep(2) beany ideafore re-read ioctl. It
seems overkill, but short sleep is probably a good idea as we call
re-read on sfdisk start and at the end. It's possible that sfdisk is
too fast and the initial re-read is not gone yet.

It would be nice to have something more elegant than sleep, any idea?

Addresses: https://github.com/karelzak/util-linux/issues/557
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-02 14:48:01 +01:00
Karel Zak 9d4081cd6d sfdisk: create empty label on 'write' command
Addresses: https://github.com/karelzak/util-linux/issues/528
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-03 19:34:49 +01:00
Karel Zak 8175ed3d74 sfdisk: allow to disable bootable flag on all partitions
Let use '-' rather than a partition number to disable the bootable flag
on all partitions:

 sfdisk --activate /dev/sdc -

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-02 13:50:30 +01:00
Karel Zak 5d5ca9deaf sfdisk: allow to use --activate for PMBR
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-02 13:19:22 +01:00
Karel Zak ea0acfc335 sfdisk: use fdisk_device_is_used()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:34:55 +02:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
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>
2017-06-29 16:54:33 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +02:00
Ruediger Meier 86be6a32d3 misc: cosmetics, remove argument from usage(FILE*)
This patch is trivial and changes nothing, because
we were always using usage(stdout)

Now all our usage() functions look very similar. If wanted we
could auto-generate another big cosmetical patch to remove all
the useless "FILE *out" constants and use printf and puts
rather than their f* friends. Such patch could be automatically
synchronized with the translation project (newlines!) to not
make the translators sick.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
J William Piggott 6e2d5a4460 include/c.h: add USAGE_COMMANDS and USAGE_COLUMNS
* login-utils/lslogins.c: all uses changed
* misc-utils/findmnt.c: likewise
* sys-utils/blkzone.c: likewise
* disk-utils/sfdisk.c: likewise
* sys-utils/lscpu.c: likewise
* sys-utils/lsmem.c: likewise
* sys-utils/wdctl.c: likewise

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-24 13:57:12 -04:00
Chris Morin b0ff9a76b7 sfdisk: disambiguate units of --show-size
[kzak@redhat.com: - use optutils.h]

Signed-off-by: Chris Morin <chris.morin2@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-22 11:29:10 +02:00
Karel Zak 76ae3fe37a sfdisk: add hints for scanners [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:28:07 +02:00
Sami Kerola 57ebfde291 fdisk, sfdisk: avoid non-ANSI function declarations [smatch scan]
Adding _FUNCTION_DEF definition will exclude compatibility type definitions
that do include void key word in empty argument list.

/usr/include/readline/rltypedefs.h:35:23: warning: non-ANSI function
declaration of function 'Function'

These functions has been replaced by set of new ones in readline 4.2 (April
2001), and removed in 6.3 (February 2014).

Reference: https://cnswww.cns.cwru.edu/php/chet/readline/CHANGES
Rererence: https://blueslugs.com/blog/2016-10-23-updating-cppfunction-in-old-readline-consumers/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-14 14:01:14 +01:00
Sami Kerola c308e2050f misc: stop mixing declarations and code
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-13 14:48:04 +01:00
Sami Kerola 2ba641e5f3 misc: add static keyword to where needed [smatch scan]
text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be
static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
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>
2017-02-20 12:58:49 +01:00
Karel Zak bb88152764 sfdisk: improve --wipe functionality
* always (except --wipe=never) wipe old partition tables
* improve warn messages
* improve man page

Addresses: https://github.com/karelzak/util-linux/issues/410
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-14 15:11:35 +01:00
Karel Zak 91cce31a8e sfdisk: --quiet fixes
Addresses: https://github.com/karelzak/util-linux/issues/412
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-10 12:54:23 +01:00
Karel Zak 11e1097e6c sfdisk: unused parameter 'sf' [-Wunused-parameter]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-05 11:53:56 +01:00