]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
swapon: split swapon-common.c
authorKarel Zak <kzak@redhat.com>
Mon, 22 Sep 2014 11:16:25 +0000 (13:16 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 22 Sep 2014 11:16:25 +0000 (13:16 +0200)
 swapon    - requires libmount and libblkid
 swapoff   - requires libmount
 swaplabel - requires libblkid

This patch add lib/swapprober.c with blkid stuff for swap. It allows
to use and link libblkid only when necessary.

Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/Makemodule.am
disk-utils/swaplabel.c
include/Makemodule.am
include/swapprober.h [new file with mode: 0644]
lib/swapprober.c [new file with mode: 0644]
sys-utils/Makemodule.am
sys-utils/swapon-common.c
sys-utils/swapon-common.h [moved from include/swapon-common.h with 90% similarity]
sys-utils/swapon.c

index 04118c73ba06ec84f318302915bacbc0d61a9b1e..3c4f8d78b149277d0cca6db6b5239f792b10b45b 100644 (file)
@@ -65,10 +65,13 @@ endif # BUILD_MKSWAP
 if BUILD_SWAPLABEL
 sbin_PROGRAMS += swaplabel
 dist_man_MANS += disk-utils/swaplabel.8
-swaplabel_SOURCES = disk-utils/swaplabel.c sys-utils/swapon-common.c
+swaplabel_SOURCES = \
+       disk-utils/swaplabel.c \
+       lib/swapprober.c \
+       include/swapprober.h
 
-swaplabel_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir) -I$(ul_libmount_incdir)
-swaplabel_LDADD = $(LDADD) libblkid.la libmount.la libcommon.la
+swaplabel_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir)
+swaplabel_LDADD = $(LDADD) libblkid.la libcommon.la
 
 if BUILD_LIBUUID
 swaplabel_LDADD += libuuid.la
index a7cccc4f868a35a1907166c4bf53b7f237b7bfba..a7498a4f178954a5c81c112e0bd8e925f3e37d70 100644 (file)
@@ -18,7 +18,6 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <blkid.h>
 #include <getopt.h>
 
 #ifdef HAVE_LIBUUID
 #endif
 
 #include "c.h"
-#include "closestream.h"
+#include "nls.h"
 #include "all-io.h"
-#include "swapheader.h"
-#include "swapon-common.h"
 #include "strutils.h"
-#include "nls.h"
+#include "closestream.h"
+
+#include "swapheader.h"
+#include "swapprober.h"
 
 #define SWAP_UUID_OFFSET       (offsetof(struct swap_header_v1_2, uuid))
 #define SWAP_LABEL_OFFSET      (offsetof(struct swap_header_v1_2, volume_name))
index dd5c3f58c5834f3cc14f058c8b5e6bc6dee1fffc..bb8aac58beb11e10ed392ed450d63e4b841f7b33 100644 (file)
@@ -41,7 +41,7 @@ dist_noinst_HEADERS += \
        include/rpmatch.h \
        include/setproctitle.h \
        include/strutils.h \
-       include/swapon-common.h \
+       include/swapprober.h \
        include/swapheader.h \
        include/sysfs.h \
        include/timer.h \
diff --git a/include/swapprober.h b/include/swapprober.h
new file mode 100644 (file)
index 0000000..5107700
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef UTIL_LINUX_SWAP_PROBER_H
+#define UTIL_LINUX_SWAP_PROBER_H
+
+#include <blkid.h>
+
+blkid_probe get_swap_prober(const char *devname);
+
+#endif /* UTIL_LINUX_SWAP_PROBER_H */
+
diff --git a/lib/swapprober.c b/lib/swapprober.c
new file mode 100644 (file)
index 0000000..deb754b
--- /dev/null
@@ -0,0 +1,48 @@
+
+#include "c.h"
+#include "nls.h"
+
+#include "swapprober.h"
+
+blkid_probe get_swap_prober(const char *devname)
+{
+       blkid_probe pr;
+       int rc;
+       const char *version = NULL;
+       char *swap_filter[] = { "swap", NULL };
+
+       pr = blkid_new_probe_from_filename(devname);
+       if (!pr) {
+               warn(_("%s: unable to probe device"), devname);
+               return NULL;
+       }
+
+       blkid_probe_enable_superblocks(pr, TRUE);
+       blkid_probe_set_superblocks_flags(pr,
+                       BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID |
+                       BLKID_SUBLKS_VERSION);
+
+       blkid_probe_filter_superblocks_type(pr, BLKID_FLTR_ONLYIN, swap_filter);
+
+       rc = blkid_do_safeprobe(pr);
+       if (rc == -1)
+               warn(_("%s: unable to probe device"), devname);
+       else if (rc == -2)
+               warnx(_("%s: ambivalent probing result, use wipefs(8)"), devname);
+       else if (rc == 1)
+               warnx(_("%s: not a valid swap partition"), devname);
+
+       if (rc == 0) {
+               /* Only the SWAPSPACE2 is supported. */
+               if (blkid_probe_lookup_value(pr, "VERSION", &version, NULL) == 0
+                   && version
+                   && strcmp(version, stringify_value(SWAP_VERSION)))
+                       warnx(_("%s: unsupported swap version '%s'"),
+                                               devname, version);
+               else
+                       return pr;
+       }
+
+       blkid_free_probe(pr);
+       return NULL;
+}
index 058bb62d498cbfb91b3fd5585cc58a41df937b92..b75d5e0053039d31610a73db9724f40267d4ee99 100644 (file)
@@ -262,7 +262,10 @@ dist_man_MANS += \
 
 swapon_SOURCES = \
        sys-utils/swapon.c \
