format_ext.c (rufus-3.12) | : | format_ext.c (rufus-3.13) | ||
---|---|---|---|---|
skipping to change at line 193 | skipping to change at line 193 | |||
} | } | |||
} | } | |||
errcode_t ext2fs_print_progress(int64_t cur_value, int64_t max_value) | errcode_t ext2fs_print_progress(int64_t cur_value, int64_t max_value) | |||
{ | { | |||
static int64_t last_value = -1; | static int64_t last_value = -1; | |||
if (max_value == 0) | if (max_value == 0) | |||
return 0; | return 0; | |||
UpdateProgressWithInfo(OP_FORMAT, MSG_217, (uint64_t)((ext2_percent_start * max_value) + (ext2_percent_share * cur_value)), max_value); | UpdateProgressWithInfo(OP_FORMAT, MSG_217, (uint64_t)((ext2_percent_start * max_value) + (ext2_percent_share * cur_value)), max_value); | |||
cur_value = (int64_t)(((float)cur_value / (float)max_value) * min(ext2_ma x_marker, (float)max_value)); | cur_value = (int64_t)(((float)cur_value / (float)max_value) * min(ext2_ma x_marker, (float)max_value)); | |||
if ((cur_value < last_value) || (cur_value > last_value)) { | if (cur_value != last_value) { | |||
last_value = cur_value; | last_value = cur_value; | |||
uprintfs("+"); | uprintfs("+"); | |||
} | } | |||
return IS_ERROR(FormatStatus) ? EXT2_ET_CANCEL_REQUESTED : 0; | return IS_ERROR(FormatStatus) ? EXT2_ET_CANCEL_REQUESTED : 0; | |||
} | } | |||
const char* GetExtFsLabel(DWORD DriveIndex, uint64_t PartitionOffset) | const char* GetExtFsLabel(DWORD DriveIndex, uint64_t PartitionOffset) | |||
{ | { | |||
static char label[EXT2_LABEL_LEN + 1]; | static char label[EXT2_LABEL_LEN + 1]; | |||
errcode_t r; | errcode_t r; | |||
skipping to change at line 223 | skipping to change at line 223 | |||
strncpy(label, ext2fs->super->s_volume_name, EXT2_LABEL_LEN); | strncpy(label, ext2fs->super->s_volume_name, EXT2_LABEL_LEN); | |||
label[EXT2_LABEL_LEN] = 0; | label[EXT2_LABEL_LEN] = 0; | |||
} | } | |||
if (ext2fs != NULL) | if (ext2fs != NULL) | |||
ext2fs_close(ext2fs); | ext2fs_close(ext2fs); | |||
return (r == 0) ? label : NULL; | return (r == 0) ? label : NULL; | |||
} | } | |||
#define TEST_IMG_PATH "\\??\\C:\\tmp\\disk.img" | #define TEST_IMG_PATH "\\??\\C:\\tmp\\disk.img" | |||
#define TEST_IMG_SIZE 4000 // Size in MB | #define TEST_IMG_SIZE 4000 // Size in MB | |||
#define SET_EXT2_FORMAT_ERROR(x) if (!IS_ERROR(FormatStatus)) FormatStatus = ext2_last_winerror(x) | ||||
BOOL FormatExtFs(DWORD DriveIndex, uint64_t PartitionOffset, DWORD BlockSize, LP CSTR FSName, LPCSTR Label, DWORD Flags) | BOOL FormatExtFs(DWORD DriveIndex, uint64_t PartitionOffset, DWORD BlockSize, LP CSTR FSName, LPCSTR Label, DWORD Flags) | |||
{ | { | |||
// Mostly taken from mke2fs.conf | // Mostly taken from mke2fs.conf | |||
const float reserve_ratio = 0.05f; | const float reserve_ratio = 0.05f; | |||
const ext2fs_default_t ext2fs_default[5] = { | const ext2fs_default_t ext2fs_default[5] = { | |||
{ 3 * MB, 1024, 128, 3}, // "floppy" | { 3 * MB, 1024, 128, 3}, // "floppy" | |||
{ 512 * MB, 1024, 128, 2}, // "small" | { 512 * MB, 1024, 128, 2}, // "small" | |||
{ 4 * GB, 4096, 256, 2}, // "default" | { 4 * GB, 4096, 256, 2}, // "default" | |||
{ 16 * GB, 4096, 256, 3}, // "big" | { 16 * GB, 4096, 256, 3}, // "big" | |||
skipping to change at line 292 | skipping to change at line 293 | |||
uprintf("Invalid ext file system version requested, defau lting to ext3"); | uprintf("Invalid ext file system version requested, defau lting to ext3"); | |||
FSName = FileSystemLabel[FS_EXT3]; | FSName = FileSystemLabel[FS_EXT3]; | |||
} | } | |||
PrintInfoDebug(0, MSG_222, FSName); | PrintInfoDebug(0, MSG_222, FSName); | |||
UpdateProgressWithInfoInit(NULL, TRUE); | UpdateProgressWithInfoInit(NULL, TRUE); | |||
// Figure out the volume size and block size | // Figure out the volume size and block size | |||
r = ext2fs_get_device_size2(volume_name, KB, &size); | r = ext2fs_get_device_size2(volume_name, KB, &size); | |||
if ((r != 0) || (size == 0)) { | if ((r != 0) || (size == 0)) { | |||
FormatStatus = ext2_last_winerror(ERROR_READ_FAULT); | SET_EXT2_FORMAT_ERROR(ERROR_READ_FAULT); | |||
uprintf("Could not read device size: %s", error_message(r)); | uprintf("Could not read device size: %s", error_message(r)); | |||
goto out; | goto out; | |||
} | } | |||
size *= KB; | size *= KB; | |||
for (i = 0; i < ARRAYSIZE(ext2fs_default); i++) { | for (i = 0; i < ARRAYSIZE(ext2fs_default); i++) { | |||
if (size < ext2fs_default[i].max_size) | if (size < ext2fs_default[i].max_size) | |||
break; | break; | |||
} | } | |||
assert(i < ARRAYSIZE(ext2fs_default)); | assert(i < ARRAYSIZE(ext2fs_default)); | |||
if ((BlockSize == 0) || (BlockSize < EXT2_MIN_BLOCK_SIZE)) | if ((BlockSize == 0) || (BlockSize < EXT2_MIN_BLOCK_SIZE)) | |||
skipping to change at line 316 | skipping to change at line 317 | |||
if (EXT2_BLOCK_SIZE(&features) == BlockSize) | if (EXT2_BLOCK_SIZE(&features) == BlockSize) | |||
break; | break; | |||
} | } | |||
assert(EXT2_BLOCK_SIZE_BITS(&features) <= EXT2_MAX_BLOCK_LOG_SIZE); | assert(EXT2_BLOCK_SIZE_BITS(&features) <= EXT2_MAX_BLOCK_LOG_SIZE); | |||
features.s_log_cluster_size = features.s_log_block_size; | features.s_log_cluster_size = features.s_log_block_size; | |||
size /= BlockSize; | size /= BlockSize; | |||
// ext2 and ext3 have a can only accomodate up to Blocksize * 2^32 sized volumes | // ext2 and ext3 have a can only accomodate up to Blocksize * 2^32 sized volumes | |||
if (((strcmp(FSName, FileSystemLabel[FS_EXT2]) == 0) || (strcmp(FSName, F ileSystemLabel[FS_EXT3]) == 0)) && | if (((strcmp(FSName, FileSystemLabel[FS_EXT2]) == 0) || (strcmp(FSName, F ileSystemLabel[FS_EXT3]) == 0)) && | |||
(size >= 0x100000000ULL)) { | (size >= 0x100000000ULL)) { | |||
FormatStatus = ext2_last_winerror(ERROR_INVALID_VOLUME_SIZE); | SET_EXT2_FORMAT_ERROR(ERROR_INVALID_VOLUME_SIZE); | |||
uprintf("Volume size is too large for ext2 or ext3"); | uprintf("Volume size is too large for ext2 or ext3"); | |||
goto out; | goto out; | |||
} | } | |||
// Set the blocks, reserved blocks and inodes | // Set the blocks, reserved blocks and inodes | |||
ext2fs_blocks_count_set(&features, size); | ext2fs_blocks_count_set(&features, size); | |||
ext2fs_r_blocks_count_set(&features, (blk64_t)(reserve_ratio * size)); | ext2fs_r_blocks_count_set(&features, (blk64_t)(reserve_ratio * size)); | |||
features.s_rev_level = 1; | features.s_rev_level = 1; | |||
features.s_inode_size = ext2fs_default[i].inode_size; | features.s_inode_size = ext2fs_default[i].inode_size; | |||
features.s_inodes_count = ((ext2fs_blocks_count(&features) >> ext2fs_defa ult[i].inode_ratio) > UINT32_MAX) ? | features.s_inodes_count = ((ext2fs_blocks_count(&features) >> ext2fs_defa ult[i].inode_ratio) > UINT32_MAX) ? | |||
skipping to change at line 344 | skipping to change at line 345 | |||
ext2fs_set_feature_large_file(&features); | ext2fs_set_feature_large_file(&features); | |||
ext2fs_set_feature_sparse_super(&features); | ext2fs_set_feature_sparse_super(&features); | |||
ext2fs_set_feature_xattr(&features); | ext2fs_set_feature_xattr(&features); | |||
if (FSName[3] != '2') | if (FSName[3] != '2') | |||
ext2fs_set_feature_journal(&features); | ext2fs_set_feature_journal(&features); | |||
features.s_default_mount_opts = EXT2_DEFM_XATTR_USER | EXT2_DEFM_ACL; | features.s_default_mount_opts = EXT2_DEFM_XATTR_USER | EXT2_DEFM_ACL; | |||
// Now that we have set our base features, initialize a virtual superbloc k | // Now that we have set our base features, initialize a virtual superbloc k | |||
r = ext2fs_initialize(volume_name, EXT2_FLAG_EXCLUSIVE | EXT2_FLAG_64BITS , &features, manager, &ext2fs); | r = ext2fs_initialize(volume_name, EXT2_FLAG_EXCLUSIVE | EXT2_FLAG_64BITS , &features, manager, &ext2fs); | |||
if (r != 0) { | if (r != 0) { | |||
FormatStatus = ext2_last_winerror(ERROR_INVALID_DATA); | SET_EXT2_FORMAT_ERROR(ERROR_INVALID_DATA); | |||
uprintf("Could not initialize %s features: %s", FSName, error_mes sage(r)); | uprintf("Could not initialize %s features: %s", FSName, error_mes sage(r)); | |||
goto out; | goto out; | |||
} | } | |||
// Zero 16 blocks of data from the start of our volume | // Zero 16 blocks of data from the start of our volume | |||
buf = calloc(16, ext2fs->io->block_size); | buf = calloc(16, ext2fs->io->block_size); | |||
assert(buf != NULL); | assert(buf != NULL); | |||
r = io_channel_write_blk64(ext2fs->io, 0, 16, buf); | r = io_channel_write_blk64(ext2fs->io, 0, 16, buf); | |||
safe_free(buf); | safe_free(buf); | |||
if (r != 0) { | if (r != 0) { | |||
FormatStatus = ext2_last_winerror(ERROR_WRITE_FAULT); | SET_EXT2_FORMAT_ERROR(ERROR_WRITE_FAULT); | |||
uprintf("Could not zero %s superblock area: %s", FSName, error_me ssage(r)); | uprintf("Could not zero %s superblock area: %s", FSName, error_me ssage(r)); | |||
goto out; | goto out; | |||
} | } | |||
// Finish setting up the file system | // Finish setting up the file system | |||
IGNORE_RETVAL(CoCreateGuid((GUID*)ext2fs->super->s_uuid)); | IGNORE_RETVAL(CoCreateGuid((GUID*)ext2fs->super->s_uuid)); | |||
ext2fs_init_csum_seed(ext2fs); | ext2fs_init_csum_seed(ext2fs); | |||
ext2fs->super->s_def_hash_version = EXT2_HASH_HALF_MD4; | ext2fs->super->s_def_hash_version = EXT2_HASH_HALF_MD4; | |||
IGNORE_RETVAL(CoCreateGuid((GUID*)ext2fs->super->s_hash_seed)); | IGNORE_RETVAL(CoCreateGuid((GUID*)ext2fs->super->s_hash_seed)); | |||
ext2fs->super->s_max_mnt_count = -1; | ext2fs->super->s_max_mnt_count = -1; | |||
ext2fs->super->s_creator_os = EXT2_OS_WINDOWS; | ext2fs->super->s_creator_os = EXT2_OS_WINDOWS; | |||
ext2fs->super->s_errors = EXT2_ERRORS_CONTINUE; | ext2fs->super->s_errors = EXT2_ERRORS_CONTINUE; | |||
if (Label != NULL) | if (Label != NULL) | |||
static_strcpy(ext2fs->super->s_volume_name, Label); | static_strcpy(ext2fs->super->s_volume_name, Label); | |||
r = ext2fs_allocate_tables(ext2fs); | r = ext2fs_allocate_tables(ext2fs); | |||
if (r != 0) { | if (r != 0) { | |||
FormatStatus = ext2_last_winerror(ERROR_INVALID_DATA); | SET_EXT2_FORMAT_ERROR(ERROR_INVALID_DATA); | |||
uprintf("Could not allocate %s tables: %s", FSName, error_message (r)); | uprintf("Could not allocate %s tables: %s", FSName, error_message (r)); | |||
goto out; | goto out; | |||
} | } | |||
r = ext2fs_convert_subcluster_bitmap(ext2fs, &ext2fs->block_map); | r = ext2fs_convert_subcluster_bitmap(ext2fs, &ext2fs->block_map); | |||
if (r != 0) { | if (r != 0) { | |||
uprintf("Could not set %s cluster bitmap: %s", FSName, error_mess age(r)); | uprintf("Could not set %s cluster bitmap: %s", FSName, error_mess age(r)); | |||
goto out; | goto out; | |||
} | } | |||
ext2_percent_start = 0.0f; | ext2_percent_start = 0.0f; | |||
skipping to change at line 395 | skipping to change at line 396 | |||
uprintf("Creating %d inode sets: [1 marker = %0.1f set(s)]", ext2fs->grou p_desc_count, | uprintf("Creating %d inode sets: [1 marker = %0.1f set(s)]", ext2fs->grou p_desc_count, | |||
max((float)ext2fs->group_desc_count / ext2_max_marker, 1.0f)); | max((float)ext2fs->group_desc_count / ext2_max_marker, 1.0f)); | |||
for (i = 0; i < (int)ext2fs->group_desc_count; i++) { | for (i = 0; i < (int)ext2fs->group_desc_count; i++) { | |||
if (ext2fs_print_progress((int64_t)i, (int64_t)ext2fs->group_desc _count)) | if (ext2fs_print_progress((int64_t)i, (int64_t)ext2fs->group_desc _count)) | |||
goto out; | goto out; | |||
cur = ext2fs_inode_table_loc(ext2fs, i); | cur = ext2fs_inode_table_loc(ext2fs, i); | |||
count = ext2fs_div_ceil((ext2fs->super->s_inodes_per_group - ext2 fs_bg_itable_unused(ext2fs, i)) | count = ext2fs_div_ceil((ext2fs->super->s_inodes_per_group - ext2 fs_bg_itable_unused(ext2fs, i)) | |||
* EXT2_INODE_SIZE(ext2fs->super), EXT2_BLOCK_SIZE(ext2fs- >super)); | * EXT2_INODE_SIZE(ext2fs->super), EXT2_BLOCK_SIZE(ext2fs- >super)); | |||
r = ext2fs_zero_blocks2(ext2fs, cur, count, &cur, &count); | r = ext2fs_zero_blocks2(ext2fs, cur, count, &cur, &count); | |||
if (r != 0) { | if (r != 0) { | |||
FormatStatus = ext2_last_winerror(ERROR_WRITE_FAULT); | SET_EXT2_FORMAT_ERROR(ERROR_WRITE_FAULT); | |||
uprintf("\r\nCould not zero inode set at position %llu (% d blocks): %s", cur, count, error_message(r)); | uprintf("\r\nCould not zero inode set at position %llu (% d blocks): %s", cur, count, error_message(r)); | |||
goto out; | goto out; | |||
} | } | |||
} | } | |||
uprintfs("\r\n"); | uprintfs("\r\n"); | |||
// Create root and lost+found dirs | // Create root and lost+found dirs | |||
r = ext2fs_mkdir(ext2fs, EXT2_ROOT_INO, EXT2_ROOT_INO, 0); | r = ext2fs_mkdir(ext2fs, EXT2_ROOT_INO, EXT2_ROOT_INO, 0); | |||
if (r != 0) { | if (r != 0) { | |||
FormatStatus = ext2_last_winerror(ERROR_DIR_NOT_ROOT); | SET_EXT2_FORMAT_ERROR(ERROR_DIR_NOT_ROOT); | |||
uprintf("Failed to create %s root dir: %s", FSName, error_message (r)); | uprintf("Failed to create %s root dir: %s", FSName, error_message (r)); | |||
goto out; | goto out; | |||
} | } | |||
ext2fs->umask = 077; | ext2fs->umask = 077; | |||
r = ext2fs_mkdir(ext2fs, EXT2_ROOT_INO, 0, "lost+found"); | r = ext2fs_mkdir(ext2fs, EXT2_ROOT_INO, 0, "lost+found"); | |||
if (r != 0) { | if (r != 0) { | |||
FormatStatus = ext2_last_winerror(ERROR_DIR_NOT_ROOT); | SET_EXT2_FORMAT_ERROR(ERROR_DIR_NOT_ROOT); | |||
uprintf("Failed to create %s 'lost+found' dir: %s", FSName, error _message(r)); | uprintf("Failed to create %s 'lost+found' dir: %s", FSName, error _message(r)); | |||
goto out; | goto out; | |||
} | } | |||
// Create bitmaps | // Create bitmaps | |||
for (i = EXT2_ROOT_INO + 1; i < (int)EXT2_FIRST_INODE(ext2fs->super); i++ ) | for (i = EXT2_ROOT_INO + 1; i < (int)EXT2_FIRST_INODE(ext2fs->super); i++ ) | |||
ext2fs_inode_alloc_stats(ext2fs, i, 1); | ext2fs_inode_alloc_stats(ext2fs, i, 1); | |||
ext2fs_mark_ib_dirty(ext2fs); | ext2fs_mark_ib_dirty(ext2fs); | |||
r = ext2fs_mark_inode_bitmap2(ext2fs->inode_map, EXT2_BAD_INO); | r = ext2fs_mark_inode_bitmap2(ext2fs->inode_map, EXT2_BAD_INO); | |||
if (r != 0) { | if (r != 0) { | |||
FormatStatus = ext2_last_winerror(ERROR_WRITE_FAULT); | SET_EXT2_FORMAT_ERROR(ERROR_WRITE_FAULT); | |||
uprintf("Could not set inode bitmaps: %s", error_message(r)); | uprintf("Could not set inode bitmaps: %s", error_message(r)); | |||
goto out; | goto out; | |||
} | } | |||
ext2fs_inode_alloc_stats(ext2fs, EXT2_BAD_INO, 1); | ext2fs_inode_alloc_stats(ext2fs, EXT2_BAD_INO, 1); | |||
r = ext2fs_update_bb_inode(ext2fs, NULL); | r = ext2fs_update_bb_inode(ext2fs, NULL); | |||
if (r != 0) { | if (r != 0) { | |||
FormatStatus = ext2_last_winerror(ERROR_WRITE_FAULT); | SET_EXT2_FORMAT_ERROR(ERROR_WRITE_FAULT); | |||
uprintf("Could not set inode stats: %s", error_message(r)); | uprintf("Could not set inode stats: %s", error_message(r)); | |||
goto out; | goto out; | |||
} | } | |||
if (FSName[3] != '2') { | if (FSName[3] != '2') { | |||
// Create the journal | // Create the journal | |||
ext2_percent_start = 0.5f; | ext2_percent_start = 0.5f; | |||
journal_size = ext2fs_default_journal_size(ext2fs_blocks_count(ex t2fs->super)); | journal_size = ext2fs_default_journal_size(ext2fs_blocks_count(ex t2fs->super)); | |||
journal_size /= 2; // That journal init is really killing us ! | journal_size /= 2; // That journal init is really killing us ! | |||
uprintf("Creating %d journal blocks: [1 marker = %0.1f block(s)]" , journal_size, | uprintf("Creating %d journal blocks: [1 marker = %0.1f block(s)]" , journal_size, | |||
max((float)journal_size / ext2_max_marker, 1.0f)); | max((float)journal_size / ext2_max_marker, 1.0f)); | |||
// Even with EXT2_MKJOURNAL_LAZYINIT, this call is absolutely dre adful in terms of speed... | // Even with EXT2_MKJOURNAL_LAZYINIT, this call is absolutely dre adful in terms of speed... | |||
r = ext2fs_add_journal_inode(ext2fs, journal_size, EXT2_MKJOURNAL _NO_MNT_CHECK | ((Flags & FP_QUICK) ? EXT2_MKJOURNAL_LAZYINIT : 0)); | r = ext2fs_add_journal_inode(ext2fs, journal_size, EXT2_MKJOURNAL _NO_MNT_CHECK | ((Flags & FP_QUICK) ? EXT2_MKJOURNAL_LAZYINIT : 0)); | |||
uprintfs("\r\n"); | uprintfs("\r\n"); | |||
if (r != 0) { | if (r != 0) { | |||
FormatStatus = ext2_last_winerror(ERROR_WRITE_FAULT); | SET_EXT2_FORMAT_ERROR(ERROR_WRITE_FAULT); | |||
uprintf("Could not create %s journal: %s", FSName, error_ message(r)); | uprintf("Could not create %s journal: %s", FSName, error_ message(r)); | |||
goto out; | goto out; | |||
} | } | |||
} | } | |||
// Create a 'persistence.conf' file if required | // Create a 'persistence.conf' file if required | |||
if (Flags & FP_CREATE_PERSISTENCE_CONF) { | if (Flags & FP_CREATE_PERSISTENCE_CONF) { | |||
// You *do* want the LF at the end of the "/ union" line, else De bian Live bails out... | // You *do* want the LF at the end of the "/ union" line, else De bian Live bails out... | |||
const char* name = "persistence.conf", data[] = "/ union\n"; | const char* name = "persistence.conf", data[] = "/ union\n"; | |||
int written = 0, fsize = sizeof(data) - 1; | int written = 0, fsize = sizeof(data) - 1; | |||
skipping to change at line 485 | skipping to change at line 486 | |||
if ((ext2fs_file_write(ext2fd, data, fsize, &written) != 0) || (w ritten != fsize)) | if ((ext2fs_file_write(ext2fd, data, fsize, &written) != 0) || (w ritten != fsize)) | |||
uprintf("Error: Could not create '%s' file", name); | uprintf("Error: Could not create '%s' file", name); | |||
else | else | |||
uprintf("Created '%s' file", name); | uprintf("Created '%s' file", name); | |||
ext2fs_file_close(ext2fd); | ext2fs_file_close(ext2fd); | |||
} | } | |||
// Finally we can call close() to get the file system gets created | // Finally we can call close() to get the file system gets created | |||
r = ext2fs_close(ext2fs); | r = ext2fs_close(ext2fs); | |||
if (r != 0) { | if (r != 0) { | |||
FormatStatus = ext2_last_winerror(ERROR_WRITE_FAULT); | SET_EXT2_FORMAT_ERROR(ERROR_WRITE_FAULT); | |||
uprintf("Could not create %s volume: %s", FSName, error_message(r )); | uprintf("Could not create %s volume: %s", FSName, error_message(r )); | |||
goto out; | goto out; | |||
} | } | |||
UpdateProgressWithInfo(OP_FORMAT, MSG_217, 100, 100); | UpdateProgressWithInfo(OP_FORMAT, MSG_217, 100, 100); | |||
uprintf("Done"); | uprintf("Done"); | |||
ret = TRUE; | ret = TRUE; | |||
out: | out: | |||
free(volume_name); | free(volume_name); | |||
ext2fs_free(ext2fs); | ext2fs_free(ext2fs); | |||
End of changes. 14 change blocks. | ||||
13 lines changed or deleted | 14 lines changed or added |