summaryrefslogtreecommitdiffstats
path: root/mount
diff options
context:
space:
mode:
authorKarel Zak2009-03-02 14:21:03 +0100
committerKarel Zak2009-03-03 15:20:45 +0100
commit81772d3c240cb72ddb977557c973b12bfef90396 (patch)
tree727f440246e420980af2413ce27208631d71185a /mount
parentswapon: add generic swap_get_header() (diff)
downloadkernel-qcow2-util-linux-81772d3c240cb72ddb977557c973b12bfef90396.tar.gz
kernel-qcow2-util-linux-81772d3c240cb72ddb977557c973b12bfef90396.tar.xz
kernel-qcow2-util-linux-81772d3c240cb72ddb977557c973b12bfef90396.zip
swapon: simplify spec to devname conversion
We needn't to use spec_to_devname() and check for pseudo filesystems. The swap{on,off} is always checking for the 'swap' fstype. This patch also removes the dependence on xmalloc.c. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'mount')
-rw-r--r--mount/Makefile.am12
-rw-r--r--mount/swapon.c28
2 files changed, 22 insertions, 18 deletions
diff --git a/mount/Makefile.am b/mount/Makefile.am
index b34df3c3b..7714efbcf 100644
--- a/mount/Makefile.am
+++ b/mount/Makefile.am
@@ -6,12 +6,12 @@ bin_PROGRAMS = mount umount
sbin_PROGRAMS = losetup swapon
dist_man_MANS = fstab.5 mount.8 swapoff.8 swapon.8 umount.8 losetup.8
-# generic sources for all programs (mount, umount, swapon, losetup)
-srcs_common = sundries.c xmalloc.c ../lib/canonicalize.c
+# generic sources for all programs (mount, umount, losetup)
+srcs_common = sundries.c xmalloc.c ../lib/canonicalize.c sundries.h xmalloc.h
# generic header for mount and umount
hdrs_mount = fstab.h mount_mntent.h mount_constants.h \
- lomount.h xmalloc.h getusername.h loop.h sundries.h
+ lomount.h getusername.h loop.h
# generic sources for mount and umount
srcs_mount = fstab.c mount_mntent.c getusername.c lomount.c devname.c devname.h \
@@ -38,12 +38,12 @@ umount_CFLAGS = $(SUID_CFLAGS) $(AM_CFLAGS) $(cflags_common)
umount_LDFLAGS = $(SUID_LDFLAGS) $(AM_LDFLAGS)
umount_LDADD = $(ldadd_common)
-swapon_SOURCES = swapon.c swap_constants.h $(srcs_common) devname.c devname.h \
- ../lib/linux_version.c ../lib/blkdev.c ../lib/fsprobe.c
+swapon_SOURCES = swapon.c swap_constants.h ../lib/linux_version.c \
+ ../lib/blkdev.c ../lib/fsprobe.c ../lib/canonicalize.c
swapon_CFLAGS = $(cflags_common)
swapon_LDADD = $(ldadd_common)
-losetup_SOURCES = lomount.c $(srcs_common) loop.h lomount.h xmalloc.h sundries.h
+losetup_SOURCES = lomount.c $(srcs_common) loop.h lomount.h
losetup_CPPFLAGS = -DMAIN $(AM_CPPFLAGS)
mount_static_LDADD =
diff --git a/mount/swapon.c b/mount/swapon.c
index 83c0404fb..b0def44a5 100644
--- a/mount/swapon.c
+++ b/mount/swapon.c
@@ -1,7 +1,6 @@
/*
* A swapon(8)/swapoff(8) for Linux 0.99.
*/
-#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
@@ -14,15 +13,13 @@
#include <sys/wait.h>
#include <fcntl.h>
#include <stdint.h>
+
#include "bitops.h"
#include "blkdev.h"
-#include "xmalloc.h"
#include "swap_constants.h"
#include "nls.h"
#include "fsprobe.h"
-#include "devname.h"
#include "pathnames.h"
-#include "sundries.h"
#include "swapheader.h"
#define PATH_MKSWAP "/sbin/mkswap"
@@ -50,11 +47,14 @@ enum {
SIG_SWSUSPEND
};
-int all = 0;
+int all;
int priority = -1; /* non-prioritized swap by default */
/* If true, don't complain if the device/file doesn't exist */
-int ifexists = 0;
+int ifexists;
+
+int verbose;
+char *progname;
static struct option longswaponopts[] = {
/* swapon only */
@@ -336,7 +336,7 @@ do_swapon(const char *orig_special, int prio, int canonic) {
printf(_("%s on %s\n"), progname, orig_special);
if (!canonic) {
- special = spec_to_devname(orig_special);
+ special = fsprobe_get_devname_by_spec(orig_special);
if (!special)
return cannot_find(orig_special);
}
@@ -492,7 +492,7 @@ do_swapoff(const char *orig_special, int quiet, int canonic) {
printf(_("%s on %s\n"), progname, orig_special);
if (!canonic) {
- special = spec_to_devname(orig_special);
+ special = fsprobe_get_devname_by_spec(orig_special);
if (!special)
return cannot_find(orig_special);
}
@@ -563,7 +563,7 @@ swapon_all(void) {
if (skip)
continue;
- special = spec_to_devname(fstab->mnt_fsname);
+ special = fsprobe_get_devname_by_spec(fstab->mnt_fsname);
if (!special) {
if (!ifexists)
status |= cannot_find(fstab->mnt_fsname);
@@ -587,12 +587,16 @@ static const char **ulist = NULL;
static int ulct = 0;
static void addl(const char *label) {
- llist = (const char **) xrealloc(llist, (++llct) * sizeof(char *));
+ llist = (const char **) realloc(llist, (++llct) * sizeof(char *));
+ if (!llist)
+ exit(EXIT_FAILURE);
llist[llct-1] = label;
}
static void addu(const char *uuid) {
- ulist = (const char **) xrealloc(ulist, (++ulct) * sizeof(char *));
+ ulist = (const char **) realloc(ulist, (++ulct) * sizeof(char *));
+ if (!ulist)
+ exit(EXIT_FAILURE);
ulist[ulct-1] = uuid;
}
@@ -744,7 +748,7 @@ main_swapoff(int argc, char *argv[]) {
if (!streq(fstab->mnt_type, MNTTYPE_SWAP))
continue;
- special = spec_to_devname(fstab->mnt_fsname);
+ special = fsprobe_get_devname_by_spec(fstab->mnt_fsname);
if (!special)
continue;