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/time.h>
36 #include <grub/font.h>
37 #include <grub/ventoy.h>
38 #include "ventoy_def.h"
40 GRUB_MOD_LICENSE ("GPLv3+");
42 static char g_iso_disk_name
[128];
43 static install_template
*g_install_template_head
= NULL
;
44 static persistence_config
*g_persistence_head
= NULL
;
45 static menu_alias
*g_menu_alias_head
= NULL
;
46 static menu_class
*g_menu_class_head
= NULL
;
48 static int ventoy_plugin_control_check(VTOY_JSON
*json
, const char *isodisk
)
51 VTOY_JSON
*pNode
= NULL
;
52 VTOY_JSON
*pChild
= NULL
;
56 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
58 grub_printf("Not array type %d\n", json
->enDataType
);
62 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
64 if (pNode
->enDataType
== JSON_TYPE_OBJECT
)
66 pChild
= pNode
->pstChild
;
67 if (pChild
->enDataType
== JSON_TYPE_STRING
)
69 grub_printf("%s: %s\n", pChild
->pcName
, pChild
->unData
.pcStrVal
);
73 grub_printf("%s is NOT string type\n", pChild
->pcName
);
79 grub_printf("%s is not an object\n", pNode
->pcName
);
87 static int ventoy_plugin_control_entry(VTOY_JSON
*json
, const char *isodisk
)
89 VTOY_JSON
*pNode
= NULL
;
90 VTOY_JSON
*pChild
= NULL
;
94 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
96 debug("Not array %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
&& pChild
->pcName
&& pChild
->unData
.pcStrVal
)
107 ventoy_set_env(pChild
->pcName
, pChild
->unData
.pcStrVal
);
115 static int ventoy_plugin_theme_check(VTOY_JSON
*json
, const char *isodisk
)
121 value
= vtoy_json_get_string_ex(json
->pstChild
, "file");
124 grub_printf("file: %s\n", value
);
127 exist
= ventoy_is_file_exist("%s%s", isodisk
, value
);
131 exist
= ventoy_is_file_exist("%s/ventoy/%s", isodisk
, value
);
136 grub_printf("Theme file %s does NOT exist\n", value
);
141 value
= vtoy_json_get_string_ex(json
->pstChild
, "gfxmode");
144 grub_printf("gfxmode: %s\n", value
);
147 value
= vtoy_json_get_string_ex(json
->pstChild
, "display_mode");
150 grub_printf("display_mode: %s\n", value
);
153 value
= vtoy_json_get_string_ex(json
->pstChild
, "ventoy_left");
156 grub_printf("ventoy_left: %s\n", value
);
159 value
= vtoy_json_get_string_ex(json
->pstChild
, "ventoy_top");
162 grub_printf("ventoy_top: %s\n", value
);
165 value
= vtoy_json_get_string_ex(json
->pstChild
, "ventoy_color");
168 grub_printf("ventoy_color: %s\n", value
);
171 node
= vtoy_json_find_item(json
->pstChild
, JSON_TYPE_ARRAY
, "fonts");
174 for (node
= node
->pstChild
; node
; node
= node
->pstNext
)
176 if (node
->enDataType
== JSON_TYPE_STRING
)
178 if (ventoy_check_file_exist("%s%s", isodisk
, node
->unData
.pcStrVal
))
180 grub_printf("%s [OK]\n", node
->unData
.pcStrVal
);
184 grub_printf("%s [NOT EXIST]\n", node
->unData
.pcStrVal
);
191 grub_printf("fonts NOT found\n");
197 static int ventoy_plugin_theme_entry(VTOY_JSON
*json
, const char *isodisk
)
203 value
= vtoy_json_get_string_ex(json
->pstChild
, "file");
208 grub_snprintf(filepath
, sizeof(filepath
), "%s%s", isodisk
, value
);
212 grub_snprintf(filepath
, sizeof(filepath
), "%s/ventoy/%s", isodisk
, value
);
215 if (ventoy_is_file_exist(filepath
) == 0)
217 debug("Theme file %s does not exist\n", filepath
);
221 debug("vtoy_theme %s\n", filepath
);
222 grub_env_set("vtoy_theme", filepath
);
225 value
= vtoy_json_get_string_ex(json
->pstChild
, "gfxmode");
228 debug("vtoy_gfxmode %s\n", value
);
229 grub_env_set("vtoy_gfxmode", value
);
232 value
= vtoy_json_get_string_ex(json
->pstChild
, "display_mode");
235 debug("display_mode %s\n", value
);
236 grub_env_set("vtoy_display_mode", value
);
239 value
= vtoy_json_get_string_ex(json
->pstChild
, "ventoy_left");
242 grub_env_set("VTLE_LFT", value
);
245 value
= vtoy_json_get_string_ex(json
->pstChild
, "ventoy_top");
248 grub_env_set("VTLE_TOP", value
);
251 value
= vtoy_json_get_string_ex(json
->pstChild
, "ventoy_color");
254 grub_env_set("VTLE_CLR", value
);
257 node
= vtoy_json_find_item(json
->pstChild
, JSON_TYPE_ARRAY
, "fonts");
260 for (node
= node
->pstChild
; node
; node
= node
->pstNext
)
262 if (node
->enDataType
== JSON_TYPE_STRING
&&
263 ventoy_check_file_exist("%s%s", isodisk
, node
->unData
.pcStrVal
))
265 grub_snprintf(filepath
, sizeof(filepath
), "%s%s", isodisk
, node
->unData
.pcStrVal
);
266 grub_font_load(filepath
);
274 static int ventoy_plugin_check_path(const char *path
, const char *file
)
278 grub_printf("%s is NOT begin with '/' \n", file
);
282 if (grub_strchr(file
, '\\'))
284 grub_printf("%s contains invalid '\\' \n", file
);
288 if (grub_strstr(file
, "//"))
290 grub_printf("%s contains invalid double slash\n", file
);
294 if (grub_strstr(file
, "../"))
296 grub_printf("%s contains invalid '../' \n", file
);
300 if (!ventoy_is_file_exist("%s%s", path
, file
))
302 grub_printf("%s%s does NOT exist\n", path
, file
);
309 static int ventoy_plugin_check_fullpath
318 VTOY_JSON
*node
= json
;
319 VTOY_JSON
*child
= NULL
;
323 if (0 == grub_strcmp(key
, node
->pcName
))
327 node
= node
->pstNext
;
335 if (JSON_TYPE_STRING
== node
->enDataType
)
337 ret
= ventoy_plugin_check_path(isodisk
, node
->unData
.pcStrVal
);
338 grub_printf("%s: %s [%s]\n", key
, node
->unData
.pcStrVal
, ret
? "FAIL" : "OK");
340 else if (JSON_TYPE_ARRAY
== node
->enDataType
)
342 for (child
= node
->pstChild
; child
; child
= child
->pstNext
)
344 if (JSON_TYPE_STRING
!= child
->enDataType
)
346 grub_printf("Non string json type\n");
350 rc
= ventoy_plugin_check_path(isodisk
, child
->unData
.pcStrVal
);
351 grub_printf("%s: %s [%s]\n", key
, child
->unData
.pcStrVal
, rc
? "FAIL" : "OK");
360 static int ventoy_plugin_parse_fullpath
365 file_fullpath
**fullpath
,
371 VTOY_JSON
*node
= json
;
372 VTOY_JSON
*child
= NULL
;
373 file_fullpath
*path
= NULL
;
377 if (0 == grub_strcmp(key
, node
->pcName
))
381 node
= node
->pstNext
;
389 if (JSON_TYPE_STRING
== node
->enDataType
)
391 debug("%s is string type data\n", node
->pcName
);
393 if ((node
->unData
.pcStrVal
[0] != '/') || (!ventoy_is_file_exist("%s%s", isodisk
, node
->unData
.pcStrVal
)))
395 debug("%s%s file not found\n", isodisk
, node
->unData
.pcStrVal
);
399 path
= (file_fullpath
*)grub_zalloc(sizeof(file_fullpath
));
402 grub_snprintf(path
->path
, sizeof(path
->path
), "%s", node
->unData
.pcStrVal
);
408 else if (JSON_TYPE_ARRAY
== node
->enDataType
)
410 for (child
= node
->pstChild
; child
; child
= child
->pstNext
)
412 if ((JSON_TYPE_STRING
!= child
->enDataType
) || (child
->unData
.pcStrVal
[0] != '/'))
414 debug("Invalid data type:%d\n", child
->enDataType
);
419 debug("%s is array type data, count=%d\n", node
->pcName
, count
);
421 path
= (file_fullpath
*)grub_zalloc(sizeof(file_fullpath
) * count
);
426 for (count
= 0, child
= node
->pstChild
; child
; child
= child
->pstNext
)
428 if (ventoy_is_file_exist("%s%s", isodisk
, child
->unData
.pcStrVal
))
430 grub_snprintf(path
->path
, sizeof(path
->path
), "%s", child
->unData
.pcStrVal
);
444 static int ventoy_plugin_auto_install_check(VTOY_JSON
*json
, const char *isodisk
)
446 const char *iso
= NULL
;
447 VTOY_JSON
*pNode
= NULL
;
449 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
451 grub_printf("Not array type %d\n", json
->enDataType
);
455 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
457 if (pNode
->enDataType
!= JSON_TYPE_OBJECT
)
459 grub_printf("NOT object type\n");
462 iso
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
465 if (0 == ventoy_plugin_check_path(isodisk
, iso
))
467 grub_printf("image: %s [OK]\n", iso
);
468 ventoy_plugin_check_fullpath(pNode
->pstChild
, isodisk
, "template");
472 grub_printf("image: %s [FAIL]\n", iso
);
477 grub_printf("image not found\n");
484 static int ventoy_plugin_auto_install_entry(VTOY_JSON
*json
, const char *isodisk
)
487 const char *iso
= NULL
;
488 VTOY_JSON
*pNode
= NULL
;
489 install_template
*node
= NULL
;
490 install_template
*next
= NULL
;
491 file_fullpath
*templatepath
= NULL
;
493 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
495 debug("Not array %d\n", json
->enDataType
);
499 if (g_install_template_head
)
501 for (node
= g_install_template_head
; node
; node
= next
)
504 grub_check_free(node
->templatepath
);
508 g_install_template_head
= NULL
;
511 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
513 iso
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
514 if (iso
&& iso
[0] == '/')
516 if (0 == ventoy_plugin_parse_fullpath(pNode
->pstChild
, isodisk
, "template", &templatepath
, &pathnum
))
518 node
= grub_zalloc(sizeof(install_template
));
521 node
->pathlen
= grub_snprintf(node
->isopath
, sizeof(node
->isopath
), "%s", iso
);
522 node
->templatepath
= templatepath
;
523 node
->templatenum
= pathnum
;
525 if (g_install_template_head
)
527 node
->next
= g_install_template_head
;
530 g_install_template_head
= node
;
539 static int ventoy_plugin_persistence_check(VTOY_JSON
*json
, const char *isodisk
)
541 const char *iso
= NULL
;
542 VTOY_JSON
*pNode
= NULL
;
544 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
546 grub_printf("Not array type %d\n", json
->enDataType
);
550 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
552 if (pNode
->enDataType
!= JSON_TYPE_OBJECT
)
554 grub_printf("NOT object type\n");
557 iso
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
560 if (0 == ventoy_plugin_check_path(isodisk
, iso
))
562 grub_printf("image: %s [OK]\n", iso
);
563 ventoy_plugin_check_fullpath(pNode
->pstChild
, isodisk
, "backend");
567 grub_printf("image: %s [FAIL]\n", iso
);
572 grub_printf("image not found\n");
579 static int ventoy_plugin_persistence_entry(VTOY_JSON
*json
, const char *isodisk
)
582 const char *iso
= NULL
;
583 VTOY_JSON
*pNode
= NULL
;
584 persistence_config
*node
= NULL
;
585 persistence_config
*next
= NULL
;
586 file_fullpath
*backendpath
= NULL
;
590 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
592 debug("Not array %d\n", json
->enDataType
);
596 if (g_persistence_head
)
598 for (node
= g_persistence_head
; node
; node
= next
)
601 grub_check_free(node
->backendpath
);
605 g_persistence_head
= NULL
;
608 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
610 iso
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
611 if (iso
&& iso
[0] == '/')
613 if (0 == ventoy_plugin_parse_fullpath(pNode
->pstChild
, isodisk
, "backend", &backendpath
, &pathnum
))
615 node
= grub_zalloc(sizeof(persistence_config
));
618 node
->pathlen
= grub_snprintf(node
->isopath
, sizeof(node
->isopath
), "%s", iso
);
619 node
->backendpath
= backendpath
;
620 node
->backendnum
= pathnum
;
622 if (g_persistence_head
)
624 node
->next
= g_persistence_head
;
627 g_persistence_head
= node
;
636 static int ventoy_plugin_menualias_check(VTOY_JSON
*json
, const char *isodisk
)
638 const char *iso
= NULL
;
639 const char *alias
= NULL
;
640 VTOY_JSON
*pNode
= NULL
;
644 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
646 grub_printf("Not array %d\n", json
->enDataType
);
650 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
652 iso
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
653 alias
= vtoy_json_get_string_ex(pNode
->pstChild
, "alias");
654 if (iso
&& iso
[0] == '/' && alias
)
656 if (ventoy_is_file_exist("%s%s", isodisk
, iso
))
658 grub_printf("image: <%s> [ OK ]\n", iso
);
662 grub_printf("image: <%s> [ NOT EXIST ]\n", iso
);
665 grub_printf("alias: <%s>\n\n", alias
);
672 static int ventoy_plugin_menualias_entry(VTOY_JSON
*json
, const char *isodisk
)
674 const char *iso
= NULL
;
675 const char *alias
= NULL
;
676 VTOY_JSON
*pNode
= NULL
;
677 menu_alias
*node
= NULL
;
678 menu_alias
*next
= NULL
;
682 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
684 debug("Not array %d\n", json
->enDataType
);
688 if (g_menu_alias_head
)
690 for (node
= g_menu_alias_head
; node
; node
= next
)
696 g_menu_alias_head
= NULL
;
699 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
701 iso
= vtoy_json_get_string_ex(pNode
->pstChild
, "image");
702 alias
= vtoy_json_get_string_ex(pNode
->pstChild
, "alias");
703 if (iso
&& iso
[0] == '/' && alias
)
705 node
= grub_zalloc(sizeof(menu_alias
));
708 node
->pathlen
= grub_snprintf(node
->isopath
, sizeof(node
->isopath
), "%s", iso
);
709 grub_snprintf(node
->alias
, sizeof(node
->alias
), "%s", alias
);
711 if (g_menu_alias_head
)
713 node
->next
= g_menu_alias_head
;
716 g_menu_alias_head
= node
;
724 static int ventoy_plugin_menuclass_entry(VTOY_JSON
*json
, const char *isodisk
)
726 const char *key
= NULL
;
727 const char *class = NULL
;
728 VTOY_JSON
*pNode
= NULL
;
729 menu_class
*tail
= NULL
;
730 menu_class
*node
= NULL
;
731 menu_class
*next
= NULL
;
735 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
737 debug("Not array %d\n", json
->enDataType
);
741 if (g_menu_class_head
)
743 for (node
= g_menu_class_head
; node
; node
= next
)
749 g_menu_class_head
= NULL
;
752 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
754 key
= vtoy_json_get_string_ex(pNode
->pstChild
, "key");
755 class = vtoy_json_get_string_ex(pNode
->pstChild
, "class");
758 node
= grub_zalloc(sizeof(menu_class
));
761 node
->patlen
= grub_snprintf(node
->pattern
, sizeof(node
->pattern
), "%s", key
);
762 grub_snprintf(node
->class, sizeof(node
->class), "%s", class);
764 if (g_menu_class_head
)
770 g_menu_class_head
= node
;
780 static int ventoy_plugin_menuclass_check(VTOY_JSON
*json
, const char *isodisk
)
782 const char *key
= NULL
;
783 const char *class = NULL
;
784 VTOY_JSON
*pNode
= NULL
;
788 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
790 grub_printf("Not array %d\n", json
->enDataType
);
794 for (pNode
= json
->pstChild
; pNode
; pNode
= pNode
->pstNext
)
796 key
= vtoy_json_get_string_ex(pNode
->pstChild
, "key");
797 class = vtoy_json_get_string_ex(pNode
->pstChild
, "class");
800 grub_printf("key: <%s>\n", key
);
801 grub_printf("class: <%s>\n\n", class);
808 static plugin_entry g_plugin_entries
[] =
810 { "control", ventoy_plugin_control_entry
, ventoy_plugin_control_check
},
811 { "theme", ventoy_plugin_theme_entry
, ventoy_plugin_theme_check
},
812 { "auto_install", ventoy_plugin_auto_install_entry
, ventoy_plugin_auto_install_check
},
813 { "persistence", ventoy_plugin_persistence_entry
, ventoy_plugin_persistence_check
},
814 { "menu_alias", ventoy_plugin_menualias_entry
, ventoy_plugin_menualias_check
},
815 { "menu_class", ventoy_plugin_menuclass_entry
, ventoy_plugin_menuclass_check
},
818 static int ventoy_parse_plugin_config(VTOY_JSON
*json
, const char *isodisk
)
821 VTOY_JSON
*cur
= json
;
823 grub_snprintf(g_iso_disk_name
, sizeof(g_iso_disk_name
), "%s", isodisk
);
827 for (i
= 0; i
< (int)ARRAY_SIZE(g_plugin_entries
); i
++)
829 if (grub_strcmp(g_plugin_entries
[i
].key
, cur
->pcName
) == 0)
831 debug("Plugin entry for %s\n", g_plugin_entries
[i
].key
);
832 g_plugin_entries
[i
].entryfunc(cur
, isodisk
);
843 grub_err_t
ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt
, int argc
, char **args
)
848 VTOY_JSON
*json
= NULL
;
853 file
= ventoy_grub_file_open(VENTOY_FILE_TYPE
, "%s/ventoy/ventoy.json", args
[0]);
856 return GRUB_ERR_NONE
;
859 debug("json configuration file size %d\n", (int)file
->size
);
861 buf
= grub_malloc(file
->size
+ 1);
864 grub_file_close(file
);
869 grub_file_read(file
, buf
, file
->size
);
870 grub_file_close(file
);
872 json
= vtoy_json_create();
880 ret
= vtoy_json_parse(json
, buf
);
883 debug("Failed to parse json string %d\n", ret
);
888 ventoy_parse_plugin_config(json
->pstChild
, args
[0]);
890 vtoy_json_destroy(json
);
894 VENTOY_CMD_RETURN(GRUB_ERR_NONE
);
897 void ventoy_plugin_dump_auto_install(void)
900 install_template
*node
= NULL
;
902 for (node
= g_install_template_head
; node
; node
= node
->next
)
904 grub_printf("\nIMAGE:<%s>\n", node
->isopath
);
905 for (i
= 0; i
< node
->templatenum
; i
++)
907 grub_printf("SCRIPT %d:<%s>\n", i
, node
->templatepath
[i
].path
);
914 void ventoy_plugin_dump_persistence(void)
918 persistence_config
*node
= NULL
;
919 ventoy_img_chunk_list chunk_list
;
921 for (node
= g_persistence_head
; node
; node
= node
->next
)
923 grub_printf("\nIMAGE:<%s>\n", node
->isopath
);
925 for (i
= 0; i
< node
->backendnum
; i
++)
927 grub_printf("PERSIST %d:<%s>", i
, node
->backendpath
[i
].path
);
928 rc
= ventoy_plugin_get_persistent_chunklist(node
->isopath
, i
, &chunk_list
);
931 grub_printf(" [ SUCCESS ]\n");
932 grub_free(chunk_list
.chunk
);
936 grub_printf(" [ FAILED ]\n");
944 install_template
* ventoy_plugin_find_install_template(const char *isopath
)
946 install_template
*node
= NULL
;
947 int len
= (int)grub_strlen(isopath
);
949 for (node
= g_install_template_head
; node
; node
= node
->next
)
951 if (node
->pathlen
== len
&& grub_strcmp(node
->isopath
, isopath
) == 0)
960 char * ventoy_plugin_get_cur_install_template(const char *isopath
)
962 install_template
*node
= NULL
;
964 node
= ventoy_plugin_find_install_template(isopath
);
965 if ((!node
) || (!node
->templatepath
))
970 if (node
->cursel
< 0 || node
->cursel
>= node
->templatenum
)
975 return node
->templatepath
[node
->cursel
].path
;
978 persistence_config
* ventoy_plugin_find_persistent(const char *isopath
)
980 persistence_config
*node
= NULL
;
981 int len
= (int)grub_strlen(isopath
);
983 for (node
= g_persistence_head
; node
; node
= node
->next
)
985 if ((len
== node
->pathlen
) && (grub_strcmp(node
->isopath
, isopath
) == 0))
994 int ventoy_plugin_get_persistent_chunklist(const char *isopath
, int index
, ventoy_img_chunk_list
*chunk_list
)
997 grub_uint64_t start
= 0;
998 grub_file_t file
= NULL
;
999 persistence_config
*node
= NULL
;
1001 node
= ventoy_plugin_find_persistent(isopath
);
1002 if ((!node
) || (!node
->backendpath
))
1009 index
= node
->cursel
;
1012 if (index
< 0 || index
>= node
->backendnum
)
1017 file
= ventoy_grub_file_open(VENTOY_FILE_TYPE
, "%s%s", g_iso_disk_name
, node
->backendpath
[index
].path
);
1020 debug("Failed to open file %s%s\n", g_iso_disk_name
, node
->backendpath
[index
].path
);
1024 grub_memset(chunk_list
, 0, sizeof(ventoy_img_chunk_list
));
1025 chunk_list
->chunk
= grub_malloc(sizeof(ventoy_img_chunk
) * DEFAULT_CHUNK_NUM
);
1026 if (NULL
== chunk_list
->chunk
)
1031 chunk_list
->max_chunk
= DEFAULT_CHUNK_NUM
;
1032 chunk_list
->cur_chunk
= 0;
1034 start
= file
->device
->disk
->partition
->start
;
1035 ventoy_get_block_list(file
, chunk_list
, start
);
1037 if (0 != ventoy_check_block_list(file
, chunk_list
, start
))
1039 grub_free(chunk_list
->chunk
);
1040 chunk_list
->chunk
= NULL
;
1048 grub_file_close(file
);
1053 const char * ventoy_plugin_get_menu_alias(const char *isopath
)
1055 menu_alias
*node
= NULL
;
1056 int len
= (int)grub_strlen(isopath
);
1058 for (node
= g_menu_alias_head
; node
; node
= node
->next
)
1060 if (node
->pathlen
== len
&& grub_strcmp(node
->isopath
, isopath
) == 0)
1069 const char * ventoy_plugin_get_menu_class(const char *isoname
)
1071 menu_class
*node
= NULL
;
1072 int len
= (int)grub_strlen(isoname
);
1074 for (node
= g_menu_class_head
; node
; node
= node
->next
)
1076 if (node
->patlen
<= len
&& grub_strstr(isoname
, node
->pattern
))
1086 grub_err_t
ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt
, int argc
, char **args
)
1092 VTOY_JSON
*node
= NULL
;
1093 VTOY_JSON
*json
= NULL
;
1102 file
= ventoy_grub_file_open(VENTOY_FILE_TYPE
, "%s/ventoy/ventoy.json", args
[0]);
1105 grub_printf("Plugin json file /ventoy/ventoy.json does NOT exist.\n");
1109 buf
= grub_malloc(file
->size
+ 1);
1112 grub_printf("Failed to malloc memory %lu.\n", (ulong
)(file
->size
+ 1));
1116 buf
[file
->size
] = 0;
1117 grub_file_read(file
, buf
, file
->size
);
1119 json
= vtoy_json_create();
1122 grub_printf("Failed to create json\n");
1126 ret
= vtoy_json_parse(json
, buf
);
1129 grub_printf("Syntax error detected in ventoy.json, please check it.\n");
1133 for (node
= json
->pstChild
; node
; node
= node
->pstNext
)
1135 if (grub_strcmp(node
->pcName
, args
[1]) == 0)
1143 grub_printf("%s is NOT found in ventoy.json\n", args
[1]);
1147 for (i
= 0; i
< (int)ARRAY_SIZE(g_plugin_entries
); i
++)
1149 if (grub_strcmp(g_plugin_entries
[i
].key
, args
[1]) == 0)
1151 if (g_plugin_entries
[i
].checkfunc
)
1153 ret
= g_plugin_entries
[i
].checkfunc(node
, args
[2]);
1160 check_free(file
, grub_file_close
);
1161 check_free(json
, vtoy_json_destroy
);
1162 grub_check_free(buf
);