:: commit 512a5fcc609efdb0b6f5c028129f555c668e791a

mintsuki <mintsuki@protonmail.com> — 2022-07-10 20:46

parents: e7e73ae6fe

mbr: Add extra FAT32 and NTFS signatures to validity check

diff --git a/common/lib/part.s2.c b/common/lib/part.s2.c
index b0e9decd..e8befe83 100644
--- a/common/lib/part.s2.c
+++ b/common/lib/part.s2.c
@@ -276,12 +276,18 @@ static bool is_valid_mbr(struct volume *volume) {
     volume_read(volume, hintc, 4, 8);
     if (memcmp(hintc, "_ECH_FS_", 8) == 0)
         return false;
+    volume_read(volume, hintc, 3, 4);
+    if (memcmp(hintc, "NTFS", 4) == 0)
+        return false;
     volume_read(volume, hintc, 54, 3);
     if (memcmp(hintc, "FAT", 3) == 0)
         return false;
     volume_read(volume, hintc, 82, 3);
     if (memcmp(hintc, "FAT", 3) == 0)
         return false;
+    volume_read(volume, hintc, 3, 5);
+    if (memcmp(hintc, "FAT32", 5) == 0)
+        return false;
     volume_read(volume, &hint, 1080, sizeof(uint16_t));
     if (hint == 0xef53)
         return false;
diff --git a/limine-deploy/limine-deploy.c b/limine-deploy/limine-deploy.c
index a9e346b9..a62ece59 100644
--- a/limine-deploy/limine-deploy.c
+++ b/limine-deploy/limine-deploy.c
@@ -496,6 +496,15 @@ int main(int argc, char *argv[]) {
                 device_write(hintc, 4, 8);
             }
         }
+        device_read(hintc, 3, 4);
+        if (memcmp(hintc, "NTFS", 4) == 0) {
+            if (!force_mbr) {
+                mbr = 0;
+            } else {
+                memset(hintc, 0, 4);
+                device_write(hintc, 3, 4);
+            }
+        }
         device_read(hintc, 54, 3);
         if (memcmp(hintc, "FAT", 3) == 0) {
             if (!force_mbr) {
@@ -514,6 +523,15 @@ int main(int argc, char *argv[]) {
                 device_write(hintc, 82, 5);
             }
         }
+        device_read(hintc, 3, 5);
+        if (memcmp(hintc, "FAT32", 5) == 0) {
+            if (!force_mbr) {
+                mbr = 0;
+            } else {
+                memset(hintc, 0, 5);
+                device_write(hintc, 3, 5);
+            }
+        }
         device_read(&hint16, 1080, sizeof(uint16_t));
         hint16 = ENDSWAP(hint16);
         if (hint16 == 0xef53) {
@@ -537,8 +555,8 @@ int main(int argc, char *argv[]) {
     if (gpt == 0 && mbr == 0) {
         fprintf(stderr, "ERROR: Could not determine if the device has a valid partition table.\n");
         fprintf(stderr, "       Please ensure the device has a valid MBR or GPT.\n");
-        fprintf(stderr, "       Alternatively, pass `--force-mbr` to override these checks. ONLY\n");
-        fprintf(stderr, "        DO THIS AT YOUR OWN RISK, DATA LOSS MAY OCCUR!\n");
+        fprintf(stderr, "       Alternatively, pass `--force-mbr` to override these checks.\n");
+        fprintf(stderr, "       **ONLY DO THIS AT YOUR OWN RISK, DATA LOSS MAY OCCUR!**\n");
         goto cleanup;
     }
 
tab: 248 wrap: offon