Commit Graph

55 Commits

Author SHA1 Message Date
Stanislav Brabec 9147d2ad8a blockdev: Don't fail on missing start sector
It causes
 # blockdev --report" error:
 blockdev: /dev/dm-9: failed to read partition start from sysfs: No such file or directory

There is no reliable way to detect a geometry in this case. Report N/A
instead.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Cc: Martin Wilck <martin.wilck@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-06-05 10:04:21 +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
Karel Zak 345ddd2828 blockdev: use new ul_path_* API
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 13:19:28 +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 43c960c8fa blockdev: correct man page name in --help
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 15:36:39 +02:00
Ruediger Meier a861538cc8 blockdev: improve --help and man page
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:28:44 +02:00
Ruediger Meier 9325dbfd20 misc: cleanup and fix --unknownopt issues
Fixed checkusage.sh warnings:

  rtcwake: --unknownopt, non-empty stdout

  rtcwake: --unknownopt, stderr too long: 21
  blockdev: --unknownopt, stderr too long: 28
  lsipc: --unknownopt, stderr too long: 77
  pg: --unknownopt, stderr too long: 23
  renice: --unknownopt, stderr too long: 18
  sulogin: --unknownopt, stderr too long: 17
  write: --unknownopt, stderr too long: 12

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Karel Zak 95305cec15 Since 569d1dac7b we read device start
sector from the /sys/block/.../start file. The file exists only for
partitions, for wholedisk is the start of the device always zero.

