Commit Graph

139 Commits

Author SHA1 Message Date
Benno Schulenberg
b779c1aecb mount, umount, swapon, fsck, lsblk, findmnt: harmonize six error messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-03-16 10:39:38 +01:00
Karel Zak
3fe3f560b7 Revert "include sysmacros.h where used"
This reverts commit 46a40c0184.
2016-03-08 14:26:33 +01:00
Mike Frysinger
46a40c0184 include sysmacros.h where used
BSD/Linux systems stick major/minor/makedev in sysmacros.h.  Newer Linux
libraries have been moving away from including sysmacros.h implicitly via
sys/types.h, so include it directly.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-03-08 14:21:55 +01:00
Ruediger Meier
2208b3ccb2 lib: remove openat fallback functions (include/at.h)
I have validated that we are still compatible at least back to
  - openSUSE 11.4
  - SLE 11
  - RHEL/CentOS 6
  - OSX 10.10.x, (Xcode 6.3)
  - FreeBSD 10.2

Confirmed incompatibility:
  - OSX 10.9.x, (Xcode 6.2)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 15:33:56 +01:00
Ruediger Meier
b0b24b11f8 lib: rename strmode() and setmode()
On BSD they are part of the standard C library.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 12:53:48 +01:00
Ruediger Meier
3fd1f7711e docs: fix typos found by codespell
Using "codespell" from https://github.com/lucasdemarchi/codespell

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-03 15:10:08 +01:00
Karel Zak
63107d1bbc lsblk: remove useless warnings
It's seems better to keep the warnings only in the debug output.

Reported-by:  Kay Sievers <kay@vrfy.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-22 19:38:18 +01:00
Karel Zak
95fb0ead2b lsblk: use unsigned type for SIZE
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-12 16:00:57 +01:00
Karel Zak
a6dc8dcd02 lsblk: allow to --sort by hidden column
For example:

	lsblk -o NAME --sort SIZE

prints NAMEs, but sort by SIZEs.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-12-10 13:03:46 +01:00
Karel Zak
1cd9d0d746 mount, umount, swapon, fsck, lsblk, findmnt: ignore malformed lines
The libmount provides way how to deal with parsing errors in fstab --
on error callback function is executed and according to the return
libmount manipulate with the malformed line, possible are three
states:

  1/ fatal error; all file ignored              (callback rc < 0)
  2/ recoverable error; malformed line ignored  (callback rc > 0)
  3/ ignore the error                           (callback rc == 0)

The 2/ is the default if no callback specified.

Unfortunately our utils uses 3/. The correct way is to use 2/.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-10-15 12:01:48 +02:00
Andreas Henriksson
56e78cb532 lsblk: fix resource leak [coverity scan]
Signed-off-by: Andreas Henriksson <andreas@fatal.se>
2015-08-31 10:09:45 +02:00
Milan Broz
c49ff158aa lsblk: Display mountpoint even for top-level device
If a filesystem is mounted on top-level block device
with existing partitions, the mountpoint is not displayed
in the lsblk output.

This situation can happen by a configuration mistake
and lsblk could be used to detect such a mistake.

This patch allows searching for a mountpoint for all displayed
devices, not only for leaf nodes.
(It should be pretty cheap operation, mtab is parsed only once.)

For example: lsblk /dev/loop1
NAME      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop1       7:1    0  128M  0 loop /mnt/tst
└─loop1p1 259:0    0  127M  0 loop

Signed-off-by: Milan Broz <gmazyland@gmail.com>
2015-07-31 10:44:57 +02:00
Karel Zak
4a102a4871 lsblk: add --json
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-04 15:49:52 +02:00
Karel Zak
92441d5c1e lsblk: use internally sysfs devnames
It seems better to keep the strange sysfs devnames internally and
translate to real devnames only on output or when we read from /dev.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-29 10:55:01 +02:00
Karel Zak
6c62abc42b lib/sysfs: rename devname functions, cleanup
Well, I don't have mental power to use function names like

 sysfs_devname_to_dev_name()

so this patch renames to

 sysfs_devname_sys_to_dev()
 sysfs_devname_dev_to_sys()

