Karel Zak [Tue, 19 Jan 2021 15:25:33 +0000 (16:25 +0100)]
tests: improve u64 use in ipcs test
UINT64_MAX is 18446744073709551615, but 2^64 is 18446744073709551616.
We also need to use kbytes in all calculation in the test than bytes
as ipcs by default do not use bytes anymore.
Karel Zak [Mon, 18 Jan 2021 15:04:18 +0000 (16:04 +0100)]
ipcs: fallback for overflow
The previous commit 7a08784ab053d6aa30db990cbec1fd35b34ed00a reduced
number of situation when we need fallback when kbytes calculated for
shmall pages, but there is still possible to see overflows.
v1->v2:
Print the non-overflow KB value only for IPC_UNIT_KB and
IPC_UNIT_DEFAULT.
This way --bytes and --human options will still get an expected
output
(but not avoiding the overflow).
Signed-off-by: Vasilis Liaskovitis <vliaskovitis@suse.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Tue, 12 Jan 2021 10:43:31 +0000 (11:43 +0100)]
lib/loopdev: make is_loopdev() more robust
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>
Sami Kerola [Thu, 24 Dec 2020 20:22:59 +0000 (20:22 +0000)]
build-sys: silence non-POSIX variable name warning
Easiest way to get rid of the following warning is to ignore the warning.
This might cause people who use non-GNU make to have hard time, but are
there such people compiling this project?
sys-utils/Makemodule.am:226: warning: addprefix sys-utils/,$(SETARCH_LINKS: non-POSIX variable name
sys-utils/Makemodule.am:226: (probably a GNU make extension)
Karel Zak [Wed, 6 Jan 2021 14:17:19 +0000 (15:17 +0100)]
docs: update TODO (add item about mnt_context_get_excode() )
- add item about https://github.com/karelzak/util-linux/issues/1208
- remove old CAP_SYS_ADMIN note (in last versions mount(8) drops suid if
necessary).
Addresses: https://github.com/karelzak/util-linux/issues/1208 Signed-off-by: Karel Zak <kzak@redhat.com>
getopt: explicitly ask for POSIX mode on POSIXLY_CORRECT
GNU libc's getopt_long(3) have the tradition of not shuffling arguments
to find options when either POSIXLY_CORRECT is defined in environment
variables or '+' prepended in short options. Hence, the current code
base is fine as is fine as is for util-linux built with GNU libc.
However, musl libc only honour POSIX convention when short options
prepended with '+'. musl libc doesn't care about POSIXLY_CORRECT.
Thus, the behaviour of util-linux's getopt(1) that linked with musl-libc
doesn't match with its own documentation.
Let's make sure a '+' is always prepended to short options if
POSIXLY_CORRECT is defined.
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
Karel Zak [Tue, 5 Jan 2021 14:20:50 +0000 (15:20 +0100)]
Merge branch '2020wk47' of https://github.com/kerolasa/util-linux
* '2020wk47' of https://github.com/kerolasa/util-linux:
build-sys: sort various lists in configure.ac
mkswap: tell how to fix insecure permissions and owner in warning
lsipc: make default output byte sizes to be in human units
man: add missing backslash to caret printing macro
lscpu: fix variable shadowing
uuidgen: give hint in usage() what uuid namepaces can be used
uuidgen: use errx() rather than fprintf() when priting errors
libuuid: simplify uuid_is_null() check
uuidparse: use uuid type definitions from libuuid header
uuidparse: use libuuid function to test nil uuid
Sami Kerola [Sat, 28 Nov 2020 16:29:09 +0000 (16:29 +0000)]
lsipc: make default output byte sizes to be in human units
Recent request to make ipcs(1) list sizes in human format caused the
observation lsipc(1) is not doing that either. This commit changes sizes to
human format, assuming --bytes option is not used.
Reference: https://github.com/karelzak/util-linux/issues/1199 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Sami Kerola [Thu, 26 Nov 2020 16:54:50 +0000 (16:54 +0000)]
lscpu: fix variable shadowing
sys-utils/lscpu-virt.c: In function ‘lscpu_read_virtualization’:
sys-utils/lscpu-virt.c:574:9: warning: declaration of ‘buf’ shadows a previous local [-Wshadow]
574 | char buf[256];
| ^~~
sys-utils/lscpu-virt.c:506:7: note: shadowed declaration is here
506 | char buf[BUFSIZ];
| ^~~
A 33553920 byte optimal I/O size arises from badly-implemented USB SATA
adapters reporting 0xffff 512 byte sectors (32 MiB - 512). Commit acb7651f8897ae73d0f45dd75bc87630001c61b9 indirectly addresses this by
ignoring the optimal I/O size if it's not a multiple of the physical
sector size. That works if the physical sector size is 4096, but 33553920 optimal is allowed for 512 physical.
This commit explicitly ignores 33553920, as there is no legitimate
situation where this number would be the real optimal I/O size.
Signed-off-by: Ryan Finnie <ryan@finnie.org> Closes: https://github.com/karelzak/util-linux/issues/1221
term-utils/scriptlive.c: In function 'process_next_step':
term-utils/scriptlive.c:125:4: warning: 'now.tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized]
term-utils/scriptlive.c:122:19: note: 'now.tv_usec' was declared here
term-utils/scriptlive.c:125:4: warning: 'now.tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized]
term-utils/scriptlive.c:122:19: note: 'now.tv_sec' was declared here
term-utils/script.c: In function 'log_close.part.0.isra':
term-utils/script.c:306:3: warning: 'now.tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized]
term-utils/script.c:303:18: note: 'now.tv_usec' was declared here
term-utils/script.c:306:3: warning: 'now.tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized]
term-utils/script.c:303:18: note: 'now.tv_sec' was declared here
sys-utils/hwclock-rtc.c: In function 'synchronize_to_clock_tick_rtc':
sys-utils/hwclock.c:169:28: warning: 'now.tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/hwclock-rtc.c:215:24: note: 'now.tv_usec' was declared here
sys-utils/hwclock.c:168:28: warning: 'now.tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/hwclock-rtc.c:215:24: note: 'now.tv_sec' was declared here
sys-utils/hwclock.c:169:28: warning: 'begin.tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/hwclock-rtc.c:215:17: note: 'begin.tv_usec' was declared here
sys-utils/hwclock.c:168:28: warning: 'begin.tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/hwclock-rtc.c:215:17: note: 'begin.tv_sec' was declared here
sys-utils/blkdiscard.c: In function 'main':
sys-utils/blkdiscard.c:304:33: warning: 'now.tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/blkdiscard.c:152:17: note: 'now.tv_usec' was declared here
sys-utils/blkdiscard.c:305:37: warning: 'now.tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/blkdiscard.c:152:17: note: 'now.tv_sec' was declared here
sys-utils/blkdiscard.c:304:33: warning: 'last.tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/blkdiscard.c:152:22: note: 'last.tv_usec' was declared here
sys-utils/blkdiscard.c:305:65: warning: 'last.tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized]
sys-utils/blkdiscard.c:152:22: note: 'last.tv_sec' was declared here
Karel Zak [Thu, 10 Dec 2020 11:10:06 +0000 (12:10 +0100)]
blkid: encode all udf and iso IDs in udev output
We encode to "safe" strings almost all variables for 'blkid -o udev'
and we need it also for SYSTEM_ID, PUBLISHER_ID, APPLICATION_ID,
BOOT_SYSTEM_ID and recently added VOLUME_SET_ID and DATA_PREPARER_ID.
This change makes blkid from util-linux more compatible with built-in
udevd blkid.
Pali Rohár [Thu, 10 Dec 2020 01:38:06 +0000 (02:38 +0100)]
libblkid: iso9660: add new test images
Image iso-different-iso-joliet-label contains different identifiers in ISO
and Joliet locations. Identifiers are prefixed with "ISO" or "Joliet"
string to verify that UNICODE Joliet has preference over ASCII ISO.
Image iso-unicode-long-label contains very long identifiers in ISO location
which do not fit into the Joliet location. In ISO location is UNICODE
character 'ï' replaced by '_' and unrepresentable spaces also by '_'.
This test verifies that libblkid can use first half of identifiers from
Joliet (which contains UNICODE) and second half from ISO which is just
uppercase and only small subset of ASCII. This image was generated by Nero
Linux software and basically this truncate and '_' replacement is done by
default for any long or UNICODE label.
Pali Rohár [Thu, 10 Dec 2020 00:52:18 +0000 (01:52 +0100)]
libblkid: iso9660: add support for VOLUME_SET_ID and DATA_PREPARER_ID
udf superblock code already sets VOLUME_SET_ID to Volume Set Identifier
from UDF Primary Volume Descriptor.
In iso9660 similar meaning has Volume Set Identifier in ISO9660
Primary (or Supplementary Joliet) Volume Descriptor. Therefore exports it
as VOLUME_SET_ID label.
In ISO9660 Primary (and Supplementary Joliet) Volume Descriptor exists
another member Data Preparer Identifier which is currently not parsed by
iso9660 superblock code.
To have iso9660 superblock code feature complete export also Data Preparer
Identifier as DATA_PREPARER_ID label. UDF does not have equivalent of Data
Preparer Identifier.
Pali Rohár [Wed, 9 Dec 2020 23:21:55 +0000 (00:21 +0100)]
libblkid: iso9660: improve label parsing
Label in Joliet is UNICODE (UTF16BE) but can contain only 16 characters.
Label in PVD is subset of ASCII but can contain up to the 32 characters.
Non-representable characters are stored as replacement character '_'.
Label in Joliet is in most cases trimmed but UNICODE version of label in
PVD. Based on these facts try to reconstruct original label if label in
Joliet is prefix of the label in PVD (ignoring non-representable
characters).
It is possible that label in Joliet and PVD are totally different. In this
case label from Joliet as prior this change.
Pali Rohár [Tue, 8 Dec 2020 23:36:13 +0000 (00:36 +0100)]
libblkid: iso9660: check that iso->publisher_id and iso->application_id are not file paths
ECMA 119 (ISO 9660) says that if the first byte is set to (5F), the
remaining bytes of this field shall specify an identifier for a file
containing the data. As libblkid does not support reading files from the
filesystem itself it cannot parse fields which starts with 0x5F '_' char.
So for now ignore iso->publisher_id and iso->application_id values which
starts with '_' character.
Pali Rohár [Tue, 8 Dec 2020 23:34:23 +0000 (00:34 +0100)]
libblkid: iso9660: do not check is_str_empty() for iso->system_id and boot->boot_system_id
ECMA 119 (ISO 9660) does not say anything if all bytes are of these fields
are FILLER then fields are not set. It says it for iso->publisher_id and
iso->application_id.
Gao Xiang [Sat, 5 Dec 2020 07:44:10 +0000 (15:44 +0800)]
libblkid: add erofs filesystem support
Enhanced Read-Only File System (EROFS) has been included in Linux
kernel, many Linux distributions, buildroot and Android AOSP for
a while. Plus, nowadays, it's known that EROFS has been commercially
used by several Android vendors for their system partitions.
util-linux in busybox can also detect it recently.
This patch adds support for detecting EROFS filesystem to libblkid.
Karel Zak [Mon, 7 Dec 2020 12:44:25 +0000 (13:44 +0100)]
Merge branch 'master' of https://github.com/pali/util-linux into master
* 'master' of https://github.com/pali/util-linux:
libblkid: udf: update test output for APPLICATION_ID and PUBLISHER_ID
libblkid: udf: add support for PUBLISHER_ID
libblkid: udf: add support for APPLICATION_ID
libblkid: udf: check that dstrings are encoded in OSTA Compressed Unicode
Manuel Bentele [Sat, 5 Dec 2020 22:51:27 +0000 (23:51 +0100)]
losetup: fix wrong printf() format specifier for ino_t data type
Since the range of the ino_t data type is platform-specific (depending on
the wordsize), a usage of the fixed format specifier %PRIu64 is not correct
for ino_t on some 32-bit architectures, eg. ARM (Raspberry Pi 1). This issue
may lead to undefinied output and is not reported by gcc (in version 10.2.0
and 8.3.0-6+rpi1) even though -Wformat is enabled by -Wall. Therefore it is
most likely that it seems to be a false negative error in gcc's format
specifier check, so that this issue was never detected before.
This change fixes the issue by the use of a cast, since there is no
platform-independent format specifier for ino_t available. The wrong format
specifier %PRIu64 is replaced by %ju, where its corresponding variable of
type ino_t is casted to uintmax_t. The type uintmax_t represents the largest
platform-specific unsigned integer, so that all integer values are preserved
for a platform-independent printing.
Fixes: https://github.com/karelzak/util-linux/issues/1211 Signed-off-by: Manuel Bentele <development@manuel-bentele.de>
Pali Rohár [Sat, 5 Dec 2020 19:45:25 +0000 (20:45 +0100)]
libblkid: udf: add support for PUBLISHER_ID
iso9660 superblock code already sets PUBLISHER_ID to Publisher Identifier
from ISO9660 Supplementary Volume Descriptor.
In udf field LVInfo1 from Implementation Use Volume Descriptor could
contain information such as Owner Name. More UDF generating tools
(e.g. Solaris's labelit or Linux udftools 2.3+) set this field to person
who creating the filesystem therefore its meaning is similar to ISO9660
Publisher Identifier. So for compatibility with iso9660 superblock code
export this field via PUBLISHER_ID label.
Pali Rohár [Sat, 5 Dec 2020 19:43:22 +0000 (20:43 +0100)]
libblkid: udf: add support for APPLICATION_ID
iso9660 superblock code already sets APPLICATION_ID to Application
Identifier from ISO9660 Supplementary Volume Descriptor.
In udf similar meaning has Application Identifier from UDF Primary Volume
Descriptor. Therefore exports it as APPLICATION_ID label.
More tools for generating hybrid ISO+UDF images (e.g. genisoimage, mkisofs
or nero) set Application Identifier in UDF Primary Volume Descriptor to
just empty string. But they set Implementation Identifier in UDF Primary
Volume Descriptor to their tool name.
So if Application Identifier is empty then exports Implementation
Identifier as APPLICATION_ID label.
Please note that Application Identifier and Implementation Identifier are
stored in UDF only in ASCII, not UNICODE.
Pali Rohár [Sat, 5 Dec 2020 19:39:35 +0000 (20:39 +0100)]
libblkid: udf: check that dstrings are encoded in OSTA Compressed Unicode
dstring structures are in UL_ENCODE_LATIN1/UL_ENCODE_UTF16BE encodings only
when corresponding desc_charset structures are set to the OSTA Compressed
Unicode. So add missing checks.
Sami Kerola [Wed, 2 Dec 2020 22:56:16 +0000 (22:56 +0000)]
lib/fileutils: make close_all_fds() to be similar with close_range()
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>
Sami Kerola [Sat, 14 Nov 2020 12:55:10 +0000 (12:55 +0000)]
login: use close_range() system call when possible
This system call was added while back, but does not have glibc support yet.
Lets try to use the new facility early on. The promise in reference link is
that the new call is faster, and works when /proc is not mounted.
Reference: https://lwn.net/Articles/789000/
Reference: https://lwn.net/Articles/789023/
Reference: https://kernelnewbies.org/LinuxChanges#Linux_5.9.New_close_range.28.29_system_call_for_easier_closing_of_file_descriptors Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Sami Kerola [Fri, 13 Nov 2020 23:04:43 +0000 (23:04 +0000)]
login: use xalloc memory allocation helpers everywhere
Apart two function calls login(1) already used xalloc functions. If there
was a time when login tried to gracefully handle allocation errors that has
not been true for long time.