Commit Graph

111 Commits

Author SHA1 Message Date
Karel Zak 72ab706502 blkid: add another UDF identifiers
Reported-by: Pali Rohár <pali.rohar@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-11 10:02:22 +01:00
Karel Zak 150394604d blkid: encode all udf and iso IDs in udev output
We encode to "safe" strings almost all variables for 'blkid -o udev'
and we need it also for SYSTEM_ID, PUBLISHER_ID, APPLICATION_ID,
BOOT_SYSTEM_ID and recently added VOLUME_SET_ID and DATA_PREPARER_ID.

This change makes blkid from util-linux more compatible with built-in
udevd blkid.

Addresses: https://github.com/karelzak/util-linux/pull/1215 (commit 5cbffdb74f)
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-10 12:10:06 +01:00
Karel Zak ac3a0fd92e blkid: add --hint <name>=value
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-03 17:15:34 +01:00
Karel Zak f1970cc557 docs: improve size arguments description in --help output
Let's add "Arguments:" section to the --help output and describe
{K,M,G...}iB suffixes there.

Addresses: https://github.com/karelzak/util-linux/pull/917
Co-Author: ed <ed@s5h.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-05 11:01:36 +01:00
Karel Zak dc30fd4383 libblkid: check for medium on CDMROMs probing
The commit 39f5af2598 introduces
O_NONBLOCK to avoid the tray close on open(). The side effect is that
open() is successful when there is no medium.

This is usually no problem for standard tools because the next read()
will fail. Unfortunately, libblkid ignores I/O errors for (and only
for) CDROMs to support some crazy hybrid data+audio disks. The final
result is many I/O errors in system log when O_NONBLOCK is enabled.

This patch add CDROM_DRIVE_STATUS to stop probing when there is no
disk or when the tray is open.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1787973
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-07 16:48:34 +01:00
Michal Suchanek 39f5af2598 libblkid: open device in nonblock mode.
When autoclose is set (kernel default but many distributions reverse the
setting) opening a CD-rom device causes the tray to close.

The function of blkid is to report the current state of the device and
not to change it. Hence it should use O_NONBLOCK when opening the
device to avoid closing a CD-rom tray.

blkid is used liberally in scripts so it can potentially interfere with
the user operating the CD-rom hardware.

[kzak@redhat.com: add O_NONBLOCK also to:
                  - wipefs
                  - blkid_new_probe_from_filename()
                  - blkid_evaluate_tag()]

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-11-06 09:55:49 +01:00
Karel Zak fa1b64da96 blkid: improve strcpy() usage [coverity scan]
The old deprecated list output format ("-o list") copies gettex string
into fixed buffer, that's really bad idea.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-16 13:56:34 +02:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Karel Zak 68224d108d include/c: add print_version() macro
Let's consolidate the version printing code. It also seems better to
use exit() after --version, because it's handled in different way by
ASAN.

It's strange, but ASAN reports leaks after return in main(). Note that
we do not use free-before-exit.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 13:47:17 +02:00
Karel Zak 0ab0817917 blkid: fix usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-11-29 13:30:11 +01:00
Karel Zak 5e91d5dd71 blkid: make PART_ENTRY_* tags optional (add --no-part-details)
blkid(8) returns information from partition table also for empty
partitions. This is necessary for example for udev, but it could be
confusing if you care about on-device content only.

Default:
 # blkid -p /dev/md0p1; echo $?
 /dev/md0p1: PART_ENTRY_SCHEME="dos" PART_ENTRY_UUID="6d8796b1-01" PART_ENTRY_TYPE="0x83" PART_ENTRY_NUMBER="1" PART_ENTRY_OFFSET="2048" PART_ENTRY_SIZE="204800" PART_ENTRY_DISK="9:0"
 0

With --no-part-details:
 # blkid -p /dev/md0p1 --no-part-details; echo $?
 2

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1653413
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-11-29 13:21:36 +01:00
Karel Zak e736434bc8 blkid: fix compiler warnings [-Wcast-qual]
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-23 12:30:37 +02:00
Pali Rohár 0d2e8ff94d blkid: Encode any field which starts with LABEL in same way as LABEL field
This applies also for LABEL_FATBOOT which contains bytes according to DOS
code page and therefore does not contain valid UTF-8 sequence.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2017-11-25 12:48:32 +01:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
changed in include/c.h and applied via sed:

  sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
  sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 16:54:33 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +02:00
Ruediger Meier fa2cd89aca misc: cosmetics, remove argument from usage(int)
This patch is trivial and changes nothing, because
we were always using usage(0).

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Karel Zak dfdb1ca818 Merge branch 'fix-exit-codes' of https://github.com/rudimeier/util-linux
* 'fix-exit-codes' of https://github.com/rudimeier/util-linux:
  misc: fix optutils.h related exit codes
  misc: fix xalloc.h related exit codes
  misc: fix more strutils related exit codes
  lib: fix strutils.h, remove STRTOXX_EXIT_CODE
  misc: fix some broken exit codes
2017-06-26 13:47:04 +02:00
Ruediger Meier 778ca2a0d4 misc: fix xalloc.h related exit codes
Found by:

grep -L "XALLOC_EXIT_CODE" $(grep -l "xalloc\.h" \
    $(git grep -l "_EX_\|FINDFS_\|BLKID_EXIT\|EX_USAGE" -- "*.c"))

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 22:40:27 +02:00
Ruediger Meier 9c8b9fbacc lib: fix strutils.h, remove STRTOXX_EXIT_CODE
As discussed on the mailing list. We fix all places
where the non-working define STRTOXX_EXIT_CODE was used.

Regarding tunelp, also see 7e3c80a7.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 22:40:12 +02:00
Ruediger Meier 3b7693cada blkid: use errtryhelp instead of errtryh
We have a --help option and this is preferred.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 21:34:40 +02:00
Karel Zak b1f1fe3dff Merge branch '2017wk16' of git://github.com/kerolasa/lelux-utiliteetit
* '2017wk16' of git://github.com/kerolasa/lelux-utiliteetit:
  chfn, chsh: use readline(3) to receive user input
  findfs: use getopt_long() to parse options
  logger: make month names, login name, and tag read-only objects
  sulogin: reduce vulnerability surface
  partx: add --list-types option
  libblkid: add blkid_partitions_get_name()
  docs: try to convince open(2) O_DIRECT rather than using raw device
  blkid: add long options
  lsipc: fix options parsing and sync with man page
2017-05-09 11:58:23 +02:00
Alexey Gladkov dc46610bf5 blkid: fix return code when display the version
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
2017-05-05 12:22:09 +02:00
Sami Kerola 15a74f755a
blkid: add long options
This change attempts to make tab completion more reasonable by alloging
memorizable option names.  That also has positive impact to manual page, in
which referrals to other options are now easier to understand.

All short options are kept exactly as they were to avoid ABI breakage.  The
only exception is -f option that getopt(3) recognized, but was not found
from anywhere else.  The -f has been part of blkid since the initial commit.

Commit: 51410fc6de
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-02 23:22:04 +01:00
Karel Zak 071147ab89 blkid: fix compiler warning [-Wdiscarded-qualifiers]
Let's also hide the show[] array in has_item().

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-24 12:07:17 +01:00
Sami Kerola 59b94cc0c5
blkid: add control struct
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-17 21:22:26 +00:00
Sami Kerola 93bdbe1993
blkid: simplify version option handling
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-17 21:22:26 +00:00
Sami Kerola f5a2b07e8c blkid: add messages to translations
Without obvious reason blkid has managed to be part of this project for
pretty long time without getting translations.  Lets change that.  In same
go use the usual error printing facilities instead of fprintf(stderr, ...);

[kzak@redhat.com: - use errtryh(),
                  - cleanup "unsupported output format"]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-13 15:34:18 +01:00
Sami Kerola 126d8cf35b blkid: add curly braces to do-while statement
Some say people read do-while statements are easily as while statements and
get wrong impression.  This happens because do-whiles are not common.
Adding braces should make it easier to read the code.

Reference: http://www.spinics.net/lists/linux-kernel-janitors/msg02018.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-13 15:24:57 +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
Yuri Chornoivan a7349ee315 docs: Fix word repetitions 2017-02-13 14:10:12 +01:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
The current default is to print all usage() output. This is overkill
in many case.

