Commit Graph

105 Commits

Author SHA1 Message Date
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
Benno Schulenberg b50945d4ac textual: spell and encode the name of Arkadiusz Miśkiewicz correctly
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-02-06 11:15:02 +01:00
Benno Schulenberg 4e0968018b textual: tiny tweaks of some error messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-01-30 15:23:49 +01:00
Benno Schulenberg ff21848c64 mkswap: properly pluralize the bad-pages message
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-01-30 15:23:45 +01:00
Benno Schulenberg 8c219bf463 textual: gettextize several overlooked messages
Also improve the clarity of some of them.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-01-25 11:47:29 +01:00
Karel Zak f3b1628642 mkswap: fix compiler warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-20 20:00:11 +01:00
Milan Broz c1f1b30171 mkswap: wipe old signature if there is no part table by default
Historically mkswap avoids wiping any signature on "whole disk",
until force option is given.

While the idea is that it should not wipe possible boot loader,
in reality it leads to many situations where e.g. LUKS device
is overwritten but still can be detected as LUKS (but unusable).

Patch chnges behaviour that only if partition table is detected,
signatures are not wiped.

Also it removes check for block device - loop device can now
map partitions in-kernel, so using mkswap on disk image in file
should behave the same as on disk.

Also it adds warning that know signature was wiped.

Signed-off-by: Milan Broz <mbroz@redhat.com>
2012-09-21 12:43:33 +02:00
Sami Kerola d5ac5df359 mkswap: fix shadow declaration
disk-utils/mkswap.c:366:57: warning: declaration of 'is_blkdev' shadows a global declaration [-Wshadow]
./include/blkdev.h:92:5: warning: shadowed declaration is here [-Wshadow]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-26 11:09:31 +02:00
Karel Zak 33fb5cfd49 disk-utils: cleanup strtoxx_or_err()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-15 17:43:32 +02:00
Petr Uzel e12c9866b5 include: rename writeall.h to all-io.h
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-15 11:32:27 +02:00
Petr Uzel dceb1f220c mkswap: improve diagnostics message if the device is mounted
Currently, attempt to create swap on mounted partition results
with "/dev/sdXy: Device or resource busy" message being printed.
Change this to explicitly telling the user that the device is mounted.

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-15 11:19:53 +02:00
Petr Uzel 95e1d8f3ba mkswap: allow creating swap on /dev/hd[ab]
Currently, mkswap does not allow swap to be created on /dev/hda and
/dev/hdb. There is no reason why /dev/hda and /dev/hdb should be treated
differently.

Addresses: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=491021
Cc: Russell Coker <russell@coker.com.au>
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-15 11:19:53 +02:00
Petr Uzel def478cf72 mkswap: use is_mounted() instead of check_mount()
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-15 11:19:52 +02:00
Sami Kerola 45ca68ece7 disk-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 20:04:39 +02:00
Karel Zak c596a05450 mkswap: check blkid_probe_lookup_values() return [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-31 13:10:58 +01:00
Karel Zak 9206b23863 test: refresh build-sys tests
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-17 15:35:10 +01:00
Karel Zak 979f1dd5fe mkswap: wipe all old signatures
mkswap(8) zaps the begin of the device (1024 bytes) only. This is not
enough, because for example ReiserFS superblock is outside this area.

This patch add blkid_do_wipe() call to mkswap(8) and all block device
is scanned and all signature are removed.

Reported-by: Martin Pitt <martin.pitt@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-11-11 13:33:51 +01:00
maximilian attems 086752639d mkswap: Use c.h
Fixes mkswap compilation against klibc.

Signed-off-by: maximilian attems <max@stro.at>
2011-08-02 13:58:54 +02:00
Davidlohr Bueso 95fa64da98 mkswap: add alignment check
This patch produces the program to warn if the given device is misaligned.

[kzak@redhat.com: - call the check for block devices only]

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-04-12 13:13:28 +02:00
Karel Zak 64d15476c0 build-sys: don't use HAVE_LIBBLKID_INTERNAL macro
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-16 17:45:53 +01:00
Karel Zak 7ee96990c0 build-sys: include <uuid.h> rather than <uuid/uuid.h>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-16 17:04:21 +01:00
Karel Zak 6c7d5ae9a2 move struct option to .rodata
It does not make sense to have writable large arrays of "struct
option" on the stack.

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-03 15:00:30 +01:00
Karel Zak 8d1b0fe28e mkswap: fix compiler warning
mkswap.c: In function ‘main’:
mkswap.c:646:6: warning: too few arguments for format

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-02-21 16:22:52 +01:00
Sami Kerola f2704664ba mkswap: coding style unification
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-02-21 16:13:51 +01:00
Sami Kerola 4c60c667c4 mkswap: fix to compiler warnings
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-02-21 16:12:49 +01:00
Sami Kerola a4d3e778ab mkswap: use EXIT_ values
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-02-21 16:12:48 +01:00
Sami Kerola e079c4e6ed mkswap: support long options and check user inputs
[kzak@redhat-com: - mimor changes to usage()]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-02-21 16:02:00 +01:00
Sami Kerola 94a50e285a mkswap: use xalloc
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-02-21 15:29:49 +01:00
Sami Kerola 00a7d0d2f0 mkswap: use libc error messaging facilities
[kzak@redhat.com: - use "%s from %s" for -V output]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-02-21 15:27:52 +01:00
Davidlohr Bueso 8abcf29002 lib: [strutils] general purpose string handling functions
This patch replaces a few functions used throughout the source:
* Renames getnum (from schedutils) to strtol_or_err
* Moves strtosize (from lib/strtosize.c)
* Moves xstrncpy (from include/xstrncpy.h)
* Adds strnlen, strnchr and strndup if not available (remove it from libmount utils)

A few Makefile.am files were modified to compile accordingly along with trivial renaming
in schedutils source code.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2010-11-23 21:06:49 +01:00
Karel Zak 5d757a9fde remove free() from atexit() callbacks
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-10-29 13:29:28 +02:00
Karel Zak 630161f271 mkswap: don't use too small user-specified page size
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=601552
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-17 10:57:47 +02:00
Karel Zak 3e16599a34 mkswap: use calloc(), remove obsolete v1 header usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-17 10:29:33 +02:00