mirror of
https://github.com/pbatard/rufus.git
synced 2025-05-28 21:54:15 -04:00
[iso] add support for distros using a NONSTANDARD GRUB 2.0 prefix directory
* Looking at you, openSUSE Live and GeckoLinux!
This commit is contained in:
parent
f669f05403
commit
3528ca773d
7 changed files with 139 additions and 17 deletions
30
src/format.c
30
src/format.c
|
@ -73,6 +73,7 @@ extern uint32_t wim_nb_files, wim_proc_files, wim_extra_files;
|
|||
static int actual_fs_type, wintogo_index = -1, wininst_index = 0;
|
||||
extern BOOL force_large_fat32, enable_ntfs_compression, lock_drive, zero_drive, fast_zeroing, enable_file_indexing, write_as_image;
|
||||
extern BOOL use_vds, write_as_esp, is_vds_available;
|
||||
extern const grub_patch_t grub_patch[2];
|
||||
uint8_t *grub2_buf = NULL, *sec_buf = NULL;
|
||||
long grub2_len;
|
||||
|
||||
|
@ -909,8 +910,8 @@ static BOOL WriteSBR(HANDLE hPhysicalDrive)
|
|||
{
|
||||
// TODO: Do we need anything special for 4K sectors?
|
||||
DWORD size, max_size, br_size = 0x200;
|
||||
int r, sub_type = boot_type;
|
||||
unsigned char* buf = NULL;
|
||||
int i, j, r, sub_type = boot_type;
|
||||
uint8_t *buf = NULL, *patched = NULL;
|
||||
FAKE_FD fake_fd = { 0 };
|
||||
FILE* fp = (FILE*)&fake_fd;
|
||||
|
||||
|
@ -953,6 +954,31 @@ static BOOL WriteSBR(HANDLE hPhysicalDrive)
|
|||
return FALSE;
|
||||
}
|
||||
}
|
||||
// TODO: Compute the projected increase in size instead of harcoding it
|
||||
if (img_report.has_grub2 == 2 && ((patched = malloc(size + 16)) != NULL)) {
|
||||
memcpy(patched, buf, size);
|
||||
// Patch GRUB for nonstandard prefix directory
|
||||
for (i = 0; i < ARRAYSIZE(grub_patch); i++) {
|
||||
if (strcmp(img_report.grub2_version, grub_patch[i].version) == 0) {
|
||||
for (j = 0; j < ARRAYSIZE(grub_patch[i].patch); j++) {
|
||||
if (memcmp(&patched[grub_patch[i].patch[j].src->offset], grub_patch[i].patch[j].src->data,
|
||||
grub_patch[i].patch[j].src->size) != 0) {
|
||||
uprintf("ERROR: Did not find expected source data for GRUB patch");
|
||||
return FALSE;
|
||||
}
|
||||
memcpy(&patched[grub_patch[i].patch[j].rep->offset], grub_patch[i].patch[j].rep->data,
|
||||
grub_patch[i].patch[j].rep->size);
|
||||
if (grub_patch[i].patch[j].rep->size > grub_patch[i].patch[j].src->size)
|
||||
size += grub_patch[i].patch[j].rep->size - grub_patch[i].patch[j].src->size;
|
||||
}
|
||||
safe_free(grub2_buf);
|
||||
grub2_buf = patched;
|
||||
buf = grub2_buf;
|
||||
uprintf("Patched Grub 2.0 SBR for NONSTANDARD prefix");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BT_MAX:
|
||||
uprintf("Writing protective message SBR");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue