Skip to contentSkip to conversation

Size reporting in userspace tools

PATCH Superseded Hugo Mills 2 participants 7 messages Oct 21, 2010 – Oct 22, 2010 Btrfs file system

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Hugo Mills

author
#0 lore raw

v2 cover Size reporting in userspace tools

While playing around with resizing volumes recently, I realised
that I didn't know whether btrfs fi show and btrfs fi df reported sizes in ISO (e.g. powers of 10^3) units, as they appear to from the labels they use, or in binary (powers of 2^10) units. Also, a mere three significant figures is somewhat less than I'm comfortable with if I'm about to resize the containing block device downwards.

This patch series adds the ability to pick which scale is used for
show and df, and labels the amounts properly (e.g. MB for ISO, MiB for binary units).

I've incorporated Frank's suggestion of defaulting to raw, and
matching coreutils' use of -h and -H. I've also updated the man pages as requested by Goffredo.

Hugo.

Signature · 4 lines
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
   --- I spent most of my money on drink, women and fast cars. The ---   
                      rest I wasted.  -- James Hunt                      
author
#1 lore raw

PATCH v2 1/4 Update pretty-printer for different systems of counting multiples.

Make the pretty-printer for data sizes capable of printing in ISO (powers of 10^3), binary (powers of 2^10) or raw (a simple byte count).

---
 btrfs-show.c |    7 ++++---
 btrfs_cmds.c |   13 ++++++++-----
 mkfs.c       |    3 ++-
 utils.c      |   48 +++++++++++++++++++++++++++++++++---------------
 utils.h      |    7 ++++++-
 5 files changed, 53 insertions(+), 25 deletions(-)
btrfs-show.c +4 -3
Index: btrfs-progs-unstable/btrfs-show.c
===================================================================
@@ -69,7 +69,8 @@
 	else
 		printf("Label: none ");
 
-	super_bytes_used = pretty_sizes(device->super_bytes_used);
+	super_bytes_used = pretty_sizes(device->super_bytes_used,
+									PRETTY_SIZE_RAW);
 
 	total = device->total_devs;
 	printf(" uuid: %s\n\tTotal devices %llu FS bytes used %s\n", uuidbuf,
@@ -81,8 +82,8 @@
 		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);
+		total_bytes = pretty_sizes(device->total_bytes, PRETTY_SIZE_RAW);
+		bytes_used = pretty_sizes(device->bytes_used, PRETTY_SIZE_RAW);
 		printf("\tdevid %4llu size %s used %s path %s\n",
 		       (unsigned long long)device->devid,
 		       total_bytes, bytes_used, device->name);
btrfs_cmds.c +8 -5
Index: btrfs-progs-unstable/btrfs_cmds.c
===================================================================
@@ -634,7 +634,8 @@
 	else
 		printf("Label: none ");
 
-	super_bytes_used = pretty_sizes(device->super_bytes_used);
+	super_bytes_used = pretty_sizes(device->super_bytes_used,
+									PRETTY_SIZE_RAW);
 
 	total = device->total_devs;
 	printf(" uuid: %s\n\tTotal devices %llu FS bytes used %s\n", uuidbuf,
@@ -646,8 +647,8 @@
 		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);
+		total_bytes = pretty_sizes(device->total_bytes, PRETTY_SIZE_RAW);
+		bytes_used = pretty_sizes(device->bytes_used, PRETTY_SIZE_RAW);
 		printf("\tdevid %4llu size %s used %s path %s\n",
 		       (unsigned long long)device->devid,
 		       total_bytes, bytes_used, device->name);
@@ -913,8 +914,10 @@
 			written += 8;
 		}
 
-		total_bytes = pretty_sizes(sargs->spaces[i].total_bytes);
-		used_bytes = pretty_sizes(sargs->spaces[i].used_bytes);
+		total_bytes = pretty_sizes(sargs->spaces[i].total_bytes,
+									PRETTY_SIZE_RAW);
+		used_bytes = pretty_sizes(sargs->spaces[i].used_bytes,
+									PRETTY_SIZE_RAW);
 		printf("%s: total=%s, used=%s\n", description, total_bytes,
 		       used_bytes);
 	}
mkfs.c +2 -1
Index: btrfs-progs-unstable/mkfs.c
===================================================================
@@ -524,7 +524,8 @@
 	printf("fs created label %s on %s\n\tnodesize %u leafsize %u "
 	    "sectorsize %u size %s\n",
 	    label, first_file, nodesize, leafsize, sectorsize,
-	    pretty_sizes(btrfs_super_total_bytes(&root->fs_info->super_copy)));
+		pretty_sizes(btrfs_super_total_bytes(&root->fs_info->super_copy),
+			PRETTY_SIZE_BINARY));
 
 	printf("%s\n", BTRFS_BUILD_VERSION);
 	btrfs_commit_transaction(trans, root);
utils.c +33 -15

63 lines not on this page · raw message

utils.h +6 -1
Index: btrfs-progs-unstable/utils.h
===================================================================
@@ -21,6 +21,11 @@
 
 #define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024)
 
+/* Constants for pretty_size() format parameter */
+#define PRETTY_SIZE_RAW 0
+#define PRETTY_SIZE_ISO 1
+#define PRETTY_SIZE_BINARY 2
+
 int make_btrfs(int fd, const char *device, const char *label,
 	       u64 blocks[6], u64 num_bytes, u32 nodesize,
 	       u32 leafsize, u32 sectorsize, u32 stripesize);
@@ -39,5 +44,5 @@
 int check_mounted(const char *devicename);
 int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
 				 int super_offset);
-char *pretty_sizes(u64 size);
+char *pretty_sizes(u64 size, int format);
 #endif
Signature · 4 lines
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
   --- I spent most of my money on drink, women and fast cars. The ---   
                      rest I wasted.  -- James Hunt                      
author
#2 lore raw

PATCH v2 2/4 Add an option to show ISO, binary or raw bytes counts using df.

In reply to Hugo Mills

Change btrfs filesystem df to allow the user to control the scales used for sizes in the output.

---
 btrfs.c        |    6 +++---
 btrfs_cmds.c   |   42 ++++++++++++++++++++++++++++++++++++------
 man/btrfs.8.in |    8 ++++++++
 3 files changed, 47 insertions(+), 9 deletions(-)
btrfs.c +3 -3
Index: btrfs-progs-unstable/btrfs.c
===================================================================
@@ -87,9 +87,9 @@
 		"Show the info of a btrfs filesystem. If no <uuid> or <label>\n"
 		"is passed, info of all the btrfs filesystem are shown."
 	},
