Commit Graph

81 Commits

Author SHA1 Message Date
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
Benno Schulenberg 217615e8ed textual: standardize reporting of program name plus package version
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-01-25 11:47:29 +01:00
Karel Zak dd5c22a679 blkid: fix double free [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-12 20:48:15 +01:00
Sami Kerola f5ee44b17a blkid: fix shadow declaration
misc-utils/blkid.c:402:15: warning: declaration of 'usage' shadows a global declaration [-Wshadow]
misc-utils/blkid.c:63:13: warning: shadowed declaration is here [-Wshadow]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-26 11:10:02 +02:00
Karel Zak a8e458b971 blkid: use err_exclusive_options()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-26 09:23:58 +02:00
Sami Kerola 72b99fc53b blkid: use exclusive_option()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-17 17:59:59 +02:00
Sami Kerola 41420120a8 blkid: fix realloc memory leak [cppcheck]
[misc-utils/blkid.c:367]: (error) Common realloc mistake: 'str' nulled but not freed upon failure

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-11 19:50:35 +02:00
Petr Uzel 078ad9bf06 blkid: stop device probing if error is detected
blkid -p dev1 dev2 [...] now stops upon first error detected and
returns correct value. Previously, if error was detected with dev1,
it continued with dev2 anyways and so the return value corresponded
to the last device only.

Reported-by: Bernhard Voelker <bernhard.voelker@siemens-enterprise.com>
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-23 09:43:51 +02:00
Petr Uzel 1578ddd658 blkid: introduce symbolic names for different blkid exit codes
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-23 09:43:51 +02:00
Petr Uzel a922091df8 blkid: use symbolic exit code
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-23 09:43:50 +02:00
Karel Zak db41a4298f misc-utils: cleanup strtoxx_or_err()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-15 17:44:37 +02:00
Karel Zak 7e9a9af14f include/ttyutils: more robust get_terminal_width()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-15 11:58:20 +02:00
Petr Uzel 597cfec51f blkid: use get_terminal_width() from ttyutils.h
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-15 11:32:56 +02:00
Bernhard Voelker 455fe9a075 Fix typos found by misspellings
The tool misspellings (https://github.com/lyda/misspell-check)
detected several typos. Command used:

  $ git ls-files | grep -v ^po/ | misspellings -f -

* isosize: Fix typo in usage string.
* configure.ac: Fix typo in help string of --enable-most-builds option.
* fdisk: Fix typo in man page.
* libblkid, blkid, mount: Likewise.
* Fix various typos in docs and in source code comments.

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
2012-04-23 13:16:35 +02:00
Sami Kerola c05a80ca63 misc-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 19:56:48 +02:00
Karel Zak 3c2662d565 blkid: use strtosize_or_err()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-30 16:17:36 +02:00
Karel Zak 24d741d88a docs: mark udev and list blkid(8) output formats deprecated
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-26 13:09:27 +02:00
Karel Zak dab3357387 blkid: add DEVNAME= to export output format
Reported-by: Balamurugan Arumugam <barumuga@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-02 14:05:26 +01:00
Karel Zak fec1339f9f blkid: remove dead assigment
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-02 14:33:18 +01:00
Karel Zak 7113ddecf8 blkid: add comment to keep static analysers happy 2012-01-31 21:16:28 +01:00
Karel Zak d75bcac49a blkid: check fd before use [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-31 14:19:27 +01:00
Karel Zak b82590ad46 blkid: move cache to /run on new systems
Why?

 * read-only root

 * /etc is pretty bad place for caches

 * all is usually cached by udev in /dev/disk/by-* and libblkid
   is able to use these symlinks

 * boot persistent cache is attractive for very small subset of
   Linux machines (and they already need extra udev tunning otherwise
   udev will probe all block devices during boot)

 * the default is possible to override in /etc/blkid.conf

The systems without /run directory will not be affected by this
change.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-25 13:20:37 +01:00
Karel Zak 077b15dcaa blkid: remove -w option from man page and usage() output
The option does not have any effect, the original functionality was
removed from e2fsprogs in year 2003 by

 commit	50b380b4d4ab668bad45033e3a8aaf93c7f42844
 git://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git

So.. don't propagate the option to users in year 2012 :-)

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-25 12:34:02 +01:00
Karel Zak 6a2f2f58a4 blkid: print ID_PART_ENTRY_* for small devices
The current optimization for small devices (1.4MiB) is broken. It
checks for partition table, but if nothing is detected then details
(ID_PART_ENTRY_*) about the current partition are not gathered.

The optimization should be enabled for small *whole* disks only.

Reported-by: David Zeuthen <davidz@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-10-21 00:37:06 +02:00
Petr Uzel 960cf5737e misc: use %m in format string instead of %s and strerror(errno)
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2011-09-27 15:46:07 +02:00
Karel Zak 54a00b5c79 blkid: potential null derefence [smatch scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-09-12 16:10:45 +02:00
Karel Zak 2327e2d6d7 blkid: fix typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-16 17:05:12 +02:00
Karel Zak bf0128d631 blkid: indent usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-16 12:12:46 +02:00
Karel Zak 525f3c28cb blkid: fix compiler warnings [-Wunused-parameter]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-01 12:48:55 +02:00
Karel Zak 70db6c7ef4 blkid: list all known filesystems/RAIDs (add -k option)
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-06-20 16:42:03 +02:00
Karel Zak bc867ea388 blkid: don't free() uninitialized variable
blkid.c: In function ‘main’:
blkid.c:656:6: warning: ‘res’ may be used uninitialized in this function [-Wuninitialized]
blkid.c:623:9: note: ‘res’ was declared here

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-06-08 12:16:08 +02:00