]> glassweightruler.freedombox.rocks Git - Ventoy.git/blobdiff - LinuxGUI/Ventoy2Disk/Core/ventoy_disk.c
Fix Windows 11 error 0x80070001. (#3010 #3029 #3105)
[Ventoy.git] / LinuxGUI / Ventoy2Disk / Core / ventoy_disk.c
index 4d0871b86f32ac80fadb55fa8af0a7855616c9b5..5d4bbff736d18a27d8eb6a31bf90d0bdc2bd9544 100644 (file)
@@ -232,6 +232,12 @@ static int ventoy_is_possible_blkdev(const char *name)
     {
         return 0;
     }
+    
+    /* /dev/zramX */
+    if (name[0] == 'z' && name[1] == 'r' && name[2] == 'a' && name[3] == 'm')
+    {
+        return 0;
+    }
 
     /* /dev/loopX */
     if (name[0] == 'l' && name[1] == 'o' && name[2] == 'o' && name[3] == 'p')
@@ -254,6 +260,33 @@ static int ventoy_is_possible_blkdev(const char *name)
     return 1;
 }
 
+int ventoy_is_disk_4k_native(const char *disk)
+{
+    int fd;
+    int rc = 0;
+    int logsector = 0;
+    int physector = 0;
+    char diskpath[256] = {0};
+
+    snprintf(diskpath, sizeof(diskpath) - 1, "/dev/%s", disk);
+
+    fd = open(diskpath, O_RDONLY | O_BINARY);
+    if (fd >= 0)
+    {
+        ioctl(fd, BLKSSZGET, &logsector);
+        ioctl(fd, BLKPBSZGET, &physector);
+        
+        if (logsector == 4096 && physector == 4096)
+        {
+            rc = 1;
+        }
+        close(fd);
+    }
+
+    vdebug("is 4k native disk <%s> <%d>\n", disk, rc);    
+    return rc;
+}
+
 uint64_t ventoy_get_disk_size_in_byte(const char *disk)
 {
     int fd;
@@ -330,6 +363,7 @@ static int fatlib_is_secure_boot_enable(void)
     flfile = fl_fopen("/EFI/BOOT/grubx64_real.efi", "rb");
     if (flfile)
     {
+        vlog("/EFI/BOOT/grubx64_real.efi find, secure boot in enabled\n");
         fl_fclose(flfile);
         return 1;
     }
@@ -504,7 +538,12 @@ int ventoy_get_vtoy_data(ventoy_disk *info, int *ppartstyle)
         goto end;
     }
 
-    vdebug("now check secure boot ...\n");
+    vdebug("ventoy partition layout check OK: [%llu %llu] [%llu %llu]\n", 
+               part1_start_sector, part1_sector_count, part2_start_sector, part2_sector_count);
+
+    vtoy->ventoy_valid = 1;
+
+    vdebug("now check secure boot for %s ...\n", info->disk_path);
 
     g_fatlib_media_fd = fd;
     g_fatlib_media_offset = part2_start_sector;
@@ -516,7 +555,6 @@ int ventoy_get_vtoy_data(ventoy_disk *info, int *ppartstyle)
         if (ret == 0 && vtoy->ventoy_ver[0])
         {
             vtoy->secure_boot_flag = fatlib_is_secure_boot_enable();            
-            vtoy->ventoy_valid = 1;
         }
         else
         {
@@ -532,6 +570,11 @@ int ventoy_get_vtoy_data(ventoy_disk *info, int *ppartstyle)
     g_fatlib_media_fd = -1;
     g_fatlib_media_offset = 0;
 
+    if (vtoy->ventoy_ver[0] == 0)
+    {
+        vtoy->ventoy_ver[0] = '?';
+    }
+
     if (0 == vtoy->ventoy_valid)
     {
         goto end;
@@ -546,7 +589,7 @@ int ventoy_get_vtoy_data(ventoy_disk *info, int *ppartstyle)
 
     rc = 0;
 end:
-    close(fd);
+    vtoy_safe_close_fd(fd);
     return rc;
 }
 
@@ -575,6 +618,7 @@ int ventoy_get_disk_info(const char *name, ventoy_disk *info)
         scnprintf(info->part2_path, "/dev/%s2", name);
     }
     
+    info->is4kn = ventoy_is_disk_4k_native(name);
     info->size_in_byte = ventoy_get_disk_size_in_byte(name);
 
     ventoy_get_disk_devnum(name, &info->major, &info->minor);