Commit Graph

137 Commits

Author SHA1 Message Date
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
Karel Zak 8e350e48c1 textual: fix typos
Reported-by: Petr Pisar <petr.pisar@atlas.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-14 18:15:29 +02:00
Karel Zak 1f7a33f135 mkswap: zap bootbits on regular files
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-04-02 12:49:07 +02:00
Karel Zak 7771431278 mkswap: move write_all() to include/writeall.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-04-01 16:17:17 +02:00
Yann Droneaud 11ba4182e6 mkswap: fixed strtoll() usage
- catch empty string
- check against LLONG_MAX and LLONG_MIN instead of ULLONG_MAX and 0

Signed-off-by: Yann Droneaud <yann@droneaud.fr>
2010-03-30 20:15:24 +02:00
Karel Zak 20543e618a mkswap: more robust strtoull() usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-03-30 14:45:37 +02:00
Karel Zak 6f3c7f5cfd mkswap: don't call blkdev_find_size()
.. it's already called by blkdev_get_size().

Signed-off-by: Karel Zak <kzak@redhat.com>
2010-03-11 01:08:45 +01:00
Karel Zak 1a70e0cba2 build-sys: add HAVE_LIBBLKID_INTERNAL
It's better to use one macro for all situations where we depends on
in-tree (internal) libblkid.

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-10-27 12:11:37 +01:00
Guillem Jover cef0ccd580 Remove now unused <sys/ioctl.h> includes
Those became unused with the switch to the blkdev functions.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2009-10-09 15:17:54 +02:00
Karel Zak 566f35bc81 mkswap: use libblkid to detect PT
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-09-29 13:30:36 +02:00
Karel Zak 3216beb062 mkswap: fix memory leaks, cleanup check_blocks()
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-09-07 08:59:27 +02:00
Peter De Wachter adda7f7ecd mkswap: unbreak -c ("check") option.
In the check_blocks() loop, current_page is not incremented. Because of this
bug, the loop does not end when the end of the device is reached.  Instead it
tries to continue reading, which of course fails, and eventually mkswap aborts
("too many bad pages").

Note that this can only be tested with swap partitions, mkswap ignores the -c
option for swap files.

Signed-off-by: Peter De Wachter <pdewacht@gmail.com>
2009-09-07 08:49:19 +02:00
Karel Zak 8c0dc0719d build-sys: fix headers in mkswap and libblkid
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-05-22 10:06:15 +02:00
Karel Zak ff3bed8068 mkswap: zap bootbits
/dev/sdb1 originally initialized by cryptsetup:

and OLD mkswap:

        # vol_id /dev/sdb1 | grep TYPE
        ID_FS_TYPE=swap

        # blkid -s TYPE /dev/sdb1
        /dev/sdb1: TYPE="crypt_LUKS"

So, we have two different *valid* signatures on the device now!

NEW mkswap:

        # blkid -s TYPE /dev/sdb1
        /dev/sdb1: TYPE="swap"

        # /lib/udev/vol_id /dev/sdb1 | grep TYPE
        ID_FS_TYPE=swap

the bootbits (first 1024 bytes) was erased.

We shouldn't zap disk labels (BSD, SUN, ...) and boot loaders (on whole
disk):

        # mkswap  /dev/sdb2
        mkswap: /dev/sdb2: warning: don't erase bootbits sectors
                (BSD partition table detected). Use -f to force.
        Setting up swapspace version 1, size = 4348 KiB
        no label, UUID=69d87cef-71ac-4fb0-a689-ce3e930dea17

        # mkswap  /dev/sdb
        mkswap: /dev/sdb: warning: don't erase bootbits sectors
                on whole disk. Use -f to force.
        Setting up swapspace version 1, size = 8188 KiB
        no label, UUID=97757ad7-8a84-43d9-bcb4-16fefd93a2ac

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-03-12 16:01:59 +01:00
Karel Zak 4c85aa3a4c mkswap: remove v0 swap space support
The kernel has not supported v0 swap space format since 2.5.22. The
new version v1 is supported since 2.1.117.

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-03-11 15:23:16 +01:00
Hugh Dickins 99e6d5259e mkswap: handle 2^32 pages
mkswap (when built 32-bit) could not quite support the maximum size
of swap area (2^32 pages): change unsigned long pagecounts to unsigned
long long pagecounts, and fix maxpages for the case when more is asked.

Signed-off-by: Hugh Dickins <hugh@veritas.com>
2009-02-27 15:26:48 +01:00
maximilian attems d144727bc3 use getpagesize()
getpagesize() is said to be more portable than sysconf(_SC_PAGESIZE)
to anything Linux.

this patch helps klibc porting effort as the sysconf
multiplex API is not supported there.

also remove comment of the switch to sysconf in mkswap.c.

