Commit Graph

137 Commits

Author SHA1 Message Date
Karel Zak b105446e69 mkswap: remove deprecated SELinux matchpathcon()
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 14:58:43 +01:00
Karel Zak ca27216aa6 build-sys: remove fallback for security_context_t
It seems like overkill to provide this #ifdef. For example coreutils
use "char *" for all selinux contexts (since 2014).

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 13:12:19 +01:00
Sami Kerola 8d6877239c
mkswap: tell how to fix insecure permissions and owner in warning
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-28 09:53:13 +00:00
Karel Zak ca6fcc1a89 mkswap: don't use deprecated security_context_t
libselinux >= 3.1 makes security_context_t type deprecated. Let's
ifdef it to avoid unwanted warnings.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-14 15:54:08 +01:00
Karel Zak 701f0385a0 mkswap: add --verbose, reduce extents check output
We do not need to provide details in the default output. It seems
better to hide it behind --verbose to be user-friendly.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-10 12:54:14 +02:00
Karel Zak e270d980ca mkswap: cleanup usage()
- don't use one string for all --help output
- use USAGE_* macros

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-10 11:26:18 +02:00
Karel Zak 199cd674ad mkswap: remove unnecessary on FS_IOC_FIEMAP
This is something user cannot fix and extents check is nothing critical.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-09 15:50:39 +02:00
Karel Zak 29b68b9c7b mkswap: improve extents check
- remove unknown extent type (kernel does not care about it too)
- fix last_logical use in messages
- improve warning for DELALLOC extents
- check for hole at the end of the file

Reported-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-09 15:41:56 +02:00
Karel Zak 195025c29e mkswap: check for holes and unwanted extentd in file
Let's make mkswap(8) more user-friend and report possible swapon
issues already when user initialize a swap file. The extents check
produces warnings, no exit with error.

  # dd if=/dev/zero of=img count=100 bs=1MiB
  # chmod 0600 img

  # fallocate --dig-hole --offset 64520192 --length 1MiB img
  # fallocate --dig-hole --offset 84520960 --length 1MiB img

  # ./mkswap img
  mkswap: extents check failed:
    - hole detected at offset 64520192 (size 1048576 bytes)
    - hole detected at offset 84520960 (size 1048576 bytes)
  file img can be rejected by kernel on swap activation.

  Setting up swapspace version 1, size = 100 MiB (104853504 bytes)
  no label, UUID=92091112-26b5-47aa-a02a-592e52528319

It checks for holes in the file, and for unknown, inline, shared and
deallocated extents.

