Commit Graph

243 Commits

Author SHA1 Message Date
Karel Zak 98a586f672 lsblk: sort list of columns
It's better to maintain sorted list and it's also better for --help output.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-09 11:09:33 +02:00
Karel Zak 856457bfcf lsblk: add column START for partition start offsets
Fix: https://github.com/karelzak/util-linux/issues/1340
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-09 10:57:54 +02:00
Karel Zak 3c9d13da63 lsblk: use MOUNTTARGETS in default output
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-11 10:46:16 +01:00
Karel Zak 62df539554 lsblk: use MOUNTPOINTS in --fs
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-08 13:45:14 +01:00
Karel Zak 37da403d57 lsblk: add FSROOTS column
It displays filesystem root attached to system, for example
btrfs with two mounted subvolumes:

	$ lsblk -oNAME,SIZE,MOUNTPOINTS,FSROOTS /dev/sdc1
	NAME SIZE MOUNTPOINTS FSROOTS
	sdc1  50M /mnt/A      /foo
		  /mnt/B      /bar

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-08 13:33:30 +01:00
Karel Zak c6648d2db1 lsblk: print all device mountpoints
* add libmount FS to struct lsblk_device

* add new column MOUNTPOINTS (pl.) with multi-line cells to display
  all mountpoints relevant for the device

* the old MOUNTPOINT is backwardly compatible and it (usually) displays the
  last device mountpoint from /proc/self/mountinfo

For example btrfs with more subvolumes:

 $ lsblk -o+MOUNTPOINTS /dev/sdc1
 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT MOUNTPOINTS
 sdc1   8:33   0  50M  0 part /mnt/test  /mnt/A
                                         /mnt/test
                                         /mnt/B

Note, in this case MOUNTPOINT displays mount point where is mounted
root of the filesystem.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-08 13:20:50 +01:00
Karel Zak 94ebe1d3e4 lsblk: add dependence between CD/DVD block and packet devices
This dependence is defined by

  $ cat /sys/class/pktcdvd/device_map
  pktcdvd0 252:0 11:0

Unfortunately, there is not any direct sysfs way how to refer this
relationship in /sys/{block,dev/block}. So, we have to read the
device_map file and then compare device numbers with the list.

$ lsblk /dev/sr0
NAME       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0         11:0    1 1024M  0 rom
└─pktcdvd0 252:0    1    0B  0 disk

Addresses: https://github.com/karelzak/util-linux/issues/1185
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-24 10:44:46 +01:00
Karel Zak a83bea2d3d bash-completion: (lsblk) update columns
and fix lsblk --help output

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-12 13:19:35 +02:00
Karel Zak 7636d906ef lsblk: add --width option
Addresses: https://github.com/karelzak/util-linux/issues/1160
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-12 12:19:48 +02:00
Karel Zak c90a8f1a3c lsblk: show all empty, except loopdevs
This patch improves the previous commit to accept also another empty devices.

Addresses: https://github.com/karelzak/util-linux/issues/1118
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-09 14:50:02 +02:00
Karel Zak 14bb8e3ca6 lsblk: ignore only loopdevs without backing file
* do not ignore all empty devices, we need more smart solution

* ignore only loop devices without backing file, for example:
 # touch img
 # losetup -f img
 losetup: img: Warning: file is smaller than 512 bytes; the loop device may be useless or invisible for system tools.

 - old version display nothing
 - new version:

 # lsblk /dev/loop0
 NAME  MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
 loop0   7:0    0   0B  0 loop

Addresses: https://github.com/karelzak/util-linux/issues/1118
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-09 12:23:33 +02:00
Karel Zak bb6c51a650 lsblk: print zero rather than empty SIZE
Addresses: https://github.com/karelzak/util-linux/issues/1118
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-09 12:00:10 +02:00
Karel Zak 6932a11035 lsblk: fix -T optional argument
Addresses: https://github.com/karelzak/util-linux/issues/1132
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-02 11:10:18 +02:00
Milan Broz e19e522df0 lsblk: Add SERIAL column to the SCSI output mode.
If there are several identical disks, disk serial number can help
to distinguish exact drive.

This could be helpful in debugging RAID failures and similar problems.

Signed-off-by: Milan Broz <gmazyland@gmail.com>
2020-07-14 10:37:56 +02:00
Ritika Srivastava c8487d854b lsblk: Ignore hidden devices
Lsblk throws the following error for nvmeNcXnY devices.

