#include <sys/types.h>
#include <linux/ext2_fs.h>
-#ifdef HAVE_LINUX_MAJOR_H
-#include <linux/major.h>
-#include <sys/stat.h> /* Only need sys/stat.h for major nr test */
-#endif
#include "et/com_err.h"
#include "uuid/uuid.h"
#include "e2p/e2p.h"
#include "ext2fs/ext2fs.h"
+#include "util.h"
#include "../version.h"
#include "nls-enable.h"
-/* Everything is STDC, these days */
-#define NOARGS void
-
#define STRIDE_LENGTH 8
#ifndef __sparc__
extern FILE *fpopen(const char *cmd, const char *mode);
const char * program_name = "mke2fs";
-const char * device_name = NULL;
+const char * device_name /* = NULL */;
/* Command line options */
-int cflag = 0;
-int verbose = 0;
-int quiet = 0;
-int super_only = 0;
-int force = 0;
-int noaction = 0;
-int journal_size = 0;
-char *bad_blocks_filename = 0;
-__u32 fs_stride = 0;
+int cflag /* = 0 */ ;
+int verbose /* = 0 */ ;
+int quiet /* = 0 */ ;
+int super_only /* = 0 */ ;
+int force /* = 0 */ ;
+int noaction /* = 0 */ ;
+int journal_size /* = 0 */ ;
+int journal_flags /* = 0 */ ;
+char *bad_blocks_filename /* = 0 */ ;
+__u32 fs_stride /* = 0 */ ;
struct ext2_super_block param;
-char *creator_os = NULL;
-char *volume_label = NULL;
-char *mount_dir = NULL;
+char *creator_os /* = NULL */ ;
+char *volume_label /* = NULL */ ;
+char *mount_dir /* = NULL */ ;
+char *journal_device /* = NULL */ ;
-static void usage(NOARGS), check_plausibility(NOARGS), check_mount(NOARGS);
-
-static void usage(NOARGS)
+static void usage(void)
{
fprintf(stderr, _("Usage: %s [-c|-t|-l filename] [-b block-size] "
- "[-f fragment-size]\n\t[-i bytes-per-inode] "
+ "[-f fragment-size]\n\t[-i bytes-per-inode] [-j journal-options]"
" [-N number-of-inodes]\n\t[-m reserved-blocks-percentage] "
"[-o creator-os] [-g blocks-per-group]\n\t[-L volume-label] "
"[-M last-mounted-directory] [-O feature[,...]]\n\t"
return l;
}
-static void proceed_question(NOARGS)
-{
- char buf[256];
- char *short_yes = _("yY");
-
- fflush(stdout);
- fflush(stderr);
- printf(_("Proceed anyway? (y,n) "));
- buf[0] = 0;
- fgets(buf, sizeof(buf), stdin);
- if (strchr(short_yes, buf[0]) == 0)
- exit(1);
-}
-
-#ifndef SCSI_BLK_MAJOR
-#define SCSI_BLK_MAJOR(M) ((M) == SCSI_DISK_MAJOR || (M) == SCSI_CDROM_MAJOR)
-#endif
-
-static void check_plausibility(NOARGS)
-{
-#ifdef HAVE_LINUX_MAJOR_H
-#ifndef MAJOR
-#define MAJOR(dev) ((dev)>>8)
-#define MINOR(dev) ((dev) & 0xff)
-#endif
-
- int val;
- struct stat s;
-
- val = stat(device_name, &s);
-
- if(val == -1) {
- fprintf(stderr, _("Could not stat %s --- %s\n"),
- device_name, error_message(errno));
- if (errno == ENOENT)
- fprintf(stderr, _("\nThe device apparently does "
- "not exist; did you specify it correctly?\n"));
- exit(1);
- }
- if(!S_ISBLK(s.st_mode)) {
- printf(_("%s is not a block special device.\n"), device_name);
- proceed_question();
- return;
- } else if ((MAJOR(s.st_rdev) == HD_MAJOR &&
- MINOR(s.st_rdev)%64 == 0) ||
- (SCSI_BLK_MAJOR(MAJOR(s.st_rdev)) &&
- MINOR(s.st_rdev)%16 == 0)) {
- printf(_("%s is entire device, not just one partition!\n"),
- device_name);
- proceed_question();
- }
-#endif
-}
-
-static void check_mount(NOARGS)
-{
- errcode_t retval;
- int mount_flags;
-
- retval = ext2fs_check_if_mounted(device_name, &mount_flags);
- if (retval) {
- com_err("ext2fs_check_if_mount", retval,
- _("while determining whether %s is mounted."),
- device_name);
- return;
- }
- if (!(mount_flags & EXT2_MF_MOUNTED))
- return;
-
- fprintf(stderr, _("%s is mounted; "), device_name);
- if (force) {
- fprintf(stderr, _("mke2fs forced anyway. "
- "Hope /etc/mtab is incorrect.\n"));
- } else {
- fprintf(stderr, _("will not make a filesystem here!\n"));
- exit(1);
- }
-}
-
/*
* This function sets the default parameters for a filesystem
*
{ 0, 0, 0, 0},
};
-static void set_fs_defaults(char *fs_type, struct ext2fs_sb *super,
+static void set_fs_defaults(char *fs_type, struct ext2_super_block *super,
int blocksize, int *inode_ratio)
{
int megs;
static void create_lost_and_found(ext2_filsys fs)
{
errcode_t retval;
- ino_t ino;
+ ext2_ino_t ino;
const char *name = "lost+found";
int i;
int lpf_size = 0;
static void reserve_inodes(ext2_filsys fs)
{
- ino_t i;
- int group;
+ ext2_ino_t i;
+ int group;
for (i = EXT2_ROOT_INO + 1; i < EXT2_FIRST_INODE(fs->super); i++) {
ext2fs_mark_inode_bitmap(fs->inode_map, i);
static void show_stats(ext2_filsys fs)
{
- struct ext2fs_sb *s = (struct ext2fs_sb *) fs->super;
+ struct ext2_super_block *s = fs->super;
char buf[80];
blk_t group_block;
int i, need, col_left;
100.0 * s->s_r_blocks_count / s->s_blocks_count);
printf(_("First data block=%u\n"), s->s_first_data_block);
if (fs->group_desc_count > 1)
- printf(_("%lu block groups\n"), fs->group_desc_count);
+ printf(_("%u block groups\n"), fs->group_desc_count);
else
- printf(_("%lu block group\n"), fs->group_desc_count);
+ 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("\n\n");
}
-#ifndef HAVE_STRCASECMP
-static int strcasecmp (char *s1, char *s2)
-{
- while (*s1 && *s2) {
- int ch1 = *s1++, ch2 = *s2++;
- if (isupper (ch1))
- ch1 = tolower (ch1);
- if (isupper (ch2))
- ch2 = tolower (ch2);
- if (ch1 != ch2)
- return ch1 - ch2;
- }
- return *s1 ? 1 : *s2 ? -1 : 0;
-}
-#endif
-
/*
* Set the S_CREATOR_OS field. Return true if OS is known,
* otherwise, 0.
int blocksize = 0;
int inode_ratio = 0;
int reserved_ratio = 5;
- ino_t num_inodes = 0;
+ ext2_ino_t num_inodes = 0;
errcode_t retval;
- int sparse_option = 0;
+ int sparse_option = 1;
char * oldpath = getenv("PATH");
- struct ext2fs_sb *param_ext2 = (struct ext2fs_sb *) ¶m;
+ struct ext2_super_block *param_ext2 = ¶m;
char * raid_opts = 0;
+ char * journal_opts = 0;
char * fs_type = 0;
- const char * feature_set = "filetype,sparse_super";
+ const char * feature_set = "filetype";
blk_t dev_size;
#ifdef linux
struct utsname ut;
}
break;
case 'j':
- journal_size = strtoul(optarg, &tmp, 0);
- if (journal_size < 4 || journal_size > 100 || *tmp) {
- com_err(program_name, 0,
- _("bad journal size - %s"), optarg);
- exit(1);
- }
+ journal_opts = optarg;
break;
case 'l':
bad_blocks_filename = malloc(strlen(optarg)+1);
if (raid_opts)
parse_raid_opts(raid_opts);
+ if (journal_opts)
+ parse_journal_opts(journal_opts);
+
if (!force)
- check_plausibility();
- check_mount();
+ check_plausibility(device_name);
+ check_mount(device_name, force, _("filesystem"));
param.s_log_frag_size = param.s_log_block_size;
*/
param.s_r_blocks_count = (param.s_blocks_count * reserved_ratio) / 100;
-#ifdef EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
+ /* Turn off features not supported by the earlier filesystem version */
+ if (param.s_rev_level == 0) {
+ sparse_option = 0;
+ feature_set = NULL;
+ }
if (sparse_option)
param_ext2->s_feature_ro_compat |=
EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
-#endif
+
if (feature_set && !strncasecmp(feature_set, "none", 4))
feature_set = NULL;
if (feature_set && e2p_edit_feature(feature_set,
ext2_filsys fs;
badblocks_list bb_list = 0;
int journal_blocks;
- struct ext2fs_sb *s;
#ifdef ENABLE_NLS
setlocale(LC_MESSAGES, "");
/*
* Generate a UUID for it...
*/
- s = (struct ext2fs_sb *) fs->super;
- uuid_generate(s->s_uuid);
+ uuid_generate(fs->super->s_uuid);
/*
* Override the creator OS, if applicable
* Set the volume label...
*/
if (volume_label) {
- memset(s->s_volume_name, 0, sizeof(s->s_volume_name));
- strncpy(s->s_volume_name, volume_label,
- sizeof(s->s_volume_name));
+ memset(fs->super->s_volume_name, 0,
+ sizeof(fs->super->s_volume_name));
+ strncpy(fs->super->s_volume_name, volume_label,
+ sizeof(fs->super->s_volume_name));
}
/*
* Set the last mount directory
*/
if (mount_dir) {
- memset(s->s_last_mounted, 0, sizeof(s->s_last_mounted));
- strncpy(s->s_last_mounted, mount_dir,
- sizeof(s->s_last_mounted));
+ memset(fs->super->s_last_mounted, 0,
+ sizeof(fs->super->s_last_mounted));
+ strncpy(fs->super->s_last_mounted, mount_dir,
+ sizeof(fs->super->s_last_mounted));
}
if (!quiet || noaction)
zap_sector(fs, 0);
#endif
}
- if (journal_size) {
+
+ journal_blocks = journal_size * 1024 / (fs->blocksize / 1024);
+ if (journal_device) {
+ if (!force)
+ check_plausibility(journal_device);
+ check_mount(journal_device, force, _("journal"));
+
+ if (!quiet)
+ printf(_("Creating journal on device %s: "),
+ journal_device);
+ retval = ext2fs_add_journal_device(fs, journal_device,
+ journal_blocks,
+ journal_flags);
+ if(retval) {
+ com_err (program_name, retval,
+ _("while trying to create journal on device %s"),
+ journal_device);
+ exit(1);
+ }
+ if (!quiet)
+ printf(_("done\n"));
+ } else if (journal_size) {
if (!quiet)
- printf(_("Creating journal: "));
- journal_blocks = journal_size * 1024 /
- (fs->blocksize / 1024);
- retval = ext2fs_add_journal_fs(fs, journal_blocks);
+ printf(_("Creating journal (%d blocks): "),
+ journal_blocks);
+ retval = ext2fs_add_journal_inode(fs, journal_blocks,
+ journal_flags);
if (retval) {
com_err (program_name, retval,
_("while trying to create journal"));