1 /******************************************************************************
4 * Copyright (c) 2020, longpanda <admin@ventoy.net>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include <grub/types.h>
22 #include <grub/misc.h>
26 #include <grub/disk.h>
27 #include <grub/device.h>
28 #include <grub/term.h>
29 #include <grub/partition.h>
30 #include <grub/file.h>
31 #include <grub/normal.h>
32 #include <grub/extcmd.h>
33 #include <grub/datetime.h>
35 #include <grub/misc.h>
36 #include <grub/kernel.h>
37 #include <grub/time.h>
38 #include <grub/ventoy.h>
39 #include "ventoy_def.h"
41 GRUB_MOD_LICENSE ("GPLv3+");
43 int g_ventoy_debug
= 0;
44 static int g_efi_os
= 0xFF;
45 grub_uint32_t g_ventoy_plat_data
;
47 void ventoy_debug(const char *fmt
, ...)
52 grub_vprintf (fmt
, args
);
56 void ventoy_str_tolower(char *str
)
60 *str
= grub_tolower(*str
);
65 void ventoy_str_toupper(char *str
)
69 *str
= grub_toupper(*str
);
76 int ventoy_strcmp(const char *pattern
, const char *str
)
78 while (*pattern
&& *str
)
80 if ((*pattern
!= *str
) && (*pattern
!= '*'))
87 return (int)(grub_uint8_t
)*pattern
- (int)(grub_uint8_t
)*str
;
90 int ventoy_strncmp (const char *pattern
, const char *str
, grub_size_t n
)
95 while (*pattern
&& *str
&& --n
)
97 if ((*pattern
!= *str
) && (*pattern
!= '*'))
104 return (int)(grub_uint8_t
)*pattern
- (int)(grub_uint8_t
)*str
;
107 void ventoy_debug_dump_guid(const char *prefix
, grub_uint8_t
*guid
)
117 for (i
= 0; i
< 16; i
++)
119 grub_printf("%02x ", guid
[i
]);
124 int ventoy_is_efi_os(void)
128 g_efi_os
= (grub_strstr(GRUB_PLATFORM
, "efi")) ? 1 : 0;
134 static int ventoy_arch_mode_init(void)
136 #ifdef GRUB_MACHINE_EFI
137 if (grub_strcmp(GRUB_TARGET_CPU
, "i386") == 0)
139 g_ventoy_plat_data
= VTOY_PLAT_I386_UEFI
;
140 grub_snprintf(g_arch_mode_suffix
, sizeof(g_arch_mode_suffix
), "%s", "ia32");
142 else if (grub_strcmp(GRUB_TARGET_CPU
, "arm64") == 0)
144 g_ventoy_plat_data
= VTOY_PLAT_ARM64_UEFI
;
145 grub_snprintf(g_arch_mode_suffix
, sizeof(g_arch_mode_suffix
), "%s", "aa64");
147 else if (grub_strcmp(GRUB_TARGET_CPU
, "mips64el") == 0)
149 g_ventoy_plat_data
= VTOY_PLAT_MIPS_UEFI
;
150 grub_snprintf(g_arch_mode_suffix
, sizeof(g_arch_mode_suffix
), "%s", "mips");
154 g_ventoy_plat_data
= VTOY_PLAT_X86_64_UEFI
;
155 grub_snprintf(g_arch_mode_suffix
, sizeof(g_arch_mode_suffix
), "%s", "uefi");
158 g_ventoy_plat_data
= VTOY_PLAT_X86_LEGACY
;
159 grub_snprintf(g_arch_mode_suffix
, sizeof(g_arch_mode_suffix
), "%s", "legacy");
165 GRUB_MOD_INIT(ventoy
)
168 ventoy_arch_mode_init();
169 ventoy_register_all_cmd();
172 GRUB_MOD_FINI(ventoy
)
174 ventoy_unregister_all_cmd();