Compare commits
65 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
433d854aab | ||
|
4cb9134e5c | ||
|
faceaf4267 | ||
|
37edd5a349 | ||
|
ed0f8721d7 | ||
|
d80a008c04 | ||
|
036e9cc167 | ||
|
26258653b7 | ||
|
754e754412 | ||
|
5af01de7c2 | ||
|
f9763a44b2 | ||
|
d063dbb7f2 | ||
|
89938e3c78 | ||
|
85840f626b | ||
|
7d1507906d | ||
|
0f8478fbe1 | ||
|
a6d3ecc7a9 | ||
|
5817b8b7b0 | ||
|
8493715fb4 | ||
|
3c46432d6f | ||
|
88dcceeabc | ||
|
ef204263ad | ||
|
e08e6705cf | ||
|
a8b2fdccc7 | ||
|
85348956df | ||
|
aa0a2ed067 | ||
|
49ceaa0f61 | ||
|
23986d742d | ||
|
039e68400d | ||
|
e384dad4d0 | ||
|
dcb3264519 | ||
|
4fda20d844 | ||
|
b32cf97f1f | ||
|
f7b35f371b | ||
|
49ca1e05a4 | ||
|
9ecbff9ce6 | ||
|
1d034f0a24 | ||
|
0ddc76a3aa | ||
|
a1ddade13c | ||
|
b925bbdeec | ||
|
e91b315f09 | ||
|
1cbe4c81b4 | ||
|
42990058ed | ||
|
171667c547 | ||
|
a5c706511b | ||
|
785255b65f | ||
|
176c819d10 | ||
|
8f2bf03084 | ||
|
4408be5cf0 | ||
|
74154ad9a3 | ||
|
43fcd4f262 | ||
|
be35990666 | ||
|
ad3db3dfcb | ||
|
227264f208 | ||
|
1f37663285 | ||
|
8cde5a4898 | ||
|
c8e86938fe | ||
|
7a0b2d945e | ||
|
5089fda07d | ||
|
f77ba141fd | ||
|
6d1ace0570 | ||
|
a2d732c170 | ||
|
a54b6f692c | ||
|
73c196a823 | ||
|
487ffc6795 |
12
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||||
|
patreon: # Replace with a single Patreon username
|
||||||
|
open_collective: # Replace with a single Open Collective username
|
||||||
|
ko_fi: # Replace with a single Ko-fi username
|
||||||
|
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||||
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
|
liberapay: # Replace with a single Liberapay username
|
||||||
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
|
otechie: # Replace with a single Otechie username
|
||||||
|
custom: ['https://www.ventoy.net/en/donation.html'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
@@ -31,7 +31,6 @@
|
|||||||
https://codeload.github.com/tianocore/edk2/zip/edk2-stable201911 ===> /home/Ventoy-master/EDK2/edk2-edk2-stable201911.zip
|
https://codeload.github.com/tianocore/edk2/zip/edk2-stable201911 ===> /home/Ventoy-master/EDK2/edk2-edk2-stable201911.zip
|
||||||
https://codeload.github.com/relan/exfat/zip/v1.3.0 ===> /home/Ventoy-master/ExFAT/exfat-1.3.0.zip
|
https://codeload.github.com/relan/exfat/zip/v1.3.0 ===> /home/Ventoy-master/ExFAT/exfat-1.3.0.zip
|
||||||
https://codeload.github.com/libfuse/libfuse/zip/fuse-2.9.9 ===> /home/Ventoy-master/ExFAT/libfuse-fuse-2.9.9.zip
|
https://codeload.github.com/libfuse/libfuse/zip/fuse-2.9.9 ===> /home/Ventoy-master/ExFAT/libfuse-fuse-2.9.9.zip
|
||||||
http://ultra-embedded.com/releases/fat_io_lib.zip ===> /home/Ventoy-master/vtoyfat/fat_io_lib/fat_io_lib.zip
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -199,5 +198,14 @@
|
|||||||
INSTALL/EFI/BOOT/MokManager.efi --> EFI/BOOT/MokManager.efi SHA-256: 3bf1f46cee0832355c7dd1dba880dea9bcaa78cc44375a1559d43bc9db18933b
|
INSTALL/EFI/BOOT/MokManager.efi --> EFI/BOOT/MokManager.efi SHA-256: 3bf1f46cee0832355c7dd1dba880dea9bcaa78cc44375a1559d43bc9db18933b
|
||||||
|
|
||||||
|
|
||||||
|
5.11 INSTALL/tool/ash
|
||||||
|
https://busybox.net/downloads/binaries/1.31.0-i686-uclibc/ busybox_ASH
|
||||||
|
SHA-256: 2943f02f85fee0c9551aec47110a558a73f919c032b3c51e56d6f197b5ec4d7b
|
||||||
|
|
||||||
|
5.12 7za.exe
|
||||||
|
download from https://www.7-zip.org/a/7z1900-extra.7z
|
||||||
|
ISNTALL/ventoy/7z/64/7za.exe SHA-256: 8117e40ee7f824f63373a4f5625bb62749f69159d0c449b3ce2f35aad3b83549
|
||||||
|
ISNTALL/ventoy/7z/32/7za.exe SHA-256: ea308c76a2f927b160a143d94072b0dce232e04b751f0c6432a94e05164e716d
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
17
Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
FROM centos:7
|
||||||
|
|
||||||
|
RUN yum -y install \
|
||||||
|
libXpm net-tools bzip2 wget vim gcc gcc-c++ samba dos2unix glibc-devel glibc.i686 glibc-devel.i686 \
|
||||||
|
mpfr.i686 mpfr-devel.i686 zlib.i686 rsync autogen autoconf automake libtool gettext* bison binutils \
|
||||||
|
flex device-mapper-devel SDL libpciaccess libusb freetype freetype-devel gnu-free-* qemu-* virt-* \
|
||||||
|
libvirt* vte* NetworkManager-bluetooth brlapi fuse-devel dejavu* gnu-efi* pesign shim \
|
||||||
|
iscsi-initiator-utils grub2-tools zip nasm acpica-tools glibc-static zlib-static
|
||||||
|
|
||||||
|
CMD cd /ventoy \
|
||||||
|
&& wget -P DOC/ https://www.fefe.de/dietlibc/dietlibc-0.34.tar.xz \
|
||||||
|
&& wget -P GRUB2/ https://ftp.gnu.org/gnu/grub/grub-2.04.tar.xz \
|
||||||
|
&& wget -O EDK2/edk2-edk2-stable201911.zip https://codeload.github.com/tianocore/edk2/zip/edk2-stable201911 \
|
||||||
|
&& wget -O ExFAT/exfat-1.3.0.zip https://codeload.github.com/relan/exfat/zip/v1.3.0 \
|
||||||
|
&& wget -O ExFAT/libfuse-fuse-2.9.9.zip https://codeload.github.com/libfuse/libfuse/zip/fuse-2.9.9 \
|
||||||
|
&& cd INSTALL && ls -la && sh all_in_one.sh
|
||||||
|
|
@@ -36,34 +36,31 @@
|
|||||||
#include <Protocol/SimpleFileSystem.h>
|
#include <Protocol/SimpleFileSystem.h>
|
||||||
#include <Ventoy.h>
|
#include <Ventoy.h>
|
||||||
|
|
||||||
UINTN g_iso_buf_size = 0;
|
|
||||||
BOOLEAN gMemdiskMode = FALSE;
|
|
||||||
BOOLEAN gDebugPrint = FALSE;
|
BOOLEAN gDebugPrint = FALSE;
|
||||||
BOOLEAN gLoadIsoEfi = FALSE;
|
BOOLEAN gLoadIsoEfi = FALSE;
|
||||||
ventoy_ram_disk g_ramdisk_param;
|
ventoy_ram_disk g_ramdisk_param;
|
||||||
ventoy_chain_head *g_chain;
|
ventoy_chain_head *g_chain;
|
||||||
ventoy_img_chunk *g_chunk;
|
ventoy_img_chunk *g_chunk;
|
||||||
|
UINT8 *g_os_param_reserved;
|
||||||
UINT32 g_img_chunk_num;
|
UINT32 g_img_chunk_num;
|
||||||
ventoy_override_chunk *g_override_chunk;
|
ventoy_override_chunk *g_override_chunk;
|
||||||
UINT32 g_override_chunk_num;
|
UINT32 g_override_chunk_num;
|
||||||
ventoy_virt_chunk *g_virt_chunk;
|
ventoy_virt_chunk *g_virt_chunk;
|
||||||
UINT32 g_virt_chunk_num;
|
UINT32 g_virt_chunk_num;
|
||||||
vtoy_block_data gBlockData;
|
vtoy_block_data gBlockData;
|
||||||
ventoy_sector_flag *g_sector_flag = NULL;
|
|
||||||
UINT32 g_sector_flag_num = 0;
|
|
||||||
static grub_env_get_pf grub_env_get = NULL;
|
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_grub_param_file_replace *g_file_replace_list = NULL;
|
||||||
ventoy_efi_file_replace g_efi_file_replace;
|
ventoy_efi_file_replace g_efi_file_replace;
|
||||||
|
|
||||||
CHAR16 gFirstTryBootFile[256] = {0};
|
|
||||||
|
|
||||||
CONST CHAR16 gIso9660EfiDriverPath[] = ISO9660_EFI_DRIVER_PATH;
|
CONST CHAR16 gIso9660EfiDriverPath[] = ISO9660_EFI_DRIVER_PATH;
|
||||||
|
|
||||||
|
BOOLEAN g_fix_windows_1st_cdrom_issue = FALSE;
|
||||||
|
|
||||||
|
STATIC BOOLEAN g_hook_keyboard = FALSE;
|
||||||
|
|
||||||
|
CHAR16 gFirstTryBootFile[256] = {0};
|
||||||
|
|
||||||
/* Boot filename */
|
/* Boot filename */
|
||||||
UINTN gBootFileStartIndex = 1;
|
UINTN gBootFileStartIndex = 1;
|
||||||
CONST CHAR16 *gEfiBootFileName[] =
|
CONST CHAR16 *gEfiBootFileName[] =
|
||||||
@@ -76,9 +73,6 @@ CONST CHAR16 *gEfiBootFileName[] =
|
|||||||
L"\\efi\\boot\\bootx64.efi",
|
L"\\efi\\boot\\bootx64.efi",
|
||||||
};
|
};
|
||||||
|
|
||||||
/* EFI block device vendor device path GUID */
|
|
||||||
EFI_GUID gVtoyBlockDevicePathGuid = VTOY_BLOCK_DEVICE_PATH_GUID;
|
|
||||||
|
|
||||||
VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...)
|
VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...)
|
||||||
{
|
{
|
||||||
VA_LIST Marker;
|
VA_LIST Marker;
|
||||||
@@ -204,6 +198,13 @@ static void EFIAPI ventoy_dump_chain(ventoy_chain_head *chain)
|
|||||||
debug("os_param->vtoy_img_size=<%llu>", chain->os_param.vtoy_img_size);
|
debug("os_param->vtoy_img_size=<%llu>", chain->os_param.vtoy_img_size);
|
||||||
debug("os_param->vtoy_img_location_addr=<0x%llx>", chain->os_param.vtoy_img_location_addr);
|
debug("os_param->vtoy_img_location_addr=<0x%llx>", chain->os_param.vtoy_img_location_addr);
|
||||||
debug("os_param->vtoy_img_location_len=<%u>", chain->os_param.vtoy_img_location_len);
|
debug("os_param->vtoy_img_location_len=<%u>", chain->os_param.vtoy_img_location_len);
|
||||||
|
debug("os_param->vtoy_reserved=<%u %u %u %u %u>",
|
||||||
|
g_os_param_reserved[0],
|
||||||
|
g_os_param_reserved[1],
|
||||||
|
g_os_param_reserved[2],
|
||||||
|
g_os_param_reserved[3],
|
||||||
|
g_os_param_reserved[4]
|
||||||
|
);
|
||||||
|
|
||||||
ventoy_debug_pause();
|
ventoy_debug_pause();
|
||||||
|
|
||||||
@@ -224,6 +225,70 @@ static void EFIAPI ventoy_dump_chain(ventoy_chain_head *chain)
|
|||||||
ventoy_dump_virt_chunk(chain);
|
ventoy_dump_virt_chunk(chain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ventoy_update_image_location(ventoy_os_param *param)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status = EFI_SUCCESS;
|
||||||
|
UINT8 chksum = 0;
|
||||||
|
unsigned int i;
|
||||||
|
unsigned int length;
|
||||||
|
UINTN address = 0;
|
||||||
|
void *buffer = NULL;
|
||||||
|
ventoy_image_location *location = NULL;
|
||||||
|
ventoy_image_disk_region *region = NULL;
|
||||||
|
ventoy_img_chunk *chunk = g_chunk;
|
||||||
|
|
||||||
|
length = sizeof(ventoy_image_location) + (g_img_chunk_num - 1) * sizeof(ventoy_image_disk_region);
|
||||||
|
|
||||||
|
Status = gBS->AllocatePool(EfiRuntimeServicesData, length + 4096 * 2, &buffer);
|
||||||
|
if (EFI_ERROR(Status) || NULL == buffer)
|
||||||
|
{
|
||||||
|
debug("Failed to allocate runtime pool %r\n", Status);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
address = (UINTN)buffer;
|
||||||
|
|
||||||
|
if (address % 4096)
|
||||||
|
{
|
||||||
|
address += 4096 - (address % 4096);
|
||||||
|
}
|
||||||
|
|
||||||
|
param->chksum = 0;
|
||||||
|
param->vtoy_img_location_addr = address;
|
||||||
|
param->vtoy_img_location_len = length;
|
||||||
|
|
||||||
|
/* update check sum */
|
||||||
|
for (i = 0; i < sizeof(ventoy_os_param); i++)
|
||||||
|
{
|
||||||
|
chksum += *((UINT8 *)param + i);
|
||||||
|
}
|
||||||
|
param->chksum = (chksum == 0) ? 0 : (UINT8)(0x100 - chksum);
|
||||||
|
|
||||||
|
location = (ventoy_image_location *)(unsigned long)(param->vtoy_img_location_addr);
|
||||||
|
if (NULL == location)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
CopyMem(&location->guid, ¶m->guid, sizeof(ventoy_guid));
|
||||||
|
location->image_sector_size = 2048;
|
||||||
|
location->disk_sector_size = g_chain->disk_sector_size;
|
||||||
|
location->region_count = g_img_chunk_num;
|
||||||
|
|
||||||
|
region = location->regions;
|
||||||
|
|
||||||
|
for (i = 0; i < g_img_chunk_num; i++)
|
||||||
|
{
|
||||||
|
region->image_sector_count = chunk->img_end_sector - chunk->img_start_sector + 1;
|
||||||
|
region->image_start_sector = chunk->img_start_sector;
|
||||||
|
region->disk_start_sector = chunk->disk_start_sector;
|
||||||
|
region++;
|
||||||
|
chunk++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
EFI_HANDLE EFIAPI ventoy_get_parent_handle(IN EFI_DEVICE_PATH_PROTOCOL *pDevPath)
|
EFI_HANDLE EFIAPI ventoy_get_parent_handle(IN EFI_DEVICE_PATH_PROTOCOL *pDevPath)
|
||||||
{
|
{
|
||||||
EFI_HANDLE Handle = NULL;
|
EFI_HANDLE Handle = NULL;
|
||||||
@@ -258,280 +323,6 @@ EFI_HANDLE EFIAPI ventoy_get_parent_handle(IN EFI_DEVICE_PATH_PROTOCOL *pDevPath
|
|||||||
return Handle;
|
return Handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
EFI_STATUS EFIAPI ventoy_block_io_reset
|
|
||||||
(
|
|
||||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
|
||||||
IN BOOLEAN ExtendedVerification
|
|
||||||
)
|
|
||||||
{
|
|
||||||
(VOID)This;
|
|
||||||
(VOID)ExtendedVerification;
|
|
||||||
return EFI_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
STATIC EFI_STATUS EFIAPI ventoy_read_iso_sector
|
|
||||||
(
|
|
||||||
IN UINT64 Sector,
|
|
||||||
IN UINTN Count,
|
|
||||||
OUT VOID *Buffer
|
|
||||||
)
|
|
||||||
{
|
|
||||||
EFI_STATUS Status = EFI_SUCCESS;
|
|
||||||
EFI_LBA MapLba = 0;
|
|
||||||
UINT32 i = 0;
|
|
||||||
UINTN secLeft = 0;
|
|
||||||
UINTN secRead = 0;
|
|
||||||
UINT64 ReadStart = 0;
|
|
||||||
UINT64 ReadEnd = 0;
|
|
||||||
UINT64 OverrideStart = 0;
|
|
||||||
UINT64 OverrideEnd= 0;
|
|
||||||
UINT8 *pCurBuf = (UINT8 *)Buffer;
|
|
||||||
ventoy_img_chunk *pchunk = g_chunk;
|
|
||||||
ventoy_override_chunk *pOverride = g_override_chunk;
|
|
||||||
EFI_BLOCK_IO_PROTOCOL *pRawBlockIo = gBlockData.pRawBlockIo;
|
|
||||||
|
|
||||||
debug("read iso sector %lu count %u", Sector, Count);
|
|
||||||
|
|
||||||
ReadStart = Sector * 2048;
|
|
||||||
ReadEnd = (Sector + Count) * 2048;
|
|
||||||
|
|
||||||
for (i = 0; Count > 0 && i < g_img_chunk_num; i++, pchunk++)
|
|
||||||
{
|
|
||||||
if (Sector >= pchunk->img_start_sector && Sector <= pchunk->img_end_sector)
|
|
||||||
{
|
|
||||||
if (g_chain->disk_sector_size == 512)
|
|
||||||
{
|
|
||||||
MapLba = (Sector - pchunk->img_start_sector) * 4 + pchunk->disk_start_sector;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MapLba = (Sector - pchunk->img_start_sector) * 2048 / g_chain->disk_sector_size + pchunk->disk_start_sector;
|
|
||||||
}
|
|
||||||
|
|
||||||
secLeft = pchunk->img_end_sector + 1 - Sector;
|
|
||||||
secRead = (Count < secLeft) ? Count : secLeft;
|
|
||||||
|
|
||||||
Status = pRawBlockIo->ReadBlocks(pRawBlockIo, pRawBlockIo->Media->MediaId,
|
|
||||||
MapLba, secRead * 2048, pCurBuf);
|
|
||||||
if (EFI_ERROR(Status))
|
|
||||||
{
|
|
||||||
debug("Raw disk read block failed %r", Status);
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
Count -= secRead;
|
|
||||||
Sector += secRead;
|
|
||||||
pCurBuf += secRead * 2048;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ReadStart > g_chain->real_img_size_in_bytes)
|
|
||||||
{
|
|
||||||
return EFI_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* override data */
|
|
||||||
pCurBuf = (UINT8 *)Buffer;
|
|
||||||
for (i = 0; i < g_override_chunk_num; i++, pOverride++)
|
|
||||||
{
|
|
||||||
OverrideStart = pOverride->img_offset;
|
|
||||||
OverrideEnd = pOverride->img_offset + pOverride->override_size;
|
|
||||||
|
|
||||||
if (OverrideStart >= ReadEnd || ReadStart >= OverrideEnd)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ReadStart <= OverrideStart)
|
|
||||||
{
|
|
||||||
if (ReadEnd <= OverrideEnd)
|
|
||||||
{
|
|
||||||
CopyMem(pCurBuf + OverrideStart - ReadStart, pOverride->override_data, ReadEnd - OverrideStart);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CopyMem(pCurBuf + OverrideStart - ReadStart, pOverride->override_data, pOverride->override_size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (ReadEnd <= OverrideEnd)
|
|
||||||
{
|
|
||||||
CopyMem(pCurBuf, pOverride->override_data + ReadStart - OverrideStart, ReadEnd - ReadStart);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CopyMem(pCurBuf, pOverride->override_data + ReadStart - OverrideStart, OverrideEnd - ReadStart);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
EFI_STATUS EFIAPI ventoy_block_io_ramdisk_read
|
|
||||||
(
|
|
||||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
|
||||||
IN UINT32 MediaId,
|
|
||||||
IN EFI_LBA Lba,
|
|
||||||
IN UINTN BufferSize,
|
|
||||||
OUT VOID *Buffer
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//debug("### ventoy_block_io_ramdisk_read sector:%u count:%u", (UINT32)Lba, (UINT32)BufferSize / 2048);
|
|
||||||
|
|
||||||
(VOID)This;
|
|
||||||
(VOID)MediaId;
|
|
||||||
|
|
||||||
CopyMem(Buffer, (char *)g_chain + (Lba * 2048), BufferSize);
|
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
)
|
|
||||||
{
|
|
||||||
UINT32 i = 0;
|
|
||||||
UINT32 j = 0;
|
|
||||||
UINT32 lbacount = 0;
|
|
||||||
UINT32 secNum = 0;
|
|
||||||
UINT64 offset = 0;
|
|
||||||
EFI_LBA curlba = 0;
|
|
||||||
EFI_LBA lastlba = 0;
|
|
||||||
UINT8 *lastbuffer;
|
|
||||||
ventoy_sector_flag *cur_flag;
|
|
||||||
ventoy_virt_chunk *node;
|
|
||||||
|
|
||||||
//debug("### ventoy_block_io_read sector:%u count:%u", (UINT32)Lba, (UINT32)BufferSize / 2048);
|
|
||||||
|
|
||||||
secNum = BufferSize / 2048;
|
|
||||||
offset = Lba * 2048;
|
|
||||||
|
|
||||||
if (offset + BufferSize < g_chain->real_img_size_in_bytes)
|
|
||||||
{
|
|
||||||
return ventoy_read_iso_sector(Lba, secNum, Buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (secNum > g_sector_flag_num)
|
|
||||||
{
|
|
||||||
cur_flag = AllocatePool(secNum * sizeof(ventoy_sector_flag));
|
|
||||||
if (NULL == cur_flag)
|
|
||||||
{
|
|
||||||
return EFI_OUT_OF_RESOURCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
FreePool(g_sector_flag);
|
|
||||||
g_sector_flag = cur_flag;
|
|
||||||
g_sector_flag_num = secNum;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (curlba = Lba, cur_flag = g_sector_flag, j = 0; j < secNum; j++, curlba++, cur_flag++)
|
|
||||||
{
|
|
||||||
cur_flag->flag = 0;
|
|
||||||
for (node = g_virt_chunk, i = 0; i < g_virt_chunk_num; i++, node++)
|
|
||||||
{
|
|
||||||
if (curlba >= node->mem_sector_start && curlba < node->mem_sector_end)
|
|
||||||
{
|
|
||||||
CopyMem((UINT8 *)Buffer + j * 2048,
|
|
||||||
(char *)g_virt_chunk + node->mem_sector_offset + (curlba - node->mem_sector_start) * 2048,
|
|
||||||
2048);
|
|
||||||
cur_flag->flag = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (curlba >= node->remap_sector_start && curlba < node->remap_sector_end)
|
|
||||||
{
|
|
||||||
cur_flag->remap_lba = node->org_sector_start + curlba - node->remap_sector_start;
|
|
||||||
cur_flag->flag = 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (curlba = Lba, cur_flag = g_sector_flag, j = 0; j < secNum; j++, curlba++, cur_flag++)
|
|
||||||
{
|
|
||||||
if (cur_flag->flag == 2)
|
|
||||||
{
|
|
||||||
if (lastlba == 0)
|
|
||||||
{
|
|
||||||
lastbuffer = (UINT8 *)Buffer + j * 2048;
|
|
||||||
lastlba = cur_flag->remap_lba;
|
|
||||||
lbacount = 1;
|
|
||||||
}
|
|
||||||
else if (lastlba + lbacount == cur_flag->remap_lba)
|
|
||||||
{
|
|
||||||
lbacount++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ventoy_read_iso_sector(lastlba, lbacount, lastbuffer);
|
|
||||||
lastbuffer = (UINT8 *)Buffer + j * 2048;
|
|
||||||
lastlba = cur_flag->remap_lba;
|
|
||||||
lbacount = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lbacount > 0)
|
|
||||||
{
|
|
||||||
ventoy_read_iso_sector(lastlba, lbacount, lastbuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
EFI_STATUS EFIAPI ventoy_block_io_write
|
|
||||||
(
|
|
||||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
|
||||||
IN UINT32 MediaId,
|
|
||||||
IN EFI_LBA Lba,
|
|
||||||
IN UINTN BufferSize,
|
|
||||||
IN VOID *Buffer
|
|
||||||
)
|
|
||||||
{
|
|
||||||
(VOID)This;
|
|
||||||
(VOID)MediaId;
|
|
||||||
(VOID)Lba;
|
|
||||||
(VOID)BufferSize;
|
|
||||||
(VOID)Buffer;
|
|
||||||
return EFI_WRITE_PROTECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
EFI_STATUS EFIAPI ventoy_block_io_flush(IN EFI_BLOCK_IO_PROTOCOL *This)
|
|
||||||
{
|
|
||||||
(VOID)This;
|
|
||||||
return EFI_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
EFI_STATUS EFIAPI ventoy_fill_device_path(VOID)
|
|
||||||
{
|
|
||||||
UINTN NameLen = 0;
|
|
||||||
UINT8 TmpBuf[128] = {0};
|
|
||||||
VENDOR_DEVICE_PATH *venPath = NULL;
|
|
||||||
|
|
||||||
venPath = (VENDOR_DEVICE_PATH *)TmpBuf;
|
|
||||||
NameLen = StrSize(VTOY_BLOCK_DEVICE_PATH_NAME);
|
|
||||||
venPath->Header.Type = HARDWARE_DEVICE_PATH;
|
|
||||||
venPath->Header.SubType = HW_VENDOR_DP;
|
|
||||||
venPath->Header.Length[0] = sizeof(VENDOR_DEVICE_PATH) + NameLen;
|
|
||||||
venPath->Header.Length[1] = 0;
|
|
||||||
CopyMem(&venPath->Guid, &gVtoyBlockDevicePathGuid, sizeof(EFI_GUID));
|
|
||||||
CopyMem(venPath + 1, VTOY_BLOCK_DEVICE_PATH_NAME, NameLen);
|
|
||||||
|
|
||||||
gBlockData.Path = AppendDevicePathNode(NULL, (EFI_DEVICE_PATH_PROTOCOL *)TmpBuf);
|
|
||||||
gBlockData.DevicePathCompareLen = sizeof(VENDOR_DEVICE_PATH) + NameLen;
|
|
||||||
|
|
||||||
debug("gBlockData.Path=<%s>\n", ConvertDevicePathToText(gBlockData.Path, FALSE, FALSE));
|
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
EFI_STATUS EFIAPI ventoy_save_ramdisk_param(VOID)
|
EFI_STATUS EFIAPI ventoy_save_ramdisk_param(VOID)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status = EFI_SUCCESS;
|
EFI_STATUS Status = EFI_SUCCESS;
|
||||||
@@ -545,7 +336,7 @@ EFI_STATUS EFIAPI ventoy_save_ramdisk_param(VOID)
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
EFI_STATUS EFIAPI ventoy_del_ramdisk_param(VOID)
|
EFI_STATUS EFIAPI ventoy_delete_ramdisk_param(VOID)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status = EFI_SUCCESS;
|
EFI_STATUS Status = EFI_SUCCESS;
|
||||||
EFI_GUID VarGuid = VENTOY_GUID;
|
EFI_GUID VarGuid = VENTOY_GUID;
|
||||||
@@ -559,7 +350,7 @@ EFI_STATUS EFIAPI ventoy_del_ramdisk_param(VOID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EFI_STATUS EFIAPI ventoy_set_variable(VOID)
|
EFI_STATUS EFIAPI ventoy_save_variable(VOID)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status = EFI_SUCCESS;
|
EFI_STATUS Status = EFI_SUCCESS;
|
||||||
EFI_GUID VarGuid = VENTOY_GUID;
|
EFI_GUID VarGuid = VENTOY_GUID;
|
||||||
@@ -585,56 +376,7 @@ EFI_STATUS EFIAPI ventoy_delete_variable(VOID)
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STATIC EFI_STATUS EFIAPI ventoy_load_image
|
||||||
EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 ImgSize)
|
|
||||||
{
|
|
||||||
EFI_STATUS Status = EFI_SUCCESS;
|
|
||||||
EFI_BLOCK_IO_PROTOCOL *pBlockIo = &(gBlockData.BlockIo);
|
|
||||||
|
|
||||||
ventoy_fill_device_path();
|
|
||||||
|
|
||||||
gBlockData.Media.BlockSize = 2048;
|
|
||||||
gBlockData.Media.LastBlock = ImgSize / 2048 - 1;
|
|
||||||
gBlockData.Media.ReadOnly = TRUE;
|
|
||||||
gBlockData.Media.MediaPresent = 1;
|
|
||||||
gBlockData.Media.LogicalBlocksPerPhysicalBlock = 1;
|
|
||||||
|
|
||||||
pBlockIo->Revision = EFI_BLOCK_IO_PROTOCOL_REVISION3;
|
|
||||||
pBlockIo->Media = &(gBlockData.Media);
|
|
||||||
pBlockIo->Reset = ventoy_block_io_reset;
|
|
||||||
|
|
||||||
if (gMemdiskMode)
|
|
||||||
{
|
|
||||||
pBlockIo->ReadBlocks = ventoy_block_io_ramdisk_read;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pBlockIo->ReadBlocks = ventoy_block_io_read;
|
|
||||||
}
|
|
||||||
|
|
||||||
pBlockIo->WriteBlocks = ventoy_block_io_write;
|
|
||||||
pBlockIo->FlushBlocks = ventoy_block_io_flush;
|
|
||||||
|
|
||||||
Status = gBS->InstallMultipleProtocolInterfaces(&gBlockData.Handle,
|
|
||||||
&gEfiBlockIoProtocolGuid, &gBlockData.BlockIo,
|
|
||||||
&gEfiDevicePathProtocolGuid, gBlockData.Path,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
debug("Install protocol %r", Status);
|
|
||||||
|
|
||||||
if (EFI_ERROR(Status))
|
|
||||||
{
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
Status = gBS->ConnectController(gBlockData.Handle, NULL, NULL, 1);
|
|
||||||
debug("Connect controller %r", Status);
|
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
EFI_STATUS EFIAPI ventoy_load_image
|
|
||||||
(
|
(
|
||||||
IN EFI_HANDLE ImageHandle,
|
IN EFI_HANDLE ImageHandle,
|
||||||
IN EFI_DEVICE_PATH_PROTOCOL *pDevicePath,
|
IN EFI_DEVICE_PATH_PROTOCOL *pDevicePath,
|
||||||
@@ -745,6 +487,7 @@ STATIC EFI_STATUS EFIAPI ventoy_find_iso_disk(IN EFI_HANDLE ImageHandle)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
STATIC EFI_STATUS EFIAPI ventoy_find_iso_disk_fs(IN EFI_HANDLE ImageHandle)
|
STATIC EFI_STATUS EFIAPI ventoy_find_iso_disk_fs(IN EFI_HANDLE ImageHandle)
|
||||||
{
|
{
|
||||||
UINTN i = 0;
|
UINTN i = 0;
|
||||||
@@ -831,70 +574,6 @@ STATIC EFI_STATUS EFIAPI ventoy_load_isoefi_driver(IN EFI_HANDLE ImageHandle)
|
|||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ventoy_update_image_location(ventoy_os_param *param)
|
|
||||||
{
|
|
||||||
EFI_STATUS Status = EFI_SUCCESS;
|
|
||||||
UINT8 chksum = 0;
|
|
||||||
unsigned int i;
|
|
||||||
unsigned int length;
|
|
||||||
UINTN address = 0;
|
|
||||||
void *buffer = NULL;
|
|
||||||
ventoy_image_location *location = NULL;
|
|
||||||
ventoy_image_disk_region *region = NULL;
|
|
||||||
ventoy_img_chunk *chunk = g_chunk;
|
|
||||||
|
|
||||||
length = sizeof(ventoy_image_location) + (g_img_chunk_num - 1) * sizeof(ventoy_image_disk_region);
|
|
||||||
|
|
||||||
Status = gBS->AllocatePool(EfiRuntimeServicesData, length + 4096 * 2, &buffer);
|
|
||||||
if (EFI_ERROR(Status) || NULL == buffer)
|
|
||||||
{
|
|
||||||
debug("Failed to allocate runtime pool %r\n", Status);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
address = (UINTN)buffer;
|
|
||||||
|
|
||||||
if (address % 4096)
|
|
||||||
{
|
|
||||||
address += 4096 - (address % 4096);
|
|
||||||
}
|
|
||||||
|
|
||||||
param->chksum = 0;
|
|
||||||
param->vtoy_img_location_addr = address;
|
|
||||||
param->vtoy_img_location_len = length;
|
|
||||||
|
|
||||||
/* update check sum */
|
|
||||||
for (i = 0; i < sizeof(ventoy_os_param); i++)
|
|
||||||
{
|
|
||||||
chksum += *((UINT8 *)param + i);
|
|
||||||
}
|
|
||||||
param->chksum = (chksum == 0) ? 0 : (UINT8)(0x100 - chksum);
|
|
||||||
|
|
||||||
location = (ventoy_image_location *)(unsigned long)(param->vtoy_img_location_addr);
|
|
||||||
if (NULL == location)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
CopyMem(&location->guid, ¶m->guid, sizeof(ventoy_guid));
|
|
||||||
location->image_sector_size = 2048;
|
|
||||||
location->disk_sector_size = g_chain->disk_sector_size;
|
|
||||||
location->region_count = g_img_chunk_num;
|
|
||||||
|
|
||||||
region = location->regions;
|
|
||||||
|
|
||||||
for (i = 0; i < g_img_chunk_num; i++)
|
|
||||||
{
|
|
||||||
region->image_sector_count = chunk->img_end_sector - chunk->img_start_sector + 1;
|
|
||||||
region->image_start_sector = chunk->img_start_sector;
|
|
||||||
region->disk_start_sector = chunk->disk_start_sector;
|
|
||||||
region++;
|
|
||||||
chunk++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
|
STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
|
||||||
{
|
{
|
||||||
UINT32 i = 0;
|
UINT32 i = 0;
|
||||||
@@ -906,6 +585,7 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
|
|||||||
EFI_STATUS Status = EFI_SUCCESS;
|
EFI_STATUS Status = EFI_SUCCESS;
|
||||||
ventoy_grub_param *pGrubParam = NULL;
|
ventoy_grub_param *pGrubParam = NULL;
|
||||||
EFI_LOADED_IMAGE_PROTOCOL *pImageInfo = NULL;
|
EFI_LOADED_IMAGE_PROTOCOL *pImageInfo = NULL;
|
||||||
|
ventoy_chain_head *chain = NULL;
|
||||||
|
|
||||||
Status = gBS->HandleProtocol(ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&pImageInfo);
|
Status = gBS->HandleProtocol(ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&pImageInfo);
|
||||||
if (EFI_ERROR(Status))
|
if (EFI_ERROR(Status))
|
||||||
@@ -977,12 +657,15 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
|
|||||||
);
|
);
|
||||||
|
|
||||||
pPos = StrStr(pCmdLine, L"mem:");
|
pPos = StrStr(pCmdLine, L"mem:");
|
||||||
g_chain = (ventoy_chain_head *)StrHexToUintn(pPos + 4);
|
chain = (ventoy_chain_head *)StrHexToUintn(pPos + 4);
|
||||||
|
|
||||||
pPos = StrStr(pPos, L"size:");
|
pPos = StrStr(pPos, L"size:");
|
||||||
size = StrDecimalToUintn(pPos + 5);
|
size = StrDecimalToUintn(pPos + 5);
|
||||||
|
|
||||||
debug("memory addr:%p size:%lu", g_chain, size);
|
debug("memory addr:%p size:%lu", chain, size);
|
||||||
|
|
||||||
|
g_chain = AllocatePool(size);
|
||||||
|
CopyMem(g_chain, chain, size);
|
||||||
|
|
||||||
if (StrStr(pCmdLine, L"memdisk"))
|
if (StrStr(pCmdLine, L"memdisk"))
|
||||||
{
|
{
|
||||||
@@ -998,6 +681,21 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
|
|||||||
g_virt_chunk = (ventoy_virt_chunk *)((char *)g_chain + g_chain->virt_chunk_offset);
|
g_virt_chunk = (ventoy_virt_chunk *)((char *)g_chain + g_chain->virt_chunk_offset);
|
||||||
g_virt_chunk_num = g_chain->virt_chunk_num;
|
g_virt_chunk_num = g_chain->virt_chunk_num;
|
||||||
|
|
||||||
|
g_os_param_reserved = (UINT8 *)(g_chain->os_param.vtoy_reserved);
|
||||||
|
|
||||||
|
/* Workaround for Windows & ISO9660 */
|
||||||
|
if (g_os_param_reserved[2] == ventoy_chain_windows && g_os_param_reserved[3] == 0)
|
||||||
|
{
|
||||||
|
g_fixup_iso9660_secover_enable = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_os_param_reserved[2] == ventoy_chain_windows && g_os_param_reserved[4] != 1)
|
||||||
|
{
|
||||||
|
g_hook_keyboard = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
debug("internal param: secover:%u keyboard:%u", g_fixup_iso9660_secover_enable, g_hook_keyboard);
|
||||||
|
|
||||||
for (i = 0; i < sizeof(ventoy_os_param); i++)
|
for (i = 0; i < sizeof(ventoy_os_param); i++)
|
||||||
{
|
{
|
||||||
chksum += *((UINT8 *)(&(g_chain->os_param)) + i);
|
chksum += *((UINT8 *)(&(g_chain->os_param)) + i);
|
||||||
@@ -1016,85 +714,85 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_fix_windows_1st_cdrom_issue = FALSE;
|
||||||
|
if (ventoy_chain_windows == g_os_param_reserved[2] ||
|
||||||
|
ventoy_chain_wim == g_os_param_reserved[2])
|
||||||
|
{
|
||||||
|
if (ventoy_is_cdrom_dp_exist())
|
||||||
|
{
|
||||||
|
debug("fixup the 1st cdrom influences when boot windows ...");
|
||||||
|
g_fix_windows_1st_cdrom_issue = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FreePool(pCmdLine);
|
FreePool(pCmdLine);
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
EFI_STATUS EFIAPI ventoy_wrapper_file_open
|
EFI_STATUS EFIAPI ventoy_clean_env(VOID)
|
||||||
(
|
|
||||||
EFI_FILE_HANDLE This,
|
|
||||||
EFI_FILE_HANDLE *New,
|
|
||||||
CHAR16 *Name,
|
|
||||||
UINT64 Mode,
|
|
||||||
UINT64 Attributes
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
UINT32 i = 0;
|
FreePool(g_sector_flag);
|
||||||
UINT32 j = 0;
|
g_sector_flag_num = 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 (gLoadIsoEfi && gBlockData.IsoDriverImage)
|
||||||
if (EFI_ERROR(Status))
|
|
||||||
{
|
{
|
||||||
return Status;
|
gBS->UnloadImage(gBlockData.IsoDriverImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_file_replace_list && g_file_replace_list->magic == GRUB_FILE_REPLACE_MAGIC &&
|
gBS->DisconnectController(gBlockData.Handle, NULL, NULL);
|
||||||
g_file_replace_list->new_file_virtual_id < g_virt_chunk_num)
|
|
||||||
|
gBS->UninstallMultipleProtocolInterfaces(gBlockData.Handle,
|
||||||
|
&gEfiBlockIoProtocolGuid, &gBlockData.BlockIo,
|
||||||
|
&gEfiDevicePathProtocolGuid, gBlockData.Path,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
ventoy_delete_variable();
|
||||||
|
|
||||||
|
if (g_chain->os_param.vtoy_img_location_addr)
|
||||||
{
|
{
|
||||||
AsciiSPrint(TmpName, sizeof(TmpName), "%s", Name);
|
FreePool((VOID *)(UINTN)g_chain->os_param.vtoy_img_location_addr);
|
||||||
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;
|
FreePool(g_chain);
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
EFI_STATUS EFIAPI ventoy_wrapper_open_volume
|
STATIC EFI_STATUS ventoy_hook_start(VOID)
|
||||||
(
|
|
||||||
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
|
|
||||||
OUT EFI_FILE_PROTOCOL **Root
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
EFI_STATUS Status = EFI_SUCCESS;
|
/* don't add debug print in this function */
|
||||||
|
|
||||||
Status = g_original_open_volume(This, Root);
|
if (g_fix_windows_1st_cdrom_issue)
|
||||||
if (!EFI_ERROR(Status))
|
|
||||||
{
|
{
|
||||||
g_original_fopen = (*Root)->Open;
|
ventoy_hook_1st_cdrom_start();
|
||||||
g_original_fclose = (*Root)->Close;
|
|
||||||
(*Root)->Open = ventoy_wrapper_file_open;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Status;
|
/* let this the last */
|
||||||
|
if (g_hook_keyboard)
|
||||||
|
{
|
||||||
|
ventoy_hook_keyboard_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STATIC EFI_STATUS ventoy_hook_stop(VOID)
|
||||||
|
{
|
||||||
|
/* don't add debug print in this function */
|
||||||
|
|
||||||
|
if (g_fix_windows_1st_cdrom_issue)
|
||||||
|
{
|
||||||
|
ventoy_hook_1st_cdrom_stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* let this the last */
|
||||||
|
if (g_hook_keyboard)
|
||||||
|
{
|
||||||
|
ventoy_hook_keyboard_stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
|
EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
|
||||||
{
|
{
|
||||||
@@ -1174,16 +872,20 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
|
|||||||
if (gDebugPrint)
|
if (gDebugPrint)
|
||||||
{
|
{
|
||||||
gST->ConIn->Reset(gST->ConIn, FALSE);
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (g_file_replace_list && g_file_replace_list->magic == GRUB_FILE_REPLACE_MAGIC)
|
||||||
|
{
|
||||||
|
ventoy_wrapper_push_openvolume(pFile->OpenVolume);
|
||||||
|
pFile->OpenVolume = ventoy_wrapper_open_volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
ventoy_hook_start();
|
||||||
|
/* can't add debug print here */
|
||||||
|
//ventoy_wrapper_system();
|
||||||
Status = gBS->StartImage(Image, NULL, NULL);
|
Status = gBS->StartImage(Image, NULL, NULL);
|
||||||
|
ventoy_hook_stop();
|
||||||
|
|
||||||
if (EFI_ERROR(Status))
|
if (EFI_ERROR(Status))
|
||||||
{
|
{
|
||||||
debug("Failed to start image %r", Status);
|
debug("Failed to start image %r", Status);
|
||||||
@@ -1210,75 +912,6 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
|
|||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
EFI_STATUS EFIAPI ventoy_clean_env(VOID)
|
|
||||||
{
|
|
||||||
FreePool(g_sector_flag);
|
|
||||||
g_sector_flag_num = 0;
|
|
||||||
|
|
||||||
if (gLoadIsoEfi && gBlockData.IsoDriverImage)
|
|
||||||
{
|
|
||||||
gBS->UnloadImage(gBlockData.IsoDriverImage);
|
|
||||||
}
|
|
||||||
|
|
||||||
gBS->DisconnectController(gBlockData.Handle, NULL, NULL);
|
|
||||||
|
|
||||||
gBS->UninstallMultipleProtocolInterfaces(gBlockData.Handle,
|
|
||||||
&gEfiBlockIoProtocolGuid, &gBlockData.BlockIo,
|
|
||||||
&gEfiDevicePathProtocolGuid, gBlockData.Path,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
ventoy_delete_variable();
|
|
||||||
|
|
||||||
if (g_chain->os_param.vtoy_img_location_addr)
|
|
||||||
{
|
|
||||||
FreePool((VOID *)(UINTN)g_chain->os_param.vtoy_img_location_addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
EFI_STATUS EFIAPI ventoy_ramdisk_boot(IN EFI_HANDLE ImageHandle)
|
|
||||||
{
|
|
||||||
EFI_STATUS Status = EFI_SUCCESS;
|
|
||||||
EFI_RAM_DISK_PROTOCOL *RamDisk = NULL;
|
|
||||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath = NULL;
|
|
||||||
|
|
||||||
debug("RamDisk Boot ...");
|
|
||||||
|
|
||||||
Status = gBS->LocateProtocol(&gEfiRamDiskProtocolGuid, NULL, (VOID **)&RamDisk);
|
|
||||||
if (EFI_ERROR(Status))
|
|
||||||
{
|
|
||||||
debug("Failed to locate ramdisk protocol %r", Status);
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
debug("Locate RamDisk Protocol %r ...", Status);
|
|
||||||
|
|
||||||
Status = RamDisk->Register((UINTN)g_chain, (UINT64)g_iso_buf_size, &gEfiVirtualCdGuid, NULL, &DevicePath);
|
|
||||||
if (EFI_ERROR(Status))
|
|
||||||
{
|
|
||||||
debug("Failed to register ramdisk %r", Status);
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
debug("Register RamDisk %r ...", Status);
|
|
||||||
debug("RamDisk DevicePath:<%s> ...", ConvertDevicePathToText(DevicePath, FALSE, FALSE));
|
|
||||||
|
|
||||||
ventoy_debug_pause();
|
|
||||||
|
|
||||||
gBlockData.Path = DevicePath;
|
|
||||||
gBlockData.DevicePathCompareLen = GetDevicePathSize(DevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
EFI_STATUS EFIAPI VentoyEfiMain
|
EFI_STATUS EFIAPI VentoyEfiMain
|
||||||
(
|
(
|
||||||
IN EFI_HANDLE ImageHandle,
|
IN EFI_HANDLE ImageHandle,
|
||||||
@@ -1286,6 +919,7 @@ EFI_STATUS EFIAPI VentoyEfiMain
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status = EFI_SUCCESS;
|
EFI_STATUS Status = EFI_SUCCESS;
|
||||||
|
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *Protocol;
|
||||||
|
|
||||||
g_sector_flag_num = 512; /* initial value */
|
g_sector_flag_num = 512; /* initial value */
|
||||||
|
|
||||||
@@ -1295,6 +929,12 @@ EFI_STATUS EFIAPI VentoyEfiMain
|
|||||||
return EFI_OUT_OF_RESOURCES;
|
return EFI_OUT_OF_RESOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status = gBS->HandleProtocol(gST->ConsoleInHandle, &gEfiSimpleTextInputExProtocolGuid, (VOID **)&Protocol);
|
||||||
|
if (EFI_SUCCESS == Status)
|
||||||
|
{
|
||||||
|
g_con_simple_input_ex = Protocol;
|
||||||
|
}
|
||||||
|
|
||||||
gST->ConOut->ClearScreen(gST->ConOut);
|
gST->ConOut->ClearScreen(gST->ConOut);
|
||||||
ventoy_clear_input();
|
ventoy_clear_input();
|
||||||
|
|
||||||
@@ -1309,18 +949,12 @@ EFI_STATUS EFIAPI VentoyEfiMain
|
|||||||
|
|
||||||
ventoy_install_blockio(ImageHandle, g_iso_buf_size);
|
ventoy_install_blockio(ImageHandle, g_iso_buf_size);
|
||||||
Status = ventoy_boot(ImageHandle);
|
Status = ventoy_boot(ImageHandle);
|
||||||
if (EFI_NOT_FOUND == Status)
|
|
||||||
{
|
ventoy_delete_ramdisk_param();
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
ventoy_del_ramdisk_param();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ventoy_set_variable();
|
ventoy_save_variable();
|
||||||
ventoy_find_iso_disk(ImageHandle);
|
ventoy_find_iso_disk(ImageHandle);
|
||||||
|
|
||||||
if (gLoadIsoEfi)
|
if (gLoadIsoEfi)
|
||||||
@@ -1336,32 +970,20 @@ EFI_STATUS EFIAPI VentoyEfiMain
|
|||||||
ventoy_debug_pause();
|
ventoy_debug_pause();
|
||||||
|
|
||||||
Status = ventoy_boot(ImageHandle);
|
Status = ventoy_boot(ImageHandle);
|
||||||
if (EFI_NOT_FOUND == Status)
|
|
||||||
{
|
|
||||||
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();
|
ventoy_clean_env();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(30);
|
||||||
|
}
|
||||||
|
|
||||||
ventoy_clear_input();
|
ventoy_clear_input();
|
||||||
gST->ConOut->ClearScreen(gST->ConOut);
|
gST->ConOut->ClearScreen(gST->ConOut);
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -25,6 +25,15 @@
|
|||||||
|
|
||||||
#define VENTOY_GUID { 0x77772020, 0x2e77, 0x6576, { 0x6e, 0x74, 0x6f, 0x79, 0x2e, 0x6e, 0x65, 0x74 }}
|
#define VENTOY_GUID { 0x77772020, 0x2e77, 0x6576, { 0x6e, 0x74, 0x6f, 0x79, 0x2e, 0x6e, 0x65, 0x74 }}
|
||||||
|
|
||||||
|
typedef enum ventoy_chain_type
|
||||||
|
{
|
||||||
|
ventoy_chain_linux = 0, /* 0: linux */
|
||||||
|
ventoy_chain_windows, /* 1: windows */
|
||||||
|
ventoy_chain_wim, /* 2: wim */
|
||||||
|
|
||||||
|
ventoy_chain_max
|
||||||
|
}ventoy_chain_type;
|
||||||
|
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
|
||||||
typedef struct ventoy_guid
|
typedef struct ventoy_guid
|
||||||
@@ -159,6 +168,8 @@ typedef struct ventoy_virt_chunk
|
|||||||
#define VTOY_BLOCK_DEVICE_PATH_GUID \
|
#define VTOY_BLOCK_DEVICE_PATH_GUID \
|
||||||
{ 0x37b87ac6, 0xc180, 0x4583, { 0xa7, 0x05, 0x41, 0x4d, 0xa8, 0xf7, 0x7e, 0xd2 }}
|
{ 0x37b87ac6, 0xc180, 0x4583, { 0xa7, 0x05, 0x41, 0x4d, 0xa8, 0xf7, 0x7e, 0xd2 }}
|
||||||
|
|
||||||
|
#define ISO9660_EFI_DRIVER_PATH L"\\ventoy\\iso9660_x64.efi"
|
||||||
|
|
||||||
#define VTOY_BLOCK_DEVICE_PATH_NAME L"ventoy"
|
#define VTOY_BLOCK_DEVICE_PATH_NAME L"ventoy"
|
||||||
|
|
||||||
#if defined (MDE_CPU_IA32)
|
#if defined (MDE_CPU_IA32)
|
||||||
@@ -202,7 +213,6 @@ typedef struct vtoy_block_data
|
|||||||
EFI_HANDLE IsoDriverImage;
|
EFI_HANDLE IsoDriverImage;
|
||||||
}vtoy_block_data;
|
}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 debug(expr, ...) if (gDebugPrint) VtoyDebug("[VTOY] "expr"\r\n", ##__VA_ARGS__)
|
||||||
#define trace(expr, ...) VtoyDebug("[VTOY] "expr"\r\n", ##__VA_ARGS__)
|
#define trace(expr, ...) VtoyDebug("[VTOY] "expr"\r\n", ##__VA_ARGS__)
|
||||||
@@ -218,6 +228,7 @@ if (gDebugPrint) \
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef const char * (*grub_env_get_pf)(const char *name);
|
typedef const char * (*grub_env_get_pf)(const char *name);
|
||||||
|
typedef int (*grub_env_printf_pf)(const char *fmt, ...);
|
||||||
|
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
|
||||||
@@ -244,8 +255,8 @@ typedef struct ventoy_grub_param_file_replace
|
|||||||
typedef struct ventoy_grub_param
|
typedef struct ventoy_grub_param
|
||||||
{
|
{
|
||||||
grub_env_get_pf grub_env_get;
|
grub_env_get_pf grub_env_get;
|
||||||
|
|
||||||
ventoy_grub_param_file_replace file_replace;
|
ventoy_grub_param_file_replace file_replace;
|
||||||
|
grub_env_printf_pf grub_env_printf;
|
||||||
}ventoy_grub_param;
|
}ventoy_grub_param;
|
||||||
|
|
||||||
typedef struct ventoy_ram_disk
|
typedef struct ventoy_ram_disk
|
||||||
@@ -254,6 +265,14 @@ typedef struct ventoy_ram_disk
|
|||||||
UINT64 DiskSize;
|
UINT64 DiskSize;
|
||||||
}ventoy_ram_disk;
|
}ventoy_ram_disk;
|
||||||
|
|
||||||
|
typedef struct ventoy_iso9660_override
|
||||||
|
{
|
||||||
|
UINT32 first_sector;
|
||||||
|
UINT32 first_sector_be;
|
||||||
|
UINT32 size;
|
||||||
|
UINT32 size_be;
|
||||||
|
}ventoy_iso9660_override;
|
||||||
|
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
|
||||||
|
|
||||||
@@ -273,6 +292,18 @@ typedef struct ventoy_system_wrapper
|
|||||||
|
|
||||||
EFI_OPEN_PROTOCOL NewOpenProtocol;
|
EFI_OPEN_PROTOCOL NewOpenProtocol;
|
||||||
EFI_OPEN_PROTOCOL OriOpenProtocol;
|
EFI_OPEN_PROTOCOL OriOpenProtocol;
|
||||||
|
|
||||||
|
EFI_LOCATE_HANDLE_BUFFER NewLocateHandleBuffer;
|
||||||
|
EFI_LOCATE_HANDLE_BUFFER OriLocateHandleBuffer;
|
||||||
|
|
||||||
|
EFI_PROTOCOLS_PER_HANDLE NewProtocolsPerHandle;
|
||||||
|
EFI_PROTOCOLS_PER_HANDLE OriProtocolsPerHandle;
|
||||||
|
|
||||||
|
EFI_LOCATE_HANDLE NewLocateHandle;
|
||||||
|
EFI_LOCATE_HANDLE OriLocateHandle;
|
||||||
|
|
||||||
|
EFI_LOCATE_DEVICE_PATH NewLocateDevicePath;
|
||||||
|
EFI_LOCATE_DEVICE_PATH OriLocateDevicePath;
|
||||||
} ventoy_system_wrapper;
|
} ventoy_system_wrapper;
|
||||||
|
|
||||||
#define ventoy_wrapper(bs, wrapper, func, newfunc) \
|
#define ventoy_wrapper(bs, wrapper, func, newfunc) \
|
||||||
@@ -282,11 +313,9 @@ typedef struct ventoy_system_wrapper
|
|||||||
bs->func = wrapper.New##func;\
|
bs->func = wrapper.New##func;\
|
||||||
}
|
}
|
||||||
|
|
||||||
extern ventoy_efi_file_replace g_efi_file_replace;
|
|
||||||
extern BOOLEAN gDebugPrint;
|
extern BOOLEAN gDebugPrint;
|
||||||
VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...);
|
VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...);
|
||||||
EFI_STATUS EFIAPI ventoy_wrapper_system(VOID);
|
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
|
EFI_STATUS EFIAPI ventoy_block_io_read
|
||||||
(
|
(
|
||||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||||
@@ -296,5 +325,37 @@ EFI_STATUS EFIAPI ventoy_block_io_read
|
|||||||
OUT VOID *Buffer
|
OUT VOID *Buffer
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
extern ventoy_chain_head *g_chain;
|
||||||
|
extern ventoy_img_chunk *g_chunk;
|
||||||
|
extern UINT32 g_img_chunk_num;
|
||||||
|
extern ventoy_override_chunk *g_override_chunk;
|
||||||
|
extern UINT32 g_override_chunk_num;
|
||||||
|
extern ventoy_virt_chunk *g_virt_chunk;
|
||||||
|
extern UINT32 g_virt_chunk_num;
|
||||||
|
extern vtoy_block_data gBlockData;
|
||||||
|
extern ventoy_efi_file_replace g_efi_file_replace;
|
||||||
|
extern ventoy_sector_flag *g_sector_flag;
|
||||||
|
extern UINT32 g_sector_flag_num;
|
||||||
|
extern BOOLEAN gMemdiskMode;
|
||||||
|
extern UINTN g_iso_buf_size;
|
||||||
|
extern ventoy_grub_param_file_replace *g_file_replace_list;
|
||||||
|
extern BOOLEAN g_fixup_iso9660_secover_enable;
|
||||||
|
extern EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *g_con_simple_input_ex;
|
||||||
|
extern BOOLEAN g_fix_windows_1st_cdrom_issue;
|
||||||
|
|
||||||
|
EFI_STATUS EFIAPI ventoy_wrapper_open_volume
|
||||||
|
(
|
||||||
|
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
|
||||||
|
OUT EFI_FILE_PROTOCOL **Root
|
||||||
|
);
|
||||||
|
EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 ImgSize);
|
||||||
|
EFI_STATUS EFIAPI ventoy_wrapper_push_openvolume(IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME OpenVolume);
|
||||||
|
EFI_STATUS ventoy_hook_keyboard_start(VOID);
|
||||||
|
EFI_STATUS ventoy_hook_keyboard_stop(VOID);
|
||||||
|
BOOLEAN ventoy_is_cdrom_dp_exist(VOID);
|
||||||
|
EFI_STATUS ventoy_hook_1st_cdrom_start(VOID);
|
||||||
|
EFI_STATUS ventoy_hook_1st_cdrom_stop(VOID);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
Ventoy.h
|
Ventoy.h
|
||||||
Ventoy.c
|
Ventoy.c
|
||||||
VentoyDebug.c
|
VentoyDebug.c
|
||||||
|
VentoyProtocol.c
|
||||||
|
|
||||||
[Packages]
|
[Packages]
|
||||||
MdePkg/MdePkg.dec
|
MdePkg/MdePkg.dec
|
||||||
|
@@ -36,6 +36,10 @@
|
|||||||
#include <Protocol/SimpleFileSystem.h>
|
#include <Protocol/SimpleFileSystem.h>
|
||||||
#include <Ventoy.h>
|
#include <Ventoy.h>
|
||||||
|
|
||||||
|
#define PROCOTOL_SLEEP_MSECONDS 0
|
||||||
|
|
||||||
|
#define debug_sleep() if (PROCOTOL_SLEEP_MSECONDS) gBS->Stall(1000 * PROCOTOL_SLEEP_MSECONDS)
|
||||||
|
|
||||||
STATIC ventoy_system_wrapper g_system_wrapper;
|
STATIC ventoy_system_wrapper g_system_wrapper;
|
||||||
|
|
||||||
static struct well_known_guid g_efi_well_known_guids[] =
|
static struct well_known_guid g_efi_well_known_guids[] =
|
||||||
@@ -84,183 +88,6 @@ static const char * ventoy_get_guid_name(EFI_GUID *guid)
|
|||||||
return gEfiGuidName;
|
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
|
STATIC EFI_STATUS EFIAPI ventoy_handle_protocol
|
||||||
(
|
(
|
||||||
IN EFI_HANDLE Handle,
|
IN EFI_HANDLE Handle,
|
||||||
@@ -270,7 +97,7 @@ STATIC EFI_STATUS EFIAPI ventoy_handle_protocol
|
|||||||
{
|
{
|
||||||
EFI_STATUS Status = EFI_SUCCESS;
|
EFI_STATUS Status = EFI_SUCCESS;
|
||||||
|
|
||||||
debug("ventoy_handle_protocol:%a", ventoy_get_guid_name(Protocol));
|
debug("ventoy_handle_protocol:%a", ventoy_get_guid_name(Protocol)); debug_sleep();
|
||||||
Status = g_system_wrapper.OriHandleProtocol(Handle, Protocol, Interface);
|
Status = g_system_wrapper.OriHandleProtocol(Handle, Protocol, Interface);
|
||||||
|
|
||||||
if (CompareGuid(Protocol, &gEfiSimpleFileSystemProtocolGuid))
|
if (CompareGuid(Protocol, &gEfiSimpleFileSystemProtocolGuid))
|
||||||
@@ -280,7 +107,7 @@ STATIC EFI_STATUS EFIAPI ventoy_handle_protocol
|
|||||||
|
|
||||||
pFile->OpenVolume(pFile, &FileProtocol);
|
pFile->OpenVolume(pFile, &FileProtocol);
|
||||||
|
|
||||||
debug("Handle FS Protocol: %p OpenVolume:%p, FileProtocol:%p, Open:%p",
|
trace("Handle FS Protocol: %p OpenVolume:%p, FileProtocol:%p, Open:%p",
|
||||||
pFile, pFile->OpenVolume, FileProtocol, FileProtocol->Open);
|
pFile, pFile->OpenVolume, FileProtocol, FileProtocol->Open);
|
||||||
|
|
||||||
sleep(3);
|
sleep(3);
|
||||||
@@ -299,7 +126,7 @@ STATIC EFI_STATUS EFIAPI ventoy_open_protocol
|
|||||||
IN UINT32 Attributes
|
IN UINT32 Attributes
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
debug("ventoy_open_protocol:%a", ventoy_get_guid_name(Protocol));
|
debug("ventoy_open_protocol:<%p> %a", Handle, ventoy_get_guid_name(Protocol)); debug_sleep();
|
||||||
return g_system_wrapper.OriOpenProtocol(Handle, Protocol, Interface, AgentHandle, ControllerHandle, Attributes);
|
return g_system_wrapper.OriOpenProtocol(Handle, Protocol, Interface, AgentHandle, ControllerHandle, Attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,15 +137,91 @@ STATIC EFI_STATUS EFIAPI ventoy_locate_protocol
|
|||||||
OUT VOID **Interface
|
OUT VOID **Interface
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
debug("ventoy_locate_protocol:%a", ventoy_get_guid_name(Protocol));
|
debug("ventoy_locate_protocol:%a", ventoy_get_guid_name(Protocol)); debug_sleep();
|
||||||
return g_system_wrapper.OriLocateProtocol(Protocol, Registration, Interface);
|
return g_system_wrapper.OriLocateProtocol(Protocol, Registration, Interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STATIC EFI_STATUS EFIAPI ventoy_locate_handle_buffer
|
||||||
|
(
|
||||||
|
IN EFI_LOCATE_SEARCH_TYPE SearchType,
|
||||||
|
IN EFI_GUID *Protocol, OPTIONAL
|
||||||
|
IN VOID *SearchKey, OPTIONAL
|
||||||
|
IN OUT UINTN *NoHandles,
|
||||||
|
OUT EFI_HANDLE **Buffer
|
||||||
|
)
|
||||||
|
{
|
||||||
|
debug("ventoy_locate_handle_buffer:%a", ventoy_get_guid_name(Protocol)); debug_sleep();
|
||||||
|
return g_system_wrapper.OriLocateHandleBuffer(SearchType, Protocol, SearchKey, NoHandles, Buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC EFI_STATUS EFIAPI ventoy_protocol_per_handle
|
||||||
|
(
|
||||||
|
IN EFI_HANDLE Handle,
|
||||||
|
OUT EFI_GUID ***ProtocolBuffer,
|
||||||
|
OUT UINTN *ProtocolBufferCount
|
||||||
|
)
|
||||||
|
{
|
||||||
|
debug("ventoy_protocol_per_handle:%p", Handle); debug_sleep();
|
||||||
|
return g_system_wrapper.OriProtocolsPerHandle(Handle, ProtocolBuffer, ProtocolBufferCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS EFIAPI ventoy_locate_handle
|
||||||
|
(
|
||||||
|
IN EFI_LOCATE_SEARCH_TYPE SearchType,
|
||||||
|
IN EFI_GUID *Protocol, OPTIONAL
|
||||||
|
IN VOID *SearchKey, OPTIONAL
|
||||||
|
IN OUT UINTN *BufferSize,
|
||||||
|
OUT EFI_HANDLE *Buffer
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UINTN i;
|
||||||
|
EFI_HANDLE Handle;
|
||||||
|
EFI_STATUS Status = EFI_SUCCESS;
|
||||||
|
|
||||||
|
debug("ventoy_locate_handle: %d %a %p", SearchType, ventoy_get_guid_name(Protocol), SearchKey);
|
||||||
|
Status = g_system_wrapper.OriLocateHandle(SearchType, Protocol, SearchKey, BufferSize, Buffer);
|
||||||
|
debug("ventoy_locate_handle: %r Handle Count:%u", Status, *BufferSize/sizeof(EFI_HANDLE));
|
||||||
|
|
||||||
|
if (EFI_SUCCESS == Status)
|
||||||
|
{
|
||||||
|
for (i = 0; i < *BufferSize / sizeof(EFI_HANDLE); i++)
|
||||||
|
{
|
||||||
|
if (Buffer[i] == gBlockData.Handle)
|
||||||
|
{
|
||||||
|
Handle = Buffer[0];
|
||||||
|
Buffer[0] = Buffer[i];
|
||||||
|
Buffer[i] = Handle;
|
||||||
|
debug("####### Handle at %u", i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debug_sleep();
|
||||||
|
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC EFI_STATUS EFIAPI ventoy_locate_device_path
|
||||||
|
(
|
||||||
|
IN EFI_GUID *Protocol,
|
||||||
|
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
|
||||||
|
OUT EFI_HANDLE *Device
|
||||||
|
)
|
||||||
|
{
|
||||||
|
debug("ventoy_locate_device_path:%a", ventoy_get_guid_name(Protocol)); debug_sleep();
|
||||||
|
return g_system_wrapper.OriLocateDevicePath(Protocol, DevicePath, Device);
|
||||||
|
}
|
||||||
|
|
||||||
EFI_STATUS EFIAPI ventoy_wrapper_system(VOID)
|
EFI_STATUS EFIAPI ventoy_wrapper_system(VOID)
|
||||||
{
|
{
|
||||||
ventoy_wrapper(gBS, g_system_wrapper, LocateProtocol, ventoy_locate_protocol);
|
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, HandleProtocol, ventoy_handle_protocol);
|
||||||
ventoy_wrapper(gBS, g_system_wrapper, OpenProtocol, ventoy_open_protocol);
|
ventoy_wrapper(gBS, g_system_wrapper, OpenProtocol, ventoy_open_protocol);
|
||||||
|
ventoy_wrapper(gBS, g_system_wrapper, LocateHandleBuffer, ventoy_locate_handle_buffer);
|
||||||
|
ventoy_wrapper(gBS, g_system_wrapper, ProtocolsPerHandle, ventoy_protocol_per_handle);
|
||||||
|
ventoy_wrapper(gBS, g_system_wrapper, LocateHandle, ventoy_locate_handle);
|
||||||
|
ventoy_wrapper(gBS, g_system_wrapper, LocateDevicePath, ventoy_locate_device_path);
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,179 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Memhole.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 <VtoyUtil.h>
|
||||||
|
|
||||||
|
STATIC BOOLEAN IsMemContiguous
|
||||||
|
(
|
||||||
|
IN CONST EFI_MEMORY_DESCRIPTOR *Prev,
|
||||||
|
IN CONST EFI_MEMORY_DESCRIPTOR *Curr,
|
||||||
|
IN CONST EFI_MEMORY_DESCRIPTOR *Next
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UINTN Addr1 = 0;
|
||||||
|
UINTN Addr2 = 0;
|
||||||
|
|
||||||
|
if (Prev == NULL || Curr == NULL || Next == NULL)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Prev->Type == EfiBootServicesData &&
|
||||||
|
Curr->Type == EfiConventionalMemory &&
|
||||||
|
Next->Type == EfiBootServicesData)
|
||||||
|
{
|
||||||
|
Addr1 = Prev->PhysicalStart + MultU64x64(SIZE_4KB, Prev->NumberOfPages);
|
||||||
|
Addr2 = Curr->PhysicalStart + MultU64x64(SIZE_4KB, Curr->NumberOfPages);
|
||||||
|
|
||||||
|
if (Addr1 == Curr->PhysicalStart && Addr2 == Next->PhysicalStart)
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC EFI_MEMORY_DESCRIPTOR* GetMemDesc
|
||||||
|
(
|
||||||
|
OUT UINTN *pSize,
|
||||||
|
OUT UINTN *pItemSize,
|
||||||
|
OUT UINTN *pDescCount
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UINTN Size = 0;
|
||||||
|
UINTN MapKey = 0;
|
||||||
|
UINTN ItemSize = 0;
|
||||||
|
UINTN DescCount = 0;
|
||||||
|
UINT32 Version = 0;
|
||||||
|
EFI_STATUS Status = EFI_SUCCESS;
|
||||||
|
EFI_MEMORY_DESCRIPTOR *pDesc = NULL;
|
||||||
|
EFI_MEMORY_DESCRIPTOR *Curr = NULL;
|
||||||
|
|
||||||
|
Status = gBS->GetMemoryMap(&Size, pDesc, &MapKey, &ItemSize, &Version);
|
||||||
|
if (EFI_BUFFER_TOO_SMALL != Status)
|
||||||
|
{
|
||||||
|
debug("GetMemoryMap: %r", Status);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Size += SIZE_1KB;
|
||||||
|
pDesc = AllocatePool(Size);
|
||||||
|
if (!pDesc)
|
||||||
|
{
|
||||||
|
debug("AllocatePool: %lu failed", Size);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZeroMem(pDesc, Size);
|
||||||
|
|
||||||
|
Status = gBS->GetMemoryMap(&Size, pDesc, &MapKey, &ItemSize, &Version);
|
||||||
|
if (EFI_ERROR(Status))
|
||||||
|
{
|
||||||
|
debug("GetMemoryMap: %r", Status);
|
||||||
|
FreePool(pDesc);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Curr = pDesc;
|
||||||
|
while (Curr && Curr < (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)pDesc + Size))
|
||||||
|
{
|
||||||
|
DescCount++;
|
||||||
|
Curr = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Curr + ItemSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
*pSize = Size;
|
||||||
|
*pItemSize = ItemSize;
|
||||||
|
*pDescCount = DescCount;
|
||||||
|
|
||||||
|
debug("GetMemoryMap: ItemSize:%lu Count:%lu", ItemSize, DescCount);
|
||||||
|
|
||||||
|
return pDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS FixWindowsMemhole(IN EFI_HANDLE ImageHandle, IN CONST CHAR16 *CmdLine)
|
||||||
|
{
|
||||||
|
UINTN Size = 0;
|
||||||
|
UINTN ItemSize = 0;
|
||||||
|
UINTN DescCount = 0;
|
||||||
|
UINTN TotalMem = 0;
|
||||||
|
EFI_STATUS Status = EFI_SUCCESS;
|
||||||
|
EFI_PHYSICAL_ADDRESS AllocAddr = 0;
|
||||||
|
EFI_MEMORY_DESCRIPTOR *pDescs = NULL;
|
||||||
|
EFI_MEMORY_DESCRIPTOR *Prev = NULL;
|
||||||
|
EFI_MEMORY_DESCRIPTOR *Next = NULL;
|
||||||
|
EFI_MEMORY_DESCRIPTOR *Curr = NULL;
|
||||||
|
|
||||||
|
(VOID)ImageHandle;
|
||||||
|
(VOID)CmdLine;
|
||||||
|
|
||||||
|
pDescs = GetMemDesc(&Size, &ItemSize, &DescCount);
|
||||||
|
if (!pDescs)
|
||||||
|
{
|
||||||
|
return EFI_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DescCount < 500)
|
||||||
|
{
|
||||||
|
FreePool(pDescs);
|
||||||
|
Printf("There is no need to fixup (%lu)\n", DescCount);
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
Curr = pDescs;
|
||||||
|
while ((UINT8 *)Curr < (UINT8 *)pDescs + Size)
|
||||||
|
{
|
||||||
|
Next = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Curr + ItemSize);
|
||||||
|
|
||||||
|
if (IsMemContiguous(Prev, Curr, Next))
|
||||||
|
{
|
||||||
|
AllocAddr = Curr->PhysicalStart;
|
||||||
|
Status = gBS->AllocatePages(AllocateAddress, EfiBootServicesData, Curr->NumberOfPages, &AllocAddr);
|
||||||
|
if (EFI_SUCCESS == Status)
|
||||||
|
{
|
||||||
|
TotalMem += MultU64x64(SIZE_4KB, Curr->NumberOfPages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Prev = Curr;
|
||||||
|
Curr = Next;
|
||||||
|
}
|
||||||
|
|
||||||
|
Printf("Fixup Windows mmap issue OK (%lu)\n", TotalMem);
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
@@ -0,0 +1,135 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* VtoyUtil.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 <VtoyUtil.h>
|
||||||
|
|
||||||
|
BOOLEAN gVtoyDebugPrint = FALSE;
|
||||||
|
STATIC CONST CHAR16 *gCurFeature= NULL;
|
||||||
|
STATIC CHAR16 *gCmdLine = NULL;
|
||||||
|
STATIC grub_env_printf_pf g_env_printf = NULL;
|
||||||
|
|
||||||
|
STATIC VtoyUtilFeature gFeatureList[] =
|
||||||
|
{
|
||||||
|
{ L"fix_windows_mmap", FixWindowsMemhole },
|
||||||
|
};
|
||||||
|
|
||||||
|
VOID EFIAPI VtoyUtilDebug(IN CONST CHAR8 *Format, ...)
|
||||||
|
{
|
||||||
|
VA_LIST Marker;
|
||||||
|
CHAR8 Buffer[512];
|
||||||
|
|
||||||
|
VA_START (Marker, Format);
|
||||||
|
AsciiVSPrint(Buffer, sizeof(Buffer), Format, Marker);
|
||||||
|
VA_END (Marker);
|
||||||
|
|
||||||
|
if (g_env_printf)
|
||||||
|
{
|
||||||
|
g_env_printf("%s", Buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC EFI_STATUS ParseCmdline(IN EFI_HANDLE ImageHandle)
|
||||||
|
{
|
||||||
|
CHAR16 *pPos = NULL;
|
||||||
|
CHAR16 *pCmdLine = NULL;
|
||||||
|
EFI_STATUS Status = EFI_SUCCESS;
|
||||||
|
ventoy_grub_param *pGrubParam = NULL;
|
||||||
|
EFI_LOADED_IMAGE_PROTOCOL *pImageInfo = NULL;
|
||||||
|
|
||||||
|
Status = gBS->HandleProtocol(ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&pImageInfo);
|
||||||
|
if (EFI_ERROR(Status))
|
||||||
|
{
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
pCmdLine = (CHAR16 *)AllocatePool(pImageInfo->LoadOptionsSize + 4);
|
||||||
|
SetMem(pCmdLine, pImageInfo->LoadOptionsSize + 4, 0);
|
||||||
|
CopyMem(pCmdLine, pImageInfo->LoadOptions, pImageInfo->LoadOptionsSize);
|
||||||
|
|
||||||
|
if (StrStr(pCmdLine, L"debug"))
|
||||||
|
{
|
||||||
|
gVtoyDebugPrint = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
pPos = StrStr(pCmdLine, L"env_param=");
|
||||||
|
if (!pPos)
|
||||||
|
{
|
||||||
|
return EFI_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
pGrubParam = (ventoy_grub_param *)StrHexToUintn(pPos + StrLen(L"env_param="));
|
||||||
|
g_env_printf = pGrubParam->grub_env_printf;
|
||||||
|
|
||||||
|
pPos = StrStr(pCmdLine, L"feature=");
|
||||||
|
if (!pPos)
|
||||||
|
{
|
||||||
|
return EFI_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
gCurFeature = pPos + StrLen(L"feature=");
|
||||||
|
|
||||||
|
gCmdLine = pCmdLine;
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
EFI_STATUS EFIAPI VtoyUtilEfiMain
|
||||||
|
(
|
||||||
|
IN EFI_HANDLE ImageHandle,
|
||||||
|
IN EFI_SYSTEM_TABLE *SystemTable
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UINTN i;
|
||||||
|
UINTN Len;
|
||||||
|
|
||||||
|
ParseCmdline(ImageHandle);
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_SIZE(gFeatureList); i++)
|
||||||
|
{
|
||||||
|
Len = StrLen(gFeatureList[i].Cmd);
|
||||||
|
if (StrnCmp(gFeatureList[i].Cmd, gCurFeature, Len) == 0)
|
||||||
|
{
|
||||||
|
debug("Find main proc <%s>", gFeatureList[i].Cmd);
|
||||||
|
gFeatureList[i].MainProc(ImageHandle, gCurFeature + Len);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FreePool(gCmdLine);
|
||||||
|
gCmdLine = NULL;
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
@@ -0,0 +1,61 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* VtoyUtil.h
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __VTOYUTIL_H__
|
||||||
|
#define __VTOYUTIL_H__
|
||||||
|
|
||||||
|
#pragma pack(1)
|
||||||
|
|
||||||
|
typedef EFI_STATUS (*VTOY_UTIL_PROC_PF)(IN EFI_HANDLE ImageHandle, IN CONST CHAR16 *CmdLine);
|
||||||
|
typedef const char * (*grub_env_get_pf)(const char *name);
|
||||||
|
typedef int (*grub_env_printf_pf)(const char *fmt, ...);
|
||||||
|
|
||||||
|
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;
|
||||||
|
grub_env_printf_pf grub_env_printf;
|
||||||
|
}ventoy_grub_param;
|
||||||
|
#pragma pack()
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct VtoyUtilFeature
|
||||||
|
{
|
||||||
|
CONST CHAR16 *Cmd;
|
||||||
|
VTOY_UTIL_PROC_PF MainProc;
|
||||||
|
}VtoyUtilFeature;
|
||||||
|
|
||||||
|
extern BOOLEAN gVtoyDebugPrint;
|
||||||
|
VOID EFIAPI VtoyUtilDebug(IN CONST CHAR8 *Format, ...);
|
||||||
|
#define debug(expr, ...) if (gVtoyDebugPrint) VtoyUtilDebug("[VTOY] "expr"\n", ##__VA_ARGS__)
|
||||||
|
#define Printf VtoyUtilDebug
|
||||||
|
|
||||||
|
EFI_STATUS FixWindowsMemhole(IN EFI_HANDLE ImageHandle, IN CONST CHAR16 *CmdLine);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@@ -0,0 +1,80 @@
|
|||||||
|
#************************************************************************************
|
||||||
|
# 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/>.
|
||||||
|
#
|
||||||
|
#************************************************************************************
|
||||||
|
|
||||||
|
[Defines]
|
||||||
|
INF_VERSION = 0x00010005
|
||||||
|
BASE_NAME = VtoyUtil
|
||||||
|
FILE_GUID = a43466a0-68c6-469d-ba4b-678bbe90bc47
|
||||||
|
MODULE_TYPE = UEFI_APPLICATION
|
||||||
|
VERSION_STRING = 1.0
|
||||||
|
ENTRY_POINT = VtoyUtilEfiMain
|
||||||
|
|
||||||
|
|
||||||
|
[Sources]
|
||||||
|
VtoyUtil.h
|
||||||
|
VtoyUtil.c
|
||||||
|
Memhole.c
|
||||||
|
|
||||||
|
[Packages]
|
||||||
|
MdePkg/MdePkg.dec
|
||||||
|
MdeModulePkg/MdeModulePkg.dec
|
||||||
|
ShellPkg/ShellPkg.dec
|
||||||
|
|
||||||
|
[LibraryClasses]
|
||||||
|
UefiApplicationEntryPoint
|
||||||
|
UefiLib
|
||||||
|
DebugLib
|
||||||
|
|
||||||
|
[Guids]
|
||||||
|
gShellVariableGuid
|
||||||
|
gEfiVirtualCdGuid
|
||||||
|
gEfiFileInfoGuid
|
||||||
|
|
||||||
|
[Protocols]
|
||||||
|
gEfiLoadedImageProtocolGuid
|
||||||
|
gEfiBlockIoProtocolGuid
|
||||||
|
gEfiDevicePathProtocolGuid
|
||||||
|
gEfiSimpleFileSystemProtocolGuid
|
||||||
|
gEfiRamDiskProtocolGuid
|
||||||
|
gEfiAbsolutePointerProtocolGuid
|
||||||
|
gEfiAcpiTableProtocolGuid
|
||||||
|
gEfiBlockIo2ProtocolGuid
|
||||||
|
gEfiBusSpecificDriverOverrideProtocolGuid
|
||||||
|
gEfiComponentNameProtocolGuid
|
||||||
|
gEfiComponentName2ProtocolGuid
|
||||||
|
gEfiDriverBindingProtocolGuid
|
||||||
|
gEfiDiskIoProtocolGuid
|
||||||
|
gEfiDiskIo2ProtocolGuid
|
||||||
|
gEfiGraphicsOutputProtocolGuid
|
||||||
|
gEfiHiiConfigAccessProtocolGuid
|
||||||
|
gEfiHiiFontProtocolGuid
|
||||||
|
gEfiLoadFileProtocolGuid
|
||||||
|
gEfiLoadFile2ProtocolGuid
|
||||||
|
gEfiLoadedImageProtocolGuid
|
||||||
|
gEfiLoadedImageDevicePathProtocolGuid
|
||||||
|
gEfiPciIoProtocolGuid
|
||||||
|
gEfiSerialIoProtocolGuid
|
||||||
|
gEfiSimpleTextInProtocolGuid
|
||||||
|
gEfiSimpleTextInputExProtocolGuid
|
||||||
|
gEfiSimpleTextOutProtocolGuid
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@@ -204,6 +204,7 @@
|
|||||||
|
|
||||||
[Components]
|
[Components]
|
||||||
MdeModulePkg/Application/Ventoy/Ventoy.inf
|
MdeModulePkg/Application/Ventoy/Ventoy.inf
|
||||||
|
MdeModulePkg/Application/VtoyUtil/VtoyUtil.inf
|
||||||
MdeModulePkg/Application/HelloWorld/HelloWorld.inf
|
MdeModulePkg/Application/HelloWorld/HelloWorld.inf
|
||||||
MdeModulePkg/Application/DumpDynPcd/DumpDynPcd.inf
|
MdeModulePkg/Application/DumpDynPcd/DumpDynPcd.inf
|
||||||
MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.inf
|
MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.inf
|
||||||
|
@@ -1578,10 +1578,12 @@ module = {
|
|||||||
name = ventoy;
|
name = ventoy;
|
||||||
common = ventoy/ventoy.c;
|
common = ventoy/ventoy.c;
|
||||||
common = ventoy/ventoy_linux.c;
|
common = ventoy/ventoy_linux.c;
|
||||||
|
common = ventoy/ventoy_unix.c;
|
||||||
common = ventoy/ventoy_windows.c;
|
common = ventoy/ventoy_windows.c;
|
||||||
common = ventoy/ventoy_plugin.c;
|
common = ventoy/ventoy_plugin.c;
|
||||||
common = ventoy/ventoy_json.c;
|
common = ventoy/ventoy_json.c;
|
||||||
common = ventoy/lzx.c;
|
common = ventoy/lzx.c;
|
||||||
|
common = ventoy/xpress.c;
|
||||||
common = ventoy/huffman.c;
|
common = ventoy/huffman.c;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
491
GRUB2/MOD_SRC/grub-2.04/grub-core/commands/test.c
Normal file
@@ -0,0 +1,491 @@
|
|||||||
|
/* test.c -- The test command.. */
|
||||||
|
/*
|
||||||
|
* GRUB -- GRand Unified Bootloader
|
||||||
|
* Copyright (C) 2005,2007,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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <grub/dl.h>
|
||||||
|
#include <grub/misc.h>
|
||||||
|
#include <grub/mm.h>
|
||||||
|
#include <grub/env.h>
|
||||||
|
#include <grub/fs.h>
|
||||||
|
#include <grub/device.h>
|
||||||
|
#include <grub/file.h>
|
||||||
|
#include <grub/command.h>
|
||||||
|
#include <grub/i18n.h>
|
||||||
|
|
||||||
|
GRUB_MOD_LICENSE ("GPLv3+");
|
||||||
|
|
||||||
|
static int g_test_case_insensitive = 0;
|
||||||
|
|
||||||
|
/* A simple implementation for signed numbers. */
|
||||||
|
static int
|
||||||
|
grub_strtosl (char *arg, char **end, int base)
|
||||||
|
{
|
||||||
|
if (arg[0] == '-')
|
||||||
|
return -grub_strtoul (arg + 1, end, base);
|
||||||
|
return grub_strtoul (arg, end, base);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Context for test_parse. */
|
||||||
|
struct test_parse_ctx
|
||||||
|
{
|
||||||
|
int invert;
|
||||||
|
int or, and;
|
||||||
|
int file_exists;
|
||||||
|
struct grub_dirhook_info file_info;
|
||||||
|
char *filename;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Take care of discarding and inverting. */
|
||||||
|
static void
|
||||||
|
update_val (int val, struct test_parse_ctx *ctx)
|
||||||
|
{
|
||||||
|
ctx->and = ctx->and && (ctx->invert ? ! val : val);
|
||||||
|
ctx->invert = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* A hook for iterating directories. */
|
||||||
|
static int
|
||||||
|
find_file (const char *cur_filename, const struct grub_dirhook_info *info,
|
||||||
|
void *data)
|
||||||
|
{
|
||||||
|
int case_insensitive = 0;
|
||||||
|
struct test_parse_ctx *ctx = data;
|
||||||
|
|
||||||
|
if (g_test_case_insensitive || info->case_insensitive)
|
||||||
|
case_insensitive = 1;
|
||||||
|
|
||||||
|
if ((case_insensitive ? grub_strcasecmp (cur_filename, ctx->filename)
|
||||||
|
: grub_strcmp (cur_filename, ctx->filename)) == 0)
|
||||||
|
{
|
||||||
|
ctx->file_info = *info;
|
||||||
|
ctx->file_exists = 1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if file exists and fetch its information. */
|
||||||
|
static void
|
||||||
|
get_fileinfo (char *path, struct test_parse_ctx *ctx)
|
||||||
|
{
|
||||||
|
char *pathname;
|
||||||
|
char *device_name;
|
||||||
|
grub_fs_t fs;
|
||||||
|
grub_device_t dev;
|
||||||
|
|
||||||
|
ctx->file_exists = 0;
|
||||||
|
device_name = grub_file_get_device_name (path);
|
||||||
|
dev = grub_device_open (device_name);
|
||||||
|
if (! dev)
|
||||||
|
{
|
||||||
|
grub_free (device_name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs = grub_fs_probe (dev);
|
||||||
|
if (! fs)
|
||||||
|
{
|
||||||
|
grub_free (device_name);
|
||||||
|
grub_device_close (dev);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pathname = grub_strchr (path, ')');
|
||||||
|
if (! pathname)
|
||||||
|
pathname = path;
|
||||||
|
else
|
||||||
|
pathname++;
|
||||||
|
|
||||||
|
/* Remove trailing '/'. */
|
||||||
|
while (*pathname && pathname[grub_strlen (pathname) - 1] == '/')
|
||||||
|
pathname[grub_strlen (pathname) - 1] = 0;
|
||||||
|
|
||||||
|
/* Split into path and filename. */
|
||||||
|
ctx->filename = grub_strrchr (pathname, '/');
|
||||||
|
if (! ctx->filename)
|
||||||
|
{
|
||||||
|
path = grub_strdup ("/");
|
||||||
|
ctx->filename = pathname;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ctx->filename++;
|
||||||
|
path = grub_strdup (pathname);
|
||||||
|
path[ctx->filename - pathname] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* It's the whole device. */
|
||||||
|
if (! *pathname)
|
||||||
|
{
|
||||||
|
ctx->file_exists = 1;
|
||||||
|
grub_memset (&ctx->file_info, 0, sizeof (ctx->file_info));
|
||||||
|
/* Root is always a directory. */
|
||||||
|
ctx->file_info.dir = 1;
|
||||||
|
|
||||||
|
/* Fetch writing time. */
|
||||||
|
ctx->file_info.mtimeset = 0;
|
||||||
|
if (fs->fs_mtime)
|
||||||
|
{
|
||||||
|
if (! fs->fs_mtime (dev, &ctx->file_info.mtime))
|
||||||
|
ctx->file_info.mtimeset = 1;
|
||||||
|
grub_errno = GRUB_ERR_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
(fs->fs_dir) (dev, path, find_file, ctx);
|
||||||
|
|
||||||
|
grub_device_close (dev);
|
||||||
|
grub_free (path);
|
||||||
|
grub_free (device_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse a test expression starting from *argn. */
|
||||||
|
static int
|
||||||
|
test_parse (char **args, int *argn, int argc)
|
||||||
|
{
|
||||||
|
struct test_parse_ctx ctx = {
|
||||||
|
.and = 1,
|
||||||
|
.or = 0,
|
||||||
|
.invert = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Here we have the real parsing. */
|
||||||
|
while (*argn < argc)
|
||||||
|
{
|
||||||
|
/* First try 3 argument tests. */
|
||||||
|
if (*argn + 2 < argc)
|
||||||
|
{
|
||||||
|
/* String tests. */
|
||||||
|
if (grub_strcmp (args[*argn + 1], "=") == 0
|
||||||
|
|| grub_strcmp (args[*argn + 1], "==") == 0)
|
||||||
|
{
|
||||||
|
update_val (grub_strcmp (args[*argn], args[*argn + 2]) == 0,
|
||||||
|
&ctx);
|
||||||
|
(*argn) += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_strcmp (args[*argn + 1], "!=") == 0)
|
||||||
|
{
|
||||||
|
update_val (grub_strcmp (args[*argn], args[*argn + 2]) != 0,
|
||||||
|
&ctx);
|
||||||
|
(*argn) += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* GRUB extension: lexicographical sorting. */
|
||||||
|
if (grub_strcmp (args[*argn + 1], "<") == 0)
|
||||||
|
{
|
||||||
|
update_val (grub_strcmp (args[*argn], args[*argn + 2]) < 0,
|
||||||
|
&ctx);
|
||||||
|
(*argn) += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_strcmp (args[*argn + 1], "<=") == 0)
|
||||||
|
{
|
||||||
|
update_val (grub_strcmp (args[*argn], args[*argn + 2]) <= 0,
|
||||||
|
&ctx);
|
||||||
|
(*argn) += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_strcmp (args[*argn + 1], ">") == 0)
|
||||||
|
{
|
||||||
|
update_val (grub_strcmp (args[*argn], args[*argn + 2]) > 0,
|
||||||
|
&ctx);
|
||||||
|
(*argn) += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_strcmp (args[*argn + 1], ">=") == 0)
|
||||||
|
{
|
||||||
|
update_val (grub_strcmp (args[*argn], args[*argn + 2]) >= 0,
|
||||||
|
&ctx);
|
||||||
|
(*argn) += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Number tests. */
|
||||||
|
if (grub_strcmp (args[*argn + 1], "-eq") == 0)
|
||||||
|
{
|
||||||
|
update_val (grub_strtosl (args[*argn], 0, 0)
|
||||||
|
== grub_strtosl (args[*argn + 2], 0, 0), &ctx);
|
||||||
|
(*argn) += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_strcmp (args[*argn + 1], "-ge") == 0)
|
||||||
|
{
|
||||||
|
update_val (grub_strtosl (args[*argn], 0, 0)
|
||||||
|
>= grub_strtosl (args[*argn + 2], 0, 0), &ctx);
|
||||||
|
(*argn) += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_strcmp (args[*argn + 1], "-gt") == 0)
|
||||||
|
{
|
||||||
|
update_val (grub_strtosl (args[*argn], 0, 0)
|
||||||
|
> grub_strtosl (args[*argn + 2], 0, 0), &ctx);
|
||||||
|
(*argn) += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_strcmp (args[*argn + 1], "-le") == 0)
|
||||||
|
{
|
||||||
|
update_val (grub_strtosl (args[*argn], 0, 0)
|
||||||
|
<= grub_strtosl (args[*argn + 2], 0, 0), &ctx);
|
||||||
|
(*argn) += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_strcmp (args[*argn + 1], "-lt") == 0)
|
||||||
|
{
|
||||||
|
update_val (grub_strtosl (args[*argn], 0, 0)
|
||||||
|
< grub_strtosl (args[*argn + 2], 0, 0), &ctx);
|
||||||
|
(*argn) += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_strcmp (args[*argn + 1], "-ne") == 0)
|
||||||
|
{
|
||||||
|
update_val (grub_strtosl (args[*argn], 0, 0)
|
||||||
|
!= grub_strtosl (args[*argn + 2], 0, 0), &ctx);
|
||||||
|
(*argn) += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* GRUB extension: compare numbers skipping prefixes.
|
||||||
|
Useful for comparing versions. E.g. vmlinuz-2 -plt vmlinuz-11. */
|
||||||
|
if (grub_strcmp (args[*argn + 1], "-pgt") == 0
|
||||||
|
|| grub_strcmp (args[*argn + 1], "-plt") == 0)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
/* Skip common prefix. */
|
||||||
|
for (i = 0; args[*argn][i] == args[*argn + 2][i]
|
||||||
|
&& args[*argn][i]; i++);
|
||||||
|
|
||||||
|
/* Go the digits back. */
|
||||||
|
i--;
|
||||||
|
while (grub_isdigit (args[*argn][i]) && i > 0)
|
||||||
|
i--;
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if (grub_strcmp (args[*argn + 1], "-pgt") == 0)
|
||||||
|
update_val (grub_strtoul (args[*argn] + i, 0, 0)
|
||||||
|
> grub_strtoul (args[*argn + 2] + i, 0, 0), &ctx);
|
||||||
|
else
|
||||||
|
update_val (grub_strtoul (args[*argn] + i, 0, 0)
|
||||||
|
< grub_strtoul (args[*argn + 2] + i, 0, 0), &ctx);
|
||||||
|
(*argn) += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -nt and -ot tests. GRUB extension: when doing -?t<bias> bias
|
||||||
|
will be added to the first mtime. */
|
||||||
|
if (grub_memcmp (args[*argn + 1], "-nt", 3) == 0
|
||||||
|
|| grub_memcmp (args[*argn + 1], "-ot", 3) == 0)
|
||||||
|
{
|
||||||
|
struct grub_dirhook_info file1;
|
||||||
|
int file1exists;
|
||||||
|
int bias = 0;
|
||||||
|
|
||||||
|
/* Fetch fileinfo. */
|
||||||
|
get_fileinfo (args[*argn], &ctx);
|
||||||
|
file1 = ctx.file_info;
|
||||||
|
file1exists = ctx.file_exists;
|
||||||
|
get_fileinfo (args[*argn + 2], &ctx);
|
||||||
|
|
||||||
|
if (args[*argn + 1][3])
|
||||||
|
bias = grub_strtosl (args[*argn + 1] + 3, 0, 0);
|
||||||
|
|
||||||
|
if (grub_memcmp (args[*argn + 1], "-nt", 3) == 0)
|
||||||
|
update_val ((file1exists && ! ctx.file_exists)
|
||||||
|
|| (file1.mtimeset && ctx.file_info.mtimeset
|
||||||
|
&& file1.mtime + bias > ctx.file_info.mtime),
|
||||||
|
&ctx);
|
||||||
|
else
|
||||||
|
update_val ((! file1exists && ctx.file_exists)
|
||||||
|
|| (file1.mtimeset && ctx.file_info.mtimeset
|
||||||
|
&& file1.mtime + bias < ctx.file_info.mtime),
|
||||||
|
&ctx);
|
||||||
|
(*argn) += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Two-argument tests. */
|
||||||
|
if (*argn + 1 < argc)
|
||||||
|
{
|
||||||
|
/* File tests. */
|
||||||
|
if (grub_strcmp (args[*argn], "-d") == 0)
|
||||||
|
{
|
||||||
|
get_fileinfo (args[*argn + 1], &ctx);
|
||||||
|
update_val (ctx.file_exists && ctx.file_info.dir, &ctx);
|
||||||
|
(*argn) += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_strcmp (args[*argn], "-D") == 0)
|
||||||
|
{
|
||||||
|
g_test_case_insensitive = 1;
|
||||||
|
get_fileinfo (args[*argn + 1], &ctx);
|
||||||
|
g_test_case_insensitive = 0;
|
||||||
|
update_val (ctx.file_exists && ctx.file_info.dir, &ctx);
|
||||||
|
(*argn) += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_strcmp (args[*argn], "-e") == 0)
|
||||||
|
{
|
||||||
|
get_fileinfo (args[*argn + 1], &ctx);
|
||||||
|
update_val (ctx.file_exists, &ctx);
|
||||||
|
(*argn) += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_strcmp (args[*argn], "-E") == 0)
|
||||||
|
{
|
||||||
|
g_test_case_insensitive = 1;
|
||||||
|
get_fileinfo (args[*argn + 1], &ctx);
|
||||||
|
g_test_case_insensitive = 0;
|
||||||
|
update_val (ctx.file_exists, &ctx);
|
||||||
|
(*argn) += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_strcmp (args[*argn], "-f") == 0)
|
||||||
|
{
|
||||||
|
get_fileinfo (args[*argn + 1], &ctx);
|
||||||
|
/* FIXME: check for other types. */
|
||||||
|
update_val (ctx.file_exists && ! ctx.file_info.dir, &ctx);
|
||||||
|
(*argn) += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (grub_strcmp (args[*argn], "-F") == 0)
|
||||||
|
{
|
||||||
|
g_test_case_insensitive = 1;
|
||||||
|
get_fileinfo (args[*argn + 1], &ctx);
|
||||||
|
g_test_case_insensitive = 0;
|
||||||
|
/* FIXME: check for other types. */
|
||||||
|
update_val (ctx.file_exists && ! ctx.file_info.dir, &ctx);
|
||||||
|
(*argn) += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_strcmp (args[*argn], "-s") == 0)
|
||||||
|
{
|
||||||
|
grub_file_t file;
|
||||||
|
file = grub_file_open (args[*argn + 1], GRUB_FILE_TYPE_GET_SIZE
|
||||||
|
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||||
|
update_val (file && (grub_file_size (file) != 0), &ctx);
|
||||||
|
if (file)
|
||||||
|
grub_file_close (file);
|
||||||
|
grub_errno = GRUB_ERR_NONE;
|
||||||
|
(*argn) += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* String tests. */
|
||||||
|
if (grub_strcmp (args[*argn], "-n") == 0)
|
||||||
|
{
|
||||||
|
update_val (args[*argn + 1][0], &ctx);
|
||||||
|
|
||||||
|
(*argn) += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (grub_strcmp (args[*argn], "-z") == 0)
|
||||||
|
{
|
||||||
|
update_val (! args[*argn + 1][0], &ctx);
|
||||||
|
(*argn) += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Special modifiers. */
|
||||||
|
|
||||||
|
/* End of expression. return to parent. */
|
||||||
|
if (grub_strcmp (args[*argn], ")") == 0)
|
||||||
|
{
|
||||||
|
(*argn)++;
|
||||||
|
return ctx.or || ctx.and;
|
||||||
|
}
|
||||||
|
/* Recursively invoke if parenthesis. */
|
||||||
|
if (grub_strcmp (args[*argn], "(") == 0)
|
||||||
|
{
|
||||||
|
(*argn)++;
|
||||||
|
update_val (test_parse (args, argn, argc), &ctx);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_strcmp (args[*argn], "!") == 0)
|
||||||
|
{
|
||||||
|
ctx.invert = ! ctx.invert;
|
||||||
|
(*argn)++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (grub_strcmp (args[*argn], "-a") == 0)
|
||||||
|
{
|
||||||
|
(*argn)++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (grub_strcmp (args[*argn], "-o") == 0)
|
||||||
|
{
|
||||||
|
ctx.or = ctx.or || ctx.and;
|
||||||
|
ctx.and = 1;
|
||||||
|
(*argn)++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* No test found. Interpret if as just a string. */
|
||||||
|
update_val (args[*argn][0], &ctx);
|
||||||
|
(*argn)++;
|
||||||
|
}
|
||||||
|
return ctx.or || ctx.and;
|
||||||
|
}
|
||||||
|
|
||||||
|
static grub_err_t
|
||||||
|
grub_cmd_test (grub_command_t cmd __attribute__ ((unused)),
|
||||||
|
int argc, char **args)
|
||||||
|
{
|
||||||
|
int argn = 0;
|
||||||
|
|
||||||
|
if (argc >= 1 && grub_strcmp (args[argc - 1], "]") == 0)
|
||||||
|
argc--;
|
||||||
|
|
||||||
|
return test_parse (args, &argn, argc) ? GRUB_ERR_NONE
|
||||||
|
: grub_error (GRUB_ERR_TEST_FAILURE, N_("false"));
|
||||||
|
}
|
||||||
|
|
||||||
|
static grub_command_t cmd_1, cmd_2;
|
||||||
|
|
||||||
|
GRUB_MOD_INIT(test)
|
||||||
|
{
|
||||||
|
cmd_1 = grub_register_command ("[", grub_cmd_test,
|
||||||
|
N_("EXPRESSION ]"), N_("Evaluate an expression."));
|
||||||
|
cmd_1->flags |= GRUB_COMMAND_FLAG_EXTRACTOR;
|
||||||
|
cmd_2 = grub_register_command ("test", grub_cmd_test,
|
||||||
|
N_("EXPRESSION"), N_("Evaluate an expression."));
|
||||||
|
cmd_2->flags |= GRUB_COMMAND_FLAG_EXTRACTOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
GRUB_MOD_FINI(test)
|
||||||
|
{
|
||||||
|
grub_unregister_command (cmd_1);
|
||||||
|
grub_unregister_command (cmd_2);
|
||||||
|
}
|
@@ -117,6 +117,8 @@ struct grub_fshelp_find_file_iter_ctx
|
|||||||
enum grub_fshelp_filetype *foundtype;
|
enum grub_fshelp_filetype *foundtype;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int g_ventoy_case_insensitive = 0;
|
||||||
|
|
||||||
/* Helper for grub_fshelp_find_file. */
|
/* Helper for grub_fshelp_find_file. */
|
||||||
static int
|
static int
|
||||||
find_file_iter (const char *filename, enum grub_fshelp_filetype filetype,
|
find_file_iter (const char *filename, enum grub_fshelp_filetype filetype,
|
||||||
@@ -124,6 +126,11 @@ find_file_iter (const char *filename, enum grub_fshelp_filetype filetype,
|
|||||||
{
|
{
|
||||||
struct grub_fshelp_find_file_iter_ctx *ctx = data;
|
struct grub_fshelp_find_file_iter_ctx *ctx = data;
|
||||||
|
|
||||||
|
if (g_ventoy_case_insensitive)
|
||||||
|
{
|
||||||
|
filetype |= GRUB_FSHELP_CASE_INSENSITIVE;
|
||||||
|
}
|
||||||
|
|
||||||
if (filetype == GRUB_FSHELP_UNKNOWN ||
|
if (filetype == GRUB_FSHELP_UNKNOWN ||
|
||||||
((filetype & GRUB_FSHELP_CASE_INSENSITIVE)
|
((filetype & GRUB_FSHELP_CASE_INSENSITIVE)
|
||||||
? grub_strcasecmp (ctx->name, filename)
|
? grub_strcasecmp (ctx->name, filename)
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
GRUB_MOD_LICENSE ("GPLv3+");
|
GRUB_MOD_LICENSE ("GPLv3+");
|
||||||
|
|
||||||
|
static int g_ventoy_no_joliet = 0;
|
||||||
static grub_uint64_t g_ventoy_last_read_pos = 0;
|
static grub_uint64_t g_ventoy_last_read_pos = 0;
|
||||||
static grub_uint64_t g_ventoy_last_read_offset = 0;
|
static grub_uint64_t g_ventoy_last_read_offset = 0;
|
||||||
static grub_uint64_t g_ventoy_last_read_dirent_pos = 0;
|
static grub_uint64_t g_ventoy_last_read_dirent_pos = 0;
|
||||||
@@ -480,8 +481,10 @@ grub_iso9660_mount (grub_disk_t disk)
|
|||||||
(voldesc.escape[2] == 0x43) || /* UCS-2 Level 2. */
|
(voldesc.escape[2] == 0x43) || /* UCS-2 Level 2. */
|
||||||
(voldesc.escape[2] == 0x45))) /* UCS-2 Level 3. */
|
(voldesc.escape[2] == 0x45))) /* UCS-2 Level 3. */
|
||||||
{
|
{
|
||||||
copy_voldesc = 1;
|
if (0 == g_ventoy_no_joliet) {
|
||||||
data->joliet = 1;
|
copy_voldesc = 1;
|
||||||
|
data->joliet = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy_voldesc)
|
if (copy_voldesc)
|
||||||
@@ -1108,6 +1111,11 @@ grub_iso9660_mtime (grub_device_t device, grub_int32_t *timebuf)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void grub_iso9660_set_nojoliet(int nojoliet)
|
||||||
|
{
|
||||||
|
g_ventoy_no_joliet = nojoliet;
|
||||||
|
}
|
||||||
|
|
||||||
grub_uint64_t grub_iso9660_get_last_read_pos(grub_file_t file)
|
grub_uint64_t grub_iso9660_get_last_read_pos(grub_file_t file)
|
||||||
{
|
{
|
||||||
(void)file;
|
(void)file;
|
||||||
|
@@ -970,8 +970,6 @@ grub_xfs_dir_iter (const char *filename, enum grub_fshelp_filetype filetype,
|
|||||||
info.mtime = grub_be_to_cpu32 (node->inode.mtime.sec);
|
info.mtime = grub_be_to_cpu32 (node->inode.mtime.sec);
|
||||||
}
|
}
|
||||||
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
||||||
if (!info.dir)
|
|
||||||
info.size = node->inode.size;
|
|
||||||
grub_free (node);
|
grub_free (node);
|
||||||
return ctx->hook (filename, &info, ctx->hook_data);
|
return ctx->hook (filename, &info, ctx->hook_data);
|
||||||
}
|
}
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
#include <grub/i18n.h>
|
#include <grub/i18n.h>
|
||||||
#include <grub/ventoy.h>
|
#include <grub/ventoy.h>
|
||||||
|
|
||||||
#define GRUB_CACHE_TIMEOUT 2
|
#define GRUB_CACHE_TIMEOUT 10
|
||||||
|
|
||||||
/* The last time the disk was used. */
|
/* The last time the disk was used. */
|
||||||
static grub_uint64_t grub_last_time = 0;
|
static grub_uint64_t grub_last_time = 0;
|
||||||
@@ -412,16 +412,23 @@ grub_disk_read_small (grub_disk_t disk, grub_disk_addr_t sector,
|
|||||||
grub_err_t grub_disk_blocklist_read(void *chunklist, grub_uint64_t sector,
|
grub_err_t grub_disk_blocklist_read(void *chunklist, grub_uint64_t sector,
|
||||||
grub_uint64_t size, grub_uint32_t log_sector_size)
|
grub_uint64_t size, grub_uint32_t log_sector_size)
|
||||||
{
|
{
|
||||||
|
grub_uint64_t sizeshift;
|
||||||
ventoy_img_chunk *last_chunk = NULL;
|
ventoy_img_chunk *last_chunk = NULL;
|
||||||
ventoy_img_chunk *new_chunk = NULL;
|
ventoy_img_chunk *new_chunk = NULL;
|
||||||
ventoy_img_chunk_list *chunk_list = (ventoy_img_chunk_list *)chunklist;
|
ventoy_img_chunk_list *chunk_list = (ventoy_img_chunk_list *)chunklist;
|
||||||
|
|
||||||
|
sizeshift = (size >> log_sector_size);
|
||||||
|
if (sizeshift == 0)
|
||||||
|
{
|
||||||
|
sizeshift = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (chunk_list->cur_chunk == 0)
|
if (chunk_list->cur_chunk == 0)
|
||||||
{
|
{
|
||||||
chunk_list->chunk[0].img_start_sector = 0;
|
chunk_list->chunk[0].img_start_sector = 0;
|
||||||
chunk_list->chunk[0].img_end_sector = (size >> 11) - 1;
|
chunk_list->chunk[0].img_end_sector = (size >> 11) - 1;
|
||||||
chunk_list->chunk[0].disk_start_sector = sector;
|
chunk_list->chunk[0].disk_start_sector = sector;
|
||||||
chunk_list->chunk[0].disk_end_sector = sector + (size >> log_sector_size) - 1;
|
chunk_list->chunk[0].disk_end_sector = sector + sizeshift - 1;
|
||||||
chunk_list->cur_chunk = 1;
|
chunk_list->cur_chunk = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -430,7 +437,7 @@ grub_err_t grub_disk_blocklist_read(void *chunklist, grub_uint64_t sector,
|
|||||||
if (last_chunk->disk_end_sector + 1 == sector)
|
if (last_chunk->disk_end_sector + 1 == sector)
|
||||||
{
|
{
|
||||||
last_chunk->img_end_sector += (size >> 11);
|
last_chunk->img_end_sector += (size >> 11);
|
||||||
last_chunk->disk_end_sector += (size >> log_sector_size);
|
last_chunk->disk_end_sector += sizeshift;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,7 +459,7 @@ grub_err_t grub_disk_blocklist_read(void *chunklist, grub_uint64_t sector,
|
|||||||
new_chunk->img_start_sector = last_chunk->img_end_sector + 1;
|
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->img_end_sector = new_chunk->img_start_sector + (size >> 11) - 1;
|
||||||
new_chunk->disk_start_sector = sector;
|
new_chunk->disk_start_sector = sector;
|
||||||
new_chunk->disk_end_sector = sector + (size >> log_sector_size) - 1;
|
new_chunk->disk_end_sector = sector + sizeshift - 1;
|
||||||
|
|
||||||
chunk_list->cur_chunk++;
|
chunk_list->cur_chunk++;
|
||||||
|
|
||||||
|
@@ -83,6 +83,29 @@ grub_file_t grub_memfile_open(const char *name)
|
|||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ventoy_check_file_exist(const char * fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
grub_file_t file;
|
||||||
|
char fullpath[256] = {0};
|
||||||
|
|
||||||
|
va_start (ap, fmt);
|
||||||
|
grub_vsnprintf(fullpath, 255, fmt, ap);
|
||||||
|
va_end (ap);
|
||||||
|
|
||||||
|
file = grub_file_open(fullpath, GRUB_FILE_TYPE_NONE);
|
||||||
|
if (!file)
|
||||||
|
{
|
||||||
|
grub_errno = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
grub_file_close(file);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
grub_file_t
|
grub_file_t
|
||||||
grub_file_open (const char *name, enum grub_file_type type)
|
grub_file_open (const char *name, enum grub_file_type type)
|
||||||
{
|
{
|
||||||
|
@@ -260,6 +260,45 @@ reclaim_module_space (void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef GRUB_MACHINE_EFI
|
||||||
|
static int ventoy_legacy_limit_workaround(void)
|
||||||
|
{
|
||||||
|
grub_file_t file;
|
||||||
|
char *pos, *root;
|
||||||
|
char buf[128];
|
||||||
|
|
||||||
|
root = grub_strdup(grub_env_get("root"));
|
||||||
|
if (!root)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos = grub_strchr(root, ',');
|
||||||
|
if (pos) *pos = 0;
|
||||||
|
|
||||||
|
grub_snprintf(buf, sizeof(buf), "(%s,1)/ventoy/ventoy.disk.img.xz", root);
|
||||||
|
file = grub_file_open(buf, GRUB_FILE_TYPE_NONE);
|
||||||
|
if (file)
|
||||||
|
{
|
||||||
|
pos = grub_malloc(file->size);
|
||||||
|
if (pos)
|
||||||
|
{
|
||||||
|
grub_file_read(file, pos, file->size);
|
||||||
|
grub_snprintf(buf, sizeof(buf), "loopback ventoydisk mem:0x%lx:size:%lu",
|
||||||
|
(unsigned long)pos, (unsigned long)file->size);
|
||||||
|
|
||||||
|
grub_parser_execute(buf);
|
||||||
|
grub_env_set("prefix", "(ventoydisk)/grub");
|
||||||
|
}
|
||||||
|
|
||||||
|
grub_file_close(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
grub_free(root);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* The main routine. */
|
/* The main routine. */
|
||||||
void __attribute__ ((noreturn))
|
void __attribute__ ((noreturn))
|
||||||
grub_main (void)
|
grub_main (void)
|
||||||
@@ -293,6 +332,12 @@ grub_main (void)
|
|||||||
grub_env_export ("root");
|
grub_env_export ("root");
|
||||||
grub_env_export ("prefix");
|
grub_env_export ("prefix");
|
||||||
|
|
||||||
|
#ifndef GRUB_MACHINE_EFI
|
||||||
|
if (0 == ventoy_check_file_exist("%s/grub.cfg", grub_env_get("prefix"))) {
|
||||||
|
ventoy_legacy_limit_workaround();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Reclaim space used for modules. */
|
/* Reclaim space used for modules. */
|
||||||
reclaim_module_space ();
|
reclaim_module_space ();
|
||||||
|
|
||||||
|
@@ -99,7 +99,7 @@ grub_env_new_context (int export_all)
|
|||||||
grub_err_t
|
grub_err_t
|
||||||
grub_env_context_open (void)
|
grub_env_context_open (void)
|
||||||
{
|
{
|
||||||
return grub_env_new_context (1);
|
return grub_env_new_context (grub_env_get("ventoy_new_context") ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int grub_extractor_level = 0;
|
int grub_extractor_level = 0;
|
||||||
|
@@ -38,7 +38,10 @@ int g_ventoy_menu_refresh = 0;
|
|||||||
int g_ventoy_memdisk_mode = 0;
|
int g_ventoy_memdisk_mode = 0;
|
||||||
int g_ventoy_iso_raw = 0;
|
int g_ventoy_iso_raw = 0;
|
||||||
int g_ventoy_iso_uefi_drv = 0;
|
int g_ventoy_iso_uefi_drv = 0;
|
||||||
int g_ventoy_last_entry = 0;
|
int g_ventoy_last_entry = -1;
|
||||||
|
int g_ventoy_suppress_esc = 0;
|
||||||
|
int g_ventoy_menu_esc = 0;
|
||||||
|
int g_ventoy_fn_mutex = 0;
|
||||||
|
|
||||||
/* Time to delay after displaying an error message about a default/fallback
|
/* Time to delay after displaying an error message about a default/fallback
|
||||||
entry failing to boot. */
|
entry failing to boot. */
|
||||||
@@ -590,8 +593,10 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
|||||||
enum timeout_style timeout_style;
|
enum timeout_style timeout_style;
|
||||||
|
|
||||||
default_entry = get_entry_number (menu, "default");
|
default_entry = get_entry_number (menu, "default");
|
||||||
|
|
||||||
if (g_ventoy_last_entry >= 0 && g_ventoy_last_entry < menu->size) {
|
if (g_ventoy_suppress_esc)
|
||||||
|
default_entry = 1;
|
||||||
|
else if (g_ventoy_last_entry >= 0 && g_ventoy_last_entry < menu->size) {
|
||||||
default_entry = g_ventoy_last_entry;
|
default_entry = g_ventoy_last_entry;
|
||||||
}
|
}
|
||||||
/* If DEFAULT_ENTRY is not within the menu entries, fall back to
|
/* If DEFAULT_ENTRY is not within the menu entries, fall back to
|
||||||
@@ -771,12 +776,12 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
|||||||
case '\r':
|
case '\r':
|
||||||
// case GRUB_TERM_KEY_RIGHT:
|
// case GRUB_TERM_KEY_RIGHT:
|
||||||
case GRUB_TERM_CTRL | 'f':
|
case GRUB_TERM_CTRL | 'f':
|
||||||
menu_fini ();
|
menu_fini ();
|
||||||
*auto_boot = 0;
|
*auto_boot = 0;
|
||||||
return current_entry;
|
return current_entry;
|
||||||
|
|
||||||
case GRUB_TERM_ESC:
|
case GRUB_TERM_ESC:
|
||||||
if (nested)
|
if (nested && 0 == g_ventoy_suppress_esc)
|
||||||
{
|
{
|
||||||
menu_fini ();
|
menu_fini ();
|
||||||
return -1;
|
return -1;
|
||||||
@@ -798,48 +803,66 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
|||||||
goto refresh;
|
goto refresh;
|
||||||
|
|
||||||
case GRUB_TERM_KEY_F2:
|
case GRUB_TERM_KEY_F2:
|
||||||
cmdstr = grub_env_get("VTOY_F2_CMD");
|
if (0 == g_ventoy_fn_mutex) {
|
||||||
if (cmdstr)
|
cmdstr = grub_env_get("VTOY_F2_CMD");
|
||||||
{
|
if (cmdstr)
|
||||||
menu_fini ();
|
{
|
||||||
grub_script_execute_sourcecode(cmdstr);
|
menu_fini ();
|
||||||
goto refresh;
|
g_ventoy_fn_mutex = 1;
|
||||||
|
grub_script_execute_sourcecode(cmdstr);
|
||||||
|
g_ventoy_fn_mutex = 0;
|
||||||
|
goto refresh;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GRUB_TERM_KEY_F3:
|
case GRUB_TERM_KEY_F3:
|
||||||
cmdstr = grub_env_get("VTOY_F3_CMD");
|
if (0 == g_ventoy_fn_mutex) {
|
||||||
if (cmdstr)
|
cmdstr = grub_env_get("VTOY_F3_CMD");
|
||||||
{
|
if (cmdstr)
|
||||||
menu_fini ();
|
{
|
||||||
grub_script_execute_sourcecode(cmdstr);
|
menu_fini ();
|
||||||
goto refresh;
|
grub_script_execute_sourcecode(cmdstr);
|
||||||
|
goto refresh;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GRUB_TERM_KEY_F4:
|
case GRUB_TERM_KEY_F4:
|
||||||
cmdstr = grub_env_get("VTOY_F4_CMD");
|
if (0 == g_ventoy_fn_mutex) {
|
||||||
if (cmdstr)
|
cmdstr = grub_env_get("VTOY_F4_CMD");
|
||||||
{
|
if (cmdstr)
|
||||||
menu_fini ();
|
{
|
||||||
grub_script_execute_sourcecode(cmdstr);
|
menu_fini ();
|
||||||
goto refresh;
|
g_ventoy_fn_mutex = 1;
|
||||||
|
grub_script_execute_sourcecode(cmdstr);
|
||||||
|
g_ventoy_fn_mutex = 0;
|
||||||
|
goto refresh;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GRUB_TERM_KEY_F5:
|
case GRUB_TERM_KEY_F5:
|
||||||
cmdstr = grub_env_get("VTOY_F5_CMD");
|
if (0 == g_ventoy_fn_mutex) {
|
||||||
if (cmdstr)
|
cmdstr = grub_env_get("VTOY_F5_CMD");
|
||||||
{
|
if (cmdstr)
|
||||||
menu_fini ();
|
{
|
||||||
grub_script_execute_sourcecode(cmdstr);
|
menu_fini ();
|
||||||
goto refresh;
|
g_ventoy_fn_mutex = 1;
|
||||||
|
grub_script_execute_sourcecode(cmdstr);
|
||||||
|
g_ventoy_fn_mutex = 0;
|
||||||
|
goto refresh;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GRUB_TERM_KEY_F6:
|
case GRUB_TERM_KEY_F6:
|
||||||
cmdstr = grub_env_get("VTOY_F6_CMD");
|
if (0 == g_ventoy_fn_mutex) {
|
||||||
if (cmdstr)
|
cmdstr = grub_env_get("VTOY_F6_CMD");
|
||||||
{
|
if (cmdstr)
|
||||||
menu_fini ();
|
{
|
||||||
grub_script_execute_sourcecode(cmdstr);
|
menu_fini ();
|
||||||
goto refresh;
|
g_ventoy_fn_mutex = 1;
|
||||||
|
grub_script_execute_sourcecode(cmdstr);
|
||||||
|
g_ventoy_fn_mutex = 0;
|
||||||
|
goto refresh;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GRUB_TERM_KEY_F7:
|
case GRUB_TERM_KEY_F7:
|
||||||
@@ -950,11 +973,16 @@ show_menu (grub_menu_t menu, int nested, int autobooted)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
g_ventoy_last_entry = boot_entry;
|
g_ventoy_last_entry = boot_entry;
|
||||||
|
if (g_ventoy_menu_esc)
|
||||||
|
break;
|
||||||
|
|
||||||
e = grub_menu_get_entry (menu, boot_entry);
|
e = grub_menu_get_entry (menu, boot_entry);
|
||||||
if (! e)
|
if (! e)
|
||||||
continue; /* Menu is empty. */
|
continue; /* Menu is empty. */
|
||||||
|
|
||||||
|
if (2 == e->argc && e->args && e->args[1] && grub_strncmp(e->args[1], "VTOY_RET", 8) == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
grub_cls ();
|
grub_cls ();
|
||||||
|
|
||||||
if (auto_boot)
|
if (auto_boot)
|
||||||
|
@@ -23,7 +23,10 @@
|
|||||||
|
|
||||||
#define VTOY_MAX_SCRIPT_BUF (4 * 1024 * 1024)
|
#define VTOY_MAX_SCRIPT_BUF (4 * 1024 * 1024)
|
||||||
|
|
||||||
#define VTOY_SIZE_1GB 1073741824
|
#define VTOY_FILT_MIN_FILE_SIZE 32768
|
||||||
|
|
||||||
|
#define VTOY_SIZE_1GB 1073741824
|
||||||
|
#define VTOY_SIZE_512KB (512 * 1024)
|
||||||
|
|
||||||
#define JSON_SUCCESS 0
|
#define JSON_SUCCESS 0
|
||||||
#define JSON_FAILED 1
|
#define JSON_FAILED 1
|
||||||
@@ -62,6 +65,7 @@ typedef struct cmd_para
|
|||||||
grub_extcmd_t cmd;
|
grub_extcmd_t cmd;
|
||||||
}cmd_para;
|
}cmd_para;
|
||||||
|
|
||||||
|
#define ventoy_align_2k(value) ((value + 2047) / 2048 * 2048)
|
||||||
#define ventoy_align(value, align) (((value) + ((align) - 1)) & (~((align) - 1)))
|
#define ventoy_align(value, align) (((value) + ((align) - 1)) & (~((align) - 1)))
|
||||||
|
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
@@ -87,6 +91,7 @@ typedef struct cpio_newc_header
|
|||||||
|
|
||||||
#define cmd_raw_name ctxt->extcmd->cmd->name
|
#define cmd_raw_name ctxt->extcmd->cmd->name
|
||||||
#define check_free(p, func) if (p) { func(p); p = NULL; }
|
#define check_free(p, func) if (p) { func(p); p = NULL; }
|
||||||
|
#define grub_check_free(p) if (p) { grub_free(p); p = NULL; }
|
||||||
|
|
||||||
typedef int (*grub_char_check_func)(int c);
|
typedef int (*grub_char_check_func)(int c);
|
||||||
#define ventoy_is_decimal(str) ventoy_string_check(str, grub_isdigit)
|
#define ventoy_is_decimal(str) ventoy_string_check(str, grub_isdigit)
|
||||||
@@ -118,15 +123,38 @@ typedef struct ventoy_udf_override
|
|||||||
grub_uint32_t position;
|
grub_uint32_t position;
|
||||||
}ventoy_udf_override;
|
}ventoy_udf_override;
|
||||||
|
|
||||||
|
typedef struct ventoy_iso9660_vd
|
||||||
|
{
|
||||||
|
grub_uint8_t type;
|
||||||
|
grub_uint8_t id[5];
|
||||||
|
grub_uint8_t ver;
|
||||||
|
grub_uint8_t res;
|
||||||
|
char sys[32];
|
||||||
|
char vol[32];
|
||||||
|
}ventoy_iso9660_vd;
|
||||||
|
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
|
||||||
|
#define img_type_iso 0
|
||||||
|
#define img_type_wim 1
|
||||||
|
#define img_type_efi 2
|
||||||
|
#define img_type_img 3
|
||||||
|
|
||||||
typedef struct img_info
|
typedef struct img_info
|
||||||
{
|
{
|
||||||
|
int pathlen;
|
||||||
char path[512];
|
char path[512];
|
||||||
char name[256];
|
char name[256];
|
||||||
|
|
||||||
|
const char *alias;
|
||||||
|
const char *class;
|
||||||
|
const char *menu_prefix;
|
||||||
|
|
||||||
int id;
|
int id;
|
||||||
|
int type;
|
||||||
grub_uint64_t size;
|
grub_uint64_t size;
|
||||||
int select;
|
int select;
|
||||||
|
int unsupport;
|
||||||
|
|
||||||
void *parent;
|
void *parent;
|
||||||
|
|
||||||
@@ -186,12 +214,15 @@ extern grub_uint8_t *g_ventoy_runtime_buf;
|
|||||||
extern ventoy_guid g_ventoy_guid;
|
extern ventoy_guid g_ventoy_guid;
|
||||||
|
|
||||||
extern ventoy_img_chunk_list g_img_chunk_list;
|
extern ventoy_img_chunk_list g_img_chunk_list;
|
||||||
|
extern ventoy_img_chunk_list g_wimiso_chunk_list;
|
||||||
|
extern char *g_wimiso_path;
|
||||||
|
|
||||||
extern int g_ventoy_debug;
|
extern int g_ventoy_debug;
|
||||||
void ventoy_debug(const char *fmt, ...);
|
void ventoy_debug(const char *fmt, ...);
|
||||||
#define debug(fmt, ...) if (g_ventoy_debug) ventoy_debug("[VTOY]: "fmt, __VA_ARGS__)
|
#define debug(fmt, ...) if (g_ventoy_debug) ventoy_debug("[VTOY]: "fmt, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define vtoy_ssprintf(buf, pos, fmt, ...) \
|
||||||
|
pos += grub_snprintf(buf + pos, VTOY_MAX_SCRIPT_BUF - pos, fmt, __VA_ARGS__)
|
||||||
|
|
||||||
#define FLAG_HEADER_RESERVED 0x00000001
|
#define FLAG_HEADER_RESERVED 0x00000001
|
||||||
#define FLAG_HEADER_COMPRESSION 0x00000002
|
#define FLAG_HEADER_COMPRESSION 0x00000002
|
||||||
@@ -204,6 +235,7 @@ void ventoy_debug(const char *fmt, ...);
|
|||||||
#define FLAG_HEADER_COMPRESS_RESERVED 0x00010000
|
#define FLAG_HEADER_COMPRESS_RESERVED 0x00010000
|
||||||
#define FLAG_HEADER_COMPRESS_XPRESS 0x00020000
|
#define FLAG_HEADER_COMPRESS_XPRESS 0x00020000
|
||||||
#define FLAG_HEADER_COMPRESS_LZX 0x00040000
|
#define FLAG_HEADER_COMPRESS_LZX 0x00040000
|
||||||
|
#define FLAG_HEADER_COMPRESS_LZMS 0x00080000
|
||||||
|
|
||||||
#define RESHDR_FLAG_FREE 0x01
|
#define RESHDR_FLAG_FREE 0x01
|
||||||
#define RESHDR_FLAG_METADATA 0x02
|
#define RESHDR_FLAG_METADATA 0x02
|
||||||
@@ -350,6 +382,19 @@ typedef struct wim_tail
|
|||||||
grub_uint32_t new_lookup_align_len;
|
grub_uint32_t new_lookup_align_len;
|
||||||
}wim_tail;
|
}wim_tail;
|
||||||
|
|
||||||
|
typedef struct wim_patch
|
||||||
|
{
|
||||||
|
int pathlen;
|
||||||
|
char path[256];
|
||||||
|
|
||||||
|
wim_hash old_hash;
|
||||||
|
wim_tail wim_data;
|
||||||
|
wim_lookup_entry *replace_look;
|
||||||
|
|
||||||
|
int valid;
|
||||||
|
|
||||||
|
struct wim_patch *next;
|
||||||
|
}wim_patch;
|
||||||
|
|
||||||
|
|
||||||
typedef enum _JSON_TYPE
|
typedef enum _JSON_TYPE
|
||||||
@@ -399,11 +444,13 @@ typedef struct _JSON_PARSE
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef int (*ventoy_plugin_entry_pf)(VTOY_JSON *json, const char *isodisk);
|
typedef int (*ventoy_plugin_entry_pf)(VTOY_JSON *json, const char *isodisk);
|
||||||
|
typedef int (*ventoy_plugin_check_pf)(VTOY_JSON *json, const char *isodisk);
|
||||||
|
|
||||||
typedef struct plugin_entry
|
typedef struct plugin_entry
|
||||||
{
|
{
|
||||||
const char *key;
|
const char *key;
|
||||||
ventoy_plugin_entry_pf entryfunc;
|
ventoy_plugin_entry_pf entryfunc;
|
||||||
|
ventoy_plugin_check_pf checkfunc;
|
||||||
}plugin_entry;
|
}plugin_entry;
|
||||||
|
|
||||||
|
|
||||||
@@ -422,12 +469,15 @@ grub_err_t ventoy_cmd_valid_initrd_count(grub_extcmd_context_t ctxt, int argc, c
|
|||||||
grub_err_t ventoy_cmd_load_cpio(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, const 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, ...);
|
grub_file_t ventoy_grub_file_open(enum grub_file_type type, const char *fmt, ...);
|
||||||
|
grub_uint64_t ventoy_grub_get_file_size(const char *fmt, ...);
|
||||||
int ventoy_is_file_exist(const char *fmt, ...);
|
int ventoy_is_file_exist(const char *fmt, ...);
|
||||||
|
int ventoy_is_dir_exist(const char *fmt, ...);
|
||||||
int ventoy_fill_data(grub_uint32_t buflen, char *buffer);
|
int ventoy_fill_data(grub_uint32_t buflen, char *buffer);
|
||||||
grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **args);
|
grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||||
grub_err_t ventoy_cmd_wimdows_reset(grub_extcmd_context_t ctxt, int argc, char **args);
|
grub_err_t ventoy_cmd_wimdows_reset(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||||
grub_err_t ventoy_cmd_wimdows_locate_wim(grub_extcmd_context_t ctxt, int argc, char **args);
|
|
||||||
grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
|
grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||||
|
grub_err_t ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||||
|
grub_err_t ventoy_cmd_dump_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||||
|
|
||||||
VTOY_JSON *vtoy_json_find_item
|
VTOY_JSON *vtoy_json_find_item
|
||||||
(
|
(
|
||||||
@@ -552,37 +602,126 @@ typedef struct ventoy_mbr_head
|
|||||||
}ventoy_mbr_head;
|
}ventoy_mbr_head;
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
|
||||||
|
typedef struct file_fullpath
|
||||||
|
{
|
||||||
|
char path[256];
|
||||||
|
}file_fullpath;
|
||||||
|
|
||||||
typedef struct install_template
|
typedef struct install_template
|
||||||
{
|
{
|
||||||
|
int pathlen;
|
||||||
char isopath[256];
|
char isopath[256];
|
||||||
char templatepath[256];
|
|
||||||
|
int autosel;
|
||||||
|
int cursel;
|
||||||
|
int templatenum;
|
||||||
|
file_fullpath *templatepath;
|
||||||
|
|
||||||
struct install_template *next;
|
struct install_template *next;
|
||||||
}install_template;
|
}install_template;
|
||||||
|
|
||||||
typedef struct persistence_config
|
typedef struct persistence_config
|
||||||
{
|
{
|
||||||
|
int pathlen;
|
||||||
char isopath[256];
|
char isopath[256];
|
||||||
char filepath[256];
|
|
||||||
|
|
||||||
|
int autosel;
|
||||||
|
int cursel;
|
||||||
|
int backendnum;
|
||||||
|
file_fullpath *backendpath;
|
||||||
|
|
||||||
struct persistence_config *next;
|
struct persistence_config *next;
|
||||||
}persistence_config;
|
}persistence_config;
|
||||||
|
|
||||||
|
#define vtoy_alias_image_file 0
|
||||||
|
#define vtoy_alias_directory 1
|
||||||
|
|
||||||
|
typedef struct menu_alias
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
int pathlen;
|
||||||
|
char isopath[256];
|
||||||
|
char alias[256];
|
||||||
|
|
||||||
|
struct menu_alias *next;
|
||||||
|
}menu_alias;
|
||||||
|
|
||||||
|
#define vtoy_class_image_file 0
|
||||||
|
#define vtoy_class_directory 1
|
||||||
|
|
||||||
|
typedef struct menu_class
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
int patlen;
|
||||||
|
char pattern[256];
|
||||||
|
char class[64];
|
||||||
|
|
||||||
|
struct menu_class *next;
|
||||||
|
}menu_class;
|
||||||
|
|
||||||
|
typedef struct injection_config
|
||||||
|
{
|
||||||
|
int pathlen;
|
||||||
|
char isopath[256];
|
||||||
|
char archive[256];
|
||||||
|
|
||||||
|
struct injection_config *next;
|
||||||
|
}injection_config;
|
||||||
|
|
||||||
|
extern int g_ventoy_menu_esc;
|
||||||
|
extern int g_ventoy_suppress_esc;
|
||||||
extern int g_ventoy_last_entry;
|
extern int g_ventoy_last_entry;
|
||||||
extern int g_ventoy_memdisk_mode;
|
extern int g_ventoy_memdisk_mode;
|
||||||
extern int g_ventoy_iso_raw;
|
extern int g_ventoy_iso_raw;
|
||||||
extern int g_ventoy_iso_uefi_drv;
|
extern int g_ventoy_iso_uefi_drv;
|
||||||
|
extern int g_ventoy_case_insensitive;
|
||||||
|
extern grub_uint8_t g_ventoy_chain_type;
|
||||||
|
|
||||||
|
|
||||||
|
#define ventoy_unix_fill_virt(new_data, new_len) \
|
||||||
|
{ \
|
||||||
|
data_secs = (new_len + 2047) / 2048; \
|
||||||
|
cur->mem_sector_start = sector; \
|
||||||
|
cur->mem_sector_end = cur->mem_sector_start + data_secs; \
|
||||||
|
cur->mem_sector_offset = offset; \
|
||||||
|
cur->remap_sector_start = 0; \
|
||||||
|
cur->remap_sector_end = 0; \
|
||||||
|
cur->org_sector_start = 0; \
|
||||||
|
grub_memcpy(override + offset, new_data, new_len); \
|
||||||
|
cur++; \
|
||||||
|
sector += data_secs; \
|
||||||
|
offset += new_len; \
|
||||||
|
chain->virt_img_size_in_bytes += data_secs * 2048; \
|
||||||
|
}
|
||||||
|
|
||||||
|
char * ventoy_get_line(char *start);
|
||||||
int ventoy_cmp_img(img_info *img1, img_info *img2);
|
int ventoy_cmp_img(img_info *img1, img_info *img2);
|
||||||
void ventoy_swap_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);
|
char * ventoy_plugin_get_cur_install_template(const char *isopath);
|
||||||
|
install_template * ventoy_plugin_find_install_template(const char *isopath);
|
||||||
|
persistence_config * ventoy_plugin_find_persistent(const char *isopath);
|
||||||
|
void ventoy_plugin_dump_injection(void);
|
||||||
void ventoy_plugin_dump_auto_install(void);
|
void ventoy_plugin_dump_auto_install(void);
|
||||||
int ventoy_fill_windows_rtdata(void *buf, char *isopath);
|
int ventoy_fill_windows_rtdata(void *buf, char *isopath);
|
||||||
int ventoy_plugin_get_persistent_chunklist(const char *isopath, ventoy_img_chunk_list *chunk_list);
|
int ventoy_plugin_get_persistent_chunklist(const char *isopath, int index, ventoy_img_chunk_list *chunk_list);
|
||||||
|
const char * ventoy_plugin_get_injection(const char *isopath);
|
||||||
|
const char * ventoy_plugin_get_menu_alias(int type, const char *isopath);
|
||||||
|
const char * ventoy_plugin_get_menu_class(int type, const char *name);
|
||||||
int ventoy_get_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
|
int ventoy_get_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
|
||||||
int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
|
int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
|
||||||
void ventoy_plugin_dump_persistence(void);
|
void ventoy_plugin_dump_persistence(void);
|
||||||
|
grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||||
|
grub_err_t ventoy_cmd_linux_get_main_initrd_index(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||||
|
grub_err_t ventoy_cmd_collect_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||||
|
grub_err_t ventoy_cmd_wim_patch_count(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||||
|
grub_err_t ventoy_cmd_locate_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||||
|
grub_err_t ventoy_cmd_unix_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||||
|
int ventoy_get_disk_guid(const char *filename, grub_uint8_t *guid);
|
||||||
|
grub_err_t ventoy_cmd_unix_reset(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||||
|
grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||||
|
grub_err_t ventoy_cmd_unix_replace_ko(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||||
|
grub_err_t ventoy_cmd_unix_freebsd_ver(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||||
|
grub_err_t ventoy_cmd_parse_freenas_ver(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||||
|
|
||||||
#endif /* __VENTOY_DEF_H__ */
|
#endif /* __VENTOY_DEF_H__ */
|
||||||
|
|
||||||
|
@@ -42,6 +42,11 @@ static void json_debug(const char *fmt, ...)
|
|||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
|
if (g_ventoy_debug == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
va_start (args, fmt);
|
va_start (args, fmt);
|
||||||
grub_vprintf (fmt, args);
|
grub_vprintf (fmt, args);
|
||||||
va_end (args);
|
va_end (args);
|
||||||
|
@@ -38,8 +38,7 @@
|
|||||||
|
|
||||||
GRUB_MOD_LICENSE ("GPLv3+");
|
GRUB_MOD_LICENSE ("GPLv3+");
|
||||||
|
|
||||||
|
char * ventoy_get_line(char *start)
|
||||||
static char * ventoy_get_line(char *start)
|
|
||||||
{
|
{
|
||||||
if (start == NULL)
|
if (start == NULL)
|
||||||
{
|
{
|
||||||
@@ -686,6 +685,8 @@ static grub_uint32_t ventoy_linux_get_override_chunk_size(void)
|
|||||||
static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *override)
|
static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *override)
|
||||||
{
|
{
|
||||||
initrd_info *node;
|
initrd_info *node;
|
||||||
|
grub_uint32_t mod;
|
||||||
|
grub_uint32_t newlen;
|
||||||
grub_uint64_t sector;
|
grub_uint64_t sector;
|
||||||
ventoy_override_chunk *cur;
|
ventoy_override_chunk *cur;
|
||||||
|
|
||||||
@@ -699,13 +700,20 @@ static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *ove
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newlen = (grub_uint32_t)(node->size + g_ventoy_cpio_size);
|
||||||
|
mod = newlen % 4;
|
||||||
|
if (mod > 0)
|
||||||
|
{
|
||||||
|
newlen += 4 - mod;
|
||||||
|
}
|
||||||
|
|
||||||
if (node->iso_type == 0)
|
if (node->iso_type == 0)
|
||||||
{
|
{
|
||||||
ventoy_iso9660_override *dirent = (ventoy_iso9660_override *)node->override_data;
|
ventoy_iso9660_override *dirent = (ventoy_iso9660_override *)node->override_data;
|
||||||
|
|
||||||
node->override_length = sizeof(ventoy_iso9660_override);
|
node->override_length = sizeof(ventoy_iso9660_override);
|
||||||
dirent->first_sector = (grub_uint32_t)sector;
|
dirent->first_sector = (grub_uint32_t)sector;
|
||||||
dirent->size = (grub_uint32_t)(node->size + g_ventoy_cpio_size);
|
dirent->size = newlen;
|
||||||
dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector);
|
dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector);
|
||||||
dirent->size_be = grub_swap_bytes32(dirent->size);
|
dirent->size_be = grub_swap_bytes32(dirent->size);
|
||||||
|
|
||||||
@@ -716,7 +724,7 @@ static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *ove
|
|||||||
ventoy_udf_override *udf = (ventoy_udf_override *)node->override_data;
|
ventoy_udf_override *udf = (ventoy_udf_override *)node->override_data;
|
||||||
|
|
||||||
node->override_length = sizeof(ventoy_udf_override);
|
node->override_length = sizeof(ventoy_udf_override);
|
||||||
udf->length = (grub_uint32_t)(node->size + g_ventoy_cpio_size);
|
udf->length = newlen;
|
||||||
udf->position = (grub_uint32_t)sector - node->udf_start_block;
|
udf->position = (grub_uint32_t)sector - node->udf_start_block;
|
||||||
|
|
||||||
sector += (udf->length + 2047) / 2048;
|
sector += (udf->length + 2047) / 2048;
|
||||||
@@ -832,6 +840,50 @@ static grub_err_t ventoy_linux_locate_initrd(int filt, int *filtcnt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
grub_err_t ventoy_cmd_linux_get_main_initrd_index(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||||
|
{
|
||||||
|
int index = 0;
|
||||||
|
char buf[32];
|
||||||
|
initrd_info *node = NULL;
|
||||||
|
|
||||||
|
(void)ctxt;
|
||||||
|
(void)argc;
|
||||||
|
(void)args;
|
||||||
|
|
||||||
|
if (argc != 1)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_initrd_img_count == 1)
|
||||||
|
{
|
||||||
|
ventoy_set_env(args[0], "0");
|
||||||
|
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (node = g_initrd_img_list; node; node = node->next)
|
||||||
|
{
|
||||||
|
if (node->size <= 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_strstr(node->name, "ucode") || grub_strstr(node->name, "-firmware"))
|
||||||
|
{
|
||||||
|
index++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
grub_snprintf(buf, sizeof(buf), "%d", index);
|
||||||
|
ventoy_set_env(args[0], buf);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
debug("main initrd index:%d\n", index);
|
||||||
|
|
||||||
|
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc, char **args)
|
grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||||
{
|
{
|
||||||
int sizefilt = 0;
|
int sizefilt = 0;
|
||||||
@@ -856,6 +908,8 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
|
|||||||
char *template_file = NULL;
|
char *template_file = NULL;
|
||||||
char *template_buf = NULL;
|
char *template_buf = NULL;
|
||||||
char *persistent_buf = NULL;
|
char *persistent_buf = NULL;
|
||||||
|
char *injection_buf = NULL;
|
||||||
|
const char *injection_file = NULL;
|
||||||
grub_uint8_t *buf = NULL;
|
grub_uint8_t *buf = NULL;
|
||||||
grub_uint32_t mod;
|
grub_uint32_t mod;
|
||||||
grub_uint32_t headlen;
|
grub_uint32_t headlen;
|
||||||
@@ -864,8 +918,9 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
|
|||||||
grub_uint32_t img_chunk_size;
|
grub_uint32_t img_chunk_size;
|
||||||
grub_uint32_t template_size = 0;
|
grub_uint32_t template_size = 0;
|
||||||
grub_uint32_t persistent_size = 0;
|
grub_uint32_t persistent_size = 0;
|
||||||
|
grub_uint32_t injection_size = 0;
|
||||||
grub_file_t file;
|
grub_file_t file;
|
||||||
grub_file_t scriptfile;
|
grub_file_t tmpfile;
|
||||||
ventoy_img_chunk_list chunk_list;
|
ventoy_img_chunk_list chunk_list;
|
||||||
|
|
||||||
(void)ctxt;
|
(void)ctxt;
|
||||||
@@ -896,37 +951,68 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
|
|||||||
g_ventoy_cpio_size = 0;
|
g_ventoy_cpio_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = ventoy_plugin_get_persistent_chunklist(args[1], &chunk_list);
|
rc = ventoy_plugin_get_persistent_chunklist(args[1], -1, &chunk_list);
|
||||||
if (rc == 0 && chunk_list.cur_chunk > 0 && chunk_list.chunk)
|
if (rc == 0 && chunk_list.cur_chunk > 0 && chunk_list.chunk)
|
||||||
{
|
{
|
||||||
persistent_size = chunk_list.cur_chunk * sizeof(ventoy_img_chunk);
|
persistent_size = chunk_list.cur_chunk * sizeof(ventoy_img_chunk);
|
||||||
persistent_buf = (char *)(chunk_list.chunk);
|
persistent_buf = (char *)(chunk_list.chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
template_file = ventoy_plugin_get_install_template(args[1]);
|
template_file = ventoy_plugin_get_cur_install_template(args[1]);
|
||||||
if (template_file)
|
if (template_file)
|
||||||
{
|
{
|
||||||
debug("auto install template: <%s>\n", template_file);
|
debug("auto install template: <%s>\n", template_file);
|
||||||
scriptfile = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", args[2], template_file);
|
tmpfile = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", args[2], template_file);
|
||||||
if (scriptfile)
|
if (tmpfile)
|
||||||
{
|
{
|
||||||
debug("auto install script size %d\n", (int)scriptfile->size);
|
debug("auto install script size %d\n", (int)tmpfile->size);
|
||||||
template_size = scriptfile->size;
|
template_size = tmpfile->size;
|
||||||
template_buf = grub_malloc(template_size);
|
template_buf = grub_malloc(template_size);
|
||||||
if (template_buf)
|
if (template_buf)
|
||||||
{
|
{
|
||||||
grub_file_read(scriptfile, template_buf, template_size);
|
grub_file_read(tmpfile, template_buf, template_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
grub_file_close(scriptfile);
|
grub_file_close(tmpfile);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debug("Failed to open install script %s%s\n", args[2], template_file);
|
debug("Failed to open install script %s%s\n", args[2], template_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
debug("auto install script skipped or not configed %s\n", args[1]);
|
||||||
|
}
|
||||||
|
|
||||||
g_ventoy_cpio_buf = grub_malloc(file->size + 4096 + template_size + persistent_size + img_chunk_size);
|
injection_file = ventoy_plugin_get_injection(args[1]);
|
||||||
|
if (injection_file)
|
||||||
|
{
|
||||||
|
debug("injection archive: <%s>\n", injection_file);
|
||||||
|
tmpfile = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", args[2], injection_file);
|
||||||
|
if (tmpfile)
|
||||||
|
{
|
||||||
|
debug("injection archive size:%d\n", (int)tmpfile->size);
|
||||||
|
injection_size = tmpfile->size;
|
||||||
|
injection_buf = grub_malloc(injection_size);
|
||||||
|
if (injection_buf)
|
||||||
|
{
|
||||||
|
grub_file_read(tmpfile, injection_buf, injection_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
grub_file_close(tmpfile);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
debug("Failed to open injection archive %s%s\n", args[2], injection_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
debug("injection not configed %s\n", args[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_ventoy_cpio_buf = grub_malloc(file->size + 4096 + template_size + persistent_size + injection_size + img_chunk_size);
|
||||||
if (NULL == g_ventoy_cpio_buf)
|
if (NULL == g_ventoy_cpio_buf)
|
||||||
{
|
{
|
||||||
grub_file_close(file);
|
grub_file_close(file);
|
||||||
@@ -963,6 +1049,15 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
|
|||||||
persistent_buf = NULL;
|
persistent_buf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (injection_size > 0 && injection_buf)
|
||||||
|
{
|
||||||
|
headlen = ventoy_cpio_newc_fill_head(buf, injection_size, injection_buf, "ventoy/ventoy_injection");
|
||||||
|
buf += headlen + ventoy_align(injection_size, 4);
|
||||||
|
|
||||||
|
grub_free(injection_buf);
|
||||||
|
injection_buf = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* step2: insert os param to cpio */
|
/* step2: insert os param to cpio */
|
||||||
headlen = ventoy_cpio_newc_fill_head(buf, 0, NULL, "ventoy/ventoy_os_param");
|
headlen = ventoy_cpio_newc_fill_head(buf, 0, NULL, "ventoy/ventoy_os_param");
|
||||||
padlen = sizeof(ventoy_os_param);
|
padlen = sizeof(ventoy_os_param);
|
||||||
@@ -1087,6 +1182,7 @@ grub_err_t ventoy_cmd_linux_chain_data(grub_extcmd_context_t ctxt, int argc, cha
|
|||||||
grub_memset(chain, 0, sizeof(ventoy_chain_head));
|
grub_memset(chain, 0, sizeof(ventoy_chain_head));
|
||||||
|
|
||||||
/* part 1: os parameter */
|
/* part 1: os parameter */
|
||||||
|
g_ventoy_chain_type = ventoy_chain_linux;
|
||||||
ventoy_fill_os_param(file, &(chain->os_param));
|
ventoy_fill_os_param(file, &(chain->os_param));
|
||||||
|
|
||||||
/* part 2: chain head */
|
/* part 2: chain head */
|
||||||
|
157
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/xpress.c
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
|
||||||
|
*
|
||||||
|
* 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 2 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, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
*
|
||||||
|
* Xpress Compression Algorithm (MS-XCA) decompression
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "wimboot.h"
|
||||||
|
#include "huffman.h"
|
||||||
|
#include "xpress.h"
|
||||||
|
|
||||||
|
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decompress XCA-compressed data
|
||||||
|
*
|
||||||
|
* @v data Compressed data
|
||||||
|
* @v len Length of compressed data
|
||||||
|
* @v buf Decompression buffer, or NULL
|
||||||
|
* @ret out_len Length of decompressed data, or negative error
|
||||||
|
*/
|
||||||
|
ssize_t xca_decompress ( const void *data, size_t len, void *buf ) {
|
||||||
|
const void *src = data;
|
||||||
|
const void *end = ( uint8_t * ) src + len;
|
||||||
|
uint8_t *out = buf;
|
||||||
|
size_t out_len = 0;
|
||||||
|
size_t out_len_threshold = 0;
|
||||||
|
const struct xca_huf_len *lengths;
|
||||||
|
struct xca xca;
|
||||||
|
uint32_t accum = 0;
|
||||||
|
int extra_bits = 0;
|
||||||
|
unsigned int huf;
|
||||||
|
struct huffman_symbols *sym;
|
||||||
|
unsigned int raw;
|
||||||
|
unsigned int match_len;
|
||||||
|
unsigned int match_offset_bits;
|
||||||
|
unsigned int match_offset;
|
||||||
|
const uint8_t *copy;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* Process data stream */
|
||||||
|
while ( src < end ) {
|
||||||
|
|
||||||
|
/* (Re)initialise decompressor if applicable */
|
||||||
|
if ( out_len >= out_len_threshold ) {
|
||||||
|
|
||||||
|
/* Construct symbol lengths */
|
||||||
|
lengths = src;
|
||||||
|
src = ( uint8_t * ) src + sizeof ( *lengths );
|
||||||
|
if ( src > end ) {
|
||||||
|
DBG ( "XCA too short to hold Huffman lengths table.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for ( raw = 0 ; raw < XCA_CODES ; raw++ )
|
||||||
|
xca.lengths[raw] = xca_huf_len ( lengths, raw );
|
||||||
|
|
||||||
|
/* Construct Huffman alphabet */
|
||||||
|
if ( ( rc = huffman_alphabet ( &xca.alphabet,
|
||||||
|
xca.lengths,
|
||||||
|
XCA_CODES ) ) != 0 )
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
/* Initialise state */
|
||||||
|
accum = XCA_GET16 ( src );
|
||||||
|
accum <<= 16;
|
||||||
|
accum |= XCA_GET16 ( src );
|
||||||
|
extra_bits = 16;
|
||||||
|
|
||||||
|
/* Determine next threshold */
|
||||||
|
out_len_threshold = ( out_len + XCA_BLOCK_SIZE );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Determine symbol */
|
||||||
|
huf = ( accum >> ( 32 - HUFFMAN_BITS ) );
|
||||||
|
sym = huffman_sym ( &xca.alphabet, huf );
|
||||||
|
raw = huffman_raw ( sym, huf );
|
||||||
|
accum <<= huffman_len ( sym );
|
||||||
|
extra_bits -= huffman_len ( sym );
|
||||||
|
if ( extra_bits < 0 ) {
|
||||||
|
accum |= ( XCA_GET16 ( src ) << ( -extra_bits ) );
|
||||||
|
extra_bits += 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Process symbol */
|
||||||
|
if ( raw < XCA_END_MARKER ) {
|
||||||
|
|
||||||
|
/* Literal symbol - add to output stream */
|
||||||
|
if ( buf )
|
||||||
|
*(out++) = raw;
|
||||||
|
out_len++;
|
||||||
|
|
||||||
|
} else if ( ( raw == XCA_END_MARKER ) &&
|
||||||
|
( (uint8_t *) src >= ( ( uint8_t * ) end - 1 ) ) ) {
|
||||||
|
|
||||||
|
/* End marker symbol */
|
||||||
|
return out_len;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
/* LZ77 match symbol */
|
||||||
|
raw -= XCA_END_MARKER;
|
||||||
|
match_offset_bits = ( raw >> 4 );
|
||||||
|
match_len = ( raw & 0x0f );
|
||||||
|
if ( match_len == 0x0f ) {
|
||||||
|
match_len = XCA_GET8 ( src );
|
||||||
|
if ( match_len == 0xff ) {
|
||||||
|
match_len = XCA_GET16 ( src );
|
||||||
|
} else {
|
||||||
|
match_len += 0x0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match_len += 3;
|
||||||
|
if ( match_offset_bits ) {
|
||||||
|
match_offset =
|
||||||
|
( ( accum >> ( 32 - match_offset_bits ))
|
||||||
|
+ ( 1 << match_offset_bits ) );
|
||||||
|
} else {
|
||||||
|
match_offset = 1;
|
||||||
|
}
|
||||||
|
accum <<= match_offset_bits;
|
||||||
|
extra_bits -= match_offset_bits;
|
||||||
|
if ( extra_bits < 0 ) {
|
||||||
|
accum |= ( XCA_GET16 ( src ) << (-extra_bits) );
|
||||||
|
extra_bits += 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy data */
|
||||||
|
out_len += match_len;
|
||||||
|
if ( buf ) {
|
||||||
|
copy = ( out - match_offset );
|
||||||
|
while ( match_len-- )
|
||||||
|
*(out++) = *(copy++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out_len;
|
||||||
|
}
|
87
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/xpress.h
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
#ifndef _XCA_H
|
||||||
|
#define _XCA_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
|
||||||
|
*
|
||||||
|
* 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 2 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, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
*
|
||||||
|
* Xpress Compression Algorithm (MS-XCA) decompression
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "huffman.h"
|
||||||
|
|
||||||
|
/** Number of XCA codes */
|
||||||
|
#define XCA_CODES 512
|
||||||
|
|
||||||
|
/** XCA decompressor */
|
||||||
|
struct xca {
|
||||||
|
/** Huffman alphabet */
|
||||||
|
struct huffman_alphabet alphabet;
|
||||||
|
/** Raw symbols
|
||||||
|
*
|
||||||
|
* Must immediately follow the Huffman alphabet.
|
||||||
|
*/
|
||||||
|
huffman_raw_symbol_t raw[XCA_CODES];
|
||||||
|
/** Code lengths */
|
||||||
|
uint8_t lengths[XCA_CODES];
|
||||||
|
};
|
||||||
|
|
||||||
|
/** XCA symbol Huffman lengths table */
|
||||||
|
struct xca_huf_len {
|
||||||
|
/** Lengths of each symbol */
|
||||||
|
uint8_t nibbles[ XCA_CODES / 2 ];
|
||||||
|
} __attribute__ (( packed ));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract Huffman-coded length of a raw symbol
|
||||||
|
*
|
||||||
|
* @v lengths Huffman lengths table
|
||||||
|
* @v symbol Raw symbol
|
||||||
|
* @ret len Huffman-coded length
|
||||||
|
*/
|
||||||
|
static inline unsigned int xca_huf_len ( const struct xca_huf_len *lengths,
|
||||||
|
unsigned int symbol ) {
|
||||||
|
return ( ( ( lengths->nibbles[ symbol / 2 ] ) >>
|
||||||
|
( 4 * ( symbol % 2 ) ) ) & 0x0f );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get word from source data stream */
|
||||||
|
#define XCA_GET16( src ) ( { \
|
||||||
|
const uint16_t *src16 = src; \
|
||||||
|
src = ( uint8_t * ) src + sizeof ( *src16 ); \
|
||||||
|
*src16; } )
|
||||||
|
|
||||||
|
/** Get byte from source data stream */
|
||||||
|
#define XCA_GET8( src ) ( { \
|
||||||
|
const uint8_t *src8 = src; \
|
||||||
|
src = ( uint8_t * ) src + sizeof ( *src8 ); \
|
||||||
|
*src8; } )
|
||||||
|
|
||||||
|
/** XCA source data stream end marker */
|
||||||
|
#define XCA_END_MARKER 256
|
||||||
|
|
||||||
|
/** XCA block size */
|
||||||
|
#define XCA_BLOCK_SIZE ( 64 * 1024 )
|
||||||
|
|
||||||
|
extern ssize_t xca_decompress ( const void *data, size_t len, void *buf );
|
||||||
|
|
||||||
|
#endif /* _XCA_H */
|
243
GRUB2/MOD_SRC/grub-2.04/include/grub/file.h
Normal file
@@ -0,0 +1,243 @@
|
|||||||
|
/*
|
||||||
|
* GRUB -- GRand Unified Bootloader
|
||||||
|
* Copyright (C) 2002,2007 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_FILE_HEADER
|
||||||
|
#define GRUB_FILE_HEADER 1
|
||||||
|
|
||||||
|
#include <grub/types.h>
|
||||||
|
#include <grub/err.h>
|
||||||
|
#include <grub/device.h>
|
||||||
|
#include <grub/fs.h>
|
||||||
|
#include <grub/disk.h>
|
||||||
|
|
||||||
|
enum grub_file_type
|
||||||
|
{
|
||||||
|
GRUB_FILE_TYPE_NONE = 0,
|
||||||
|
/* GRUB module to be loaded. */
|
||||||
|
GRUB_FILE_TYPE_GRUB_MODULE,
|
||||||
|
/* Loopback file to be represented as disk. */
|
||||||
|
GRUB_FILE_TYPE_LOOPBACK,
|
||||||
|
/* Linux kernel to be loaded. */
|
||||||
|
GRUB_FILE_TYPE_LINUX_KERNEL,
|
||||||
|
/* Linux initrd. */
|
||||||
|
GRUB_FILE_TYPE_LINUX_INITRD,
|
||||||
|
|
||||||
|
/* Multiboot kernel. */
|
||||||
|
GRUB_FILE_TYPE_MULTIBOOT_KERNEL,
|
||||||
|
/* Multiboot module. */
|
||||||
|
GRUB_FILE_TYPE_MULTIBOOT_MODULE,
|
||||||
|
|
||||||
|
/* Xen hypervisor - used on ARM only. */
|
||||||
|
GRUB_FILE_TYPE_XEN_HYPERVISOR,
|
||||||
|
/* Xen module - used on ARM only. */
|
||||||
|
GRUB_FILE_TYPE_XEN_MODULE,
|
||||||
|
|
||||||
|
GRUB_FILE_TYPE_BSD_KERNEL,
|
||||||
|
GRUB_FILE_TYPE_FREEBSD_ENV,
|
||||||
|
GRUB_FILE_TYPE_FREEBSD_MODULE,
|
||||||
|
GRUB_FILE_TYPE_FREEBSD_MODULE_ELF,
|
||||||
|
GRUB_FILE_TYPE_NETBSD_MODULE,
|
||||||
|
GRUB_FILE_TYPE_OPENBSD_RAMDISK,
|
||||||
|
|
||||||
|
GRUB_FILE_TYPE_XNU_INFO_PLIST,
|
||||||
|
GRUB_FILE_TYPE_XNU_MKEXT,
|
||||||
|
GRUB_FILE_TYPE_XNU_KEXT,
|
||||||
|
GRUB_FILE_TYPE_XNU_KERNEL,
|
||||||
|
GRUB_FILE_TYPE_XNU_RAMDISK,
|
||||||
|
GRUB_FILE_TYPE_XNU_HIBERNATE_IMAGE,
|
||||||
|
GRUB_FILE_XNU_DEVPROP,
|
||||||
|
|
||||||
|
GRUB_FILE_TYPE_PLAN9_KERNEL,
|
||||||
|
|
||||||
|
GRUB_FILE_TYPE_NTLDR,
|
||||||
|
GRUB_FILE_TYPE_TRUECRYPT,
|
||||||
|
GRUB_FILE_TYPE_FREEDOS,
|
||||||
|
GRUB_FILE_TYPE_PXECHAINLOADER,
|
||||||
|
GRUB_FILE_TYPE_PCCHAINLOADER,
|
||||||
|
|
||||||
|
GRUB_FILE_TYPE_COREBOOT_CHAINLOADER,
|
||||||
|
|
||||||
|
GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE,
|
||||||
|
|
||||||
|
/* File holding signature. */
|
||||||
|
GRUB_FILE_TYPE_SIGNATURE,
|
||||||
|
/* File holding public key to verify signature once. */
|
||||||
|
GRUB_FILE_TYPE_PUBLIC_KEY,
|
||||||
|
/* File holding public key to add to trused keys. */
|
||||||
|
GRUB_FILE_TYPE_PUBLIC_KEY_TRUST,
|
||||||
|
/* File of which we intend to print a blocklist to the user. */
|
||||||
|
GRUB_FILE_TYPE_PRINT_BLOCKLIST,
|
||||||
|
/* File we intend to use for test loading or testing speed. */
|
||||||
|
GRUB_FILE_TYPE_TESTLOAD,
|
||||||
|
/* File we open only to get its size. E.g. in ls output. */
|
||||||
|
GRUB_FILE_TYPE_GET_SIZE,
|
||||||
|
/* Font file. */
|
||||||
|
GRUB_FILE_TYPE_FONT,
|
||||||
|
/* File holding encryption key for encrypted ZFS. */
|
||||||
|
GRUB_FILE_TYPE_ZFS_ENCRYPTION_KEY,
|
||||||
|
/* File we open n grub-fstest. */
|
||||||
|
GRUB_FILE_TYPE_FSTEST,
|
||||||
|
/* File we open n grub-mount. */
|
||||||
|
GRUB_FILE_TYPE_MOUNT,
|
||||||
|
/* File which we attempt to identify the type of. */
|
||||||
|
GRUB_FILE_TYPE_FILE_ID,
|
||||||
|
/* File holding ACPI table. */
|
||||||
|
GRUB_FILE_TYPE_ACPI_TABLE,
|
||||||
|
/* File holding Device Tree. */
|
||||||
|
GRUB_FILE_TYPE_DEVICE_TREE_IMAGE,
|
||||||
|
/* File we intend show to user. */
|
||||||
|
GRUB_FILE_TYPE_CAT,
|
||||||
|
GRUB_FILE_TYPE_HEXCAT,
|
||||||
|
/* One of pair of files we intend to compare. */
|
||||||
|
GRUB_FILE_TYPE_CMP,
|
||||||
|
/* List of hashes for hashsum. */
|
||||||
|
GRUB_FILE_TYPE_HASHLIST,
|
||||||
|
/* File hashed by hashsum. */
|
||||||
|
GRUB_FILE_TYPE_TO_HASH,
|
||||||
|
/* Keyboard layout. */
|
||||||
|
GRUB_FILE_TYPE_KEYBOARD_LAYOUT,
|
||||||
|
/* Picture file. */
|
||||||
|
GRUB_FILE_TYPE_PIXMAP,
|
||||||
|
/* *.lst shipped by GRUB. */
|
||||||
|
GRUB_FILE_TYPE_GRUB_MODULE_LIST,
|
||||||
|
/* config file. */
|
||||||
|
GRUB_FILE_TYPE_CONFIG,
|
||||||
|
GRUB_FILE_TYPE_THEME,
|
||||||
|
GRUB_FILE_TYPE_GETTEXT_CATALOG,
|
||||||
|
GRUB_FILE_TYPE_FS_SEARCH,
|
||||||
|
GRUB_FILE_TYPE_AUDIO,
|
||||||
|
GRUB_FILE_TYPE_VBE_DUMP,
|
||||||
|
|
||||||
|
GRUB_FILE_TYPE_LOADENV,
|
||||||
|
GRUB_FILE_TYPE_SAVEENV,
|
||||||
|
|
||||||
|
GRUB_FILE_TYPE_VERIFY_SIGNATURE,
|
||||||
|
|
||||||
|
GRUB_FILE_TYPE_MASK = 0xffff,
|
||||||
|
|
||||||
|
/* --skip-sig is specified. */
|
||||||
|
GRUB_FILE_TYPE_SKIP_SIGNATURE = 0x10000,
|
||||||
|
GRUB_FILE_TYPE_NO_DECOMPRESS = 0x20000
|
||||||
|
};
|
||||||
|
|
||||||
|
/* File description. */
|
||||||
|
struct grub_file
|
||||||
|
{
|
||||||
|
/* File name. */
|
||||||
|
char *name;
|
||||||
|
|
||||||
|
/* The underlying device. */
|
||||||
|
grub_device_t device;
|
||||||
|
|
||||||
|
/* The underlying filesystem. */
|
||||||
|
grub_fs_t fs;
|
||||||
|
|
||||||
|
/* The current offset. */
|
||||||
|
grub_off_t offset;
|
||||||
|
grub_off_t progress_offset;
|
||||||
|
|
||||||
|
/* Progress info. */
|
||||||
|
grub_uint64_t last_progress_time;
|
||||||
|
grub_off_t last_progress_offset;
|
||||||
|
grub_uint64_t estimated_speed;
|
||||||
|
|
||||||
|
/* The file size. */
|
||||||
|
grub_off_t size;
|
||||||
|
|
||||||
|
/* If file is not easily seekable. Should be set by underlying layer. */
|
||||||
|
int not_easily_seekable;
|
||||||
|
|
||||||
|
/* Filesystem-specific data. */
|
||||||
|
void *data;
|
||||||
|
|
||||||
|
/* This is called when a sector is read. Used only for a disk device. */
|
||||||
|
grub_disk_read_hook_t read_hook;
|
||||||
|
|
||||||
|
/* Caller-specific data passed to the read hook. */
|
||||||
|
void *read_hook_data;
|
||||||
|
};
|
||||||
|
typedef struct grub_file *grub_file_t;
|
||||||
|
|
||||||
|
extern grub_disk_read_hook_t EXPORT_VAR(grub_file_progress_hook);
|
||||||
|
|
||||||
|
/* Filters with lower ID are executed first. */
|
||||||
|
typedef enum grub_file_filter_id
|
||||||
|
{
|
||||||
|
GRUB_FILE_FILTER_VERIFY,
|
||||||
|
GRUB_FILE_FILTER_GZIO,
|
||||||
|
GRUB_FILE_FILTER_XZIO,
|
||||||
|
GRUB_FILE_FILTER_LZOPIO,
|
||||||
|
GRUB_FILE_FILTER_MAX,
|
||||||
|
GRUB_FILE_FILTER_COMPRESSION_FIRST = GRUB_FILE_FILTER_GZIO,
|
||||||
|
GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_LZOPIO,
|
||||||
|
} grub_file_filter_id_t;
|
||||||
|
|
||||||
|
typedef grub_file_t (*grub_file_filter_t) (grub_file_t in, enum grub_file_type type);
|
||||||
|
|
||||||
|
extern grub_file_filter_t EXPORT_VAR(grub_file_filters)[GRUB_FILE_FILTER_MAX];
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
grub_file_filter_register (grub_file_filter_id_t id, grub_file_filter_t filter)
|
||||||
|
{
|
||||||
|
grub_file_filters[id] = filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
grub_file_filter_unregister (grub_file_filter_id_t id)
|
||||||
|
{
|
||||||
|
grub_file_filters[id] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get a device name from NAME. */
|
||||||
|
char *EXPORT_FUNC(grub_file_get_device_name) (const char *name);
|
||||||
|
|
||||||
|
int EXPORT_FUNC(ventoy_check_file_exist) (const char * fmt, ...);
|
||||||
|
grub_file_t EXPORT_FUNC(grub_file_open) (const char *name, enum grub_file_type type);
|
||||||
|
grub_ssize_t EXPORT_FUNC(grub_file_read) (grub_file_t file, void *buf,
|
||||||
|
grub_size_t len);
|
||||||
|
grub_off_t EXPORT_FUNC(grub_file_seek) (grub_file_t file, grub_off_t offset);
|
||||||
|
grub_err_t EXPORT_FUNC(grub_file_close) (grub_file_t file);
|
||||||
|
|
||||||
|
/* Return value of grub_file_size() in case file size is unknown. */
|
||||||
|
#define GRUB_FILE_SIZE_UNKNOWN 0xffffffffffffffffULL
|
||||||
|
|
||||||
|
static inline grub_off_t
|
||||||
|
grub_file_size (const grub_file_t file)
|
||||||
|
{
|
||||||
|
return file->size;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline grub_off_t
|
||||||
|
grub_file_tell (const grub_file_t file)
|
||||||
|
{
|
||||||
|
return file->offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
grub_file_seekable (const grub_file_t file)
|
||||||
|
{
|
||||||
|
return !file->not_easily_seekable;
|
||||||
|
}
|
||||||
|
|
||||||
|
grub_file_t
|
||||||
|
grub_file_offset_open (grub_file_t parent, enum grub_file_type type,
|
||||||
|
grub_off_t start, grub_off_t size);
|
||||||
|
void
|
||||||
|
grub_file_offset_close (grub_file_t file);
|
||||||
|
|
||||||
|
#endif /* ! GRUB_FILE_HEADER */
|
@@ -40,6 +40,15 @@ typedef enum ventoy_fs_type
|
|||||||
ventoy_fs_max
|
ventoy_fs_max
|
||||||
}ventoy_fs_type;
|
}ventoy_fs_type;
|
||||||
|
|
||||||
|
typedef enum ventoy_chain_type
|
||||||
|
{
|
||||||
|
ventoy_chain_linux = 0, /* 0: linux */
|
||||||
|
ventoy_chain_windows, /* 1: windows */
|
||||||
|
ventoy_chain_wim, /* 2: wim */
|
||||||
|
|
||||||
|
ventoy_chain_max
|
||||||
|
}ventoy_chain_type;
|
||||||
|
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
|
||||||
typedef struct ventoy_guid
|
typedef struct ventoy_guid
|
||||||
@@ -109,6 +118,9 @@ typedef struct ventoy_os_param
|
|||||||
*
|
*
|
||||||
* vtoy_reserved[0]: vtoy_break_level
|
* vtoy_reserved[0]: vtoy_break_level
|
||||||
* vtoy_reserved[1]: vtoy_debug_level
|
* vtoy_reserved[1]: vtoy_debug_level
|
||||||
|
* vtoy_reserved[2]: vtoy_chain_type 0:Linux 1:Windows 2:wimfile
|
||||||
|
* vtoy_reserved[3]: vtoy_iso_format 0:iso9660 1:udf
|
||||||
|
* vtoy_reserved[4]: vtoy_windows_cd_prompt
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
grub_uint8_t vtoy_reserved[32]; // Internal use by ventoy
|
grub_uint8_t vtoy_reserved[32]; // Internal use by ventoy
|
||||||
@@ -120,7 +132,8 @@ typedef struct ventoy_os_param
|
|||||||
typedef struct ventoy_windows_data
|
typedef struct ventoy_windows_data
|
||||||
{
|
{
|
||||||
char auto_install_script[384];
|
char auto_install_script[384];
|
||||||
grub_uint8_t reserved[128];
|
char injection_archive[384];
|
||||||
|
grub_uint8_t reserved[256];
|
||||||
}ventoy_windows_data;
|
}ventoy_windows_data;
|
||||||
|
|
||||||
|
|
||||||
@@ -201,12 +214,13 @@ typedef struct ventoy_img_chunk_list
|
|||||||
|
|
||||||
#define ventoy_filt_register grub_file_filter_register
|
#define ventoy_filt_register grub_file_filter_register
|
||||||
|
|
||||||
typedef const char * (*grub_env_get_pf)(const char *name);
|
|
||||||
|
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
|
||||||
#define GRUB_FILE_REPLACE_MAGIC 0x1258BEEF
|
#define GRUB_FILE_REPLACE_MAGIC 0x1258BEEF
|
||||||
|
|
||||||
|
typedef const char * (*grub_env_get_pf)(const char *name);
|
||||||
|
typedef int (*grub_env_printf_pf)(const char *fmt, ...);
|
||||||
|
|
||||||
typedef struct ventoy_grub_param_file_replace
|
typedef struct ventoy_grub_param_file_replace
|
||||||
{
|
{
|
||||||
grub_uint32_t magic;
|
grub_uint32_t magic;
|
||||||
@@ -218,8 +232,8 @@ typedef struct ventoy_grub_param_file_replace
|
|||||||
typedef struct ventoy_grub_param
|
typedef struct ventoy_grub_param
|
||||||
{
|
{
|
||||||
grub_env_get_pf grub_env_get;
|
grub_env_get_pf grub_env_get;
|
||||||
|
|
||||||
ventoy_grub_param_file_replace file_replace;
|
ventoy_grub_param_file_replace file_replace;
|
||||||
|
grub_env_printf_pf grub_env_printf;
|
||||||
}ventoy_grub_param;
|
}ventoy_grub_param;
|
||||||
|
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
@@ -227,6 +241,7 @@ typedef struct ventoy_grub_param
|
|||||||
|
|
||||||
int grub_ext_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_img_chunk_list *chunk_list);
|
int grub_ext_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_img_chunk_list *chunk_list);
|
||||||
int grub_fat_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_img_chunk_list *chunk_list);
|
int grub_fat_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_img_chunk_list *chunk_list);
|
||||||
|
void grub_iso9660_set_nojoliet(int nojoliet);
|
||||||
grub_uint64_t grub_iso9660_get_last_read_pos(grub_file_t file);
|
grub_uint64_t grub_iso9660_get_last_read_pos(grub_file_t file);
|
||||||
grub_uint64_t grub_iso9660_get_last_file_dirent_pos(grub_file_t file);
|
grub_uint64_t grub_iso9660_get_last_file_dirent_pos(grub_file_t file);
|
||||||
grub_uint64_t grub_udf_get_file_offset(grub_file_t file);
|
grub_uint64_t grub_udf_get_file_offset(grub_file_t file);
|
||||||
|
@@ -12,18 +12,17 @@ make install
|
|||||||
PATH=$PATH:$VT_DIR/GRUB2/INSTALL/bin/:$VT_DIR/GRUB2/INSTALL/sbin/
|
PATH=$PATH:$VT_DIR/GRUB2/INSTALL/bin/:$VT_DIR/GRUB2/INSTALL/sbin/
|
||||||
|
|
||||||
net_modules_legacy="net tftp http"
|
net_modules_legacy="net tftp http"
|
||||||
all_modules_legacy="date drivemap blocklist ext2 xfs ventoy chain read halt iso9660 linux16 test true sleep reboot echo video_colors video_cirrus video_bochs vga vbe video_fb font video gettext extcmd terminal linux minicmd help configfile tr trig boot biosdisk disk ls tar squash4 password_pbkdf2 all_video png jpeg part_msdos fat exfat ntfs loopback gzio normal udf gfxmenu gfxterm gfxterm_background gfxterm_menu"
|
all_modules_legacy="date drivemap blocklist vga_text ntldr search at_keyboard usb_keyboard gcry_md5 hashsum gzio xzio lzopio lspci pci ext2 xfs ventoy chain read halt iso9660 linux16 test true sleep reboot echo videotest videoinfo videotest_checksum video_colors video_cirrus video_bochs vga vbe video_fb font video gettext extcmd terminal linux minicmd help configfile tr trig boot biosdisk disk ls tar squash4 password_pbkdf2 all_video png jpeg part_gpt part_msdos fat exfat ntfs loopback gzio normal udf gfxmenu gfxterm gfxterm_background gfxterm_menu"
|
||||||
|
|
||||||
net_modules_uefi="efinet net tftp http"
|
net_modules_uefi="efinet net tftp http"
|
||||||
all_modules_uefi="blocklist ventoy test ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux relocator jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop efi_uga video_bochs video_cirrus video video_fb gfxterm_background gfxterm_menu"
|
all_modules_uefi="blocklist ventoy test search at_keyboard usb_keyboard gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux relocator jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop efi_uga video_bochs video_cirrus video video_fb gfxterm_background gfxterm_menu"
|
||||||
|
|
||||||
|
|
||||||
if [ "$1" = "uefi" ]; then
|
if [ "$1" = "uefi" ]; then
|
||||||
all_modules="$net_modules_uefi $all_modules_uefi"
|
all_modules="$net_modules_uefi $all_modules_uefi "
|
||||||
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi" --prefix '(,msdos2)/grub' --output "$VT_DIR/INSTALL/EFI/BOOT/grubx64_real.efi" --format 'x86_64-efi' --compression 'auto' $all_modules_uefi 'fat' 'part_msdos'
|
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/EFI/BOOT/grubx64_real.efi" --format 'x86_64-efi' --compression 'auto' $all_modules_uefi 'fat' 'part_msdos'
|
||||||
else
|
else
|
||||||
all_modules="$net_modules_legacy $all_modules_legacy"
|
all_modules="$net_modules_legacy $all_modules_legacy "
|
||||||
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc" --prefix '(,msdos2)/grub' --output "$VT_DIR/INSTALL/grub/i386-pc/core.img" --format 'i386-pc' --compression 'auto' $all_modules_legacy 'fat' 'part_msdos' 'biosdisk'
|
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/grub/i386-pc/core.img" --format 'i386-pc' --compression 'auto' $all_modules_legacy 'fat' 'part_msdos' 'biosdisk'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
grub-mknetdir --modules="$all_modules" --net-directory=$VT_DIR/GRUB2/PXE --subdir=grub2 --locales=en@quot || exit 1
|
grub-mknetdir --modules="$all_modules" --net-directory=$VT_DIR/GRUB2/PXE --subdir=grub2 --locales=en@quot || exit 1
|
||||||
@@ -33,11 +32,29 @@ if [ "$1" = "uefi" ]; then
|
|||||||
cp -a $VT_DIR/GRUB2/PXE/grub2/x86_64-efi/core.efi $VT_DIR/GRUB2/NBP/core.efi || exit 1
|
cp -a $VT_DIR/GRUB2/PXE/grub2/x86_64-efi/core.efi $VT_DIR/GRUB2/NBP/core.efi || exit 1
|
||||||
|
|
||||||
rm -f $VT_DIR/INSTALL/grub/x86_64-efi/normal.mod
|
rm -f $VT_DIR/INSTALL/grub/x86_64-efi/normal.mod
|
||||||
cp -a $VT_DIR/GRUB2/PXE/grub2/x86_64-efi/normal.mod $VT_DIR/INSTALL/grub/x86_64-efi/normal.mod || exit 1
|
cp -a $VT_DIR/GRUB2/PXE/grub2/x86_64-efi/normal.mod $VT_DIR/INSTALL/grub/x86_64-efi/normal.mod || exit 1
|
||||||
|
|
||||||
|
#copy other modules
|
||||||
|
ls -1 $VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi/ | egrep '\.(lst|mod)$' | while read line; do
|
||||||
|
if ! echo $all_modules | grep -q " ${line%.mod} "; then
|
||||||
|
echo "Copy $line ..."
|
||||||
|
rm -f $VT_DIR/INSTALL/grub/x86_64-efi/$line
|
||||||
|
cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi/$line $VT_DIR/INSTALL/grub/x86_64-efi/
|
||||||
|
fi
|
||||||
|
done
|
||||||
else
|
else
|
||||||
rm -f $VT_DIR/GRUB2/NBP/core.0
|
rm -f $VT_DIR/GRUB2/NBP/core.0
|
||||||
cp -a $VT_DIR/GRUB2/PXE/grub2/i386-pc/core.0 $VT_DIR/GRUB2/NBP/core.0 || exit 1
|
cp -a $VT_DIR/GRUB2/PXE/grub2/i386-pc/core.0 $VT_DIR/GRUB2/NBP/core.0 || exit 1
|
||||||
|
|
||||||
rm -f $VT_DIR/INSTALL/grub/i386-pc/boot.img
|
rm -f $VT_DIR/INSTALL/grub/i386-pc/boot.img
|
||||||
cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc/boot.img $VT_DIR/INSTALL/grub/i386-pc/boot.img || exit 1
|
cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc/boot.img $VT_DIR/INSTALL/grub/i386-pc/boot.img || exit 1
|
||||||
|
|
||||||
|
#copy other modules
|
||||||
|
ls -1 $VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc/ | egrep '\.(lst|mod)$' | while read line; do
|
||||||
|
if ! echo $all_modules | grep -q " ${line%.mod} "; then
|
||||||
|
echo "Copy $line ..."
|
||||||
|
rm -f $VT_DIR/INSTALL/grub/i386-pc/$line
|
||||||
|
cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc/$line $VT_DIR/INSTALL/grub/i386-pc/
|
||||||
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
BIN
ICON/forums.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
ICON/logo_128.png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
ICON/logo_16.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
ICON/logo_256.png
Normal file
After Width: | Height: | Size: 76 KiB |
BIN
ICON/logo_32.png
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
ICON/logo_48.png
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
ICON/logo_512.png
Normal file
After Width: | Height: | Size: 223 KiB |
BIN
ICON/logo_64.png
Normal file
After Width: | Height: | Size: 7.7 KiB |
BIN
ICON/logo_72.png
Normal file
After Width: | Height: | Size: 9.0 KiB |
@@ -19,19 +19,25 @@
|
|||||||
|
|
||||||
. /ventoy/hook/ventoy-hook-lib.sh
|
. /ventoy/hook/ventoy-hook-lib.sh
|
||||||
|
|
||||||
|
if is_ventoy_hook_finished; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
vtlog "####### $0 $* ########"
|
vtlog "####### $0 $* ########"
|
||||||
|
|
||||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||||
|
|
||||||
while ! [ -e /dev/null ]; do
|
wait_for_usb_disk_ready
|
||||||
echo 'xxxxxxxxxx'
|
|
||||||
echo 'xxxxxxxxxx' > /dev/console
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
|
|
||||||
vtlog "... start inotifyd listen $vtHook ..."
|
vtdiskname=$(get_ventoy_disk_name)
|
||||||
$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $VTOY_PATH/hook/guix/ventoy-disk.sh /dev:n 2>&- &
|
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
|
PATH=$VTPATH_OLD
|
||||||
|
|
||||||
|
set_ventoy_hook_finish
|
23
IMG/cpio/ventoy/hook/adelie/ventoy-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/>.
|
||||||
|
#
|
||||||
|
#************************************************************************************
|
||||||
|
|
||||||
|
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
||||||
|
|
||||||
|
$VTOY_PATH/hook/adelie/disk-hook.sh &
|
||||||
|
|
@@ -32,13 +32,14 @@ fi
|
|||||||
|
|
||||||
#
|
#
|
||||||
# We do a trick for ATL series here.
|
# We do a trick for ATL series here.
|
||||||
# Use /dev/loop7 and wapper it as a cdrom with bind mount.
|
# Use /dev/vtCheatLoop and wapper it as a cdrom with bind mount.
|
||||||
# Then the installer will accept /dev/loop7 as the install medium.
|
# Then the installer will accept /dev/vtCheatLoop as the install medium.
|
||||||
#
|
#
|
||||||
ventoy_copy_device_mapper /dev/loop7
|
vtCheatLoop=loop6
|
||||||
$BUSYBOX_PATH/mkdir -p /tmp/loop7/device/
|
ventoy_copy_device_mapper /dev/$vtCheatLoop
|
||||||
echo 5 > /tmp/loop7/device/type
|
$BUSYBOX_PATH/mkdir -p /tmp/$vtCheatLoop/device/
|
||||||
$BUSYBOX_PATH/mount --bind /tmp/loop7 /sys/block/loop7 >> $VTLOG 2>&1
|
echo 5 > /tmp/$vtCheatLoop/device/type
|
||||||
|
$BUSYBOX_PATH/mount --bind /tmp/$vtCheatLoop /sys/block/$vtCheatLoop >> $VTLOG 2>&1
|
||||||
|
|
||||||
|
|
||||||
# OK finish
|
# OK finish
|
||||||
|
42
IMG/cpio/ventoy/hook/android/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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# OK finish
|
||||||
|
set_ventoy_hook_finish
|
||||||
|
|
27
IMG/cpio/ventoy/hook/android/ventoy-hook.sh
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#!/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
|
||||||
|
|
||||||
|
if ! [ -d /dev ]; then
|
||||||
|
$BUSYBOX_PATH/mkdir /dev
|
||||||
|
fi
|
||||||
|
|
||||||
|
$SED "1a\export ROOT=/dev/mapper/ventoy" -i /init
|
||||||
|
$SED "/check_root \$device/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/android/ventoy-disk.sh" -i /init
|
50
IMG/cpio/ventoy/hook/arch/ovios-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
|
||||||
|
|
||||||
|
wait_for_usb_disk_ready
|
||||||
|
|
||||||
|
vtdiskname=$(get_ventoy_disk_name)
|
||||||
|
if [ "$vtdiskname" = "unknown" ]; then
|
||||||
|
vtlog "ventoy disk not found"
|
||||||
|
PATH=$VTPATH_OLD
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
|
||||||
|
|
||||||
|
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
|
||||||
|
blkdev_num_mknod=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
|
||||||
|
vtDM=$(ventoy_find_dm_id ${blkdev_num})
|
||||||
|
|
||||||
|
vtlog "blkdev_num=$blkdev_num blkdev_num_mknod=$blkdev_num_mknod vtDM=$vtDM"
|
||||||
|
|
||||||
|
if [ -b /dev/$vtDM ]; then
|
||||||
|
vtlog "dev already exist ..."
|
||||||
|
else
|
||||||
|
vtlog "mknode dev ..."
|
||||||
|
mknod -m 660 /dev/$vtDM b $blkdev_num_mknod
|
||||||
|
fi
|
||||||
|
|
||||||
|
PATH=$VTPATH_OLD
|
@@ -22,6 +22,18 @@
|
|||||||
if $GREP -q '^"$mount_handler"' /init; then
|
if $GREP -q '^"$mount_handler"' /init; then
|
||||||
echo 'use mount_handler ...' >> $VTLOG
|
echo 'use mount_handler ...' >> $VTLOG
|
||||||
$SED "/^\"\$mount_handler\"/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ventoy-disk.sh \"\$archisodevice\"" -i /init
|
$SED "/^\"\$mount_handler\"/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ventoy-disk.sh \"\$archisodevice\"" -i /init
|
||||||
|
|
||||||
|
if [ -f /hooks/archiso ]; then
|
||||||
|
$SED '/while ! poll_device "${dev}"/a\ if /ventoy/busybox/sh /ventoy/hook/arch/ventoy-timeout.sh ${dev}; then break; fi' -i /hooks/archiso
|
||||||
|
fi
|
||||||
|
elif $GREP -q '^KEEP_SEARCHING' /init; then
|
||||||
|
echo 'KEEP_SEARCHING found ...' >> $VTLOG
|
||||||
|
$SED "/^KEEP_SEARCHING/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ovios-disk.sh " -i /init
|
||||||
|
|
||||||
|
$BUSYBOX_PATH/mkdir -p /dev
|
||||||
|
$BUSYBOX_PATH/mkdir -p /sys
|
||||||
|
$BUSYBOX_PATH/mount -t sysfs sys /sys
|
||||||
|
|
||||||
else
|
else
|
||||||
# some archlinux initramfs doesn't contain device-mapper udev rules file
|
# some archlinux initramfs doesn't contain device-mapper udev rules file
|
||||||
ARCH_UDEV_DIR=$(ventoy_get_udev_conf_dir)
|
ARCH_UDEV_DIR=$(ventoy_get_udev_conf_dir)
|
||||||
|
36
IMG/cpio/ventoy/hook/arch/ventoy-timeout.sh
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#!/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 $* ############"
|
||||||
|
|
||||||
|
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 [ -b /dev/$vtDM ]; then
|
||||||
|
vtlog "ln -s /dev/$vtDM $1"
|
||||||
|
ln -s /dev/$vtDM "$1"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
vtlog "Device-mapper not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
47
IMG/cpio/ventoy/hook/cdlinux/disk-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 "####### $0 $* ########"
|
||||||
|
|
||||||
|
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||||
|
|
||||||
|
wait_for_usb_disk_ready
|
||||||
|
|
||||||
|
vtdiskname=$(get_ventoy_disk_name)
|
||||||
|
if [ "$vtdiskname" = "unknown" ]; then
|
||||||
|
vtlog "ventoy disk not found"
|
||||||
|
PATH=$VTPATH_OLD
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
|
||||||
|
|
||||||
|
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
|
||||||
|
mknod -m 0666 /dev/ventoy b $blkdev_num
|
||||||
|
|
||||||
|
|
||||||
|
PATH=$VTPATH_OLD
|
||||||
|
|
||||||
|
set_ventoy_hook_finish
|
43
IMG/cpio/ventoy/hook/cdlinux/ventoy-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/>.
|
||||||
|
#
|
||||||
|
#************************************************************************************
|
||||||
|
|
||||||
|
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
||||||
|
|
||||||
|
echo "CDlinux process..." >> $VTLOG
|
||||||
|
|
||||||
|
$BUSYBOX_PATH/mknod -m 0660 /ventoy/ram0 b 1 0
|
||||||
|
|
||||||
|
$BUSYBOX_PATH/mkdir /vtmnt /ventoy_rdroot
|
||||||
|
$BUSYBOX_PATH/mount -t squashfs /ventoy/ram0 /vtmnt
|
||||||
|
|
||||||
|
$BUSYBOX_PATH/mount -nt tmpfs -o mode=755 tmpfs /ventoy_rdroot
|
||||||
|
|
||||||
|
$BUSYBOX_PATH/cp -a /vtmnt/* /ventoy_rdroot
|
||||||
|
$BUSYBOX_PATH/ls -1a /vtmnt/ | $GREP '^\.[^.]' | while read vtLine; do
|
||||||
|
$BUSYBOX_PATH/cp -a /vtmnt/$vtLine /ventoy_rdroot
|
||||||
|
done
|
||||||
|
|
||||||
|
$BUSYBOX_PATH/umount /vtmnt && $BUSYBOX_PATH/rm -rf /vtmnt
|
||||||
|
$BUSYBOX_PATH/cp -a /ventoy /ventoy_rdroot
|
||||||
|
|
||||||
|
echo 'echo "CDL_DEV=/dev/mapper/ventoy" >>"$VAR_FILE"' >> /ventoy_rdroot/etc/rc.d/rc.var
|
||||||
|
|
||||||
|
ventoy_set_rule_dir_prefix /ventoy_rdroot
|
||||||
|
ventoy_systemd_udevd_work_around
|
||||||
|
ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k noreplace"
|
@@ -19,4 +19,10 @@
|
|||||||
|
|
||||||
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
. $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
|
if $GREP -q find_and_mount_installer /init; then
|
||||||
|
echo "find_and_mount_installer" >> $VTLOG
|
||||||
|
$SED "/find_and_mount_installer *$/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/clear/disk-hook.sh" -i /init
|
||||||
|
else
|
||||||
|
echo "find_installer" >> $VTLOG
|
||||||
|
$SED "/\$.*find_installer/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/clear/disk-hook.sh" -i /init
|
||||||
|
fi
|
||||||
|
52
IMG/cpio/ventoy/hook/cucumber/disk-hook.sh
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/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"
|
||||||
|
|
||||||
|
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 "mount media /dev/$vtDM ..."
|
||||||
|
if ! [ -e /media/install ]; then
|
||||||
|
mkdir -p /media/install
|
||||||
|
fi
|
||||||
|
mount /dev/$vtDM /media/install
|
||||||
|
|
||||||
|
PATH=$VTPATH_OLD
|
||||||
|
|
||||||
|
set_ventoy_hook_finish
|
26
IMG/cpio/ventoy/hook/cucumber/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
|
||||||
|
|
||||||
|
if [ -e /sbin/mount_installer ]; then
|
||||||
|
echo "hook at mount_installer ..." >> $VTLOG
|
||||||
|
$SED "1 a $BUSYBOX_PATH/sh $VTOY_PATH/hook/cucumber/disk-hook.sh" -i /sbin/mount_installer
|
||||||
|
fi
|
||||||
|
|
@@ -17,6 +17,8 @@
|
|||||||
#
|
#
|
||||||
#************************************************************************************
|
#************************************************************************************
|
||||||
|
|
||||||
|
CD_DETECT="/var/lib/dpkg/info/cdrom-detect.postinst"
|
||||||
|
|
||||||
if [ -e /init ] && $GREP -q '^mountroot$' /init; then
|
if [ -e /init ] && $GREP -q '^mountroot$' /init; then
|
||||||
echo "Here before mountroot ..." >> $VTLOG
|
echo "Here before mountroot ..." >> $VTLOG
|
||||||
|
|
||||||
@@ -29,7 +31,15 @@ if [ -e /init ] && $GREP -q '^mountroot$' /init; then
|
|||||||
$SED "s#^ *LIVEMEDIA=.*#LIVEMEDIA=/dev/mapper/ventoy#" -i /scripts/casper
|
$SED "s#^ *LIVEMEDIA=.*#LIVEMEDIA=/dev/mapper/ventoy#" -i /scripts/casper
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
elif [ -e "$CD_DETECT" ]; then
|
||||||
|
echo "$CD_DETECT exist, now add hook in it..." >> $VTLOG
|
||||||
|
|
||||||
|
$SED "1 a $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/disk_mount_hook.sh" -i "$CD_DETECT"
|
||||||
|
TITLE_LINE=$($GREP -m1 '^hw-detect.*detect_progress_title' "$CD_DETECT")
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "add $TITLE_LINE for hook" >> $VTLOG
|
||||||
|
$SED "1 a$TITLE_LINE" -i "$CD_DETECT"
|
||||||
|
fi
|
||||||
elif [ -e /init ] && $GREP -q '/start-udev$' /init; then
|
elif [ -e /init ] && $GREP -q '/start-udev$' /init; then
|
||||||
echo "Here use notify ..." >> $VTLOG
|
echo "Here use notify ..." >> $VTLOG
|
||||||
|
|
||||||
|
@@ -32,4 +32,5 @@ if [ "$vtdiskname" = "unknown" ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
vtlog "${vtdiskname#/dev/}2 found..."
|
||||||
$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/udev_disk_hook.sh "${vtdiskname#/dev/}2"
|
$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/udev_disk_hook.sh "${vtdiskname#/dev/}2"
|
||||||
|
71
IMG/cpio/ventoy/hook/debian/linuxconsole-disk.sh
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
#!/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
|
||||||
|
|
||||||
|
|
||||||
|
vtoydm -i -f $VTOY_PATH/ventoy_image_map -d $vtdiskname > $VTOY_PATH/iso_file_list
|
||||||
|
|
||||||
|
vtline=$(grep '[-][-] drivers-.*\.squashfs' $VTOY_PATH/iso_file_list)
|
||||||
|
sector=$(echo $vtline | awk '{print $(NF-1)}')
|
||||||
|
length=$(echo $vtline | awk '{print $NF}')
|
||||||
|
|
||||||
|
vtoydm -e -f $VTOY_PATH/ventoy_image_map -d $vtdiskname -s $sector -l $length -o $VTOY_PATH/driver.squashfs
|
||||||
|
mount -t squashfs $VTOY_PATH/driver.squashfs /lib/modules
|
||||||
|
modprobe dm-mod
|
||||||
|
|
||||||
|
umount /lib/modules
|
||||||
|
rm -f $VTOY_PATH/driver.squashfs
|
||||||
|
|
||||||
|
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
|
||||||
|
|
||||||
|
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
|
||||||
|
blkdev_dev=$($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 ! [ -b /dev/$vtDM ]; then
|
||||||
|
mknod -m 0660 /dev/$vtDM b $blkdev_dev
|
||||||
|
fi
|
||||||
|
|
||||||
|
if mount /dev/$vtDM /media/ydfs; then
|
||||||
|
vtlog "mount success"
|
||||||
|
else
|
||||||
|
vtlog "mount failed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
PATH=$VTPATH_OLD
|
||||||
|
|
||||||
|
set_ventoy_hook_finish
|
23
IMG/cpio/ventoy/hook/debian/linuxconsole-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 "s#/busybox/bin/sleep 2#/busybox/bin/sleep 10#" -i /etc/init.d/tty1
|
||||||
|
$SED "/install *-d *.media.ydfs/a return" -i /ydfs/detect/media
|
||||||
|
$SED "/install *-d *.media.ydfs/a $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/linuxconsole-disk.sh" -i /ydfs/detect/media
|
||||||
|
|
@@ -20,5 +20,11 @@
|
|||||||
$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/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
|
$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
|
if [ -e /init ] && $GREP -q '^mountroot$' /init; then
|
||||||
ventoy_add_udev_rule "$VTOY_PATH/hook/debian/udev_disk_hook.sh %k"
|
echo "Here before mountroot ..." >> $VTLOG
|
||||||
|
$SED "/^mountroot$/i\\$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/disk_mount_hook.sh" -i /init
|
||||||
|
else
|
||||||
|
echo "Use default hook ..." >> $VTLOG
|
||||||
|
ventoy_systemd_udevd_work_around
|
||||||
|
ventoy_add_udev_rule "$VTOY_PATH/hook/debian/udev_disk_hook.sh %k"
|
||||||
|
fi
|
||||||
|
@@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
ventoy_os_install_dmsetup() {
|
ventoy_os_install_dmsetup() {
|
||||||
|
|
||||||
|
vtlog "ventoy_os_install_dmsetup $1 ..."
|
||||||
|
|
||||||
vt_usb_disk=$1
|
vt_usb_disk=$1
|
||||||
|
|
||||||
# dump iso file location
|
# dump iso file location
|
||||||
@@ -48,7 +50,7 @@ ventoy_os_install_dmsetup() {
|
|||||||
if $GREP -q 'device-mapper' /proc/devices; then
|
if $GREP -q 'device-mapper' /proc/devices; then
|
||||||
vtlog "device mapper module is loaded"
|
vtlog "device mapper module is loaded"
|
||||||
else
|
else
|
||||||
vtlog"device mapper module is NOT loaded, now load it..."
|
vtlog "device mapper module is NOT loaded, now load it..."
|
||||||
|
|
||||||
VER=$($BUSYBOX_PATH/uname -r)
|
VER=$($BUSYBOX_PATH/uname -r)
|
||||||
KO=$($FIND /lib/modules/$VER/kernel/drivers/md -name "dm-mod*")
|
KO=$($FIND /lib/modules/$VER/kernel/drivers/md -name "dm-mod*")
|
||||||
@@ -97,7 +99,18 @@ ventoy_udev_disk_common_hook $*
|
|||||||
# So if ventoy is installed on a non-USB device, we just mount /cdrom here except
|
# So if ventoy is installed on a non-USB device, we just mount /cdrom here except
|
||||||
# for these has boot=live or boot=casper parameter in cmdline
|
# for these has boot=live or boot=casper parameter in cmdline
|
||||||
#
|
#
|
||||||
if echo $ID_BUS | $GREP -q -i usb; then
|
VT_BUS_USB=""
|
||||||
|
if [ -n "$ID_BUS" ]; then
|
||||||
|
if echo $ID_BUS | $GREP -q -i usb; then
|
||||||
|
VT_BUS_USB="YES"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if $BUSYBOX_PATH/ls -l /sys/class/block/${1:0:-1} | $GREP -q -i usb; then
|
||||||
|
VT_BUS_USB="YES"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$VT_BUS_USB" ]; then
|
||||||
vtlog "$1 is USB device"
|
vtlog "$1 is USB device"
|
||||||
else
|
else
|
||||||
vtlog "$1 is NOT USB device (bus $ID_BUS)"
|
vtlog "$1 is NOT USB device (bus $ID_BUS)"
|
||||||
|
@@ -60,6 +60,10 @@ ventoy_get_debian_distro() {
|
|||||||
echo 'porteus'; return
|
echo 'porteus'; return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if $GREP -q 'linuxconsole' /proc/version; then
|
||||||
|
echo 'linuxconsole'; return
|
||||||
|
fi
|
||||||
|
|
||||||
echo 'default'
|
echo 'default'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,13 +23,15 @@ if is_ventoy_hook_finished; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
vtlog "##### INOTIFYD: $2/$3 is created ..."
|
|
||||||
|
|
||||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||||
|
|
||||||
if is_inotify_ventoy_part $3; then
|
if is_inotify_ventoy_part $3; then
|
||||||
|
vtlog "##### INOTIFYD: $2/$3 is created (YES) ..."
|
||||||
vtlog "find ventoy partition $3 ..."
|
vtlog "find ventoy partition $3 ..."
|
||||||
$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/udev_disk_hook.sh "$3"
|
$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/udev_disk_hook.sh "$3"
|
||||||
|
else
|
||||||
|
vtlog "##### INOTIFYD: $2/$3 is created (NO)..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PATH=$VTPATH_OLD
|
PATH=$VTPATH_OLD
|
||||||
|
@@ -21,5 +21,11 @@
|
|||||||
|
|
||||||
vtHook=$($CAT $VTOY_PATH/inotifyd-hook-script.txt)
|
vtHook=$($CAT $VTOY_PATH/inotifyd-hook-script.txt)
|
||||||
|
|
||||||
vtlog "... start inotifyd listen $vtHook ..."
|
vtdisk=$(get_ventoy_disk_name)
|
||||||
$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $vtHook /dev:n 2>&- &
|
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
|
||||||
|
43
IMG/cpio/ventoy/hook/fatdog/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
|
23
IMG/cpio/ventoy/hook/fatdog/ventoy-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/>.
|
||||||
|
#
|
||||||
|
#************************************************************************************
|
||||||
|
|
||||||
|
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
||||||
|
|
||||||
|
$SED "/find_local_device *(/a $BUSYBOX_PATH/sh $VTOY_PATH/hook/fatdog/disk-hook.sh" -i /init
|
||||||
|
$SED "/find_and_choose_local_device *(/a $BUSYBOX_PATH/sh $VTOY_PATH/hook/fatdog/disk-hook.sh" -i /init
|
@@ -19,13 +19,11 @@
|
|||||||
|
|
||||||
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
||||||
|
|
||||||
if [ -d /etc/udev/rules.d ]; then
|
if $GREP -q kaspersky /proc/version; then
|
||||||
|
$SED "/sysresccd_stage1_normal[^(]*$/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/gentoo/disk_hook.sh" -i /init
|
||||||
|
elif [ -d /etc/udev/rules.d ] || [ -d /lib/udev/rules.d ]; then
|
||||||
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"
|
||||||
else
|
else
|
||||||
if $GREP -q kaspersky /proc/version; then
|
$SED "/mdev *-s/a\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/gentoo/disk_hook.sh" -i /init
|
||||||
$SED "/sysresccd_stage1_normal[^(]*$/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/gentoo/disk_hook.sh" -i /init
|
|
||||||
else
|
|
||||||
$SED "/mdev *-s/a\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/gentoo/disk_hook.sh" -i /init
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
@@ -23,11 +23,11 @@ if is_ventoy_hook_finished; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
vtlog "##### INOTIFYD: $2/$3 is created ..."
|
|
||||||
|
|
||||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||||
|
|
||||||
if is_inotify_ventoy_part $3; then
|
if is_inotify_ventoy_part $3; then
|
||||||
|
vtlog "##### INOTIFYD: $2/$3 is created (YES)..."
|
||||||
|
|
||||||
vtlog "find ventoy partition $3 ..."
|
vtlog "find ventoy partition $3 ..."
|
||||||
$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh $3 noreplace
|
$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh $3 noreplace
|
||||||
|
|
||||||
@@ -42,6 +42,8 @@ if is_inotify_ventoy_part $3; then
|
|||||||
# fi
|
# fi
|
||||||
|
|
||||||
set_ventoy_hook_finish
|
set_ventoy_hook_finish
|
||||||
|
else
|
||||||
|
vtlog "##### INOTIFYD: $2/$3 is created (NO)..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PATH=$VTPATH_OLD
|
PATH=$VTPATH_OLD
|
||||||
|
26
IMG/cpio/ventoy/hook/guix/ventoy-before-init.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
|
||||||
|
|
||||||
|
$BUSYBOX_PATH/mkdir /dev
|
||||||
|
$BUSYBOX_PATH/mknod -m 0660 /dev/null c 1 3
|
||||||
|
|
||||||
|
$BUSYBOX_PATH/sh $VTOY_PATH/hook/guix/ventoy-disk.sh &
|
||||||
|
|
@@ -19,24 +19,32 @@
|
|||||||
|
|
||||||
. /ventoy/hook/ventoy-hook-lib.sh
|
. /ventoy/hook/ventoy-hook-lib.sh
|
||||||
|
|
||||||
if is_ventoy_hook_finished; then
|
vtlog "######### $0 $* ############"
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
vtlog "##### INOTIFYD: $2/$3 is created ..."
|
|
||||||
|
|
||||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||||
|
|
||||||
if is_inotify_ventoy_part $3; then
|
wait_for_usb_disk_ready
|
||||||
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 ..."
|
vtdiskname=$(get_ventoy_disk_name)
|
||||||
|
if [ "$vtdiskname" = "unknown" ]; then
|
||||||
|
vtlog "ventoy disk not found"
|
||||||
|
PATH=$VTPATH_OLD
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
set_ventoy_hook_finish
|
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
|
||||||
|
|
||||||
|
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
|
||||||
|
blkdev_num_mknod=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
|
||||||
|
vtDM=$(ventoy_find_dm_id ${blkdev_num})
|
||||||
|
|
||||||
|
vtlog "blkdev_num=$blkdev_num blkdev_num_mknod=$blkdev_num_mknod vtDM=$vtDM"
|
||||||
|
|
||||||
|
if [ -b /dev/$vtDM ]; then
|
||||||
|
vtlog "dev already exist ..."
|
||||||
|
else
|
||||||
|
vtlog "mknode dev ..."
|
||||||
|
mknod -m 660 /dev/$vtDM b $blkdev_num_mknod
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PATH=$VTPATH_OLD
|
PATH=$VTPATH_OLD
|
||||||
|
@@ -18,8 +18,3 @@
|
|||||||
#************************************************************************************
|
#************************************************************************************
|
||||||
|
|
||||||
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
. $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 &
|
|
||||||
|
70
IMG/cpio/ventoy/hook/kiosk/ventoy-disk.sh
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
#!/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
|
||||||
|
|
||||||
|
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||||
|
|
||||||
|
ventoy_os_install_dmsetup_by_unsquashfs() {
|
||||||
|
vtlog "ventoy_os_install_dmsetup_by_unsquashfs $*"
|
||||||
|
|
||||||
|
vtKerVer=$(uname -r)
|
||||||
|
vtKoPo=$(ventoy_get_module_postfix)
|
||||||
|
vtlog "vtKerVer=$vtKerVer vtKoPo=$vtKoPo"
|
||||||
|
|
||||||
|
vtoydm -i -f $VTOY_PATH/ventoy_image_map -d $1 > $VTOY_PATH/iso_file_list
|
||||||
|
|
||||||
|
vtline=$(grep '[-][-] .*kernel.xzm ' $VTOY_PATH/iso_file_list)
|
||||||
|
sector=$(echo $vtline | awk '{print $(NF-1)}')
|
||||||
|
length=$(echo $vtline | awk '{print $NF}')
|
||||||
|
|
||||||
|
vtlog "vtline=$vtline sector=$sector length=$length"
|
||||||
|
|
||||||
|
vtoydm -e -f $VTOY_PATH/ventoy_image_map -d $1 -s $sector -l $length -o $VTOY_PATH/kernel.xzm
|
||||||
|
mkdir -p $VTOY_PATH/sqfs
|
||||||
|
mount $VTOY_PATH/kernel.xzm $VTOY_PATH/sqfs
|
||||||
|
|
||||||
|
dmModPath="/lib/modules/$vtKerVer/kernel/drivers/md/dm-mod.$vtKoPo"
|
||||||
|
|
||||||
|
if [ -e $VTOY_PATH/sqfs${dmModPath} ]; then
|
||||||
|
vtlog "success $VTOY_PATH/sqfs${dmModPath}"
|
||||||
|
insmod $VTOY_PATH/sqfs${dmModPath}
|
||||||
|
else
|
||||||
|
vterr "failed $VTOY_PATH/sqfs${dmModPath}"
|
||||||
|
false
|
||||||
|
fi
|
||||||
|
|
||||||
|
umount $VTOY_PATH/sqfs
|
||||||
|
rm -f $VTOY_PATH/kernel.xzm
|
||||||
|
}
|
||||||
|
|
||||||
|
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_by_unsquashfs $vtdiskname
|
||||||
|
|
||||||
|
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
|
||||||
|
|
||||||
|
PATH=$VTPATH_OLD
|
22
IMG/cpio/ventoy/hook/kiosk/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 '/^ *search [^(]*$/i\ /ventoy/busybox/sh /ventoy/hook/kiosk/ventoy-disk.sh' -i /init
|
43
IMG/cpio/ventoy/hook/kwort/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/kwort/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 "1 a $BUSYBOX_PATH/sh $VTOY_PATH/hook/kwort/disk-hook.sh" -i /etc/rc.d/init/media
|
@@ -1,7 +1,29 @@
|
|||||||
#!/ventoy/busybox/sh
|
#!/ventoy/busybox/sh
|
||||||
|
#************************************************************************************
|
||||||
|
# Copyright (c) 2020, longpanda <admin@ventoy.net>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License as
|
||||||
|
# published by the Free Software Foundation; either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
#************************************************************************************
|
||||||
|
|
||||||
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
||||||
|
|
||||||
ventoy_systemd_udevd_work_around
|
#ventoy_systemd_udevd_work_around
|
||||||
|
#ventoy_add_udev_rule "$VTOY_PATH/hook/mageia/udev_disk_hook.sh %k noreplace"
|
||||||
|
|
||||||
|
ventoy_set_inotify_script mageia/ventoy-inotifyd-hook.sh
|
||||||
|
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/mageia/ventoy-inotifyd-start.sh /lib/dracut/hooks/pre-udev/99-ventoy-inotifyd-start.sh
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ventoy_add_udev_rule "$VTOY_PATH/hook/mageia/udev_disk_hook.sh %k noreplace"
|
|
||||||
|
70
IMG/cpio/ventoy/hook/mageia/ventoy-inotifyd-hook.sh
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
#!/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
|
||||||
|
|
||||||
|
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||||
|
|
||||||
|
if is_inotify_ventoy_part $3; then
|
||||||
|
vtlog "##### INOTIFYD: $2/$3 is created (YES) ..."
|
||||||
|
|
||||||
|
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})
|
||||||
|
vtLABEL=$($BUSYBOX_PATH/blkid /dev/$vtDM | $AWK '{print $2}' | $SED 's/.*"\(.*\)".*/\1/')
|
||||||
|
|
||||||
|
vtlog "blkdev_num=$blkdev_num vtDM=$vtDM label $vtLABEL ..."
|
||||||
|
|
||||||
|
if [ -n "$vtLABEL" ]; then
|
||||||
|
$BUSYBOX_PATH/mkdir -p /dev/disk/by-label/
|
||||||
|
ln -s /dev/$vtDM /dev/disk/by-label/$vtLABEL
|
||||||
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# cheatcode for mageia
|
||||||
|
#
|
||||||
|
# From mageia/soft/drakx/mdk-stage1 source code, we see that the stage1 binary will search
|
||||||
|
# /tmp/syslog file to determin whether there is a DAC960 cdrom in the system.
|
||||||
|
# So we insert some string to /tmp/syslog file to cheat the stage1 program.
|
||||||
|
#
|
||||||
|
$BUSYBOX_PATH/mkdir -p /dev/rd
|
||||||
|
ventoy_copy_device_mapper "/dev/rd/ventoy"
|
||||||
|
echo 'ventoy cheatcode /dev/rd/ventoy: model' >> /tmp/syslog
|
||||||
|
|
||||||
|
if [ -e /sbin/mgalive-root ]; then
|
||||||
|
vtlog "set mgalive-root ..."
|
||||||
|
|
||||||
|
$BUSYBOX_PATH/cp -a $BUSYBOX_PATH/blkid /sbin/blkid
|
||||||
|
$BUSYBOX_PATH/mkdir -p /dev/mapper
|
||||||
|
ln -s /dev/$vtDM /dev/mapper/ventoy
|
||||||
|
/sbin/mgalive-root /dev/dm-0
|
||||||
|
fi
|
||||||
|
|
||||||
|
set_ventoy_hook_finish
|
||||||
|
else
|
||||||
|
vtlog "##### INOTIFYD: $2/$3 is created (NO) ..."
|
||||||
|
fi
|
||||||
|
|
||||||
|
PATH=$VTPATH_OLD
|
31
IMG/cpio/ventoy/hook/mageia/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
|
@@ -23,11 +23,10 @@ if is_ventoy_hook_finished; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
vtlog "##### INOTIFYD: $2/$3 is created ..."
|
|
||||||
|
|
||||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||||
|
|
||||||
if is_inotify_ventoy_part $3; then
|
if is_inotify_ventoy_part $3; then
|
||||||
|
vtlog "##### INOTIFYD: $2/$3 is created (YES) ..."
|
||||||
vtlog "find ventoy partition $3 ..."
|
vtlog "find ventoy partition $3 ..."
|
||||||
$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh "$3"
|
$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh "$3"
|
||||||
|
|
||||||
@@ -41,6 +40,8 @@ if is_inotify_ventoy_part $3; then
|
|||||||
mkdir -p /dev/disk/by-label
|
mkdir -p /dev/disk/by-label
|
||||||
fi
|
fi
|
||||||
$BUSYBOX_PATH/cp -a /dev/$vtDM /dev/disk/by-label/$vtLABEL
|
$BUSYBOX_PATH/cp -a /dev/$vtDM /dev/disk/by-label/$vtLABEL
|
||||||
|
else
|
||||||
|
vtlog "##### INOTIFYD: $2/$3 is created (NO) ..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PATH=$VTPATH_OLD
|
PATH=$VTPATH_OLD
|
||||||
|
48
IMG/cpio/ventoy/hook/parabola/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
|
||||||
|
|
44
IMG/cpio/ventoy/hook/parabola/ventoy-hook.sh
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#!/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
|
||||||
|
|
||||||
|
if $GREP -q '^"$mount_handler"' /init; then
|
||||||
|
echo 'use mount_handler ...' >> $VTLOG
|
||||||
|
$SED "/^\"\$mount_handler\"/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/parabola/ventoy-disk.sh \"\$parabolaisodevice\"" -i /init
|
||||||
|
|
||||||
|
if [ -f /hooks/parabolaiso ]; then
|
||||||
|
$SED '/while ! poll_device "${dev}"/a\ if /ventoy/busybox/sh /ventoy/hook/parabola/ventoy-timeout.sh ${dev}; then break; fi' -i /hooks/parabolaiso
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
# 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
|
36
IMG/cpio/ventoy/hook/parabola/ventoy-timeout.sh
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#!/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 $* ############"
|
||||||
|
|
||||||
|
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 [ -b /dev/$vtDM ]; then
|
||||||
|
vtlog "ln -s /dev/$vtDM $1"
|
||||||
|
ln -s /dev/$vtDM "$1"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
vtlog "Device-mapper not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
47
IMG/cpio/ventoy/hook/pmagic/disk-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 "####### $0 $* ########"
|
||||||
|
|
||||||
|
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||||
|
|
||||||
|
wait_for_usb_disk_ready
|
||||||
|
|
||||||
|
vtdiskname=$(get_ventoy_disk_name)
|
||||||
|
if [ "$vtdiskname" = "unknown" ]; then
|
||||||
|
vtlog "ventoy disk not found"
|
||||||
|
PATH=$VTPATH_OLD
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
|
||||||
|
|
||||||
|
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
|
||||||
|
mknod -m 0666 /dev/ventoy b $blkdev_num
|
||||||
|
|
||||||
|
|
||||||
|
PATH=$VTPATH_OLD
|
||||||
|
|
||||||
|
set_ventoy_hook_finish
|
@@ -23,18 +23,10 @@ if is_ventoy_hook_finished || not_ventoy_disk "${1:0:-1}"; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ventoy_udev_disk_common_hook $*
|
ventoy_udev_disk_common_hook $* "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
|
||||||
# cheatcode for mageia
|
|
||||||
#
|
|
||||||
# From mageia/soft/drakx/mdk-stage1 source code, we see that the stage1 binary will search
|
|
||||||
# /tmp/syslog file to determin whether there is a DAC960 cdrom in the system.
|
|
||||||
# So we insert some string to /tmp/syslog file to cheat the stage1 program.
|
|
||||||
#
|
|
||||||
$BUSYBOX_PATH/mkdir -p /dev/rd
|
|
||||||
ventoy_copy_device_mapper "/dev/rd/ventoy"
|
|
||||||
echo 'ventoy cheatcode /dev/rd/ventoy: model' >> /tmp/syslog
|
|
||||||
|
|
||||||
# OK finish
|
# OK finish
|
||||||
set_ventoy_hook_finish
|
set_ventoy_hook_finish
|
||||||
|
|
31
IMG/cpio/ventoy/hook/pmagic/ventoy-hook.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/>.
|
||||||
|
#
|
||||||
|
#************************************************************************************
|
||||||
|
|
||||||
|
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
||||||
|
|
||||||
|
if $GREP -q 'Searching *for *PMAGIC' /init; then
|
||||||
|
echo "Find Searching PMAGIC" >> $VTLOG
|
||||||
|
$SED "/Searching *for *PMAGIC/a\ root=/dev/ventoy" -i /init
|
||||||
|
$SED "/Searching *for *PMAGIC/a\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/pmagic/disk-hook.sh" -i /init
|
||||||
|
else
|
||||||
|
echo "Use default..." >> $VTLOG
|
||||||
|
$SED "s#^root=.*cmdline.*#root=/dev/ventoy#g'" -i /init
|
||||||
|
ventoy_systemd_udevd_work_around
|
||||||
|
ventoy_add_udev_rule "$VTOY_PATH/hook/pmagic/udev_disk_hook.sh %k"
|
||||||
|
fi
|
@@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
. /ventoy/hook/ventoy-hook-lib.sh
|
. /ventoy/hook/ventoy-hook-lib.sh
|
||||||
|
|
||||||
|
vtCheatLoop=loop6
|
||||||
|
|
||||||
ventoy_os_install_dmsetup() {
|
ventoy_os_install_dmsetup() {
|
||||||
vtlog "ventoy_os_install_dmsetup $1"
|
vtlog "ventoy_os_install_dmsetup $1"
|
||||||
|
|
||||||
@@ -50,9 +52,9 @@ ventoy_os_install_dmsetup() {
|
|||||||
|
|
||||||
|
|
||||||
if is_ventoy_hook_finished || not_ventoy_disk "${1:0:-1}"; then
|
if is_ventoy_hook_finished || not_ventoy_disk "${1:0:-1}"; then
|
||||||
# /dev/loop7 come first
|
# /dev/vtCheatLoop come first
|
||||||
if [ "$1" = "loop7" ] && [ -b $VTOY_DM_PATH ]; then
|
if [ "$1" = "$vtCheatLoop" ] && [ -b $VTOY_DM_PATH ]; then
|
||||||
ventoy_copy_device_mapper /dev/loop7
|
ventoy_copy_device_mapper /dev/$vtCheatLoop
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
@@ -64,7 +66,7 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
#some distro add there repo file to /etc/anaconda.repos.d/ which will cause error during installation
|
#some distro add there repo file to /etc/anaconda.repos.d/ which will cause error during installation
|
||||||
$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $VTOY_PATH/hook/rhel6/anaconda-repo-listen.sh /etc/anaconda.repos.d:n &
|
#$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $VTOY_PATH/hook/rhel6/anaconda-repo-listen.sh /etc/anaconda.repos.d:n &
|
||||||
|
|
||||||
ventoy_udev_disk_common_hook $* "noreplace"
|
ventoy_udev_disk_common_hook $* "noreplace"
|
||||||
|
|
||||||
@@ -72,14 +74,14 @@ $BUSYBOX_PATH/mount $VTOY_DM_PATH /mnt/ventoy
|
|||||||
|
|
||||||
#
|
#
|
||||||
# We do a trick for rhel6 series here.
|
# We do a trick for rhel6 series here.
|
||||||
# Use /dev/loop7 and wapper it as a removable cdrom with bind mount.
|
# Use /dev/$vtCheatLoop and wapper it as a removable cdrom with bind mount.
|
||||||
# Then the anaconda installer will accept /dev/loop7 as the install medium.
|
# Then the anaconda installer will accept /dev/$vtCheatLoop as the install medium.
|
||||||
#
|
#
|
||||||
ventoy_copy_device_mapper /dev/loop7
|
ventoy_copy_device_mapper /dev/$vtCheatLoop
|
||||||
|
|
||||||
$BUSYBOX_PATH/cp -a /sys/devices/virtual/block/loop7 /tmp/ >> $VTLOG 2>&1
|
$BUSYBOX_PATH/cp -a /sys/devices/virtual/block/$vtCheatLoop /tmp/ >> $VTLOG 2>&1
|
||||||
echo 19 > /tmp/loop7/capability
|
echo 19 > /tmp/$vtCheatLoop/capability
|
||||||
$BUSYBOX_PATH/mount --bind /tmp/loop7 /sys/block/loop7 >> $VTLOG 2>&1
|
$BUSYBOX_PATH/mount --bind /tmp/$vtCheatLoop /sys/block/$vtCheatLoop >> $VTLOG 2>&1
|
||||||
|
|
||||||
# OK finish
|
# OK finish
|
||||||
set_ventoy_hook_finish
|
set_ventoy_hook_finish
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
$BUSYBOX_PATH/mkdir -p /etc/anaconda.repos.d /mnt/ventoy
|
$BUSYBOX_PATH/mkdir -p /etc/anaconda.repos.d /mnt/ventoy
|
||||||
ventoy_print_yum_repo "ventoy" "file:///mnt/ventoy" > /etc/anaconda.repos.d/ventoy.repo
|
ventoy_print_yum_repo "ventoy" "file:///mnt/ventoy" > /etc/anaconda.repos.d/ventoy.repo
|
||||||
|
|
||||||
|
|
||||||
ventoy_add_udev_rule "$VTOY_PATH/hook/rhel6/udev_disk_hook.sh %k"
|
ventoy_add_udev_rule "$VTOY_PATH/hook/rhel6/udev_disk_hook.sh %k"
|
||||||
ventoy_add_kernel_udev_rule "loop7" "$VTOY_PATH/hook/rhel6/udev_disk_hook.sh %k"
|
|
||||||
|
#loop7 was used by loader
|
||||||
|
ventoy_add_kernel_udev_rule "loop6" "$VTOY_PATH/hook/rhel6/udev_disk_hook.sh %k"
|
||||||
|
@@ -31,7 +31,13 @@ else
|
|||||||
VTKS="inst.ks=hd:/dev/dm-0:$vtRawKs"
|
VTKS="inst.ks=hd:/dev/dm-0:$vtRawKs"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
if echo $vtParam | $GREP -q '^ks=.*:/'; then
|
||||||
|
vtRawKs=$(echo $vtParam | $AWK -F: '{print $NF}')
|
||||||
|
VTKS="ks=hd:/dev/dm-0:$vtRawKs"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "VTKS=$VTKS" >> $VTLOG
|
echo "VTKS=$VTKS" >> $VTLOG
|
||||||
@@ -44,8 +50,20 @@ fi
|
|||||||
|
|
||||||
ventoy_set_inotify_script rhel7/ventoy-inotifyd-hook.sh
|
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
|
#Fedora
|
||||||
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-timeout.sh /lib/dracut/hooks/initqueue/timeout/01-ventoy-timeout.sh
|
if $BUSYBOX_PATH/which dmsquash-live-root > /dev/null; then
|
||||||
|
vtPriority=99
|
||||||
|
else
|
||||||
|
vtPriority=01
|
||||||
|
fi
|
||||||
|
|
||||||
|
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-inotifyd-start.sh /lib/dracut/hooks/pre-udev/${vtPriority}-ventoy-inotifyd-start.sh
|
||||||
|
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-timeout.sh /lib/dracut/hooks/initqueue/timeout/${vtPriority}-ventoy-timeout.sh
|
||||||
|
|
||||||
|
if [ -e /sbin/dmsquash-live-root ]; then
|
||||||
|
echo "patch /sbin/dmsquash-live-root ..." >> $VTLOG
|
||||||
|
$SED "1 a $BUSYBOX_PATH/sh $VTOY_PATH/hook/rhel7/ventoy-make-link.sh" -i /sbin/dmsquash-live-root
|
||||||
|
fi
|
||||||
|
|
||||||
# suppress write protected mount warning
|
# suppress write protected mount warning
|
||||||
if [ -e /usr/sbin/anaconda-diskroot ]; then
|
if [ -e /usr/sbin/anaconda-diskroot ]; then
|
||||||
|
@@ -23,11 +23,21 @@ if is_ventoy_hook_finished; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
vtlog "##### INOTIFYD: $2/$3 is created ..."
|
|
||||||
|
|
||||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||||
|
|
||||||
if is_inotify_ventoy_part $3; then
|
if is_inotify_ventoy_part $3; then
|
||||||
|
|
||||||
|
vtlog "##### INOTIFYD: $2/$3 is created (YES) ..."
|
||||||
|
|
||||||
|
vtGenRulFile='/etc/udev/rules.d/99-live-squash.rules'
|
||||||
|
if [ -e $vtGenRulFile ] && $GREP -q dmsquash $vtGenRulFile; then
|
||||||
|
vtScript=$($GREP -m1 'RUN.=' $vtGenRulFile | $AWK -F'RUN.=' '{print $2}' | $SED 's/"\(.*\)".*/\1/')
|
||||||
|
vtlog "vtScript=$vtScript"
|
||||||
|
$vtScript
|
||||||
|
else
|
||||||
|
vtlog "$vtGenRulFile not exist..."
|
||||||
|
fi
|
||||||
|
|
||||||
vtlog "find ventoy partition ..."
|
vtlog "find ventoy partition ..."
|
||||||
$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh $3 noreplace
|
$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh $3 noreplace
|
||||||
|
|
||||||
@@ -41,10 +51,14 @@ if is_inotify_ventoy_part $3; then
|
|||||||
ventoy_swap_device /dev/dm-0 /dev/$vtDM
|
ventoy_swap_device /dev/dm-0 /dev/$vtDM
|
||||||
fi
|
fi
|
||||||
|
|
||||||
vtlog "set anaconda-diskroot ..."
|
if [ -e /sbin/anaconda-diskroot ]; then
|
||||||
/sbin/initqueue --settled --onetime --name anaconda-diskroot anaconda-diskroot /dev/dm-0
|
vtlog "set anaconda-diskroot ..."
|
||||||
|
/sbin/anaconda-diskroot /dev/dm-0
|
||||||
|
fi
|
||||||
|
|
||||||
set_ventoy_hook_finish
|
set_ventoy_hook_finish
|
||||||
|
else
|
||||||
|
vtlog "##### INOTIFYD: $2/$3 is created (NO) ..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PATH=$VTPATH_OLD
|
PATH=$VTPATH_OLD
|
||||||
|
35
IMG/cpio/ventoy/hook/rhel7/ventoy-make-link.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 ! [ -e /dev/mapper/ventoy ]; then
|
||||||
|
vtlog "link to /dev/mapper/ventoy"
|
||||||
|
ln -s /dev/dm-0 /dev/mapper/ventoy
|
||||||
|
fi
|
||||||
|
|
||||||
|
VTLABEL=$($BUSYBOX_PATH/blkid /dev/dm-0 | $SED 's/.*LABEL="\([^"]*\)".*/\1/')
|
||||||
|
vtlog "VTLABEL=$VTLABEL"
|
||||||
|
|
||||||
|
if [ -n "$VTLABEL" ]; then
|
||||||
|
if ! [ -e "/dev/disk/by-label/$VTLABEL" ]; then
|
||||||
|
vtlog "link to /dev/disk/by-label/$VTLABEL"
|
||||||
|
ln -s /dev/dm-0 "/dev/disk/by-label/$VTLABEL"
|
||||||
|
fi
|
||||||
|
fi
|
@@ -26,7 +26,9 @@ 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/')
|
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})
|
vtDM=$(ventoy_find_dm_id ${blkdev_num})
|
||||||
|
|
||||||
vtlog "diskroot $vtDM ..."
|
if [ -e /sbin/anaconda-diskroot ]; then
|
||||||
/sbin/initqueue --settled --onetime --name anaconda-diskroot anaconda-diskroot /dev/$vtDM
|
vtlog "set anaconda-diskroot ..."
|
||||||
|
/sbin/anaconda-diskroot /dev/dm-0
|
||||||
|
fi
|
||||||
|
|
||||||
PATH=$VTPATH_OLD
|
PATH=$VTPATH_OLD
|
||||||
|
63
IMG/cpio/ventoy/hook/vine/dev-listen.sh
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#!/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
|
||||||
|
|
||||||
|
while [ -n "1" ]; do
|
||||||
|
if [ -e /dev/null ]; then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
$SLEEP 0.5
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
while [ -n "1" ]; do
|
||||||
|
if [ -e /sys/block ]; then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
$SLEEP 0.5
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
while [ -n "Y" ]; do
|
||||||
|
vtdiskname=$(get_ventoy_disk_name)
|
||||||
|
if [ "$vtdiskname" != "unknown" ]; then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
$SLEEP 0.5
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
vtshortdev=${vtdiskname#/dev/}
|
||||||
|
|
||||||
|
if ! [ -b $vtdiskname ]; then
|
||||||
|
blkdev=$($CAT /sys/class/block/$vtshortdev/dev | $SED 's/:/ /g')
|
||||||
|
$BUSYBOX_PATH/mknod -m 0660 $vtdiskname b $blkdev
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! [ -b "${vtdiskname}2" ]; then
|
||||||
|
blkdev=$($CAT /sys/class/block/${vtshortdev}2/dev | $SED 's/:/ /g')
|
||||||
|
$BUSYBOX_PATH/mknod -m 0660 "${vtdiskname}2" b $blkdev
|
||||||
|
fi
|
||||||
|
|
||||||
|
$BUSYBOX_PATH/ls /dev/ > /dev/console
|
||||||
|
|
||||||
|
$BUSYBOX_PATH/sh $VTOY_PATH/hook/vine/udev_disk_hook.sh "${vtdiskname#/dev/}2"
|
||||||
|
|
||||||
|
|
79
IMG/cpio/ventoy/hook/vine/udev_disk_hook.sh
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
#!/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
|
||||||
|
|
||||||
|
vtCheatLoop=loop6
|
||||||
|
|
||||||
|
ventoy_os_install_dmsetup() {
|
||||||
|
vtlog "ventoy_os_install_dmsetup $1"
|
||||||
|
|
||||||
|
vt_usb_disk=$1
|
||||||
|
|
||||||
|
# dump iso file location
|
||||||
|
$VTOY_PATH/tool/vtoydm -i -f $VTOY_PATH/ventoy_image_map -d ${vt_usb_disk} > $VTOY_PATH/iso_file_list
|
||||||
|
|
||||||
|
# install dmsetup
|
||||||
|
LINE=$($GREP 'kernel-[0-9].*\.rpm' $VTOY_PATH/iso_file_list)
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
install_rpm_from_line "$LINE" ${vt_usb_disk}
|
||||||
|
fi
|
||||||
|
|
||||||
|
$BUSYBOX_PATH/modprobe dm-mod
|
||||||
|
|
||||||
|
vtlog "dmsetup install finish, now check it..."
|
||||||
|
|
||||||
|
dmsetup_path=/ventoy/tool/dmsetup
|
||||||
|
if [ -z "$dmsetup_path" ]; then
|
||||||
|
vterr "dmsetup still not found after install"
|
||||||
|
elif $dmsetup_path info >> $VTLOG 2>&1; then
|
||||||
|
vtlog "$dmsetup_path work ok"
|
||||||
|
else
|
||||||
|
vterr "$dmsetup_path not work"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if is_ventoy_hook_finished || not_ventoy_disk "${1:0:-1}"; then
|
||||||
|
# /dev/vtCheatLoop come first
|
||||||
|
if [ "$1" = "$vtCheatLoop" ] && [ -b $VTOY_DM_PATH ]; then
|
||||||
|
ventoy_copy_device_mapper /dev/$vtCheatLoop
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
ventoy_os_install_dmsetup "/dev/${1:0:-1}"
|
||||||
|
|
||||||
|
ventoy_udev_disk_common_hook $* "noreplace"
|
||||||
|
|
||||||
|
$BUSYBOX_PATH/mount $VTOY_DM_PATH /mnt/ventoy
|
||||||
|
|
||||||
|
#
|
||||||
|
# We do a trick for rhel6 series here.
|
||||||
|
# Use /dev/$vtCheatLoop and wapper it as a removable cdrom with bind mount.
|
||||||
|
# Then the anaconda installer will accept /dev/$vtCheatLoop as the install medium.
|
||||||
|
#
|
||||||
|
ventoy_copy_device_mapper /dev/$vtCheatLoop
|
||||||
|
|
||||||
|
$BUSYBOX_PATH/cp -a /sys/devices/virtual/block/$vtCheatLoop /tmp/ >> $VTLOG 2>&1
|
||||||
|
echo 19 > /tmp/$vtCheatLoop/capability
|
||||||
|
$BUSYBOX_PATH/mount --bind /tmp/$vtCheatLoop /sys/block/$vtCheatLoop >> $VTLOG 2>&1
|
||||||
|
|
||||||
|
# OK finish
|
||||||
|
set_ventoy_hook_finish
|
28
IMG/cpio/ventoy/hook/vine/ventoy-hook.sh
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#!/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 -p /etc/anaconda.repos.d /mnt/ventoy
|
||||||
|
ventoy_print_yum_repo "ventoy" "file:///mnt/ventoy" > /etc/anaconda.repos.d/ventoy.repo
|
||||||
|
|
||||||
|
|
||||||
|
$BUSYBOX_PATH/mknod -m 0660 /dev/null c 1 3
|
||||||
|
$VTOY_PATH/hook/vine/dev-listen.sh &
|
||||||
|
|
@@ -51,7 +51,17 @@ fi
|
|||||||
# #
|
# #
|
||||||
####################################################################
|
####################################################################
|
||||||
cd /
|
cd /
|
||||||
rm -rf /init /linuxrc /sbin /dev/ /root
|
rm -rf /init /linuxrc /dev/ /root
|
||||||
|
|
||||||
|
vtSbinFileNum=$(ls -1 /sbin | wc -l)
|
||||||
|
if [ $vtSbinFileNum -eq 1 ]; then
|
||||||
|
echo "remove whole sbin directory" >> $VTLOG
|
||||||
|
rm -rf /sbin
|
||||||
|
else
|
||||||
|
echo "remove only sbin/init file" >> $VTLOG
|
||||||
|
ls -l /sbin >> $VTLOG
|
||||||
|
rm -f /sbin/init
|
||||||
|
fi
|
||||||
|
|
||||||
ventoy_is_initrd_ramdisk() {
|
ventoy_is_initrd_ramdisk() {
|
||||||
#As I known, PCLinuxOS use ramdisk
|
#As I known, PCLinuxOS use ramdisk
|
||||||
@@ -62,6 +72,13 @@ ventoy_is_initrd_ramdisk() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ventoy_mount_squashfs() {
|
||||||
|
mkdir /dev
|
||||||
|
mount -t devtmpfs devtmpfs /dev
|
||||||
|
dd if=$1 of=/dev/ram0 status=none
|
||||||
|
umount /dev && rm -rf /dev
|
||||||
|
}
|
||||||
|
|
||||||
# param: file skip magic tmp
|
# param: file skip magic tmp
|
||||||
ventoy_unpack_initramfs() {
|
ventoy_unpack_initramfs() {
|
||||||
vtfile=$1; vtskip=$2; vtmagic=$3; vttmp=$4
|
vtfile=$1; vtskip=$2; vtmagic=$3; vttmp=$4
|
||||||
@@ -73,6 +90,11 @@ ventoy_unpack_initramfs() {
|
|||||||
# vtmagic='1F8B'
|
# vtmagic='1F8B'
|
||||||
#fi
|
#fi
|
||||||
|
|
||||||
|
if [ "${vtmagic:0:4}" = '6873' ]; then
|
||||||
|
ventoy_mount_squashfs $vtfile
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
for vtx in '1F8B zcat' '1F9E zcat' '425A bzcat' '5D00 lzcat' 'FD37 xzcat' '894C lzopcat' '0221 lz4cat' '28B5 zstdcat' '3037 cat'; do
|
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
|
if [ "${vtx:0:4}" = "${vtmagic:0:4}" ]; then
|
||||||
echo "vtx=$vtx" >> $VTLOG
|
echo "vtx=$vtx" >> $VTLOG
|
||||||
@@ -161,7 +183,40 @@ fi
|
|||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
# #
|
# #
|
||||||
# Step 3 : Hand over to ventoy.sh #
|
# Step 3 : Extract injection archive #
|
||||||
|
# #
|
||||||
|
####################################################################
|
||||||
|
ventoy_unpack_injection() {
|
||||||
|
vtmagic=$(hexdump -n 2 -e '2/1 "%02X"' $VTOY_PATH/ventoy_injection)
|
||||||
|
echo "ventoy_unpack_injection vtmagic=$vtmagic ..."
|
||||||
|
|
||||||
|
if [ "1F8B" = "$vtmagic" ] || [ "1F9E" = "$vtmagic" ]; then
|
||||||
|
echo "tar.gz tar -xzvf"
|
||||||
|
tar -xzvf $VTOY_PATH/ventoy_injection -C /
|
||||||
|
elif [ "425A" = "$vtmagic" ]; then
|
||||||
|
echo "tar.bz2 tar -xjvf"
|
||||||
|
tar -xjvf $VTOY_PATH/ventoy_injection -C /
|
||||||
|
elif [ "FD37" = "$vtmagic" ]; then
|
||||||
|
echo "tar.xz tar -xJvf"
|
||||||
|
tar -xJvf $VTOY_PATH/ventoy_injection -C /
|
||||||
|
elif [ "5D00" = "$vtmagic" ]; then
|
||||||
|
echo "tar.lzma tar -xavf"
|
||||||
|
tar -xavf $VTOY_PATH/ventoy_injection -C /
|
||||||
|
else
|
||||||
|
echo "unzip -o"
|
||||||
|
unzip -o $VTOY_PATH/ventoy_injection -d /
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -e $VTOY_PATH/ventoy_injection ]; then
|
||||||
|
echo "### decompress injection ... ###" >>$VTLOG
|
||||||
|
ventoy_unpack_injection > $VTOY_PATH/injection.log 2>&1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
####################################################################
|
||||||
|
# #
|
||||||
|
# Step 4 : Hand over to ventoy.sh #
|
||||||
# #
|
# #
|
||||||
####################################################################
|
####################################################################
|
||||||
echo "Now hand over to ventoy.sh" >>$VTLOG
|
echo "Now hand over to ventoy.sh" >>$VTLOG
|
||||||
|
@@ -87,6 +87,10 @@ ventoy_get_os_type() {
|
|||||||
elif $EGREP -q 'archlinux|ARCH' /proc/version; then
|
elif $EGREP -q 'archlinux|ARCH' /proc/version; then
|
||||||
echo 'arch'; return
|
echo 'arch'; return
|
||||||
|
|
||||||
|
# kiosk
|
||||||
|
elif $EGREP -q 'kiosk' /proc/version; then
|
||||||
|
echo 'kiosk'; return
|
||||||
|
|
||||||
# gentoo
|
# gentoo
|
||||||
elif $EGREP -q '[Gg]entoo' /proc/version; then
|
elif $EGREP -q '[Gg]entoo' /proc/version; then
|
||||||
echo 'gentoo'; return
|
echo 'gentoo'; return
|
||||||
@@ -129,8 +133,9 @@ ventoy_get_os_type() {
|
|||||||
if $GREP -q 'XenServer' /etc/os-release; then
|
if $GREP -q 'XenServer' /etc/os-release; then
|
||||||
echo 'xen'; return
|
echo 'xen'; return
|
||||||
elif $GREP -q 'SUSE ' /etc/os-release; then
|
elif $GREP -q 'SUSE ' /etc/os-release; then
|
||||||
echo 'suse'; return
|
echo 'suse'; return
|
||||||
|
elif $GREP -q 'uruk' /etc/os-release; then
|
||||||
|
echo 'debian'; return
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -184,6 +189,42 @@ ventoy_get_os_type() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if $GREP -q 'android.x86' /proc/version; then
|
||||||
|
echo 'android'; return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $GREP -q 'adelielinux' /proc/version; then
|
||||||
|
echo 'adelie'; return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $GREP -q 'pmagic' /proc/version; then
|
||||||
|
echo 'pmagic'; return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $GREP -q 'CDlinux' /proc/cmdline; then
|
||||||
|
echo 'cdlinux'; return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $GREP -q 'parabola' /proc/version; then
|
||||||
|
echo 'parabola'; return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $GREP -q 'cucumber' /proc/version; then
|
||||||
|
echo 'cucumber'; return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $GREP -q 'fatdog' /proc/version; then
|
||||||
|
echo 'fatdog'; return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $GREP -q 'KWORT' /proc/version; then
|
||||||
|
echo 'kwort'; return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $GREP -q 'iwamoto' /proc/version; then
|
||||||
|
echo 'vine'; return
|
||||||
|
fi
|
||||||
|
|
||||||
echo "default"
|
echo "default"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +252,6 @@ if [ "$VTOY_BREAK_LEVEL" = "03" ] || [ "$VTOY_BREAK_LEVEL" = "13" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
# #
|
# #
|
||||||
# Step 4 : Hand over to real init #
|
# Step 4 : Hand over to real init #
|
||||||
@@ -228,7 +268,8 @@ if [ -f $VTOY_PATH/ventoy_persistent_map ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
cd /
|
cd /
|
||||||
unset VTOY_PATH VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD
|
|
||||||
|
unset VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD
|
||||||
|
|
||||||
for vtinit in $user_rdinit /init /sbin/init /linuxrc; do
|
for vtinit in $user_rdinit /init /sbin/init /linuxrc; do
|
||||||
if [ -d /ventoy_rdroot ]; then
|
if [ -d /ventoy_rdroot ]; then
|
||||||
@@ -239,6 +280,9 @@ for vtinit in $user_rdinit /init /sbin/init /linuxrc; do
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ -e "$vtinit" ];then
|
if [ -e "$vtinit" ];then
|
||||||
|
if [ -f "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh" ]; then
|
||||||
|
$BUSYBOX_PATH/sh "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh"
|
||||||
|
fi
|
||||||
exec "$vtinit"
|
exec "$vtinit"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
77
INSTALL/CreatePersistentImg.sh
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
size=1024
|
||||||
|
fstype=ext4
|
||||||
|
label=casper-rw
|
||||||
|
|
||||||
|
print_usage() {
|
||||||
|
echo 'Usage: CreatePersistentImg.sh [ -s size ] [ -t fstype ] [ -l LABEL ]'
|
||||||
|
echo ' OPTION: (optional)'
|
||||||
|
echo ' -s size in MB, default is 1024'
|
||||||
|
echo ' -t filesystem type, default is ext4 ext2/ext3/ext4/xfs are supported now'
|
||||||
|
echo ' -l label, default is casper-rw'
|
||||||
|
echo ''
|
||||||
|
}
|
||||||
|
|
||||||
|
while [ -n "$1" ]; do
|
||||||
|
if [ "$1" = "-s" ]; then
|
||||||
|
shift
|
||||||
|
size=$1
|
||||||
|
elif [ "$1" = "-t" ]; then
|
||||||
|
shift
|
||||||
|
fstype=$1
|
||||||
|
elif [ "$1" = "-l" ]; then
|
||||||
|
shift
|
||||||
|
label=$1
|
||||||
|
else
|
||||||
|
print_usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
# check label
|
||||||
|
if [ -z "$label" ]; then
|
||||||
|
echo "The label can NOT be empty."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check size
|
||||||
|
if echo $size | grep -q "^[0-9][0-9]*$"; then
|
||||||
|
if [ $size -le 1 ]; then
|
||||||
|
echo "Invalid size $size"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Invalid size $size"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# check file system type
|
||||||
|
# nodiscard must be set for ext2/3/4
|
||||||
|
# -K must be set for xfs
|
||||||
|
if echo $fstype | grep -q '^ext[234]$'; then
|
||||||
|
fsopt='-E nodiscard'
|
||||||
|
elif [ "$fstype" = "xfs" ]; then
|
||||||
|
fsopt='-K'
|
||||||
|
else
|
||||||
|
echo "unsupported file system $fstype"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 00->ff avoid sparse file
|
||||||
|
dd if=/dev/zero bs=1M count=$size | tr '\000' '\377' > persistence.img
|
||||||
|
sync
|
||||||
|
|
||||||
|
freeloop=$(losetup -f)
|
||||||
|
|
||||||
|
losetup $freeloop persistence.img
|
||||||
|
|
||||||
|
mkfs -t $fstype $fsopt -L $label $freeloop
|
||||||
|
|
||||||
|
sync
|
||||||
|
|
||||||
|
losetup -d $freeloop
|
||||||
|
|