#include <fcntl.h>
#include <ctype.h>
#include <time.h>
-#ifdef __linux__
-#include <sys/utsname.h>
-#include <linux/version.h>
-#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#else
#include "prof_err.h"
#include "../version.h"
#include "nls-enable.h"
-#include "quota/mkquota.h"
+#include "quota/quotaio.h"
#include "mke2fs.h"
#define STRIDE_LENGTH 8
static int packed_meta_blocks;
static char *bad_blocks_filename = NULL;
static __u32 fs_stride;
-static int quotatype = -1; /* Initialize both user and group quotas by default */
+/* Initialize usr/grp quotas by default */
+static unsigned int quotatype_bits = (QUOTA_USR_BIT | QUOTA_GRP_BIT);
static __u64 offset;
static blk64_t journal_location = ~0LL;
static int proceed_delay = -1;
return l;
}
-#ifdef __linux__
-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 KERNEL_VERSION(major, minor, rev);
-}
-
-static int is_before_linux_ver(unsigned int major, unsigned int minor)
-{
- struct utsname ut;
- static int linux_version_code = -1;
-
- if (uname(&ut)) {
- perror("uname");
- exit(1);
- }
- if (linux_version_code < 0)
- linux_version_code = parse_version_number(ut.release);
- if (linux_version_code == 0)
- return 0;
-
- return linux_version_code < KERNEL_VERSION(major, minor, 0);
-}
-#else
-static int is_before_linux_ver(unsigned int major, unsigned int minor)
-{
- return 0;
-}
-#endif
-
/*
* Helper function for read_bb_file and test_disk
*/
ext2fs_block_alloc_stats_range(fs, goal,
fs->inode_blocks_per_group, +1);
ext2fs_inode_table_loc_set(fs, i, goal);
+ ext2fs_group_desc_csum_set(fs, i);
}
return 0;
}
#define PATH_SET "PATH=/sbin"
+static int option_handle_function(char *token, void *data)
+{
+ if (!strncmp(token, "usr", 3)) {
+ quotatype_bits |= QUOTA_USR_BIT;
+ } else if (!strncmp(token, "grp", 3)) {
+ quotatype_bits |= QUOTA_GRP_BIT;
+ } else {
+ fprintf(stderr, _("Invalid quotatype parameter: %s\n"),
+ token);
+ return 1;
+ }
+ return 0;
+
+}
+
static void parse_extended_opts(struct ext2_super_block *param,
const char *opts)
{
char *buf, *token, *next, *p, *arg, *badopt = 0;
int len;
int r_usage = 0;
+ int ret;
len = strlen(opts);
buf = malloc(len+1);
if (*p || num_backups > 2) {
fprintf(stderr,
_("Invalid # of backup "
- "superbocks: %s\n"),
+ "superblocks: %s\n"),
arg);
r_usage++;
continue;
badopt = token;
continue;
}
- if (!strncmp(arg, "usr", 3)) {
- quotatype = 0;
- } else if (!strncmp(arg, "grp", 3)) {
- quotatype = 1;
- } else {
- fprintf(stderr,
- _("Invalid quotatype parameter: %s\n"),
- arg);
+ ret = parse_quota_opts(arg, option_handle_function,
+ NULL);
+ if (ret) {
r_usage++;
continue;
}
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|
EXT2_FEATURE_INCOMPAT_META_BG|
EXT4_FEATURE_INCOMPAT_FLEX_BG|
+ EXT4_FEATURE_INCOMPAT_EA_INODE|
EXT4_FEATURE_INCOMPAT_MMP |
+ EXT4_FEATURE_INCOMPAT_DIRDATA|
EXT4_FEATURE_INCOMPAT_64BIT,
/* R/O compat */
EXT2_FEATURE_RO_COMPAT_LARGE_FILE|
return ret;
}
+static unsigned int get_uint_from_profile(char **types, const char *opt,
+ unsigned int def_val)
+{
+ unsigned int ret;
+ char **cpp;
+
+ profile_get_uint(profile, "defaults", opt, 0, def_val, &ret);
+ for (cpp = types; *cpp; cpp++)
+ profile_get_uint(profile, "fs_types", *cpp, opt, ret, &ret);
+ return ret;
+}
+
static double get_double_from_profile(char **types, const char *opt,
double def_val)
{
memset(&fs_param, 0, sizeof(struct ext2_super_block));
fs_param.s_rev_level = 1; /* Create revision 1 filesystems now */
- if (is_before_linux_ver(2, 2))
+ if (ext2fs_is_before_linux_ver(2, 2, 0))
fs_param.s_rev_level = 0;
if (argc && *argv) {
_("flex_bg size must be a power of 2"));
exit(1);
}
+ if (flex_bg_size > MAX_32_NUM) {
+ com_err(program_name, 0,
+ _("flex_bg size (%lu) must be less than"
+ " or equal to 2^31"), flex_bg_size);
+ exit(1);
+ }
break;
case 'i':
inode_ratio = strtoul(optarg, &tmp, 0);
_("bad revision level - %s"), optarg);
exit(1);
}
+ if (r_opt > EXT2_MAX_SUPP_REV) {
+ com_err(program_name, EXT2_ET_REV_TOO_HIGH,
+ _("while trying to create revision %d"), r_opt);
+ exit(1);
+ }
fs_param.s_rev_level = r_opt;
break;
case 's': /* deprecated */
printf(_("Using journal device's blocksize: %d\n"), blocksize);
fs_param.s_log_block_size =
int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
- ext2fs_close(jfs);
+ ext2fs_close_free(&jfs);
}
if (optind < argc) {
flags |= CHECK_FS_EXIST;
if (!quiet)
flags |= VERBOSE_CREATE;
+ if (fs_blocks_count == 0)
+ flags |= NO_SIZE;
if (!check_plausibility(device_name, flags, &is_device) && !force)
proceed_question(proceed_delay);
tmp = NULL;
if (fs_param.s_rev_level != EXT2_GOOD_OLD_REV) {
tmp = get_string_from_profile(fs_types, "base_features",
- "sparse_super,filetype,resize_inode,dir_index");
+ "sparse_super,large_file,filetype,resize_inode,dir_index");
edit_feature(tmp, &fs_param.s_feature_compat);
free(tmp);
if (use_bsize == -1) {
use_bsize = sys_page_size;
- if (is_before_linux_ver(2, 6) && use_bsize > 4096)
+ if (ext2fs_is_before_linux_ver(2, 6, 0) &&
+ use_bsize > 4096)
use_bsize = 4096;
}
if (lsector_size && use_bsize < lsector_size)
blocksize, sys_page_size);
}
- lazy_itable_init = 0;
+ /*
+ * On newer kernels we do have lazy_itable_init support. So pick the
+ * right default in case ext4 module is not loaded.
+ */
+ if (ext2fs_is_before_linux_ver(2, 6, 37))
+ lazy_itable_init = 0;
+ else
+ lazy_itable_init = 1;
+
if (access("/sys/fs/ext4/features/lazy_itable_init", R_OK) == 0)
lazy_itable_init = 1;
"See https://ext4.wiki.kernel.org/"
"index.php/Bigalloc for more information\n\n"));
- if (!quiet &&
- (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_QUOTA))
- fprintf(stderr, "%s", _("\nWarning: the quota feature is "
- "still under development\n"
- "See https://ext4.wiki.kernel.org/"
- "index.php/Quota for more information\n\n"));
-
/* Since sparse_super is the default, we would only have a problem
* here if it was explicitly disabled.
*/
inode_size = get_int_from_profile(fs_types, "inode_size", 0);
if (!flex_bg_size && (fs_param.s_feature_incompat &
EXT4_FEATURE_INCOMPAT_FLEX_BG))
- flex_bg_size = get_int_from_profile(fs_types,
- "flex_bg_size", 16);
+ flex_bg_size = get_uint_from_profile(fs_types,
+ "flex_bg_size", 16);
if (flex_bg_size) {
if (!(fs_param.s_feature_incompat &
EXT4_FEATURE_INCOMPAT_FLEX_BG)) {
{
quota_ctx_t qctx;
- quota_init_context(&qctx, fs, -1);
+ quota_init_context(&qctx, fs, QUOTA_ALL_BIT);
quota_compute_usage(qctx);
- quota_write_inode(qctx, quotatype);
+ quota_write_inode(qctx, quotatype_bits);
quota_release_context(&qctx);
return 0;
if (fs->super->s_feature_incompat &
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
create_journal_dev(fs);
- exit(ext2fs_close(fs) ? 1 : 0);
+ exit(ext2fs_close_free(&fs) ? 1 : 0);
}
if (bad_blocks_filename)
}
if (!quiet)
printf("%s", _("done\n"));
- ext2fs_close(jfs);
+ ext2fs_close_free(&jfs);
free(journal_device);
} else if ((journal_size) ||
(fs_param.s_feature_compat &
EXT4_FEATURE_RO_COMPAT_QUOTA))
create_quota_inodes(fs);
- retval = mk_hugefiles(fs);
+ retval = mk_hugefiles(fs, device_name);
if (retval)
com_err(program_name, retval, "while creating huge files");
"filesystem accounting information: "));
checkinterval = fs->super->s_checkinterval;
max_mnt_count = fs->super->s_max_mnt_count;
- retval = ext2fs_close(fs);
+ retval = ext2fs_close_free(&fs);
if (retval) {
fprintf(stderr, "%s",
_("\nWarning, had trouble writing out superblocks."));