lib/sysfs: add subsystem and hotplug detection

Signed-off-by: Karel Zak <kzak@redhat.com>
eject: use sysfs API to detect hotplug

Signed-off-by: Karel Zak <kzak@redhat.com>
lsblk: add HOTPLUG column

Signed-off-by: Karel Zak <kzak@redhat.com>
docs: update TODO file

Signed-off-by: Karel Zak <kzak@redhat.com>
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>
libfdisk: fix cfdisk freespace analyze

The problem is how fdisk_partition_cmp_start() compare numbers, the
function returns result from "a->start - b->start", unfortunately the
numbers are uint64, but function returns "int".

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1170191
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk: rename sector_t to fdisk_sector_t

.. just to avoid too generic names for public API.

Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk: remove 'end' from struct fdisk_partition

This struct member duplicate "start+size".

Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk: fix bug in cmp_numbers() and partitions sorting

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1170191
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid: fix potential bufer overflows

While digging deeper into libblk probing, I found that some
computations might wrap and allocate too few buffer space which then
overflows. In particular on 32bit systems (chromebook) where size_t is
32bit, this is problematic (for 64bit the result fits into the calloc
size_t).

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount: add new libmnt_monitor API

It's usually enough to us [e]poll() to monitor kernel mount table, but
there is no way how to monitor changes in userspace mount options
(e.g. _netdev). The management of these mount options is completely
hidden in libmount and /rub/mount/utab is private libmount file.

This patch introduces new libmnt_mount API to monitor also userspace
mount table.

Signed-off-by: Karel Zak <kzak@redhat.com>
lib/mbalign: fix unsigned integer overflow [AddressSanitizer]

This error was reported 155 times.

lib/mbsalign.c:322:18: runtime error: unsigned integer overflow: 0 - 1
cannot be represented in type 'size_t' (aka 'unsigned long')

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
cal: fix signed integer overflow [AddressSanitizer]

misc-utils/cal.c:811:16: runtime error: signed integer overflow:
2147483645 + 536870911 cannot be represented in type 'int'

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
more: fix unsigned integer overflow [AddressSanitizer]

text-utils/more.c:1137:20: runtime error: unsigned integer overflow: 0 -
1 cannot be represented in type 'size_t' (aka 'unsigned long')
text-utils/more.c:1139:7: runtime error: unsigned integer overflow: 2 +
18446744073709551615 cannot be represented in type 'unsigned long'

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
lib: fix crc32 and crc64 interger overflows [AddressSanitizer]

lib/crc32.c:111:11: runtime error: unsigned integer overflow: 0 - 1
cannot be represented in type 'size_t' (aka 'unsigned long')

lib/crc64.c:101:12: runtime error: unsigned integer overflow: 0 - 1
cannot be represented in type 'size_t' (aka 'unsigned long')

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
fdisk: (sgi) fix unsigned integer overflow [AddressSanitizer]

include/pt-sgi.h:103:7: runtime error: unsigned integer overflow: 0 -
1186450447 cannot be represented in type 'unsigned int'

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
strutils: fix unsigned integer overflows [AddressSanitizer]

include/strutils.h:174:10: runtime error: unsigned integer overflow: 0 -
1 cannot be represented in type 'size_t' (aka 'unsigned long')

include/strutils.h:178:6: runtime error: unsigned integer overflow:
18446744073709551615 + 1 cannot be represented in type 'size_t' (aka
'unsigned long')

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
mkfs.cramfs: fix unsigned integer overflow [AddressSanitizer]

The original_size should be in 512 bytes blocks but it isn't while the
new_size is using 512 bytes blocks.  When original_size size is smaller
then 512 the new_size grows rather than shrinks, what one usually would
expect after data compression.  See also TODO comment near the change.

disk-utils/mkfs.cramfs.c:622:20: runtime error: unsigned integer
overflow: 64 - 512 cannot be represented in type 'unsigned long'

Reference: http://www.spinics.net/lists/util-linux-ng/msg10630.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
include/c: define UL_ASAN_BLACKLIST address_sanitizer function attribute

The UL_ASAN_BLACKLIST allows AddressSanitizer to be set off for functions
that cannot be checked.

Reference: http://dxr.mozilla.org/mozilla-central/source/mfbt/Attributes.h
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
lscpu: blacklist vmware_bdoor() AddressSanitizer check

AddressSanitizer is identifying the __asm__ segment as suspicious.

==1215==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000
(pc 0x0000004ccffd bp 0x7fff9b7184f0 sp 0x7fff9b7184e0 T0)
    #0 0x4ccffc in vmware_bdoor /home/src/util-linux/sys-utils/lscpu.c:660

Signed-off-by: Sami Kerola <kerolasa@iki.fi>