Addresses: https://github.com/karelzak/util-linux/issues/338
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 13:13:34 +01:00
Karel Zak 090d8c763a include/closestream: define exit codes
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-16 13:35:06 +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
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
Boris Egorov 43b4f7ea5f lib/tty: Pass default width to get_terminal_width()
Almost any code calling get_terminal_width() checks returned width for
non-positive values and sets it to some default value (say, 80). So,
let's pass this default value directly to the function.

[kzak@redhat.com: - get_terminal_width() refactoring]

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-06 12:22:07 +01:00
Sami Kerola 67791b7787 blkid, uuidd, uuidgen: assume getopt.h and getopt.h are available
These headers are in use allover this project without issues.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-10-09 11:17:09 +02:00
Karel Zak f8098e2b2c blkid: don't ignore info about partitions on non-formated devices
# blkid -p /dev/sdc1; echo $?
 2

but libblkid provides information about partition, fixed version:

 # blkid -p /dev/sdc1; echo $?
 /dev/sdc1: PART_ENTRY_SCHEME="dos" PART_ENTRY_UUID="4c1e518c-01" PART_ENTRY_TYPE="0x83" PART_ENTRY_NUMBER="1" PART_ENTRY_OFFSET="2048" PART_ENTRY_SIZE="1021952" PART_ENTRY_DISK="8:32"
 0

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-21 12:14:55 +02: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 16714abef2 blkid: remove extra trailing spaces in output
$  blkid | egrep -i 'sda.*label' | cat -A
/dev/sda2: UUID="8382f307-fb43-489f-ab38-8d4cf37ca88c" SEC_TYPE="ext2" TYPE="ext3" LABEL="test" $
/dev/sda5: UUID="0b46d673-8c23-4709-b92c-3fdf460e1dd4" TYPE="ext3" LABEL="rescue" SEC_TYPE="ext2" $
/dev/sda6: UUID="cb9d814f-d885-435b-8e6d-ac17c0ac5aa1" TYPE="ext3" LABEL="root" $
/dev/sda8: UUID="1e2851bd-cc6f-4d72-bf9f-c6fa754155b1" TYPE="ext3" LABEL="data" SEC_TYPE="ext2" $
/dev/sda9: UUID="d16a2f42-9a50-4489-a788-8624c832a7f3" TYPE="ext3" LABEL="storage" SEC_TYPE="ext2" $
/dev/sda7: TYPE="swap" LABEL="swap" UUID="8393acfa-d4bd-40fc-8eb9-5ccd8d85e103" $

Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=586179
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-23 14:43:31 +02:00
Karel Zak 293eef71ea Revert "blkid: remove unused variable"
This reverts commit 0fd4b81325.
2014-05-13 09:55:10 +02:00
Sami Kerola 0fd4b81325 blkid: remove unused variable
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-05-12 13:07:04 +02:00
Phillip Susi 856ee0ba61 blkid: simple typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-08 10:12:17 +01:00
Karel Zak 1c9885cde8 blkid: escape quotes in the output
# e2label /dev/loop0 'La"bel'
 # blkid -p /dev/loop0
 /dev/loop0: LABEL="La"bel"  ....

new version:

 /dev/loop0: LABEL="La\"bel" ....

Reported-by: Phillip Susi <psusi@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-07 14:10:26 +01:00
Karel Zak 834eca4e91 blkid: export ID_PART_TABLE_UUID
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-06-13 14:36:02 +02:00
Karel Zak 08af448f5c blkid: fix typo in ID_FS_AMBIVALEN=
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-14 15:03:30 +02:00
Sami Kerola d0ed8dc2b9 blkid, hwclock, ldattach: use program_invocation_short_name
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-26 13:25:57 +02:00
Karel Zak 5d00280cdb blkid: use xalloc everywhere
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-10 17:30:34 +02:00
Karel Zak 3b1346a877 blkid: use O_CLOEXEC
... to make "strace -e open blkid" for libblkid stuff without
exceptions.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-03 16:14:47 +02:00
Sami Kerola fe20e5d14a blkid: use xalloc.h when possible
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-03-26 10:53:28 +01:00
Benno Schulenberg a9b2c52f77 blkid: also accept -V for displaying version information
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-03-20 14:08:03 +01:00