[core] avoid the creation of 'System Volume Information' for ESPs written in DD mode

* Trying to mount accessible partitions after writing an image may lead to the
  creation of the infamous 'System Volume Information' folder on ESPs, which in
  turn leads to checksum errors for Ubuntu's boot/grub/efi.img (that maps to the
  Ubuntu ESP). So comment out that code.
* Also fix a missing CRLFs in the log after displaying write progress.
This commit is contained in:
Pete Batard 2021-05-18 15:18:28 +01:00
parent 03ef8aa024
commit 3bb83709da
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
3 changed files with 20 additions and 14 deletions

View file

@ -1565,7 +1565,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive)
// Read block and compare against the block that needs to be written
s = ReadFile(hPhysicalDrive, cmp_buffer, read_size[0], &comp_size, NULL);
if ((!s) || (comp_size != read_size[0])) {
uprintf("Read error: Could not read data for fast zeroing comparison - %s", WindowsErrorString());
uprintf("\r\nRead error: Could not read data for fast zeroing comparison - %s", WindowsErrorString());
goto out;
}
@ -1585,7 +1585,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive)
// Move the file pointer position back for writing
li.QuadPart = wb;
if (!SetFilePointerEx(hPhysicalDrive, li, NULL, FILE_BEGIN)) {
uprintf("Error: Could not reset position - %s", WindowsErrorString());
uprintf("\r\nError: Could not reset position - %s", WindowsErrorString());
goto out;
}
// Throttle read operations
@ -1598,9 +1598,9 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive)
if ((s) && (write_size == read_size[0]))
break;
if (s)
uprintf("Write error: Wrote %d bytes, expected %d bytes", write_size, read_size[0]);
uprintf("\r\nWrite error: Wrote %d bytes, expected %d bytes", write_size, read_size[0]);
else
uprintf("Write error at sector %lld: %s", wb / SelectedDrive.SectorSize, WindowsErrorString());
uprintf("\r\nWrite error at sector %lld: %s", wb / SelectedDrive.SectorSize, WindowsErrorString());
if (i < WRITE_RETRIES) {
li.QuadPart = wb;
uprintf("Retrying in %d seconds...", WRITE_TIMEOUT / 1000);
@ -1688,7 +1688,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive)
// 1. Wait for the current read operation to complete (and update the read size)
if ((!WaitFileAsync(hSourceImage, DRIVE_ACCESS_TIMEOUT)) ||
(!GetSizeAsync(hSourceImage, &read_size[read_bufnum]))) {
uprintf("Read error: %s", WindowsErrorString());
uprintf("\r\nRead error: %s", WindowsErrorString());
FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_READ_FAULT;
goto out;
}
@ -1716,9 +1716,9 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive)
if ((s) && (write_size == read_size[proc_bufnum]))
break;
if (s)
uprintf("Write error: Wrote %d bytes, expected %d bytes", write_size, read_size[proc_bufnum]);
uprintf("\r\nWrite error: Wrote %d bytes, expected %d bytes", write_size, read_size[proc_bufnum]);
else
uprintf("Write error at sector %lld: %s", wb / SelectedDrive.SectorSize, WindowsErrorString());
uprintf("\r\nWrite error at sector %lld: %s", wb / SelectedDrive.SectorSize, WindowsErrorString());
if (i < WRITE_RETRIES) {
li.QuadPart = wb;
uprintf("Retrying in %d seconds...", WRITE_TIMEOUT / 1000);
@ -1736,7 +1736,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive)
if (i > WRITE_RETRIES)
goto out;
}
uprintfs("\r\n");
}
RefreshDriveLayout(hPhysicalDrive);
ret = TRUE;
@ -1961,6 +1961,11 @@ DWORD WINAPI FormatThread(void* param)
if ((boot_type == BT_IMAGE) && write_as_image) {
WriteDrive(hPhysicalDrive, FALSE);
// Trying to mount accessible partitions after writing an image leads to the
// creation of the infamous 'System Volume Information' folder on ESPs, which
// in turn leads to checksum errors for Ubuntu's boot/grub/efi.img (that maps
// to the Ubuntu ESP). So we no longer call on the code below...
#if 0
// If the image contains a partition we might be able to access, try to re-mount it
safe_unlockclose(hPhysicalDrive);
safe_unlockclose(hLogicalVolume);
@ -1971,6 +1976,7 @@ DWORD WINAPI FormatThread(void* param)
if ((volume_name != NULL) && (MountVolume(drive_name, volume_name)))
uprintf("Remounted %s as %C:", volume_name, drive_name[0]);
}
#endif
goto out;
}