Karel Zak [Fri, 25 May 2018 10:51:55 +0000 (12:51 +0200)]
lscpu: use new ul_path_* API
* use ul_path_* API for /sys/devices/system/cpu paths
* use ul_path_* API for /proc
* rename is_compatible() to is_devtree_compatible() as it works
with the devices tree only
Karel Zak [Wed, 9 May 2018 13:54:12 +0000 (15:54 +0200)]
lib/path: new implementation
The goal is to avoid duplicate code in path.c and sysfs.c and make it
possible to define prefix for paths for all sysfs and procfs based
utils. Now we have /proc snapshots (for tests) for lscpu only. It
would be nice to have the same (for sysfs) for lsblk and another tools.
* very simple API to read numbers, strings and symlinks
* based on openat()
pc = ul_new_path("/sys/block/sda");
ul_path_read_u64(pc, &size, "size");
ul_path_read_u64(pc, &lsz, "queue/logical_block_size");
* printf-like API to generate paths, for example:
ul_path_readf_u64(pc, &num, "sda%d/size", partno)
* allow to define prefix to redirect hardcoded paths to another
location, for example:
pc = ul_new_path("/sys/block/sda");
ul_path_set_prefix(pc, "/my/regression/dump");
ul_path_read_u64(pc, &num, "size");
to read /my/regression/dump/sys/block/sda/size
* allow to extend the API by "dialects", for example for sysfs:
pc = ul_new_path(NULL);
sysfs_blkdev_init_path(pc, devno, NULL);
and use ul_path_* functions to read from @pc initialized by
sysfs_blkdev_init_path()
partx: exit with error code when partition read failed
Make sure partx exits with a non-0 return code when
it runs into either code-path where getting the partition
table failed (or wasn't even attempted because of previous
error condition).
Change was tested using:
touch /tmp/foobar
partx -s - /tmp/foobar
Previously that was only printing an error/warning message
and then exiting with 0, but after this change it exits
with 1.
Signed-off-by: Andreas Henriksson <andreas@fatal.se> Reported-by: Juan Céspedes <cespedes@debian.org>
Addresses: https://bugs.debian.org/898426
Karel Zak [Mon, 11 Jun 2018 10:21:56 +0000 (12:21 +0200)]
wipefs: postpone BLKRRPART until all is done
It's possible we erase from the whole device before we erase from the
partition on the same disk:
# wipefs -a /dev/sdc /dev/sdc1
the current code calls re-read PT ioctl immediately after erase (so,
before sdc1 is processed). The result is that sdc1 node is no more
accessible:
# wipefs -a /dev/sdc /dev/sdc1
/dev/sdc: 2 bytes were erased at offset 0x000001fe (dos): 55 aa
/dev/sdc: calling ioctl to re-read partition table: Success
wipefs: error: /dev/sdc1: probing initialization failed: No such file or directory
It seems the most simple solution is to postpone the re-read ioctl and
do it as the last thing.
# wipefs -a /dev/sdc /dev/sdc1
/dev/sdc: 2 bytes were erased at offset 0x000001fe (dos): 55 aa
/dev/sdc1: 2 bytes were erased at offset 0x00000438 (ext4): 53 ef
/dev/sdc: calling ioctl to re-read partition table: Success
The patch also adds a small delay before the re-read ioctl call. It's
not elegant, but without the usleep(25000) the first attempt returns
EBUSY.
Addresses: https://github.com/karelzak/util-linux/issues/598 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Fri, 8 Jun 2018 09:37:55 +0000 (11:37 +0200)]
blkzone: fix whole device detection
Matias Bjørling wrote:
The current detection code for chunk size assumes that the
underlying device is a device that uses the minor device id
as the partition id, and that the whole device has minor id 0.
This is not true for example null_blk and nvme device drivers.
Let's use sysfs_devno_to_wholedisk() to get whole-disk devno.
Addresses: https://github.com/karelzak/util-linux/pull/646 Reported-by: Matias Bjørling matias.bjorling@wdc.com Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Wed, 6 Jun 2018 13:57:24 +0000 (15:57 +0200)]
agetty: keep c_iflags unmodified on --autologin
agetty sets c_iflags according to interaction with serial line in
get_logname(). For --autologin it does not read from the line, so we
have no clue how to set the flags.
The current behavior is to zeroize the flags. Unfortunately, it seems
like bad idea, because the line may be already properly initialized by
kernel (or systemd, etc.).
The new behavior is not touch the flags on --autologin.
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1252764 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Mon, 4 Jun 2018 13:20:28 +0000 (15:20 +0200)]
libsmartcols: don't print empty column
The commit 0f9f927b6f62cb7f488fadfad76c4a5defdefe36 forces
libsmartcols to use one byte as a minimal column width. This seems
like a bug if the column is empty and without header.
Karel Zak [Fri, 1 Jun 2018 12:07:53 +0000 (14:07 +0200)]
mount: keep MS_MOVE as flag
The previous commit 4ebea84bb1ca6b0fa817588aba13de26c8d5e5a0 replaced
all operations by strings, but it does not work for MS_MOVE as this
operation is not supported in fstab by libmount.
Karel Zak [Fri, 1 Jun 2018 10:11:03 +0000 (12:11 +0200)]
mount: use internally string to set move/bind operations
It's better to inform libmount about operations by string than by
flags, because for example "rbind,slave" cannot be specified by
MS_REC|MS_BIND|MS_SLAVE.
https://bugzilla.redhat.com/show_bug.cgi?id=1584443 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Mon, 28 May 2018 13:46:28 +0000 (15:46 +0200)]
libmount: accept another flags on MS_REMOUNT|MS_BIND
The current libmount MS_REMOUNT|MS_BIND support is restricted to
MS_RDONLY (read-only bind mount). This is too restrictive as Linux
kernel supports bind-remount for arbitrary VFS flags.
After this update you can use
# mount /dev/sdc1 /mnt/A
# mount --bind -onosuid,noexec /mnt/A /mnt/B
Sami Kerola [Sat, 12 May 2018 21:45:58 +0000 (22:45 +0100)]
include/pt-mbr.h: fix integer overflow
gcc -fsanitize=undefined gives following warning.
include/pt-mbr.h:27:51: runtime error: left shift of 248 by 24 places cannot
be represented in type 'int'
It looks like char is converted internally to int before bit-shift, and that
type overflows when char value is greater than 127. Following code snippet
will show the effect what is stored when undefined behaviour happens.
#include <stdio.h>
#include <inttypes.h>
int main(int argc, unsigned char **argv)
{
char p[] = { 170, 170, 170, 170 };
unsigned int uint = p[3];
uint64_t res = 0;
/* overflow */
res = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
printf("%" PRIu64 "\n", res);
/* this is fine */
res = 0;
res = p[0] | (p[1] << 8) | (p[2] << 16) | (uint << 24);
printf("%" PRIu64 "\n", res);
return 0;
}
I tested gcc 8.1.0, clang 6.0.0, and tcc 0.9.27 and they all printed the
same values.
Because output is result of undefined behavior what is stored may change in
future, and other compilers / version might do something different. In the
case of what pt-mbr.h the destination data type size was commonly 32 bits in
size, that truncated excess rubbish from bitshift. Needless to say that was
not very robust code.
Sami Kerola [Thu, 10 May 2018 20:18:53 +0000 (21:18 +0100)]
nls: remove translation strings
While looking earlier commit I noticed everything but formatting was removed
from a message in namei.c file. That inspired me to look if there are more
strings that does not need translation project attention. This change
removes at least some of them, if not all.
Sami Kerola [Fri, 4 May 2018 19:38:03 +0000 (20:38 +0100)]
tests: move stderr redirection out from test expression
Fix shellcheck error.
if ! [ "$paraller_jobs" -ge 0 2>/dev/null ]; then
^-- SC1009: The mentioned parser error was in this if expression.
^-- SC1073: Couldn't parse this test expression.
^-- SC1072: Expected test to end here (don't
wrap commands in []/[[]]). Fix any
mentioned problems and try again.
Karel Zak [Fri, 25 May 2018 11:53:03 +0000 (13:53 +0200)]
libblkid: (ntfs) enlarge cluster limit to 2MB
Windows 10 Creators edition has extended the ntfs cluster limit to
2MB. As a consequence blkid does not identify recent partitions with
clusters beyond 65K as ntfs ones.
Addresses: https://github.com/karelzak/util-linux/issues/641 Signed-off-by: Karel Zak <kzak@redhat.com>
Co-Author: Jean-Pierre André <jean-pierre.andre@wanadoo.fr>