X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/Ventoy.git/blobdiff_plain/4f840ed6736c4622c246bdaba3671e5820b79657..6bd0463d3403c5c3dfe8ef5efe4ff74ceb86eeda:/VtoyTool/vtoydump.c diff --git a/VtoyTool/vtoydump.c b/VtoyTool/vtoydump.c index ff3a4d2..34c1ee7 100644 --- a/VtoyTool/vtoydump.c +++ b/VtoyTool/vtoydump.c @@ -35,7 +35,9 @@ #define IS_DIGIT(x) ((x) >= '0' && (x) <= '9') #ifndef USE_DIET_C +#ifndef __mips__ typedef unsigned long long uint64_t; +#endif typedef unsigned int uint32_t; typedef unsigned short uint16_t; typedef unsigned char uint8_t; @@ -433,6 +435,33 @@ static int vtoy_printf_iso_path(ventoy_os_param *param) return 0; } +static int vtoy_check_device(ventoy_os_param *param, const char *device) +{ + unsigned long long size; + uint8_t vtguid[16] = {0}; + uint8_t vtsig[4] = {0}; + + debug("vtoy_check_device for <%s>\n", device); + + size = vtoy_get_disk_size_in_byte(device); + vtoy_get_disk_guid(device, vtguid, vtsig); + + debug("param->vtoy_disk_size=%llu size=%llu\n", + (unsigned long long)param->vtoy_disk_size, (unsigned long long)size); + + if (memcmp(vtguid, param->vtoy_disk_guid, 16) == 0 && + memcmp(vtsig, param->vtoy_disk_signature, 4) == 0) + { + debug("<%s> is right ventoy disk\n", device); + return 0; + } + else + { + debug("<%s> is NOT right ventoy disk\n", device); + return 1; + } +} + static int vtoy_print_os_param(ventoy_os_param *param, char *diskname) { int cnt = 0; @@ -440,16 +469,20 @@ static int vtoy_print_os_param(ventoy_os_param *param, char *diskname) const char *fs; cnt = vtoy_find_disk_by_size(param->vtoy_disk_size, diskname); - if (cnt > 1) + debug("find disk by size %llu, cnt=%d...\n", (unsigned long long)param->vtoy_disk_size, cnt); + if (1 == cnt) { - cnt = vtoy_find_disk_by_guid(param, diskname); + if (vtoy_check_device(param, diskname) != 0) + { + cnt = 0; + } } - else if (cnt == 0) + else { cnt = vtoy_find_disk_by_guid(param, diskname); - debug("find 0 disk by size, try with guid cnt=%d...\n", cnt); + debug("find disk by guid cnt=%d...\n", cnt); } - + if (param->vtoy_disk_part_type < ventoy_fs_max) { fs = g_ventoy_fs[param->vtoy_disk_part_type]; @@ -470,34 +503,6 @@ static int vtoy_print_os_param(ventoy_os_param *param, char *diskname) } } -static int vtoy_check_device(ventoy_os_param *param, const char *device) -{ - unsigned long long size; - uint8_t vtguid[16] = {0}; - uint8_t vtsig[4] = {0}; - - debug("vtoy_check_device for <%s>\n", device); - - size = vtoy_get_disk_size_in_byte(device); - vtoy_get_disk_guid(device, vtguid, vtsig); - - debug("param->vtoy_disk_size=%llu size=%llu\n", - (unsigned long long)param->vtoy_disk_size, (unsigned long long)size); - - if ((param->vtoy_disk_size == size || param->vtoy_disk_size == size + 512) && - memcmp(vtguid, param->vtoy_disk_guid, 16) == 0 && - memcmp(vtsig, param->vtoy_disk_signature, 4) == 0) - { - debug("<%s> is right ventoy disk\n", device); - return 0; - } - else - { - debug("<%s> is NOT right ventoy disk\n", device); - return 1; - } -} - /* * Find disk and image path from ventoy runtime data. * By default data is read from phymem(legacy bios) or efivar(UEFI), if -f is input, data is read from file. @@ -563,8 +568,20 @@ int vtoydump_main(int argc, char **argv) rc = vtoy_os_param_from_file(filename, param); if (rc) { - debug("ventoy os param not found %d\n", rc); - goto end; + debug("ventoy os param not found %d %d\n", rc, ENOENT); + if (ENOENT == rc) + { + debug("now try with file %s\n", "/ventoy/ventoy_os_param"); + rc = vtoy_os_param_from_file("/ventoy/ventoy_os_param", param); + if (rc) + { + goto end; + } + } + else + { + goto end; + } } if (verbose)