Stanislav Brabec [Thu, 21 Jan 2016 21:58:31 +0000 (22:58 +0100)]
libmount: handle btrfs default subvolume mount
When mounting btrfs volume without subvol= and subvolid=, and the
btrfs volume has default subvolume defined, mount() mounts the default
subvolume and not the volume root as other filesystems do.
To handle this situation correctly (for example for "mount -a"),
libmount has to be capable to detect default subvolume.
Add btrfs.c and btrfs.h that implement needed functions.
This patch adds mnt_table_find_target_with_option() to the library API.
Known problems not covered by this patch:
- Use of subvolid= in fstab is not yet handled.
- Use of type auto in combination with subvol= in fstab is not yet
handled.
- Use of btrfs in loop devices, where image file is specified in fstab is
not yet handled (use of /dev/loop0 in fstab works).
- If fstab uses subvol=, and subvol path changes since last "mount -a",
subsequent "mount -a" will not recognize that it is already mounted,
and it will attempt to mount it second time. To fix it, libmount should
remember subvolid in time of mount (subvolid is unique for the
subvolume, subvol is not).
- mountinfo contains subvol and subvolid since kernel 4.2. Before kernel
4.2, there is no reasonable way to solve this situation. (One would
create temporary mount point, mount the default, call needed ioctl() to
determine what was mounted, deduce the default subvolume, compare it
with subvolume of mounted volume, unmount and return result.)
How to reproduce:
truncate -s1G btrfs_test.img
mkdir -p btrfs_mnt
/sbin/mkfs.btrfs -f -d single -m single ./btrfs_test.img
mount -o loop btrfs_test.img btrfs_mnt
pushd .
cd btrfs_mnt
mkdir -p d0/dd0/ddd0
cd d0/dd0/ddd0
touch file{1..5}
btrfs subvol create s1
cd s1
touch file{1..5}
mkdir -p d1/dd1/ddd1
cd d1/dd1/ddd1
btrfs subvol create s2
rid=$(btrfs inspect rootid s2)
echo new default $rid
btrfs subvol get-default .
btrfs subvol set-default $rid .
popd
umount btrfs_mnt
losetup /dev/loop0 $PWD/btrfs_test.img
echo "/dev/loop0 $PWD/btrfs_mnt btrfs defaults 0 0" >>/etc/fstab
mount -a
mount -a
umount btrfs_mnt
sed -i "/\/dev\/loop0/d" /etc/fstab
losetup -d /dev/loop0
rm btrfs_test.img
rmdir btrfs_mnt
Current behavior:
mount: /dev/loop0 is already mounted or /root/btrfs_mnt busy
/dev/loop0 is already mounted on /root/btrfs_mnt
Expected behavior is to ignore already mounted FS.
[kzak@redhat.com: - make 'var' optional for mnt_table_find_target_with_option(),
- add mnt_table_find_target_with_option() to symbols table and docs
- add "btrfs" string between supported debug modes
- minor coding style changes]
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz> Cc: David Štěrba <dsterba@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>
Igor Gnatenko [Sun, 24 Jan 2016 22:57:51 +0000 (23:57 +0100)]
add .editorconfig
EditorConfig is very well known config file for text editors/IDE's
with settings for project. This format supported by Vim, GNOME Builder,
Atom, Sublime and many others.
We will provide this configuration to be more friendly for newcomers.
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
Karel Zak [Fri, 22 Jan 2016 15:51:59 +0000 (16:51 +0100)]
libsmartcols: support multibyte titles, rename wrap to padding
- let's support multibyte table titles
- use lib/mbalign.c to align the title
- rename title_wrap to title_padding (we already use "wrap" on another
places for another things)
Karel Zak [Fri, 22 Jan 2016 12:34:05 +0000 (13:34 +0100)]
Merge branch 'table_title' of https://github.com/ignatenkobrain/util-linux
* 'table_title' of https://github.com/ignatenkobrain/util-linux:
libsmartcols: set everything once in scols_table_set_title()
libsmartcols: put new line after title
libsmartcols: fix title aligning to center
libsmartcols: don't try to align title if it's more that term
libsmartcols: use symbols for title wrap
libsmartcols: implement title of table
Boris Egorov [Tue, 19 Jan 2016 06:18:21 +0000 (12:18 +0600)]
tests: remove redundant check for NULL [cppcheck]
We set SA_SIGINFO flag, so we should not get NULL.
[tests/helpers/test_sigreceive.c:45] -> [tests/helpers/test_sigreceive.c:47]: (warning) Either the condition 'if(info)' is redundant or there is possible null pointer dereference: info.
Boris Egorov [Tue, 19 Jan 2016 05:45:15 +0000 (11:45 +0600)]
readprofile: add scanf field width limits [cppcheck]
[sys-utils/readprofile.c:301]: (warning) scanf without field width limits can crash with huge input data.
[sys-utils/readprofile.c:322]: (warning) scanf without field width limits can crash with huge input data.
Boris Egorov [Tue, 19 Jan 2016 05:42:26 +0000 (11:42 +0600)]
libblkid,libmount: Do not use void* in calculations [cppcheck]
[libblkid/src/superblocks/zfs.c:179]: (portability) 'label' is of type 'const void *'. When using void pointers in calculations, the behaviour is undefined.
[libblkid/src/superblocks/zfs.c:237]: (portability) 'label' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[libblkid/src/topology/topology.c:221]: (portability) 'chn.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[libmount/src/fs.c:153]: (portability) 'old' is of type 'const void *'. When using void pointers in calculations, the behaviour is undefined.
[libmount/src/fs.c:154]: (portability) 'new' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
Boris Egorov [Tue, 19 Jan 2016 05:37:57 +0000 (11:37 +0600)]
libblkid: (zfs) add cast to fix UB [cppcheck]
[libblkid/src/superblocks/zfs.c:173]: (error) Shifting 32-bit value by 56 bits is undefined behaviour
[libblkid/src/superblocks/zfs.c:173]: (error) Shifting 32-bit value by 40 bits is undefined behaviour
Karel Zak [Mon, 18 Jan 2016 13:35:33 +0000 (14:35 +0100)]
libblkid: make minix prober more robust
It seems that the current minix probing code is not robust enough and
it returns false positive for Fedora f24 install images. The crazy thing
is that the image pass also all Linux kernel minix_fill_super() checks
and mount(2) fails later when it tries to read filesystem root
directory.
The fsck.minix requires sb->s_log_zone_size to be zero (Linux kernel
does not care about it), let's use the same requirement for libblkid.
Note, it would be possible to check minix root directory inode in
libblkid, but this solution requires minix prober specific seek &
read. We want to avoid extra read operations...
References: https://bugzilla.redhat.com/show_bug.cgi?id=1299255 Signed-off-by: Karel Zak <kzak@redhat.com>
Andrew Wilcox [Tue, 12 Jan 2016 09:35:11 +0000 (10:35 +0100)]
libfdisk: Add GPT type GUID for Itanium Linux root
References: http://www.freedesktop.org/wiki/Specifications/DiscoverablePartitionsSpec/ Signed-off-by: Andrew Wilcox <awilfox@adelielinux.org> Signed-off-by: Karel Zak <kzak@redhat.com>
Boris Egorov [Tue, 5 Jan 2016 16:17:58 +0000 (22:17 +0600)]
lib/tty: Pass default width to get_terminal_width()
Almost any code calling get_terminal_width() checks returned width for
non-positive values and sets it to some default value (say, 80). So,
let's pass this default value directly to the function.
Ruediger Meier [Tue, 15 Dec 2015 13:03:23 +0000 (14:03 +0100)]
tests: use sfdisk --no-reread wherever it's needed
The first BLKRRPART ioctl causes udev events and then second one may
fail, see Discussion
http://comments.gmane.org/gmane.linux.utilities.util-linux-ng/11885
Karel Zak [Tue, 15 Dec 2015 11:25:56 +0000 (12:25 +0100)]
login, mount: fix __SC_GETPW_R_SIZE_MAX usage
sysconf(_SC_GETPW_R_SIZE_MAX) returns initial suggested size for pwd
buffer (see getpwnam_r man page or POSIX). This is not large enough in
some cases.
Yes, this sysconf option is misnamed (should be _SC_GETPW_R_SIZE_MIN).
Ruediger Meier [Thu, 10 Dec 2015 15:56:11 +0000 (16:56 +0100)]
tests: skip nonroot before checking for progs in PATH
The least annoying and most useful order is this one:
1. check for compiled UL commands
2. check for root
3. check for loop support
4. check for external progs
Karel Zak [Thu, 10 Dec 2015 10:18:04 +0000 (11:18 +0100)]
Merge branch 'test-fixes' of https://github.com/rudimeier/util-linux
* 'test-fixes' of https://github.com/rudimeier/util-linux:
tests: use xz instead of bzip2 for blkid images
tests: add some line tests
tests: avoid sed -E
Ruediger Meier [Wed, 9 Dec 2015 12:01:51 +0000 (13:01 +0100)]
blkdiscard: don't report "zero range" at the end
We want to address the case that we have printed the last useful
stats line already within the loop. Avoiding an additional line
"Discarded 0 bytes ..." at the end.
Note there is a behavior change now for the edge cases "-v -l 0" and
"-v -o blksize" where we don't print any stats line anymore. But actually
it's correct, we never make any BLKDISCARD syscall with zero range.
Perhaps we should return error in these cases to help people who always
want to parse stats output on success.