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
#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))
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 \
--- /dev/null
+#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 */
+
--- /dev/null
+
+#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;
+}
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) \
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
-#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
*/
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;
-}
#ifndef UTIL_LINUX_SWAPON_COMMON_H
#define UTIL_LINUX_SWAPON_COMMON_H
-#include <blkid.h>
#include <libmount.h>
extern struct libmnt_cache *mntcache;
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 */
#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"