Let's make it possible to use the function to normalize the string
between two buffers (from source to destination).
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit adds zone-aware magics and probing functions for zoned btrfs.
The superblock (and its copies) are the only data structure in btrfs with a
fixed location on a device. Since we cannot do overwrites in a sequential
write required zone, we cannot place the superblock in the zone.
Thus, zoned btrfs uses superblock log writing to update superblocks on
sequential write required zones. It uses two zones as a circular buffer to
write updated superblocks. Once the first zone is filled up, start writing
into the second buffer. When both zones are filled up, and before starting
to write to the first zone again, it reset the first zone.
We can determine the position of the latest superblock by reading the write
pointer information from a device. One corner case is when both zones are
full. For this situation, we read out the last superblock of each zone and
compare them to determine which zone is older.
The magics can detect a superblock magic ("_BHRfs_M") at the beginning of
zone #0 or zone #1 to see if it is zoned btrfs. When both zones are filled
up, zoned btrfs resets the first zone to write a new superblock. If btrfs
crashes at the moment, we do not see a superblock at zone #0. Thus, we need
to check not only zone #0 but also zone #1.
It also supports the temporary magic ("!BHRfS_M") in zone #0. Mkfs.btrfs
first writes the temporary superblock to the zone during the mkfs process.
It will survive there until the zones are filled up and reset. So, we also
need to detect this temporary magic.
Finally, this commit extends probe_btrfs() to load the latest superblock
determined by the write pointers.
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
tolower() does not work "as expected" for tr_TR.UTF-8 (Turkish).
Fortunately, we need to convert only objects and variables names in
JSON output, and this is always old good ASCII.
Anyway, for more details:
$ cat a.c
#include <ctype.h>
#include <stdio.h>
#include <locale.h>
int main(void)
{
int in, out;
setlocale(LC_ALL, "");
in ='I';
out = tolower(in);
printf("%1$c [%1$d] --> %2$c [%2$d]\n", in, out);
return 0;
}
$ make a
cc a.c -o a
$ LANG=en_US.utf8 ./a
I [73] --> i [105]
$ LANG=tr_TR.UTF-8 ./a
I [73] --> I [73]
Fixes: https://github.com/karelzak/util-linux/issues/1302
Signed-off-by: Karel Zak <kzak@redhat.com>
The code should be able to keep track about previous content and print
JSON objects separator automatically.
Signed-off-by: Karel Zak <kzak@redhat.com>
* rename MANPAGES_EXTRA= to ADOCFILES_COMMON=
* keep track about individual adoc files by dist_noinst_DATA=
This variable is not effected by automake conditions, so the files
are always distributed.
Signed-off-by: Karel Zak <kzak@redhat.com>
The current implementation of the function does not care if the device
is whole-disk device or partition, all is loopdev. This is regression
as the original is_loopdev() version was based on whole-disk devices
major numbers only.
Fixes: https://github.com/karelzak/util-linux/issues/1202
Signed-off-by: Karel Zak <kzak@redhat.com>
We need to evaluate "include::" directive relatively to project
top-level source directory rather than to the current document
location.
Signed-off-by: Karel Zak <kzak@redhat.com>
The symlinks are generated by asciidoctor and current dist_man_MANS
depends on order (nan page before man link). This solutions is useless
when execute "make -j". The real solution is to keep man pages in
separate variable and use only this variable evaluate what we need to
generate.
Signed-off-by: Karel Zak <kzak@redhat.com>
To build: meson build && ninja -C build
To run tests: ninja -C build check
To install for packaging: DESTDIR=/var/tmp/inst ninja -C build install
To install for realz: sudo ninja -C build install
v2:
- Optional items are now based on the 'feature' feature in meson.
Built libraries which are disabled turn into disabler() objects
and also poison any executables which link to them.
What is there:
- building of the binaries and libs and the python module
- installation of binaries, libs, python module, localization files,
man pages, pkgconfig files
- running of tests
- most options to configure build equivalently to the
./configure settings
Partially implemented:
- disabling of stuff when things missing. In the C code, the defines
are all used, so that should be fine. In the build system, some
files should be skipped, but that is probably not always done properly.
Getting this right might require some testing of various build option
combinations to get the details right.
Not implemented:
- static builds of fdisk and other binaries
- things marked with XXX or FIXME
- ???
Differences:
- .la files are not created. They are useless and everybody hates them.
- Requires.private in pkgconfig files are not present in the
autogenerated .pc file. Not sure if they should be there or not. If
necessary, they can be added by hand.
- man pages and systemd units are installed by the install target. Not
sure why 'make install' doesn't do that.
- the split between / and /usr is probably wrong. But it's all pointless
anyway, so maybe we could simplify things but not implementing it at
all under meson?
noinst_LTLIBRARIES causes the libraries to be always built
unconditionally. EXTRA_LTLIBRARIES causes them to be built
only if other build target needs them.
In other words, avoid building libcommon.a and libtcolors.a
unless they are needed by another library/executable and
save some build time.
https://www.gnu.org/software/automake/manual/html_node/Libtool-Convenience-Libraries.html
The current situation:
# su --pty - kzak
$ ll $(tty)
crw--w---- 1 root tty 136, 9 Feb 23 11:53 /dev/pts/9
$ mesg
mesg: cannot open /dev/pts/9: Permission denied
the pseudo-terminal is still owned by the original user.
New version:
# su --pty - kzak
# ll $(tty)
crw--w---- 1 kzak tty 136, 9 Feb 23 11:56 /dev/pts/9
# mesg
is y
The patch follows login(1) to change the pty owner and group. It
follows "TTYPERM" and "TTYGROUP" from login.defs (or econf lib).
Signed-off-by: Karel Zak <kzak@redhat.com>
It seems the current kernel can create a loop devices with a different
major number. For example
# losetup /dev/loop12345678 file.img
# lsblk /dev/loop12345678
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop12345678 15:811342 0 5M 0 loop
We need a way how to verify the device is loopdev also when the device is
not associated with any backing file -- in this case there is no "loop"
directory in /sys/dev/block/<maj:min>/, but we can cannonicalize this sysfs
symlink as it points to /sys/devices/virtual/block/loop<n> (see "loop" in
the path).
Note that without this change losetup is not able to list and delete
the loop device.
Addresses: https://github.com/karelzak/util-linux/issues/1202
Signed-off-by: Karel Zak <kzak@redhat.com>
This patch add support to format multi-line cells (columns with
SCOLS_FL_WRAP) to arrays in JSON output.
For example mountpoints[] in lsblk output:
Normal output:
$ lsblk -oNAME,FSTYPE,TYPE,MOUNTPOINTS /dev/sdc1
NAME FSTYPE TYPE MOUNTPOINTS
sdc1 btrfs part /mnt/A
/mnt/test
/mnt/B
JSON output:
$ lsblk -J -oNAME,FSTYPE,TYPE,MOUNTPOINTS /dev/sdc1
{
"blockdevices": [
{
"name": "sdc1",
"fstype": "btrfs",
"type": "part",
"mountpoints": [
"/mnt/A",
"/mnt/test",
"/mnt/B"
]
}
]
}
Signed-off-by: Karel Zak <kzak@redhat.com>
The util-linux close_all_fds() serves the same purpose as close_range()
that will over time obsolete local implementation completely. For
upcoming few years it is best to have a fallback that uses same input
arguments as the new system call. That allows surrounding code and
variables not to be affected by version of mass file descriptor closing
function.
Proposed-by: Karel Zak <kzak@redhat.com>
Reference: https://github.com/karelzak/util-linux/pull/1205#discussion_r534080128
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* w45:
fdformat: remove command from default build
more: improve error messaging when input file is directory
ul: make set_column() zero check more obvious
colrm: fix argument parsing
rfkill: stop execution when rfkill device cannot be opened
cifuzz: reindent yaml file
man: make tilde and caret characters to render correctly
Let's split the code to make it possible to test separately bsearch as
well as procfs based cap_last_cap().
$ ./test_caputils --last-by-bsearch
last cap: 39
$ ./test_caputils --last-by-procfs
last cap: 39
$ ./test_caputils --last
last cap: 39
Signed-off-by: Karel Zak <kzak@redhat.com>
* add delay between attempts
* zeroize errno and check for EAGAIN (like in other code)
* add small test program
./test_procutils --is-procfs [<dir>]
Signed-off-by: Karel Zak <kzak@redhat.com>
The file is simple list of signal names and trivial function to search
in the list. We do not need any extra license here and as public
domain it will be more portable to other tools (GPL and BSD) in the
util-linux.
All previous contributors (Sami, Niklas and me) agree with this change.
Signed-off-by: Karel Zak <kzak@redhat.com>
This allows the rest of the programs using cap_last_cap to trust the
value returned by it, since it will either be obtained from procfs
(straight from kernel) or with prctl.
Also checked if the file under /proc is actually mounted in a procfs.
As mentioned in 'Generating optimal glyphs' title in the manual page
mentioned in reference:
Where a proper caret (^) that renders well in both a terminal and PDF is
required, use "\(ha".
Using a naked "~" character results in a poor rendering in PDF. Instead
use "\(ti".
Reference: https://man7.org/linux/man-pages/man7/man-pages.7.html#STYLE_GUIDE
Signed-off-by: Sami Kerola <kerolasa@iki.fi>