diff options
author | Theodore Ts'o <tytso@mit.edu> | 2005-01-05 03:01:06 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2005-01-05 03:01:06 -0500 |
commit | 55f4cbd96e0029f0ff67c4913192d87bf52fd149 (patch) | |
tree | 5bdd5d25b266754c464f1e485fc991c933e5dda5 /lib | |
parent | f90c9919b488d08bb59363a94fd1a0d57d61775f (diff) | |
download | e2fsprogs-55f4cbd96e0029f0ff67c4913192d87bf52fd149.tar.gz |
Add new function in e2p for parsing the number of blocks on the command line
for mke2fs and resize2fs, and use this function so that filesystem size
inputs to e2fsprogs command line programs are parsed consistently.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/e2p/ChangeLog | 6 | ||||
-rw-r--r-- | lib/e2p/Makefile.in | 8 | ||||
-rw-r--r-- | lib/e2p/e2p.h | 2 | ||||
-rw-r--r-- | lib/e2p/parse_num.c | 64 |
4 files changed, 76 insertions, 4 deletions
diff --git a/lib/e2p/ChangeLog b/lib/e2p/ChangeLog index 9cb7485c..1df48da3 100644 --- a/lib/e2p/ChangeLog +++ b/lib/e2p/ChangeLog @@ -1,3 +1,9 @@ +2005-01-05 Theodore Ts'o <tytso@mit.edu> + + * parse_num.c (parse_num_blocks): New file which adds a standard + function for parsing the number of blocks by programs such + as mke2fs and resize2fs. + 2004-12-23 Theodore Ts'o <tytso@mit.edu> * ls.c (list_super2): Print the s_reserved_gdt_blocks field if it diff --git a/lib/e2p/Makefile.in b/lib/e2p/Makefile.in index 9d9bc263..4b11a614 100644 --- a/lib/e2p/Makefile.in +++ b/lib/e2p/Makefile.in @@ -18,15 +18,15 @@ all:: OBJS= feature.o fgetflags.o fsetflags.o fgetversion.o fsetversion.o \ getflags.o getversion.o hashstr.o iod.o ls.o mntopts.o \ - pe.o pf.o ps.o setflags.o setversion.o uuid.o + parse_num.o pe.o pf.o ps.o setflags.o setversion.o uuid.o SRCS= $(srcdir)/feature.c $(srcdir)/fgetflags.c \ $(srcdir)/fsetflags.c $(srcdir)/fgetversion.c \ $(srcdir)/fsetversion.c $(srcdir)/getflags.c \ $(srcdir)/getversion.c $(srcdir)/hashstr.c $(srcdir)/iod.c \ - $(srcdir)/ls.c $(srcdir)/mntopts.c $(srcdir)/pe.c \ - $(srcdir)/pf.c $(srcdir)/ps.c $(srcdir)/setflags.c \ - $(srcdir)/setversion.c $(srcdir)/uuid.c + $(srcdir)/ls.c $(srcdir)/mntopts.c $(srcdir)/parse_num.c \ + $(srcdir)/pe.c $(srcdir)/pf.c $(srcdir)/ps.c \ + $(srcdir)/setflags.c $(srcdir)/setversion.c $(srcdir)/uuid.c HFILES= e2p.h diff --git a/lib/e2p/e2p.h b/lib/e2p/e2p.h index ebd30ab5..048014f1 100644 --- a/lib/e2p/e2p.h +++ b/lib/e2p/e2p.h @@ -45,3 +45,5 @@ int e2p_string2hash(char *string); const char *e2p_mntopt2string(unsigned int mask); int e2p_string2mntopt(char *string, unsigned int *mask); int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok); + +unsigned long parse_num_blocks(const char *arg, int log_block_size); diff --git a/lib/e2p/parse_num.c b/lib/e2p/parse_num.c new file mode 100644 index 00000000..3910e70d --- /dev/null +++ b/lib/e2p/parse_num.c @@ -0,0 +1,64 @@ +/* + * parse_num.c - Parse the number of blocks + * + * Copyright (C) 2004,2005 Theodore Ts'o <tytso@mit.edu> + * + * This file can be redistributed under the terms of the GNU Library General + * Public License + */ + +#include "e2p.h" + +#include <stdlib.h> + +unsigned long parse_num_blocks(const char *arg, int log_block_size) +{ + char *p; + unsigned long long num; + + num = strtoull(arg, &p, 0); + + if (p[0] && p[1]) + return 0; + + switch (*p) { /* Using fall-through logic */ + case 'T': case 't': + num <<= 10; + case 'G': case 'g': + num <<= 10; + case 'M': case 'm': + num <<= 10; + case 'K': case 'k': + num >>= log_block_size; + break; + case 's': + num >>= 1; + break; + case '\0': + break; + default: + return 0; + } + return num; +} + +#ifdef DEBUG +#include <unistd.h> +#include <stdio.h> + +main(int argc, char **argv) +{ + unsigned long num; + int log_block_size = 0; + + if (argc != 2) { + fprintf(stderr, "Usage: %s arg\n", argv[0]); + exit(1); + } + + num = parse_num_blocks(argv[1], log_block_size); + + printf("Parsed number: %lu\n", num); + exit(0); +} +#endif |