2
2
* mke2fs.c - Make a ext2fs filesystem.
4
* Copyright (C) 1994, 1995, 1996, 1997 Theodore Ts'o.
4
* Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
5
* 2003, 2004, 2005 by Theodore Ts'o.
7
8
* This file may be redistributed under the terms of the GNU Public
124
static int parse_version_number(const char *s)
126
int major, minor, rev;
132
major = strtol(cp, &endptr, 10);
133
if (cp == endptr || *endptr != '.')
136
minor = strtol(cp, &endptr, 10);
137
if (cp == endptr || *endptr != '.')
140
rev = strtol(cp, &endptr, 10);
143
return ((((major * 256) + minor) * 256) + rev);
123
149
* This function sets the default parameters for a filesystem
140
166
{ default_str, 3, 1024, 8192 },
141
167
{ "journal", 0, 4096, 8192 },
142
168
{ "news", 0, 4096, 4096 },
143
{ "largefile", 0, DEF_MAX_BLOCKSIZE, 1024 * 1024 },
144
{ "largefile4", 0, DEF_MAX_BLOCKSIZE, 4096 * 1024 },
169
{ "largefile", 0, 4096, 1024 * 1024 },
170
{ "largefile4", 0, 4096, 4096 * 1024 },
172
198
use_bsize = p->blocksize;
174
200
if (blocksize <= 0) {
175
if (use_bsize == DEF_MAX_BLOCKSIZE)
201
if (use_bsize == DEF_MAX_BLOCKSIZE) {
176
202
use_bsize = sys_page_size;
203
if ((linux_version_code < (2*65536 + 6*256)) &&
177
207
if (sector_size && use_bsize < sector_size)
178
208
use_bsize = sector_size;
179
209
if ((blocksize < 0) && (use_bsize < (-blocksize)))
668
699
strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name));
669
700
printf(_("Filesystem label=%s\n"), buf);
670
701
fputs(_("OS type: "), stdout);
671
switch (fs->super->s_creator_os) {
672
case EXT2_OS_LINUX: fputs("Linux", stdout); break;
673
case EXT2_OS_HURD: fputs("GNU/Hurd", stdout); break;
674
case EXT2_OS_MASIX: fputs ("Masix", stdout); break;
675
default: fputs(_("(unknown os)"), stdout);
702
os = e2p_os2string(fs->super->s_creator_os);
678
706
printf(_("Block size=%u (log=%u)\n"), fs->blocksize,
679
707
s->s_log_block_size);
685
713
s->s_r_blocks_count,
686
714
100.0 * s->s_r_blocks_count / s->s_blocks_count);
687
715
printf(_("First data block=%u\n"), s->s_first_data_block);
716
if (s->s_reserved_gdt_blocks)
717
printf(_("Maximum filesystem blocks=%lu\n"),
718
(s->s_reserved_gdt_blocks + fs->desc_blocks) *
719
(fs->blocksize / sizeof(struct ext2_group_desc)) *
720
s->s_blocks_per_group);
688
721
if (fs->group_desc_count > 1)
689
722
printf(_("%u block groups\n"), fs->group_desc_count);
732
765
sb->s_creator_os = EXT2_OS_HURD;
733
766
else if (strcasecmp(os, "masix") == 0)
734
767
sb->s_creator_os = EXT2_OS_MASIX;
768
else if (strcasecmp(os, "freebsd") == 0)
769
sb->s_creator_os = EXT2_OS_FREEBSD;
770
else if (strcasecmp(os, "lites") == 0)
771
sb->s_creator_os = EXT2_OS_LITES;
740
777
#define PATH_SET "PATH=/sbin"
742
static void parse_raid_opts(const char *opts)
779
static void parse_extended_opts(struct ext2_super_block *param,
744
782
char *buf, *token, *next, *p, *arg;
748
786
len = strlen(opts);
749
787
buf = malloc(len+1);
751
fprintf(stderr, _("Couldn't allocate memory to parse "
790
_("Couldn't allocate memory to parse options!\n"));
755
793
strcpy(buf, opts);
768
806
if (strcmp(token, "stride") == 0) {
773
811
fs_stride = strtoul(arg, &p, 0);
774
812
if (*p || (fs_stride == 0)) {
776
_("Invalid stride parameter.\n"));
814
_("Invalid stride parameter: %s\n"),
819
} else if (!strcmp(token, "resize")) {
820
unsigned long resize, bpg, rsv_groups;
821
unsigned long group_desc_count, desc_blocks;
822
unsigned int gdpb, blocksize;
830
resize = parse_num_blocks(arg,
831
param->s_log_block_size);
835
_("Invalid resize parameter: %s\n"),
840
if (resize <= param->s_blocks_count) {
842
_("The resize maximum must be greater "
843
"than the filesystem size.\n"));
848
blocksize = EXT2_BLOCK_SIZE(param);
849
bpg = param->s_blocks_per_group;
852
gdpb = blocksize / sizeof(struct ext2_group_desc);
853
group_desc_count = (param->s_blocks_count +
855
desc_blocks = (group_desc_count +
857
rsv_groups = (resize + bpg - 1) / bpg;
858
rsv_gdb = (rsv_groups + gdpb - 1) / gdpb -
860
if (rsv_gdb > EXT2_ADDR_PER_BLOCK(param))
861
rsv_gdb = EXT2_ADDR_PER_BLOCK(param);
864
param->s_feature_compat |=
865
EXT2_FEATURE_COMPAT_RESIZE_INODE;
867
param->s_reserved_gdt_blocks = rsv_gdb;
784
fprintf(stderr, _("\nBad raid options specified.\n\n"
785
"Raid options are separated by commas, "
873
fprintf(stderr, _("\nBad options specified.\n\n"
874
"Extended options are separated by commas, "
786
875
"and may take an argument which\n"
787
876
"\tis set off by an equals ('=') sign.\n\n"
788
"Valid raid options are:\n"
789
"\tstride=<stride length in blocks>\n\n"));
877
"Valid extended options are:\n"
878
"\tstride=<stride length in blocks>\n"
879
"\tresize=<resize maximum size in blocks>\n\n"));
794
884
static __u32 ok_features[3] = {
795
885
EXT3_FEATURE_COMPAT_HAS_JOURNAL |
886
EXT2_FEATURE_COMPAT_RESIZE_INODE |
796
887
EXT2_FEATURE_COMPAT_DIR_INDEX, /* Compat */
797
888
EXT2_FEATURE_INCOMPAT_FILETYPE| /* Incompat */
798
889
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|
871
if ((ut.release[0] == '1') ||
872
(ut.release[0] == '2' && ut.release[1] == '.' &&
873
ut.release[2] < '2' && ut.release[3] == '.')) {
961
linux_version_code = parse_version_number(ut.release);
962
if (linux_version_code && linux_version_code < (2*65536 + 2*256)) {
874
963
param.s_rev_level = 0;
875
964
param.s_feature_incompat = 0;
876
965
param.s_feature_compat = 0;
969
1058
strcpy(bad_blocks_filename, optarg);
972
reserved_ratio = strtoul(optarg, &tmp, 0);
1061
reserved_ratio = strtod(optarg, &tmp);
973
1062
if (reserved_ratio > 50 || *tmp) {
974
1063
com_err(program_name, 0,
975
_("bad reserved blocks percent - %s"),
1064
_("invalid reserved blocks percent - %s"),
984
1073
creator_os = optarg;
987
param.s_rev_level = atoi(optarg);
1079
param.s_rev_level = strtoul(optarg, &tmp, 0);
1081
com_err(program_name, 0,
1082
_("bad revision level - %s"), optarg);
988
1085
if (param.s_rev_level == EXT2_GOOD_OLD_REV) {
989
1086
param.s_feature_incompat = 0;
990
1087
param.s_feature_compat = 0;
1028
1119
mount_dir = optarg;
1122
num_inodes = strtoul(optarg, &tmp, 0);
1124
com_err(program_name, 0,
1125
_("bad num inodes - %s"), optarg);
1031
if (!strcmp(optarg, "none") || default_features) {
1130
if (!strcmp(optarg, "none")) {
1032
1131
param.s_feature_compat = 0;
1033
1132
param.s_feature_incompat = 0;
1034
1133
param.s_feature_ro_compat = 0;
1035
default_features = 0;
1037
if (!strcmp(optarg, "none"))
1039
1136
if (e2p_edit_feature(optarg,
1040
1137
¶m.s_feature_compat,
1041
1138
ok_features)) {
1063
1162
if ((optind == argc) && !show_version_only)
1065
device_name = argv[optind];
1067
if (optind < argc) {
1068
unsigned long tmp2 = strtoul(argv[optind++], &tmp, 0);
1070
if ((*tmp) || (tmp2 > 0xfffffffful)) {
1071
com_err(program_name, 0, _("bad blocks count - %s"),
1075
param.s_blocks_count = tmp2;
1164
device_name = argv[optind++];
1080
1166
if (!quiet || show_version_only)
1081
1167
fprintf (stderr, "mke2fs %s (%s)\n", E2FSPROGS_VERSION,
1140
1223
if ((blocksize > 4096) &&
1141
1224
(param.s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL))
1142
fprintf(stderr, "\nWarning: some 2.4 kernels do not support "
1143
"blocksizes greater than 4096 \n\tusing ext3."
1144
" Use -b 4096 if this is an issue for you.\n\n");
1225
fprintf(stderr, _("\nWarning: some 2.4 kernels do not support "
1226
"blocksizes greater than 4096\n\tusing ext3. "
1227
"Use -b 4096 if this is an issue for you.\n\n"));
1229
if (optind < argc) {
1230
param.s_blocks_count = parse_num_blocks(argv[optind++],
1231
param.s_log_block_size);
1232
if (!param.s_blocks_count) {
1233
com_err(program_name, 0, _("invalid blocks count - %s"),
1146
1241
if (param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
1165
1260
if (noaction && param.s_blocks_count) {
1166
1261
dev_size = param.s_blocks_count;
1169
1265
retval = ext2fs_get_device_size(device_name,
1170
1266
EXT2_BLOCK_SIZE(¶m),
1268
if ((retval == EFBIG) &&
1270
(param.s_log_block_size == 0)) {
1271
param.s_log_block_size = 2;
1172
1277
if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) {
1173
1278
com_err(program_name, retval,
1174
1279
_("while trying to determine filesystem size"));
1234
1339
set_fs_defaults(fs_type, ¶m, blocksize, sector_size, &inode_ratio);
1235
1340
blocksize = EXT2_BLOCK_SIZE(¶m);
1343
parse_extended_opts(¶m, extended_opts);
1345
/* Since sparse_super is the default, we would only have a problem
1346
* here if it was explicitly disabled.
1348
if ((param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE) &&
1349
!(param.s_feature_ro_compat&EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
1350
com_err(program_name, 0,
1351
_("reserved online resize blocks not supported "
1352
"on non-sparse filesystem"));
1237
1356
if (param.s_blocks_per_group) {
1238
1357
if (param.s_blocks_per_group < 256 ||
1239
1358
param.s_blocks_per_group > 8 * (unsigned) blocksize) {
1365
if (!force && param.s_blocks_count >= (1 << 31)) {
1366
com_err(program_name, 0,
1367
_("Filesystem too large. No more than 2**31-1 blocks\n"
1368
"\t (8TB using a blocksize of 4k) are currently supported."));
1246
1372
if (inode_size) {
1247
1373
if (inode_size < EXT2_GOOD_OLD_INODE_SIZE ||
1248
1374
inode_size > EXT2_BLOCK_SIZE(¶m) ||
1249
1375
inode_size & (inode_size - 1)) {
1250
1376
com_err(program_name, 0,
1251
_("bad inode size %d (min %d/max %d)"),
1377
_("invalid inode size %d (min %d/max %d)"),
1252
1378
inode_size, EXT2_GOOD_OLD_INODE_SIZE,
1432
1557
create_lost_and_found(fs);
1433
1558
reserve_inodes(fs);
1434
1559
create_bad_block_inode(fs, bb_list);
1560
if (fs->super->s_feature_compat &
1561
EXT2_FEATURE_COMPAT_RESIZE_INODE) {
1562
retval = ext2fs_create_resize_inode(fs);
1564
com_err("ext2fs_create_resize_inode", retval,
1565
_("while reserving blocks for online resize"));
1437
1571
if (journal_device) {