--- /dev/null
+/*
+ * getsize.c --- get the size of a partition.
+ *
+ * Copyright (C) 1995, 1995 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License.
+ * %End-Header%
+ */
+
+/* include this before sys/queues.h! */
+#include "blkidP.h"
+
+#include <stdio.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <fcntl.h>
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+#ifdef HAVE_LINUX_FD_H
+#include <linux/fd.h>
+#endif
+#ifdef HAVE_SYS_DISKLABEL_H
+#include <sys/disklabel.h>
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_SYS_DISK_H
+#ifdef HAVE_SYS_QUEUE_H
+#include <sys/queue.h> /* for LIST_HEAD */
+#endif
+#include <sys/disk.h>
+#endif
+#ifdef __linux__
+#include <sys/utsname.h>
+#endif
+
+#if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
+#define BLKGETSIZE _IO(0x12,96) /* return device size */
+#endif
+
+#if defined(__linux__) && defined(_IOR) && !defined(BLKGETSIZE64)
+#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
+#endif
+
+#ifdef APPLE_DARWIN
+#define BLKGETSIZE DKIOCGETBLOCKCOUNT32
+#endif /* APPLE_DARWIN */
+
+static int valid_offset(int fd, blkid_loff_t offset)
+{
+ char ch;
+
+ if (blkid_llseek(fd, offset, 0) < 0)
+ return 0;
+ if (read(fd, &ch, 1) < 1)
+ return 0;
+ return 1;
+}
+
+/*
+ * Returns the number of blocks in a partition
+ */
+blkid_loff_t blkid_get_dev_size(int fd)
+{
+ int valid_blkgetsize64 = 1;
+#ifdef __linux__
+ struct utsname ut;
+#endif
+ unsigned long long size64;
+ unsigned long size;
+ blkid_loff_t high, low;
+#ifdef FDGETPRM
+ struct floppy_struct this_floppy;
+#endif
+#ifdef HAVE_SYS_DISKLABEL_H
+ int part = -1;
+ struct disklabel lab;
+ struct partition *pp;
+ char ch;
+ struct stat st;
+#endif /* HAVE_SYS_DISKLABEL_H */
+
+#ifdef DKIOCGETBLOCKCOUNT /* For Apple Darwin */
+ if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size64) >= 0) {
+ if ((sizeof(blkid_loff_t) < sizeof(unsigned long long))
+ && (size64 << 9 > 0xFFFFFFFF))
+ return 0; /* EFBIG */
+ return (blkid_loff_t) size64 << 9;
+ }
+#endif
+
+#ifdef BLKGETSIZE64
+#ifdef __linux__
+ if ((uname(&ut) == 0) &&
+ ((ut.release[0] == '2') && (ut.release[1] == '.') &&
+ (ut.release[2] < '6') && (ut.release[3] == '.')))
+ valid_blkgetsize64 = 0;
+#endif
+ if (valid_blkgetsize64 &&
+ ioctl(fd, BLKGETSIZE64, &size64) >= 0) {
+ if ((sizeof(blkid_loff_t) < sizeof(unsigned long long))
+ && ((size64) > 0xFFFFFFFF))
+ return 0; /* EFBIG */
+ return size64;
+ }
+#endif
+
+#ifdef BLKGETSIZE
+ if (ioctl(fd, BLKGETSIZE, &size) >= 0)
+ return (blkid_loff_t)size << 9;
+#endif
+
+#ifdef FDGETPRM
+ if (ioctl(fd, FDGETPRM, &this_floppy) >= 0)
+ return (blkid_loff_t)this_floppy.size << 9;
+#endif
+#ifdef HAVE_SYS_DISKLABEL_H
+#if 0
+ /*
+ * This should work in theory but I haven't tested it. Anyone
+ * on a BSD system want to test this for me? In the meantime,
+ * binary search mechanism should work just fine.
+ */
+ if ((fstat(fd, &st) >= 0) && S_ISBLK(st.st_mode))
+ part = st.st_rdev & 7;
+ if (part >= 0 && (ioctl(fd, DIOCGDINFO, (char *)&lab) >= 0)) {
+ pp = &lab.d_partitions[part];
+ if (pp->p_size)
+ return pp->p_size << 9;
+ }
+#endif
+#endif /* HAVE_SYS_DISKLABEL_H */
+
+ /*
+ * OK, we couldn't figure it out by using a specialized ioctl,
+ * which is generally the best way. So do binary search to
+ * find the size of the partition.
+ */
+ low = 0;
+ for (high = 1024; valid_offset(fd, high); high *= 2)
+ low = high;
+ while (low < high - 1)
+ {
+ const blkid_loff_t mid = (low + high) / 2;
+
+ if (valid_offset(fd, mid))
+ low = mid;
+ else
+ high = mid;
+ }
+ return low + 1;
+}
+
+#ifdef TEST_PROGRAM
+int main(int argc, char **argv)
+{
+ blkid_loff_t bytes;
+ int fd;
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s device\n"
+ "Determine the size of a device\n", argv[0]);
+ return 1;
+ }
+
+ if ((fd = open(argv[1], O_RDONLY)) < 0)
+ perror(argv[0]);
+
+ bytes = blkid_get_dev_size(fd);
+ printf("Device %s has %Ld 1k blocks.\n", argv[1], bytes >> 10);
+
+ return 0;
+}
+#endif
+++ /dev/null
-/*
- * getsize.c --- get the size of a partition.
- *
- * Copyright (C) 1995, 1995 Theodore Ts'o.
- *
- * %Begin-Header%
- * This file may be redistributed under the terms of the
- * GNU Lesser General Public License.
- * %End-Header%
- */
-
-/* include this before sys/queues.h! */
-#include "blkidP.h"
-
-#include <stdio.h>
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
-#include <fcntl.h>
-#ifdef HAVE_SYS_IOCTL_H
-#include <sys/ioctl.h>
-#endif
-#ifdef HAVE_LINUX_FD_H
-#include <linux/fd.h>
-#endif
-#ifdef HAVE_SYS_DISKLABEL_H
-#include <sys/disklabel.h>
-#include <sys/stat.h>
-#endif
-#ifdef HAVE_SYS_DISK_H
-#ifdef HAVE_SYS_QUEUE_H
-#include <sys/queue.h> /* for LIST_HEAD */
-#endif
-#include <sys/disk.h>
-#endif
-#ifdef __linux__
-#include <sys/utsname.h>
-#endif
-
-#if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
-#define BLKGETSIZE _IO(0x12,96) /* return device size */
-#endif
-
-#if defined(__linux__) && defined(_IOR) && !defined(BLKGETSIZE64)
-#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
-#endif
-
-#ifdef APPLE_DARWIN
-#define BLKGETSIZE DKIOCGETBLOCKCOUNT32
-#endif /* APPLE_DARWIN */
-
-static int valid_offset(int fd, blkid_loff_t offset)
-{
- char ch;
-
- if (blkid_llseek(fd, offset, 0) < 0)
- return 0;
- if (read(fd, &ch, 1) < 1)
- return 0;
- return 1;
-}
-
-/*
- * Returns the number of blocks in a partition
- */
-blkid_loff_t blkid_get_dev_size(int fd)
-{
- int valid_blkgetsize64 = 1;
-#ifdef __linux__
- struct utsname ut;
-#endif
- unsigned long long size64;
- unsigned long size;
- blkid_loff_t high, low;
-#ifdef FDGETPRM
- struct floppy_struct this_floppy;
-#endif
-#ifdef HAVE_SYS_DISKLABEL_H
- int part = -1;
- struct disklabel lab;
- struct partition *pp;
- char ch;
- struct stat st;
-#endif /* HAVE_SYS_DISKLABEL_H */
-
-#ifdef DKIOCGETBLOCKCOUNT /* For Apple Darwin */
- if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size64) >= 0) {
- if ((sizeof(blkid_loff_t) < sizeof(unsigned long long))
- && (size64 << 9 > 0xFFFFFFFF))
- return 0; /* EFBIG */
- return (blkid_loff_t) size64 << 9;
- }
-#endif
-
-#ifdef BLKGETSIZE64
-#ifdef __linux__
- if ((uname(&ut) == 0) &&
- ((ut.release[0] == '2') && (ut.release[1] == '.') &&
- (ut.release[2] < '6') && (ut.release[3] == '.')))
- valid_blkgetsize64 = 0;
-#endif
- if (valid_blkgetsize64 &&
- ioctl(fd, BLKGETSIZE64, &size64) >= 0) {
- if ((sizeof(blkid_loff_t) < sizeof(unsigned long long))
- && ((size64) > 0xFFFFFFFF))
- return 0; /* EFBIG */
- return size64;
- }
-#endif
-
-#ifdef BLKGETSIZE
- if (ioctl(fd, BLKGETSIZE, &size) >= 0)
- return (blkid_loff_t)size << 9;
-#endif
-
-#ifdef FDGETPRM
- if (ioctl(fd, FDGETPRM, &this_floppy) >= 0)
- return (blkid_loff_t)this_floppy.size << 9;
-#endif
-#ifdef HAVE_SYS_DISKLABEL_H
-#if 0
- /*
- * This should work in theory but I haven't tested it. Anyone
- * on a BSD system want to test this for me? In the meantime,
- * binary search mechanism should work just fine.
- */
- if ((fstat(fd, &st) >= 0) && S_ISBLK(st.st_mode))
- part = st.st_rdev & 7;
- if (part >= 0 && (ioctl(fd, DIOCGDINFO, (char *)&lab) >= 0)) {
- pp = &lab.d_partitions[part];
- if (pp->p_size)
- return pp->p_size << 9;
- }
-#endif
-#endif /* HAVE_SYS_DISKLABEL_H */
-
- /*
- * OK, we couldn't figure it out by using a specialized ioctl,
- * which is generally the best way. So do binary search to
- * find the size of the partition.
- */
- low = 0;
- for (high = 1024; valid_offset(fd, high); high *= 2)
- low = high;
- while (low < high - 1)
- {
- const blkid_loff_t mid = (low + high) / 2;
-
- if (valid_offset(fd, mid))
- low = mid;
- else
- high = mid;
- }
- return low + 1;
-}
-
-#ifdef TEST_PROGRAM
-int main(int argc, char **argv)
-{
- blkid_loff_t bytes;
- int fd;
-
- if (argc < 2) {
- fprintf(stderr, "Usage: %s device\n"
- "Determine the size of a device\n", argv[0]);
- return 1;
- }
-
- if ((fd = open(argv[1], O_RDONLY)) < 0)
- perror(argv[0]);
-
- bytes = blkid_get_dev_size(fd);
- printf("Device %s has %Ld 1k blocks.\n", argv[1], bytes >> 10);
-
- return 0;
-}
-#endif
/*
* mke2fs.c - Make a ext2fs filesystem.
- *
+ *
* Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
- * 2003, 2004, 2005 by Theodore Ts'o.
+ * 2003, 2004, 2005 by Theodore Ts'o.
*
* %Begin-Header%
* This file may be redistributed under the terms of the GNU Public
*/
/* Usage: mke2fs [options] device
- *
+ *
* The device may be a block device or a image of one, but this isn't
- * enforced (but it's not much fun on a character device :-).
+ * enforced (but it's not much fun on a character device :-).
*/
#include <stdio.h>
static int noaction;
static int journal_size;
static int journal_flags;
-static char *bad_blocks_filename;
+static const char *bad_blocks_filename;
static __u32 fs_stride;
static struct ext2_super_block param;
static char *volume_label;
static char *mount_dir;
static char *journal_device;
-static int sync_kludge; /* Set using the MKE2FS_SYNC env. option */
+static int sync_kludge; /* Set using the MKE2FS_SYNC env. option */
static int sys_page_size = 4096;
static int linux_version_code = 0;
* Note that order is important in the table below.
*/
#define DEF_MAX_BLOCKSIZE -1
-static char default_str[] = "default";
+static const char default_str[] = "default";
struct mke2fs_defaults {
const char *type;
int size;
int blocksize;
int inode_ratio;
-} settings[] = {
- { default_str, 0, 4096, 8192 },
+};
+
+static const struct mke2fs_defaults settings[] = {
+ { default_str, 0, 4096, 8192 },
{ default_str, 512, 1024, 4096 },
- { default_str, 3, 1024, 8192 },
- { "journal", 0, 4096, 8192 },
- { "news", 0, 4096, 4096 },
- { "largefile", 0, 4096, 1024 * 1024 },
- { "largefile4", 0, 4096, 4096 * 1024 },
- { 0, 0, 0, 0},
+ { default_str, 3, 1024, 8192 },
+ { "journal", 0, 4096, 8192 },
+ { "news", 0, 4096, 4096 },
+ { "largefile", 0, 4096, 1024 * 1024 },
+ { "largefile4", 0, 4096, 4096 * 1024 },
+ { 0, 0, 0, 0},
};
static void set_fs_defaults(const char *fs_type,
{
int megs;
int ratio = 0;
- struct mke2fs_defaults *p;
+ const struct mke2fs_defaults *p;
int use_bsize = 1024;
megs = super->s_blocks_count * (EXT2_BLOCK_SIZE(super) / 1024) / 1024;
quiet ? "" : "-s ", (cflag > 1) ? "-w " : "",
fs->device_name, fs->super->s_blocks_count);
if (!quiet)
- printf(_("Running command: %s\n"), buf);
+ printf("Running command: %s\n", buf);
f = popen(buf, "r");
if (!f) {
bb_perror_msg_and_die("Could not run '%s'", buf);
{
dgrp_t i;
blk_t j;
- unsigned must_be_good;
+ unsigned must_be_good;
blk_t blk;
badblocks_iterate bb_iter;
errcode_t retval;
if (!bb_list)
return;
-
+
/*
* The primary superblock and group descriptors *must* be
* good; if not, abort.
*/
group_block = fs->super->s_first_data_block +
fs->super->s_blocks_per_group;
-
+
for (i = 1; i < fs->group_desc_count; i++) {
group_bad = 0;
for (j=0; j < fs->desc_blocks+1; j++) {
if (ext2fs_badblocks_list_test(bb_list,
group_block + j)) {
- if (!group_bad)
+ if (!group_bad)
bb_error_msg(
"Warning: the backup superblock/group descriptors at block %d contain\n"
- " bad blocks\n", group_block);
+ " bad blocks\n", group_block);
group_bad++;
group = ext2fs_group_of_blk(fs, group_block+j);
fs->group_desc[group].bg_free_blocks_count++;
}
group_block += fs->super->s_blocks_per_group;
}
-
+
/*
* Mark all the bad blocks as used...
*/
if (retval) {
bb_error_msg_and_die("while marking bad blocks as used");
}
- while (ext2fs_badblocks_list_iterate(bb_iter, &blk))
+ while (ext2fs_badblocks_list_iterate(bb_iter, &blk))
ext2fs_mark_block_bitmap(fs->block_map, blk);
ext2fs_badblocks_list_iterate_end(bb_iter);
}
{
if (progress->format[0] == 0)
return;
- fputs(_("done \n"), stdout);
+ fputs("done \n", stdout);
}
}
/* 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);
}
/* OK, do the write loop */
next_update = 0;
}
}
return 0;
-}
+}
static void write_inode_tables(ext2_filsys fs)
{
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++) {
progress_update(&progress, i);
-
+
blk = fs->group_desc[i].bg_inode_table;
num = fs->inode_blocks_per_group;
static void create_root_dir(ext2_filsys fs)
{
- errcode_t retval;
+ 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 look up lost+found");
}
-
+
for (i=1; i < EXT2_NDIR_BLOCKS; i++) {
if ((lpf_size += fs->blocksize) >= 16*1024)
break;
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--;
static void create_journal_dev(ext2_filsys fs)
{
- struct progress_struct progress;
+ struct progress_struct progress;
errcode_t retval;
char *buf;
blk_t blk;
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,
static void show_stats(ext2_filsys fs)
{
struct ext2_super_block *s = fs->super;
- char buf[80];
- char *os;
+ char buf[80];
+ 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",
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 type: ", stdout);
+ os = e2p_os2string(fs->super->s_creator_os);
fputs(os, stdout);
free(os);
- printf("\n");
- printf(_("Block size=%u (log=%u)\n"), fs->blocksize,
+ printf("\nBlock size=%u (log=%u)\n", fs->blocksize,
s->s_log_block_size);
- printf(_("Fragment size=%u (log=%u)\n"), fs->fragsize,
+ printf("Fragment size=%u (log=%u)\n", fs->fragsize,
s->s_log_frag_size);
- printf(_("%u inodes, %u blocks\n"), s->s_inodes_count,
+ 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"),
+ 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);
+ 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);
+ 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"),
+ 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 inodes per group\n", s->s_inodes_per_group);
if (fs->group_desc_count == 1) {
printf("\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++) {
#define PATH_SET "PATH=/sbin"
-static void parse_extended_opts(struct ext2_super_block *sb_param,
+static void parse_extended_opts(struct ext2_super_block *sb_param,
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;
continue;
}
- resize = parse_num_blocks(arg,
+ resize = parse_num_blocks(arg,
sb_param->s_log_block_size);
if (resize == 0) {
desc_blocks = (group_desc_count +
gdpb - 1) / gdpb;
rsv_groups = (resize + bpg - 1) / bpg;
- rsv_gdb = (rsv_groups + gdpb - 1) / gdpb -
+ rsv_gdb = (rsv_groups + gdpb - 1) / gdpb -
desc_blocks;
if (rsv_gdb > EXT2_ADDR_PER_BLOCK(sb_param))
rsv_gdb = EXT2_ADDR_PER_BLOCK(sb_param);
"\tstride=<stride length in blocks>\n"
"\tresize=<resize maximum size in blocks>\n");
}
-}
+}
static __u32 ok_features[3] = {
EXT3_FEATURE_COMPAT_HAS_JOURNAL |
EXT2_FEATURE_COMPAT_RESIZE_INODE |
- EXT2_FEATURE_COMPAT_DIR_INDEX, /* Compat */
- EXT2_FEATURE_INCOMPAT_FILETYPE| /* Incompat */
+ EXT2_FEATURE_COMPAT_DIR_INDEX, /* Compat */
+ EXT2_FEATURE_INCOMPAT_FILETYPE| /* Incompat */
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|
EXT2_FEATURE_INCOMPAT_META_BG,
- EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER /* R/O compat */
+ EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER /* R/O compat */
};
-static void PRS(int argc, char *argv[])
+static int PRS(int argc, char *argv[])
{
int b, c;
int size;
/* 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);
- putenv (newpath);
+
+ bb_xasprintf(&newpath, "%s:%s", PATH_SET, oldpath);
} else
putenv (PATH_SET);
if (sysval > 0)
sys_page_size = sysval;
#endif /* _SC_PAGESIZE */
-
+
setbuf(stdout, NULL);
setbuf(stderr, NULL);
memset(¶m, 0, sizeof(struct ext2_super_block));
bb_error_msg(
"Warning: blocksize %d not usable on most systems",
blocksize);
- if (blocksize > 0)
+ if (blocksize > 0)
param.s_log_block_size =
int_log2(blocksize >>
EXT2_MIN_BLOCK_LOG_SIZE);
journal_size = -1;
break;
case 'l':
- bad_blocks_filename = xmalloc(strlen(optarg)+1);
- strcpy(bad_blocks_filename, optarg);
+ bad_blocks_filename = optarg;
break;
case 'm':
reserved_ratio = strtoul(optarg, &tmp, 0);
if (atoi(optarg))
param.s_feature_ro_compat |=
EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
- else
+ else
param.s_feature_ro_compat &=
~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
break;
device_name = argv[optind++];
if (!quiet || show_version_only)
- bb_error_msg("mke2fs %s (%s)", E2FSPROGS_VERSION,
+ bb_error_msg("mke2fs %s (%s)", E2FSPROGS_VERSION,
E2FSPROGS_DATE);
if (show_version_only) {
- exit(0);
+ return 0;
}
/*
* device, use it to figure out the blocksize
*/
if (blocksize <= 0 && journal_device) {
- ext2_filsys jfs;
- io_manager io_ptr;
+ ext2_filsys jfs;
+ io_manager io_ptr;
#ifdef CONFIG_TESTIO_DEBUG
io_ptr = test_io_manager;
" Use -b 4096 if this is an issue for you\n");
if (optind < argc) {
- param.s_blocks_count = parse_num_blocks(argv[optind++],
+ param.s_blocks_count = parse_num_blocks(argv[optind++],
param.s_log_block_size);
if (!param.s_blocks_count) {
bb_error_msg_and_die("bad blocks count - %s", argv[optind - 1]);
param.s_feature_incompat = EXT3_FEATURE_INCOMPAT_JOURNAL_DEV;
param.s_feature_compat = 0;
param.s_feature_ro_compat = 0;
- }
+ }
if (param.s_rev_level == EXT2_GOOD_OLD_REV &&
(param.s_feature_compat || param.s_feature_ro_compat ||
param.s_feature_incompat))
- param.s_rev_level = 1; /* Create a revision 1 filesystem */
+ param.s_rev_level = 1; /* Create a revision 1 filesystem */
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;
EXT2_BLOCK_SIZE(¶m),
&dev_size);
if ((retval == EFBIG) &&
- (blocksize == 0) &&
+ (blocksize == 0) &&
(param.s_log_block_size == 0)) {
param.s_log_block_size = 2;
blocksize = 4096;
goto retry;
}
}
-
+
if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) {
bb_error_msg_and_die("Could not determine filesystem size");
}
param.s_blocks_count &= ~((sys_page_size /
EXT2_BLOCK_SIZE(¶m))-1);
}
-
+
} else if (!force && (param.s_blocks_count > dev_size)) {
bb_error_msg("Filesystem larger than apparent device size");
proceed_question();
if ((tmp = getenv("MKE2FS_DEVICE_SECTSIZE")) != NULL)
sector_size = atoi(tmp);
-
+
set_fs_defaults(fs_type, ¶m, blocksize, sector_size, &inode_ratio);
blocksize = EXT2_BLOCK_SIZE(¶m);
-
+
if (extended_opts)
parse_extended_opts(¶m, extended_opts);
/*
* Calculate number of inodes based on the inode ratio
*/
- param.s_inodes_count = num_inodes ? num_inodes :
+ param.s_inodes_count = num_inodes ? num_inodes :
((__u64) param.s_blocks_count * blocksize)
/ inode_ratio;
* Calculate number of blocks to reserve
*/
param.s_r_blocks_count = (param.s_blocks_count * reserved_ratio) / 100;
+ return 1;
}
int mke2fs_main (int argc, char *argv[])
{
- errcode_t retval = 0;
+ errcode_t retval;
ext2_filsys fs;
badblocks_list bb_list = 0;
int journal_blocks;
int val;
io_manager io_ptr;
-#ifdef ENABLE_NLS
- setlocale(LC_MESSAGES, "");
- setlocale(LC_CTYPE, "");
- bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
- textdomain(NLS_CAT_NAME);
-#endif
- PRS(argc, argv);
+ if(!PRS(argc, argv))
+ return 0;
#ifdef CONFIG_TESTIO_DEBUG
io_ptr = test_io_manager;
strncpy(fs->super->s_last_mounted, mount_dir,
sizeof(fs->super->s_last_mounted));
}
-
+
if (!quiet || noaction)
show_stats(fs);
if (noaction)
- exit(0);
+ return 0;
if (fs->super->s_feature_incompat &
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
create_journal_dev(fs);
- exit(ext2fs_close(fs) ? 1 : 0);
+ return (ext2fs_close(fs) ? 1 : 0);
}
if (bad_blocks_filename)
create_lost_and_found(fs);
reserve_inodes(fs);
create_bad_block_inode(fs, bb_list);
- if (fs->super->s_feature_compat &
+ if (fs->super->s_feature_compat &
EXT2_FEATURE_COMPAT_RESIZE_INODE) {
retval = ext2fs_create_resize_inode(fs);
if (retval) {
}
if (journal_device) {
- ext2_filsys jfs;
-
+ ext2_filsys jfs;
+
if (!force)
- check_plausibility(journal_device);
- check_mount(journal_device, force, _("journal"));
+ check_plausibility(journal_device);
+ check_mount(journal_device, force, "journal");
retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
EXT2_FLAG_JOURNAL_DEV_OK, 0,