Linux kernel reports devices greater than area readable by read(2).
The readable area is usually 2-3 CD blocks smaller (CD block is
2048-bytes) than size returned by BLKGETSIZE. This patch checks for
this issues to avoid I/O errors in probing functions.
Reported-by: Thomas Schmitt <scdbackup@gmx.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
When a probe is created with an offset, e.g. via
blkid_probe_set_device(), this offset is correctly used when looking for
the signatures, but is not respected by blkid_do_wipe() function.
Therefore the signature is removed from an invalid location.
Usecase: Wiping signatures from an area on the block device where
partition is to be created (but as it does not exist yet, there's no
device node for it and probe on the whole block device has to be used
with correct offset and length).
Reproducer:
======================== wiper.c ===========================
const char *dev;
unsigned long offset;
unsigned long size;
int main(int argc, char** argv) {
if (argc != 4) {
printf("usage: wiper dev offset size\n");
exit(1);
}
dev = argv[1];
offset = strtoull(argv[2], NULL, 10);
size = strtoull(argv[3], NULL, 10);
printf("dev=%s, off=%llu, size=%llu\n", dev, offset, size);
int fd = open (dev, O_RDWR);
if (fd == -1) {
perror("open");
exit(1);
}
blkid_loff_t wipe_offset = offset * SECTOR_SIZE;
blkid_loff_t wipe_size = size * SECTOR_SIZE;
int ret;
blkid_probe pr;
pr = blkid_new_probe();
if (!pr)
return 0;
ret = blkid_probe_set_device(pr, fd, wipe_offset, wipe_size);
ret = blkid_probe_enable_superblocks(pr, 1);
ret = blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC);
while (blkid_do_probe(pr) == 0) {
ret = blkid_do_wipe(pr, 0);
}
blkid_free_probe(pr);
close(fd);
}
======================== wiper.c ===========================
Steps to reproduce:
modprobe scsi_debug
parted -s /dev/sdX mklabel gpt
parted -s /dev/sdX mkpart first 2048s 4095s
mkfs.ext2 /dev/sdX1
wipefs -np /dev/sdX1
./wiper /dev/sdX1 2048 2048
Actual result: wiper gets into endless loop, because
blkid_do_wipe() wipes at wrong location (1080), leaving the signature
on /dev/sdc1. So it is again found by blkid_do_probe(), and so on.
Expected result: wiper clears the ext2 signature at offset 1049656(=1080+2048*512).
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
From abb2a420924c792be33aa3ed825b1348ea7d51a9 Mon Sep 17 00:00:00 2001
From: "Yuriy M. Kaminskiy" <yumkam@gmail.com>
Date: Wed, 13 Apr 2016 17:30:10 +0300
Subject: [PATCH] losetup: fix outdated comment
--direct-io argument was made optional by
f98d9641a3, but this comment was not
updated accordingly
Signed-off-by: Yuriy M. Kaminskiy <yumkam@gmail.com>
* '2016wk15' of git://github.com/kerolasa/lelux-utiliteetit:
mount: try to tell what mount was doing when it failed
dmesg: --notime should not suppress --show-delta
script: check status of writes when closing outputs
script: avoid trying fclose(NULL)
sulogin: make fopen O_CLOEXEC specifier usage portable
script: close file descriptors on exec
docs: optinal option arguments should be long-only
It might be that the underlying filesystem just doesn't support SELinux
labeling. This fixes creating swap on vfat live media:
# livecd-iso-to-disk.sh --msdos --swap-size-mb 666 ...
Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
Earlier output did not give enough information to system admin to fix an
issue in /etc/fstab effectively.
$ sudo mount -a
mount: mount(2) failed: No such file or directory
Addresses: https://bugs.launchpad.net/bugs/1557145
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The --show-delta is off by default, which means it can be only on when user
has requested to see these time stamps. The --notime option should not turn
the delta outputing off, because then option order matters and no-one wants
that. Example of the old output:
$ dmesg --notime --show-delta | sed -n 's/ version.*//p; q'
[< 0.000000>] Linux
$ dmesg --show-delta --notime | sed -n 's/ version.*//p; q'
Linux
Addresses: https://bugs.launchpad.net/bugs/1544595
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Here is a one-liner to reproduce the issue.
$ mkdir example && cd example && chmod 0500 . && script
Script started, file is typescript
script: cannot open typescript: Permission denied
Script done, file is typescript
Segmentation fault (core dumped)
Addresses: https://bugs.launchpad.net/bugs/1537518
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The close at exit specifier "e" is glibc extension, so use it only if when
the extension is available.
Proposed-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The commands spawned from script(1) will never need access various file
descriptors the script(1) is using.
Reviewed-by: Ruediger Meier <sweet_f_a@gmx.de>
Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The file mtab is evil and already unused by mainstream distributions.
Now libmount is able to detect mtab->/proc/mounts and use
/proc/self/mountinfo if necessary. This heuristic seems overkill in
many cases. It's also dangerous on systems where mountinfo is strongly
required (systemd based distros).
This patch #ifdefs mtab code and forces libmount to always use
/proc/self/mountinfo.
The new configure option --enable-libmount-support-mtab is necessary
to enable old behavior to support mtab.
Signed-off-by: Karel Zak <kzak@redhat.com>
The library libblkid (as well as fdisks) requires protective MBR when
probe for GPT by default. This is unnecessary for wipefs where we're
more promiscuous and we want to delete as much as possible. This patch
enables BLKID_PARTS_FORCE_GPT for wipefs.
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1326474
Signed-off-by: Karel Zak <kzak@redhat.com>
We want to to use it for other tests without depending on
gnu md5sum and without cut or awk.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Earlier message:
$ chrt -i 1 ls
chrt: failed to set pid 0's policy: Invalid argument
basically told 'something failed', while the new one tries to be more
helpful.
$ chrt -i 1 ls
chrt: unsupported priority value for the policy: 1: see --max for valid range
Addresses: https://bugs.debian.org/791707
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Some inputs make getwc(3) not to progress file descriptor and neither to
report EILSEQ. Detect such situation and skip the bad input.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The path canonicalization is expensive and in many cases unwanted due
to problems with readlink() on unreachable NFS and automounters.
This patch add a possibility to search also by $(CWD)/<path> if the
<path> is relative to reduce number of situation when we convert the
path to the canonical absolute path.
The common use-case:
# cd /some/long/path
# umount ./mountpoint
old version:
15543: libmount: TAB: [0x560a99a54230]: lookup TARGET: './test'
15543: libmount: CACHE: [0x560a99a54290]: canonicalize path ./test
15543: libmount: CACHE: [0x560a99a54290]: add entry [ 1] (path): /mnt/test: ./test
15543: libmount: TAB: [0x560a99a54230]: lookup canonical TARGET: '/mnt/test'
15543: libmount: CXT: [0x560a99a54050]: umount fs: /mnt/test
new version:
15597: libmount: TAB: [0xabf230]: lookup TARGET: './test'
15597: libmount: TAB: [0xabf230]: lookup absolute TARGET: '/mnt/test'
15597: libmount: CXT: [0xabf050]: umount fs: /mnt/test
Signed-off-by: Karel Zak <kzak@redhat.com>
script(1) waits for empty slave FD (shell stdin) before it writes to
master. This feature has been intorduiced by 54c6611d6f
to avoid misbehavior when we need to send EOF to the shell.
Unfortunately, this feature has been used all time for all messages.
This is wrong because command in the session (or shell) may ignore
stdin at all and wait forever in busy loop is really bad idea. Test
case:
script /dev/null
tailf /etc/passwd
<enter>
<enter>
... script process taking 100% CPU.
This patch forces script to use empty-stave detection only when we
need to write EOF. The busy loop has been modified to use nanosleep
and it does not wait forever...
Addresses: http://bugs.debian.org/820843
Signed-off-by: Karel Zak <kzak@redhat.com>
Now we are able to disable all programs which have systemd/journald
support. This feature is needed by openSUSE packagers who are building
util-linux in 2 stages to avoid build cycles.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>