1.0.14 release

pull/253/head v1.0.14
longpanda 4 years ago
parent 42990058ed
commit 1cbe4c81b4

@ -52,6 +52,8 @@ static grub_env_get_pf grub_env_get = NULL;
ventoy_grub_param_file_replace *g_file_replace_list = NULL;
ventoy_efi_file_replace g_efi_file_replace;
STATIC BOOLEAN g_hook_keyboard = FALSE;
CHAR16 gFirstTryBootFile[256] = {0};
/* Boot filename */
@ -191,11 +193,12 @@ static void EFIAPI ventoy_dump_chain(ventoy_chain_head *chain)
debug("os_param->vtoy_img_size=<%llu>", chain->os_param.vtoy_img_size);
debug("os_param->vtoy_img_location_addr=<0x%llx>", chain->os_param.vtoy_img_location_addr);
debug("os_param->vtoy_img_location_len=<%u>", chain->os_param.vtoy_img_location_len);
debug("os_param->vtoy_reserved=<%u %u %u %u>",
debug("os_param->vtoy_reserved=<%u %u %u %u %u>",
g_os_param_reserved[0],
g_os_param_reserved[1],
g_os_param_reserved[2],
g_os_param_reserved[3]
g_os_param_reserved[3],
g_os_param_reserved[4]
);
ventoy_debug_pause();
@ -585,6 +588,13 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
g_fixup_iso9660_secover_enable = TRUE;
}
if (g_os_param_reserved[2] == 1 && g_os_param_reserved[4] != 1)
{
g_hook_keyboard = TRUE;
}
debug("internal param: secover:%u keyboard:%u", g_fixup_iso9660_secover_enable, g_hook_keyboard);
for (i = 0; i < sizeof(ventoy_os_param); i++)
{
chksum += *((UINT8 *)(&(g_chain->os_param)) + i);
@ -707,16 +717,26 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
if (gDebugPrint)
{
gST->ConIn->Reset(gST->ConIn, FALSE);
//ventoy_wrapper_system();
}
if (g_file_replace_list && g_file_replace_list->magic == GRUB_FILE_REPLACE_MAGIC)
{
ventoy_wrapper_push_openvolume(pFile->OpenVolume);
pFile->OpenVolume = ventoy_wrapper_open_volume;
}
if (g_hook_keyboard)
{
ventoy_hook_keyboard_start();
}
/* can't add debug print here */
//ventoy_wrapper_system();
Status = gBS->StartImage(Image, NULL, NULL);
if (g_hook_keyboard)
{
ventoy_hook_keyboard_stop();
}
if (EFI_ERROR(Status))
{
debug("Failed to start image %r", Status);
@ -743,7 +763,6 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI VentoyEfiMain
(
IN EFI_HANDLE ImageHandle,
@ -751,6 +770,7 @@ EFI_STATUS EFIAPI VentoyEfiMain
)
{
EFI_STATUS Status = EFI_SUCCESS;
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *Protocol;
g_sector_flag_num = 512; /* initial value */
@ -760,6 +780,12 @@ EFI_STATUS EFIAPI VentoyEfiMain
return EFI_OUT_OF_RESOURCES;
}
Status = gBS->HandleProtocol(gST->ConsoleInHandle, &gEfiSimpleTextInputExProtocolGuid, (VOID **)&Protocol);
if (EFI_SUCCESS == Status)
{
g_con_simple_input_ex = Protocol;
}
gST->ConOut->ClearScreen(gST->ConOut);
ventoy_clear_input();

@ -291,7 +291,6 @@ typedef struct ventoy_system_wrapper
extern BOOLEAN gDebugPrint;
VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...);
EFI_STATUS EFIAPI ventoy_wrapper_system(VOID);
EFI_STATUS EFIAPI ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL *File);
EFI_STATUS EFIAPI ventoy_block_io_read
(
IN EFI_BLOCK_IO_PROTOCOL *This,
@ -317,6 +316,7 @@ extern BOOLEAN gMemdiskMode;
extern UINTN g_iso_buf_size;
extern ventoy_grub_param_file_replace *g_file_replace_list;
extern BOOLEAN g_fixup_iso9660_secover_enable;
extern EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *g_con_simple_input_ex;
EFI_STATUS EFIAPI ventoy_wrapper_open_volume
(
@ -325,6 +325,8 @@ EFI_STATUS EFIAPI ventoy_wrapper_open_volume
);
EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 ImgSize);
EFI_STATUS EFIAPI ventoy_wrapper_push_openvolume(IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME OpenVolume);
EFI_STATUS ventoy_hook_keyboard_start(VOID);
EFI_STATUS ventoy_hook_keyboard_stop(VOID);
#endif