-	{ do_df_filesystem, 1,
-	  "filesystem df", "<path>\n"
-		"Show space usage information for a mount point\n."
+	{ do_df_filesystem, -1,
+	  "filesystem df", "[options] <path>\n"
+		"Show space usage information for a mount point."
 	},
 	{ do_balance, 1,
 	  "filesystem balance", "<path>\n"
btrfs_cmds.c +36 -6

72 lines not on this page · raw message

man/btrfs.8.in +8 -0
Index: btrfs-progs-unstable/man/btrfs.8.in
===================================================================
@@ -21,6 +21,8 @@
 .PP
 \fBbtrfs\fP \fBfilesystem resize\fP\fI [+/\-]<size>[gkm]|max <filesystem>\fP
 .PP
+\fBbtrfs\fP \fBfilesystem df\fP\fI [options] <path>\fP
+.PP
 \fBbtrfs\fP \fBdevice scan\fP\fI [<device> [<device>..]]\fP
 .PP
 \fBbtrfs\fP \fBdevice show\fP\fI <dev>|<label> [<dev>|<label>...]\fP
@@ -143,6 +145,12 @@
 passed, \fBbtrfs\fR show info of all the btrfs filesystem.
 .TP
 
+\fBfilesystem df\fR [options] <path>\fR
+Show the amount of space used on this filesystem, in bytes. Options:
+-h, --human-readable Use powers of 2^10 (1024) to report sizes.
+-H, --si Use powers of 10^3 (1000) to report sizes, in SI multiples.
+.TP
+
 \fBdevice balance\fR \fI<path>\fR
 Balance the chunks of the filesystem identified by \fI<path>\fR
 across the devices.
Signature · 4 lines
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
   --- I spent most of my money on drink, women and fast cars. The ---   
                      rest I wasted.  -- James Hunt                      
#3 lore raw

Re: [patch v2 2/4] Add an option to show ISO, binary or raw bytes counts using df.

Quoted 15 lines · Hugo Mills

Change btrfs filesystem df to allow the user to control the scales used for sizes in the output.

---
 btrfs.c        |    6 +++---
 btrfs_cmds.c   |   42 ++++++++++++++++++++++++++++++++++++------
 man/btrfs.8.in |    8 ++++++++
 3 files changed, 47 insertions(+), 9 deletions(-)

Index: btrfs-progs-unstable/btrfs.c
===================================================================

btrfs.c line 87

Quoted 1 line
btrfs.c +0 -0
@@ -87,9 +87,9 @@
 		"Show the info of a btrfs filesystem. If no <uuid> or 

<label>\n"

btrfs.c line 93

Quoted 9 lines
btrfs.c +3 -3
 		"is passed, info of all the btrfs filesystem are shown."
 	},
-	{ do_df_filesystem, 1,
-	  "filesystem df", "<path>\n"
-		"Show space usage information for a mount point\n."
+	{ do_df_filesystem, -1,
+	  "filesystem df", "[options] <path>\n"
+		"Show space usage information for a mount point."
 	},

Please, explicit the option on the "short help" like

Quoted 8 lines
btrfs.c +1 -0
+	  "filesystem df", "[-h|-H|--si|--human-readable] <path>\n"
 
 
 	{ do_balance, 1,
 	  "filesystem balance", "<path>\n"

Index: btrfs-progs-unstable/btrfs_cmds.c
===================================================================
--- btrfs-progs-unstable.orig/btrfs_cmds.c 2010-10-20 19:19:20.000000000

+0100

Quoted 65 lines

+++ btrfs-progs-unstable/btrfs_cmds.c 2010-10-20 19:58:48.000000000 +0100

btrfs.c +34 -2
@@ -14,7 +14,6 @@
  * Boston, MA 021110-1307, USA.
  */
 
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -28,6 +27,7 @@
 #include <limits.h>
 #include <uuid/uuid.h>
 #include <ctype.h>
+#include <getopt.h>
 
 #undef ULONG_MAX
 
@@ -835,13 +835,45 @@
 	return 0;
 }
 
+const struct option df_options[] = {
+	{ "human-readable", 0, NULL, 'h' },
+	{ "si", 0, NULL, 'H' },
+	{ NULL, 0, NULL, 0 }
+};
+
 int do_df_filesystem(int nargs, char **argv)
 {
 	struct btrfs_ioctl_space_args *sargs;
 	u64 count = 0, i;
 	int ret;
 	int fd;
-	char *path = argv[1];
+	char *path;
+	int format = PRETTY_SIZE_RAW;
+
+	optind = 1;
+	while(1) {
+		int c = getopt_long(nargs, argv, "hH", df_options, NULL);
+		if (c < 0)
+			break;
+		switch(c) {
+		case 'h':
+			format = PRETTY_SIZE_BINARY;
+			break;
+		case 'H':
+			format = PRETTY_SIZE_ISO;
+			break;
+		default:
+			fprintf(stderr, "Invalid arguments for df\n");
+			free(argv);
+			return 1;
+		}
+	}
+	if (nargs - optind != 1) {
+		fprintf(stderr, "No path given for df\n");
+		free(argv);
+		return 1;
+	}
+	path = argv[optind];
 
 	fd = open_file_or_dir(path);
 	if (fd < 0) {

btrfs.c line 918

Quoted 5 lines
btrfs.c +0 -2
@@ -914,10 +946,8 @@
 			written += 8;
 		}
 
-		total_bytes = pretty_sizes(sargs->spaces[i].total_bytes,
-									

PRETTY_SIZE_RAW);

btrfs.c line 920

Quoted 2 lines
btrfs.c +0 -2
-		used_bytes = pretty_sizes(sargs->spaces[i].used_bytes,
-									

PRETTY_SIZE_RAW);

btrfs.c line 949

Quoted 1 line
btrfs.c +1 -0
+		total_bytes = pretty_sizes(sargs->spaces[i].total_bytes, 

format);

btrfs.c line 950

Quoted 1 line
btrfs.c +1 -0
+		used_bytes = pretty_sizes(sargs->spaces[i].used_bytes, 

format);

Quoted 6 lines
btrfs.c +0 -0
 		printf("%s: total=%s, used=%s\n", description, total_bytes,
 		       used_bytes);
 	}

Index: btrfs-progs-unstable/man/btrfs.8.in
===================================================================
--- btrfs-progs-unstable.orig/man/btrfs.8.in 2010-10-20 19:23:36.000000000

+0100

Quoted 1 line

+++ btrfs-progs-unstable/man/btrfs.8.in 2010-10-20 19:28:14.000000000

+0100

btrfs.c line 22

Quoted 3 lines
btrfs.c +0 -0
@@ -21,6 +21,8 @@
 .PP
 \fBbtrfs\fP \fBfilesystem resize\fP\fI [+/\-]<size>[gkm]|max 

<filesystem>\fP

btrfs.c line 25

Quoted 3 lines
btrfs.c +2 -0
 .PP
+\fBbtrfs\fP \fBfilesystem df\fP\fI [options] <path>\fP
+.PP

The same here

btrfs.c line 148

Quoted 8 lines
btrfs.c +1 -0
 \fBbtrfs\fP \fBdevice scan\fP\fI [<device> [<device>..]]\fP
 .PP
 \fBbtrfs\fP \fBdevice show\fP\fI <dev>|<label> [<dev>|<label>...]\fP
@@ -143,6 +145,12 @@
 passed, \fBbtrfs\fR show info of all the btrfs filesystem.
 .TP
 
+\fBfilesystem df\fR [options] <path>\fR

The same here

Quoted 20 lines
btrfs.c +5 -0
+Show the amount of space used on this filesystem, in bytes. Options:
+-h, --human-readable Use powers of 2^10 (1024) to report sizes.
+-H, --si Use powers of 10^3 (1000) to report sizes, in SI multiples.
+.TP
+
 \fBdevice balance\fR \fI<path>\fR
 Balance the chunks of the filesystem identified by \fI<path>\fR
 across the devices.
Signature · 10 lines
-- 
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
   --- I spent most of my money on drink, women and fast cars. The ---   
                      rest I wasted.  -- James Hunt                      

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <[email protected]>
Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512
author
#4 lore raw

PATCH v2 3/4 Add an option to show ISO, binary or raw bytes counts using show.

In reply to Hugo Mills

Change btrfs filesystem show to allow the user to control the scales used for sizes in the output.

---
 btrfs.c        |    2 +-
 btrfs_cmds.c   |   45 ++++++++++++++++++++++++++++++++++++++-------
 man/btrfs.8.in |   10 ++++++++++
 3 files changed, 49 insertions(+), 8 deletions(-)
btrfs.c +1 -1
Index: btrfs-progs-unstable/btrfs.c
===================================================================
@@ -83,7 +83,7 @@
 		"will occupe all available space on the device."
 	},
 	{ do_show_filesystem, 999,
-	  "filesystem show", "[<uuid>|<label>]\n"
+	  "filesystem show", "[options] [<uuid>|<label>]\n"
 		"Show the info of a btrfs filesystem. If no <uuid> or <label>\n"
 		"is passed, info of all the btrfs filesystem are shown."
 	},
btrfs_cmds.c +38 -7

81 lines not on this page · raw message

man/btrfs.8.in +10 -0
Index: btrfs-progs-unstable/man/btrfs.8.in
===================================================================
@@ -23,6 +23,8 @@
 .PP
 \fBbtrfs\fP \fBfilesystem df\fP\fI [options] <path>\fP
 .PP
+\fBbtrfs\fP \fBfilesystem show\fP\fI [options] [<uuid>|<label>]\fP
+.PP
 \fBbtrfs\fP \fBdevice scan\fP\fI [<device> [<device>..]]\fP
 .PP
 \fBbtrfs\fP \fBdevice show\fP\fI <dev>|<label> [<dev>|<label>...]\fP
@@ -151,6 +153,14 @@
 -H, --si Use powers of 10^3 (1000) to report sizes, in SI multiples.
 .TP
 
+\fBfilesystem show\fR [options] [<uuid>|<label>]\fR
+Show the usage of each device in the btrfs filesystem with the given
+uuid or label, or all filesystems if no uuid or label is provided.
+Options:
+-h, --human-readable Use powers of 2^10 (1024) to report sizes.
+-H, --si Use powers of 10^3 (1000) to report sizes, in SI multiples.
+.TP
+
 \fBdevice balance\fR \fI<path>\fR
 Balance the chunks of the filesystem identified by \fI<path>\fR
 across the devices.
Signature · 4 lines
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
   --- I spent most of my money on drink, women and fast cars. The ---   
                      rest I wasted.  -- James Hunt                      
#5 lore raw

Re: [patch v2 3/4] Add an option to show ISO, binary or raw bytes counts using show.

Quoted 15 lines · Hugo Mills

Change btrfs filesystem show to allow the user to control the scales used for sizes in the output.

---
 btrfs.c        |    2 +-
 btrfs_cmds.c   |   45 ++++++++++++++++++++++++++++++++++++++-------
 man/btrfs.8.in |   10 ++++++++++
 3 files changed, 49 insertions(+), 8 deletions(-)

Index: btrfs-progs-unstable/btrfs.c
===================================================================

btrfs.c line 86

Quoted 5 lines
btrfs.c +1 -1
@@ -83,7 +83,7 @@
 		"will occupe all available space on the device."
 	},
 	{ do_show_filesystem, 999,
-	  "filesystem show", "[<uuid>|<label>]\n"
+	  "filesystem show", "[options] [<uuid>|<label>]\n"

Please put explicitly the option like my other comments

btrfs.c line 87

Quoted 1 line
btrfs.c +0 -0
 		"Show the info of a btrfs filesystem. If no <uuid> or 

<label>\n"

Quoted 5 lines
btrfs.c +0 -0
 		"is passed, info of all the btrfs filesystem are shown."
 	},

