#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__
char *mount_dir /* = NULL */ ;
char *journal_device /* = NULL */ ;
-static void usage(NOARGS);
-static void check_plausibility(const char *device);
-static void check_mount(const char *device);
-
-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] [-j journal-options]"
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(const char *device)
-{
-#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, &s);
-
- if(val == -1) {
- fprintf(stderr, _("Could not stat %s --- %s\n"),
- device, 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);
- 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);
- proceed_question();
- }
-#endif
-}
-
-static void check_mount(const char *device)
-{
- errcode_t retval;
- int mount_flags;
-
- retval = ext2fs_check_if_mounted(device, &mount_flags);
- if (retval) {
- com_err("ext2fs_check_if_mount", retval,
- _("while determining whether %s is mounted."),
- device);
- return;
- }
- if (!(mount_flags & EXT2_MF_MOUNTED))
- return;
-
- fprintf(stderr, _("%s is mounted; "), device);
- 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.
}
}
-static void parse_journal_opts(const char *opts)
-{
- char *buf, *token, *next, *p, *arg;
- int len;
- int journal_usage = 0;
-
- len = strlen(opts);
- buf = malloc(len+1);
- if (!buf) {
- fprintf(stderr, _("Couldn't allocate memory to parse "
- "journal options!\n"));
- exit(1);
- }
- strcpy(buf, opts);
- for (token = buf; token && *token; token = next) {
- p = strchr(token, ',');
- next = 0;
- if (p) {
- *p = 0;
- next = p+1;
- }
- arg = strchr(token, '=');
- if (arg) {
- *arg = 0;
- arg++;
- }
- printf("Journal option=%s, argument=%s\n", token,
- arg ? arg : "NONE");
- if (strcmp(token, "device") == 0) {
- if (!arg) {
- journal_usage++;
- continue;
- }
- journal_device = arg;
- } else if (strcmp(token, "size") == 0) {
- if (!arg) {
- journal_usage++;
- continue;
- }
- journal_size = strtoul(arg, &p, 0);
- journal_size_check:
- if (*p || (journal_size < 4 || journal_size > 100)) {
- fprintf(stderr,
- _("Invalid journal size parameter - %s.\n"),
- arg);
- journal_usage++;
- continue;
- }
- } else if (strcmp(token, "v1_superblock") == 0) {
- journal_flags |= EXT2_MKJOURNAL_V1_SUPER;
- continue;
- } else {
- journal_size = strtoul(token, &p, 0);
- if (*p)
- journal_usage++;
- else
- goto journal_size_check;
- }
- }
- if (journal_usage) {
- fprintf(stderr, _("\nBad journal options specified.\n\n"
- "Journal options are separated by commas, "
- "and may take an argument which\n"
- "\tis set off by an equals ('=') sign.\n\n"
- "Valid raid options are:\n"
- "\tsize=<journal size in megabytes>\n"
- "\tdevice=<journal device>\n\n"
- "Journal size must be between "
- "4 and 100 megabytes.\n\n" ));
- exit(1);
- }
-}
-
static __u32 ok_features[3] = {
0, /* Compat */
EXT2_FEATURE_INCOMPAT_FILETYPE, /* Incompat */
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 = 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;
if (!force)
check_plausibility(device_name);
- check_mount(device_name);
+ check_mount(device_name, force, _("filesystem"));
param.s_log_frag_size = param.s_log_block_size;
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)
if (journal_device) {
if (!force)
check_plausibility(journal_device);
- check_mount(journal_device);
+ check_mount(journal_device, force, _("journal"));
if (!quiet)
printf(_("Creating journal on device %s: "),
if (!quiet)
printf(_("Creating journal (%d blocks): "),
journal_blocks);
- retval = ext2fs_add_journal_fs(fs, journal_blocks,
- journal_flags);
+ retval = ext2fs_add_journal_inode(fs, journal_blocks,
+ journal_flags);
if (retval) {
com_err (program_name, retval,
_("while trying to create journal"));