Commit Graph

1750 Commits

Author SHA1 Message Date
Karel Zak df0836dc90 wipefs: fix compiler warning
misc-utils/wipefs.c: In function ‘main’:
misc-utils/wipefs.c:838:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
misc-utils/wipefs.c:838:3: note: use option -std=c99 or -std=gnu99 to compile your code

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-20 09:20:54 +01:00
Karel Zak 8399fe089b lsblk: fix filesystem array allocation
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-19 14:59:01 +01:00
Roberto Bergantinos Corpas ff21f476f8 findmnt: add option to list all fs-independent flags
It might be useful for security auditing purposes list all possible
mount flags/options including default set which are normally not listed.

This patch adds "--vfs-all" option to list all fs-independent flags
on VFS-OPTIONS column, as well as libmount funcionality to accomplish
it.

i.e.:

$ findmnt -o VFS-OPTIONS
VFS-OPTIONS
rw,relatime
rw,nosuid,nodev,noexec,relatime
rw,nosuid,nodev,noexec,relatime
ro,nosuid,nodev,noexec
...

$ findmnt --vfs-all -o VFS-OPTIONS
VFS-OPTIONS
rw,exec,suid,dev,async,loud,nomand,atime,noiversion,diratime,relatime,nostrictatime,nolazytime,symfollow
rw,noexec,nosuid,nodev,async,loud,nomand,atime,noiversion,diratime,relatime,nostrictatime,nolazytime,symfollow
rw,noexec,nosuid,nodev,async,loud,nomand,atime,noiversion,diratime,relatime,nostrictatime,nolazytime,symfollow
ro,noexec,nosuid,nodev,async,loud,nomand,atime,noiversion,diratime,norelatime,nostrictatime,nolazytime,symfollow
...

[kzak@redhat.com: - cleanup coding style and comments]

Signed-off-by: Roberto Bergantinos Corpas <rbergant@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-15 17:51:07 +01:00
Karel Zak 3c9d13da63 lsblk: use MOUNTTARGETS in default output
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-11 10:46:16 +01:00
Karel Zak 62df539554 lsblk: use MOUNTPOINTS in --fs
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-08 13:45:14 +01:00
Karel Zak 37da403d57 lsblk: add FSROOTS column
It displays filesystem root attached to system, for example
btrfs with two mounted subvolumes:

	$ lsblk -oNAME,SIZE,MOUNTPOINTS,FSROOTS /dev/sdc1
	NAME SIZE MOUNTPOINTS FSROOTS
	sdc1  50M /mnt/A      /foo
		  /mnt/B      /bar

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-08 13:33:30 +01:00
Karel Zak c6648d2db1 lsblk: print all device mountpoints
* add libmount FS to struct lsblk_device

* add new column MOUNTPOINTS (pl.) with multi-line cells to display
  all mountpoints relevant for the device

* the old MOUNTPOINT is backwardly compatible and it (usually) displays the
  last device mountpoint from /proc/self/mountinfo

For example btrfs with more subvolumes:

 $ lsblk -o+MOUNTPOINTS /dev/sdc1
 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT MOUNTPOINTS
 sdc1   8:33   0  50M  0 part /mnt/test  /mnt/A
                                         /mnt/test
                                         /mnt/B

Note, in this case MOUNTPOINT displays mount point where is mounted
root of the filesystem.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-08 13:20:50 +01:00
Karel Zak e7091237db Merge branch 'getopt-musl' of https://github.com/sgn/util-linux
* 'getopt-musl' of https://github.com/sgn/util-linux:
  getopt: explicitly ask for POSIX mode on POSIXLY_CORRECT
2021-01-07 12:09:57 +01:00
Đoàn Trần Công Danh 27fd7278a1 getopt: explicitly ask for POSIX mode on POSIXLY_CORRECT
GNU libc's getopt_long(3) have the tradition of not shuffling arguments
to find options when either POSIXLY_CORRECT is defined in environment
variables or '+' prepended in short options. Hence, the current code
base is fine as is fine as is for util-linux built with GNU libc.

