mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[iso] improve write performance during ISO extraction by preallocating the file size of each file on the target filesystem before writing to it
The actual benefit gained from this will vary: it depends on the input ISO layout (with a large number of small files giving a bigger improvement), the target filesystem, and also the host OS because of driver differences between versions. Windows 7 seems to benefit more than Windows 10, and NTFS more than FAT32. All scenarios should see at least a minor speed gain from this however. (No actual percentage claims made upon urgent request of my lawyer)
This commit is contained in:
parent
faebe1040f
commit
acc9cec32b
1 changed files with 50 additions and 35 deletions
85
src/iso.c
85
src/iso.c
|
@ -361,6 +361,15 @@ static void __inline set_directory_timestamp(char* path, LPFILETIME creation, LP
|
||||||
safe_closehandle(dir_handle);
|
safe_closehandle(dir_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Preallocates the target size of a newly created file in order to prevent fragmentation from repeated writes
|
||||||
|
static void __inline preallocate_filesize(HANDLE hFile, int64_t file_length)
|
||||||
|
{
|
||||||
|
SetFileInformationByHandle(hFile, FileEndOfFileInfo, &file_length, sizeof(file_length));
|
||||||
|
|
||||||
|
// FileAllocationInfo does not require the size to be a multiple of the cluster size; the FS driver takes care of this.
|
||||||
|
SetFileInformationByHandle(hFile, FileAllocationInfo, &file_length, sizeof(file_length));
|
||||||
|
}
|
||||||
|
|
||||||
// Returns 0 on success, nonzero on error
|
// Returns 0 on success, nonzero on error
|
||||||
static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const char *psz_path)
|
static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const char *psz_path)
|
||||||
{
|
{
|
||||||
|
@ -440,23 +449,26 @@ static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const cha
|
||||||
uprintf(stupid_antivirus);
|
uprintf(stupid_antivirus);
|
||||||
else
|
else
|
||||||
goto out;
|
goto out;
|
||||||
} else while (file_length > 0) {
|
} else {
|
||||||
if (FormatStatus) goto out;
|
preallocate_filesize(file_handle, file_length);
|
||||||
memset(buf, 0, UDF_BLOCKSIZE);
|
while (file_length > 0) {
|
||||||
read = udf_read_block(p_udf_dirent, buf, 1);
|
if (FormatStatus) goto out;
|
||||||
if (read < 0) {
|
memset(buf, 0, UDF_BLOCKSIZE);
|
||||||
uprintf(" Error reading UDF file %s", &psz_fullpath[strlen(psz_extract_dir)]);
|
read = udf_read_block(p_udf_dirent, buf, 1);
|
||||||
goto out;
|
if (read < 0) {
|
||||||
|
uprintf(" Error reading UDF file %s", &psz_fullpath[strlen(psz_extract_dir)]);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
buf_size = (DWORD)MIN(file_length, read);
|
||||||
|
ISO_BLOCKING(r = WriteFileWithRetry(file_handle, buf, buf_size, &wr_size, WRITE_RETRIES));
|
||||||
|
if (!r) {
|
||||||
|
uprintf(" Error writing file: %s", WindowsErrorString());
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
file_length -= read;
|
||||||
|
if (nb_blocks++ % PROGRESS_THRESHOLD == 0)
|
||||||
|
UpdateProgress(OP_DOS, 100.0f*nb_blocks/total_blocks);
|
||||||
}
|
}
|
||||||
buf_size = (DWORD)MIN(file_length, read);
|
|
||||||
ISO_BLOCKING(r = WriteFileWithRetry(file_handle, buf, buf_size, &wr_size, WRITE_RETRIES));
|
|
||||||
if (!r) {
|
|
||||||
uprintf(" Error writing file: %s", WindowsErrorString());
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
file_length -= read;
|
|
||||||
if (nb_blocks++ % PROGRESS_THRESHOLD == 0)
|
|
||||||
UpdateProgress(OP_DOS, 100.0f*nb_blocks/total_blocks);
|
|
||||||
}
|
}
|
||||||
if ((preserve_timestamps) && (!SetFileTime(file_handle, to_filetime(udf_get_attribute_time(p_udf_dirent)),
|
if ((preserve_timestamps) && (!SetFileTime(file_handle, to_filetime(udf_get_attribute_time(p_udf_dirent)),
|
||||||
to_filetime(udf_get_access_time(p_udf_dirent)), to_filetime(udf_get_modification_time(p_udf_dirent)))))
|
to_filetime(udf_get_access_time(p_udf_dirent)), to_filetime(udf_get_modification_time(p_udf_dirent)))))
|
||||||
|
@ -586,26 +598,29 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path)
|
||||||
uprintf(stupid_antivirus);
|
uprintf(stupid_antivirus);
|
||||||
else
|
else
|
||||||
goto out;
|
goto out;
|
||||||
} else for (j=0; j<p_statbuf->extents; j++) {
|
} else {
|
||||||
extent_length = p_statbuf->extsize[j];
|
preallocate_filesize(file_handle, file_length);
|
||||||
for (i=0; extent_length>0; i++) {
|
for (j=0; j<p_statbuf->extents; j++) {
|
||||||
if (FormatStatus) goto out;
|
extent_length = p_statbuf->extsize[j];
|
||||||
memset(buf, 0, ISO_BLOCKSIZE);
|
for (i=0; extent_length>0; i++) {
|
||||||
lsn = p_statbuf->lsn[j] + (lsn_t)i;
|
if (FormatStatus) goto out;
|
||||||
if (iso9660_iso_seek_read(p_iso, buf, lsn, 1) != ISO_BLOCKSIZE) {
|
memset(buf, 0, ISO_BLOCKSIZE);
|
||||||
uprintf(" Error reading ISO9660 file %s at LSN %lu",
|
lsn = p_statbuf->lsn[j] + (lsn_t)i;
|
||||||
psz_iso_name, (long unsigned int)lsn);
|
if (iso9660_iso_seek_read(p_iso, buf, lsn, 1) != ISO_BLOCKSIZE) {
|
||||||
goto out;
|
uprintf(" Error reading ISO9660 file %s at LSN %lu",
|
||||||
|
psz_iso_name, (long unsigned int)lsn);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
buf_size = (DWORD)MIN(extent_length, ISO_BLOCKSIZE);
|
||||||
|
ISO_BLOCKING(r = WriteFileWithRetry(file_handle, buf, buf_size, &wr_size, WRITE_RETRIES));
|
||||||
|
if (!r) {
|
||||||
|
uprintf(" Error writing file: %s", WindowsErrorString());
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
extent_length -= ISO_BLOCKSIZE;
|
||||||
|
if (nb_blocks++ % PROGRESS_THRESHOLD == 0)
|
||||||
|
UpdateProgress(OP_DOS, 100.0f*nb_blocks/total_blocks);
|
||||||
}
|
}
|
||||||
buf_size = (DWORD)MIN(extent_length, ISO_BLOCKSIZE);
|
|
||||||
ISO_BLOCKING(r = WriteFileWithRetry(file_handle, buf, buf_size, &wr_size, WRITE_RETRIES));
|
|
||||||
if (!r) {
|
|
||||||
uprintf(" Error writing file: %s", WindowsErrorString());
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
extent_length -= ISO_BLOCKSIZE;
|
|
||||||
if (nb_blocks++ % PROGRESS_THRESHOLD == 0)
|
|
||||||
UpdateProgress(OP_DOS, 100.0f*nb_blocks/total_blocks);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (preserve_timestamps) {
|
if (preserve_timestamps) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue