From: Audrius Butkevicius <audrius.butkevicius@elastichosts.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH] btrfs-progs: add '-b' option to filesystem df and show
Date: Fri, 1 Feb 2013 09:59:49 +0000 [thread overview]
Message-ID: <20130201095947.GA32445@gmail.com> (raw)
Add '-b' and '--bytes' options to btrfs filesystem df and show, for easier
integration with scripts. This causes all sizes to be displayed in decimal
bytes instead of pretty-printed with human-readable suffices KB, MB, etc.
Signed-off-by: Audrius Butkevicius <audrius.butkevicius@elastichosts.com>
---
cmds-filesystem.c | 93 +++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 68 insertions(+), 25 deletions(-)
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 507239a..9392209 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -40,7 +40,7 @@ static const char * const filesystem_cmd_group_usage[] = {
};
static const char * const cmd_df_usage[] = {
- "btrfs filesystem df <path>",
+ "btrfs filesystem df [-b|--bytes] <path>",
"Show space usage information for a mount point",
NULL
};
@@ -53,11 +53,23 @@ static int cmd_df(int argc, char **argv)
int fd;
int e;
char *path;
+ int start = 1;
+ int rawbytes = 0;
+
+ while (argc > start) {
+ if (!strcmp(argv[start], "--bytes") ||
+ !strcmp(argv[start], "-b")) {
+ rawbytes = 1;
+ start += 1;
+ } else {
+ break;
+ }
+ }
- if (check_argc_exact(argc, 2))
+ if (check_argc_exact(argc, start + 1))
usage(cmd_df_usage);
- path = argv[1];
+ path = argv[start];
fd = open_file_or_dir(path);
if (fd < 0) {
@@ -150,10 +162,18 @@ static int cmd_df(int argc, char **argv)
written += 8;
}
- total_bytes = pretty_sizes(sargs->spaces[i].total_bytes);
- used_bytes = pretty_sizes(sargs->spaces[i].used_bytes);
- printf("%s: total=%s, used=%s\n", description, total_bytes,
- used_bytes);
+ if (rawbytes) {
+ printf("%s: total=%llu, used=%llu\n", description,
+ (unsigned long long)sargs->spaces[i].total_bytes,
+ (unsigned long long)sargs->spaces[i].used_bytes);
+ } else {
+ total_bytes = pretty_sizes(sargs->spaces[i].total_bytes);
+ used_bytes = pretty_sizes(sargs->spaces[i].used_bytes);
+ printf("%s: total=%s, used=%s\n", description, total_bytes,
+ used_bytes);
+ free(total_bytes);
+ free(bytes_used);
+ }
}
close(fd);
free(sargs);
@@ -182,7 +202,7 @@ static int uuid_search(struct btrfs_fs_devices *fs_devices, char *search)
return 0;
}
-static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
+static void print_one_uuid(struct btrfs_fs_devices *fs_devices, int rawbytes)
{
char uuidbuf[37];
struct list_head *cur;
@@ -199,25 +219,39 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
else
printf("Label: none ");
- super_bytes_used = pretty_sizes(device->super_bytes_used);
-
total = device->total_devs;
- printf(" uuid: %s\n\tTotal devices %llu FS bytes used %s\n", uuidbuf,
- (unsigned long long)total, super_bytes_used);
- free(super_bytes_used);
+ if (rawbytes) {
+ printf(" uuid: %s\n\tTotal devices %llu FS bytes used %llu\n",
+ uuidbuf, (unsigned long long)total,
+ (unsigned long long)device->super_bytes_used);
+ } else {
+ super_bytes_used = pretty_sizes(device->super_bytes_used);
+ printf(" uuid: %s\n\tTotal devices %llu FS bytes used %s\n",
+ uuidbuf, (unsigned long long)total, super_bytes_used);
+ free(super_bytes_used);
+ }
list_for_each(cur, &fs_devices->devices) {
char *total_bytes;
char *bytes_used;
device = list_entry(cur, struct btrfs_device, dev_list);
- total_bytes = pretty_sizes(device->total_bytes);
- bytes_used = pretty_sizes(device->bytes_used);
- printf("\tdevid %4llu size %s used %s path %s\n",
- (unsigned long long)device->devid,
- total_bytes, bytes_used, device->name);
- free(total_bytes);
- free(bytes_used);
+ if (rawbytes) {
+ printf("\tdevid %4llu size %llu used %llu path %s\n",
+ (unsigned long long)device->devid,
+ (unsigned long long)device->total_bytes,
+ (unsigned long long)device->bytes_used,
+ device->name);
+ }
+ else {
+ total_bytes = pretty_sizes(device->total_bytes);
+ bytes_used = pretty_sizes(device->bytes_used);
+ printf("\tdevid %4llu size %s used %s path %s\n",
+ (unsigned long long)device->devid,
+ total_bytes, bytes_used, device->name);
+ free(total_bytes);
+ free(bytes_used);
+ }
devs_found++;
}
if (devs_found < total) {
@@ -227,7 +261,7 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
}
static const char * const cmd_show_usage[] = {
- "btrfs filesystem show [--all-devices] [<uuid>|<label>]",
+ "btrfs filesystem show [--all-devices] [-b|--bytes] [<uuid>|<label>]",
"Show the structure of a filesystem",
"If no argument is given, structure of all present filesystems is shown.",
NULL
@@ -240,12 +274,21 @@ static int cmd_show(int argc, char **argv)
struct list_head *cur_uuid;
char *search = 0;
int ret;
+ int rawbytes = 0;
int checklist = 1;
int searchstart = 1;
- if( argc > 1 && !strcmp(argv[1],"--all-devices")){
- checklist = 0;
- searchstart += 1;
+ while (argc > searchstart) {
+ if (!strcmp(argv[searchstart], "--all-devices")) {
+ checklist = 0;
+ searchstart += 1;
+ } else if (!strcmp(argv[searchstart], "--bytes") ||
+ !strcmp(argv[searchstart], "-b")) {
+ rawbytes = 1;
+ searchstart += 1;
+ } else {
+ break;
+ }
}
if (check_argc_max(argc, searchstart + 1))
@@ -270,7 +313,7 @@ static int cmd_show(int argc, char **argv)
list);
if (search && uuid_search(fs_devices, search) == 0)
continue;
- print_one_uuid(fs_devices);
+ print_one_uuid(fs_devices, rawbytes);
}
printf("%s\n", BTRFS_BUILD_VERSION);
return 0;
--
1.7.10.4
next reply other threads:[~2013-02-01 9:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-01 9:59 Audrius Butkevicius [this message]
2013-02-01 10:30 ` [PATCH] btrfs-progs: add '-b' option to filesystem df and show Hugo Mills
2013-02-20 13:05 ` Audrius Butkevicius
2013-02-20 14:15 ` Mike Fleetwood
2013-02-20 14:54 ` Hugo Mills
2013-02-20 18:17 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130201095947.GA32445@gmail.com \
--to=audrius.butkevicius@elastichosts.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.