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/>.
20 #include <grub/types.h>
21 #include <grub/misc.h>
25 #include <grub/disk.h>
26 #include <grub/device.h>
27 #include <grub/term.h>
28 #include <grub/partition.h>
29 #include <grub/file.h>
30 #include <grub/normal.h>
31 #include <grub/extcmd.h>
32 #include <grub/datetime.h>
33 #include <grub/i18n.h>
35 #include <grub/crypto.h>
36 #include <grub/time.h>
37 #include <grub/font.h>
38 #include <grub/ventoy.h>
39 #include "ventoy_def.h"
41 GRUB_MOD_LICENSE ("GPLv3+");
43 char g_arch_mode_suffix
[64];
44 static char g_iso_disk_name
[128];
45 static vtoy_password g_boot_pwd
;
46 static vtoy_password g_file_type_pwd
[img_type_max
];
47 static install_template
*g_install_template_head
= NULL
;
48 static dud
*g_dud_head
= NULL
;
49 static menu_password
*g_pwd_head
= NULL
;
50 static persistence_config
*g_persistence_head
= NULL
;
51 static menu_tip
*g_menu_tip_head
= NULL
;
52 static menu_alias
*g_menu_alias_head
= NULL
;
53 static menu_class
*g_menu_class_head
= NULL
;
54 static custom_boot
*g_custom_boot_head
= NULL
;
55 static injection_config
*g_injection_head
= NULL
;
56 static auto_memdisk
*g_auto_memdisk_head
= NULL
;
57 static image_list
*g_image_list_head
= NULL
;
58 static conf_replace
*g_conf_replace_head
= NULL
;
60 static int g_theme_num
= 0;
61 static theme_list
*g_theme_head
= NULL
;
62 static int g_theme_random
= vtoy_theme_random_boot_second
;
63 static char g_theme_single_file
[256];
65 static int ventoy_plugin_is_parent(const char *pat
, int patlen
, const char *isopath
)
69 if (isopath
[patlen
] == '/' && ventoy_strncmp(pat
, isopath
, patlen
) == 0 &&
70 grub_strchr(isopath
+ patlen
+ 1, '/') == NULL
)
77 if (pat
[0] == '/' && grub_strchr(isopath
+ 1, '/') == NULL
)
86 static int ventoy_plugin_control_check(VTOY_JSON
*json
, const char *isodisk
)
89 VTOY_JSON
*pNode
= NULL
;
90 VTOY_JSON
*pChild
= NULL
;
94 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
96 grub_printf("Not array type %d\n", json
->enDataType
);
100 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
102 if (pNode
->enDataType
== JSON_TYPE_OBJECT
)
104 pChild
= pNode
->pstChild
;
105 if (pChild
->enDataType
== JSON_TYPE_STRING
)
107 if (grub_strcmp(pChild
->pcName
, "VTOY_DEFAULT_IMAGE") == 0)
109 grub_printf("%s: %s [%s]\n", pChild
->pcName
, pChild
->unData
.pcStrVal
,
110 ventoy_check_file_exist("%s%s", isodisk
, pChild
->unData
.pcStrVal
) ? "OK" : "NOT EXIST");
114 grub_printf("%s: %s\n", pChild
->pcName
, pChild
->unData
.pcStrVal
);
119 grub_printf("%s is NOT string type\n", pChild
->pcName
);
125 grub_printf("%s is not an object\n", pNode
->pcName
);
133 static int ventoy_plugin_control_entry(VTOY_JSON
*json
, const char *isodisk
)
135 VTOY_JSON
*pNode
= NULL
;
136 VTOY_JSON
*pChild
= NULL
;
140 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
142 debug("Not array %d\n", json
->enDataType
);
146 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
148 if (pNode
->enDataType
== JSON_TYPE_OBJECT
)
150 pChild
= pNode
->pstChild
;
151 if (pChild
->enDataType
== JSON_TYPE_STRING
&& pChild
->pcName
&& pChild
->unData
.pcStrVal
)
153 ventoy_set_env(pChild
->pcName
, pChild
->unData
.pcStrVal
);
161 static int ventoy_plugin_theme_check(VTOY_JSON
*json
, const char *isodisk
)
167 value
= vtoy_json_get_string_ex(json
->pstChild
, "file");
170 grub_printf("file: %s\n", value
);
173 exist
= ventoy_is_file_exist("%s%s", isodisk
, value
);
177 exist
= ventoy_is_file_exist("%s/ventoy/%s", isodisk
, value
);
182 grub_printf("Theme file %s does NOT exist\n", value
);
188 node
= vtoy_json_find_item(json
->pstChild
, JSON_TYPE_ARRAY
, "file");
191 for (node
= node
->pstChild
; node
; node
= node
->pstNext
)
193 value
= node
->unData
.pcStrVal
;
194 grub_printf("file: %s\n", value
);
197 exist
= ventoy_is_file_exist("%s%s", isodisk
, value
);
201 exist
= ventoy_is_file_exist("%s/ventoy/%s", isodisk
, value
);
206 grub_printf("Theme file %s does NOT exist\n", value
);
211 value
= vtoy_json_get_string_ex(json
->pstChild
, "random");
214 grub_printf("random: %s\n", value
);
219 value
= vtoy_json_get_string_ex(json
->pstChild
, "gfxmode");
222 grub_printf("gfxmode: %s\n", value
);
225 value
= vtoy_json_get_string_ex(json
->pstChild
, "display_mode");
228 grub_printf("display_mode: %s\n", value
);
231 value
= vtoy_json_get_string_ex(json
->pstChild
, "serial_param");
234 grub_printf("serial_param %s\n", value
);
237 value
= vtoy_json_get_string_ex(json
->pstChild
, "ventoy_left");
240 grub_printf("ventoy_left: %s\n", value
);
243 value
= vtoy_json_get_string_ex(json
->pstChild
, "ventoy_top");
246 grub_printf("ventoy_top: %s\n", value
);
249 value
= vtoy_json_get_string_ex(json
->pstChild
, "ventoy_color");
252 grub_printf("ventoy_color: %s\n", value
);
255 node
= vtoy_json_find_item(json
->pstChild
, JSON_TYPE_ARRAY
, "fonts");
258 for (node
= node
->pstChild
; node
; node
= node
->pstNext
)
260 if (node
->enDataType
== JSON_TYPE_STRING
)
262 if (ventoy_check_file_exist("%s%s", isodisk
, node
->unData
.pcStrVal
))
264 grub_printf("%s [OK]\n", node
->unData
.pcStrVal
);
268 grub_printf("%s [NOT EXIST]\n", node
->unData
.pcStrVal
);
275 grub_printf("fonts NOT found\n");
281 static int ventoy_plugin_theme_entry(VTOY_JSON
*json
, const char *isodisk
)
285 VTOY_JSON
*node
= NULL
;
286 theme_list
*tail
= NULL
;
287 theme_list
*themenode
= NULL
;
289 value
= vtoy_json_get_string_ex(json
->pstChild
, "file");
294 grub_snprintf(filepath
, sizeof(filepath
), "%s%s", isodisk
, value
);
298 grub_snprintf(filepath
, sizeof(filepath
), "%s/ventoy/%s", isodisk
, value
);
301 if (ventoy_check_file_exist(filepath
) == 0)
303 debug("Theme file %s does not exist\n", filepath
);
307 debug("vtoy_theme %s\n", filepath
);
308 ventoy_env_export("vtoy_theme", filepath
);
309 grub_snprintf(g_theme_single_file
, sizeof(g_theme_single_file
), "%s", filepath
);
313 node
= vtoy_json_find_item(json
->pstChild
, JSON_TYPE_ARRAY
, "file");
316 for (node
= node
->pstChild
; node
; node
= node
->pstNext
)
318 value
= node
->unData
.pcStrVal
;
321 grub_snprintf(filepath
, sizeof(filepath
), "%s%s", isodisk
, value
);
325 grub_snprintf(filepath
, sizeof(filepath
), "%s/ventoy/%s", isodisk
, value
);
328 if (ventoy_check_file_exist(filepath
) == 0)
333 themenode
= grub_zalloc(sizeof(theme_list
));
336 grub_snprintf(themenode
->theme
.path
, sizeof(themenode
->theme
.path
), "%s", filepath
);
339 tail
->next
= themenode
;
343 g_theme_head
= themenode
;
350 ventoy_env_export("vtoy_theme", "random");
351 value
= vtoy_json_get_string_ex(json
->pstChild
, "random");
354 if (grub_strcmp(value
, "boot_second") == 0)
356 g_theme_random
= vtoy_theme_random_boot_second
;
358 else if (grub_strcmp(value
, "boot_day") == 0)
360 g_theme_random
= vtoy_theme_random_boot_day
;
362 else if (grub_strcmp(value
, "boot_month") == 0)
364 g_theme_random
= vtoy_theme_random_boot_month
;
370 value
= vtoy_json_get_string_ex(json
->pstChild
, "gfxmode");
373 debug("vtoy_gfxmode %s\n", value
);
374 ventoy_env_export("vtoy_gfxmode", value
);
377 value
= vtoy_json_get_string_ex(json
->pstChild
, "display_mode");
380 debug("display_mode %s\n", value
);
381 ventoy_env_export("vtoy_display_mode", value
);
384 value
= vtoy_json_get_string_ex(json
->pstChild
, "serial_param");
387 debug("serial_param %s\n", value
);
388 ventoy_env_export("vtoy_serial_param", value
);
391 value
= vtoy_json_get_string_ex(json
->pstChild
, "ventoy_left");
394 ventoy_env_export("VTLE_LFT", value
);
397 value
= vtoy_json_get_string_ex(json
->pstChild
, "ventoy_top");
400 ventoy_env_export("VTLE_TOP", value
);
403 value
= vtoy_json_get_string_ex(json
->pstChild
, "ventoy_color");
406 ventoy_env_export("VTLE_CLR", value
);
409 node
= vtoy_json_find_item(json
->pstChild
, JSON_TYPE_ARRAY
, "fonts");
412 for (node
= node
->pstChild
; node
; node
= node
->pstNext
)
414 if (node
->enDataType
== JSON_TYPE_STRING
&&
415 ventoy_check_file_exist("%s%s", isodisk
, node
->unData
.pcStrVal
))
417 grub_snprintf(filepath
, sizeof(filepath
), "%s%s", isodisk
, node
->unData
.pcStrVal
);
418 grub_font_load(filepath
);
426 static int ventoy_plugin_check_path(const char *path
, const char *file
)
430 grub_printf("%s is NOT begin with '/' \n", file
);
434 if (grub_strchr(file
, '\\'))
436 grub_printf("%s contains invalid '\\' \n", file
);
440 if (grub_strstr(file
, "//"))
442 grub_printf("%s contains invalid double slash\n", file
);
446 if (grub_strstr(file
, "../"))
448 grub_printf("%s contains invalid '../' \n", file
);
452 if (!ventoy_is_file_exist("%s%s", path
, file
))
454 grub_printf("%s%s does NOT exist\n", path
, file
);
461 static int ventoy_plugin_check_fullpath
472 VTOY_JSON
*node
= json
;
473 VTOY_JSON
*child
= NULL
;
477 if (0 == grub_strcmp(key
, node
->pcName
))
481 node
= node
->pstNext
;
489 if (JSON_TYPE_STRING
== node
->enDataType
)
492 ret
= ventoy_plugin_check_path(isodisk
, node
->unData
.pcStrVal
);
493 grub_printf("%s: %s [%s]\n", key
, node
->unData
.pcStrVal
, ret
? "FAIL" : "OK");
495 else if (JSON_TYPE_ARRAY
== node
->enDataType
)
497 for (child
= node
->pstChild
; child
; child
= child
->pstNext
)
499 if (JSON_TYPE_STRING
!= child
->enDataType
)
501 grub_printf("Non string json type\n");
505 rc
= ventoy_plugin_check_path(isodisk
, child
->unData
.pcStrVal
);
506 grub_printf("%s: %s [%s]\n", key
, child
->unData
.pcStrVal
, rc
? "FAIL" : "OK");
517 static int ventoy_plugin_parse_fullpath
522 file_fullpath
**fullpath
,
528 VTOY_JSON
*node
= json
;
529 VTOY_JSON
*child
= NULL
;
530 file_fullpath
*path
= NULL
;
534 if (0 == grub_strcmp(key
, node
->pcName
))
538 node
= node
->pstNext
;
546 if (JSON_TYPE_STRING
== node
->enDataType
)
548 debug("%s is string type data\n", node
->pcName
);
550 if ((node
->unData
.pcStrVal
[0] != '/') || (!ventoy_is_file_exist("%s%s", isodisk
, node
->unData
.pcStrVal
)))
552 debug("%s%s file not found\n", isodisk
, node
->unData
.pcStrVal
);
556 path
= (file_fullpath
*)grub_zalloc(sizeof(file_fullpath
));
559 grub_snprintf(path
->path
, sizeof(path
->path
), "%s", node
->unData
.pcStrVal
);
565 else if (JSON_TYPE_ARRAY
== node
->enDataType
)
567 for (child
= node
->pstChild
; child
; child
= child
->pstNext
)
569 if ((JSON_TYPE_STRING
!= child
->enDataType
) || (child
->unData
.pcStrVal
[0] != '/'))
571 debug("Invalid data type:%d\n", child
->enDataType
);
576 debug("%s is array type data, count=%d\n", node
->pcName
, count
);
578 path
= (file_fullpath
*)grub_zalloc(sizeof(file_fullpath
) * count
);
583 for (count
= 0, child
= node
->pstChild
; child
; child
= child
->pstNext
)
585 if (ventoy_is_file_exist("%s%s", isodisk
, child
->unData
.pcStrVal
))
587 grub_snprintf(path
->path
, sizeof(path
->path
), "%s", child
->unData
.pcStrVal
);
601 static int ventoy_plugin_auto_install_check(VTOY_JSON
*json
, const char *isodisk
)
606 const char *iso
= NULL
;
607 VTOY_JSON
*pNode
= NULL
;
609 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
611 grub_printf("Not array type %d\n", json
->enDataType
);
615 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
617 if (pNode
->enDataType
!= JSON_TYPE_OBJECT
)
619 grub_printf("NOT object type\n");
622 if ((iso
= vtoy_json_get_string_ex(pNode
->pstChild
, "image")) != NULL
)
624 pos
= grub_strchr(iso
, '*');
625 if (pos
|| 0 == ventoy_plugin_check_path(isodisk
, iso
))
627 grub_printf("image: %s [%s]\n", iso
, (pos
? "*" : "OK"));
628 ventoy_plugin_check_fullpath(pNode
->pstChild
, isodisk
, "template", &pathnum
);
630 if (JSON_SUCCESS
== vtoy_json_get_int(pNode
->pstChild
, "autosel", &autosel
))
632 if (autosel
>= 0 && autosel
<= pathnum
)
634 grub_printf("autosel: %d [OK]\n", autosel
);
638 grub_printf("autosel: %d [FAIL]\n", autosel
);
644 grub_printf("image: %s [FAIL]\n", iso
);
647 else if ((iso
= vtoy_json_get_string_ex(pNode
->pstChild
, "parent")) != NULL
)
649 if (ventoy_is_dir_exist("%s%s", isodisk
, iso
))
651 grub_printf("parent: %s [OK]\n", iso
);
652 ventoy_plugin_check_fullpath(pNode
->pstChild
, isodisk
, "template", &pathnum
);
654 if (JSON_SUCCESS
== vtoy_json_get_int(pNode
->pstChild
, "autosel", &autosel
))
656 if (autosel
>= 0 && autosel
<= pathnum
)
658 grub_printf("autosel: %d [OK]\n", autosel
);
662 grub_printf("autosel: %d [FAIL]\n", autosel
);
668 grub_printf("parent: %s [FAIL]\n", iso
);
673 grub_printf("image not found\n");
680 static int ventoy_plugin_auto_install_entry(VTOY_JSON
*json
, const char *isodisk
)
685 const char *iso
= NULL
;
686 VTOY_JSON
*pNode
= NULL
;
687 install_template
*node
= NULL
;
688 install_template
*next
= NULL
;
689 file_fullpath
*templatepath
= NULL
;
691 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
693 debug("Not array %d\n", json
->enDataType
);
697 if (g_install_template_head
)
699 for (node
= g_install_template_head
; node
; node
= next
)
702 grub_check_free(node
->templatepath
);
706 g_install_template_head
= NULL
;
709 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
711 type
= auto_install_type_file
;
712 iso
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
715 type
= auto_install_type_parent
;
716 iso
= vtoy_json_get_string_ex(pNode
->pstChild
, "parent");
719 if (iso
&& iso
[0] == '/')
721 if (0 == ventoy_plugin_parse_fullpath(pNode
->pstChild
, isodisk
, "template", &templatepath
, &pathnum
))
723 node
= grub_zalloc(sizeof(install_template
));
727 node
->pathlen
= grub_snprintf(node
->isopath
, sizeof(node
->isopath
), "%s", iso
);
728 node
->templatepath
= templatepath
;
729 node
->templatenum
= pathnum
;
732 if (JSON_SUCCESS
== vtoy_json_get_int(pNode
->pstChild
, "autosel", &autosel
))
734 if (autosel
>= 0 && autosel
<= pathnum
)
736 node
->autosel
= autosel
;
740 if (g_install_template_head
)
742 node
->next
= g_install_template_head
;
745 g_install_template_head
= node
;
754 static int ventoy_plugin_dud_check(VTOY_JSON
*json
, const char *isodisk
)
758 const char *iso
= NULL
;
759 VTOY_JSON
*pNode
= NULL
;
761 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
763 grub_printf("Not array type %d\n", json
->enDataType
);
767 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
769 if (pNode
->enDataType
!= JSON_TYPE_OBJECT
)
771 grub_printf("NOT object type\n");
774 iso
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
777 pos
= grub_strchr(iso
, '*');
778 if (pos
|| 0 == ventoy_plugin_check_path(isodisk
, iso
))
780 grub_printf("image: %s [%s]\n", iso
, (pos
? "*" : "OK"));
781 ventoy_plugin_check_fullpath(pNode
->pstChild
, isodisk
, "dud", &pathnum
);
785 grub_printf("image: %s [FAIL]\n", iso
);
790 grub_printf("image not found\n");
797 static int ventoy_plugin_dud_entry(VTOY_JSON
*json
, const char *isodisk
)
800 const char *iso
= NULL
;
801 VTOY_JSON
*pNode
= NULL
;
804 file_fullpath
*dudpath
= NULL
;
806 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
808 debug("Not array %d\n", json
->enDataType
);
814 for (node
= g_dud_head
; node
; node
= next
)
817 grub_check_free(node
->dudpath
);
824 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
826 iso
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
827 if (iso
&& iso
[0] == '/')
829 if (0 == ventoy_plugin_parse_fullpath(pNode
->pstChild
, isodisk
, "dud", &dudpath
, &pathnum
))
831 node
= grub_zalloc(sizeof(dud
));
834 node
->pathlen
= grub_snprintf(node
->isopath
, sizeof(node
->isopath
), "%s", iso
);
835 node
->dudpath
= dudpath
;
836 node
->dudnum
= pathnum
;
837 node
->files
= grub_zalloc(sizeof(dudfile
) * pathnum
);
843 node
->next
= g_dud_head
;
860 static int ventoy_plugin_parse_pwdstr(char *pwdstr
, vtoy_password
*pwd
)
867 vtoy_password tmpPwd
;
869 len
= (int)grub_strlen(pwdstr
);
872 if (NULL
== pwd
) grub_printf("Password too long %d\n", len
);
876 grub_memset(&tmpPwd
, 0, sizeof(tmpPwd
));
878 if (grub_strncmp(pwdstr
, "txt#", 4) == 0)
880 tmpPwd
.type
= VTOY_PASSWORD_TXT
;
881 grub_snprintf(tmpPwd
.text
, sizeof(tmpPwd
.text
), "%s", pwdstr
+ 4);
883 else if (grub_strncmp(pwdstr
, "md5#", 4) == 0)
887 for (i
= 0; i
< 16; i
++)
889 bytes
[0] = pwdstr
[4 + i
* 2];
890 bytes
[1] = pwdstr
[4 + i
* 2 + 1];
893 if (grub_isxdigit(bytes
[0]) && grub_isxdigit(bytes
[1]))
895 tmpPwd
.md5
[i
] = (grub_uint8_t
)grub_strtoul(bytes
, NULL
, 16);
899 if (NULL
== pwd
) grub_printf("Invalid md5 hex format %s %d\n", pwdstr
, i
);
903 tmpPwd
.type
= VTOY_PASSWORD_MD5
;
905 else if ((len
- 4) > 32)
907 pos
= grub_strchr(pwdstr
+ 4, '#');
910 if (NULL
== pwd
) grub_printf("Invalid md5 password format %s\n", pwdstr
);
914 if (len
- 1 - (int)(long)(pos
- pwdstr
) != 32)
916 if (NULL
== pwd
) grub_printf("Invalid md5 salt password format %s\n", pwdstr
);
922 grub_snprintf(tmpPwd
.salt
, sizeof(tmpPwd
.salt
), "%s", pwdstr
+ 4);
926 for (i
= 0; i
< 16; i
++)
928 bytes
[0] = pos
[i
* 2];
929 bytes
[1] = pos
[i
* 2 + 1];
932 if (grub_isxdigit(bytes
[0]) && grub_isxdigit(bytes
[1]))
934 tmpPwd
.md5
[i
] = (grub_uint8_t
)grub_strtoul(bytes
, NULL
, 16);
938 if (NULL
== pwd
) grub_printf("Invalid md5 hex format %s %d\n", pwdstr
, i
);
943 tmpPwd
.type
= VTOY_PASSWORD_SALT_MD5
;
947 if (NULL
== pwd
) grub_printf("Invalid md5 password format %s\n", pwdstr
);
953 if (NULL
== pwd
) grub_printf("Invalid password format %s\n", pwdstr
);
959 grub_memcpy(pwd
, &tmpPwd
, sizeof(tmpPwd
));
965 static int ventoy_plugin_get_pwd_type(const char *pwd
)
970 for (i
= 0; pwd
&& i
< (int)ARRAY_SIZE(g_menu_prefix
); i
++)
972 grub_snprintf(pwdtype
, sizeof(pwdtype
), "%spwd", g_menu_prefix
[i
]);
973 if (grub_strcmp(pwdtype
, pwd
) == 0)
975 return img_type_start
+ i
;
982 static int ventoy_plugin_pwd_entry(VTOY_JSON
*json
, const char *isodisk
)
985 const char *iso
= NULL
;
986 const char *pwd
= NULL
;
987 VTOY_JSON
*pNode
= NULL
;
988 VTOY_JSON
*pCNode
= NULL
;
989 menu_password
*node
= NULL
;
990 menu_password
*tail
= NULL
;
991 menu_password
*next
= NULL
;
995 if (json
->enDataType
!= JSON_TYPE_OBJECT
)
997 debug("Not object %d\n", json
->enDataType
);
1003 for (node
= g_pwd_head
; node
; node
= next
)
1012 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
1014 if (pNode
->pcName
&& grub_strcmp("bootpwd", pNode
->pcName
) == 0)
1016 ventoy_plugin_parse_pwdstr(pNode
->unData
.pcStrVal
, &g_boot_pwd
);
1018 else if ((type
= ventoy_plugin_get_pwd_type(pNode
->pcName
)) >= 0)
1020 ventoy_plugin_parse_pwdstr(pNode
->unData
.pcStrVal
, g_file_type_pwd
+ type
);
1022 else if (pNode
->pcName
&& grub_strcmp("menupwd", pNode
->pcName
) == 0)
1024 for (pCNode
= pNode
->pstChild
; pCNode
; pCNode
= pCNode
->pstNext
)
1026 if (pCNode
->enDataType
!= JSON_TYPE_OBJECT
)
1031 type
= vtoy_menu_pwd_file
;
1032 iso
= vtoy_json_get_string_ex(pCNode
->pstChild
, "file");
1035 type
= vtoy_menu_pwd_parent
;
1036 iso
= vtoy_json_get_string_ex(pCNode
->pstChild
, "parent");
1039 pwd
= vtoy_json_get_string_ex(pCNode
->pstChild
, "pwd");
1040 if (iso
&& pwd
&& iso
[0] == '/')
1042 node
= grub_zalloc(sizeof(menu_password
));
1046 node
->pathlen
= grub_snprintf(node
->isopath
, sizeof(node
->isopath
), "%s", iso
);
1048 if (ventoy_plugin_parse_pwdstr((char *)pwd
, &(node
->password
)))
1072 static int ventoy_plugin_pwd_check(VTOY_JSON
*json
, const char *isodisk
)
1076 const char *iso
= NULL
;
1077 const char *pwd
= NULL
;
1078 VTOY_JSON
*pNode
= NULL
;
1079 VTOY_JSON
*pCNode
= NULL
;
1081 if (json
->enDataType
!= JSON_TYPE_OBJECT
)
1083 grub_printf("Not object %d\n", json
->enDataType
);
1087 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
1089 if (pNode
->pcName
&& grub_strcmp("bootpwd", pNode
->pcName
) == 0)
1091 if (0 == ventoy_plugin_parse_pwdstr(pNode
->unData
.pcStrVal
, NULL
))
1093 grub_printf("bootpwd:<%s>\n", pNode
->unData
.pcStrVal
);
1097 grub_printf("Invalid bootpwd.\n");
1100 else if ((type
= ventoy_plugin_get_pwd_type(pNode
->pcName
)) >= 0)
1102 if (0 == ventoy_plugin_parse_pwdstr(pNode
->unData
.pcStrVal
, NULL
))
1104 grub_printf("%s:<%s>\n", pNode
->pcName
, pNode
->unData
.pcStrVal
);
1108 grub_printf("Invalid pwd <%s>\n", pNode
->unData
.pcStrVal
);
1111 else if (pNode
->pcName
&& grub_strcmp("menupwd", pNode
->pcName
) == 0)
1114 for (pCNode
= pNode
->pstChild
; pCNode
; pCNode
= pCNode
->pstNext
)
1116 if (pCNode
->enDataType
!= JSON_TYPE_OBJECT
)
1118 grub_printf("Not object %d\n", pCNode
->enDataType
);
1122 if ((iso
= vtoy_json_get_string_ex(pCNode
->pstChild
, "file")) != NULL
)
1124 pos
= grub_strchr(iso
, '*');
1125 if (pos
|| 0 == ventoy_plugin_check_path(isodisk
, iso
))
1127 pwd
= vtoy_json_get_string_ex(pCNode
->pstChild
, "pwd");
1129 if (0 == ventoy_plugin_parse_pwdstr((char *)pwd
, NULL
))
1131 grub_printf("file:<%s> [%s]\n", iso
, (pos
? "*" : "OK"));
1132 grub_printf("pwd:<%s>\n\n", pwd
);
1136 grub_printf("Invalid password for <%s>\n", iso
);
1141 grub_printf("<%s%s> not found\n", isodisk
, iso
);
1144 else if ((iso
= vtoy_json_get_string_ex(pCNode
->pstChild
, "parent")) != NULL
)
1146 if (ventoy_is_dir_exist("%s%s", isodisk
, iso
))
1148 pwd
= vtoy_json_get_string_ex(pCNode
->pstChild
, "pwd");
1149 if (0 == ventoy_plugin_parse_pwdstr((char *)pwd
, NULL
))
1151 grub_printf("dir:<%s> [%s]\n", iso
, (pos
? "*" : "OK"));
1152 grub_printf("pwd:<%s>\n\n", pwd
);
1156 grub_printf("Invalid password for <%s>\n", iso
);
1161 grub_printf("<%s%s> not found\n", isodisk
, iso
);
1166 grub_printf("No file item found in json.\n");
1175 static int ventoy_plugin_persistence_check(VTOY_JSON
*json
, const char *isodisk
)
1180 const char *iso
= NULL
;
1181 VTOY_JSON
*pNode
= NULL
;
1183 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
1185 grub_printf("Not array type %d\n", json
->enDataType
);
1189 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
1191 if (pNode
->enDataType
!= JSON_TYPE_OBJECT
)
1193 grub_printf("NOT object type\n");
1196 iso
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
1199 pos
= grub_strchr(iso
, '*');
1200 if (pos
|| 0 == ventoy_plugin_check_path(isodisk
, iso
))
1202 grub_printf("image: %s [%s]\n", iso
, (pos
? "*" : "OK"));
1203 ventoy_plugin_check_fullpath(pNode
->pstChild
, isodisk
, "backend", &pathnum
);
1205 if (JSON_SUCCESS
== vtoy_json_get_int(pNode
->pstChild
, "autosel", &autosel
))
1207 if (autosel
>= 0 && autosel
<= pathnum
)
1209 grub_printf("autosel: %d [OK]\n", autosel
);
1213 grub_printf("autosel: %d [FAIL]\n", autosel
);
1219 grub_printf("image: %s [FAIL]\n", iso
);
1224 grub_printf("image not found\n");
1231 static int ventoy_plugin_persistence_entry(VTOY_JSON
*json
, const char *isodisk
)
1235 const char *iso
= NULL
;
1236 VTOY_JSON
*pNode
= NULL
;
1237 persistence_config
*node
= NULL
;
1238 persistence_config
*next
= NULL
;
1239 file_fullpath
*backendpath
= NULL
;
1243 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
1245 debug("Not array %d\n", json
->enDataType
);
1249 if (g_persistence_head
)
1251 for (node
= g_persistence_head
; node
; node
= next
)
1254 grub_check_free(node
->backendpath
);
1258 g_persistence_head
= NULL
;
1261 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
1263 iso
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
1264 if (iso
&& iso
[0] == '/')
1266 if (0 == ventoy_plugin_parse_fullpath(pNode
->pstChild
, isodisk
, "backend", &backendpath
, &pathnum
))
1268 node
= grub_zalloc(sizeof(persistence_config
));
1271 node
->pathlen
= grub_snprintf(node
->isopath
, sizeof(node
->isopath
), "%s", iso
);
1272 node
->backendpath
= backendpath
;
1273 node
->backendnum
= pathnum
;
1276 if (JSON_SUCCESS
== vtoy_json_get_int(pNode
->pstChild
, "autosel", &autosel
))
1278 if (autosel
>= 0 && autosel
<= pathnum
)
1280 node
->autosel
= autosel
;
1284 if (g_persistence_head
)
1286 node
->next
= g_persistence_head
;
1289 g_persistence_head
= node
;
1298 static int ventoy_plugin_menualias_check(VTOY_JSON
*json
, const char *isodisk
)
1301 const char *path
= NULL
;
1302 const char *alias
= NULL
;
1303 VTOY_JSON
*pNode
= NULL
;
1307 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
1309 grub_printf("Not array %d\n", json
->enDataType
);
1313 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
1315 type
= vtoy_alias_image_file
;
1316 path
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
1319 path
= vtoy_json_get_string_ex(pNode
->pstChild
, "dir");
1320 type
= vtoy_alias_directory
;
1323 alias
= vtoy_json_get_string_ex(pNode
->pstChild
, "alias");
1324 if (path
&& path
[0] == '/' && alias
)
1326 if (vtoy_alias_image_file
== type
)
1328 if (grub_strchr(path
, '*'))
1330 grub_printf("image: <%s> [ * ]\n", path
);
1332 else if (ventoy_is_file_exist("%s%s", isodisk
, path
))
1334 grub_printf("image: <%s> [ OK ]\n", path
);
1338 grub_printf("image: <%s> [ NOT EXIST ]\n", path
);
1343 if (ventoy_is_dir_exist("%s%s", isodisk
, path
))
1345 grub_printf("dir: <%s> [ OK ]\n", path
);
1349 grub_printf("dir: <%s> [ NOT EXIST ]\n", path
);
1353 grub_printf("alias: <%s>\n\n", alias
);
1360 static int ventoy_plugin_menualias_entry(VTOY_JSON
*json
, const char *isodisk
)
1363 const char *path
= NULL
;
1364 const char *alias
= NULL
;
1365 VTOY_JSON
*pNode
= NULL
;
1366 menu_alias
*node
= NULL
;
1367 menu_alias
*next
= NULL
;
1371 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
1373 debug("Not array %d\n", json
->enDataType
);
1377 if (g_menu_alias_head
)
1379 for (node
= g_menu_alias_head
; node
; node
= next
)
1385 g_menu_alias_head
= NULL
;
1388 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
1390 type
= vtoy_alias_image_file
;
1391 path
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
1394 path
= vtoy_json_get_string_ex(pNode
->pstChild
, "dir");
1395 type
= vtoy_alias_directory
;
1398 alias
= vtoy_json_get_string_ex(pNode
->pstChild
, "alias");
1399 if (path
&& path
[0] == '/' && alias
)
1401 node
= grub_zalloc(sizeof(menu_alias
));
1405 node
->pathlen
= grub_snprintf(node
->isopath
, sizeof(node
->isopath
), "%s", path
);
1406 grub_snprintf(node
->alias
, sizeof(node
->alias
), "%s", alias
);
1408 if (g_menu_alias_head
)
1410 node
->next
= g_menu_alias_head
;
1413 g_menu_alias_head
= node
;
1421 static int ventoy_plugin_menutip_check(VTOY_JSON
*json
, const char *isodisk
)
1423 const char *path
= NULL
;
1424 const char *tip
= NULL
;
1425 VTOY_JSON
*pNode
= NULL
;
1429 if (json
->enDataType
!= JSON_TYPE_OBJECT
)
1431 grub_printf("Not object %d\n", json
->enDataType
);
1435 tip
= vtoy_json_get_string_ex(json
->pstChild
, "left");
1438 grub_printf("left: <%s>\n", tip
);
1441 tip
= vtoy_json_get_string_ex(json
->pstChild
, "top");
1444 grub_printf("top: <%s>\n", tip
);
1447 tip
= vtoy_json_get_string_ex(json
->pstChild
, "color");
1450 grub_printf("color: <%s>\n", tip
);
1453 pNode
= vtoy_json_find_item(json
->pstChild
, JSON_TYPE_ARRAY
, "tips");
1454 for (pNode
= pNode
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
1456 path
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
1457 if (path
&& path
[0] == '/')
1459 if (grub_strchr(path
, '*'))
1461 grub_printf("image: <%s> [ * ]\n", path
);
1463 else if (ventoy_check_file_exist("%s%s", isodisk
, path
))
1465 grub_printf("image: <%s> [ OK ]\n", path
);
1469 grub_printf("image: <%s> [ NOT EXIST ]\n", path
);
1472 tip
= vtoy_json_get_string_ex(pNode
->pstChild
, "tip");
1475 grub_printf("tip: <%s>\n", tip
);
1479 tip
= vtoy_json_get_string_ex(pNode
->pstChild
, "tip1");
1481 grub_printf("tip1: <%s>\n", tip
);
1483 grub_printf("tip1: <NULL>\n");
1485 tip
= vtoy_json_get_string_ex(pNode
->pstChild
, "tip2");
1487 grub_printf("tip2: <%s>\n", tip
);
1489 grub_printf("tip2: <NULL>\n");
1494 grub_printf("image: <%s> [ INVALID ]\n", path
);
1501 static int ventoy_plugin_menutip_entry(VTOY_JSON
*json
, const char *isodisk
)
1503 const char *path
= NULL
;
1504 const char *tip
= NULL
;
1505 VTOY_JSON
*pNode
= NULL
;
1506 menu_tip
*node
= NULL
;
1507 menu_tip
*next
= NULL
;
1511 if (json
->enDataType
!= JSON_TYPE_OBJECT
)
1513 debug("Not object %d\n", json
->enDataType
);
1517 pNode
= vtoy_json_find_item(json
->pstChild
, JSON_TYPE_ARRAY
, "tips");
1520 debug("Not tips found\n");
1524 if (g_menu_tip_head
)
1526 for (node
= g_menu_tip_head
; node
; node
= next
)
1532 g_menu_tip_head
= NULL
;
1535 tip
= vtoy_json_get_string_ex(json
->pstChild
, "left");
1538 grub_env_set("VTOY_TIP_LEFT", tip
);
1541 tip
= vtoy_json_get_string_ex(json
->pstChild
, "top");
1544 grub_env_set("VTOY_TIP_TOP", tip
);
1547 tip
= vtoy_json_get_string_ex(json
->pstChild
, "color");
1550 grub_env_set("VTOY_TIP_COLOR", tip
);
1553 for (pNode
= pNode
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
1555 path
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
1556 if (path
&& path
[0] == '/')
1558 node
= grub_zalloc(sizeof(menu_tip
));
1561 node
->pathlen
= grub_snprintf(node
->isopath
, sizeof(node
->isopath
), "%s", path
);
1563 tip
= vtoy_json_get_string_ex(pNode
->pstChild
, "tip");
1566 grub_snprintf(node
->tip1
, 1000, "%s", tip
);
1570 tip
= vtoy_json_get_string_ex(pNode
->pstChild
, "tip1");
1572 grub_snprintf(node
->tip1
, 1000, "%s", tip
);
1574 tip
= vtoy_json_get_string_ex(pNode
->pstChild
, "tip2");
1576 grub_snprintf(node
->tip2
, 1000, "%s", tip
);
1579 if (g_menu_tip_head
)
1581 node
->next
= g_menu_tip_head
;
1584 g_menu_tip_head
= node
;
1592 static int ventoy_plugin_injection_check(VTOY_JSON
*json
, const char *isodisk
)
1595 const char *path
= NULL
;
1596 const char *archive
= NULL
;
1597 VTOY_JSON
*pNode
= NULL
;
1601 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
1603 grub_printf("Not array %d\n", json
->enDataType
);
1607 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
1609 type
= injection_type_file
;
1610 path
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
1613 type
= injection_type_parent
;
1614 path
= vtoy_json_get_string_ex(pNode
->pstChild
, "parent");
1617 grub_printf("image/parent not found\n");
1622 archive
= vtoy_json_get_string_ex(pNode
->pstChild
, "archive");
1625 grub_printf("archive not found\n");
1629 if (type
== injection_type_file
)
1631 if (grub_strchr(path
, '*'))
1633 grub_printf("image: <%s> [*]\n", path
);
1637 grub_printf("image: <%s> [%s]\n", path
, ventoy_check_file_exist("%s%s", isodisk
, path
) ? "OK" : "NOT EXIST");
1642 grub_printf("parent: <%s> [%s]\n", path
,
1643 ventoy_is_dir_exist("%s%s", isodisk
, path
) ? "OK" : "NOT EXIST");
1646 grub_printf("archive: <%s> [%s]\n\n", archive
, ventoy_check_file_exist("%s%s", isodisk
, archive
) ? "OK" : "NOT EXIST");
1652 static int ventoy_plugin_injection_entry(VTOY_JSON
*json
, const char *isodisk
)
1655 const char *path
= NULL
;
1656 const char *archive
= NULL
;
1657 VTOY_JSON
*pNode
= NULL
;
1658 injection_config
*node
= NULL
;
1659 injection_config
*next
= NULL
;
1663 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
1665 debug("Not array %d\n", json
->enDataType
);
1669 if (g_injection_head
)
1671 for (node
= g_injection_head
; node
; node
= next
)
1677 g_injection_head
= NULL
;
1680 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
1682 type
= injection_type_file
;
1683 path
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
1686 type
= injection_type_parent
;
1687 path
= vtoy_json_get_string_ex(pNode
->pstChild
, "parent");
1690 archive
= vtoy_json_get_string_ex(pNode
->pstChild
, "archive");
1691 if (path
&& path
[0] == '/' && archive
&& archive
[0] == '/')
1693 node
= grub_zalloc(sizeof(injection_config
));
1697 node
->pathlen
= grub_snprintf(node
->isopath
, sizeof(node
->isopath
), "%s", path
);
1698 grub_snprintf(node
->archive
, sizeof(node
->archive
), "%s", archive
);
1700 if (g_injection_head
)
1702 node
->next
= g_injection_head
;
1705 g_injection_head
= node
;
1713 static int ventoy_plugin_menuclass_entry(VTOY_JSON
*json
, const char *isodisk
)
1717 const char *key
= NULL
;
1718 const char *class = NULL
;
1719 VTOY_JSON
*pNode
= NULL
;
1720 menu_class
*tail
= NULL
;
1721 menu_class
*node
= NULL
;
1722 menu_class
*next
= NULL
;
1726 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
1728 debug("Not array %d\n", json
->enDataType
);
1732 if (g_menu_class_head
)
1734 for (node
= g_menu_class_head
; node
; node
= next
)
1740 g_menu_class_head
= NULL
;
1743 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
1746 type
= vtoy_class_image_file
;
1747 key
= vtoy_json_get_string_ex(pNode
->pstChild
, "key");
1750 key
= vtoy_json_get_string_ex(pNode
->pstChild
, "parent");
1757 key
= vtoy_json_get_string_ex(pNode
->pstChild
, "dir");
1758 type
= vtoy_class_directory
;
1762 class = vtoy_json_get_string_ex(pNode
->pstChild
, "class");
1765 node
= grub_zalloc(sizeof(menu_class
));
1769 node
->parent
= parent
;
1770 node
->patlen
= grub_snprintf(node
->pattern
, sizeof(node
->pattern
), "%s", key
);
1771 grub_snprintf(node
->class, sizeof(node
->class), "%s", class);
1773 if (g_menu_class_head
)
1779 g_menu_class_head
= node
;
1789 static int ventoy_plugin_menuclass_check(VTOY_JSON
*json
, const char *isodisk
)
1791 const char *name
= NULL
;
1792 const char *key
= NULL
;
1793 const char *class = NULL
;
1794 VTOY_JSON
*pNode
= NULL
;
1798 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
1800 grub_printf("Not array %d\n", json
->enDataType
);
1804 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
1807 key
= vtoy_json_get_string_ex(pNode
->pstChild
, "key");
1811 key
= vtoy_json_get_string_ex(pNode
->pstChild
, "parent");
1815 key
= vtoy_json_get_string_ex(pNode
->pstChild
, "dir");
1819 class = vtoy_json_get_string_ex(pNode
->pstChild
, "class");
1822 grub_printf("%s: <%s>\n", name
, key
);
1823 grub_printf("class: <%s>\n\n", class);
1830 static int ventoy_plugin_custom_boot_entry(VTOY_JSON
*json
, const char *isodisk
)
1834 const char *key
= NULL
;
1835 const char *cfg
= NULL
;
1836 VTOY_JSON
*pNode
= NULL
;
1837 custom_boot
*tail
= NULL
;
1838 custom_boot
*node
= NULL
;
1839 custom_boot
*next
= NULL
;
1843 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
1845 debug("Not array %d\n", json
->enDataType
);
1849 if (g_custom_boot_head
)
1851 for (node
= g_custom_boot_head
; node
; node
= next
)
1857 g_custom_boot_head
= NULL
;
1860 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
1862 type
= vtoy_custom_boot_image_file
;
1863 key
= vtoy_json_get_string_ex(pNode
->pstChild
, "file");
1866 key
= vtoy_json_get_string_ex(pNode
->pstChild
, "dir");
1867 type
= vtoy_custom_boot_directory
;
1870 cfg
= vtoy_json_get_string_ex(pNode
->pstChild
, "vcfg");
1873 node
= grub_zalloc(sizeof(custom_boot
));
1877 node
->pathlen
= grub_snprintf(node
->path
, sizeof(node
->path
), "%s", key
);
1878 len
= (int)grub_snprintf(node
->cfg
, sizeof(node
->cfg
), "%s", cfg
);
1880 if (len
>= 5 && grub_strncmp(node
->cfg
+ len
- 5, ".vcfg", 5) == 0)
1882 if (g_custom_boot_head
)
1888 g_custom_boot_head
= node
;
1903 static int ventoy_plugin_custom_boot_check(VTOY_JSON
*json
, const char *isodisk
)
1907 const char *key
= NULL
;
1908 const char *cfg
= NULL
;
1909 VTOY_JSON
*pNode
= NULL
;
1913 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
1915 grub_printf("Not array %d\n", json
->enDataType
);
1919 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
1921 type
= vtoy_custom_boot_image_file
;
1922 key
= vtoy_json_get_string_ex(pNode
->pstChild
, "file");
1925 key
= vtoy_json_get_string_ex(pNode
->pstChild
, "dir");
1926 type
= vtoy_custom_boot_directory
;
1929 cfg
= vtoy_json_get_string_ex(pNode
->pstChild
, "vcfg");
1930 len
= (int)grub_strlen(cfg
);
1933 if (len
< 5 || grub_strncmp(cfg
+ len
- 5, ".vcfg", 5))
1935 grub_printf("<%s> does not have \".vcfg\" suffix\n\n", cfg
);
1939 grub_printf("%s: <%s>\n", (type
== vtoy_custom_boot_directory
) ? "dir" : "file", key
);
1940 grub_printf("vcfg: <%s>\n\n", cfg
);
1948 static int ventoy_plugin_conf_replace_entry(VTOY_JSON
*json
, const char *isodisk
)
1950 const char *isof
= NULL
;
1951 const char *orgf
= NULL
;
1952 const char *newf
= NULL
;
1953 VTOY_JSON
*pNode
= NULL
;
1954 conf_replace
*tail
= NULL
;
1955 conf_replace
*node
= NULL
;
1956 conf_replace
*next
= NULL
;
1960 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
1962 debug("Not array %d\n", json
->enDataType
);
1966 if (g_conf_replace_head
)
1968 for (node
= g_conf_replace_head
; node
; node
= next
)
1974 g_conf_replace_head
= NULL
;
1977 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
1979 isof
= vtoy_json_get_string_ex(pNode
->pstChild
, "iso");
1980 orgf
= vtoy_json_get_string_ex(pNode
->pstChild
, "org");
1981 newf
= vtoy_json_get_string_ex(pNode
->pstChild
, "new");
1982 if (isof
&& orgf
&& newf
&& isof
[0] == '/' && orgf
[0] == '/' && newf
[0] == '/')
1984 node
= grub_zalloc(sizeof(conf_replace
));
1987 node
->pathlen
= grub_snprintf(node
->isopath
, sizeof(node
->isopath
), "%s", isof
);
1988 grub_snprintf(node
->orgconf
, sizeof(node
->orgconf
), "%s", orgf
);
1989 grub_snprintf(node
->newconf
, sizeof(node
->newconf
), "%s", newf
);
1991 if (g_conf_replace_head
)
1997 g_conf_replace_head
= node
;
2007 static int ventoy_plugin_conf_replace_check(VTOY_JSON
*json
, const char *isodisk
)
2009 const char *isof
= NULL
;
2010 const char *orgf
= NULL
;
2011 const char *newf
= NULL
;
2012 VTOY_JSON
*pNode
= NULL
;
2013 grub_file_t file
= NULL
;
2018 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
2020 grub_printf("Not array %d\n", json
->enDataType
);
2024 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
2026 isof
= vtoy_json_get_string_ex(pNode
->pstChild
, "iso");
2027 orgf
= vtoy_json_get_string_ex(pNode
->pstChild
, "org");
2028 newf
= vtoy_json_get_string_ex(pNode
->pstChild
, "new");
2029 if (isof
&& orgf
&& newf
&& isof
[0] == '/' && orgf
[0] == '/' && newf
[0] == '/')
2031 if (ventoy_check_file_exist("%s%s", isodisk
, isof
))
2033 grub_printf("iso:<%s> [OK]\n", isof
);
2035 grub_snprintf(cmd
, sizeof(cmd
), "loopback vtisocheck \"%s%s\"", isodisk
, isof
);
2036 grub_script_execute_sourcecode(cmd
);
2038 file
= ventoy_grub_file_open(VENTOY_FILE_TYPE
, "(vtisocheck)/%s", orgf
);
2041 if (grub_strcmp(file
->fs
->name
, "iso9660") == 0)
2043 grub_printf("org:<%s> [OK]\n", orgf
);
2047 grub_printf("org:<%s> [Exist But NOT ISO9660]\n", orgf
);
2049 grub_file_close(file
);
2053 grub_printf("org:<%s> [NOT Exist]\n", orgf
);
2056 grub_script_execute_sourcecode("loopback -d vtisocheck");
2058 else if (grub_strchr(isof
, '*'))
2060 grub_printf("iso:<%s> [*]\n", isof
);
2061 grub_printf("org:<%s>\n", orgf
);
2065 grub_printf("iso:<%s> [NOT Exist]\n", isof
);
2066 grub_printf("org:<%s>\n", orgf
);
2069 file
= ventoy_grub_file_open(VENTOY_FILE_TYPE
, "%s%s", isodisk
, newf
);
2072 if (file
->size
> vtoy_max_replace_file_size
)
2074 grub_printf("new:<%s> [Too Big %lu] \n", newf
, (ulong
)file
->size
);
2078 grub_printf("new:<%s> [OK]\n", newf
);
2080 grub_file_close(file
);
2084 grub_printf("new:<%s> [NOT Exist]\n", newf
);
2093 static int ventoy_plugin_auto_memdisk_entry(VTOY_JSON
*json
, const char *isodisk
)
2095 VTOY_JSON
*pNode
= NULL
;
2096 auto_memdisk
*node
= NULL
;
2097 auto_memdisk
*next
= NULL
;
2101 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
2103 debug("Not array %d\n", json
->enDataType
);
2107 if (g_auto_memdisk_head
)
2109 for (node
= g_auto_memdisk_head
; node
; node
= next
)
2115 g_auto_memdisk_head
= NULL
;
2118 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
2120 if (pNode
->enDataType
== JSON_TYPE_STRING
)
2122 node
= grub_zalloc(sizeof(auto_memdisk
));
2125 node
->pathlen
= grub_snprintf(node
->isopath
, sizeof(node
->isopath
), "%s", pNode
->unData
.pcStrVal
);
2127 if (g_auto_memdisk_head
)
2129 node
->next
= g_auto_memdisk_head
;
2132 g_auto_memdisk_head
= node
;
2140 static int ventoy_plugin_auto_memdisk_check(VTOY_JSON
*json
, const char *isodisk
)
2142 VTOY_JSON
*pNode
= NULL
;
2144 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
2146 grub_printf("Not array %d\n", json
->enDataType
);
2150 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
2152 if (pNode
->enDataType
== JSON_TYPE_STRING
)
2154 grub_printf("<%s> ", pNode
->unData
.pcStrVal
);
2156 if (grub_strchr(pNode
->unData
.pcStrVal
, '*'))
2158 grub_printf(" [*]\n");
2160 else if (ventoy_check_file_exist("%s%s", isodisk
, pNode
->unData
.pcStrVal
))
2162 grub_printf(" [OK]\n");
2166 grub_printf(" [NOT EXIST]\n");
2174 static int ventoy_plugin_image_list_entry(VTOY_JSON
*json
, const char *isodisk
)
2176 VTOY_JSON
*pNode
= NULL
;
2177 image_list
*node
= NULL
;
2178 image_list
*next
= NULL
;
2179 image_list
*tail
= NULL
;
2183 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
2185 debug("Not array %d\n", json
->enDataType
);
2189 if (g_image_list_head
)
2191 for (node
= g_image_list_head
; node
; node
= next
)
2197 g_image_list_head
= NULL
;
2200 if (grub_strncmp(json
->pcName
, "image_blacklist", 15) == 0)
2202 g_plugin_image_list
= VENTOY_IMG_BLACK_LIST
;
2206 g_plugin_image_list
= VENTOY_IMG_WHITE_LIST
;
2209 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
2211 if (pNode
->enDataType
== JSON_TYPE_STRING
)
2213 node
= grub_zalloc(sizeof(image_list
));
2216 node
->pathlen
= grub_snprintf(node
->isopath
, sizeof(node
->isopath
), "%s", pNode
->unData
.pcStrVal
);
2218 if (g_image_list_head
)
2224 g_image_list_head
= node
;
2234 static int ventoy_plugin_image_list_check(VTOY_JSON
*json
, const char *isodisk
)
2236 VTOY_JSON
*pNode
= NULL
;
2238 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
2240 grub_printf("Not array %d\n", json
->enDataType
);
2244 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
2246 if (pNode
->enDataType
== JSON_TYPE_STRING
)
2248 grub_printf("<%s> ", pNode
->unData
.pcStrVal
);
2250 if (grub_strchr(pNode
->unData
.pcStrVal
, '*'))
2252 grub_printf(" [*]\n");
2254 else if (ventoy_check_file_exist("%s%s", isodisk
, pNode
->unData
.pcStrVal
))
2256 grub_printf(" [OK]\n");
2260 grub_printf(" [NOT EXIST]\n");
2268 static plugin_entry g_plugin_entries
[] =
2270 { "control", ventoy_plugin_control_entry
, ventoy_plugin_control_check
},
2271 { "theme", ventoy_plugin_theme_entry
, ventoy_plugin_theme_check
},
2272 { "auto_install", ventoy_plugin_auto_install_entry
, ventoy_plugin_auto_install_check
},
2273 { "persistence", ventoy_plugin_persistence_entry
, ventoy_plugin_persistence_check
},
2274 { "menu_alias", ventoy_plugin_menualias_entry
, ventoy_plugin_menualias_check
},
2275 { "menu_tip", ventoy_plugin_menutip_entry
, ventoy_plugin_menutip_check
},
2276 { "menu_class", ventoy_plugin_menuclass_entry
, ventoy_plugin_menuclass_check
},
2277 { "injection", ventoy_plugin_injection_entry
, ventoy_plugin_injection_check
},
2278 { "auto_memdisk", ventoy_plugin_auto_memdisk_entry
, ventoy_plugin_auto_memdisk_check
},
2279 { "image_list", ventoy_plugin_image_list_entry
, ventoy_plugin_image_list_check
},
2280 { "image_blacklist", ventoy_plugin_image_list_entry
, ventoy_plugin_image_list_check
},
2281 { "conf_replace", ventoy_plugin_conf_replace_entry
, ventoy_plugin_conf_replace_check
},
2282 { "dud", ventoy_plugin_dud_entry
, ventoy_plugin_dud_check
},
2283 { "password", ventoy_plugin_pwd_entry
, ventoy_plugin_pwd_check
},
2284 { "custom_boot", ventoy_plugin_custom_boot_entry
, ventoy_plugin_custom_boot_check
},
2287 static int ventoy_parse_plugin_config(VTOY_JSON
*json
, const char *isodisk
)
2291 VTOY_JSON
*cur
= json
;
2293 grub_snprintf(g_iso_disk_name
, sizeof(g_iso_disk_name
), "%s", isodisk
);
2297 for (i
= 0; i
< (int)ARRAY_SIZE(g_plugin_entries
); i
++)
2299 grub_snprintf(key
, sizeof(key
), "%s_%s", g_plugin_entries
[i
].key
, g_arch_mode_suffix
);
2300 if (grub_strcmp(g_plugin_entries
[i
].key
, cur
->pcName
) == 0 || grub_strcmp(key
, cur
->pcName
) == 0)
2302 debug("Plugin entry for %s\n", g_plugin_entries
[i
].key
);
2303 g_plugin_entries
[i
].entryfunc(cur
, isodisk
);
2314 grub_err_t
ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt
, int argc
, char **args
)
2319 VTOY_JSON
*json
= NULL
;
2324 grub_env_set("VTOY_TIP_LEFT", "10%");
2325 grub_env_set("VTOY_TIP_TOP", "80%+5");
2326 grub_env_set("VTOY_TIP_COLOR", "blue");
2327 grub_env_set("VTOY_TIP_ALIGN", "left");
2329 file
= ventoy_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD
, "%s/ventoy/ventoy.json", args
[0]);
2332 return GRUB_ERR_NONE
;
2335 debug("json configuration file size %d\n", (int)file
->size
);
2337 buf
= grub_malloc(file
->size
+ 1);
2340 grub_file_close(file
);
2344 buf
[file
->size
] = 0;
2345 grub_file_read(file
, buf
, file
->size
);
2346 grub_file_close(file
);
2348 json
= vtoy_json_create();
2356 ret
= vtoy_json_parse(json
, buf
);
2359 grub_env_set("VTOY_PLUGIN_SYNTAX_ERROR", "1");
2360 grub_env_export("VTOY_PLUGIN_SYNTAX_ERROR");
2362 debug("Failed to parse json string %d\n", ret
);
2367 ventoy_parse_plugin_config(json
->pstChild
, args
[0]);
2369 vtoy_json_destroy(json
);
2373 if (g_boot_pwd
.type
)
2375 grub_printf("\n\n======= %s ======\n\n", grub_env_get("VTOY_TEXT_MENU_VER"));
2376 if (ventoy_check_password(&g_boot_pwd
, 3))
2378 grub_printf("\n!!! Password check failed, will exit after 5 seconds. !!!\n");
2385 if (g_menu_tip_head
)
2387 grub_env_set("VTOY_MENU_TIP_ENABLE", "1");
2391 grub_env_unset("VTOY_MENU_TIP_ENABLE");
2394 VENTOY_CMD_RETURN(GRUB_ERR_NONE
);
2397 void ventoy_plugin_dump_injection(void)
2399 injection_config
*node
= NULL
;
2401 for (node
= g_injection_head
; node
; node
= node
->next
)
2403 grub_printf("\n%s:<%s>\n", (node
->type
== injection_type_file
) ? "IMAGE" : "PARENT", node
->isopath
);
2404 grub_printf("ARCHIVE:<%s>\n", node
->archive
);
2411 void ventoy_plugin_dump_auto_install(void)
2414 install_template
*node
= NULL
;
2416 for (node
= g_install_template_head
; node
; node
= node
->next
)
2418 grub_printf("\n%s:<%s> <%d>\n",
2419 (node
->type
== auto_install_type_file
) ? "IMAGE" : "PARENT",
2420 node
->isopath
, node
->templatenum
);
2421 for (i
= 0; i
< node
->templatenum
; i
++)
2423 grub_printf("SCRIPT %d:<%s>\n", i
, node
->templatepath
[i
].path
);
2430 void ventoy_plugin_dump_persistence(void)
2434 persistence_config
*node
= NULL
;
2435 ventoy_img_chunk_list chunk_list
;
2437 for (node
= g_persistence_head
; node
; node
= node
->next
)
2439 grub_printf("\nIMAGE:<%s> <%d>\n", node
->isopath
, node
->backendnum
);
2441 for (i
= 0; i
< node
->backendnum
; i
++)
2443 grub_printf("PERSIST %d:<%s>", i
, node
->backendpath
[i
].path
);
2444 rc
= ventoy_plugin_get_persistent_chunklist(node
->isopath
, i
, &chunk_list
);
2447 grub_printf(" [ SUCCESS ]\n");
2448 grub_free(chunk_list
.chunk
);
2452 grub_printf(" [ FAILED ]\n");
2460 install_template
* ventoy_plugin_find_install_template(const char *isopath
)
2463 install_template
*node
= NULL
;
2465 if (!g_install_template_head
)
2470 len
= (int)grub_strlen(isopath
);
2471 for (node
= g_install_template_head
; node
; node
= node
->next
)
2473 if (node
->type
== auto_install_type_file
)
2475 if (node
->pathlen
== len
&& ventoy_strcmp(node
->isopath
, isopath
) == 0)
2482 for (node
= g_install_template_head
; node
; node
= node
->next
)
2484 if (node
->type
== auto_install_type_parent
)
2486 if (node
->pathlen
< len
&& ventoy_plugin_is_parent(node
->isopath
, node
->pathlen
, isopath
))
2496 char * ventoy_plugin_get_cur_install_template(const char *isopath
)
2498 install_template
*node
= NULL
;
2500 node
= ventoy_plugin_find_install_template(isopath
);
2501 if ((!node
) || (!node
->templatepath
))
2506 if (node
->cursel
< 0 || node
->cursel
>= node
->templatenum
)
2511 return node
->templatepath
[node
->cursel
].path
;
2514 persistence_config
* ventoy_plugin_find_persistent(const char *isopath
)
2517 persistence_config
*node
= NULL
;
2519 if (!g_persistence_head
)
2524 len
= (int)grub_strlen(isopath
);
2525 for (node
= g_persistence_head
; node
; node
= node
->next
)
2527 if ((len
== node
->pathlen
) && (ventoy_strcmp(node
->isopath
, isopath
) == 0))
2536 int ventoy_plugin_get_persistent_chunklist(const char *isopath
, int index
, ventoy_img_chunk_list
*chunk_list
)
2539 grub_uint64_t start
= 0;
2540 grub_file_t file
= NULL
;
2541 persistence_config
*node
= NULL
;
2543 node
= ventoy_plugin_find_persistent(isopath
);
2544 if ((!node
) || (!node
->backendpath
))
2551 index
= node
->cursel
;
2554 if (index
< 0 || index
>= node
->backendnum
)
2559 file
= ventoy_grub_file_open(VENTOY_FILE_TYPE
, "%s%s", g_iso_disk_name
, node
->backendpath
[index
].path
);
2562 debug("Failed to open file %s%s\n", g_iso_disk_name
, node
->backendpath
[index
].path
);
2566 grub_memset(chunk_list
, 0, sizeof(ventoy_img_chunk_list
));
2567 chunk_list
->chunk
= grub_malloc(sizeof(ventoy_img_chunk
) * DEFAULT_CHUNK_NUM
);
2568 if (NULL
== chunk_list
->chunk
)
2573 chunk_list
->max_chunk
= DEFAULT_CHUNK_NUM
;
2574 chunk_list
->cur_chunk
= 0;
2576 start
= file
->device
->disk
->partition
->start
;
2577 ventoy_get_block_list(file
, chunk_list
, start
);
2579 if (0 != ventoy_check_block_list(file
, chunk_list
, start
))
2581 grub_free(chunk_list
->chunk
);
2582 chunk_list
->chunk
= NULL
;
2590 grub_file_close(file
);
2595 const char * ventoy_plugin_get_injection(const char *isopath
)
2598 injection_config
*node
= NULL
;
2600 if (!g_injection_head
)
2605 len
= (int)grub_strlen(isopath
);
2606 for (node
= g_injection_head
; node
; node
= node
->next
)
2608 if (node
->type
== injection_type_file
)
2610 if (node
->pathlen
== len
&& ventoy_strcmp(node
->isopath
, isopath
) == 0)
2612 return node
->archive
;
2617 for (node
= g_injection_head
; node
; node
= node
->next
)
2619 if (node
->type
== injection_type_parent
)
2621 if (node
->pathlen
< len
&& ventoy_plugin_is_parent(node
->isopath
, node
->pathlen
, isopath
))
2623 return node
->archive
;
2631 const char * ventoy_plugin_get_menu_alias(int type
, const char *isopath
)
2634 menu_alias
*node
= NULL
;
2636 if (!g_menu_alias_head
)
2641 len
= (int)grub_strlen(isopath
);
2642 for (node
= g_menu_alias_head
; node
; node
= node
->next
)
2644 if (node
->type
== type
&& node
->pathlen
&&
2645 node
->pathlen
== len
&& ventoy_strcmp(node
->isopath
, isopath
) == 0)
2654 const menu_tip
* ventoy_plugin_get_menu_tip(const char *isopath
)
2657 menu_tip
*node
= NULL
;
2659 if (!g_menu_tip_head
)
2664 len
= (int)grub_strlen(isopath
);
2665 for (node
= g_menu_tip_head
; node
; node
= node
->next
)
2667 if (node
->pathlen
== len
&& ventoy_strcmp(node
->isopath
, isopath
) == 0)
2676 const char * ventoy_plugin_get_menu_class(int type
, const char *name
, const char *path
)
2680 menu_class
*node
= NULL
;
2682 if (!g_menu_class_head
)
2687 namelen
= (int)grub_strlen(name
);
2688 pathlen
= (int)grub_strlen(path
);
2690 if (vtoy_class_image_file
== type
)
2692 for (node
= g_menu_class_head
; node
; node
= node
->next
)
2694 if (node
->type
!= type
)
2699 if (node
->parent
== 0)
2701 if ((node
->patlen
< namelen
) && grub_strstr(name
, node
->pattern
))
2708 for (node
= g_menu_class_head
; node
; node
= node
->next
)
2710 if (node
->type
!= type
)
2717 if ((node
->patlen
< pathlen
) && ventoy_plugin_is_parent(node
->pattern
, node
->patlen
, path
))
2726 for (node
= g_menu_class_head
; node
; node
= node
->next
)
2728 if (node
->type
== type
&& node
->patlen
== namelen
&& grub_strncmp(name
, node
->pattern
, namelen
) == 0)
2738 int ventoy_plugin_add_custom_boot(const char *vcfgpath
)
2741 custom_boot
*node
= NULL
;
2743 node
= grub_zalloc(sizeof(custom_boot
));
2746 node
->type
= vtoy_custom_boot_image_file
;
2747 node
->pathlen
= grub_snprintf(node
->path
, sizeof(node
->path
), "%s", vcfgpath
);
2748 grub_snprintf(node
->cfg
, sizeof(node
->cfg
), "%s", vcfgpath
);
2751 len
= node
->pathlen
- 5;
2752 node
->path
[len
] = 0;
2753 node
->pathlen
= len
;
2755 if (g_custom_boot_head
)
2757 node
->next
= g_custom_boot_head
;
2759 g_custom_boot_head
= node
;
2765 const char * ventoy_plugin_get_custom_boot(const char *isopath
)
2769 custom_boot
*node
= NULL
;
2771 if (!g_custom_boot_head
)
2776 len
= (int)grub_strlen(isopath
);
2778 for (node
= g_custom_boot_head
; node
; node
= node
->next
)
2780 if (node
->type
== vtoy_custom_boot_image_file
)
2782 if (node
->pathlen
== len
&& grub_strncmp(isopath
, node
->path
, len
) == 0)
2789 if (node
->pathlen
< len
&& isopath
[node
->pathlen
] == '/' &&
2790 grub_strncmp(isopath
, node
->path
, node
->pathlen
) == 0)
2792 for (i
= node
->pathlen
+ 1; i
< len
; i
++)
2794 if (isopath
[i
] == '/')
2811 grub_err_t
ventoy_cmd_dump_custom_boot(grub_extcmd_context_t ctxt
, int argc
, char **args
)
2813 custom_boot
*node
= NULL
;
2819 for (node
= g_custom_boot_head
; node
; node
= node
->next
)
2821 grub_printf("[%s] <%s>:<%s>\n", (node
->type
== vtoy_custom_boot_directory
) ? "dir" : "file",
2822 node
->path
, node
->cfg
);
2828 int ventoy_plugin_check_memdisk(const char *isopath
)
2831 auto_memdisk
*node
= NULL
;
2833 if (!g_auto_memdisk_head
)
2838 len
= (int)grub_strlen(isopath
);
2839 for (node
= g_auto_memdisk_head
; node
; node
= node
->next
)
2841 if (node
->pathlen
== len
&& ventoy_strncmp(node
->isopath
, isopath
, len
) == 0)
2850 int ventoy_plugin_get_image_list_index(int type
, const char *name
)
2854 image_list
*node
= NULL
;
2856 if (!g_image_list_head
)
2861 len
= (int)grub_strlen(name
);
2863 for (node
= g_image_list_head
; node
; node
= node
->next
, index
++)
2865 if (vtoy_class_directory
== type
)
2867 if (len
< node
->pathlen
&& ventoy_strncmp(node
->isopath
, name
, len
) == 0)
2874 if (len
== node
->pathlen
&& ventoy_strncmp(node
->isopath
, name
, len
) == 0)
2884 conf_replace
* ventoy_plugin_find_conf_replace(const char *iso
)
2889 if (!g_conf_replace_head
)
2894 len
= (int)grub_strlen(iso
);
2896 for (node
= g_conf_replace_head
; node
; node
= node
->next
)
2898 if (node
->pathlen
== len
&& ventoy_strncmp(node
->isopath
, iso
, len
) == 0)
2907 dud
* ventoy_plugin_find_dud(const char *iso
)
2917 len
= (int)grub_strlen(iso
);
2918 for (node
= g_dud_head
; node
; node
= node
->next
)
2920 if (node
->pathlen
== len
&& ventoy_strncmp(node
->isopath
, iso
, len
) == 0)
2929 int ventoy_plugin_load_dud(dud
*node
, const char *isopart
)
2935 for (i
= 0; i
< node
->dudnum
; i
++)
2937 if (node
->files
[i
].size
> 0)
2939 debug("file %d has been loaded\n", i
);
2943 file
= ventoy_grub_file_open(VENTOY_FILE_TYPE
, "%s%s", isopart
, node
->dudpath
[i
].path
);
2946 buf
= grub_malloc(file
->size
);
2949 grub_file_read(file
, buf
, file
->size
);
2950 node
->files
[i
].size
= (int)file
->size
;
2951 node
->files
[i
].buf
= buf
;
2953 grub_file_close(file
);
2960 static const vtoy_password
* ventoy_plugin_get_password(const char *isopath
)
2964 const char *pos
= NULL
;
2965 menu_password
*node
= NULL
;
2974 len
= (int)grub_strlen(isopath
);
2975 for (node
= g_pwd_head
; node
; node
= node
->next
)
2977 if (node
->type
== vtoy_menu_pwd_file
)
2979 if (node
->pathlen
== len
&& ventoy_strncmp(node
->isopath
, isopath
, len
) == 0)
2981 return &(node
->password
);
2986 for (node
= g_pwd_head
; node
; node
= node
->next
)
2988 if (node
->type
== vtoy_menu_pwd_parent
)
2990 if (node
->pathlen
< len
&& ventoy_plugin_is_parent(node
->isopath
, node
->pathlen
, isopath
))
2992 return &(node
->password
);
3000 if (*isopath
== '.')
3009 for (i
= 0; i
< (int)ARRAY_SIZE(g_menu_prefix
); i
++)
3011 if (g_file_type_pwd
[i
].type
&& 0 == grub_strcasecmp(pos
+ 1, g_menu_prefix
[i
]))
3013 return g_file_type_pwd
+ i
;
3021 grub_err_t
ventoy_cmd_check_password(grub_extcmd_context_t ctxt
, int argc
, char **args
)
3024 const vtoy_password
*pwd
= NULL
;
3029 pwd
= ventoy_plugin_get_password(args
[0]);
3032 if (0 == ventoy_check_password(pwd
, 1))
3050 grub_err_t
ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt
, int argc
, char **args
)
3057 VTOY_JSON
*node
= NULL
;
3058 VTOY_JSON
*json
= NULL
;
3067 file
= ventoy_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD
, "%s/ventoy/ventoy.json", args
[0]);
3070 grub_printf("Plugin json file /ventoy/ventoy.json does NOT exist.\n");
3071 grub_printf("Attention: directory name and filename are both case-sensitive.\n");
3075 buf
= grub_malloc(file
->size
+ 1);
3078 grub_printf("Failed to malloc memory %lu.\n", (ulong
)(file
->size
+ 1));
3082 buf
[file
->size
] = 0;
3083 grub_file_read(file
, buf
, file
->size
);
3085 json
= vtoy_json_create();
3088 grub_printf("Failed to create json\n");
3092 ret
= vtoy_json_parse(json
, buf
);
3095 grub_printf("Syntax error detected in ventoy.json, please check it.\n");
3099 grub_snprintf(key
, sizeof(key
), "%s_%s", args
[1], g_arch_mode_suffix
);
3100 for (node
= json
->pstChild
; node
; node
= node
->pstNext
)
3102 if (grub_strcmp(node
->pcName
, args
[1]) == 0 || grub_strcmp(node
->pcName
, key
) == 0)
3110 grub_printf("%s is NOT found in ventoy.json\n", args
[1]);
3114 for (i
= 0; i
< (int)ARRAY_SIZE(g_plugin_entries
); i
++)
3116 if (grub_strcmp(g_plugin_entries
[i
].key
, args
[1]) == 0)
3118 if (g_plugin_entries
[i
].checkfunc
)
3120 ret
= g_plugin_entries
[i
].checkfunc(node
, args
[2]);
3127 check_free(file
, grub_file_close
);
3128 check_free(json
, vtoy_json_destroy
);
3129 grub_check_free(buf
);
3134 grub_err_t
ventoy_cmd_set_theme(grub_extcmd_context_t ctxt
, int argc
, char **args
)
3136 grub_uint32_t i
= 0;
3137 grub_uint32_t mod
= 0;
3138 theme_list
*node
= g_theme_head
;
3139 struct grub_datetime datetime
;
3145 if (g_theme_single_file
[0])
3147 debug("single theme %s\n", g_theme_single_file
);
3148 grub_env_set("theme", g_theme_single_file
);
3152 debug("g_theme_num = %d\n", g_theme_num
);
3154 if (g_theme_num
== 0)
3159 grub_memset(&datetime
, 0, sizeof(datetime
));
3160 grub_get_datetime(&datetime
);
3162 if (g_theme_random
== vtoy_theme_random_boot_second
)
3164 grub_divmod32((grub_uint32_t
)datetime
.second
, (grub_uint32_t
)g_theme_num
, &mod
);
3166 else if (g_theme_random
== vtoy_theme_random_boot_day
)
3168 grub_divmod32((grub_uint32_t
)datetime
.day
, (grub_uint32_t
)g_theme_num
, &mod
);
3170 else if (g_theme_random
== vtoy_theme_random_boot_month
)
3172 grub_divmod32((grub_uint32_t
)datetime
.month
, (grub_uint32_t
)g_theme_num
, &mod
);
3175 debug("%04d/%02d/%02d %02d:%02d:%02d radom:%d mod:%d\n",
3176 datetime
.year
, datetime
.month
, datetime
.day
,
3177 datetime
.hour
, datetime
.minute
, datetime
.second
,
3178 g_theme_random
, mod
);
3180 for (i
= 0; i
< mod
&& node
; i
++)
3185 debug("random theme %s\n", node
->theme
.path
);
3186 grub_env_set("theme", node
->theme
.path
);
3189 VENTOY_CMD_RETURN(GRUB_ERR_NONE
);