From 0c5cd4af24561c24d434596e80ad476d8ff38b97 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 10 Mar 2010 23:08:26 +0100 Subject: [PATCH] swapon: remove " (deleted)" from filenames from /proc/swaps The filenames in /proc/swaps are generated by seq_path() and this function uses __d_path() from fs/dcache.c. The filename could generated with " (deleted)" suffix. We need real filenames without the suffix. Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=562403 Signed-off-by: Karel Zak --- mount/swapon.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mount/swapon.c b/mount/swapon.c index 5574f7ea..9f702ecb 100644 --- a/mount/swapon.c +++ b/mount/swapon.c @@ -120,11 +120,15 @@ swapoff_usage(FILE *fp, int n) { static int numSwaps; static char **swapFiles; /* array of swap file and partition names */ +#define DELETED_SUFFIX "\\040(deleted)" +#define DELETED_SUFFIX_SZ (sizeof(DELETED_SUFFIX) - 1) + static void read_proc_swaps(void) { FILE *swaps; char line[1024]; char *p, **q; + size_t sz; numSwaps = 0; swapFiles = NULL; @@ -152,7 +156,17 @@ read_proc_swaps(void) { * This will fail with names with embedded spaces. */ for (p = line; *p && *p != ' '; p++); - *p = 0; + *p = '\0'; + + /* the kernel can use " (deleted)" suffix for paths + * in /proc/swaps, we have to remove this junk. + */ + sz = strlen(line); + if (sz > DELETED_SUFFIX_SZ) { + p = line + (sz - DELETED_SUFFIX_SZ); + if (strcmp(p, DELETED_SUFFIX) == 0) + *p = '\0'; + } q = realloc(swapFiles, (numSwaps+1) * sizeof(*swapFiles)); if (q == NULL) -- 2.39.5