-       sys-utils/swapon-common.c
+       sys-utils/swapon-common.c \
+       sys-utils/swapon-common.h \
+       lib/swapprober.c \
+       include/swapprober.h
 swapon_CFLAGS = $(AM_CFLAGS) \
        -I$(ul_libblkid_incdir) \
        -I$(ul_libmount_incdir) \
@@ -273,8 +276,11 @@ swapon_LDADD = $(LDADD) \
        libmount.la \
        libsmartcols.la
 
-swapoff_SOURCES = sys-utils/swapoff.c sys-utils/swapon-common.c
-swapoff_CFLAGS = $(AM_CFLAGS) -I$(ul_libmount_incdir) -I$(ul_libblkid_incdir)
+swapoff_SOURCES = \
+       sys-utils/swapoff.c \
+       sys-utils/swapon-common.c \
+       sys-utils/swapon-common.h
+swapoff_CFLAGS = $(AM_CFLAGS) -I$(ul_libmount_incdir)
 swapoff_LDADD = $(LDADD) libmount.la
 endif
 
index 203d5c4d09e5d834c124d7acffb3f5e31a62e7ce..8f7788cb03515de59787b922a04f579989ee454c 100644 (file)
@@ -1,11 +1,10 @@
-#include <blkid.h>
 
 #include "c.h"
 #include "nls.h"
-#include "swapheader.h"
-#include "swapon-common.h"
 #include "xalloc.h"
 
+#include "swapon-common.h"
+
 /*
  * content of /proc/swaps and /etc/fstab
  */
@@ -106,45 +105,3 @@ size_t numof_uuids(void)
        return ulct;
 }
 
-blkid_probe get_swap_prober(const char *devname)
-{
-       blkid_probe pr;
-       int rc;
-       const char *version = NULL;
-       char *swap_filter[] = { "swap", NULL };
-
-       pr = blkid_new_probe_from_filename(devname);
-       if (!pr) {
-               warn(_("%s: unable to probe device"), devname);
-               return NULL;
-       }
-
-       blkid_probe_enable_superblocks(pr, TRUE);
-       blkid_probe_set_superblocks_flags(pr,
-                       BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID |
-                       BLKID_SUBLKS_VERSION);
-
-       blkid_probe_filter_superblocks_type(pr, BLKID_FLTR_ONLYIN, swap_filter);
-
-       rc = blkid_do_safeprobe(pr);
-       if (rc == -1)
-               warn(_("%s: unable to probe device"), devname);
-       else if (rc == -2)
-               warnx(_("%s: ambivalent probing result, use wipefs(8)"), devname);
-       else if (rc == 1)
-               warnx(_("%s: not a valid swap partition"), devname);
-
-       if (rc == 0) {
-               /* Only the SWAPSPACE2 is supported. */
-               if (blkid_probe_lookup_value(pr, "VERSION", &version, NULL) == 0
-                   && version
-                   && strcmp(version, stringify_value(SWAP_VERSION)))
-                       warnx(_("%s: unsupported swap version '%s'"),
-                                               devname, version);
-               else
-                       return pr;
-       }
-
-       blkid_free_probe(pr);
-       return NULL;
-}
similarity index 90%
rename from include/swapon-common.h
rename to sys-utils/swapon-common.h
index da58e199d7d0389fc6ba7395eec04f2c3c34b145..d1b679f2c2ccd91820361e7df56804ca6bc22c8b 100644 (file)
@@ -1,7 +1,6 @@
 #ifndef UTIL_LINUX_SWAPON_COMMON_H
 #define UTIL_LINUX_SWAPON_COMMON_H
 
-#include <blkid.h>
 #include <libmount.h>
 
 extern struct libmnt_cache *mntcache;
@@ -23,6 +22,4 @@ extern void add_uuid(const char *uuid);
 extern const char *get_uuid(size_t i);
 extern size_t numof_uuids(void);
 
-blkid_probe get_swap_prober(const char *devname);
-
 #endif /* UTIL_LINUX_SWAPON_COMMON_H */
index ea5fdb28ac4540eeecd103a51c1ab7e9a2343772..976f87e405adcb95d0cebd8dd7792533295031aa 100644 (file)
@@ -12,9 +12,6 @@
 #include <stdint.h>
 #include <ctype.h>
 
-#include <blkid.h>
-
-#include <libmount.h>
 #include <libsmartcols.h>
 
 #include "c.h"
 #include "blkdev.h"
 #include "pathnames.h"
 #include "xalloc.h"
+#include "strutils.h"
 #include "closestream.h"
 
 #include "swapheader.h"
+#include "swapprober.h"
 #include "swapon-common.h"
-#include "strutils.h"
 
 #define PATH_MKSWAP    "/sbin/mkswap"