1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00
This commit is contained in:
Matthijs Lavrijsen 2018-06-24 13:35:57 +00:00 committed by GitHub
commit 742e1cc167
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,7 +449,9 @@ 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 {
preallocate_filesize(file_handle, file_length);
while (file_length > 0) {
if (FormatStatus) goto out; if (FormatStatus) goto out;
memset(buf, 0, UDF_BLOCKSIZE); memset(buf, 0, UDF_BLOCKSIZE);
read = udf_read_block(p_udf_dirent, buf, 1); read = udf_read_block(p_udf_dirent, buf, 1);
@ -458,6 +469,7 @@ static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const cha
if (nb_blocks++ % PROGRESS_THRESHOLD == 0) if (nb_blocks++ % PROGRESS_THRESHOLD == 0)
UpdateProgress(OP_DOS, 100.0f*nb_blocks/total_blocks); 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)))))
uprintf(" Could not set timestamp: %s", WindowsErrorString()); uprintf(" Could not set timestamp: %s", WindowsErrorString());
@ -586,7 +598,9 @@ 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 {
preallocate_filesize(file_handle, file_length);
for (j=0; j<p_statbuf->extents; j++) {
extent_length = p_statbuf->extsize[j]; extent_length = p_statbuf->extsize[j];
for (i=0; extent_length>0; i++) { for (i=0; extent_length>0; i++) {
if (FormatStatus) goto out; if (FormatStatus) goto out;
@ -608,6 +622,7 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path)
UpdateProgress(OP_DOS, 100.0f*nb_blocks/total_blocks); UpdateProgress(OP_DOS, 100.0f*nb_blocks/total_blocks);
} }
} }
}
if (preserve_timestamps) { if (preserve_timestamps) {
LPFILETIME ft = to_filetime(mktime(&p_statbuf->tm)); LPFILETIME ft = to_filetime(mktime(&p_statbuf->tm));
if (!SetFileTime(file_handle, ft, ft, ft)) if (!SetFileTime(file_handle, ft, ft, ft))