Commit Graph

601 Commits

Author SHA1 Message Date
Rafael Fontenelle 0e85613e3a Fix misspellings 2021-09-04 11:11:04 -03:00
Karel Zak 2964fd916f libblkid: (btrfs) add debug messages to zoned support
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-08-03 13:29:16 +02:00
Karel Zak 822324953e libblkid: use snprintf() rather than sprintf() 2021-07-27 13:29:05 +02:00
Pali Rohár c3f10636ef libblkid: vfat: Fix reading FAT32 boot label
FAT32 can be formatted with boot sign 0x28 to indicate that only serial id
is present or with boot sign 0x29 which indicates that both boot label and
serial id is present.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2021-07-05 15:10:51 +02:00
Pali Rohár 575b559254 libblkid: vfat: Fix reading FAT16 boot label and serial id
Older FAT16 variants do not have to contain boot label or serial id. Boot
sign 0x28 indicates that only serial id is present and boot sign 0x29
indicates that both boot label and serial id is present. Other boot sign
values (e.g. zero) indicates older FAT16 variant without boot label and
boot sign.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2021-07-05 15:09:12 +02:00
Karel Zak 0c409b7b54 libblkid: remove EVMS support
"When you discover you're riding a dead horse, the best strategy is to dismount."

EVMS is dead since 2006, LVM is the winner.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-30 11:35:45 +02:00
Karel Zak 0395e8f7d7 libblkid: check errno after strto..()
Addresses: https://github.com/karelzak/util-linux/issues/1356
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-21 15:00:40 +02:00
Karel Zak 17fc8693cd include/c: add drop_permissions(), consolidate UID/GID reset
Fixes: https://github.com/karelzak/util-linux/issues/1354
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-21 12:25:31 +02:00
Karel Zak 66e259c746 libblkid: fix and cleanup blkid_safe_string()
* Don't use 'size_t len' variable for utf8_encoded_valid_unichar()
  return code as it returns negative numbers on invalid utf8 sequence.

* Don't rely only on \0, but check the current position against output
  buffer size.

* Accept hex encoding like the original version.

* Use else-if to avoid unnecessary 'continue'.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-16 10:58:11 +02:00
Karel Zak 6db3685989 libblkid: Optimize the blkid_safe_string() function
Processing whitespace characters. Allows valid ASCII, valid UTF-8.
Replace everything else with '_'

Co-Author: changlianzhi <changlianzhi@uniontech.com>
Signed-off-by: changlianzhi <changlianzhi@uniontech.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-15 10:25:24 +02:00
Karel Zak 60d1f1a329 libblkid: check for ioctl macro rather than for header file
libblkid/src/probe.c:1012:22: error: ‘BLKGETZONESZ’ undeclared (first use in this function)
 1012 |   if (!ioctl(pr->fd, BLKGETZONESZ, &zone_size_sector))
      |                      ^~~~~~~~~~~~

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-09 16:12:13 +02:00
John Baublitz 0842c84218 libblkid: Add hyphens to UUID string representation in Stratis superblock parsing
[kzak@redhat.com: - small code cleanup]

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-09 10:40:31 +02:00
Karel Zak ac55a4130f Merge branch 'next'
* next: (26 commits)
  build-sys: add script to compare config.h from meson and autotools
  meson: add missing header files check
  docs: update TODO
  tests: update lscpu outputs
  lscpu: read MHZ from /sys/.../cpufreq/scaling_cur_freq
  lscpu: use locale-independent strtod() when read from kernel
  lib/c_strtod; add locale independent strtod()
  tests: update lscpu output
  lscpu: use MHZ as number to be locale sensitive
  lscpu: add SCALMHZ% and "CPU scaling MHz:"
  sulogin: fix whitespace error
  sulogin: ignore none-existing console devices
  lsns: fix old error message
  lsns: fix copy & past in man page
  lsns: fill UID and USER columns for interpolated namespaces
  fixup! lsns: interpolate missing namespaces for converting forests to a tree
  lsns: interpolate missing namespaces for converting forests to a tree
  lsns: reorganize members specifying other namespaces in lsns_namespace
  lsns: make namespace having no process printable
  libblkid: support zone reset for wipefs
  ...
