]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Plugson/src/Core/ventoy_disk_windows.c
The gpt pointer is not initialized, and when offset < 0, it may result in freeing...
[Ventoy.git] / Plugson / src / Core / ventoy_disk_windows.c
1 /******************************************************************************
2 * ventoy_disk.c ---- ventoy disk
3 * Copyright (c) 2021, longpanda <admin@ventoy.net>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19 #include <windows.h>
20 #include <stdlib.h>
21 #include <stdint.h>
22 #include <time.h>
23 #include <ventoy_define.h>
24 #include <ventoy_disk.h>
25 #include <ventoy_util.h>
26 #include <fat_filelib.h>
27
28 static int g_disk_num = 0;
29 ventoy_disk *g_disk_list = NULL;
30
31 int ventoy_disk_init(void)
32 {
33 char Letter = 'A';
34 DWORD Drives = GetLogicalDrives();
35
36 vlog("ventoy disk init ...\n");
37
38 g_disk_list = zalloc(sizeof(ventoy_disk) * MAX_DISK);
39
40 while (Drives)
41 {
42 if (Drives & 0x01)
43 {
44 if (CheckRuntimeEnvironment(Letter, g_disk_list + g_disk_num) == 0)
45 {
46 g_disk_list[g_disk_num].devname[0] = Letter;
47 g_disk_num++;
48 vlog("%C: is ventoy disk\n", Letter);
49 }
50 else
51 {
52 memset(g_disk_list + g_disk_num, 0, sizeof(ventoy_disk));
53 vlog("%C: is NOT ventoy disk\n", Letter);
54 }
55 }
56
57 Letter++;
58 Drives >>= 1;
59 }
60
61 return 0;
62 }
63
64 void ventoy_disk_exit(void)
65 {
66 vlog("ventoy disk exit ...\n");
67
68 check_free(g_disk_list);
69 g_disk_list = NULL;
70 g_disk_num = 0;
71 }
72
73 const ventoy_disk * ventoy_get_disk_list(int *num)
74 {
75 *num = g_disk_num;
76 return g_disk_list;
77 }
78
79 const ventoy_disk * ventoy_get_disk_node(int id)
80 {
81 if (id >= 0 && id < g_disk_num)
82 {
83 return g_disk_list + id;
84 }
85
86 return NULL;
87 }
88