However, musl libc only honour POSIX convention when short options
prepended with '+'. musl libc doesn't care about POSIXLY_CORRECT.
Thus, the behaviour of util-linux's getopt(1) that linked with musl-libc
doesn't match with its own documentation.

Let's make sure a '+' is always prepended to short options if
POSIXLY_CORRECT is defined.

Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
2021-01-06 20:57:57 +07:00
Karel Zak 4b447adf50 Merge branch '2020wk47' of https://github.com/kerolasa/util-linux
* '2020wk47' of https://github.com/kerolasa/util-linux:
  build-sys: sort various lists in configure.ac
  mkswap: tell how to fix insecure permissions and owner in warning
  lsipc: make default output byte sizes to be in human units
  man: add missing backslash to caret printing macro
  lscpu: fix variable shadowing
  uuidgen: give hint in usage() what uuid namepaces can be used
  uuidgen: use errx() rather than fprintf() when priting errors
  libuuid: simplify uuid_is_null() check
  uuidparse: use uuid type definitions from libuuid header
  uuidparse: use libuuid function to test nil uuid
2021-01-05 15:20:50 +01:00
Sami Kerola e69cb8b91d
uuidgen: give hint in usage() what uuid namepaces can be used
Also fix --help and --version alignment.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-28 09:53:12 +00:00
Sami Kerola 451d0e9e7b
uuidgen: use errx() rather than fprintf() when priting errors
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-28 09:53:12 +00:00
Sami Kerola ab85f756a0
uuidparse: use uuid type definitions from libuuid header
While on it add missing UUID_TYPE_DCE_NIL to the header.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-28 09:53:12 +00:00
Sami Kerola facafe2edb
uuidparse: use libuuid function to test nil uuid
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-28 09:53:08 +00:00
Ville Skyttä 3c56068609 *: spelling and grammar fixes 2020-12-17 23:39:05 +02:00
Karel Zak 1492fb4ef2 lsblk: read SCSI_IDENT_SERIAL also from udev
Addresses: https://github.com/karelzak/util-linux/issues/1143
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-14 11:38:04 +01:00
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 58b510e580 libsmartcols: sanitize variable names on export output
The shells are very restrictive about variable names, only [:alnum:]
chars are allowed (and alphabetic chars as the first char).  The
library will replace "bad" chars with "_". The char '%' at the end is
replaced by _PCT.

Addresses: https://github.com/karelzak/util-linux/issues/1201
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-03 12:14:10 +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
Karel Zak 665d79e793 Merge remote-tracking branch 'sami/uuidd-work'
* sami/uuidd-work:
  uuidd: fix misleading indentation
  uuidd: make timeout to take effect when debug is not defined
  uuidd: remove unnecessary bulk request size limit
  uuidd: add uuidd specific data types that are used in protocol
  uuidd: reorder bulk time and random generation code
  uuidd: document uuidd protocol
  uuidd: override operation type when performing bulk request
  uuidd: move option parsing to separate function
  uuidd: add command-line option values struct
  uuidd: use pid_t type when referring to process id
2020-11-24 13:12:22 +01:00
Karel Zak 7ffd3b0ef6 build-sys: do not use extra subdir for getopt examples
This is unnecessary, we have ${docsdir}/util-linux which is good
enough for these two getopt examples. I guess the "getopt"
subdirectory is legacy from time getopt has been merged into
util-linux.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-24 12:46:03 +01:00
Karel Zak 94ebe1d3e4 lsblk: add dependence between CD/DVD block and packet devices
This dependence is defined by

  $ cat /sys/class/pktcdvd/device_map
  pktcdvd0 252:0 11:0

Unfortunately, there is not any direct sysfs way how to refer this
relationship in /sys/{block,dev/block}. So, we have to read the
device_map file and then compare device numbers with the list.

