1.0.78 release

This commit is contained in:
longpanda 2022-07-01 19:10:12 +08:00
parent 0b81845e42
commit e46e24dde7
24 changed files with 338 additions and 167 deletions

View file

@ -107,12 +107,14 @@ grub_uint32_t g_wimiso_size = 0;
int g_vhdboot_enable = 0;
grub_uint64_t g_conf_replace_offset = 0;
grub_uint64_t g_svd_replace_offset = 0;
conf_replace *g_conf_replace_node = NULL;
grub_uint8_t *g_conf_replace_new_buf = NULL;
int g_conf_replace_new_len = 0;
int g_conf_replace_new_len_align = 0;
int g_conf_replace_count = 0;
grub_uint64_t g_conf_replace_offset[VTOY_MAX_CONF_REPLACE] = { 0 };
conf_replace *g_conf_replace_node[VTOY_MAX_CONF_REPLACE] = { NULL };
grub_uint8_t *g_conf_replace_new_buf[VTOY_MAX_CONF_REPLACE] = { NULL };
int g_conf_replace_new_len[VTOY_MAX_CONF_REPLACE] = { 0 };
int g_conf_replace_new_len_align[VTOY_MAX_CONF_REPLACE] = { 0 };
int g_ventoy_disk_bios_id = 0;
ventoy_gpt_info *g_ventoy_part_info = NULL;
@ -3250,8 +3252,9 @@ static grub_err_t ventoy_cmd_img_sector(grub_extcmd_context_t ctxt, int argc, ch
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s\n", args[0]);
}
g_conf_replace_node = NULL;
g_conf_replace_offset = 0;
g_conf_replace_count = 0;
grub_memset(g_conf_replace_node, 0, sizeof(g_conf_replace_node ));
grub_memset(g_conf_replace_offset, 0, sizeof(g_conf_replace_offset ));
if (g_img_chunk_list.chunk)
{
@ -3294,11 +3297,15 @@ static grub_err_t ventoy_cmd_img_sector(grub_extcmd_context_t ctxt, int argc, ch
static grub_err_t ventoy_select_conf_replace(grub_extcmd_context_t ctxt, int argc, char **args)
{
int i;
int n;
grub_uint64_t offset = 0;
grub_uint32_t align = 0;
grub_file_t file = NULL;
conf_replace *node = NULL;
conf_replace *nodes[VTOY_MAX_CONF_REPLACE] = { NULL };
ventoy_grub_param_file_replace *replace = NULL;
(void)ctxt;
(void)argc;
(void)args;
@ -3310,67 +3317,72 @@ static grub_err_t ventoy_select_conf_replace(grub_extcmd_context_t ctxt, int arg
return 0;
}
node = ventoy_plugin_find_conf_replace(args[1]);
if (!node)
n = ventoy_plugin_find_conf_replace(args[1], nodes);
if (!n)
{
debug("Conf replace not found for %s\n", args[1]);
goto end;
}
debug("Find conf replace for %s\n", args[1]);
debug("Find %d conf replace for %s\n", n, args[1]);
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "(loop)%s", node->orgconf);
if (file)
g_conf_replace_count = n;
for (i = 0; i < n; i++)
{
offset = grub_iso9660_get_last_file_dirent_pos(file);
grub_file_close(file);
node = nodes[i];
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "(loop)%s", node->orgconf);
if (file)
{
offset = grub_iso9660_get_last_file_dirent_pos(file);
grub_file_close(file);
}
else if (node->img > 0)
{
offset = 0;
}
else
{
debug("<(loop)%s> NOT exist\n", node->orgconf);
continue;
}
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", args[0], node->newconf);
if (!file)
{
debug("New config file <%s%s> NOT exist\n", args[0], node->newconf);
continue;
}
align = ((int)file->size + 2047) / 2048 * 2048;
if (align > vtoy_max_replace_file_size)
{
debug("New config file <%s%s> too big\n", args[0], node->newconf);
grub_file_close(file);
continue;
}
grub_file_read(file, g_conf_replace_new_buf[i], file->size);
grub_file_close(file);
g_conf_replace_new_len[i] = (int)file->size;
g_conf_replace_new_len_align[i] = align;
g_conf_replace_node[i] = node;
g_conf_replace_offset[i] = offset + 2;
if (node->img > 0)
{
replace = &(g_grub_param->img_replace[i]);
replace->magic = GRUB_IMG_REPLACE_MAGIC;
grub_snprintf(replace->old_file_name[replace->old_name_cnt], 256, "%s", node->orgconf);
replace->old_name_cnt++;
}
debug("conf_replace OK: newlen[%d]: %d img:%d\n", i, g_conf_replace_new_len[i], node->img);
}
else if (node->img > 0)
{
offset = 0;
}
else
{
debug("<(loop)%s> NOT exist\n", node->orgconf);
goto end;
}
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", args[0], node->newconf);
if (!file)
{
debug("New config file <%s%s> NOT exist\n", args[0], node->newconf);
goto end;
}
align = ((int)file->size + 2047) / 2048 * 2048;
if (align > vtoy_max_replace_file_size)
{
debug("New config file <%s%s> too big\n", args[0], node->newconf);
goto end;
}
grub_file_read(file, g_conf_replace_new_buf, file->size);
g_conf_replace_new_len = (int)file->size;
g_conf_replace_new_len_align = align;
g_conf_replace_node = node;
g_conf_replace_offset = offset + 2;
if (node->img > 0)
{
g_grub_param->img_replace.magic = GRUB_IMG_REPLACE_MAGIC;
g_grub_param->img_replace.old_name_cnt = 1;
grub_snprintf(g_grub_param->img_replace.old_file_name[0], 256, "%s", node->orgconf);
}
debug("conf_replace OK: newlen: %d\n", g_conf_replace_new_len);
end:
if (file)
{
grub_file_close(file);
}
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
@ -5945,6 +5957,7 @@ static grub_err_t ventoy_cmd_dump_rsv_page(grub_extcmd_context_t ctxt, int argc,
int ventoy_env_init(void)
{
int i;
char buf[64];
grub_env_set("vtdebug_flag", "");
@ -5952,7 +5965,10 @@ int ventoy_env_init(void)
g_part_list_buf = grub_malloc(VTOY_PART_BUF_LEN);
g_tree_script_buf = grub_malloc(VTOY_MAX_SCRIPT_BUF);
g_list_script_buf = grub_malloc(VTOY_MAX_SCRIPT_BUF);
g_conf_replace_new_buf = grub_malloc(vtoy_max_replace_file_size);
for (i = 0; i < VTOY_MAX_CONF_REPLACE; i++)
{
g_conf_replace_new_buf[i] = grub_malloc(vtoy_max_replace_file_size);
}
ventoy_filt_register(0, ventoy_wrapper_open);

View file

@ -960,7 +960,7 @@ typedef struct custom_boot
struct custom_boot *next;
}custom_boot;
#define vtoy_max_replace_file_size (2 * 1024 * 1024)
#define vtoy_max_replace_file_size (1024 * 1024)
typedef struct conf_replace
{
int pathlen;
@ -1046,12 +1046,13 @@ extern int g_vhdboot_enable;
extern int g_plugin_image_list;
extern ventoy_gpt_info *g_ventoy_part_info;
extern grub_uint64_t g_conf_replace_offset;
extern int g_conf_replace_count;
extern grub_uint64_t g_conf_replace_offset[VTOY_MAX_CONF_REPLACE];
extern grub_uint64_t g_svd_replace_offset;
extern conf_replace *g_conf_replace_node;
extern grub_uint8_t *g_conf_replace_new_buf;
extern int g_conf_replace_new_len;
extern int g_conf_replace_new_len_align;
extern conf_replace *g_conf_replace_node[VTOY_MAX_CONF_REPLACE];
extern grub_uint8_t *g_conf_replace_new_buf[VTOY_MAX_CONF_REPLACE];
extern int g_conf_replace_new_len[VTOY_MAX_CONF_REPLACE];
extern int g_conf_replace_new_len_align[VTOY_MAX_CONF_REPLACE];
extern int g_ventoy_disk_bios_id;
extern grub_uint64_t g_ventoy_disk_size;
extern grub_uint64_t g_ventoy_disk_part_size[2];
@ -1095,7 +1096,7 @@ const menu_tip * ventoy_plugin_get_menu_tip(int type, const char *isopath);
const char * ventoy_plugin_get_menu_class(int type, const char *name, const char *path);
int ventoy_plugin_check_memdisk(const char *isopath);
int ventoy_plugin_get_image_list_index(int type, const char *name);
conf_replace * ventoy_plugin_find_conf_replace(const char *iso);
int ventoy_plugin_find_conf_replace(const char *iso, conf_replace *nodes[VTOY_MAX_CONF_REPLACE]);
dud * ventoy_plugin_find_dud(const char *iso);
int ventoy_plugin_load_dud(dud *node, const char *isopart);
int ventoy_get_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);

View file

@ -654,11 +654,18 @@ int ventoy_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, co
static grub_uint32_t ventoy_linux_get_virt_chunk_count(void)
{
int i;
grub_uint32_t count = g_valid_initrd_count;
if (g_conf_replace_offset > 0)
if (g_conf_replace_count > 0)
{
count++;
for (i = 0; i < g_conf_replace_count; i++)
{
if (g_conf_replace_offset[i] > 0)
{
count++;
}
}
}
if (g_append_ext_sector > 0)
@ -671,13 +678,20 @@ static grub_uint32_t ventoy_linux_get_virt_chunk_count(void)
static grub_uint32_t ventoy_linux_get_virt_chunk_size(void)
{
int i;
grub_uint32_t size;
size = (sizeof(ventoy_virt_chunk) + g_ventoy_cpio_size) * g_valid_initrd_count;
if (g_conf_replace_offset > 0)
if (g_conf_replace_count > 0)
{
size += sizeof(ventoy_virt_chunk) + g_conf_replace_new_len_align;
for (i = 0; i < g_conf_replace_count; i++)
{
if (g_conf_replace_offset[i] > 0)
{
size += sizeof(ventoy_virt_chunk) + g_conf_replace_new_len_align[i];
}
}
}
if (g_append_ext_sector > 0)
@ -690,6 +704,7 @@ static grub_uint32_t ventoy_linux_get_virt_chunk_size(void)
static void ventoy_linux_fill_virt_data( grub_uint64_t isosize, ventoy_chain_head *chain)
{
int i = 0;
int id = 0;
int virtid = 0;
initrd_info *node;
@ -699,6 +714,7 @@ static void ventoy_linux_fill_virt_data( grub_uint64_t isosize, ventoy_chain_
grub_uint32_t initrd_secs;
char *override;
ventoy_virt_chunk *cur;
ventoy_grub_param_file_replace *replace = NULL;
char name[32];
override = (char *)chain + chain->virt_chunk_offset;
@ -764,30 +780,37 @@ static void ventoy_linux_fill_virt_data( grub_uint64_t isosize, ventoy_chain_
virtid++;
}
if (g_conf_replace_offset > 0)
if (g_conf_replace_count > 0)
{
cpio_secs = g_conf_replace_new_len_align / 2048;
cur->mem_sector_start = sector;
cur->mem_sector_end = cur->mem_sector_start + cpio_secs;
cur->mem_sector_offset = offset;
cur->remap_sector_start = 0;
cur->remap_sector_end = 0;
cur->org_sector_start = 0;
grub_memcpy(override + offset, g_conf_replace_new_buf, g_conf_replace_new_len);
chain->virt_img_size_in_bytes += g_conf_replace_new_len_align;
if (g_grub_param->img_replace.magic == GRUB_IMG_REPLACE_MAGIC)
for (i = 0; i < g_conf_replace_count; i++)
{
g_grub_param->img_replace.new_file_virtual_id = virtid;
}
if (g_conf_replace_offset[i] > 0)
{
cpio_secs = g_conf_replace_new_len_align[i] / 2048;
cur->mem_sector_start = sector;
cur->mem_sector_end = cur->mem_sector_start + cpio_secs;
cur->mem_sector_offset = offset;
cur->remap_sector_start = 0;
cur->remap_sector_end = 0;
cur->org_sector_start = 0;
offset += g_conf_replace_new_len_align;
sector += cpio_secs;
cur++;
virtid++;
grub_memcpy(override + offset, g_conf_replace_new_buf[i], g_conf_replace_new_len[i]);
chain->virt_img_size_in_bytes += g_conf_replace_new_len_align[i];
replace = g_grub_param->img_replace + i;
if (replace->magic == GRUB_IMG_REPLACE_MAGIC)
{
replace->new_file_virtual_id = virtid;
}
offset += g_conf_replace_new_len_align[i];
sector += cpio_secs;
cur++;
virtid++;
}
}
}
return;
@ -795,11 +818,18 @@ static void ventoy_linux_fill_virt_data( grub_uint64_t isosize, ventoy_chain_
static grub_uint32_t ventoy_linux_get_override_chunk_count(void)
{
int i;
grub_uint32_t count = g_valid_initrd_count;
if (g_conf_replace_offset > 0)
if (g_conf_replace_count > 0)
{
count++;
for (i = 0; i < g_conf_replace_count; i++)
{
if (g_conf_replace_offset[i] > 0)
{
count++;
}
}
}
if (g_svd_replace_offset > 0)
@ -812,11 +842,18 @@ static grub_uint32_t ventoy_linux_get_override_chunk_count(void)
static grub_uint32_t ventoy_linux_get_override_chunk_size(void)
{
int i;
int count = g_valid_initrd_count;
if (g_conf_replace_offset > 0)
if (g_conf_replace_count > 0)
{
count++;
for (i = 0; i < g_conf_replace_count; i++)
{
if (g_conf_replace_offset[i] > 0)
{
count++;
}
}
}
if (g_svd_replace_offset > 0)
@ -829,6 +866,7 @@ static grub_uint32_t ventoy_linux_get_override_chunk_size(void)
static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *override)
{
int i;
initrd_info *node;
grub_uint32_t mod;
grub_uint32_t newlen;
@ -883,23 +921,29 @@ static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *ove
cur++;
}
if (g_conf_replace_offset > 0)
{
cur->img_offset = g_conf_replace_offset;
cur->override_size = sizeof(ventoy_iso9660_override);
if (g_conf_replace_count > 0)
{
for (i = 0; i < g_conf_replace_count; i++)
{
if (g_conf_replace_offset[i] > 0)
{
cur->img_offset = g_conf_replace_offset[i];
cur->override_size = sizeof(ventoy_iso9660_override);
newlen = (grub_uint32_t)(g_conf_replace_new_len);
newlen = (grub_uint32_t)(g_conf_replace_new_len[i]);
dirent = (ventoy_iso9660_override *)cur->override_data;
dirent->first_sector = (grub_uint32_t)sector;
dirent->size = newlen;
dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector);
dirent->size_be = grub_swap_bytes32(dirent->size);
dirent = (ventoy_iso9660_override *)cur->override_data;
dirent->first_sector = (grub_uint32_t)sector;
dirent->size = newlen;
dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector);
dirent->size_be = grub_swap_bytes32(dirent->size);
sector += (dirent->size + 2047) / 2048;
cur++;
sector += (dirent->size + 2047) / 2048;
cur++;
}
}
}
if (g_svd_replace_offset > 0)
{
cur->img_offset = g_svd_replace_offset;

View file

@ -3054,14 +3054,15 @@ int ventoy_plugin_get_image_list_index(int type, const char *name)
return 0;
}
conf_replace * ventoy_plugin_find_conf_replace(const char *iso)
int ventoy_plugin_find_conf_replace(const char *iso, conf_replace *nodes[VTOY_MAX_CONF_REPLACE])
{
int n = 0;
int len;
conf_replace *node;
if (!g_conf_replace_head)
{
return NULL;
return 0;
}
len = (int)grub_strlen(iso);
@ -3070,11 +3071,15 @@ conf_replace * ventoy_plugin_find_conf_replace(const char *iso)
{
if (node->pathlen == len && ventoy_strncmp(node->isopath, iso, len) == 0)
{
return node;
nodes[n++] = node;
if (n >= VTOY_MAX_CONF_REPLACE)
{
return n;
}
}
}
return NULL;
return n;
}
dud * ventoy_plugin_find_dud(const char *iso)

View file

@ -262,6 +262,7 @@ typedef struct ventoy_img_chunk_list
#pragma pack(1)
#define VTOY_MAX_CONF_REPLACE 2
#define GRUB_FILE_REPLACE_MAGIC 0x1258BEEF
#define GRUB_IMG_REPLACE_MAGIC 0x1259BEEF
@ -282,7 +283,7 @@ typedef struct ventoy_grub_param
grub_env_get_pf grub_env_get;
grub_env_set_pf grub_env_set;
ventoy_grub_param_file_replace file_replace;
ventoy_grub_param_file_replace img_replace;
ventoy_grub_param_file_replace img_replace[VTOY_MAX_CONF_REPLACE];
grub_env_printf_pf grub_env_printf;
}ventoy_grub_param;