lsblk: nvme1c1n1: unknown device name

This is because nvmeNcXnY devices are hidden and do not have
the file /sys/block/<nvmeNcXnY>/dev.

Following patch was added
https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=d51f05bfecb299a830897106460bf395be440c0a
Which made lsblk read from /sys/block/<nvmeNcXnY>/device/dev
which do exist for nvmeNcXnY devices.

After the above patch, the unknown error goes away.
However, another error is encountered in the very next step.

nvme1c1n1: failed to initialize sysfs handler

This is because lsblk looks for /sys/dev/block/242:1
(nvmeNcXnY major:minor) pathname which usually exists for other
block devices but not for the nvmeNcXnY devices as they are hidden.

Below patch does not even print this error for hidden devices
and exits silently.

[kzak@redhat.com: - add prefix to make sysfs_devname_is_hidden()
                    usable for  /sys dumps
                  - use the function in initialize_device() more early]

Signed-off-by: Ritika Srivastava <ritika.srivastava@oracle.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-05-14 15:48:26 +02:00
Anthony Iliopoulos b239651bba lsblk: add dax (direct access) capability column
Signed-off-by: Anthony Iliopoulos <ailiop@suse.com>
2020-05-06 15:09:39 +02:00
Karel Zak 91b636b565 lsblk: fix -P regression from v2.34
Since v2.34 --list prints devices only once to make the output
user-readable. Unfortunately, it's regression for scripts/applications
where we need to parse lsblk output. So, let's make --pairs and --raw
backwardly compatible with versions before 2.34 and print all hierarchy.

Addresses: https://github.com/ibm-s390-tools/s390-tools/issues/80
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-25 15:31:23 +01:00
Karel Zak 107e955946 lsblk: add PARTTYPENAME column
Print also partition type in human-readable way.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1777261
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-12-04 12:38:57 +01:00
Karel Zak 4631edaee2 lsblk: add FSVER to --fs
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-11-15 11:23:44 +01:00
Karel Zak 9cca1ef2d5 lsblk: add FSVER (filesystem version) column
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1764523
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-11-12 13:55:55 +01:00
Karel Zak 6f74ede50a lsblk: read also GROUP,OWNER and MODE from dumps
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-15 13:08:09 +02:00
Sami Kerola f3aded3fdb
include/xalloc: ensure xstrdup() and xstrndup() returns nonnull attribute
Turned out lsblk is passing null as argument to xstrdup(), so fix that and
add assert() to make sure promise of not returning null is kept in future.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-07-14 11:52:13 +01:00
Karel Zak e3bb9bfb76 lsblk: force to print PKNAME for partition
PKNAME (parent kernel device name) is based on printed tree according
to parent -> child relationship. The tree is optional and not printed
if partition specified (.e.g "lsblk -o+PKNAME /dev/sda1"), but old
versions print the PKNAME also in this case.

