X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/Ventoy.git/blobdiff_plain/dce5d1b769ff2c404d61d8a60510de624b275337..4e8d8b2e19d0222f5f859c8462f420877b68aa24:/LinuxGUI/Ventoy2Disk/Core/ventoy_disk.c diff --git a/LinuxGUI/Ventoy2Disk/Core/ventoy_disk.c b/LinuxGUI/Ventoy2Disk/Core/ventoy_disk.c index a4ac62b..5d4bbff 100644 --- a/LinuxGUI/Ventoy2Disk/Core/ventoy_disk.c +++ b/LinuxGUI/Ventoy2Disk/Core/ventoy_disk.c @@ -260,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; @@ -514,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; @@ -526,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 { @@ -542,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; @@ -585,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);