mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-09-17 09:21:15 +00:00
Compare commits
34 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
84c500666a | ||
|
fe0dda6904 | ||
|
af1222be42 | ||
|
b3e796583c | ||
|
1d117b537d | ||
|
3c78caf1f5 | ||
|
7a65572096 | ||
|
6142cb0e32 | ||
|
a20ee56f83 | ||
|
d0edcc0ef0 | ||
|
c84c072209 | ||
|
8204c31df8 | ||
|
f028a6f89c | ||
|
263f5dd3a8 | ||
|
cf4b82e4db | ||
|
fdfa7e22c9 | ||
|
835cb958ed | ||
|
ce9c679ab3 | ||
|
967a259cee | ||
|
f25289e379 | ||
|
0490480467 | ||
|
0a1b6e221c | ||
|
3fc76d6b63 | ||
|
474b9a3fad | ||
|
3ca624f3ee | ||
|
d42bc35915 | ||
|
39b5edc345 | ||
|
9c183ed416 | ||
|
8e0c630fe5 | ||
|
9f57cb3929 | ||
|
525ef4f516 | ||
|
212c9cdbc9 | ||
|
ad9a031092 | ||
|
d5b829f8e8 |
@@ -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();
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
757
GPLv3
757
GPLv3
@@ -1,165 +1,674 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
0. Additional Definitions.
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
0. Definitions.
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
4. Combined Works.
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
1. Source Code.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
d) Do one of the following:
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
5. Combined Libraries.
|
||||
2. Basic Permissions.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
|
@@ -374,7 +374,7 @@ static int ventoy_is_mbr_match(ventoy_mbr_head *head)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (head->PartTbl[0].FsFlag != 0x07 || head->PartTbl[0].StartSectorId != 2048) {
|
||||
if (head->PartTbl[0].StartSectorId != 2048) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
1100
GRUB2/grub-2.04/grub-core/fs/ext2.c
Normal file
1100
GRUB2/grub-2.04/grub-core/fs/ext2.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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,10 @@ 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;
|
||||
|
||||
if (!info.dir)
|
||||
info.size = ctxt.dir.file_size;
|
||||
|
||||
#ifdef MODE_EXFAT
|
||||
if (!ctxt.dir.have_stream)
|
||||
continue;
|
||||
@@ -1270,54 +1274,6 @@ GRUB_MOD_FINI(fat)
|
||||
|
||||
#ifdef MODE_EXFAT
|
||||
|
||||
static int grub_fat_add_chunk(ventoy_img_chunk_list *chunk_list, grub_uint64_t sector, grub_uint64_t size, grub_uint32_t log_sector_size)
|
||||
{
|
||||
ventoy_img_chunk *last_chunk;
|
||||
ventoy_img_chunk *new_chunk;
|
||||
|
||||
if (chunk_list->cur_chunk == 0)
|
||||
{
|
||||
chunk_list->chunk[0].img_start_sector = 0;
|
||||
chunk_list->chunk[0].img_end_sector = (size >> 11) - 1;
|
||||
chunk_list->chunk[0].disk_start_sector = sector;
|
||||
chunk_list->chunk[0].disk_end_sector = sector + (size >> log_sector_size) - 1;
|
||||
chunk_list->cur_chunk = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
last_chunk = chunk_list->chunk + chunk_list->cur_chunk - 1;
|
||||
if (last_chunk->disk_end_sector + 1 == sector)
|
||||
{
|
||||
last_chunk->img_end_sector += (size >> 11);
|
||||
last_chunk->disk_end_sector += (size >> log_sector_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (chunk_list->cur_chunk == chunk_list->max_chunk)
|
||||
{
|
||||
new_chunk = grub_realloc(chunk_list->chunk, chunk_list->max_chunk * 2 * sizeof(ventoy_img_chunk));
|
||||
if (NULL == new_chunk)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
chunk_list->chunk = new_chunk;
|
||||
chunk_list->max_chunk *= 2;
|
||||
|
||||
/* issue: update last_chunk */
|
||||
last_chunk = chunk_list->chunk + chunk_list->cur_chunk - 1;
|
||||
}
|
||||
|
||||
new_chunk = chunk_list->chunk + chunk_list->cur_chunk;
|
||||
new_chunk->img_start_sector = last_chunk->img_end_sector + 1;
|
||||
new_chunk->img_end_sector = new_chunk->img_start_sector + (size >> 11) - 1;
|
||||
new_chunk->disk_start_sector = sector;
|
||||
new_chunk->disk_end_sector = sector + (size >> log_sector_size) - 1;
|
||||
|
||||
chunk_list->cur_chunk++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int grub_fat_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_img_chunk_list *chunk_list)
|
||||
{
|
||||
grub_size_t size;
|
||||
@@ -1409,7 +1365,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;
|
||||
@@ -1427,7 +1383,7 @@ int grub_fat_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_i
|
||||
if (size > len)
|
||||
size = len;
|
||||
|
||||
grub_fat_add_chunk(chunk_list, sector, size, disk->log_sector_size);
|
||||
grub_disk_blocklist_read(chunk_list, sector, size, disk->log_sector_size);
|
||||
|
||||
len -= size;
|
||||
logical_cluster++;
|
||||
@@ -1445,4 +1401,3 @@ END:
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
1239
GRUB2/grub-2.04/grub-core/fs/ntfs.c
Normal file
1239
GRUB2/grub-2.04/grub-core/fs/ntfs.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1152,6 +1152,8 @@ grub_udf_dir_iter (const char *filename, enum grub_fshelp_filetype filetype,
|
||||
|
||||
info.mtime -= 60 * tz;
|
||||
}
|
||||
if (!info.dir)
|
||||
info.size = U64 (node->block.fe.file_size);
|
||||
grub_free (node);
|
||||
return ctx->hook (filename, &info, ctx->hook_data);
|
||||
}
|
||||
|
1164
GRUB2/grub-2.04/grub-core/fs/xfs.c
Normal file
1164
GRUB2/grub-2.04/grub-core/fs/xfs.c
Normal file
File diff suppressed because it is too large
Load Diff
600
GRUB2/grub-2.04/grub-core/kern/disk.c
Normal file
600
GRUB2/grub-2.04/grub-core/kern/disk.c
Normal file
@@ -0,0 +1,600 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2003,2004,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB 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.
|
||||
*
|
||||
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/disk.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/partition.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/ventoy.h>
|
||||
|
||||
#define GRUB_CACHE_TIMEOUT 2
|
||||
|
||||
/* The last time the disk was used. */
|
||||
static grub_uint64_t grub_last_time = 0;
|
||||
|
||||
struct grub_disk_cache grub_disk_cache_table[GRUB_DISK_CACHE_NUM];
|
||||
|
||||
void (*grub_disk_firmware_fini) (void);
|
||||
int grub_disk_firmware_is_tainted;
|
||||
|
||||
#if DISK_CACHE_STATS
|
||||
static unsigned long grub_disk_cache_hits;
|
||||
static unsigned long grub_disk_cache_misses;
|
||||
|
||||
void
|
||||
grub_disk_cache_get_performance (unsigned long *hits, unsigned long *misses)
|
||||
{
|
||||
*hits = grub_disk_cache_hits;
|
||||
*misses = grub_disk_cache_misses;
|
||||
}
|
||||
#endif
|
||||
|
||||
grub_err_t (*grub_disk_write_weak) (grub_disk_t disk,
|
||||
grub_disk_addr_t sector,
|
||||
grub_off_t offset,
|
||||
grub_size_t size,
|
||||
const void *buf);
|
||||
#include "disk_common.c"
|
||||
|
||||
void
|
||||
grub_disk_cache_invalidate_all (void)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < GRUB_DISK_CACHE_NUM; i++)
|
||||
{
|
||||
struct grub_disk_cache *cache = grub_disk_cache_table + i;
|
||||
|
||||
if (cache->data && ! cache->lock)
|
||||
{
|
||||
grub_free (cache->data);
|
||||
cache->data = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
grub_disk_cache_fetch (unsigned long dev_id, unsigned long disk_id,
|
||||
grub_disk_addr_t sector)
|
||||
{
|
||||
struct grub_disk_cache *cache;
|
||||
unsigned cache_index;
|
||||
|
||||
cache_index = grub_disk_cache_get_index (dev_id, disk_id, sector);
|
||||
cache = grub_disk_cache_table + cache_index;
|
||||
|
||||
if (cache->dev_id == dev_id && cache->disk_id == disk_id
|
||||
&& cache->sector == sector)
|
||||
{
|
||||
cache->lock = 1;
|
||||
#if DISK_CACHE_STATS
|
||||
grub_disk_cache_hits++;
|
||||
#endif
|
||||
return cache->data;
|
||||
}
|
||||
|
||||
#if DISK_CACHE_STATS
|
||||
grub_disk_cache_misses++;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_disk_cache_unlock (unsigned long dev_id, unsigned long disk_id,
|
||||
grub_disk_addr_t sector)
|
||||
{
|
||||
struct grub_disk_cache *cache;
|
||||
unsigned cache_index;
|
||||
|
||||
cache_index = grub_disk_cache_get_index (dev_id, disk_id, sector);
|
||||
cache = grub_disk_cache_table + cache_index;
|
||||
|
||||
if (cache->dev_id == dev_id && cache->disk_id == disk_id
|
||||
&& cache->sector == sector)
|
||||
cache->lock = 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_disk_cache_store (unsigned long dev_id, unsigned long disk_id,
|
||||
grub_disk_addr_t sector, const char *data)
|
||||
{
|
||||
unsigned cache_index;
|
||||
struct grub_disk_cache *cache;
|
||||
|
||||
cache_index = grub_disk_cache_get_index (dev_id, disk_id, sector);
|
||||
cache = grub_disk_cache_table + cache_index;
|
||||
|
||||
cache->lock = 1;
|
||||
grub_free (cache->data);
|
||||
cache->data = 0;
|
||||
cache->lock = 0;
|
||||
|
||||
cache->data = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
|
||||
if (! cache->data)
|
||||
return grub_errno;
|
||||
|
||||
grub_memcpy (cache->data, data,
|
||||
GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
|
||||
cache->dev_id = dev_id;
|
||||
cache->disk_id = disk_id;
|
||||
cache->sector = sector;
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
grub_disk_dev_t grub_disk_dev_list;
|
||||
|
||||
void
|
||||
grub_disk_dev_register (grub_disk_dev_t dev)
|
||||
{
|
||||
dev->next = grub_disk_dev_list;
|
||||
grub_disk_dev_list = dev;
|
||||
}
|
||||
|
||||
void
|
||||
grub_disk_dev_unregister (grub_disk_dev_t dev)
|
||||
{
|
||||
grub_disk_dev_t *p, q;
|
||||
|
||||
for (p = &grub_disk_dev_list, q = *p; q; p = &(q->next), q = q->next)
|
||||
if (q == dev)
|
||||
{
|
||||
*p = q->next;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the location of the first ',', if any, which is not
|
||||
escaped by a '\'. */
|
||||
static const char *
|
||||
find_part_sep (const char *name)
|
||||
{
|
||||
const char *p = name;
|
||||
char c;
|
||||
|
||||
while ((c = *p++) != '\0')
|
||||
{
|
||||
if (c == '\\' && *p == ',')
|
||||
p++;
|
||||
else if (c == ',')
|
||||
return p - 1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
grub_disk_t
|
||||
grub_disk_open (const char *name)
|
||||
{
|
||||
const char *p;
|
||||
grub_disk_t disk;
|
||||
grub_disk_dev_t dev;
|
||||
char *raw = (char *) name;
|
||||
grub_uint64_t current_time;
|
||||
|
||||
grub_dprintf ("disk", "Opening `%s'...\n", name);
|
||||
|
||||
disk = (grub_disk_t) grub_zalloc (sizeof (*disk));
|
||||
if (! disk)
|
||||
return 0;
|
||||
disk->log_sector_size = GRUB_DISK_SECTOR_BITS;
|
||||
/* Default 1MiB of maximum agglomerate. */
|
||||
disk->max_agglomerate = 1048576 >> (GRUB_DISK_SECTOR_BITS
|
||||
+ GRUB_DISK_CACHE_BITS);
|
||||
|
||||
p = find_part_sep (name);
|
||||
if (p)
|
||||
{
|
||||
grub_size_t len = p - name;
|
||||
|
||||
raw = grub_malloc (len + 1);
|
||||
if (! raw)
|
||||
goto fail;
|
||||
|
||||
grub_memcpy (raw, name, len);
|
||||
raw[len] = '\0';
|
||||
disk->name = grub_strdup (raw);
|
||||
}
|
||||
else
|
||||
disk->name = grub_strdup (name);
|
||||
if (! disk->name)
|
||||
goto fail;
|
||||
|
||||
for (dev = grub_disk_dev_list; dev; dev = dev->next)
|
||||
{
|
||||
if ((dev->disk_open) (raw, disk) == GRUB_ERR_NONE)
|
||||
break;
|
||||
else if (grub_errno == GRUB_ERR_UNKNOWN_DEVICE)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
else
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (! dev)
|
||||
{
|
||||
grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("disk `%s' not found"),
|
||||
name);
|
||||
goto fail;
|
||||
}
|
||||
if (disk->log_sector_size > GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS
|
||||
|| disk->log_sector_size < GRUB_DISK_SECTOR_BITS)
|
||||
{
|
||||
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"sector sizes of %d bytes aren't supported yet",
|
||||
(1 << disk->log_sector_size));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
disk->dev = dev;
|
||||
|
||||
if (p)
|
||||
{
|
||||
disk->partition = grub_partition_probe (disk, p + 1);
|
||||
if (! disk->partition)
|
||||
{
|
||||
/* TRANSLATORS: It means that the specified partition e.g.
|
||||
hd0,msdos1=/dev/sda1 doesn't exist. */
|
||||
grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("no such partition"));
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
/* The cache will be invalidated about 2 seconds after a device was
|
||||
closed. */
|
||||
current_time = grub_get_time_ms ();
|
||||
|
||||
if (current_time > (grub_last_time
|
||||
+ GRUB_CACHE_TIMEOUT * 1000))
|
||||
grub_disk_cache_invalidate_all ();
|
||||
|
||||
grub_last_time = current_time;
|
||||
|
||||
fail:
|
||||
|
||||
if (raw && raw != name)
|
||||
grub_free (raw);
|
||||
|
||||
if (grub_errno != GRUB_ERR_NONE)
|
||||
{
|
||||
grub_error_push ();
|
||||
grub_dprintf ("disk", "Opening `%s' failed.\n", name);
|
||||
grub_error_pop ();
|
||||
|
||||
grub_disk_close (disk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return disk;
|
||||
}
|
||||
|
||||
void
|
||||
grub_disk_close (grub_disk_t disk)
|
||||
{
|
||||
grub_partition_t part;
|
||||
grub_dprintf ("disk", "Closing `%s'.\n", disk->name);
|
||||
|
||||
if (disk->dev && disk->dev->disk_close)
|
||||
(disk->dev->disk_close) (disk);
|
||||
|
||||
/* Reset the timer. */
|
||||
grub_last_time = grub_get_time_ms ();
|
||||
|
||||
while (disk->partition)
|
||||
{
|
||||
part = disk->partition->parent;
|
||||
grub_free (disk->partition);
|
||||
disk->partition = part;
|
||||
}
|
||||
grub_free ((void *) disk->name);
|
||||
grub_free (disk);
|
||||
}
|
||||
|
||||
/* Small read (less than cache size and not pass across cache unit boundaries).
|
||||
sector is already adjusted and is divisible by cache unit size.
|
||||
*/
|
||||
static grub_err_t
|
||||
grub_disk_read_small_real (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
grub_off_t offset, grub_size_t size, void *buf)
|
||||
{
|
||||
char *data;
|
||||
char *tmp_buf;
|
||||
|
||||
/* Fetch the cache. */
|
||||
data = grub_disk_cache_fetch (disk->dev->id, disk->id, sector);
|
||||
if (data)
|
||||
{
|
||||
/* Just copy it! */
|
||||
grub_memcpy (buf, data + offset, size);
|
||||
grub_disk_cache_unlock (disk->dev->id, disk->id, sector);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
/* Allocate a temporary buffer. */
|
||||
tmp_buf = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
|
||||
if (! tmp_buf)
|
||||
return grub_errno;
|
||||
|
||||
/* Otherwise read data from the disk actually. */
|
||||
if (disk->total_sectors == GRUB_DISK_SIZE_UNKNOWN
|
||||
|| sector + GRUB_DISK_CACHE_SIZE
|
||||
< (disk->total_sectors << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)))
|
||||
{
|
||||
grub_err_t err;
|
||||
err = (disk->dev->disk_read) (disk, transform_sector (disk, sector),
|
||||
1U << (GRUB_DISK_CACHE_BITS
|
||||
+ GRUB_DISK_SECTOR_BITS
|
||||
- disk->log_sector_size), tmp_buf);
|
||||
if (!err)
|
||||
{
|
||||
/* Copy it and store it in the disk cache. */
|
||||
grub_memcpy (buf, tmp_buf + offset, size);
|
||||
grub_disk_cache_store (disk->dev->id, disk->id,
|
||||
sector, tmp_buf);
|
||||
grub_free (tmp_buf);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
grub_free (tmp_buf);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
{
|
||||
/* Uggh... Failed. Instead, just read necessary data. */
|
||||
unsigned num;
|
||||
grub_disk_addr_t aligned_sector;
|
||||
|
||||
sector += (offset >> GRUB_DISK_SECTOR_BITS);
|
||||
offset &= ((1 << GRUB_DISK_SECTOR_BITS) - 1);
|
||||
aligned_sector = (sector & ~((1ULL << (disk->log_sector_size
|
||||
- GRUB_DISK_SECTOR_BITS))
|
||||
- 1));
|
||||
offset += ((sector - aligned_sector) << GRUB_DISK_SECTOR_BITS);
|
||||
num = ((size + offset + (1ULL << (disk->log_sector_size))
|
||||
- 1) >> (disk->log_sector_size));
|
||||
|
||||
tmp_buf = grub_malloc (num << disk->log_sector_size);
|
||||
if (!tmp_buf)
|
||||
return grub_errno;
|
||||
|
||||
if ((disk->dev->disk_read) (disk, transform_sector (disk, aligned_sector),
|
||||
num, tmp_buf))
|
||||
{
|
||||
grub_error_push ();
|
||||
grub_dprintf ("disk", "%s read failed\n", disk->name);
|
||||
grub_error_pop ();
|
||||
grub_free (tmp_buf);
|
||||
return grub_errno;
|
||||
}
|
||||
grub_memcpy (buf, tmp_buf + offset, size);
|
||||
grub_free (tmp_buf);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_disk_read_small (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
grub_off_t offset, grub_size_t size, void *buf)
|
||||
{
|
||||
grub_err_t err;
|
||||
|
||||
err = grub_disk_read_small_real (disk, sector, offset, size, buf);
|
||||
if (err)
|
||||
return err;
|
||||
if (disk->read_hook)
|
||||
(disk->read_hook) (sector + (offset >> GRUB_DISK_SECTOR_BITS),
|
||||
offset & (GRUB_DISK_SECTOR_SIZE - 1),
|
||||
size, disk->read_hook_data);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t grub_disk_blocklist_read(void *chunklist, grub_uint64_t sector,
|
||||
grub_uint64_t size, grub_uint32_t log_sector_size)
|
||||
{
|
||||
ventoy_img_chunk *last_chunk = NULL;
|
||||
ventoy_img_chunk *new_chunk = NULL;
|
||||
ventoy_img_chunk_list *chunk_list = (ventoy_img_chunk_list *)chunklist;
|
||||
|
||||
if (chunk_list->cur_chunk == 0)
|
||||
{
|
||||
chunk_list->chunk[0].img_start_sector = 0;
|
||||
chunk_list->chunk[0].img_end_sector = (size >> 11) - 1;
|
||||
chunk_list->chunk[0].disk_start_sector = sector;
|
||||
chunk_list->chunk[0].disk_end_sector = sector + (size >> log_sector_size) - 1;
|
||||
chunk_list->cur_chunk = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
last_chunk = chunk_list->chunk + chunk_list->cur_chunk - 1;
|
||||
if (last_chunk->disk_end_sector + 1 == sector)
|
||||
{
|
||||
last_chunk->img_end_sector += (size >> 11);
|
||||
last_chunk->disk_end_sector += (size >> log_sector_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (chunk_list->cur_chunk == chunk_list->max_chunk)
|
||||
{
|
||||
new_chunk = grub_realloc(chunk_list->chunk, chunk_list->max_chunk * 2 * sizeof(ventoy_img_chunk));
|
||||
if (NULL == new_chunk)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
chunk_list->chunk = new_chunk;
|
||||
chunk_list->max_chunk *= 2;
|
||||
|
||||
/* issue: update last_chunk */
|
||||
last_chunk = chunk_list->chunk + chunk_list->cur_chunk - 1;
|
||||
}
|
||||
|
||||
new_chunk = chunk_list->chunk + chunk_list->cur_chunk;
|
||||
new_chunk->img_start_sector = last_chunk->img_end_sector + 1;
|
||||
new_chunk->img_end_sector = new_chunk->img_start_sector + (size >> 11) - 1;
|
||||
new_chunk->disk_start_sector = sector;
|
||||
new_chunk->disk_end_sector = sector + (size >> log_sector_size) - 1;
|
||||
|
||||
chunk_list->cur_chunk++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Read data from the disk. */
|
||||
grub_err_t
|
||||
grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
grub_off_t offset, grub_size_t size, void *buf)
|
||||
{
|
||||
if (disk->read_hook == (grub_disk_read_hook_t)grub_disk_blocklist_read)
|
||||
{
|
||||
return grub_disk_blocklist_read((ventoy_img_chunk_list *)disk->read_hook_data, sector, size, disk->log_sector_size);
|
||||
}
|
||||
|
||||
/* First of all, check if the region is within the disk. */
|
||||
if (grub_disk_adjust_range (disk, §or, &offset, size) != GRUB_ERR_NONE)
|
||||
{
|
||||
grub_error_push ();
|
||||
grub_dprintf ("disk", "Read out of range: sector 0x%llx (%s).\n",
|
||||
(unsigned long long) sector, grub_errmsg);
|
||||
grub_error_pop ();
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
/* First read until first cache boundary. */
|
||||
if (offset || (sector & (GRUB_DISK_CACHE_SIZE - 1)))
|
||||
{
|
||||
grub_disk_addr_t start_sector;
|
||||
grub_size_t pos;
|
||||
grub_err_t err;
|
||||
grub_size_t len;
|
||||
|
||||
start_sector = sector & ~((grub_disk_addr_t) GRUB_DISK_CACHE_SIZE - 1);
|
||||
pos = (sector - start_sector) << GRUB_DISK_SECTOR_BITS;
|
||||
len = ((GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS)
|
||||
- pos - offset);
|
||||
if (len > size)
|
||||
len = size;
|
||||
err = grub_disk_read_small (disk, start_sector,
|
||||
offset + pos, len, buf);
|
||||
if (err)
|
||||
return err;
|
||||
buf = (char *) buf + len;
|
||||
size -= len;
|
||||
offset += len;
|
||||
sector += (offset >> GRUB_DISK_SECTOR_BITS);
|
||||
offset &= ((1 << GRUB_DISK_SECTOR_BITS) - 1);
|
||||
}
|
||||
|
||||
/* Until SIZE is zero... */
|
||||
while (size >= (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS))
|
||||
{
|
||||
char *data = NULL;
|
||||
grub_disk_addr_t agglomerate;
|
||||
grub_err_t err;
|
||||
|
||||
/* agglomerate read until we find a first cached entry. */
|
||||
for (agglomerate = 0; agglomerate
|
||||
< (size >> (GRUB_DISK_SECTOR_BITS + GRUB_DISK_CACHE_BITS))
|
||||
&& agglomerate < disk->max_agglomerate;
|
||||
agglomerate++)
|
||||
{
|
||||
data = grub_disk_cache_fetch (disk->dev->id, disk->id,
|
||||
sector + (agglomerate
|
||||
<< GRUB_DISK_CACHE_BITS));
|
||||
if (data)
|
||||
break;
|
||||
}
|
||||
|
||||
if (data)
|
||||
{
|
||||
grub_memcpy ((char *) buf
|
||||
+ (agglomerate << (GRUB_DISK_CACHE_BITS
|
||||
+ GRUB_DISK_SECTOR_BITS)),
|
||||
data, GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS);
|
||||
grub_disk_cache_unlock (disk->dev->id, disk->id,
|
||||
sector + (agglomerate
|
||||
<< GRUB_DISK_CACHE_BITS));
|
||||
}
|
||||
|
||||
if (agglomerate)
|
||||
{
|
||||
grub_disk_addr_t i;
|
||||
|
||||
err = (disk->dev->disk_read) (disk, transform_sector (disk, sector),
|
||||
agglomerate << (GRUB_DISK_CACHE_BITS
|
||||
+ GRUB_DISK_SECTOR_BITS
|
||||
- disk->log_sector_size),
|
||||
buf);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
for (i = 0; i < agglomerate; i ++)
|
||||
grub_disk_cache_store (disk->dev->id, disk->id,
|
||||
sector + (i << GRUB_DISK_CACHE_BITS),
|
||||
(char *) buf
|
||||
+ (i << (GRUB_DISK_CACHE_BITS
|
||||
+ GRUB_DISK_SECTOR_BITS)));
|
||||
|
||||
|
||||
if (disk->read_hook)
|
||||
(disk->read_hook) (sector, 0, agglomerate << (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS),
|
||||
disk->read_hook_data);
|
||||
|
||||
sector += agglomerate << GRUB_DISK_CACHE_BITS;
|
||||
size -= agglomerate << (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS);
|
||||
buf = (char *) buf
|
||||
+ (agglomerate << (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS));
|
||||
}
|
||||
|
||||
if (data)
|
||||
{
|
||||
if (disk->read_hook)
|
||||
(disk->read_hook) (sector, 0, (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS),
|
||||
disk->read_hook_data);
|
||||
sector += GRUB_DISK_CACHE_SIZE;
|
||||
buf = (char *) buf + (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS);
|
||||
size -= (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS);
|
||||
}
|
||||
}
|
||||
|
||||
/* And now read the last part. */
|
||||
if (size)
|
||||
{
|
||||
grub_err_t err;
|
||||
err = grub_disk_read_small (disk, sector, 0, size, buf);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
grub_uint64_t
|
||||
grub_disk_get_size (grub_disk_t disk)
|
||||
{
|
||||
if (disk->partition)
|
||||
return grub_partition_get_len (disk->partition);
|
||||
else if (disk->total_sectors != GRUB_DISK_SIZE_UNKNOWN)
|
||||
return disk->total_sectors << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS);
|
||||
else
|
||||
return GRUB_DISK_SIZE_UNKNOWN;
|
||||
}
|
@@ -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. */
|
||||
|
@@ -37,6 +37,7 @@
|
||||
#include <grub/efi/efi.h>
|
||||
#endif
|
||||
#include <grub/time.h>
|
||||
#include <grub/relocator.h>
|
||||
#include <grub/ventoy.h>
|
||||
#include "ventoy_def.h"
|
||||
|
||||
@@ -52,11 +53,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 +69,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;
|
||||
@@ -90,6 +101,36 @@ int ventoy_is_efi_os(void)
|
||||
return g_efi_os;
|
||||
}
|
||||
|
||||
static int ventoy_get_fs_type(const char *fs)
|
||||
{
|
||||
if (NULL == fs)
|
||||
{
|
||||
return ventoy_fs_max;
|
||||
}
|
||||
else if (grub_strncmp(fs, "exfat", 5) == 0)
|
||||
{
|
||||
return ventoy_fs_exfat;
|
||||
}
|
||||
else if (grub_strncmp(fs, "ntfs", 4) == 0)
|
||||
{
|
||||
return ventoy_fs_ntfs;
|
||||
}
|
||||
else if (grub_strncmp(fs, "ext", 3) == 0)
|
||||
{
|
||||
return ventoy_fs_ext;
|
||||
}
|
||||
else if (grub_strncmp(fs, "xfs", 3) == 0)
|
||||
{
|
||||
return ventoy_fs_xfs;
|
||||
}
|
||||
else if (grub_strncmp(fs, "udf", 3) == 0)
|
||||
{
|
||||
return ventoy_fs_udf;
|
||||
}
|
||||
|
||||
return ventoy_fs_max;
|
||||
}
|
||||
|
||||
static int ventoy_string_check(const char *str, grub_char_check_func check)
|
||||
{
|
||||
if (!str)
|
||||
@@ -530,7 +571,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 +601,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 +634,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 +668,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 +738,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 +842,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 +941,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,34 +961,49 @@ 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;
|
||||
}
|
||||
|
||||
grub_memset(&g_img_iterator_head, 0, sizeof(g_img_iterator_head));
|
||||
|
||||
g_img_iterator_head.tail = &tail;
|
||||
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)
|
||||
if (ventoy_get_fs_type(fs->name) >= ventoy_fs_max)
|
||||
{
|
||||
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);
|
||||
debug("unsupported fs:<%s>\n", fs->name);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
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, "/");
|
||||
|
||||
for (node = &g_img_iterator_head; node; node = node->next)
|
||||
{
|
||||
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 +1016,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 +1100,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 +1112,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 +1138,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);
|
||||
}
|
||||
|
||||
@@ -1012,19 +1249,7 @@ void ventoy_fill_os_param(grub_file_t file, ventoy_os_param *param)
|
||||
|
||||
param->vtoy_disk_size = disk->total_sectors * (1 << disk->log_sector_size);
|
||||
param->vtoy_disk_part_id = disk->partition->number + 1;
|
||||
|
||||
if (grub_strcmp(file->fs->name, "exfat") == 0)
|
||||
{
|
||||
param->vtoy_disk_part_type = 0;
|
||||
}
|
||||
else if (grub_strcmp(file->fs->name, "ntfs") == 0)
|
||||
{
|
||||
param->vtoy_disk_part_type = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
param->vtoy_disk_part_type = 0xFFFF;
|
||||
}
|
||||
param->vtoy_disk_part_type = ventoy_get_fs_type(file->fs->name);
|
||||
|
||||
pos = grub_strstr(file->name, "/");
|
||||
if (!pos)
|
||||
@@ -1051,6 +1276,52 @@ void ventoy_fill_os_param(grub_file_t file, ventoy_os_param *param)
|
||||
return;
|
||||
}
|
||||
|
||||
static int ventoy_get_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start)
|
||||
{
|
||||
int fs_type;
|
||||
grub_uint32_t i = 0;
|
||||
grub_uint32_t sector = 0;
|
||||
grub_uint32_t count = 0;
|
||||
grub_off_t size = 0;
|
||||
grub_off_t read = 0;
|
||||
|
||||
fs_type = ventoy_get_fs_type(file->fs->name);
|
||||
if (fs_type == ventoy_fs_exfat)
|
||||
{
|
||||
grub_fat_get_file_chunk(start, file, chunklist);
|
||||
}
|
||||
else
|
||||
{
|
||||
file->read_hook = (grub_disk_read_hook_t)grub_disk_blocklist_read;
|
||||
file->read_hook_data = chunklist;
|
||||
|
||||
for (size = file->size; size > 0; size -= read)
|
||||
{
|
||||
read = (size > VTOY_SIZE_1GB) ? VTOY_SIZE_1GB : size;
|
||||
grub_file_read(file, NULL, read);
|
||||
}
|
||||
|
||||
for (i = 0; start > 0 && i < chunklist->cur_chunk; i++)
|
||||
{
|
||||
chunklist->chunk[i].disk_start_sector += start;
|
||||
chunklist->chunk[i].disk_end_sector += start;
|
||||
}
|
||||
|
||||
if (ventoy_fs_udf == fs_type)
|
||||
{
|
||||
for (i = 0; i < chunklist->cur_chunk; i++)
|
||||
{
|
||||
count = (chunklist->chunk[i].disk_end_sector + 1 - chunklist->chunk[i].disk_start_sector) >> 2;
|
||||
chunklist->chunk[i].img_start_sector = sector;
|
||||
chunklist->chunk[i].img_end_sector = sector + count - 1;
|
||||
sector += count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t ventoy_cmd_img_sector(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
grub_file_t file;
|
||||
@@ -1080,11 +1351,12 @@ static grub_err_t ventoy_cmd_img_sector(grub_extcmd_context_t ctxt, int argc, ch
|
||||
g_img_chunk_list.max_chunk = DEFAULT_CHUNK_NUM;
|
||||
g_img_chunk_list.cur_chunk = 0;
|
||||
|
||||
debug("get fat file chunk part start:%llu\n", (unsigned long long)file->device->disk->partition->start);
|
||||
grub_fat_get_file_chunk(file->device->disk->partition->start, file, &g_img_chunk_list);
|
||||
ventoy_get_block_list(file, &g_img_chunk_list, file->device->disk->partition->start);
|
||||
|
||||
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 +1381,335 @@ static grub_err_t ventoy_cmd_dump_img_sector(grub_extcmd_context_t ctxt, int arg
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
static grub_err_t ventoy_cmd_relocator_chaindata(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
(void)args;
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
static grub_err_t ventoy_cmd_relocator_chaindata(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int rc = 0;
|
||||
ulong chain_len = 0;
|
||||
char *chain_data = NULL;
|
||||
char *relocator_addr = NULL;
|
||||
grub_relocator_chunk_t ch;
|
||||
struct grub_relocator *relocator = NULL;
|
||||
char envbuf[64] = { 0 };
|
||||
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
(void)args;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
chain_data = (char *)grub_strtoul(args[0], NULL, 16);
|
||||
chain_len = grub_strtoul(args[1], NULL, 10);
|
||||
|
||||
relocator = grub_relocator_new ();
|
||||
if (!relocator)
|
||||
{
|
||||
debug("grub_relocator_new failed %p %lu\n", chain_data, chain_len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = grub_relocator_alloc_chunk_addr (relocator, &ch,
|
||||
0x100000, // GRUB_LINUX_BZIMAGE_ADDR,
|
||||
chain_len);
|
||||
if (rc)
|
||||
{
|
||||
debug("grub_relocator_alloc_chunk_addr failed %d %p %lu\n", rc, chain_data, chain_len);
|
||||
grub_relocator_unload (relocator);
|
||||
return 1;
|
||||
}
|
||||
|
||||
relocator_addr = get_virtual_current_address(ch);
|
||||
|
||||
grub_memcpy(relocator_addr, chain_data, chain_len);
|
||||
|
||||
grub_relocator_unload (relocator);
|
||||
|
||||
grub_snprintf(envbuf, sizeof(envbuf), "0x%lx", (unsigned long)relocator_addr);
|
||||
grub_env_set("vtoy_chain_relocator_addr", envbuf);
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
#endif
|
||||
|
||||
static grub_err_t ventoy_cmd_test_block_list(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
grub_uint32_t i;
|
||||
grub_file_t file;
|
||||
ventoy_img_chunk_list chunklist;
|
||||
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
|
||||
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
|
||||
if (!file)
|
||||
{
|
||||
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s\n", args[0]);
|
||||
}
|
||||
|
||||
/* get image chunk data */
|
||||
grub_memset(&chunklist, 0, sizeof(chunklist));
|
||||
chunklist.chunk = grub_malloc(sizeof(ventoy_img_chunk) * DEFAULT_CHUNK_NUM);
|
||||
if (NULL == chunklist.chunk)
|
||||
{
|
||||
return grub_error(GRUB_ERR_OUT_OF_MEMORY, "Can't allocate image chunk memoty\n");
|
||||
}
|
||||
|
||||
chunklist.max_chunk = DEFAULT_CHUNK_NUM;
|
||||
chunklist.cur_chunk = 0;
|
||||
|
||||
ventoy_get_block_list(file, &chunklist, 0);
|
||||
|
||||
grub_file_close(file);
|
||||
|
||||
grub_printf("filesystem: <%s> entry number:<%u>\n", file->fs->name, chunklist.cur_chunk);
|
||||
|
||||
for (i = 0; i < chunklist.cur_chunk; i++)
|
||||
{
|
||||
grub_printf("%llu+%llu,", (ulonglong)chunklist.chunk[i].disk_start_sector,
|
||||
(ulonglong)(chunklist.chunk[i].disk_end_sector + 1 - chunklist.chunk[i].disk_start_sector));
|
||||
}
|
||||
|
||||
grub_printf("\n==================================\n");
|
||||
for (i = 0; i < chunklist.cur_chunk; i++)
|
||||
{
|
||||
grub_printf("%2u: [%llu %llu] - [%llu %llu]\n", i,
|
||||
(ulonglong)chunklist.chunk[i].img_start_sector,
|
||||
(ulonglong)chunklist.chunk[i].img_end_sector,
|
||||
(ulonglong)chunklist.chunk[i].disk_start_sector,
|
||||
(ulonglong)chunklist.chunk[i].disk_end_sector
|
||||
);
|
||||
}
|
||||
|
||||
grub_free(chunklist.chunk);
|
||||
|
||||
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_dump_auto_install(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
(void)args;
|
||||
|
||||
ventoy_plugin_dump_auto_install();
|
||||
|
||||
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)
|
||||
{
|
||||
static int configfile_mode = 0;
|
||||
char memfile[128] = {0};
|
||||
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
(void)args;
|
||||
|
||||
/*
|
||||
* args[0]: 0:normal 1:configfile
|
||||
* args[1]: 0:list_buf 1:tree_buf
|
||||
*/
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
debug("Invalid argc %d\n", argc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (args[0][0] == '0')
|
||||
{
|
||||
if (args[1][0] == '0')
|
||||
{
|
||||
grub_script_execute_sourcecode(g_list_script_buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_script_execute_sourcecode(g_tree_script_buf);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (configfile_mode)
|
||||
{
|
||||
debug("Now already in F3 mode %d\n", configfile_mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (args[1][0] == '0')
|
||||
{
|
||||
grub_snprintf(memfile, sizeof(memfile), "configfile mem:0x%llx:size:%d",
|
||||
(ulonglong)(ulong)g_list_script_buf, g_list_script_pos);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
configfile_mode = 1;
|
||||
grub_script_execute_sourcecode(memfile);
|
||||
configfile_mode = 0;
|
||||
}
|
||||
|
||||
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 +1761,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 +1795,11 @@ 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_dump_auto_install", ventoy_cmd_dump_auto_install, 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 +1818,11 @@ 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_relocator_chaindata", ventoy_cmd_relocator_chaindata, 0, NULL, "", "", NULL },
|
||||
{ "vt_test_block_list", ventoy_cmd_test_block_list, 0, NULL, "", "", NULL },
|
||||
|
||||
|
||||
{ "vt_load_plugin", ventoy_cmd_load_plugin, 0, NULL, "", "", NULL },
|
||||
};
|
||||
|
@@ -21,10 +21,15 @@
|
||||
#ifndef __VENTOY_DEF_H__
|
||||
#define __VENTOY_DEF_H__
|
||||
|
||||
#define VTOY_MAX_SCRIPT_BUF (4 * 1024 * 1024)
|
||||
|
||||
#define VTOY_SIZE_1GB 1073741824
|
||||
|
||||
#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 +120,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 +139,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];
|
||||
@@ -400,7 +420,7 @@ grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc,
|
||||
grub_err_t ventoy_cmd_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_valid_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
int ventoy_cpio_newc_fill_head(void *buf, int filesize, void *filedata, const char *name);
|
||||
int ventoy_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, const char *name);
|
||||
grub_file_t ventoy_grub_file_open(enum grub_file_type type, const char *fmt, ...);
|
||||
int ventoy_is_file_exist(const char *fmt, ...);
|
||||
int ventoy_fill_data(grub_uint32_t buflen, char *buffer);
|
||||
@@ -504,5 +524,54 @@ 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()
|
||||
|
||||
|
||||
typedef struct install_template
|
||||
{
|
||||
char isopath[256];
|
||||
char templatepath[256];
|
||||
|
||||
struct install_template *next;
|
||||
}install_template;
|
||||
|
||||
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);
|
||||
char * ventoy_plugin_get_install_template(const char *isopath);
|
||||
void ventoy_plugin_dump_auto_install(void);
|
||||
int ventoy_fill_windows_rtdata(void *buf, char *isopath);
|
||||
|
||||
|
||||
#endif /* __VENTOY_DEF_H__ */
|
||||
|
||||
|
@@ -588,7 +588,7 @@ static void ventoy_cpio_newc_fill_int(grub_uint32_t value, char *buf, int buflen
|
||||
}
|
||||
}
|
||||
|
||||
int ventoy_cpio_newc_fill_head(void *buf, int filesize, void *filedata, const char *name)
|
||||
int ventoy_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, const char *name)
|
||||
{
|
||||
int namelen = 0;
|
||||
int headlen = 0;
|
||||
@@ -852,18 +852,22 @@ grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc,
|
||||
|
||||
grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
grub_uint8_t *buf;
|
||||
char *template_file = NULL;
|
||||
char *template_buf = NULL;
|
||||
grub_uint8_t *buf = NULL;
|
||||
grub_uint32_t mod;
|
||||
grub_uint32_t headlen;
|
||||
grub_uint32_t initrd_head_len;
|
||||
grub_uint32_t padlen;
|
||||
grub_uint32_t img_chunk_size;
|
||||
grub_uint32_t template_size = 0;
|
||||
grub_file_t file;
|
||||
grub_file_t scriptfile;
|
||||
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
|
||||
if (argc != 1)
|
||||
if (argc != 3)
|
||||
{
|
||||
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s cpiofile\n", cmd_raw_name);
|
||||
}
|
||||
@@ -888,7 +892,30 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
|
||||
g_ventoy_cpio_size = 0;
|
||||
}
|
||||
|
||||
g_ventoy_cpio_buf = grub_malloc(file->size + 4096 + img_chunk_size);
|
||||
template_file = ventoy_plugin_get_install_template(args[1]);
|
||||
if (template_file)
|
||||
{
|
||||
debug("auto install template: <%s>\n", template_file);
|
||||
scriptfile = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", args[2], template_file);
|
||||
if (scriptfile)
|
||||
{
|
||||
debug("auto install script size %d\n", (int)scriptfile->size);
|
||||
template_size = scriptfile->size;
|
||||
template_buf = grub_malloc(template_size);
|
||||
if (template_buf)
|
||||
{
|
||||
grub_file_read(scriptfile, template_buf, template_size);
|
||||
}
|
||||
|
||||
grub_file_close(scriptfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
debug("Failed to open install script %s%s\n", args[2], template_file);
|
||||
}
|
||||
}
|
||||
|
||||
g_ventoy_cpio_buf = grub_malloc(file->size + 4096 + template_size + img_chunk_size);
|
||||
if (NULL == g_ventoy_cpio_buf)
|
||||
{
|
||||
grub_file_close(file);
|
||||
@@ -910,6 +937,12 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
|
||||
headlen = ventoy_cpio_newc_fill_head(buf, img_chunk_size, g_img_chunk_list.chunk, "ventoy/ventoy_image_map");
|
||||
buf += headlen + ventoy_align(img_chunk_size, 4);
|
||||
|
||||
if (template_buf)
|
||||
{
|
||||
headlen = ventoy_cpio_newc_fill_head(buf, template_size, template_buf, "ventoy/autoinstall");
|
||||
buf += headlen + ventoy_align(template_size, 4);
|
||||
}
|
||||
|
||||
/* step2: insert os param to cpio */
|
||||
headlen = ventoy_cpio_newc_fill_head(buf, 0, NULL, "ventoy/ventoy_os_param");
|
||||
padlen = sizeof(ventoy_os_param);
|
||||
|
@@ -38,6 +38,8 @@
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static install_template *g_install_template_head = NULL;
|
||||
|
||||
static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
const char *value;
|
||||
@@ -46,7 +48,15 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
|
||||
value = vtoy_json_get_string_ex(json->pstChild, "file");
|
||||
if (value)
|
||||
{
|
||||
grub_snprintf(filepath, sizeof(filepath), "%s/ventoy/%s", isodisk, value);
|
||||
if (value[0] == '/')
|
||||
{
|
||||
grub_snprintf(filepath, sizeof(filepath), "%s%s", isodisk, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_snprintf(filepath, sizeof(filepath), "%s/ventoy/%s", isodisk, value);
|
||||
}
|
||||
|
||||
if (ventoy_is_file_exist(filepath) == 0)
|
||||
{
|
||||
debug("Theme file %s does not exist\n", filepath);
|
||||
@@ -67,9 +77,67 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
const char *iso = NULL;
|
||||
const char *script = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
install_template *node = NULL;
|
||||
install_template *next = NULL;
|
||||
|
||||
(void)isodisk;
|
||||
|
||||
if (json->enDataType != JSON_TYPE_ARRAY)
|
||||
{
|
||||
debug("Not array %d\n", json->enDataType);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (g_install_template_head)
|
||||
{
|
||||
for (node = g_install_template_head; node; node = next)
|
||||
{
|
||||
next = node->next;
|
||||
grub_free(node);
|
||||
}
|
||||
|
||||
g_install_template_head = NULL;
|
||||
}
|
||||
|
||||
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
|
||||
{
|
||||
iso = vtoy_json_get_string_ex(pNode->pstChild, "image");
|
||||
if (iso && iso[0] == '/')
|
||||
{
|
||||
script = vtoy_json_get_string_ex(pNode->pstChild, "template");
|
||||
if (script && script[0] == '/')
|
||||
{
|
||||
node = grub_zalloc(sizeof(install_template));
|
||||
if (node)
|
||||
{
|
||||
grub_snprintf(node->isopath, sizeof(node->isopath), "%s", iso);
|
||||
grub_snprintf(node->templatepath, sizeof(node->templatepath), "%s", script);
|
||||
|
||||
if (g_install_template_head)
|
||||
{
|
||||
node->next = g_install_template_head;
|
||||
}
|
||||
|
||||
g_install_template_head = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static plugin_entry g_plugin_entries[] =
|
||||
{
|
||||
{ "theme", ventoy_plugin_theme_entry },
|
||||
{ "auto_install", ventoy_plugin_auto_install_entry },
|
||||
};
|
||||
|
||||
static int ventoy_parse_plugin_config(VTOY_JSON *json, const char *isodisk)
|
||||
@@ -149,3 +217,33 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
|
||||
void ventoy_plugin_dump_auto_install(void)
|
||||
{
|
||||
install_template *node = NULL;
|
||||
|
||||
for (node = g_install_template_head; node; node = node->next)
|
||||
{
|
||||
grub_printf("IMAGE:<%s>\n", node->isopath);
|
||||
grub_printf("SCRIPT:<%s>\n\n", node->templatepath);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
char * ventoy_plugin_get_install_template(const char *isopath)
|
||||
{
|
||||
install_template *node = NULL;
|
||||
|
||||
for (node = g_install_template_head; node; node = node->next)
|
||||
{
|
||||
if (grub_strcmp(node->isopath, isopath) == 0)
|
||||
{
|
||||
return node->templatepath;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@@ -401,7 +401,7 @@ static int ventoy_update_all_hash(void *meta_data, wim_directory_entry *dir)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dir->len == 0)
|
||||
if (dir->len < sizeof(wim_directory_entry))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -420,7 +420,7 @@ static int ventoy_update_all_hash(void *meta_data, wim_directory_entry *dir)
|
||||
}
|
||||
|
||||
dir = (wim_directory_entry *)((char *)dir + dir->len);
|
||||
} while (dir->len);
|
||||
} while (dir->len >= sizeof(wim_directory_entry));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -440,14 +440,14 @@ static int ventoy_cat_exe_file_data(grub_uint32_t exe_len, grub_uint8_t *exe_dat
|
||||
jump_align = ventoy_align(jump_len, 16);
|
||||
|
||||
g_wim_data.jump_exe_len = jump_len;
|
||||
g_wim_data.bin_raw_len = jump_align + sizeof(ventoy_os_param) + exe_len;
|
||||
g_wim_data.bin_raw_len = jump_align + sizeof(ventoy_os_param) + sizeof(ventoy_windows_data) + exe_len;
|
||||
g_wim_data.bin_align_len = ventoy_align(g_wim_data.bin_raw_len, 2048);
|
||||
|
||||
g_wim_data.jump_bin_data = grub_malloc(g_wim_data.bin_align_len);
|
||||
if (g_wim_data.jump_bin_data)
|
||||
{
|
||||
grub_memcpy(g_wim_data.jump_bin_data, jump_data, jump_len);
|
||||
grub_memcpy(g_wim_data.jump_bin_data + jump_align + sizeof(ventoy_os_param), exe_data, exe_len);
|
||||
grub_memcpy(g_wim_data.jump_bin_data + jump_align + sizeof(ventoy_os_param) + sizeof(ventoy_windows_data), exe_data, exe_len);
|
||||
}
|
||||
|
||||
debug("jump_exe_len:%u bin_raw_len:%u bin_align_len:%u\n",
|
||||
@@ -456,7 +456,35 @@ static int ventoy_cat_exe_file_data(grub_uint32_t exe_len, grub_uint8_t *exe_dat
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_update_before_chain(ventoy_os_param *param)
|
||||
int ventoy_fill_windows_rtdata(void *buf, char *isopath)
|
||||
{
|
||||
char *pos = NULL;
|
||||
char *script = NULL;
|
||||
ventoy_windows_data *data = (ventoy_windows_data *)buf;
|
||||
|
||||
grub_memset(data, 0, sizeof(ventoy_windows_data));
|
||||
|
||||
pos = grub_strstr(isopath, "/");
|
||||
if (!pos)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
script = ventoy_plugin_get_install_template(pos);
|
||||
if (script)
|
||||
{
|
||||
debug("auto install script <%s>\n", script);
|
||||
grub_snprintf(data->auto_install_script, sizeof(data->auto_install_script) - 1, "%s", script);
|
||||
}
|
||||
else
|
||||
{
|
||||
debug("auto install script not found %p\n", pos);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_update_before_chain(ventoy_os_param *param, char *isopath)
|
||||
{
|
||||
grub_uint32_t jump_align = 0;
|
||||
wim_lookup_entry *meta_look = NULL;
|
||||
@@ -469,6 +497,7 @@ static int ventoy_update_before_chain(ventoy_os_param *param)
|
||||
if (g_wim_data.jump_bin_data)
|
||||
{
|
||||
grub_memcpy(g_wim_data.jump_bin_data + jump_align, param, sizeof(ventoy_os_param));
|
||||
ventoy_fill_windows_rtdata(g_wim_data.jump_bin_data + jump_align + sizeof(ventoy_os_param), isopath);
|
||||
}
|
||||
|
||||
grub_crypto_hash(GRUB_MD_SHA1, g_wim_data.bin_hash.sha1, g_wim_data.jump_bin_data, g_wim_data.bin_raw_len);
|
||||
@@ -878,7 +907,7 @@ grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, c
|
||||
|
||||
if (g_wim_data.jump_bin_data && g_wim_data.new_meta_data)
|
||||
{
|
||||
ventoy_update_before_chain(&(chain->os_param));
|
||||
ventoy_update_before_chain(&(chain->os_param), args[0]);
|
||||
}
|
||||
|
||||
/* part 2: chain head */
|
||||
@@ -928,4 +957,3 @@ grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, c
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
|
||||
|
265
GRUB2/grub-2.04/include/grub/disk.h
Normal file
265
GRUB2/grub-2.04/include/grub/disk.h
Normal file
@@ -0,0 +1,265 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB 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.
|
||||
*
|
||||
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_DISK_HEADER
|
||||
#define GRUB_DISK_HEADER 1
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/device.h>
|
||||
/* For NULL. */
|
||||
#include <grub/mm.h>
|
||||
|
||||
/* These are used to set a device id. When you add a new disk device,
|
||||
you must define a new id for it here. */
|
||||
enum grub_disk_dev_id
|
||||
{
|
||||
GRUB_DISK_DEVICE_BIOSDISK_ID,
|
||||
GRUB_DISK_DEVICE_OFDISK_ID,
|
||||
GRUB_DISK_DEVICE_LOOPBACK_ID,
|
||||
GRUB_DISK_DEVICE_EFIDISK_ID,
|
||||
GRUB_DISK_DEVICE_DISKFILTER_ID,
|
||||
GRUB_DISK_DEVICE_HOST_ID,
|
||||
GRUB_DISK_DEVICE_ATA_ID,
|
||||
GRUB_DISK_DEVICE_MEMDISK_ID,
|
||||
GRUB_DISK_DEVICE_NAND_ID,
|
||||
GRUB_DISK_DEVICE_SCSI_ID,
|
||||
GRUB_DISK_DEVICE_CRYPTODISK_ID,
|
||||
GRUB_DISK_DEVICE_ARCDISK_ID,
|
||||
GRUB_DISK_DEVICE_HOSTDISK_ID,
|
||||
GRUB_DISK_DEVICE_PROCFS_ID,
|
||||
GRUB_DISK_DEVICE_CBFSDISK_ID,
|
||||
GRUB_DISK_DEVICE_UBOOTDISK_ID,
|
||||
GRUB_DISK_DEVICE_XEN,
|
||||
GRUB_DISK_DEVICE_OBDISK_ID,
|
||||
};
|
||||
|
||||
struct grub_disk;
|
||||
#ifdef GRUB_UTIL
|
||||
struct grub_disk_memberlist;
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GRUB_DISK_PULL_NONE,
|
||||
GRUB_DISK_PULL_REMOVABLE,
|
||||
GRUB_DISK_PULL_RESCAN,
|
||||
GRUB_DISK_PULL_MAX
|
||||
} grub_disk_pull_t;
|
||||
|
||||
typedef int (*grub_disk_dev_iterate_hook_t) (const char *name, void *data);
|
||||
|
||||
/* Disk device. */
|
||||
struct grub_disk_dev
|
||||
{
|
||||
/* The device name. */
|
||||
const char *name;
|
||||
|
||||
/* The device id used by the cache manager. */
|
||||
enum grub_disk_dev_id id;
|
||||
|
||||
/* Call HOOK with each device name, until HOOK returns non-zero. */
|
||||
int (*disk_iterate) (grub_disk_dev_iterate_hook_t hook, void *hook_data,
|
||||
grub_disk_pull_t pull);
|
||||
|
||||
/* Open the device named NAME, and set up DISK. */
|
||||
grub_err_t (*disk_open) (const char *name, struct grub_disk *disk);
|
||||
|
||||
/* Close the disk DISK. */
|
||||
void (*disk_close) (struct grub_disk *disk);
|
||||
|
||||
/* Read SIZE sectors from the sector SECTOR of the disk DISK into BUF. */
|
||||
grub_err_t (*disk_read) (struct grub_disk *disk, grub_disk_addr_t sector,
|
||||
grub_size_t size, char *buf);
|
||||
|
||||
/* Write SIZE sectors from BUF into the sector SECTOR of the disk DISK. */
|
||||
grub_err_t (*disk_write) (struct grub_disk *disk, grub_disk_addr_t sector,
|
||||
grub_size_t size, const char *buf);
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
struct grub_disk_memberlist *(*disk_memberlist) (struct grub_disk *disk);
|
||||
const char * (*disk_raidname) (struct grub_disk *disk);
|
||||
#endif
|
||||
|
||||
/* The next disk device. */
|
||||
struct grub_disk_dev *next;
|
||||
};
|
||||
typedef struct grub_disk_dev *grub_disk_dev_t;
|
||||
|
||||
extern grub_disk_dev_t EXPORT_VAR (grub_disk_dev_list);
|
||||
|
||||
struct grub_partition;
|
||||
|
||||
typedef void (*grub_disk_read_hook_t) (grub_disk_addr_t sector,
|
||||
unsigned offset, unsigned length,
|
||||
void *data);
|
||||
|
||||
/* Disk. */
|
||||
struct grub_disk
|
||||
{
|
||||
/* The disk name. */
|
||||
const char *name;
|
||||
|
||||
/* The underlying disk device. */
|
||||
grub_disk_dev_t dev;
|
||||
|
||||
/* The total number of sectors. */
|
||||
grub_uint64_t total_sectors;
|
||||
|
||||
/* Logarithm of sector size. */
|
||||
unsigned int log_sector_size;
|
||||
|
||||
/* Maximum number of sectors read divided by GRUB_DISK_CACHE_SIZE. */
|
||||
unsigned int max_agglomerate;
|
||||
|
||||
/* The id used by the disk cache manager. */
|
||||
unsigned long id;
|
||||
|
||||
/* The partition information. This is machine-specific. */
|
||||
struct grub_partition *partition;
|
||||
|
||||
/* Called when a sector was read. OFFSET is between 0 and
|
||||
the sector size minus 1, and LENGTH is between 0 and the sector size. */
|
||||
grub_disk_read_hook_t read_hook;
|
||||
|
||||
/* Caller-specific data passed to the read hook. */
|
||||
void *read_hook_data;
|
||||
|
||||
/* Device-specific data. */
|
||||
void *data;
|
||||
};
|
||||
typedef struct grub_disk *grub_disk_t;
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
struct grub_disk_memberlist
|
||||
{
|
||||
grub_disk_t disk;
|
||||
struct grub_disk_memberlist *next;
|
||||
};
|
||||
typedef struct grub_disk_memberlist *grub_disk_memberlist_t;
|
||||
#endif
|
||||
|
||||
/* The sector size. */
|
||||
#define GRUB_DISK_SECTOR_SIZE 0x200
|
||||
#define GRUB_DISK_SECTOR_BITS 9
|
||||
|
||||
/* The maximum number of disk caches. */
|
||||
#define GRUB_DISK_CACHE_NUM 1021
|
||||
|
||||
/* The size of a disk cache in 512B units. Must be at least as big as the
|
||||
largest supported sector size, currently 16K. */
|
||||
#define GRUB_DISK_CACHE_BITS 6
|
||||
#define GRUB_DISK_CACHE_SIZE (1 << GRUB_DISK_CACHE_BITS)
|
||||
|
||||
#define GRUB_DISK_MAX_MAX_AGGLOMERATE ((1 << (30 - GRUB_DISK_CACHE_BITS - GRUB_DISK_SECTOR_BITS)) - 1)
|
||||
|
||||
/* Return value of grub_disk_get_size() in case disk size is unknown. */
|
||||
#define GRUB_DISK_SIZE_UNKNOWN 0xffffffffffffffffULL
|
||||
|
||||
/* This is called from the memory manager. */
|
||||
void grub_disk_cache_invalidate_all (void);
|
||||
|
||||
void EXPORT_FUNC(grub_disk_dev_register) (grub_disk_dev_t dev);
|
||||
void EXPORT_FUNC(grub_disk_dev_unregister) (grub_disk_dev_t dev);
|
||||
static inline int
|
||||
grub_disk_dev_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data)
|
||||
{
|
||||
grub_disk_dev_t p;
|
||||
grub_disk_pull_t pull;
|
||||
|
||||
for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++)
|
||||
for (p = grub_disk_dev_list; p; p = p->next)
|
||||
if (p->disk_iterate && (p->disk_iterate) (hook, hook_data, pull))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_disk_t EXPORT_FUNC(grub_disk_open) (const char *name);
|
||||
void EXPORT_FUNC(grub_disk_close) (grub_disk_t disk);
|
||||
grub_err_t EXPORT_FUNC(grub_disk_blocklist_read)(void *chunklist, grub_uint64_t sector,
|
||||
grub_uint64_t size, grub_uint32_t log_sector_size);
|
||||
|
||||
grub_err_t EXPORT_FUNC(grub_disk_read) (grub_disk_t disk,
|
||||
grub_disk_addr_t sector,
|
||||
grub_off_t offset,
|
||||
grub_size_t size,
|
||||
void *buf);
|
||||
grub_err_t grub_disk_write (grub_disk_t disk,
|
||||
grub_disk_addr_t sector,
|
||||
grub_off_t offset,
|
||||
grub_size_t size,
|
||||
const void *buf);
|
||||
extern grub_err_t (*EXPORT_VAR(grub_disk_write_weak)) (grub_disk_t disk,
|
||||
grub_disk_addr_t sector,
|
||||
grub_off_t offset,
|
||||
grub_size_t size,
|
||||
const void *buf);
|
||||
|
||||
|
||||
grub_uint64_t EXPORT_FUNC(grub_disk_get_size) (grub_disk_t disk);
|
||||
|
||||
#if DISK_CACHE_STATS
|
||||
void
|
||||
EXPORT_FUNC(grub_disk_cache_get_performance) (unsigned long *hits, unsigned long *misses);
|
||||
#endif
|
||||
|
||||
extern void (* EXPORT_VAR(grub_disk_firmware_fini)) (void);
|
||||
extern int EXPORT_VAR(grub_disk_firmware_is_tainted);
|
||||
|
||||
static inline void
|
||||
grub_stop_disk_firmware (void)
|
||||
{
|
||||
/* To prevent two drivers operating on the same disks. */
|
||||
grub_disk_firmware_is_tainted = 1;
|
||||
if (grub_disk_firmware_fini)
|
||||
{
|
||||
grub_disk_firmware_fini ();
|
||||
grub_disk_firmware_fini = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Disk cache. */
|
||||
struct grub_disk_cache
|
||||
{
|
||||
enum grub_disk_dev_id dev_id;
|
||||
unsigned long disk_id;
|
||||
grub_disk_addr_t sector;
|
||||
char *data;
|
||||
int lock;
|
||||
};
|
||||
|
||||
extern struct grub_disk_cache EXPORT_VAR(grub_disk_cache_table)[GRUB_DISK_CACHE_NUM];
|
||||
|
||||
#if defined (GRUB_UTIL)
|
||||
void grub_lvm_init (void);
|
||||
void grub_ldm_init (void);
|
||||
void grub_mdraid09_init (void);
|
||||
void grub_mdraid1x_init (void);
|
||||
void grub_diskfilter_init (void);
|
||||
void grub_lvm_fini (void);
|
||||
void grub_ldm_fini (void);
|
||||
void grub_mdraid09_fini (void);
|
||||
void grub_mdraid1x_fini (void);
|
||||
void grub_diskfilter_fini (void);
|
||||
#endif
|
||||
|
||||
#endif /* ! GRUB_DISK_HEADER */
|
132
GRUB2/grub-2.04/include/grub/fs.h
Normal file
132
GRUB2/grub-2.04/include/grub/fs.h
Normal file
@@ -0,0 +1,132 @@
|
||||
/* fs.h - filesystem manager */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2003,2004,2007,2008,2009 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB 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.
|
||||
*
|
||||
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_FS_HEADER
|
||||
#define GRUB_FS_HEADER 1
|
||||
|
||||
#include <grub/device.h>
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/types.h>
|
||||
|
||||
#include <grub/list.h>
|
||||
/* For embedding types. */
|
||||
#ifdef GRUB_UTIL
|
||||
#include <grub/partition.h>
|
||||
#endif
|
||||
|
||||
/* Forward declaration is required, because of mutual reference. */
|
||||
struct grub_file;
|
||||
|
||||
struct grub_dirhook_info
|
||||
{
|
||||
unsigned dir:1;
|
||||
unsigned mtimeset:1;
|
||||
unsigned case_insensitive:1;
|
||||
unsigned inodeset:1;
|
||||
grub_int32_t mtime;
|
||||
grub_uint64_t inode;
|
||||
grub_uint64_t size;
|
||||
};
|
||||
|
||||
typedef int (*grub_fs_dir_hook_t) (const char *filename,
|
||||
const struct grub_dirhook_info *info,
|
||||
void *data);
|
||||
|
||||
/* Filesystem descriptor. */
|
||||
struct grub_fs
|
||||
{
|
||||
/* The next filesystem. */
|
||||
struct grub_fs *next;
|
||||
struct grub_fs **prev;
|
||||
|
||||
/* My name. */
|
||||
const char *name;
|
||||
|
||||
/* Call HOOK with each file under DIR. */
|
||||
grub_err_t (*fs_dir) (grub_device_t device, const char *path,
|
||||
grub_fs_dir_hook_t hook, void *hook_data);
|
||||
|
||||
/* Open a file named NAME and initialize FILE. */
|
||||
grub_err_t (*fs_open) (struct grub_file *file, const char *name);
|
||||
|
||||
/* Read LEN bytes data from FILE into BUF. */
|
||||
grub_ssize_t (*fs_read) (struct grub_file *file, char *buf, grub_size_t len);
|
||||
|
||||
/* Close the file FILE. */
|
||||
grub_err_t (*fs_close) (struct grub_file *file);
|
||||
|
||||
/* Return the label of the device DEVICE in LABEL. The label is
|
||||
returned in a grub_malloc'ed buffer and should be freed by the
|
||||
caller. */
|
||||
grub_err_t (*fs_label) (grub_device_t device, char **label);
|
||||
|
||||
/* Return the uuid of the device DEVICE in UUID. The uuid is
|
||||
returned in a grub_malloc'ed buffer and should be freed by the
|
||||
caller. */
|
||||
grub_err_t (*fs_uuid) (grub_device_t device, char **uuid);
|
||||
|
||||
/* Get writing time of filesystem. */
|
||||
grub_err_t (*fs_mtime) (grub_device_t device, grub_int32_t *timebuf);
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
/* Determine sectors available for embedding. */
|
||||
grub_err_t (*fs_embed) (grub_device_t device, unsigned int *nsectors,
|
||||
unsigned int max_nsectors,
|
||||
grub_embed_type_t embed_type,
|
||||
grub_disk_addr_t **sectors);
|
||||
|
||||
/* Whether this filesystem reserves first sector for DOS-style boot. */
|
||||
int reserved_first_sector;
|
||||
|
||||
/* Whether blocklist installs have a chance to work. */
|
||||
int blocklist_install;
|
||||
#endif
|
||||
};
|
||||
typedef struct grub_fs *grub_fs_t;
|
||||
|
||||
/* This is special, because block lists are not files in usual sense. */
|
||||
extern struct grub_fs grub_fs_blocklist;
|
||||
|
||||
/* This hook is used to automatically load filesystem modules.
|
||||
If this hook loads a module, return non-zero. Otherwise return zero.
|
||||
The newly loaded filesystem is assumed to be inserted into the head of
|
||||
the linked list GRUB_FS_LIST through the function grub_fs_register. */
|
||||
typedef int (*grub_fs_autoload_hook_t) (void);
|
||||
extern grub_fs_autoload_hook_t EXPORT_VAR(grub_fs_autoload_hook);
|
||||
extern grub_fs_t EXPORT_VAR (grub_fs_list);
|
||||
|
||||
#ifndef GRUB_LST_GENERATOR
|
||||
static inline void
|
||||
grub_fs_register (grub_fs_t fs)
|
||||
{
|
||||
grub_list_push (GRUB_AS_LIST_P (&grub_fs_list), GRUB_AS_LIST (fs));
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void
|
||||
grub_fs_unregister (grub_fs_t fs)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST (fs));
|
||||
}
|
||||
|
||||
#define FOR_FILESYSTEMS(var) FOR_LIST_ELEMENTS((var), (grub_fs_list))
|
||||
|
||||
grub_fs_t EXPORT_FUNC(grub_fs_probe) (grub_device_t device);
|
||||
|
||||
#endif /* ! GRUB_FS_HEADER */
|
@@ -28,6 +28,17 @@
|
||||
|
||||
#define VENTOY_GUID { 0x77772020, 0x2e77, 0x6576, { 0x6e, 0x74, 0x6f, 0x79, 0x2e, 0x6e, 0x65, 0x74 }}
|
||||
|
||||
typedef enum ventoy_fs_type
|
||||
{
|
||||
ventoy_fs_exfat = 0, /* 0: exfat */
|
||||
ventoy_fs_ntfs, /* 1: NTFS */
|
||||
ventoy_fs_ext, /* 2: ext2/ext3/ext4 */
|
||||
ventoy_fs_xfs, /* 3: XFS */
|
||||
ventoy_fs_udf, /* 4: UDF */
|
||||
|
||||
ventoy_fs_max
|
||||
}ventoy_fs_type;
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct ventoy_guid
|
||||
@@ -104,6 +115,15 @@ typedef struct ventoy_os_param
|
||||
grub_uint8_t reserved[31];
|
||||
}ventoy_os_param;
|
||||
|
||||
|
||||
typedef struct ventoy_windows_data
|
||||
{
|
||||
char auto_install_script[384];
|
||||
grub_uint8_t reserved[128];
|
||||
}ventoy_windows_data;
|
||||
|
||||
|
||||
|
||||
#pragma pack()
|
||||
|
||||
// compile assert check : sizeof(ventoy_os_param) must be 512
|
||||
@@ -183,9 +203,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()
|
||||
|
46
IMG/cpio/ventoy/hook/alt/udev_disk_hook.sh
Normal file
46
IMG/cpio/ventoy/hook/alt/udev_disk_hook.sh
Normal 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
|
||||
|
24
IMG/cpio/ventoy/hook/alt/ventoy-hook.sh
Normal file
24
IMG/cpio/ventoy/hook/alt/ventoy-hook.sh
Normal 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"
|
48
IMG/cpio/ventoy/hook/arch/ventoy-disk.sh
Normal file
48
IMG/cpio/ventoy/hook/arch/ventoy-disk.sh
Normal 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
|
||||
|
||||
vtlog "######### $0 $* ############"
|
||||
|
||||
if is_ventoy_hook_finished; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
wait_for_usb_disk_ready
|
||||
|
||||
vtdiskname=$(get_ventoy_disk_name)
|
||||
if [ "$vtdiskname" = "unknown" ]; then
|
||||
vtlog "ventoy disk not found"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
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})
|
||||
|
||||
vtlog "ln -s /dev/$vtDM $1"
|
||||
ln -s /dev/$vtDM "$1"
|
||||
fi
|
||||
|
||||
# OK finish
|
||||
set_ventoy_hook_finish
|
||||
|
@@ -19,16 +19,21 @@
|
||||
|
||||
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
||||
|
||||
# some archlinux initramfs doesn't contain device-mapper udev rules file
|
||||
ARCH_UDEV_DIR=$(ventoy_get_udev_conf_dir)
|
||||
if [ -s "$ARCH_UDEV_DIR/13-dm-disk.rules" ]; then
|
||||
echo 'dm-disk rule exist' >> $VTLOG
|
||||
if $GREP -q '^"$mount_handler"' /init; then
|
||||
echo 'use mount_handler ...' >> $VTLOG
|
||||
$SED "/^\"\$mount_handler\"/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ventoy-disk.sh \"\$archisodevice\"" -i /init
|
||||
else
|
||||
echo 'Copy dm-disk rule file' >> $VTLOG
|
||||
$CAT $VTOY_PATH/hook/default/13-dm-disk.rules > "$ARCH_UDEV_DIR/13-dm-disk.rules"
|
||||
# some archlinux initramfs doesn't contain device-mapper udev rules file
|
||||
ARCH_UDEV_DIR=$(ventoy_get_udev_conf_dir)
|
||||
if [ -s "$ARCH_UDEV_DIR/13-dm-disk.rules" ]; then
|
||||
echo 'dm-disk rule exist' >> $VTLOG
|
||||
else
|
||||
echo 'Copy dm-disk rule file' >> $VTLOG
|
||||
$CAT $VTOY_PATH/hook/default/13-dm-disk.rules > "$ARCH_UDEV_DIR/13-dm-disk.rules"
|
||||
fi
|
||||
|
||||
# use default proc
|
||||
ventoy_systemd_udevd_work_around
|
||||
|
||||
ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k"
|
||||
fi
|
||||
|
||||
# use default proc
|
||||
ventoy_systemd_udevd_work_around
|
||||
|
||||
ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k"
|
||||
|
38
IMG/cpio/ventoy/hook/berry/ventoy-disk.sh
Normal file
38
IMG/cpio/ventoy/hook/berry/ventoy-disk.sh
Normal 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
|
||||
|
20
IMG/cpio/ventoy/hook/berry/ventoy-hook.sh
Normal file
20
IMG/cpio/ventoy/hook/berry/ventoy-hook.sh
Normal 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
|
43
IMG/cpio/ventoy/hook/clear/disk-hook.sh
Normal file
43
IMG/cpio/ventoy/hook/clear/disk-hook.sh
Normal 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
|
22
IMG/cpio/ventoy/hook/clear/ventoy-hook.sh
Normal file
22
IMG/cpio/ventoy/hook/clear/ventoy-hook.sh
Normal 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
|
@@ -17,5 +17,39 @@
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
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
|
||||
|
||||
if $GREP -q 'live-media=' /proc/cmdline; then
|
||||
if [ -f /scripts/casper ] && $GREP -q '^ *LIVEMEDIA=' /scripts/casper; then
|
||||
$SED "s#^ *LIVEMEDIA=.*#LIVEMEDIA=/dev/mapper/ventoy#" -i /scripts/casper
|
||||
fi
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
if [ -f $VTOY_PATH/autoinstall ]; then
|
||||
echo "Do auto install ..." >> $VTLOG
|
||||
|
||||
if $GREP -q "^mount /proc$" /init; then
|
||||
$SED "/^mount \/proc/a export file=$VTOY_PATH/autoinstall; export auto='true'; export priority='critical'" -i /init
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
|
35
IMG/cpio/ventoy/hook/debian/disk_mount_hook.sh
Normal file
35
IMG/cpio/ventoy/hook/debian/disk_mount_hook.sh
Normal 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"
|
43
IMG/cpio/ventoy/hook/debian/knoppix-disk.sh
Normal file
43
IMG/cpio/ventoy/hook/debian/knoppix-disk.sh
Normal 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
|
||||
|
23
IMG/cpio/ventoy/hook/debian/knoppix-hook.sh
Normal file
23
IMG/cpio/ventoy/hook/debian/knoppix-hook.sh
Normal 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
|
77
IMG/cpio/ventoy/hook/debian/porteus-disk.sh
Normal file
77
IMG/cpio/ventoy/hook/debian/porteus-disk.sh
Normal 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
|
||||
|
48
IMG/cpio/ventoy/hook/debian/porteus-hook.sh
Normal file
48
IMG/cpio/ventoy/hook/debian/porteus-hook.sh
Normal 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
|
48
IMG/cpio/ventoy/hook/debian/puppy-disk.sh
Normal file
48
IMG/cpio/ventoy/hook/debian/puppy-disk.sh
Normal 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
|
22
IMG/cpio/ventoy/hook/debian/puppy-hook.sh
Normal file
22
IMG/cpio/ventoy/hook/debian/puppy-hook.sh
Normal 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
|
43
IMG/cpio/ventoy/hook/debian/pve-disk.sh
Normal file
43
IMG/cpio/ventoy/hook/debian/pve-disk.sh
Normal 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
|
21
IMG/cpio/ventoy/hook/debian/pve-hook.sh
Normal file
21
IMG/cpio/ventoy/hook/debian/pve-hook.sh
Normal 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
|
77
IMG/cpio/ventoy/hook/debian/slax-disk.sh
Normal file
77
IMG/cpio/ventoy/hook/debian/slax-disk.sh
Normal 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
|
||||
|
20
IMG/cpio/ventoy/hook/debian/slax-hook.sh
Normal file
20
IMG/cpio/ventoy/hook/debian/slax-hook.sh
Normal 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
|
24
IMG/cpio/ventoy/hook/debian/tails-hook.sh
Normal file
24
IMG/cpio/ventoy/hook/debian/tails-hook.sh
Normal 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"
|
@@ -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
|
||||
|
||||
|
88
IMG/cpio/ventoy/hook/debian/veket-disk.sh
Normal file
88
IMG/cpio/ventoy/hook/debian/veket-disk.sh
Normal 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
|
22
IMG/cpio/ventoy/hook/debian/veket-hook.sh
Normal file
22
IMG/cpio/ventoy/hook/debian/veket-hook.sh
Normal 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
|
@@ -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
|
||||
|
35
IMG/cpio/ventoy/hook/debian/ventoy-inotifyd-hook.sh
Normal file
35
IMG/cpio/ventoy/hook/debian/ventoy-inotifyd-hook.sh
Normal 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
|
25
IMG/cpio/ventoy/hook/default/ventoy-inotifyd-start.sh
Normal file
25
IMG/cpio/ventoy/hook/default/ventoy-inotifyd-start.sh
Normal 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>&- &
|
26
IMG/cpio/ventoy/hook/gobo/ventoy-hook.sh
Normal file
26
IMG/cpio/ventoy/hook/gobo/ventoy-hook.sh
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/ventoy/busybox/sh
|
||||
#************************************************************************************
|
||||
# Copyright (c) 2020, longpanda <admin@ventoy.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
||||
|
||||
$SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE root=live:/dev/mapper/ventoy#" -i /lib/dracut-lib.sh
|
||||
|
||||
ventoy_set_inotify_script gobo/ventoy-inotifyd-hook.sh
|
||||
|
||||
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/gobo/ventoy-inotifyd-start.sh /lib/dracut/hooks/pre-udev/01-ventoy-inotifyd-start.sh
|
47
IMG/cpio/ventoy/hook/gobo/ventoy-inotifyd-hook.sh
Normal file
47
IMG/cpio/ventoy/hook/gobo/ventoy-inotifyd-hook.sh
Normal 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 $3 ..."
|
||||
$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
|
31
IMG/cpio/ventoy/hook/gobo/ventoy-inotifyd-start.sh
Normal file
31
IMG/cpio/ventoy/hook/gobo/ventoy-inotifyd-start.sh
Normal 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
|
42
IMG/cpio/ventoy/hook/guix/ventoy-disk.sh
Normal file
42
IMG/cpio/ventoy/hook/guix/ventoy-disk.sh
Normal 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
|
||||
|
||||
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
|
||||
|
||||
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})
|
||||
|
||||
vtlog "This is $vtDM ..."
|
||||
|
||||
set_ventoy_hook_finish
|
||||
fi
|
||||
|
||||
PATH=$VTPATH_OLD
|
25
IMG/cpio/ventoy/hook/guix/ventoy-hook.sh
Normal file
25
IMG/cpio/ventoy/hook/guix/ventoy-hook.sh
Normal 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/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
||||
|
||||
$BUSYBOX_PATH/mkdir /dev
|
||||
$BUSYBOX_PATH/mknode -m 0666 /dev/null c 1 3
|
||||
|
||||
$BUSYBOX_PATH/nohup $VTOY_PATH/hook/guix/ventoy-waitdev.sh &
|
37
IMG/cpio/ventoy/hook/guix/ventoy-waitdev.sh
Normal file
37
IMG/cpio/ventoy/hook/guix/ventoy-waitdev.sh
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/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
|
||||
|
||||
while ! [ -e /dev/null ]; do
|
||||
echo 'xxxxxxxxxx'
|
||||
echo 'xxxxxxxxxx' > /dev/console
|
||||
sleep 1
|
||||
done
|
||||
|
||||
vtlog "... start inotifyd listen $vtHook ..."
|
||||
$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $VTOY_PATH/hook/guix/ventoy-disk.sh /dev:n 2>&- &
|
||||
|
||||
|
||||
PATH=$VTPATH_OLD
|
||||
|
@@ -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
|
||||
|
46
IMG/cpio/ventoy/hook/manjaro/ventoy-inotifyd-hook.sh
Normal file
46
IMG/cpio/ventoy/hook/manjaro/ventoy-inotifyd-hook.sh
Normal 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
|
50
IMG/cpio/ventoy/hook/nutyx/ventoy-disk.sh
Normal file
50
IMG/cpio/ventoy/hook/nutyx/ventoy-disk.sh
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/ventoy/busybox/sh
|
||||
#************************************************************************************
|
||||
# Copyright (c) 2020, longpanda <admin@ventoy.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
. /ventoy/hook/ventoy-hook-lib.sh
|
||||
|
||||
vtlog "####### $0 $* ########"
|
||||
|
||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||
|
||||
if is_ventoy_hook_finished; then
|
||||
exit 0
|
||||
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_udev_disk_common_hook "${vtdiskname#/dev/}2"
|
||||
|
||||
blkdev_num=$(dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
|
||||
vtDM=$(ventoy_find_dm_id ${blkdev_num})
|
||||
|
||||
vtlog "link /dev/$vtDM $VTOY_DM_PATH"
|
||||
ln -s /dev/$vtDM $VTOY_DM_PATH
|
||||
|
||||
set_ventoy_hook_finish
|
||||
|
||||
PATH=$VTPATH_OLD
|
||||
|
22
IMG/cpio/ventoy/hook/nutyx/ventoy-hook.sh
Normal file
22
IMG/cpio/ventoy/hook/nutyx/ventoy-hook.sh
Normal 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_media$/i $BUSYBOX_PATH/sh $VTOY_PATH/hook/nutyx/ventoy-disk.sh" -i /init
|
@@ -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
|
||||
|
||||
|
@@ -19,11 +19,36 @@
|
||||
|
||||
. $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 [ -f $VTOY_PATH/autoinstall ]; then
|
||||
VTKS="inst.ks=file:$VTOY_PATH/autoinstall"
|
||||
else
|
||||
for vtParam in $($CAT /proc/cmdline); do
|
||||
if echo $vtParam | $GREP -q 'inst.ks=hd:LABEL='; then
|
||||
vtRawKs=$(echo $vtParam | $AWK -F: '{print $NF}')
|
||||
VTKS="inst.ks=hd:/dev/dm-0:$vtRawKs"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
echo "VTKS=$VTKS" >> $VTLOG
|
||||
|
||||
if $GREP -q 'root=live' /proc/cmdline; then
|
||||
$SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE root=live:/dev/dm-0 $VTKS#" -i /lib/dracut-lib.sh
|
||||
else
|
||||
$SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE inst.stage2=hd:/dev/dm-0 $VTKS#" -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
|
||||
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-timeout.sh /lib/dracut/hooks/initqueue/timeout/01-ventoy-timeout.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
|
||||
|
||||
|
50
IMG/cpio/ventoy/hook/rhel7/ventoy-inotifyd-hook.sh
Normal file
50
IMG/cpio/ventoy/hook/rhel7/ventoy-inotifyd-hook.sh
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/ventoy/busybox/sh
|
||||
#************************************************************************************
|
||||
# Copyright (c) 2020, longpanda <admin@ventoy.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
. /ventoy/hook/ventoy-hook-lib.sh
|
||||
|
||||
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
|
||||
|
||||
vtlog "set anaconda-diskroot ..."
|
||||
/sbin/initqueue --settled --onetime --name anaconda-diskroot anaconda-diskroot /dev/dm-0
|
||||
|
||||
set_ventoy_hook_finish
|
||||
fi
|
||||
|
||||
PATH=$VTPATH_OLD
|
31
IMG/cpio/ventoy/hook/rhel7/ventoy-inotifyd-start.sh
Normal file
31
IMG/cpio/ventoy/hook/rhel7/ventoy-inotifyd-start.sh
Normal 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
|
32
IMG/cpio/ventoy/hook/rhel7/ventoy-timeout.sh
Normal file
32
IMG/cpio/ventoy/hook/rhel7/ventoy-timeout.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/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
|
||||
|
||||
blkdev_num=$(dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
|
||||
vtDM=$(ventoy_find_dm_id ${blkdev_num})
|
||||
|
||||
vtlog "diskroot $vtDM ..."
|
||||
/sbin/initqueue --settled --onetime --name anaconda-diskroot anaconda-diskroot /dev/$vtDM
|
||||
|
||||
PATH=$VTPATH_OLD
|
@@ -19,6 +19,17 @@
|
||||
|
||||
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
||||
|
||||
ventoy_systemd_udevd_work_around
|
||||
if [ -f $VTOY_PATH/autoinstall ]; then
|
||||
if [ -f /linuxrc.config ]; then
|
||||
echo "AutoYaST: file:///ventoy/autoinstall" >> /info-ventoy
|
||||
$SED "1 iinfo: file:/info-ventoy" -i /linuxrc.config
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
#echo "Exec: /bin/sh $VTOY_PATH/hook/suse/cdrom-hook.sh" >> /info-ventoy
|
||||
#echo "install: hd:/?device=/dev/mapper/ventoy" >> /info-ventoy
|
||||
#$SED "1 iinfo: file:/info-ventoy" -i /linuxrc.config
|
||||
|
||||
ventoy_systemd_udevd_work_around
|
||||
ventoy_add_udev_rule "$VTOY_PATH/hook/suse/udev_disk_hook.sh %k"
|
||||
|
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
}
|
||||
|
42
IMG/cpio/ventoy/hook/zeroshell/disk_hook.sh
Normal file
42
IMG/cpio/ventoy/hook/zeroshell/disk_hook.sh
Normal 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
|
24
IMG/cpio/ventoy/hook/zeroshell/ventoy-hook.sh
Normal file
24
IMG/cpio/ventoy/hook/zeroshell/ventoy-hook.sh
Normal 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
|
@@ -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
|
||||
|
@@ -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
|
||||
|
||||
|
BIN
IMG/cpio/ventoy/tool/xzminidec
Normal file
BIN
IMG/cpio/ventoy/tool/xzminidec
Normal file
Binary file not shown.
@@ -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,33 @@ 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
|
||||
|
||||
if $GREP -q 'Gobo ' /proc/version; then
|
||||
echo 'gobo'; return
|
||||
fi
|
||||
|
||||
if $GREP -q 'NuTyX' /proc/version; then
|
||||
echo 'nutyx'; return
|
||||
fi
|
||||
|
||||
if [ -d /gnu ]; then
|
||||
vtLineNum=$($FIND /gnu/ -name guix | $BUSYBOX_PATH/wc -l)
|
||||
if [ $vtLineNum -gt 0 ]; then
|
||||
echo 'guix'; return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "default"
|
||||
}
|
||||
|
||||
|
5
INSTALL/DO_NOT_RUN_Ventoy2Disk_HERE.txt
Normal file
5
INSTALL/DO_NOT_RUN_Ventoy2Disk_HERE.txt
Normal 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.
BIN
INSTALL/EFI/BOOT/MokManager.efi
Normal file
BIN
INSTALL/EFI/BOOT/MokManager.efi
Normal file
Binary file not shown.
BIN
INSTALL/EFI/BOOT/grubx64.efi
Normal file
BIN
INSTALL/EFI/BOOT/grubx64.efi
Normal file
Binary file not shown.
BIN
INSTALL/EFI/BOOT/grubx64_real.efi
Normal file
BIN
INSTALL/EFI/BOOT/grubx64_real.efi
Normal file
Binary file not shown.
Binary file not shown.
@@ -1,14 +1,24 @@
|
||||
#!/bin/sh
|
||||
|
||||
OLDDIR=$PWD
|
||||
|
||||
if ! [ -f ./tool/ventoy_lib.sh ]; then
|
||||
cd ${0%Ventoy2Disk.sh}
|
||||
fi
|
||||
|
||||
. ./tool/ventoy_lib.sh
|
||||
|
||||
print_usage() {
|
||||
echo 'Usage: VentoyInstaller.sh OPTION /dev/sdX'
|
||||
echo ' OPTION:'
|
||||
echo 'Usage: Ventoy2Disk.sh CMD [ OPTION ] /dev/sdX'
|
||||
echo ' CMD:'
|
||||
echo ' -i install ventoy to sdX (fail if disk already installed with ventoy)'
|
||||
echo ' -u update ventoy in sdX'
|
||||
echo ' -I force install ventoy to sdX (no matter installed or not)'
|
||||
echo ''
|
||||
echo ' OPTION: (optional)'
|
||||
echo ' -s enable secure boot support (default is disabled)'
|
||||
echo ''
|
||||
|
||||
}
|
||||
|
||||
echo ''
|
||||
@@ -18,40 +28,69 @@ 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
|
||||
|
||||
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
|
||||
print_usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$SUDO_USER" ]; then
|
||||
if [ "$USER" != "root" ]; then
|
||||
vterr "EUID is $EUID root permission is required."
|
||||
echo ''
|
||||
exit 1
|
||||
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
|
||||
vterr "$1 is NOT a valid device"
|
||||
print_usage
|
||||
cd $OLDDIR
|
||||
exit 1
|
||||
fi
|
||||
DISK=$1
|
||||
fi
|
||||
|
||||
shift
|
||||
done
|
||||
|
||||
if [ -z "$MODE" ]; then
|
||||
print_usage
|
||||
cd $OLDDIR
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
if dd if="$DISK" of=/dev/null bs=1 count=1 >/dev/null 2>&1; then
|
||||
vtdebug "root permission check ok ..."
|
||||
else
|
||||
vterr "Failed to access $DISK, maybe root privilege is needed!"
|
||||
echo ''
|
||||
cd $OLDDIR
|
||||
exit 1
|
||||
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 +106,19 @@ 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"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ -e /sys/class/block/${DISK#/dev/}/start ]; then
|
||||
vterr "$DISK is a partition, please use the whole disk"
|
||||
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 +128,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 +139,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 +149,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 +186,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 +214,43 @@ 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
|
||||
rm -f ./tmp_mnt/ENROLL_THIS_KEY_IN_MOKMANAGER.cer
|
||||
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 +265,7 @@ else
|
||||
echo ""
|
||||
vtwarn "Please use -i option if you want to install ventoy to $DISK"
|
||||
echo ""
|
||||
cd $OLDDIR
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -214,21 +277,44 @@ 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
|
||||
rm -f ./tmp_mnt/ENROLL_THIS_KEY_IN_MOKMANAGER.cer
|
||||
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 +322,5 @@ else
|
||||
|
||||
fi
|
||||
|
||||
cd $OLDDIR
|
||||
|
||||
|
@@ -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
|
||||
@@ -30,6 +50,21 @@ function get_os_type {
|
||||
fi
|
||||
}
|
||||
|
||||
function vt_check_pe {
|
||||
unset VT_PE_SUPPORT
|
||||
|
||||
if [ -f $1/HBCD_PE.ini ]; then
|
||||
set ventoy_compatible=YES
|
||||
set VT_PE_SUPPORT=YES
|
||||
elif [ -f $1/easyu.flg ]; then
|
||||
set VT_PE_SUPPORT=YES
|
||||
elif [ -f $1/USM.ICO ]; then
|
||||
set VT_PE_SUPPORT=YES
|
||||
elif [ -d $1/USM_TOOL ]; then
|
||||
set VT_PE_SUPPORT=YES
|
||||
fi
|
||||
}
|
||||
|
||||
function locate_initrd {
|
||||
vt_linux_locate_initrd
|
||||
|
||||
@@ -42,7 +77,8 @@ function locate_initrd {
|
||||
function find_wim_file {
|
||||
unset ventoy_wim_file
|
||||
|
||||
for file in "sources/boot.wim" "sources/BOOT.WIM" "Sources/Win10PEx64.WIM" "boot/BOOT.WIM" "winpe_x64.wim"; do
|
||||
for file in "sources/boot.wim" "sources/BOOT.WIM" "Sources/Win10PEx64.WIM" "boot/BOOT.WIM" \
|
||||
"winpe_x64.wim" "boot/10pex64.wim" "BOOT/USM1PE6L.WIM" "BOOT/USM1PE6F.WIM"; do
|
||||
if [ -e $1/$file ]; then
|
||||
set ventoy_wim_file=$1/$file
|
||||
break
|
||||
@@ -76,6 +112,26 @@ 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
|
||||
elif [ -f (loop)/isolinux/initramfs ]; then
|
||||
vt_linux_specify_initrd_file /isolinux/initramfs
|
||||
elif [ -f (loop)/boot/iniramfs.igz ]; then
|
||||
vt_linux_specify_initrd_file /boot/iniramfs.igz
|
||||
elif [ -f (loop)/initrd-x86_64 ]; then
|
||||
vt_linux_specify_initrd_file /initrd-x86_64
|
||||
|
||||
fi
|
||||
}
|
||||
@@ -108,15 +164,15 @@ function uefi_windows_menu_func {
|
||||
|
||||
function uefi_linux_menu_func {
|
||||
if [ "$ventoy_compatible" = "NO" ]; then
|
||||
vt_load_cpio ${vtoy_path}/ventoy.cpio
|
||||
vt_load_cpio ${vtoy_path}/ventoy.cpio $2 $1
|
||||
|
||||
vt_linux_clear_initrd
|
||||
|
||||
if [ -d (loop)/pmagic ]; then
|
||||
vt_linux_specify_initrd_file /pmagic/initrd.img
|
||||
else
|
||||
for file in "boot/grub/grub.cfg" "EFI/BOOT/grub.cfg" "EFI/boot/grub.cfg" "efi/boot/grub.cfg" "EFI/BOOT/BOOTX64.conf"; do
|
||||
if [ -e (loop)/$file ]; then
|
||||
for file in "boot/grub/grub.cfg" "EFI/BOOT/grub.cfg" "EFI/boot/grub.cfg" "efi/boot/grub.cfg" "EFI/BOOT/BOOTX64.conf" "/grub/grub.cfg"; do
|
||||
if [ -e (loop)/$file ]; then
|
||||
vt_linux_parse_initrd_grub file (loop)/$file
|
||||
fi
|
||||
done
|
||||
@@ -137,6 +193,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 +229,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 +246,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)
|
||||
@@ -191,13 +266,16 @@ function uefi_iso_menu_func {
|
||||
vt_img_sector ${1}${chosen_path}
|
||||
|
||||
if [ "$vtoy_os" = "Windows" ]; then
|
||||
if [ "$ventoy_fs_probe" = "iso9660" ]; then
|
||||
set ventoy_compatible=YES
|
||||
vt_check_pe (loop)
|
||||
if [ "$VT_PE_SUPPORT" != "YES" ]; then
|
||||
if [ "$ventoy_fs_probe" = "iso9660" ]; then
|
||||
set ventoy_compatible=YES
|
||||
fi
|
||||
fi
|
||||
|
||||
uefi_windows_menu_func $1
|
||||
uefi_windows_menu_func $1 ${chosen_path}
|
||||
else
|
||||
uefi_linux_menu_func $1
|
||||
uefi_linux_menu_func $1 ${chosen_path}
|
||||
fi
|
||||
|
||||
terminal_output gfxterm
|
||||
@@ -215,8 +293,6 @@ function uefi_iso_memdisk {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function legacy_windows_menu_func {
|
||||
vt_windows_reset
|
||||
|
||||
@@ -236,8 +312,7 @@ function legacy_windows_menu_func {
|
||||
fi
|
||||
|
||||
if [ -n "$vtoy_chain_mem_addr" ]; then
|
||||
linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft
|
||||
initrd16 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
|
||||
linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
|
||||
boot
|
||||
else
|
||||
echo "chain empty failed"
|
||||
@@ -247,8 +322,7 @@ function legacy_windows_menu_func {
|
||||
|
||||
function legacy_linux_menu_func {
|
||||
if [ "$ventoy_compatible" = "NO" ]; then
|
||||
|
||||
vt_load_cpio $vtoy_path/ventoy.cpio
|
||||
vt_load_cpio $vtoy_path/ventoy.cpio $2 $1
|
||||
|
||||
vt_linux_clear_initrd
|
||||
|
||||
@@ -279,6 +353,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
|
||||
|
||||
@@ -288,9 +367,8 @@ function legacy_linux_menu_func {
|
||||
sleep 5
|
||||
fi
|
||||
|
||||
if [ -n "$vtoy_chain_mem_addr" ]; then
|
||||
linux16 $vtoy_path/ipxe.krn ${vtdebug_flag}
|
||||
initrd16 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
|
||||
if [ -n "$vtoy_chain_mem_addr" ]; then
|
||||
linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
|
||||
boot
|
||||
else
|
||||
echo "chain empty failed"
|
||||
@@ -319,7 +397,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)
|
||||
@@ -328,12 +406,16 @@ function legacy_iso_menu_func {
|
||||
vt_img_sector ${1}${chosen_path}
|
||||
|
||||
if [ "$vtoy_os" = "Windows" ]; then
|
||||
if [ "$ventoy_fs_probe" = "iso9660" ]; then
|
||||
set ventoy_compatible=YES
|
||||
vt_check_pe (loop)
|
||||
if [ "$VT_PE_SUPPORT" != "YES" ]; then
|
||||
if [ "$ventoy_fs_probe" = "iso9660" ]; then
|
||||
set ventoy_compatible=YES
|
||||
fi
|
||||
fi
|
||||
legacy_windows_menu_func $1
|
||||
|
||||
legacy_windows_menu_func $1 ${chosen_path}
|
||||
else
|
||||
legacy_linux_menu_func $1
|
||||
legacy_linux_menu_func $1 ${chosen_path}
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -346,6 +428,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 +453,13 @@ function legacy_iso_memdisk {
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
set VENTOY_VERSION="1.0.06"
|
||||
set VENTOY_VERSION="1.0.9Y"
|
||||
|
||||
|
||||
# Default menu display mode, you can change it as you want.
|
||||
# 0: List mode
|
||||
# 1: TreeView mode
|
||||
set VTOY_DEFAULT_MENU_MODE=0
|
||||
|
||||
#disable timeout
|
||||
unset timeout
|
||||
@@ -364,6 +468,22 @@ 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"
|
||||
|
||||
if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
|
||||
set VTOY_F3_CMD="vt_dynamic_menu 1 1"
|
||||
set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView"
|
||||
else
|
||||
set VTOY_F3_CMD="vt_dynamic_menu 1 0"
|
||||
set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView"
|
||||
fi
|
||||
|
||||
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 +505,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 +517,22 @@ 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
|
||||
if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
|
||||
vt_dynamic_menu 0 0
|
||||
else
|
||||
vt_dynamic_menu 0 1
|
||||
fi
|
||||
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 |
@@ -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.
BIN
INSTALL/tool/ENROLL_THIS_KEY_IN_MOKMANAGER.cer
Normal file
BIN
INSTALL/tool/ENROLL_THIS_KEY_IN_MOKMANAGER.cer
Normal file
Binary file not shown.
@@ -14,16 +14,6 @@ ventoy_true() {
|
||||
}
|
||||
|
||||
ventoy_is_linux64() {
|
||||
if [ -e /lib64 ]; then
|
||||
ventoy_true
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -e /usr/lib64 ]; then
|
||||
ventoy_true
|
||||
return
|
||||
fi
|
||||
|
||||
if uname -a | egrep -q 'x86_64|amd64'; then
|
||||
ventoy_true
|
||||
return
|
||||
@@ -165,12 +155,12 @@ is_disk_contains_ventoy() {
|
||||
return
|
||||
fi
|
||||
|
||||
PART1_TYPE=$(dd if=$DISK bs=1 count=1 skip=450 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
|
||||
if [ "$PART1_TYPE" != "07" ]; then
|
||||
vtdebug "part1 type is $PART2_TYPE not 07"
|
||||
ventoy_false
|
||||
return
|
||||
fi
|
||||
# PART1_TYPE=$(dd if=$DISK bs=1 count=1 skip=450 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
|
||||
# if [ "$PART1_TYPE" != "07" ]; then
|
||||
# vtdebug "part1 type is $PART2_TYPE not 07"
|
||||
# ventoy_false
|
||||
# return
|
||||
# fi
|
||||
|
||||
if [ -e /sys/class/block/${PART1#/dev/}/start ]; then
|
||||
PART1_START=$(cat /sys/class/block/${PART1#/dev/}/start)
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -117,6 +117,10 @@ static void cmdline_strip ( char *cmdline, const char *cruft ) {
|
||||
*/
|
||||
static int cmdline_init ( void ) {
|
||||
userptr_t cmdline_user;
|
||||
userptr_t chainaddr;
|
||||
char *pos1;
|
||||
char *pos2;
|
||||
int chainlen;
|
||||
char *cmdline;
|
||||
size_t len;
|
||||
int rc;
|
||||
@@ -129,6 +133,23 @@ static int cmdline_init ( void ) {
|
||||
cmdline_user = phys_to_user ( cmdline_phys );
|
||||
len = ( strlen_user ( cmdline_user, 0 ) + 1 /* NUL */ );
|
||||
|
||||
pos1 = strstr((char *)cmdline_user, "mem:");
|
||||
if (pos1)
|
||||
{
|
||||
pos2 = strstr(pos1, ":size:");
|
||||
if (pos2)
|
||||
{
|
||||
*pos2 = 0;
|
||||
chainaddr = phys_to_user(strtoul(pos1 + 4 + 2, NULL, 16)); // skip 0x prefix in hex number
|
||||
chainlen = (int)strtoul(pos2 + 6, NULL, 10);
|
||||
*pos2 = ':';
|
||||
|
||||
g_initrd_addr = (void *)umalloc(chainlen);
|
||||
g_initrd_len = chainlen;
|
||||
memcpy_user((userptr_t)g_initrd_addr, 0, chainaddr, 0, chainlen);
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate and copy command line */
|
||||
cmdline_copy = malloc ( len );
|
||||
if ( ! cmdline_copy ) {
|
||||
@@ -137,6 +158,9 @@ static int cmdline_init ( void ) {
|
||||
rc = -ENOMEM;
|
||||
goto err_alloc_cmdline_copy;
|
||||
}
|
||||
|
||||
g_cmdline_copy = cmdline_copy;
|
||||
|
||||
cmdline = cmdline_copy;
|
||||
copy_from_user ( cmdline, cmdline_user, 0, len );
|
||||
DBGC ( colour, "RUNTIME found command line \"%s\" at %08x\n",
|
||||
@@ -221,11 +245,6 @@ static int initrd_init ( void ) {
|
||||
memcpy_user ( image->data, 0, phys_to_user ( initrd_phys ), 0,
|
||||
initrd_len );
|
||||
|
||||
g_initrd_addr = (void *)image->data;
|
||||
g_initrd_len = image->len;
|
||||
g_cmdline_copy = cmdline_copy;
|
||||
|
||||
|
||||
/* Mark initrd as consumed */
|
||||
initrd_phys = 0;
|
||||
|
||||
|
@@ -126,11 +126,8 @@ void hide_umalloc ( physaddr_t start, physaddr_t end ) {
|
||||
*
|
||||
*/
|
||||
void hide_textdata ( void ) {
|
||||
/* Deleted by longpanda */
|
||||
#if 0
|
||||
hide_region ( &hidemem_textdata, virt_to_phys ( _textdata ),
|
||||
virt_to_phys ( _etextdata ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
BIN
LANGUAGES/languages.ini
Normal file
BIN
LANGUAGES/languages.ini
Normal file
Binary file not shown.
12
README.md
12
README.md
@@ -1,11 +1,11 @@
|
||||
# Ventoy
|
||||
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.
|
||||
With ventoy, you don't need to format the disk over and over, 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,15 +13,17 @@ 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+)
|
||||
* 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
|
||||
* Auto installation supported (1.0.09+)
|
||||
* Readonly to USB drive during boot
|
||||
* USB normal use unafftected
|
||||
* Data nondestructive during version upgrade
|
||||
* No need to update Ventoy when a new distro is released
|
||||
|
||||

|
||||

|
||||
|
@@ -22,53 +22,7 @@
|
||||
#include "Ventoy2Disk.h"
|
||||
#include "Language.h"
|
||||
|
||||
const TCHAR * g_Str_English[STR_ID_MAX] =
|
||||
{
|
||||
TEXT("Error"),
|
||||
TEXT("Warning"),
|
||||
TEXT("Info"),
|
||||
TEXT("Please run under the correct directory!"),
|
||||
TEXT("Device"),
|
||||
TEXT("Ventoy At Local"),
|
||||
TEXT("Ventoy In Device"),
|
||||
TEXT("Status - READY"),
|
||||
TEXT("Install"),
|
||||
TEXT("Update"),
|
||||
TEXT("Upgrade operation is safe, ISO files will be unchanged.\r\nContinue?"),
|
||||
TEXT("The disk will be formatted and all the data will be lost.\r\nContinue?"),
|
||||
TEXT("The disk will be formatted and all the data will be lost.\r\nContinue? (Double Check)"),
|
||||
TEXT("Congratulations!\r\nVentoy has been successfully installed to the device."),
|
||||
TEXT("An error occurred during the installation. You can replug the USB and try again. Check log.txt for detail."),
|
||||
TEXT("Congratulations!\r\nVentoy has been successfully updated to the device."),
|
||||
TEXT("An error occurred during the update. You can replug the USB and try again. Check log.txt for detail."),
|
||||
|
||||
TEXT("A thread is running, please wait..."),
|
||||
};
|
||||
|
||||
const TCHAR * g_Str_ChineseSimple[STR_ID_MAX] =
|
||||
{
|
||||
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
|
||||
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
|
||||
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("״̬ - <><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
|
||||
TEXT("<EFBFBD><EFBFBD>װ"),
|
||||
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
|
||||
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ȫ<EFBFBD><EFBFBD>, ISO<53>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ᶪʧ\r\n<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
|
||||
TEXT("<EFBFBD><EFBFBD><EFBFBD>̻ᱻ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6>ᶪʧ!\r\n<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
|
||||
TEXT("<EFBFBD><EFBFBD><EFBFBD>̻ᱻ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6>ᶪʧ!\r\n<EFBFBD>ٴ<EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
|
||||
TEXT("<EFBFBD><EFBFBD>ϲ<EFBFBD><EFBFBD>! Ventoy <20>Ѿ<EFBFBD><D1BE>ɹ<EFBFBD><C9B9><EFBFBD>װ<EFBFBD><D7B0><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8>."),
|
||||
TEXT("<EFBFBD><EFBFBD>װ Ventoy <20><><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><D0B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>°β<C2B0>һ<EFBFBD><D2BB>U<EFBFBD><55>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>, <20><>ϸ<EFBFBD><CFB8>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD> log.txt <20>ļ<EFBFBD>."),
|
||||
TEXT("<EFBFBD><EFBFBD>ϲ<EFBFBD><EFBFBD>! <20>°汾<C2B0><E6B1BE> Ventoy <20>Ѿ<EFBFBD><D1BE>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8>."),
|
||||
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ventoy <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>°β<C2B0>һ<EFBFBD><D2BB>U<EFBFBD><55>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>, <20><>ϸ<EFBFBD><CFB8>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD> log.txt <20>ļ<EFBFBD>."),
|
||||
|
||||
TEXT("<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD>ȴ<EFBFBD>..."),
|
||||
};
|
||||
|
||||
const TCHAR * GetString(enum STR_ID ID)
|
||||
{
|
||||
return g_Str_English[ID];
|
||||
return g_cur_lang_data->MsgString[ID];
|
||||
};
|
||||
|
@@ -21,35 +21,65 @@
|
||||
#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_CFG_INI_A ".\\Ventoy2Disk.ini"
|
||||
#define VENTOY_MAX_LANGUAGE 200
|
||||
|
||||
#define GET_INI_STRING(Section, Key, Buf) GetPrivateProfileString(Section, Key, TEXT("#"), Buf, sizeof(Buf), VENTOY_LANGUAGE_INI)
|
||||
|
||||
typedef struct VENTOY_LANGUAGE
|
||||
{
|
||||
WCHAR Name[128];
|
||||
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)
|
||||
|
@@ -824,10 +824,137 @@ 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)
|
||||
{
|
||||
if (filebuf)
|
||||
{
|
||||
fl_fwrite(filebuf, 1, size, file);
|
||||
}
|
||||
|
||||
fl_fflush(file);
|
||||
fl_fclose(file);
|
||||
}
|
||||
|
||||
if (filebuf)
|
||||
{
|
||||
free(filebuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = 1;
|
||||
}
|
||||
|
||||
fl_shutdown();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int disk_xz_flush(void *src, unsigned int size)
|
||||
{
|
||||
unsigned int i;
|
||||
@@ -919,6 +1046,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 +1095,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;
|
||||
|
@@ -130,8 +130,7 @@ static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes)
|
||||
PartStartSector = 2048;
|
||||
PartSectorCount = (UINT32)((SizeBytes - VENTOY_EFI_PART_SIZE - SIZE_1MB) / 512);
|
||||
|
||||
if (MBR.PartTbl[0].FsFlag != 0x07 ||
|
||||
MBR.PartTbl[0].StartSectorId != PartStartSector ||
|
||||
if (MBR.PartTbl[0].StartSectorId != PartStartSector ||
|
||||
MBR.PartTbl[0].SectorCount != PartSectorCount)
|
||||
{
|
||||
Log("Part1 not match %u %u", PartStartSector, PartSectorCount);
|
||||
|
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user