2021-06-02 12:33:07 +02:00
Karel Zak 95fbd2db43 libblkid: fix docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-31 18:16:57 +02:00
Karel Zak d58121a22a docs: update copyright years
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-31 18:12:07 +02:00
Naohiro Aota db22115875 libblkid: support zone reset for wipefs
We cannot overwrite superblock magic in a sequential required zone. So,
wipefs cannot work as it is. Instead, this commit implements the wiping by
zone resetting.

Zone resetting must be done only for a sequential write zone. This is
checked by is_conventional().

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
2021-05-24 13:39:53 +02:00
Naohiro Aota 6be38dccae libblkid: add magic and probing for zoned btrfs
This commit adds zone-aware magics and probing functions for zoned btrfs.

The superblock (and its copies) are the only data structure in btrfs with a
fixed location on a device. Since we cannot do overwrites in a sequential
write required zone, we cannot place the superblock in the zone.

Thus, zoned btrfs uses superblock log writing to update superblocks on
sequential write required zones. It uses two zones as a circular buffer to
write updated superblocks. Once the first zone is filled up, start writing
into the second buffer. When both zones are filled up, and before starting
to write to the first zone again, it reset the first zone.

We can determine the position of the latest superblock by reading the write
pointer information from a device. One corner case is when both zones are
full. For this situation, we read out the last superblock of each zone and
compare them to determine which zone is older.

The magics can detect a superblock magic ("_BHRfs_M") at the beginning of
zone #0 or zone #1 to see if it is zoned btrfs. When both zones are filled
up, zoned btrfs resets the first zone to write a new superblock. If btrfs
crashes at the moment, we do not see a superblock at zone #0. Thus, we need
to check not only zone #0 but also zone #1.

It also supports the temporary magic ("!BHRfS_M") in zone #0. Mkfs.btrfs
first writes the temporary superblock to the zone during the mkfs process.
It will survive there until the zones are filled up and reset. So, we also
need to detect this temporary magic.

Finally, this commit extends probe_btrfs() to load the latest superblock
determined by the write pointers.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
2021-05-24 13:39:53 +02:00
Naohiro Aota b250fbbf56 libblkid: implement zone-aware probing
This patch makes libblkid zone-aware. It can probe the magic located at
some offset from the beginning of some specific zone of a device.

This patch introduces some new fields to struct blkid_idmag. They indicate
the magic location is placed related to a zone and the offset in the zone.

Also, this commit introduces `zone_size` to struct blkid_struct_probe. It
stores the size of zones of a device.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
2021-05-24 13:39:53 +02:00
Christian Hesse e08e3d587c fix whitespace issue in ducumentation
This removes trailing whitespaces and fixes minor issues.
2021-05-10 15:53:50 +02:00
Karel Zak d8d54e4bfc build-sys: keep adoc files in dist_noinst_DATA
* rename MANPAGES_EXTRA= to ADOCFILES_COMMON=

* keep track about individual adoc files by dist_noinst_DATA=
  This variable is not effected by automake conditions, so the files
  are always distributed.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-05 13:35:30 +02:00
Karel Zak 751eca28fc libblkid: remove workaround for FAT+MBR on whole-disk
The current libblkid ignores FAT when created on the same whole-disk
device as valid MBR. This restriction is not compatible with many
devices (like USB flash disk) created by Windows or the latest
dosfstools where the first partition is used for entire device and
where is also valid FAT. The filesystem is accessible from partition
as well as from whole-disk device.

The conclusion (between util-linux, dosfstools and udisks) is that
libblkid has to provide all details, not hide anything and the proper
policy (hide/show) has to be implemented by udisks (or so).

