summaryrefslogtreecommitdiffstats
path: root/mount/swapon.c
diff options
context:
space:
mode:
authorKarel Zak2010-12-17 01:10:36 +0100
committerKarel Zak2010-12-17 01:10:36 +0100
commit57a60bf0effd1539aa78fd19aa13024ce6a9edf6 (patch)
tree34e8a1b429799a0f4fbb0e88853e542b8b2a8edb /mount/swapon.c
parentswapon: Canonicalize swap device (diff)
downloadkernel-qcow2-util-linux-57a60bf0effd1539aa78fd19aa13024ce6a9edf6.tar.gz
kernel-qcow2-util-linux-57a60bf0effd1539aa78fd19aa13024ce6a9edf6.tar.xz
kernel-qcow2-util-linux-57a60bf0effd1539aa78fd19aa13024ce6a9edf6.zip
swpaon: use canonicalized devnames on -s output
Old version Filename Type Size Used Priority /dev/sda3 partition 2353516 76 -1 /dev/dm-1 partition 409596 0 -2 New version: Filename Type Size Used Priority /dev/sda3 partition 2353516 76 -1 /dev/mapper/VUL-lvol0 partition 409596 0 -2 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'mount/swapon.c')
-rw-r--r--mount/swapon.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/mount/swapon.c b/mount/swapon.c
index 812884711..f0577bbb8 100644
--- a/mount/swapon.c
+++ b/mount/swapon.c
@@ -14,6 +14,7 @@
#include <fcntl.h>
#include <stdint.h>
#include <err.h>
+#include <ctype.h>
#include "bitops.h"
#include "blkdev.h"
@@ -201,19 +202,36 @@ is_in_proc_swaps(const char *fname) {
static int
display_summary(void)
{
- FILE *swaps;
- char line[1024] ;
+ FILE *swaps;
+ char line[1024] ;
+
+ if ((swaps = fopen(_PATH_PROC_SWAPS, "r")) == NULL) {
+ warn(_("%s: open failed"), _PATH_PROC_SWAPS);
+ return -1;
+ }
- if ((swaps = fopen(_PATH_PROC_SWAPS, "r")) == NULL) {
- warn(_("%s: open failed"), _PATH_PROC_SWAPS);
- return -1;
- }
+ while (fgets(line, sizeof(line), swaps)) {
+ char *p, *dev, *cn;
+ if (!strncmp(line, "Filename\t", 9)) {
+ printf("%s", line);
+ continue;
+ }
+ for (p = line; *p && *p != ' '; p++);
+ *p = '\0';
+ for (++p; *p && isblank((unsigned int) *p); p++);
- while (fgets(line, sizeof(line), swaps))
- printf("%s", line);
+ dev = unmangle(line);
+ if (!dev)
+ continue;
+ cn = canonicalize_path(dev);
+ if (cn)
+ printf("%-40s%s", cn, p);
+ free(dev);
+ free(cn);
+ }
- fclose(swaps);
- return 0 ;
+ fclose(swaps);
+ return 0 ;
}
/* calls mkswap */