References: https://bugzilla.redhat.com/show_bug.cgi?id=1202443
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-17 11:10:20 +01:00
Karel Zak 9eaa7292e4 blockdev: check return when read from sysfs [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-28 14:33:36 +01:00
Sami Kerola 338a6bc55b textual: improve error messages
Use error printing facilities that add command name in front of the error
message, and add explanation that is part of existing translations.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-09 09:19:22 +01:00
Phillip Susi 569d1dac7b blockdev: don't use HDIO_GETGEO
blockdev was still using this depreciated ioctl and that was
causing blockdev --report to fail on loop and nbd devices.
Switch to reading the partition start from sysfs instead.
This also allows it to correctly report > 2^32 sector counts.

[kzak@redhat.com: - check sysfs_init() return,
                  - use uint64_t rather than unsigned long long]

Signed-off-by: Phillip Susi <psusi@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-04 15:09:18 +01:00
Karel Zak 7ab32ae64d blockdev: add note about --setbsz usability
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-11 11:16:23 +02:00
Karel Zak 39d2e7067d Revert "blockdev: Remove the --setbsz (set blocksize) option which has never worked."
This reverts commit b1555acc2f.

It seems that the option is used by kernel guys to test kernel, so
let's keep the option in the blockdev(8) although it's almost useless
in userspace. All we need is to improve docs to make things more
obvious to end users.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-11 11:05:45 +02:00
Richard W.M. Jones b1555acc2f blockdev: Remove the --setbsz (set blocksize) option which has never worked.
This option has never worked.  If you try setting the block size on a
block device, and then read it using --getbsz, you will see that the
block size never changes.

The reason for this is because the block size is specific to the
current file descriptor opening the block device, so the change of
block size only persists for as long as blockdev has the device open,
and is lost once blockdev exits.

Also the block size is not really used anywhere.  Filesystems, for
example, have their own idea of block size and ignore this setting
completely.

(Thanks Masayoshi Mizuma for diagnosing the problem)

Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
2013-10-08 15:48:00 +02:00
Karel Zak e421313dc2 textual: use UTIL_LINUX_VERSION everywhere
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-01-25 12:05:26 +01:00
Benno Schulenberg 217615e8ed textual: standardize reporting of program name plus package version
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-01-25 11:47:29 +01:00
Karel Zak 657d9adb71 fix buffer overrun in some calls to sscanf
Reported-by: Sergei Antonov <saproj@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-09 22:26:27 +02:00
Sami Kerola 45ca68ece7 disk-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 20:04:39 +02:00
Karel Zak 15705de0ed blockdev: make the code more readable for static analysers
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-02 12:49:13 +01:00
Karel Zak 16bd802561 blockdev: remove non-ANSI function declaration [smatch scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-17 17:23:01 +01:00
Wanlong Gao f61a097bec blockdev: make functions static
make the functions in blockdev to statics.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
2012-01-05 17:09:27 +01:00
Karel Zak 637775c798 blockdev: indent usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-16 10:20:45 +02:00
Sami Kerola baaa447911 blockdev: coding style fix
Sync with README.devel

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-30 00:35:54 +02:00
Sami Kerola 75737ad645 blockdev: type mismatch fix
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-30 00:35:54 +02:00
Sami Kerola b763186fb4 blockdev: broken compiler warning circumvention removed
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-30 00:35:54 +02:00
Sami Kerola 14c76d8b51 blockdev: use pathnames.h to find partitions
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-30 00:35:54 +02:00
Sami Kerola 6b515d0b24 blockdev: use libc error facilities
Favour symbolic return values and use {err,warn}{,x} where ever
applies.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-30 00:35:48 +02:00
Sami Kerola bded204c49 blockdev: add --help option
The option is also accepted in format `-h'. As a side effect
usage function is now able to return success, and since it had to
be touched the printing is cleaned up.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-30 00:21:21 +02:00
Sami Kerola cc4d8d7206 blockdev: remove progname
Use errx, warnx or program_invocation_short_name instead.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-29 23:13:57 +02:00
Sami Kerola 00239f33ed blockdev: set options read only
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-29 22:31:03 +02:00
Karel Zak 455fdf4af8 blockdev: sync man page with code
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-08-24 12:59:41 +02:00
Karel Zak 1519ab5ffc blockdev: add BLKDISCARDZEROES
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-08-24 11:47:55 +02:00
Benno Schulenberg e6b0611b46 messages: gettextize a few skipped or forgotten ones
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2010-06-14 11:19:19 +02:00
Francesco Cosoleto eaa7716fae blockdev: reduce usage text width
Use spaces in usage text instead of tabs and reduce the distance between
option names and descriptions.

This helps to minimize problems due to limited number of columns and
translated texts which take up more space than English.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2010-03-31 17:27:09 +02:00
Karel Zak 515422fdb3 blockdev: use c.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-10-16 01:05:45 +02:00
Karel Zak ed98508a1c blockdev: fix topology ioctls
kernel 2.6.32-rc4 (kvm):

 # blockdev -v --getss --getpbsz --getiomin --getioopt --getmaxsect --getalignoff   /dev/sda
 get logical block (sector) size: 512
 get physical block (sector) size: 512
 get minimum I/O size: 512
 get optimal I/O size: 0
 get max sectors per request: 1024
 get alignment offset: 0

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-10-15 02:32:03 +02:00
Karel Zak d965d63f64 blockdev: add topology ioctls support
new options:

   --getpbsz                      get physical block (sector) size
   --getiomin                     get minimum I/O size
   --getioopt                     get optimal I/O size
   --getalignoff                  get alignment offset
   --getmaxsect                   get max sectors per request

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-10-15 01:22:42 +02:00
Karel Zak 726fa24e73 blockdev: add support for uint and ushort ioctls
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-10-15 00:06:07 +02:00
Karel Zak c3f62be7d8 blockdev: refactoring (better commands definition)
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-10-14 23:57:52 +02:00
Karel Zak 18c3e24341 blockdev: fix possible buffer overflow
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-04-29 14:17:39 +02:00
Karel Zak bc8b63833e blockdev: use lib/blkdev.c, fix --report
This patch replaces duplicate code with blkdev_ functions from
lib/blkdev.c.

The patch also fix the output from "blockdev --report". The Size field
was in 512-byte sectors instead in real size in bytes.

Signed-off-by: Karel Zak <kzak@redhat.com>
2007-11-07 20:59:28 +01:00
lizf 122db55d60 blockdev: fix: opened file leaving unclosed
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
2007-10-26 01:02:45 +02:00
Benno Schulenberg 65b27d3669 po: gettextizing some overlooked messages.
Gettextize three new strings, make two strings indentical to two others,
and gettextize three strings that are already gettextized elsewhere.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-08-14 14:46:28 +02:00
Karel Zak 1dea05a811 blockdev: use LU and LLU for BLKGETSIZE and BLKGETSIZE64
The "blkockdev --getsize" returns negative numbers on i386
for 1Tb devices. The BLKGETSIZE and BLKGETSIZE64 have to
use unsigned long and unsigned long long.

$ blockdev --getsize /dev/mapper/huge
-2147483648

Signed-off-by: Karel Zak <kzak@redhat.com>
2007-08-01 15:47:33 +02:00
Karel Zak 3281d4268a blockdev: fix "blockdev --getsz" for large devices
The "blockdev --getsz" command doesn't try to use BLKGETSIZE64 when
previous BLKGETSIZE failed with EFBIG. This patch fixes this problem.

Signed-off-by: Karel Zak <kzak@redhat.com>
2007-08-01 15:06:18 +02:00
Karel Zak a424171cd1 blockdev: cleanup usage() and update man page
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-06-29 12:06:58 +02:00
Karel Zak c2a1e78808 blockdev: add BLKFRAGET/BLKFRASET ioctls
In Linux 2.6 the BLKRASET ioctl has the desired effect for mounted
file-systems.  In Linux 2.4 it appears to set the number of blocks to
read-ahead on the *device* as opposed to within a *file*, and the
maximum value of this number is 255.  As a result the invocation of
blockdev will fail on Linux 2.4 for any usefully large value of
READAHEAD, and will not in any case have the desired affect for
fragmented files.

(Based on the blockdev-getfra-setfra.patch Debian patch.)

Signed-off-by: Karel Zak <kzak@redhat.com>
2007-06-29 11:38:54 +02:00
Karel Zak baf39af15b Imported from util-linux-2.13-pre2 tarball. 2006-12-07 00:26:58 +01:00
Karel Zak 48d7b13a1e Imported from util-linux-2.13-pre1 tarball. 2006-12-07 00:26:54 +01:00
Karel Zak c129767e06 Imported from util-linux-2.12b tarball. 2006-12-07 00:26:16 +01:00