mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-06-03 08:28:50 -04:00
1.0.78 release
This commit is contained in:
parent
0b81845e42
commit
e46e24dde7
24 changed files with 338 additions and 167 deletions
|
@ -60,7 +60,7 @@ 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;
|
||||
ventoy_efi_file_replace g_img_file_replace[VTOY_MAX_CONF_REPLACE];
|
||||
|
||||
CONST CHAR16 gIso9660EfiDriverPath[] = ISO9660_EFI_DRIVER_PATH;
|
||||
CONST CHAR16 gUdfEfiDriverPath[] = UDF_EFI_DRIVER_PATH;
|
||||
|
@ -829,6 +829,7 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
|
|||
ventoy_grub_param *pGrubParam = NULL;
|
||||
EFI_LOADED_IMAGE_PROTOCOL *pImageInfo = NULL;
|
||||
ventoy_chain_head *chain = NULL;
|
||||
ventoy_grub_param_file_replace *replace = NULL;
|
||||
|
||||
Status = gBS->HandleProtocol(ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&pImageInfo);
|
||||
if (EFI_ERROR(Status))
|
||||
|
@ -926,18 +927,27 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
|
|||
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] : ""
|
||||
);
|
||||
|
||||
for (i = 0; i < VTOY_MAX_CONF_REPLACE; i++)
|
||||
{
|
||||
replace = pGrubParam->img_replace + i;
|
||||
if (replace->magic == GRUB_IMG_REPLACE_MAGIC)
|
||||
{
|
||||
ventoy_proc_img_replace_name(replace);
|
||||
old_cnt = replace->old_file_cnt;
|
||||
debug("img replace[%d]: magic:0x%x virtid:%u name count:%u <%a> <%a> <%a> <%a>",
|
||||
i, replace->magic,
|
||||
replace->new_file_virtual_id,
|
||||
old_cnt,
|
||||
old_cnt > 0 ? replace->old_file_name[0] : "",
|
||||
old_cnt > 1 ? replace->old_file_name[1] : "",
|
||||
old_cnt > 2 ? replace->old_file_name[2] : "",
|
||||
old_cnt > 3 ? replace->old_file_name[3] : ""
|
||||
);
|
||||
g_img_replace_list = pGrubParam->img_replace;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pPos = StrStr(pCmdLine, L"mem:");
|
||||
chain = (ventoy_chain_head *)StrHexToUintn(pPos + 4);
|
||||
|
@ -1178,8 +1188,7 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
|
|||
gST->ConIn->Reset(gST->ConIn, FALSE);
|
||||
}
|
||||
|
||||
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))
|
||||
if ((g_file_replace_list && g_file_replace_list->magic == GRUB_FILE_REPLACE_MAGIC) || g_img_replace_list)
|
||||
{
|
||||
ventoy_wrapper_push_openvolume(pFile->OpenVolume);
|
||||
pFile->OpenVolume = ventoy_wrapper_open_volume;
|
||||
|
|
|
@ -244,6 +244,7 @@ typedef int (*grub_env_printf_pf)(const char *fmt, ...);
|
|||
|
||||
#pragma pack(1)
|
||||
|
||||
#define VTOY_MAX_CONF_REPLACE 2
|
||||
#define GRUB_FILE_REPLACE_MAGIC 0x1258BEEF
|
||||
#define GRUB_IMG_REPLACE_MAGIC 0x1259BEEF
|
||||
|
||||
|
@ -270,7 +271,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;
|
||||
|
||||
|
@ -400,7 +401,7 @@ extern ventoy_virt_chunk *g_virt_chunk;
|
|||
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_efi_file_replace g_img_file_replace[VTOY_MAX_CONF_REPLACE];
|
||||
extern ventoy_sector_flag *g_sector_flag;
|
||||
extern UINT32 g_sector_flag_num;
|
||||
extern BOOLEAN gMemdiskMode;
|
||||
|
|
|
@ -37,9 +37,6 @@
|
|||
#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;
|
||||
|
@ -1251,13 +1248,96 @@ ventoy_wrapper_file_flush_ex(EFI_FILE_HANDLE This, EFI_FILE_IO_TOKEN *Token)
|
|||
|
||||
/* Ex version */
|
||||
STATIC EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_flush_ex_img(EFI_FILE_HANDLE This, EFI_FILE_IO_TOKEN *Token)
|
||||
ventoy_wrapper_file_flush_ex_img0(EFI_FILE_HANDLE This, EFI_FILE_IO_TOKEN *Token)
|
||||
{
|
||||
(VOID)This;
|
||||
(VOID)Token;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
/* Ex version */
|
||||
STATIC EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_flush_ex_img1(EFI_FILE_HANDLE This, EFI_FILE_IO_TOKEN *Token)
|
||||
{
|
||||
(VOID)This;
|
||||
(VOID)Token;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
#define DEF_WRAP_FUNC(n) \
|
||||
STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_flush_ex_img#n(EFI_FILE_HANDLE This, EFI_FILE_IO_TOKEN *Token) \
|
||||
{\
|
||||
(VOID)This;\
|
||||
(VOID)Token;\
|
||||
return EFI_SUCCESS;\
|
||||
}
|
||||
|
||||
#define ITEM_WRAP_FUNC(n) ventoy_wrapper_file_flush_ex_img#n
|
||||
|
||||
#if (VTOY_MAX_CONF_REPLACE > 2)
|
||||
DEF_WRAP_FUNC(2);
|
||||
#endif
|
||||
#if (VTOY_MAX_CONF_REPLACE > 3)
|
||||
DEF_WRAP_FUNC(3);
|
||||
#endif
|
||||
#if (VTOY_MAX_CONF_REPLACE > 4)
|
||||
DEF_WRAP_FUNC(4);
|
||||
#endif
|
||||
#if (VTOY_MAX_CONF_REPLACE > 5)
|
||||
DEF_WRAP_FUNC(5);
|
||||
#endif
|
||||
#if (VTOY_MAX_CONF_REPLACE > 6)
|
||||
DEF_WRAP_FUNC(6);
|
||||
#endif
|
||||
#if (VTOY_MAX_CONF_REPLACE > 7)
|
||||
DEF_WRAP_FUNC(7);
|
||||
#endif
|
||||
#if (VTOY_MAX_CONF_REPLACE > 8)
|
||||
#error "VTOY_MAX_CONF_REPLACE overflow"
|
||||
#endif
|
||||
|
||||
static EFI_FILE_FLUSH_EX g_img_flush_func[VTOY_MAX_CONF_REPLACE] =
|
||||
{
|
||||
ventoy_wrapper_file_flush_ex_img0,
|
||||
ventoy_wrapper_file_flush_ex_img1,
|
||||
#if (VTOY_MAX_CONF_REPLACE > 2)
|
||||
ITEM_WRAP_FUNC(2),
|
||||
#endif
|
||||
#if (VTOY_MAX_CONF_REPLACE > 3)
|
||||
ITEM_WRAP_FUNC(3),
|
||||
#endif
|
||||
#if (VTOY_MAX_CONF_REPLACE > 4)
|
||||
ITEM_WRAP_FUNC(4),
|
||||
#endif
|
||||
#if (VTOY_MAX_CONF_REPLACE > 5)
|
||||
ITEM_WRAP_FUNC(5),
|
||||
#endif
|
||||
#if (VTOY_MAX_CONF_REPLACE > 6)
|
||||
ITEM_WRAP_FUNC(6),
|
||||
#endif
|
||||
#if (VTOY_MAX_CONF_REPLACE > 7)
|
||||
ITEM_WRAP_FUNC(7),
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC ventoy_efi_file_replace *ventoy_wrapper_get_replace(EFI_FILE_HANDLE This)
|
||||
{
|
||||
UINTN i;
|
||||
|
||||
if (This->FlushEx == ventoy_wrapper_file_flush_ex)
|
||||
{
|
||||
return &g_efi_file_replace;
|
||||
}
|
||||
|
||||
for (i = 0; i < VTOY_MAX_CONF_REPLACE; i++)
|
||||
{
|
||||
if (This->FlushEx == g_img_flush_func[i])
|
||||
{
|
||||
return g_img_file_replace + i;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_write(EFI_FILE_HANDLE This, UINTN *Len, VOID *Data)
|
||||
|
@ -1288,7 +1368,7 @@ ventoy_wrapper_file_set_pos(EFI_FILE_HANDLE This, UINT64 Position)
|
|||
{
|
||||
ventoy_efi_file_replace *replace = NULL;
|
||||
|
||||
ASSIGN_REPLACE(This, replace);
|
||||
replace = ventoy_wrapper_get_replace(This);
|
||||
|
||||
if (Position <= replace->FileSizeBytes)
|
||||
{
|
||||
|
@ -1307,7 +1387,7 @@ ventoy_wrapper_file_get_pos(EFI_FILE_HANDLE This, UINT64 *Position)
|
|||
{
|
||||
ventoy_efi_file_replace *replace = NULL;
|
||||
|
||||
ASSIGN_REPLACE(This, replace);
|
||||
replace = ventoy_wrapper_get_replace(This);
|
||||
|
||||
*Position = replace->CurPos;
|
||||
|
||||
|
@ -1321,7 +1401,7 @@ ventoy_wrapper_file_get_info(EFI_FILE_HANDLE This, EFI_GUID *Type, UINTN *Len, V
|
|||
EFI_FILE_INFO *Info = (EFI_FILE_INFO *) Data;
|
||||
ventoy_efi_file_replace *replace = NULL;
|
||||
|
||||
ASSIGN_REPLACE(This, replace);
|
||||
replace = ventoy_wrapper_get_replace(This);
|
||||
|
||||
debug("ventoy_wrapper_file_get_info ... %u", *Len);
|
||||
|
||||
|
@ -1356,7 +1436,7 @@ ventoy_wrapper_file_read(EFI_FILE_HANDLE This, UINTN *Len, VOID *Data)
|
|||
UINTN ReadLen = *Len;
|
||||
ventoy_efi_file_replace *replace = NULL;
|
||||
|
||||
ASSIGN_REPLACE(This, replace);
|
||||
replace = ventoy_wrapper_get_replace(This);
|
||||
|
||||
debug("ventoy_wrapper_file_read ... %u", *Len);
|
||||
|
||||
|
@ -1382,7 +1462,7 @@ ventoy_wrapper_file_read_ex(IN EFI_FILE_PROTOCOL *This, IN OUT EFI_FILE_IO_TOKEN
|
|||
return ventoy_wrapper_file_read(This, &(Token->BufferSize), Token->Buffer);
|
||||
}
|
||||
|
||||
STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL *File, BOOLEAN Img)
|
||||
STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL *File, BOOLEAN Img, UINTN Index)
|
||||
{
|
||||
File->Revision = EFI_FILE_PROTOCOL_REVISION2;
|
||||
File->Open = ventoy_wrapper_fs_open;
|
||||
|
@ -1398,7 +1478,15 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL *File, B
|
|||
File->OpenEx = ventoy_wrapper_file_open_ex;
|
||||
File->ReadEx = ventoy_wrapper_file_read_ex;
|
||||
File->WriteEx = ventoy_wrapper_file_write_ex;
|
||||
File->FlushEx = Img ? ventoy_wrapper_file_flush_ex_img : ventoy_wrapper_file_flush_ex;
|
||||
|
||||
if (Img)
|
||||
{
|
||||
File->FlushEx = g_img_flush_func[Index];
|
||||
}
|
||||
else
|
||||
{
|
||||
File->FlushEx = ventoy_wrapper_file_flush_ex;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
@ -1419,6 +1507,7 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open
|
|||
CHAR8 TmpName[256];
|
||||
CHAR8 OldName[256];
|
||||
ventoy_virt_chunk *virt = NULL;
|
||||
ventoy_grub_param_file_replace *replace = NULL;
|
||||
|
||||
debug("## ventoy_wrapper_file_open <%s> ", Name);
|
||||
|
||||
|
@ -1449,7 +1538,7 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open
|
|||
{
|
||||
g_original_fclose(*New);
|
||||
*New = &g_efi_file_replace.WrapperHandle;
|
||||
ventoy_wrapper_file_procotol(*New, FALSE);
|
||||
ventoy_wrapper_file_procotol(*New, FALSE, 0);
|
||||
|
||||
virt = g_virt_chunk + g_file_replace_list->new_file_virtual_id;
|
||||
|
||||
|
@ -1475,15 +1564,18 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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)
|
||||
for (i = 0; g_img_replace_list && i < VTOY_MAX_CONF_REPLACE; i++)
|
||||
{
|
||||
AsciiSPrint(TmpName, sizeof(TmpName), "%s", Name);
|
||||
for (j = 0; j < g_img_replace_list->old_file_cnt; j++)
|
||||
replace = g_img_replace_list + i;
|
||||
if (replace->magic != GRUB_IMG_REPLACE_MAGIC || replace->new_file_virtual_id >= g_virt_chunk_num)
|
||||
{
|
||||
AsciiStrCpyS(OldName, sizeof(OldName), g_img_replace_list[i].old_file_name[j]);
|
||||
continue;
|
||||
}
|
||||
|
||||
AsciiSPrint(TmpName, sizeof(TmpName), "%s", Name);
|
||||
for (j = 0; j < replace->old_file_cnt; j++)
|
||||
{
|
||||
AsciiStrCpyS(OldName, sizeof(OldName), replace->old_file_name[j]);
|
||||
if ((0 == AsciiStrCmp(OldName, TmpName)) ||
|
||||
(AsciiStrnCmp(OldName, "\\loader\\entries\\", 16) == 0 &&
|
||||
AsciiStrCmp(OldName + 16, TmpName) == 0
|
||||
|
@ -1491,31 +1583,31 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open
|
|||
)
|
||||
{
|
||||
g_original_fclose(*New);
|
||||
*New = &g_img_file_replace.WrapperHandle;
|
||||
ventoy_wrapper_file_procotol(*New, TRUE);
|
||||
*New = &(g_img_file_replace[i].WrapperHandle);
|
||||
ventoy_wrapper_file_procotol(*New, TRUE, i);
|
||||
|
||||
virt = g_virt_chunk + g_img_replace_list->new_file_virtual_id;
|
||||
virt = g_virt_chunk + replace->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;
|
||||
g_img_file_replace[i].BlockIoSectorStart = virt->mem_sector_start;
|
||||
g_img_file_replace[i].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);
|
||||
g_img_file_replace[i].BlockIoSectorStart, Sectors, Sectors * 2048);
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (StrCmp(Name, L"\\loader\\entries") == 0)
|
||||
{
|
||||
(*New)->Open = ventoy_wrapper_file_open;
|
||||
}
|
||||
if (g_img_replace_list && StrCmp(Name, L"\\loader\\entries") == 0)
|
||||
{
|
||||
(*New)->Open = ventoy_wrapper_file_open;
|
||||
}
|
||||
|
||||
return Status;
|
||||
|
|
|
@ -28,6 +28,8 @@ typedef int (*grub_env_set_pf)(const char *name, const char *val);
|
|||
typedef const char * (*grub_env_get_pf)(const char *name);
|
||||
typedef int (*grub_env_printf_pf)(const char *fmt, ...);
|
||||
|
||||
#define VTOY_MAX_CONF_REPLACE 2
|
||||
|
||||
typedef struct ventoy_grub_param_file_replace
|
||||
{
|
||||
UINT32 magic;
|
||||
|
@ -41,7 +43,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;
|
||||
#pragma pack()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue