+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
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
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);
--- /dev/null
+/*
+ * 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
+2005-01-05 Theodore Ts'o <tytso@mit.edu>
+
+ * mke2fs.c (PRS, parse_r_opts): Use parse_num_blocks() from the
+ e2p library to parse the number of blocks from the command
+ line.
+
2004-12-23 Theodore Ts'o <tytso@mit.edu>
* dumpe2fs.c (list_desc): If reserved GDT blocks are present,
/*
* mke2fs.c - Make a ext2fs filesystem.
*
- * Copyright (C) 1994, 1995, 1996, 1997 Theodore Ts'o.
+ * Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+ * 2003, 2004, 2005 by Theodore Ts'o.
*
* %Begin-Header%
* This file may be redistributed under the terms of the GNU Public
continue;
}
- p = &arg[strlen(arg) - 1];
-
- switch(*p++) {
- case 'T':
- case 't': resize <<= 10; /* no break */
- case 'G':
- case 'g': resize <<= 10; /* no break */
- case 'M':
- case 'm': resize <<= 10; /* no break */
- case 'K':
- case 'k': resize >>= param->s_log_block_size -10; *p = 0; break;
- case 'b': resize >>= param->s_log_block_size - 9; *p = 0; break;
- case '0': break;
- case '1': break;
- case '2': break;
- case '3': break;
- case '4': break;
- case '5': break;
- case '6': break;
- case '7': break;
- case '8': break;
- case '9': break;
- default: r_usage++; continue;
- }
-
- resize *= strtoul(arg, NULL, 0);
+ resize = parse_num_blocks(arg,
+ param->s_log_block_size);
if (resize == 0) {
- fprintf(stderr,
- _("Invalid resize parameter.\n"));
+ fprintf(stderr,
+ _("Invalid resize parameter: %s\n"),
+ arg);
r_usage++;
continue;
}
}
while ((c = getopt (argc, argv,
- "b:cf:g:i:jl:m:no:qr:R:s:tvI:J:ST:FL:M:N:O:V")) != EOF)
+ "b:cf:g:i:jl:m:no:qr:R:s:tvI:J:ST:FL:M:N:O:V")) != EOF) {
switch (c) {
case 'b':
blocksize = strtol(optarg, &tmp, 0);
default:
usage();
}
- if ((optind == argc) && !show_version_only)
- usage();
- device_name = argv[optind];
- optind++;
- if (optind < argc) {
- unsigned long long tmp2 = strtoull(argv[optind++], &tmp, 0);
-
- if ((*tmp) || (tmp2 > 0xfffffffful)) {
- com_err(program_name, 0, _("bad blocks count - %s"),
- argv[optind - 1]);
- exit(1);
- }
- param.s_blocks_count = tmp2;
}
- if (optind < argc)
+ if ((optind == argc) && !show_version_only)
usage();
+ device_name = argv[optind++];
if (!quiet || show_version_only)
fprintf (stderr, "mke2fs %s (%s)\n", E2FSPROGS_VERSION,
"blocksizes greater than 4096 \n\tusing ext3."
" Use -b 4096 if this is an issue for you.\n\n");
+ if (optind < argc) {
+ param.s_blocks_count = parse_num_blocks(argv[optind++],
+ param.s_log_block_size);
+ if (!param.s_blocks_count) {
+ com_err(program_name, 0, _("bad blocks count - %s"),
+ argv[optind - 1]);
+ exit(1);
+ }
+ }
+ if (optind < argc)
+ usage();
+
if (param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
if (!fs_type)
fs_type = "journal";
+2005-01-05 Theodore Ts'o <tytso@mit.edu>
+
+ * main.c (main): Use parse_num_blocks() from the e2p library to
+ parse the number of blocks from the command line.
+
2004-12-16 Theodore Ts'o <tytso@mit.edu>
* resize2fs.c (resize_fs): Call ext2fs_create_resize_inode to
$(srcdir)/main.c \
$(srcdir)/sim_progress.c
-LIBS= $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBINTL)
-DEPLIBS= $(LIBEXT2FS) $(LIBCOM_ERR)
+LIBS= $(LIBE2P) $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBINTL)
+DEPLIBS= $(LIBE2P) $(LIBEXT2FS) $(LIBCOM_ERR)
-STATIC_LIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(LIBINTL)
-STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR)
+STATIC_LIBS= $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) \
+ $(LIBINTL)
+STATIC_DEPLIBS= $(STATIC_LIBE2P) $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR)
.c.o:
@echo " CC $<"
* Copyright (C) 1997, 1998 by Theodore Ts'o and
* PowerQuest, Inc.
*
- * Copyright (C) 1999, 2000, 2001 by Theosore Ts'o
+ * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 by Theodore Ts'o
*
* %Begin-Header%
* This file may be redistributed under the terms of the GNU Public
#include <fcntl.h>
#include <sys/stat.h>
+#include "e2p/e2p.h"
+
#include "resize2fs.h"
#include "../version.h"
exit(1);
}
-static int get_units(const char *s)
-{
- if (strlen(s) != 1)
- return -1;
- switch(s[0]) {
- case 's':
- return 512;
- case 'K':
- return 1024;
- case 'M':
- return 1024*1024;
- case 'G':
- return 1024*1024*1024;
- }
- return -1;
-}
-
int main (int argc, char ** argv)
{
errcode_t retval;
int fd;
blk_t new_size = 0;
blk_t max_size = 0;
- int units = 0;
io_manager io_ptr;
char *tmp;
+ char *new_size_str = 0;
struct stat st_buf;
unsigned int sys_page_size = 4096;
long sysval;
usage(program_name);
device_name = argv[optind++];
- if (optind < argc) {
- new_size = strtoul(argv[optind++], &tmp, 0);
- if (*tmp) {
- units = get_units(tmp);
- if (units < 0) {
- com_err(program_name, 0,
- _("bad filesystem size - %s"),
- argv[optind - 1]);
- exit(1);
- }
- }
- }
+ if (optind < argc)
+ new_size_str = argv[optind++];
if (optind < argc)
usage(program_name);
_("while trying to determine filesystem size"));
exit(1);
}
- if (units) {
- if ((unsigned) units < fs->blocksize)
- new_size = (new_size * units) / fs->blocksize;
- else if ((unsigned) units > fs->blocksize)
- new_size = new_size * (units / fs->blocksize);
- }
- if (!new_size) {
+ if (new_size_str) {
+ new_size = parse_num_blocks(new_size_str,
+ fs->super->s_log_block_size);
+ if (!new_size) {
+ com_err(program_name, 0, _("bad filesystem size - %s"),
+ new_size_str);
+ exit(1);
+ }
+ } else {
new_size = max_size;
/* Round down to an even multiple of a pagesize */
if (sys_page_size > fs->blocksize)