Commit Graph

590 Commits

Author SHA1 Message Date
Karel Zak 7816ee22d5 libblkid: (ntfs) enlarge cluster limit to 2MB
Windows 10 Creators edition has extended the ntfs cluster limit to
2MB. As a consequence blkid does not identify recent partitions with
clusters beyond 65K as ntfs ones.

Addresses: https://github.com/karelzak/util-linux/issues/641
Signed-off-by: Karel Zak <kzak@redhat.com>
Co-Author: Jean-Pierre André <jean-pierre.andre@wanadoo.fr>
2018-05-25 13:53:03 +02:00
Karel Zak 9a74f82271 libblkid: (zfs) fix compiler warning [-Wmaybe-uninitialized]
Reported-by: L A Walsh <lkml@tlinx.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-05-03 10:32:42 +02:00
Karel Zak 136f89ce5e libblkid: add BitLocker detection
Supported:
* WinVista version
* Win7 and later versions (based on NTFS)
* BitLockerToGo (for removable media; based on FAT32)

Unfortunately, it's without LABEL and UUID. It seems BitLocker does
not use volume_label and volume_serial stuff from NTFS header.

Addresses: https://github.com/karelzak/util-linux/issues/617
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-04-24 11:47:55 +02:00
Karel Zak 2b8ac985ba libblkid: (hfs) check allocation size
The current prober is based on signature only (two bytes!). It seems
pretty fragile. Linux kernel also checks for allocation size in the
superblock, let's use it too... it's better than nothing.

Reported-by: Milan Broz <gmazyland@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-04-12 14:21:47 +02:00
Karel Zak 04060bc3f1 Merge branch 'master' of https://github.com/pali/util-linux
* 'master' of https://github.com/pali/util-linux:
  tests: Add tests for FAT32 labels
  blkid: Encode any field which starts with LABEL in same way as LABEL field
  libblkid: vfat: Change parsing label in special cases
2018-03-27 12:54:53 +02:00
Tony Asleson 80ec018c6a libblkid: ignore private Stratis devices
[kzak@redhat.com: - tiny coding style changes]

References: 20e1c3dc03
Signed-off-by: Tony Asleson <tasleson@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-09 13:34:42 +01:00
Karel Zak 0e06893f6a libblkid:(dos) make subtypes probing more robust
The current code mix partitions as defined on disk with partitions
from partlist (as recognized by libblkid). It seems better to follow
partlist only.

Reported-by: Vaclav Dolezal <vdolezal@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-27 10:36:40 +01:00
Karel Zak 54b3434f68 libblkid: (mpool) checksum is LE
Reported-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-26 23:48:45 +01:00
Karel Zak 7748dd7bd0 libblkid: (mpool) don't use gtkdocs-like comment block
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-21 11:40:39 +01:00
Ruediger Meier 73afd3f8e8 misc: fix typos using codespell
Some more funny typos, please review carefully.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-02-16 11:12:52 +01:00
Karel Zak dcca7846c0 libblkid: make mpool independent on libuuid
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-13 10:30:39 +01:00
Karel Zak 63c9c05d35 misc: remove %p from debug messages
From libs where suid program may be executed by non-root user.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 13:18:57 +01:00
Vaclav Dolezal 046351760f libblkid: atari - reject devices with blocksize != 512
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2018-01-30 13:50:15 +01:00
Vaclav Dolezal 568419b1aa libblkid: atari - don't add duplicate entries
This should protect against looped XGMs.

Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2018-01-24 14:40:21 +01:00
Vaclav Dolezal 98d87b95de libblkid: atari - test if any partition fits disk size
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2018-01-24 14:40:21 +01:00
Vaclav Dolezal 1ca8fba830 libblkid: atari - fix bad variable name
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2018-01-24 12:18:23 +01:00
Vaclav Dolezal 50c71f25ff libblkid: Support for Atari partitioning scheme
Addresses: https://github.com/karelzak/util-linux/issues/517
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2018-01-23 17:02:41 +01:00
Ruediger Meier af1bc027db build-sys: remove redundant EXTRA_DIST files
The sources of AC_CONFIG_FILES (*.in) are automatically
distributed.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier 4beacf105e build-sys: avoid using prog_DEPENDENCIES
Use EXTRA_prog_DEPENDENCIES to have the benefit
of automake's automatic prog_DEPENDENCIES.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier 0da03d4490 build-sys: remove unneeded dependencies on bla.h.in
We have already automakes's automatic dependencies like
  bla.h.in -> bla.h -> foo.o -> bar.la

An explicit direct dependency bla.h.in -> bar.la
is redundant and useless anyways.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier a459f2ec33 build-sys: automake is able to find headers in builddir ...
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier 1d667d8849 build-sys: remove generated headers from dist tar ball
Headers should only be listed in either *_HEADERS or
*_SOURCES, especially when we want nodist_*_HEADERS.

Since all the generated headers are made by configure we
don't even need to use BUILT_SOURCES or other tricks.

Also see automake docs 9.4.1 Built Sources Example:
  case "Build bindir.h from configure"

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Karel Zak a15dca2f6d include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()
Let's make it possible to use debug.h without environment variables.

Suggested-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-17 13:58:29 +01:00
Karel Zak 6d00cfb233 include/debug: don't print pointer address for SUID programs
* introduce new flag __UL_DEBUG_FL_NOADDR to suppress pointer address printing

* use __UL_DEBUG_FL_NOADDR when SUID

* move ul_debugobj() to debugobj.h, and require UL_DEBUG_CURRENT_MASK
  to provide access to the current mask from ul_debugobj(). It's better
  than modify all ul_debugobj() calls and use the global mask as
  argument.

* remove never used UL_DEBUG_DEFINE_FLAG

Reported-by: halfdog <me@halfdog.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-12 11:01:26 +01:00
Tony Asleson f82b085c31 libblkid: Add support for stratis
Initial support for stratis, ref.
https://github.com/stratis-storage

[kzak@redhat.com: - remove C++ comment]

Signed-off-by: Tony Asleson <tasleson@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-11 10:08:24 +01:00
Karel Zak 10211619dc libblkid: (bcache) cleanup magic string definition
Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-12-18 13:03:46 +01:00
Karel Zak 42dea85c5a lib/md5: use ul_/UL_ prefix
The symbols names are too generic.

Addresses: https://github.com/karelzak/util-linux/issues/548
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-12-12 12:06:15 +01:00
Karel Zak b480afcaba libblkid: add debug messages when ignore useless devices
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-12-07 12:15:48 +01:00
Sweet Tea Dorminy 6418cba457 libblkid: Add VDO superblock information into blkid
[kzak@redhat.com: - add tests/expected/blkid/low-probe-vdo
                  - enlarge the image (must be > 1024)]

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-12-07 12:11:32 +01:00
Pali Rohár f0ca7e80d7 libblkid: vfat: Change parsing label in special cases
* Use only label from the root directory and do not fallback to the label
  stored in boot sector. This is how MS-DOS 6.22, MS-DOS 7.10, Windows 98,
  Windows XP and also Windows 10 behave. Moreover Windows XP and Windows 10
  do not touch label in boot sector anymore, so removing FAT label on those
  Windowses leads to having old label still stored in boot sector (which
  MS-DOS and Windows fully ignore).

* Label entry "NO NAME" in root directory is treated as label "NO NAME"
  instead of empty label. In root directory it has no special meaning.
  String "NO NAME" has a special meaning (empty label) only for label
  stored in boot sector.

* Label from the boot sector is now stored into LABEL_FATBOOT field. So if
  there are applications which depends or needs to read this label, they
  have ability.

After this change LABEL always correspondent to the label from the root
directory and LABEL_FATBOOT to the label stored in the boot sector. If some
of those labels is missing or is not present (e.g. "NO LABEL" in boot
sector) then particular field is not set.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2017-11-25 12:48:18 +01:00
Karel Zak 6e08d4d9f8 Merge branch 'master' of https://github.com/pali/util-linux
* 'master' of https://github.com/pali/util-linux:
  libblkid: udf: Fix parsing UDF revision
2017-11-21 12:42:35 +01:00
Andy Grover f024c96c34 libblkid: Mark char* params to blkid_dev_set_search as const
They are not changed by the function.

Signed-off-by: Andy Grover <agrover@redhat.com>
2017-11-21 10:43:09 +01:00
Pali Rohár 3999e62a72 libblkid: udf: Fix parsing UDF revision
UDF revision is stored as decimal number in hexadecimal format.
E.g. number 0x0150 is revision 1.50, number 0x0201 is revision 2.01.

Apparently all UDF test images have number which has same representation in
decimal and hexadecimal format, so problem was not detected.

