Commit Graph

182 Commits

Author SHA1 Message Date
Karel Zak fbae144212 libfdisk: add and fix __format__ attributes
Reported-by: Jan Pazdziora <jpazdziora@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-18 16:42:57 +02:00
Karel Zak 8207f99b7a sfdisk: fix resources leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-25 10:25:12 +01:00
Karel Zak 45c2daa612 sfdisk: support for type="partition type name"
For example:

 # echo 'size=10MiB, type="linux usr x86"' | sfdisk /dev/sdc
 ...
 New situation:

 Device     Start   End Sectors Size Type
 /dev/sdc1   2048 22527   20480  10M Linux /usr (x86)

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-02-23 09:25:36 +01:00
Karel Zak ee7f4bee9b sfdisk: fix backward --move-data
* fix final message where number of moved sectors overflow number of
  all moved sectors

* align last step size before we use it for backward mode source and
  destination offsets calculation

Addresses: https://github.com/karelzak/util-linux/issues/1176
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-06 11:38:51 +01:00
Dimitri John Ledkov d7101e5911
sfdisk: correct --json --dump false exclusive
`--json` implies `--dump`, thus `--json --dump` must be
allowed. `--list-free` is incompatible with `--dump`, and thus also
with `--json`. Currently `--json --dump` is prohibited, even though
`--list-free` is not specified at all.

Regression introduced in 03154d2cf2.

Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com>
2020-11-04 12:47:55 +00:00
Sami Kerola 43ce3e7311 sfdisk: do not free device name too soon [coverity scan]
Fixes use after free error.

CID: 360798
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-16 12:00:53 +02:00
Karel Zak 29decc7b37 sfdisk: disable bootbits protection on '--wipe always'
Addresses: https://github.com/karelzak/util-linux/issues/1156
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-15 12:04:15 +02:00
Karel Zak 134b6296e3 fdisk: always report fdisk_create_disklabel() errors
This is fdisk, cfdisk and sfdisk change to inform user about fdisk_create_disklabel()
issues.

Addresses: https://github.com/karelzak/util-linux/issues/1147
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-30 11:49:05 +02:00
Karel Zak c3ef1268a0 sfdisk: add --lock and LOCK_BLOCK_DEVICE
Addresses: https://github.com/karelzak/util-linux/issues/921
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-05-27 16:59:46 +02:00
Wolfram Sang 9bf7517162 sfdisk: avoid unneeded empty lines with '--list-free'
Similar to commit 4a52959d1 ("(s)fdisk: avoid unneeded empty lines with
'--list'"), there were also two superfluous empty lines when /dev/sr0
didn't contain a medium. Refactor the '--list-free' code the same way as
in the mentioned commit.

Signed-off-by: Wolfram Sang <wsa@kernel.org>
2020-05-12 10:09:46 +02:00
Wolfram Sang 4a52959d18 (s)fdisk: avoid unneeded empty lines with '--list'
On my system, I got two superfluous empty lines because /dev/sr0 didn't
contain a medium. Refactor the code to handle the seperator within
print_device_pt() and print it only when assigning the device worked.
This unifies handling between print_all_devices_pt and (s)fdisk because
the latter did not consider the return code for the seperator while the
former did. Also, it saves some lines of code.

Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=814184 (first part)
Signed-off-by: Wolfram Sang <wsa@kernel.org>
2020-05-11 11:28:49 +02:00
Karel Zak 79ef974a68 sfdisk: only report I/O errors on --move-data
Now sfdisk stops everything on I/O error when moving data. It seems
better to report the error to user and continue as it's better to have
one bad sector in the partition than inconsistent all partition.

Addresses: https://github.com/karelzak/util-linux/issues/984
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-04-22 15:03:26 +02:00
Rosen Penev 042f62dfc5
[clang-tidy] do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:20:59 -07:00
Karel Zak e441601563 Merge branch 'topic/fdisk' 2020-03-03 16:22:10 +01:00
Karel Zak 5839a4ea03 sfdisk: extend --part-type, support aliases
* add support for aliases to sfdisk scripts
* add shortcuts and aliases to --part-type command

Note that --part-type evaluates shortcuts and aliases as the last
possibility (so after regular type string). This is necessary for
backward compatibility.

Example ('raid' type alias):
 # sfdisk --part-type /dev/sdc 1 raid

 # fdisk -l /dev/sdc
 ...
 Device     Boot Start    End Sectors Size Id Type
 /dev/sdc1        2048 204799  202752  99M fd Linux raid autodetect

Example ('L' type shortcut):

 # sfdisk --part-type /dev/sdc 1 L

 # fdisk -l /dev/sdc
 ...
 Device     Boot Start    End Sectors Size Id Type
 /dev/sdc1        2048 204799  202752  99M 83 Linux

Addresses: https://github.com/karelzak/util-linux/issues/958
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-03 16:15:39 +01:00
Karel Zak ac762ed71f sfdisk: fix previous --append patch, improve man page
- fix stupid typo (!has_container_or_unused(sf))
- use fdisk_is_partition_used() as fdisk_get_partition() returns
  nothing for unused partition
- update tests
- add more hints to the man page

Addresses: https://github.com/calamares/calamares/issues/1332
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-02 14:41:39 +01:00
Karel Zak fa3fface0f sfdisk: fix --append to PT with gaps
sfdisk trying to be more smart than libfdisk when analyze if we can
append to the current PT. libfdisk is able to use unused partition
to create a new one (if partno not strictly specified), but sfdisk
assumes that we can add partition to extended partition only.

Addresses: https://github.com/calamares/calamares/issues/1332
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-02 12:27:36 +01:00
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