From: Goffredo Baroncelli <kreijack@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Stefan Behrens <sbehrens@giantdisaster.de>,
Wang Sheng-Hui <shhuiw@gmail.com>,
Goffredo Baroncelli <kreijack@inwind.it>
Subject: [PATCH 1/5] Move parse_size() to utils.[hc]
Date: Tue, 23 Oct 2012 19:51:51 +0200 [thread overview]
Message-ID: <1351014715-5727-2-git-send-email-kreijack@inwind.com> (raw)
In-Reply-To: <1351014715-5727-1-git-send-email-kreijack@inwind.com>
From: Goffredo Baroncelli <kreijack@inwind.it>
Move the function from cmds-filesystem.c and mkfs.c to utils.c
---
cmds-filesystem.c | 26 --------------------------
mkfs.c | 31 -------------------------------
utils.c | 26 ++++++++++++++++++++++++++
utils.h | 2 ++
4 files changed, 28 insertions(+), 57 deletions(-)
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 9c43d35..507239a 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -311,32 +311,6 @@ static int cmd_sync(int argc, char **argv)
return 0;
}
-static u64 parse_size(char *s)
-{
- int len = strlen(s);
- char c;
- u64 mult = 1;
-
- if (!isdigit(s[len - 1])) {
- c = tolower(s[len - 1]);
- switch (c) {
- case 'g':
- mult *= 1024;
- case 'm':
- mult *= 1024;
- case 'k':
- mult *= 1024;
- case 'b':
- break;
- default:
- fprintf(stderr, "Unknown size descriptor %c\n", c);
- exit(1);
- }
- s[len - 1] = '\0';
- }
- return atoll(s) * mult;
-}
-
static int parse_compress_type(char *s)
{
if (strcmp(optarg, "zlib") == 0)
diff --git a/mkfs.c b/mkfs.c
index 47f0c9c..ca850d9 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -54,37 +54,6 @@ struct directory_name_entry {
struct list_head list;
};
-static u64 parse_size(char *s)
-{
- int len = strlen(s);
- char c;
- u64 mult = 1;
- u64 ret;
-
- s = strdup(s);
-
- if (len && !isdigit(s[len - 1])) {
- c = tolower(s[len - 1]);
- switch (c) {
- case 'g':
- mult *= 1024;
- case 'm':
- mult *= 1024;
- case 'k':
- mult *= 1024;
- case 'b':
- break;
- default:
- fprintf(stderr, "Unknown size descriptor %c\n", c);
- exit(1);
- }
- s[len - 1] = '\0';
- }
- ret = atol(s) * mult;
- free(s);
- return ret;
-}
-
static int make_root_dir(struct btrfs_root *root, int mixed)
{
struct btrfs_trans_handle *trans;
diff --git a/utils.c b/utils.c
index 205e667..705be7b 100644
--- a/utils.c
+++ b/utils.c
@@ -1220,3 +1220,29 @@ scan_again:
return 0;
}
+u64 parse_size(char *s)
+{
+ int len = strlen(s);
+ char c;
+ u64 mult = 1;
+
+ if (!isdigit(s[len - 1])) {
+ c = tolower(s[len - 1]);
+ switch (c) {
+ case 'g':
+ mult *= 1024;
+ case 'm':
+ mult *= 1024;
+ case 'k':
+ mult *= 1024;
+ case 'b':
+ break;
+ default:
+ fprintf(stderr, "Unknown size descriptor %c\n", c);
+ exit(1);
+ }
+ s[len - 1] = '\0';
+ }
+ return atoll(s) * mult;
+}
+
diff --git a/utils.h b/utils.h
index 3a0368b..714fd7a 100644
--- a/utils.h
+++ b/utils.h
@@ -46,4 +46,6 @@ int check_label(char *input);
int get_mountpt(char *dev, char *mntpt, size_t size);
int btrfs_scan_block_devices(int run_ioctl);
+
+u64 parse_size(char *s);
#endif
--
1.7.10.4
next prev parent reply other threads:[~2012-10-23 17:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-23 17:51 [PATCH][BTRFS-PROGS][V2] Update to parse_size() Goffredo Baroncelli
2012-10-23 17:51 ` Goffredo Baroncelli [this message]
2012-10-23 17:51 ` [PATCH 2/5] parse_size(): replace atoll() with strtoull() Goffredo Baroncelli
2012-10-23 17:51 ` [PATCH 3/5] parse_size(): check for invalid suffix Goffredo Baroncelli
2012-10-23 17:51 ` [PATCH 4/5] parse_size(): add new suffixes Goffredo Baroncelli
2012-10-23 17:51 ` [PATCH 5/5] Update the man page with the new prefixes Goffredo Baroncelli
2012-10-25 16:13 ` David Sterba
2012-10-25 19:22 ` Goffredo Baroncelli
2012-10-23 18:48 ` [PATCH][BTRFS-PROGS][V2] Update to parse_size() Goffredo Baroncelli
2012-10-25 16:33 ` David Sterba
-- strict thread matches above, loose matches on Subject: below --
2012-10-22 20:17 [PATCH][BTRFS-PROGS] " Goffredo Baroncelli
2012-10-22 20:17 ` [PATCH 1/5] Move parse_size() to utils.[hc] Goffredo Baroncelli
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=1351014715-5727-2-git-send-email-kreijack@inwind.com \
--to=kreijack@gmail.com \
--cc=kreijack@inwind.it \
--cc=linux-btrfs@vger.kernel.org \
--cc=sbehrens@giantdisaster.de \
--cc=shhuiw@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).