Move parse_size() to utils.[hc]

Move the function from cmds-filesystem.c and mkfs.c to utils.c

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
This commit is contained in:
Goffredo Baroncelli 2012-10-29 18:53:17 +01:00 committed by David Sterba
parent 043437d8e1
commit 8f76aee6bc
4 changed files with 28 additions and 57 deletions

View File

@ -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)

31
mkfs.c
View File

@ -55,37 +55,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;

26
utils.c
View File

@ -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;
}

View File

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