Compare commits

...

10 Commits

Author SHA1 Message Date
longpanda
3ca624f3ee 1.0.09 beta1 release 2020-05-04 23:47:01 +08:00
longpanda
d42bc35915 some missing 2020-05-03 07:58:27 +08:00
luzeagithub
39b5edc345 Rename DON_NOT_RUN_Ventoy2Disk_HERE.txt to DO_NOT_RUN_Ventoy2Disk_HERE.txt (#46) 2020-05-03 07:54:15 +08:00
longpanda
9c183ed416 add tip for installation 2020-05-01 07:55:04 +08:00
longpanda
8e0c630fe5 Merge branch 'master' of https://github.com/ventoy/Ventoy 2020-04-30 22:41:13 +08:00
longpanda
9f57cb3929 1.0.08 release 2020-04-30 22:40:42 +08:00
longpanda
525ef4f516 Update README.md 2020-04-29 09:24:10 +08:00
longpanda
212c9cdbc9 1.0.08beta2 2020-04-27 20:44:36 +08:00
longpanda
ad9a031092 1.0.08beta1 2020-04-26 22:37:38 +08:00
longpanda
d5b829f8e8 1.0.07 release 2020-04-24 21:58:07 +08:00
74 changed files with 3045 additions and 300 deletions

View File

@@ -53,15 +53,27 @@ ventoy_sector_flag *g_sector_flag = NULL;
UINT32 g_sector_flag_num = 0;
static grub_env_get_pf grub_env_get = NULL;
EFI_FILE_OPEN g_original_fopen = NULL;
EFI_FILE_CLOSE g_original_fclose = NULL;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME g_original_open_volume = NULL;
ventoy_grub_param_file_replace *g_file_replace_list = NULL;
ventoy_efi_file_replace g_efi_file_replace;
CHAR16 gFirstTryBootFile[256] = {0};
CONST CHAR16 gIso9660EfiDriverPath[] = ISO9660_EFI_DRIVER_PATH;
/* Boot filename */
UINTN gBootFileStartIndex = 1;
CONST CHAR16 *gEfiBootFileName[] =
{
L"@",
EFI_REMOVABLE_MEDIA_FILE_NAME,
L"\\EFI\\BOOT\\GRUBX64.EFI",
L"\\EFI\\BOOT\\BOOTx64.EFI",
L"\\EFI\\BOOT\\bootx64.efi",
L"\\efi\\boot\\bootx64.efi",
};
/* EFI block device vendor device path GUID */
@@ -886,6 +898,7 @@ static int ventoy_update_image_location(ventoy_os_param *param)
STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
{
UINT32 i = 0;
UINT32 old_cnt = 0;
UINTN size = 0;
UINT8 chksum = 0;
CHAR16 *pPos = NULL;
@@ -915,8 +928,33 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
gLoadIsoEfi = TRUE;
}
pPos = StrStr(pCmdLine, L"FirstTry=@");
if (pPos)
{
pPos += StrLen(L"FirstTry=");
for (i = 0; i < ARRAY_SIZE(gFirstTryBootFile); i++, pPos++)
{
if (*pPos != L' ' && *pPos != L'\t' && *pPos)
{
gFirstTryBootFile[i] = (*pPos == '@') ? '\\' : *pPos;
}
else
{
break;
}
}
gEfiBootFileName[0] = gFirstTryBootFile;
gBootFileStartIndex = 0;
}
debug("cmdline:<%s>", pCmdLine);
if (gFirstTryBootFile[0])
{
debug("First Try:<%s>", gFirstTryBootFile);
}
pPos = StrStr(pCmdLine, L"env_param=");
if (!pPos)
{
@@ -926,6 +964,18 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
pGrubParam = (ventoy_grub_param *)StrHexToUintn(pPos + StrLen(L"env_param="));
grub_env_get = pGrubParam->grub_env_get;
g_file_replace_list = &pGrubParam->file_replace;
old_cnt = g_file_replace_list->old_file_cnt;
debug("file replace: magic:0x%x virtid:%u name count:%u <%a> <%a> <%a> <%a>",
g_file_replace_list->magic,
g_file_replace_list->new_file_virtual_id,
old_cnt,
old_cnt > 0 ? g_file_replace_list->old_file_name[0] : "",
old_cnt > 1 ? g_file_replace_list->old_file_name[1] : "",
old_cnt > 2 ? g_file_replace_list->old_file_name[2] : "",
old_cnt > 3 ? g_file_replace_list->old_file_name[3] : ""
);
pPos = StrStr(pCmdLine, L"mem:");
g_chain = (ventoy_chain_head *)StrHexToUintn(pPos + 4);
@@ -970,8 +1020,85 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI ventoy_wrapper_file_open
(
EFI_FILE_HANDLE This,
EFI_FILE_HANDLE *New,
CHAR16 *Name,
UINT64 Mode,
UINT64 Attributes
)
{
UINT32 i = 0;
UINT32 j = 0;
UINT64 Sectors = 0;
EFI_STATUS Status = EFI_SUCCESS;
CHAR8 TmpName[256];
ventoy_virt_chunk *virt = NULL;
Status = g_original_fopen(This, New, Name, Mode, Attributes);
if (EFI_ERROR(Status))
{
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)
{
AsciiSPrint(TmpName, sizeof(TmpName), "%s", Name);
for (j = 0; j < 4; j++)
{
if (0 == AsciiStrCmp(g_file_replace_list[i].old_file_name[j], TmpName))
{
g_original_fclose(*New);
*New = &g_efi_file_replace.WrapperHandle;
ventoy_wrapper_file_procotol(*New);
virt = g_virt_chunk + g_file_replace_list->new_file_virtual_id;
Sectors = (virt->mem_sector_end - virt->mem_sector_start) + (virt->remap_sector_end - virt->remap_sector_start);
g_efi_file_replace.BlockIoSectorStart = virt->mem_sector_start;
g_efi_file_replace.FileSizeBytes = Sectors * 2048;
if (gDebugPrint)
{
debug("## ventoy_wrapper_file_open <%s> BlockStart:%lu Sectors:%lu Bytes:%lu", Name,
g_efi_file_replace.BlockIoSectorStart, Sectors, Sectors * 2048);
sleep(3);
}
return Status;
}
}
}
return Status;
}
EFI_STATUS EFIAPI ventoy_wrapper_open_volume
(
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
OUT EFI_FILE_PROTOCOL **Root
)
{
EFI_STATUS Status = EFI_SUCCESS;
Status = g_original_open_volume(This, Root);
if (!EFI_ERROR(Status))
{
g_original_fopen = (*Root)->Open;
g_original_fclose = (*Root)->Close;
(*Root)->Open = ventoy_wrapper_file_open;
}
return Status;
}
EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
{
UINTN t = 0;
UINTN i = 0;
UINTN j = 0;
UINTN Find = 0;
@@ -982,78 +1109,99 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *pFile = NULL;
EFI_DEVICE_PATH_PROTOCOL *pDevPath = NULL;
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid,
for (t = 0; t < 3; t++)
{
Count = 0;
Handles = NULL;
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid,
NULL, &Count, &Handles);
if (EFI_ERROR(Status))
{
return Status;
}
debug("ventoy_boot fs count:%u", Count);
for (i = 0; i < Count; i++)
{
Status = gBS->HandleProtocol(Handles[i], &gEfiSimpleFileSystemProtocolGuid, (VOID **)&pFile);
if (EFI_ERROR(Status))
{
continue;
return Status;
}
Status = gBS->OpenProtocol(Handles[i], &gEfiDevicePathProtocolGuid,
(VOID **)&pDevPath,
ImageHandle,
Handles[i],
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (EFI_ERROR(Status))
{
debug("Failed to open device path protocol %r", Status);
continue;
}
debug("ventoy_boot fs count:%u", Count);
debug("Handle:%p FS DP: <%s>", Handles[i], ConvertDevicePathToText(pDevPath, FALSE, FALSE));
if (CompareMem(gBlockData.Path, pDevPath, gBlockData.DevicePathCompareLen))
for (i = 0; i < Count; i++)
{
debug("Not ventoy disk file system");
continue;
}
for (j = 0; j < ARRAY_SIZE(gEfiBootFileName); j++)
{
Status = ventoy_load_image(ImageHandle, pDevPath, gEfiBootFileName[j],
StrSize(gEfiBootFileName[j]), &Image);
if (EFI_SUCCESS == Status)
Status = gBS->HandleProtocol(Handles[i], &gEfiSimpleFileSystemProtocolGuid, (VOID **)&pFile);
if (EFI_ERROR(Status))
{
continue;
}
debug("FS:%u Protocol:%p OpenVolume:%p", i, pFile, pFile->OpenVolume);
Status = gBS->OpenProtocol(Handles[i], &gEfiDevicePathProtocolGuid,
(VOID **)&pDevPath,
ImageHandle,
Handles[i],
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (EFI_ERROR(Status))
{
debug("Failed to open device path protocol %r", Status);
continue;
}
debug("Handle:%p FS DP: <%s>", Handles[i], ConvertDevicePathToText(pDevPath, FALSE, FALSE));
if (CompareMem(gBlockData.Path, pDevPath, gBlockData.DevicePathCompareLen))
{
debug("Not ventoy disk file system");
continue;
}
for (j = gBootFileStartIndex; j < ARRAY_SIZE(gEfiBootFileName); j++)
{
Status = ventoy_load_image(ImageHandle, pDevPath, gEfiBootFileName[j],
StrSize(gEfiBootFileName[j]), &Image);
if (EFI_SUCCESS == Status)
{
break;
}
debug("Failed to load image %r <%s>", Status, gEfiBootFileName[j]);
}
if (j >= ARRAY_SIZE(gEfiBootFileName))
{
continue;
}
Find++;
debug("Find boot file, now try to boot .....");
ventoy_debug_pause();
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)
{
g_original_open_volume = pFile->OpenVolume;
pFile->OpenVolume = ventoy_wrapper_open_volume;
}
Status = gBS->StartImage(Image, NULL, NULL);
if (EFI_ERROR(Status))
{
debug("Failed to start image %r", Status);
sleep(3);
gBS->UnloadImage(Image);
break;
}
debug("Failed to load image %r <%s>", Status, gEfiBootFileName[j]);
}
if (j >= ARRAY_SIZE(gEfiBootFileName))
{
continue;
}
FreePool(Handles);
Find++;
debug("Find boot file, now try to boot .....");
ventoy_debug_pause();
if (gDebugPrint)
if (Find == 0)
{
gST->ConIn->Reset(gST->ConIn, FALSE);
}
Status = gBS->StartImage(Image, NULL, NULL);
if (EFI_ERROR(Status))
{
debug("Failed to start image %r", Status);
sleep(3);
gBS->UnloadImage(Image);
break;
debug("Fs not found, now wait and retry...");
sleep(2);
}
}
FreePool(Handles);
if (Find == 0)
{
return EFI_NOT_FOUND;
@@ -1190,9 +1338,21 @@ EFI_STATUS EFIAPI VentoyEfiMain
Status = ventoy_boot(ImageHandle);
if (EFI_NOT_FOUND == Status)
{
gST->ConOut->OutputString(gST->ConOut, L"No bootfile found for UEFI!\r\n");
gST->ConOut->OutputString(gST->ConOut, L"Maybe the image does not support " VENTOY_UEFI_DESC L"!\r\n");
sleep(300);
if (!gLoadIsoEfi)
{
gLoadIsoEfi = TRUE;
ventoy_find_iso_disk_fs(ImageHandle);
ventoy_load_isoefi_driver(ImageHandle);
Status = ventoy_boot(ImageHandle);
}
if (EFI_NOT_FOUND == Status)
{
gST->ConOut->OutputString(gST->ConOut, L"No bootfile found for UEFI!\r\n");
gST->ConOut->OutputString(gST->ConOut, L"Maybe the image does not support " VENTOY_UEFI_DESC L"!\r\n");
sleep(60);
}
}
ventoy_clean_env();

View File

@@ -205,6 +205,7 @@ typedef struct vtoy_block_data
#define ISO9660_EFI_DRIVER_PATH L"\\ventoy\\iso9660_x64.efi"
#define debug(expr, ...) if (gDebugPrint) VtoyDebug("[VTOY] "expr"\r\n", ##__VA_ARGS__)
#define trace(expr, ...) VtoyDebug("[VTOY] "expr"\r\n", ##__VA_ARGS__)
#define sleep(sec) gBS->Stall(1000000 * (sec))
#define ventoy_debug_pause() \
@@ -219,9 +220,32 @@ if (gDebugPrint) \
typedef const char * (*grub_env_get_pf)(const char *name);
#pragma pack(1)
#define GRUB_FILE_REPLACE_MAGIC 0x1258BEEF
typedef struct ventoy_efi_file_replace
{
UINT64 BlockIoSectorStart;
UINT64 CurPos;
UINT64 FileSizeBytes;
EFI_FILE_PROTOCOL WrapperHandle;
}ventoy_efi_file_replace;
typedef struct ventoy_grub_param_file_replace
{
UINT32 magic;
char old_file_name[4][256];
UINT32 old_file_cnt;
UINT32 new_file_virtual_id;
}ventoy_grub_param_file_replace;
typedef struct ventoy_grub_param
{
grub_env_get_pf grub_env_get;
ventoy_grub_param_file_replace file_replace;
}ventoy_grub_param;
typedef struct ventoy_ram_disk
@@ -233,8 +257,44 @@ typedef struct ventoy_ram_disk
#pragma pack()
typedef struct well_known_guid
{
EFI_GUID *guid;
const char *name;
}well_known_guid;
typedef struct ventoy_system_wrapper
{
EFI_LOCATE_PROTOCOL NewLocateProtocol;
EFI_LOCATE_PROTOCOL OriLocateProtocol;
EFI_HANDLE_PROTOCOL NewHandleProtocol;
EFI_HANDLE_PROTOCOL OriHandleProtocol;
EFI_OPEN_PROTOCOL NewOpenProtocol;
EFI_OPEN_PROTOCOL OriOpenProtocol;
} ventoy_system_wrapper;
#define ventoy_wrapper(bs, wrapper, func, newfunc) \
{\
wrapper.Ori##func = bs->func;\
wrapper.New##func = newfunc;\
bs->func = wrapper.New##func;\
}
extern ventoy_efi_file_replace g_efi_file_replace;
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,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
OUT VOID *Buffer
);
#endif

View File

@@ -28,6 +28,7 @@
[Sources]
Ventoy.h
Ventoy.c
VentoyDebug.c
[Packages]
MdePkg/MdePkg.dec
@@ -42,6 +43,7 @@
[Guids]
gShellVariableGuid
gEfiVirtualCdGuid
gEfiFileInfoGuid
[Protocols]
gEfiLoadedImageProtocolGuid
@@ -49,3 +51,30 @@
gEfiDevicePathProtocolGuid
gEfiSimpleFileSystemProtocolGuid
gEfiRamDiskProtocolGuid
gEfiAbsolutePointerProtocolGuid
gEfiAcpiTableProtocolGuid
gEfiBlockIo2ProtocolGuid
gEfiBusSpecificDriverOverrideProtocolGuid
gEfiComponentNameProtocolGuid
gEfiComponentName2ProtocolGuid
gEfiDriverBindingProtocolGuid
gEfiDiskIoProtocolGuid
gEfiDiskIo2ProtocolGuid
gEfiGraphicsOutputProtocolGuid
gEfiHiiConfigAccessProtocolGuid
gEfiHiiFontProtocolGuid
gEfiLoadFileProtocolGuid
gEfiLoadFile2ProtocolGuid
gEfiLoadedImageProtocolGuid
gEfiLoadedImageDevicePathProtocolGuid
gEfiPciIoProtocolGuid
gEfiSerialIoProtocolGuid
gEfiSimpleTextInProtocolGuid
gEfiSimpleTextInputExProtocolGuid
gEfiSimpleTextOutProtocolGuid

View File

@@ -0,0 +1,325 @@
/******************************************************************************
* Ventoy.c
*
* 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/>.
*
*/
#include <Uefi.h>
#include <Library/DebugLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiApplicationEntryPoint.h>
#include <Protocol/LoadedImage.h>
#include <Guid/FileInfo.h>
#include <Guid/FileSystemInfo.h>
#include <Protocol/BlockIo.h>
#include <Protocol/RamDisk.h>
#include <Protocol/SimpleFileSystem.h>
#include <Ventoy.h>
STATIC ventoy_system_wrapper g_system_wrapper;
static struct well_known_guid g_efi_well_known_guids[] =
{
{ &gEfiAbsolutePointerProtocolGuid, "AbsolutePointer" },
{ &gEfiAcpiTableProtocolGuid, "AcpiTable" },
{ &gEfiBlockIoProtocolGuid, "BlockIo" },
{ &gEfiBlockIo2ProtocolGuid, "BlockIo2" },
{ &gEfiBusSpecificDriverOverrideProtocolGuid, "BusSpecificDriverOverride" },
{ &gEfiComponentNameProtocolGuid, "ComponentName" },
{ &gEfiComponentName2ProtocolGuid, "ComponentName2" },
{ &gEfiDevicePathProtocolGuid, "DevicePath" },
{ &gEfiDriverBindingProtocolGuid, "DriverBinding" },
{ &gEfiDiskIoProtocolGuid, "DiskIo" },
{ &gEfiDiskIo2ProtocolGuid, "DiskIo2" },
{ &gEfiGraphicsOutputProtocolGuid, "GraphicsOutput" },
{ &gEfiHiiConfigAccessProtocolGuid, "HiiConfigAccess" },
{ &gEfiHiiFontProtocolGuid, "HiiFont" },
{ &gEfiLoadFileProtocolGuid, "LoadFile" },
{ &gEfiLoadFile2ProtocolGuid, "LoadFile2" },
{ &gEfiLoadedImageProtocolGuid, "LoadedImage" },
{ &gEfiLoadedImageDevicePathProtocolGuid, "LoadedImageDevicePath"},
{ &gEfiPciIoProtocolGuid, "PciIo" },
{ &gEfiSerialIoProtocolGuid, "SerialIo" },
{ &gEfiSimpleFileSystemProtocolGuid, "SimpleFileSystem" },
{ &gEfiSimpleTextInProtocolGuid, "SimpleTextInput" },
{ &gEfiSimpleTextInputExProtocolGuid, "SimpleTextInputEx" },
{ &gEfiSimpleTextOutProtocolGuid, "SimpleTextOutput" },
};
STATIC CHAR8 gEfiGuidName[128];
static const char * ventoy_get_guid_name(EFI_GUID *guid)
{
UINTN i;
for (i = 0; i < ARRAY_SIZE(g_efi_well_known_guids); i++)
{
if (CompareGuid(g_efi_well_known_guids[i].guid, guid))
{
return g_efi_well_known_guids[i].name;
}
}
AsciiSPrint(gEfiGuidName, sizeof(gEfiGuidName), "%g", 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,
IN EFI_GUID *Protocol,
OUT VOID **Interface
)
{
EFI_STATUS Status = EFI_SUCCESS;
debug("ventoy_handle_protocol:%a", ventoy_get_guid_name(Protocol));
Status = g_system_wrapper.OriHandleProtocol(Handle, Protocol, Interface);
if (CompareGuid(Protocol, &gEfiSimpleFileSystemProtocolGuid))
{
EFI_FILE_PROTOCOL *FileProtocol = NULL;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *pFile = *((EFI_SIMPLE_FILE_SYSTEM_PROTOCOL **)(Interface));
pFile->OpenVolume(pFile, &FileProtocol);
debug("Handle FS Protocol: %p OpenVolume:%p, FileProtocol:%p, Open:%p",
pFile, pFile->OpenVolume, FileProtocol, FileProtocol->Open);
sleep(3);
}
return Status;
}
STATIC EFI_STATUS EFIAPI ventoy_open_protocol
(
IN EFI_HANDLE Handle,
IN EFI_GUID *Protocol,
OUT VOID **Interface, OPTIONAL
IN EFI_HANDLE AgentHandle,
IN EFI_HANDLE ControllerHandle,
IN UINT32 Attributes
)
{
debug("ventoy_open_protocol:%a", ventoy_get_guid_name(Protocol));
return g_system_wrapper.OriOpenProtocol(Handle, Protocol, Interface, AgentHandle, ControllerHandle, Attributes);
}
STATIC EFI_STATUS EFIAPI ventoy_locate_protocol
(
IN EFI_GUID *Protocol,
IN VOID *Registration, OPTIONAL
OUT VOID **Interface
)
{
debug("ventoy_locate_protocol:%a", ventoy_get_guid_name(Protocol));
return g_system_wrapper.OriLocateProtocol(Protocol, Registration, Interface);
}
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);
return EFI_SUCCESS;
}

View File

@@ -558,7 +558,7 @@ grub_fat_read_data (grub_disk_t disk, grub_fshelp_node_t node,
if (next_cluster >= node->data->cluster_eof_mark)
return ret;
if (next_cluster < 2 || next_cluster >= node->data->num_clusters)
if (next_cluster < 2 || (next_cluster - 2) >= node->data->num_clusters)
{
grub_error (GRUB_ERR_BAD_FS, "invalid cluster %u",
next_cluster);
@@ -964,6 +964,12 @@ grub_fat_dir (grub_device_t device, const char *path, grub_fs_dir_hook_t hook,
info.dir = !! (ctxt.dir.attr & GRUB_FAT_ATTR_DIRECTORY);
info.case_insensitive = 1;
#ifdef MODE_EXFAT
if (!info.dir)
info.size = ctxt.dir.file_size;
#endif
#ifdef MODE_EXFAT
if (!ctxt.dir.have_stream)
continue;
@@ -1409,7 +1415,7 @@ int grub_fat_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_i
return 0;
}
if (next_cluster < 2 || next_cluster >= node->data->num_clusters)
if (next_cluster < 2 || (next_cluster - 2) >= node->data->num_clusters)
{
grub_error (GRUB_ERR_BAD_FS, "invalid cluster %u", next_cluster);
return -1;
@@ -1445,4 +1451,3 @@ END:
}
#endif

View File

@@ -34,6 +34,12 @@
#include <grub/dl.h>
#include <grub/env.h>
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;
/* Time to delay after displaying an error message about a default/fallback
entry failing to boot. */
#define DEFAULT_ENTRY_ERROR_DELAY_MS 2500
@@ -577,16 +583,20 @@ print_countdown (struct grub_term_coordinate *pos, int n)
static int
run_menu (grub_menu_t menu, int nested, int *auto_boot)
{
const char *cmdstr;
grub_uint64_t saved_time;
int default_entry, current_entry;
int default_entry,current_entry;
int timeout;
enum timeout_style timeout_style;
default_entry = get_entry_number (menu, "default");
if (g_ventoy_last_entry >= 0 && g_ventoy_last_entry < menu->size) {
default_entry = g_ventoy_last_entry;
}
/* If DEFAULT_ENTRY is not within the menu entries, fall back to
the first entry. */
if (default_entry < 0 || default_entry >= menu->size)
else if (default_entry < 0 || default_entry >= menu->size)
default_entry = 0;
timeout = grub_menu_get_timeout ();
@@ -787,34 +797,76 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
}
goto refresh;
case GRUB_TERM_KEY_F2:
cmdstr = grub_env_get("VTOY_F2_CMD");
if (cmdstr)
{
menu_fini ();
grub_script_execute_sourcecode(cmdstr);
goto refresh;
}
break;
case GRUB_TERM_KEY_F3:
cmdstr = grub_env_get("VTOY_F3_CMD");
if (cmdstr)
{
menu_fini ();
grub_script_execute_sourcecode(cmdstr);
goto refresh;
}
break;
case GRUB_TERM_KEY_F4:
cmdstr = grub_env_get("VTOY_F4_CMD");
if (cmdstr)
{
menu_fini ();
grub_script_execute_sourcecode(cmdstr);
goto refresh;
}
break;
case GRUB_TERM_KEY_F5:
cmdstr = grub_env_get("VTOY_F5_CMD");
if (cmdstr)
{
menu_fini ();
grub_script_execute_sourcecode(cmdstr);
goto refresh;
}
break;
case GRUB_TERM_KEY_F6:
cmdstr = grub_env_get("VTOY_F6_CMD");
if (cmdstr)
{
menu_fini ();
grub_script_execute_sourcecode(cmdstr);
goto refresh;
}
break;
case GRUB_TERM_KEY_F7:
cmdstr = grub_env_get("VTOY_F7_CMD");
if (cmdstr)
{
menu_fini ();
grub_script_execute_sourcecode(cmdstr);
goto refresh;
}
break;
case GRUB_TERM_KEY_F1:
menu_fini ();
if (grub_env_get("VTOY_MEM_DISK")) {
grub_env_unset("VTOY_MEM_DISK");
}else {
grub_env_set("VTOY_MEM_DISK", grub_env_get("VTOY_MEM_DISK_STR"));
}
grub_env_set("VTOY_MENU_REFRESH", "1");
g_ventoy_memdisk_mode = 1 - g_ventoy_memdisk_mode;
g_ventoy_menu_refresh = 1;
goto refresh;
case GRUB_TERM_KEY_F3:
case (GRUB_TERM_CTRL | 'i'):
menu_fini ();
if (grub_env_get("VTOY_ISO_RAW")) {
grub_env_unset("VTOY_ISO_RAW");
}else {
grub_env_set("VTOY_ISO_RAW", grub_env_get("VTOY_ISO_RAW_STR"));
}
grub_env_set("VTOY_MENU_REFRESH", "1");
g_ventoy_iso_raw = 1 - g_ventoy_iso_raw;
g_ventoy_menu_refresh = 1;
goto refresh;
case GRUB_TERM_KEY_F4:
case (GRUB_TERM_CTRL | 'u'):
menu_fini ();
if (grub_env_get("VTOY_ISO_UEFI_DRV")) {
grub_env_unset("VTOY_ISO_UEFI_DRV");
}else {
grub_env_set("VTOY_ISO_UEFI_DRV", grub_env_get("VTOY_ISO_UEFI_DRV_STR"));
}
grub_env_set("VTOY_MENU_REFRESH", "1");
g_ventoy_iso_uefi_drv = 1 - g_ventoy_iso_uefi_drv;
g_ventoy_menu_refresh = 1;
goto refresh;
default:
@@ -897,6 +949,8 @@ show_menu (grub_menu_t menu, int nested, int autobooted)
if (boot_entry < 0)
break;
g_ventoy_last_entry = boot_entry;
e = grub_menu_get_entry (menu, boot_entry);
if (! e)
continue; /* Menu is empty. */

View File

@@ -52,11 +52,14 @@ int g_valid_initrd_count = 0;
static grub_file_t g_old_file;
char g_img_swap_tmp_buf[1024];
img_info g_img_swap_tmp;
img_info *g_ventoy_img_list = NULL;
int g_ventoy_img_count = 0;
grub_device_t g_enum_dev = NULL;
grub_fs_t g_enum_fs = NULL;
img_iterator_node g_img_iterator_head;
img_iterator_node *g_img_iterator_tail = NULL;
grub_uint8_t g_ventoy_break_level = 0;
grub_uint8_t g_ventoy_debug_level = 0;
@@ -65,12 +68,19 @@ grub_uint32_t g_ventoy_cpio_size = 0;
cpio_newc_header *g_ventoy_initrd_head = NULL;
grub_uint8_t *g_ventoy_runtime_buf = NULL;
ventoy_grub_param g_grub_param;
ventoy_grub_param *g_grub_param = NULL;
ventoy_guid g_ventoy_guid = VENTOY_GUID;
ventoy_img_chunk_list g_img_chunk_list;
static char *g_tree_script_buf = NULL;
static int g_tree_script_pos = 0;
static char *g_list_script_buf = NULL;
static int g_list_script_pos = 0;
void ventoy_debug(const char *fmt, ...)
{
va_list args;
@@ -530,7 +540,7 @@ static grub_err_t ventoy_cmd_check_compatible(grub_extcmd_context_t ctxt, int ar
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
static int ventoy_cmp_img(img_info *img1, img_info *img2)
int ventoy_cmp_img(img_info *img1, img_info *img2)
{
char *s1, *s2;
int c1 = 0;
@@ -560,15 +570,17 @@ static int ventoy_cmp_img(img_info *img1, img_info *img2)
return (c1 - c2);
}
static void ventoy_swap_img(img_info *img1, img_info *img2)
void ventoy_swap_img(img_info *img1, img_info *img2)
{
grub_memcpy(g_img_swap_tmp_buf, img1->name, sizeof(img1->name));
grub_memcpy(img1->name, img2->name, sizeof(img1->name));
grub_memcpy(img2->name, g_img_swap_tmp_buf, sizeof(img1->name));
grub_memcpy(&g_img_swap_tmp, img1, sizeof(img_info));
grub_memcpy(g_img_swap_tmp_buf, img1->path, sizeof(img1->path));
grub_memcpy(img1->path, img2->path, sizeof(img1->path));
grub_memcpy(img2->path, g_img_swap_tmp_buf, sizeof(img1->path));
grub_memcpy(img1, img2, sizeof(img_info));
img1->next = g_img_swap_tmp.next;
img1->prev = g_img_swap_tmp.prev;
g_img_swap_tmp.next = img2->next;
g_img_swap_tmp.prev = img2->prev;
grub_memcpy(img2, &g_img_swap_tmp, sizeof(img_info));
}
static int ventoy_img_name_valid(const char *filename, grub_size_t namelen)
@@ -591,11 +603,27 @@ static int ventoy_img_name_valid(const char *filename, grub_size_t namelen)
return 1;
}
static int ventoy_check_ignore_flag(const char *filename, const struct grub_dirhook_info *info, void *data)
{
if (0 == info->dir)
{
if (filename && filename[0] == '.' && 0 == grub_strncmp(filename, ".ventoyignore", 13))
{
*((int *)data) = 1;
return 0;
}
}
return 0;
}
static int ventoy_colect_img_files(const char *filename, const struct grub_dirhook_info *info, void *data)
{
int ignore = 0;
grub_size_t len;
img_info *img;
img_info *tail;
img_iterator_node *tmp;
img_iterator_node *new_node;
img_iterator_node *node = (img_iterator_node *)data;
@@ -609,14 +637,47 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
return 0;
}
new_node = grub_malloc(sizeof(img_iterator_node));
if (!ventoy_img_name_valid(filename, len))
{
return 0;
}
if (filename[0] == '$' && 0 == grub_strncmp(filename, "$RECYCLE.BIN", 12))
{
return 0;
}
new_node = grub_zalloc(sizeof(img_iterator_node));
if (new_node)
{
new_node->tail = node->tail;
grub_snprintf(new_node->dir, sizeof(new_node->dir), "%s%s/", node->dir, filename);
new_node->dirlen = grub_snprintf(new_node->dir, sizeof(new_node->dir), "%s%s/", node->dir, filename);
new_node->next = g_img_iterator_head.next;
g_img_iterator_head.next = new_node;
g_enum_fs->fs_dir(g_enum_dev, new_node->dir, ventoy_check_ignore_flag, &ignore);
if (ignore)
{
debug("Directory %s ignored...\n", new_node->dir);
grub_free(new_node);
return 0;
}
new_node->tail = node->tail;
new_node->parent = node;
if (!node->firstchild)
{
node->firstchild = new_node;
}
if (g_img_iterator_tail)
{
g_img_iterator_tail->next = new_node;
g_img_iterator_tail = new_node;
}
else
{
g_img_iterator_head.next = new_node;
g_img_iterator_tail = new_node;
}
}
}
else
@@ -646,6 +707,22 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
{
g_ventoy_img_list = img;
}
img->size = info->size;
img->id = g_ventoy_img_count;
img->parent = node;
if (node && NULL == node->firstiso)
{
node->firstiso = img;
}
node->isocnt++;
tmp = node->parent;
while (tmp)
{
tmp->isocnt++;
tmp = tmp->parent;
}
*((img_info **)(node->tail)) = img;
g_ventoy_img_count++;
@@ -734,6 +811,96 @@ int ventoy_fill_data(grub_uint32_t buflen, char *buffer)
return len;
}
static img_info * ventoy_get_min_iso(img_iterator_node *node)
{
img_info *minimg = NULL;
img_info *img = (img_info *)(node->firstiso);
while (img && (img_iterator_node *)(img->parent) == node)
{
if (img->select == 0 && (NULL == minimg || grub_strcmp(img->name, minimg->name) < 0))
{
minimg = img;
}
img = img->next;
}
if (minimg)
{
minimg->select = 1;
}
return minimg;
}
static img_iterator_node * ventoy_get_min_child(img_iterator_node *node)
{
img_iterator_node *Minchild = NULL;
img_iterator_node *child = node->firstchild;
while (child && child->parent == node)
{
if (child->select == 0 && (NULL == Minchild || grub_strcmp(child->dir, Minchild->dir) < 0))
{
Minchild = child;
}
child = child->next;
}
if (Minchild)
{
Minchild->select = 1;
}
return Minchild;
}
static int ventoy_dynamic_tree_menu(img_iterator_node *node)
{
int offset = 1;
img_info *img;
img_iterator_node *child = NULL;
if (node->isocnt == 0 || node->done == 1)
{
return 0;
}
if (node->parent && node->parent->dirlen < node->dirlen)
{
offset = node->parent->dirlen;
}
if (node != &g_img_iterator_head)
{
node->dir[node->dirlen - 1] = 0;
g_tree_script_pos += grub_snprintf(g_tree_script_buf + g_tree_script_pos, VTOY_MAX_SCRIPT_BUF - g_tree_script_pos,
"submenu \"%-10s [%s]\" {\n", "DIR", node->dir + offset);
}
while ((child = ventoy_get_min_child(node)) != NULL)
{
ventoy_dynamic_tree_menu(child);
}
while ((img = ventoy_get_min_iso(node)) != NULL)
{
g_tree_script_pos += grub_snprintf(g_tree_script_buf + g_tree_script_pos, VTOY_MAX_SCRIPT_BUF - g_tree_script_pos,
"menuentry \"%-10s %s\" --id=\"VID_%d\" {\n"
" common_menuentry \n"
"}\n",
grub_get_human_size(img->size, GRUB_HUMAN_SIZE_SHORT), img->name, img->id);
}
if (node != &g_img_iterator_head)
{
g_tree_script_pos += grub_snprintf(g_tree_script_buf + g_tree_script_pos, VTOY_MAX_SCRIPT_BUF - g_tree_script_pos, "}\n");
}
node->done = 1;
return 0;
}
static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char **args)
{
grub_fs_t fs;
@@ -743,6 +910,7 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
char *device_name = NULL;
char buf[32];
img_iterator_node *node = NULL;
img_iterator_node *tmp = NULL;
(void)ctxt;
@@ -762,13 +930,13 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
goto fail;
}
dev = grub_device_open(device_name);
g_enum_dev = dev = grub_device_open(device_name);
if (!dev)
{
goto fail;
}
fs = grub_fs_probe(dev);
g_enum_fs = fs = grub_fs_probe(dev);
if (!fs)
{
goto fail;
@@ -776,20 +944,29 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
grub_memset(&g_img_iterator_head, 0, sizeof(g_img_iterator_head));
g_img_iterator_head.dirlen = 1;
g_img_iterator_head.tail = &tail;
grub_strcpy(g_img_iterator_head.dir, "/");
grub_strcpy(g_img_iterator_head.dir, "/");
fs->fs_dir(dev, "/", ventoy_colect_img_files, &g_img_iterator_head);
while (g_img_iterator_head.next)
for (node = &g_img_iterator_head; node; node = node->next)
{
node = g_img_iterator_head.next;
g_img_iterator_head.next = node->next;
fs->fs_dir(dev, node->dir, ventoy_colect_img_files, node);
grub_free(node);
fs->fs_dir(dev, node->dir, ventoy_colect_img_files, node);
}
for (node = &g_img_iterator_head; node; node = node->next)
{
ventoy_dynamic_tree_menu(node);
}
/* free node */
node = g_img_iterator_head.next;
while (node)
{
tmp = node->next;
grub_free(node);
node = tmp;
}
/* sort image list by image name */
for (cur = g_ventoy_img_list; cur; cur = cur->next)
{
@@ -802,6 +979,16 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
}
}
for (cur = g_ventoy_img_list; cur; cur = cur->next)
{
g_list_script_pos += grub_snprintf(g_list_script_buf + g_list_script_pos, VTOY_MAX_SCRIPT_BUF - g_list_script_pos,
"menuentry \"%s\" --id=\"VID_%d\" {\n"
" common_menuentry \n"
"}\n",
cur->name, cur->id);
}
g_list_script_buf[g_list_script_pos] = 0;
grub_snprintf(buf, sizeof(buf), "%d", g_ventoy_img_count);
grub_env_set(args[1], buf);
@@ -876,7 +1063,9 @@ static grub_err_t ventoy_cmd_img_name(grub_extcmd_context_t ctxt, int argc, char
static grub_err_t ventoy_cmd_chosen_img_path(grub_extcmd_context_t ctxt, int argc, char **args)
{
const char *name = NULL;
int img_id = 0;
char *pos = NULL;
const char *id = NULL;
img_info *cur = g_ventoy_img_list;
(void)ctxt;
@@ -886,13 +1075,22 @@ static grub_err_t ventoy_cmd_chosen_img_path(grub_extcmd_context_t ctxt, int arg
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s {var}", cmd_raw_name);
}
name = grub_env_get("chosen");
id = grub_env_get("chosen");
pos = grub_strstr(id, "VID_");
if (pos)
{
img_id = (int)grub_strtoul(pos + 4, NULL, 10);
}
else
{
img_id = (int)grub_strtoul(id, NULL, 10);
}
while (cur)
{
if (0 == grub_strcmp(name, cur->name))
if (img_id == cur->id)
{
grub_env_set(args[0], cur->path);
break;
}
cur = cur->next;
@@ -903,6 +1101,8 @@ static grub_err_t ventoy_cmd_chosen_img_path(grub_extcmd_context_t ctxt, int arg
return grub_error(GRUB_ERR_BAD_ARGUMENT, "No such image");
}
grub_env_set(args[0], cur->path);
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
@@ -1085,6 +1285,8 @@ static grub_err_t ventoy_cmd_img_sector(grub_extcmd_context_t ctxt, int argc, ch
grub_file_close(file);
grub_memset(&g_grub_param->file_replace, 0, sizeof(g_grub_param->file_replace));
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
@@ -1109,6 +1311,173 @@ static grub_err_t ventoy_cmd_dump_img_sector(grub_extcmd_context_t ctxt, int arg
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
static grub_err_t ventoy_cmd_add_replace_file(grub_extcmd_context_t ctxt, int argc, char **args)
{
int i;
ventoy_grub_param_file_replace *replace = NULL;
(void)ctxt;
(void)argc;
(void)args;
if (argc >= 2)
{
replace = &(g_grub_param->file_replace);
replace->magic = GRUB_FILE_REPLACE_MAGIC;
replace->old_name_cnt = 0;
for (i = 0; i < 4 && i + 1 < argc; i++)
{
replace->old_name_cnt++;
grub_snprintf(replace->old_file_name[i], sizeof(replace->old_file_name[i]), "%s", args[i + 1]);
}
replace->new_file_virtual_id = (grub_uint32_t)grub_strtoul(args[0], NULL, 10);
}
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
static grub_err_t ventoy_cmd_dump_menu(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
(void)argc;
(void)args;
if (argc == 0)
{
grub_printf("List Mode: CurLen:%d MaxLen:%u\n", g_list_script_pos, VTOY_MAX_SCRIPT_BUF);
grub_printf("%s", g_list_script_buf);
}
else
{
grub_printf("Tree Mode: CurLen:%d MaxLen:%u\n", g_tree_script_pos, VTOY_MAX_SCRIPT_BUF);
grub_printf("%s", g_tree_script_buf);
}
return 0;
}
static grub_err_t ventoy_cmd_check_mode(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
(void)argc;
(void)args;
if (argc != 1)
{
return 1;
}
if (args[0][0] == '0')
{
return g_ventoy_memdisk_mode ? 0 : 1;
}
else if (args[0][0] == '1')
{
return g_ventoy_iso_raw ? 0 : 1;
}
else if (args[0][0] == '2')
{
return g_ventoy_iso_uefi_drv ? 0 : 1;
}
return 1;
}
static grub_err_t ventoy_cmd_dynamic_menu(grub_extcmd_context_t ctxt, int argc, char **args)
{
char memfile[128] = {0};
(void)ctxt;
(void)argc;
(void)args;
if (argc == 0)
{
grub_script_execute_sourcecode(g_list_script_buf);
}
else
{
g_ventoy_last_entry = -1;
grub_snprintf(memfile, sizeof(memfile), "configfile mem:0x%llx:size:%d",
(ulonglong)(ulong)g_tree_script_buf, g_tree_script_pos);
grub_script_execute_sourcecode(memfile);
}
return 0;
}
static grub_err_t ventoy_cmd_find_bootable_hdd(grub_extcmd_context_t ctxt, int argc, char **args)
{
int id = 0;
int find = 0;
grub_disk_t disk;
const char *isopath = NULL;
char hdname[32];
ventoy_mbr_head mbr;
(void)ctxt;
(void)argc;
if (argc != 1)
{
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s variable\n", cmd_raw_name);
}
isopath = grub_env_get("iso_path");
if (!isopath)
{
debug("isopath is null %p\n", isopath);
return 0;
}
debug("isopath is %s\n", isopath);
for (id = 0; id < 30 && (find == 0); id++)
{
grub_snprintf(hdname, sizeof(hdname), "hd%d,", id);
if (grub_strstr(isopath, hdname))
{
debug("skip %s ...\n", hdname);
continue;
}
grub_snprintf(hdname, sizeof(hdname), "hd%d", id);
disk = grub_disk_open(hdname);
if (!disk)
{
debug("%s not exist\n", hdname);
break;
}
grub_memset(&mbr, 0, sizeof(mbr));
if (0 == grub_disk_read(disk, 0, 0, 512, &mbr))
{
if (mbr.Byte55 == 0x55 && mbr.ByteAA == 0xAA)
{
if (mbr.PartTbl[0].Active == 0x80 || mbr.PartTbl[1].Active == 0x80 ||
mbr.PartTbl[2].Active == 0x80 || mbr.PartTbl[3].Active == 0x80)
{
grub_env_set(args[0], hdname);
find = 1;
}
}
debug("%s is %s\n", hdname, find ? "bootable" : "NOT bootable");
}
else
{
debug("read %s failed\n", hdname);
}
grub_disk_close(disk);
}
return 0;
}
grub_file_t ventoy_grub_file_open(enum grub_file_type type, const char *fmt, ...)
{
va_list ap;
@@ -1160,12 +1529,20 @@ static int ventoy_env_init(void)
char buf[64];
grub_env_set("vtdebug_flag", "");
grub_env_export("vtdebug_flag");
g_tree_script_buf = grub_malloc(VTOY_MAX_SCRIPT_BUF);
g_list_script_buf = grub_malloc(VTOY_MAX_SCRIPT_BUF);
ventoy_filt_register(0, ventoy_wrapper_open);
g_grub_param.grub_env_get = grub_env_get;
grub_snprintf(buf, sizeof(buf), "%p", &g_grub_param);
grub_env_set("env_param", buf);
g_grub_param = (ventoy_grub_param *)grub_zalloc(sizeof(ventoy_grub_param));
if (g_grub_param)
{
g_grub_param->grub_env_get = grub_env_get;
grub_snprintf(buf, sizeof(buf), "%p", g_grub_param);
grub_env_set("env_param", buf);
}
return 0;
}
@@ -1186,6 +1563,10 @@ static cmd_para ventoy_cmds[] =
{ "vt_img_sector", ventoy_cmd_img_sector, 0, NULL, "{imageName}", "", NULL },
{ "vt_dump_img_sector", ventoy_cmd_dump_img_sector, 0, NULL, "", "", NULL },
{ "vt_load_cpio", ventoy_cmd_load_cpio, 0, NULL, "", "", NULL },
{ "vt_find_first_bootable_hd", ventoy_cmd_find_bootable_hdd, 0, NULL, "", "", NULL },
{ "vt_dump_menu", ventoy_cmd_dump_menu, 0, NULL, "", "", NULL },
{ "vt_dynamic_menu", ventoy_cmd_dynamic_menu, 0, NULL, "", "", NULL },
{ "vt_check_mode", ventoy_cmd_check_mode, 0, NULL, "", "", NULL },
{ "vt_is_udf", ventoy_cmd_is_udf, 0, NULL, "", "", NULL },
{ "vt_file_size", ventoy_cmd_file_size, 0, NULL, "", "", NULL },
@@ -1204,6 +1585,9 @@ static cmd_para ventoy_cmds[] =
{ "vt_windows_reset", ventoy_cmd_wimdows_reset, 0, NULL, "", "", NULL },
{ "vt_windows_locate_wim", ventoy_cmd_wimdows_locate_wim, 0, NULL, "", "", NULL },
{ "vt_windows_chain_data", ventoy_cmd_windows_chain_data, 0, NULL, "", "", NULL },
{ "vt_add_replace_file", ventoy_cmd_add_replace_file, 0, NULL, "", "", NULL },
{ "vt_load_plugin", ventoy_cmd_load_plugin, 0, NULL, "", "", NULL },
};

View File

@@ -21,10 +21,13 @@
#ifndef __VENTOY_DEF_H__
#define __VENTOY_DEF_H__
#define VTOY_MAX_SCRIPT_BUF (4 * 1024 * 1024)
#define JSON_SUCCESS 0
#define JSON_FAILED 1
#define JSON_NOT_FOUND 2
#define ulong unsigned long
#define ulonglong unsigned long long
#define vtoy_to_upper(c) (((char)(c) >= 'a' && (char)(c) <= 'z') ? ((char)(c) - 'a' + 'A') : (char)(c))
@@ -115,11 +118,15 @@ typedef struct ventoy_udf_override
#pragma pack()
typedef struct img_info
{
char path[512];
char name[256];
int id;
grub_uint64_t size;
int select;
void *parent;
struct img_info *next;
struct img_info *prev;
@@ -130,8 +137,19 @@ typedef struct img_iterator_node
struct img_iterator_node *next;
img_info **tail;
char dir[400];
int dirlen;
int isocnt;
int done;
int select;
struct img_iterator_node *parent;
struct img_iterator_node *firstchild;
void *firstiso;
}img_iterator_node;
typedef struct initrd_info
{
char name[256];
@@ -504,5 +522,41 @@ static inline int ventoy_is_word_end(int c)
return (c == 0 || c == ',' || ventoy_isspace(c));
}
#pragma pack(1)
typedef struct ventoy_part_table
{
grub_uint8_t Active; // 0x00 0x80
grub_uint8_t StartHead;
grub_uint16_t StartSector : 6;
grub_uint16_t StartCylinder : 10;
grub_uint8_t FsFlag;
grub_uint8_t EndHead;
grub_uint16_t EndSector : 6;
grub_uint16_t EndCylinder : 10;
grub_uint32_t StartSectorId;
grub_uint32_t SectorCount;
}ventoy_part_table;
typedef struct ventoy_mbr_head
{
grub_uint8_t BootCode[446];
ventoy_part_table PartTbl[4];
grub_uint8_t Byte55;
grub_uint8_t ByteAA;
}ventoy_mbr_head;
#pragma pack()
extern int g_ventoy_last_entry;
extern int g_ventoy_memdisk_mode;
extern int g_ventoy_iso_raw;
extern int g_ventoy_iso_uefi_drv;
int ventoy_cmp_img(img_info *img1, img_info *img2);
void ventoy_swap_img(img_info *img1, img_info *img2);
#endif /* __VENTOY_DEF_H__ */

View File

@@ -183,9 +183,22 @@ typedef struct ventoy_img_chunk_list
typedef const char * (*grub_env_get_pf)(const char *name);
#pragma pack(1)
#define GRUB_FILE_REPLACE_MAGIC 0x1258BEEF
typedef struct ventoy_grub_param_file_replace
{
grub_uint32_t magic;
char old_file_name[4][256];
grub_uint32_t old_name_cnt;
grub_uint32_t new_file_virtual_id;
}ventoy_grub_param_file_replace;
typedef struct ventoy_grub_param
{
grub_env_get_pf grub_env_get;
ventoy_grub_param_file_replace file_replace;
}ventoy_grub_param;
#pragma pack()

View File

@@ -0,0 +1,46 @@
#!/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
if is_ventoy_hook_finished || not_ventoy_disk "${1:0:-1}"; then
exit 0
fi
ventoy_udev_disk_common_hook $* "noreplace"
if ! [ -e $VTOY_DM_PATH ]; then
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
mknod -m 0666 $VTOY_DM_PATH b $blkdev_num
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.
#
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
# OK finish
set_ventoy_hook_finish

View File

@@ -0,0 +1,24 @@
#!/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
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/alt/udev_disk_hook.sh %k"

View File

@@ -0,0 +1,38 @@
#!/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"
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,20 @@
#!/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/>.
#
#************************************************************************************
$SED "/for .*\$DEVICES/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/berry/ventoy-disk.sh" -i /init

View File

@@ -0,0 +1,43 @@
#!/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
if is_ventoy_hook_finished; then
exit 0
fi
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"
PATH=$VTPATH_OLD
set_ventoy_hook_finish

View File

@@ -0,0 +1,22 @@
#!/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
$SED "/find_and_mount_installer *$/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/clear/disk-hook.sh" -i /init

View File

@@ -17,5 +17,21 @@
#
#************************************************************************************
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/debian/udev_disk_hook.sh %k"
if [ -e /init ] && $GREP -q '^mountroot$' /init; then
echo "Here before mountroot ..." >> $VTLOG
$SED "/^mountroot$/i\\$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/disk_mount_hook.sh" -i /init
$SED "/^mountroot$/i\\export LIVEMEDIA=/dev/mapper/ventoy" -i /init
$SED "/^mountroot$/i\\export LIVE_MEDIA=/dev/mapper/ventoy" -i /init
elif [ -e /init ] && $GREP -q '/start-udev$' /init; then
echo "Here use notify ..." >> $VTLOG
ventoy_set_inotify_script debian/ventoy-inotifyd-hook.sh
$SED "/start-udev$/i\\mount -n -o mode=0755 -t devtmpfs devtmpfs /dev" -i /init
$SED "/start-udev$/i\\$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/ventoy-inotifyd-start.sh" -i /init
else
echo "Here use udev hook ..." >> $VTLOG
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/debian/udev_disk_hook.sh %k"
fi

View File

@@ -0,0 +1,35 @@
#!/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
$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/udev_disk_hook.sh "${vtdiskname#/dev/}2"

View File

@@ -0,0 +1,43 @@
#!/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"
if ! [ -e $VTOY_DM_PATH ]; then
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
mknod -m 0666 $VTOY_DM_PATH b $blkdev_num
fi
PATH=$VTPATH_OLD

View File

@@ -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/>.
#
#************************************************************************************
$SED '/^findknoppix/a\ return 0' -i /init
$SED '/^findknoppix/a\ trymount $ROOTDEV /mnt-system >/dev/null 2>&1' -i /init
$SED '/^findknoppix/a\ ROOTDEV=/dev/mapper/ventoy' -i /init
$SED "/^findknoppix/a\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/knoppix-disk.sh" -i /init

View File

@@ -0,0 +1,77 @@
#!/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
ventoy_os_install_dmsetup_by_fuse() {
vtlog "ventoy_os_install_dmsetup_by_fuse $*"
mkdir -p $VTOY_PATH/mnt/fuse $VTOY_PATH/mnt/iso $VTOY_PATH/mnt/squashfs
vtoydm -p -f $VTOY_PATH/ventoy_image_map -d $1 > $VTOY_PATH/ventoy_dm_table
vtoy_fuse_iso -f $VTOY_PATH/ventoy_dm_table -m $VTOY_PATH/mnt/fuse
mount -t iso9660 $VTOY_PATH/mnt/fuse/ventoy.iso $VTOY_PATH/mnt/iso
sfsfile=$(ls $VTOY_PATH/mnt/iso/porteus/base/*kernel.xzm)
mount -t squashfs $sfsfile $VTOY_PATH/mnt/squashfs
KoName=$(ls $VTOY_PATH/mnt/squashfs/lib/modules/$2/kernel/drivers/md/dm-mod.ko*)
vtlog "insmod $KoName"
insmod $KoName
umount $VTOY_PATH/mnt/squashfs
umount $VTOY_PATH/mnt/iso
umount $VTOY_PATH/mnt/fuse
}
ventoy_os_install_dmsetup() {
vtlog "ventoy_os_install_dmsetup"
if grep -q 'device-mapper' /proc/devices; then
vtlog "device-mapper module already loaded"
return;
fi
vtKerVer=$(uname -r)
ventoy_os_install_dmsetup_by_fuse $1 $vtKerVer
}
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_os_install_dmsetup $vtdiskname
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,48 @@
#!/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/>.
#
#************************************************************************************
porteus_hook() {
$SED "/searching *for *\$SGN *file/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/porteus-disk.sh" -i $1
$SED "/searching *for *\$CFG *file/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/porteus-disk.sh" -i $1
}
if $GREP -q exfat /proc/filesystems; then
vtPath=$($VTOY_PATH/tool/vtoydump -p $VTOY_PATH/ventoy_os_param)
$GREP '`value from`' /usr/* -r | $AWK -F: '{print $1}' | while read vtline; do
echo "hooking $vtline ..." >> $VTLOG
$SED "s#\`value from\`#$vtPath#g" -i $vtline
done
else
for vtfile in '/init' '/linuxrc' ; do
if [ -e $vtfile ]; then
if ! $GREP -q ventoy $vtfile; then
echo "hooking $vtfile ..." >> $VTLOG
porteus_hook $vtfile
fi
fi
done
fi
# replace blkid in system
vtblkid=$($BUSYBOX_PATH/which blkid)
$BUSYBOX_PATH/rm -f $vtblkid
$BUSYBOX_PATH/cp -a $BUSYBOX_PATH/blkid $vtblkid

View File

@@ -0,0 +1,48 @@
#!/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
if is_ventoy_hook_finished; then
exit 0
fi
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"
if ! [ -e $VTOY_DM_PATH ]; then
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
mknod -m 0666 $VTOY_DM_PATH b $blkdev_num
fi
PATH=$VTPATH_OLD
set_ventoy_hook_finish

View File

@@ -0,0 +1,22 @@
#!/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/>.
#
#************************************************************************************
$SED '1 apmedia=usbhd' -i /init
$SED "/^ *HAVE_PARTS=/a\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/puppy-disk.sh" -i /init
$SED "/^ *HAVE_PARTS=/a\ HAVE_PARTS='mapper/ventoy|iso9660'" -i /init

View File

@@ -0,0 +1,43 @@
#!/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
if is_ventoy_hook_finished; then
exit 0
fi
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"
PATH=$VTPATH_OLD
set_ventoy_hook_finish

View File

@@ -0,0 +1,21 @@
#!/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/>.
#
#************************************************************************************
$SED "/\/sys\/block\/hd\*/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/pve-disk.sh" -i /init
$SED "s#/sys/block/hd\*#/sys/block/dm* /sys/block/hd*#" -i /init

View File

@@ -0,0 +1,77 @@
#!/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
ventoy_os_install_dmsetup_by_fuse() {
vtlog "ventoy_os_install_dmsetup_by_fuse $*"
mkdir -p $VTOY_PATH/mnt/fuse $VTOY_PATH/mnt/iso $VTOY_PATH/mnt/squashfs
vtoydm -p -f $VTOY_PATH/ventoy_image_map -d $1 > $VTOY_PATH/ventoy_dm_table
vtoy_fuse_iso -f $VTOY_PATH/ventoy_dm_table -m $VTOY_PATH/mnt/fuse
mount -t iso9660 $VTOY_PATH/mnt/fuse/ventoy.iso $VTOY_PATH/mnt/iso
mount -t squashfs $VTOY_PATH/mnt/iso/slax/01-core.sb $VTOY_PATH/mnt/squashfs
KoName=$(ls $VTOY_PATH/mnt/squashfs/lib/modules/$2/kernel/drivers/md/dm-mod.ko*)
vtlog "insmod $KoName"
insmod $KoName
umount $VTOY_PATH/mnt/squashfs
umount $VTOY_PATH/mnt/iso
umount $VTOY_PATH/mnt/fuse
}
ventoy_os_install_dmsetup() {
vtlog "ventoy_os_install_dmsetup"
if grep -q 'device-mapper' /proc/devices; then
vtlog "device-mapper module already loaded"
return;
fi
vtKerVer=$(uname -r)
if modprobe fuse 2>>$VTLOG; then
ventoy_os_install_dmsetup_by_fuse $1 $vtKerVer
fi
}
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_os_install_dmsetup $vtdiskname
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,20 @@
#!/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/>.
#
#************************************************************************************
$SED "/find_data/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/slax-disk.sh" -i /init

View File

@@ -0,0 +1,24 @@
#!/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/>.
#
#************************************************************************************
$SED "s#.*livefs_root=.*find_livefs.*#$BUSYBOX_PATH/mount -t iso9660 /dev/mapper/ventoy \$mountpoint; livefs_root=\$mountpoint#" -i /usr/lib/live/boot/9990-main.sh
$SED "s#.*livefs_root=.*find_livefs.*#$BUSYBOX_PATH/mount -t iso9660 /dev/mapper/ventoy \$mountpoint; livefs_root=\$mountpoint#" -i /usr/bin/boot/9990-main.sh
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/debian/udev_disk_hook.sh %k"

View File

@@ -86,6 +86,10 @@ if [ -z "$dmsetup_path" ]; then
ventoy_os_install_dmsetup "/dev/${1:0:-1}"
fi
if ! $GREP -q 'device-mapper' /proc/devices; then
ventoy_os_install_dmsetup "/dev/${1:0:-1}"
fi
ventoy_udev_disk_common_hook $*
#
@@ -103,7 +107,14 @@ else
else
vtlog "No boot param, need to mount"
$BUSYBOX_PATH/mkdir /cdrom
$BUSYBOX_PATH/mount -t iso9660 $VTOY_DM_PATH /cdrom
if [ -b $VTOY_DM_PATH ]; then
vtlog "mount $VTOY_DM_PATH ..."
$BUSYBOX_PATH/mount -t iso9660 $VTOY_DM_PATH /cdrom
else
vtlog "mount /dev/$1 ..."
$BUSYBOX_PATH/mount -t iso9660 /dev/$1 /cdrom
fi
fi
fi

View File

@@ -0,0 +1,88 @@
#!/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
if is_ventoy_hook_finished; then
exit 0
fi
vtlog "####### $0 $* ########"
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
ventoy_os_install_dmsetup_by_fuse() {
vtlog "ventoy_os_install_dmsetup_by_fuse $*"
mkdir -p $VTOY_PATH/mnt/fuse $VTOY_PATH/mnt/iso $VTOY_PATH/mnt/squashfs
vtoydm -p -f $VTOY_PATH/ventoy_image_map -d $1 > $VTOY_PATH/ventoy_dm_table
vtoy_fuse_iso -f $VTOY_PATH/ventoy_dm_table -m $VTOY_PATH/mnt/fuse
mount -t iso9660 $VTOY_PATH/mnt/fuse/ventoy.iso $VTOY_PATH/mnt/iso
sfsfile=$(ls $VTOY_PATH/mnt/iso/adrv_veket*.sfs)
mount -t squashfs $sfsfile $VTOY_PATH/mnt/squashfs
KoName=$(ls $VTOY_PATH/mnt/squashfs/lib/modules/$2/kernel/drivers/dax/dax.ko*)
vtlog "insmod $KoName"
insmod $KoName
KoName=$(ls $VTOY_PATH/mnt/squashfs/lib/modules/$2/kernel/drivers/md/dm-mod.ko*)
vtlog "insmod $KoName"
insmod $KoName
umount $VTOY_PATH/mnt/squashfs
umount $VTOY_PATH/mnt/iso
umount $VTOY_PATH/mnt/fuse
}
ventoy_os_install_dmsetup() {
vtlog "ventoy_os_install_dmsetup"
if grep -q 'device-mapper' /proc/devices; then
vtlog "device-mapper module already loaded"
return;
fi
vtKerVer=$(uname -r)
ventoy_os_install_dmsetup_by_fuse $1 $vtKerVer
}
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_os_install_dmsetup $vtdiskname
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/')
mknod -m 0666 /dev/ventoy b $blkdev_num
PATH=$VTPATH_OLD
set_ventoy_hook_finish

View File

@@ -0,0 +1,22 @@
#!/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/>.
#
#************************************************************************************
$SED '1 apmedia=usbhd' -i /init
$SED "/^ *HAVE_PARTS=/a\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/veket-disk.sh" -i /init
$SED "/^ *HAVE_PARTS=/a\ HAVE_PARTS='ventoy|iso9660'" -i /init

View File

@@ -52,14 +52,6 @@ ventoy_get_debian_distro() {
echo 'pve'; return
fi
if $GREP -q '[Dd]eepin' /proc/version; then
echo 'deepin'; return
fi
if $GREP -q '[Uu][Oo][Ss] ' /proc/version; then
echo 'deepin'; return
fi
if [ -d /porteus ]; then
echo 'porteus'; return
fi

View File

@@ -0,0 +1,35 @@
#!/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
if is_ventoy_hook_finished; then
exit 0
fi
vtlog "##### INOTIFYD: $2/$3 is created ..."
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
if is_inotify_ventoy_part $3; then
vtlog "find ventoy partition $3 ..."
$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/udev_disk_hook.sh "$3"
fi
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,25 @@
#!/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
vtHook=$($CAT $VTOY_PATH/inotifyd-hook-script.txt)
vtlog "... start inotifyd listen $vtHook ..."
$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $vtHook /dev:n 2>&- &

View File

@@ -28,6 +28,13 @@ else
$CAT $VTOY_PATH/hook/default/13-dm-disk.rules > "$DISTRO_UDEV_DIR/13-dm-disk.rules"
fi
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k"
if $GREP -q '^mount_setup$' init; then
echo "Here use notify ..." >> $VTLOG
ventoy_set_inotify_script manjaro/ventoy-inotifyd-hook.sh
$SED "/^mount_setup$/a\\$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/ventoy-inotifyd-start.sh" -i /init
else
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k"
fi

View File

@@ -0,0 +1,46 @@
#!/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
if is_ventoy_hook_finished; then
exit 0
fi
vtlog "##### INOTIFYD: $2/$3 is created ..."
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
if is_inotify_ventoy_part $3; then
vtlog "find ventoy partition $3 ..."
$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})
vtLABEL=$($BUSYBOX_PATH/blkid /dev/$vtDM | $AWK '{print $2}' | $SED 's/.*"\(.*\)".*/\1/')
vtlog "blkdev_num=$blkdev_num vtDM=$vtDM label $vtLABEL ..."
if ! [ -d /dev/disk/by-label ]; then
mkdir -p /dev/disk/by-label
fi
$BUSYBOX_PATH/cp -a /dev/$vtDM /dev/disk/by-label/$vtLABEL
fi
PATH=$VTPATH_OLD

View File

@@ -64,6 +64,8 @@ ventoy_os_install_device_mapper() {
fi
}
wait_for_usb_disk_ready
vtdiskname=$(get_ventoy_disk_name)
ventoy_os_install_device_mapper $vtdiskname

View File

@@ -19,11 +19,21 @@
. $VTOY_PATH/hook/ventoy-os-lib.sh
ventoy_systemd_udevd_work_around
#ventoy_systemd_udevd_work_around
#ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k noreplace"
ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k noreplace"
if $GREP -q 'root=live' /proc/cmdline; then
$SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE root=live:/dev/dm-0#" -i /lib/dracut-lib.sh
else
$SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE inst.stage2=hd:/dev/dm-0#" -i /lib/dracut-lib.sh
fi
ventoy_set_inotify_script rhel7/ventoy-inotifyd-hook.sh
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-inotifyd-start.sh /lib/dracut/hooks/pre-udev/01-ventoy-inotifyd-start.sh
# suppress write protected mount warning
if [ -e /usr/sbin/anaconda-diskroot ]; then
$SED 's/^mount $dev $repodir/mount -oro $dev $repodir/' -i /usr/sbin/anaconda-diskroot
fi

View File

@@ -0,0 +1,47 @@
#!/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
if is_ventoy_hook_finished; then
exit 0
fi
vtlog "##### INOTIFYD: $2/$3 is created ..."
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
if is_inotify_ventoy_part $3; then
vtlog "find ventoy partition ..."
$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh $3 noreplace
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})
if [ "$vtDM" = "dm-0" ]; then
vtlog "This is dm-0, OK ..."
else
vtlog "####### This is $vtDM ####### this is abnormal ..."
ventoy_swap_device /dev/dm-0 /dev/$vtDM
fi
set_ventoy_hook_finish
fi
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,31 @@
#!/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
vtHook=$($CAT $VTOY_PATH/inotifyd-hook-script.txt)
vtdisk=$(get_ventoy_disk_name)
if [ "$vtdisk" = "unknown" ]; then
vtlog "... start inotifyd listen $vtHook ..."
$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $vtHook /dev:n 2>&- &
else
vtlog "... $vtdisk already exist ..."
$BUSYBOX_PATH/sh $vtHook n /dev "${vtdisk#/dev/}2"
fi

View File

@@ -226,7 +226,7 @@ wait_for_ventoy_dm_disk_label() {
if ls -l /dev/disk/by-label/ | $GREP -q "$DM"; then
break
else
$SLEEP 0.3
$SLEEP 1
fi
done
}
@@ -395,7 +395,7 @@ ventoy_udev_disk_common_hook() {
else
vtlog "==== create ventoy device mapper failed ===="
$SLEEP 5
$SLEEP 3
if $GREP -q "/dev/$VTDISK" /proc/mounts; then
$GREP "/dev/$VTDISK" /proc/mounts | while read vtLine; do
@@ -421,4 +421,37 @@ ventoy_udev_disk_common_hook() {
fi
}
is_inotify_ventoy_part() {
if echo $1 | grep -q "2$"; then
if ! [ -e /sys/block/$1 ]; then
if [ -e /sys/class/block/$1 ]; then
if [ -e /dev/${1:0:-1} ]; then
$VTOY_PATH/tool/vtoydump -f $VTOY_PATH/ventoy_os_param -c ${1:0:-1}
return
fi
fi
fi
fi
[ "1" = "0" ]
}
ventoy_find_dm_id() {
for vt in $($BUSYBOX_PATH/ls /sys/block/); do
if [ "${vt:0:3}" = "dm-" ]; then
vtMajorMinor=$($CAT /sys/block/$vt/dev)
if [ "$vtMajorMinor" = "$1" ]; then
echo ${vt}
return
fi
fi
done
echo 'xx'
}
ventoy_swap_device() {
mv $1 $VTOY_PATH/swap_tmp_dev
mv $2 $1
mv $VTOY_PATH/swap_tmp_dev $2
}

View File

@@ -80,14 +80,19 @@ ventoy_add_udev_rule() {
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=869719
#
ventoy_systemd_udevd_work_around() {
VTSYSTEMUDEV="$VT_RULE_DIR_PREFIX/lib/systemd/system/systemd-udevd.service"
if [ -e $VTSYSTEMUDEV ]; then
if $GREP -q 'SystemCallArchitectures.*native' $VTSYSTEMUDEV; then
$SED "s/.*\(SystemCallArchitectures.*native\)/#\1/g" -i $VTSYSTEMUDEV
for vtdir in 'lib' 'usr/lib'; do
VTSYSTEMUDEV="$VT_RULE_DIR_PREFIX/$vtdir/systemd/system/systemd-udevd.service"
if [ -e $VTSYSTEMUDEV ]; then
if $GREP -q 'SystemCallArchitectures.*native' $VTSYSTEMUDEV; then
$SED "s/.*\(SystemCallArchitectures.*native\)/#\1/g" -i $VTSYSTEMUDEV
break
fi
fi
fi
done
}
ventoy_print_yum_repo() {
echo "[$1]"
echo "name=$1"
@@ -96,3 +101,7 @@ ventoy_print_yum_repo() {
echo "gpgcheck=0"
echo "priority=0"
}
ventoy_set_inotify_script() {
echo $VTOY_PATH/hook/$1 > $VTOY_PATH/inotifyd-hook-script.txt
}

View File

@@ -0,0 +1,42 @@
#!/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"
if ! [ -e $VTOY_DM_PATH ]; then
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
mknod -m 0666 $VTOY_DM_PATH b $blkdev_num
fi
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,24 @@
#!/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
$SED "/while.*\$device/i\ device=/dev/mapper/ventoy" -i /init
$SED "/while.*\$device/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/zeroshell/disk_hook.sh" -i /init

View File

@@ -76,8 +76,19 @@ ventoy_unpack_initramfs() {
for vtx in '1F8B zcat' '1F9E zcat' '425A bzcat' '5D00 lzcat' 'FD37 xzcat' '894C lzopcat' '0221 lz4cat' '28B5 zstdcat' '3037 cat'; do
if [ "${vtx:0:4}" = "${vtmagic:0:4}" ]; then
echo "vtx=$vtx" >> $VTLOG
if [ $vtskip -eq 0 ]; then
${vtx:5} $vtfile | (cpio -idmu 2>>$VTLOG; cat > $vttmp)
if [ $vtskip -eq 0 ]; then
if [ "${vtx:5}" = "xzcat" ]; then
rm -f $VTOY_PATH/xzlog
${vtx:5} $vtfile 2> $VTOY_PATH/xzlog | (cpio -idmu 2>>$VTLOG; cat > $vttmp)
if grep -q 'corrupted data' $VTOY_PATH/xzlog; then
echo 'xzcat failed, now try xzminidec...' >> $VTLOG
cat $vtfile | xzminidec | (cpio -idmu 2>>$VTLOG; cat > $vttmp)
fi
else
${vtx:5} $vtfile | (cpio -idmu 2>>$VTLOG; cat > $vttmp)
fi
else
dd if=$vtfile skip=$vtskip iflag=skip_bytes status=none | ${vtx:5} | (cpio -idmu 2>>$VTLOG; cat > $vttmp)
fi
@@ -104,64 +115,36 @@ ventoy_unpack_initrd() {
# This export is for busybox cpio command
export EXTRACT_UNSAFE_SYMLINKS=1
# special process
need_xzminidec() {
if [ -e /initrd001 ]; then
testmagic=$(hexdump -n 2 -e '2/1 "%02X"' /initrd001)
for vtfile in $(ls /initrd*); do
#decompress first initrd
vtmagic=$(hexdump -n 2 -e '2/1 "%02X"' $vtfile)
if ventoy_is_initrd_ramdisk; then
ventoy_unpack_initrd $vtfile $vtmagic ${vtfile}_tmp
mv ${vtfile}_tmp $vtfile
break
else
testmagic='xxxx'
ventoy_unpack_initramfs $vtfile 0 $vtmagic ${vtfile}_tmp
fi
if [ "FD37" = "${testmagic:0:4}" ]; then
if echo $vtkerver | grep -q 'kaspersky'; then
true
elif echo $vtkerver | grep -q 'kiosk.*Gentoo'; then
true
elif echo $vtkerver | grep -q 'porteus '; then
true
else
false
fi
else
false
fi
}
if need_xzminidec; then
echo "use xzminidec" >> $VTLOG
cat /initrd001 | xzminidec | cpio -idmu 2>>$VTLOG
rm -f /initrd001
else
for vtfile in $(ls /initrd*); do
#decompress first initrd
vtmagic=$(hexdump -n 2 -e '2/1 "%02X"' $vtfile)
if ventoy_is_initrd_ramdisk; then
ventoy_unpack_initrd $vtfile $vtmagic ${vtfile}_tmp
mv ${vtfile}_tmp $vtfile
break
else
ventoy_unpack_initramfs $vtfile 0 $vtmagic ${vtfile}_tmp
fi
#only for cpio,cpio,...,initrd sequence, initrd,cpio or initrd,initrd sequence is not supported
while [ -e ${vtfile}_tmp ] && [ $(stat -c '%s' ${vtfile}_tmp) -gt 512 ]; do
mv ${vtfile}_tmp $vtfile
vtdump=$(hexdump -n 512 -e '512/1 "%02X"' $vtfile)
vtmagic=$(echo $vtdump | sed 's/^\(00\)*//')
let vtoffset="(${#vtdump}-${#vtmagic})/2"
if [ -z "$vtmagic" ]; then
echo "terminate with all zero data file" >> $VTLOG
break
fi
ventoy_unpack_initramfs $vtfile $vtoffset ${vtmagic:0:4} ${vtfile}_tmp
done
#only for cpio,cpio,...,initrd sequence, initrd,cpio or initrd,initrd sequence is not supported
while [ -e ${vtfile}_tmp ] && [ $(stat -c '%s' ${vtfile}_tmp) -gt 512 ]; do
mv ${vtfile}_tmp $vtfile
vtdump=$(hexdump -n 512 -e '512/1 "%02X"' $vtfile)
vtmagic=$(echo $vtdump | sed 's/^\(00\)*//')
let vtoffset="(${#vtdump}-${#vtmagic})/2"
rm -f $vtfile ${vtfile}_tmp
if [ -z "$vtmagic" ]; then
echo "terminate with all zero data file" >> $VTLOG
break
fi
ventoy_unpack_initramfs $vtfile $vtoffset ${vtmagic:0:4} ${vtfile}_tmp
done
fi
rm -f $vtfile ${vtfile}_tmp
done
#break here for debug
if [ "$VTOY_BREAK_LEVEL" = "02" ] || [ "$VTOY_BREAK_LEVEL" = "12" ]; then

View File

@@ -52,3 +52,12 @@ else
$BUSYBOX_PATH/cp -a $VTOY_PATH/tool/unsquashfs_32 $VTOY_PATH/tool/vtoy_unsquashfs
fi
if $VTOY_PATH/tool/unsquashfs_64 -t 2>>$VTLOG; then
echo "use unsquashfs_64" >>$VTLOG
$BUSYBOX_PATH/cp -a $VTOY_PATH/tool/unsquashfs_64 $VTOY_PATH/tool/vtoy_unsquashfs
else
echo "use unsquashfs_32" >>$VTLOG
$BUSYBOX_PATH/cp -a $VTOY_PATH/tool/unsquashfs_32 $VTOY_PATH/tool/vtoy_unsquashfs
fi

Binary file not shown.

View File

@@ -130,6 +130,7 @@ ventoy_get_os_type() {
echo 'xen'; return
elif $GREP -q 'SUSE ' /etc/os-release; then
echo 'suse'; return
fi
fi
@@ -156,6 +157,20 @@ ventoy_get_os_type() {
echo 'debian'; return
fi
if $GREP -q 'Clear Linux ' /proc/version; then
echo 'clear'; return
fi
if $GREP -q 'artix' /proc/version; then
echo 'arch'; return
fi
if $GREP -q 'berry ' /proc/version; then
echo 'berry'; return
fi
echo "default"
}

View File

@@ -0,0 +1,5 @@
For Ventoy2Disk.exe (Windows) or Ventoy2Disk.sh (Linux).
You should download the install package, decompress it, and run the exe/sh there.
They should NOT be run in the source tree(INSTALL directory).

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,5 +1,11 @@
#!/bin/sh
OLDDIR=$PWD
if ! [ -f ./tool/ventoy_lib.sh ]; then
cd ${0%Ventoy2Disk.sh}
fi
. ./tool/ventoy_lib.sh
print_usage() {
@@ -18,27 +24,33 @@ echo '* longpanda admin@ventoy.net *'
echo '***********************************************************'
echo ''
vtdebug "############# Ventoy2Disk ################"
vtdebug "############# Ventoy2Disk $0 ################"
if ! [ -e ventoy/version ]; then
vterr "Please run under the correct directory!"
exit 1
fi
while [ -n "$1" ]; do
if [ "$1" = "-i" ]; then
MODE="install"
elif [ "$1" = "-I" ]; then
MODE="install"
FORCE="Y"
elif [ "$1" = "-u" ]; then
MODE="update"
elif [ "$1" = "-s" ]; then
SECUREBOOT="YES"
else
if ! [ -b "$1" ]; then
print_usage
cd $OLDDIR
exit 1
fi
DISK=$1
fi
shift
done
if [ "$1" = "-i" ]; then
MODE="install"
elif [ "$1" = "-I" ]; then
MODE="install"
FORCE="Y"
elif [ "$1" = "-u" ]; then
MODE="update"
else
print_usage
exit 1
fi
if ! [ -b "$2" ]; then
if [ -z "$MODE" ]; then
print_usage
cd $OLDDIR
exit 1
fi
@@ -46,12 +58,22 @@ if [ -z "$SUDO_USER" ]; then
if [ "$USER" != "root" ]; then
vterr "EUID is $EUID root permission is required."
echo ''
cd $OLDDIR
exit 1
fi
fi
vtdebug "MODE=$MODE FORCE=$FORCE"
if ! [ -f ./boot/boot.img ]; then
if [ -d ./grub ]; then
vterr "Don't run me here, please download the released install package, and run there."
else
vterr "Please run under the right directory!"
fi
exit 1
fi
#decompress tool
cd tool
chmod +x ./xzcat
@@ -67,25 +89,33 @@ cd ../
if ! check_tool_work_ok; then
vterr "Some tools can not run in current system. Please check log.txt for detail."
cd $OLDDIR
exit 1
fi
DISK=$2
if ! [ -b "$DISK" ]; then
vterr "Disk $DISK does not exist"
cd $OLDDIR
exit 1
fi
if [ -e /sys/class/block/${DISK#/dev/}/start ]; then
vterr "$DISK is a partition, please use the whole disk"
cd $OLDDIR
exit 1
fi
grep "^$DISK" /proc/mounts | while read mtline; do
mtpnt=$(echo $mtline | awk '{print $DISK}')
vtdebug "Trying to umount $mtpnt ..."
umount $mtpnt >/dev/null 2>&1
done
if grep "$DISK" /proc/mounts; then
vterr "$DISK is already mounted, please umount it first!"
cd $OLDDIR
exit 1
fi
@@ -95,6 +125,7 @@ if [ "$MODE" = "install" ]; then
if ! fdisk -v >/dev/null 2>&1; then
vterr "fdisk is needed by ventoy installation, but is not found in the system."
cd $OLDDIR
exit 1
fi
@@ -105,6 +136,7 @@ if [ "$MODE" = "install" ]; then
vtwarn "Use -u option to do a safe upgrade operation."
vtwarn "OR if you really want to reinstall ventoy to $DISK, please use -I option."
vtwarn ""
cd $OLDDIR
exit 1
fi
fi
@@ -114,6 +146,7 @@ if [ "$MODE" = "install" ]; then
if [ $disk_sector_num -gt 4294967296 ]; then
vterr "$DISK is over 2TB size, MBR will not work on it."
cd $OLDDIR
exit 1
fi
@@ -150,7 +183,7 @@ if [ "$MODE" = "install" ]; then
exit 1
fi
if ! dd if=/dev/zero of=$DISK bs=1 count=512 status=none; then
if ! dd if=/dev/zero of=$DISK bs=1 count=512 status=none conv=fsync; then
vterr "Write data to $DISK failed, please check whether it's in use."
exit 1
fi
@@ -178,17 +211,42 @@ if [ "$MODE" = "install" ]; then
chmod +x ./tool/vtoy_gen_uuid
dd status=none if=./boot/boot.img of=$DISK bs=1 count=446
./tool/xzcat ./boot/core.img.xz | dd status=none of=$DISK bs=512 count=2047 seek=1
./tool/xzcat ./ventoy/ventoy.disk.img.xz | dd status=none of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start_sector
vtinfo "writing data to disk ..."
dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=446
./tool/xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1
./tool/xzcat ./ventoy/ventoy.disk.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start_sector
#disk uuid
./tool/vtoy_gen_uuid | dd status=none of=${DISK} seek=384 bs=1 count=16
./tool/vtoy_gen_uuid | dd status=none conv=fsync of=${DISK} seek=384 bs=1 count=16
#disk signature
./tool/vtoy_gen_uuid | dd status=none of=${DISK} skip=12 seek=440 bs=1 count=4
./tool/vtoy_gen_uuid | dd status=none conv=fsync of=${DISK} skip=12 seek=440 bs=1 count=4
vtinfo "sync data ..."
sync
vtinfo "esp partition processing ..."
if [ "$SECUREBOOT" != "YES" ]; then
mkdir ./tmp_mnt
vtdebug "mounting part2 ...."
for tt in 1 2 3; do
if mount ${DISK}2 ./tmp_mnt; then
vtdebug "mounting part2 success"
break
fi
sleep 2
done
rm -f ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
rm -f ./tmp_mnt/EFI/BOOT/grubx64.efi
rm -f ./tmp_mnt/EFI/BOOT/MokManager.efi
mv ./tmp_mnt/EFI/BOOT/grubx64_real.efi ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
umount ./tmp_mnt
rm -rf ./tmp_mnt
fi
echo ""
vtinfo "Install Ventoy to $DISK successfully finished."
@@ -203,6 +261,7 @@ else
echo ""
vtwarn "Please use -i option if you want to install ventoy to $DISK"
echo ""
cd $OLDDIR
exit 1
fi
@@ -214,21 +273,43 @@ else
read -p "Update Ventoy $oldver ===> $curver Continue? (y/n)" Answer
if [ "$Answer" != "y" ]; then
if [ "$Answer" != "Y" ]; then
cd $OLDDIR
exit 0
fi
fi
PART2=$(get_disk_part_name $DISK 2)
dd status=none if=./boot/boot.img of=$DISK bs=1 count=440
dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=440
./tool/xzcat ./boot/core.img.xz | dd status=none of=$DISK bs=512 count=2047 seek=1
./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)
./tool/xzcat ./ventoy/ventoy.disk.img.xz | dd status=none of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_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
if [ "$SECUREBOOT" != "YES" ]; then
mkdir ./tmp_mnt
vtdebug "mounting part2 ...."
for tt in 1 2 3; do
if mount ${DISK}2 ./tmp_mnt; then
vtdebug "mounting part2 success"
break
fi
sleep 2
done
rm -f ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
rm -f ./tmp_mnt/EFI/BOOT/grubx64.efi
rm -f ./tmp_mnt/EFI/BOOT/MokManager.efi
mv ./tmp_mnt/EFI/BOOT/grubx64_real.efi ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
umount ./tmp_mnt
rm -rf ./tmp_mnt
fi
echo ""
vtinfo "Update Ventoy to $DISK successfully finished."
@@ -236,3 +317,5 @@ else
fi
cd $OLDDIR

View File

@@ -16,6 +16,26 @@
#
#************************************************************************************
function ventoy_power {
echo '<1> Reboot'
echo '<2> Halt'
echo '<0> Return to menu'
echo -e '\nPlease enter your choice:'
unset vtOpt
read vtOpt
if [ "$vtOpt" = "1" ]; then
echo -e '\n\nSystem is rebooting ... \n'
sleep 1
reboot
elif [ "$vtOpt" = "2" ]; then
echo -e '\n\nSystem is halting ... \n'
sleep 1
halt
fi
}
function get_os_type {
set vtoy_os=Linux
for file in "efi/microsoft" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com"; do
@@ -76,6 +96,20 @@ function distro_specify_initrd_file {
vt_linux_specify_initrd_file /boot/initrd.xz
elif [ -f (loop)/boot/initrd ]; then
vt_linux_specify_initrd_file /boot/initrd
elif [ -f (loop)/boot/x86_64/loader/initrd ]; then
vt_linux_specify_initrd_file /boot/x86_64/loader/initrd
elif [ -f (loop)/boot/initramfs-x86_64.img ]; then
vt_linux_specify_initrd_file /boot/initramfs-x86_64.img
fi
}
function distro_specify_initrd_file_phase2 {
if [ -f (loop)/boot/initrd.img ]; then
vt_linux_specify_initrd_file /boot/initrd.img
elif [ -f (loop)/Setup/initrd.gz ]; then
vt_linux_specify_initrd_file /Setup/initrd.gz
fi
}
@@ -137,6 +171,17 @@ function uefi_linux_menu_func {
distro_specify_initrd_file
vt_linux_initrd_count vtcount
if [ $vtcount -eq 0 ]; then
distro_specify_initrd_file_phase2
if [ "$vt_efi_dir" = "NO" ]; then
if [ -f (loop)/efi.img ]; then
vt_add_replace_file 0 "initrd"
fi
fi
fi
locate_initrd
fi
@@ -162,7 +207,7 @@ function uefi_iso_menu_func {
if [ -n "$vtisouefi" ]; then
set LoadIsoEfiDriver=on
unset vtisouefi
elif [ -n "$VTOY_ISO_UEFI_DRV" ]; then
elif vt_check_mode 2; then
set LoadIsoEfiDriver=on
else
unset LoadIsoEfiDriver
@@ -179,10 +224,18 @@ function uefi_iso_menu_func {
loopback loop ${1}${chosen_path}
get_os_type (loop)
if [ -d (loop)/EFI ]; then
set vt_efi_dir=YES
elif [ -d (loop)/efi ]; then
set vt_efi_dir=YES
else
set vt_efi_dir=NO
fi
if [ -n "$vtcompat" ]; then
set ventoy_compatible=YES
unset vtcompat
elif [ -n "$VTOY_ISO_RAW" ]; then
elif vt_check_mode 1; then
set ventoy_compatible=YES
else
vt_check_compatible (loop)
@@ -193,6 +246,8 @@ function uefi_iso_menu_func {
if [ "$vtoy_os" = "Windows" ]; then
if [ "$ventoy_fs_probe" = "iso9660" ]; then
set ventoy_compatible=YES
elif [ -f (loop)/HBCD_PE.ini ]; then
set ventoy_compatible=YES
fi
uefi_windows_menu_func $1
@@ -215,8 +270,6 @@ function uefi_iso_memdisk {
}
function legacy_windows_menu_func {
vt_windows_reset
@@ -279,6 +332,11 @@ function legacy_linux_menu_func {
distro_specify_initrd_file
vt_linux_initrd_count vtcount
if [ $vtcount -eq 0 ]; then
distro_specify_initrd_file_phase2
fi
locate_initrd
fi
@@ -319,7 +377,7 @@ function legacy_iso_menu_func {
if [ -n "$vtcompat" ]; then
set ventoy_compatible=YES
unset vtcompat
elif [ -n "$VTOY_ISO_RAW" ]; then
elif vt_check_mode 1; then
set ventoy_compatible=YES
else
vt_check_compatible (loop)
@@ -330,7 +388,10 @@ function legacy_iso_menu_func {
if [ "$vtoy_os" = "Windows" ]; then
if [ "$ventoy_fs_probe" = "iso9660" ]; then
set ventoy_compatible=YES
elif [ -f (loop)/HBCD_PE.ini ]; then
set ventoy_compatible=YES
fi
legacy_windows_menu_func $1
else
legacy_linux_menu_func $1
@@ -346,6 +407,22 @@ function legacy_iso_memdisk {
boot
}
function common_menuentry {
if [ "$grub_platform" = "pc" ]; then
if vt_check_mode 0; then
legacy_iso_memdisk $iso_path
else
legacy_iso_menu_func $iso_path
fi
else
if vt_check_mode 0; then
uefi_iso_memdisk $iso_path
else
uefi_iso_menu_func $iso_path
fi
fi
}
#############################################################
#############################################################
@@ -355,7 +432,7 @@ function legacy_iso_memdisk {
#############################################################
#############################################################
set VENTOY_VERSION="1.0.06"
set VENTOY_VERSION="1.0.08"
#disable timeout
unset timeout
@@ -364,6 +441,16 @@ set VTOY_MEM_DISK_STR="MEMDISK"
set VTOY_ISO_RAW_STR="ISO RAW"
set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
set VTOY_F2_CMD="ventoy_power"
set VTOY_F3_CMD="vt_dynamic_menu tree"
set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView"
if [ "$grub_platform" = "pc" ]; then
set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
else
set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
fi
vt_device $root vtoy_dev
if [ "$vtoy_dev" = "tftp" ]; then
@@ -385,7 +472,11 @@ if [ -f $iso_path/ventoy/ventoy.json ]; then
vt_load_plugin $iso_path
fi
terminal_output gfxterm
if [ -n "$vtoy_gfxmode" ]; then
set gfxmode=$vtoy_gfxmode
else
set gfxmode=1920x1080,1366x768,1024x768
fi
if [ -n "$vtoy_theme" ]; then
set theme=$vtoy_theme
@@ -393,43 +484,18 @@ else
set theme=$prefix/themes/ventoy/theme.txt
fi
if [ -n "$vtoy_gfxmode" ]; then
set gfxmode=$vtoy_gfxmode
else
set gfxmode=1024x768
fi
terminal_output gfxterm
#colect all image files (iso files)
set ventoy_img_count=0
vt_list_img $iso_path ventoy_img_count
#Dynamic menu for every iso file
if vt_cmp $ventoy_img_count ne 0; then
set imgid=0
while vt_cmp $imgid lt $ventoy_img_count; do
vt_img_name $imgid img_name
menuentry "$img_name" {
if [ "$grub_platform" = "pc" ]; then
if [ -n "$VTOY_MEM_DISK" ]; then
legacy_iso_memdisk $iso_path
else
legacy_iso_menu_func $iso_path
fi
else
if [ -n "$VTOY_MEM_DISK" ]; then
uefi_iso_memdisk $iso_path
else
uefi_iso_menu_func $iso_path
fi
fi
}
vt_incr imgid 1
done
#Main menu
if [ $ventoy_img_count -gt 0 ]; then
vt_dynamic_menu
else
menuentry "No ISO files found (Press enter to reboot ...)" {
echo -e "\n Rebooting ... "
reboot
}
fi

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 269 KiB

After

Width:  |  Height:  |  Size: 257 KiB

View File

@@ -19,7 +19,7 @@ terminal-box: "terminal_box_*.png"
item_font = "ascii"
item_color = "#ffffff"
item_height = 30
item_icon_space = 1
item_spacing = 1
item_padding = 1
@@ -27,8 +27,7 @@ terminal-box: "terminal_box_*.png"
selected_item_color= "#f2f2f2"
selected_item_pixmap_style = "select_*.png"
#icon_height = 30
#icon_width = 30
item_icon_space = 0
scrollbar = true
scrollbar_width = 10
@@ -49,6 +48,14 @@ terminal-box: "terminal_box_*.png"
highlight_style = "*"
}
+ hbox{
left = 30%
top = 95%
width = 10%
height = 25
+ label {text = "@VTOY_HOTKEY_TIP@" color = "blue" align = "left"}
}
+ hbox{
left = 90%

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -2,10 +2,10 @@
Ventoy is an open source tool to create bootable USB drive for ISO files.
With ventoy, you don't need to format the disk again and again, you just need to copy the iso file to the USB drive and boot it.
You can copy many iso files at a time and ventoy will give you a boot menu to select them.
Both Legacy BIOS and UEFI are supported in the same way. 160+ ISO files are tested.
Both Legacy BIOS and UEFI are supported in the same way. 200+ ISO files are tested.
A "Ventoy Compatible" concept is introduced by ventoy, which can help to support any ISO file.
See http://www.ventoy.net for detail.
See https://www.ventoy.net for detail.
# Features
* 100% open source
@@ -13,9 +13,10 @@ See http://www.ventoy.net for detail.
* Fast (limited only by the speed of copying iso file)
* Directly boot from iso file, no extraction needed
* Legacy + UEFI supported in the same way
* UEFI Secure Boot supported (since 1.0.07+) Notes
* ISO files larger than 4GB supported
* Native boot menu style for Legacy & UEFI
* Most type of OS supported, 100+ iso files tested
* Most type of OS supported, 200+ iso files tested
* Not only boot but also complete installation process
* "Ventoy Compatible" concept
* Plugin Framework
@@ -24,4 +25,4 @@ See http://www.ventoy.net for detail.
* Data nondestructive during version upgrade
* No need to update Ventoy when a new distro is released
![avatar](http://www.ventoy.net/static/img/screen/screen_uefi.png)
![avatar](https://www.ventoy.net/static/img/screen/screen_uefi.png)

View File

@@ -52,8 +52,8 @@ const TCHAR * g_Str_ChineseSimple[STR_ID_MAX] =
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD>Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!"),
TEXT("<EFBFBD>"),
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ventoy"),
TEXT("<EFBFBD><EFBFBD><EFBFBD> Ventoy"),
TEXT("<EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ventoy <20>"),
TEXT("<EFBFBD><EFBFBD>ڲ<EFBFBD> Ventoy <20>"),
TEXT("״̬ - ׼<><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
TEXT("<EFBFBD><EFBFBD>װ"),
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
@@ -70,5 +70,5 @@ const TCHAR * g_Str_ChineseSimple[STR_ID_MAX] =
const TCHAR * GetString(enum STR_ID ID)
{
return g_Str_English[ID];
return g_cur_lang_data->MsgString[ID];
};

View File

@@ -21,35 +21,64 @@
#ifndef __LANGUAGE_H__
#define __LANGUAGE_H__
typedef enum STR_ID
{
STR_ERROR = 0,
STR_WARNING,
STR_INFO,
STR_INCORRECT_DIR,
STR_ERROR = 0,
STR_WARNING, // 1
STR_INFO, // 2
STR_INCORRECT_DIR, //3
STR_INCORRECT_TREE_DIR, //4
STR_DEVICE,
STR_LOCAL_VER,
STR_DISK_VER,
STR_STATUS,
STR_INSTALL,
STR_UPDATE,
STR_DEVICE, //5
STR_LOCAL_VER, //6
STR_DISK_VER, //7
STR_STATUS, //8
STR_INSTALL, //9
STR_UPDATE, //10
STR_UPDATE_TIP,
STR_INSTALL_TIP,
STR_INSTALL_TIP2,
STR_UPDATE_TIP, //11
STR_INSTALL_TIP, //12
STR_INSTALL_TIP2,//13
STR_INSTALL_SUCCESS,
STR_INSTALL_FAILED,
STR_UPDATE_SUCCESS,
STR_UPDATE_FAILED,
STR_INSTALL_SUCCESS,//14
STR_INSTALL_FAILED,//15
STR_UPDATE_SUCCESS,//16
STR_UPDATE_FAILED,//17
STR_WAIT_PROCESS,
STR_WAIT_PROCESS,//18
STR_MENU_OPTION,//19
STR_MENU_SECURE_BOOT,//20
STR_ID_MAX
STR_ID_MAX
}STR_ID;
extern BOOL g_SecureBoot;
#define VTOY_MENU_SECURE_BOOT 0xA000
#define VTOY_MENU_LANGUAGE_BEGIN 0xB000
#define VENTOY_LANGUAGE_INI TEXT(".\\ventoy\\languages.ini")
#define VENTOY_CFG_INI TEXT(".\\Ventoy2Disk.ini")
#define VENTOY_MAX_LANGUAGE 200
#define GET_INI_STRING(Key, Buf) GetPrivateProfileString(Language, Key, TEXT("#"), Buf, sizeof(Buf), VENTOY_LANGUAGE_INI)
typedef struct VENTOY_LANGUAGE
{
WCHAR Name[64];
WCHAR FontFamily[64];
int FontSize;
WCHAR StrId[STR_ID_MAX][64];
WCHAR MsgString[STR_ID_MAX][1024];
}VENTOY_LANGUAGE;
extern VENTOY_LANGUAGE *g_cur_lang_data;
const TCHAR * GetString(enum STR_ID ID);
#define _G(a) GetString(a)

View File

@@ -824,10 +824,128 @@ int GetVentoyVerInPhyDrive(const PHY_DRIVE_INFO *pDriveInfo, CHAR *VerBuf, size_
static unsigned int g_disk_unxz_len = 0;
static BYTE *g_part_img_pos = NULL;
static BYTE *g_part_img_buf[VENTOY_EFI_PART_SIZE / SIZE_1MB];
static int VentoyFatMemRead(uint32 Sector, uint8 *Buffer, uint32 SectorCount)
{
uint32 i;
uint32 offset;
BYTE *MbBuf = NULL;
for (i = 0; i < SectorCount; i++)
{
offset = (Sector + i) * 512;
if (g_part_img_buf[1] == NULL)
{
MbBuf = g_part_img_buf[0] + offset;
memcpy(Buffer + i * 512, MbBuf, 512);
}
else
{
MbBuf = g_part_img_buf[offset / SIZE_1MB];
memcpy(Buffer + i * 512, MbBuf + (offset % SIZE_1MB), 512);
}
}
return 1;
}
static int VentoyFatMemWrite(uint32 Sector, uint8 *Buffer, uint32 SectorCount)
{
uint32 i;
uint32 offset;
BYTE *MbBuf = NULL;
for (i = 0; i < SectorCount; i++)
{
offset = (Sector + i) * 512;
if (g_part_img_buf[1] == NULL)
{
MbBuf = g_part_img_buf[0] + offset;
memcpy(MbBuf, Buffer + i * 512, 512);
}
else
{
MbBuf = g_part_img_buf[offset / SIZE_1MB];
memcpy(MbBuf + (offset % SIZE_1MB), Buffer + i * 512, 512);
}
}
return 1;
}
int VentoyProcSecureBoot(BOOL SecureBoot)
{
int rc = 0;
int size;
char *filebuf = NULL;
void *file = NULL;
Log("VentoyProcSecureBoot %d ...", SecureBoot);
if (SecureBoot)
{
Log("Secure boot is enabled ...");
return 0;
}
fl_init();
if (0 == fl_attach_media(VentoyFatMemRead, VentoyFatMemWrite))
{
file = fl_fopen("/EFI/BOOT/grubx64_real.efi", "rb");
Log("Open ventoy efi file %p ", file);
if (file)
{
fl_fseek(file, 0, SEEK_END);
size = (int)fl_ftell(file);
fl_fseek(file, 0, SEEK_SET);
Log("ventoy efi file size %d ...", size);
filebuf = (char *)malloc(size);
if (filebuf)
{
fl_fread(filebuf, 1, size, file);
}
fl_fclose(file);
Log("Now delete all efi files ...");
fl_remove("/EFI/BOOT/BOOTX64.EFI");
fl_remove("/EFI/BOOT/grubx64.efi");
fl_remove("/EFI/BOOT/grubx64_real.efi");
fl_remove("/EFI/BOOT/MokManager.efi");
file = fl_fopen("/EFI/BOOT/BOOTX64.EFI", "wb");
Log("Open bootx64 efi file %p ", file);
if (file)
{
fl_fwrite(filebuf, 1, size, file);
fl_fflush(file);
fl_fclose(file);
}
}
}
else
{
rc = 1;
}
fl_shutdown();
return rc;
}
static int disk_xz_flush(void *src, unsigned int size)
{
unsigned int i;
@@ -919,6 +1037,9 @@ static int FormatPart2Fat(HANDLE hDrive, UINT64 StartSectorId)
if (len == writelen)
{
Log("decompress finished success");
VentoyProcSecureBoot(g_SecureBoot);
for (i = 0; i < VENTOY_EFI_PART_SIZE / SIZE_1MB; i++)
{
dwSize = 0;
@@ -965,6 +1086,9 @@ static int FormatPart2Fat(HANDLE hDrive, UINT64 StartSectorId)
if (g_disk_unxz_len == VENTOY_EFI_PART_SIZE)
{
Log("decompress finished success");
VentoyProcSecureBoot(g_SecureBoot);
for (int i = 0; i < VENTOY_EFI_PART_SIZE / SIZE_1MB; i++)
{
dwSize = 0;

View File

@@ -26,17 +26,55 @@
HINSTANCE g_hInst;
BOOL g_SecureBoot = FALSE;
HWND g_DialogHwnd;
HWND g_ComboxHwnd;
HWND g_StaticLocalVerHwnd;
HWND g_StaticDiskVerHwnd;
HWND g_BtnInstallHwnd;
HWND g_StaticDevHwnd;
HWND g_StaticLocalHwnd;
HWND g_StaticDiskHwnd;
HWND g_BtnUpdateHwnd;
HWND g_ProgressBarHwnd;
HWND g_StaticStatusHwnd;
CHAR g_CurVersion[64];
HANDLE g_ThreadHandle = NULL;
int g_language_count = 0;
int g_cur_lang_id = 0;
VENTOY_LANGUAGE *g_language_data = NULL;
VENTOY_LANGUAGE *g_cur_lang_data = NULL;
static int LoadCfgIni(void)
{
int value;
value = GetPrivateProfileInt(TEXT("Ventoy"), TEXT("SecureBoot"), 0, VENTOY_CFG_INI);
if (value == 1)
{
g_SecureBoot = TRUE;
}
return 0;
}
static int WriteCfgIni(void)
{
WCHAR TmpBuf[128];
swprintf_s(TmpBuf, 128, TEXT("%d"), g_cur_lang_id);
WritePrivateProfileString(TEXT("Ventoy"), TEXT("Language"), TmpBuf, VENTOY_CFG_INI);
swprintf_s(TmpBuf, 128, TEXT("%d"), g_SecureBoot);
WritePrivateProfileString(TEXT("Ventoy"), TEXT("SecureBoot"), TmpBuf, VENTOY_CFG_INI);
return 0;
}
void GetExeVersionInfo(const char *FilePath)
{
UINT length;
@@ -124,15 +162,126 @@ static void OnComboxSelChange(HWND hCombox)
UpdateWindow(g_DialogHwnd);
}
static void UpdateItemString(int defaultLangId)
{
int i;
HMENU SubMenu;
HFONT hLangFont;
HMENU hMenu = GetMenu(g_DialogHwnd);
g_cur_lang_id = defaultLangId;
g_cur_lang_data = g_language_data + defaultLangId;
hLangFont = CreateFont(g_language_data[defaultLangId].FontSize, 0, 0, 0, 400, FALSE, FALSE, 0,
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH, g_language_data[defaultLangId].FontFamily);
SendMessage(g_BtnInstallHwnd, WM_SETFONT, (WPARAM)hLangFont, TRUE);
SendMessage(g_BtnUpdateHwnd, WM_SETFONT, (WPARAM)hLangFont, TRUE);
SendMessage(g_StaticStatusHwnd, WM_SETFONT, (WPARAM)hLangFont, TRUE);
SendMessage(g_StaticLocalHwnd, WM_SETFONT, (WPARAM)hLangFont, TRUE);
SendMessage(g_StaticDiskHwnd, WM_SETFONT, (WPARAM)hLangFont, TRUE);
SendMessage(g_StaticDevHwnd, WM_SETFONT, (WPARAM)hLangFont, TRUE);
SendMessage(g_DialogHwnd, WM_SETFONT, (WPARAM)hLangFont, TRUE);
ModifyMenu(hMenu, 0, MF_BYPOSITION | MF_STRING, 0, _G(STR_MENU_OPTION));
SetWindowText(GetDlgItem(g_DialogHwnd, IDC_STATIC_DEV), _G(STR_DEVICE));
SetWindowText(GetDlgItem(g_DialogHwnd, IDC_STATIC_LOCAL), _G(STR_LOCAL_VER));
SetWindowText(GetDlgItem(g_DialogHwnd, IDC_STATIC_DISK), _G(STR_DISK_VER));
SetWindowText(g_StaticStatusHwnd, _G(STR_STATUS));
SetWindowText(g_BtnInstallHwnd, _G(STR_INSTALL));
SetWindowText(g_BtnUpdateHwnd, _G(STR_UPDATE));
SubMenu = GetSubMenu(hMenu, 0);
if (g_SecureBoot)
{
ModifyMenu(SubMenu, 0, MF_BYPOSITION | MF_STRING | MF_CHECKED, 0, _G(STR_MENU_SECURE_BOOT));
}
else
{
ModifyMenu(SubMenu, 0, MF_BYPOSITION | MF_STRING | MF_UNCHECKED, 0, _G(STR_MENU_SECURE_BOOT));
}
ShowWindow(g_DialogHwnd, SW_HIDE);
ShowWindow(g_DialogHwnd, SW_NORMAL);
//Update check
for (i = 0; i < g_language_count; i++)
{
CheckMenuItem(hMenu, VTOY_MENU_LANGUAGE_BEGIN | i, MF_BYCOMMAND | MF_STRING | MF_UNCHECKED);
}
CheckMenuItem(hMenu, VTOY_MENU_LANGUAGE_BEGIN | defaultLangId, MF_BYCOMMAND | MF_STRING | MF_CHECKED);
}
static void LanguageInit(void)
{
SetWindowText(GetDlgItem(g_DialogHwnd, IDC_STATIC_DEV), _G(STR_DEVICE));
SetWindowText(GetDlgItem(g_DialogHwnd, IDC_STATIC_LOCAL), _G(STR_LOCAL_VER));
SetWindowText(GetDlgItem(g_DialogHwnd, IDC_STATIC_DISK), _G(STR_DISK_VER));
SetWindowText(g_StaticStatusHwnd, _G(STR_STATUS));
int i, j, k;
int id, DefaultId;
WCHAR Language[64];
WCHAR TmpBuf[256];
LANGID LangId = GetSystemDefaultUILanguage();
HMENU SubMenu;
HMENU hMenu = GetMenu(g_DialogHwnd);
SetWindowText(g_BtnInstallHwnd, _G(STR_INSTALL));
SetWindowText(g_BtnUpdateHwnd, _G(STR_UPDATE));
SubMenu = GetSubMenu(hMenu, 1);
DeleteMenu(SubMenu, 0, MF_BYPOSITION);
g_language_data = (VENTOY_LANGUAGE *)malloc(sizeof(VENTOY_LANGUAGE)* VENTOY_MAX_LANGUAGE);
memset(g_language_data, 0, sizeof(VENTOY_LANGUAGE)* VENTOY_MAX_LANGUAGE);
swprintf_s(Language, 64, L"StringDefine");
for (i = 0; i < STR_ID_MAX; i++)
{
swprintf_s(TmpBuf, 256, L"%d", i);
GET_INI_STRING(TmpBuf, g_language_data[0].StrId[i]);
}
for (i = 0; i < VENTOY_MAX_LANGUAGE; i++)
{
swprintf_s(Language, 64, L"Language%d", i);
GET_INI_STRING(TEXT("name"), g_language_data[i].Name);
if (g_language_data[i].Name[0] == '#')
{
break;
}
g_language_count++;
Log("Find Language%d ...", i);
AppendMenu(SubMenu, MF_STRING | MF_BYCOMMAND, VTOY_MENU_LANGUAGE_BEGIN | i, g_language_data[i].Name);
GET_INI_STRING(TEXT("FontFamily"), g_language_data[i].FontFamily);
g_language_data[i].FontSize = GetPrivateProfileInt(Language, TEXT("FontSize"), 10, VENTOY_LANGUAGE_INI);
for (j = 0; j < STR_ID_MAX; j++)
{
GET_INI_STRING(g_language_data[0].StrId[j], g_language_data[i].MsgString[j]);
for (k = 0; g_language_data[i].MsgString[j][k] && g_language_data[i].MsgString[j][k + 1]; k++)
{
if (g_language_data[i].MsgString[j][k] == '#' && g_language_data[i].MsgString[j][k + 1] == '@')
{
g_language_data[i].MsgString[j][k] = '\r';
g_language_data[i].MsgString[j][k + 1] = '\n';
}
}
}
}
DefaultId = (MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED) == LangId) ? 0 : 1;
id = GetPrivateProfileInt(TEXT("Ventoy"), TEXT("Language"), DefaultId, VENTOY_CFG_INI);
if (id >= i)
{
id = DefaultId;
}
UpdateItemString(id);
}
static BOOL InitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
@@ -149,6 +298,13 @@ static BOOL InitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
g_StaticLocalVerHwnd = GetDlgItem(hWnd, IDC_STATIC_LOCAL_VER);
g_StaticDiskVerHwnd = GetDlgItem(hWnd, IDC_STATIC_DISK_VER);
g_BtnInstallHwnd = GetDlgItem(hWnd, IDC_BUTTON4);
g_StaticDevHwnd = GetDlgItem(hWnd, IDC_STATIC_DEV);
g_StaticLocalHwnd = GetDlgItem(hWnd, IDC_STATIC_LOCAL);
g_StaticDiskHwnd = GetDlgItem(hWnd, IDC_STATIC_DISK);
g_BtnUpdateHwnd = GetDlgItem(hWnd, IDC_BUTTON3);
g_ProgressBarHwnd = GetDlgItem(hWnd, IDC_PROGRESS1);
g_StaticStatusHwnd = GetDlgItem(hWnd, IDC_STATIC_STATUS);
@@ -160,8 +316,12 @@ static BOOL InitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
SendMessage(g_ProgressBarHwnd, PBM_SETRANGE, (WPARAM)0, (LPARAM)(MAKELPARAM(0, PT_FINISH)));
PROGRESS_BAR_SET_POS(PT_START);
SetMenu(hWnd, LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_MENU1)));
LoadCfgIni();
LanguageInit();
// Fill device combox
hCombox = GetDlgItem(hWnd, IDC_COMBO1);
for (i = 0; i < g_PhyDriveCount; i++)
@@ -358,6 +518,31 @@ static void OnUpdateBtnClick(void)
g_ThreadHandle = CreateThread(NULL, 0, UpdateVentoyThread, (LPVOID)pPhyDrive, 0, NULL);
}
static void MenuProc(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
WORD CtrlID;
HMENU hMenu = GetMenu(hWnd);
CtrlID = LOWORD(wParam);
if (CtrlID == 0)
{
g_SecureBoot = !g_SecureBoot;
if (g_SecureBoot)
{
CheckMenuItem(hMenu, 0, MF_BYCOMMAND | MF_STRING | MF_CHECKED);
}
else
{
CheckMenuItem(hMenu, 0, MF_BYCOMMAND | MF_STRING | MF_UNCHECKED);
}
}
else if (CtrlID >= VTOY_MENU_LANGUAGE_BEGIN && CtrlID < VTOY_MENU_LANGUAGE_BEGIN + g_language_count)
{
UpdateItemString(CtrlID - VTOY_MENU_LANGUAGE_BEGIN);
}
}
INT_PTR CALLBACK DialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
@@ -385,6 +570,10 @@ INT_PTR CALLBACK DialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lPara
OnUpdateBtnClick();
}
if (lParam == 0 && NotifyCode == 0)
{
MenuProc(hWnd, wParam, lParam);
}
break;
}
@@ -417,6 +606,7 @@ INT_PTR CALLBACK DialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lPara
{
EndDialog(hWnd, 0);
}
WriteCfgIni();
break;
}
}
@@ -430,7 +620,14 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
if (!IsFileExist(VENTOY_FILE_VERSION))
{
MessageBox(NULL, _G(STR_INCORRECT_DIR), _G(STR_ERROR), MB_OK | MB_ICONERROR);
if (IsDirExist("grub"))
{
MessageBox(NULL, _G(STR_INCORRECT_DIR), _G(STR_ERROR), MB_OK | MB_ICONERROR);
}
else
{
MessageBox(NULL, _G(STR_INCORRECT_DIR), _G(STR_ERROR), MB_OK | MB_ICONERROR);
}
return ERROR_NOT_FOUND;
}
@@ -444,6 +641,8 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
Ventoy2DiskInit();
g_hInst = hInstance;
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DialogProc);

Binary file not shown.

View File

@@ -328,6 +328,11 @@ static int vtoy_find_disk_by_size(unsigned long long size, char *diskname)
int rc = 0;
dir = opendir("/sys/block");
if (!dir)
{
return 0;
}
while ((p = readdir(dir)) != NULL)
{
if (!vtoy_is_possible_blkdev(p->d_name))
@@ -357,6 +362,11 @@ static int vtoy_find_disk_by_guid(uint8_t *guid, char *diskname)
uint8_t vtguid[16];
dir = opendir("/sys/block");
if (!dir)
{
return 0;
}
while ((p = readdir(dir)) != NULL)
{
if (!vtoy_is_possible_blkdev(p->d_name))
@@ -378,6 +388,12 @@ static int vtoy_find_disk_by_guid(uint8_t *guid, char *diskname)
return count;
}
static int vtoy_printf_iso_path(ventoy_os_param *param)
{
printf("%s\n", param->vtoy_img_path);
return 0;
}
static int vtoy_print_os_param(ventoy_os_param *param, char *diskname)
{
int cnt = 0;
@@ -432,7 +448,7 @@ static int vtoy_check_device(ventoy_os_param *param, const char *device)
debug("param->vtoy_disk_size=%llu size=%llu\n",
(unsigned long long)param->vtoy_disk_size, (unsigned long long)size);
if (param->vtoy_disk_size == size &&
if ((param->vtoy_disk_size == size || param->vtoy_disk_size == size + 512) &&
memcmp(vtguid, param->vtoy_disk_guid, 16) == 0)
{
debug("<%s> is right ventoy disk\n", device);
@@ -458,12 +474,13 @@ int vtoydump_main(int argc, char **argv)
{
int rc;
int ch;
int print_path = 0;
char filename[256] = {0};
char diskname[256] = {0};
char device[64] = {0};
ventoy_os_param *param = NULL;
while ((ch = getopt(argc, argv, "c:f:v::")) != -1)
while ((ch = getopt(argc, argv, "c:f:p:v::")) != -1)
{
if (ch == 'f')
{
@@ -477,6 +494,11 @@ int vtoydump_main(int argc, char **argv)
{
strncpy(device, optarg, sizeof(device) - 1);
}
else if (ch == 'p')
{
print_path = 1;
strncpy(filename, optarg, sizeof(filename) - 1);
}
else
{
fprintf(stderr, "Usage: %s -f datafile [ -v ] \n", argv[0]);
@@ -513,7 +535,11 @@ int vtoydump_main(int argc, char **argv)
vtoy_dump_os_param(param);
}
if (device[0])
if (print_path)
{
rc = vtoy_printf_iso_path(param);
}
else if (device[0])
{
rc = vtoy_check_device(param, device);
}

Binary file not shown.

Binary file not shown.