Commit Graph

595 Commits

Author SHA1 Message Date
Pali Rohár 427ea35512 libblkid: detect session_offset hint for optical discs
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>
2020-11-10 23:40:52 +01:00
Pali Rohár bfd4da5628 libblkid: do size correction of optical discs also by last written sector
Everything after last written sector is undefined.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-11-10 23:21:14 +01:00
Pali Rohár 6b88a410ae libblkid: detect CD/DVD discs in packet writing mode
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>
2020-11-10 23:21:13 +01:00
Samanta Navarro c70b4f2a5b libblkid: limit amount of parsed partitions
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>
2020-11-10 11:53:16 +00:00
Samanta Navarro 3fbeb9eeb8 libblkid: fix time_t handling
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>
2020-11-10 11:52:45 +00:00
Karel Zak b7bca24476 libblkid: overwrite existing hint
Addresses: https://github.com/karelzak/util-linux/issues/1161
Suggested-by:  Pali Rohár <pali.rohar@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-09 17:11:51 +01:00
Karel Zak 248c239b27 libblkid: export blkid_probe_reset_hints()
* 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>
2020-11-09 11:42:58 +01:00
Samanta Navarro 8f22adaaf3 libblkid: allow a lot of mac partitions
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>
2020-11-08 11:47:33 +00:00
Samanta Navarro 02162731c1 libblkid: fix memory leak in config parser
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>
2020-11-08 11:47:33 +00:00
Samanta Navarro bd0f347f86 misc: fix typos
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:42:28 +00:00
Samanta Navarro cb77628876 misc: fix typos [codespell]
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:42:25 +00:00
Karel Zak 67719fbbda libblkid: add blkid_probe_{set,get}_hint()
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>
2020-11-03 17:12:20 +01:00
Sami Kerola 7f9e76b4df fsck, libblkid: fix printf format string issue [coverity scan]
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>
2020-10-16 11:35:16 +02:00
Karel Zak 282ceadc3a libblkid: make Atari more robust
* ignore large disks
* check in-table stored device size
* check bad sectors list
* check partition dimensions against in-table device size

Addresses: https://github.com/karelzak/util-linux/issues/1159
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-13 16:19:20 +02:00
Karel Zak 2cc76d50d7 libblkid: fix Atari prober logic
Addresses: https://github.com/karelzak/util-linux/issues/1159
Addresses: https://github.com/karelzak/util-linux/issues/1116
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-09 13:06:08 +02:00
Karel Zak 8d3f9430c5 libblkid: use /sys to read all block devices
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>
2020-10-07 13:49:45 +02:00
Karel Zak 4b2e840c11 libblkid: (gpt) accept tiny devices
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>
2020-09-30 13:11:01 +02:00
Karel Zak e913192048 libblkid: improve debug for /proc/partitions
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-30 11:37:09 +02:00
Karel Zak bd64c5a3f1 libblkid: (docs) add missing references
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-22 10:33:44 +02:00
Karel Zak 29e204d117 docs: reword others "allow to"
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-14 14:31:29 +02:00
Michael Kerrisk (man-pages) 4f68c8b179 Manual pages: various: reword "allow(s) to"
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>
2020-07-14 14:08:54 +02:00
Yuri Chornoivan 311e33afef Fix minor typos 2020-07-09 20:14:32 +03:00
Karel Zak a732e4a1d3 libblkid: remove blkid_llseek()
Let's use libc lseek() everywhere like we use in another tools. It's
year 2020 ...

