summaryrefslogtreecommitdiffstats
path: root/sys-utils/swapon.c
diff options
context:
space:
mode:
authorSami Kerola2014-07-01 22:40:04 +0200
committerKarel Zak2014-07-22 12:17:20 +0200
commit5db57cfc469b45ada0162a64d627ce25a3d2431f (patch)
tree23d67c74e1555511670244087243e5d8faf86a2e /sys-utils/swapon.c
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 'sys-utils/swapon.c')
-rw-r--r--sys-utils/swapon.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/sys-utils/swapon.c b/sys-utils/swapon.c
index b50016aff..0c8ca03e1 100644
--- a/sys-utils/swapon.c
+++ b/sys-utils/swapon.c
@@ -12,6 +12,8 @@
#include <stdint.h>
#include <ctype.h>
+#include <blkid.h>
+
#include <libmount.h>
#include <libsmartcols.h>
@@ -97,13 +99,23 @@ struct colinfo {
static int no_headings;
static int raw;
-enum { COL_PATH, COL_TYPE, COL_SIZE, COL_USED, COL_PRIO };
+enum {
+ COL_PATH,
+ COL_TYPE,
+ COL_SIZE,
+ COL_USED,
+ COL_PRIO,
+ COL_UUID,
+ COL_LABEL
+};
struct colinfo infos[] = {
[COL_PATH] = { "NAME", 0.20, 0, N_("device file or partition path") },
[COL_TYPE] = { "TYPE", 0.20, SCOLS_FL_TRUNC, N_("type of the device")},
[COL_SIZE] = { "SIZE", 0.20, SCOLS_FL_RIGHT, N_("size of the swap area")},
[COL_USED] = { "USED", 0.20, SCOLS_FL_RIGHT, N_("bytes in use")},
[COL_PRIO] = { "PRIO", 0.20, SCOLS_FL_RIGHT, N_("swap priority")},
+ [COL_UUID] = { "UUID", 0.20, 0, N_("swap uuid")},
+ [COL_LABEL] = { "LABEL", 0.20, 0, N_("swap label")},
};
static int columns[ARRAY_SIZE(infos) * 2];
@@ -142,6 +154,8 @@ static void add_scols_line(struct libscols_table *table, struct libmnt_fs *fs, i
{
int i;
struct libscols_line *line;
+ blkid_probe pr = NULL;
+ const char *data;
assert(table);
assert(fs);
@@ -149,7 +163,9 @@ static void add_scols_line(struct libscols_table *table, struct libmnt_fs *fs, i
line = scols_table_new_line(table, NULL);
if (!line)
err(EXIT_FAILURE, _("failed to initialize output line"));
-
+ data = mnt_fs_get_source(fs);
+ if (access(data, R_OK) == 0)
+ pr = get_swap_prober(data);
for (i = 0; i < ncolumns; i++) {
char *str = NULL;
off_t size;
@@ -180,6 +196,22 @@ static void add_scols_line(struct libscols_table *table, struct libmnt_fs *fs, i
case COL_PRIO:
xasprintf(&str, "%d", mnt_fs_get_priority(fs));
break;
+ case COL_UUID:
+ if (pr && !blkid_probe_lookup_value(pr, "UUID", &data, NULL))
+ xasprintf(&str, "%s", data);
+ else if (pr)
+ xasprintf(&str, "");
+ else
+ xasprintf(&str, _("read failed"));
+ break;
+ case COL_LABEL:
+ if (pr && !blkid_probe_lookup_value(pr, "LABEL", &data, NULL))
+ xasprintf(&str, "%s", data);
+ else if (pr)
+ xasprintf(&str, "");
+ else
+ xasprintf(&str, _("read failed"));
+ break;
default:
break;
}
@@ -187,6 +219,8 @@ static void add_scols_line(struct libscols_table *table, struct libmnt_fs *fs, i
if (str)
scols_line_refer_data(line, i, str);
}
+ if (pr)
+ blkid_free_probe(pr);
return;
}