]> glassweightruler.freedombox.rocks Git - Ventoy.git/blobdiff - LinuxGUI/Ventoy2Disk/Core/ventoy_disk.c
Fix arch iso boot issue (#2825 #2824)
[Ventoy.git] / LinuxGUI / Ventoy2Disk / Core / ventoy_disk.c
index 4df2040ec7ac96a777c657939f32c89f20aa2b8d..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;
@@ -508,6 +541,8 @@ int ventoy_get_vtoy_data(ventoy_disk *info, int *ppartstyle)
     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;
@@ -520,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
         {
@@ -536,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;
@@ -579,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);