Addresses: https://github.com/karelzak/util-linux/issues/813
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-27 09:22:18 +02:00
Karel Zak 106e696064 lsblk: make sure __process_one_device() has proper arguments [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-23 12:36:53 +02:00
Karel Zak 74152bf944 lsblk: check ul_path_scanf() return value [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-23 12:31:49 +02:00
Karel Zak 404eef654a lsblk: check stat() return code [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-23 12:28:13 +02:00
Karel Zak f6f8a671a9 lsblk: fix heap-use-after-free
Addresses: https://github.com/karelzak/util-linux/issues/787
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-06 12:39:07 +02:00
Karel Zak fe22543d6b lsblk: add more debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-02 15:51:48 +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 7761bd3bb6 lib/fileutils: add xreaddir()
Remove duplicate code and keep only one implementation in
include/fileutils.h.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-11 13:11:53 +02:00
Karel Zak a44cd89128 lscpu: fix excl[] array order
It (rows and columns) must be in ASCII order.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-03-19 16:56:28 +01:00
Karel Zak fb3761809f lsblk: force tree on --json --tree independently on used columns
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-03-18 16:58:41 +01:00
Karel Zak b9c088f2f3 lsblk: allow to specify tree column
* document --tree (was missing in the man page)
* add optional argument to --tree to specify tree

For example:

$ lsblk -o KNAME,SIZE,MOUNTPOINT --tree=KNAME /dev/dm-0
KNAME      SIZE MOUNTPOINT
dm-0     232.9G
└─dm-1   232.9G
  └─dm-2 232.9G

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-20 12:49:24 +01:00
Sami Kerola e361253e88
lsblk: fix null pointer dereferences
Both catched with -Wnull-dereference compiler option:

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-12-10 20:25:58 +00:00
Karel Zak 0bd05f5ee4 lsblk: add --merge
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:57:49 +01:00
Karel Zak dc4662f0e7 lsblk: add --dedup <column>
The target use-case are systems with large number of multi-path
devices or systems with duplicate (copied) filesystems.

The feature is flexible enough to use arbitrary column (for example
WWM or UUID, ...) as de-duplication key.

For example tree with multi-path devices sd{c,d,e,f}

./lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda           8:0    0 223.6G  0 disk
├─sda1        8:1    0   200M  0 part  /boot/efi
├─sda2        8:2    0   200M  0 part  /boot
├─sda3        8:3    0 130.3G  0 part
├─sda4        8:4    0    50G  0 part  /
└─sda5        8:5    0  42.9G  0 part
sdb           8:16   0  74.5G  0 disk
└─sdb1        8:17   0  74.5G  0 part  /home/archive
sdc           8:32   0   100M  0 disk
└─mpatha    253:0    0   100M  0 mpath
  ├─mpatha1 253:1    0    50M  0 part
  └─mpatha2 253:2    0    49M  0 part
sdd           8:48   0   100M  0 disk
└─mpatha    253:0    0   100M  0 mpath
  ├─mpatha1 253:1    0    50M  0 part
  └─mpatha2 253:2    0    49M  0 part
sde           8:64   0   100M  0 disk
└─mpatha    253:0    0   100M  0 mpath
  ├─mpatha1 253:1    0    50M  0 part
  └─mpatha2 253:2    0    49M  0 part
sdf           8:80   0   100M  0 disk
└─mpatha    253:0    0   100M  0 mpath
  ├─mpatha1 253:1    0    50M  0 part
  └─mpatha2 253:2    0    49M  0 part

De-duplicate by WWN:

./lsblk -M WWN
NAME        MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda           8:0    0 223.6G  0 disk
├─sda1        8:1    0   200M  0 part  /boot/efi
├─sda2        8:2    0   200M  0 part  /boot
├─sda3        8:3    0 130.3G  0 part
├─sda4        8:4    0    50G  0 part  /
└─sda5        8:5    0  42.9G  0 part
sdb           8:16   0  74.5G  0 disk
└─sdb1        8:17   0  74.5G  0 part  /home/archive
sdc           8:32   0   100M  0 disk
└─mpatha    253:0    0   100M  0 mpath
  ├─mpatha1 253:1    0    50M  0 part
  └─mpatha2 253:2    0    49M  0 part

Addresses: https://github.com/karelzak/util-linux/issues/616
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak 10501add02 lsblk: remember whole-disk, remove unused struct member
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak d81e32bde9 lsblk: make device_get_data() more generic
* independent on smartcols line
* keep sort data optional

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak 57a061339b lsblk: apply --nodeps to partitions too
The new implementation differentiates between partitions and another
dependences -- this is regression, we need root devices only.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak 8a2f175cbb lsblk: read queue/discard_granularity only when necessary
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak 81a8936c56 lsblk: reuse 'removable' flag from parent
It's used in the default output, let's make it a little bit more
effective.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak ff7992d631 lsblk: don't keep sysfs dirs open
Don't keep open sysfs file descriptors for all time to avoid problems
on systems with huge number of block devices.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak b158bd29de lsblk: rename set_device()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak b93585e8fc lsblk: add comments
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak e7b5353e8b lsblk: add process_all_devices_inverse()
This is necessary to implement --inverse. Note that this new
implementation scans /sys/dev/block/ to get top-level devices
and than it calls process_one_device().

Note that standard non-inverse tree does not use process_one_device()
as it's more effective to scan /sys/block where are no partitions.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak e15c9e3dc5 lsblk: reorder functions
The goal is to call process_one_device() from process_all_devices(),
so let's it keep in code in the right order.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak cf3c1bc77a lsblk: make process_partitions() more readable
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak 0e086f8230 lsblk: remove unncessary parent pointer
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak ae4c2c375b lsblk: use real rather than hardcoded parent
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak 4ca3c472f3 lsblk: use devtree functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00