From: Karel Zak Date: Fri, 17 Dec 2010 00:10:36 +0000 (+0100) Subject: swpaon: use canonicalized devnames on -s output X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57a60bf0effd1539aa78fd19aa13024ce6a9edf6;p=util-linux 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 --- diff --git a/mount/swapon.c b/mount/swapon.c index 81288471..f0577bbb 100644 --- a/mount/swapon.c +++ b/mount/swapon.c @@ -14,6 +14,7 @@ #include #include #include +#include #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 */