* [PATCH 0/2] Support for small units in display
@ 2012-07-09 17:02 Pierre Carrier
2012-07-09 17:02 ` [PATCH 1/2] utils.c: fix sizes in B & malloc in pretty_sizes Pierre Carrier
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Pierre Carrier @ 2012-07-09 17:02 UTC (permalink / raw)
To: linux-btrfs; +Cc: Pierre Carrier
Allow better inspection of sizes using an environment variable.
Not pretty, but convenient to determine the exact size of a filesystem,
eg when resizing an underlying partition or LUN.
Pierre Carrier (2):
utils.c: fix sizes in B & malloc in pretty_sizes
utils.c: offer to limit divisions in pretty_sizes
utils.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
--
1.7.11.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/2] utils.c: fix sizes in B & malloc in pretty_sizes
2012-07-09 17:02 [PATCH 0/2] Support for small units in display Pierre Carrier
@ 2012-07-09 17:02 ` Pierre Carrier
2012-07-09 17:29 ` Pierre Carrier
2012-07-09 17:02 ` [PATCH 2/2] utils.c: offer to limit divisions " Pierre Carrier
2012-07-09 17:27 ` [PATCH 0/2] Support for small units in display Pierre Carrier
2 siblings, 1 reply; 9+ messages in thread
From: Pierre Carrier @ 2012-07-09 17:02 UTC (permalink / raw)
To: linux-btrfs; +Cc: Pierre Carrier
Before, sizes below 1KB where displayed in KB,
but without a unit.
Signed-off-by: Pierre Carrier <pierre@spotify.com>
diff --git a/utils.c b/utils.c
index aade9e2..dde0513 100644
--- a/utils.c
+++ b/utils.c
@@ -1108,13 +1108,20 @@ char *pretty_sizes(u64 size)
size /= 1024;
num_divs++;
}
- if (num_divs == 0)
+ if (num_divs == 0) {
num_divs = 1;
+ fraction = (float)fract_size;
+ } else
+ fraction = (float)fract_size / 1024;
+
if (num_divs > ARRAY_SIZE(size_strs))
return NULL;
- fraction = (float)fract_size / 1024;
+
pretty = malloc(pretty_len);
+ if (!pretty)
+ return NULL;
+
snprintf(pretty, pretty_len, "%.2f%s", fraction, size_strs[num_divs-1]);
return pretty;
}
--
1.7.11.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 1/2] utils.c: fix sizes in B & malloc in pretty_sizes
2012-07-09 17:02 ` [PATCH 1/2] utils.c: fix sizes in B & malloc in pretty_sizes Pierre Carrier
@ 2012-07-09 17:29 ` Pierre Carrier
2012-07-17 12:43 ` David Sterba
0 siblings, 1 reply; 9+ messages in thread
From: Pierre Carrier @ 2012-07-09 17:29 UTC (permalink / raw)
To: linux-btrfs; +Cc: Pierre Carrier
Before, sizes below 1KB are still displayed in KB,
but without a unit.
Signed-off-by: Pierre Carrier <pierre@spotify.com>
diff --git a/utils.c b/utils.c
index aade9e2..937e763 100644
--- a/utils.c
+++ b/utils.c
@@ -1108,13 +1108,20 @@ char *pretty_sizes(u64 size)
size /= 1024;
num_divs++;
}
- if (num_divs == 0)
+ if (num_divs <= 1) {
num_divs = 1;
+ fraction = (float)fract_size;
+ } else
+ fraction = (float)fract_size / 1024;
+
if (num_divs > ARRAY_SIZE(size_strs))
return NULL;
- fraction = (float)fract_size / 1024;
+
pretty = malloc(pretty_len);
+ if (!pretty)
+ return NULL;
+
snprintf(pretty, pretty_len, "%.2f%s", fraction, size_strs[num_divs-1]);
return pretty;
}
--
1.7.11.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/2] utils.c: offer to limit divisions in pretty_sizes
2012-07-09 17:02 [PATCH 0/2] Support for small units in display Pierre Carrier
2012-07-09 17:02 ` [PATCH 1/2] utils.c: fix sizes in B & malloc in pretty_sizes Pierre Carrier
@ 2012-07-09 17:02 ` Pierre Carrier
2012-07-09 17:30 ` Pierre Carrier
2012-07-09 17:27 ` [PATCH 0/2] Support for small units in display Pierre Carrier
2 siblings, 1 reply; 9+ messages in thread
From: Pierre Carrier @ 2012-07-09 17:02 UTC (permalink / raw)
To: linux-btrfs; +Cc: Pierre Carrier
Dirty hack to allow inspection of sizes in lower units.
Useful to know the minimum size a partition shoud be resized to
after a 'btrfs filesystem resize'.
Label: 'home' uuid: 10453c4c-1c5b-4df5-b4a5-43a7f377430a
Total devices 1 FS bytes used 42.80GB
devid 1 size 62.16GB used 62.16GB path /dev/sda5
Label: 'home' uuid: 10453c4c-1c5b-4df5-b4a5-43a7f377430a
Total devices 1 FS bytes used 44884524.00KB
devid 1 size 65182236.00KB used 65182208.00KB path /dev/sda5
Signed-off-by: Pierre Carrier <pierre@spotify.com>
diff --git a/utils.c b/utils.c
index dde0513..e660799 100644
--- a/utils.c
+++ b/utils.c
@@ -1096,13 +1096,18 @@ static char *size_strs[] = { "", "KB", "MB", "GB", "TB",
char *pretty_sizes(u64 size)
{
int num_divs = 0;
+ int max_divs = INT_MAX;
int pretty_len = 16;
u64 last_size = size;
u64 fract_size = size;
float fraction;
char *pretty;
+ char *max_divs_s;
- while(size > 0) {
+ if (max_divs_s = getenv("MAX_DIVS"))
+ max_divs = atoi(max_divs_s);
+
+ while(size > 0 && num_divs < max_divs) {
fract_size = last_size;
last_size = size;
size /= 1024;
--
1.7.11.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/2] utils.c: offer to limit divisions in pretty_sizes
2012-07-09 17:02 ` [PATCH 2/2] utils.c: offer to limit divisions " Pierre Carrier
@ 2012-07-09 17:30 ` Pierre Carrier
2012-07-17 12:58 ` David Sterba
0 siblings, 1 reply; 9+ messages in thread
From: Pierre Carrier @ 2012-07-09 17:30 UTC (permalink / raw)
To: linux-btrfs; +Cc: Pierre Carrier
Dirty hack to allow inspection of sizes in lower units.
Useful to know the minimum size a partition shoud be resized to
after a 'btrfs filesystem resize'.
Label: 'home' uuid: 10453c4c-1c5b-4df5-b4a5-43a7f377430a
Total devices 1 FS bytes used 42.80GB
devid 1 size 62.16GB used 62.16GB path /dev/sda5
Label: 'home' uuid: 10453c4c-1c5b-4df5-b4a5-43a7f377430a
Total devices 1 FS bytes used 44884524.00KB
devid 1 size 65182236.00KB used 65182208.00KB path /dev/sda5
Signed-off-by: Pierre Carrier <pierre@spotify.com>
diff --git a/utils.c b/utils.c
index 937e763..3f0b7e7 100644
--- a/utils.c
+++ b/utils.c
@@ -1096,13 +1096,18 @@ static char *size_strs[] = { "", "KB", "MB", "GB", "TB",
char *pretty_sizes(u64 size)
{
int num_divs = 0;
+ int max_divs = INT_MAX;
int pretty_len = 16;
u64 last_size = size;
u64 fract_size = size;
float fraction;
char *pretty;
+ char *max_divs_s;
- while(size > 0) {
+ if (max_divs_s = getenv("MAX_DIVS"))
+ max_divs = atoi(max_divs_s);
+
+ while(size > 0 && num_divs <= max_divs) {
fract_size = last_size;
last_size = size;
size /= 1024;
@@ -1117,7 +1122,6 @@ char *pretty_sizes(u64 size)
if (num_divs > ARRAY_SIZE(size_strs))
return NULL;
-
pretty = malloc(pretty_len);
if (!pretty)
return NULL;
--
1.7.11.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] utils.c: offer to limit divisions in pretty_sizes
2012-07-09 17:30 ` Pierre Carrier
@ 2012-07-17 12:58 ` David Sterba
0 siblings, 0 replies; 9+ messages in thread
From: David Sterba @ 2012-07-17 12:58 UTC (permalink / raw)
To: Pierre Carrier; +Cc: linux-btrfs
On Mon, Jul 09, 2012 at 05:30:21PM +0000, Pierre Carrier wrote:
> Dirty hack to allow inspection of sizes in lower units.
A commandline option would suit better IMHO. If this is a one-shot task
to find the sizes expressed with a different multiplier, then I don't
understhand the env variable approach. If it's meant to express all
size-related numbers with a given multiplier, than it could make sense,
but it has to be well documented and possibly a better variable name
picked.
Hugo referenced one of his patches,
http://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg06518.html
that adds -h or -H (1024-based and SI-based), but that does not fix the
problem that you want to se a specific size. So, I'm suggesting a
generic option
--units=PFX
where PFX can be arbitrary from KB, KiB and the rest of the list. Plus a
way to include the human-readable forms, both 1024- and SI-based.
david
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 0/2] Support for small units in display
2012-07-09 17:02 [PATCH 0/2] Support for small units in display Pierre Carrier
2012-07-09 17:02 ` [PATCH 1/2] utils.c: fix sizes in B & malloc in pretty_sizes Pierre Carrier
2012-07-09 17:02 ` [PATCH 2/2] utils.c: offer to limit divisions " Pierre Carrier
@ 2012-07-09 17:27 ` Pierre Carrier
2012-07-17 12:34 ` David Sterba
2 siblings, 1 reply; 9+ messages in thread
From: Pierre Carrier @ 2012-07-09 17:27 UTC (permalink / raw)
To: linux-btrfs; +Cc: Pierre Carrier
I didn't test the initial patches enough.
A second round is coming.
This time it works fine:
devid 1 size 66746609664.00 used 66746580992.00 path /dev/sda5
devid 1 size 65182236.00KB used 65182208.00KB path /dev/sda5
devid 1 size 63654.53MB used 63654.50MB path /dev/sda5
devid 1 size 62.16GB used 62.16GB path /dev/sda5
devid 1 size 62.16GB used 62.16GB path /dev/sda5
Pierre Carrier (2):
utils.c: fix sizes in B & malloc in pretty_sizes
utils.c: offer to limit divisions in pretty_sizes
utils.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
--
1.7.11.1
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2012-07-17 12:58 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-09 17:02 [PATCH 0/2] Support for small units in display Pierre Carrier
2012-07-09 17:02 ` [PATCH 1/2] utils.c: fix sizes in B & malloc in pretty_sizes Pierre Carrier
2012-07-09 17:29 ` Pierre Carrier
2012-07-17 12:43 ` David Sterba
2012-07-09 17:02 ` [PATCH 2/2] utils.c: offer to limit divisions " Pierre Carrier
2012-07-09 17:30 ` Pierre Carrier
2012-07-17 12:58 ` David Sterba
2012-07-09 17:27 ` [PATCH 0/2] Support for small units in display Pierre Carrier
2012-07-17 12:34 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).