The old implementation uses /proc/partitions where devices are
filtered by kernel (missing devices with ext_range=1 and removable
devices).
The problem with the old implementation is whole-disk heuristic based
on device name, order of devices, etc.
The new implementation use the same code to read also removable
devices.
Addresses: https://github.com/karelzak/util-linux/issues/1151
Signed-off-by: Karel Zak <kzak@redhat.com>
The library is not distributed and almost all code in this ar(1)
archive is Public Domain or LGPL ... but let's avoid any doubts and do
not mix non-GPL and GPL code there.
Addresses: https://github.com/karelzak/util-linux/issues/1157
Signed-off-by: Karel Zak <kzak@redhat.com>
It's was originally GPL, but all the current code in the file is from
me and I don't think it makes sense to use GPL here anymore. We need
to use lib/ files in LGPL as well as in GPL binaries, etc. Let's makes
things (build-system) less complicated.
Signed-off-by: Karel Zak <kzak@redhat.com>
The strings from utmp does not have to be terminated. It's seems
better to explicitly terminate it than rely on "%.*s" printf()
functionality -- printf() man page assumes that "If a precision is
given, no null byte need be present", but static analyzers are pretty
unhappy with it.
Signed-off-by: Karel Zak <kzak@redhat.com>
The flag works (= kernel accepts it) for all scheduling policies
and sched_getattr() returns the flag for all policies.
There is no reason for userspace to be more smart than kernel or hide
the flag when it prints sched_getattr()/sched_getscheduler() results.
# chrt -v --reset-on-fork --batch 0 /bin/true
pid 1315019's new scheduling policy: SCHED_BATCH|SCHED_RESET_ON_FORK
# chrt -v --reset-on-fork --fifo 1 /bin/true
pid 1315055's new scheduling policy: SCHED_FIFO|SCHED_RESET_ON_FORK
# chrt -v --reset-on-fork --deadline --sched-period 10000 0 /bin/true
pid 1315182's new scheduling policy: SCHED_DEADLINE|SCHED_RESET_ON_FORK
# chrt -v --reset-on-fork --idle 0 /bin/true
pid 1315247's new scheduling policy: SCHED_IDLE|SCHED_RESET_ON_FORK
# chrt -v --reset-on-fork --rr 1 /bin/true
pid 1315275's new scheduling policy: SCHED_RR|SCHED_RESET_ON_FORK
# chrt -v --reset-on-fork --other 0 /bin/true
pid 1315311's new scheduling policy: SCHED_OTHER|SCHED_RESET_ON_FORK
Signed-off-by: Karel Zak <kzak@redhat.com>
Reviewed by many people, used for years (but probably nobody uses
SCHED_DEADLINE with reset-on-fork), but we all missed:
- sched_setscheduler() uses SCHED_RESET_ON_FORK (0x40000000)
- sched_setattr() uses SCHED_FLAG_RESET_ON_FORK (0x01)
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1883013
Signed-off-by: Karel Zak <kzak@redhat.com>
The macro FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION does not have to
enabled in all cases (e.g. default travis-ci, local tests, ...). It
seems more robust also check for __SANITIZE_ADDRESS__ too.
Addresses: https://github.com/karelzak/util-linux/pull/1115
Signed-off-by: Karel Zak <kzak@redhat.com>
GPT prober reads 2 first sectors. There is no overhead as we already
read begin of the device for another filesystems (like FAT) and we
have these sectors already in memory.
Addresses: https://github.com/karelzak/util-linux/issues/1147
Signed-off-by: Karel Zak <kzak@redhat.com>
The default is 128 partitions (entries in partitions array). The size
of the entry is 128 bytes, it means 32 sectors (512-byte) for the
array. The default is too large for tiny devices and it seems better to
dynamically reduce the number to fix the device size.
The reduction is reported to user.
Example:
$ dd if=/dev/zero of=8-sectors.img count=8 bs=512
$ fdisk 8-sectors.img
...
Command (m for help): g
Created a new GPT disklabel (GUID: 3DB3EECE-BCCA-6C46-95FA-7E23783BB3B2).
The maximal number of partitions is 8 (default is 128).
Command (m for help): x
Expert command (m for help): p
Disk 8-sectors.img: 4 KiB, 4096 bytes, 8 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 3DB3EECE-BCCA-6C46-95FA-7E23783BB3B2
First LBA: 4
Last LBA: 4
Alternative LBA: 7
Partition entries LBA: 2
Allocated partition entries: 8
In this case, sectors:
0 - PMBR
1 - GPT header
2-3 - GPT array of partitions (8 entries, 128 bytes each)
4 - partition data
5-6 - backup GPT array of partitions
7 - backup GPT header
The smallest image is 6 sectors with 4 entries in array of partitions.
Note that Linux kernel has no problem to accept 4K image with 1
512-bytes GPT partition.
# losetup -P -f 4K.img
# lsblk /dev/loop0
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 4K 0 loop
└─loop0p1 259:5 0 512B 0 part
... but we need to fix libblkid, it ignores so small devices to probe for GPT :)
Addresses: https://github.com/karelzak/util-linux/issues/1147
Signed-off-by: Karel Zak <kzak@redhat.com>
The current code creates GPT header and partitions arrays (with 128
entries ...) although there is no space for all the stuff. This patch
forces fdisk_create_disklabel() to return -ENOSPC if the last and first
usable LBA calculation is out of device size.
Addresses: https://github.com/karelzak/util-linux/issues/1147
Signed-off-by: Karel Zak <kzak@redhat.com>
- remove extra line about stdout in usage() output
- use our macros to print int about --help and --version
- remove uint8_t bit-field from struct col_ctl (it seems fragile for
future code changes).
Signed-off-by: Karel Zak <kzak@redhat.com>
* 'col-refactor' of https://github.com/kerolasa/util-linux:
col: replace LINE and CHAR typedefs with structs
col: free memory before exit [LeakSanitizer]
col: tidy up sources a little bit
col: add defaults to switch case clauses
col: flip all comparisions to numerical order
col: use size_t when dealing with numbers that buffer sizes
col: add structure to hold line variables
col: add update_cur_line() function
col: add handle_not_graphic() function
col: initialize variables when they are declared
col: move option handling to separate function
col: move global variables to a control structure
col: use inline function rather than function like define
col: use typedef and enum to clarify struct
col: remove function prototypes
col: add more tests
ARM SBBR (Sever Base Boot Requirements) require SMBIOS tables, and
SMBIOS Type 4 describes the CPU manufacturer and model name (among other
details). If SMBIOS Type 4 is present, use it to extract these strings.
Example output (before and after the patch) on an HP m400, Lenovo HR330A,
and HPE Apollo 70:
[root@hp-m400 ~]# /usr/bin/lscpu | grep -i -e vendor -e model -e stepping
Vendor ID: APM
Model: 1
Model name: X-Gene
Stepping: 0x0
[root@hp-m400 ~]# ./lscpu | grep -i -e vendor -e model -e stepping
Vendor ID: AppliedMicro
Model: 1
Model name: X-Gene
Stepping: 0x0
[root@lenovo-hr330a ~]# /usr/bin/lscpu | grep -i -e vendor -e model -e stepping
Vendor ID: APM
Model: 2
Model name: X-Gene
Stepping: 0x3
[root@lenovo-hr330a ~]# ./lscpu | grep -i -e vendor -e model -e stepping
Vendor ID: Ampere(TM)
Model: 2
Model name: eMAG
Stepping: 0x3
[root@hpe-apollo-70 ~]# /usr/bin/lscpu | grep -i -e vendor -e model -e stepping
Vendor ID: Cavium
Model: 1
Model name: ThunderX2 99xx
Stepping: 0x1
[root@hpe-apollo-70 ~]# ./lscpu | grep -i -e vendor -e model -e stepping
Vendor ID: Cavium Inc.
Model: 1
Model name: Cavium ThunderX2(R) CPU CN9980 v2.1 @ 2.20GHz
Stepping: 0x1
[kzak@redhat.com: - move dmi_header to lscpu.h
- make arm_cpu_smbios() more robust for failed
open() and read()
- use original arm_cpu_decode() also on failed
arm_cpu_smbios()]
Signed-off-by: Jeffrey Bastian <jbastian@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
We append to the options string in loop there. It seems better to use
ul_buffer for this case to avoid duplicate strlen() and reallocs.
Signed-off-by: Karel Zak <kzak@redhat.com>
This function is used by fstab (etc.) parser to split VFS, FS and
userspace options to separate lists. Unfortunately, the current
implementation reallocates the final string always when append a new
option to the string.
The new implementation pre-allocate memory for the final string
according to source string length (1/2 of the original string). This
dramatically reduces realloc() calls.
For example oss-fuzz (./test_mount_fuzz) uses 800K input string, old
version needs 28s to parse the string, new version 500ms.
Addresses: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23861
Signed-off-by: Karel Zak <kzak@redhat.com>
The goal is to use it in libmount when generate options strings
and in libsmartcols to replace libscols_buffer.
Signed-off-by: Karel Zak <kzak@redhat.com>