Addresses: https://github.com/karelzak/util-linux/issues/1120
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-09 11:10:51 +02:00
Karel Zak b8671fe763 mkswap: add --lock and LOCK_BLOCK_DEVICE
Addresses: https://github.com/karelzak/util-linux/issues/921
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-05-27 16:59:16 +02:00
Karel Zak a6a24f18e6 mkswap: cast before lseek [lgtm scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-20 15:47:55 +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
Noel Cragg 4850e97257 mkswap: fix page size warning message
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-11-29 11:38:41 +01:00
Karel Zak f11157e804 mkswap: fix compiler warnings [-Wcast-qual]
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-23 11:43:30 +02:00
Philip Prindeville b443c1779e misc: replace magic number 37 with UUID_STR_LEN
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2017-09-05 11:49:21 +02: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 b305445495 misc: consolidate all --help option descriptions
Now we are always using the same text also for commands
which had still hardcoded descriptions or where we can't
use the standard print_usage_help_options macro.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:28:36 +02:00
Ruediger Meier 6e1eda6f22 misc: never use usage(stderr)
Here we fix all cases where we have usage(FILE*)
functions.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Karel Zak d2f265d629 mkswap: use memcpy() for non-terminated string [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:27:59 +02:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +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
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
Lubomir Rintel d97dc0ee25 mkswap: tolerate ENOTSUP when failing to relabel
It might be that the underlying filesystem just doesn't support SELinux
labeling. This fixes creating swap on vfat live media:

  # livecd-iso-to-disk.sh --msdos --swap-size-mb 666 ...

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
2016-04-18 10:51:28 +02:00
Ruediger Meier fea1cbf748 misc: never cast void* from malloc(3) and friends
Such cast could hide serious compiler warnings in case we are
missing includes (e.g. <stdlib.h> or "xalloc.h").

See
http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 23:29:27 +01:00
Ruediger Meier fdbd7bb940 misc: again fixing many printf format strings
This is again a huge patch regarding printf format strings to
fix compiler warnings seen on clang/OSX.

I'm trying to follow these rules strictly:

 #type      #format   #cast
 uintmax_t   %ju      -
 intmax_t    %jd      -
 uint64_t    PRIu64   -
 int64_t     PRId64   -
 size_t      %zu      -
 ssize_t     %zd      -
 ino_t       %ju      (uintmax_t)
 off_t       %jd      (intmax_t)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 23:16:04 +01:00
Ruediger Meier f3e0213aa4 include: remove unused mntent.h
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 16:54:23 +01:00
Wayne R. Roth cc706d9f09 mkswap: add warnings for insecure device permissions/owners
Logic modified from sys-utils/swapon.c

Signed-off-by: Wayne R. Roth <wayneroth42@gmail.com>
2016-01-26 11:26:00 +01:00
Sami Kerola 80c320fac1
mkswap: fix block device open race
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-22 20:56:38 +00:00
Benno Schulenberg fc14ceba5e textual: grammarize and harmonize the stat error message
The message "stat failed %s" seems to say that stat() failed to
do something, or failed to pass a test, but of course it means
that the statting of something failed.  So say so.  Also make
two very similar messages equal to this one.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-02-02 11:27:10 +01:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
This adds a concise description of a tool to its usage text.

A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:27:38 +01:00
Sami Kerola acec6eec4e mkswap: remove memory leaks [LeakSanitizer] [valgrind]
==18922==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x49d12b in __interceptor_malloc (/home/src/util-linux/.libs/lt-mkswap+0x49d12b)
    #1 0x7faf2a5069c9 in __GI___strdup (/usr/lib/libc.so.6+0x819c9)
    #2 0xffff96e7e33 (<unknown module>)

SUMMARY: AddressSanitizer: 8 byte(s) leaked in 1 allocation(s).

And another one that valgrind found.

==6316== 8 bytes in 1 blocks are definitely lost in loss record 1 of 1
==6316==    at 0x4C29F90: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6316==    by 0x5E3F9C9: strdup (in /usr/lib/libc-2.20.so)
==6316==    by 0x43A25F: size_to_human_string (strutils.c:495)
==6316==    by 0x42B35C: main (mkswap.c:488)

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-11-18 12:56:46 +01:00
Karel Zak 9a83b03c73 mkswap: make final report more human readable
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-07 14:03:35 +01:00
Karel Zak 3ba01c145c mkswap: device write code refactoring
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-07 13:55:37 +01:00
Karel Zak fabf29f4fe mkswap: device open code refactoring
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-07 13:46:42 +01:00
Karel Zak 99f78758aa mkswap: always use header from control struct
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-07 13:35:50 +01:00
Karel Zak 8591859cd7 mkswap: coding style improvements
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-07 13:25:11 +01:00
Sami Kerola d68f402c54 mkswap: various minor improvement
Use correct data type in page_bad(), and add information to error message
how many bad pages were seen.

In check_blocks() move initialization to variable introduction, fix typo,
and avoid memset() when array initializer can do the job.

In main() use correct initializer for pointer.  Move swap file specific
actions to same location, and add warning when request too --check is
dismissed by command.  At the end remove momory leak.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-11-07 13:21:06 +01:00
Sami Kerola 076ba5a696 mkswap: set variable only when it's value is known
Avoid updating ctl->pagesize twice when user does specify page size.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-11-07 13:21:06 +01:00
Sami Kerola 6af1822752 mkswap: make remaining functions to take control structure as argument
The wipe_device() and new_prober().

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-11-07 13:21:06 +01:00
Sami Kerola de3822c39c mkswap: add struct mkswap_control to remove global variables
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-11-07 13:21:06 +01:00
Sami Kerola 3d5c8ba1c9 mkswap: use err() rather than perror() && exit()
The messsages in err() are verified from po/util-linux.pot to be already
part of translations.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-11-07 13:21:05 +01:00
Sami Kerola c181617cfb mkswap: remove unnecessary size check
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-11-07 13:21:05 +01:00
Sami Kerola a1466ab2b2 mkswap: remove system architecture specific max swap size checks
Since kernel version 2.3.4 (June 1999) all architectures has used
uint32_t as maximum number or pages in a swap device or file, there is no
longer need to support systems earlier than that.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-11-07 13:21:05 +01:00
Karel Zak 62acb047a6 build-sys: remove obsolete wholedisk.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-17 12:16:29 +02:00
Sami Kerola 24f83f7392 swapon, swapheader, mkswap: move swap signature to header
Both swapon and mkswap need to know what is valid device signature, so
share the value.

[kzak@redhat.com: - use SWAP_SIGNATURE_SZ properly in write_signature()]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-05-06 10:16:54 +02:00
Sami Kerola 506b499991 mkswap: remove legacy swap structure
If software archeolgists want to know how the old, and unused, swap
header looked they can dig it from the revision history.

[kzak@redhat.com: - use sizeof() for SWAP_HEADER_SIZE]

Reference: 4c85aa3a4c
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-05-06 10:08:51 +02:00
Sami Kerola 8a101b1447 mkswap, swaplabel: move version number to header
Corrently only the swap version 1 is supported, which is a magic value so
move it to header.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-05-04 11:42:03 +01:00
Sami Kerola 793a05f840 mkswap: remove unnecessary usage output
The usage output changes too often making unnecessarily expected output
in test unstable.  Besides in this case the usage ouput does not even
help user, because invalid swap target size error cannot be fixed by
specificing an option.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-03-12 12:06:33 +01:00
Karel Zak a0b42dc369 mkswap: fix compiler warning [-Wunused-variable]
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-17 15:01:49 +01:00
Sami Kerola 833b7e0d80 mkswap: unify write check to a file descriptor
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-26 13:26:07 +02:00