This patch adds new test image with UDF revision 1.50. Internally number is
stored as 0x0150. In decimal format it is (incorrectly) 1.80, but in
hexadecimal correct 1.50.

$ dd if=/dev/zero of=udf-hdd-mkudffs-1.3-8.img bs=1M count=10
$ mkudffs -r 0x150 -b 512 udf-hdd-mkudffs-1.3-8.img

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2017-11-20 18:16:59 +01:00
Pali Rohár 3ea60856ee libblkid: udf: Update copyright
Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2017-11-16 19:53:59 +01:00
Pali Rohár 06d9f4763f libblkid: udf: Use UDF revision field from LVD domain id "*OSTA UDF Compliant" as a fallback value for ID_FS_VERSION when LVIDIU is missing
Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2017-11-16 18:53:52 +01:00
Karel Zak f9dc7fd135 Merge branch 'master' of https://github.com/pali/util-linux
* 'master' of https://github.com/pali/util-linux:
  libblkid: udf: Stop scanning Volume Descriptors after we found Terminating Descriptor
  libblkid: udf: Really try to read only first LVID
2017-11-16 14:18:16 +01:00
John Groves b0a89709bf libblkid: Add support for Micron mpool formatted drives
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-16 11:44:52 +01:00
Pali Rohár 4572e4070d libblkid: udf: Stop scanning Volume Descriptors after we found Terminating Descriptor
Terminating Descriptor is the last descriptor in Volume Descriptor
Sequence. After it there can be unrecorded or empty sectors which we do not
have to scan.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2017-11-15 18:12:50 +01:00
Pali Rohár d0ecd5e984 libblkid: udf: Really try to read only first LVID
We do not want to scan whole LVID sequence.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2017-11-15 18:05:52 +01:00
Pali Rohár 6e810fa59d libblkid: udf: Fix parsing LVID location
And add comment about Logical Volume Integrity Sequence that we do not scan it fully.
2017-11-14 10:25:02 +01:00
Pali Rohár e44eb3e6e5 libblkid: udf: Fix reading Logical Volume Integrity Descriptor Implementation Use (LVIDIU)
LVIDIU is stored at the end of Logical Volume Integrity Descriptor (LVID),
after two variable length array of partitions. And number of partitions is
stored in LVID, not in Logical Volume Descriptor (LVD).

Length of LVIDIU is also stored in LVID, so add check that LVIDIU has
enough size.

Fixes commit db31676743.
2017-11-13 21:45:34 +01:00
Karel Zak cfcbf7526a Merge branch 'udf' of https://github.com/pali/util-linux
* 'udf' of https://github.com/pali/util-linux:
  test: Add UDF hdd image with final block size 4096 created by Linux mkudffs 1.3
  libblkid: udf: Optimize and fix probing when block size > 2048 bytes
2017-11-13 12:32:03 +01:00
Karel Zak 16068d0b9e Merge branch 'master' of https://github.com/pali/util-linux
* 'master' of https://github.com/pali/util-linux:
  libblkid: vfat: Fix reading labels which starts with byte 0x05
2017-11-13 12:23:23 +01:00
Pali Rohár f5f269ece5 libblkid: udf: Optimize and fix probing when block size > 2048 bytes
Optimize probing and detecting for UDF. Do not read and try to detect VRS
(Volume Recognition Sequence) on same blocks more times. For specific VSD
(Volume Structure Descriptor) length do it only once.

Fix probing of devices which has block size larger then 2048 bytes. It is
not truth that VSD is always 2048 bytes long. Its size is minimum of the
disk block size and 2048 bytes. See ECMA-167 sections 2/8.4 and 2/9.1.
Therefore when block size is larger then 2048 bytes, VRS needs to be
scanned again.

In commit 501aeb60a4 was removed check for
empty VSD identifier because it caused that UDF image with block size of
the 4096 bytes was not detected. Reason was that VRS was improperly scanned
as VSD was 4096 bytes long, with 2048 bytes zero padding.

Now when processing of devices with block size larger then 2048 bytes is
fixed we can correctly stop scanning VRS at first invalid VSD as specified
in ECMA-167 section 2/8.3.1.
2017-11-12 21:55:21 +01:00
Karel Zak 4545ba6276 libblkid: improve FreeBSD partitions parsing
FreeBSD since version 10 uses relative offsets for nested partitions.
Based on Richard Narron changes in kernel:block/partitions/msdos.c.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-10 12:55:11 +01:00
Pali Rohár e526f50391 libblkid: vfat: Fix reading labels which starts with byte 0x05
When FAT directory entry has leading byte 0x05 it is interpreted as byte
0xE5. This is how FAT stores file name which starts with byte 0xE5 as
leading byte in 0xE5 in FAT directory entry means that file slot is empty.

Fixes: #533
2017-11-09 19:03:34 +01:00
Milan Broz 573538bfba blkid: Add support for LUKS2 and new LABEL attributes.
This patch adds support for detection of a LUKS2 superblock.

LUKS2 is new version of Linux Unified Key Setup for encrypted
block devices.

LUKS2 contains a binary header and then JSON area for metadata.
Blkid should only parse the binary part, including newly available
optional LABEL and SUBSYSTEM fields.

LABEL is similar to filesystem label. The SUBSYSTEM field is
in principle, just a second label and can be used for specific udev rules
(for example if you have some 3rd party system that activates
volumes automatically, you can mark devices using this attribute).
Both labels are optional.

The magic string and UUID location are intentionally on the same offset
as LUKS v1, so even unpatched blkid now recognizes LUKS2.

Anyway, the code should not parse other versions of the header, so we now
explicitly check for header version and support only version 1 and 2.

