]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Fix the issue that Linux WEB/GUI does not restore MBR when updating. (#1935)
authorlongpanda <admin@ventoy.net>
Sun, 30 Oct 2022 05:39:19 +0000 (13:39 +0800)
committerlongpanda <admin@ventoy.net>
Sun, 30 Oct 2022 05:39:19 +0000 (13:39 +0800)
20 files changed:
INSTALL/tool/aarch64/Plugson
INSTALL/tool/aarch64/V2DServer
INSTALL/tool/aarch64/Ventoy2Disk.gtk3
INSTALL/tool/aarch64/Ventoy2Disk.qt5
INSTALL/tool/i386/Plugson
INSTALL/tool/i386/V2DServer
INSTALL/tool/i386/Ventoy2Disk.gtk2
INSTALL/tool/i386/Ventoy2Disk.gtk3
INSTALL/tool/i386/Ventoy2Disk.qt5
INSTALL/tool/mips64el/Plugson
INSTALL/tool/mips64el/V2DServer
INSTALL/tool/mips64el/Ventoy2Disk.gtk3
INSTALL/tool/mips64el/Ventoy2Disk.qt5
INSTALL/tool/x86_64/Plugson
INSTALL/tool/x86_64/V2DServer
INSTALL/tool/x86_64/Ventoy2Disk.gtk2
INSTALL/tool/x86_64/Ventoy2Disk.gtk3
INSTALL/tool/x86_64/Ventoy2Disk.qt5
LinuxGUI/Ventoy2Disk/Core/ventoy_util.h
LinuxGUI/Ventoy2Disk/Web/ventoy_http.c

index 5a98000c51cc265e336af7cb161c01b71c717c91..de9b9dbc0d7adf450527f251f5c2f65b256c1b61 100644 (file)
Binary files a/INSTALL/tool/aarch64/Plugson and b/INSTALL/tool/aarch64/Plugson differ
index 6fa19f449181c1ac8a67b4434966e72dc54edbda..0b382c1cbca5a62ba5cc1f77cf62fc503bd541e8 100644 (file)
Binary files a/INSTALL/tool/aarch64/V2DServer and b/INSTALL/tool/aarch64/V2DServer differ
index c8e9d2a5daf313ae2f06e9eea991e137ddbe1ff4..ed5738598d164839ea1e3b59ec7baf747d8207c4 100644 (file)
Binary files a/INSTALL/tool/aarch64/Ventoy2Disk.gtk3 and b/INSTALL/tool/aarch64/Ventoy2Disk.gtk3 differ
index 79eca778dd5983c5dd287043e748e817de5b110a..ba06df2912ac162189a997c514ad04488ec888b6 100644 (file)
Binary files a/INSTALL/tool/aarch64/Ventoy2Disk.qt5 and b/INSTALL/tool/aarch64/Ventoy2Disk.qt5 differ
index 6f0776c92af70fcab84f995def3169ef8ed194c8..582660a567fcf267d0c4416075cf4b906a702e0c 100644 (file)
Binary files a/INSTALL/tool/i386/Plugson and b/INSTALL/tool/i386/Plugson differ
index d14a35414a639f40daaa084b9f17e2fcb1c792ec..b9b6d91865ff902c087d635393c40ec515a07c12 100644 (file)
Binary files a/INSTALL/tool/i386/V2DServer and b/INSTALL/tool/i386/V2DServer differ
index 6e94fbd0b764e8c0845e2a06c5f91d9ba871974c..e71a4804edae44e8b159643f562af4f5e37222b8 100644 (file)
Binary files a/INSTALL/tool/i386/Ventoy2Disk.gtk2 and b/INSTALL/tool/i386/Ventoy2Disk.gtk2 differ
index 39b7f880a184254456f0dc07d1b524ceca331efa..cdb33d1974897574e1c49d18a4b46ca9283300e9 100644 (file)
Binary files a/INSTALL/tool/i386/Ventoy2Disk.gtk3 and b/INSTALL/tool/i386/Ventoy2Disk.gtk3 differ
index 61ed87a1608f8d2d0f8a3520ed50002693e2c9fe..51bc50e94b15f3a825b6d321ac7260e3ca821a51 100644 (file)
Binary files a/INSTALL/tool/i386/Ventoy2Disk.qt5 and b/INSTALL/tool/i386/Ventoy2Disk.qt5 differ
index 0af729f0cb1c3e09d514503036ff0c38163bbe9a..8870f5c00c1e5684fa0ad91dd3529fab411aef79 100644 (file)
Binary files a/INSTALL/tool/mips64el/Plugson and b/INSTALL/tool/mips64el/Plugson differ
index 8777a85e10d90ea2ca26e3bd4738f8fea24a9f85..16a78cb87c4d0598e8bce6a89021e2a7a45ab409 100644 (file)
Binary files a/INSTALL/tool/mips64el/V2DServer and b/INSTALL/tool/mips64el/V2DServer differ
index 9f4c75901ca0bb137240a82c91f7b7140e175876..c2af26b49d715129caf796e3c8d25219280d6a55 100644 (file)
Binary files a/INSTALL/tool/mips64el/Ventoy2Disk.gtk3 and b/INSTALL/tool/mips64el/Ventoy2Disk.gtk3 differ
index 924e4a0d5c6304771f124aa86763b1edd092bcd7..eee73b25e5c98002ad54ae8509dd1d7775c49777 100644 (file)
Binary files a/INSTALL/tool/mips64el/Ventoy2Disk.qt5 and b/INSTALL/tool/mips64el/Ventoy2Disk.qt5 differ
index cd83b6db67d73eb818e47d75e55fadf1b510ba39..2358244e6222697af0516f5faf4e962cfc4f7b6b 100644 (file)
Binary files a/INSTALL/tool/x86_64/Plugson and b/INSTALL/tool/x86_64/Plugson differ
index 19da8b4e890083195922a4a84d74867d11fc7303..e28b652db5b7ce60f26a7fb9e47418f88cc32146 100644 (file)
Binary files a/INSTALL/tool/x86_64/V2DServer and b/INSTALL/tool/x86_64/V2DServer differ
index ef253183027498256be3b08678c8223bc0a1a2f3..f5c379587558b8832aee4142ad68cffe17238739 100644 (file)
Binary files a/INSTALL/tool/x86_64/Ventoy2Disk.gtk2 and b/INSTALL/tool/x86_64/Ventoy2Disk.gtk2 differ
index 881e17cc5125fe9259890d138e2dae7418429403..03411cf948e9ee9fd3be9efe036211cc902451d0 100644 (file)
Binary files a/INSTALL/tool/x86_64/Ventoy2Disk.gtk3 and b/INSTALL/tool/x86_64/Ventoy2Disk.gtk3 differ
index 13860cba9822e5ba5c7f47fd1ac7a8a52e10404b..e3ab28e2d2a39302107964c4096d386bdb44af91 100644 (file)
Binary files a/INSTALL/tool/x86_64/Ventoy2Disk.qt5 and b/INSTALL/tool/x86_64/Ventoy2Disk.qt5 differ
index 87eb5463a1caa66fdba5586a9e8aad019e003ffa..87bdbd5e784d9e89a623f2c1a2a7aaa2a5bfae25 100644 (file)
@@ -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__ */
 
index ac9920f7b554873b011a786eb5adc6d86bdcbd8c..561e0807d2b6fb0856ab07035f89dd23a1d6e963 100644 (file)
@@ -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");