Commit Graph

81 Commits

Author SHA1 Message Date
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