diff --git a/INSTALL/tool/aarch64/Plugson b/INSTALL/tool/aarch64/Plugson index 5a98000c51c..de9b9dbc0d7 100644 Binary files a/INSTALL/tool/aarch64/Plugson and b/INSTALL/tool/aarch64/Plugson differ diff --git a/INSTALL/tool/aarch64/V2DServer b/INSTALL/tool/aarch64/V2DServer index 6fa19f44918..0b382c1cbca 100644 Binary files a/INSTALL/tool/aarch64/V2DServer and b/INSTALL/tool/aarch64/V2DServer differ diff --git a/INSTALL/tool/aarch64/Ventoy2Disk.gtk3 b/INSTALL/tool/aarch64/Ventoy2Disk.gtk3 index c8e9d2a5daf..ed5738598d1 100644 Binary files a/INSTALL/tool/aarch64/Ventoy2Disk.gtk3 and b/INSTALL/tool/aarch64/Ventoy2Disk.gtk3 differ diff --git a/INSTALL/tool/aarch64/Ventoy2Disk.qt5 b/INSTALL/tool/aarch64/Ventoy2Disk.qt5 index 79eca778dd5..ba06df2912a 100644 Binary files a/INSTALL/tool/aarch64/Ventoy2Disk.qt5 and b/INSTALL/tool/aarch64/Ventoy2Disk.qt5 differ diff --git a/INSTALL/tool/i386/Plugson b/INSTALL/tool/i386/Plugson index 6f0776c92af..582660a567f 100644 Binary files a/INSTALL/tool/i386/Plugson and b/INSTALL/tool/i386/Plugson differ diff --git a/INSTALL/tool/i386/V2DServer b/INSTALL/tool/i386/V2DServer index d14a35414a6..b9b6d91865f 100644 Binary files a/INSTALL/tool/i386/V2DServer and b/INSTALL/tool/i386/V2DServer differ diff --git a/INSTALL/tool/i386/Ventoy2Disk.gtk2 b/INSTALL/tool/i386/Ventoy2Disk.gtk2 index 6e94fbd0b76..e71a4804eda 100644 Binary files a/INSTALL/tool/i386/Ventoy2Disk.gtk2 and b/INSTALL/tool/i386/Ventoy2Disk.gtk2 differ diff --git a/INSTALL/tool/i386/Ventoy2Disk.gtk3 b/INSTALL/tool/i386/Ventoy2Disk.gtk3 index 39b7f880a18..cdb33d19748 100644 Binary files a/INSTALL/tool/i386/Ventoy2Disk.gtk3 and b/INSTALL/tool/i386/Ventoy2Disk.gtk3 differ diff --git a/INSTALL/tool/i386/Ventoy2Disk.qt5 b/INSTALL/tool/i386/Ventoy2Disk.qt5 index 61ed87a1608..51bc50e94b1 100644 Binary files a/INSTALL/tool/i386/Ventoy2Disk.qt5 and b/INSTALL/tool/i386/Ventoy2Disk.qt5 differ diff --git a/INSTALL/tool/mips64el/Plugson b/INSTALL/tool/mips64el/Plugson index 0af729f0cb1..8870f5c00c1 100644 Binary files a/INSTALL/tool/mips64el/Plugson and b/INSTALL/tool/mips64el/Plugson differ diff --git a/INSTALL/tool/mips64el/V2DServer b/INSTALL/tool/mips64el/V2DServer index 8777a85e10d..16a78cb87c4 100644 Binary files a/INSTALL/tool/mips64el/V2DServer and b/INSTALL/tool/mips64el/V2DServer differ diff --git a/INSTALL/tool/mips64el/Ventoy2Disk.gtk3 b/INSTALL/tool/mips64el/Ventoy2Disk.gtk3 index 9f4c75901ca..c2af26b49d7 100644 Binary files a/INSTALL/tool/mips64el/Ventoy2Disk.gtk3 and b/INSTALL/tool/mips64el/Ventoy2Disk.gtk3 differ diff --git a/INSTALL/tool/mips64el/Ventoy2Disk.qt5 b/INSTALL/tool/mips64el/Ventoy2Disk.qt5 index 924e4a0d5c6..eee73b25e5c 100644 Binary files a/INSTALL/tool/mips64el/Ventoy2Disk.qt5 and b/INSTALL/tool/mips64el/Ventoy2Disk.qt5 differ diff --git a/INSTALL/tool/x86_64/Plugson b/INSTALL/tool/x86_64/Plugson index cd83b6db67d..2358244e622 100644 Binary files a/INSTALL/tool/x86_64/Plugson and b/INSTALL/tool/x86_64/Plugson differ diff --git a/INSTALL/tool/x86_64/V2DServer b/INSTALL/tool/x86_64/V2DServer index 19da8b4e890..e28b652db5b 100644 Binary files a/INSTALL/tool/x86_64/V2DServer and b/INSTALL/tool/x86_64/V2DServer differ diff --git a/INSTALL/tool/x86_64/Ventoy2Disk.gtk2 b/INSTALL/tool/x86_64/Ventoy2Disk.gtk2 index ef253183027..f5c37958755 100644 Binary files a/INSTALL/tool/x86_64/Ventoy2Disk.gtk2 and b/INSTALL/tool/x86_64/Ventoy2Disk.gtk2 differ diff --git a/INSTALL/tool/x86_64/Ventoy2Disk.gtk3 b/INSTALL/tool/x86_64/Ventoy2Disk.gtk3 index 881e17cc512..03411cf948e 100644 Binary files a/INSTALL/tool/x86_64/Ventoy2Disk.gtk3 and b/INSTALL/tool/x86_64/Ventoy2Disk.gtk3 differ diff --git a/INSTALL/tool/x86_64/Ventoy2Disk.qt5 b/INSTALL/tool/x86_64/Ventoy2Disk.qt5 index 13860cba982..e3ab28e2d2a 100644 Binary files a/INSTALL/tool/x86_64/Ventoy2Disk.qt5 and b/INSTALL/tool/x86_64/Ventoy2Disk.qt5 differ diff --git a/LinuxGUI/Ventoy2Disk/Core/ventoy_util.h b/LinuxGUI/Ventoy2Disk/Core/ventoy_util.h index 87eb5463a1c..87bdbd5e784 100644 --- a/LinuxGUI/Ventoy2Disk/Core/ventoy_util.h +++ b/LinuxGUI/Ventoy2Disk/Core/ventoy_util.h @@ -50,6 +50,7 @@ int ventoy_read_file_to_buf(const char *FileName, int ExtLen, void **Bufer, int const char * ventoy_get_local_version(void); int ventoy_fill_gpt(uint64_t size, uint64_t reserve, int align4k, VTOY_GPT_INFO *gpt); int ventoy_fill_mbr(uint64_t size, uint64_t reserve, int align4k, MBR_HEAD *pMBR); +int VentoyGetLocalBootImg(MBR_HEAD *pMBR); #endif /* __VENTOY_UTIL_H__ */ diff --git a/LinuxGUI/Ventoy2Disk/Web/ventoy_http.c b/LinuxGUI/Ventoy2Disk/Web/ventoy_http.c index ac9920f7b55..561e0807d2b 100644 --- a/LinuxGUI/Ventoy2Disk/Web/ventoy_http.c +++ b/LinuxGUI/Ventoy2Disk/Web/ventoy_http.c @@ -683,10 +683,45 @@ static int ventoy_write_gpt_part_table(int fd, uint64_t disksize, VTOY_GPT_INFO return 0; } +static int ventoy_mbr_need_update(ventoy_disk *disk, MBR_HEAD *mbr) +{ + int update = 0; + int partition_style; + MBR_HEAD LocalMBR; + + partition_style = disk->vtoydata.partition_style; + memcpy(mbr, &(disk->vtoydata.gptinfo.MBR), 512); + + VentoyGetLocalBootImg(&LocalMBR); + memcpy(LocalMBR.BootCode + 0x180, mbr->BootCode + 0x180, 16); + if (partition_style) + { + LocalMBR.BootCode[92] = 0x22; + } + + if (memcmp(LocalMBR.BootCode, mbr->BootCode, 440)) + { + memcpy(mbr->BootCode, LocalMBR.BootCode, 440); + vlog("MBR boot code different, must update it.\n"); + update = 1; + } + + if (partition_style == 0 && mbr->PartTbl[0].Active == 0) + { + mbr->PartTbl[0].Active = 0x80; + mbr->PartTbl[1].Active = 0; + mbr->PartTbl[2].Active = 0; + mbr->PartTbl[3].Active = 0; + vlog("set MBR partition 1 active flag enabled\n"); + update = 1; + } + + return update; +} + static void * ventoy_update_thread(void *data) { int fd; - int updateMBR; ssize_t len; off_t offset; MBR_HEAD MBR; @@ -744,34 +779,17 @@ static void * ventoy_update_thread(void *data) len = write(fd, disk->vtoydata.rsvdata, sizeof(disk->vtoydata.rsvdata)); vlog("Writing reserve data offset:%llu len:%llu ...\n", (_ull)offset, (_ull)len); - updateMBR = 0; - memcpy(&MBR, &(disk->vtoydata.gptinfo.MBR), 512); - - if (disk->vtoydata.partition_style == 0 && MBR.PartTbl[0].Active == 0) - { - MBR.PartTbl[0].Active = 0x80; - MBR.PartTbl[1].Active = 0; - MBR.PartTbl[2].Active = 0; - MBR.PartTbl[3].Active = 0; - updateMBR = 1; - vlog("set MBR partition 1 active flag enabled\n"); - } - - if (MBR.BootCode[0x190] != 0x56 || MBR.BootCode[0x191] != 0x54) - { - vlog("set VT data %02x %02x\n", MBR.BootCode[0x190], MBR.BootCode[0x191]); - MBR.BootCode[0x190] = 0x56; - MBR.BootCode[0x191] = 0x54; - updateMBR = 1; - } - - if (updateMBR) + if (ventoy_mbr_need_update(disk, &MBR)) { offset = lseek(fd, 0, SEEK_SET); len = write(fd, &MBR, 512); vlog("update MBR offset:%llu len:%llu\n", (_ull)offset, (_ull)len); } - + else + { + vlog("No need to update MBR\n"); + } + g_current_progress = PT_SYNC_DATA1; vlog("fsync data1...\n");