From 2b6759df0c24a16ad5ddb855f0b453dd086a3747 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 21 Feb 2014 12:27:58 +0100 Subject: [PATCH] findmnt: add --bytes to print sizes in bytes Signed-off-by: Karel Zak --- misc-utils/findmnt.8 | 3 +++ misc-utils/findmnt.c | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/misc-utils/findmnt.8 b/misc-utils/findmnt.8 index 6b8e8d8fd..0176cd130 100644 --- a/misc-utils/findmnt.8 +++ b/misc-utils/findmnt.8 @@ -45,6 +45,9 @@ Disable all built-in filters and print all filesystems. .BR \-a , " \-\-ascii" Use ascii characters for tree formatting. .TP +.BR \-b , " \-\-bytes" +Print the SIZE, USED and AVAIL column in bytes rather than in a human-readable format. +.TP .BR \-c , " \-\-canonicalize" Canonicalize all printed paths. .TP diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index 988cd7397..dc1cbb745 100644 --- a/misc-utils/findmnt.c +++ b/misc-utils/findmnt.c @@ -59,7 +59,8 @@ enum { FL_POLL = (1 << 9), FL_DF = (1 << 10), FL_ALL = (1 << 11), - FL_UNIQ = (1 << 12) + FL_UNIQ = (1 << 12), + FL_BYTES = (1 << 13) }; /* column IDs */ @@ -478,8 +479,14 @@ static char *get_vfs_attr(struct libmnt_fs *fs, int sizetype) return sizestr; } - return vfs_attr == 0 ? xstrdup("0") : - size_to_human_string(SIZE_SUFFIX_1LETTER, vfs_attr); + if (!vfs_attr) + sizestr = xstrdup("0"); + else if (flags & FL_BYTES) + xasprintf(&sizestr, "%ju", vfs_attr); + else + sizestr = size_to_human_string(SIZE_SUFFIX_1LETTER, vfs_attr); + + return sizestr; } /* reads FS data from libmount @@ -1124,6 +1131,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out) fputs(_(" -A, --all disable all built-in filters, print all filesystems\n"), out); fputs(_(" -a, --ascii use ASCII chars for tree formatting\n"), out); + fputs(_(" -b, --bytes print sizes in bytes rather than in human readable format\n"), out); fputs(_(" -c, --canonicalize canonicalize printed paths\n"), out); fputs(_(" -D, --df imitate the output of df(1)\n"), out); fputs(_(" -d, --direction direction of search, 'forward' or 'backward'\n"), out); @@ -1176,6 +1184,7 @@ int main(int argc, char *argv[]) static const struct option longopts[] = { { "all", 0, 0, 'A' }, { "ascii", 0, 0, 'a' }, + { "bytes", 0, 0, 'b' }, { "canonicalize", 0, 0, 'c' }, { "direction", 1, 0, 'd' }, { "df", 0, 0, 'D' }, @@ -1227,7 +1236,7 @@ int main(int argc, char *argv[]) tt_flags |= TT_FL_TREE; while ((c = getopt_long(argc, argv, - "AacDd:ehifF:o:O:p::PklmnN:rst:uvRS:T:Uw:V", + "AabcDd:ehifF:o:O:p::PklmnN:rst:uvRS:T:Uw:V", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); @@ -1239,6 +1248,9 @@ int main(int argc, char *argv[]) case 'a': tt_flags |= TT_FL_ASCII; break; + case 'b': + flags |= FL_BYTES; + break; case 'c': flags |= FL_CANONICALIZE; break;