summaryrefslogtreecommitdiffstats
path: root/disk-utils
diff options
context:
space:
mode:
authorSami Kerola2014-07-01 22:40:04 +0200
committerKarel Zak2014-07-22 12:17:20 +0200
commit5db57cfc469b45ada0162a64d627ce25a3d2431f (patch)
tree23d67c74e1555511670244087243e5d8faf86a2e /disk-utils
parentMerge branch 'rename' of git://github.com/kerolasa/lelux-utiliteetit (diff)
downloadkernel-qcow2-util-linux-5db57cfc469b45ada0162a64d627ce25a3d2431f.tar.gz
kernel-qcow2-util-linux-5db57cfc469b45ada0162a64d627ce25a3d2431f.tar.xz
kernel-qcow2-util-linux-5db57cfc469b45ada0162a64d627ce25a3d2431f.zip
swapon: share get_swap_prober() with swaplabel to print uuid and label
The swapon(8) listing was almost complete, apart from label and uuid. This change moves the code from swaplabel(8) to shared scope to be used for printouts in other swap commands, such as swapon. Adding this feature to lsblk(8) was a consideration, but lsblk is not interested of swapfiles, so the swapon seems like a better option to add this information. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'disk-utils')
-rw-r--r--disk-utils/Makemodule.am6
-rw-r--r--disk-utils/swaplabel.c46
2 files changed, 3 insertions, 49 deletions
diff --git a/disk-utils/Makemodule.am b/disk-utils/Makemodule.am
index fb3b564cd..c6183f5ca 100644
--- a/disk-utils/Makemodule.am
+++ b/disk-utils/Makemodule.am
@@ -65,10 +65,10 @@ endif # BUILD_MKSWAP
if BUILD_SWAPLABEL
sbin_PROGRAMS += swaplabel
dist_man_MANS += disk-utils/swaplabel.8
-swaplabel_SOURCES = disk-utils/swaplabel.c
+swaplabel_SOURCES = disk-utils/swaplabel.c sys-utils/swapon-common.c
-swaplabel_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir)
-swaplabel_LDADD = $(LDADD) libblkid.la libcommon.la
+swaplabel_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir) -I$(ul_libmount_incdir)
+swaplabel_LDADD = $(LDADD) libblkid.la libmount.la libcommon.la
if BUILD_LIBUUID
swaplabel_LDADD += libuuid.la
diff --git a/disk-utils/swaplabel.c b/disk-utils/swaplabel.c
index 8d5b260c5..809c365cb 100644
--- a/disk-utils/swaplabel.c
+++ b/disk-utils/swaplabel.c
@@ -35,52 +35,6 @@
#define SWAP_UUID_OFFSET (offsetof(struct swap_header_v1_2, uuid))
#define SWAP_LABEL_OFFSET (offsetof(struct swap_header_v1_2, volume_name))
-/*
- * Returns new libblkid prober. This function call exit() on error.
- */
-static 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;
-}
-
/* Print the swap partition information */
static int print_info(blkid_probe pr)
{