* enforced (but it's not much fun on a character device :-).
*/
-#define _XOPEN_SOURCE 600 /* for inclusion of PATH_MAX */
+#define _XOPEN_SOURCE 600
#include "config.h"
#include <stdio.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
+#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
+#endif
#include <libgen.h>
#include <limits.h>
#include <blkid/blkid.h>
int journal_flags;
static int lazy_itable_init;
static int packed_meta_blocks;
+int no_copy_xattrs;
static char *bad_blocks_filename = NULL;
static __u32 fs_stride;
/* Initialize usr/grp quotas by default */
static blk64_t dev_size;
static struct ext2_super_block fs_param;
+static __u32 zero_buf[4];
static char *fs_uuid = NULL;
static char *creator_os;
static char *volume_label;
static char *undo_file;
static int android_sparse_file; /* -E android_sparse */
-static char *android_sparse_params;
static profile_t profile;
exit(1);
}
- for (ino = 1; ino < EXT2_FIRST_INO(fs->super); ino++)
- ext2fs_write_inode_full(fs, ino, inode,
- EXT2_INODE_SIZE(fs->super));
+ for (ino = 1; ino < EXT2_FIRST_INO(fs->super); ino++) {
+ retval = ext2fs_write_inode_full(fs, ino, inode,
+ EXT2_INODE_SIZE(fs->super));
+ if (retval) {
+ com_err("ext2fs_write_inode_full", retval,
+ _("while writing reserved inodes"));
+ exit(1);
+ }
+ }
ext2fs_free_mem(&inode);
}
}
if (sync_kludge) {
if (sync_kludge == 1)
- sync();
+ io_channel_flush(fs->io);
else if ((i % sync_kludge) == 0)
- sync();
+ io_channel_flush(fs->io);
}
}
ext2fs_numeric_progress_close(fs, &progress,
continue;
}
param->s_desc_size = desc_size;
+ } else if (strcmp(token, "hash_seed") == 0) {
+ if (!arg) {
+ r_usage++;
+ badopt = token;
+ continue;
+ }
+ if (uuid_parse(arg,
+ (unsigned char *)param->s_hash_seed) != 0) {
+ fprintf(stderr,
+ _("Invalid hash seed: %s\n"), arg);
+ r_usage++;
+ continue;
+ }
} else if (strcmp(token, "offset") == 0) {
if (!arg) {
r_usage++;
r_usage++;
continue;
}
+ } else if (strcmp(token, "no_copy_xattrs") == 0) {
+ no_copy_xattrs = 1;
+ continue;
} else if (strcmp(token, "num_backup_sb") == 0) {
if (!arg) {
r_usage++;
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_64BIT|
EXT4_FEATURE_INCOMPAT_INLINE_DATA|
}
putenv (newpath);
- tmp = getenv("MKE2FS_SYNC");
- if (tmp)
- sync_kludge = atoi(tmp);
-
/* Determine the system page size if possible */
#ifdef HAVE_SYSCONF
#if (!defined(_SC_PAGESIZE) && defined(_SC_PAGE_SIZE))
if (optind < argc)
usage();
+ profile_get_integer(profile, "options", "sync_kludge", 0, 0,
+ &sync_kludge);
+ tmp = getenv("MKE2FS_SYNC");
+ if (tmp)
+ sync_kludge = atoi(tmp);
+
profile_get_integer(profile, "options", "proceed_delay", 0, 0,
&proceed_delay);
dev_size = fs_blocks_count;
retval = 0;
} else
+#ifndef _WIN32
retval = ext2fs_get_device_size2(device_name,
EXT2_BLOCK_SIZE(&fs_param),
&dev_size);
-
+#else
+ retval = ext2fs_get_device_size(device_name,
+ EXT2_BLOCK_SIZE(&fs_param),
+ &dev_size);
+#endif
if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) {
com_err(program_name, retval, "%s",
_("while trying to determine filesystem size"));
ext2fs_clear_feature_filetype(&fs_param);
ext2fs_clear_feature_huge_file(&fs_param);
ext2fs_clear_feature_metadata_csum(&fs_param);
+ ext2fs_clear_feature_ea_inode(&fs_param);
}
edit_feature(fs_features ? fs_features : tmp,
&fs_param.s_feature_compat);
"metadata_csum feature.\n"));
exit(1);
}
+ if (ext2fs_has_feature_ea_inode(&fs_param)) {
+ fprintf(stderr, "%s", _("The HURD does not support the "
+ "ea_inode feature.\n"));
+ exit(1);
+ }
}
/* Get the hardware sector sizes, if available */
(unsigned long long) fs_blocks_count);
}
+ if (quotatype_bits & QUOTA_PRJ_BIT)
+ ext2fs_set_feature_project(&fs_param);
+
+ if (ext2fs_has_feature_project(&fs_param)) {
+ quotatype_bits |= QUOTA_PRJ_BIT;
+ if (inode_size == EXT2_GOOD_OLD_INODE_SIZE) {
+ com_err(program_name, 0,
+ _("%d byte inodes are too small for "
+ "project quota"),
+ inode_size);
+ exit(1);
+ }
+ if (inode_size == 0) {
+ inode_size = get_int_from_profile(fs_types,
+ "inode_size", 0);
+ if (inode_size <= EXT2_GOOD_OLD_INODE_SIZE*2)
+ inode_size = EXT2_GOOD_OLD_INODE_SIZE*2;
+ }
+ }
+
/* Don't allow user to set both metadata_csum and uninit_bg bits. */
if (ext2fs_has_feature_metadata_csum(&fs_param) &&
ext2fs_has_feature_gdt_csum(&fs_param))
exit(1);
}
- /*
- * If inode size is 128 and project quota is enabled, we need
- * to notify users that project ID will never be useful.
- */
- if (ext2fs_has_feature_project(&fs_param) &&
- fs_param.s_inode_size == EXT2_GOOD_OLD_INODE_SIZE) {
- com_err(program_name, 0,
- _("%d byte inodes are too small for project quota; "
- "specify larger size"),
- fs_param.s_inode_size);
- exit(1);
- }
-
/* Make sure number of inodes specified will fit in 32 bits */
if (num_inodes == 0) {
unsigned long long n;
if (!quiet)
flags |= EXT2_FLAG_PRINT_PROGRESS;
if (android_sparse_file) {
- android_sparse_params = malloc(PATH_MAX + 32);
+ char *android_sparse_params = malloc(strlen(device_name) + 48);
+
if (!android_sparse_params) {
com_err(program_name, ENOMEM, "%s",
_("in malloc for android_sparse_params"));
exit(1);
}
- snprintf(android_sparse_params, PATH_MAX + 32, "%s:%u:%u",
+ sprintf(android_sparse_params, "(%s):%u:%u",
device_name, fs_param.s_blocks_count,
1024 << fs_param.s_log_block_size);
retval = ext2fs_initialize(android_sparse_params, flags,
&fs_param, sparse_io_manager, &fs);
+ free(android_sparse_params);
} else
retval = ext2fs_initialize(device_name, flags, &fs_param,
io_ptr, &fs);
if (ext2fs_has_feature_csum_seed(fs->super) &&
!ext2fs_has_feature_metadata_csum(fs->super)) {
printf("%s", _("The metadata_csum_seed feature "
- "requres the metadata_csum feature.\n"));
+ "requires the metadata_csum feature.\n"));
exit(1);
}
* Parse or generate a UUID for the filesystem
*/
if (fs_uuid) {
- if (uuid_parse(fs_uuid, fs->super->s_uuid) !=0) {
+ if ((strcasecmp(fs_uuid, "null") == 0) ||
+ (strcasecmp(fs_uuid, "clear") == 0)) {
+ uuid_clear(fs->super->s_uuid);
+ } else if (strcasecmp(fs_uuid, "time") == 0) {
+ uuid_generate_time(fs->super->s_uuid);
+ } else if (strcasecmp(fs_uuid, "random") == 0) {
+ uuid_generate(fs->super->s_uuid);
+ } else if (uuid_parse(fs_uuid, fs->super->s_uuid) != 0) {
com_err(device_name, 0, "could not parse UUID: %s\n",
fs_uuid);
exit(1);
free(hash_alg_str);
fs->super->s_def_hash_version = (hash_alg >= 0) ? hash_alg :
EXT2_HASH_HALF_MD4;
- uuid_generate((unsigned char *) fs->super->s_hash_seed);
+
+ if (memcmp(fs_param.s_hash_seed, zero_buf,
+ sizeof(fs_param.s_hash_seed)) != 0) {
+ memcpy(fs->super->s_hash_seed, fs_param.s_hash_seed,
+ sizeof(fs->super->s_hash_seed));
+ } else
+ uuid_generate((unsigned char *) fs->super->s_hash_seed);
/*
* Periodic checks can be enabled/disabled via config file.
if (ext2fs_has_feature_bigalloc(&fs_param))
fix_cluster_bg_counts(fs);
- if (ext2fs_has_feature_project(&fs_param))
- quotatype_bits |= QUOTA_PRJ_BIT;
if (ext2fs_has_feature_quota(&fs_param))
create_quota_inodes(fs);
max_mnt_count = fs->super->s_max_mnt_count;
retval = ext2fs_close_free(&fs);
if (retval) {
- fprintf(stderr, "%s",
- _("\nWarning, had trouble writing out superblocks.\n"));
+ com_err(program_name, retval, "%s",
+ _("while writing out and closing file system"));
+ retval = 1;
} else if (!quiet) {
printf("%s", _("done\n\n"));
if (!getenv("MKE2FS_SKIP_CHECK_MSG"))