Commit Graph

32 Commits

Author SHA1 Message Date
Karel Zak e304441936 blkdiscard: do not probe for signatures on --force
The command-line option --force is defined as "disable all checks",
but the current code does not follow this idea. We need a way how to
disable read from the device (for example for dm-integrity devices).

Fixes: https://github.com/karelzak/util-linux/issues/1308
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-13 10:34:14 +02:00
Karel Zak b6464f8dc5 blkdiscard: fix compilation without libblkid
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-07 20:38:26 +02:00
Karel Zak 5d58258d62 blkdiscard: fix compiler warnings [-Wmaybe-uninitialized]
sys-utils/blkdiscard.c: In function 'main':
sys-utils/blkdiscard.c:304:33: warning: 'now.tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/blkdiscard.c:152:17: note: 'now.tv_usec' was declared here
sys-utils/blkdiscard.c:305:37: warning: 'now.tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/blkdiscard.c:152:17: note: 'now.tv_sec' was declared here
sys-utils/blkdiscard.c:304:33: warning: 'last.tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/blkdiscard.c:152:22: note: 'last.tv_usec' was declared here
sys-utils/blkdiscard.c:305:65: warning: 'last.tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/blkdiscard.c:152:22: note: 'last.tv_sec' was declared here

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-14 15:56:55 +01:00
Karel Zak 883d1d6564 build-sys: fix blkdiscard blkid.h use
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-06-19 19:04:10 +02:00
Lukas Czerner 0f23e4c13e blkdiscard: Refuse to proceed if signatures are found
Currently the blkdiscard has the ability to wipe out entere device in a
matter of seconds. This is fine as long as it's intentional, it is
potentially catastrophic if it's not.

With this commit blkdiscard will check for existing signatures on the
device and refuse to continue if any are found unless the operation is
forced with the -f option.

In an attempt to avoid breaking existing automation scripts the force is
only required when stdin refers to a terminal.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
2020-06-19 10:03:00 +02:00
Karel Zak f1970cc557 docs: improve size arguments description in --help output
Let's add "Arguments:" section to the --help output and describe
{K,M,G...}iB suffixes there.

Addresses: https://github.com/karelzak/util-linux/pull/917
Co-Author: ed <ed@s5h.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-05 11:01:36 +01:00
Karel Zak 34fed3ff17 blkdiscard: use O_EXCL, add --force
Let's make it more robust and safe. O_EXCL is an elegant way how to avoid
unwanted discard on mounted device.

Addresses: https://github.com/karelzak/util-linux/issues/915
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-23 15:49:55 +01: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
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 6e1eda6f22 misc: never use usage(stderr)
Here we fix all cases where we have usage(FILE*)
functions.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02: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 677ec86cef Use --help suggestion on invalid option
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>
2016-12-19 13:13:34 +01:00
Benno Schulenberg b31fd516ff blkdiscard: slice up the recently changed usage text
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-03-09 12:11:18 +01:00
Karel Zak 7154cc8926 blkdiscard: add --zeroout (BLKZEROOUT ioctl)
Requested-by: Yaniv Kaul <ykaul@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-24 15:21:38 +01:00
Ruediger Meier eeae448805 blkdiscard: don't report "zero range" at the end
We want to address the case that we have printed the last useful
stats line already within the loop. Avoiding an additional line
"Discarded 0 bytes ..." at the end.

Note there is a behavior change now for the edge cases "-v -l 0" and
"-v -o blksize" where we don't print any stats line anymore. But actually
it's correct, we never make any BLKDISCARD syscall with zero range.
Perhaps we should return error in these cases to help people who always
want to parse stats output on success.

CC: Federico Simoncelli <fsimonce@redhat.com>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2015-12-09 18:23:29 +01:00
Ruediger Meier a3e91e2646 blkdiscard: fix stats reporting (off by one)
CC: Federico Simoncelli <fsimonce@redhat.com>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2015-12-09 18:23:29 +01:00
Ruediger Meier 0e76536579 blkdiscard: fix timeval comparison inclusive usecs
We will see if this makes our "--step" tests reliable.

CC: Federico Simoncelli <fsimonce@redhat.com>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2015-12-09 18:23:29 +01:00
Sami Kerola ee24ab6f1e misc: fix redundant assignment and reassignments before use [cppcheck]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-08-08 07:46:39 +01:00
Benno Schulenberg fc14ceba5e textual: grammarize and harmonize the stat error message
The message "stat failed %s" seems to say that stat() failed to
do something, or failed to pass a test, but of course it means
that the statting of something failed.  So say so.  Also make
two very similar messages equal to this one.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-02-02 11:27:10 +01:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
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>
2015-01-06 11:27:38 +01:00
Karel Zak 784467ad2d blkdiscard: fix compiler warning
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-26 12:38:53 +01:00
Karel Zak 700031ade7 misc: use monotonic time rater than gettimeofday
Based on patch Alexander Samilovskih <alexsamilovskih@gmail.com>

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-18 14:35:21 +01:00
Karel Zak 4f55368cc5 blkdiscard: fix includes
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-27 10:00:19 +01:00
Federico Simoncelli c472a7e35a blkdiscard: add support for steps and progress
Signed-off-by: Federico Simoncelli <fsimonce@redhat.com>
2014-10-27 09:16:49 +01:00
Federico Simoncelli d7ce9acb33 blkdiscard: fail on sector misalignment 2014-10-27 09:16:47 +01:00
Karel Zak 0c75b6a470 blkdiscard: fix err->errx()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-14 12:14:05 +02:00
Raphael S. Carvalho 303884a495 blkdiscard: fix underflow when offset is greater than device size
If offset (range[0]) is greater than device size (blksize), the variable 'end'
will be greater than blksize, and range[1] (length) will be recalculated.
The underflow happens when subtracting range[0] (offset) from blksize, thus
range[1] will be the result of an underflow. The bug leads to unwanted behavior
from the program, where range[1] is likely to be a high number and then will
discard a considerable amount of blocks from the device. The fix consists of
exitting the program with an error message when the condition stated above is
true. Spotted while auditing the code.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2014-10-14 12:04:14 +02:00
Theodore Ts'o 8883945957 blkdiscard: BLKSSZGET fills in an int, not a uint64
Reported-by: Jason Cipriani <jason.cipriani@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-11-04 14:58:47 +01:00
Karel Zak 777519226d blkdiscard: use fstat() rather than stat() [coverity scan]
Calling function "open(char const *, int, ...)" that uses "path" after
 a check function. This can cause a time-of-check, time-of-use race
 condition.

.. well, in blkdiscard context it's mostly cosmetic change.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-06 10:29:04 +02:00
Benno Schulenberg 4ce393f4d8 textual: fix several typos and angular brackets in messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-06-07 12:11:14 +02:00
Lukas Czerner d964b669c8 blkdiscard: add new command
blkdiscard is used to discard device sectors. This is useful for
solid-state drivers (SSDs) and thinly-provisioned storage. Unlike
fstrim this command is used directly on the block device.

blkkdiscard uses BLKDISCARD ioctl or BLKSECDISCARD ioctl for the secure
discard.

All data in the discarded region on the device will be lost!

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
2012-09-28 01:12:09 +02:00