cpio_newc_header *g_ventoy_initrd_head = NULL;
grub_uint8_t *g_ventoy_runtime_buf = NULL;
+int g_plugin_image_list = 0;
+
ventoy_grub_param *g_grub_param = NULL;
ventoy_guid g_ventoy_guid = VENTOY_GUID;
{
return 0;
}
-
+
+ if (g_plugin_image_list)
+ {
+ grub_snprintf(g_img_swap_tmp_buf, sizeof(g_img_swap_tmp_buf), "%s%s", node->dir, filename);
+ if (ventoy_plugin_check_image_list(g_img_swap_tmp_buf) == 0)
+ {
+ return 0;
+ }
+ }
+
img = grub_zalloc(sizeof(img_info));
if (img)
{
img_info *minimg = NULL;
img_info *img = (img_info *)(node->firstiso);
- while (img && (img_iterator_node *)(img->parent) == node)
+ if (g_plugin_image_list)
{
- if (img->select == 0 && (NULL == minimg || ventoy_cmp_img(img, minimg) < 0))
+ while (img && (img_iterator_node *)(img->parent) == node)
{
- minimg = img;
+ if (img->select == 0)
+ {
+ minimg = img;
+ break;
+ }
+ img = img->next;
+ }
+ }
+ else
+ {
+ while (img && (img_iterator_node *)(img->parent) == node)
+ {
+ if (img->select == 0 && (NULL == minimg || ventoy_cmp_img(img, minimg) < 0))
+ {
+ minimg = img;
+ }
+ img = img->next;
}
- img = img->next;
}
if (minimg)
img_iterator_node *Minchild = NULL;
img_iterator_node *child = node->firstchild;
- while (child && child->parent == node)
+ if (g_plugin_image_list)
+ {
+ while (child && child->parent == node)
+ {
+ if (child->select == 0)
+ {
+ Minchild = child;
+ break;
+ }
+ child = child->next;
+ }
+ }
+ else
{
- if (child->select == 0 && (NULL == Minchild || ventoy_cmp_subdir(child->dir, Minchild->dir) < 0))
+ while (child && child->parent == node)
{
- Minchild = child;
+ if (child->select == 0 && (NULL == Minchild || ventoy_cmp_subdir(child->dir, Minchild->dir) < 0))
+ {
+ Minchild = child;
+ }
+ child = child->next;
}
- child = child->next;
}
if (Minchild)
grub_snprintf(g_iso_path, sizeof(g_iso_path), "%s", args[0]);
strdata = ventoy_get_env("VTOY_DEFAULT_SEARCH_ROOT");
- if (strdata && strdata[0] == '/')
+ if (0 == g_plugin_image_list && strdata && strdata[0] == '/')
{
len = grub_snprintf(g_img_iterator_head.dir, sizeof(g_img_iterator_head.dir) - 1, "%s", strdata);
if (g_img_iterator_head.dir[len - 1] != '/')
node = tmp;
}
- /* sort image list by image name */
- for (cur = g_ventoy_img_list; cur; cur = cur->next)
+ /* sort image list by image name if image_list is not set in ventoy.json */
+ if (0 == g_plugin_image_list)
{
- for (tail = cur->next; tail; tail = tail->next)
+ for (cur = g_ventoy_img_list; cur; cur = cur->next)
{
- if (ventoy_cmp_img(cur, tail) > 0)
+ for (tail = cur->next; tail; tail = tail->next)
{
- ventoy_swap_img(cur, tail);
+ if (ventoy_cmp_img(cur, tail) > 0)
+ {
+ ventoy_swap_img(cur, tail);
+ }
}
}
}
struct auto_memdisk *next;
}auto_memdisk;
+typedef struct image_list
+{
+ int pathlen;
+ char isopath[256];
+
+ struct image_list *next;
+}image_list;
+
extern int g_ventoy_menu_esc;
extern int g_ventoy_suppress_esc;
extern int g_ventoy_last_entry;
extern int g_ventoy_case_insensitive;
extern grub_uint8_t g_ventoy_chain_type;
extern int g_vhdboot_enable;
+extern int g_plugin_image_list;
extern ventoy_gpt_info *g_ventoy_part_info;
#define ventoy_unix_fill_virt(new_data, new_len) \
const char * ventoy_plugin_get_menu_alias(int type, const char *isopath);
const char * ventoy_plugin_get_menu_class(int type, const char *name);
int ventoy_plugin_check_memdisk(const char *isopath);
+int ventoy_plugin_check_image_list(const char *isopath);
int ventoy_get_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
void ventoy_plugin_dump_persistence(void);
static menu_class *g_menu_class_head = NULL;
static injection_config *g_injection_head = NULL;
static auto_memdisk *g_auto_memdisk_head = NULL;
+static image_list *g_image_list_head = NULL;
static int ventoy_plugin_control_check(VTOY_JSON *json, const char *isodisk)
{
return 0;
}
+static int ventoy_plugin_image_list_entry(VTOY_JSON *json, const char *isodisk)
+{
+ VTOY_JSON *pNode = NULL;
+ image_list *node = NULL;
+ image_list *next = NULL;
+
+ (void)isodisk;
+
+ if (json->enDataType != JSON_TYPE_ARRAY)
+ {
+ debug("Not array %d\n", json->enDataType);
+ return 0;
+ }
+
+ if (g_image_list_head)
+ {
+ for (node = g_image_list_head; node; node = next)
+ {
+ next = node->next;
+ grub_free(node);
+ }
+
+ g_image_list_head = NULL;
+ }
+
+ g_plugin_image_list = 1;
+
+ for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
+ {
+ if (pNode->enDataType == JSON_TYPE_STRING)
+ {
+ node = grub_zalloc(sizeof(image_list));
+ if (node)
+ {
+ node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", pNode->unData.pcStrVal);
+
+ if (g_image_list_head)
+ {
+ node->next = g_image_list_head;
+ }
+
+ g_image_list_head = node;
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int ventoy_plugin_image_list_check(VTOY_JSON *json, const char *isodisk)
+{
+ VTOY_JSON *pNode = NULL;
+
+ if (json->enDataType != JSON_TYPE_ARRAY)
+ {
+ grub_printf("Not array %d\n", json->enDataType);
+ return 1;
+ }
+
+ for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
+ {
+ if (pNode->enDataType == JSON_TYPE_STRING)
+ {
+ grub_printf("<%s> ", pNode->unData.pcStrVal);
+
+ if (ventoy_check_file_exist("%s%s", isodisk, pNode->unData.pcStrVal))
+ {
+ grub_printf(" [OK]\n");
+ }
+ else
+ {
+ grub_printf(" [NOT EXIST]\n");
+ }
+ }
+ }
+
+ return 0;
+}
+
static plugin_entry g_plugin_entries[] =
{
{ "control", ventoy_plugin_control_entry, ventoy_plugin_control_check },
{ "menu_class", ventoy_plugin_menuclass_entry, ventoy_plugin_menuclass_check },
{ "injection", ventoy_plugin_injection_entry, ventoy_plugin_injection_check },
{ "auto_memdisk", ventoy_plugin_auto_memdisk_entry, ventoy_plugin_auto_memdisk_check },
+ { "image_list", ventoy_plugin_image_list_entry, ventoy_plugin_image_list_check },
};
static int ventoy_parse_plugin_config(VTOY_JSON *json, const char *isodisk)
return 0;
}
+int ventoy_plugin_check_image_list(const char *isopath)
+{
+ int len;
+ image_list *node = NULL;
+
+ if (!g_image_list_head)
+ {
+ return 0;
+ }
+
+ len = (int)grub_strlen(isopath);
+ for (node = g_image_list_head; node; node = node->next)
+ {
+ if (node->pathlen == len && grub_strncmp(isopath, node->isopath, len) == 0)
+ {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, char **args)
{
int i = 0;
echo -e "\npress ENTER to exit ..."
read vtInputKey
unset pager
- }
+ }
+
+ menuentry 'Check image list plugin configuration' --class=debug_imagelist {
+ set pager=1
+ vt_check_plugin_json $vt_plugin_path image_list $vtoy_iso_part
+
+ echo -e "\npress ENTER to exit ..."
+ read vtInputKey
+ unset pager
+ }
menuentry 'Return to previous menu [Esc]' --class=vtoyret VTOY_RET {
echo 'Return ...'