Commit Graph

568 Commits

Author SHA1 Message Date
Karel Zak 3d725afab4 libblkid: fix comment block
The command block with /** triggers gtkdoc; don't use it for regular
comments.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 11:00:34 +01:00
Karel Zak a7d5efbb9a libblkid: make gfs2 prober more extendible
The current GFS2 prober hard codes superblock constants, but these
constants are affected by GFS2 development.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1913844
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-11 11:58:16 +01:00
Ville Skyttä 3c56068609 *: spelling and grammar fixes 2020-12-17 23:39:05 +02:00
Pali Rohár 5cbffdb74f libblkid: iso9660: add support for VOLUME_SET_ID and DATA_PREPARER_ID
udf superblock code already sets VOLUME_SET_ID to Volume Set Identifier
from UDF Primary Volume Descriptor.

In iso9660 similar meaning has Volume Set Identifier in ISO9660
Primary (or Supplementary Joliet) Volume Descriptor. Therefore exports it
as VOLUME_SET_ID label.

In ISO9660 Primary (and Supplementary Joliet) Volume Descriptor exists
another member Data Preparer Identifier which is currently not parsed by
iso9660 superblock code.

To have iso9660 superblock code feature complete export also Data Preparer
Identifier as DATA_PREPARER_ID label. UDF does not have equivalent of Data
Preparer Identifier.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-12-10 01:52:18 +01:00
Pali Rohár 18565da827 libblkid: iso9660: parse SYSTEM_ID, PUBLISHER_ID and APPLICATION_ID from Joliet
Joliet may contain UNICODE variant of these identifiers. So prefer UNICODE
variant from Joliet over ASCII variant if Joliet one is available.

Also use same technique as for Label for reconstructing original UNICODE
variants of these identifiers.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-12-10 01:43:46 +01:00
Pali Rohár dab6d75cfc libblkid: iso9660: improve label parsing
Label in Joliet is UNICODE (UTF16BE) but can contain only 16 characters.
Label in PVD is subset of ASCII but can contain up to the 32 characters.
Non-representable characters are stored as replacement character '_'.

Label in Joliet is in most cases trimmed but UNICODE version of label in
PVD. Based on these facts try to reconstruct original label if label in
Joliet is prefix of the label in PVD (ignoring non-representable
characters).

It is possible that label in Joliet and PVD are totally different. In this
case label from Joliet as prior this change.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-12-10 00:21:55 +01:00
Pali Rohár 4bfcb1fc4a libblkid: iso9660: fix parsing images which do not have Primary Volume Descriptor as the first
ECMA 119 (ISO 9660) does not mandate that Primary Volume Descriptor needs
to be the first in Volume Descriptor Set sequence.

Move assignment of labels outside of the for-loop and correctly detects
Primary Volume Descriptor via its type (0x01) at any position in sequence.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-12-09 01:22:28 +01:00
Pali Rohár db66eddf7f libblkid: iso9660: set block size also for High Sierra format
High Sierra format has also block size 2048.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-12-09 01:22:10 +01:00
Pali Rohár 5ff184b5b5 libblkid: iso9660: check that iso->publisher_id and iso->application_id are not file paths
ECMA 119 (ISO 9660) says that if the first byte is set to (5F), the
remaining bytes of this field shall specify an identifier for a file
containing the data. As libblkid does not support reading files from the
filesystem itself it cannot parse fields which starts with 0x5F '_' char.

So for now ignore iso->publisher_id and iso->application_id values which
starts with '_' character.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-12-09 00:36:13 +01:00
Pali Rohár 8d027a2135 libblkid: iso9660: do not check is_str_empty() for iso->system_id and boot->boot_system_id
ECMA 119 (ISO 9660) does not say anything if all bytes are of these fields
are FILLER then fields are not set. It says it for iso->publisher_id and
iso->application_id.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-12-09 00:34:23 +01:00
Gao Xiang 7b2a874e2e libblkid: add erofs filesystem support
Enhanced Read-Only File System (EROFS) has been included in Linux
kernel, many Linux distributions, buildroot and Android AOSP for
a while. Plus, nowadays, it's known that EROFS has been commercially
used by several Android vendors for their system partitions.
util-linux in busybox can also detect it recently.

This patch adds support for detecting EROFS filesystem to libblkid.

Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
2020-12-08 10:34:47 +01:00
Pali Rohár 67c4bf1f24 libblkid: udf: add support for PUBLISHER_ID
iso9660 superblock code already sets PUBLISHER_ID to Publisher Identifier
from ISO9660 Supplementary Volume Descriptor.

In udf field LVInfo1 from Implementation Use Volume Descriptor could
contain information such as Owner Name. More UDF generating tools
(e.g. Solaris's labelit or Linux udftools 2.3+) set this field to person
who creating the filesystem therefore its meaning is similar to ISO9660
Publisher Identifier. So for compatibility with iso9660 superblock code
export this field via PUBLISHER_ID label.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-12-05 20:45:25 +01:00
Pali Rohár f09ceed2b6 libblkid: udf: add support for APPLICATION_ID
iso9660 superblock code already sets APPLICATION_ID to Application
Identifier from ISO9660 Supplementary Volume Descriptor.

In udf similar meaning has Application Identifier from UDF Primary Volume
Descriptor. Therefore exports it as APPLICATION_ID label.

More tools for generating hybrid ISO+UDF images (e.g. genisoimage, mkisofs
or nero) set Application Identifier in UDF Primary Volume Descriptor to
just empty string. But they set Implementation Identifier in UDF Primary
Volume Descriptor to their tool name.

So if Application Identifier is empty then exports Implementation
Identifier as APPLICATION_ID label.

Please note that Application Identifier and Implementation Identifier are
stored in UDF only in ASCII, not UNICODE.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-12-05 20:43:22 +01:00
Pali Rohár d8056b5489 libblkid: udf: check that dstrings are encoded in OSTA Compressed Unicode
dstring structures are in UL_ENCODE_LATIN1/UL_ENCODE_UTF16BE encodings only
when corresponding desc_charset structures are set to the OSTA Compressed
Unicode. So add missing checks.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-12-05 20:39:35 +01:00
nick black 4d8fb3c063
libblkid: fix some typos in function comments 2020-11-26 22:52:20 -05:00
Karel Zak 0e0a3b59da libblkid: initialize magic strings in robust way
It is the worst habit to depend on the order of the members of the
structure ...

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-25 15:45:23 +01:00
Karel Zak c175692050 Merge remote-tracking branch 'pali/multisesssion'
* pali/multisesssion:
  libblkid: udf: add support for unclosed sequential Write-Once media
  libblkid: udf: add support for multisession via session_offset hint
  libblkid: iso9660: add support for multisession via session_offset hint
  libblkid: fix blkid_probe_get_sb() to use hint offset calculation
  libblkid: allow to specify offset defined by hint for blkid_probe_get_idmag()
  libblkid: detect session_offset hint for optical discs
  libblkid: do size correction of optical discs also by last written sector
  libblkid: detect CD/DVD discs in packet writing mode
  libblkid: overwrite existing hint
  libblkid: export blkid_probe_reset_hints()
  blkid: add --hint <name>=value
  libblkid: add blkid_probe_{set,get}_hint()
2020-11-25 14:48:30 +01:00
Pali Rohár 3a9a6036a4 libblkid: drbdmanage: use blkid_probe_strncpy_uuid instead of blkid_probe_set_id_label
Function blkid_probe_strncpy_uuid() is better suitable for setting UUID
than function blkid_probe_set_id_label().

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-11-22 19:44:09 +01:00
Pali Rohár 8e3c0176bd libblkid: udf: add support for unclosed sequential Write-Once media 2020-11-10 23:40:53 +01:00
Pali Rohár 6408acd9e0 libblkid: udf: add support for multisession via session_offset hint
To read multisession UDF disc it is required to probe VSD and AVDP from the
selected session (specified by session_offset) and then read other volume
descriptors from absolute location specified in AVDP, which is in most
cases in previous session.

So it is required for udf detector to be able to read data from any
location of disc and therefore blkid's --offset argument cannot be used to
access multisession optical disc.

Only blkid's --hint session_offset argument can be used to instruct blkid
to read multisession optical disc or disc images correctly.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-11-10 23:40:53 +01:00
Pali Rohár cf2f10bb59 libblkid: iso9660: add support for multisession via session_offset hint
The only required change is to read disc from offset specified by
session_offset instead of beginning of disc (offset 0).

So either blkid's --offset or --hint session_offset argument would work for
correct detection of multisession ISO9660 optical disc or disc image.

Although the ISO9660 specification allows also non-2kB sector sizes,
current blkid implementation has hardcoded ISO9660 sector size to 2kB.
Therefore there is check that session_offset is multiple of 2048.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-11-10 23:40:53 +01:00
Pali Rohár b5c5b42014 libblkid: fix blkid_probe_get_sb() to use hint offset calculation 2020-11-10 23:40:53 +01:00
Pali Rohár 3e31657db5 libblkid: allow to specify offset defined by hint for blkid_probe_get_idmag()
Extends struct blkid_idmag with a new member hoff which specify name of the
hint used for blkid_probe_get_hint() function to retrieve offset to kboff.

blkid_probe_get_idmag() will use supplied hint offset in bytes as a start
position from which the final offsets for magic strings are calculated.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-11-10 23:40:53 +01:00
Pali Rohár 427ea35512 libblkid: detect session_offset hint for optical discs
When offset and session_offset hint are not specified then sets
session_offset hint from CDROMMULTISESSION ioctl which returns start
position of the last session of multisession optical disc.

It is expected that session_offset hint contains position offset in bytes
where starts session of multisession optical disc which should be read.

Filesystems designed for optical discs are expected to use this value when
dealing with multisession optical disc to know where they should start
reading optical disc or image of optical disc.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-11-10 23:40:52 +01:00
Pali Rohár bfd4da5628 libblkid: do size correction of optical discs also by last written sector
Everything after last written sector is undefined.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-11-10 23:21:14 +01:00
Pali Rohár 6b88a410ae libblkid: detect CD/DVD discs in packet writing mode
Packet writing mode for CD and DVD discs is provided by kernel module
pktcdvd.ko which exports block devices /dev/pktcdvd/pktcdvd*.

These block devices do not accept CDROM_DRIVE_STATUS ioctl, therefore
current blkid code does not detect them as BLKID_FL_CDROM_DEV and also
does not do necessary size correction.

Extend detection of CD/DVD discs by additional CDROM_LAST_WRITTEN ioctl
which is accepted also by pktcdvd.ko.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-11-10 23:21:13 +01:00
Samanta Navarro c70b4f2a5b libblkid: limit amount of parsed partitions
The linux kernel does not support more than 256 partitions
(DISK_MAX_PARTS). The atari and mac block devices have no such limits.

Use dos logical partition limit for atari as well (100).
Use the kernel limit for mac (256).

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-10 11:53:16 +00:00
Samanta Navarro 3fbeb9eeb8 libblkid: fix time_t handling
The time_t data type is a signed integer. A signed integer overflow is
not defined in C programming language.

A signed overflow occurs on 32 bit systems with 32 time_t for loop back
devices, e.g. when calling "blkid /dev/loop0". This happens because
bid_time is set to INT_MIN and the diff calculation cannot store the
result in time_t (positive int - INT_MIN > INT_MAX).

This fix changes the code to use an unsigned integer calculation. It
pretty much means that the code works as before, but well defined in C.
Checking diff to be positive protects the code against system setups
with dates before 1970 as well.

The time_t data type on modern Linux systems is 64 bit even for 32 bit
systems. Since long is 32 bit on these systems, long long is a better
data type for 64 bit output.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-10 11:52:45 +00:00
Karel Zak b7bca24476 libblkid: overwrite existing hint
Addresses: https://github.com/karelzak/util-linux/issues/1161
Suggested-by:  Pali Rohár <pali.rohar@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-09 17:11:51 +01:00
Karel Zak 248c239b27 libblkid: export blkid_probe_reset_hints()
* make hints persistent and do not call blkid_probe_reset_hints() in
  blkid_probe_set_device()
* export blkid_probe_reset_hints() by API to keep it completely in
  user's hands

Reported-by: Pali Rohár <pali.rohar@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-09 11:42:58 +01:00
Samanta Navarro 8f22adaaf3 libblkid: allow a lot of mac partitions
If the map count is set to INT_MAX then the for loop does not stop
because its check is never false.

I have not found a correct upper limit. The other partition logics have
a maximum amount (exception is atari.c).

The loop itself wouldn't be endless. If the iteration reaches block 0
then the signature will be wrong. This means that map count = INT_MAX
case would fail even if such a setup would be correct on disk.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-08 11:47:33 +00:00
Samanta Navarro 02162731c1 libblkid: fix memory leak in config parser
Multiple occurrences of CACHE_FILE lead to memory leaks.
Also if last occurrence of CACHE_FILE is empty then cache file is not
set to NULL again.

An example /etc/blkid.conf could be:

CACHE_FILE=/tmp/cache1
CACHE_FILE=/tmp/cache2
CACHE_FILE=

I would expect that CACHE_FILE is empty but actually it is still
/tmp/cache2.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-08 11:47:33 +00:00
Samanta Navarro bd0f347f86 misc: fix typos
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:42:28 +00:00
Samanta Navarro cb77628876 misc: fix typos [codespell]
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:42:25 +00:00
Karel Zak 67719fbbda libblkid: add blkid_probe_{set,get}_hint()
Add new API for additional probing hints (offsets). The idea is that
probing function can optionally use the hint to detect superblock or
partition table if on unusual place where the library does not expects (etc.)

The hints use strings as identifiers (e.g. "last-medium-session") to
make it extendable and prober specific (if necessary). The function
blkid_probe_set_hint() always add a new hint, so you can specify more
offsets with the same (hint) name.

The function blkid_probe_get_hint() is not public. For now it returns
the first hint only.

Addresses: https://github.com/karelzak/util-linux/issues/1161
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-03 17:12:20 +01:00
Sami Kerola 7f9e76b4df fsck, libblkid: fix printf format string issue [coverity scan]
According to coverirty a printf format string contains an unrecognized
format specifier (CWE-628).  Lets avoid glibc extension "%m" that is same
as "%s", strerror(errno).

CID: 360699
CID: 360718
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-16 11:35:16 +02:00
Karel Zak 282ceadc3a libblkid: make Atari more robust
* ignore large disks
* check in-table stored device size
* check bad sectors list
* check partition dimensions against in-table device size

Addresses: https://github.com/karelzak/util-linux/issues/1159
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-13 16:19:20 +02:00
Karel Zak 2cc76d50d7 libblkid: fix Atari prober logic
Addresses: https://github.com/karelzak/util-linux/issues/1159
Addresses: https://github.com/karelzak/util-linux/issues/1116
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-09 13:06:08 +02:00
Karel Zak 8d3f9430c5 libblkid: use /sys to read all block devices
The old implementation uses /proc/partitions where devices are
filtered by kernel (missing devices with ext_range=1 and removable
devices).

The problem with the old implementation is whole-disk heuristic based
on device name, order of devices, etc.

The new implementation use the same code to read also removable
devices.

Addresses: https://github.com/karelzak/util-linux/issues/1151
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-07 13:49:45 +02:00
Karel Zak 4b2e840c11 libblkid: (gpt) accept tiny devices
GPT prober reads 2 first sectors. There is no overhead as we already
read begin of the device for another filesystems (like FAT) and we
have these sectors already in memory.

Addresses: https://github.com/karelzak/util-linux/issues/1147
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-30 13:11:01 +02:00
Karel Zak e913192048 libblkid: improve debug for /proc/partitions
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-30 11:37:09 +02:00
Karel Zak bd64c5a3f1 libblkid: (docs) add missing references
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-22 10:33:44 +02:00
Karel Zak 29e204d117 docs: reword others "allow to"
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-14 14:31:29 +02:00
Michael Kerrisk (man-pages) 4f68c8b179 Manual pages: various: reword "allow(s) to"
The wording "allow(s) to" is not grammatical English. Reword various
pages to use a more correct form such "can be use to" or "allows
the [noun] of".

Aklong the way, fix a few nearby wording errors in some pages.

Signed-off-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
2020-07-14 14:08:54 +02:00
Yuri Chornoivan 311e33afef Fix minor typos 2020-07-09 20:14:32 +03:00
Karel Zak a732e4a1d3 libblkid: remove blkid_llseek()
Let's use libc lseek() everywhere like we use in another tools. It's
year 2020 ...

Addresses: https://github.com/karelzak/util-linux/issues/1083
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-01 15:47:20 +02:00
Karel Zak 487b55db54 libblkid: (docs) document new function
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-06-09 10:51:37 +02:00
Karel Zak b3391f3ac7 libmount: add support for ID=
This patch add support for a new tag. The tag is based on udev block
device ID (see /dev/disk/by-id). The usual use-case is to use
WWN for this purpose, for example

  # mount ID=wwn-0x50026b724b09a1ff /mnt

Note that ID is not strictly defined and udevd generates various IDs
also for HW where WWN is undefined. This is reason why introduce ID=
seems better and more generic than more restrictive WWN=.

Addresses: https://github.com/karelzak/util-linux/issues/1008
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-06-03 16:53:00 +02:00
Karel Zak f8ad710f6c build-sys: add missing LDADD to blkid test
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-05-29 09:54:48 +02:00
Michael Kerrisk (man-pages) a8d0d330cf Manual pages: Standardize on AUTHORS as section title
There is quite some value (in terms of readability and user
expectations) if consistent names are used for the sections
within manual pages. This patch is one of a series to bring
about this consistency.

In the Linux man-pages project, I long ago did away with the
AUTHOR(S) section, but I realize some projects like to keep this.

But, let's make sure that the section is consistently titled
across pages. Currently we have AUTHOR (47) or AUTHORS (41).
Let's standardize on the latter (which is also what is
suggested in man-pages(7)).

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-05-20 12:56:12 +02:00