[BusyBox] mke2fs size reduction
Tito
farmatito at tiscali.it
Thu Jun 16 12:00:01 UTC 2005
Hi Mike,
this is a first attempt to reduce size
of mke2fs.
Reduction so far is:
text data bss dec hex filename
11698 156 1108 12962 32a2 e2fsprogs/mke2fs.o.orig
text data bss dec hex filename
10577 152 1108 11837 2e3d e2fsprogs/mke2fs.o
I've tested the patched version a little and it seems ok to me.
Please take a look at it and apply it if you think it is ok.
Ciao,
Tito
-------------- next part --------------
--- e2fsprogs/mke2fs_orig.c 2005-06-12 12:04:02.000000000 +0200
+++ e2fsprogs/mke2fs.c 2005-06-16 08:10:58.000000000 +0200
@@ -21,9 +21,6 @@
#include <fcntl.h>
#include <ctype.h>
#include <time.h>
-#ifdef __linux__
-#include <sys/utsname.h>
-#endif
#include <getopt.h>
#include <unistd.h>
#include <stdlib.h>
@@ -45,12 +42,9 @@
#define ZAP_BOOTBLOCK
#endif
-static const char * program_name = "mke2fs";
static const char * device_name /* = NULL */;
-
/* Command line options */
static int cflag;
-static int verbose;
static int quiet;
static int super_only;
static int force;
@@ -91,30 +85,6 @@
return l;
}
-static int parse_version_number(const char *s)
-{
- int major, minor, rev;
- char *endptr;
- const char *cp = s;
-
- if (!s)
- return 0;
- major = strtol(cp, &endptr, 10);
- if (cp == endptr || *endptr != '.')
- return 0;
- cp = endptr + 1;
- minor = strtol(cp, &endptr, 10);
- if (cp == endptr || *endptr != '.')
- return 0;
- cp = endptr + 1;
- rev = strtol(cp, &endptr, 10);
- if (cp == endptr)
- return 0;
- return ((((major * 256) + minor) * 256) + rev);
-}
-
-
-
/*
* This function sets the default parameters for a filesystem
*
@@ -196,23 +166,80 @@
}
/*
+ * Busybox stuff
+ */
+static void e2_error_msg_and_die(char *fmt, ... ) __attribute__ ((noreturn, format (printf, 1, 2)));
+static void e2_error_msg_and_die(char *fmt, ... )
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ bb_fprintf(stderr,"Couldn't: ");
+ bb_error_msg_and_die(fmt, ap);
+ /* Not reached */
+ /*va_end(ap);*/
+}
+
+/*
+ * Busybox stuff
+ */
+static void e2_warning_msg(char *fmt, ... )__attribute__ ((format (printf, 1, 2)));
+static void e2_warning_msg(char *fmt, ... )
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ bb_fprintf(stderr,"Warning: ");
+ bb_error_msg(fmt, ap);
+ va_end(ap);
+}
+
+/*
+ * Busybox stuff
+ */
+static void x_ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f, badblocks_list *bb_list)
+{
+ if (ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block)) {
+ e2_error_msg_and_die("read bad blocks list");
+ }
+}
+
+/*
+ * Busybox stuff
+ */
+static void if_not_quiet_print_and_flush(char *fmt, ... )__attribute__ ((format (printf, 1, 2)));
+static void if_not_quiet_print_and_flush(char *fmt, ... )
+{
+ va_list ap;
+
+ if (quiet)
+ return;
+ va_start(ap, fmt);
+ bb_vfprintf(stdout, fmt, ap);
+ va_end(ap);
+ fflush(stdout);
+}
+
+/*
+ * Busybox stuff
+ */
+static void print_version(void)
+{
+ bb_error_msg("%s %s (%s)", bb_applet_name, E2FSPROGS_VERSION,
+ E2FSPROGS_DATE);
+}
+
+/*
* Reads the bad blocks list from a file
*/
static void read_bb_file(ext2_filsys fs, badblocks_list *bb_list,
const char *bad_blocks_file)
{
FILE *f;
- errcode_t retval;
- f = fopen(bad_blocks_file, "r");
- if (!f) {
- bb_perror_msg_and_die("Could not read bad blocks file %s", bad_blocks_file);
- }
- retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
+ f = bb_xfopen(bad_blocks_file, "r");
+ x_ext2fs_read_bb_FILE(fs, f, bb_list);
fclose (f);
- if (retval) {
- bb_error_msg_and_die("Could not read bad blocks list");
- }
}
/*
@@ -221,24 +248,19 @@
static void test_disk(ext2_filsys fs, badblocks_list *bb_list)
{
FILE *f;
- errcode_t retval;
char buf[1024];
-
- sprintf(buf, "badblocks -b %d %s%s%s %d", fs->blocksize,
+
+ snprintf(buf, sizeof(buf), "badblocks -b %d %s%s%s %d", fs->blocksize,
quiet ? "" : "-s ", (cflag > 1) ? "-w " : "",
fs->device_name, fs->super->s_blocks_count);
- if (verbose)
- printf(_("Running command: %s\n"), buf);
+ if_not_quiet_print_and_flush("Running command: %s\n", buf);
f = popen(buf, "r");
if (!f) {
- bb_perror_msg_and_die("Could not run '%s'", buf);
+ /*bb_perror_msg_and_die("Could not run '%s'", buf);*/
+ e2_error_msg_and_die("run '%s': %m", buf);
}
- retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
+ x_ext2fs_read_bb_FILE(fs, f, bb_list);
pclose(f);
- if (retval) {
- bb_error_msg_and_die(
- "Could not get list of bad blocks from program");
- }
}
static void handle_bad_blocks(ext2_filsys fs, badblocks_list bb_list)
@@ -248,7 +270,6 @@
unsigned must_be_good;
blk_t blk;
badblocks_iterate bb_iter;
- errcode_t retval;
blk_t group_block;
int group;
int group_bad;
@@ -284,9 +305,9 @@
if (ext2fs_badblocks_list_test(bb_list,
group_block + j)) {
if (!group_bad)
- bb_error_msg(
- "Warning: the backup superblock/group descriptors at block %d contain\n"
- " bad blocks\n", group_block);
+ e2_warning_msg(
+ "the backup superblock/group descriptors at block %d contain\n"
+ "bad blocks\n", group_block);
group_bad++;
group = ext2fs_group_of_blk(fs, group_block+j);
fs->group_desc[group].bg_free_blocks_count++;
@@ -299,8 +320,7 @@
/*
* Mark all the bad blocks as used...
*/
- retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter);
- if (retval) {
+ if (ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter)) {
bb_error_msg_and_die("while marking bad blocks as used");
}
while (ext2fs_badblocks_list_iterate(bb_iter, &blk))
@@ -358,7 +378,8 @@
{
if (progress->format[0] == 0)
return;
- fputs(_("done \n"), stdout);
+ /*fputs("done \n", stdout);*/
+ printf("%-28s\n", "done");
}
@@ -390,8 +411,8 @@
}
/* Allocate the zeroizing buffer if necessary */
if (!buf) {
- buf = xmalloc(fs->blocksize * STRIDE_LENGTH);
- memset(buf, 0, fs->blocksize * STRIDE_LENGTH);
+ buf = xcalloc(fs->blocksize * STRIDE_LENGTH, 1);
+ /*memset(buf, 0, fs->blocksize * STRIDE_LENGTH);*/
}
/* OK, do the write loop */
next_update = 0;
@@ -420,7 +441,6 @@
static void write_inode_tables(ext2_filsys fs)
{
- errcode_t retval;
blk_t blk;
dgrp_t i;
int num;
@@ -429,7 +449,7 @@
if (quiet)
memset(&progress, 0, sizeof(progress));
else
- progress_init(&progress, _("Writing inode tables: "),
+ progress_init(&progress, "Writing inode tables: ",
fs->group_desc_count);
for (i = 0; i < fs->group_desc_count; i++) {
@@ -438,17 +458,14 @@
blk = fs->group_desc[i].bg_inode_table;
num = fs->inode_blocks_per_group;
- retval = zero_blocks(fs, blk, num, 0, &blk, &num);
- if (retval) {
- bb_error_msg_and_die(
- "\nCould not write %d blocks "
+ if (zero_blocks(fs, blk, num, 0, &blk, &num)) {
+ /*fputs("\n", stderr);*/
+ e2_error_msg_and_die(
+ "write %d blocks "
"in inode table starting at %d.",
num, blk);
}
- if (sync_kludge) {
- if (sync_kludge == 1)
- sync();
- else if ((i % sync_kludge) == 0)
+ if (sync_kludge && (sync_kludge == 1 || (i % sync_kludge) == 0)) {
sync();
}
}
@@ -458,69 +475,69 @@
static void create_root_dir(ext2_filsys fs)
{
- errcode_t retval;
struct ext2_inode inode;
-
- retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, 0);
- if (retval) {
- bb_error_msg_and_die("Could not create root dir");
+ char *msg = "create root dir";
+
+ if (ext2fs_mkdir(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, 0)) {
+ goto ERROR_MSG1;
}
if (geteuid()) {
- retval = ext2fs_read_inode(fs, EXT2_ROOT_INO, &inode);
- if (retval) {
- bb_error_msg_and_die("Could not read root inode");
+ if (ext2fs_read_inode(fs, EXT2_ROOT_INO, &inode)) {
+ msg = "read root inode";
+ goto ERROR_MSG1;
}
inode.i_uid = getuid();
if (inode.i_uid)
inode.i_gid = getgid();
- retval = ext2fs_write_new_inode(fs, EXT2_ROOT_INO, &inode);
- if (retval) {
- bb_error_msg_and_die("Could not set root inode ownership");
+ if (ext2fs_write_new_inode(fs, EXT2_ROOT_INO, &inode)) {
+ msg = "set root inode ownership";
+ goto ERROR_MSG1;
}
}
+ return;
+ERROR_MSG1:
+ e2_error_msg_and_die(msg);
}
static void create_lost_and_found(ext2_filsys fs)
{
- errcode_t retval;
ext2_ino_t ino;
const char *name = "lost+found";
int i;
int lpf_size = 0;
-
+ char *msg = "create";
+
fs->umask = 077;
- retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, 0, name);
- if (retval) {
- bb_error_msg_and_die("Could not create lost+found");
+ if (ext2fs_mkdir(fs, EXT2_ROOT_INO, 0, name)) {
+ goto ERROR_MSG2;
}
- retval = ext2fs_lookup(fs, EXT2_ROOT_INO, name, strlen(name), 0, &ino);
- if (retval) {
- bb_error_msg_and_die("Could not look up lost+found");
+ if (ext2fs_lookup(fs, EXT2_ROOT_INO, name, /*strlen(name)*/ 10, 0, &ino)) {
+ msg = "look up";
+ goto ERROR_MSG2;
}
for (i=1; i < EXT2_NDIR_BLOCKS; i++) {
if ((lpf_size += fs->blocksize) >= 16*1024)
break;
- retval = ext2fs_expand_dir(fs, ino);
- if (retval) {
- bb_error_msg_and_die("Could not expand lost+found");
+ if (ext2fs_expand_dir(fs, ino)) {
+ msg = "expand";
+ goto ERROR_MSG2;
}
}
+ return;
+ERROR_MSG2:
+ e2_error_msg_and_die("%s %s", msg, name);
}
static void create_bad_block_inode(ext2_filsys fs, badblocks_list bb_list)
{
- errcode_t retval;
-
ext2fs_mark_inode_bitmap(fs->inode_map, EXT2_BAD_INO);
fs->group_desc[0].bg_free_inodes_count--;
fs->super->s_free_inodes_count--;
- retval = ext2fs_update_bb_inode(fs, bb_list);
- if (retval) {
- bb_error_msg_and_die("Could not set bad block inode");
+ if (ext2fs_update_bb_inode(fs, bb_list)) {
+ e2_error_msg_and_die("set bad block inode");
}
-
}
static void reserve_inodes(ext2_filsys fs)
@@ -544,17 +561,15 @@
static void zap_sector(ext2_filsys fs, int sect, int nsect)
{
char *buf;
- int retval;
unsigned int *magic;
buf = xmalloc(512*nsect);
if (sect == 0) {
/* Check for a BSD disklabel, and don't erase it if so */
- retval = io_channel_read_blk(fs->io, 0, -512, buf);
- if (retval)
- bb_error_msg("Warning: could not read block 0");
- else {
+ if (io_channel_read_blk(fs->io, 0, -512, buf)) {
+ e2_warning_msg("couldn't read block 0");
+ } else {
magic = (unsigned int *) (buf + BSD_LABEL_OFFSET);
if ((*magic == BSD_DISKMAGIC) ||
(*magic == BSD_MAGICDISK))
@@ -564,45 +579,39 @@
memset(buf, 0, 512*nsect);
io_channel_set_blksize(fs->io, 512);
- retval = io_channel_write_blk(fs->io, sect, -512*nsect, buf);
+ if (io_channel_write_blk(fs->io, sect, -512*nsect, buf))
+ e2_warning_msg("couldn't erase sector %d", sect);
io_channel_set_blksize(fs->io, fs->blocksize);
free(buf);
- if (retval)
- bb_error_msg("Warning: could not erase sector %d", sect);
+
}
static void create_journal_dev(ext2_filsys fs)
{
struct progress_struct progress;
- errcode_t retval;
char *buf;
blk_t blk;
int count;
-
- retval = ext2fs_create_journal_superblock(fs,
- fs->super->s_blocks_count, 0, &buf);
- if (retval) {
- bb_error_msg_and_die("Could not init journal superblock");
+ char *msg = "init";
+
+ if (ext2fs_create_journal_superblock(fs, fs->super->s_blocks_count, 0, &buf)) {
+ goto ERROR_MSG3;
}
if (quiet)
memset(&progress, 0, sizeof(progress));
else
- progress_init(&progress, _("Zeroing journal device: "),
+ progress_init(&progress, "Zeroing journal device: ",
fs->super->s_blocks_count);
- retval = zero_blocks(fs, 0, fs->super->s_blocks_count,
- &progress, &blk, &count);
- if (retval) {
- bb_error_msg_and_die("Could not zero journal device (block %u, count %d)",
- blk, count);
+ if (zero_blocks(fs, 0, fs->super->s_blocks_count, &progress, &blk, &count)) {
+ e2_error_msg_and_die("zero journal device (block %u, count %d)", blk, count);
}
zero_blocks(0, 0, 0, 0, 0, 0);
- retval = io_channel_write_blk(fs->io,
- fs->super->s_first_data_block+1,
- 1, buf);
- if (retval) {
- bb_error_msg_and_die("Could not write journal superblock");
+ if (io_channel_write_blk(fs->io, fs->super->s_first_data_block+1, 1, buf)) {
+ msg = "write";
+ERROR_MSG3:
+ bb_error_msg_and_die("%s journal superblock", msg);
}
progress_close(&progress);
}
@@ -610,53 +619,51 @@
static void show_stats(ext2_filsys fs)
{
struct ext2_super_block *s = fs->super;
- char buf[80];
- char *os;
- blk_t group_block;
- dgrp_t i;
- int need, col_left;
+ char *os;
+ blk_t group_block;
+ dgrp_t i;
+ int need, col_left;
if (param.s_blocks_count != s->s_blocks_count)
- bb_error_msg("warning: %d blocks unused\n",
+ e2_warning_msg("%d blocks unused\n",
param.s_blocks_count - s->s_blocks_count);
- memset(buf, 0, sizeof(buf));
- strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name));
- printf("Filesystem label=%s\n", buf);
- fputs(_("OS type: "), stdout);
- os = e2p_os2string(fs->super->s_creator_os);
- fputs(os, stdout);
+ os = e2p_os2string(fs->super->s_creator_os);
+ printf( "Filesystem label=%s\n"
+ "OS type: %s\n"
+ "Block size=%u (log=%u)\n"
+ "Fragment size=%u (log=%u)\n"
+ "%u inodes, %u blocks\n"
+ "%u blocks (%2.2f%%) reserved for the super user\n"
+ "First data block=%u\n",
+ s->s_volume_name,
+ os,
+ fs->blocksize, s->s_log_block_size,
+ fs->fragsize, s->s_log_frag_size,
+ s->s_inodes_count, s->s_blocks_count,
+ s->s_r_blocks_count, 100.0 * s->s_r_blocks_count / s->s_blocks_count,
+ s->s_first_data_block);
free(os);
- printf("\n");
- printf(_("Block size=%u (log=%u)\n"), fs->blocksize,
- s->s_log_block_size);
- printf(_("Fragment size=%u (log=%u)\n"), fs->fragsize,
- s->s_log_frag_size);
- printf(_("%u inodes, %u blocks\n"), s->s_inodes_count,
- s->s_blocks_count);
- printf(_("%u blocks (%2.2f%%) reserved for the super user\n"),
- s->s_r_blocks_count,
- 100.0 * s->s_r_blocks_count / s->s_blocks_count);
- printf(_("First data block=%u\n"), s->s_first_data_block);
+
if (s->s_reserved_gdt_blocks)
- printf(_("Maximum filesystem blocks=%lu\n"),
+ printf("Maximum filesystem blocks=%lu\n",
(s->s_reserved_gdt_blocks + fs->desc_blocks) *
(fs->blocksize / sizeof(struct ext2_group_desc)) *
s->s_blocks_per_group);
- if (fs->group_desc_count > 1)
- printf(_("%u block groups\n"), fs->group_desc_count);
- else
- printf(_("%u block group\n"), fs->group_desc_count);
- printf(_("%u blocks per group, %u fragments per group\n"),
- s->s_blocks_per_group, s->s_frags_per_group);
- printf(_("%u inodes per group\n"), s->s_inodes_per_group);
+
+ printf( "%u block group%s\n"
+ "%u blocks per group, %u fragments per group\n"
+ "%u inodes per group\n",
+ fs->group_desc_count, (fs->group_desc_count > 1) ? "s" : "",
+ s->s_blocks_per_group, s->s_frags_per_group,
+ s->s_inodes_per_group);
if (fs->group_desc_count == 1) {
- printf("\n");
+ putchar('\n');
return;
}
- printf(_("Superblock backups stored on blocks: "));
+ printf("Superblock backups stored on blocks: ");
group_block = s->s_first_data_block;
col_left = 0;
for (i = 1; i < fs->group_desc_count; i++) {
@@ -673,7 +680,7 @@
col_left -= need;
printf("%u", group_block);
}
- printf("\n\n");
+ puts("\n");
}
/*
@@ -682,22 +689,21 @@
*/
static int set_os(struct ext2_super_block *sb, char *os)
{
- if (isdigit (*os))
+ short i;
+
+ if (isdigit (*os)) {
sb->s_creator_os = atoi (os);
- else if (strcasecmp(os, "linux") == 0)
- sb->s_creator_os = EXT2_OS_LINUX;
- else if (strcasecmp(os, "GNU") == 0 || strcasecmp(os, "hurd") == 0)
+ return 1;
+ }
+ i = e2p_string2os(os);
+ if( i >= 0) {
+ sb->s_creator_os = i;
+ return 1;
+ } else if (!strcasecmp("GNU", os)) {
sb->s_creator_os = EXT2_OS_HURD;
- else if (strcasecmp(os, "masix") == 0)
- sb->s_creator_os = EXT2_OS_MASIX;
- else if (strcasecmp(os, "freebsd") == 0)
- sb->s_creator_os = EXT2_OS_FREEBSD;
- else if (strcasecmp(os, "lites") == 0)
- sb->s_creator_os = EXT2_OS_LITES;
- else
- return 0;
-
- return 1;
+ return 1;
+ }
+ return 0;
}
#define PATH_SET "PATH=/sbin"
@@ -706,12 +712,9 @@
const char *opts)
{
char *buf, *token, *next, *p, *arg;
- int len;
int r_usage = 0;
- len = strlen(opts);
- buf = xmalloc(len+1);
- strcpy(buf, opts);
+ buf = bb_xstrdup(opts);
for (token = buf; token && *token; token = next) {
p = strchr(token, ',');
next = 0;
@@ -806,7 +809,6 @@
EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER /* R/O compat */
};
-
static void PRS(int argc, char *argv[])
{
int b, c;
@@ -817,27 +819,21 @@
int inode_size = 0;
int reserved_ratio = 5;
int sector_size = 0;
- int show_version_only = 0;
ext2_ino_t num_inodes = 0;
errcode_t retval;
char * oldpath = getenv("PATH");
char * extended_opts = 0;
const char * fs_type = 0;
blk_t dev_size;
-#ifdef __linux__
- struct utsname ut;
-#endif
long sysval;
/* Update our PATH to include /sbin */
if (oldpath) {
char *newpath;
- newpath = xmalloc(sizeof (PATH_SET) + 1 + strlen (oldpath));
- strcpy (newpath, PATH_SET);
- strcat (newpath, ":");
- strcat (newpath, oldpath);
+ bb_xasprintf(&newpath, "%s:%s", PATH_SET, oldpath);
putenv (newpath);
+ /*free(newpath);*/
} else
putenv (PATH_SET);
@@ -866,10 +862,7 @@
#endif
#ifdef __linux__
- if (uname(&ut)) {
- bb_perror_msg_and_die("uname");
- }
- linux_version_code = parse_version_number(ut.release);
+ linux_version_code = get_kernel_revision();
if (linux_version_code && linux_version_code < (2*65536 + 2*256)) {
param.s_rev_level = 0;
param.s_feature_incompat = 0;
@@ -878,13 +871,8 @@
}
#endif
- if (argc && *argv) {
- program_name = basename(*argv);
-
- /* If called as mkfs.ext3, create a journal inode */
- if (!strcmp(*argv + strlen(*argv) - 9, "mkfs.ext3"))
+ if (!strcmp(bb_applet_name, "mkfs.ext3"))
journal_size = -1;
- }
while ((c = getopt (argc, argv,
"b:cE:f:g:i:jl:m:no:qr:R:s:tvI:J:ST:FL:M:N:O:V")) != EOF) {
@@ -897,8 +885,8 @@
bb_error_msg_and_die("bad block size - %s", optarg);
}
if (blocksize > 4096)
- bb_error_msg(
- "Warning: blocksize %d not usable on most systems",
+ e2_warning_msg(
+ "blocksize %d not usable on most systems",
blocksize);
if (blocksize > 0)
param.s_log_block_size =
@@ -917,8 +905,7 @@
}
param.s_log_frag_size =
int_log2(size >> EXT2_MIN_BLOCK_LOG_SIZE);
- bb_error_msg(
- "Warning: fragments not supported. "
+ e2_warning_msg("fragments not supported."
"Ignoring -f option");
break;
case 'g':
@@ -935,7 +922,7 @@
if (inode_ratio < EXT2_MIN_BLOCK_SIZE ||
inode_ratio > EXT2_MAX_BLOCK_SIZE * 1024 ||
*tmp) {
- bb_error_msg_and_die("bad inode ratio %s (min %d/max %d",
+ bb_error_msg_and_die("bad inode ratio %s (min %d/max %d)",
optarg, EXT2_MIN_BLOCK_SIZE,
EXT2_MAX_BLOCK_SIZE);
}
@@ -950,8 +937,7 @@
journal_size = -1;
break;
case 'l':
- bad_blocks_filename = xmalloc(strlen(optarg)+1);
- strcpy(bad_blocks_filename, optarg);
+ bad_blocks_filename = bb_xstrdup(optarg);
break;
case 'm':
reserved_ratio = strtoul(optarg, &tmp, 0);
@@ -993,7 +979,8 @@
num_inodes = atoi(optarg);
break;
case 'v':
- verbose = 1;
+ /*verbose = 1;*/
+ quiet = 0;
break;
case 'q':
quiet = 1;
@@ -1032,23 +1019,18 @@
break;
case 'V':
/* Print version number and exit */
- show_version_only++;
- break;
+ print_version();
+ exit(EXIT_SUCCESS);
default:
bb_show_usage();
}
}
- if ((optind == argc) && !show_version_only)
+ if (optind == argc)
bb_show_usage();
device_name = argv[optind++];
- if (!quiet || show_version_only)
- bb_error_msg("mke2fs %s (%s)", E2FSPROGS_VERSION,
- E2FSPROGS_DATE);
-
- if (show_version_only) {
- exit(0);
- }
+ if (!quiet)
+ print_version();
/*
* If there's no blocksize specified and there is a journal
@@ -1068,7 +1050,7 @@
EXT2_FLAG_JOURNAL_DEV_OK, 0,
0, io_ptr, &jfs);
if (retval) {
- bb_error_msg_and_die("Could not open journal device %s", journal_device);
+ e2_error_msg_and_die("open journal device %s", journal_device);
}
if ((blocksize < 0) && (jfs->blocksize < (unsigned) (-blocksize))) {
bb_error_msg_and_die(
@@ -1088,15 +1070,16 @@
blocksize, sys_page_size);
proceed_question();
}
- bb_error_msg(
- "Warning: %d-byte blocks too big for system "
+ e2_warning_msg(
+ "%d-byte blocks too big for system "
"(max %d), forced to continue",
blocksize, sys_page_size);
}
if ((blocksize > 4096) &&
(param.s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL))
- bb_error_msg(
- "\nWarning: some 2.4 kernels do not support "
+ /*fputs("\n", stderr);*/
+ e2_warning_msg(
+ "some 2.4 kernels do not support "
"blocksizes greater than 4096 \n\tusing ext3."
" Use -b 4096 if this is an issue for you\n");
@@ -1125,7 +1108,7 @@
if (!force)
check_plausibility(device_name);
- check_mount(device_name, force, _("filesystem"));
+ check_mount(device_name, force, "filesystem");
param.s_log_frag_size = param.s_log_block_size;
@@ -1133,7 +1116,7 @@
dev_size = param.s_blocks_count;
retval = 0;
} else {
- retry:
+retry:
retval = ext2fs_get_device_size(device_name,
EXT2_BLOCK_SIZE(¶m),
&dev_size);
@@ -1147,12 +1130,12 @@
}
if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) {
- bb_error_msg_and_die("Could not determine filesystem size");
+ e2_error_msg_and_die("determine filesystem size");
}
if (!param.s_blocks_count) {
if (retval == EXT2_ET_UNIMPLEMENTED) {
- bb_error_msg_and_die(
- "Couldn't determine device size; you "
+ e2_error_msg_and_die(
+ "determine device size; you "
"must specify\nthe size of the "
"filesystem");
} else {
@@ -1193,9 +1176,8 @@
param.s_first_meta_bg = atoi(tmp);
/* Get the hardware sector size, if available */
- retval = ext2fs_get_device_sectsize(device_name, §or_size);
- if (retval) {
- bb_error_msg_and_die("Could not determine hardware sector size");
+ if (ext2fs_get_device_sectsize(device_name, §or_size)) {
+ e2_error_msg_and_die("determine hardware sector size");
}
if ((tmp = getenv("MKE2FS_DEVICE_SECTSIZE")) != NULL)
@@ -1232,8 +1214,8 @@
blocksize);
}
if (inode_size != EXT2_GOOD_OLD_INODE_SIZE)
- bb_error_msg(
- "Warning: %d-byte inodes not usable on most systems",
+ e2_warning_msg(
+ "%d-byte inodes not usable on most systems",
inode_size);
param.s_inode_size = inode_size;
}
@@ -1282,7 +1264,7 @@
retval = ext2fs_initialize(device_name, 0, ¶m,
io_ptr, &fs);
if (retval) {
- bb_error_msg_and_die("Could not set up superblock");
+ e2_error_msg_and_die("set up superblock");
}
/*
@@ -1367,7 +1349,7 @@
fs->stride = fs_stride;
retval = ext2fs_allocate_tables(fs);
if (retval) {
- bb_error_msg_and_die("Could not allocate filesystem tables");
+ e2_error_msg_and_die("allocate filesystem tables");
}
if (super_only) {
fs->super->s_state |= EXT2_ERROR_FS;
@@ -1396,7 +1378,7 @@
NULL, &ret_blk, NULL);
if (retval) {
- bb_error_msg("Could not zero block %u at end of filesystem", ret_blk);
+ e2_warning_msg("couldn't zero block %u at end of filesystem", ret_blk);
}
write_inode_tables(fs);
create_root_dir(fs);
@@ -1407,7 +1389,7 @@
EXT2_FEATURE_COMPAT_RESIZE_INODE) {
retval = ext2fs_create_resize_inode(fs);
if (retval) {
- bb_error_msg_and_die("Could not reserve blocks for online resize");
+ e2_error_msg_and_die("reserve blocks for online resize");
}
}
}
@@ -1417,24 +1399,20 @@
if (!force)
check_plausibility(journal_device);
- check_mount(journal_device, force, _("journal"));
+ check_mount(journal_device, force, "journal");
retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
EXT2_FLAG_JOURNAL_DEV_OK, 0,
fs->blocksize, unix_io_manager, &jfs);
if (retval) {
- bb_error_msg_and_die("Could not open journal device %s", journal_device);
- }
- if (!quiet) {
- printf("Adding journal to device %s: ", journal_device);
- fflush(stdout);
+ e2_error_msg_and_die("open journal device %s", journal_device);
}
+ if_not_quiet_print_and_flush("Adding journal to device %s: ", journal_device);
retval = ext2fs_add_journal_device(fs, jfs);
if(retval) {
- bb_error_msg_and_die("Could not add journal to device %s", journal_device);
+ e2_error_msg_and_die("add journal to device %s", journal_device);
}
- if (!quiet)
- printf("done\n");
+ if_not_quiet_print_and_flush("done\n");
ext2fs_close(jfs);
free(journal_device);
} else if (journal_size) {
@@ -1445,31 +1423,25 @@
~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
goto no_journal;
}
- if (!quiet) {
- printf("Creating journal (%d blocks): ",
- journal_blocks);
- fflush(stdout);
- }
+ if_not_quiet_print_and_flush("Creating journal (%d blocks): ", journal_blocks);
retval = ext2fs_add_journal_inode(fs, journal_blocks,
journal_flags);
if (retval) {
- bb_error_msg_and_die("Could not create journal");
+ e2_error_msg_and_die("create journal");
}
- if (!quiet)
- printf("done\n");
+ if_not_quiet_print_and_flush("done\n");
}
no_journal:
- if (!quiet)
- printf("Writing superblocks and "
+ if_not_quiet_print_and_flush("Writing superblocks and "
"filesystem accounting information: ");
retval = ext2fs_flush(fs);
if (retval) {
- bb_error_msg("\nWarning, had trouble writing out superblocks");
+ /* fputs("\n", stderr); */
+ e2_warning_msg("had trouble writing out superblocks");
}
- if (!quiet) {
- printf("done\n\n");
- if (!getenv("MKE2FS_SKIP_CHECK_MSG"))
+ if_not_quiet_print_and_flush("done\n");
+ if (!quiet && !getenv("MKE2FS_SKIP_CHECK_MSG")) {
print_check_message(fs);
}
val = ext2fs_close(fs);
More information about the busybox
mailing list