]> glassweightruler.freedombox.rocks Git - Ventoy.git/blobdiff - VtoyTool/vtoydump.c
1. change some directory structure for the build script
[Ventoy.git] / VtoyTool / vtoydump.c
index c393ee248e0bf15bcaee2130332396161afe5540..e494598ad5605df3553841774c4bcd1f2347595c 100644 (file)
@@ -43,6 +43,17 @@ typedef unsigned char   uint8_t;
 
 #define VENTOY_GUID { 0x77772020, 0x2e77, 0x6576, { 0x6e, 0x74, 0x6f, 0x79, 0x2e, 0x6e, 0x65, 0x74 }}
 
 
 #define VENTOY_GUID { 0x77772020, 0x2e77, 0x6576, { 0x6e, 0x74, 0x6f, 0x79, 0x2e, 0x6e, 0x65, 0x74 }}
 
+typedef enum ventoy_fs_type
+{
+    ventoy_fs_exfat = 0, /* 0: exfat */
+    ventoy_fs_ntfs,      /* 1: NTFS */
+    ventoy_fs_ext,       /* 2: ext2/ext3/ext4 */
+    ventoy_fs_xfs,       /* 3: XFS */
+    ventoy_fs_udf,       /* 4: UDF */
+
+    ventoy_fs_max
+}ventoy_fs_type;
+
 #pragma pack(1)
 
 typedef struct ventoy_guid
 #pragma pack(1)
 
 typedef struct ventoy_guid
@@ -130,6 +141,11 @@ static int verbose = 0;
 
 static ventoy_guid vtoy_guid = VENTOY_GUID;
 
 
 static ventoy_guid vtoy_guid = VENTOY_GUID;
 
+static const char *g_ventoy_fs[ventoy_fs_max] = 
+{
+    "exfat", "ntfs", "ext*", "xfs", "udf"
+};
+
 static int vtoy_check_os_param(ventoy_os_param *param)
 {
     uint32_t i;
 static int vtoy_check_os_param(ventoy_os_param *param)
 {
     uint32_t i;
@@ -328,6 +344,11 @@ static int vtoy_find_disk_by_size(unsigned long long size, char *diskname)
     int rc = 0;
 
     dir = opendir("/sys/block");
     int rc = 0;
 
     dir = opendir("/sys/block");
+    if (!dir)
+    {
+        return 0;
+    }
+    
     while ((p = readdir(dir)) != NULL)
     {
         if (!vtoy_is_possible_blkdev(p->d_name))
     while ((p = readdir(dir)) != NULL)
     {
         if (!vtoy_is_possible_blkdev(p->d_name))
@@ -357,6 +378,11 @@ static int vtoy_find_disk_by_guid(uint8_t *guid, char *diskname)
     uint8_t vtguid[16];
 
     dir = opendir("/sys/block");
     uint8_t vtguid[16];
 
     dir = opendir("/sys/block");
+    if (!dir)
+    {
+        return 0;
+    }
+    
     while ((p = readdir(dir)) != NULL)
     {
         if (!vtoy_is_possible_blkdev(p->d_name))
     while ((p = readdir(dir)) != NULL)
     {
         if (!vtoy_is_possible_blkdev(p->d_name))
@@ -378,6 +404,12 @@ static int vtoy_find_disk_by_guid(uint8_t *guid, char *diskname)
     return count;    
 }
 
     return count;    
 }
 
+static int vtoy_printf_iso_path(ventoy_os_param *param)
+{
+    printf("%s\n", param->vtoy_img_path);
+    return 0;
+}
+
 static int vtoy_print_os_param(ventoy_os_param *param, char *diskname)
 {
     int   cnt = 0;
 static int vtoy_print_os_param(ventoy_os_param *param, char *diskname)
 {
     int   cnt = 0;
@@ -394,14 +426,10 @@ static int vtoy_print_os_param(ventoy_os_param *param, char *diskname)
         cnt = vtoy_find_disk_by_guid(param->vtoy_disk_guid, diskname);
         debug("find 0 disk by size, try with guid cnt=%d...\n", cnt);
     }
         cnt = vtoy_find_disk_by_guid(param->vtoy_disk_guid, diskname);
         debug("find 0 disk by size, try with guid cnt=%d...\n", cnt);
     }
-    
-    if (param->vtoy_disk_part_type == 0)
-    {
-        fs = "exfat";
-    }
-    else if (param->vtoy_disk_part_type == 0)
+
+    if (param->vtoy_disk_part_type < ventoy_fs_max)
     {
     {
-        fs = "ntfs";
+        fs = g_ventoy_fs[param->vtoy_disk_part_type];
     }
     else
     {
     }
     else
     {
@@ -432,7 +460,7 @@ static int vtoy_check_device(ventoy_os_param *param, const char *device)
     debug("param->vtoy_disk_size=%llu size=%llu\n", 
         (unsigned long long)param->vtoy_disk_size, (unsigned long long)size);
 
     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 && 
+    if ((param->vtoy_disk_size == size || param->vtoy_disk_size == size + 512) && 
         memcmp(vtguid, param->vtoy_disk_guid, 16) == 0)
     {
         debug("<%s> is right ventoy disk\n", device);
         memcmp(vtguid, param->vtoy_disk_guid, 16) == 0)
     {
         debug("<%s> is right ventoy disk\n", device);
@@ -458,12 +486,13 @@ int vtoydump_main(int argc, char **argv)
 {
     int rc;
     int ch;
 {
     int rc;
     int ch;
+    int print_path = 0;
     char filename[256] = {0};
     char diskname[256] = {0};
     char device[64] = {0};
     ventoy_os_param *param = NULL;
 
     char filename[256] = {0};
     char diskname[256] = {0};
     char device[64] = {0};
     ventoy_os_param *param = NULL;
 
-    while ((ch = getopt(argc, argv, "c:f:v::")) != -1)
+    while ((ch = getopt(argc, argv, "c:f:p:v::")) != -1)
     {
         if (ch == 'f')
         {
     {
         if (ch == 'f')
         {
@@ -477,6 +506,11 @@ int vtoydump_main(int argc, char **argv)
         {
             strncpy(device, optarg, sizeof(device) - 1);
         }
         {
             strncpy(device, optarg, sizeof(device) - 1);
         }
+        else if (ch == 'p')
+        {
+            print_path = 1;
+            strncpy(filename, optarg, sizeof(filename) - 1);
+        }
         else
         {
             fprintf(stderr, "Usage: %s -f datafile [ -v ] \n", argv[0]);
         else
         {
             fprintf(stderr, "Usage: %s -f datafile [ -v ] \n", argv[0]);
@@ -513,7 +547,11 @@ int vtoydump_main(int argc, char **argv)
         vtoy_dump_os_param(param);
     }
 
         vtoy_dump_os_param(param);
     }
 
-    if (device[0])
+    if (print_path)
+    {
+        rc = vtoy_printf_iso_path(param);
+    }
+    else if (device[0])
     {
         rc = vtoy_check_device(param, device);
     }
     {
         rc = vtoy_check_device(param, device);
     }