Signed-off-by: maximilian attems <max@stro.at>
2008-07-30 13:26:58 +02:00
maximilian attems fc68cd4973 disk-utils: s/MOUNTED/_PATH_MOUNTED/
no longer use deprecated alias.
helps compiling util-linux-ng against klibc.

add pathnames.h include, where _PATH_MOUNTED is defined.

Signed-off-by: maximilian attems <max@stro.at>
2008-07-28 11:06:07 +02:00
Samuel Thibault 098fa6b120 disk-utils: clean up code, use blkdev_* functions
[kzak@redhat.com: split the original patch to small patches]

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2008-07-24 01:15:07 +02:00
Samuel Thibault ff035f67ed mkswap: non-linux support
GNU/Hurd uses linux-like swapspace, so mkswap makes sense on
non-linux platforms too.

[kzak@redhat.com: split the original patch to small patches]

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2008-07-24 00:52:13 +02:00
Karel Zak 4ba66edf82 selinux: is_selinux_enabled() returns 0, 1 and -1
Unfortunately, the current libselinux implementation of
is_selinux_enabled() returns -1 on error. This behavior is
undocumented.

The proper solution is to use "if (is_selinux_enabled() > 0)".

Signed-off-by: Karel Zak <kzak@redhat.com>
2008-07-01 14:32:53 +02:00
Karel Zak 89fb9aeb55 mkswap: set errno=0 in write_all()
Signed-off-by: Karel Zak <kzak@redhat.com>
2008-04-16 21:58:26 +02:00
Karel Zak db83e35c6a mkswap: when writing the signature page, handle EINTR returns
If the signature page write bumps into EINTR, it should finish the
write, instead of dying.