$ lsblk /dev/sr0
NAME       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0         11:0    1 1024M  0 rom
└─pktcdvd0 252:0    1    0B  0 disk

Addresses: https://github.com/karelzak/util-linux/issues/1185
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-24 10:44:46 +01:00
Sami Kerola ef6ac59689
uuidd: fix misleading indentation
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 22:48:08 +00:00
Sami Kerola f187035d73
uuidd: make timeout to take effect when debug is not defined
The trailing comma made code to compile without issues, but meant all_done()
was called only when --debug was in defined in command-line.

Fixes: 3d6250e96b
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 22:48:08 +00:00
Sami Kerola 0453925535
uuidd: remove unnecessary bulk request size limit
Limiting random query to 1000 uuid's was pointless when the next line will
further restrict upper limit to 63 entries.  The 63 entries is what fits to
the uuidd communication buffer with the header.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 22:48:07 +00:00
Sami Kerola b491161819
uuidd: add uuidd specific data types that are used in protocol
Use a typedef for types that are sensitive what comes to uuidd protocol
field widths, read write sizes, and related checks.

Proposed-by: Karel Zak <kzak@redhat.com>
Reference: https://github.com/karelzak/util-linux/pull/1196#discussion_r528595794
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 22:48:07 +00:00
Sami Kerola ea9416925c
uuidd: reorder bulk time and random generation code
Write the data and response length values in same close to order they appear
in protocol.  This should make code a little easier to read.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 22:47:13 +00:00
Sami Kerola 2049075a79
uuidd: document uuidd protocol
Seeing what can be expected should make it easier to understand what the
code does.

Notice that simply writing down the resposes one can start wondering deeper
questions, such as, why does the time bulk response reply only one uuid
followed by number how many were requested?  Was that a some type of TODO
note?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 22:33:33 +00:00
Sami Kerola 77a54655bb
uuidd: override operation type when performing bulk request
Relying to single vs bulk requests to be exactly two steps away from each
other was an unnecessary dirty trick.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 21:34:40 +00:00
Sami Kerola 084efcee43
uuidd: move option parsing to separate function
Moving the option parsing to a separate function will allow moving some
variables from main() heap to be in scope that free them later.  That should
make the uuidd to have a little bit smaller runtime memory allocation.

The static long options is changed to be local variable.  That should make
it to be part of heap for a bit, until removed.  Earlier the variable was in
data segment and permanently in runtime memory.  Whether this makes any
impact either way is not entirely clear, but hope is the runtime memory
allocation is tiny bit smaller.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 21:34:40 +00:00
Sami Kerola b03ffec18c
uuidd: add command-line option values struct
The struct will help seeing where the variable values are coming from.  This
will also help upcoming refactoring.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 21:34:40 +00:00
Sami Kerola c14e0f6239
uuidd: use pid_t type when referring to process id
Earlier use of a variable that holds switch enabling boolean to hold process
id was a little bit strange, and not exactly correct.  An int should be good
enough to hold any pid, but it is better to be precise and use the type that
is meant for the job.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 21:34:39 +00:00
Sami Kerola 3ea54b843c
man: make tilde and caret characters to render correctly
As mentioned in 'Generating optimal glyphs' title in the manual page
mentioned in reference:

    Where a proper caret (^) that renders well in both a terminal and PDF is
    required, use "\(ha".

    Using a naked "~" character results in a poor rendering in PDF.  Instead
    use "\(ti".

Reference: https://man7.org/linux/man-pages/man7/man-pages.7.html#STYLE_GUIDE
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-14 15:22:34 +00:00
Karel Zak e577bea10e wipefs: (man) add hint to erase on partitions and disk
Addresses: https://github.com/karelzak/util-linux/issues/1177
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-09 12:54:18 +01:00
Karel Zak de9cbcdcef Merge branch 'whereis' of https://github.com/ferivoz/util-linux
* 'whereis' of https://github.com/ferivoz/util-linux:
  whereis: extend test case
  whereis: filter bin, man and src differently
  whereis: do not strip suffixes
  whereis: do not ignore trailing numbers
  whereis: add --disable-whereis to configure
  whereis: add lib32 directories
  whereis: support zst compressed man pages
  whereis: fix out of boundary read
