diff options
author | Karel Zak | 2014-09-22 13:16:25 +0200 |
---|---|---|
committer | Karel Zak | 2014-09-22 13:16:25 +0200 |
commit | 18b3e5495b2bd1d89286f452d1d2952e065dfecd (patch) | |
tree | 008f4099b0814ad1e7408b7de6572fcc804031f8 /sys-utils | |
parent | logger: gettimeofday needs <sys/time.h> (diff) | |
download | kernel-qcow2-util-linux-18b3e5495b2bd1d89286f452d1d2952e065dfecd.tar.gz kernel-qcow2-util-linux-18b3e5495b2bd1d89286f452d1d2952e065dfecd.tar.xz kernel-qcow2-util-linux-18b3e5495b2bd1d89286f452d1d2952e065dfecd.zip |
swapon: split swapon-common.c
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>
Diffstat (limited to 'sys-utils')
-rw-r--r-- | sys-utils/Makemodule.am | 12 | ||||
-rw-r--r-- | sys-utils/swapon-common.c | 47 | ||||
-rw-r--r-- | sys-utils/swapon-common.h | 25 | ||||
-rw-r--r-- | sys-utils/swapon.c | 6 |
4 files changed, 38 insertions, 52 deletions
diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am index 058bb62d4..b75d5e005 100644 --- a/sys-utils/Makemodule.am +++ b/sys-utils/Makemodule.am @@ -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 diff --git a/sys-utils/swapon-common.c b/sys-utils/swapon-common.c index 203d5c4d0..8f7788cb0 100644 --- a/sys-utils/swapon-common.c +++ b/sys-utils/swapon-common.c @@ -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; -} diff --git a/sys-utils/swapon-common.h b/sys-utils/swapon-common.h new file mode 100644 index 000000000..d1b679f2c --- /dev/null +++ b/sys-utils/swapon-common.h @@ -0,0 +1,25 @@ +#ifndef UTIL_LINUX_SWAPON_COMMON_H +#define UTIL_LINUX_SWAPON_COMMON_H + +#include <libmount.h> + +extern struct libmnt_cache *mntcache; + +extern struct libmnt_table *get_fstab(void); +extern struct libmnt_table *get_swaps(void); +extern void free_tables(void); + +extern int match_swap(struct libmnt_fs *fs, void *data); +extern int is_active_swap(const char *filename); + +extern int cannot_find(const char *special); + +extern void add_label(const char *label); +extern const char *get_label(size_t i); +extern size_t numof_labels(void); + +extern void add_uuid(const char *uuid); +extern const char *get_uuid(size_t i); +extern size_t numof_uuids(void); + +#endif /* UTIL_LINUX_SWAPON_COMMON_H */ diff --git a/sys-utils/swapon.c b/sys-utils/swapon.c index ea5fdb28a..976f87e40 100644 --- a/sys-utils/swapon.c +++ b/sys-utils/swapon.c @@ -12,9 +12,6 @@ #include <stdint.h> #include <ctype.h> -#include <blkid.h> - -#include <libmount.h> #include <libsmartcols.h> #include "c.h" @@ -23,11 +20,12 @@ #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" |