Commit Graph

527 Commits

Author SHA1 Message Date
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