Extends struct blkid_idmag with a new member hoff which specify name of the
hint used for blkid_probe_get_hint() function to retrieve offset to kboff.
blkid_probe_get_idmag() will use supplied hint offset in bytes as a start
position from which the final offsets for magic strings are calculated.
Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
When offset and session_offset hint are not specified then sets
session_offset hint from CDROMMULTISESSION ioctl which returns start
position of the last session of multisession optical disc.
It is expected that session_offset hint contains position offset in bytes
where starts session of multisession optical disc which should be read.
Filesystems designed for optical discs are expected to use this value when
dealing with multisession optical disc to know where they should start
reading optical disc or image of optical disc.
Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
Packet writing mode for CD and DVD discs is provided by kernel module
pktcdvd.ko which exports block devices /dev/pktcdvd/pktcdvd*.
These block devices do not accept CDROM_DRIVE_STATUS ioctl, therefore
current blkid code does not detect them as BLKID_FL_CDROM_DEV and also
does not do necessary size correction.
Extend detection of CD/DVD discs by additional CDROM_LAST_WRITTEN ioctl
which is accepted also by pktcdvd.ko.
Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
The linux kernel does not support more than 256 partitions
(DISK_MAX_PARTS). The atari and mac block devices have no such limits.
Use dos logical partition limit for atari as well (100).
Use the kernel limit for mac (256).
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
The time_t data type is a signed integer. A signed integer overflow is
not defined in C programming language.
A signed overflow occurs on 32 bit systems with 32 time_t for loop back
devices, e.g. when calling "blkid /dev/loop0". This happens because
bid_time is set to INT_MIN and the diff calculation cannot store the
result in time_t (positive int - INT_MIN > INT_MAX).
This fix changes the code to use an unsigned integer calculation. It
pretty much means that the code works as before, but well defined in C.
Checking diff to be positive protects the code against system setups
with dates before 1970 as well.
The time_t data type on modern Linux systems is 64 bit even for 32 bit
systems. Since long is 32 bit on these systems, long long is a better
data type for 64 bit output.
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
* make hints persistent and do not call blkid_probe_reset_hints() in
blkid_probe_set_device()
* export blkid_probe_reset_hints() by API to keep it completely in
user's hands
Reported-by: Pali Rohár <pali.rohar@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
If the map count is set to INT_MAX then the for loop does not stop
because its check is never false.
I have not found a correct upper limit. The other partition logics have
a maximum amount (exception is atari.c).
The loop itself wouldn't be endless. If the iteration reaches block 0
then the signature will be wrong. This means that map count = INT_MAX
case would fail even if such a setup would be correct on disk.
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
Multiple occurrences of CACHE_FILE lead to memory leaks.
Also if last occurrence of CACHE_FILE is empty then cache file is not
set to NULL again.
An example /etc/blkid.conf could be:
CACHE_FILE=/tmp/cache1
CACHE_FILE=/tmp/cache2
CACHE_FILE=
I would expect that CACHE_FILE is empty but actually it is still
/tmp/cache2.
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
Add new API for additional probing hints (offsets). The idea is that
probing function can optionally use the hint to detect superblock or
partition table if on unusual place where the library does not expects (etc.)
The hints use strings as identifiers (e.g. "last-medium-session") to
make it extendable and prober specific (if necessary). The function
blkid_probe_set_hint() always add a new hint, so you can specify more
offsets with the same (hint) name.
The function blkid_probe_get_hint() is not public. For now it returns
the first hint only.
Addresses: https://github.com/karelzak/util-linux/issues/1161
Signed-off-by: Karel Zak <kzak@redhat.com>
According to coverirty a printf format string contains an unrecognized
format specifier (CWE-628). Lets avoid glibc extension "%m" that is same
as "%s", strerror(errno).
CID: 360699
CID: 360718
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
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>
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 wording "allow(s) to" is not grammatical English. Reword various
pages to use a more correct form such "can be use to" or "allows
the [noun] of".
Aklong the way, fix a few nearby wording errors in some pages.
Signed-off-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
This patch add support for a new tag. The tag is based on udev block
device ID (see /dev/disk/by-id). The usual use-case is to use
WWN for this purpose, for example
# mount ID=wwn-0x50026b724b09a1ff /mnt
Note that ID is not strictly defined and udevd generates various IDs
also for HW where WWN is undefined. This is reason why introduce ID=
seems better and more generic than more restrictive WWN=.
Addresses: https://github.com/karelzak/util-linux/issues/1008
Signed-off-by: Karel Zak <kzak@redhat.com>
There is quite some value (in terms of readability and user
expectations) if consistent names are used for the sections
within manual pages. This patch is one of a series to bring
about this consistency.
In the Linux man-pages project, I long ago did away with the
AUTHOR(S) section, but I realize some projects like to keep this.
But, let's make sure that the section is consistently titled
across pages. Currently we have AUTHOR (47) or AUTHORS (41).
Let's standardize on the latter (which is also what is
suggested in man-pages(7)).
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
Using double quotes in .SH lines containing multiple words is unneeded,
and in any case is not consistently done in the util-linux manual pages,
where double quotes are used in only around half of the cases.
(This usage was long ago elminated in the man-pages project, with
no ill effects reported to date.)
Remove these quotes, so that .SH lines are more uniform, in preparation
for some (more easily) scripted doiscovery of consistency problems in
(and possibly global fixes to) the manual pages.
Other than stripping the double quotes, this patch makes no changes to
the content of the manual pages.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
The dax (direct access) blockdev capability is exposed via sysfs, add it
to the list of topology values to be obtained while probing.
Expose blkid_topology_get_dax() symbol that programs can link against
for querying the capability.
Reorder the idinfos array to give precedence to the sysfs over ioctl so
that the dax probe has a chance to be executed, as there is no ioctl
interface for it.
Signed-off-by: Anthony Iliopoulos <ailiop@suse.com>
This PR fixes an off by one in `strncmp(dev->bid_name, "/dev/mapper/", 11)` check. The `"/dev/mapper/"` string literal has a length of 12 and without this fix paths like `"/dev/mapperSOMETHING"` would also be accepted.
The zonefs filesystem was added to upstream linux kernel 5.6. This
patch add support for probing zonefs formatted zoned block devices so
that other file system formatting tool can detect its presence on a
device.
[kzak@redhat.com: - use standard integer types]
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/superblocks/exfat.c: In function ‘probe_exfat’:
./include/c.h:133:17: warning: comparison of distinct pointer types lacks a cast
libblkid/src/superblocks/exfat.c:129:5: note: in expansion of macro ‘min’
./include/c.h:134:8: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
Let's consolidate the code, we need to use it in libfdisk too. It
seems better to keep it generic and libblkid independent.
This patch also removes blkid_encode_alloc(), this function is overkill.
Signed-off-by: Karel Zak <kzak@redhat.com>
The logger and rtwake time function changes continue the same fixes as
previous commit - use thread safe functions. The libsmartcols condition
removal is possible because width must be greater than tb->termwidth that is
size_t and cannot be smaller than zero. And remove couple FIXME's that are
old and unlikely ever to get fixed.
Reference: 3160589d86
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Function blkid_encode_to_utf8() says that is supports BLKID_ENC_UTF16LE and
BLKID_ENC_UTF16BE encodings, but it is not truth and supports only UCS-2
(and not full UTF-16).
As all places where BLKID_ENC_UTF16LE and BLKID_ENC_UTF16BE is used expects
UTF-16 and not UCS-2, this patch changes implementation of encodings
BLKID_ENC_UTF16LE and BLKID_ENC_UTF16BE to supports full UTF-16, including
surrogate pairs and not only UCS-2.
The commit 39f5af2598 introduces
O_NONBLOCK to avoid the tray close on open(). The side effect is that
open() is successful when there is no medium.
This is usually no problem for standard tools because the next read()
will fail. Unfortunately, libblkid ignores I/O errors for (and only
for) CDROMs to support some crazy hybrid data+audio disks. The final
result is many I/O errors in system log when O_NONBLOCK is enabled.
This patch add CDROM_DRIVE_STATUS to stop probing when there is no
disk or when the tray is open.
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1787973
Signed-off-by: Karel Zak <kzak@redhat.com>
* 'master' of https://github.com/dsd/util-linux:
libblkid: improve identification of ISO9660 partition
isosize: move ISO size functions into a shared header
Add a comma (,) after "e.g." and "i.e.", or use English words
(man-pages(7) [package "manpages"]).
Abbreviation points should be protected (usually with the
non-printing, zero width character '\&') from being interpreted as an
end of sentence, if they are not, and that independent of their current
place on the line.
This is important when typing, as one does not usually know in
advance when the editor jumps to a new line.
Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
Recent changes to the iso9660 handler attempt to better handle the case
where the media has both an ordinary ISO9660 filesystem, and a partition
table with a partition entry pointing at the ISO9660 filesystem.
Rather than assuming the presence of a partition table means that there
is an ISO9660 partition, check that such a partition exists before
deciding upon which device the metadata should be presented. One real
world example of this is the grub-mkrescue image format; add a unit test
to cover that.
Secondly, even if we find an appropriate entry in the partition table,
verify that we actually have a device that corresponds to the partition
where we would then proceed to expose this metadata. In the case of a
CD/DVD (i.e. /dev/sr0) we would not normally expect to see devices
corresponding to the partitions, in that case the ISO metadata should be
presented on the whole disk (/dev/sr0).
Fixes: 7ef86a0891 ("libblkid: improve handling of ISO files with partition tables")
Link: https://bugzilla.redhat.com/show_bug.cgi?id=1783066
Signed-off-by: Daniel Drake <drake@endlessm.com>
Apple's newfs_udf, when creating UDF 2.60 disks, sets value 2.50 into
both Minimum UDF Read Revision and Minimum UDF Write Revision fields in
LVIDIU. And sets 2.60 value into UDF revision field in LVD descriptor.
So to correctly parse and set blkid ID_FS_VERSION field, use maximum value
from Minimum UDF Read Revision in LVIDIU, Minimum UDF Write Revision in
LVDIU and UDF revision in LVD descriptor.
This commit also adds a testing UDF 2.60 disk image with 4K sectors created
by Apple's newfs_udf to verify that ID_FS_VERSION is set correctly to 2.60.
When autoclose is set (kernel default but many distributions reverse the
setting) opening a CD-rom device causes the tray to close.
The function of blkid is to report the current state of the device and
not to change it. Hence it should use O_NONBLOCK when opening the
device to avoid closing a CD-rom tray.
blkid is used liberally in scripts so it can potentially interfere with
the user operating the CD-rom hardware.
[kzak@redhat.com: add O_NONBLOCK also to:
- wipefs
- blkid_new_probe_from_filename()
- blkid_evaluate_tag()]
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
Sorry detail-oriented people tend to wipe these out if they notice them.
Add in automated tools and lots of excess end-of-line spaces get wiped
out.
Addresses: https://github.com/karelzak/util-linux/pull/849
Signed-off-by: Karel Zak <kzak@redhat.com>
The ISO format specifically leaves the first 32kb blank so that it
can be used for other purposes, such as adding a partition table.
This is commonly used (e.g. by Endless and Fedora installation media) to
have partition 0 starting at sector 0 as a mountable iso9660 filesystem,
followed by more partitions (e.g. an EFI system partition).
Such layouts can be easily created by tools such as xorriso.
When plugging in a USB disk flashed with this type of ISO, blkid presents
a somewhat confusing view of the block devices. Taking the example of
a 'sda' disk with two partitions:
1. The "iso partition"
2. An unformatted partition
In such a setup, before the changes here, blkid will currently report the
ISO metadata attributes ID_FS_PUBLISHER_ID, ID_FS_UUID, ID_FS_LABEL, and
ID_FS_TYPE=iso9660 on both sda *and* sda1.
Since sda2 is unformatted, it won't have any ID_FS_ attributes of it's
own. And due to the following standard udev rule:
# for partitions import parent information
ENV{DEVTYPE}=="partition", IMPORT{parent}="ID_*"
sda2 will actually import all of the ID_FS_ stuff from the parent device
sda.
The result at this point is that three udev devices all have the same
ID_FS_ attribute values, leading to strange results such as three
devices all racing to own the link in /dev/disk/by-uuid, so you can't
reliably do a mount-by-UUID.
Clean up this situation by detecting such partitioned ISO disks
in the superblock probing setup. If files of this kind are detected,
we now only expose the ISO metadata attributes on the specific partition
that points to the ISO data (and not the parent disk).
Signed-off-by: Daniel Drake <drake@endlessm.com>
This patch extends libblkid, so that it reports filesystem block size.
When blkid returns a specific number in the BLOCK_SIZE attribute, it
guarantees that all the bios submitted by the filesystem are aligned on
this boundary.
We need this because when we want to enable dm-integrity or dm-writecache
on an existing filesystem, we need to know filesystem block size, so that
dm-integrity or dm-writecache is initialized with matching block size.
We could always use block size 512 for dm-integrity and dm-writecache, but
that would cause metadata overhead and performance degradation. On the
other hand, if we used block size 4096, it would fail if the filesystem
has smaller blocksize.
[kzak@redhat.com: - move vfat BLOCK_SIZE to probing function
- remove unwanted debug fprintf from ZFS prober]
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
The function blkid_verify() uses private device file descriptor and
uses blkid_probe_set_device() to assign the descriptor to low-level
probing code. Unfortunately, close() in this case is not enough as the
prober can internally open whole-disk device too.
The library API has been extended so blkid_probe_set_device()
deallocates and close previously used prober for whole-disk. This new
functionality is used in blkid_verify() now.
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1734545
Signed-off-by: Karel Zak <kzak@redhat.com>
We do not need all the metadata and it seems the extra padding is
problematic in some cases. Let's keep is simple and use fixed offset
for the metadata rather than sizeof().
References: https://github.com/karelzak/util-linux/pull/820
Signed-off-by: Karel Zak <kzak@redhat.com>
With aligned attribute many blkid tests fail with following error. So
instead of aligning to 4K add padding that makes the struct same size
without causing asan trip over.
libblkid/src/superblocks/drbd.c:179:6: runtime error: member access
within misaligned address 0x55913d7e6958 for type 'struct
meta_data_on_disk_9', which requires 4096 byte alignment
In zfs structure it seems compiler is adding padding, that does not mix well
with be32_to_cpu() and other bit operations.
libblkid/src/superblocks/zfs.c:109:23: runtime error: load of misaligned
address 0x7ff6406540e4 for type 'uint32_t' (aka 'unsigned int'), which
requires 8 byte alignment
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Without this running test_blkid_save without arguments will cause a crash
when strdup() refers to none-exiting file name.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Kernel 5.2 can use superblock version 3 for dm-integrity.
Let's remove the explicit version check to be compatible
with future extensions.
Signed-off-by: Milan Broz <gmazyland@gmail.com>
This started as fix to following warning.
libblkid/src/superblocks/bcache.c:33:3: warning: ISO C99 doesn’t
support unnamed structs/unions [-Wc99-c11-compat]
But when sent to review Karel told out rather than getting rid of warnings
lets get rid of everything unnecessary.
[kzak@redhat.com: - use original struct member names rather than 'padN']
Reference: https://github.com/karelzak/util-linux/pull/802
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
Let's keep compilers and static analyzers happy. The idea is to use
memcpy() to copy from buffer to variable and use all label as unsigned
char rather than vectorize by uint16_t.
Signed-off-by: Karel Zak <kzak@redhat.com>
If blkid_verify deems that device revalidation is not needed since BLKID_PROBE_MIN
seconds haven't elapsed since the last revalidation of the device it returns
a blkid_dev. However, if this device has been read from the cache file on disk then
it wont' have BLKID_BID_FL_VERIFIED bit set. This in turn could lead to a later
call to blkid_dev_get free this device in case its part of a multi device
configuration. This is particularly relevant to btrfs raid configurations.
Namely this was exhibited by btrfs-progs which use blkid for device enumeration.
In case of a multi-device filesystem (i.e raid10) running xfstest btrfs/011
would fail sporadically since cached devices read from cache were not revalidated
due to being recently validated (according to timestamp in the cache file) at
the same time their in-memory blkid_dev structures didn't have BLKID_BID_FL_VERIFIED
set. This lead to their untimely removal from the cache from blkid_get_dev.
Fix this by setting the BLKID_BID_FL_VERIFIED when returning from blkid_verify
with a valid device irrespective of whether full revalidation was performed or
the device is deemed valid due to being recently validated.
[kzak@redhat.com: - remove also check for BLKID_BID_FL_VERIFIED, the
function needs to check for elapsed time only]
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
That constant is set to 200 seconds and is already check in probe_all().
It essentially controls how often blkid_probe_all can do a full cache
revalidation. Since blkid_verify is called from within probe_all() iff at least
BLKID_PROBE_INTERVAL seconds have elapsed it makes no sense to check this value
in blkid_verify.
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
This change fixes "warning: variable 'var' may be uninitialized when used
here [-Wconditional-uninitialized]" warnings reported in various files.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Currently we use libuuid to print UUID only. This code is possible to replace
by one snprintf(). It seems better to duplicate this one snprintf than force
all distros to keep libuuid together with libblkid.
Note, this scenario has been already supported on --disable-libuuid.
Reported-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
blkid(8) in high-level mode checks partitions and unpartitioned
whole-disk devices from the file /proc/partitions.
The current heuristic assumes that partition name ends with a digit.
Unfortunately, this is not correct -- for example md0 or nvme0n1 are
whole-disk devices.
This commit uses sysfs_devno_is_wholedisk() to make sure the device is
a partition (according to kernel or DM). It's probably more expensive,
because this way requires more syscalls (to read stuff from /sys etc.).
The patch also adds more information to the blkid(8) man page.
Addresses: https://github.com/karelzak/util-linux/issues/728
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/superblocks/ntfs.c:80:2: warning: ISO C restricts enumerator
values to range of 'int' (4294967295 is too large) [-Wpedantic]
Addressed: https://github.com/karelzak/util-linux/pull/732
Signed-off-by: Karel Zak <kzak@redhat.com>
* 'master' of https://github.com/kvanals/util-linux:
Removed BlueStore VERSION information as it is gibberish
Updated BlueStore expected result
Added BlueStore test image
Stratis superblock is little endian, ensure we retrieve the
number of sectors and initialization time correctly.
Signed-off-by: Tony Asleson <tasleson@redhat.com>
This adds the according meta-data structs + defines and an additional
function to detect DRBD9 magics.
Signed-off-by: Roland Kammerer <roland.kammerer@linbit.com>
Some new features in Linux kernel 4.19 for dm-integrity use metadata
format version 2, patch adds it to detection.
Signed-off-by: Milan Broz <gmazyland@gmail.com>
Let's use standardized names for licenses. The names used by SPDX
makes things more obvious at first glance. For complete list see:
https://spdx.org/licenses/
Note, this commit does not change any license or so...
Signed-off-by: Karel Zak <kzak@redhat.com>
It's probably unnecessary change as blkid_parttable_set_id() is used
by MBR code and we use proper buffer size there, but better safe than
sorry.
Signed-off-by: Karel Zak <kzak@redhat.com>
* use "const" in functions where we don't modify arguments
* use "const" when cast from const buffer to any struct (superblock etc.)
Signed-off-by: Karel Zak <kzak@redhat.com>
This patch adds search for a secondary LUKS2 header,
if the primary one is corrupted.
This patch is primarily needed for wipefs that should wipe
both signatures (otherwise LUKS2 header recovery can use
secondary header and revert wipefs action).
Signed-off-by: Milan Broz <gmazyland@gmail.com>