Index: btrfs-progs-unstable/btrfs_cmds.c
===================================================================
--- btrfs-progs-unstable.orig/btrfs_cmds.c 2010-10-20 20:03:37.000000000

+0100

Quoted 11 lines

+++ btrfs-progs-unstable/btrfs_cmds.c 2010-10-20 20:08:00.000000000 +0100

btrfs.c +1 -1
@@ -617,7 +617,7 @@
 	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 format)
 {
 	char uuidbuf[37];
 	struct list_head *cur;

btrfs.c line 638

Quoted 5 lines
btrfs.c +0 -2
@@ -634,8 +634,7 @@
 	else
 		printf("Label: none ");
 
-	super_bytes_used = pretty_sizes(device->super_bytes_used,
-									

PRETTY_SIZE_RAW);

btrfs.c line 650

Quoted 9 lines
btrfs.c +1 -1
+	super_bytes_used = pretty_sizes(device->super_bytes_used, format);
 
 	total = device->total_devs;
 	printf(" uuid: %s\n\tTotal devices %llu FS bytes used %s\n", uuidbuf,
@@ -647,8 +646,8 @@
 		char *total_bytes;
 		char *bytes_used;
 		device = list_entry(cur, struct btrfs_device, dev_list);
-		total_bytes = pretty_sizes(device->total_bytes, 

PRETTY_SIZE_RAW);

btrfs.c line 651

Quoted 1 line
btrfs.c +0 -1
-		bytes_used = pretty_sizes(device->bytes_used, 

PRETTY_SIZE_RAW);

Quoted 61 lines
btrfs.c +36 -2
+		total_bytes = pretty_sizes(device->total_bytes, format);
+		bytes_used = pretty_sizes(device->bytes_used, format);
 		printf("\tdevid %4llu size %s used %s path %s\n",
 		       (unsigned long long)device->devid,
 		       total_bytes, bytes_used, device->name);
@@ -662,13 +661,45 @@
 	printf("\n");
 }
 
+const struct option show_options[] = {
+	{ "human-readable", 0, NULL, 'h' },
+	{ "si", 0, NULL, 'H' },
+	{ NULL, 0, NULL, 0 }
+};
+
 int do_show_filesystem(int argc, char **argv)
 {
 	struct list_head *all_uuids;
 	struct btrfs_fs_devices *fs_devices;
 	struct list_head *cur_uuid;
-	char *search = argv[1];
+	char *search;
 	int ret;
+	int format = PRETTY_SIZE_RAW;
+
+	optind = 1;
+	while(1) {
+		int c = getopt_long(argc, argv, "hH", show_options, NULL);
+		if (c < 0)
+			break;
+		switch(c) {
+		case 'h':
+			format = PRETTY_SIZE_BINARY;
+			break;
+		case 'H':
+			format = PRETTY_SIZE_ISO;
+			break;
+		default:
+			fprintf(stderr, "Invalid arguments for show\n");
+			free(argv);
+			return 1;
+		}
+	}
+	if (argc - optind > 1) {
+		fprintf(stderr, "Too many arguments for show\n");
+		free(argv);
+		return 1;
+	}
+	search = argv[optind];
 
 	ret = btrfs_scan_one_dir("/dev", 0);
 	if (ret){
@@ -682,7 +713,7 @@
 					list);
 		if (search && uuid_search(fs_devices, search) == 0)
 			continue;
-		print_one_uuid(fs_devices);
+		print_one_uuid(fs_devices, format);
 	}
 	printf("%s\n", BTRFS_BUILD_VERSION);
 	return 0;
Quoted 3 lines

Index: btrfs-progs-unstable/man/btrfs.8.in
===================================================================
--- btrfs-progs-unstable.orig/man/btrfs.8.in 2010-10-20 20:03:53.000000000

+0100

Quoted 1 line

+++ btrfs-progs-unstable/man/btrfs.8.in 2010-10-20 20:08:15.000000000

+0100

btrfs.c line 27

Quoted 6 lines
btrfs.c +2 -0
@@ -23,6 +23,8 @@
 .PP
 \fBbtrfs\fP \fBfilesystem df\fP\fI [options] <path>\fP
 .PP
+\fBbtrfs\fP \fBfilesystem show\fP\fI [options] [<uuid>|<label>]\fP
+.PP

Same here

btrfs.c line 156

Quoted 8 lines
Quoted 1 line

\fBbtrfs\fP \fBdevice scan\fP\fI [<device> [<device>..]]\fP

.PP
\fBbtrfs\fP \fBdevice show\fP\fI <dev>|<label> [<dev>|<label>...]\fP

btrfs.c +1 -0
@@ -151,6 +153,14 @@
 -H, --si Use powers of 10^3 (1000) to report sizes, in SI multiples.
 .TP
 
+\fBfilesystem show\fR [options] [<uuid>|<label>]\fR

Same here

Quoted 22 lines
btrfs.c +7 -0
+Show the usage of each device in the btrfs filesystem with the given
+uuid or label, or all filesystems if no uuid or label is provided.
+Options:
+-h, --human-readable Use powers of 2^10 (1024) to report sizes.
+-H, --si Use powers of 10^3 (1000) to report sizes, in SI multiples.
+.TP
+
 \fBdevice balance\fR \fI<path>\fR
 Balance the chunks of the filesystem identified by \fI<path>\fR
 across the devices.
Signature · 10 lines
-- 
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
   --- I spent most of my money on drink, women and fast cars. The ---   
                      rest I wasted.  -- James Hunt                      

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <[email protected]>
Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512
author
#6 lore raw

PATCH v2 4/4 Add an option to show ISO, binary or raw bytes counts using btrfs-show.

In reply to Hugo Mills

Change btrfs-show to allow the user to control the scales used for sizes in the output.

---
 btrfs-show.c        |   27 +++++++++++++++++++--------
 man/btrfs-show.8.in |   10 ++++++++--
 2 files changed, 27 insertions(+), 10 deletions(-)
btrfs-show.c +19 -8
Index: btrfs-progs-unstable/btrfs-show.c
===================================================================
@@ -52,7 +52,7 @@
 	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 format)
 {
 	char uuidbuf[37];
 	struct list_head *cur;
@@ -69,8 +69,7 @@
 	else
 		printf("Label: none ");
 
-	super_bytes_used = pretty_sizes(device->super_bytes_used,
-									PRETTY_SIZE_RAW);
+	super_bytes_used = pretty_sizes(device->super_bytes_used, format);
 
 	total = device->total_devs;
 	printf(" uuid: %s\n\tTotal devices %llu FS bytes used %s\n", uuidbuf,
@@ -82,8 +81,8 @@
 		char *total_bytes;
 		char *bytes_used;
 		device = list_entry(cur, struct btrfs_device, dev_list);
-		total_bytes = pretty_sizes(device->total_bytes, PRETTY_SIZE_RAW);
-		bytes_used = pretty_sizes(device->bytes_used, PRETTY_SIZE_RAW);
+		total_bytes = pretty_sizes(device->total_bytes, format);
+		bytes_used = pretty_sizes(device->bytes_used, format);
 		printf("\tdevid %4llu size %s used %s path %s\n",
 		       (unsigned long long)device->devid,
 		       total_bytes, bytes_used, device->name);
@@ -99,13 +98,18 @@
 
 static void print_usage(void)
 {
-	fprintf(stderr, "usage: btrfs-show [search label or device]\n");
+	fprintf(stderr, "usage: btrfs-show [options] [search label or device]\n");
+	fprintf(stderr, "Options:\n");
+	fprintf(stderr, "\t-h, --human-readable\tShow sizes in powers of 2^10.\n");
+	fprintf(stderr, "\t-s, --si\t\tShow sizes in powers of 10^3 (SI multiples).\n");
 	fprintf(stderr, "%s\n", BTRFS_BUILD_VERSION);
 	exit(1);
 }
 
 static struct option long_options[] = {
 	/* { "byte-count", 1, NULL, 'b' }, */
+	{ "human-readable", 0, NULL, 'h' },
+	{ "si", 0, NULL, 'H' },
 	{ 0, 0, 0, 0}
 };
 
@@ -117,14 +121,21 @@
 	char *search = NULL;
 	int ret;
 	int option_index = 0;
+	int format = PRETTY_SIZE_RAW;
 
 	while(1) {
 		int c;
-		c = getopt_long(ac, av, "", long_options,
+		c = getopt_long(ac, av, "hH", long_options,
 				&option_index);
 		if (c < 0)
 			break;
 		switch(c) {
+			case 'H':
+				format = PRETTY_SIZE_ISO;
+				break;
+			case 'h':
+				format = PRETTY_SIZE_BINARY;
+				break;
 			default:
 				print_usage();
 		}
@@ -144,7 +155,7 @@
 					list);
 		if (search && uuid_search(fs_devices, search) == 0)
 			continue;
-		print_one_uuid(fs_devices);
+		print_one_uuid(fs_devices, format);
 	}
 	printf("%s\n", BTRFS_BUILD_VERSION);
 	return 0;
man/btrfs-show.8.in +8 -2
Index: btrfs-progs-unstable/man/btrfs-show.8.in
===================================================================
@@ -2,13 +2,19 @@
 .SH NAME
 btrfs-show \- scan the /dev directory for btrfs partitions and print results.
 .SH SYNOPSIS
-.B btrfs-show
+.B btrfs-show [options]
 .SH DESCRIPTION
 .B btrfs-show
 is used to scan the /dev directory for btrfs partitions and display brief
 information such as lable, uuid, etc of each btrfs partition.
 .SH OPTIONS
-none
+.TP
+\fB\-h\fR, \fB\-\-human\-readable\fR
+Show values in multiples of 2^10.
+.TP
+\fB\-H\fR, \fB\-\-si\fR
+Show values in multiples of 10^3 (SI multiples).
+
 .SH AVAILABILITY
 .B btrfs-show
 is part of btrfs-progs. Btrfs is currently under heavy development,
Signature · 4 lines
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
   --- I spent most of my money on drink, women and fast cars. The ---   
                      rest I wasted.  -- James Hunt