CC: Tomáš Bžatek <tbzatek@redhat.com>
CC: Pali Rohár <pali.rohar@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-04-09 14:42:18 +02:00
Karel Zak 53b37016c3 meson: generate man pages from asciidoc
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-04-06 15:32:46 +02:00
Karel Zak 625e9c61e8 build-sys: make man pages location independent
We need to evaluate "include::" directive relatively to project
top-level source directory rather than to the current document
location.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-31 11:50:47 +02:00
Karel Zak 25ce8fb1ed Merge remote-tracking branch 'mariobl/topic/asciidoc'
* mariobl/topic/asciidoc: (71 commits)
  Asciidoc: Update .pot template
  Asciidoc: Reorder example command sequence
  Asciidoc: Update .pot template
  Asciidoc: Better gettext message splitting in nsenter.1.adoc
  Asciidoc: Update .pot template
  Asciidoc: Fix typo and remove invisible spaces which confuse po4a
  Asciidoc: Update .pot template
  Asciidoc: Fix typo
  Asciidoc: Fix artifact from initial import, sixth attempt
  Asciidoc: Update .pot template
  Asciidoc: Fix artifacts from initial import, fifth attempt
  Asciidoc: Fix artifacts from initial import, fourth attempt
  Asciidoc: Update .pot template
  Asciidoc: Fix artifacts from initial import, third attempt
  Asciidoc: Fix artifacts from initial import, second attempt
  Asciidoc: Fix artifacts from initial import
  Asciidoc: Add po4a config file and initial translation template for man pages
  Asciidoc: Small indentation fix in mount.8.adoc
  Asciidoc: Review sys-utils man pages, part 2
  build-sys: fix out-of-tree build
  ...

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-29 15:09:27 +02:00
Karel Zak 4f79d3032e build-sys: split man pages and man page links
The symlinks are generated by asciidoctor and current dist_man_MANS
depends on order (nan page before man link). This solutions is useless
when execute "make -j". The real solution is to keep man pages in
separate variable and use only this variable evaluate what we need to
generate.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-26 11:49:59 +01:00
Mario Blättermann 295b3979d9 Asciidoc: Add Po4a hint to file headers 2021-03-20 16:42:47 +01:00
Karel Zak 308a097968 meson: update sources and dependencies
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-17 15:07:27 +01:00
Zbigniew Jędrzejewski-Szmek 69939195bd meson: implement building of static programs
The whole thing is complicated by the fact that we have two layers
of libraries: e.g. libmount also needs libblkid. If we just tell meson
to make libmount static, this is not enough, because we also need it
to link to a static libblkid. Hence in the case of libs that link to
other libs internally, we need to create a different object with a
a different set of link_with items.

To avoid building the libraries twice, libfdisk and libmount are first
built into an internal "convenience" library, which is then linked into
the static and shared versions as appropriate.
2021-03-17 15:07:27 +01:00
Zbigniew Jędrzejewski-Szmek d4c880d5a4 meson: add second build system
To build: meson build && ninja -C build
To run tests: ninja -C build check
To install for packaging: DESTDIR=/var/tmp/inst ninja -C build install
To install for realz: sudo ninja -C build install

v2:
- Optional items are now based on the 'feature' feature in meson.
  Built libraries which are disabled turn into disabler() objects
  and also poison any executables which link to them.

What is there:
- building of the binaries and libs and the python module
- installation of binaries, libs, python module, localization files,
  man pages, pkgconfig files
- running of tests
- most options to configure build equivalently to the
  ./configure settings

Partially implemented:
- disabling of stuff when things missing. In the C code, the defines
  are all used, so that should be fine. In the build system, some
  files should be skipped, but that is probably not always done properly.
  Getting this right might require some testing of various build option
  combinations to get the details right.

Not implemented:
- static builds of fdisk and other binaries
- things marked with XXX or FIXME
- ???

Differences:
- .la files are not created. They are useless and everybody hates them.
- Requires.private in pkgconfig files are not present in the
  autogenerated .pc file. Not sure if they should be there or not. If
  necessary, they can be added by hand.
- man pages and systemd units are installed by the install target. Not
  sure why 'make install' doesn't do that.
- the split between / and /usr is probably wrong. But it's all pointless
  anyway, so maybe we could simplify things but not implementing it at
  all under meson?
2021-03-17 15:07:27 +01:00
Mario Blättermann 4251413a14 Asciidoc: add missing bugreports section to libblkid and some cleanup 2021-03-16 21:17:50 +01:00
Mario Blättermann b366e6fc6b Asciidoc: Remove already imported *roff man pages 2021-03-16 19:35:37 +01:00
Mario Blättermann 1b73028b89 libblikid.3.adoc: Add missing SYNOPSIS section 2021-03-12 13:34:59 +01:00
Mario Blättermann e2db4d9410 Add asciidoc man pages and some include files 2021-03-11 18:38:46 +01:00
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