Commit Graph

46 Commits

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