Addresses-Ubuntu-Bug: 206113
Signed-off-by: LaMont Jones <lamont@canonical.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2008-04-15 00:35:05 +02:00
Karel Zak 7b241808f1 mkswap: fix compiler warnings
mkswap.c:529: warning: pointer targets in assignment differ in signedness
mkswap.c:531: warning: pointer targets in assignment differ in signedness
mkswap.c:550: warning: pointer targets in passing argument 1 of `uuid_parse' differ in signedness

Signed-off-by: Karel Zak <kzak@redhat.com>
2008-03-20 14:54:06 +01:00
Martin Schulze 93bf0f285d mkswap: set UUID for swap space (add -U option)
A friend of mine is looking into the possibility of cloning Debian
(and other) systems automatically and stomped over swap partitions
getting assigned new UUIDs every time the new harddisk is partitioned
and swap is created.

It's essential when partitions are to be recognised by their uuid and
not by their old device path anymore.

Addresses-Ubuntu-Bug: #66637
Signed-off-by: LaMont Jones <lamont@debian.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2008-02-15 01:31:50 +01:00
Karel Zak b7188e932e mkswap: cleanup kB vs. KiB usage in error messages
mkswap(8) man page is talking about KiB (2^10), but the mkswap binary
uses kB (10^3) in error messages. That's strange. Let's use KiB
everywhere.

Signed-off-by: Karel Zak <kzak@redhat.com>
2007-11-07 13:46:34 +01:00
Karel Zak 54e377b386 mkswap: BLKGETSIZE cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-11-07 13:26:27 +01:00
Karel Zak 8023c83bd5 mkswap: linux_version() code consolidation
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-11-06 02:40:49 +01:00
Benno Schulenberg 6557c51226 docs: tweak a few messages for clarity
Add a missing period, a missing space, a comma and a word for clarity,
plus a period and an uppercase letter to match surrounding messages.
Further add a missing call to gettext, and undo an unneeded linewrap.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2007-10-26 01:02:44 +02:00
KaiGai Kohei 71bf788444 mkswap: possible to crash with SELinux relabeling support
When fgetfilecon() is failed with -ENODATA, this process does not
exit.  However, "oldcontext" is not initialized in this case, so
context_new() will be called with uninitialized "oldcontext" at the
next.

Finally, it makes a segmentation fault, because context_new() have to
refer an incorrect memory region.

The attached patch fixes this matter using matchpathcon().  If we
cannot obtain actual file context due to -ENODATA, a context which is
returned by matchpathcon() is applied as oldcontext.  Then, the type
of the context is relabeled to "swapfile_t" explicitly.

Signed-off-by: KaiGai Kohei <kaigai@kaigai.gr.jp>
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-10-25 21:50:36 +02:00
Matthias Koenig 2018629905 disk-utils: let mkfs tools open with O_EXCL
Let mkswap, mkfs.bfs, mkfs.minix open with O_EXCL if
used on block devices to prevent writing to the device
even if they are busy (mounted).

Unfortunately, O_EXCL has zero effect for 2.4 kernels where
in-kernel code doesn't use O_EXCL-like access locks. (Tested
on RHEL3.)

Signed-off-by: Matthias Koenig <mkoenig@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-07-27 13:39:29 +02:00
Karel Zak f88c89db4f mkswap: fix signedness problems and remove obsolete code
The UUID is unsigned char *

Signed-off-by: Karel Zak <kzak@redhat.com>
2007-07-25 17:18:57 +02:00
Matthias Koenig 30294a2fe8 mkswap: default to V1 in any case
mkswap(8) enforces to use v0 swap format when pagesize > 16kB.
(use case might be ppc64 with CONFIG_PPC_64K_PAGES).

As version 0 swap is not supported anymore by recent kernels, the
behaviour in this case is rather strange.

Here is a testcase:

for i in 4 8 16 32 64; do mkswap -p `expr $i \* 1024` ./swap.file; done
Setting up swapspace version 1, size = 4294963 kB

Using user-specified page size 8192, instead of the system values
4096/4096
Setting up swapspace version 1, size = 4294959 kB

Using user-specified page size 16384, instead of the system values
4096/4096
Setting up swapspace version 1, size = 4294950 kB

Using user-specified page size 32768, instead of the system values
4096/4096
Setting up swapspace version 0, size = 4294934 kB

Using user-specified page size 65536, instead of the system values
4096/4096
Setting up swapspace version 0, size = 4294901 kB

Signed-off-by: Matthias Koenig <mkoenig@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-07-24 14:59:32 +02:00
Matthias Koenig 766dd75716 disk-utils: fix libuuid usage in mkswap
Fix libuuid usage in mkswap.

Signed-off-by: Matthias Koenig <mkoenig@suse.de>
2007-05-16 23:55:23 +02:00
Karel Zak 3e18b040af mkswap: automatically add selinux label to swapfile
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-02-08 15:22:37 +01:00
Karel Zak 8abb4c2e00 mkswap: avoid mkswap usage on already mounted device
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-02-07 10:32:02 +01:00
Karel Zak 6b9a290adf mkswap: gcc happy: unsigned long usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-02-07 10:10:22 +01:00
Karel Zak 7ac3b5b8e3 Clean up pagesize/PAGE_SIZE usage.
Now all code in util-linux uses sysconf(_SC_PAGESIZE) that is standardized and
preferred way of querying page size. The asm/page.h file is not included to the
code anymore. (This patch doesn't change mount's FS detection code which will
be removed later).

Signed-off-by: Karel Zak <kzak@redhat.com>
2007-02-06 11:35:15 +01:00
Karel Zak baf39af15b Imported from util-linux-2.13-pre2 tarball. 2006-12-07 00:26:58 +01:00
Karel Zak 48d7b13a1e Imported from util-linux-2.13-pre1 tarball. 2006-12-07 00:26:54 +01:00
Karel Zak 756bfd018e Imported from util-linux-2.12o tarball. 2006-12-07 00:26:31 +01:00
Karel Zak d03dd60840 Imported from util-linux-2.12a tarball. 2006-12-07 00:26:14 +01:00
Karel Zak 95f1bdeee4 Imported from util-linux-2.11x tarball. 2006-12-07 00:26:05 +01:00
Karel Zak 0e6f4a203d Imported from util-linux-2.11v tarball. 2006-12-07 00:26:02 +01:00
Karel Zak a2c5f3cadc Imported from util-linux-2.11r tarball. 2006-12-07 00:25:56 +01:00
Karel Zak 1d4ad1decc Imported from util-linux-2.11q tarball. 2006-12-07 00:25:54 +01:00
Karel Zak c07ebfa1e0 Imported from util-linux-2.11b tarball. 2006-12-07 00:25:46 +01:00
Karel Zak 66ee8158b6 Imported from util-linux-2.10s tarball. 2006-12-07 00:25:44 +01:00
Karel Zak 22853e4a82 Imported from util-linux-2.10m tarball. 2006-12-07 00:25:43 +01:00
Karel Zak eb63b9b8f4 Imported from util-linux-2.10f tarball. 2006-12-07 00:25:41 +01:00
Karel Zak 7eda085c41 Imported from util-linux-2.9v tarball. 2006-12-07 00:25:39 +01:00
Karel Zak 5c36a0eb7c Imported from util-linux-2.9i tarball. 2006-12-07 00:25:37 +01:00
Karel Zak 2b6fc908bc Imported from util-linux-2.8 tarball. 2006-12-07 00:25:35 +01:00
Karel Zak fd6b7a7ffc Imported from util-linux-2.7.1 tarball. 2006-12-07 00:25:34 +01:00
Karel Zak 726f69e29c Imported from util-linux-2.5 tarball. 2006-12-07 00:25:33 +01:00
Karel Zak 6dbe3af945 Imported from util-linux-2.2 tarball. 2006-12-07 00:25:32 +01:00