]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Vlnk/src/vlnk.c
Fix the order issue in TreeView mode. (#3218)
[Ventoy.git] / Vlnk / src / vlnk.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <string.h>
5 #include "vlnk.h"
6
7 int ventoy_create_vlnk(uint32_t disksig, uint64_t partoffset, const char *path, ventoy_vlnk *vlnk)
8 {
9 uint32_t crc;
10 ventoy_guid guid = VENTOY_GUID;
11
12 memcpy(&(vlnk->guid), &guid, sizeof(ventoy_guid));
13 vlnk->disk_signature = disksig;
14 vlnk->part_offset = partoffset;
15
16 #ifdef WIN32
17 strcpy_s(vlnk->filepath, sizeof(vlnk->filepath) - 1, path);
18 #else
19 strncpy(vlnk->filepath, path, sizeof(vlnk->filepath) - 1);
20 #endif
21
22 crc = ventoy_getcrc32c(0, vlnk, sizeof(ventoy_vlnk));
23 vlnk->crc32 = crc;
24
25 return 0;
26 }
27
28
29 int CheckVlnkData(ventoy_vlnk *vlnk)
30 {
31 uint32_t readcrc, calccrc;
32 ventoy_guid guid = VENTOY_GUID;
33
34 if (memcmp(&vlnk->guid, &guid, sizeof(guid)))
35 {
36 return 0;
37 }
38
39 readcrc = vlnk->crc32;
40 vlnk->crc32 = 0;
41 calccrc = ventoy_getcrc32c(0, vlnk, sizeof(ventoy_vlnk));
42
43 if (readcrc != calccrc)
44 {
45 return 0;
46 }
47
48 return 1;
49 }
50
51 int IsSupportedImgSuffix(char *suffix)
52 {
53 int i = 0;
54 const char *suffixs[] =
55 {
56 ".iso", ".img", ".wim", ".efi", ".vhd", ".vhdx", ".dat", ".vtoy", NULL
57 };
58
59 if (!suffix)
60 {
61 return 0;
62 }
63
64 while (suffixs[i])
65 {
66
67 #ifdef WIN32
68 if (_stricmp(suffixs[i], suffix) == 0)
69 #else
70 if (strcasecmp(suffixs[i], suffix) == 0)
71 #endif
72 {
73 return 1;
74 }
75
76 i++;
77 }
78
79 return 0;
80 }