]> err.no Git - util-linux/commitdiff
swpaon: use canonicalized devnames on -s output
authorKarel Zak <kzak@redhat.com>
Fri, 17 Dec 2010 00:10:36 +0000 (01:10 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 17 Dec 2010 00:10:36 +0000 (01:10 +0100)
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>
mount/swapon.c

index 812884711c19dbb121bce033e0add7d6cce2acfe..f0577bbb8387f3f4d2ec39a7c1959efcd8ddbee6 100644 (file)
@@ -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 */