Signed-off-by: Milan Broz <gmazyland@gmail.com>
2017-10-23 16:31:46 +02:00
Karel Zak ee7f1e9e08 libfdisk: (sun) make math more robust [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-11 14:50:43 +02:00
Karel Zak 9f20d80079 misc: cleanup UUID_STR_LEN definitions
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-15 13:25:32 +02:00
Philip Prindeville b443c1779e misc: replace magic number 37 with UUID_STR_LEN
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2017-09-05 11:49:21 +02:00
Pali Rohár c748335382 libblkid: udf: Define magic constants 2017-08-20 14:50:02 +02:00
Karel Zak feeeaca967 libblkid: fix compiler warning [-Wformat-truncation=]
The MBR partition pseudo-UUID is generated from table ID and partition
partno. The final UUID size limit is 37 bytes. The table ID has to be
restricted to keep compiler happy (for MBR the table ID is 8 bytes
as string).

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-16 11:55:57 +02:00
Karel Zak 1266fcf9cf libblkid: mark UBI as RAID
UBI is volume manager rather than filesystem. Note that libblkid has
optimized RAIDs probing (don't search for another filesystems is RAID
detected). We also don't search for RAIDs on very small devices, but
this optimization is ignored for UBI char devices (size=1byte).

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-03 15:31:54 +02:00
Rafał Miłecki a6b1ec864a libblkid: add support for UBI superblock
UBI is a volume management system that can be used on a raw flash
partition for providing multiple logical volumes. Detecting UBI
superblock may be useful for tools wanting to simplify or automate
attaching UBI.

Please note it's not directly related to the ubifs support which is just
a filesystem working on top of UBI volume.

In other words: UBI can be used on MTD partition (e.g. /dev/mtdblock0)
while ubifs can be used on UBI volume (e.g. /dev/ubi0_0).

This patch adds simple code reading UBI version and unique number and
setting it in the blkid_probe.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2017-08-03 14:11:21 +02:00
Mark Tinguely aaf133265f libblkid: add HPE extended-XFS to known filesystems
The HPE (formerly SGI) enhanced XFS has changed its magic
version number to allow the use of EXFS and community XFS
filesystems at the same time.

This patch adds HPE EXFS support to libblkid.

[kzak@redhat.com: - removed EXFS log prober, it uses the same magic
                    string as XFS log]

Signed-off-by: Mark Tinguely <mark.tinguely@hpe.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-20 10:12:21 +02:00
Milan Broz 78f9ecb990 blkid: Add dm-integrity superblock signature
Since the kernel version 4.12 there is a new dm-integrity module
that provides an emulated per-sector metadata format for storing data integrity.

This patch adds dm-integrity magic signature to blkid to recognize such
a block device.

Signed-off-by: Milan Broz <gmazyland@gmail.com>
2017-07-18 14:43:21 +02:00
Ruediger Meier 21be08ac8c build-sys: don't use non-existing UUID_LIBS
We've added UUID_LIBS in f77a4d1087 but I don't see what it
was good for.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-07-18 11:06:53 +02:00
Karel Zak 884659b32a libblkid: don't use CDROM_GET_CAPABILITY ioctl for DM devices
For some reason kernel commit e980f62353c697cbf0c4325e43df6e44399aeb64
add extra warning when the ioctl is used for DM devices. It seems we
can avoid this ioctl when the device has dm/uuid.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1469532
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-12 14:35:53 +02:00
Karel Zak 10bba184bb Merge branch 'master' of https://github.com/pali/util-linux
* 'master' of https://github.com/pali/util-linux:
  tests: update UDF test, add ID_FS_VERSION
  libblkid: udf: Add support for ID_FS_VERSION
  libblkid: udf: Fix types
  libblkid: udf: De-duplicate code for dstring decoding
2017-07-11 14:31:23 +02:00
Karel Zak 4360f56cf6 libblkid: don't check for size on UBI (char dev)
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-11 12:17:40 +02:00
Pali Rohár db31676743 libblkid: udf: Add support for ID_FS_VERSION
Set ID_FS_VERSION to Minimum UDF Read Revision.
2017-07-05 13:50:52 +02:00
Pali Rohár 35b1ec3c4b libblkid: udf: Fix types 2017-07-05 13:46:12 +02:00
Pali Rohár 7afa432a07 libblkid: udf: De-duplicate code for dstring decoding 2017-07-05 12:15:00 +02:00
Karel Zak d2b0c6587d libblkid: allow to hide already detected signatures
The libblkid probing functions returns the first successful result of
the filesystem/RAID/PT. Unfortunately, some signatures is possible to
detect by more ways or device may contains more copies (e.g. GPT).

This is no problem when we wipe signatures from the device. In this
case we zeroize on-device signature and re-scan for the signature (by
blkid_probe_step_back()).

The problem is if we want to read all permutations without the device
modification (for example wipefs(8) dry run).

This patch add blkid_probe_hide_range(). The function remove (zeroize)
specified signature from in-memory cached buffers. If the buffer is
later re-used by probing functions then the signature is invisible and
we can try detect another variant of the magic string.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-28 10:28:41 +02:00
Karel Zak 08029093b0 libblkid: remove dead code and blkid_probe_new_value()
The function blkid_probe_new_value() is unnecessary.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-27 11:26:41 +02:00
Pali Rohár f0fcfdc30f libblkid: udf: Fix parsing of UDF dstring structures
First byte of dstring is OSTA Compression ID and the last byte is length of
recorded bytes (including first byte). Last byte is not a part of recorded
characters, therefore it should not be treated as data to decode.
2017-06-22 10:38:08 +02:00
Pali Rohár 501aeb60a4 libblkid: udf: Fix detection of UDF images with block size 1024 and 4096
When detecting block size of UDF filesystem, try to use also block size
512, 1024, 2048 and 4096. This would allow blkid to detect UDF filesystem
in image file created from 4K hard disk (which should have UDF block size
4096).

Before this patch only UDF images with block size of 512 and 2048 were
detected as only block size from blkid_probe_get_sectorsize() and 2048 were
used (blkid_probe_get_sectorsize() returns for disk images 512).
2017-06-14 23:15:14 +02:00
Sami Kerola f4d3783867 misc: remove stray semicolons
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 12:21:29 +02:00
Sami Kerola 1b5042636f misc: fix reassigned values before old ones has been used [cppcheck]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 12:19:20 +02:00
Ruediger Meier 11e904f02c libblkid: fix gcc-7 warning -Wint-in-bool-context
BLOCK_SIZE(sb) should be unsigned so that the left shift is defined.

This was the warning:

../libblkid/src/superblocks/exfat.c: In function 'probe_exfat':
../libblkid/src/superblocks/exfat.c:40:42: warning: '<<' in boolean context, did you mean '<' ? [-Wint-in-bool-context]
 #define CLUSTER_SIZE(sb) (BLOCK_SIZE(sb) << (sb)->bpc_bits)
                          ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
../libblkid/src/superblocks/exfat.c:122:14: note: in expansion of macro 'CLUSTER_SIZE'
  if (!sb || !CLUSTER_SIZE(sb))
              ^~~~~~~~~~~~

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-14 11:48:22 +02:00
Ruediger Meier f64ddc95f3 misc: fix gcc-7 sprintf warnings -Wformat-overflow
../login-utils/last.c: In function ‘main’:
../login-utils/last.c:624:23: warning: ‘%s’ directive writing up to 31 bytes into a region of size 27 [-Wformat-overflow=]
   sprintf(path, "/dev/%s", ut->ut_line);
                       ^~   ~~
../login-utils/last.c:624:3: note: ‘sprintf’ output between 6 and 37 bytes into a destination of size 32
   sprintf(path, "/dev/%s", ut->ut_line);

../libblkid/src/devname.c: In function 'probe_one':
../libblkid/src/devname.c:166:29: warning: '%s' directive writing up to 255 bytes into a region of size 245 [-Wformat-overflow=]
   sprintf(path, "/sys/block/%s/slaves", de->d_name);
                             ^~
../libblkid/src/devname.c:166:3: note: 'sprintf' output between 19 and 274 bytes into a destination of size 256
   sprintf(path, "/sys/block/%s/slaves", de->d_name);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-14 11:48:22 +02:00
Karel Zak bff78d701d libblkid: (vfat) add more debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-09 11:11:38 +02:00
Ruediger Meier c0d7b11a3f build-sys: fix library order when linking
We got some errors on Alpine Linux where $LTLIBINTL is non-empty:

./.libs/libcommon.a(libcommon_la-blkdev.o): In function `open_blkdev_or_file':
lib/blkdev.c:282: undefined reference to `libintl_gettext
collect2: error: ld returned 1 exit status

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-01 03:16:48 +02:00
Karel Zak ae4e2abcb1 libblkid: (docs) add missing 'since' tags
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-23 14:27:36 +02:00
Pali Rohár d8ba647d0d libblkid: udf: Change algorithm for reporting UUID
Ensure that reported UUID always contains only lowercase hexadecimal digits
and is always 16 characters length, padded with zero digits.

Volume Set Identifier is converted to UTF-8 before generating UUID from it.
As it could potentially contain any Unicode character. So correctly handle
both 8bit and 16bit OSTA Compressed Unicode encodings.

Disks which have only lowercase hexadecimal digits in Volume Set Identifier
would have same UUID as before this patch.
2017-05-17 20:36:40 +02:00
Pali Rohár 22acc2681d libblkid: udf: Correctly handle UDF strings encoded in 8bit OSTA Compressed Unicode
String encoded in 8bit OSTA Compressed Unicode contains one Unicode
codepoint per 8bits. Maximal Unicode codepoint is U+FF. Which effectively
means that it is equivalent to Latin1 encoding.

Before this patch libblkid copied raw 8bit OSTA Compressed Unicode from
disk and treated it as UTF-8. It worked fine just for UTF-8 invariants,
other characters were incorrectly encoded. This patch fixes this problem.

Note that processing UUID is not fixed in this patch.
2017-05-16 23:52:05 +02:00
Pali Rohár 98bc12ab48 libblkid: Add support for Latin1 encoding in blkid_encode_to_utf8() 2017-05-16 23:51:50 +02:00
Karel Zak ce59d8bfa5 Merge branch 'master' of https://github.com/pali/util-linux
* 'master' of https://github.com/pali/util-linux:
  tests: Add UDF CD-ROM hybrid image (ISO+Joliet+UDF) created by Nero 6
  tests: Fix test output for low-probe-udf to contain UDF data
  Revert "libblkid: Probe UDF volumes for ISO9660 info as well"
2017-05-11 10:59:14 +02:00
Pali Rohár ccfb5b0a1d Revert "libblkid: Probe UDF volumes for ISO9660 info as well"
This reverts commit 8053b51c76.

Reporting meaningless ID_FS_LABEL=UDF_Volume written in that commit was
caused by reading wrong value for UDF label and it was fixed in commit
2f2730bc77.

So after this revert blkid reports for UDF filesystems label of UDF
filesystem and not label of ISO (if present) like other systems. In most
cases UDF and ISO labels are same (sometimes just one is upper case).

Commit 8053b51c76 just fixed result, not
reason why blkid reported different UDF Label as Windows. Real reason was
fixed in 2f2730bc77.
2017-05-05 18:38:15 +02:00
Sami Kerola 635d9aa5db
libblkid: add blkid_partitions_get_name()
This new function can be use to enquiry what partition names libblkid is
aware of.  First use of this information will be in partx(8) to make bash
completion to work without a magic list.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-02 23:22:04 +01:00
Pali Rohár 49d84dbedc libblkid: udf: For better readibility use one snprintf call instead multiple in loop 2017-05-01 09:28:22 +02:00
Ruediger Meier c8df4b17d4 misc: fix some printf format strings
Fix compiler warnings seen on Linux/i586 and OSX/travis.

  #type            #format   #cast
   unsigned long    %lu       -
   uint64_t         PRIu64    -
   fdisk_sector_t   %ju       (uintmax_t)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-04-10 15:40:58 +02:00
Karel Zak 044d6e5565 libblkid: fix typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-24 11:46:33 +01:00
Tobias Stoeckmann 62ab1ebb12 libblkid: prevent OOB access while probing HFS+
It is possible to perform out of boundary read accesses due to
insufficient boundary checks in probe_hfsplus.

The first issue occurs if the leaf count in a B-node is too
small. The second happens while parsing a unicode description which
is longer than 255 UTF-8 characters. The length is stored in a 16 bit
integer, but the array in the struct is limited to 255 * 2, which is
in sync with Apple's Open Source HFS+ implementation (HFSUniStr255).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2017-03-23 15:46:36 +01:00
Sami Kerola 57f1539592 libblkid: ensure uninitialized variable is not used [clang]
Following condition can be true if minix file system is corrupt, and versio
number is found to be greater than 3.  It is fair to say described scenario
is unlikely.

libblkid/src/superblocks/minix.c:107:13: warning: variable 'zone_size' is
used uninitialized whenever
      'if' condition is false [-Wsometimes-uninitialized]
        } else if (version == 3) {
                   ^~~~~~~~~~~~
libblkid/src/superblocks/minix.c:121:6: note: uninitialized use occurs here
        if (zone_size != 0 || ninodes == 0 || ninodes == UINT32_MAX)
            ^~~~~~~~~

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-13 14:48:12 +01:00
Sami Kerola c88f7aee8f libblkid: avoid overflow when initializing array
libblkid/src/superblocks/drbdmanage.c:38:42: warning: too long
initializer-string for array of char(no space for nul char)

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-13 14:48:10 +01:00
Sami Kerola c308e2050f misc: stop mixing declarations and code
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-13 14:48:04 +01:00
Tobias Stoeckmann 55a5fbbc33 libblkid: Fix blkid.conf parsing
The SEND_UEVENT=yes|no line is not properly parsed, because the offset
jumps one byte too far behind the equal sign. Therefore, every
configuration that contains the line "SEND_UEVENT=yes" still does not
send an uevent.

The fix is simple: adjust the offset to be "12" instead of "13".
2017-03-13 12:46:47 +01:00
Karel Zak bf3e7a40ab libblkid: remove unnecessary 'static' keyword
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-20 13:08:30 +01:00
Sami Kerola c5e3ebcedc libblkid: declare across file variables in blkidP.h [smatch scan]
Else these variables will cause following warning:

libblkid/src/superblocks/superblocks.c:165:29: warning: symbol
'superblocks_drv' was not declared.  Should it be static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 13:00:58 +01:00
Sami Kerola 2ba641e5f3 misc: add static keyword to where needed [smatch scan]
text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be
static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Karel Zak e9e88bb8e9 libblkid: (gpt) fix force flag
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-15 11:30:58 +01:00
Karel Zak 74493d48d8 libblkid: fix BLKID_PARTS_FORCE_GPT usage
Now wipefs always inform about MBR as about PMBR. That's bug.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-14 14:57:24 +01:00
Alden Tondettar a157a23f6d libblkid: Fix out of bounds reads in BEFS handling
The BEFS prober is quite trusting of whatever data is fed to it and
performs almost no bounds checks. There don't seem to be any
out-of-bounds writes as far as I can tell, but there are many ways a
corrupted image could cause libblkid to read OOB and segfault, or hang
in an infinite loop.

This fix makes a few sanity-checks of the superblock, add bounds checks
wherever they seem needed, and crudely checks for cycles in the B+ tree.

Signed-off-by: Alden Tondettar <alden.tondettar@gmail.com>
2017-01-25 11:43:06 +01:00
Alden Tondettar dfb8d4ba92 libblkid: Fix out of bounds reads on bad GPT header
If a GUID Partition Table claims to have more than 2**25 entries, or if the
size of each entry is not exactly 128 bytes, libblkid can read out of bounds
and segfault. Perform the appropriate checks.

[kzak@redhat.com: - fix typo]

Signed-off-by: Alden Tondettar <alden.tondettar@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-25 11:41:22 +01:00
Alden Tondettar 999a2ffec9 libblkid: Fix out of bounds reads on bad NTFS Master File Table
The NTFS prober does not validate certain fields in struct file_attribute,
and could attempt to read the disk label from outside the space allocated
for the Master File Table.  Perform the appropriate checks.

Note that one variable (attr_off) is now 64-bit, so a check for integer
overflow has been removed as unneeded/confusing.

Signed-off-by: Alden Tondettar <alden.tondettar@gmail.com>
2017-01-25 11:39:10 +01:00
Alden Tondettar a7caeabadf libblkid: Fix out of bounds byte swaps in ZFS handling
A corrupted ZFS filesystem can trigger 32-bit endian-conversions of
unintended memory locations in zfs_extract_guid_name(), in several ways:

* The variable "left" (number of bytes remaining in the buffer) does not
  account for the 12 bytes of the nvlist header.

* The field nvp->nvp_namelen (name length in name/value pair) is rounded
  up to the nearest multiple of 4, but only the unrounded size is checked.

* The fields nvs->nvs_type, nvs_strlen, etc. are modified _before_ checking
  if they are within bounds.

* A negative value of nvp->nvp_namelen will bypass the check that
  nvp->nvp_namelen fits into nvp->nvp_size (size of name/value pair).

This allows for mangling of locations up to 12 + 3 + 8 == 23
bytes beyond the end of stack-based buff[4096], and up to 2**31 bytes
before its beginning.

Furthermore some debugging messages are printed from unchecked memory
locations, possibly resulting in OOB reads or setuid programs leaking
sensitive data when LIBBLKID_DEBUG is set.

This fix attempts to correct all of these problems. It also eliminates the
stack-based buffer (in case anything else was missed) and refactors things
a bit to (hopefully) make it easier to spot any mistakes.

Signed-off-by: Alden Tondettar <alden.tondettar@gmail.com>
2017-01-25 11:39:10 +01:00
Karel Zak 76fab513b8 libblkid: add blkid_probe_set_sectorsize()
The usual way is to use ioctl to ask block device for sector size, but
this is useless for disk images (regular files). And the default
(512-bytes) may be pretty wrong for disk images from 4K disks. Let's
support a way how to specify proper sector size.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-13 13:26:37 +01:00
Nate Clark 892553b1a4 libblkid/minix: Sanity check superblock s_state for v 1 and 2
Swap devices with specific values in the uuid can look like minix
devices to blkid. Add an extra check to make sure the state of the
filesystem has valid state flags.

A couple of offending swap uuids include:
35f1f264-137f-471a-bc85-acc9f4bc04a3
35f1f264-7f13-471a-bc85-acc9f4bc04a3
35f1f264-138f-471a-bc85-acc9f4bc04a3
35f1f264-8f13-471a-bc85-acc9f4bc04a3

Without this change a swap device with any of those uuids would be
detected as minix and swap by blkid.

Signed-off-by: Nate Clark <nate@neworld.us>
2017-01-04 15:24:40 -05:00
Nate Clark f82c804869 libblkid/minix: Use same checks for version 3
fsck.minix performs the same sanity checks on all versions of the
superblock. Update the probe to perform the same sanity checks so it is
less likely a different type of filesystem will be identified as minix.

Signed-off-by: Nate Clark <nate@neworld.us>
2017-01-04 15:24:32 -05:00
Nate Clark a9975c1072 libblkid/minix: Match minix superblock types
All of the types in the minix super block are unsigned but in
probe_minix they were being treated as signed. This would cause some of
the extra sanity checks to pass on a non minix device. The types were
updated to match the return types of the helper functions in
disk-utils/minix_programs.h

This can be checked by creating a swap partition with one of these UUIDs
35f1f264-2468-471a-bc85-acc9f4bc04a3
35f1f264-6824-471a-bc85-acc9f4bc04a3
35f1f264-2478-471a-bc85-acc9f4bc04a3
35f1f264-7824-471a-bc85-acc9f4bc04a3

Prior to this change they would all be considered minix and swap by
blkid.

Signed-off-by: Nate Clark <nate@neworld.us>
2017-01-04 15:24:22 -05:00
Sébastien Helleu d673b74e9d docs: replace FTP by HTTPS in kernel.org URLs
The links to ftp://ftp.kernel.org/ are replaced by
https://www.kernel.org/.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 11:22:26 +01:00
Ruediger Meier 223939d95b misc: spelling, always use "cannot" instead of "can not"
Just to be consistent ...

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-11-30 14:56:50 +01:00
Ruediger Meier eaaf0e7e37 misc: once again some printf format strings
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-10-27 11:03:27 +02:00
Ruediger Meier 332123f2b6 misc: fix some compiler warnings
libsmartcols/samples/fromfile.c:59:2: warning: passing argument 3 of 'string_to_bitmask' from incompatible pointer type
  text-utils/pg.c:79:0: warning: "TABSIZE" redefined
  libblkid/src/read.c:455:13: warning: 'debug_dump_dev' defined but not used [-Wunused-function]
  libblkid/src/probe.c:769:13: warning: unused function 'cdrom_size_correction' [-Wunused-function]
  /usr/include/sys/termios.h:3:2: warning: "this file includes <sys/termios.h> which is deprecated, use <termios.h> instead" [-W#warnings]

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-10-27 11:03:24 +02:00
Gustavo Zacarias 7f0d4d56a2 lib/crc32: prefix public functions
Make the publicly-visible crc32 library functions prefixed by ul_, such
as crc32() -> ul_crc32().
This is because it clashes with the crc32() function from zlib.
For newer versions of glib (2.50+) zlib and libblkid are required
dependencies and otherwise results in build failure when building
statically.

Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
2016-10-19 12:11:59 +02:00
Tobias Stoeckmann e8c20678f3 libblkid: Avoid strlen if only first char is checked
A strlen() call can lead to out of boundary read access if the
superblock in question has no nul-bytes after the string. This
could be avoided by using strnlen() but the calls in question
merely existed to check if the string length is not 0.

By changing the calls as proposed with this diff, these files are
in sync with other superblock files, which do exactly the same.
2016-10-06 14:56:39 +02:00
Karel Zak e12e917bad libblkid: check blkid_parse_tag_string() return code [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-04 16:23:52 +02:00
Rostislav Skudnov f98b563268 libblkid: [exfat] Limit maximum number of iterations in find_label
Do not hang if there is a cluster chain loop in rootdir

[kzak@redhat.com: - add return NULL]

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-30 13:50:51 +02:00
Karel Zak 4db236f7e4 libblkid: ignore empty MBR on LVM device
It's possible to use boot sector and empty MBR on LVM physical volume
to make LVM disk bootable. In this case MBR should be ignored and disk
reported as LVM.

Just for the record, this is ugly non-default LVM setup maintained for
backward compatibility (yes, LVM guys don't like it too).

Unfortunately people still use it. The proper way is to use regular
partitioned disk.

Reported-by: Xen <list@xenhideout.nl>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-30 12:07:40 +02:00
Karel Zak a1df9c9d4e libblkid: remove unused function
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-30 11:22:30 +02:00
Tobias Stoeckmann 8fa57ab0b5 libblkid: Avoid OOB access on illegal ZFS superblocks
64 bit systems can trigger an out of boundary access while performing
a ZFS superblock probe.

This happens due to a possible integer overflow while calculating
the remaining available bytes. The variable is of type "int" and the
string length is allowed to be larger than INT_MAX, which means that
avail calculation can overflow, circumventing the "avail < 0" check and
therefore accessing memory outside the "buff" array later on.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2016-08-29 13:22:24 +02:00
Rostislav Skudnov 9d89a95e88 libblkid: Check that cluster size is nonzero when probing exFAT
This should prevent division by zero in find_label()

Signed-off-by: Rostislav Skudnov <rostislav@tuxera.com>
2016-08-16 12:08:46 +02:00
Karel Zak 38f6945d63 liblkid: fix probe_nilfs2 I/O error backup
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-02 15:54:13 +02:00
Sami Kerola 6b95f11c06
libblkid: fix debugging macro [oclint]
The oclint was complaining 'empty do/while statement' that turned out to be
true and I started to think it is best to use the same DBG() macro as in
other source files for this library.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Sami Kerola 92a4d098ce
libblkid: simplify if clause [oclint]
Move negative and positive testing of 'has' variable to top level, and test
flag bit mask on second level.  This way the 'has' needs to be checked only
once.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Karel Zak 50d1594c2e libblkid: avoid non-empty recursion in EBR
This is extension to the patch 7164a1c34d.

We also need to detect non-empty recursion in the EBR chain. It's
possible to create standard valid logical partitions and in the last one
points back to the EBR chain. In this case all offsets will be non-empty.

Unfortunately, it's valid to create logical partitions that are not in
the "disk order" (sorted by start offset). So link somewhere back is
valid, but this link cannot points to already existing partition
(otherwise we will see recursion).

This patch forces libblkid to ignore duplicate logical partitions, the
duplicate chain segment is interpreted as non-data segment, after 100
iterations with non-data segments it will break the loop -- no memory
is allocated in this case by the loop.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1349536
References: http://seclists.org/oss-sec/2016/q3/40
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-12 13:34:54 +02:00
Karel Zak 7164a1c34d libblkid: ignore extended partition at zero offset
If the extended partition starts at zero LBA then MBR is interpreted
as EBR and all is recursively parsed... result is out-of-memory.

 MBR --extended-partition--> EBR --> MBR --> ENB --> MBR ...

Note that such PT is not possible to create by standard partitioning
tools.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1349536
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-07 14:22:41 +02:00
Alexey Obitotskiy 6c448f452e libblkid: Add metadata signature check for IMSM on 4Kn drives
Drives with 512 and 4K sectors have different offset for
metadata signature. Without signature detected on 4Kn drives
those drives will not be recognized as raid member. This
patch adds checking for IMSM signature for 4Kn drives.

Signed-off-by: Alexey Obitotskiy <aleksey.obitotskiy@intel.com>
2016-07-01 13:40:11 +02:00
Torsten Hilbrich ac681a310c liblkid: Add length check in probe_nilfs2 before crc32
The bytes variable is read from the file system to probe and must be
checked before used as length parameter in the crc32 call.

The following problems may occur here:

- bytes smaller than sumoff + 4: underflow in length calculation
- bytes larger than remaining space in sb: overflow of buffer

This fixes a problem where an encrypted volume had the correct magic
values 0x3434 at offset 0x406 and the following uint16_t (which is
read into the nilfs_super_block.s_bytes struct) was parsed as 1.

Then crc32 was called with the length value 18446744073709551597
causing a segmentation fault.

[kzak@redhat.com: - fix probe_nilfs2() return code]

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-06-24 11:13:24 +02:00
Karel Zak 7f787ced5d libblkid: don't check nonnull attributes for NULL [-Wnonnull-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-06-14 14:39:16 +02:00
Sebastian Rasmussen 9e93004171 misc: Fix various typos
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Sebastian Rasmussen d35df4db5b docs: Fix various typos
Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Karel Zak 924c93d9df libblkid: store only canonical devnames to the cache
Let's try to use symlink:

 # ls -la /dev/block/8\:1
 # lrwxrwxrwx 1 root root 7 May 25 16:42 /dev/block/8:1 -> ../sda1

 # blkid /dev/block/8:1
 /dev/block/8:3: LABEL="HOME" UUID="196972ad-3b13-4bba-ac54-4cb3f7b409a4" TYPE="ext4" PARTUUID="6073277f-87bc-43ff-bcfd-724c4484a63a"

unfortunately the symlink is stored to the cache:

 <device DEVNO="0x0803" TIME="1464253300.715279" LABEL="HOME" UUID="196972ad-3b13-4bba-ac54-4cb3f7b409a4" TYPE="ext4" PARTUUID="6073277f-87bc-43ff-bcfd-724c4484a63a">/dev/block/8:3</device>

next time if you ask for LABEL=HOME the answer will be /dev/block/8:3
rather than /dev/sda3.

It seems better to canonicalize the paths we store to the cache.

Unfortunately if you ask for /dev/block/8:3 then you probably expect
that blkid_dev_devname() returns the same path. This patch introduces
dev->bid_xname, this is the path used by application (and never stored
in the cache).

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1332779
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-26 12:15:26 +02:00
Karel Zak 14308bc3f2 libblkid: improve debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-25 15:06:22 +02:00
Karel Zak 55ad13c26f libblkid: make I/O errors on CDROMs non-fatal
It seems too tricky to get a real size of the data track on hybrid
disks with audio+data. It seems overkill to analyze all header in
libblkid and on some disks it's probably possible to get I/O error
almost everywhere due to crazy copy protection etc.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-28 13:54:01 +02:00
Karel Zak 6548ac6aa7 Revert "libblkid: check for multi-session CDROMs"
This reverts commit a14cc9a504.

We need a better way (probably analyze track ioctls CDROMREADTOCHDR
and CDROMREADTOCENTRY) to get also proper track size.

The original patch works only if data track is the last track.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-27 18:49:36 +02:00
Karel Zak a14cc9a504 libblkid: check for multi-session CDROMs
.. and read last session if probing offset is not specified.

udev uses cdrom_id to get last session offset, so people don't see a
problem with hybrid media (audio+data), but if you execute blkid on
command line (without -O <offset>) then you get I/O errors.

It seems that we can use the same way as kernel filesystem iso9960
driver when session= mount option is not specified ... just use
CDROMMULTISESSION ioctl to get last session offset and probe this last
session rather than all medium.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-27 14:18:41 +02:00
Karel Zak 1bd62f72d8 libblkid: fix mistake in debug message
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-19 12:45:00 +02:00
Karel Zak bfebe74e3b libblkid: reduce probing area for crazy CDROMs
Linux kernel reports devices greater than area readable by read(2).
The readable area is usually 2-3 CD blocks smaller (CD block is
2048-bytes) than size returned by BLKGETSIZE. This patch checks for
this issues to avoid I/O errors in probing functions.

Reported-by: Thomas Schmitt <scdbackup@gmx.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-19 12:39:05 +02:00
Petr Uzel 445e6b1ec8 libblkid: make blkid_do_wipe() work with probes with offset
When a probe is created with an offset, e.g. via
blkid_probe_set_device(), this offset is correctly used when looking for
the signatures, but is not respected by blkid_do_wipe() function.
Therefore the signature is removed from an invalid location.

Usecase: Wiping signatures from an area on the block device where
partition is to be created (but as it does not exist yet, there's no
device node for it and probe on the whole block device has to be used
with correct offset and length).

Reproducer:
======================== wiper.c ===========================

const char *dev;
unsigned long offset;
unsigned long size;

int main(int argc, char** argv) {

        if (argc != 4) {
                printf("usage: wiper dev offset size\n");
                exit(1);
        }

        dev = argv[1];
        offset = strtoull(argv[2], NULL, 10);
        size = strtoull(argv[3], NULL, 10);

        printf("dev=%s, off=%llu, size=%llu\n", dev, offset, size);

        int fd = open (dev, O_RDWR);
        if (fd == -1) {
                perror("open");
                exit(1);
        }

        blkid_loff_t wipe_offset = offset * SECTOR_SIZE;
        blkid_loff_t wipe_size = size * SECTOR_SIZE;

        int ret;

        blkid_probe pr;
        pr = blkid_new_probe();
        if (!pr)
                return 0;
        ret = blkid_probe_set_device(pr, fd, wipe_offset, wipe_size);
        ret = blkid_probe_enable_superblocks(pr, 1);
        ret = blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC);

        while (blkid_do_probe(pr) == 0) {
                ret = blkid_do_wipe(pr, 0);
        }

        blkid_free_probe(pr);
        close(fd);
}
======================== wiper.c ===========================

Steps to reproduce:
modprobe scsi_debug
parted -s /dev/sdX mklabel gpt
parted -s /dev/sdX mkpart first 2048s 4095s
mkfs.ext2 /dev/sdX1

wipefs -np /dev/sdX1

./wiper /dev/sdX1 2048 2048

Actual result: wiper gets into endless loop, because
blkid_do_wipe() wipes at wrong location (1080), leaving the signature
on /dev/sdc1. So it is again found by blkid_do_probe(), and so on.

Expected result: wiper clears the ext2 signature at offset 1049656(=1080+2048*512).

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2016-04-18 19:53:51 +02:00
Karel Zak e04f386084 libblkid: revert mmap usage
The implementation has not been ready for I/O errors and it seems that
there is no elegant way how to resolve this issue. Linux returns
SIGBUS on mmap errors and play with signals (or longjumps) in shared
library is really bad idea.

It also seems that mmaped devices have some unexpected side-effects
with page-cache where for example dd returns old data for already
modified device etc.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-30 14:53:33 +02:00
Kent Overstreet 7ce27dc517 libblkid: Update for newer bcache superblocks
Later version of bcache add different checksum types, and allow for superblocks
greater than 4k - skipping the checksum check (as in most other probes) is the
easiest solution.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2016-03-23 10:52:38 +01:00
Ruediger Meier 18336d16d9 build-sys: use AC_PROG_MKDIR_P and remove a few gnuisms
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-13 21:48:09 +01:00
Karel Zak 5bb1d22e8a build-sys: fix if..endif for *_la_LDFLAGS
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-10 13:54:15 +01:00
Karel Zak 8f6a58efde misc: avoid shadowing
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-09 12:00:52 +01:00
Karel Zak 3fe3f560b7 Revert "include sysmacros.h where used"
This reverts commit 46a40c0184.
2016-03-08 14:26:33 +01:00
Mike Frysinger 46a40c0184 include sysmacros.h where used
BSD/Linux systems stick major/minor/makedev in sysmacros.h.  Newer Linux
libraries have been moving away from including sysmacros.h implicitly via
sys/types.h, so include it directly.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-03-08 14:21:55 +01:00
Ruediger Meier fea1cbf748 misc: never cast void* from malloc(3) and friends
Such cast could hide serious compiler warnings in case we are
missing includes (e.g. <stdlib.h> or "xalloc.h").

See
http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 23:29:27 +01:00
Ruediger Meier fdbd7bb940 misc: again fixing many printf format strings
This is again a huge patch regarding printf format strings to
fix compiler warnings seen on clang/OSX.

I'm trying to follow these rules strictly:

 #type      #format   #cast
 uintmax_t   %ju      -
 intmax_t    %jd      -
 uint64_t    PRIu64   -
 int64_t     PRId64   -
 size_t      %zu      -
 ssize_t     %zd      -
 ino_t       %ju      (uintmax_t)
 off_t       %jd      (intmax_t)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 23:16:04 +01:00
Ruediger Meier 2208b3ccb2 lib: remove openat fallback functions (include/at.h)
I have validated that we are still compatible at least back to
  - openSUSE 11.4
  - SLE 11
  - RHEL/CentOS 6
  - OSX 10.10.x, (Xcode 6.3)
  - FreeBSD 10.2

Confirmed incompatibility:
  - OSX 10.9.x, (Xcode 6.2)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 15:33:56 +01:00
Ruediger Meier 4d751c008e lib: provide fallback if mkostemp(3) missing
It's missing on OSX.

CC: Yuriy M. Kaminskiy <yumkam@gmail.com>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-29 13:05:18 +01:00
Ruediger Meier b9710f1f08 misc: fix compiler warnungs (unsigned/signed)
These ones should be fixed:
libblkid/src/probe.c:393:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/probe.c:907:25: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libblkid/src/probe.c:1221:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:540:47: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:1043:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:1056:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:1057:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:1061:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:1199:27: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libblkid/src/partitions/partitions.c:1410:26: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libblkid/src/partitions/partitions.c:1431:25: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libblkid/src/superblocks/linux_raid.c:151:8: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
libblkid/src/superblocks/linux_raid.c:155:2: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
libblkid/src/superblocks/superblocks.c:375:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/superblocks/xfs.c:141:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libsmartcols/src/table.c:333:24: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libsmartcols/src/table.c:344:25: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libsmartcols/src/table_print.c:753:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/ask.c:364:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/utils.c:33:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/context.c:435:56: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/context.c:730:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/script.c:557:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/dos.c:1791:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/gpt.c:813:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
disk-utils/partx.c:140:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
disk-utils/partx.c:551:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
disk-utils/partx.c:640:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 03:18:27 +01:00
Ruediger Meier 71177ab8f9 misc: fix warnings "unused parameter" [-Wunused-parameter]
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 03:18:24 +01:00
Ruediger Meier 5fde1d9f06 tests: fix compiler warnings [-Wmissing-prototypes]
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 03:18:09 +01:00
Ruediger Meier b55b9fccf6 libblkid: fix compiler warnings [-Wmissing-prototypes]
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 01:25:07 +01:00
Ruediger Meier b0b54cc582 build-sys: always add AM_CFLAGS
We were missing our nice compliler warnings for many programs
and libs. See next commits how many trivial and non-trival
warnings have to be fixed.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 01:17:29 +01:00
Ruediger Meier b201f1d86c build-sys: always use global LDADD
This was a major showstopper when building on a system where
LTLIBINTL libs are needed (e.g. OSX). Maybe there are a few test
programs which wouldn't need LDADD ... never mind.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 01:16:58 +01:00
Ruediger Meier a8d4e707e2 libblkid: don't include endian.h
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 16:54:35 +01:00
Ruediger Meier 3719bf8de9 build-sys: check linker support for version scripts
The macro AX_CHECK_VSCRIPT was taken from gnu autoconf archive.
http://www.gnu.org/software/autoconf-archive/

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 12:53:48 +01:00
Ruediger Meier 3fd1f7711e docs: fix typos found by codespell
Using "codespell" from https://github.com/lucasdemarchi/codespell

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-03 15:10:08 +01:00
Boris Egorov 0cd7ecefc5 libblkid: check limits before indexing array [cppcheck]
[libblkid/src/encode.c:165]: (style) Array index 'i' is used before limits check.
2016-01-19 12:59:12 +06:00
Boris Egorov fef0063119 libblkid,libmount: Do not use void* in calculations [cppcheck]
[libblkid/src/superblocks/zfs.c:179]: (portability) 'label' is of type 'const void *'. When using void pointers in calculations, the behaviour is undefined.
[libblkid/src/superblocks/zfs.c:237]: (portability) 'label' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[libblkid/src/topology/topology.c:221]: (portability) 'chn.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[libmount/src/fs.c:153]: (portability) 'old' is of type 'const void *'. When using void pointers in calculations, the behaviour is undefined.
[libmount/src/fs.c:154]: (portability) 'new' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
2016-01-19 12:59:12 +06:00
Boris Egorov 18b76be61c libblkid: (zfs) add cast to fix UB [cppcheck]
[libblkid/src/superblocks/zfs.c:173]: (error) Shifting 32-bit value by 56 bits is undefined behaviour
[libblkid/src/superblocks/zfs.c:173]: (error) Shifting 32-bit value by 40 bits is undefined behaviour
2016-01-19 11:41:37 +06:00
Karel Zak 7675d69d01 libblkid: make minix prober more robust
It seems that the current minix probing code is not robust enough and
it returns false positive for Fedora f24 install images. The crazy thing
is that the image pass also all Linux kernel minix_fill_super() checks
and mount(2) fails later when it tries to read filesystem root
directory.

The fsck.minix requires sb->s_log_zone_size to be zero (Linux kernel
does not care about it), let's use the same requirement for libblkid.

Note, it would be possible to check minix root directory inode in
libblkid, but this solution requires minix prober specific seek &
read. We want to avoid extra read operations...

References: https://bugzilla.redhat.com/show_bug.cgi?id=1299255
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-18 14:47:40 +01:00
Karel Zak f12cd8d1e9 libblkid: use internally uint64_t for offsets and sizes
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-12 18:42:10 +01:00
Karel Zak 28a2df8dc0 libblkid: fix buffers mapping on 32bit archs
Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-12-03 12:24:22 +01:00
Karel Zak 710dd49239 blkid: don't mark zfs as RAID
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-11-18 11:55:35 +01:00
Karel Zak 4546fd398f Revert "libblkid: support LSI RAID on partition too"
This reverts commit bc9007c372.

We need a better way, it seems that the original report is mostly
about udev rules disadvantages than about libblkid bug. See RH
bugzilla (#1172510) for more details.
2015-10-15 12:04:35 +02:00
Karel Zak d5b7d2912a libblkid: make XFS Log visible for wipefs
Reported-by: Peter Rajnoha <prajnoha@redhat.com>
Signed-off-by: root <root@ws.net.home>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-10-13 12:02:17 +02:00
Karel Zak bc9007c372 libblkid: support LSI RAID on partition too
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1172510
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-10-13 10:55:47 +02:00
Karel Zak 2355dd6a49 libblkid: add read() based fallback for char (UBI) devs
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-24 11:10:09 +02:00
Karel Zak a674a0ab03 libblkid: use mmap() rather than read()
diff between
	perf stat -e 'syscalls:sys_enter_*'
for old and new version:

-                35      syscalls:sys_enter_lseek
-                38      syscalls:sys_enter_read
+                 3      syscalls:sys_enter_read
...
-                19      syscalls:sys_enter_mmap
+                17      syscalls:sys_enter_mmap

-       0.001083084 seconds time elapsed
+       0.000751722 seconds time elapsed

The patch dramatically reduces malloc()+seek()+read() operations in
libblkid. The code mmaps ~2MiB of the begin and the end of the device
and it moves buffers management to kernel.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-24 11:10:09 +02:00
Karel Zak 9325a8be9e libblkid: (zfs) keep bufferes read-only
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-24 11:10:09 +02:00
Karel Zak 6b86ef4a6a libblkid: (promise raid) cleanup code
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-24 11:10:09 +02:00
Karel Zak 7020de0be8 lib/crc32: don't require to modify GPT header
This patch introduces smart crc32 function that is able to exclude
specified. The advantage is that we does not have to modify GPT header
(set the current in-header crc field to zero) when we count crc32.

This allows to keep GPT header in read-only buffers and simplify code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-24 09:26:42 +02:00
Karel Zak 7caa6b37be libblkid: use 'VERSION' rather than 'PERSISTENCE_VERSION'
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-31 13:23:55 +02:00
Karel Zak 7430affdd9 libblkid: (drbdmanage) improve version setting code
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-31 11:49:45 +02:00
Karel Zak 1198e39051 libblkid: (drbdmanage) add magic strings array terminator
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-27 11:07:39 +02:00
Philipp Marek 2dc8cfb9a8 libblkid: added drbdmanage control volume detection.
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-24 11:01:34 +02:00
Karel Zak 2bf68c9334 libblkid: fix inconsistent indenting [smatch scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-05 12:48:54 +02:00
Karel Zak e97c021472 libblkid: remove dead code [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-04 12:31:39 +02:00
Boris Egorov 7508d991c5 libblkid/whereis: simplify some conditions [cppcheck]
[misc-utils/whereis.c:466]: (style) Redundant condition: uflag.
'A && (!A || B)' is equivalent to 'A || B'
[libblkid/src/tag.c:373]: (style) Redundant condition: dev.
'A && (!A || B)' is equivalent to 'A || B'

Signed-off-by: Boris Egorov <egorov@linux.com>
2015-06-25 12:08:50 +02:00
Karel Zak 85ccc1d425 libblkid: (nilfs2) check size for backup superblock only
The size of the device seems irrelevant for the primary superblock.
The primary superblock is stored on fixed offset, possible collision
between last partition and whole-disk is possible only for backup
superblock only.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-09 16:01:16 +02:00
Karel Zak 00817742ce libblkid: (nilfs2) check devise size
Unfortunately, nilfs2 have the same problem like many RAIDs. It uses
the end of the device to store (backup) superblock. The end of the
last partition is the same location as the end of the whole-disk. It
means that the superblock seems valid for the last partitions as well
as for whole-device.

Fortunately, nilfs2 superblock contains size of the device, so we can
distinguish between whole-disk and partition device.

Reported-by: Heinz Diehl <htd+ml@fritha.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-09 10:37:11 +02:00
Karel Zak d5dbd57b22 docs: fix gtk-docs related warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-28 12:28:23 +02:00
Karel Zak 6c62abc42b lib/sysfs: rename devname functions, cleanup
Well, I don't have mental power to use function names like

 sysfs_devname_to_dev_name()

so this patch renames to

 sysfs_devname_sys_to_dev()
 sysfs_devname_dev_to_sys()

It also cleanups usage of the functions. We have to be sure that
sysfs.c code returns regular devnames. The existence of the sysfs
devnames (with '!') should be completely hidden in sysfs specific
code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-28 12:09:41 +02:00
Stanislav Brabec d0dc6c17c5 Fix /sys to /dev node name translation
linux/drivers/base/core.c: device_get_devnode() defines a translation of
'!' in sysfs nodes to '/' in /dev nodes. The same translation has to be
done to properly support device nodes with slash (e. g. device nodes of
cciss driver and several other drivers).

Introduce new helper sysfs_devname_to_devno() and use it where
appropriate.

Fixes for example lsblk -f on devices using cciss driver.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2015-05-26 11:42:38 +02:00
Sami Kerola cf92286084 libblkid: fix compiler warnings
warning: extra ';' outside of a function [-Wextra-semi]

warning: embedding a directive within macro arguments has undefined
behavior [-Wembedded-directive]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-03-16 23:43:24 +00:00
Karel Zak 0487bcb1a3 libblkid: fix compiler warning [-Wunused-variable]
libblkid/src/superblocks/zfs.c: In function 'probe_zfs':
libblkid/src/superblocks/zfs.c:199:11: warning: unused variable 'swab_magic' [-Wunused-variable]

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-06 10:57:12 +01:00
Michal Humpula e44a4c7ac9 zfs: make less syscalls 2015-02-28 21:19:42 +01:00
Michal Humpula 5dd705ba65 blkid: make zfs detection more robust
Try to use all the possible uberblock locations.
2015-02-25 20:25:07 +01:00
Karel Zak af17d349fc libblkid: cleanup names, don't copy probing results
* cleanup function and variable names (s/vals/values/)
* in "safe probe" mode libblkid copies probing result from the first
  attempt, this is unnecessary, with values list we can just move
  values to another list rather than copy all.
* add new debug messages

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-24 10:24:15 +01:00
Ondrej Oprala 6c4a7811f8 libblkid: make probing data structures more dynamic
* replace static probing result array with list
* use allocated buffers for probing result variables

[kzak@redhat.com: - rename some functions
                  - clean up \0 terminator usage in variables
                  - remove never used code to convert UUID to lower-case
                  - remove possible memory leaks on errors]

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-24 10:22:37 +01:00
Karel Zak 703bf3535d libblkid: set SBMAGIC for nilfs2
Reported-by: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-19 11:33:39 +01:00
Karel Zak 6a7857d247 libblkid: (hfs) avoid overflow [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-28 15:02:41 +01:00
Karel Zak d655ceac78 libblkid: fix macro redefinition [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-28 14:57:53 +01:00
Karel Zak aaa0ba88b4 libblkid: improve MBR vs. FAT + boot sector detection
It seems that some systems are able to produce boot sector + MBR with
almost valid FAT superblock. The libblkid already checks for FAT magic
string, media, correct sector and dir size, etc. -- but all this is
not enough.

The patch add to FAT prober also MBR detection to make sure that there
is no MBR with usable first partition. All this is enabled for
whole-disk devices only.

first sector (and this is no FAT baby ;-)

$ hexdump -C -n 512 /dev/nbd0
00000000  eb 58 90 4d 53 44 4f 53  35 2e 30 00 02 10 16 10  |.X.MSDOS5.0.....|
00000010  02 00 00 00 00 f8 00 00  3f 00 ff 00 00 00 00 00  |........?.......|
00000020  00 00 40 01 f5 27 00 00  00 00 00 00 02 00 00 00  |..@..'..........|
00000030  01 00 06 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000040  80 01 29 c5 a3 06 1a 4e  4f 20 4e 41 4d 45 20 20  |..)....NO NAME  |
00000050  20 20 46 41 54 33 32 20  20 20 33 c9 8e d1 bc f4  |  FAT32   3.....|
00000060  7b 8e c1 8e d9 bd 00 7c  88 56 40 88 4e 02 8a 56  |{......|.V@.N..V|
00000070  40 b4 41 bb aa 55 cd 13  72 10 81 fb 55 aa 75 0a  |@.A..U..r...U.u.|
00000080  f6 c1 01 74 05 fe 46 02  eb 2d 8a 56 40 b4 08 cd  |...t..F..-.V@...|
00000090  13 73 05 b9 ff ff 8a f1  66 0f b6 c6 40 66 0f b6  |.s......f...@f..|
000000a0  d1 80 e2 3f f7 e2 86 cd  c0 ed 06 41 66 0f b7 c9  |...?.......Af...|
000000b0  66 f7 e1 66 89 46 f8 83  7e 16 00 75 39 83 7e 2a  |f..f.F..~..u9.~*|
000000c0  00 77 33 66 8b 46 1c 66  83 c0 0c bb 00 80 b9 01  |.w3f.F.f........|
000000d0  00 e8 2c 00 e9 a8 03 a1  f8 7d 80 c4 7c 8b f0 ac  |..,......}..|...|
000000e0  84 c0 74 17 3c ff 74 09  b4 0e bb 07 00 cd 10 eb  |..t.<.t.........|
000000f0  ee a1 fa 7d eb e4 a1 7d  80 eb df 98 cd 16 cd 19  |...}...}........|
00000100  66 60 80 7e 02 00 0f 84  20 00 66 6a 00 66 50 06  |f`.~.... .fj.fP.|
00000110  53 66 68 10 00 01 00 b4  42 8a 56 40 8b f4 cd 13  |Sfh.....B.V@....|
00000120  66 58 66 58 66 58 66 58  eb 33 66 3b 46 f8 72 03  |fXfXfXfX.3f;F.r.|
00000130  f9 eb 2a 66 33 d2 66 0f  b7 4e 18 66 f7 f1 fe c2  |..*f3.f..N.f....|
00000140  8a ca 66 8b d0 66 c1 ea  10 f7 76 1a 86 d6 8a 56  |..f..f....v....V|
00000150  40 8a e8 c0 e4 06 0a cc  b8 01 02 cd 13 66 61 0f  |@............fa.|
00000160  82 74 ff 81 c3 00 02 66  40 49 75 94 c3 42 4f 4f  |.t.....f@Iu..BOO|
00000170  54 4d 47 52 20 20 20 20  00 00 00 00 00 00 00 00  |TMGR    ........|
00000180  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001a0  00 00 00 00 00 00 00 00  00 00 00 00 0d 0a 44 69  |..............Di|
000001b0  73 6b 20 65 72 72 6f 72  ff 0d 0a 50 72 65 00 00  |sk error...Pre..|
000001c0  01 01 0c 3f e0 ff 00 08  00 00 00 f8 3f 01 00 00  |...?........?...|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|

MBR:
$ hexdump -C -s 446 -n $((512 - 446)) /dev/nbd0
000001be  00 00 01 01 0c 3f e0 ff  00 08 00 00 00 f8 3f 01  |.....?........?.|
000001ce  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001fe  55 aa                                             |U.|

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1182831
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-27 13:09:27 +01:00
Karel Zak 861b11d5e2 libblkid: (bcache) fix keys usage
References: http://bugs.debian.org/775374
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-15 11:58:08 +01:00
Karel Zak 325165d0c3 libblkid: fix compiler warnings [-Wpointer-sign]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-13 13:40:25 +01:00
Karel Zak 3d9644f30d Merge branch '2015wk01' of https://github.com/kerolasa/lelux-utiliteetit
* '2015wk01' of https://github.com/kerolasa/lelux-utiliteetit:
  eject: add verbosity to cdrom door lock error
  libblkid: assume strtoull() is available
  ipcs: remove FIXME markup
  ul: remove unexplained TERM=lpr override
  look: remove dead code
  docs: make tools/checkmans.sh to pass without warnings
  build-sys: fix make checkincludes warnings
  docs: add howto-pull-request.txt
  docs: small improvements to howto-contribute.txt

Conflicts:
	Documentation/howto-pull-request.txt
2015-01-08 14:53:01 +01:00
Sami Kerola 9385a11d8d libblkid: assume strtoull() is available
The strtoull() is part of ISO/IEC 9899:1999 (aka C99) and the function
has been happily used in prlimit(1) since 2011-10-19 without anyone
complaining compatibility issues.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/strtoul.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-01-07 22:05:43 +00:00
Pali Rohár 2f2730bc77 libblkid: udf: Fix reading LABEL, add support for UUID and other udf identifiers 2014-12-15 18:28:42 +01:00
Pali Rohár 1e9d4d4ab6 libblkid: superblocks: Add function blkid_probe_set_utf8_id_label for setting utf8 id label 2014-12-15 16:31:18 +01:00
Sebastian Krahmer 109df14fad libblkid: fix potential bufer overflows
While digging deeper into libblk probing, I found that some
computations might wrap and allocate too few buffer space which then
overflows. In particular on 32bit systems (chromebook) where size_t is
32bit, this is problematic (for 64bit the result fits into the calloc
size_t).

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-12-05 11:37:05 +01:00
Karel Zak 89e90ae7b2 libblkid: care about unsafe chars in cache
The high-level libblkid API uses /run/blkid/blkid.tab cache to
store probing results. The cache format is

   <device NAME="value" ...>devname</device>

and unfortunately the cache code does not escape quotation marks:

   # mkfs.ext4 -L 'AAA"BBB'

   # cat /run/blkid/blkid.tab
   ...
   <device ... LABEL="AAA"BBB" ...>/dev/sdb1</device>

such string is later incorrectly parsed and blkid(8) returns
nonsenses. And for use-cases like

   # eval $(blkid -o export /dev/sdb1)

it's also insecure.

Note that mount, udevd and blkid -p are based on low-level libblkid
API, it bypass the cache and directly read data from the devices.

The current udevd upstream does not depend on blkid(8) output at all,
it's directly linked with the library and all unsafe chars are encoded by
\x<hex> notation.

   # mkfs.ext4 -L 'X"`/tmp/foo` "' /dev/sdb1
   # udevadm info --export-db | grep LABEL
   ...
   E: ID_FS_LABEL=X__/tmp/foo___
   E: ID_FS_LABEL_ENC=X\x22\x60\x2ftmp\x2ffoo\x60\x20\x22

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-27 13:39:35 +01:00
Karel Zak adc9f78cfc build-sys: cleanup library symbol files
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-20 14:01:03 +01:00
Boris Egorov ad1ac445da libblkid: (nilfs) fix typo
Signed-off-by: Boris Egorov <egorov@linux.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-13 15:10:22 +01:00
Karel Zak b7da851e5a libblkid: clean up debug, add "help" debug mask
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-03 13:12:20 +01:00