Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Goffredo Baroncelli <kreijack@libero.it>
To: Hugo Mills <hugo@carfax.org.uk>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [patch v2 2/4] Add an option to show ISO, binary or raw bytes counts using df.
Date: Fri, 22 Oct 2010 09:55:44 +0200	[thread overview]
Message-ID: <201010220955.44932.kreijack@libero.it> (raw)
In-Reply-To: <20101021190202.961098322@carfax.org.uk>

On Thursday, 21 October, 2010, Hugo Mills wrote:
> Change btrfs filesystem df to allow the user to control the scales
> used for sizes in the output.
> 
> Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
> ---
>  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-progs-unstable.orig/btrfs.c	2010-10-20 19:12:18.000000000 +0100
> +++ btrfs-progs-unstable/btrfs.c	2010-10-20 19:48:34.000000000 +0100
> @@ -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."
>  	},

Please, explicit the option on the "short help" like
> +	  "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
> +++ btrfs-progs-unstable/btrfs_cmds.c	2010-10-20 19:58:48.000000000 +0100
> @@ -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) {
> @@ -914,10 +946,8 @@
>  			written += 8;
>  		}
>  
> -		total_bytes = pretty_sizes(sargs->spaces[i].total_bytes,
> -									
PRETTY_SIZE_RAW);
> -		used_bytes = pretty_sizes(sargs->spaces[i].used_bytes,
> -									
PRETTY_SIZE_RAW);
> +		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);
>  	}
> Index: btrfs-progs-unstable/man/btrfs.8.in
> ===================================================================
> --- btrfs-progs-unstable.orig/man/btrfs.8.in	2010-10-20 19:23:36.000000000 
+0100
> +++ btrfs-progs-unstable/man/btrfs.8.in	2010-10-20 19:28:14.000000000 
+0100
> @@ -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

The same here

>  \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

> +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.
> 
> -- 
> === 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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack@inwind.it>
Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512

  reply	other threads:[~2010-10-22  7:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-21 19:01 [patch v2 0/4] Size reporting in userspace tools Hugo Mills
2010-10-21 19:01 ` [patch v2 1/4] Update pretty-printer for different systems of counting multiples Hugo Mills
2010-10-21 19:01 ` [patch v2 2/4] Add an option to show ISO, binary or raw bytes counts using df Hugo Mills
2010-10-22  7:55   ` Goffredo Baroncelli [this message]
2010-10-21 19:01 ` [patch v2 3/4] Add an option to show ISO, binary or raw bytes counts using show Hugo Mills
2010-10-22  7:57   ` Goffredo Baroncelli
2010-10-21 19:01 ` [patch v2 4/4] Add an option to show ISO, binary or raw bytes counts using btrfs-show Hugo Mills

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=201010220955.44932.kreijack@libero.it \
    --to=kreijack@libero.it \
    --cc=hugo@carfax.org.uk \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox