Size reporting of btrfs tool
cover Size reporting of btrfs tool
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).
Hugo.
Signature · 3 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
--- emacs: Eighty Megabytes And Constantly Swapping. --- PATCH 1/4 Update pretty-printer for different multiple systems.
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).
We default to binary sizes, maintaining the original behaviour, but print (e.g.) MiB to indicate that it's a power of 2^10.
--- 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
@@ -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_BINARY ); 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_BINARY ); + bytes_used =pretty_sizes (device->bytes_used,PRETTY_SIZE_BINARY );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
@@ -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_BINARY ); 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_BINARY ); + bytes_used =pretty_sizes (device->bytes_used,PRETTY_SIZE_BINARY );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_BINARY ); + used_bytes =pretty_sizes (sargs->spaces[i].used_bytes, +PRETTY_SIZE_BINARY );printf ("%s: total=%s, used=%s\n" , description, total_bytes, used_bytes); }
mkfs.c +2 -1
@@ -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
@@ -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
PATCH 2/4 Add an option to show ISO, binary or raw bytes counts using df.
In reply to [email protected]Change btrfs filesystem df to allow the user to control the scales used for sizes in the output.
--- btrfs.c | 5 +++-- btrfs_cmds.c | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 7 deletions(-)
btrfs.c +3 -2
@@ -87,9 +87,10 @@"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" + { do_df_filesystem, -1, +"filesystem df" ,"[-r|-b|-i] <path>\n" "Show space usage information for a mount point\n." +"-r, -b, -i for raw (bytes), binary or ISO sizes." }, { do_balance, 1,"filesystem balance" ,"<path>\n"
btrfs_cmds.c +32 -5
@@ -841,7 +841,36 @@u64 count =0 , i;int ret;int fd; -char *path = argv[1 ]; +char *path; +int format =PRETTY_SIZE_BINARY ; + + optind =1 ; +while (1 ) { +int c =getopt (nargs, argv,"rbi" ); +if (c <0 ) +break ; +switch (c) { +case 'r' : + format =PRETTY_SIZE_RAW ; +break ; +case 'b' : + format =PRETTY_SIZE_BINARY ; +break ; +case 'i' : + 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 ) {
@@ -914,10 +943,8 @@ written +=8 ; } - total_bytes =pretty_sizes (sargs->spaces[i].total_bytes, -PRETTY_SIZE_BINARY ); - used_bytes =pretty_sizes (sargs->spaces[i].used_bytes, -PRETTY_SIZE_BINARY ); + total_bytes =pretty_sizes (sargs->spaces[i].total_bytes, format); + used_bytes =pretty_sizes (sargs->spaces[i].used_bytes, format);printf ("%s: total=%s, used=%s\n" , description, total_bytes, used_bytes); }
Re: [patch 2/4] Add an option to show ISO, binary or raw bytes counts using df.
Quoted 8 lines · On 17/10/10 19:26, [email protected] wrote:
Change btrfs filesystem df to allow the user to control the scales used for sizes in the output.
Index:
btrfs-progs-unstable/btrfs.c
===================================================================
btrfs.c line 94
Quoted 10 lines
btrfs.c +3
-2@@ -87,9 +87,10 @@"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" + { do_df_filesystem, -1, +"filesystem df" ,"[-r|-b|-i]<path>\n" "Show space usage information for a mount point\n." +"-r, -b, -i for raw (bytes), binary or ISO sizes." },
This seems to eat up the short option namespace a bit quickly.
Fileutils uses different names as well, it may be convenient for users to match its names:
-h --human-readable powers of 2**10 -H --si powers of 1000
btrfs_cmds.c line 845
Quoted 13 lines
btrfs.c +0
-0{ do_balance,1 ,"filesystem balance" ,"<path>\n" Index:
btrfs-progs-unstable/btrfs_cmds.c
===================================================================btrfs_cmds.c +2
-1@@ -841,7 +841,36 @@u64 count =0 , i;int ret;int fd; -char *path = argv[1 ]; +char *path; +int format =PRETTY_SIZE_BINARY ;
Should the default not be to show sizes in bytes ("RAW")?
Frank
Re: [patch 2/4] Add an option to show ISO, binary or raw bytes counts using df.
Quoted 23 lines · Frank Kingswood
Quoted 8 lines · On 17/10/10 19:26, [email protected] wrote:
Change btrfs filesystem df to allow the user to control the scales used for sizes in the output.
Index:
btrfs-progs-unstable/btrfs.c
===================================================================btrfs.c line 94
Quoted 10 lines
btrfs.c +3
-2@@ -87,9 +87,10 @@"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" + { do_df_filesystem, -1, +"filesystem df" ,"[-r|-b|-i]<path>\n" "Show space usage information for a mount point\n." +"-r, -b, -i for raw (bytes), binary or ISO sizes." },This seems to eat up the short option namespace a bit quickly. Fileutils uses different names as well, it may be convenient for users to match its names:
Quoted 2 lines
-h --human-readable powers of 2**10 -H --si powers of 1000
Matching fileutils is probably a good idea. I'm happy to use -h and
-H.
Quoted 7 lines
Quoted 7 lines
btrfs.c +0
-0{ do_balance,1 ,"filesystem balance" ,"<path>\n" Index:
btrfs-progs-unstable/btrfs_cmds.c
===================================================================btrfs_cmds.c +0
-0@@ -841,7 +841,36 @@
Quoted 8 lines
btrfs_cmds.c line 845
Quoted 6 lines
btrfs_cmds.c +2
-1u64 count =0 , i;int ret;int fd; -char *path = argv[1 ]; +char *path; +int format =PRETTY_SIZE_BINARY ;Should the default not be to show sizes in bytes ("RAW")?
I was trying not to change the default behaviour at all, but with
-h/-H (and no switch for --raw), that would make sense. I'll re-roll the patches. (And update the man pages, as Goffredo asked).
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 don't like the look of it, I tell you." "Well, stop ---
looking at it, then." PATCH 3/4 Add an option to show ISO, binary or raw bytes counts using show.
In reply to [email protected]Change btrfs filesystem show to allow the user to control the scales used for sizes in the output.
--- btrfs.c | 5 +++-- btrfs_cmds.c | 42 +++++++++++++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 9 deletions(-)
btrfs.c +3 -2
@@ -83,9 +83,10 @@"will occupe all available space on the device." }, { do_show_filesystem, 999, -"filesystem show" ,"[<uuid>|<label>]\n" +"filesystem show" ,"[-r|-b|-i] [<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." +"is passed, info of all the btrfs filesystem are shown.\n" +"-r, -b, -i for raw (bytes), binary or ISO sizes." }, { do_df_filesystem, -1,"filesystem df" ,"[-r|-b|-i] <path>\n"
btrfs_cmds.c +35 -7
73 lines not on this page · raw message
PATCH 4/4 Add an option to show ISO, binary or raw bytes counts using btrfs-show.
In reply to [email protected]Change btrfs-show to allow the user to control the scales used for sizes in the output.
--- btrfs-show.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
btrfs-show.c +17 -7
@@ -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_BINARY ); + 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_BINARY ); - bytes_used =pretty_sizes (device->bytes_used,PRETTY_SIZE_BINARY ); + 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,7 +98,8 @@static void print_usage (void ) { -fprintf (stderr,"usage: btrfs-show [search label or device]\n" ); +fprintf (stderr,"usage: btrfs-show [-i|-b|-r] [search label or device]\n" ); +fprintf (stderr,"Options:\n -i, -b, -r: Show sizes in ISO, binary or raw form respectively.\n" );fprintf (stderr,"%s\n" ,BTRFS_BUILD_VERSION );exit (1 ); }
@@ -117,6 +117,7 @@char *search =NULL ;int ret;int option_index =0 ; +int format =PRETTY_SIZE_BINARY ;while (1 ) {int c;
@@ -125,6 +126,15 @@if (c <0 )break ;switch (c) { +case 'i' : + format =PRETTY_SIZE_ISO ; +break ; +case 'b' : + format =PRETTY_SIZE_BINARY ; +break ; +case 'r' : + format =PRETTY_SIZE_RAW ; +break ;default :print_usage (); }
@@ -144,7 +154,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 ;