It also cleanups usage of the functions. We have to be sure that
sysfs.c code returns regular devnames. The existence of the sysfs
devnames (with '!') should be completely hidden in sysfs specific
code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-28 12:09:41 +02:00
Stanislav Brabec
d0dc6c17c5 Fix /sys to /dev node name translation
linux/drivers/base/core.c: device_get_devnode() defines a translation of
'!' in sysfs nodes to '/' in /dev nodes. The same translation has to be
done to properly support device nodes with slash (e. g. device nodes of
cciss driver and several other drivers).

Introduce new helper sysfs_devname_to_devno() and use it where
appropriate.

Fixes for example lsblk -f on devices using cciss driver.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2015-05-26 11:42:38 +02:00
Karel Zak
40b175084f lib/strutils: fix string_add_to_idarray() int vs. size_t
The function uses "int" as argument, but for array size (and index) is better
to use unsigned type (size_t). If we mix "size_t" in util (e.g. fdisk)
and "int" in lib/strutils.c then result is unexpected behavior on
ppc64.

	# sfdisk --list -o DEVICE,START,SIZE /dev/sdb
	Disk /dev/sdb: 50 MiB, 52428800 bytes, 102400 sectors
	Units: sectors of 1 * 512 = 512 bytes
	Sector size (logical/physical): 512 bytes / 4096 bytes
	I/O size (minimum/optimal): 4096 bytes / 32768 bytes
	Disklabel type: gpt
	Disk identifier: 3B8559DB-33AF-43E9-BEFC-C331D829B539
	lt-sfdisk: libfdisk/src/label.c:178: fdisk_label_get_field: Assertion `id > 0' failed.

The patch cleanup all code to use size_t everywhere.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-22 11:08:05 +02:00
Karel Zak
296dc15c24 lsblk: don't ignore dependences for partitioned devies
The code only lists partitions, but ignore another dependencies
on whole-disk device:

	$ lsblk /dev/sdb
	NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
	sdb      8:16   0 298.1G  0 disk
	└─sdb1   8:17   0 298.1G  0 part

	$ ls /sys/block/sdb/holders/
	dm-0

fixed version:

	$ lsblk /dev/sdb
	NAME        MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
	sdb           8:16   0 298.1G  0 disk
	├─sdb1        8:17   0 298.1G  0 part
	└─mpatha    253:0    0 298.1G  0 mpath
	  └─mpatha1 253:1    0 298.1G  0 part

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-01 12:23:23 +02:00
Karel Zak
92abdcaee0 lsblk: follow kernel for inverse tree
For multi-path devices kernel defines dependence between the device
and whole-list:

	$ ls /sys/block/dm-0/slaves/
	sdb

but lsblk inserts partition into the tree:

	$ lsblk -s -oNAME,KNAME /dev/dm-1
	mpatha1   dm-1
	└─mpatha  dm-0
	  └─sdb1  sdb1     <--- !
	    └─sdb sdb

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-01 12:06:41 +02:00
Karel Zak
7e786ecae1 lsblk: add debug support
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-01 12:06:15 +02:00
Karel Zak
1539750f2a lsblk: implement SOMEOK (=64) return code
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-29 12:35:26 +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
7f14ee1b55 lsblk: add SUBSYSTEMS column
$ lsblk -oNAME,SIZE,TYPE,SUBSYSTEMS /dev/sr0
 NAME  SIZE TYPE SUBSYSTEMS
 sr0   7.8M rom  block:scsi:usb:pci

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-12-02 11:38:15 +01:00
Karel Zak
483987c275 lsblk: add HOTPLUG column
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-12-02 11:09:04 +01:00
Sami Kerola
7fe033ef9a lsblk: fix compiler warning
warning: ISO C forbids empty initializer braces [-Wpedantic]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:42 +02:00
Benno Schulenberg
1d23119072 textual: remove some inconsistent periods from error messages
While doing so, also improve translatability and some wordings.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-08-11 14:51:54 +02:00
Karel Zak
ccef45168b Merge branch 'master' of https://github.com/yurchor/util-linux
* 'master' of https://github.com/yurchor/util-linux:
  Fix typos in user visible messages
2014-07-22 12:01:50 +02:00
Karel Zak
b6327c6fd8 lsblk: check number of used columns
The current code does not check size of the columns[] array when add
the next on command line specified column. We check the array size for
"-o <columns>" but not for another options.

Old version:

   $ for x in $(seq 0 100); do echo "-t"; done | xargs lsblk
   xargs: lsblk: terminated by signal 11

new version:

  $ for x in $(seq 0 100); do echo "-t"; done | xargs lsblk
  lsblk: too many columns specified, the limit is 83 columns.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-18 13:47:53 +02:00
Karel Zak
03df0d1150 lsblk: differentiate between infos[] and columns[]
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-18 13:45:32 +02:00
Yuri Chornoivan
b5af3ee835 Fix typos in user visible messages 2014-07-03 09:33:15 +03:00
Karel Zak
710ed55dcd libsmartcols: add debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-06 13:47:06 +02:00
Ruediger Meier
4e9e0d1e06 lsblk: fix, set default sort_id = -1
Introduced in 642048e4:
 $ lsblk -o SIZE /dev/loop1
lsblk: the sort column has to be between output columns.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-05-21 11:59:24 +00:00
Karel Zak
642048e4a4 lsblk: add --sort <column>
This implementation allow to sort output by arbitrary output column.

Note that output is always converted to human readable strings, but
sort functions in many cases work with original data (stored as
private data to cells by scols_cell_set_userdata()).

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-05-20 15:12:51 +02:00
Masatake YAMATO
1b4d2a4a4a lsblk: add -O option to show all available columns
Simple command line for gathering information as many as possible is
useful when understanding a system, especially when trouble shooting.

This patch introduces -O option which enables all available columns.

[kzak@redhat.com: - define collisions between options,
                  - define columns when parse argv[]]

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-05-06 10:56:52 +02:00
Karel Zak
0925a9dd6c libsmartcols: clean up flags usage
* rename flags functions to scols_table_enable_*
 * rename *_no_foo() functions to _nofoo()
 * output formats are mutually exclusive, so don't use flags there
 * don't assume symbols in scols_new_table(), use scols_table_set_symbols()

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-03 16:09:57 +02:00
Karel Zak
5c5941df74 lsblk: remove unnecessary code
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-03 12:29:20 +02:00
Karel Zak
bb6e822ad2 lsblk: clean up data preparation
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-03 12:29:20 +02:00
Ondrej Oprala
9bd4e5c0bd lsblk: use libsmartcols
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2014-04-03 12:29:18 +02:00
Karel Zak
5a2fd9329e lsblk: add PARTFLAGS column
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-07 11:14:46 +01:00
Michael Marineau
4686ba17a8 lsblk: add PARTTYPE tag
To stay in sync with blkid add PARTTYPE as an available output column.
2014-02-10 10:47:21 +01:00
Karel Zak
71d842c019 lsblk: fix -D segfault
References: https://bugzilla.redhat.com/show_bug.cgi?id=1031262
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-18 11:27:35 +01:00
Benno Schulenberg
3e59c48159 textual: remove duplicate mention of '--help' from lsblk help text
Also improve the alphabetization of the other options.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-10-14 14:54:47 +02:00
Karel Zak
a239b17926 lsblk: use TT_FL_FREEDATA for tt table
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:46:59 +02:00
Karel Zak
50fccba1ab misc: use libmnt_table reference counter
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-21 16:07:51 +02:00
Karel Zak
6195f9e6fa misc: use libmnt_cache reference counting
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-21 14:38:38 +02:00
Karel Zak
da531dd8d5 lsblk: use devno to get mountpoint
The device (for example LVM logical volume) could be renamed and then
the device name from /proc/self/mountinfo does not match with reality.
So, we also need to check devno. Unfortunately we cannot completely
rely on devno, because for example btrfs uses psudo device numbers.

References: https://bugzilla.redhat.com/show_bug.cgi?id=980463
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-07-08 14:21:03 +02:00
Karel Zak
460c7afb79 lsblk: add SERIAL column
... to return short serial number of the disk (from udev db)

Addresses: https://github.com/karelzak/util-linux/issues/33
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-13 13:33:41 +02:00
Yuri Chornoivan
ef75bc880e Fix various typos 2013-04-26 12:50:03 +02:00
Karel Zak
c7e76cd145 lsblk: add --paths
Now it's not so simple to generate full paths to devices if you want to
use user friendly names like /dev/mapper/foo. Let's make it easy.
2013-03-29 17:16:09 +01:00
Karel Zak
65060bd04d lsblk: check returns [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-27 14:13:12 +01:00