@ -36,6 +36,10 @@
#include <Protocol/SimpleFileSystem.h>
#include <Ventoy.h>
#define PROCOTOL_SLEEP_SECONDS 0
#define debug_sleep() if (PROCOTOL_SLEEP_SECONDS) sleep(PROCOTOL_SLEEP_SECONDS)
STATIC ventoy_system_wrapper g_system_wrapper;
static struct well_known_guid g_efi_well_known_guids[] =
@ -84,183 +88,6 @@ static const char * ventoy_get_guid_name(EFI_GUID *guid)
return gEfiGuidName;
}
EFI_STATUS EFIAPI
ventoy_wrapper_fs_open(EFI_FILE_HANDLE This, EFI_FILE_HANDLE *New, CHAR16 *Name, UINT64 Mode, UINT64 Attributes)
{
(VOID)This;
(VOID)New;
(VOID)Name;
(VOID)Mode;
(VOID)Attributes;
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI
ventoy_wrapper_file_open_ex(EFI_FILE_HANDLE This, EFI_FILE_HANDLE *New, CHAR16 *Name, UINT64 Mode, UINT64 Attributes, EFI_FILE_IO_TOKEN *Token)
{
return ventoy_wrapper_fs_open(This, New, Name, Mode, Attributes);
}
EFI_STATUS EFIAPI
ventoy_wrapper_file_delete(EFI_FILE_HANDLE This)
{
(VOID)This;
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI
ventoy_wrapper_file_set_info(EFI_FILE_HANDLE This, EFI_GUID *Type, UINTN Len, VOID *Data)
{
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI
ventoy_wrapper_file_flush(EFI_FILE_HANDLE This)
{
(VOID)This;
return EFI_SUCCESS;
}
/* Ex version */
EFI_STATUS EFIAPI
ventoy_wrapper_file_flush_ex(EFI_FILE_HANDLE This, EFI_FILE_IO_TOKEN *Token)
{
(VOID)This;
(VOID)Token;
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI
ventoy_wrapper_file_write(EFI_FILE_HANDLE This, UINTN *Len, VOID *Data)
{
(VOID)This;
(VOID)Len;
(VOID)Data;
return EFI_WRITE_PROTECTED;
}
EFI_STATUS EFIAPI
ventoy_wrapper_file_write_ex(IN EFI_FILE_PROTOCOL *This, IN OUT EFI_FILE_IO_TOKEN *Token)
{
return ventoy_wrapper_file_write(This, &(Token->BufferSize), Token->Buffer);
}
static EFI_STATUS EFIAPI
ventoy_wrapper_file_close(EFI_FILE_HANDLE This)
{
(VOID)This;
return EFI_SUCCESS;
}
static EFI_STATUS EFIAPI
ventoy_wrapper_file_set_pos(EFI_FILE_HANDLE This, UINT64 Position)
{
(VOID)This;
g_efi_file_replace.CurPos = Position;
return EFI_SUCCESS;
}
static EFI_STATUS EFIAPI
ventoy_wrapper_file_get_pos(EFI_FILE_HANDLE This, UINT64 *Position)
{
(VOID)This;
*Position = g_efi_file_replace.CurPos;
return EFI_SUCCESS;
}
static EFI_STATUS EFIAPI
ventoy_wrapper_file_get_info(EFI_FILE_HANDLE This, EFI_GUID *Type, UINTN *Len, VOID *Data)
{
EFI_FILE_INFO *Info = (EFI_FILE_INFO *) Data;
debug("ventoy_wrapper_file_get_info ... %u", *Len);
if (!CompareGuid(Type, &gEfiFileInfoGuid))
{
return EFI_INVALID_PARAMETER;
}
if (*Len == 0)
{
*Len = 384;
return EFI_BUFFER_TOO_SMALL;
}
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->Attribute = EFI_FILE_READ_ONLY;
//Info->FileName = EFI_FILE_READ_ONLY;
*Len = Info->Size;
return EFI_SUCCESS;
}
static EFI_STATUS EFIAPI
ventoy_wrapper_file_read(EFI_FILE_HANDLE This, UINTN *Len, VOID *Data)
{
EFI_LBA Lba;
UINTN ReadLen = *Len;
(VOID)This;
debug("ventoy_wrapper_file_read ... %u", *Len);
if (g_efi_file_replace.CurPos + ReadLen > g_efi_file_replace.FileSizeBytes)
{
ReadLen = g_efi_file_replace.FileSizeBytes - g_efi_file_replace.CurPos;
}
Lba = g_efi_file_replace.CurPos / 2048 + g_efi_file_replace.BlockIoSectorStart;
ventoy_block_io_read(NULL, 0, Lba, ReadLen, Data);
*Len = ReadLen;
g_efi_file_replace.CurPos += ReadLen;
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI
ventoy_wrapper_file_read_ex(IN EFI_FILE_PROTOCOL *This, IN OUT EFI_FILE_IO_TOKEN *Token)
{
return ventoy_wrapper_file_read(This, &(Token->BufferSize), Token->Buffer);
}
EFI_STATUS EFIAPI ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL *File)
{
File->Revision = EFI_FILE_PROTOCOL_REVISION2;
File->Open = ventoy_wrapper_fs_open;
File->Close = ventoy_wrapper_file_close;
File->Delete = ventoy_wrapper_file_delete;
File->Read = ventoy_wrapper_file_read;
File->Write = ventoy_wrapper_file_write;
File->GetPosition = ventoy_wrapper_file_get_pos;
File->SetPosition = ventoy_wrapper_file_set_pos;
File->GetInfo = ventoy_wrapper_file_get_info;
File->SetInfo = ventoy_wrapper_file_set_info;
File->Flush = ventoy_wrapper_file_flush;
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;
return EFI_SUCCESS;
}
STATIC EFI_STATUS EFIAPI ventoy_handle_protocol
(
IN EFI_HANDLE Handle,
@ -270,7 +97,7 @@ STATIC EFI_STATUS EFIAPI ventoy_handle_protocol
{
EFI_STATUS Status = EFI_SUCCESS;
debug("ventoy_handle_protocol:%a", ventoy_get_guid_name(Protocol));
debug("ventoy_handle_protocol:%a", ventoy_get_guid_name(Protocol)); debug_sleep();
Status = g_system_wrapper.OriHandleProtocol(Handle, Protocol, Interface);
if (CompareGuid(Protocol, &gEfiSimpleFileSystemProtocolGuid))
@ -280,7 +107,7 @@ STATIC EFI_STATUS EFIAPI ventoy_handle_protocol
pFile->OpenVolume(pFile, &FileProtocol);
debug("Handle FS Protocol: %p OpenVolume:%p, FileProtocol:%p, Open:%p",
trace("Handle FS Protocol: %p OpenVolume:%p, FileProtocol:%p, Open:%p",
pFile, pFile->OpenVolume, FileProtocol, FileProtocol->Open);
sleep(3);
@ -299,7 +126,7 @@ STATIC EFI_STATUS EFIAPI ventoy_open_protocol
IN UINT32 Attributes
)
{
debug("ventoy_open_protocol:%a", ventoy_get_guid_name(Protocol));
debug("ventoy_open_protocol:%a", ventoy_get_guid_name(Protocol)); debug_sleep();
return g_system_wrapper.OriOpenProtocol(Handle, Protocol, Interface, AgentHandle, ControllerHandle, Attributes);
}
@ -310,7 +137,7 @@ STATIC EFI_STATUS EFIAPI ventoy_locate_protocol
OUT VOID **Interface
)
{
debug("ventoy_locate_protocol:%a", ventoy_get_guid_name(Protocol));
debug("ventoy_locate_protocol:%a", ventoy_get_guid_name(Protocol)); debug_sleep();
return g_system_wrapper.OriLocateProtocol(Protocol, Registration, Interface);
}
@ -318,7 +145,7 @@ EFI_STATUS EFIAPI ventoy_wrapper_system(VOID)
{
ventoy_wrapper(gBS, g_system_wrapper, LocateProtocol, ventoy_locate_protocol);
ventoy_wrapper(gBS, g_system_wrapper, HandleProtocol, ventoy_handle_protocol);
ventoy_wrapper(gBS, g_system_wrapper, OpenProtocol, ventoy_open_protocol);
ventoy_wrapper(gBS, g_system_wrapper, OpenProtocol, ventoy_open_protocol);
return EFI_SUCCESS;
}

@ -57,6 +57,18 @@ UINT64 g_fixup_iso9660_secover_1st_secs = 0;
UINT64 g_fixup_iso9660_secover_cur_secs = 0;
UINT64 g_fixup_iso9660_secover_tot_secs = 0;
STATIC UINTN g_keyboard_hook_count = 0;
STATIC BOOLEAN g_blockio_start_record_bcd = FALSE;
STATIC BOOLEAN g_blockio_bcd_read_done = FALSE;
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *g_con_simple_input_ex = NULL;
STATIC EFI_INPUT_READ_KEY_EX g_org_read_key_ex = NULL;
STATIC EFI_INPUT_READ_KEY g_org_read_key = NULL;
#if 0
/* Block IO procotol */
#endif
EFI_STATUS EFIAPI ventoy_block_io_reset
(
IN EFI_BLOCK_IO_PROTOCOL *This,
@ -176,6 +188,14 @@ STATIC EFI_STATUS EFIAPI ventoy_read_iso_sector
}
}
if (g_blockio_start_record_bcd && FALSE == g_blockio_bcd_read_done)
{
if (*(UINT32 *)Buffer == 0x66676572)
{
g_blockio_bcd_read_done = TRUE;
}
}
return EFI_SUCCESS;
}
@ -194,6 +214,14 @@ EFI_STATUS EFIAPI ventoy_block_io_ramdisk_read
(VOID)MediaId;
CopyMem(Buffer, (char *)g_chain + (Lba * 2048), BufferSize);
if (g_blockio_start_record_bcd && FALSE == g_blockio_bcd_read_done)
{
if (*(UINT32 *)Buffer == 0x66676572)
{
g_blockio_bcd_read_done = TRUE;
}
}
return EFI_SUCCESS;
}
@ -548,7 +576,187 @@ EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 Im
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI ventoy_wrapper_file_open
#if 0
/* For file replace */
#endif
STATIC EFI_STATUS EFIAPI
ventoy_wrapper_fs_open(EFI_FILE_HANDLE This, EFI_FILE_HANDLE *New, CHAR16 *Name, UINT64 Mode, UINT64 Attributes)
{
(VOID)This;
(VOID)New;
(VOID)Name;
(VOID)Mode;
(VOID)Attributes;
return EFI_SUCCESS;
}
STATIC EFI_STATUS EFIAPI
ventoy_wrapper_file_open_ex(EFI_FILE_HANDLE This, EFI_FILE_HANDLE *New, CHAR16 *Name, UINT64 Mode, UINT64 Attributes, EFI_FILE_IO_TOKEN *Token)
{
return ventoy_wrapper_fs_open(This, New, Name, Mode, Attributes);
}
STATIC EFI_STATUS EFIAPI
ventoy_wrapper_file_delete(EFI_FILE_HANDLE This)
{
(VOID)This;
return EFI_SUCCESS;
}
STATIC EFI_STATUS EFIAPI
ventoy_wrapper_file_set_info(EFI_FILE_HANDLE This, EFI_GUID *Type, UINTN Len, VOID *Data)
{
return EFI_SUCCESS;
}
STATIC EFI_STATUS EFIAPI
ventoy_wrapper_file_flush(EFI_FILE_HANDLE This)
{
(VOID)This;
return EFI_SUCCESS;
}
/* Ex version */
STATIC EFI_STATUS EFIAPI
ventoy_wrapper_file_flush_ex(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)
{
(VOID)This;
(VOID)Len;
(VOID)Data;
return EFI_WRITE_PROTECTED;
}
STATIC EFI_STATUS EFIAPI
ventoy_wrapper_file_write_ex(IN EFI_FILE_PROTOCOL *This, IN OUT EFI_FILE_IO_TOKEN *Token)
{
return ventoy_wrapper_file_write(This, &(Token->BufferSize), Token->Buffer);
}
STATIC EFI_STATUS EFIAPI
ventoy_wrapper_file_close(EFI_FILE_HANDLE This)
{
(VOID)This;
return EFI_SUCCESS;
}
STATIC EFI_STATUS EFIAPI
ventoy_wrapper_file_set_pos(EFI_FILE_HANDLE This, UINT64 Position)
{
(VOID)This;
g_efi_file_replace.CurPos = Position;
return EFI_SUCCESS;
}
STATIC EFI_STATUS EFIAPI
ventoy_wrapper_file_get_pos(EFI_FILE_HANDLE This, UINT64 *Position)
{
(VOID)This;
*Position = g_efi_file_replace.CurPos;
return EFI_SUCCESS;
}
STATIC EFI_STATUS EFIAPI
ventoy_wrapper_file_get_info(EFI_FILE_HANDLE This, EFI_GUID *Type, UINTN *Len, VOID *Data)
{
EFI_FILE_INFO *Info = (EFI_FILE_INFO *) Data;
debug("ventoy_wrapper_file_get_info ... %u", *Len);
if (!CompareGuid(Type, &gEfiFileInfoGuid))
{
return EFI_INVALID_PARAMETER;
}
if (*Len == 0)
{
*Len = 384;
return EFI_BUFFER_TOO_SMALL;
}
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->Attribute = EFI_FILE_READ_ONLY;
//Info->FileName = EFI_FILE_READ_ONLY;
*Len = Info->Size;
return EFI_SUCCESS;
}
STATIC EFI_STATUS EFIAPI
ventoy_wrapper_file_read(EFI_FILE_HANDLE This, UINTN *Len, VOID *Data)
{
EFI_LBA Lba;
UINTN ReadLen = *Len;
(VOID)This;
debug("ventoy_wrapper_file_read ... %u", *Len);
if (g_efi_file_replace.CurPos + ReadLen > g_efi_file_replace.FileSizeBytes)
{
ReadLen = g_efi_file_replace.FileSizeBytes - g_efi_file_replace.CurPos;
}
Lba = g_efi_file_replace.CurPos / 2048 + g_efi_file_replace.BlockIoSectorStart;
ventoy_block_io_read(NULL, 0, Lba, ReadLen, Data);
*Len = ReadLen;
g_efi_file_replace.CurPos += ReadLen;
return EFI_SUCCESS;
}
STATIC EFI_STATUS EFIAPI
ventoy_wrapper_file_read_ex(IN EFI_FILE_PROTOCOL *This, IN OUT EFI_FILE_IO_TOKEN *Token)
{
return ventoy_wrapper_file_read(This, &(Token->BufferSize), Token->Buffer);
}
STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL *File)
{
File->Revision = EFI_FILE_PROTOCOL_REVISION2;
File->Open = ventoy_wrapper_fs_open;
File->Close = ventoy_wrapper_file_close;
File->Delete = ventoy_wrapper_file_delete;
File->Read = ventoy_wrapper_file_read;
File->Write = ventoy_wrapper_file_write;
File->GetPosition = ventoy_wrapper_file_get_pos;
File->SetPosition = ventoy_wrapper_file_set_pos;
File->GetInfo = ventoy_wrapper_file_get_info;
File->SetInfo = ventoy_wrapper_file_set_info;
File->Flush = ventoy_wrapper_file_flush;
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;
return EFI_SUCCESS;
}
STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open
(
EFI_FILE_HANDLE This,
EFI_FILE_HANDLE *New,
@ -629,3 +837,82 @@ EFI_STATUS EFIAPI ventoy_wrapper_push_openvolume(IN EFI_SIMPLE_FILE_SYSTEM_PROTO
return EFI_SUCCESS;
}
#if 0
/* For auto skip Windows 'Press any key to boot from CD or DVD ...' */
#endif
STATIC EFI_STATUS EFIAPI ventoy_wrapper_read_key_ex
(
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
OUT EFI_KEY_DATA *KeyData
)
{
/* only hook once before BCD file read */
if (g_keyboard_hook_count == 0 && g_blockio_bcd_read_done == FALSE)
{
g_keyboard_hook_count++;
KeyData->Key.ScanCode = SCAN_DELETE;
KeyData->Key.UnicodeChar = 0;
KeyData->KeyState.KeyShiftState = 0;
KeyData->KeyState.KeyToggleState = 0;
return EFI_SUCCESS;
}
return g_org_read_key_ex(This, KeyData);
}
EFI_STATUS EFIAPI ventoy_wrapper_read_key
(
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
OUT EFI_INPUT_KEY *Key
)
{
/* only hook once before BCD file read */
if (g_keyboard_hook_count == 0 && g_blockio_bcd_read_done == FALSE)
{
g_keyboard_hook_count++;
Key->ScanCode = SCAN_DELETE;
Key->UnicodeChar = 0;
return EFI_SUCCESS;
}
return g_org_read_key(This, Key);
}
EFI_STATUS ventoy_hook_keyboard_start(VOID)
{
g_blockio_start_record_bcd = TRUE;
g_blockio_bcd_read_done = FALSE;
g_keyboard_hook_count = 0;
if (g_con_simple_input_ex)
{
g_org_read_key_ex = g_con_simple_input_ex->ReadKeyStrokeEx;
g_con_simple_input_ex->ReadKeyStrokeEx = ventoy_wrapper_read_key_ex;
}
g_org_read_key = gST->ConIn->ReadKeyStroke;
gST->ConIn->ReadKeyStroke = ventoy_wrapper_read_key;
return EFI_SUCCESS;
}
EFI_STATUS ventoy_hook_keyboard_stop(VOID)
{
g_blockio_start_record_bcd = FALSE;
g_blockio_bcd_read_done = FALSE;
g_keyboard_hook_count = 0;
if (g_con_simple_input_ex)
{
g_con_simple_input_ex->ReadKeyStrokeEx = g_org_read_key_ex;
}
gST->ConIn->ReadKeyStroke = g_org_read_key;
return EFI_SUCCESS;
}

@ -38,7 +38,7 @@ int g_ventoy_menu_refresh = 0;
int g_ventoy_memdisk_mode = 0;
int g_ventoy_iso_raw = 0;
int g_ventoy_iso_uefi_drv = 0;
int g_ventoy_last_entry = 0;
int g_ventoy_last_entry = -1;
int g_ventoy_suppress_esc = 0;
int g_ventoy_menu_esc = 0;
int g_ventoy_fn_mutex = 0;

@ -69,6 +69,7 @@ img_iterator_node *g_img_iterator_tail = NULL;
grub_uint8_t g_ventoy_break_level = 0;
grub_uint8_t g_ventoy_debug_level = 0;
grub_uint8_t g_ventoy_chain_type = 0;
grub_uint8_t *g_ventoy_cpio_buf = NULL;
grub_uint32_t g_ventoy_cpio_size = 0;
cpio_newc_header *g_ventoy_initrd_head = NULL;
@ -90,6 +91,15 @@ static int g_tree_script_pos = 0;
static char *g_list_script_buf = NULL;
static int g_list_script_pos = 0;
static const char *g_menu_class[] =
{
"vtoyiso", "vtoywim", "vtoyefi", "vtoyimg"
};
static const char *g_menu_prefix[] =
{
"iso", "wim", "efi", "img"
};
void ventoy_debug(const char *fmt, ...)
{
@ -806,6 +816,12 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
{
type = img_type_wim;
}
#ifdef GRUB_MACHINE_EFI
else if (0 == grub_strcasecmp(filename + len - 4, ".efi"))
{
type = img_type_efi;
}
#endif
else
{
return 0;
@ -831,12 +847,12 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
}
}
grub_snprintf(img->path, sizeof(img->path), "%s%s", node->dir, img->name);
img->pathlen = grub_snprintf(img->path, sizeof(img->path), "%s%s", node->dir, img->name);
img->size = info->size;
if (0 == img->size)
{
img->size = ventoy_grub_get_file_size("%s/%s", g_iso_path, img->path);
img->size = ventoy_grub_get_file_size("%s/%s%s", g_iso_path, node->dir, filename);
}
if (img->size < VTOY_FILT_MIN_FILE_SIZE)
@ -876,6 +892,12 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
g_ventoy_img_count++;
img->alias = ventoy_plugin_get_menu_alias(img->path);
img->class = ventoy_plugin_get_menu_class(img->name);
if (!img->class)
{
img->class = g_menu_class[type];
}
img->menu_prefix = g_menu_prefix[type];
debug("Add %s%s to list %d\n", node->dir, filename, g_ventoy_img_count);
}
@ -1025,7 +1047,7 @@ static int ventoy_dynamic_tree_menu(img_iterator_node *node)
if (g_default_menu_mode == 0)
{
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos,
"menuentry \"%-10s [Return to ListView]\" VTOY_RET {\n "
"menuentry \"%-10s [Return to ListView]\" --class=\"vtoyret\" VTOY_RET {\n "
" echo 'return ...' \n"
"}\n", "<--");
}
@ -1034,11 +1056,11 @@ static int ventoy_dynamic_tree_menu(img_iterator_node *node)
{
node->dir[node->dirlen - 1] = 0;
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos,
"submenu \"%-10s [%s]\" {\n",
"submenu \"%-10s [%s]\" --class=\"vtoydir\" {\n",
"DIR", node->dir + offset);
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos,
"menuentry \"%-10s [../]\" VTOY_RET {\n "
"menuentry \"%-10s [../]\" --class=\"vtoyret\" VTOY_RET {\n "
" echo 'return ...' \n"
"}\n", "<--");
}
@ -1051,13 +1073,13 @@ static int ventoy_dynamic_tree_menu(img_iterator_node *node)
while ((img = ventoy_get_min_iso(node)) != NULL)
{
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos,
"menuentry \"%-10s %s%s\" --id=\"VID_%d\" {\n"
"menuentry \"%-10s %s%s\" --class=\"%s\" --id=\"VID_%d\" {\n"
" %s_%s \n"
"}\n",
grub_get_human_size(img->size, GRUB_HUMAN_SIZE_SHORT),
img->unsupport ? "[unsupported] " : "",
img->alias ? img->alias : img->name, img->id,
(img->type == img_type_iso) ? "iso" : "wim",
img->alias ? img->alias : img->name, img->class, img->id,
img->menu_prefix,
img->unsupport ? "unsupport_menuentry" : "common_menuentry");
}
@ -1077,8 +1099,11 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
grub_device_t dev = NULL;
img_info *cur = NULL;
img_info *tail = NULL;
img_info *default_node = NULL;
const char *strdata = NULL;
char *device_name = NULL;
const char *default_image = NULL;
int img_len = 0;
char buf[32];
img_iterator_node *node = NULL;
img_iterator_node *tmp = NULL;
@ -1188,22 +1213,45 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
if (g_default_menu_mode == 1)
{
vtoy_ssprintf(g_list_script_buf, g_list_script_pos,
"menuentry \"%s [Return to TreeView]\" VTOY_RET {\n "
"menuentry \"%s [Return to TreeView]\" --class=\"vtoyret\" VTOY_RET {\n "
" echo 'return ...' \n"
"}\n", "<--");
}
if (g_default_menu_mode == 0)
{
default_image = ventoy_get_env("VTOY_DEFAULT_IMAGE");
if (default_image)
{
img_len = grub_strlen(default_image);
}
}
for (cur = g_ventoy_img_list; cur; cur = cur->next)
{
vtoy_ssprintf(g_list_script_buf, g_list_script_pos,
"menuentry \"%s%s\" --id=\"VID_%d\" {\n"
"menuentry \"%s%s\" --class=\"%s\" --id=\"VID_%d\" {\n"
" %s_%s \n"
"}\n",
cur->unsupport ? "[unsupported] " : "",
cur->alias ? cur->alias : cur->name, cur->id,
(cur->type == img_type_iso) ? "iso" : "wim",
cur->alias ? cur->alias : cur->name, cur->class, cur->id,
cur->menu_prefix,
cur->unsupport ? "unsupport_menuentry" : "common_menuentry");
if (g_default_menu_mode == 0 && default_image && default_node == NULL)
{
if (img_len == cur->pathlen && grub_strcmp(default_image, cur->path) == 0)
{
default_node = cur;
}
}
}
if (default_node)
{
vtoy_ssprintf(g_list_script_buf, g_list_script_pos, "set default='VID_%d'\n", default_node->id);
}
g_list_script_buf[g_list_script_pos] = 0;
grub_snprintf(buf, sizeof(buf), "%d", g_ventoy_img_count);
@ -1421,6 +1469,7 @@ void ventoy_fill_os_param(grub_file_t file, ventoy_os_param *param)
{
char *pos;
const char *fs = NULL;
const char *cdprompt = NULL;
grub_uint32_t i;
grub_uint8_t chksum = 0;
grub_disk_t disk;
@ -1449,6 +1498,17 @@ void ventoy_fill_os_param(grub_file_t file, ventoy_os_param *param)
param->vtoy_reserved[2] = g_ventoy_chain_type;
/* Windows CD/DVD prompt 0:suppress 1:reserved */
param->vtoy_reserved[4] = 0;
if (g_ventoy_chain_type == 1) /* Windows */
{
cdprompt = ventoy_get_env("VTOY_WINDOWS_CD_PROMPT");
if (cdprompt && cdprompt[0] == '1' && cdprompt[1] == 0)
{
param->vtoy_reserved[4] = 1;
}
}
fs = ventoy_get_env("ventoy_fs_probe");
if (fs && grub_strcmp(fs, "udf") == 0)
{
@ -1905,7 +1965,7 @@ static grub_err_t ventoy_cmd_dump_img_list(grub_extcmd_context_t ctxt, int argc,
while (cur)
{
grub_printf("path:<%s>\n", cur->path);
grub_printf("path:<%s> id=%d\n", cur->path, cur->id);
grub_printf("name:<%s>\n\n", cur->name);
cur = cur->next;
}

@ -127,13 +127,18 @@ typedef struct ventoy_udf_override
#define img_type_iso 0
#define img_type_wim 1
#define img_type_efi 2
#define img_type_img 3
typedef struct img_info
{
int pathlen;
char path[512];
char name[256];
const char *alias;
const char *class;
const char *menu_prefix;
int id;
int type;
@ -623,6 +628,15 @@ typedef struct menu_alias
struct menu_alias *next;
}menu_alias;
typedef struct menu_class
{
int patlen;
char pattern[256];
char class[64];
struct menu_class *next;
}menu_class;
extern int g_ventoy_menu_esc;
extern int g_ventoy_suppress_esc;
extern int g_ventoy_last_entry;
@ -641,6 +655,7 @@ void ventoy_plugin_dump_auto_install(void);
int ventoy_fill_windows_rtdata(void *buf, char *isopath);
int ventoy_plugin_get_persistent_chunklist(const char *isopath, int index, ventoy_img_chunk_list *chunk_list);
const char * ventoy_plugin_get_menu_alias(const char *isopath);
const char * ventoy_plugin_get_menu_class(const char *isoname);
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);

@ -33,6 +33,7 @@
#include <grub/i18n.h>
#include <grub/net.h>
#include <grub/time.h>
#include <grub/font.h>
#include <grub/ventoy.h>
#include "ventoy_def.h"
@ -42,6 +43,7 @@ static char g_iso_disk_name[128];
static install_template *g_install_template_head = NULL;
static persistence_config *g_persistence_head = NULL;
static menu_alias *g_menu_alias_head = NULL;
static menu_class *g_menu_class_head = NULL;
static int ventoy_plugin_control_check(VTOY_JSON *json, const char *isodisk)
{
@ -114,6 +116,7 @@ static int ventoy_plugin_theme_check(VTOY_JSON *json, const char *isodisk)
{
int exist = 0;
const char *value;
VTOY_JSON *node;
value = vtoy_json_get_string_ex(json->pstChild, "file");
if (value)
@ -165,6 +168,29 @@ static int ventoy_plugin_theme_check(VTOY_JSON *json, const char *isodisk)
grub_printf("ventoy_color: %s\n", value);
}
node = vtoy_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "fonts");
if (node)
{
for (node = node->pstChild; node; node = node->pstNext)
{
if (node->enDataType == JSON_TYPE_STRING)
{
if (ventoy_check_file_exist("%s%s", isodisk, node->unData.pcStrVal))
{
grub_printf("%s [OK]\n", node->unData.pcStrVal);
}
else
{
grub_printf("%s [NOT EXIST]\n", node->unData.pcStrVal);
}
}
}
}
else
{
grub_printf("fonts NOT found\n");
}
return 0;
}
@ -172,6 +198,7 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
{
const char *value;
char filepath[256];
VTOY_JSON *node;
value = vtoy_json_get_string_ex(json->pstChild, "file");
if (value)
@ -227,6 +254,20 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
grub_env_set("VTLE_CLR", value);
}
node = vtoy_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "fonts");
if (node)
{
for (node = node->pstChild; node; node = node->pstNext)
{
if (node->enDataType == JSON_TYPE_STRING &&
ventoy_check_file_exist("%s%s", isodisk, node->unData.pcStrVal))
{
grub_snprintf(filepath, sizeof(filepath), "%s%s", isodisk, node->unData.pcStrVal);
grub_font_load(filepath);
}
}
}
return 0;
}
@ -612,7 +653,15 @@ static int ventoy_plugin_menualias_check(VTOY_JSON *json, const char *isodisk)
alias = vtoy_json_get_string_ex(pNode->pstChild, "alias");
if (iso && iso[0] == '/' && alias)
{
grub_printf("image: <%s>\n", iso);
if (ventoy_is_file_exist("%s%s", isodisk, iso))
{
grub_printf("image: <%s> [ OK ]\n", iso);
}
else
{
grub_printf("image: <%s> [ NOT EXIST ]\n", iso);
}
grub_printf("alias: <%s>\n\n", alias);
}
}
@ -672,6 +721,90 @@ static int ventoy_plugin_menualias_entry(VTOY_JSON *json, const char *isodisk)
return 0;
}
static int ventoy_plugin_menuclass_entry(VTOY_JSON *json, const char *isodisk)
{
const char *key = NULL;
const char *class = NULL;
VTOY_JSON *pNode = NULL;
menu_class *tail = NULL;
menu_class *node = NULL;
menu_class *next = NULL;
(void)isodisk;
if (json->enDataType != JSON_TYPE_ARRAY)
{
debug("Not array %d\n", json->enDataType);
return 0;
}
if (g_menu_class_head)
{
for (node = g_menu_class_head; node; node = next)
{
next = node->next;
grub_free(node);
}
g_menu_class_head = NULL;
}
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
{
key = vtoy_json_get_string_ex(pNode->pstChild, "key");
class = vtoy_json_get_string_ex(pNode->pstChild, "class");
if (key && class)
{
node = grub_zalloc(sizeof(menu_class));
if (node)
{
node->patlen = grub_snprintf(node->pattern, sizeof(node->pattern), "%s", key);
grub_snprintf(node->class, sizeof(node->class), "%s", class);
if (g_menu_class_head)
{
tail->next = node;
}
else
{
g_menu_class_head = node;
}
tail = node;
}
}
}
return 0;
}
static int ventoy_plugin_menuclass_check(VTOY_JSON *json, const char *isodisk)
{
const char *key = NULL;
const char *class = NULL;
VTOY_JSON *pNode = NULL;
(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)
{
key = vtoy_json_get_string_ex(pNode->pstChild, "key");
class = vtoy_json_get_string_ex(pNode->pstChild, "class");
if (key && class)
{
grub_printf("key: <%s>\n", key);
grub_printf("class: <%s>\n\n", class);
}
}
return 0;
}
static plugin_entry g_plugin_entries[] =
{
{ "control", ventoy_plugin_control_entry, ventoy_plugin_control_check },
@ -679,6 +812,7 @@ static plugin_entry g_plugin_entries[] =
{ "auto_install", ventoy_plugin_auto_install_entry, ventoy_plugin_auto_install_check },
{ "persistence", ventoy_plugin_persistence_entry, ventoy_plugin_persistence_check },
{ "menu_alias", ventoy_plugin_menualias_entry, ventoy_plugin_menualias_check },
{ "menu_class", ventoy_plugin_menuclass_entry, ventoy_plugin_menuclass_check },
};
static int ventoy_parse_plugin_config(VTOY_JSON *json, const char *isodisk)
@ -932,6 +1066,23 @@ const char * ventoy_plugin_get_menu_alias(const char *isopath)
return NULL;
}
const char * ventoy_plugin_get_menu_class(const char *isoname)
{
menu_class *node = NULL;
int len = (int)grub_strlen(isoname);
for (node = g_menu_class_head; node; node = node->next)
{
if (node->patlen <= len && grub_strstr(isoname, node->pattern))
{
return node->class;
}
}
return NULL;
}
grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, char **args)
{
int i = 0;

@ -45,6 +45,9 @@ static int g_wim_total_patch_count = 0;
static int g_wim_valid_patch_count = 0;
static wim_patch *g_wim_patch_head = NULL;
static grub_uint64_t g_suppress_wincd_override_offset = 0;
static grub_uint32_t g_suppress_wincd_override_data = 0;
grub_uint8_t g_temp_buf[512];
grub_ssize_t lzx_decompress ( const void *data, grub_size_t len, void *buf );
@ -923,13 +926,15 @@ grub_err_t ventoy_cmd_locate_wim_patch(grub_extcmd_context_t ctxt, int argc, cha
static grub_uint32_t ventoy_get_override_chunk_num(void)
{
grub_uint32_t chunk_num = 0;
if (g_iso_fs_type == 0)
{
/* ISO9660: */
/* per wim */
/* 1: file_size and file_offset */
/* 2: new wim file header */
return g_wim_valid_patch_count * 2;
chunk_num = g_wim_valid_patch_count * 2;
}
else
{
@ -941,8 +946,24 @@ static grub_uint32_t ventoy_get_override_chunk_num(void)
/* 1: file_size in file_entry or extend_file_entry */
/* 2: data_size and position in extend data short ad */
/* 3: new wim file header */
return g_wim_valid_patch_count * 3 + 1;
chunk_num = g_wim_valid_patch_count * 3 + 1;
}
if (g_suppress_wincd_override_offset > 0)
{
chunk_num++;
}
return chunk_num;
}
static void ventoy_fill_suppress_wincd_override_data(void *override)
{
ventoy_override_chunk *cur = (ventoy_override_chunk *)override;
cur->override_size = 4;
cur->img_offset = g_suppress_wincd_override_offset;
grub_memcpy(cur->override_data, &g_suppress_wincd_override_data, cur->override_size);
}
static void ventoy_windows_fill_override_data_iso9660( grub_uint64_t isosize, void *override)
@ -958,6 +979,12 @@ static void ventoy_windows_fill_override_data_iso9660( grub_uint64_t isosize,
cur = (ventoy_override_chunk *)override;
if (g_suppress_wincd_override_offset > 0)
{
ventoy_fill_suppress_wincd_override_data(cur);
cur++;
}
debug("ventoy_windows_fill_override_data_iso9660 %lu\n", (ulong)isosize);
for (node = g_wim_patch_head; node; node = node->next)
@ -1012,6 +1039,12 @@ static void ventoy_windows_fill_override_data_udf( grub_uint64_t isosize, voi
sector = (isosize + 2047) / 2048;
cur = (ventoy_override_chunk *)override;
if (g_suppress_wincd_override_offset > 0)
{
ventoy_fill_suppress_wincd_override_data(cur);
cur++;
}
debug("ventoy_windows_fill_override_data_udf %lu\n", (ulong)isosize);
@ -1182,6 +1215,61 @@ static int ventoy_windows_drive_map(ventoy_chain_head *chain)
return 0;
}
static int ventoy_suppress_windows_cd_prompt(void)
{
int rc = 1;
const char *cdprompt = NULL;
grub_uint64_t readpos = 0;
grub_file_t file = NULL;
grub_uint8_t data[32];
cdprompt = ventoy_get_env("VTOY_WINDOWS_CD_PROMPT");
if (cdprompt && cdprompt[0] == '1' && cdprompt[1] == 0)
{
debug("VTOY_WINDOWS_CD_PROMPT:<%s>\n", cdprompt);
return 0;
}
g_ventoy_case_insensitive = 1;
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s/boot/bootfix.bin", "(loop)");
g_ventoy_case_insensitive = 0;
if (!file)
{
debug("Failed to open %s\n", "bootfix.bin");
goto end;
}
grub_file_read(file, data, 32);
if (file->fs && file->fs->name && grub_strcmp(file->fs->name, "udf") == 0)
{
readpos = grub_udf_get_file_offset(file);
}
else
{
readpos = grub_iso9660_get_last_read_pos(file);
}
debug("bootfix.bin readpos:%lu (sector:%lu) data: %02x %02x %02x %02x\n",
(ulong)readpos, (ulong)readpos / 2048, data[24], data[25], data[26], data[27]);
if (*(grub_uint32_t *)(data + 24) == 0x13cd0080)
{
g_suppress_wincd_override_offset = readpos + 24;
g_suppress_wincd_override_data = 0x13cd00fd;
rc = 0;
}
debug("g_suppress_wincd_override_offset:%lu\n", (ulong)g_suppress_wincd_override_offset);
end:
check_free(file, grub_file_close);
return rc;
}
grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, char **args)
{
int unknown_image = 0;
@ -1250,11 +1338,18 @@ grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, c
}
}
g_suppress_wincd_override_offset = 0;
if (!ventoy_is_efi_os()) /* legacy mode */
{
ventoy_suppress_windows_cd_prompt();
}
img_chunk_size = g_img_chunk_list.cur_chunk * sizeof(ventoy_img_chunk);
if (ventoy_compatible || unknown_image)
{
size = sizeof(ventoy_chain_head) + img_chunk_size;
override_size = g_suppress_wincd_override_offset > 0 ? sizeof(ventoy_override_chunk) : 0;
size = sizeof(ventoy_chain_head) + img_chunk_size + override_size;
}
else
{
@ -1319,6 +1414,13 @@ grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, c
if (ventoy_compatible || unknown_image)
{
if (g_suppress_wincd_override_offset > 0)
{
chain->override_chunk_offset = chain->img_chunk_offset + img_chunk_size;
chain->override_chunk_num = 1;
ventoy_fill_suppress_wincd_override_data((char *)chain + chain->override_chunk_offset);
}
return 0;
}

@ -111,6 +111,7 @@ typedef struct ventoy_os_param
* vtoy_reserved[1]: vtoy_debug_level
* vtoy_reserved[2]: vtoy_chain_type 0:Linux 1:Windows
* vtoy_reserved[3]: vtoy_iso_format 0:iso9660 1:udf
* vtoy_reserved[4]: vtoy_windows_cd_prompt
*
*/
grub_uint8_t vtoy_reserved[32]; // Internal use by ventoy

@ -12,14 +12,15 @@ make install
PATH=$PATH:$VT_DIR/GRUB2/INSTALL/bin/:$VT_DIR/GRUB2/INSTALL/sbin/
net_modules_legacy="net tftp http"
all_modules_legacy="date drivemap blocklist ntldr search at_keyboard usb_keyboard gcry_md5 hashsum gzio xzio lzopio lspci pci ext2 xfs ventoy chain read halt iso9660 linux16 test true sleep reboot echo videotest videoinfo videotest_checksum video_colors video_cirrus video_bochs vga vbe video_fb font video gettext extcmd terminal linux minicmd help configfile tr trig boot biosdisk disk ls tar squash4 password_pbkdf2 all_video png jpeg part_msdos fat exfat ntfs loopback gzio normal udf gfxmenu gfxterm gfxterm_background gfxterm_menu"
all_modules_legacy="date drivemap blocklist ntldr search at_keyboard usb_keyboard gcry_md5 hashsum gzio xzio lzopio lspci pci ext2 xfs ventoy chain read halt iso9660 linux16 test true sleep reboot echo videotest videoinfo videotest_checksum video_colors video_cirrus video_bochs vga vbe video_fb font video gettext extcmd terminal linux minicmd help configfile tr trig boot biosdisk disk ls tar squash4 password_pbkdf2 all_video png jpeg part_gpt part_msdos fat exfat ntfs loopback gzio normal udf gfxmenu gfxterm gfxterm_background gfxterm_menu"
net_modules_uefi="efinet net tftp http"
all_modules_uefi="blocklist ventoy test search at_keyboard usb_keyboard gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux relocator jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop efi_uga video_bochs video_cirrus video video_fb gfxterm_background gfxterm_menu"
all_extra_modules="elf macho offsetio regexp file"
if [ "$1" = "uefi" ]; then
all_modules="$net_modules_uefi $all_modules_uefi"
all_modules="$net_modules_uefi $all_modules_uefi $all_extra_modules"
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi" --prefix '(,msdos2)/grub' --output "$VT_DIR/INSTALL/EFI/BOOT/grubx64_real.efi" --format 'x86_64-efi' --compression 'auto' $all_modules_uefi 'fat' 'part_msdos'
else
all_modules="$net_modules_legacy $all_modules_legacy"
@ -38,6 +39,11 @@ else
rm -f $VT_DIR/GRUB2/NBP/core.0
cp -a $VT_DIR/GRUB2/PXE/grub2/i386-pc/core.0 $VT_DIR/GRUB2/NBP/core.0 || exit 1
for md in $all_extra_modules; do
rm -f $VT_DIR/INSTALL/grub/i386-pc/${md}.mod
cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc/${md}.mod $VT_DIR/INSTALL/grub/i386-pc/
done
rm -f $VT_DIR/INSTALL/grub/i386-pc/boot.img
cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc/boot.img $VT_DIR/INSTALL/grub/i386-pc/boot.img || exit 1
fi

@ -19,19 +19,25 @@
. /ventoy/hook/ventoy-hook-lib.sh
if is_ventoy_hook_finished; then
exit 0
fi
vtlog "####### $0 $* ########"
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
while ! [ -e /dev/null ]; do
echo 'xxxxxxxxxx'
echo 'xxxxxxxxxx' > /dev/console
sleep 1
done
wait_for_usb_disk_ready
vtlog "... start inotifyd listen $vtHook ..."
$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $VTOY_PATH/hook/guix/ventoy-disk.sh /dev:n 2>&- &
vtdiskname=$(get_ventoy_disk_name)
if [ "$vtdiskname" = "unknown" ]; then
vtlog "ventoy disk not found"
PATH=$VTPATH_OLD
exit 0
fi
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
PATH=$VTPATH_OLD
set_ventoy_hook_finish

@ -0,0 +1,23 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
$VTOY_PATH/hook/adelie/disk-hook.sh &

@ -32,13 +32,14 @@ fi
#
# We do a trick for ATL series here.
# Use /dev/loop7 and wapper it as a cdrom with bind mount.
# Then the installer will accept /dev/loop7 as the install medium.
# Use /dev/vtCheatLoop and wapper it as a cdrom with bind mount.
# Then the installer will accept /dev/vtCheatLoop as the install medium.
#
ventoy_copy_device_mapper /dev/loop7
$BUSYBOX_PATH/mkdir -p /tmp/loop7/device/
echo 5 > /tmp/loop7/device/type
$BUSYBOX_PATH/mount --bind /tmp/loop7 /sys/block/loop7 >> $VTLOG 2>&1
vtCheatLoop=loop6
ventoy_copy_device_mapper /dev/$vtCheatLoop
$BUSYBOX_PATH/mkdir -p /tmp/$vtCheatLoop/device/
echo 5 > /tmp/$vtCheatLoop/device/type
$BUSYBOX_PATH/mount --bind /tmp/$vtCheatLoop /sys/block/$vtCheatLoop >> $VTLOG 2>&1
# OK finish

@ -0,0 +1,50 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
vtlog "######### $0 $* ############"
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
wait_for_usb_disk_ready
vtdiskname=$(get_ventoy_disk_name)
if [ "$vtdiskname" = "unknown" ]; then
vtlog "ventoy disk not found"
PATH=$VTPATH_OLD
exit 0
fi
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
blkdev_num_mknod=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
vtDM=$(ventoy_find_dm_id ${blkdev_num})
vtlog "blkdev_num=$blkdev_num blkdev_num_mknod=$blkdev_num_mknod vtDM=$vtDM"
if [ -b /dev/$vtDM ]; then
vtlog "dev already exist ..."
else
vtlog "mknode dev ..."
mknod -m 660 /dev/$vtDM b $blkdev_num_mknod
fi
PATH=$VTPATH_OLD

@ -26,6 +26,14 @@ if $GREP -q '^"$mount_handler"' /init; then
if [ -f /hooks/archiso ]; then
$SED '/while ! poll_device "${dev}"/a\ if /ventoy/busybox/sh /ventoy/hook/arch/ventoy-timeout.sh ${dev}; then break; fi' -i /hooks/archiso
fi
elif $GREP -q '^KEEP_SEARCHING' /init; then
echo 'KEEP_SEARCHING found ...' >> $VTLOG
$SED "/^KEEP_SEARCHING/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ovios-disk.sh " -i /init
$BUSYBOX_PATH/mkdir -p /dev
$BUSYBOX_PATH/mkdir -p /sys
$BUSYBOX_PATH/mount -t sysfs sys /sys
else
# some archlinux initramfs doesn't contain device-mapper udev rules file
ARCH_UDEV_DIR=$(ventoy_get_udev_conf_dir)

@ -32,4 +32,5 @@ if [ "$vtdiskname" = "unknown" ]; then
exit 0
fi
vtlog "${vtdiskname#/dev/}2 found..."
$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/udev_disk_hook.sh "${vtdiskname#/dev/}2"

@ -21,6 +21,8 @@
ventoy_os_install_dmsetup() {
vtlog "ventoy_os_install_dmsetup $1 ..."
vt_usb_disk=$1
# dump iso file location

@ -0,0 +1,26 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
$BUSYBOX_PATH/mkdir /dev
$BUSYBOX_PATH/mknod -m 0660 /dev/null c 1 3
$BUSYBOX_PATH/sh $VTOY_PATH/hook/guix/ventoy-disk.sh &

@ -19,24 +19,32 @@
. /ventoy/hook/ventoy-hook-lib.sh
if is_ventoy_hook_finished; then
vtlog "######### $0 $* ############"
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
wait_for_usb_disk_ready
vtdiskname=$(get_ventoy_disk_name)
if [ "$vtdiskname" = "unknown" ]; then
vtlog "ventoy disk not found"
PATH=$VTPATH_OLD
exit 0
fi
vtlog "##### INOTIFYD: $2/$3 is created ..."
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
if is_inotify_ventoy_part $3; then
vtlog "find ventoy partition ..."
$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh $3
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
vtDM=$(ventoy_find_dm_id ${blkdev_num})
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
blkdev_num_mknod=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
vtDM=$(ventoy_find_dm_id ${blkdev_num})
vtlog "This is $vtDM ..."
vtlog "blkdev_num=$blkdev_num blkdev_num_mknod=$blkdev_num_mknod vtDM=$vtDM"
set_ventoy_hook_finish
if [ -b /dev/$vtDM ]; then
vtlog "dev already exist ..."
else
vtlog "mknode dev ..."
mknod -m 660 /dev/$vtDM b $blkdev_num_mknod
fi
PATH=$VTPATH_OLD

@ -18,8 +18,3 @@
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
$BUSYBOX_PATH/mkdir /dev
$BUSYBOX_PATH/mknode -m 0666 /dev/null c 1 3
$BUSYBOX_PATH/nohup $VTOY_PATH/hook/guix/ventoy-waitdev.sh &

@ -19,6 +19,8 @@
. /ventoy/hook/ventoy-hook-lib.sh
vtCheatLoop=loop6
ventoy_os_install_dmsetup() {
vtlog "ventoy_os_install_dmsetup $1"
@ -50,9 +52,9 @@ ventoy_os_install_dmsetup() {
if is_ventoy_hook_finished || not_ventoy_disk "${1:0:-1}"; then
# /dev/loop7 come first
if [ "$1" = "loop7" ] && [ -b $VTOY_DM_PATH ]; then
ventoy_copy_device_mapper /dev/loop7
# /dev/vtCheatLoop come first
if [ "$1" = "$vtCheatLoop" ] && [ -b $VTOY_DM_PATH ]; then
ventoy_copy_device_mapper /dev/$vtCheatLoop
fi
exit 0
fi
@ -72,14 +74,14 @@ $BUSYBOX_PATH/mount $VTOY_DM_PATH /mnt/ventoy
#
# We do a trick for rhel6 series here.
# Use /dev/loop7 and wapper it as a removable cdrom with bind mount.
# Then the anaconda installer will accept /dev/loop7 as the install medium.
# Use /dev/$vtCheatLoop and wapper it as a removable cdrom with bind mount.
# Then the anaconda installer will accept /dev/$vtCheatLoop as the install medium.
#
ventoy_copy_device_mapper /dev/loop7
ventoy_copy_device_mapper /dev/$vtCheatLoop
$BUSYBOX_PATH/cp -a /sys/devices/virtual/block/loop7 /tmp/ >> $VTLOG 2>&1
echo 19 > /tmp/loop7/capability
$BUSYBOX_PATH/mount --bind /tmp/loop7 /sys/block/loop7 >> $VTLOG 2>&1
$BUSYBOX_PATH/cp -a /sys/devices/virtual/block/$vtCheatLoop /tmp/ >> $VTLOG 2>&1
echo 19 > /tmp/$vtCheatLoop/capability
$BUSYBOX_PATH/mount --bind /tmp/$vtCheatLoop /sys/block/$vtCheatLoop >> $VTLOG 2>&1
# OK finish
set_ventoy_hook_finish

@ -23,4 +23,6 @@ $BUSYBOX_PATH/mkdir -p /etc/anaconda.repos.d /mnt/ventoy
ventoy_print_yum_repo "ventoy" "file:///mnt/ventoy" > /etc/anaconda.repos.d/ventoy.repo
ventoy_add_udev_rule "$VTOY_PATH/hook/rhel6/udev_disk_hook.sh %k"
ventoy_add_kernel_udev_rule "loop7" "$VTOY_PATH/hook/rhel6/udev_disk_hook.sh %k"
#loop7 was used by loader
ventoy_add_kernel_udev_rule "loop6" "$VTOY_PATH/hook/rhel6/udev_disk_hook.sh %k"

@ -192,6 +192,10 @@ ventoy_get_os_type() {
echo 'android'; return
fi
if $GREP -q 'adelielinux' /proc/version; then
echo 'adelie'; return
fi
echo "default"
}
@ -218,7 +222,6 @@ if [ "$VTOY_BREAK_LEVEL" = "03" ] || [ "$VTOY_BREAK_LEVEL" = "13" ]; then
exec $BUSYBOX_PATH/sh
fi
####################################################################
# #
# Step 4 : Hand over to real init #
@ -235,7 +238,8 @@ if [ -f $VTOY_PATH/ventoy_persistent_map ]; then
fi
cd /
unset VTOY_PATH VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD
unset VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD
for vtinit in $user_rdinit /init /sbin/init /linuxrc; do
if [ -d /ventoy_rdroot ]; then
@ -246,6 +250,9 @@ for vtinit in $user_rdinit /init /sbin/init /linuxrc; do
fi
else
if [ -e "$vtinit" ];then
if [ -f "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh" ]; then
$BUSYBOX_PATH/sh "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh"
fi
exec "$vtinit"
fi
fi

Binary file not shown.

Binary file not shown.

@ -1,34 +1,34 @@
submenu 'Check plugin json configuration (ventoy.json)' {
submenu 'Check plugin json configuration (ventoy.json)' --class=debug_json {
menuentry 'Check global control plugin configuration' {
set pager=1
vt_check_plugin_json $iso_path control $iso_path
vt_check_plugin_json $vt_plugin_path control $iso_path
echo -e "\npress ENTER to exit ..."
read vtInputKey
unset pager
}
menuentry 'Check theme plugin configuration' {
menuentry 'Check theme plugin configuration' --class=debug_theme {
set pager=1
vt_check_plugin_json $iso_path theme $iso_path
vt_check_plugin_json $vt_plugin_path theme $iso_path
echo -e "\npress ENTER to exit ..."
read vtInputKey
unset pager
}
menuentry 'Check auto install plugin configuration' {
menuentry 'Check auto install plugin configuration' --class=debug_autoinstall {
set pager=1
vt_check_plugin_json $iso_path auto_install $iso_path
vt_check_plugin_json $vt_plugin_path auto_install $iso_path
echo -e "\npress ENTER to exit ..."
read vtInputKey
unset pager
}
menuentry 'Check persistence plugin configuration' {
menuentry 'Check persistence plugin configuration' --class=debug_persistence {
set pager=1
vt_check_plugin_json $iso_path persistence $iso_path
vt_check_plugin_json $vt_plugin_path persistence $iso_path
echo -e "\n############### dump persistence ###############"
vt_dump_persistence
@ -38,20 +38,29 @@ submenu 'Check plugin json configuration (ventoy.json)' {
unset pager
}
menuentry 'Check menu alias plugin configuration' {
menuentry 'Check menu alias plugin configuration' --class=debug_menualias {
set pager=1
vt_check_plugin_json $iso_path menu_alias $iso_path
vt_check_plugin_json $vt_plugin_path menu_alias $iso_path
echo -e "\npress ENTER to exit ..."
read vtInputKey
unset pager
}
menuentry 'Return to previous menu [Esc]' VTOY_RET {
menuentry 'Check menu class plugin configuration' --class=debug_menuclass {
set pager=1
vt_check_plugin_json $vt_plugin_path menu_class $iso_path
echo -e "\npress ENTER to exit ..."
read vtInputKey
unset pager
}
menuentry 'Return to previous menu [Esc]' --class=vtoyret VTOY_RET {
echo 'Return ...'
}
}
menuentry 'Return to previous menu [Esc]' VTOY_RET {
menuentry 'Return to previous menu [Esc]' --class=vtoyret VTOY_RET {
echo 'Return ...'
}

@ -152,7 +152,9 @@ function distro_specify_initrd_file_phase2 {
vt_linux_specify_initrd_file /live/initrd.img
elif [ -f (loop)/initrd.img ]; then
vt_linux_specify_initrd_file /initrd.img
elif [ -f (loop)/sysresccd/boot/x86_64/sysresccd.img ]; then
vt_linux_specify_initrd_file /sysresccd/boot/x86_64/sysresccd.img
fi
}
@ -337,6 +339,8 @@ function uefi_iso_memdisk {
terminal_output console
chainloader ${vtoy_path}/ventoy_x64.efi memdisk env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_iso_buf_addr}:size:${vtoy_iso_buf_size}
boot
terminal_output gfxterm
}
@ -502,12 +506,16 @@ function iso_common_menuentry {
fi
}
function iso_unsupport_menuentry {
function common_unsupport_menuentry {
echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
echo -e " 文件名中不能有中文或空格 \n"
echo -e "\n Will return to main menu after 10 seconds ...\n"
sleep 10
}
function iso_unsupport_menuentry {
common_unsupport_menuentry
}
function wim_common_menuentry {
vt_chosen_img_path chosen_path
@ -521,6 +529,7 @@ function wim_common_menuentry {
else
terminal_output console
chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
terminal_output gfxterm
fi
boot
else
@ -530,9 +539,20 @@ function wim_common_menuentry {
}
function wim_unsupport_menuentry {
echo -e "\n The name of the wim file could NOT contain space or non-ascii characters. \n"
echo -e "\n Will return to main menu after 10 seconds ...\n"
sleep 10
common_unsupport_menuentry
}
function efi_common_menuentry {
vt_chosen_img_path chosen_path
terminal_output console
chainloader ${iso_path}${chosen_path}
boot
terminal_output gfxterm
}
function efi_unsupport_menuentry {
common_unsupport_menuentry
}
#############################################################
@ -543,16 +563,13 @@ function wim_unsupport_menuentry {
#############################################################
#############################################################
set VENTOY_VERSION="1.0.13"
set VENTOY_VERSION="1.0.14"
# Default menu display mode, you can change it as you want.
# 0: List mode
# 1: TreeView mode
set VTOY_DEFAULT_MENU_MODE=0
#disable timeout
unset timeout
set VTOY_MEM_DISK_STR="[Memdisk]"
set VTOY_ISO_RAW_STR="Compatible Mode"
set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
@ -579,6 +596,13 @@ if [ "$vtoy_dev" = "tftp" ]; then
fi
done
loadfont ascii
if [ -f $iso_path/ventoy/ventoy.json ]; then
set vt_plugin_path=$iso_path
else
set vt_plugin_path=$prefix
vt_load_plugin $vt_plugin_path
fi
else
if [ "$prefix" = "(ventoydisk)/grub" ]; then
set vtoy_path=(ventoydisk)/ventoy
@ -589,6 +613,7 @@ else
set iso_path=($vtoy_dev,1)
set vtoy_efi_part=($vtoy_dev,2)
loadfont unicode
set vt_plugin_path=$iso_path
fi
@ -597,6 +622,12 @@ if [ -f $iso_path/ventoy/ventoy.json ]; then
vt_load_plugin $iso_path
fi
if [ -n "$VTOY_MENU_TIMEOUT" ]; then
set timeout=$VTOY_MENU_TIMEOUT
else
unset timeout
fi
if [ -f $iso_path/ventoy/ventoy_wimboot.img ]; then
vt_load_wimboot $iso_path/ventoy/ventoy_wimboot.img
elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
@ -631,8 +662,6 @@ else
terminal_output gfxterm
fi
#vtdebug on
#colect all image files (iso files)
set ventoy_img_count=0
vt_list_img $iso_path ventoy_img_count

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -1,6 +1,6 @@
if [ "$grub_platform" = "pc" ]; then
menuentry 'Search and boot Windows' {
menuentry 'Search and boot Windows' --class=boot_windows {
if search -n -s -f /bootmgr; then
ntldr /bootmgr
elif search -n -s -f /ntldr; then
@ -10,19 +10,27 @@ if [ "$grub_platform" = "pc" ]; then
fi
}
menuentry 'Boot the 1st local disk' {
menuentry 'Search and boot Grub4dos' --class=boot_g4d {
if search -n -s -f /grldr; then
ntldr /grldr
else
echo "Grub4dos NOT found ..."
fi
}
menuentry 'Boot the 1st local disk' --class=boot_disk {
set root=(hd0,1)
chainloader +1
boot
}
menuentry 'Boot the 2nd local disk' {
menuentry 'Boot the 2nd local disk' --class=boot_disk {
set root=(hd1,1)
chainloader +1
boot
}
menuentry 'Boot the 3rd local disk' {
menuentry 'Boot the 3rd local disk' --class=boot_disk {
set root=(hd2,1)
chainloader +1
boot
@ -30,7 +38,7 @@ if [ "$grub_platform" = "pc" ]; then
else
menuentry 'Search and boot Windows' {
menuentry 'Search and boot Windows' --class=boot_windows {
if search -n -s -f /EFI/Microsoft/Boot/bootmgfw.efi; then
terminal_output console
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
@ -40,7 +48,7 @@ else
fi
}
menuentry 'Search and boot BOOTX64.EFI' {
menuentry 'Search and boot BOOTX64.EFI' --class=boot_uefi {
if search -n -s -f /efi/boot/bootx64.efi; then
terminal_output console
chainloader /efi/boot/bootx64.efi
@ -52,6 +60,6 @@ else
fi
menuentry 'Return to menu [Esc]' VTOY_RET {
menuentry 'Return to menu [Esc]' --class=vtoyret VTOY_RET {
echo 'Return ...'
}

@ -1,15 +1,15 @@
menuentry Reboot {
menuentry Reboot --class=power_reboot {
echo -e '\n\nSystem is rebooting ... \n'
sleep 1
reboot
}
menuentry Halt {
menuentry Halt --class=power_halt {
echo -e '\n\nSystem is halting ... \n'
sleep 1
halt
}
menuentry 'Return to menu [Esc]' VTOY_RET {
menuentry 'Return to menu [Esc]' --class=vtoyret VTOY_RET {
echo 'Return ...'
}

@ -34,12 +34,11 @@ terminal-box: "terminal_box_*.png"
id = "__timeout__"
text = "@TIMEOUT_NOTIFICATION_SHORT@"
left = 95%
width = 48
top = 95%
height = 48
left = 20%
width = 60%
top = 85%
text_color = "#f2f2f2"
text_color = "red"
bar_style = "*"
highlight_style = "*"
}

@ -10,12 +10,13 @@ print_usage() {
echo ' -I force install ventoy to sdX (no matter installed or not)'
echo ''
echo ' OPTION: (optional)'
echo ' -s enable secure boot support (default is disabled)'
echo ' -r SIZE_MB preserve some space at the bottom of the disk (only for install)'
echo ' -s enable secure boot support (default is disabled)'
echo ''
}
RESERVE_SIZE_MB=0
while [ -n "$1" ]; do
if [ "$1" = "-i" ]; then
MODE="install"
@ -26,6 +27,10 @@ while [ -n "$1" ]; do
MODE="update"
elif [ "$1" = "-s" ]; then
SECUREBOOT="YES"
elif [ "$1" = "-r" ]; then
RESERVE_SPACE="YES"
shift
RESERVE_SIZE_MB=$1
else
if ! [ -b "$1" ]; then
vterr "$1 is NOT a valid device"
@ -53,6 +58,15 @@ if [ -e /sys/class/block/${DISK#/dev/}/start ]; then
exit 1
fi
if [ -n "$RESERVE_SPACE" ]; then
if echo $RESERVE_SIZE_MB | grep -q '^[0-9][0-9]*$'; then
vtdebug "User will reserve $RESERVE_SIZE_MB MB disk space"
else
vterr "$RESERVE_SIZE_MB is invalid for reserved space"
exit 1
fi
fi
if dd if="$DISK" of=/dev/null bs=1 count=1 >/dev/null 2>&1; then
vtdebug "root permission check ok ..."
else
@ -61,7 +75,7 @@ else
exit 1
fi
vtdebug "MODE=$MODE FORCE=$FORCE"
vtdebug "MODE=$MODE FORCE=$FORCE RESERVE_SPACE=$RESERVE_SPACE RESERVE_SIZE_MB=$RESERVE_SIZE_MB"
if ! check_tool_work_ok; then
vterr "Some tools can not run in current system. Please check log.txt for detail."
@ -124,12 +138,28 @@ if [ "$MODE" = "install" ]; then
exit 1
fi
if [ -n "$RESERVE_SPACE" ]; then
sum_size_mb=$(expr $RESERVE_SIZE_MB + $VENTOY_PART_SIZE_MB)
reserve_sector_num=$(expr $sum_size_mb \* 2048)
if [ $disk_sector_num -le $reserve_sector_num ]; then
vterr "Can't reserve $RESERVE_SIZE_MB MB space from $DISK"
exit 1
fi
fi
#Print disk info
echo "Disk : $DISK"
parted -s $DISK p 2>&1 | grep Model
echo "Size : $disk_size_gb GB"
echo ''
if [ -n "$RESERVE_SPACE" ]; then
echo "You will reserve $RESERVE_SIZE_MB MB disk space "
fi
echo ''
vtwarn "Attention:"
vtwarn "You will install Ventoy to $DISK."
vtwarn "All the data on the disk $DISK will be lost!!!"
@ -162,7 +192,7 @@ if [ "$MODE" = "install" ]; then
exit 1
fi
format_ventoy_disk $DISK $PARTTOOL
format_ventoy_disk $RESERVE_SIZE_MB $DISK $PARTTOOL
# format part1
if ventoy_is_linux64; then
@ -278,8 +308,7 @@ else
./tool/xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1
disk_sector_num=$(cat /sys/block/${DISK#/dev/}/size)
part2_start=$(expr $disk_sector_num - $VENTOY_SECTOR_NUM)
part2_start=$(cat /sys/class/block/${PART2#/dev/}/start)
./tool/xzcat ./ventoy/ventoy.disk.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start
sync

@ -2,6 +2,7 @@
#Ventoy partition 32MB
VENTOY_PART_SIZE=33554432
VENTOY_PART_SIZE_MB=32
VENTOY_SECTOR_SIZE=512
VENTOY_SECTOR_NUM=65536
@ -185,18 +186,28 @@ get_disk_ventoy_version() {
}
format_ventoy_disk() {
DISK=$1
PARTTOOL=$2
reserve_mb=$1
DISK=$2
PARTTOOL=$3
PART1=$(get_disk_part_name $DISK 1)
PART2=$(get_disk_part_name $DISK 2)
sector_num=$(cat /sys/block/${DISK#/dev/}/size)
part1_start_sector=2048
part1_end_sector=$(expr $sector_num - $VENTOY_SECTOR_NUM - 1)
export part2_start_sector=$(expr $part1_end_sector + 1)
part2_end_sector=$(expr $sector_num - 1)
part1_start_sector=2048
if [ $reserve_mb -gt 0 ]; then
reserve_sector_num=$(expr $reserve_mb \* 2048)
part1_end_sector=$(expr $sector_num - $reserve_sector_num - $VENTOY_SECTOR_NUM - 1)
else
part1_end_sector=$(expr $sector_num - $VENTOY_SECTOR_NUM - 1)
fi
part2_start_sector=$(expr $part1_end_sector + 1)
part2_end_sector=$(expr $part2_start_sector + $VENTOY_SECTOR_NUM - 1)
export part2_start_sector
vtdebug "part1_start_sector=$part1_start_sector part1_end_sector=$part1_end_sector"
vtdebug "part2_start_sector=$part2_start_sector part2_end_sector=$part2_end_sector"

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -1057,6 +1057,28 @@ static __asmcall void int13 ( struct i386_all_regs *ix86 ) {
return;
}
if (VENTOY_BOOT_FIXBIN_DRIVE == bios_drive && INT13_READ_SECTORS == command)
{
/* read sector 0 0x80 */
if (ix86->regs.dh == 0 && (ix86->regs.cl & 0x3f) == 1 && ix86->regs.al == 1)
{
userptr_t buffer;
buffer = real_to_user(ix86->segs.es, ix86->regs.bx);
if (buffer)
{
memset((void *)buffer, 0, 512);
}
ix86->regs.dl = 0x80;
ix86->regs.ah = 0;
/* Set OF to indicate to wrapper not to chain this call */
ix86->flags |= OF;
return;
}
}
// drive swap
if (g_drive_map1 >= 0x80 && g_drive_map2 >= 0x80)
{

@ -92,7 +92,7 @@ struct san_device {
uint8_t boot_catalog_sector[2048];
/** SAN paths */
struct san_path path[0];
struct san_path path[0];
};
/** SAN device flags */

@ -170,6 +170,7 @@ typedef struct ventoy_sector_flag
}ventoy_sector_flag;
#define VENTOY_BIOS_FAKE_DRIVE 0xFE
#define VENTOY_BOOT_FIXBIN_DRIVE 0xFD
extern int g_debug;
extern char *g_cmdline_copy;

Binary file not shown.

@ -51,12 +51,19 @@ typedef enum STR_ID
STR_MENU_OPTION,//19
STR_MENU_SECURE_BOOT,//20
STR_MENU_PART_CFG,//21
STR_BTN_OK,//22
STR_BTN_CANCEL,//23
STR_PRESERVE_SPACE,//24
STR_SPACE_VAL_INVALID,//25
STR_ID_MAX
}STR_ID;
extern BOOL g_SecureBoot;
#define VTOY_MENU_SECURE_BOOT 0xA000
#define VTOY_MENU_PART_CFG 0xA001
#define VTOY_MENU_LANGUAGE_BEGIN 0xB000

@ -304,7 +304,7 @@ static DWORD GetVentoyVolumeName(int PhyDrive, UINT32 StartSectorId, CHAR *NameB
PartOffset = 512ULL * StartSectorId;
Log("GetVentoyVolumeName PhyDrive %d PartOffset:%llu", PhyDrive, (ULONGLONG)PartOffset);
Log("GetVentoyVolumeName PhyDrive %d SectorStart:%u PartOffset:%llu", PhyDrive, StartSectorId, (ULONGLONG)PartOffset);
hVolume = FindFirstVolumeA(VolumeName, sizeof(VolumeName));
if (hVolume == INVALID_HANDLE_VALUE)
@ -798,7 +798,7 @@ static int VentoyFatDiskRead(uint32 Sector, uint8 *Buffer, uint32 SectorCount)
}
int GetVentoyVerInPhyDrive(const PHY_DRIVE_INFO *pDriveInfo, CHAR *VerBuf, size_t BufLen)
int GetVentoyVerInPhyDrive(const PHY_DRIVE_INFO *pDriveInfo, MBR_HEAD *pMBR, CHAR *VerBuf, size_t BufLen)
{
int rc = 0;
HANDLE hDrive;
@ -810,7 +810,7 @@ int GetVentoyVerInPhyDrive(const PHY_DRIVE_INFO *pDriveInfo, CHAR *VerBuf, size_
}
g_FatPhyDrive = hDrive;
g_Part2StartSec = (pDriveInfo->SizeInBytes - VENTOY_EFI_PART_SIZE) / 512;
g_Part2StartSec = pMBR->PartTbl[1].StartSectorId;
Log("Parse FAT fs...");
@ -1033,8 +1033,9 @@ static int FormatPart2Fat(HANDLE hDrive, UINT64 StartSectorId)
BOOL bRet;
unsigned char *data = NULL;
LARGE_INTEGER liCurrentPosition;
LARGE_INTEGER liNewPosition;
Log("FormatPart2Fat ...");
Log("FormatPart2Fat %llu...", StartSectorId);
rc = ReadWholeFileToBuf(VENTOY_FILE_DISK_IMG, 0, (void **)&data, &len);
if (rc)
@ -1044,7 +1045,9 @@ static int FormatPart2Fat(HANDLE hDrive, UINT64 StartSectorId)
}
liCurrentPosition.QuadPart = StartSectorId * 512;
SetFilePointerEx(hDrive, liCurrentPosition, &liCurrentPosition, FILE_BEGIN);
SetFilePointerEx(hDrive, liCurrentPosition, &liNewPosition, FILE_BEGIN);
Log("Set file pointer: %llu New pointer:%llu", liCurrentPosition.QuadPart, liNewPosition.QuadPart);
memset(g_part_img_buf, 0, sizeof(g_part_img_buf));
@ -1063,7 +1066,7 @@ static int FormatPart2Fat(HANDLE hDrive, UINT64 StartSectorId)
for (i = 0; i < VENTOY_EFI_PART_SIZE / SIZE_1MB; i++)
{
dwSize = 0;
bRet = WriteFile(hDrive, g_part_img_buf[0] + i * SIZE_1MB, SIZE_1MB, &dwSize, NULL);
bRet = WriteFile(hDrive, g_part_img_buf[0] + i * SIZE_1MB, SIZE_1MB, &dwSize, NULL);
Log("Write part data bRet:%u dwSize:%u code:%u", bRet, dwSize, LASTERR);
if (!bRet)
@ -1425,11 +1428,10 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive)
CHAR DriveName[] = "?:\\";
CHAR DriveLetters[MAX_PATH] = { 0 };
UINT32 StartSector;
UINT64 ReservedMB = 0;
MBR_HEAD BootImg;
MBR_HEAD MBR;
StartSector = (UINT32)(pPhyDrive->SizeInBytes / 512 - VENTOY_EFI_PART_SIZE / 512);
Log("UpdateVentoy2PhyDrive PhyDrive%d <<%s %s %dGB>>",
pPhyDrive->PhyDrive, pPhyDrive->VendorId, pPhyDrive->ProductId,
GetHumanReadableGBSize(pPhyDrive->SizeInBytes));
@ -1446,8 +1448,15 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive)
}
// Read MBR
SetFilePointer(hDrive, 0, NULL, FILE_BEGIN);
ReadFile(hDrive, &MBR, sizeof(MBR), &dwSize, NULL);
StartSector = MBR.PartTbl[1].StartSectorId;
Log("StartSector in PartTbl:%u", StartSector);
ReservedMB = (pPhyDrive->SizeInBytes / 512 - (StartSector + VENTOY_EFI_PART_SIZE / 512)) / 2048;
Log("Reserved Disk Space:%u MB", ReservedMB);
GetLettersBelongPhyDrive(pPhyDrive->PhyDrive, DriveLetters, sizeof(DriveLetters));
if (DriveLetters[0] == 0)

@ -427,10 +427,12 @@ static int VentoyFillLocation(UINT64 DiskSizeInBytes, UINT32 StartSectorId, UINT
int VentoyFillMBR(UINT64 DiskSizeBytes, MBR_HEAD *pMBR)
{
GUID Guid;
int ReservedValue;
UINT32 DiskSignature;
UINT32 DiskSectorCount;
UINT32 PartSectorCount;
UINT32 PartStartSector;
UINT32 ReservedSector;
VentoyGetLocalBootImg(pMBR);
@ -444,9 +446,21 @@ int VentoyFillMBR(UINT64 DiskSizeBytes, MBR_HEAD *pMBR)
DiskSectorCount = (UINT32)(DiskSizeBytes / 512);
ReservedValue = GetReservedSpaceInMB();
if (ReservedValue <= 0)
{
ReservedSector = 0;
}
else
{
ReservedSector = (UINT32)(ReservedValue * 2048);
}
Log("ReservedSector: %u", ReservedSector);
//Part1
PartStartSector = VENTOY_PART1_START_SECTOR;
PartSectorCount = DiskSectorCount - VENTOY_EFI_PART_SIZE / 512 - PartStartSector;
PartSectorCount = DiskSectorCount - ReservedSector - VENTOY_EFI_PART_SIZE / 512 - PartStartSector;
VentoyFillLocation(DiskSizeBytes, PartStartSector, PartSectorCount, pMBR->PartTbl);
pMBR->PartTbl[0].Active = 0x80; // bootable

@ -70,7 +70,7 @@ int ParseCmdLineOption(LPSTR lpCmdLine)
return 0;
}
static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes)
static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes, MBR_HEAD *pMBR)
{
int i;
BOOL bRet;
@ -121,30 +121,24 @@ static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes)
Log("PartTbl.EndCylinder = %u", MBR.PartTbl[i].EndCylinder);
}
if (MBR.PartTbl[2].SectorCount > 0 || MBR.PartTbl[3].SectorCount > 0)
{
Log("Part3 Part4 are not empty");
return FALSE;
}
PartStartSector = 2048;
PartSectorCount = (UINT32)((SizeBytes - VENTOY_EFI_PART_SIZE - SIZE_1MB) / 512);
if (MBR.PartTbl[0].StartSectorId != PartStartSector ||
MBR.PartTbl[0].SectorCount != PartSectorCount)
if (MBR.PartTbl[0].StartSectorId != 2048)
{
Log("Part1 not match %u %u", PartStartSector, PartSectorCount);
Log("Part1 not match %u", MBR.PartTbl[0].StartSectorId);
return FALSE;
}
PartStartSector = (UINT32)((SizeBytes - VENTOY_EFI_PART_SIZE) / 512);
PartStartSector = MBR.PartTbl[0].StartSectorId + MBR.PartTbl[0].SectorCount;
PartSectorCount = VENTOY_EFI_PART_SIZE / 512;
if (MBR.PartTbl[1].FsFlag != 0xEF ||
MBR.PartTbl[1].StartSectorId != PartStartSector ||
MBR.PartTbl[1].SectorCount != PartSectorCount)
{
Log("Part2 not match %u %u", PartStartSector, PartSectorCount);
Log("Part2 not match [0x%x 0x%x] [%u %u] [%u %u]",
MBR.PartTbl[1].FsFlag, 0xEF,
MBR.PartTbl[1].StartSectorId, PartStartSector,
MBR.PartTbl[1].SectorCount, PartSectorCount);
return FALSE;
}
@ -154,6 +148,7 @@ static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes)
return FALSE;
}
memcpy(pMBR, &MBR, sizeof(MBR_HEAD));
Log("PhysicalDrive%d is ventoy disk", PhyDrive);
return TRUE;
}
@ -167,6 +162,7 @@ static int FilterPhysicalDrive(PHY_DRIVE_INFO *pDriveList, DWORD DriveCount)
int Id = 0;
int LetterCount = 0;
PHY_DRIVE_INFO *CurDrive;
MBR_HEAD MBR;
int LogLetter[VENTOY_MAX_PHY_DRIVE];
int PhyDriveId[VENTOY_MAX_PHY_DRIVE];
@ -221,9 +217,9 @@ static int FilterPhysicalDrive(PHY_DRIVE_INFO *pDriveList, DWORD DriveCount)
}
}
if (IsVentoyPhyDrive(CurDrive->PhyDrive, CurDrive->SizeInBytes))
if (IsVentoyPhyDrive(CurDrive->PhyDrive, CurDrive->SizeInBytes, &MBR))
{
GetVentoyVerInPhyDrive(CurDrive, CurDrive->VentoyVersion, sizeof(CurDrive->VentoyVersion));
GetVentoyVerInPhyDrive(CurDrive, &MBR, CurDrive->VentoyVersion, sizeof(CurDrive->VentoyVersion));
}
}

@ -144,7 +144,7 @@ int GetRegDwordValue(HKEY Key, LPCSTR SubKey, LPCSTR ValueName, DWORD *pValue);
int GetPhysicalDriveCount(void);
int GetAllPhysicalDriveInfo(PHY_DRIVE_INFO *pDriveList, DWORD *pDriveCount);
int GetPhyDriveByLogicalDrive(int DriveLetter);
int GetVentoyVerInPhyDrive(const PHY_DRIVE_INFO *pDriveInfo, CHAR *VerBuf, size_t BufLen);
int GetVentoyVerInPhyDrive(const PHY_DRIVE_INFO *pDriveInfo, MBR_HEAD *pMBR, CHAR *VerBuf, size_t BufLen);
int Ventoy2DiskInit(void);
int Ventoy2DiskDestroy(void);
PHY_DRIVE_INFO * GetPhyDriveInfoById(int Id);
@ -159,5 +159,7 @@ int INIT unxz(unsigned char *in, int in_size,
unsigned char *out, int *in_used,
void(*error)(char *x));
void disk_io_set_param(HANDLE Handle, UINT64 SectorCount);
INT_PTR CALLBACK PartDialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
int GetReservedSpaceInMB(void);
#endif

@ -104,6 +104,7 @@
<ClCompile Include="ff14\source\ffsystem.c" />
<ClCompile Include="ff14\source\ffunicode.c" />
<ClCompile Include="Language.c" />
<ClCompile Include="PartDialog.c" />
<ClCompile Include="PhyDrive.c" />
<ClCompile Include="Utility.c" />
<ClCompile Include="Ventoy2Disk.c" />

@ -69,6 +69,9 @@
<ClCompile Include="ff14\source\ffunicode.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="PartDialog.c">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Ventoy2Disk.h">

Loading…
Cancel
Save