Commit 6f793940 authored by Randy Dunlap's avatar Randy Dunlap Committed by Linus Torvalds

mm: swapfile: fix /proc/swaps heading and Size/Used/Priority alignment

Fix the heading and Size/Used/Priority field alignments in /proc/swaps.
If the Size and/or Used value is >= 10000000 (8 bytes), then the
alignment by using tab characters is broken.

This patch maintains the use of tabs for alignment.  If spaces are
preferred, we can just use a Field Width specifier for the bytes and
inuse fields.  That way those fields don't have to be a multiple of 8
bytes in width.  E.g., with a field width of 12, both Size and Used
would always fit on the first line of an 80-column wide terminal (only
Priority would be on the second line).

There are actually 2 problems: heading alignment and field width.  On an
xterm, if Used is 7 bytes in length, the tab does nothing, and the
display is like this, with no space/tab between the Used and Priority
fields.  (ugh)

Filename				Type		Size	Used	Priority
/dev/sda8                               partition	16779260	2023012-1

To be clear, if one does 'cat /proc/swaps >/tmp/proc.swaps', it does look
different, like so:

Filename				Type		Size	Used	Priority
/dev/sda8                               partition	16779260	2086988	-1
Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Link: http://lkml.kernel.org/r/c0ffb41a-81ac-ddfa-d452-a9229ecc0387@infradead.orgSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 49070588
...@@ -2801,20 +2801,24 @@ static int swap_show(struct seq_file *swap, void *v) ...@@ -2801,20 +2801,24 @@ static int swap_show(struct seq_file *swap, void *v)
struct swap_info_struct *si = v; struct swap_info_struct *si = v;
struct file *file; struct file *file;
int len; int len;
unsigned int bytes, inuse;
if (si == SEQ_START_TOKEN) { if (si == SEQ_START_TOKEN) {
seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n"); seq_puts(swap,"Filename\t\t\t\tType\t\tSize\t\tUsed\t\tPriority\n");
return 0; return 0;
} }
bytes = si->pages << (PAGE_SHIFT - 10);
inuse = si->inuse_pages << (PAGE_SHIFT - 10);
file = si->swap_file; file = si->swap_file;
len = seq_file_path(swap, file, " \t\n\\"); len = seq_file_path(swap, file, " \t\n\\");
seq_printf(swap, "%*s%s\t%u\t%u\t%d\n", seq_printf(swap, "%*s%s\t%u\t%s%u\t%s%d\n",
len < 40 ? 40 - len : 1, " ", len < 40 ? 40 - len : 1, " ",
S_ISBLK(file_inode(file)->i_mode) ? S_ISBLK(file_inode(file)->i_mode) ?
"partition" : "file\t", "partition" : "file\t",
si->pages << (PAGE_SHIFT - 10), bytes, bytes < 10000000 ? "\t" : "",
si->inuse_pages << (PAGE_SHIFT - 10), inuse, inuse < 10000000 ? "\t" : "",
si->prio); si->prio);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment