137
140
{ default_str, 3, 1024, 8192 },
138
141
{ "journal", 0, 4096, 8192 },
139
142
{ "news", 0, 4096, 4096 },
140
{ "largefile", 0, 4096, 1024 * 1024 },
141
{ "largefile4", 0, 4096, 4096 * 1024 },
143
{ "largefile", 0, DEF_MAX_BLOCKSIZE, 1024 * 1024 },
144
{ "largefile4", 0, DEF_MAX_BLOCKSIZE, 4096 * 1024 },
145
148
static void set_fs_defaults(const char *fs_type,
146
149
struct ext2_super_block *super,
147
int blocksize, int *inode_ratio)
150
int blocksize, int sector_size,
151
155
struct mke2fs_defaults *p;
156
int use_bsize = 1024;
153
megs = (super->s_blocks_count * (EXT2_BLOCK_SIZE(super) / 1024) /
158
megs = super->s_blocks_count * (EXT2_BLOCK_SIZE(super) / 1024) / 1024;
156
160
ratio = *inode_ratio;
160
164
if ((strcmp(p->type, fs_type) != 0) &&
161
165
(strcmp(p->type, default_str) != 0))
163
if ((p->size != 0) &&
167
if ((p->size != 0) && (megs > p->size))
167
*inode_ratio = p->inode_ratio;
168
if (blocksize == 0) {
169
super->s_log_frag_size = super->s_log_block_size =
170
int_log2(p->blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
174
super->s_blocks_count /= EXT2_BLOCK_SIZE(super) / 1024;
170
*inode_ratio = p->inode_ratio < blocksize ?
171
blocksize : p->inode_ratio;
172
use_bsize = p->blocksize;
174
if (blocksize <= 0) {
175
if (use_bsize == DEF_MAX_BLOCKSIZE)
176
use_bsize = sys_page_size;
177
if (sector_size && use_bsize < sector_size)
178
use_bsize = sector_size;
179
if ((blocksize < 0) && (use_bsize < (-blocksize)))
180
use_bsize = -blocksize;
181
blocksize = use_bsize;
182
super->s_blocks_count /= blocksize / 1024;
184
super->s_log_frag_size = super->s_log_block_size =
185
int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
178
190
* Helper function for read_bb_file and test_disk
180
static void invalid_block(ext2_filsys fs, blk_t blk)
192
static void invalid_block(ext2_filsys fs EXT2FS_ATTR((unused)), blk_t blk)
182
194
fprintf(stderr, _("Bad block %u out of range; ignored.\n"), blk);
262
275
fprintf(stderr, _("Blocks %d through %d must be good "
263
276
"in order to build a filesystem.\n"),
264
277
fs->super->s_first_data_block, must_be_good);
265
fprintf(stderr, _("Aborting....\n"));
278
fputs(_("Aborting....\n"), stderr);
333
347
sprintf(progress->format, "%%%dd/%%%dld", i, i);
334
348
memset(progress->backup, '\b', sizeof(progress->backup)-1);
335
349
progress->backup[sizeof(progress->backup)-1] = 0;
336
if ((2*i)+1 < sizeof(progress->backup))
350
if ((2*i)+1 < (int) sizeof(progress->backup))
337
351
progress->backup[(2*i)+1] = 0;
338
352
progress->max = max;
354
progress->skip_progress = 0;
355
if (getenv("MKE2FS_SKIP_PROGRESS"))
356
progress->skip_progress++;
340
358
fputs(label, stdout);
344
362
static void progress_update(struct progress_struct *progress, __u32 val)
346
if (progress->format[0] == 0)
364
if ((progress->format[0] == 0) || progress->skip_progress)
348
366
printf(progress->format, val, progress->max);
349
367
fputs(progress->backup, stdout);
399
417
if (next_update_incr < 1)
400
418
next_update_incr = 1;
401
419
for (j=0; j < num; j += STRIDE_LENGTH, blk += STRIDE_LENGTH) {
402
if (num-j > STRIDE_LENGTH)
421
if (count > STRIDE_LENGTH)
403
422
count = STRIDE_LENGTH;
406
423
retval = io_channel_write_blk(fs->io, blk, count, buf);
603
memset(buf, 0, 512*nsect);
586
604
io_channel_set_blksize(fs->io, 512);
587
605
retval = io_channel_write_blk(fs->io, sect, -512*nsect, buf);
588
606
io_channel_set_blksize(fs->io, fs->blocksize);
648
667
memset(buf, 0, sizeof(buf));
649
668
strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name));
650
669
printf(_("Filesystem label=%s\n"), buf);
651
printf(_("OS type: "));
670
fputs(_("OS type: "), stdout);
652
671
switch (fs->super->s_creator_os) {
653
case EXT2_OS_LINUX: printf ("Linux"); break;
654
case EXT2_OS_HURD: printf ("GNU/Hurd"); break;
655
case EXT2_OS_MASIX: printf ("Masix"); break;
656
default: printf (_("(unknown 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);
659
678
printf(_("Block size=%u (log=%u)\n"), fs->blocksize,
775
794
static __u32 ok_features[3] = {
776
EXT3_FEATURE_COMPAT_HAS_JOURNAL, /* Compat */
795
EXT3_FEATURE_COMPAT_HAS_JOURNAL |
796
EXT2_FEATURE_COMPAT_DIR_INDEX, /* Compat */
777
797
EXT2_FEATURE_INCOMPAT_FILETYPE| /* Incompat */
778
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV,
798
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|
799
EXT2_FEATURE_INCOMPAT_META_BG,
779
800
EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER /* R/O compat */
783
804
static void PRS(int argc, char *argv[])
788
blk_t group_blk_max = 8192;
789
809
int blocksize = 0;
790
810
int inode_ratio = 0;
791
812
int reserved_ratio = 5;
814
int show_version_only = 0;
792
815
ext2_ino_t num_inodes = 0;
793
816
errcode_t retval;
794
817
char * oldpath = getenv("PATH");
815
839
tmp = getenv("MKE2FS_SYNC");
817
841
sync_kludge = atoi(tmp);
843
/* Determine the system page size if possible */
845
#if (!defined(_SC_PAGESIZE) && defined(_SC_PAGE_SIZE))
846
#define _SC_PAGESIZE _SC_PAGE_SIZE
849
sysval = sysconf(_SC_PAGESIZE);
851
sys_page_size = sysval;
852
#endif /* _SC_PAGESIZE */
853
#endif /* HAVE_SYSCONF */
819
855
setbuf(stdout, NULL);
820
856
setbuf(stderr, NULL);
823
859
param.s_rev_level = 1; /* Create revision 1 filesystems now */
824
860
param.s_feature_incompat |= EXT2_FEATURE_INCOMPAT_FILETYPE;
825
861
param.s_feature_ro_compat |= EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
863
param.s_feature_compat |= EXT2_FEATURE_COMPAT_DIR_INDEX;
828
867
if (uname(&ut)) {
838
877
param.s_feature_ro_compat = 0;
841
fprintf (stderr, "mke2fs %s (%s)\n",
842
E2FSPROGS_VERSION, E2FSPROGS_DATE);
844
881
if (argc && *argv) {
845
882
program_name = get_progname(*argv);
853
890
"b:cf:g:i:jl:m:no:qr:R:s:tvI:J:ST:FL:M:N:O:V")) != EOF)
856
blocksize = strtoul(optarg, &tmp, 0);
857
if (blocksize < 1024 || blocksize > 4096 || *tmp) {
893
blocksize = strtol(optarg, &tmp, 0);
894
b = (blocksize > 0) ? blocksize : -blocksize;
895
if (b < EXT2_MIN_BLOCK_SIZE ||
896
b > EXT2_MAX_BLOCK_SIZE || *tmp) {
858
897
com_err(program_name, 0,
859
898
_("bad block size - %s"), optarg);
862
param.s_log_block_size =
863
int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
864
group_blk_max = blocksize * 8;
901
if (blocksize > 4096)
902
fprintf(stderr, _("Warning: blocksize %d not "
903
"usable on most systems.\n"),
906
param.s_log_block_size =
907
int_log2(blocksize >>
908
EXT2_MIN_BLOCK_LOG_SIZE);
866
910
case 'c': /* Check for bad blocks */
867
911
case 't': /* deprecated */
871
915
size = strtoul(optarg, &tmp, 0);
872
if (size < 1024 || size > 4096 || *tmp) {
916
if (size < EXT2_MIN_BLOCK_SIZE ||
917
size > EXT2_MAX_BLOCK_SIZE || *tmp) {
873
918
com_err(program_name, 0,
874
919
_("bad fragment size - %s"),
897
942
inode_ratio = strtoul(optarg, &tmp, 0);
898
if (inode_ratio < 1024 || inode_ratio > 4096 * 1024 ||
943
if (inode_ratio < EXT2_MIN_BLOCK_SIZE ||
944
inode_ratio > EXT2_MAX_BLOCK_SIZE * 1024 ||
900
946
com_err(program_name, 0,
901
_("bad inode ratio - %s"), optarg);
947
_("bad inode ratio %s (min %d/max %d"),
948
optarg, EXT2_MIN_BLOCK_SIZE,
949
EXT2_MAX_BLOCK_SIZE);
954
1002
#ifdef EXT2_DYNAMIC_REV
956
param.s_inode_size = atoi(optarg);
1004
inode_size = strtoul(optarg, &tmp, 0);
1006
com_err(program_name, 0,
1007
_("bad inode size - %s"), optarg);
1004
1057
/* Print version number and exit */
1005
fprintf(stderr, _("\tUsing %s\n"),
1006
error_message(EXT2_ET_BASE));
1058
show_version_only++;
1063
if ((optind == argc) && !show_version_only)
1013
1065
device_name = argv[optind];
1025
1077
if (optind < argc)
1080
if (!quiet || show_version_only)
1081
fprintf (stderr, "mke2fs %s (%s)\n", E2FSPROGS_VERSION,
1084
if (show_version_only) {
1085
fprintf(stderr, _("\tUsing %s\n"),
1086
error_message(EXT2_ET_BASE));
1029
1091
parse_raid_opts(raid_opts);
1032
1094
* If there's no blocksize specified and there is a journal
1033
1095
* device, use it to figure out the blocksize
1035
if (blocksize == 0 && journal_device) {
1097
if (blocksize <= 0 && journal_device) {
1036
1098
ext2_filsys jfs;
1101
#ifdef CONFIG_TESTIO_DEBUG
1102
io_ptr = test_io_manager;
1103
test_io_backing_manager = unix_io_manager;
1105
io_ptr = unix_io_manager;
1038
1107
retval = ext2fs_open(journal_device,
1039
1108
EXT2_FLAG_JOURNAL_DEV_OK, 0,
1040
0, unix_io_manager, &jfs);
1042
1111
com_err(program_name, retval,
1043
1112
_("while trying to open journal device %s\n"),
1044
1113
journal_device);
1116
if ((blocksize < 0) && (jfs->blocksize < (unsigned) (-blocksize))) {
1117
com_err(program_name, 0,
1118
_("Journal dev blocksize (%d) smaller than "
1119
"minimum blocksize %d\n"), jfs->blocksize,
1047
1123
blocksize = jfs->blocksize;
1048
1124
param.s_log_block_size =
1049
1125
int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE);
1050
1126
ext2fs_close(jfs);
1129
if (blocksize > sys_page_size) {
1131
com_err(program_name, 0,
1132
_("%d-byte blocks too big for system (max %d)"),
1133
blocksize, sys_page_size);
1136
fprintf(stderr, _("Warning: %d-byte blocks too big for system "
1137
"(max %d), forced to continue\n"),
1138
blocksize, sys_page_size);
1140
if ((blocksize > 4096) &&
1141
(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");
1053
1146
if (param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
1055
1148
fs_type = "journal";
1104
1197
param.s_blocks_count = dev_size;
1198
if (sys_page_size > EXT2_BLOCK_SIZE(¶m))
1199
param.s_blocks_count &= ~((sys_page_size /
1200
EXT2_BLOCK_SIZE(¶m))-1);
1107
1203
} else if (!force && (param.s_blocks_count > dev_size)) {
1108
1204
com_err(program_name, 0,
1109
_("Filesystem larger than apparent filesystem size."));
1205
_("Filesystem larger than apparent device size."));
1110
1206
proceed_question();
1119
1215
journal_size = -1;
1121
set_fs_defaults(fs_type, ¶m, blocksize, &inode_ratio);
1217
/* Set first meta blockgroup via an environment variable */
1218
/* (this is mostly for debugging purposes) */
1219
if ((param.s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) &&
1220
((tmp = getenv("MKE2FS_FIRST_META_BG"))))
1221
param.s_first_meta_bg = atoi(tmp);
1223
/* Get the hardware sector size, if available */
1224
retval = ext2fs_get_device_sectsize(device_name, §or_size);
1226
com_err(program_name, retval,
1227
_("while trying to determine hardware sector size"));
1231
if ((tmp = getenv("MKE2FS_DEVICE_SECTSIZE")) != NULL)
1232
sector_size = atoi(tmp);
1234
set_fs_defaults(fs_type, ¶m, blocksize, sector_size, &inode_ratio);
1235
blocksize = EXT2_BLOCK_SIZE(¶m);
1123
1237
if (param.s_blocks_per_group) {
1124
1238
if (param.s_blocks_per_group < 256 ||
1125
param.s_blocks_per_group > group_blk_max || *tmp) {
1239
param.s_blocks_per_group > 8 * (unsigned) blocksize) {
1126
1240
com_err(program_name, 0,
1127
1241
_("blocks per group count out of range"));
1247
if (inode_size < EXT2_GOOD_OLD_INODE_SIZE ||
1248
inode_size > EXT2_BLOCK_SIZE(¶m) ||
1249
inode_size & (inode_size - 1)) {
1250
com_err(program_name, 0,
1251
_("bad inode size %d (min %d/max %d)"),
1252
inode_size, EXT2_GOOD_OLD_INODE_SIZE,
1256
if (inode_size != EXT2_GOOD_OLD_INODE_SIZE)
1257
fprintf(stderr, _("Warning: %d-byte inodes not usable "
1258
"on most systems\n"),
1260
param.s_inode_size = inode_size;
1133
1264
* Calculate number of inodes based on the inode ratio
1135
1266
param.s_inodes_count = num_inodes ? num_inodes :
1136
((__u64) param.s_blocks_count * EXT2_BLOCK_SIZE(¶m))
1267
((__u64) param.s_blocks_count * blocksize)
1160
1293
PRS(argc, argv);
1295
#ifdef CONFIG_TESTIO_DEBUG
1296
io_ptr = test_io_manager;
1297
test_io_backing_manager = unix_io_manager;
1299
io_ptr = unix_io_manager;
1163
1303
* Initialize the superblock....
1165
1305
retval = ext2fs_initialize(device_name, 0, ¶m,
1166
unix_io_manager, &fs);
1168
1308
com_err(device_name, retval, _("while setting up superblock"));
1181
1321
uuid_generate(fs->super->s_uuid);
1324
* Initialize the directory index variables
1326
fs->super->s_def_hash_version = EXT2_HASH_TEA;
1327
uuid_generate((unsigned char *) fs->super->s_hash_seed);
1184
1330
* Add "jitter" to the superblock's check interval so that we
1185
1331
* don't check all the filesystems at the same time. We use a
1186
1332
* kludgy hack of using the UUID to derive a random jitter value.
1255
1401
fs->flags &= ~(EXT2_FLAG_IB_DIRTY|EXT2_FLAG_BB_DIRTY);
1257
1403
/* rsv must be a power of two (64kB is MD RAID sb alignment) */
1258
int rsv = 65536 / fs->blocksize;
1404
unsigned int rsv = 65536 / fs->blocksize;
1259
1405
unsigned long blocks = fs->super->s_blocks_count;
1260
1406
unsigned long start;
1280
1426
com_err(program_name, retval,
1281
_("zeroing block %u at end of filesystem"),
1427
_("while zeroing block %u at end of filesystem"),
1285
1430
write_inode_tables(fs);
1286
1431
create_root_dir(fs);