Addresses: https://github.com/karelzak/util-linux/issues/1083
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-01 15:47:20 +02:00
Karel Zak 487b55db54 libblkid: (docs) document new function
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-06-09 10:51:37 +02:00
Karel Zak b3391f3ac7 libmount: add support for ID=
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>
2020-06-03 16:53:00 +02:00
Karel Zak f8ad710f6c build-sys: add missing LDADD to blkid test
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-05-29 09:54:48 +02:00
Michael Kerrisk (man-pages) a8d0d330cf Manual pages: Standardize on AUTHORS as section title
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>
2020-05-20 12:56:12 +02:00
Michael Kerrisk (man-pages) 5a82980632 docs: (man) remove double quotes (") in .SH lines
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>
2020-05-19 12:15:34 +02:00
Karel Zak f821f63fce libblkid: fix fstatat() use in blkid__scan_dir()
Addresses: https://github.com/karelzak/util-linux/issues/1037
References: 2208b3ccb2
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-05-12 09:16:49 +02:00
Anthony Iliopoulos 17c57e2509 libblkid: add dax capability detection in topology probing
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>
2020-05-06 15:27:29 +02:00
Rosen Penev ad296391f9
[clang-tidy] fix wrong *cmp usage
Found with bugprone-suspicious-string-compare

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:21:00 -07:00
Rosen Penev 042f62dfc5
[clang-tidy] do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:20:59 -07:00
Rosen Penev bd89499e07
[clang-tidy] do not return in void functions
Found with readability-redundant-control-flow

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-19 14:03:21 -07:00
Rosen Penev 13ae035211
[clang-tidy] fix mismatching declarations
Found with readability-inconsistent-declaration-parameter-name

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-19 14:03:21 -07:00
Disconnect3d 7fa6e86789
Fix off by one when checking "/dev/mapper/" path
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.
2020-04-13 16:14:10 +02:00
Karel Zak ba481a28a8 libblkid: remove unnecessary uuid.h
Addresses: https://github.com/karelzak/util-linux/issues/993
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-23 15:21:48 +01:00
Damien Le Moal 9d691cbc94 libblkid: Add support for zonefs
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>
2020-03-23 11:27:16 +01:00
Karel Zak 81826929eb libblkid: fix compiler warning [-Wsign-compare]
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>
2020-02-25 12:06:06 +01:00
Karel Zak 35c6ed615f libblkid: move UTF encoding function to lib/
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>
2020-02-25 12:00:27 +01:00
Sami Kerola f6b6beaf6a
various: fix more lgtm scan warnings
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>
2020-02-20 20:18:46 +00:00
Pali Rohár fb4ed8a511 exfat: Fix parsing exfat label
According to released exfat specification, label is only 22 bytes long.
2020-02-12 18:08:46 +01:00
Pali Rohár f8b9b74394 libblkid: Fix UTF-16 support in function blkid_encode_to_utf8()
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.
2020-02-09 13:04:34 +01:00
Karel Zak f6e182078a libblkid: (zfs) don't probe whole-disk areas covered by partitions
Addresses: https://github.com/karelzak/util-linux/issues/918
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-13 13:00:14 +01:00
Karel Zak 27903b1cc4 Revert "libblkid: improve handling of ISO files with partition tables"
This reverts commit 7ef86a0891.
2020-01-13 11:53:11 +01:00
Karel Zak cd361f901e Revert "libblkid: improve identification of ISO9660 partition"
This reverts commit fc84bc0a46.
2020-01-13 11:48:37 +01:00
John Baublitz c54f54d680 libblkid: Fix documentation in libblkid header 2020-01-10 12:05:46 +01:00
Karel Zak 9650cebc7d Merge branch 'fix-xfs-external-log' of https://github.com/mfoliveira/util-linux 2020-01-08 09:53:32 +01:00
Karel Zak e72eea70c4 libblkid: check status for the current CDROM slot
It's probably more safer.

Reported-by: Michal Suchánek <msuchanek@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-08 09:23:04 +01:00
Mauricio Faria de Oliveira d756af7d64 libblkid: (xfs) external log: check for regular xfs on more sectors
The xfs external log probe only checks for regular xfs on sector zero,
but then checks for valid log record headers on all first 512 sectors.

This can incorrectly detect an xfs external log if a regular xfs (i.e.
with internal log) is shifted by up to 512 sectors; it may happen with
bcache and LVM1 for example, as the regular xfs is found later in disk.

This results in ambivalent filesystem detection, thus no UUID for udev.

Fix this problem by checking for regular xfs on all sectors considered
by the xfs external log probe.

Test-case with bcache:
---

    $ IMG=bcache-backing-device.img
    $ dd if=/dev/zero of=$IMG bs=1G count=0 seek=1
    $ DEV=$(sudo losetup --find --show $IMG)

    $ sudo make-bcache -B $DEV

    $ sudo mkfs.xfs -d agsize=16m -l agnum=0 -f /dev/bcache0

    $ sudo LD_LIBRARY_PATH=./.libs ./wipefs /dev/bcache0
    DEVICE  OFFSET TYPE UUID                                 LABEL
    bcache0 0x0    xfs  9f6dfa9d-4488-46f7-906b-dcfc96027cfe

    $ echo 1 | sudo tee /sys/block/bcache0/bcache/stop

    $ sudo hexdump -C $DEV | grep -m2 -e XFSB -e 'fe ed ba be'
    00002000  58 46 53 42 00 00 10 00  00 00 00 00 00 03 f0 00  |XFSB............|
    00007000  fe ed ba be 00 00 00 01  00 00 00 02 00 00 00 14  |................|

  Without patch:

    $ sudo LD_LIBRARY_PATH=./.libs ./wipefs $DEV
    DEVICE OFFSET TYPE             UUID                                 LABEL
    loop0  0x1018 bcache           23da3ba9-2467-453d-b020-06f02c947190
    loop0  0x7000 xfs_external_log

  With patch:

    $ sudo LD_LIBRARY_PATH=./.libs ./wipefs $DEV
    DEVICE OFFSET TYPE             UUID                                 LABEL
    loop0  0x1018 bcache           23da3ba9-2467-453d-b020-06f02c947190

Test-case with LVM1:
---

    $ IMG=lvm-backing-device.img
    $ dd if=/dev/zero of=$IMG bs=1G count=0 seek=1
    $ DEV=$(sudo losetup --find --show $IMG)

    $ sudo lvm pvcreate -M1 $DEV
    $ sudo lvm vgcreate -M1 lvm-vg-test $DEV
    $ sudo lvm lvcreate  lvm-vg-test --name lvm-lv-test --extents 100%VG

    $ sudo mkfs.xfs -d agsize=16m -l agnum=0 -f /dev/mapper/lvm--vg--test-lvm--lv--test

    $ sudo LD_LIBRARY_PATH=./.libs ./wipefs /dev/mapper/lvm--vg--test-lvm--lv--test
    DEVICE                      OFFSET TYPE UUID                                 LABEL
    lvm--vg--test-lvm--lv--test 0x0    xfs  451ba725-8394-4ebe-9b49-fc5f4a99667f

    $ sudo lvchange -an lvm-vg-test

    $ sudo hexdump -C $DEV | grep -m2 -e XFSB -e 'fe ed ba be'
    00020000  58 46 53 42 00 00 10 00  00 00 00 00 00 03 f0 00  |XFSB............|
    00025000  fe ed ba be 00 00 00 01  00 00 00 02 00 00 00 14  |................|

  Without patch:

    $ sudo LD_LIBRARY_PATH=./.libs ./wipefs $DEV
    DEVICE OFFSET  TYPE             UUID                                   LABEL
    loop0  0x0     LVM1_member      agUhNT-9f42-Z30B-Z4Ew-skWd-3h3a-tWMY0A
    loop0  0x25000 xfs_external_log

  With patch:

    $ sudo LD_LIBRARY_PATH=./.libs ./wipefs $DEV
    DEVICE OFFSET TYPE        UUID                                   LABEL
    loop0  0x0    LVM1_member agUhNT-9f42-Z30B-Z4Ew-skWd-3h3a-tWMY0A

Signed-off-by: Mauricio Faria de Oliveira <mfo@canonical.com>
2020-01-07 19:25:57 -03:00
Karel Zak dc30fd4383 libblkid: check for medium on CDMROMs probing
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>
2020-01-07 16:48:34 +01:00
Karel Zak 24cee7157a docs: update year in libs docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-06 12:59:45 +01:00
Karel Zak 63f8c66af8 Merge branch 'master' of https://github.com/dsd/util-linux
* 'master' of https://github.com/dsd/util-linux:
  libblkid: improve identification of ISO9660 partition
  isosize: move ISO size functions into a shared header
2019-12-20 12:55:49 +01:00
Karel Zak 5202d809b6 Merge branch 'master' of https://github.com/pali/util-linux
* 'master' of https://github.com/pali/util-linux:
  libblkid: udf: Fix reporting UDF 2.60 revision for Mac OS X disks
2019-12-17 12:34:18 +01:00
Bjarni Ingi Gislason eb02489380 man pages: Add a comma after "e.g." and "i.e."
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>
2019-12-17 12:32:43 +01:00
Daniel Drake fc84bc0a46 libblkid: improve identification of ISO9660 partition
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>
2019-12-16 14:29:24 +08:00
Pali Rohár 92fc937ba4 libblkid: udf: Fix reporting UDF 2.60 revision for Mac OS X disks
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.
2019-12-15 12:55:41 +01:00
Karel Zak 5fbb920ed4 libblkid: improve MD I/O size calculation [lgtm scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-12-03 14:51:31 +01:00
Karel Zak 2d1e803b08 libblkid: improve vfat entries calculation [lgtm scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-12-03 14:49:16 +01:00
Michal Suchanek 39f5af2598 libblkid: open device in nonblock mode.
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>
2019-11-06 09:55:49 +01:00
Elliott Mitchell 2bb3aa36b2 cleanup: Remove some spurious spaces
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>
2019-10-01 13:01:43 +02:00
Daniel Drake 7ef86a0891 libblkid: improve handling of ISO files with partition tables
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>
2019-09-25 11:41:30 +08:00
Karel Zak 351de28ae6 libblkid: remove unnecessary condition [lgtm scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-20 15:52:34 +02:00
Sami Kerola 218b1dd6f9
misc: fix typos [codespell]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-09-12 19:41:46 +01:00
Karel Zak 2771d40b88 libblkid: (xfs) fix sector size calculation
Reported-by: Anatoly Pugachev <matorola@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-03 15:10:35 +02:00
Mikulas Patocka cd129b7d2f blkid: retport block size of a filesystem
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>
2019-09-02 12:55:53 +02:00
Karel Zak c4d6d1c54d libblkid: fix file descriptor leak in blkid_verify()
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>
2019-07-31 16:31:10 +02:00
Karel Zak 1768d77c18 libblkid: (drbd) fix comment formatting
... to avoid misinterpretation by gtk-docs.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-22 11:49:45 +02:00
Karel Zak cdb9140967 libblkid: do not interpret NTFS as MBR
# mkntfs -Q -F /dev/sdc

old version:
 # ./blkid -p /dev/sdc
 /dev/sdc: UUID="0E9E8C5F2F718479" TYPE="ntfs" USAGE="filesystem" PTTYPE="dos"

new version:
 # ./blkid -p /dev/sdc
 /dev/sdc: UUID="0E9E8C5F2F718479" TYPE="ntfs" USAGE="filesystem"

Reported-by: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-17 12:35:45 +02:00
Karel Zak 5c8a88356d libblkid: (drbd) simplify padding
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>
2019-07-15 12:07:42 +02:00
Sami Kerola f55dd4cc2d
libblkid: fix address sanitizer issues
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>
2019-07-14 11:53:59 +01:00
Sami Kerola 9175f39075
libblkid: check number of test_blkid_save arguments correctly
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>
2019-07-14 11:53:59 +01:00
Milan Broz 73421b953e libblkid: fix detection of dm-integrity superblock version
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>
2019-06-04 13:04:09 +02:00
Sami Kerola ebd13d3fc5 libblkid: remove unneeded fields from struct bcache_super_block
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>
2019-05-27 11:58:13 +02:00
Karel Zak 16d7868fc1 libblkid: (silicon raid) improve checksum calculation [-Waddress-of-packed-member]
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>
2019-05-22 17:46:14 +02:00
Karel Zak 5b3b21128c libblkid: make partitions reference counting more robust [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 16:28:31 +02:00
Karel Zak 488b3a69df libblkid: don't ignore blkid_probe_set_magic() errors [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 16:24:51 +02:00
Karel Zak 709beed937 libblkid: fix possible uninitialized value use [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 16:15:15 +02:00
Nikolay Borisov 99878f5dc4 libblkid: Set BLKID_BID_FL_VERIFIED in case revalidation is not needed
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>
2019-05-14 13:35:58 +02:00
Nikolay Borisov 5de879b0f2 libblkid: Don't check BLKID_PROBE_INTERVAL in blkid_verify
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>
2019-05-14 13:33:13 +02:00
Sami Kerola 110260830d docs: fix typos [codespell]
Reference: https://github.com/codespell-project/codespell
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-02-18 13:22:43 +01:00
Sami Kerola 4813a5210f various: fix 'uninitialized when used' warnings [clang]
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>
2019-02-18 13:19:24 +01:00
Karel Zak 84084dc324 libblkid: tiny code simplification
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-18 12:32:25 +01:00
Karel Zak c2435b946f libblkid: remove dependence on libuuid
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>
2019-01-22 12:33:19 +01:00
Karel Zak 969e8cbeb1 libblkid: improve whole-disk detection when read /proc/partitions
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>
2019-01-08 12:07:18 +01:00
Karel Zak 9b13b5602e libblkid: (ntfs) fix compiler warning [-Wpedantic]
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>
2019-01-02 14:47:25 +01:00
Karel Zak 2d6cad08cf Merge branch 'master' of https://github.com/kvanals/util-linux
* 'master' of https://github.com/kvanals/util-linux:
  Removed BlueStore VERSION information as it is gibberish
  Updated BlueStore expected result
  Added BlueStore test image
2019-01-02 14:20:21 +01:00
Kenneth Van Alstyne 36b0530e12 Removed BlueStore VERSION information as it is gibberish 2018-12-17 20:21:32 -06:00
Karel Zak 200769b6c0 libblkid: (bluestore) terminate magic strings array
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-17 11:05:23 +01:00
Karel Zak be2762b862 Merge branch 'master' of https://github.com/kvanals/util-linux
* 'master' of https://github.com/kvanals/util-linux:
  Finished up BlueStore support
  Added support for detecting Ceph BlueStore Block Devices
2018-12-17 10:45:33 +01:00
Tony Asleson ae62a1751f libblkid: stratis: correct byte order
Stratis superblock is little endian, ensure we retrieve the
number of sectors and initialization time correctly.

Signed-off-by: Tony Asleson <tasleson@redhat.com>
2018-12-17 10:16:11 +01:00
Kenneth Van Alstyne 4125497278 Finished up BlueStore support 2018-12-14 14:32:13 -06:00
Kenneth Van Alstyne bd301d459f Added support for detecting Ceph BlueStore Block Devices 2018-12-14 14:27:10 -06:00
Roland Kammerer ca2071c6ea libblkid: add check for DRBD9
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>
2018-11-21 10:48:08 +01:00
Andreas Henriksson b7fb72090b libblkid: Fix hidding typo
Spelling error spotted by lintian.

Signed-off-by: Andreas Henriksson <andreas@fatal.se>
2018-11-21 10:48:00 +01:00
Milan Broz 1741d2ea57 libblkid: fix detection of dm-integrity superblock
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>
2018-11-12 11:32:24 +01:00
Karel Zak 4189907e6c docs: use SPDX license names
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>
2018-08-16 14:47:21 +02:00
Karel Zak f665f6e43c libblkid: use xstrncpy() for PT id [coverity scan]
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>
2018-07-25 11:25:33 +02:00
Karel Zak 47afae0caa libblkid: const qualifier cleanup
* 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>
2018-07-20 15:05:32 +02:00
Milan Broz 8bee1a220d libblkid: Check for a secondary LUKS2 header.
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>
2018-07-11 14:18:33 +02:00
Harry Mallon 4d0bc05697 libblkid: Add more APFS checking to avoid false positives 2018-07-06 18:39:26 +01:00