+static int ventoy_plugin_conf_replace_entry(VTOY_JSON *json, const char *isodisk)
+{
+ const char *isof = NULL;
+ const char *orgf = NULL;
+ const char *newf = NULL;
+ VTOY_JSON *pNode = NULL;
+ conf_replace *tail = NULL;
+ conf_replace *node = NULL;
+ conf_replace *next = NULL;
+
+ (void)isodisk;
+
+ if (json->enDataType != JSON_TYPE_ARRAY)
+ {
+ debug("Not array %d\n", json->enDataType);
+ return 0;
+ }
+
+ if (g_conf_replace_head)
+ {
+ for (node = g_conf_replace_head; node; node = next)
+ {
+ next = node->next;
+ grub_free(node);
+ }
+
+ g_conf_replace_head = NULL;
+ }
+
+ for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
+ {
+ isof = vtoy_json_get_string_ex(pNode->pstChild, "iso");
+ orgf = vtoy_json_get_string_ex(pNode->pstChild, "org");
+ newf = vtoy_json_get_string_ex(pNode->pstChild, "new");
+ if (isof && orgf && newf && isof[0] == '/' && orgf[0] == '/' && newf[0] == '/')
+ {
+ node = grub_zalloc(sizeof(conf_replace));
+ if (node)
+ {
+ node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", isof);
+ grub_snprintf(node->orgconf, sizeof(node->orgconf), "%s", orgf);
+ grub_snprintf(node->newconf, sizeof(node->newconf), "%s", newf);
+
+ if (g_conf_replace_head)
+ {
+ tail->next = node;
+ }
+ else
+ {
+ g_conf_replace_head = node;
+ }
+ tail = node;
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int ventoy_plugin_conf_replace_check(VTOY_JSON *json, const char *isodisk)
+{
+ const char *isof = NULL;
+ const char *orgf = NULL;
+ const char *newf = NULL;
+ VTOY_JSON *pNode = NULL;
+ grub_file_t file = NULL;
+ char cmd[256];
+
+ (void)isodisk;
+
+ if (json->enDataType != JSON_TYPE_ARRAY)
+ {
+ grub_printf("Not array %d\n", json->enDataType);
+ return 1;
+ }
+
+ for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
+ {
+ isof = vtoy_json_get_string_ex(pNode->pstChild, "iso");
+ orgf = vtoy_json_get_string_ex(pNode->pstChild, "org");
+ newf = vtoy_json_get_string_ex(pNode->pstChild, "new");
+ if (isof && orgf && newf && isof[0] == '/' && orgf[0] == '/' && newf[0] == '/')
+ {
+ if (ventoy_check_file_exist("%s%s", isodisk, isof))
+ {
+ grub_printf("iso:<%s> [OK]\n", isof);
+
+ grub_snprintf(cmd, sizeof(cmd), "loopback vtisocheck %s%s", isodisk, isof);
+ grub_script_execute_sourcecode(cmd);
+
+ file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "(vtisocheck)/%s", orgf);
+ if (file)
+ {
+ if (grub_strcmp(file->fs->name, "iso9660") == 0)
+ {
+ grub_printf("org:<%s> [OK]\n", orgf);
+ }
+ else
+ {
+ grub_printf("org:<%s> [Exist But NOT ISO9660]\n", orgf);
+ }
+ grub_file_close(file);
+ }
+ else
+ {
+ grub_printf("org:<%s> [NOT Exist]\n", orgf);
+ }
+
+ grub_script_execute_sourcecode("loopback -d vtisocheck");
+ }
+ else
+ {
+ grub_printf("iso:<%s> [NOT Exist]\n", isof);
+ grub_printf("org:<%s>\n", orgf);
+ }
+
+ file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", isodisk, newf);
+ if (file)
+ {
+ if (file->size > vtoy_max_replace_file_size)
+ {
+ grub_printf("new:<%s> [Too Big %lu] \n", newf, (ulong)file->size);
+ }
+ else
+ {
+ grub_printf("new:<%s> [OK]\n", newf);
+ }
+ grub_file_close(file);
+ }
+ else
+ {
+ grub_printf("new:<%s> [NOT Exist]\n", newf);
+ }
+ grub_printf("\n");
+ }
+ }
+
+ return 0;
+}
+