ventoy_grub_param_file_replace *g_file_replace_list = NULL;
ventoy_efi_file_replace g_efi_file_replace;
+ventoy_grub_param_file_replace *g_img_replace_list = NULL;
+ventoy_efi_file_replace g_img_file_replace;
+
CONST CHAR16 gIso9660EfiDriverPath[] = ISO9660_EFI_DRIVER_PATH;
CONST CHAR16 gUdfEfiDriverPath[] = UDF_EFI_DRIVER_PATH;
return EFI_SUCCESS;
}
+STATIC EFI_STATUS ventoy_proc_img_replace_name(ventoy_grub_param_file_replace *replace)
+{
+ UINT32 i;
+ char tmp[256];
+
+ if (replace->magic != GRUB_IMG_REPLACE_MAGIC)
+ {
+ return EFI_SUCCESS;
+ }
+
+ if (replace->old_file_name[0][0] == 0)
+ {
+ return EFI_SUCCESS;
+ }
+
+ AsciiStrCpyS(tmp, sizeof(tmp), replace->old_file_name[0]);
+
+ for (i = 0; i < 256 && tmp[i]; i++)
+ {
+ if (tmp[i] == '/')
+ {
+ tmp[i] = '\\';
+ }
+ }
+
+ AsciiStrCpyS(replace->old_file_name[0], 256, tmp);
+ return EFI_SUCCESS;
+}
+
STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
{
UINT32 i = 0;
old_cnt > 3 ? g_file_replace_list->old_file_name[3] : ""
);
+ g_img_replace_list = &pGrubParam->img_replace;
+ ventoy_proc_img_replace_name(g_img_replace_list);
+ old_cnt = g_img_replace_list->old_file_cnt;
+ debug("img replace: magic:0x%x virtid:%u name count:%u <%a> <%a> <%a> <%a>",
+ g_img_replace_list->magic,
+ g_img_replace_list->new_file_virtual_id,
+ old_cnt,
+ old_cnt > 0 ? g_img_replace_list->old_file_name[0] : "",
+ old_cnt > 1 ? g_img_replace_list->old_file_name[1] : "",
+ old_cnt > 2 ? g_img_replace_list->old_file_name[2] : "",
+ old_cnt > 3 ? g_img_replace_list->old_file_name[3] : ""
+ );
+
pPos = StrStr(pCmdLine, L"mem:");
chain = (ventoy_chain_head *)StrHexToUintn(pPos + 4);
gST->ConIn->Reset(gST->ConIn, FALSE);
}
- if (g_file_replace_list && g_file_replace_list->magic == GRUB_FILE_REPLACE_MAGIC)
+ if ((g_file_replace_list && g_file_replace_list->magic == GRUB_FILE_REPLACE_MAGIC) ||
+ (g_img_replace_list && g_img_replace_list->magic == GRUB_IMG_REPLACE_MAGIC))
{
ventoy_wrapper_push_openvolume(pFile->OpenVolume);
pFile->OpenVolume = ventoy_wrapper_open_volume;
#pragma pack(1)
#define GRUB_FILE_REPLACE_MAGIC 0x1258BEEF
+#define GRUB_IMG_REPLACE_MAGIC 0x1259BEEF
typedef struct ventoy_efi_file_replace
{
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;
grub_env_printf_pf grub_env_printf;
}ventoy_grub_param;
extern UINT32 g_virt_chunk_num;
extern vtoy_block_data gBlockData;
extern ventoy_efi_file_replace g_efi_file_replace;
+extern ventoy_efi_file_replace g_img_file_replace;
extern ventoy_sector_flag *g_sector_flag;
extern UINT32 g_sector_flag_num;
extern BOOLEAN gMemdiskMode;
extern UINTN g_iso_buf_size;
extern UINT8 *g_iso_data_buf;
extern ventoy_grub_param_file_replace *g_file_replace_list;
+extern ventoy_grub_param_file_replace *g_img_replace_list;
extern BOOLEAN g_fixup_iso9660_secover_enable;
extern EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *g_con_simple_input_ex;
extern BOOLEAN g_fix_windows_1st_cdrom_issue;
#include <Protocol/DriverBinding.h>
#include <Ventoy.h>
+#define ASSIGN_REPLACE(This, replace) \
+ replace = (This->FlushEx == ventoy_wrapper_file_flush_ex) ? &g_efi_file_replace : &g_img_file_replace
+
UINT8 *g_iso_data_buf = NULL;
UINTN g_iso_buf_size = 0;
BOOLEAN gMemdiskMode = FALSE;
return EFI_SUCCESS;
}
+/* Ex version */
+STATIC EFI_STATUS EFIAPI
+ventoy_wrapper_file_flush_ex_img(EFI_FILE_HANDLE This, EFI_FILE_IO_TOKEN *Token)
+{
+ (VOID)This;
+ (VOID)Token;
+ return EFI_SUCCESS;
+}
+
STATIC EFI_STATUS EFIAPI
ventoy_wrapper_file_write(EFI_FILE_HANDLE This, UINTN *Len, VOID *Data)
return EFI_SUCCESS;
}
-
STATIC EFI_STATUS EFIAPI
ventoy_wrapper_file_set_pos(EFI_FILE_HANDLE This, UINT64 Position)
{
- (VOID)This;
-
- if (Position <= g_efi_file_replace.FileSizeBytes)
+ ventoy_efi_file_replace *replace = NULL;
+
+ ASSIGN_REPLACE(This, replace);
+
+ if (Position <= replace->FileSizeBytes)
{
- g_efi_file_replace.CurPos = Position;
+ replace->CurPos = Position;
}
else
{
- g_efi_file_replace.CurPos = g_efi_file_replace.FileSizeBytes;
+ replace->CurPos = replace->FileSizeBytes;
}
return EFI_SUCCESS;
STATIC EFI_STATUS EFIAPI
ventoy_wrapper_file_get_pos(EFI_FILE_HANDLE This, UINT64 *Position)
{
- (VOID)This;
+ ventoy_efi_file_replace *replace = NULL;
- *Position = g_efi_file_replace.CurPos;
+ ASSIGN_REPLACE(This, replace);
+
+ *Position = replace->CurPos;
return EFI_SUCCESS;
}
ventoy_wrapper_file_get_info(EFI_FILE_HANDLE This, EFI_GUID *Type, UINTN *Len, VOID *Data)
{
EFI_FILE_INFO *Info = (EFI_FILE_INFO *) Data;
+ ventoy_efi_file_replace *replace = NULL;
+
+ ASSIGN_REPLACE(This, replace);
debug("ventoy_wrapper_file_get_info ... %u", *Len);
ZeroMem(Data, sizeof(EFI_FILE_INFO));
Info->Size = sizeof(EFI_FILE_INFO);
- Info->FileSize = g_efi_file_replace.FileSizeBytes;
- Info->PhysicalSize = g_efi_file_replace.FileSizeBytes;
+ Info->FileSize = replace->FileSizeBytes;
+ Info->PhysicalSize = replace->FileSizeBytes;
Info->Attribute = EFI_FILE_READ_ONLY;
//Info->FileName = EFI_FILE_READ_ONLY;
{
EFI_LBA Lba;
UINTN ReadLen = *Len;
-
- (VOID)This;
+ ventoy_efi_file_replace *replace = NULL;
+ ASSIGN_REPLACE(This, replace);
+
debug("ventoy_wrapper_file_read ... %u", *Len);
- if (g_efi_file_replace.CurPos + ReadLen > g_efi_file_replace.FileSizeBytes)
+ if (replace->CurPos + ReadLen > replace->FileSizeBytes)
{
- ReadLen = g_efi_file_replace.FileSizeBytes - g_efi_file_replace.CurPos;
+ ReadLen = replace->FileSizeBytes - replace->CurPos;
}
- Lba = g_efi_file_replace.CurPos / 2048 + g_efi_file_replace.BlockIoSectorStart;
+ Lba = replace->CurPos / 2048 + replace->BlockIoSectorStart;
ventoy_block_io_read(NULL, 0, Lba, ReadLen, Data);
*Len = ReadLen;
- g_efi_file_replace.CurPos += ReadLen;
+ replace->CurPos += ReadLen;
return EFI_SUCCESS;
}
return ventoy_wrapper_file_read(This, &(Token->BufferSize), Token->Buffer);
}
-STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL *File)
+STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL *File, BOOLEAN Img)
{
File->Revision = EFI_FILE_PROTOCOL_REVISION2;
File->Open = ventoy_wrapper_fs_open;
File->OpenEx = ventoy_wrapper_file_open_ex;
File->ReadEx = ventoy_wrapper_file_read_ex;
File->WriteEx = ventoy_wrapper_file_write_ex;
- File->FlushEx = ventoy_wrapper_file_flush_ex;
+ File->FlushEx = Img ? ventoy_wrapper_file_flush_ex_img : ventoy_wrapper_file_flush_ex;
return EFI_SUCCESS;
}
UINT64 Sectors = 0;
EFI_STATUS Status = EFI_SUCCESS;
CHAR8 TmpName[256];
+ CHAR8 OldName[256];
ventoy_virt_chunk *virt = NULL;
debug("## ventoy_wrapper_file_open <%s> ", Name);
return Status;
}
+
if (g_file_replace_list && g_file_replace_list->magic == GRUB_FILE_REPLACE_MAGIC &&
g_file_replace_list->new_file_virtual_id < g_virt_chunk_num)
{
{
g_original_fclose(*New);
*New = &g_efi_file_replace.WrapperHandle;
- ventoy_wrapper_file_procotol(*New);
+ ventoy_wrapper_file_procotol(*New, FALSE);
virt = g_virt_chunk + g_file_replace_list->new_file_virtual_id;
}
}
+
+
+ if (g_img_replace_list && g_img_replace_list->magic == GRUB_IMG_REPLACE_MAGIC &&
+ g_img_replace_list->new_file_virtual_id < g_virt_chunk_num)
+ {
+ AsciiSPrint(TmpName, sizeof(TmpName), "%s", Name);
+ for (j = 0; j < g_img_replace_list->old_file_cnt; j++)
+ {
+ AsciiStrCpyS(OldName, sizeof(OldName), g_img_replace_list[i].old_file_name[j]);
+ if ((0 == AsciiStrCmp(OldName, TmpName)) ||
+ (AsciiStrnCmp(OldName, "\\loader\\entries", 15) == 0 &&
+ AsciiStrCmp(OldName + 16, TmpName) == 0
+ )
+ )
+ {
+ g_original_fclose(*New);
+ *New = &g_img_file_replace.WrapperHandle;
+ ventoy_wrapper_file_procotol(*New, TRUE);
+
+ virt = g_virt_chunk + g_img_replace_list->new_file_virtual_id;
+
+ Sectors = (virt->mem_sector_end - virt->mem_sector_start) + (virt->remap_sector_end - virt->remap_sector_start);
+
+ g_img_file_replace.BlockIoSectorStart = virt->mem_sector_start;
+ g_img_file_replace.FileSizeBytes = Sectors * 2048;
+
+ if (gDebugPrint)
+ {
+ debug("## ventoy_wrapper_file_open2 <%s> BlockStart:%lu Sectors:%lu Bytes:%lu", Name,
+ g_img_file_replace.BlockIoSectorStart, Sectors, Sectors * 2048);
+ sleep(3);
+ }
+
+ return Status;
+ }
+ }
+
+ if (StrCmp(Name, L"\\loader\\entries") == 0)
+ {
+ (*New)->Open = ventoy_wrapper_file_open;
+ }
+ }
+
return Status;
}
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;
grub_env_printf_pf grub_env_printf;
}ventoy_grub_param;
#pragma pack()
}
grub_memset(&g_grub_param->file_replace, 0, sizeof(g_grub_param->file_replace));
+ grub_memset(&g_grub_param->img_replace, 0, sizeof(g_grub_param->img_replace));
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
debug("Find conf replace for %s\n", args[1]);
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "(loop)%s", node->orgconf);
- if (!file)
+ 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);
goto end;
}
- offset = grub_iso9660_get_last_file_dirent_pos(file);
- grub_file_close(file);
-
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", args[0], node->newconf);
if (!file)
{
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:
typedef struct conf_replace
{
int pathlen;
+ int img;
char isopath[256];
char orgconf[256];
char newconf[256];
#define ret_goto_end(a) ret = a; goto end;
+extern ventoy_grub_param *g_grub_param;
+
#endif /* __VENTOY_DEF_H__ */
static void ventoy_linux_fill_virt_data( grub_uint64_t isosize, ventoy_chain_head *chain)
{
int id = 0;
+ int virtid = 0;
initrd_info *node;
grub_uint64_t sector;
grub_uint32_t offset;
offset += g_ventoy_cpio_size;
sector += cpio_secs + initrd_secs;
cur++;
+ virtid++;
}
/* Lenovo EasyStartup need an addional sector for boundary check */
offset += VTOY_APPEND_EXT_SIZE;
sector += cpio_secs;
cur++;
+ virtid++;
}
if (g_conf_replace_offset > 0)
chain->virt_img_size_in_bytes += g_conf_replace_new_len_align;
+ if (g_grub_param->img_replace.magic == GRUB_IMG_REPLACE_MAGIC)
+ {
+ g_grub_param->img_replace.new_file_virtual_id = virtid;
+ }
+
offset += g_conf_replace_new_len_align;
sector += cpio_secs;
cur++;
+ virtid++;
}
return;
static int ventoy_plugin_conf_replace_entry(VTOY_JSON *json, const char *isodisk)
{
+ int img = 0;
const char *isof = NULL;
const char *orgf = NULL;
const char *newf = NULL;
node = grub_zalloc(sizeof(conf_replace));
if (node)
{
+ if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "img", &img))
+ {
+ node->img = img;
+ }
+
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);
static int ventoy_plugin_conf_replace_check(VTOY_JSON *json, const char *isodisk)
{
+ int img = 0;
const char *isof = NULL;
const char *orgf = NULL;
const char *newf = NULL;
}
else
{
- grub_printf("new:<%s> [OK]\n", newf);
+ grub_printf("new1:<%s> [OK]\n", newf);
}
grub_file_close(file);
}
{
grub_printf("new:<%s> [NOT Exist]\n", newf);
}
+
+ if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "img", &img))
+ {
+ grub_printf("img:<%d>\n", img);
+ }
+
grub_printf("\n");
}
}
#pragma pack(1)
#define GRUB_FILE_REPLACE_MAGIC 0x1258BEEF
+#define GRUB_IMG_REPLACE_MAGIC 0x1259BEEF
typedef const char * (*grub_env_get_pf)(const char *name);
typedef int (*grub_env_set_pf)(const char *name, const char *val);
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;
grub_env_printf_pf grub_env_printf;
}ventoy_grub_param;