2020-11-06 09:44:52 +01:00
Samanta Navarro 653f672ab6 whereis: filter bin, man and src differently
Consider "s." prefixes for source code files only (even though I do not
know which VCS does that), compression suffixes for manual pages and
strict matching for executables.

Calling "whereis python3" is kind of okay to return python3.8 next to
python3, but python3.8-config is not the same tool as python3.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro 117ddbeedc whereis: do not strip suffixes
The whereis implementations of FreeBSD, macOS, NetBSD, and OpenBSD do
not strip suffixes. Although whereis is not a POSIX tool and has no
shared standard, even its manual page indicates that the supplied names
are command names.

Commands do not have a suffix on Linux systems.

Stripping suffixes actually leads to issues with tools like fsck.ext4,
since fsck.ext4 is not the same tool as fsck and definitely not the same
tool as fsck.minix.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro d95ee9fd75 whereis: do not ignore trailing numbers
The commands diff and diff3 are so distinct that their manual pages
should not be mixed in whereis output.

Theoretically this works for commands and binaries with links to each
other, e.g. gpg and gpg2, but if gpg is version 1 and gpg2 is version 2
then manual pages do not match either.

Also the while loop does not decrement "i" while incrementing "dp". The
effect of this is that the output of whereis depends on manual pages
being compressed or not.

The easiest solution is to not ignore trailing numbers.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro 74b7c01fa6 whereis: add lib32 directories
These directories are sometimes used by Linux distributions.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro 6065250a4d whereis: support zst compressed man pages
Add zst as extension for manual pages. Current version of man-db
supports zst extension out of the box.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro cd4142f7c3 whereis: fix out of boundary read
If whereis encounters a short file name then an out of boundary
read can occur.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro bd0f347f86 misc: fix typos
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:42:28 +00: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 1ab5f9b705 docs: rename to getopt-example
Addresses: 27114b2974 (commitcomment-43591002)
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-03 15:23:03 +01:00
Sami Kerola 364de8f4f5 lib/randutils: rename random_get_bytes()
Rename random_get_bytes() to avoid colliding a Solaris library function that
has the same name.

Reported-by: Sad Clouds <cryintothebluesky@gmail.com>
Reference: https://lore.kernel.org/util-linux/20201101141608.ba365cf67d92ee3973226de9@gmail.com/
Reference: https://blogs.oracle.com/solaris/solaris-random-number-generation-v2
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-03 12:38:45 +01:00
Karel Zak 07c8462fb7 cal: do not use putp(), directly use stdio functions
It seems our putp() based output is not portable as some ncurses
implementations strictly follow POSIX where putp() accepts only
terminfo capability strings and nothing else.

We already use standard stdio.h functions to output terminfo strings
(e.g.  for colors). It seems we can do the same for cal(1) to
highlight the current day.

Note that mix putp() and fputs() is bad idea due to different
buffering ways in some cases (see cal.c git log for more details).

This patch also reduces complexity of the code as we can directly
output to stdout without snprintf to string.

Addresses: https://github.com/karelzak/util-linux/pull/1167
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-21 10:19:26 +02:00
Sami Kerola dab057ebd2 hardlink: fix hardlink pcre leak
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-16 11:25:11 +02:00
Karel Zak a83bea2d3d bash-completion: (lsblk) update columns
and fix lsblk --help output

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-12 13:19:35 +02:00
Karel Zak 7636d906ef lsblk: add --width option
Addresses: https://github.com/karelzak/util-linux/issues/1160
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-12 12:19:48 +02:00