mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-09-18 09:51:15 +00:00
Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
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 |
@@ -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/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
|
||||
http://ultra-embedded.com/releases/fat_io_lib.zip ===> /home/Ventoy-master/vtoyfat/fat_io_lib/fat_io_lib.zip
|
||||
|
||||
|
||||
|
||||
@@ -199,5 +198,7 @@
|
||||
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
|
||||
|
||||
|
17
Dockerfile
Normal file
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
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -25,6 +25,15 @@
|
||||
|
||||
#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)
|
||||
|
||||
typedef struct ventoy_guid
|
||||
@@ -199,10 +208,8 @@ typedef struct vtoy_block_data
|
||||
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *pDiskFs;
|
||||
EFI_DEVICE_PATH_PROTOCOL *pDiskFsDevPath;
|
||||
|
||||
EFI_HANDLE IsoDriverImage;
|
||||
}vtoy_block_data;
|
||||
|
||||
#define ISO9660_EFI_DRIVER_PATH L"\\ventoy\\iso9660_x64.efi"
|
||||
|
||||
#define debug(expr, ...) if (gDebugPrint) VtoyDebug("[VTOY] "expr"\r\n", ##__VA_ARGS__)
|
||||
#define trace(expr, ...) VtoyDebug("[VTOY] "expr"\r\n", ##__VA_ARGS__)
|
||||
@@ -218,6 +225,7 @@ if (gDebugPrint) \
|
||||
}
|
||||
|
||||
typedef const char * (*grub_env_get_pf)(const char *name);
|
||||
typedef int (*grub_env_printf_pf)(const char *fmt, ...);
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
@@ -244,8 +252,8 @@ typedef struct 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;
|
||||
|
||||
typedef struct ventoy_ram_disk
|
||||
@@ -254,6 +262,14 @@ typedef struct ventoy_ram_disk
|
||||
UINT64 DiskSize;
|
||||
}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()
|
||||
|
||||
|
||||
@@ -273,6 +289,18 @@ typedef struct ventoy_system_wrapper
|
||||
|
||||
EFI_OPEN_PROTOCOL NewOpenProtocol;
|
||||
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;
|
||||
|
||||
#define ventoy_wrapper(bs, wrapper, func, newfunc) \
|
||||
@@ -282,11 +310,9 @@ typedef struct ventoy_system_wrapper
|
||||
bs->func = wrapper.New##func;\
|
||||
}
|
||||
|
||||
extern ventoy_efi_file_replace g_efi_file_replace;
|
||||
extern BOOLEAN gDebugPrint;
|
||||
VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...);
|
||||
EFI_STATUS EFIAPI ventoy_wrapper_system(VOID);
|
||||
EFI_STATUS EFIAPI ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL *File);
|
||||
EFI_STATUS EFIAPI ventoy_block_io_read
|
||||
(
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
@@ -296,5 +322,37 @@ EFI_STATUS EFIAPI ventoy_block_io_read
|
||||
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
|
||||
|
||||
|
@@ -29,6 +29,7 @@
|
||||
Ventoy.h
|
||||
Ventoy.c
|
||||
VentoyDebug.c
|
||||
VentoyProtocol.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
|
@@ -36,6 +36,10 @@
|
||||
#include <Protocol/SimpleFileSystem.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 struct well_known_guid g_efi_well_known_guids[] =
|
||||
@@ -84,183 +88,6 @@ static const char * ventoy_get_guid_name(EFI_GUID *guid)
|
||||
return gEfiGuidName;
|
||||
}
|
||||
|
||||
EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_fs_open(EFI_FILE_HANDLE This, EFI_FILE_HANDLE *New, CHAR16 *Name, UINT64 Mode, UINT64 Attributes)
|
||||
{
|
||||
(VOID)This;
|
||||
(VOID)New;
|
||||
(VOID)Name;
|
||||
(VOID)Mode;
|
||||
(VOID)Attributes;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_open_ex(EFI_FILE_HANDLE This, EFI_FILE_HANDLE *New, CHAR16 *Name, UINT64 Mode, UINT64 Attributes, EFI_FILE_IO_TOKEN *Token)
|
||||
{
|
||||
return ventoy_wrapper_fs_open(This, New, Name, Mode, Attributes);
|
||||
}
|
||||
|
||||
EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_delete(EFI_FILE_HANDLE This)
|
||||
{
|
||||
(VOID)This;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_set_info(EFI_FILE_HANDLE This, EFI_GUID *Type, UINTN Len, VOID *Data)
|
||||
{
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_flush(EFI_FILE_HANDLE This)
|
||||
{
|
||||
(VOID)This;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/* Ex version */
|
||||
EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_flush_ex(EFI_FILE_HANDLE This, EFI_FILE_IO_TOKEN *Token)
|
||||
{
|
||||
(VOID)This;
|
||||
(VOID)Token;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_write(EFI_FILE_HANDLE This, UINTN *Len, VOID *Data)
|
||||
{
|
||||
(VOID)This;
|
||||
(VOID)Len;
|
||||
(VOID)Data;
|
||||
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_write_ex(IN EFI_FILE_PROTOCOL *This, IN OUT EFI_FILE_IO_TOKEN *Token)
|
||||
{
|
||||
return ventoy_wrapper_file_write(This, &(Token->BufferSize), Token->Buffer);
|
||||
}
|
||||
|
||||
|
||||
static EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_close(EFI_FILE_HANDLE This)
|
||||
{
|
||||
(VOID)This;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_set_pos(EFI_FILE_HANDLE This, UINT64 Position)
|
||||
{
|
||||
(VOID)This;
|
||||
|
||||
g_efi_file_replace.CurPos = Position;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
static EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_get_pos(EFI_FILE_HANDLE This, UINT64 *Position)
|
||||
{
|
||||
(VOID)This;
|
||||
|
||||
*Position = g_efi_file_replace.CurPos;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_get_info(EFI_FILE_HANDLE This, EFI_GUID *Type, UINTN *Len, VOID *Data)
|
||||
{
|
||||
EFI_FILE_INFO *Info = (EFI_FILE_INFO *) Data;
|
||||
|
||||
debug("ventoy_wrapper_file_get_info ... %u", *Len);
|
||||
|
||||
if (!CompareGuid(Type, &gEfiFileInfoGuid))
|
||||
{
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (*Len == 0)
|
||||
{
|
||||
*Len = 384;
|
||||
return EFI_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
ZeroMem(Data, sizeof(EFI_FILE_INFO));
|
||||
|
||||
Info->Size = sizeof(EFI_FILE_INFO);
|
||||
Info->FileSize = g_efi_file_replace.FileSizeBytes;
|
||||
Info->PhysicalSize = g_efi_file_replace.FileSizeBytes;
|
||||
Info->Attribute = EFI_FILE_READ_ONLY;
|
||||
//Info->FileName = EFI_FILE_READ_ONLY;
|
||||
|
||||
*Len = Info->Size;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
static EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_read(EFI_FILE_HANDLE This, UINTN *Len, VOID *Data)
|
||||
{
|
||||
EFI_LBA Lba;
|
||||
UINTN ReadLen = *Len;
|
||||
|
||||
(VOID)This;
|
||||
|
||||
debug("ventoy_wrapper_file_read ... %u", *Len);
|
||||
|
||||
if (g_efi_file_replace.CurPos + ReadLen > g_efi_file_replace.FileSizeBytes)
|
||||
{
|
||||
ReadLen = g_efi_file_replace.FileSizeBytes - g_efi_file_replace.CurPos;
|
||||
}
|
||||
|
||||
Lba = g_efi_file_replace.CurPos / 2048 + g_efi_file_replace.BlockIoSectorStart;
|
||||
|
||||
ventoy_block_io_read(NULL, 0, Lba, ReadLen, Data);
|
||||
|
||||
*Len = ReadLen;
|
||||
|
||||
g_efi_file_replace.CurPos += ReadLen;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_read_ex(IN EFI_FILE_PROTOCOL *This, IN OUT EFI_FILE_IO_TOKEN *Token)
|
||||
{
|
||||
return ventoy_wrapper_file_read(This, &(Token->BufferSize), Token->Buffer);
|
||||
}
|
||||
|
||||
EFI_STATUS EFIAPI ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL *File)
|
||||
{
|
||||
File->Revision = EFI_FILE_PROTOCOL_REVISION2;
|
||||
File->Open = ventoy_wrapper_fs_open;
|
||||
File->Close = ventoy_wrapper_file_close;
|
||||
File->Delete = ventoy_wrapper_file_delete;
|
||||
File->Read = ventoy_wrapper_file_read;
|
||||
File->Write = ventoy_wrapper_file_write;
|
||||
File->GetPosition = ventoy_wrapper_file_get_pos;
|
||||
File->SetPosition = ventoy_wrapper_file_set_pos;
|
||||
File->GetInfo = ventoy_wrapper_file_get_info;
|
||||
File->SetInfo = ventoy_wrapper_file_set_info;
|
||||
File->Flush = ventoy_wrapper_file_flush;
|
||||
File->OpenEx = ventoy_wrapper_file_open_ex;
|
||||
File->ReadEx = ventoy_wrapper_file_read_ex;
|
||||
File->WriteEx = ventoy_wrapper_file_write_ex;
|
||||
File->FlushEx = ventoy_wrapper_file_flush_ex;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
STATIC EFI_STATUS EFIAPI ventoy_handle_protocol
|
||||
(
|
||||
IN EFI_HANDLE Handle,
|
||||
@@ -270,7 +97,7 @@ STATIC EFI_STATUS EFIAPI ventoy_handle_protocol
|
||||
{
|
||||
EFI_STATUS Status = EFI_SUCCESS;
|
||||
|
||||
debug("ventoy_handle_protocol:%a", ventoy_get_guid_name(Protocol));
|
||||
debug("ventoy_handle_protocol:%a", ventoy_get_guid_name(Protocol)); debug_sleep();
|
||||
Status = g_system_wrapper.OriHandleProtocol(Handle, Protocol, Interface);
|
||||
|
||||
if (CompareGuid(Protocol, &gEfiSimpleFileSystemProtocolGuid))
|
||||
@@ -280,7 +107,7 @@ STATIC EFI_STATUS EFIAPI ventoy_handle_protocol
|
||||
|
||||
pFile->OpenVolume(pFile, &FileProtocol);
|
||||
|
||||
debug("Handle FS Protocol: %p OpenVolume:%p, FileProtocol:%p, Open:%p",
|
||||
trace("Handle FS Protocol: %p OpenVolume:%p, FileProtocol:%p, Open:%p",
|
||||
pFile, pFile->OpenVolume, FileProtocol, FileProtocol->Open);
|
||||
|
||||
sleep(3);
|
||||
@@ -299,7 +126,7 @@ STATIC EFI_STATUS EFIAPI ventoy_open_protocol
|
||||
IN UINT32 Attributes
|
||||
)
|
||||
{
|
||||
debug("ventoy_open_protocol:%a", ventoy_get_guid_name(Protocol));
|
||||
debug("ventoy_open_protocol:<%p> %a", Handle, ventoy_get_guid_name(Protocol)); debug_sleep();
|
||||
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
|
||||
)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
ventoy_wrapper(gBS, g_system_wrapper, LocateProtocol, ventoy_locate_protocol);
|
||||
ventoy_wrapper(gBS, g_system_wrapper, HandleProtocol, ventoy_handle_protocol);
|
||||
ventoy_wrapper(gBS, g_system_wrapper, OpenProtocol, ventoy_open_protocol);
|
||||
ventoy_wrapper(gBS, g_system_wrapper, LocateProtocol, ventoy_locate_protocol);
|
||||
ventoy_wrapper(gBS, g_system_wrapper, HandleProtocol, ventoy_handle_protocol);
|
||||
ventoy_wrapper(gBS, g_system_wrapper, OpenProtocol, ventoy_open_protocol);
|
||||
ventoy_wrapper(gBS, g_system_wrapper, 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;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -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]
|
||||
MdeModulePkg/Application/Ventoy/Ventoy.inf
|
||||
MdeModulePkg/Application/VtoyUtil/VtoyUtil.inf
|
||||
MdeModulePkg/Application/HelloWorld/HelloWorld.inf
|
||||
MdeModulePkg/Application/DumpDynPcd/DumpDynPcd.inf
|
||||
MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.inf
|
||||
|
491
GRUB2/MOD_SRC/grub-2.04/grub-core/commands/test.c
Normal file
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;
|
||||
};
|
||||
|
||||
int g_ventoy_case_insensitive = 0;
|
||||
|
||||
/* Helper for grub_fshelp_find_file. */
|
||||
static int
|
||||
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;
|
||||
|
||||
if (g_ventoy_case_insensitive)
|
||||
{
|
||||
filetype |= GRUB_FSHELP_CASE_INSENSITIVE;
|
||||
}
|
||||
|
||||
if (filetype == GRUB_FSHELP_UNKNOWN ||
|
||||
((filetype & GRUB_FSHELP_CASE_INSENSITIVE)
|
||||
? grub_strcasecmp (ctx->name, filename)
|
||||
|
@@ -32,6 +32,7 @@
|
||||
|
||||
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_offset = 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] == 0x45))) /* UCS-2 Level 3. */
|
||||
{
|
||||
copy_voldesc = 1;
|
||||
data->joliet = 1;
|
||||
if (0 == g_ventoy_no_joliet) {
|
||||
copy_voldesc = 1;
|
||||
data->joliet = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (copy_voldesc)
|
||||
@@ -1108,6 +1111,11 @@ grub_iso9660_mtime (grub_device_t device, grub_int32_t *timebuf)
|
||||
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)
|
||||
{
|
||||
(void)file;
|
||||
|
@@ -27,7 +27,7 @@
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/ventoy.h>
|
||||
|
||||
#define GRUB_CACHE_TIMEOUT 2
|
||||
#define GRUB_CACHE_TIMEOUT 10
|
||||
|
||||
/* The last time the disk was used. */
|
||||
static grub_uint64_t grub_last_time = 0;
|
||||
|
@@ -83,6 +83,29 @@ grub_file_t grub_memfile_open(const char *name)
|
||||
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_open (const char *name, enum grub_file_type type)
|
||||
{
|
||||
|
@@ -260,6 +260,45 @@ reclaim_module_space (void)
|
||||
#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. */
|
||||
void __attribute__ ((noreturn))
|
||||
grub_main (void)
|
||||
@@ -293,6 +332,12 @@ grub_main (void)
|
||||
grub_env_export ("root");
|
||||
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_module_space ();
|
||||
|
||||
|
@@ -38,9 +38,10 @@ int g_ventoy_menu_refresh = 0;
|
||||
int g_ventoy_memdisk_mode = 0;
|
||||
int g_ventoy_iso_raw = 0;
|
||||
int g_ventoy_iso_uefi_drv = 0;
|
||||
int g_ventoy_last_entry = 0;
|
||||
int g_ventoy_last_entry = -1;
|
||||
int g_ventoy_suppress_esc = 0;
|
||||
int g_ventoy_menu_esc = 0;
|
||||
int g_ventoy_fn_mutex = 0;
|
||||
|
||||
/* Time to delay after displaying an error message about a default/fallback
|
||||
entry failing to boot. */
|
||||
@@ -802,39 +803,53 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
goto refresh;
|
||||
|
||||
case GRUB_TERM_KEY_F2:
|
||||
cmdstr = grub_env_get("VTOY_F2_CMD");
|
||||
if (cmdstr)
|
||||
{
|
||||
menu_fini ();
|
||||
grub_script_execute_sourcecode(cmdstr);
|
||||
goto refresh;
|
||||
if (0 == g_ventoy_fn_mutex) {
|
||||
cmdstr = grub_env_get("VTOY_F2_CMD");
|
||||
if (cmdstr)
|
||||
{
|
||||
menu_fini ();
|
||||
g_ventoy_fn_mutex = 1;
|
||||
grub_script_execute_sourcecode(cmdstr);
|
||||
g_ventoy_fn_mutex = 0;
|
||||
goto refresh;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GRUB_TERM_KEY_F3:
|
||||
cmdstr = grub_env_get("VTOY_F3_CMD");
|
||||
if (cmdstr)
|
||||
{
|
||||
menu_fini ();
|
||||
grub_script_execute_sourcecode(cmdstr);
|
||||
goto refresh;
|
||||
if (0 == g_ventoy_fn_mutex) {
|
||||
cmdstr = grub_env_get("VTOY_F3_CMD");
|
||||
if (cmdstr)
|
||||
{
|
||||
menu_fini ();
|
||||
grub_script_execute_sourcecode(cmdstr);
|
||||
goto refresh;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GRUB_TERM_KEY_F4:
|
||||
cmdstr = grub_env_get("VTOY_F4_CMD");
|
||||
if (cmdstr)
|
||||
{
|
||||
menu_fini ();
|
||||
grub_script_execute_sourcecode(cmdstr);
|
||||
goto refresh;
|
||||
if (0 == g_ventoy_fn_mutex) {
|
||||
cmdstr = grub_env_get("VTOY_F4_CMD");
|
||||
if (cmdstr)
|
||||
{
|
||||
menu_fini ();
|
||||
g_ventoy_fn_mutex = 1;
|
||||
grub_script_execute_sourcecode(cmdstr);
|
||||
g_ventoy_fn_mutex = 0;
|
||||
goto refresh;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GRUB_TERM_KEY_F5:
|
||||
cmdstr = grub_env_get("VTOY_F5_CMD");
|
||||
if (cmdstr)
|
||||
{
|
||||
menu_fini ();
|
||||
grub_script_execute_sourcecode(cmdstr);
|
||||
goto refresh;
|
||||
if (0 == g_ventoy_fn_mutex) {
|
||||
cmdstr = grub_env_get("VTOY_F5_CMD");
|
||||
if (cmdstr)
|
||||
{
|
||||
menu_fini ();
|
||||
g_ventoy_fn_mutex = 1;
|
||||
grub_script_execute_sourcecode(cmdstr);
|
||||
g_ventoy_fn_mutex = 0;
|
||||
goto refresh;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GRUB_TERM_KEY_F6:
|
||||
|
@@ -68,6 +68,8 @@ img_iterator_node *g_img_iterator_tail = NULL;
|
||||
|
||||
grub_uint8_t g_ventoy_break_level = 0;
|
||||
grub_uint8_t g_ventoy_debug_level = 0;
|
||||
grub_uint8_t g_ventoy_chain_type = 0;
|
||||
|
||||
grub_uint8_t *g_ventoy_cpio_buf = NULL;
|
||||
grub_uint32_t g_ventoy_cpio_size = 0;
|
||||
cpio_newc_header *g_ventoy_initrd_head = NULL;
|
||||
@@ -89,6 +91,15 @@ static int g_tree_script_pos = 0;
|
||||
static char *g_list_script_buf = NULL;
|
||||
static int g_list_script_pos = 0;
|
||||
|
||||
static const char *g_menu_class[] =
|
||||
{
|
||||
"vtoyiso", "vtoywim", "vtoyefi", "vtoyimg"
|
||||
};
|
||||
|
||||
static const char *g_menu_prefix[] =
|
||||
{
|
||||
"iso", "wim", "efi", "img"
|
||||
};
|
||||
|
||||
void ventoy_debug(const char *fmt, ...)
|
||||
{
|
||||
@@ -433,6 +444,27 @@ static grub_err_t ventoy_cmd_load_iso_to_mem(grub_extcmd_context_t ctxt, int arg
|
||||
return rc;
|
||||
}
|
||||
|
||||
static grub_err_t ventoy_cmd_iso9660_nojoliet(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
(void)ctxt;
|
||||
|
||||
if (argc != 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args[0][0] == '1')
|
||||
{
|
||||
grub_iso9660_set_nojoliet(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_iso9660_set_nojoliet(0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t ventoy_cmd_is_udf(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int i;
|
||||
@@ -784,6 +816,12 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
|
||||
{
|
||||
type = img_type_wim;
|
||||
}
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
else if (0 == grub_strcasecmp(filename + len - 4, ".efi"))
|
||||
{
|
||||
type = img_type_efi;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
@@ -809,12 +847,12 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
|
||||
}
|
||||
}
|
||||
|
||||
grub_snprintf(img->path, sizeof(img->path), "%s%s", node->dir, img->name);
|
||||
img->pathlen = grub_snprintf(img->path, sizeof(img->path), "%s%s", node->dir, img->name);
|
||||
|
||||
img->size = info->size;
|
||||
if (0 == img->size)
|
||||
{
|
||||
img->size = ventoy_grub_get_file_size("%s/%s", g_iso_path, img->path);
|
||||
img->size = ventoy_grub_get_file_size("%s/%s%s", g_iso_path, node->dir, filename);
|
||||
}
|
||||
|
||||
if (img->size < VTOY_FILT_MIN_FILE_SIZE)
|
||||
@@ -853,6 +891,14 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
|
||||
*((img_info **)(node->tail)) = img;
|
||||
g_ventoy_img_count++;
|
||||
|
||||
img->alias = ventoy_plugin_get_menu_alias(vtoy_alias_image_file, img->path);
|
||||
img->class = ventoy_plugin_get_menu_class(vtoy_class_image_file, img->name);
|
||||
if (!img->class)
|
||||
{
|
||||
img->class = g_menu_class[type];
|
||||
}
|
||||
img->menu_prefix = g_menu_prefix[type];
|
||||
|
||||
debug("Add %s%s to list %d\n", node->dir, filename, g_ventoy_img_count);
|
||||
}
|
||||
}
|
||||
@@ -983,7 +1029,9 @@ static img_iterator_node * ventoy_get_min_child(img_iterator_node *node)
|
||||
static int ventoy_dynamic_tree_menu(img_iterator_node *node)
|
||||
{
|
||||
int offset = 1;
|
||||
img_info *img;
|
||||
img_info *img = NULL;
|
||||
const char *dir_class = NULL;
|
||||
const char *dir_alias = NULL;
|
||||
img_iterator_node *child = NULL;
|
||||
|
||||
if (node->isocnt == 0 || node->done == 1)
|
||||
@@ -1001,7 +1049,7 @@ static int ventoy_dynamic_tree_menu(img_iterator_node *node)
|
||||
if (g_default_menu_mode == 0)
|
||||
{
|
||||
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos,
|
||||
"menuentry \"%-10s [Return to ListView]\" VTOY_RET {\n "
|
||||
"menuentry \"%-10s [Return to ListView]\" --class=\"vtoyret\" VTOY_RET {\n "
|
||||
" echo 'return ...' \n"
|
||||
"}\n", "<--");
|
||||
}
|
||||
@@ -1009,12 +1057,28 @@ static int ventoy_dynamic_tree_menu(img_iterator_node *node)
|
||||
else
|
||||
{
|
||||
node->dir[node->dirlen - 1] = 0;
|
||||
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos,
|
||||
"submenu \"%-10s [%s]\" {\n",
|
||||
"DIR", node->dir + offset);
|
||||
dir_class = ventoy_plugin_get_menu_class(vtoy_class_directory, node->dir);
|
||||
if (!dir_class)
|
||||
{
|
||||
dir_class = "vtoydir";
|
||||
}
|
||||
|
||||
dir_alias = ventoy_plugin_get_menu_alias(vtoy_alias_directory, node->dir);
|
||||
if (dir_alias)
|
||||
{
|
||||
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos,
|
||||
"submenu \"%-10s %s\" --class=\"%s\" {\n",
|
||||
"DIR", dir_alias, dir_class);
|
||||
}
|
||||
else
|
||||
{
|
||||
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos,
|
||||
"submenu \"%-10s [%s]\" --class=\"%s\" {\n",
|
||||
"DIR", node->dir + offset, dir_class);
|
||||
}
|
||||
|
||||
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos,
|
||||
"menuentry \"%-10s [../]\" VTOY_RET {\n "
|
||||
"menuentry \"%-10s [../]\" --class=\"vtoyret\" VTOY_RET {\n "
|
||||
" echo 'return ...' \n"
|
||||
"}\n", "<--");
|
||||
}
|
||||
@@ -1027,12 +1091,13 @@ static int ventoy_dynamic_tree_menu(img_iterator_node *node)
|
||||
while ((img = ventoy_get_min_iso(node)) != NULL)
|
||||
{
|
||||
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos,
|
||||
"menuentry \"%-10s %s%s\" --id=\"VID_%d\" {\n"
|
||||
"menuentry \"%-10s %s%s\" --class=\"%s\" --id=\"VID_%d\" {\n"
|
||||
" %s_%s \n"
|
||||
"}\n",
|
||||
grub_get_human_size(img->size, GRUB_HUMAN_SIZE_SHORT),
|
||||
img->unsupport ? "[unsupported] " : "", img->name, img->id,
|
||||
(img->type == img_type_iso) ? "iso" : "wim",
|
||||
img->unsupport ? "[unsupported] " : "",
|
||||
img->alias ? img->alias : img->name, img->class, img->id,
|
||||
img->menu_prefix,
|
||||
img->unsupport ? "unsupport_menuentry" : "common_menuentry");
|
||||
}
|
||||
|
||||
@@ -1052,8 +1117,11 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
|
||||
grub_device_t dev = NULL;
|
||||
img_info *cur = NULL;
|
||||
img_info *tail = NULL;
|
||||
img_info *default_node = NULL;
|
||||
const char *strdata = NULL;
|
||||
char *device_name = NULL;
|
||||
const char *default_image = NULL;
|
||||
int img_len = 0;
|
||||
char buf[32];
|
||||
img_iterator_node *node = NULL;
|
||||
img_iterator_node *tmp = NULL;
|
||||
@@ -1115,7 +1183,7 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
|
||||
if (strdata && strdata[0] == '/')
|
||||
{
|
||||
len = grub_snprintf(g_img_iterator_head.dir, sizeof(g_img_iterator_head.dir) - 1, "%s", strdata);
|
||||
if (g_img_iterator_head.dir[len] != '/')
|
||||
if (g_img_iterator_head.dir[len - 1] != '/')
|
||||
{
|
||||
g_img_iterator_head.dir[len++] = '/';
|
||||
}
|
||||
@@ -1163,21 +1231,45 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
|
||||
if (g_default_menu_mode == 1)
|
||||
{
|
||||
vtoy_ssprintf(g_list_script_buf, g_list_script_pos,
|
||||
"menuentry \"%s [Return to TreeView]\" VTOY_RET {\n "
|
||||
"menuentry \"%s [Return to TreeView]\" --class=\"vtoyret\" VTOY_RET {\n "
|
||||
" echo 'return ...' \n"
|
||||
"}\n", "<--");
|
||||
}
|
||||
|
||||
if (g_default_menu_mode == 0)
|
||||
{
|
||||
default_image = ventoy_get_env("VTOY_DEFAULT_IMAGE");
|
||||
if (default_image)
|
||||
{
|
||||
img_len = grub_strlen(default_image);
|
||||
}
|
||||
}
|
||||
|
||||
for (cur = g_ventoy_img_list; cur; cur = cur->next)
|
||||
{
|
||||
vtoy_ssprintf(g_list_script_buf, g_list_script_pos,
|
||||
"menuentry \"%s%s\" --id=\"VID_%d\" {\n"
|
||||
"menuentry \"%s%s\" --class=\"%s\" --id=\"VID_%d\" {\n"
|
||||
" %s_%s \n"
|
||||
"}\n",
|
||||
cur->unsupport ? "[unsupported] " : "", cur->name, cur->id,
|
||||
(cur->type == img_type_iso) ? "iso" : "wim",
|
||||
cur->unsupport ? "[unsupported] " : "",
|
||||
cur->alias ? cur->alias : cur->name, cur->class, cur->id,
|
||||
cur->menu_prefix,
|
||||
cur->unsupport ? "unsupport_menuentry" : "common_menuentry");
|
||||
|
||||
if (g_default_menu_mode == 0 && default_image && default_node == NULL)
|
||||
{
|
||||
if (img_len == cur->pathlen && grub_strcmp(default_image, cur->path) == 0)
|
||||
{
|
||||
default_node = cur;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (default_node)
|
||||
{
|
||||
vtoy_ssprintf(g_list_script_buf, g_list_script_pos, "set default='VID_%d'\n", default_node->id);
|
||||
}
|
||||
|
||||
g_list_script_buf[g_list_script_pos] = 0;
|
||||
|
||||
grub_snprintf(buf, sizeof(buf), "%d", g_ventoy_img_count);
|
||||
@@ -1394,6 +1486,8 @@ int ventoy_has_efi_eltorito(grub_file_t file, grub_uint32_t sector)
|
||||
void ventoy_fill_os_param(grub_file_t file, ventoy_os_param *param)
|
||||
{
|
||||
char *pos;
|
||||
const char *fs = NULL;
|
||||
const char *cdprompt = NULL;
|
||||
grub_uint32_t i;
|
||||
grub_uint8_t chksum = 0;
|
||||
grub_disk_t disk;
|
||||
@@ -1420,6 +1514,25 @@ void ventoy_fill_os_param(grub_file_t file, ventoy_os_param *param)
|
||||
param->vtoy_reserved[0] = g_ventoy_break_level;
|
||||
param->vtoy_reserved[1] = g_ventoy_debug_level;
|
||||
|
||||
param->vtoy_reserved[2] = g_ventoy_chain_type;
|
||||
|
||||
/* Windows CD/DVD prompt 0:suppress 1:reserved */
|
||||
param->vtoy_reserved[4] = 0;
|
||||
if (g_ventoy_chain_type == 1) /* Windows */
|
||||
{
|
||||
cdprompt = ventoy_get_env("VTOY_WINDOWS_CD_PROMPT");
|
||||
if (cdprompt && cdprompt[0] == '1' && cdprompt[1] == 0)
|
||||
{
|
||||
param->vtoy_reserved[4] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
fs = ventoy_get_env("ventoy_fs_probe");
|
||||
if (fs && grub_strcmp(fs, "udf") == 0)
|
||||
{
|
||||
param->vtoy_reserved[3] = 1;
|
||||
}
|
||||
|
||||
/* calculate checksum */
|
||||
for (i = 0; i < sizeof(ventoy_os_param); i++)
|
||||
{
|
||||
@@ -1567,6 +1680,8 @@ static grub_err_t ventoy_cmd_sel_auto_install(grub_extcmd_context_t ctxt, int ar
|
||||
(void)argc;
|
||||
(void)args;
|
||||
|
||||
debug("select auto installation argc:%d\n", argc);
|
||||
|
||||
if (argc < 1)
|
||||
{
|
||||
return 0;
|
||||
@@ -1575,6 +1690,14 @@ static grub_err_t ventoy_cmd_sel_auto_install(grub_extcmd_context_t ctxt, int ar
|
||||
node = ventoy_plugin_find_install_template(args[0]);
|
||||
if (!node)
|
||||
{
|
||||
debug("Auto install template not found for %s\n", args[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (node->autosel >= 0 && node->autosel <= node->templatenum)
|
||||
{
|
||||
node->cursel = node->autosel - 1;
|
||||
debug("Auto install template auto select %d\n", node->autosel);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1622,6 +1745,8 @@ static grub_err_t ventoy_cmd_sel_persistence(grub_extcmd_context_t ctxt, int arg
|
||||
(void)argc;
|
||||
(void)args;
|
||||
|
||||
debug("select persistence argc:%d\n", argc);
|
||||
|
||||
if (argc < 1)
|
||||
{
|
||||
return 0;
|
||||
@@ -1630,6 +1755,14 @@ static grub_err_t ventoy_cmd_sel_persistence(grub_extcmd_context_t ctxt, int arg
|
||||
node = ventoy_plugin_find_persistent(args[0]);
|
||||
if (!node)
|
||||
{
|
||||
debug("Persistence image not found for %s\n", args[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (node->autosel >= 0 && node->autosel <= node->backendnum)
|
||||
{
|
||||
node->cursel = node->autosel - 1;
|
||||
debug("Persistence image auto select %d\n", node->autosel);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1854,6 +1987,24 @@ static grub_err_t ventoy_cmd_dump_menu(grub_extcmd_context_t ctxt, int argc, cha
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t ventoy_cmd_dump_img_list(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
img_info *cur = g_ventoy_img_list;
|
||||
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
(void)args;
|
||||
|
||||
while (cur)
|
||||
{
|
||||
grub_printf("path:<%s> id=%d\n", cur->path, cur->id);
|
||||
grub_printf("name:<%s>\n\n", cur->name);
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t ventoy_cmd_dump_auto_install(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
(void)ctxt;
|
||||
@@ -1962,6 +2113,31 @@ static grub_err_t ventoy_cmd_dynamic_menu(grub_extcmd_context_t ctxt, int argc,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t ventoy_cmd_file_exist_nocase(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
grub_file_t file;
|
||||
|
||||
(void)ctxt;
|
||||
|
||||
if (argc != 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_ventoy_case_insensitive = 1;
|
||||
file = grub_file_open(args[0], VENTOY_FILE_TYPE);
|
||||
g_ventoy_case_insensitive = 0;
|
||||
|
||||
grub_errno = 0;
|
||||
|
||||
if (file)
|
||||
{
|
||||
grub_file_close(file);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static grub_err_t ventoy_cmd_find_bootable_hdd(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int id = 0;
|
||||
@@ -2102,6 +2278,32 @@ int ventoy_is_file_exist(const char *fmt, ...)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ventoy_is_dir_exist(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int len;
|
||||
char *pos = NULL;
|
||||
char buf[256] = {0};
|
||||
|
||||
grub_snprintf(buf, sizeof(buf), "%s", "[ -d ");
|
||||
pos = buf + 5;
|
||||
|
||||
va_start (ap, fmt);
|
||||
len = grub_vsnprintf(pos, 255, fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
grub_strncpy(pos + len, " ]", 2);
|
||||
|
||||
debug("script exec %s\n", buf);
|
||||
|
||||
if (0 == grub_script_execute_sourcecode(buf))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_env_init(void)
|
||||
{
|
||||
char buf[64];
|
||||
@@ -2109,6 +2311,8 @@ static int ventoy_env_init(void)
|
||||
grub_env_set("vtdebug_flag", "");
|
||||
grub_env_export("vtdebug_flag");
|
||||
|
||||
|
||||
|
||||
g_tree_script_buf = grub_malloc(VTOY_MAX_SCRIPT_BUF);
|
||||
g_list_script_buf = grub_malloc(VTOY_MAX_SCRIPT_BUF);
|
||||
|
||||
@@ -2118,6 +2322,7 @@ static int ventoy_env_init(void)
|
||||
if (g_grub_param)
|
||||
{
|
||||
g_grub_param->grub_env_get = grub_env_get;
|
||||
g_grub_param->grub_env_printf = (grub_env_printf_pf)grub_printf;
|
||||
grub_snprintf(buf, sizeof(buf), "%p", g_grub_param);
|
||||
grub_env_set("env_param", buf);
|
||||
}
|
||||
@@ -2146,11 +2351,13 @@ static cmd_para ventoy_cmds[] =
|
||||
{ "vt_dump_menu", ventoy_cmd_dump_menu, 0, NULL, "", "", NULL },
|
||||
{ "vt_dynamic_menu", ventoy_cmd_dynamic_menu, 0, NULL, "", "", NULL },
|
||||
{ "vt_check_mode", ventoy_cmd_check_mode, 0, NULL, "", "", NULL },
|
||||
{ "vt_dump_img_list", ventoy_cmd_dump_img_list, 0, NULL, "", "", NULL },
|
||||
{ "vt_dump_auto_install", ventoy_cmd_dump_auto_install, 0, NULL, "", "", NULL },
|
||||
{ "vt_dump_persistence", ventoy_cmd_dump_persistence, 0, NULL, "", "", NULL },
|
||||
{ "vt_select_auto_install", ventoy_cmd_sel_auto_install, 0, NULL, "", "", NULL },
|
||||
{ "vt_select_persistence", ventoy_cmd_sel_persistence, 0, NULL, "", "", NULL },
|
||||
|
||||
{ "vt_iso9660_nojoliet", ventoy_cmd_iso9660_nojoliet, 0, NULL, "", "", NULL },
|
||||
{ "vt_is_udf", ventoy_cmd_is_udf, 0, NULL, "", "", NULL },
|
||||
{ "vt_file_size", ventoy_cmd_file_size, 0, NULL, "", "", NULL },
|
||||
{ "vt_load_iso_to_mem", ventoy_cmd_load_iso_to_mem, 0, NULL, "", "", NULL },
|
||||
@@ -2164,18 +2371,25 @@ static cmd_para ventoy_cmds[] =
|
||||
{ "vt_linux_valid_initrd_count", ventoy_cmd_valid_initrd_count, 0, NULL, "", "", NULL },
|
||||
{ "vt_linux_locate_initrd", ventoy_cmd_linux_locate_initrd, 0, NULL, "", "", NULL },
|
||||
{ "vt_linux_chain_data", ventoy_cmd_linux_chain_data, 0, NULL, "", "", NULL },
|
||||
{ "vt_linux_get_main_initrd_index", ventoy_cmd_linux_get_main_initrd_index, 0, NULL, "", "", NULL },
|
||||
|
||||
{ "vt_windows_reset", ventoy_cmd_wimdows_reset, 0, NULL, "", "", NULL },
|
||||
{ "vt_windows_locate_wim", ventoy_cmd_wimdows_locate_wim, 0, NULL, "", "", NULL },
|
||||
{ "vt_windows_chain_data", ventoy_cmd_windows_chain_data, 0, NULL, "", "", NULL },
|
||||
{ "vt_windows_collect_wim_patch", ventoy_cmd_collect_wim_patch, 0, NULL, "", "", NULL },
|
||||
{ "vt_windows_locate_wim_patch", ventoy_cmd_locate_wim_patch, 0, NULL, "", "", NULL },
|
||||
{ "vt_windows_count_wim_patch", ventoy_cmd_wim_patch_count, 0, NULL, "", "", NULL },
|
||||
{ "vt_dump_wim_patch", ventoy_cmd_dump_wim_patch, 0, NULL, "", "", NULL },
|
||||
{ "vt_wim_chain_data", ventoy_cmd_wim_chain_data, 0, NULL, "", "", NULL },
|
||||
|
||||
{ "vt_add_replace_file", ventoy_cmd_add_replace_file, 0, NULL, "", "", NULL },
|
||||
{ "vt_relocator_chaindata", ventoy_cmd_relocator_chaindata, 0, NULL, "", "", NULL },
|
||||
{ "vt_test_block_list", ventoy_cmd_test_block_list, 0, NULL, "", "", NULL },
|
||||
{ "vt_file_exist_nocase", ventoy_cmd_file_exist_nocase, 0, NULL, "", "", NULL },
|
||||
|
||||
|
||||
{ "vt_load_plugin", ventoy_cmd_load_plugin, 0, NULL, "", "", NULL },
|
||||
{ "vt_check_plugin_json", ventoy_cmd_plugin_check_json, 0, NULL, "", "", NULL },
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@@ -127,11 +127,19 @@ typedef struct ventoy_udf_override
|
||||
|
||||
#define img_type_iso 0
|
||||
#define img_type_wim 1
|
||||
#define img_type_efi 2
|
||||
#define img_type_img 3
|
||||
|
||||
typedef struct img_info
|
||||
{
|
||||
int pathlen;
|
||||
char path[512];
|
||||
char name[256];
|
||||
|
||||
const char *alias;
|
||||
const char *class;
|
||||
const char *menu_prefix;
|
||||
|
||||
int id;
|
||||
int type;
|
||||
grub_uint64_t size;
|
||||
@@ -217,6 +225,7 @@ void ventoy_debug(const char *fmt, ...);
|
||||
#define FLAG_HEADER_COMPRESS_RESERVED 0x00010000
|
||||
#define FLAG_HEADER_COMPRESS_XPRESS 0x00020000
|
||||
#define FLAG_HEADER_COMPRESS_LZX 0x00040000
|
||||
#define FLAG_HEADER_COMPRESS_LZMS 0x00080000
|
||||
|
||||
#define RESHDR_FLAG_FREE 0x01
|
||||
#define RESHDR_FLAG_METADATA 0x02
|
||||
@@ -363,6 +372,19 @@ typedef struct wim_tail
|
||||
grub_uint32_t new_lookup_align_len;
|
||||
}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
|
||||
@@ -412,11 +434,13 @@ typedef struct _JSON_PARSE
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
const char *key;
|
||||
ventoy_plugin_entry_pf entryfunc;
|
||||
ventoy_plugin_check_pf checkfunc;
|
||||
}plugin_entry;
|
||||
|
||||
|
||||
@@ -437,12 +461,13 @@ int ventoy_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, co
|
||||
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_dir_exist(const char *fmt, ...);
|
||||
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_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_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
|
||||
(
|
||||
@@ -577,6 +602,7 @@ typedef struct install_template
|
||||
int pathlen;
|
||||
char isopath[256];
|
||||
|
||||
int autosel;
|
||||
int cursel;
|
||||
int templatenum;
|
||||
file_fullpath *templatepath;
|
||||
@@ -589,6 +615,7 @@ typedef struct persistence_config
|
||||
int pathlen;
|
||||
char isopath[256];
|
||||
|
||||
int autosel;
|
||||
int cursel;
|
||||
int backendnum;
|
||||
file_fullpath *backendpath;
|
||||
@@ -596,12 +623,40 @@ typedef struct persistence_config
|
||||
struct persistence_config *next;
|
||||
}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;
|
||||
|
||||
extern int g_ventoy_menu_esc;
|
||||
extern int g_ventoy_suppress_esc;
|
||||
extern int g_ventoy_last_entry;
|
||||
extern int g_ventoy_memdisk_mode;
|
||||
extern int g_ventoy_iso_raw;
|
||||
extern int g_ventoy_iso_uefi_drv;
|
||||
extern int g_ventoy_case_insensitive;
|
||||
extern grub_uint8_t g_ventoy_chain_type;
|
||||
|
||||
int ventoy_cmp_img(img_info *img1, img_info *img2);
|
||||
void ventoy_swap_img(img_info *img1, img_info *img2);
|
||||
@@ -611,9 +666,16 @@ persistence_config * ventoy_plugin_find_persistent(const char *isopath);
|
||||
void ventoy_plugin_dump_auto_install(void);
|
||||
int ventoy_fill_windows_rtdata(void *buf, char *isopath);
|
||||
int ventoy_plugin_get_persistent_chunklist(const char *isopath, int index, ventoy_img_chunk_list *chunk_list);
|
||||
const char * ventoy_plugin_get_menu_alias(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_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
|
||||
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);
|
||||
|
||||
#endif /* __VENTOY_DEF_H__ */
|
||||
|
||||
|
@@ -42,6 +42,11 @@ static void json_debug(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
if (g_ventoy_debug == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
va_start (args, fmt);
|
||||
grub_vprintf (fmt, args);
|
||||
va_end (args);
|
||||
|
@@ -841,6 +841,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)
|
||||
{
|
||||
int sizefilt = 0;
|
||||
@@ -1100,6 +1144,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));
|
||||
|
||||
/* part 1: os parameter */
|
||||
g_ventoy_chain_type = ventoy_chain_linux;
|
||||
ventoy_fill_os_param(file, &(chain->os_param));
|
||||
|
||||
/* part 2: chain head */
|
||||
|
@@ -33,6 +33,7 @@
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/net.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/font.h>
|
||||
#include <grub/ventoy.h>
|
||||
#include "ventoy_def.h"
|
||||
|
||||
@@ -41,6 +42,47 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
||||
static char g_iso_disk_name[128];
|
||||
static install_template *g_install_template_head = NULL;
|
||||
static persistence_config *g_persistence_head = NULL;
|
||||
static menu_alias *g_menu_alias_head = NULL;
|
||||
static menu_class *g_menu_class_head = NULL;
|
||||
|
||||
static int ventoy_plugin_control_check(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int rc = 0;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
VTOY_JSON *pChild = NULL;
|
||||
|
||||
(void)isodisk;
|
||||
|
||||
if (json->enDataType != JSON_TYPE_ARRAY)
|
||||
{
|
||||
grub_printf("Not array type %d\n", json->enDataType);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
|
||||
{
|
||||
if (pNode->enDataType == JSON_TYPE_OBJECT)
|
||||
{
|
||||
pChild = pNode->pstChild;
|
||||
if (pChild->enDataType == JSON_TYPE_STRING)
|
||||
{
|
||||
grub_printf("%s: %s\n", pChild->pcName, pChild->unData.pcStrVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("%s is NOT string type\n", pChild->pcName);
|
||||
rc = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("%s is not an object\n", pNode->pcName);
|
||||
rc = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_control_entry(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
@@ -70,10 +112,93 @@ static int ventoy_plugin_control_entry(VTOY_JSON *json, const char *isodisk)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_theme_check(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int exist = 0;
|
||||
const char *value;
|
||||
VTOY_JSON *node;
|
||||
|
||||
value = vtoy_json_get_string_ex(json->pstChild, "file");
|
||||
if (value)
|
||||
{
|
||||
grub_printf("file: %s\n", value);
|
||||
if (value[0] == '/')
|
||||
{
|
||||
exist = ventoy_is_file_exist("%s%s", isodisk, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
exist = ventoy_is_file_exist("%s/ventoy/%s", isodisk, value);
|
||||
}
|
||||
|
||||
if (exist == 0)
|
||||
{
|
||||
grub_printf("Theme file %s does NOT exist\n", value);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
value = vtoy_json_get_string_ex(json->pstChild, "gfxmode");
|
||||
if (value)
|
||||
{
|
||||
grub_printf("gfxmode: %s\n", value);
|
||||
}
|
||||
|
||||
value = vtoy_json_get_string_ex(json->pstChild, "display_mode");
|
||||
if (value)
|
||||
{
|
||||
grub_printf("display_mode: %s\n", value);
|
||||
}
|
||||
|
||||
value = vtoy_json_get_string_ex(json->pstChild, "ventoy_left");
|
||||
if (value)
|
||||
{
|
||||
grub_printf("ventoy_left: %s\n", value);
|
||||
}
|
||||
|
||||
value = vtoy_json_get_string_ex(json->pstChild, "ventoy_top");
|
||||
if (value)
|
||||
{
|
||||
grub_printf("ventoy_top: %s\n", value);
|
||||
}
|
||||
|
||||
value = vtoy_json_get_string_ex(json->pstChild, "ventoy_color");
|
||||
if (value)
|
||||
{
|
||||
grub_printf("ventoy_color: %s\n", value);
|
||||
}
|
||||
|
||||
node = vtoy_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "fonts");
|
||||
if (node)
|
||||
{
|
||||
for (node = node->pstChild; node; node = node->pstNext)
|
||||
{
|
||||
if (node->enDataType == JSON_TYPE_STRING)
|
||||
{
|
||||
if (ventoy_check_file_exist("%s%s", isodisk, node->unData.pcStrVal))
|
||||
{
|
||||
grub_printf("%s [OK]\n", node->unData.pcStrVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("%s [NOT EXIST]\n", node->unData.pcStrVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("fonts NOT found\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
const char *value;
|
||||
char filepath[256];
|
||||
VTOY_JSON *node;
|
||||
|
||||
value = vtoy_json_get_string_ex(json->pstChild, "file");
|
||||
if (value)
|
||||
@@ -104,6 +229,13 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
|
||||
grub_env_set("vtoy_gfxmode", value);
|
||||
}
|
||||
|
||||
value = vtoy_json_get_string_ex(json->pstChild, "display_mode");
|
||||
if (value)
|
||||
{
|
||||
debug("display_mode %s\n", value);
|
||||
grub_env_set("vtoy_display_mode", value);
|
||||
}
|
||||
|
||||
value = vtoy_json_get_string_ex(json->pstChild, "ventoy_left");
|
||||
if (value)
|
||||
{
|
||||
@@ -122,9 +254,114 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
|
||||
grub_env_set("VTLE_CLR", value);
|
||||
}
|
||||
|
||||
node = vtoy_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "fonts");
|
||||
if (node)
|
||||
{
|
||||
for (node = node->pstChild; node; node = node->pstNext)
|
||||
{
|
||||
if (node->enDataType == JSON_TYPE_STRING &&
|
||||
ventoy_check_file_exist("%s%s", isodisk, node->unData.pcStrVal))
|
||||
{
|
||||
grub_snprintf(filepath, sizeof(filepath), "%s%s", isodisk, node->unData.pcStrVal);
|
||||
grub_font_load(filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_check_path(const char *path, const char *file)
|
||||
{
|
||||
if (file[0] != '/')
|
||||
{
|
||||
grub_printf("%s is NOT begin with '/' \n", file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (grub_strchr(file, '\\'))
|
||||
{
|
||||
grub_printf("%s contains invalid '\\' \n", file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (grub_strstr(file, "//"))
|
||||
{
|
||||
grub_printf("%s contains invalid double slash\n", file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (grub_strstr(file, "../"))
|
||||
{
|
||||
grub_printf("%s contains invalid '../' \n", file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!ventoy_is_file_exist("%s%s", path, file))
|
||||
{
|
||||
grub_printf("%s%s does NOT exist\n", path, file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_check_fullpath
|
||||
(
|
||||
VTOY_JSON *json,
|
||||
const char *isodisk,
|
||||
const char *key,
|
||||
int *pathnum
|
||||
)
|
||||
{
|
||||
int rc = 0;
|
||||
int ret = 0;
|
||||
int cnt = 0;
|
||||
VTOY_JSON *node = json;
|
||||
VTOY_JSON *child = NULL;
|
||||
|
||||
while (node)
|
||||
{
|
||||
if (0 == grub_strcmp(key, node->pcName))
|
||||
{
|
||||
break;
|
||||
}
|
||||
node = node->pstNext;
|
||||
}
|
||||
|
||||
if (!node)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (JSON_TYPE_STRING == node->enDataType)
|
||||
{
|
||||
cnt = 1;
|
||||
ret = ventoy_plugin_check_path(isodisk, node->unData.pcStrVal);
|
||||
grub_printf("%s: %s [%s]\n", key, node->unData.pcStrVal, ret ? "FAIL" : "OK");
|
||||
}
|
||||
else if (JSON_TYPE_ARRAY == node->enDataType)
|
||||
{
|
||||
for (child = node->pstChild; child; child = child->pstNext)
|
||||
{
|
||||
if (JSON_TYPE_STRING != child->enDataType)
|
||||
{
|
||||
grub_printf("Non string json type\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = ventoy_plugin_check_path(isodisk, child->unData.pcStrVal);
|
||||
grub_printf("%s: %s [%s]\n", key, child->unData.pcStrVal, rc ? "FAIL" : "OK");
|
||||
ret += rc;
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*pathnum = cnt;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_parse_fullpath
|
||||
(
|
||||
VTOY_JSON *json,
|
||||
@@ -209,9 +446,64 @@ static int ventoy_plugin_parse_fullpath
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_auto_install_check(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int pathnum = 0;
|
||||
int autosel = 0;
|
||||
const char *iso = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
|
||||
if (json->enDataType != JSON_TYPE_ARRAY)
|
||||
{
|
||||
grub_printf("Not array type %d\n", json->enDataType);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
|
||||
{
|
||||
if (pNode->enDataType != JSON_TYPE_OBJECT)
|
||||
{
|
||||
grub_printf("NOT object type\n");
|
||||
}
|
||||
|
||||
iso = vtoy_json_get_string_ex(pNode->pstChild, "image");
|
||||
if (iso)
|
||||
{
|
||||
if (0 == ventoy_plugin_check_path(isodisk, iso))
|
||||
{
|
||||
grub_printf("image: %s [OK]\n", iso);
|
||||
ventoy_plugin_check_fullpath(pNode->pstChild, isodisk, "template", &pathnum);
|
||||
|
||||
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "autosel", &autosel))
|
||||
{
|
||||
if (autosel >= 0 && autosel <= pathnum)
|
||||
{
|
||||
grub_printf("autosel: %d [OK]\n", autosel);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("autosel: %d [FAIL]\n", autosel);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("image: %s [FAIL]\n", iso);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("image not found\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int pathnum = 0;
|
||||
int autosel = 0;
|
||||
const char *iso = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
install_template *node = NULL;
|
||||
@@ -250,6 +542,15 @@ static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk
|
||||
node->templatepath = templatepath;
|
||||
node->templatenum = pathnum;
|
||||
|
||||
node->autosel = -1;
|
||||
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "autosel", &autosel))
|
||||
{
|
||||
if (autosel >= 0 && autosel <= pathnum)
|
||||
{
|
||||
node->autosel = autosel;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_install_template_head)
|
||||
{
|
||||
node->next = g_install_template_head;
|
||||
@@ -264,9 +565,63 @@ static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_persistence_check(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int autosel = 0;
|
||||
int pathnum = 0;
|
||||
const char *iso = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
|
||||
if (json->enDataType != JSON_TYPE_ARRAY)
|
||||
{
|
||||
grub_printf("Not array type %d\n", json->enDataType);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
|
||||
{
|
||||
if (pNode->enDataType != JSON_TYPE_OBJECT)
|
||||
{
|
||||
grub_printf("NOT object type\n");
|
||||
}
|
||||
|
||||
iso = vtoy_json_get_string_ex(pNode->pstChild, "image");
|
||||
if (iso)
|
||||
{
|
||||
if (0 == ventoy_plugin_check_path(isodisk, iso))
|
||||
{
|
||||
grub_printf("image: %s [OK]\n", iso);
|
||||
ventoy_plugin_check_fullpath(pNode->pstChild, isodisk, "backend", &pathnum);
|
||||
|
||||
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "autosel", &autosel))
|
||||
{
|
||||
if (autosel >= 0 && autosel <= pathnum)
|
||||
{
|
||||
grub_printf("autosel: %d [OK]\n", autosel);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("autosel: %d [FAIL]\n", autosel);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("image: %s [FAIL]\n", iso);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("image not found\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_persistence_entry(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int autosel = 0;
|
||||
int pathnum = 0;
|
||||
const char *iso = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
@@ -308,6 +663,15 @@ static int ventoy_plugin_persistence_entry(VTOY_JSON *json, const char *isodisk)
|
||||
node->backendpath = backendpath;
|
||||
node->backendnum = pathnum;
|
||||
|
||||
node->autosel = -1;
|
||||
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "autosel", &autosel))
|
||||
{
|
||||
if (autosel >= 0 && autosel <= pathnum)
|
||||
{
|
||||
node->autosel = autosel;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_persistence_head)
|
||||
{
|
||||
node->next = g_persistence_head;
|
||||
@@ -322,13 +686,234 @@ static int ventoy_plugin_persistence_entry(VTOY_JSON *json, const char *isodisk)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_menualias_check(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int type;
|
||||
const char *path = NULL;
|
||||
const char *alias = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
|
||||
(void)isodisk;
|
||||
|
||||
if (json->enDataType != JSON_TYPE_ARRAY)
|
||||
{
|
||||
grub_printf("Not array %d\n", json->enDataType);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
|
||||
{
|
||||
type = vtoy_alias_image_file;
|
||||
path = vtoy_json_get_string_ex(pNode->pstChild, "image");
|
||||
if (!path)
|
||||
{
|
||||
path = vtoy_json_get_string_ex(pNode->pstChild, "dir");
|
||||
type = vtoy_alias_directory;
|
||||
}
|
||||
|
||||
alias = vtoy_json_get_string_ex(pNode->pstChild, "alias");
|
||||
if (path && path[0] == '/' && alias)
|
||||
{
|
||||
if (vtoy_alias_image_file == type)
|
||||
{
|
||||
if (ventoy_is_file_exist("%s%s", isodisk, path))
|
||||
{
|
||||
grub_printf("image: <%s> [ OK ]\n", path);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("image: <%s> [ NOT EXIST ]\n", path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ventoy_is_dir_exist("%s%s", isodisk, path))
|
||||
{
|
||||
grub_printf("dir: <%s> [ OK ]\n", path);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("dir: <%s> [ NOT EXIST ]\n", path);
|
||||
}
|
||||
}
|
||||
|
||||
grub_printf("alias: <%s>\n\n", alias);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_menualias_entry(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int type;
|
||||
const char *path = NULL;
|
||||
const char *alias = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
menu_alias *node = NULL;
|
||||
menu_alias *next = NULL;
|
||||
|
||||
(void)isodisk;
|
||||
|
||||
if (json->enDataType != JSON_TYPE_ARRAY)
|
||||
{
|
||||
debug("Not array %d\n", json->enDataType);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (g_menu_alias_head)
|
||||
{
|
||||
for (node = g_menu_alias_head; node; node = next)
|
||||
{
|
||||
next = node->next;
|
||||
grub_free(node);
|
||||
}
|
||||
|
||||
g_menu_alias_head = NULL;
|
||||
}
|
||||
|
||||
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
|
||||
{
|
||||
type = vtoy_alias_image_file;
|
||||
path = vtoy_json_get_string_ex(pNode->pstChild, "image");
|
||||
if (!path)
|
||||
{
|
||||
path = vtoy_json_get_string_ex(pNode->pstChild, "dir");
|
||||
type = vtoy_alias_directory;
|
||||
}
|
||||
|
||||
alias = vtoy_json_get_string_ex(pNode->pstChild, "alias");
|
||||
if (path && path[0] == '/' && alias)
|
||||
{
|
||||
node = grub_zalloc(sizeof(menu_alias));
|
||||
if (node)
|
||||
{
|
||||
node->type = type;
|
||||
node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", path);
|
||||
grub_snprintf(node->alias, sizeof(node->alias), "%s", alias);
|
||||
|
||||
if (g_menu_alias_head)
|
||||
{
|
||||
node->next = g_menu_alias_head;
|
||||
}
|
||||
|
||||
g_menu_alias_head = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_menuclass_entry(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int type;
|
||||
const char *key = NULL;
|
||||
const char *class = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
menu_class *tail = NULL;
|
||||
menu_class *node = NULL;
|
||||
menu_class *next = NULL;
|
||||
|
||||
(void)isodisk;
|
||||
|
||||
if (json->enDataType != JSON_TYPE_ARRAY)
|
||||
{
|
||||
debug("Not array %d\n", json->enDataType);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (g_menu_class_head)
|
||||
{
|
||||
for (node = g_menu_class_head; node; node = next)
|
||||
{
|
||||
next = node->next;
|
||||
grub_free(node);
|
||||
}
|
||||
|
||||
g_menu_class_head = NULL;
|
||||
}
|
||||
|
||||
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
|
||||
{
|
||||
type = vtoy_class_image_file;
|
||||
key = vtoy_json_get_string_ex(pNode->pstChild, "key");
|
||||
if (!key)
|
||||
{
|
||||
key = vtoy_json_get_string_ex(pNode->pstChild, "dir");
|
||||
type = vtoy_class_directory;
|
||||
}
|
||||
|
||||
class = vtoy_json_get_string_ex(pNode->pstChild, "class");
|
||||
if (key && class)
|
||||
{
|
||||
node = grub_zalloc(sizeof(menu_class));
|
||||
if (node)
|
||||
{
|
||||
node->type = type;
|
||||
node->patlen = grub_snprintf(node->pattern, sizeof(node->pattern), "%s", key);
|
||||
grub_snprintf(node->class, sizeof(node->class), "%s", class);
|
||||
|
||||
if (g_menu_class_head)
|
||||
{
|
||||
tail->next = node;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_menu_class_head = node;
|
||||
}
|
||||
tail = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_menuclass_check(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int type;
|
||||
const char *key = NULL;
|
||||
const char *class = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
|
||||
(void)isodisk;
|
||||
|
||||
if (json->enDataType != JSON_TYPE_ARRAY)
|
||||
{
|
||||
grub_printf("Not array %d\n", json->enDataType);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
|
||||
{
|
||||
type = vtoy_class_image_file;
|
||||
key = vtoy_json_get_string_ex(pNode->pstChild, "key");
|
||||
if (!key)
|
||||
{
|
||||
key = vtoy_json_get_string_ex(pNode->pstChild, "dir");
|
||||
type = vtoy_class_directory;
|
||||
}
|
||||
|
||||
class = vtoy_json_get_string_ex(pNode->pstChild, "class");
|
||||
if (key && class)
|
||||
{
|
||||
grub_printf("%s: <%s>\n", (type == vtoy_class_directory) ? "dir" : "key", key);
|
||||
grub_printf("class: <%s>\n\n", class);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static plugin_entry g_plugin_entries[] =
|
||||
{
|
||||
{ "control", ventoy_plugin_control_entry },
|
||||
{ "theme", ventoy_plugin_theme_entry },
|
||||
{ "auto_install", ventoy_plugin_auto_install_entry },
|
||||
{ "persistence", ventoy_plugin_persistence_entry },
|
||||
{ "control", ventoy_plugin_control_entry, ventoy_plugin_control_check },
|
||||
{ "theme", ventoy_plugin_theme_entry, ventoy_plugin_theme_check },
|
||||
{ "auto_install", ventoy_plugin_auto_install_entry, ventoy_plugin_auto_install_check },
|
||||
{ "persistence", ventoy_plugin_persistence_entry, ventoy_plugin_persistence_check },
|
||||
{ "menu_alias", ventoy_plugin_menualias_entry, ventoy_plugin_menualias_check },
|
||||
{ "menu_class", ventoy_plugin_menuclass_entry, ventoy_plugin_menuclass_check },
|
||||
};
|
||||
|
||||
static int ventoy_parse_plugin_config(VTOY_JSON *json, const char *isodisk)
|
||||
@@ -417,7 +1002,7 @@ void ventoy_plugin_dump_auto_install(void)
|
||||
|
||||
for (node = g_install_template_head; node; node = node->next)
|
||||
{
|
||||
grub_printf("\nIMAGE:<%s>\n", node->isopath);
|
||||
grub_printf("\nIMAGE:<%s> <%d>\n", node->isopath, node->templatenum);
|
||||
for (i = 0; i < node->templatenum; i++)
|
||||
{
|
||||
grub_printf("SCRIPT %d:<%s>\n", i, node->templatepath[i].path);
|
||||
@@ -436,7 +1021,7 @@ void ventoy_plugin_dump_persistence(void)
|
||||
|
||||
for (node = g_persistence_head; node; node = node->next)
|
||||
{
|
||||
grub_printf("\nIMAGE:<%s>\n", node->isopath);
|
||||
grub_printf("\nIMAGE:<%s> <%d>\n", node->isopath, node->backendnum);
|
||||
|
||||
for (i = 0; i < node->backendnum; i++)
|
||||
{
|
||||
@@ -566,3 +1151,130 @@ end:
|
||||
return rc;
|
||||
}
|
||||
|
||||
const char * ventoy_plugin_get_menu_alias(int type, const char *isopath)
|
||||
{
|
||||
menu_alias *node = NULL;
|
||||
int len = (int)grub_strlen(isopath);
|
||||
|
||||
for (node = g_menu_alias_head; node; node = node->next)
|
||||
{
|
||||
if (node->type == type && node->pathlen &&
|
||||
node->pathlen == len && grub_strcmp(node->isopath, isopath) == 0)
|
||||
{
|
||||
return node->alias;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char * ventoy_plugin_get_menu_class(int type, const char *name)
|
||||
{
|
||||
menu_class *node = NULL;
|
||||
int len = (int)grub_strlen(name);
|
||||
|
||||
if (vtoy_class_image_file == type)
|
||||
{
|
||||
for (node = g_menu_class_head; node; node = node->next)
|
||||
{
|
||||
if (node->type == type && node->patlen <= len && grub_strstr(name, node->pattern))
|
||||
{
|
||||
return node->class;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (node = g_menu_class_head; node; node = node->next)
|
||||
{
|
||||
if (node->type == type && node->patlen == len && grub_strncmp(name, node->pattern, len) == 0)
|
||||
{
|
||||
return node->class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int i = 0;
|
||||
int ret = 0;
|
||||
char *buf = NULL;
|
||||
grub_file_t file;
|
||||
VTOY_JSON *node = NULL;
|
||||
VTOY_JSON *json = NULL;
|
||||
|
||||
(void)ctxt;
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s/ventoy/ventoy.json", args[0]);
|
||||
if (!file)
|
||||
{
|
||||
grub_printf("Plugin json file /ventoy/ventoy.json does NOT exist.\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
buf = grub_malloc(file->size + 1);
|
||||
if (!buf)
|
||||
{
|
||||
grub_printf("Failed to malloc memory %lu.\n", (ulong)(file->size + 1));
|
||||
goto end;
|
||||
}
|
||||
|
||||
buf[file->size] = 0;
|
||||
grub_file_read(file, buf, file->size);
|
||||
|
||||
json = vtoy_json_create();
|
||||
if (!json)
|
||||
{
|
||||
grub_printf("Failed to create json\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
ret = vtoy_json_parse(json, buf);
|
||||
if (ret)
|
||||
{
|
||||
grub_printf("Syntax error detected in ventoy.json, please check it.\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
for (node = json->pstChild; node; node = node->pstNext)
|
||||
{
|
||||
if (grub_strcmp(node->pcName, args[1]) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!node)
|
||||
{
|
||||
grub_printf("%s is NOT found in ventoy.json\n", args[1]);
|
||||
goto end;
|
||||
}
|
||||
|
||||
for (i = 0; i < (int)ARRAY_SIZE(g_plugin_entries); i++)
|
||||
{
|
||||
if (grub_strcmp(g_plugin_entries[i].key, args[1]) == 0)
|
||||
{
|
||||
if (g_plugin_entries[i].checkfunc)
|
||||
{
|
||||
ret = g_plugin_entries[i].checkfunc(node, args[2]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
check_free(file, grub_file_close);
|
||||
check_free(json, vtoy_json_destroy);
|
||||
grub_check_free(buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
243
GRUB2/MOD_SRC/grub-2.04/include/grub/file.h
Normal file
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_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)
|
||||
|
||||
typedef struct ventoy_guid
|
||||
@@ -109,6 +118,9 @@ typedef struct ventoy_os_param
|
||||
*
|
||||
* vtoy_reserved[0]: vtoy_break_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
|
||||
@@ -201,12 +213,13 @@ typedef struct ventoy_img_chunk_list
|
||||
|
||||
#define ventoy_filt_register grub_file_filter_register
|
||||
|
||||
typedef const char * (*grub_env_get_pf)(const char *name);
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
#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
|
||||
{
|
||||
grub_uint32_t magic;
|
||||
@@ -218,8 +231,8 @@ typedef struct 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()
|
||||
@@ -227,6 +240,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_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_file_dirent_pos(grub_file_t file);
|
||||
grub_uint64_t grub_udf_get_file_offset(grub_file_t file);
|
||||
|
@@ -12,18 +12,19 @@ make install
|
||||
PATH=$PATH:$VT_DIR/GRUB2/INSTALL/bin/:$VT_DIR/GRUB2/INSTALL/sbin/
|
||||
|
||||
net_modules_legacy="net tftp http"
|
||||
all_modules_legacy="date drivemap blocklist lspci pci ext2 xfs ventoy chain read halt iso9660 linux16 test true sleep reboot echo videotest videoinfo videotest_checksum video_colors video_cirrus video_bochs vga vbe video_fb font video gettext extcmd terminal linux minicmd help configfile tr trig boot biosdisk disk ls tar squash4 password_pbkdf2 all_video png jpeg part_msdos fat exfat ntfs loopback gzio normal udf gfxmenu gfxterm gfxterm_background gfxterm_menu"
|
||||
all_modules_legacy="date drivemap blocklist 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"
|
||||
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"
|
||||
|
||||
all_extra_modules="elf macho offsetio regexp file"
|
||||
|
||||
if [ "$1" = "uefi" ]; then
|
||||
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'
|
||||
all_modules="$net_modules_uefi $all_modules_uefi $all_extra_modules"
|
||||
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/EFI/BOOT/grubx64_real.efi" --format 'x86_64-efi' --compression 'auto' $all_modules_uefi 'fat' 'part_msdos'
|
||||
else
|
||||
all_modules="$net_modules_legacy $all_modules_legacy"
|
||||
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
|
||||
|
||||
grub-mknetdir --modules="$all_modules" --net-directory=$VT_DIR/GRUB2/PXE --subdir=grub2 --locales=en@quot || exit 1
|
||||
@@ -38,6 +39,11 @@ else
|
||||
rm -f $VT_DIR/GRUB2/NBP/core.0
|
||||
cp -a $VT_DIR/GRUB2/PXE/grub2/i386-pc/core.0 $VT_DIR/GRUB2/NBP/core.0 || exit 1
|
||||
|
||||
for md in $all_extra_modules; do
|
||||
rm -f $VT_DIR/INSTALL/grub/i386-pc/${md}.mod
|
||||
cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc/${md}.mod $VT_DIR/INSTALL/grub/i386-pc/
|
||||
done
|
||||
|
||||
rm -f $VT_DIR/INSTALL/grub/i386-pc/boot.img
|
||||
cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc/boot.img $VT_DIR/INSTALL/grub/i386-pc/boot.img || exit 1
|
||||
fi
|
||||
|
@@ -19,19 +19,25 @@
|
||||
|
||||
. /ventoy/hook/ventoy-hook-lib.sh
|
||||
|
||||
if is_ventoy_hook_finished; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
vtlog "####### $0 $* ########"
|
||||
|
||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||
|
||||
while ! [ -e /dev/null ]; do
|
||||
echo 'xxxxxxxxxx'
|
||||
echo 'xxxxxxxxxx' > /dev/console
|
||||
sleep 1
|
||||
done
|
||||
wait_for_usb_disk_ready
|
||||
|
||||
vtlog "... start inotifyd listen $vtHook ..."
|
||||
$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $VTOY_PATH/hook/guix/ventoy-disk.sh /dev:n 2>&- &
|
||||
vtdiskname=$(get_ventoy_disk_name)
|
||||
if [ "$vtdiskname" = "unknown" ]; then
|
||||
vtlog "ventoy disk not found"
|
||||
PATH=$VTPATH_OLD
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
|
||||
|
||||
PATH=$VTPATH_OLD
|
||||
|
||||
set_ventoy_hook_finish
|
23
IMG/cpio/ventoy/hook/adelie/ventoy-hook.sh
Normal file
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.
|
||||
# Use /dev/loop7 and wapper it as a cdrom with bind mount.
|
||||
# Then the installer will accept /dev/loop7 as the install medium.
|
||||
# Use /dev/vtCheatLoop and wapper it as a cdrom with bind mount.
|
||||
# Then the installer will accept /dev/vtCheatLoop as the install medium.
|
||||
#
|
||||
ventoy_copy_device_mapper /dev/loop7
|
||||
$BUSYBOX_PATH/mkdir -p /tmp/loop7/device/
|
||||
echo 5 > /tmp/loop7/device/type
|
||||
$BUSYBOX_PATH/mount --bind /tmp/loop7 /sys/block/loop7 >> $VTLOG 2>&1
|
||||
vtCheatLoop=loop6
|
||||
ventoy_copy_device_mapper /dev/$vtCheatLoop
|
||||
$BUSYBOX_PATH/mkdir -p /tmp/$vtCheatLoop/device/
|
||||
echo 5 > /tmp/$vtCheatLoop/device/type
|
||||
$BUSYBOX_PATH/mount --bind /tmp/$vtCheatLoop /sys/block/$vtCheatLoop >> $VTLOG 2>&1
|
||||
|
||||
|
||||
# OK finish
|
||||
|
50
IMG/cpio/ventoy/hook/arch/ovios-disk.sh
Normal file
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
|
@@ -26,6 +26,14 @@ if $GREP -q '^"$mount_handler"' /init; then
|
||||
if [ -f /hooks/archiso ]; then
|
||||
$SED '/while ! poll_device "${dev}"/a\ if /ventoy/busybox/sh /ventoy/hook/arch/ventoy-timeout.sh ${dev}; then break; fi' -i /hooks/archiso
|
||||
fi
|
||||
elif $GREP -q '^KEEP_SEARCHING' /init; then
|
||||
echo 'KEEP_SEARCHING found ...' >> $VTLOG
|
||||
$SED "/^KEEP_SEARCHING/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ovios-disk.sh " -i /init
|
||||
|
||||
$BUSYBOX_PATH/mkdir -p /dev
|
||||
$BUSYBOX_PATH/mkdir -p /sys
|
||||
$BUSYBOX_PATH/mount -t sysfs sys /sys
|
||||
|
||||
else
|
||||
# some archlinux initramfs doesn't contain device-mapper udev rules file
|
||||
ARCH_UDEV_DIR=$(ventoy_get_udev_conf_dir)
|
||||
|
47
IMG/cpio/ventoy/hook/cdlinux/disk-hook.sh
Normal file
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
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 "CDL_DEV=/dev/mapper/ventoy" >> /ventoy_rdroot/etc/default/cdlinux
|
||||
|
||||
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"
|
@@ -19,4 +19,10 @@
|
||||
|
||||
. $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
|
||||
|
@@ -17,6 +17,8 @@
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
CD_DETECT="/var/lib/dpkg/info/cdrom-detect.postinst"
|
||||
|
||||
if [ -e /init ] && $GREP -q '^mountroot$' /init; then
|
||||
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
|
||||
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
|
||||
echo "Here use notify ..." >> $VTLOG
|
||||
|
||||
|
@@ -32,4 +32,5 @@ if [ "$vtdiskname" = "unknown" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
vtlog "${vtdiskname#/dev/}2 found..."
|
||||
$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/udev_disk_hook.sh "${vtdiskname#/dev/}2"
|
||||
|
@@ -21,6 +21,8 @@
|
||||
|
||||
ventoy_os_install_dmsetup() {
|
||||
|
||||
vtlog "ventoy_os_install_dmsetup $1 ..."
|
||||
|
||||
vt_usb_disk=$1
|
||||
|
||||
# dump iso file location
|
||||
@@ -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
|
||||
# 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"
|
||||
else
|
||||
vtlog "$1 is NOT USB device (bus $ID_BUS)"
|
||||
|
@@ -23,13 +23,15 @@ if is_ventoy_hook_finished; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
vtlog "##### INOTIFYD: $2/$3 is created ..."
|
||||
|
||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||
|
||||
if is_inotify_ventoy_part $3; then
|
||||
vtlog "##### INOTIFYD: $2/$3 is created (YES) ..."
|
||||
vtlog "find ventoy partition $3 ..."
|
||||
$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/udev_disk_hook.sh "$3"
|
||||
else
|
||||
vtlog "##### INOTIFYD: $2/$3 is created (NO)..."
|
||||
fi
|
||||
|
||||
PATH=$VTPATH_OLD
|
||||
|
@@ -19,13 +19,11 @@
|
||||
|
||||
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
||||
|
||||
if [ -d /etc/udev/rules.d ] || [ -d /lib/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_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k noreplace"
|
||||
else
|
||||
if $GREP -q kaspersky /proc/version; then
|
||||
$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
|
||||
$SED "/mdev *-s/a\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/gentoo/disk_hook.sh" -i /init
|
||||
fi
|
||||
|
@@ -23,11 +23,11 @@ if is_ventoy_hook_finished; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
vtlog "##### INOTIFYD: $2/$3 is created ..."
|
||||
|
||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||
|
||||
if is_inotify_ventoy_part $3; then
|
||||
vtlog "##### INOTIFYD: $2/$3 is created (YES)..."
|
||||
|
||||
vtlog "find ventoy partition $3 ..."
|
||||
$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
|
||||
|
||||
set_ventoy_hook_finish
|
||||
else
|
||||
vtlog "##### INOTIFYD: $2/$3 is created (NO)..."
|
||||
fi
|
||||
|
||||
PATH=$VTPATH_OLD
|
||||
|
26
IMG/cpio/ventoy/hook/guix/ventoy-before-init.sh
Normal file
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
|
||||
|
||||
if is_ventoy_hook_finished; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
vtlog "##### INOTIFYD: $2/$3 is created ..."
|
||||
vtlog "######### $0 $* ############"
|
||||
|
||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||
|
||||
if is_inotify_ventoy_part $3; then
|
||||
vtlog "find ventoy partition ..."
|
||||
$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh $3
|
||||
wait_for_usb_disk_ready
|
||||
|
||||
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})
|
||||
vtdiskname=$(get_ventoy_disk_name)
|
||||
if [ "$vtdiskname" = "unknown" ]; then
|
||||
vtlog "ventoy disk not found"
|
||||
PATH=$VTPATH_OLD
|
||||
exit 0
|
||||
fi
|
||||
|
||||
vtlog "This is $vtDM ..."
|
||||
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
|
||||
|
||||
set_ventoy_hook_finish
|
||||
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
|
||||
|
@@ -18,8 +18,3 @@
|
||||
#************************************************************************************
|
||||
|
||||
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
||||
|
||||
$BUSYBOX_PATH/mkdir /dev
|
||||
$BUSYBOX_PATH/mknode -m 0666 /dev/null c 1 3
|
||||
|
||||
$BUSYBOX_PATH/nohup $VTOY_PATH/hook/guix/ventoy-waitdev.sh &
|
||||
|
70
IMG/cpio/ventoy/hook/kiosk/ventoy-disk.sh
Normal file
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
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
|
@@ -1,7 +1,29 @@
|
||||
#!/ventoy/busybox/sh
|
||||
#************************************************************************************
|
||||
# Copyright (c) 2020, longpanda <admin@ventoy.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
||||
|
||||
ventoy_systemd_udevd_work_around
|
||||
#ventoy_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
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
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
|
||||
fi
|
||||
|
||||
vtlog "##### INOTIFYD: $2/$3 is created ..."
|
||||
|
||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||
|
||||
if is_inotify_ventoy_part $3; then
|
||||
vtlog "##### INOTIFYD: $2/$3 is created (YES) ..."
|
||||
vtlog "find ventoy partition $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
|
||||
fi
|
||||
$BUSYBOX_PATH/cp -a /dev/$vtDM /dev/disk/by-label/$vtLABEL
|
||||
else
|
||||
vtlog "##### INOTIFYD: $2/$3 is created (NO) ..."
|
||||
fi
|
||||
|
||||
PATH=$VTPATH_OLD
|
||||
|
47
IMG/cpio/ventoy/hook/pmagic/disk-hook.sh
Normal file
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
|
||||
fi
|
||||
|
||||
ventoy_udev_disk_common_hook $*
|
||||
|
||||
#
|
||||
# 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
|
||||
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
|
||||
|
||||
# OK finish
|
||||
set_ventoy_hook_finish
|
||||
|
31
IMG/cpio/ventoy/hook/pmagic/ventoy-hook.sh
Normal file
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
|
||||
|
||||
vtCheatLoop=loop6
|
||||
|
||||
ventoy_os_install_dmsetup() {
|
||||
vtlog "ventoy_os_install_dmsetup $1"
|
||||
|
||||
@@ -50,9 +52,9 @@ ventoy_os_install_dmsetup() {
|
||||
|
||||
|
||||
if is_ventoy_hook_finished || not_ventoy_disk "${1:0:-1}"; then
|
||||
# /dev/loop7 come first
|
||||
if [ "$1" = "loop7" ] && [ -b $VTOY_DM_PATH ]; then
|
||||
ventoy_copy_device_mapper /dev/loop7
|
||||
# /dev/vtCheatLoop come first
|
||||
if [ "$1" = "$vtCheatLoop" ] && [ -b $VTOY_DM_PATH ]; then
|
||||
ventoy_copy_device_mapper /dev/$vtCheatLoop
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
@@ -64,7 +66,7 @@ fi
|
||||
|
||||
|
||||
#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"
|
||||
|
||||
@@ -72,14 +74,14 @@ $BUSYBOX_PATH/mount $VTOY_DM_PATH /mnt/ventoy
|
||||
|
||||
#
|
||||
# We do a trick for rhel6 series here.
|
||||
# Use /dev/loop7 and wapper it as a removable cdrom with bind mount.
|
||||
# Then the anaconda installer will accept /dev/loop7 as the install medium.
|
||||
# Use /dev/$vtCheatLoop and wapper it as a removable cdrom with bind mount.
|
||||
# Then the anaconda installer will accept /dev/$vtCheatLoop as the install medium.
|
||||
#
|
||||
ventoy_copy_device_mapper /dev/loop7
|
||||
ventoy_copy_device_mapper /dev/$vtCheatLoop
|
||||
|
||||
$BUSYBOX_PATH/cp -a /sys/devices/virtual/block/loop7 /tmp/ >> $VTLOG 2>&1
|
||||
echo 19 > /tmp/loop7/capability
|
||||
$BUSYBOX_PATH/mount --bind /tmp/loop7 /sys/block/loop7 >> $VTLOG 2>&1
|
||||
$BUSYBOX_PATH/cp -a /sys/devices/virtual/block/$vtCheatLoop /tmp/ >> $VTLOG 2>&1
|
||||
echo 19 > /tmp/$vtCheatLoop/capability
|
||||
$BUSYBOX_PATH/mount --bind /tmp/$vtCheatLoop /sys/block/$vtCheatLoop >> $VTLOG 2>&1
|
||||
|
||||
# OK finish
|
||||
set_ventoy_hook_finish
|
||||
|
@@ -22,6 +22,7 @@
|
||||
$BUSYBOX_PATH/mkdir -p /etc/anaconda.repos.d /mnt/ventoy
|
||||
ventoy_print_yum_repo "ventoy" "file:///mnt/ventoy" > /etc/anaconda.repos.d/ventoy.repo
|
||||
|
||||
|
||||
ventoy_add_udev_rule "$VTOY_PATH/hook/rhel6/udev_disk_hook.sh %k"
|
||||
ventoy_add_kernel_udev_rule "loop7" "$VTOY_PATH/hook/rhel6/udev_disk_hook.sh %k"
|
||||
|
||||
#loop7 was used by loader
|
||||
ventoy_add_kernel_udev_rule "loop6" "$VTOY_PATH/hook/rhel6/udev_disk_hook.sh %k"
|
||||
|
@@ -31,6 +31,12 @@ else
|
||||
VTKS="inst.ks=hd:/dev/dm-0:$vtRawKs"
|
||||
break
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
@@ -44,8 +50,15 @@ fi
|
||||
|
||||
ventoy_set_inotify_script rhel7/ventoy-inotifyd-hook.sh
|
||||
|
||||
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-inotifyd-start.sh /lib/dracut/hooks/pre-udev/01-ventoy-inotifyd-start.sh
|
||||
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-timeout.sh /lib/dracut/hooks/initqueue/timeout/01-ventoy-timeout.sh
|
||||
#Fedora
|
||||
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
|
||||
|
||||
# suppress write protected mount warning
|
||||
if [ -e /usr/sbin/anaconda-diskroot ]; then
|
||||
|
@@ -23,11 +23,21 @@ if is_ventoy_hook_finished; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
vtlog "##### INOTIFYD: $2/$3 is created ..."
|
||||
|
||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||
|
||||
if is_inotify_ventoy_part $3; then
|
||||
|
||||
vtlog "##### 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 ..."
|
||||
$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh $3 noreplace
|
||||
|
||||
@@ -41,11 +51,14 @@ if is_inotify_ventoy_part $3; then
|
||||
ventoy_swap_device /dev/dm-0 /dev/$vtDM
|
||||
fi
|
||||
|
||||
vtlog "set anaconda-diskroot ..."
|
||||
/sbin/anaconda-diskroot /dev/dm-0
|
||||
#/sbin/initqueue --settled --onetime --name anaconda-diskroot anaconda-diskroot /dev/dm-0
|
||||
if [ -e /sbin/anaconda-diskroot ]; then
|
||||
vtlog "set anaconda-diskroot ..."
|
||||
/sbin/anaconda-diskroot /dev/dm-0
|
||||
fi
|
||||
|
||||
set_ventoy_hook_finish
|
||||
else
|
||||
vtlog "##### INOTIFYD: $2/$3 is created (NO) ..."
|
||||
fi
|
||||
|
||||
PATH=$VTPATH_OLD
|
||||
|
@@ -26,8 +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/')
|
||||
vtDM=$(ventoy_find_dm_id ${blkdev_num})
|
||||
|
||||
vtlog "diskroot $vtDM ..."
|
||||
/sbin/anaconda-diskroot /dev/dm-0
|
||||
#/sbin/initqueue --settled --onetime --name anaconda-diskroot anaconda-diskroot /dev/$vtDM
|
||||
if [ -e /sbin/anaconda-diskroot ]; then
|
||||
vtlog "set anaconda-diskroot ..."
|
||||
/sbin/anaconda-diskroot /dev/dm-0
|
||||
fi
|
||||
|
||||
PATH=$VTPATH_OLD
|
||||
|
@@ -51,7 +51,17 @@ fi
|
||||
# #
|
||||
####################################################################
|
||||
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() {
|
||||
#As I known, PCLinuxOS use ramdisk
|
||||
@@ -62,6 +72,13 @@ ventoy_is_initrd_ramdisk() {
|
||||
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
|
||||
ventoy_unpack_initramfs() {
|
||||
vtfile=$1; vtskip=$2; vtmagic=$3; vttmp=$4
|
||||
@@ -73,6 +90,11 @@ ventoy_unpack_initramfs() {
|
||||
# vtmagic='1F8B'
|
||||
#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
|
||||
if [ "${vtx:0:4}" = "${vtmagic:0:4}" ]; then
|
||||
echo "vtx=$vtx" >> $VTLOG
|
||||
|
@@ -87,6 +87,10 @@ ventoy_get_os_type() {
|
||||
elif $EGREP -q 'archlinux|ARCH' /proc/version; then
|
||||
echo 'arch'; return
|
||||
|
||||
# kiosk
|
||||
elif $EGREP -q 'kiosk' /proc/version; then
|
||||
echo 'kiosk'; return
|
||||
|
||||
# gentoo
|
||||
elif $EGREP -q '[Gg]entoo' /proc/version; then
|
||||
echo 'gentoo'; return
|
||||
@@ -188,6 +192,18 @@ ventoy_get_os_type() {
|
||||
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
|
||||
|
||||
echo "default"
|
||||
}
|
||||
|
||||
@@ -214,8 +230,6 @@ if [ "$VTOY_BREAK_LEVEL" = "03" ] || [ "$VTOY_BREAK_LEVEL" = "13" ]; then
|
||||
exec $BUSYBOX_PATH/sh
|
||||
fi
|
||||
|
||||
|
||||
|
||||
####################################################################
|
||||
# #
|
||||
# Step 4 : Hand over to real init #
|
||||
@@ -232,7 +246,8 @@ if [ -f $VTOY_PATH/ventoy_persistent_map ]; then
|
||||
fi
|
||||
|
||||
cd /
|
||||
unset VTOY_PATH VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD
|
||||
|
||||
unset VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD
|
||||
|
||||
for vtinit in $user_rdinit /init /sbin/init /linuxrc; do
|
||||
if [ -d /ventoy_rdroot ]; then
|
||||
@@ -243,6 +258,9 @@ for vtinit in $user_rdinit /init /sbin/init /linuxrc; do
|
||||
fi
|
||||
else
|
||||
if [ -e "$vtinit" ];then
|
||||
if [ -f "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh" ]; then
|
||||
$BUSYBOX_PATH/sh "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh"
|
||||
fi
|
||||
exec "$vtinit"
|
||||
fi
|
||||
fi
|
||||
|
Binary file not shown.
Binary file not shown.
@@ -23,6 +23,8 @@ sh buildlib.sh
|
||||
cd $VTOY_PATH/vtoyfat
|
||||
sh build.sh || exit 1
|
||||
|
||||
cd $VTOY_PATH/vtoygpt
|
||||
sh build.sh || exit 1
|
||||
|
||||
cd $VTOY_PATH/ExFAT
|
||||
sh buidlibfuse.sh || exit 1
|
||||
|
82
INSTALL/grub/debug.cfg
Normal file
82
INSTALL/grub/debug.cfg
Normal file
@@ -0,0 +1,82 @@
|
||||
submenu 'Check plugin json configuration (ventoy.json)' --class=debug_json {
|
||||
menuentry 'Check global control plugin configuration' --class=debug_control {
|
||||
set pager=1
|
||||
vt_check_plugin_json $vt_plugin_path control $iso_path
|
||||
|
||||
echo -e "\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
unset pager
|
||||
}
|
||||
|
||||
menuentry 'Check theme plugin configuration' --class=debug_theme {
|
||||
set pager=1
|
||||
vt_check_plugin_json $vt_plugin_path theme $iso_path
|
||||
|
||||
echo -e "\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
unset pager
|
||||
}
|
||||
|
||||
menuentry 'Check auto install plugin configuration' --class=debug_autoinstall {
|
||||
set pager=1
|
||||
vt_check_plugin_json $vt_plugin_path auto_install $iso_path
|
||||
|
||||
echo -e "\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
unset pager
|
||||
}
|
||||
|
||||
menuentry 'Check persistence plugin configuration' --class=debug_persistence {
|
||||
set pager=1
|
||||
vt_check_plugin_json $vt_plugin_path persistence $iso_path
|
||||
|
||||
echo -e "\n############### dump persistence ###############"
|
||||
vt_dump_persistence
|
||||
|
||||
echo -e "\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
unset pager
|
||||
}
|
||||
|
||||
menuentry 'Check menu alias plugin configuration' --class=debug_menualias {
|
||||
set pager=1
|
||||
vt_check_plugin_json $vt_plugin_path menu_alias $iso_path
|
||||
|
||||
echo -e "\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
unset pager
|
||||
}
|
||||
|
||||
menuentry 'Check menu class plugin configuration' --class=debug_menuclass {
|
||||
set pager=1
|
||||
vt_check_plugin_json $vt_plugin_path menu_class $iso_path
|
||||
|
||||
echo -e "\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
unset pager
|
||||
}
|
||||
|
||||
menuentry 'Return to previous menu [Esc]' --class=vtoyret VTOY_RET {
|
||||
echo 'Return ...'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if [ "$grub_platform" != "pc" ]; then
|
||||
submenu 'Ventoy UEFI Utilities' --class=debug_util {
|
||||
menuentry 'Fixup Windows BlinitializeLibrary Failure' {
|
||||
chainloader ${vtoy_path}/vtoyutil_x64.efi env_param=${env_param} ${vtdebug_flag} feature=fix_windows_mmap
|
||||
boot
|
||||
echo -e "\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
}
|
||||
|
||||
menuentry 'Return to previous menu [Esc]' --class=vtoyret VTOY_RET {
|
||||
echo 'Return ...'
|
||||
}
|
||||
}
|
||||
fi
|
||||
|
||||
menuentry 'Return to previous menu [Esc]' --class=vtoyret VTOY_RET {
|
||||
echo 'Return ...'
|
||||
}
|
Binary file not shown.
BIN
INSTALL/grub/fonts/unicode.pf2
Normal file
BIN
INSTALL/grub/fonts/unicode.pf2
Normal file
Binary file not shown.
@@ -16,14 +16,62 @@
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
function ventoy_pause {
|
||||
if [ -n "${vtdebug_flag}" ]; then
|
||||
echo "press Enter to continue ......"
|
||||
read vtTmpPause
|
||||
fi
|
||||
}
|
||||
|
||||
function ventoy_debug_pause {
|
||||
if [ -n "${vtdebug_flag}" ]; then
|
||||
echo "press Enter to continue ......"
|
||||
read vtTmpPause
|
||||
fi
|
||||
}
|
||||
|
||||
function ventoy_cli_console {
|
||||
if [ "$grub_platform" = "pc" ]; then
|
||||
#terminal_output vga_text
|
||||
terminal_output console
|
||||
else
|
||||
if [ "$vtoy_display_mode" != "CLI" ]; then
|
||||
terminal_output console
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function ventoy_gui_console {
|
||||
if [ "$grub_platform" = "pc" ]; then
|
||||
if [ "$vtoy_display_mode" = "CLI" ]; then
|
||||
terminal_output console
|
||||
else
|
||||
terminal_output gfxterm
|
||||
fi
|
||||
else
|
||||
if [ "$vtoy_display_mode" != "CLI" ]; then
|
||||
terminal_output gfxterm
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function ventoy_power {
|
||||
configfile ($root)/grub/power.cfg
|
||||
configfile $prefix/power.cfg
|
||||
}
|
||||
|
||||
function ventoy_diagnosis {
|
||||
configfile $prefix/debug.cfg
|
||||
}
|
||||
|
||||
function ventoy_localboot {
|
||||
configfile $prefix/localboot.cfg
|
||||
}
|
||||
|
||||
function get_os_type {
|
||||
set vtoy_os=Linux
|
||||
for file in "efi/microsoft" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com" "BOOT/etfsboot.com"; do
|
||||
if [ -e $1/$file ]; then
|
||||
|
||||
for file in "efi/microsoft/boot/bcd" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com" ; do
|
||||
if vt_file_exist_nocase (loop)/$file; then
|
||||
set vtoy_os=Windows
|
||||
break
|
||||
fi
|
||||
@@ -34,18 +82,10 @@ function get_os_type {
|
||||
fi
|
||||
}
|
||||
|
||||
function vt_check_pe {
|
||||
unset VT_PE_SUPPORT
|
||||
|
||||
function vt_check_compatible_pe {
|
||||
#Check for PE without external tools
|
||||
if [ -f $1/HBCD_PE.ini ]; then
|
||||
set ventoy_compatible=YES
|
||||
set VT_PE_SUPPORT=YES
|
||||
elif [ -f $1/easyu.flg ]; then
|
||||
set VT_PE_SUPPORT=YES
|
||||
elif [ -f $1/USM.ICO ]; then
|
||||
set VT_PE_SUPPORT=YES
|
||||
elif [ -d $1/USM_TOOL ]; then
|
||||
set VT_PE_SUPPORT=YES
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -54,22 +94,37 @@ function locate_initrd {
|
||||
|
||||
if [ -n "${vtdebug_flag}" ]; then
|
||||
vt_linux_dump_initrd
|
||||
sleep 5
|
||||
ventoy_debug_pause
|
||||
fi
|
||||
}
|
||||
|
||||
function find_wim_file {
|
||||
unset ventoy_wim_file
|
||||
function locate_wim {
|
||||
vt_windows_locate_wim_patch (loop)
|
||||
|
||||
for file in "sources/boot.wim" "sources/BOOT.WIM" "Sources/Win10PEx64.WIM" "boot/BOOT.WIM" \
|
||||
"winpe_x64.wim" "boot/10pex64.wim" "BOOT/USM1PE6L.WIM" "BOOT/USM1PE6F.WIM"; do
|
||||
if [ -e $1/$file ]; then
|
||||
set ventoy_wim_file=$1/$file
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -n "${vtdebug_flag}" ]; then
|
||||
echo '###############################################'
|
||||
vt_dump_wim_patch
|
||||
echo '###############################################'
|
||||
ventoy_debug_pause
|
||||
fi
|
||||
}
|
||||
|
||||
function distro_specify_wim_patch {
|
||||
if [ -d (loop)/h3pe ]; then
|
||||
vt_windows_collect_wim_patch wim /BOOT/H3_10PE.WIM
|
||||
vt_windows_collect_wim_patch wim /BOOT/H3_7PE.WIM
|
||||
vt_windows_collect_wim_patch wim /BOOT/H3_8PE.WIM
|
||||
vt_windows_collect_wim_patch wim /BOOT/H3_81PE.WIM
|
||||
fi
|
||||
}
|
||||
|
||||
function distro_specify_wim_patch_phase2 {
|
||||
if [ -f (loop)/boot/boot.wim ]; then
|
||||
vt_windows_collect_wim_patch wim /boot/boot.wim
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function distro_specify_initrd_file {
|
||||
if [ -e (loop)/boot/all.rdz ]; then
|
||||
vt_linux_specify_initrd_file /boot/all.rdz
|
||||
@@ -121,6 +176,10 @@ function distro_specify_initrd_file_phase2 {
|
||||
vt_linux_specify_initrd_file /live/initrd.img
|
||||
elif [ -f (loop)/initrd.img ]; then
|
||||
vt_linux_specify_initrd_file /initrd.img
|
||||
elif [ -f (loop)/sysresccd/boot/x86_64/sysresccd.img ]; then
|
||||
vt_linux_specify_initrd_file /sysresccd/boot/x86_64/sysresccd.img
|
||||
elif [ -f (loop)/CDlinux/initrd ]; then
|
||||
vt_linux_specify_initrd_file /CDlinux/initrd
|
||||
|
||||
fi
|
||||
}
|
||||
@@ -129,30 +188,48 @@ function uefi_windows_menu_func {
|
||||
vt_windows_reset
|
||||
|
||||
if [ "$ventoy_compatible" = "NO" ]; then
|
||||
find_wim_file (loop)
|
||||
if [ -n "$ventoy_wim_file" ]; then
|
||||
vt_windows_locate_wim $ventoy_wim_file
|
||||
|
||||
if [ "$ventoy_fs_probe" = "iso9660" ]; then
|
||||
loopback -d loop
|
||||
vt_iso9660_nojoliet 1
|
||||
loopback loop $1$2
|
||||
fi
|
||||
|
||||
for file in "efi/microsoft/boot/bcd"; do
|
||||
vt_windows_collect_wim_patch bcd (loop)/$file
|
||||
done
|
||||
|
||||
vt_windows_count_wim_patch vt_wim_cnt
|
||||
if [ $vt_wim_cnt -eq 0 ]; then
|
||||
distro_specify_wim_patch_phase2
|
||||
fi
|
||||
|
||||
ventoy_debug_pause
|
||||
locate_wim
|
||||
fi
|
||||
|
||||
vt_windows_chain_data ${1}${chosen_path}
|
||||
|
||||
if [ -n "${vtdebug_flag}" ]; then
|
||||
sleep 5
|
||||
fi
|
||||
ventoy_debug_pause
|
||||
|
||||
if [ -n "$vtoy_chain_mem_addr" ]; then
|
||||
terminal_output console
|
||||
ventoy_cli_console
|
||||
chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
|
||||
boot
|
||||
else
|
||||
echo "chain empty failed"
|
||||
sleep 5
|
||||
ventoy_pause
|
||||
fi
|
||||
}
|
||||
|
||||
function uefi_linux_menu_func {
|
||||
if [ "$ventoy_compatible" = "NO" ]; then
|
||||
|
||||
if [ "$ventoy_fs_probe" = "udf" ]; then
|
||||
loopback -d loop
|
||||
set ventoy_fs_probe=iso9660
|
||||
loopback loop $1$2
|
||||
fi
|
||||
|
||||
vt_load_cpio ${vtoy_path}/ventoy.cpio $2 $1
|
||||
|
||||
vt_linux_clear_initrd
|
||||
@@ -169,17 +246,11 @@ function uefi_linux_menu_func {
|
||||
|
||||
# special process for special distros
|
||||
if [ -d (loop)/loader/entries ]; then
|
||||
set LoadIsoEfiDriver=on
|
||||
vt_linux_parse_initrd_grub dir (loop)/loader/entries/
|
||||
elif [ -d (loop)/boot/grub ]; then
|
||||
vt_linux_parse_initrd_grub dir (loop)/boot/grub/
|
||||
fi
|
||||
|
||||
if [ -e (loop)/syslinux/alt0/full.cz ]; then
|
||||
set LoadIsoEfiDriver=on
|
||||
set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
|
||||
fi
|
||||
|
||||
distro_specify_initrd_file
|
||||
|
||||
vt_linux_initrd_count vtcount
|
||||
@@ -194,17 +265,35 @@ function uefi_linux_menu_func {
|
||||
fi
|
||||
|
||||
locate_initrd
|
||||
|
||||
if [ -d (loop)/loader/entries ]; then
|
||||
vt_linux_get_main_initrd_index vtindex
|
||||
|
||||
if [ -d (loop)/arch ]; then
|
||||
if [ -f (loop)/arch/boot/x86_64/archiso.img ]; then
|
||||
vt_add_replace_file $vtindex "EFI\\archiso\\archiso.img"
|
||||
elif [ -f (loop)/boot/initramfs_x86_64.img ]; then
|
||||
vt_add_replace_file $vtindex "boot\\initramfs_x86_64.img"
|
||||
fi
|
||||
elif [ -f (loop)/EFI/BOOT/initrd.gz ]; then
|
||||
vt_add_replace_file $vtindex "EFI\\BOOT\\initrd.gz"
|
||||
fi
|
||||
elif [ -e (loop)/syslinux/alt0/full.cz ]; then
|
||||
vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
|
||||
set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
vt_linux_chain_data ${1}${chosen_path}
|
||||
|
||||
if [ -n "$vtoy_chain_mem_addr" ]; then
|
||||
terminal_output console
|
||||
ventoy_cli_console
|
||||
chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
|
||||
boot
|
||||
else
|
||||
echo "chain empty failed"
|
||||
sleep 5
|
||||
ventoy_pause
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -232,6 +321,7 @@ function uefi_iso_menu_func {
|
||||
set ventoy_fs_probe=udf
|
||||
else
|
||||
set ventoy_fs_probe=iso9660
|
||||
vt_iso9660_nojoliet 0
|
||||
fi
|
||||
|
||||
loopback loop ${1}${chosen_path}
|
||||
@@ -257,19 +347,13 @@ function uefi_iso_menu_func {
|
||||
vt_img_sector ${1}${chosen_path}
|
||||
|
||||
if [ "$vtoy_os" = "Windows" ]; then
|
||||
vt_check_pe (loop)
|
||||
if [ "$VT_PE_SUPPORT" != "YES" ]; then
|
||||
if [ "$ventoy_fs_probe" = "iso9660" ]; then
|
||||
set ventoy_compatible=YES
|
||||
fi
|
||||
fi
|
||||
|
||||
vt_check_compatible_pe (loop)
|
||||
uefi_windows_menu_func $1 ${chosen_path}
|
||||
else
|
||||
uefi_linux_menu_func $1 ${chosen_path}
|
||||
fi
|
||||
|
||||
terminal_output gfxterm
|
||||
ventoy_gui_console
|
||||
}
|
||||
|
||||
function uefi_iso_memdisk {
|
||||
@@ -278,9 +362,11 @@ function uefi_iso_memdisk {
|
||||
echo 'Loading ISO file to memory ...'
|
||||
vt_load_iso_to_mem ${1}${chosen_path} vtoy_iso_buf
|
||||
|
||||
terminal_output console
|
||||
ventoy_cli_console
|
||||
chainloader ${vtoy_path}/ventoy_x64.efi memdisk env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_iso_buf_addr}:size:${vtoy_iso_buf_size}
|
||||
boot
|
||||
|
||||
ventoy_gui_console
|
||||
}
|
||||
|
||||
|
||||
@@ -288,31 +374,49 @@ function legacy_windows_menu_func {
|
||||
vt_windows_reset
|
||||
|
||||
if [ "$ventoy_compatible" = "NO" ]; then
|
||||
find_wim_file (loop)
|
||||
if [ -n "$ventoy_wim_file" ]; then
|
||||
vt_windows_locate_wim $ventoy_wim_file
|
||||
elif [ -n "${vtdebug_flag}" ]; then
|
||||
echo No wim file found
|
||||
|
||||
if [ "$ventoy_fs_probe" = "iso9660" ]; then
|
||||
loopback -d loop
|
||||
vt_iso9660_nojoliet 1
|
||||
loopback loop $1$2
|
||||
fi
|
||||
|
||||
for file in "boot/bcd" "/efi/microsoft/boot/bcd" "SSTR/BCD"; do
|
||||
vt_windows_collect_wim_patch bcd (loop)/$file
|
||||
done
|
||||
|
||||
distro_specify_wim_patch
|
||||
|
||||
vt_windows_count_wim_patch vt_wim_cnt
|
||||
if [ $vt_wim_cnt -eq 0 ]; then
|
||||
distro_specify_wim_patch_phase2
|
||||
fi
|
||||
|
||||
ventoy_debug_pause
|
||||
locate_wim
|
||||
fi
|
||||
|
||||
vt_windows_chain_data ${1}${chosen_path}
|
||||
|
||||
if [ -n "${vtdebug_flag}" ]; then
|
||||
sleep 5
|
||||
fi
|
||||
ventoy_debug_pause
|
||||
|
||||
if [ -n "$vtoy_chain_mem_addr" ]; then
|
||||
linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
|
||||
boot
|
||||
else
|
||||
echo "chain empty failed"
|
||||
sleep 5
|
||||
ventoy_pause
|
||||
fi
|
||||
}
|
||||
|
||||
function legacy_linux_menu_func {
|
||||
if [ "$ventoy_compatible" = "NO" ]; then
|
||||
|
||||
if [ "$ventoy_fs_probe" = "udf" ]; then
|
||||
loopback -d loop
|
||||
set ventoy_fs_probe=iso9660
|
||||
loopback loop $1$2
|
||||
fi
|
||||
|
||||
vt_load_cpio $vtoy_path/ventoy.cpio $2 $1
|
||||
|
||||
vt_linux_clear_initrd
|
||||
@@ -353,17 +457,14 @@ function legacy_linux_menu_func {
|
||||
fi
|
||||
|
||||
vt_linux_chain_data ${1}${chosen_path}
|
||||
|
||||
if [ -n "${vtdebug_flag}" ]; then
|
||||
sleep 5
|
||||
fi
|
||||
ventoy_debug_pause
|
||||
|
||||
if [ -n "$vtoy_chain_mem_addr" ]; then
|
||||
linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
|
||||
boot
|
||||
else
|
||||
echo "chain empty failed"
|
||||
sleep 5
|
||||
ventoy_pause
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -381,10 +482,10 @@ function legacy_iso_menu_func {
|
||||
set ventoy_fs_probe=udf
|
||||
else
|
||||
set ventoy_fs_probe=iso9660
|
||||
vt_iso9660_nojoliet 0
|
||||
fi
|
||||
|
||||
loopback loop ${1}${chosen_path}
|
||||
|
||||
get_os_type (loop)
|
||||
|
||||
if [ -n "$vtcompat" ]; then
|
||||
@@ -399,13 +500,7 @@ function legacy_iso_menu_func {
|
||||
vt_img_sector ${1}${chosen_path}
|
||||
|
||||
if [ "$vtoy_os" = "Windows" ]; then
|
||||
vt_check_pe (loop)
|
||||
if [ "$VT_PE_SUPPORT" != "YES" ]; then
|
||||
if [ "$ventoy_fs_probe" = "iso9660" ]; then
|
||||
set ventoy_compatible=YES
|
||||
fi
|
||||
fi
|
||||
|
||||
vt_check_compatible_pe (loop)
|
||||
legacy_windows_menu_func $1 ${chosen_path}
|
||||
else
|
||||
legacy_linux_menu_func $1 ${chosen_path}
|
||||
@@ -437,40 +532,57 @@ function iso_common_menuentry {
|
||||
fi
|
||||
}
|
||||
|
||||
function iso_unsupport_menuentry {
|
||||
function common_unsupport_menuentry {
|
||||
echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
|
||||
echo -e " 文件名中不能有中文或空格 \n"
|
||||
echo -e "\n Will return to main menu after 10 seconds ...\n"
|
||||
sleep 10
|
||||
}
|
||||
|
||||
function iso_unsupport_menuentry {
|
||||
common_unsupport_menuentry
|
||||
}
|
||||
|
||||
function wim_common_menuentry {
|
||||
vt_chosen_img_path chosen_path
|
||||
vt_wim_chain_data ${iso_path}${chosen_path}
|
||||
if [ -n "${vtdebug_flag}" ]; then
|
||||
sleep 5
|
||||
fi
|
||||
|
||||
ventoy_debug_pause
|
||||
|
||||
if [ -n "$vtoy_chain_mem_addr" ]; then
|
||||
if [ "$grub_platform" = "pc" ]; then
|
||||
linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
|
||||
else
|
||||
terminal_output console
|
||||
ventoy_cli_console
|
||||
chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
|
||||
ventoy_gui_console
|
||||
fi
|
||||
boot
|
||||
else
|
||||
echo "chain empty failed"
|
||||
sleep 5
|
||||
ventoy_pause
|
||||
fi
|
||||
}
|
||||
|
||||
function wim_unsupport_menuentry {
|
||||
echo -e "\n The name of the wim file could NOT contain space or non-ascii characters. \n"
|
||||
echo -e "\n Will return to main menu after 10 seconds ...\n"
|
||||
sleep 10
|
||||
common_unsupport_menuentry
|
||||
}
|
||||
|
||||
function efi_common_menuentry {
|
||||
vt_chosen_img_path chosen_path
|
||||
|
||||
ventoy_cli_console
|
||||
chainloader ${iso_path}${chosen_path}
|
||||
boot
|
||||
ventoy_gui_console
|
||||
}
|
||||
|
||||
function efi_unsupport_menuentry {
|
||||
common_unsupport_menuentry
|
||||
}
|
||||
|
||||
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
#############################################################
|
||||
@@ -479,21 +591,20 @@ function wim_unsupport_menuentry {
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
set VENTOY_VERSION="1.0.12"
|
||||
set VENTOY_VERSION="1.0.15"
|
||||
|
||||
# Default menu display mode, you can change it as you want.
|
||||
# 0: List mode
|
||||
# 1: TreeView mode
|
||||
set VTOY_DEFAULT_MENU_MODE=0
|
||||
|
||||
#disable timeout
|
||||
unset timeout
|
||||
|
||||
set VTOY_MEM_DISK_STR="[Memdisk]"
|
||||
set VTOY_ISO_RAW_STR="ISO RAW"
|
||||
set VTOY_ISO_RAW_STR="Compatible Mode"
|
||||
set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
|
||||
|
||||
set VTOY_F2_CMD="ventoy_power"
|
||||
set VTOY_F4_CMD="ventoy_localboot"
|
||||
set VTOY_F5_CMD="ventoy_diagnosis"
|
||||
|
||||
if [ "$grub_platform" = "pc" ]; then
|
||||
set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
|
||||
@@ -512,19 +623,39 @@ if [ "$vtoy_dev" = "tftp" ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
loadfont ascii
|
||||
|
||||
if [ -f $iso_path/ventoy/ventoy.json ]; then
|
||||
set vt_plugin_path=$iso_path
|
||||
else
|
||||
set vt_plugin_path=$prefix
|
||||
vt_load_plugin $vt_plugin_path
|
||||
fi
|
||||
else
|
||||
set vtoy_path=($root)/ventoy
|
||||
if [ "$prefix" = "(ventoydisk)/grub" ]; then
|
||||
set vtoy_path=(ventoydisk)/ventoy
|
||||
else
|
||||
set vtoy_path=($root)/ventoy
|
||||
fi
|
||||
|
||||
set iso_path=($vtoy_dev,1)
|
||||
set vtoy_efi_part=($vtoy_dev,2)
|
||||
loadfont unicode
|
||||
set vt_plugin_path=$iso_path
|
||||
fi
|
||||
|
||||
loadfont ascii
|
||||
|
||||
#Load Plugin
|
||||
if [ -f $iso_path/ventoy/ventoy.json ]; then
|
||||
vt_load_plugin $iso_path
|
||||
fi
|
||||
|
||||
if [ -n "$VTOY_MENU_TIMEOUT" ]; then
|
||||
set timeout=$VTOY_MENU_TIMEOUT
|
||||
else
|
||||
unset timeout
|
||||
fi
|
||||
|
||||
if [ -f $iso_path/ventoy/ventoy_wimboot.img ]; then
|
||||
vt_load_wimboot $iso_path/ventoy/ventoy_wimboot.img
|
||||
elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
|
||||
@@ -534,10 +665,10 @@ fi
|
||||
|
||||
if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
|
||||
set VTOY_F3_CMD="vt_dynamic_menu 1 1"
|
||||
set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView"
|
||||
set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Debug"
|
||||
else
|
||||
set VTOY_F3_CMD="vt_dynamic_menu 1 0"
|
||||
set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView"
|
||||
set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Debug"
|
||||
fi
|
||||
|
||||
|
||||
@@ -547,14 +678,17 @@ else
|
||||
set gfxmode=1920x1080,1366x768,1024x768
|
||||
fi
|
||||
|
||||
if [ -n "$vtoy_theme" ]; then
|
||||
set theme=$vtoy_theme
|
||||
if [ "$vtoy_display_mode" = "CLI" ]; then
|
||||
terminal_output console
|
||||
else
|
||||
set theme=$prefix/themes/ventoy/theme.txt
|
||||
if [ -n "$vtoy_theme" ]; then
|
||||
set theme=$vtoy_theme
|
||||
else
|
||||
set theme=$prefix/themes/ventoy/theme.txt
|
||||
fi
|
||||
terminal_output gfxterm
|
||||
fi
|
||||
|
||||
terminal_output gfxterm
|
||||
|
||||
#colect all image files (iso files)
|
||||
set ventoy_img_count=0
|
||||
vt_list_img $iso_path ventoy_img_count
|
||||
|
Binary file not shown.
BIN
INSTALL/grub/i386-pc/elf.mod
Normal file
BIN
INSTALL/grub/i386-pc/elf.mod
Normal file
Binary file not shown.
BIN
INSTALL/grub/i386-pc/file.mod
Normal file
BIN
INSTALL/grub/i386-pc/file.mod
Normal file
Binary file not shown.
BIN
INSTALL/grub/i386-pc/macho.mod
Normal file
BIN
INSTALL/grub/i386-pc/macho.mod
Normal file
Binary file not shown.
BIN
INSTALL/grub/i386-pc/offsetio.mod
Normal file
BIN
INSTALL/grub/i386-pc/offsetio.mod
Normal file
Binary file not shown.
BIN
INSTALL/grub/i386-pc/regexp.mod
Normal file
BIN
INSTALL/grub/i386-pc/regexp.mod
Normal file
Binary file not shown.
65
INSTALL/grub/localboot.cfg
Normal file
65
INSTALL/grub/localboot.cfg
Normal file
@@ -0,0 +1,65 @@
|
||||
|
||||
if [ "$grub_platform" = "pc" ]; then
|
||||
menuentry 'Search and boot Windows' --class=boot_windows {
|
||||
if search -n -s -f /bootmgr; then
|
||||
ntldr /bootmgr
|
||||
elif search -n -s -f /ntldr; then
|
||||
ntldr /ntldr
|
||||
else
|
||||
echo "Windows NOT found ..."
|
||||
fi
|
||||
}
|
||||
|
||||
menuentry 'Search and boot Grub4dos' --class=boot_g4d {
|
||||
if search -n -s -f /grldr; then
|
||||
ntldr /grldr
|
||||
else
|
||||
echo "Grub4dos NOT found ..."
|
||||
fi
|
||||
}
|
||||
|
||||
menuentry 'Boot the 1st local disk' --class=boot_disk {
|
||||
set root=(hd0,1)
|
||||
chainloader +1
|
||||
boot
|
||||
}
|
||||
|
||||
menuentry 'Boot the 2nd local disk' --class=boot_disk {
|
||||
set root=(hd1,1)
|
||||
chainloader +1
|
||||
boot
|
||||
}
|
||||
|
||||
menuentry 'Boot the 3rd local disk' --class=boot_disk {
|
||||
set root=(hd2,1)
|
||||
chainloader +1
|
||||
boot
|
||||
}
|
||||
|
||||
else
|
||||
|
||||
menuentry 'Search and boot Windows' --class=boot_windows {
|
||||
if search -n -s -f /EFI/Microsoft/Boot/bootmgfw.efi; then
|
||||
terminal_output console
|
||||
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
|
||||
boot
|
||||
else
|
||||
echo "Windows NOT found ..."
|
||||
fi
|
||||
}
|
||||
|
||||
menuentry 'Search and boot BOOTX64.EFI' --class=boot_uefi {
|
||||
if search -n -s -f /efi/boot/bootx64.efi; then
|
||||
terminal_output console
|
||||
chainloader /efi/boot/bootx64.efi
|
||||
boot
|
||||
else
|
||||
echo "BOOTX64.EFI NOT found ..."
|
||||
fi
|
||||
}
|
||||
|
||||
fi
|
||||
|
||||
menuentry 'Return to menu [Esc]' --class=vtoyret VTOY_RET {
|
||||
echo 'Return ...'
|
||||
}
|
@@ -1,15 +1,15 @@
|
||||
menuentry Reboot {
|
||||
menuentry Reboot --class=power_reboot {
|
||||
echo -e '\n\nSystem is rebooting ... \n'
|
||||
sleep 1
|
||||
reboot
|
||||
}
|
||||
|
||||
menuentry Halt {
|
||||
menuentry Halt --class=power_halt {
|
||||
echo -e '\n\nSystem is halting ... \n'
|
||||
sleep 1
|
||||
reboot
|
||||
halt
|
||||
}
|
||||
|
||||
menuentry 'Return to menu [Esc]' VTOY_RET {
|
||||
menuentry 'Return to menu [Esc]' --class=vtoyret VTOY_RET {
|
||||
echo 'Return ...'
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 257 KiB After Width: | Height: | Size: 257 KiB |
@@ -1,9 +1,7 @@
|
||||
|
||||
desktop-image: "background.png"
|
||||
title-text: " "
|
||||
title-font: "ascii"
|
||||
title-color: "#ffffff"
|
||||
message-font: "ascii"
|
||||
message-color: "#f2f2f2"
|
||||
|
||||
terminal-box: "terminal_box_*.png"
|
||||
@@ -16,14 +14,12 @@ terminal-box: "terminal_box_*.png"
|
||||
|
||||
menu_pixmap_style = "menu_*.png"
|
||||
|
||||
item_font = "ascii"
|
||||
item_color = "#ffffff"
|
||||
item_height = 30
|
||||
|
||||
item_spacing = 1
|
||||
item_padding = 1
|
||||
|
||||
selected_item_font = "ascii"
|
||||
selected_item_color= "#f2f2f2"
|
||||
selected_item_pixmap_style = "select_*.png"
|
||||
|
||||
@@ -38,12 +34,11 @@ terminal-box: "terminal_box_*.png"
|
||||
id = "__timeout__"
|
||||
text = "@TIMEOUT_NOTIFICATION_SHORT@"
|
||||
|
||||
left = 95%
|
||||
width = 48
|
||||
top = 95%
|
||||
height = 48
|
||||
left = 20%
|
||||
width = 60%
|
||||
top = 85%
|
||||
|
||||
text_color = "#f2f2f2"
|
||||
text_color = "red"
|
||||
bar_style = "*"
|
||||
highlight_style = "*"
|
||||
}
|
||||
@@ -67,8 +62,8 @@ terminal-box: "terminal_box_*.png"
|
||||
|
||||
|
||||
+ hbox{
|
||||
left = 90%
|
||||
top = 30
|
||||
left = 30%
|
||||
top = 95%-50
|
||||
width = 10%
|
||||
height = 25
|
||||
+ label {text = "@VTOY_ISO_RAW@" color = "red" align = "left"}
|
||||
|
Binary file not shown.
@@ -6,16 +6,17 @@ print_usage() {
|
||||
echo 'Usage: Ventoy2Disk.sh CMD [ OPTION ] /dev/sdX'
|
||||
echo ' CMD:'
|
||||
echo ' -i install ventoy to sdX (fail if disk already installed with ventoy)'
|
||||
echo ' -u update ventoy in sdX'
|
||||
echo ' -I force install ventoy to sdX (no matter installed or not)'
|
||||
echo ' -u update ventoy in sdX'
|
||||
echo ''
|
||||
echo ' OPTION: (optional)'
|
||||
echo ' -s enable secure boot support (default is disabled)'
|
||||
echo ' -r SIZE_MB preserve some space at the bottom of the disk (only for install)'
|
||||
echo ' -s enable secure boot support (default is disabled)'
|
||||
echo ' -g use GPT partition style, default is MBR (only for install)'
|
||||
echo ''
|
||||
|
||||
}
|
||||
|
||||
|
||||
RESERVE_SIZE_MB=0
|
||||
while [ -n "$1" ]; do
|
||||
if [ "$1" = "-i" ]; then
|
||||
MODE="install"
|
||||
@@ -26,6 +27,12 @@ while [ -n "$1" ]; do
|
||||
MODE="update"
|
||||
elif [ "$1" = "-s" ]; then
|
||||
SECUREBOOT="YES"
|
||||
elif [ "$1" = "-g" ]; then
|
||||
VTGPT="YES"
|
||||
elif [ "$1" = "-r" ]; then
|
||||
RESERVE_SPACE="YES"
|
||||
shift
|
||||
RESERVE_SIZE_MB=$1
|
||||
else
|
||||
if ! [ -b "$1" ]; then
|
||||
vterr "$1 is NOT a valid device"
|
||||
@@ -53,6 +60,15 @@ if [ -e /sys/class/block/${DISK#/dev/}/start ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -n "$RESERVE_SPACE" ]; then
|
||||
if echo $RESERVE_SIZE_MB | grep -q '^[0-9][0-9]*$'; then
|
||||
vtdebug "User will reserve $RESERVE_SIZE_MB MB disk space"
|
||||
else
|
||||
vterr "$RESERVE_SIZE_MB is invalid for reserved space"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if dd if="$DISK" of=/dev/null bs=1 count=1 >/dev/null 2>&1; then
|
||||
vtdebug "root permission check ok ..."
|
||||
else
|
||||
@@ -61,7 +77,7 @@ else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
vtdebug "MODE=$MODE FORCE=$FORCE"
|
||||
vtdebug "MODE=$MODE FORCE=$FORCE RESERVE_SPACE=$RESERVE_SPACE RESERVE_SIZE_MB=$RESERVE_SIZE_MB"
|
||||
|
||||
if ! check_tool_work_ok; then
|
||||
vterr "Some tools can not run in current system. Please check log.txt for detail."
|
||||
@@ -96,13 +112,22 @@ fi
|
||||
if [ "$MODE" = "install" ]; then
|
||||
vtdebug "install ventoy ..."
|
||||
|
||||
if parted -v > /dev/null 2>&1; then
|
||||
PARTTOOL='parted'
|
||||
elif fdisk -v >/dev/null 2>&1; then
|
||||
PARTTOOL='fdisk'
|
||||
if [ -n "$VTGPT" ]; then
|
||||
if parted -v > /dev/null 2>&1; then
|
||||
PARTTOOL='parted'
|
||||
else
|
||||
vterr "parted is not found in the sysstem, Ventoy can't create new partition."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
vterr "Both parted and fdisk are not found in the sysstem, Ventoy can't create new partition."
|
||||
exit 1
|
||||
if parted -v > /dev/null 2>&1; then
|
||||
PARTTOOL='parted'
|
||||
elif fdisk -v >/dev/null 2>&1; then
|
||||
PARTTOOL='fdisk'
|
||||
else
|
||||
vterr "Both parted and fdisk are not found in the sysstem, Ventoy can't create new partition."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
version=$(get_disk_ventoy_version $DISK)
|
||||
@@ -124,10 +149,30 @@ if [ "$MODE" = "install" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -n "$RESERVE_SPACE" ]; then
|
||||
sum_size_mb=$(expr $RESERVE_SIZE_MB + $VENTOY_PART_SIZE_MB)
|
||||
reserve_sector_num=$(expr $sum_size_mb \* 2048)
|
||||
|
||||
if [ $disk_sector_num -le $reserve_sector_num ]; then
|
||||
vterr "Can't reserve $RESERVE_SIZE_MB MB space from $DISK"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
#Print disk info
|
||||
echo "Disk : $DISK"
|
||||
parted -s $DISK p 2>&1 | grep Model
|
||||
echo "Size : $disk_size_gb GB"
|
||||
if [ -n "$VTGPT" ]; then
|
||||
echo "Style: GPT"
|
||||
else
|
||||
echo "Style: MBR"
|
||||
fi
|
||||
echo ''
|
||||
|
||||
if [ -n "$RESERVE_SPACE" ]; then
|
||||
echo "You will reserve $RESERVE_SIZE_MB MB disk space "
|
||||
fi
|
||||
echo ''
|
||||
|
||||
vtwarn "Attention:"
|
||||
@@ -162,7 +207,13 @@ if [ "$MODE" = "install" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
format_ventoy_disk $DISK $PARTTOOL
|
||||
if [ -n "$VTGPT" ]; then
|
||||
vtdebug "format_ventoy_disk_gpt $RESERVE_SIZE_MB $DISK $PARTTOOL ..."
|
||||
format_ventoy_disk_gpt $RESERVE_SIZE_MB $DISK $PARTTOOL
|
||||
else
|
||||
vtdebug "format_ventoy_disk_mbr $RESERVE_SIZE_MB $DISK $PARTTOOL ..."
|
||||
format_ventoy_disk_mbr $RESERVE_SIZE_MB $DISK $PARTTOOL
|
||||
fi
|
||||
|
||||
# format part1
|
||||
if ventoy_is_linux64; then
|
||||
@@ -186,8 +237,17 @@ if [ "$MODE" = "install" ]; then
|
||||
chmod +x ./tool/vtoy_gen_uuid
|
||||
|
||||
vtinfo "writing data to disk ..."
|
||||
|
||||
dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=446
|
||||
./tool/xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1
|
||||
|
||||
if [ -n "$VTGPT" ]; then
|
||||
echo -en '\x22' | dd status=none of=$DISK conv=fsync bs=1 count=1 seek=92
|
||||
./tool/xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2014 seek=34
|
||||
echo -en '\x23' | dd of=$DISK conv=fsync bs=1 count=1 seek=17908 status=none
|
||||
else
|
||||
./tool/xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1
|
||||
fi
|
||||
|
||||
./tool/xzcat ./ventoy/ventoy.disk.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start_sector
|
||||
|
||||
#disk uuid
|
||||
@@ -263,23 +323,31 @@ else
|
||||
fi
|
||||
|
||||
PART2=$(get_disk_part_name $DISK 2)
|
||||
SHORT_PART2=${PART2#/dev/}
|
||||
part2_start=$(cat /sys/class/block/$SHORT_PART2/start)
|
||||
|
||||
dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=440
|
||||
PART1_TYPE=$(dd if=$DISK bs=1 count=1 skip=450 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
|
||||
|
||||
PART1_ACTIVE=$(dd if=$DISK bs=1 count=1 skip=446 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
|
||||
PART2_ACTIVE=$(dd if=$DISK bs=1 count=1 skip=462 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
|
||||
if [ "$PART1_TYPE" = "EE" ]; then
|
||||
vtdebug "This is GPT partition style ..."
|
||||
./tool/xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2014 seek=34
|
||||
echo -en '\x23' | dd of=$DISK conv=fsync bs=1 count=1 seek=17908 status=none
|
||||
else
|
||||
vtdebug "This is MBR partition style ..."
|
||||
dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=440
|
||||
|
||||
vtdebug "PART1_ACTIVE=$PART1_ACTIVE PART2_ACTIVE=$PART2_ACTIVE"
|
||||
if [ "$PART1_ACTIVE" = "00" ] && [ "$PART2_ACTIVE" = "80" ]; then
|
||||
vtdebug "change 1st partition active, 2nd partition inactive ..."
|
||||
echo -en '\x80' | dd of=$DISK conv=fsync bs=1 count=1 seek=446 status=none
|
||||
echo -en '\x00' | dd of=$DISK conv=fsync bs=1 count=1 seek=462 status=none
|
||||
PART1_ACTIVE=$(dd if=$DISK bs=1 count=1 skip=446 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
|
||||
PART2_ACTIVE=$(dd if=$DISK bs=1 count=1 skip=462 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
|
||||
|
||||
vtdebug "PART1_ACTIVE=$PART1_ACTIVE PART2_ACTIVE=$PART2_ACTIVE"
|
||||
if [ "$PART1_ACTIVE" = "00" ] && [ "$PART2_ACTIVE" = "80" ]; then
|
||||
vtdebug "change 1st partition active, 2nd partition inactive ..."
|
||||
echo -en '\x80' | dd of=$DISK conv=fsync bs=1 count=1 seek=446 status=none
|
||||
echo -en '\x00' | dd of=$DISK conv=fsync bs=1 count=1 seek=462 status=none
|
||||
fi
|
||||
./tool/xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1
|
||||
fi
|
||||
|
||||
./tool/xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1
|
||||
|
||||
disk_sector_num=$(cat /sys/block/${DISK#/dev/}/size)
|
||||
part2_start=$(expr $disk_sector_num - $VENTOY_SECTOR_NUM)
|
||||
./tool/xzcat ./ventoy/ventoy.disk.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start
|
||||
|
||||
sync
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
#Ventoy partition 32MB
|
||||
VENTOY_PART_SIZE=33554432
|
||||
VENTOY_PART_SIZE_MB=32
|
||||
VENTOY_SECTOR_SIZE=512
|
||||
VENTOY_SECTOR_NUM=65536
|
||||
|
||||
@@ -125,11 +126,15 @@ is_disk_contains_ventoy() {
|
||||
return
|
||||
fi
|
||||
|
||||
PART1_TYPE=$(dd if=$DISK bs=1 count=1 skip=450 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
|
||||
PART2_TYPE=$(dd if=$DISK bs=1 count=1 skip=466 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
|
||||
if [ "$PART2_TYPE" != "EF" ]; then
|
||||
vtdebug "part2 type is $PART2_TYPE not EF"
|
||||
ventoy_false
|
||||
return
|
||||
|
||||
if [ "$PART1_TYPE" != "EE" ]; then
|
||||
if [ "$PART2_TYPE" != "EF" ]; then
|
||||
vtdebug "part2 type is $PART2_TYPE not EF"
|
||||
ventoy_false
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
# PART1_TYPE=$(dd if=$DISK bs=1 count=1 skip=450 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
|
||||
@@ -184,9 +189,10 @@ get_disk_ventoy_version() {
|
||||
ventoy_false
|
||||
}
|
||||
|
||||
format_ventoy_disk() {
|
||||
DISK=$1
|
||||
PARTTOOL=$2
|
||||
format_ventoy_disk_mbr() {
|
||||
reserve_mb=$1
|
||||
DISK=$2
|
||||
PARTTOOL=$3
|
||||
|
||||
PART1=$(get_disk_part_name $DISK 1)
|
||||
PART2=$(get_disk_part_name $DISK 2)
|
||||
@@ -194,9 +200,18 @@ format_ventoy_disk() {
|
||||
sector_num=$(cat /sys/block/${DISK#/dev/}/size)
|
||||
|
||||
part1_start_sector=2048
|
||||
part1_end_sector=$(expr $sector_num - $VENTOY_SECTOR_NUM - 1)
|
||||
export part2_start_sector=$(expr $part1_end_sector + 1)
|
||||
part2_end_sector=$(expr $sector_num - 1)
|
||||
|
||||
if [ $reserve_mb -gt 0 ]; then
|
||||
reserve_sector_num=$(expr $reserve_mb \* 2048)
|
||||
part1_end_sector=$(expr $sector_num - $reserve_sector_num - $VENTOY_SECTOR_NUM - 1)
|
||||
else
|
||||
part1_end_sector=$(expr $sector_num - $VENTOY_SECTOR_NUM - 1)
|
||||
fi
|
||||
|
||||
part2_start_sector=$(expr $part1_end_sector + 1)
|
||||
part2_end_sector=$(expr $part2_start_sector + $VENTOY_SECTOR_NUM - 1)
|
||||
|
||||
export part2_start_sector
|
||||
|
||||
vtdebug "part1_start_sector=$part1_start_sector part1_end_sector=$part1_end_sector"
|
||||
vtdebug "part2_start_sector=$part2_start_sector part2_end_sector=$part2_end_sector"
|
||||
@@ -207,7 +222,7 @@ format_ventoy_disk() {
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Create partitions on $DISK by $PARTTOOL ..."
|
||||
echo "Create partitions on $DISK by $PARTTOOL in MBR style ..."
|
||||
|
||||
if [ "$PARTTOOL" = "parted" ]; then
|
||||
vtdebug "format disk by parted ..."
|
||||
@@ -278,7 +293,104 @@ EOF
|
||||
|
||||
echo "create efi fat fs $PART2 ..."
|
||||
for i in 0 1 2 3 4 5 6 7 8 9; do
|
||||
if mkfs.vfat -F 16 -n EFI $PART2; then
|
||||
if mkfs.vfat -F 16 -n VTOYEFI $PART2; then
|
||||
echo 'success'
|
||||
break
|
||||
else
|
||||
echo "$? retry ..."
|
||||
sleep 2
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
format_ventoy_disk_gpt() {
|
||||
reserve_mb=$1
|
||||
DISK=$2
|
||||
PARTTOOL=$3
|
||||
|
||||
PART1=$(get_disk_part_name $DISK 1)
|
||||
PART2=$(get_disk_part_name $DISK 2)
|
||||
|
||||
sector_num=$(cat /sys/block/${DISK#/dev/}/size)
|
||||
|
||||
part1_start_sector=2048
|
||||
|
||||
if [ $reserve_mb -gt 0 ]; then
|
||||
reserve_sector_num=$(expr $reserve_mb \* 2048 + 33)
|
||||
part1_end_sector=$(expr $sector_num - $reserve_sector_num - $VENTOY_SECTOR_NUM - 1)
|
||||
else
|
||||
part1_end_sector=$(expr $sector_num - $VENTOY_SECTOR_NUM - 34)
|
||||
fi
|
||||
|
||||
part2_start_sector=$(expr $part1_end_sector + 1)
|
||||
part2_end_sector=$(expr $part2_start_sector + $VENTOY_SECTOR_NUM - 1)
|
||||
|
||||
export part2_start_sector
|
||||
|
||||
vtdebug "part1_start_sector=$part1_start_sector part1_end_sector=$part1_end_sector"
|
||||
vtdebug "part2_start_sector=$part2_start_sector part2_end_sector=$part2_end_sector"
|
||||
|
||||
if [ -e $PART2 ]; then
|
||||
echo "delete $PART2"
|
||||
rm -f $PART2
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Create partitions on $DISK by $PARTTOOL in GPT style ..."
|
||||
|
||||
vtdebug "format disk by parted ..."
|
||||
parted -a none --script $DISK \
|
||||
mklabel gpt \
|
||||
unit s \
|
||||
mkpart Ventoy ntfs $part1_start_sector $part1_end_sector \
|
||||
mkpart VTOYEFI fat16 $part2_start_sector $part2_end_sector \
|
||||
set 2 msftdata on \
|
||||
set 2 hidden on \
|
||||
quit
|
||||
|
||||
sync
|
||||
|
||||
if ventoy_is_linux64; then
|
||||
vtoygpt=./tool/vtoygpt_64
|
||||
else
|
||||
vtoygpt=./tool/vtoygpt_32
|
||||
fi
|
||||
|
||||
$vtoygpt -f $DISK
|
||||
sync
|
||||
|
||||
udevadm trigger >/dev/null 2>&1
|
||||
partprobe >/dev/null 2>&1
|
||||
sleep 3
|
||||
echo "Done"
|
||||
|
||||
echo 'mkfs on disk partitions ...'
|
||||
for i in 1 2 3 4 5 6 7; do
|
||||
if [ -b $PART2 ]; then
|
||||
break
|
||||
else
|
||||
echo "wait $PART2 ..."
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
if ! [ -b $PART2 ]; then
|
||||
MajorMinor=$(sed "s/:/ /" /sys/class/block/${PART2#/dev/}/dev)
|
||||
echo "mknod -m 0660 $PART2 b $MajorMinor ..."
|
||||
mknod -m 0660 $PART2 b $MajorMinor
|
||||
|
||||
if ! [ -b $PART1 ]; then
|
||||
MajorMinor=$(sed "s/:/ /" /sys/class/block/${PART1#/dev/}/dev)
|
||||
echo "mknod -m 0660 $PART1 b $MajorMinor ..."
|
||||
mknod -m 0660 $PART1 b $MajorMinor
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "create efi fat fs $PART2 ..."
|
||||
for i in 0 1 2 3 4 5 6 7 8 9; do
|
||||
if mkfs.vfat -F 16 -n VTOYEFI $PART2; then
|
||||
echo 'success'
|
||||
break
|
||||
else
|
||||
@@ -291,3 +403,4 @@ EOF
|
||||
|
||||
|
||||
|
||||
|
||||
|
BIN
INSTALL/tool/vtoygpt_32
Normal file
BIN
INSTALL/tool/vtoygpt_32
Normal file
Binary file not shown.
BIN
INSTALL/tool/vtoygpt_64
Normal file
BIN
INSTALL/tool/vtoygpt_64
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
INSTALL/ventoy/vtoyutil_x64.efi
Normal file
BIN
INSTALL/ventoy/vtoyutil_x64.efi
Normal file
Binary file not shown.
@@ -31,7 +31,7 @@ while ! grep -q 524288 /sys/block/${LOOP#/dev/}/size 2>/dev/null; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
format_ventoy_disk $LOOP fdisk
|
||||
format_ventoy_disk_mbr 0 $LOOP fdisk
|
||||
|
||||
$GRUB_DIR/sbin/grub-bios-setup --skip-fs-probe --directory="./grub/i386-pc" $LOOP
|
||||
|
||||
@@ -104,7 +104,7 @@ cd $CurDir
|
||||
tar -czvf ventoy-${curver}-linux.tar.gz $tmpdir
|
||||
|
||||
rm -f ventoy-${curver}-windows.zip
|
||||
cp -a Ventoy2Disk.exe $tmpdir/
|
||||
cp -a Ventoy2Disk*.exe $tmpdir/
|
||||
cp -a $LANG_DIR/languages.ini $tmpdir/ventoy/
|
||||
rm -rf $tmpdir/tool
|
||||
rm -f $tmpdir/*.sh
|
||||
|
@@ -33,6 +33,8 @@ ventoy_img_chunk *g_chunk;
|
||||
uint32_t g_img_chunk_num;
|
||||
ventoy_img_chunk *g_cur_chunk;
|
||||
uint32_t g_disk_sector_size;
|
||||
uint8_t *g_os_param_reserved;
|
||||
|
||||
|
||||
ventoy_override_chunk *g_override_chunk;
|
||||
uint32_t g_override_chunk_num;
|
||||
@@ -42,6 +44,14 @@ uint32_t g_virt_chunk_num;
|
||||
|
||||
ventoy_sector_flag g_sector_flag[128];
|
||||
|
||||
#define VENTOY_ISO9660_SECTOR_OVERFLOW 2097152
|
||||
|
||||
int g_fixup_iso9660_secover_enable = 0;
|
||||
int g_fixup_iso9660_secover_start = 0;
|
||||
uint64 g_fixup_iso9660_secover_1st_secs = 0;
|
||||
uint64 g_fixup_iso9660_secover_cur_secs = 0;
|
||||
uint64 g_fixup_iso9660_secover_tot_secs = 0;
|
||||
|
||||
static struct int13_disk_address __bss16 ( ventoy_address );
|
||||
#define ventoy_address __use_data16 ( ventoy_address )
|
||||
|
||||
@@ -195,6 +205,17 @@ static int ventoy_vdisk_read_real(uint64_t lba, unsigned int count, unsigned lon
|
||||
memcpy((char *)databuffer, override_data + start - override_start, override_end - start);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_fixup_iso9660_secover_enable && (!g_fixup_iso9660_secover_start) &&
|
||||
g_override_chunk[i].override_size == sizeof(ventoy_iso9660_override))
|
||||
{
|
||||
ventoy_iso9660_override *dirent = (ventoy_iso9660_override *)override_data;
|
||||
if (dirent->first_sector >= VENTOY_ISO9660_SECTOR_OVERFLOW)
|
||||
{
|
||||
g_fixup_iso9660_secover_start = 1;
|
||||
g_fixup_iso9660_secover_cur_secs = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
@@ -202,6 +223,59 @@ end:
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t ventoy_fixup_iso9660_sector(uint64_t Lba, uint32_t secNum)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
|
||||
if (g_fixup_iso9660_secover_cur_secs > 0)
|
||||
{
|
||||
Lba += VENTOY_ISO9660_SECTOR_OVERFLOW;
|
||||
g_fixup_iso9660_secover_cur_secs += secNum;
|
||||
if (g_fixup_iso9660_secover_cur_secs >= g_fixup_iso9660_secover_tot_secs)
|
||||
{
|
||||
g_fixup_iso9660_secover_start = 0;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ventoy_iso9660_override *dirent;
|
||||
ventoy_override_chunk *pOverride;
|
||||
|
||||
for (i = 0, pOverride = g_override_chunk; i < g_override_chunk_num; i++, pOverride++)
|
||||
{
|
||||
dirent = (ventoy_iso9660_override *)pOverride->override_data;
|
||||
if (Lba == dirent->first_sector)
|
||||
{
|
||||
g_fixup_iso9660_secover_start = 0;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_fixup_iso9660_secover_start)
|
||||
{
|
||||
for (i = 0, pOverride = g_override_chunk; i < g_override_chunk_num; i++, pOverride++)
|
||||
{
|
||||
dirent = (ventoy_iso9660_override *)pOverride->override_data;
|
||||
if (Lba + VENTOY_ISO9660_SECTOR_OVERFLOW == dirent->first_sector)
|
||||
{
|
||||
g_fixup_iso9660_secover_tot_secs = (dirent->size + 2047) / 2048;
|
||||
g_fixup_iso9660_secover_cur_secs = secNum;
|
||||
if (g_fixup_iso9660_secover_cur_secs >= g_fixup_iso9660_secover_tot_secs)
|
||||
{
|
||||
g_fixup_iso9660_secover_start = 0;
|
||||
}
|
||||
Lba += VENTOY_ISO9660_SECTOR_OVERFLOW;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
return Lba;
|
||||
}
|
||||
|
||||
int ventoy_vdisk_read(struct san_device *sandev, uint64_t lba, unsigned int count, unsigned long buffer)
|
||||
{
|
||||
uint32_t i, j;
|
||||
@@ -223,6 +297,12 @@ int ventoy_vdisk_read(struct san_device *sandev, uint64_t lba, unsigned int coun
|
||||
|
||||
ix86 = (struct i386_all_regs *)sandev->x86_regptr;
|
||||
|
||||
/* Workaround for SSTR PE loader error */
|
||||
if (g_fixup_iso9660_secover_start)
|
||||
{
|
||||
lba = ventoy_fixup_iso9660_sector(lba, count);
|
||||
}
|
||||
|
||||
readend = (lba + count) * 2048;
|
||||
if (readend <= g_chain->real_img_size_in_bytes)
|
||||
{
|
||||
@@ -384,6 +464,8 @@ static void ventoy_dump_chain(ventoy_chain_head *chain)
|
||||
printf("os_param->vtoy_img_size=<%llu>\n", chain->os_param.vtoy_img_size);
|
||||
printf("os_param->vtoy_reserve[0]=<%u>\n", vtoy_reserve[0]);
|
||||
printf("os_param->vtoy_reserve[1]=<%u>\n", vtoy_reserve[1]);
|
||||
printf("os_param->vtoy_reserve[2]=<%u>\n", vtoy_reserve[2]);
|
||||
printf("os_param->vtoy_reserve[3]=<%u>\n", vtoy_reserve[3]);
|
||||
printf("os_param->vtoy_img_location_addr=<0x%llx>\n", chain->os_param.vtoy_img_location_addr);
|
||||
printf("os_param->vtoy_img_location_len=<%u>\n", chain->os_param.vtoy_img_location_len);
|
||||
ventoy_debug_pause();
|
||||
@@ -489,6 +571,14 @@ int ventoy_boot_vdisk(void *data)
|
||||
g_disk_sector_size = g_chain->disk_sector_size;
|
||||
g_cur_chunk = g_chunk;
|
||||
|
||||
g_os_param_reserved = (uint8_t *)(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 = 1;
|
||||
}
|
||||
|
||||
g_override_chunk = (ventoy_override_chunk *)((char *)g_chain + g_chain->override_chunk_offset);
|
||||
g_override_chunk_num = g_chain->override_chunk_num;
|
||||
|
||||
|
@@ -1057,6 +1057,28 @@ static __asmcall void int13 ( struct i386_all_regs *ix86 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (VENTOY_BOOT_FIXBIN_DRIVE == bios_drive && INT13_READ_SECTORS == command)
|
||||
{
|
||||
/* read sector 0 0x80 */
|
||||
if (ix86->regs.dh == 0 && (ix86->regs.cl & 0x3f) == 1 && ix86->regs.al == 1)
|
||||
{
|
||||
userptr_t buffer;
|
||||
|
||||
buffer = real_to_user(ix86->segs.es, ix86->regs.bx);
|
||||
if (buffer)
|
||||
{
|
||||
memset((void *)buffer, 0, 512);
|
||||
}
|
||||
|
||||
ix86->regs.dl = 0x80;
|
||||
ix86->regs.ah = 0;
|
||||
|
||||
/* Set OF to indicate to wrapper not to chain this call */
|
||||
ix86->flags |= OF;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// drive swap
|
||||
if (g_drive_map1 >= 0x80 && g_drive_map2 >= 0x80)
|
||||
{
|
||||
|
@@ -85,13 +85,14 @@ struct san_device {
|
||||
struct list_head opened;
|
||||
/** List of closed SAN paths */
|
||||
struct list_head closed;
|
||||
/** SAN paths */
|
||||
struct san_path path[0];
|
||||
|
||||
unsigned int exdrive;
|
||||
int int13_command;
|
||||
void *x86_regptr;
|
||||
uint8_t boot_catalog_sector[2048];
|
||||
|
||||
/** SAN paths */
|
||||
struct san_path path[0];
|
||||
};
|
||||
|
||||
/** SAN device flags */
|
||||
|
@@ -13,6 +13,15 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
|
||||
#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)
|
||||
|
||||
typedef struct ventoy_guid
|
||||
@@ -80,6 +89,14 @@ typedef struct ventoy_os_param
|
||||
grub_uint8_t reserved[31];
|
||||
}ventoy_os_param;
|
||||
|
||||
typedef struct ventoy_iso9660_override
|
||||
{
|
||||
uint32_t first_sector;
|
||||
uint32_t first_sector_be;
|
||||
uint32_t size;
|
||||
uint32_t size_be;
|
||||
}ventoy_iso9660_override;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
// compile assert to check that size of ventoy_os_param must be 512
|
||||
@@ -162,6 +179,7 @@ typedef struct ventoy_sector_flag
|
||||
}ventoy_sector_flag;
|
||||
|
||||
#define VENTOY_BIOS_FAKE_DRIVE 0xFE
|
||||
#define VENTOY_BOOT_FIXBIN_DRIVE 0xFD
|
||||
|
||||
extern int g_debug;
|
||||
extern char *g_cmdline_copy;
|
||||
|
Binary file not shown.
@@ -53,3 +53,9 @@ Title | Link
|
||||
|
||||
# FAQ
|
||||
See [https://www.ventoy.net/en/faq.html](https://www.ventoy.net/en/faq.html) for detail
|
||||
|
||||
|
||||
# Forum
|
||||
[https://forums.ventoy.net](https://forums.ventoy.net)
|
||||
|
||||
|
||||
|
@@ -51,12 +51,43 @@ typedef enum STR_ID
|
||||
STR_MENU_OPTION,//19
|
||||
STR_MENU_SECURE_BOOT,//20
|
||||
|
||||
STR_MENU_PART_CFG,//21
|
||||
STR_BTN_OK,//22
|
||||
STR_BTN_CANCEL,//23
|
||||
STR_PRESERVE_SPACE,//24
|
||||
STR_SPACE_VAL_INVALID,//25
|
||||
|
||||
STR_MENU_CLEAR, //26
|
||||
STR_CLEAR_SUCCESS, //27
|
||||
STR_CLEAR_FAILED, //28
|
||||
STR_MENU_PART_STYLE, //29
|
||||
STR_DISK_2TB_MBR_ERROR,//30
|
||||
|
||||
|
||||
STR_ID_MAX
|
||||
}STR_ID;
|
||||
|
||||
extern BOOL g_SecureBoot;
|
||||
|
||||
#define VTOY_MENU_SECURE_BOOT 0xA000
|
||||
#define VTOY_MENU_PART_CFG 0xA001
|
||||
#define VTOY_MENU_CLEAN 0xA002
|
||||
#define VTOY_MENU_PART_STYLE 0xA003
|
||||
#define VTOY_MENU_PART_MBR 0xA004
|
||||
#define VTOY_MENU_PART_GPT 0xA005
|
||||
|
||||
|
||||
typedef enum OPT_SUBMENU
|
||||
{
|
||||
OPT_SUBMENU_SECURE_BOOT = 0,
|
||||
OPT_SUBMENU_PART_STYLE,
|
||||
OPT_SUBMENU_PART_CFG,
|
||||
OPT_SUBMENU_CLEAR,
|
||||
|
||||
OPT_SUBMENU_MAX
|
||||
}OPT_SUBMENU;
|
||||
|
||||
|
||||
#define VTOY_MENU_LANGUAGE_BEGIN 0xB000
|
||||
|
||||
|
||||
|
BIN
Ventoy2Disk/Ventoy2Disk/PartDialog.c
Normal file
BIN
Ventoy2Disk/Ventoy2Disk/PartDialog.c
Normal file
Binary file not shown.
@@ -304,7 +304,7 @@ static DWORD GetVentoyVolumeName(int PhyDrive, UINT32 StartSectorId, CHAR *NameB
|
||||
|
||||
PartOffset = 512ULL * StartSectorId;
|
||||
|
||||
Log("GetVentoyVolumeName PhyDrive %d PartOffset:%llu", PhyDrive, (ULONGLONG)PartOffset);
|
||||
Log("GetVentoyVolumeName PhyDrive %d SectorStart:%u PartOffset:%llu", PhyDrive, StartSectorId, (ULONGLONG)PartOffset);
|
||||
|
||||
hVolume = FindFirstVolumeA(VolumeName, sizeof(VolumeName));
|
||||
if (hVolume == INVALID_HANDLE_VALUE)
|
||||
@@ -798,7 +798,7 @@ static int VentoyFatDiskRead(uint32 Sector, uint8 *Buffer, uint32 SectorCount)
|
||||
}
|
||||
|
||||
|
||||
int GetVentoyVerInPhyDrive(const PHY_DRIVE_INFO *pDriveInfo, CHAR *VerBuf, size_t BufLen)
|
||||
int GetVentoyVerInPhyDrive(const PHY_DRIVE_INFO *pDriveInfo, UINT64 Part2StartSector, CHAR *VerBuf, size_t BufLen)
|
||||
{
|
||||
int rc = 0;
|
||||
HANDLE hDrive;
|
||||
@@ -810,7 +810,7 @@ int GetVentoyVerInPhyDrive(const PHY_DRIVE_INFO *pDriveInfo, CHAR *VerBuf, size_
|
||||
}
|
||||
|
||||
g_FatPhyDrive = hDrive;
|
||||
g_Part2StartSec = (pDriveInfo->SizeInBytes - VENTOY_EFI_PART_SIZE) / 512;
|
||||
g_Part2StartSec = Part2StartSector;
|
||||
|
||||
Log("Parse FAT fs...");
|
||||
|
||||
@@ -934,6 +934,7 @@ int VentoyProcSecureBoot(BOOL SecureBoot)
|
||||
fl_remove("/EFI/BOOT/grubx64.efi");
|
||||
fl_remove("/EFI/BOOT/grubx64_real.efi");
|
||||
fl_remove("/EFI/BOOT/MokManager.efi");
|
||||
fl_remove("/ENROLL_THIS_KEY_IN_MOKMANAGER.cer");
|
||||
|
||||
file = fl_fopen("/EFI/BOOT/BOOTX64.EFI", "wb");
|
||||
Log("Open bootx64 efi file %p ", file);
|
||||
@@ -1033,8 +1034,9 @@ static int FormatPart2Fat(HANDLE hDrive, UINT64 StartSectorId)
|
||||
BOOL bRet;
|
||||
unsigned char *data = NULL;
|
||||
LARGE_INTEGER liCurrentPosition;
|
||||
LARGE_INTEGER liNewPosition;
|
||||
|
||||
Log("FormatPart2Fat ...");
|
||||
Log("FormatPart2Fat %llu...", StartSectorId);
|
||||
|
||||
rc = ReadWholeFileToBuf(VENTOY_FILE_DISK_IMG, 0, (void **)&data, &len);
|
||||
if (rc)
|
||||
@@ -1044,7 +1046,9 @@ static int FormatPart2Fat(HANDLE hDrive, UINT64 StartSectorId)
|
||||
}
|
||||
|
||||
liCurrentPosition.QuadPart = StartSectorId * 512;
|
||||
SetFilePointerEx(hDrive, liCurrentPosition, &liCurrentPosition, FILE_BEGIN);
|
||||
SetFilePointerEx(hDrive, liCurrentPosition, &liNewPosition, FILE_BEGIN);
|
||||
|
||||
Log("Set file pointer: %llu New pointer:%llu", liCurrentPosition.QuadPart, liNewPosition.QuadPart);
|
||||
|
||||
memset(g_part_img_buf, 0, sizeof(g_part_img_buf));
|
||||
|
||||
@@ -1063,7 +1067,7 @@ static int FormatPart2Fat(HANDLE hDrive, UINT64 StartSectorId)
|
||||
for (i = 0; i < VENTOY_EFI_PART_SIZE / SIZE_1MB; i++)
|
||||
{
|
||||
dwSize = 0;
|
||||
bRet = WriteFile(hDrive, g_part_img_buf[0] + i * SIZE_1MB, SIZE_1MB, &dwSize, NULL);
|
||||
bRet = WriteFile(hDrive, g_part_img_buf[0] + i * SIZE_1MB, SIZE_1MB, &dwSize, NULL);
|
||||
Log("Write part data bRet:%u dwSize:%u code:%u", bRet, dwSize, LASTERR);
|
||||
|
||||
if (!bRet)
|
||||
@@ -1151,7 +1155,7 @@ End:
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int WriteGrubStage1ToPhyDrive(HANDLE hDrive)
|
||||
static int WriteGrubStage1ToPhyDrive(HANDLE hDrive, int PartStyle)
|
||||
{
|
||||
int Len = 0;
|
||||
int readLen = 0;
|
||||
@@ -1177,9 +1181,20 @@ static int WriteGrubStage1ToPhyDrive(HANDLE hDrive)
|
||||
|
||||
unxz(ImgBuf, Len, NULL, NULL, RawBuf, &readLen, unxz_error);
|
||||
|
||||
SetFilePointer(hDrive, 512, NULL, FILE_BEGIN);
|
||||
if (PartStyle)
|
||||
{
|
||||
Log("Write GPT stage1 ...");
|
||||
RawBuf[500] = 35;//update blocklist
|
||||
SetFilePointer(hDrive, 512 * 34, NULL, FILE_BEGIN);
|
||||
bRet = WriteFile(hDrive, RawBuf, SIZE_1MB - 512 * 34, &dwSize, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Write MBR stage1 ...");
|
||||
SetFilePointer(hDrive, 512, NULL, FILE_BEGIN);
|
||||
bRet = WriteFile(hDrive, RawBuf, SIZE_1MB - 512, &dwSize, NULL);
|
||||
}
|
||||
|
||||
bRet = WriteFile(hDrive, RawBuf, SIZE_1MB - 512, &dwSize, NULL);
|
||||
Log("WriteFile Ret:%u dwSize:%u ErrCode:%u", bRet, dwSize, GetLastError());
|
||||
|
||||
free(RawBuf);
|
||||
@@ -1229,9 +1244,13 @@ static int FormatPart1exFAT(UINT64 DiskSizeBytes)
|
||||
|
||||
Ret = f_mount(0, TEXT("0:"), 1);
|
||||
Log("umount part %d", Ret);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("mount exfat failed %d", Ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1241,7 +1260,8 @@ static int FormatPart1exFAT(UINT64 DiskSizeBytes)
|
||||
}
|
||||
|
||||
|
||||
int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive)
|
||||
|
||||
int ClearVentoyFromPhyDrive(HWND hWnd, PHY_DRIVE_INFO *pPhyDrive, char *pDrvLetter)
|
||||
{
|
||||
int i;
|
||||
int rc = 0;
|
||||
@@ -1252,16 +1272,18 @@ int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive)
|
||||
CHAR MountDrive;
|
||||
CHAR DriveName[] = "?:\\";
|
||||
CHAR DriveLetters[MAX_PATH] = { 0 };
|
||||
LARGE_INTEGER liCurrentPosition;
|
||||
char *pTmpBuf = NULL;
|
||||
MBR_HEAD MBR;
|
||||
|
||||
Log("InstallVentoy2PhyDrive PhyDrive%d <<%s %s %dGB>>",
|
||||
*pDrvLetter = 0;
|
||||
|
||||
Log("ClearVentoyFromPhyDrive PhyDrive%d <<%s %s %dGB>>",
|
||||
pPhyDrive->PhyDrive, pPhyDrive->VendorId, pPhyDrive->ProductId,
|
||||
GetHumanReadableGBSize(pPhyDrive->SizeInBytes));
|
||||
|
||||
PROGRESS_BAR_SET_POS(PT_LOCK_FOR_CLEAN);
|
||||
|
||||
VentoyFillMBR(pPhyDrive->SizeInBytes, &MBR);
|
||||
|
||||
Log("Lock disk for clean ............................. ");
|
||||
|
||||
hDrive = GetPhysicalHandle(pPhyDrive->PhyDrive, TRUE, FALSE, FALSE);
|
||||
@@ -1319,6 +1341,210 @@ int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive)
|
||||
goto End;
|
||||
}
|
||||
|
||||
// clear first and last 1MB space
|
||||
pTmpBuf = malloc(SIZE_1MB);
|
||||
if (!pTmpBuf)
|
||||
{
|
||||
Log("Failed to alloc memory.");
|
||||
rc = 1;
|
||||
goto End;
|
||||
}
|
||||
memset(pTmpBuf, 0, SIZE_1MB);
|
||||
|
||||
SET_FILE_POS(512);
|
||||
bRet = WriteFile(hDrive, pTmpBuf, SIZE_1MB - 512, &dwSize, NULL);
|
||||
Log("Write fisrt 1MB ret:%d size:%u err:%d", bRet, dwSize, LASTERR);
|
||||
if (!bRet)
|
||||
{
|
||||
rc = 1;
|
||||
goto End;
|
||||
}
|
||||
|
||||
SET_FILE_POS(SIZE_1MB);
|
||||
bRet = WriteFile(hDrive, pTmpBuf, SIZE_1MB, &dwSize, NULL);
|
||||
Log("Write 2nd 1MB ret:%d size:%u err:%d", bRet, dwSize, LASTERR);
|
||||
if (!bRet)
|
||||
{
|
||||
rc = 1;
|
||||
goto End;
|
||||
}
|
||||
|
||||
SET_FILE_POS(0);
|
||||
bRet = ReadFile(hDrive, &MBR, sizeof(MBR), &dwSize, NULL);
|
||||
Log("Read MBR ret:%d size:%u err:%d", bRet, dwSize, LASTERR);
|
||||
if (!bRet)
|
||||
{
|
||||
rc = 1;
|
||||
goto End;
|
||||
}
|
||||
|
||||
//clear boot code and partition table (reserved disk signature)
|
||||
memset(MBR.BootCode, 0, 440);
|
||||
memset(MBR.PartTbl, 0, sizeof(MBR.PartTbl));
|
||||
|
||||
VentoyFillLocation(pPhyDrive->SizeInBytes, 2048, (UINT32)(pPhyDrive->SizeInBytes / 512 - 2048), MBR.PartTbl);
|
||||
|
||||
MBR.PartTbl[0].Active = 0x00; // bootable
|
||||
MBR.PartTbl[0].FsFlag = 0x07; // exFAT/NTFS/HPFS
|
||||
|
||||
SET_FILE_POS(0);
|
||||
bRet = WriteFile(hDrive, &MBR, 512, &dwSize, NULL);
|
||||
Log("Write MBR ret:%d size:%u err:%d", bRet, dwSize, LASTERR);
|
||||
if (!bRet)
|
||||
{
|
||||
rc = 1;
|
||||
goto End;
|
||||
}
|
||||
|
||||
Log("Clear Ventoy successfully finished");
|
||||
|
||||
//Refresh Drive Layout
|
||||
DeviceIoControl(hDrive, IOCTL_DISK_UPDATE_PROPERTIES, NULL, 0, NULL, 0, &dwSize, NULL);
|
||||
|
||||
End:
|
||||
|
||||
PROGRESS_BAR_SET_POS(PT_MOUNT_VOLUME);
|
||||
|
||||
if (pTmpBuf)
|
||||
{
|
||||
free(pTmpBuf);
|
||||
}
|
||||
|
||||
if (rc == 0)
|
||||
{
|
||||
Log("Mounting Ventoy Partition ....................... ");
|
||||
Sleep(1000);
|
||||
|
||||
state = 0;
|
||||
memset(DriveLetters, 0, sizeof(DriveLetters));
|
||||
GetLettersBelongPhyDrive(pPhyDrive->PhyDrive, DriveLetters, sizeof(DriveLetters));
|
||||
Log("Logical drive letter after write ventoy: <%s>", DriveLetters);
|
||||
|
||||
for (i = 0; i < sizeof(DriveLetters) && DriveLetters[i]; i++)
|
||||
{
|
||||
DriveName[0] = DriveLetters[i];
|
||||
Log("%s is ventoy part1, already mounted", DriveName);
|
||||
state = 1;
|
||||
}
|
||||
|
||||
if (state != 1)
|
||||
{
|
||||
Log("need to mount ventoy part1...");
|
||||
if (0 == GetVentoyVolumeName(pPhyDrive->PhyDrive, MBR.PartTbl[0].StartSectorId, DriveLetters, sizeof(DriveLetters), FALSE))
|
||||
{
|
||||
DriveName[0] = MountDrive;
|
||||
bRet = SetVolumeMountPointA(DriveName, DriveLetters);
|
||||
Log("SetVolumeMountPoint <%s> <%s> bRet:%u code:%u", DriveName, DriveLetters, bRet, GetLastError());
|
||||
|
||||
*pDrvLetter = MountDrive;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Failed to find ventoy volume");
|
||||
}
|
||||
}
|
||||
|
||||
Log("OK\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
FindProcessOccupyDisk(hDrive, pPhyDrive);
|
||||
}
|
||||
|
||||
CHECK_CLOSE_HANDLE(hDrive);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int PartStyle)
|
||||
{
|
||||
int i;
|
||||
int rc = 0;
|
||||
int state = 0;
|
||||
HANDLE hDrive;
|
||||
DWORD dwSize;
|
||||
BOOL bRet;
|
||||
CHAR MountDrive;
|
||||
CHAR DriveName[] = "?:\\";
|
||||
CHAR DriveLetters[MAX_PATH] = { 0 };
|
||||
MBR_HEAD MBR;
|
||||
VTOY_GPT_INFO *pGptInfo = NULL;
|
||||
|
||||
Log("InstallVentoy2PhyDrive %s PhyDrive%d <<%s %s %dGB>>",
|
||||
PartStyle ? "GPT" : "MBR", pPhyDrive->PhyDrive, pPhyDrive->VendorId, pPhyDrive->ProductId,
|
||||
GetHumanReadableGBSize(pPhyDrive->SizeInBytes));
|
||||
|
||||
if (PartStyle)
|
||||
{
|
||||
pGptInfo = malloc(sizeof(VTOY_GPT_INFO));
|
||||
memset(pGptInfo, 0, sizeof(VTOY_GPT_INFO));
|
||||
}
|
||||
|
||||
PROGRESS_BAR_SET_POS(PT_LOCK_FOR_CLEAN);
|
||||
|
||||
VentoyFillMBR(pPhyDrive->SizeInBytes, &MBR, PartStyle);//also used to format 1st partition in GPT mode
|
||||
if (PartStyle)
|
||||
{
|
||||
VentoyFillGpt(pPhyDrive->SizeInBytes, pGptInfo);
|
||||
}
|
||||
|
||||
Log("Lock disk for clean ............................. ");
|
||||
|
||||
hDrive = GetPhysicalHandle(pPhyDrive->PhyDrive, TRUE, FALSE, FALSE);
|
||||
if (hDrive == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
Log("Failed to open physical disk");
|
||||
free(pGptInfo);
|
||||
return 1;
|
||||
}
|
||||
|
||||
GetLettersBelongPhyDrive(pPhyDrive->PhyDrive, DriveLetters, sizeof(DriveLetters));
|
||||
|
||||
if (DriveLetters[0] == 0)
|
||||
{
|
||||
Log("No drive letter was assigned...");
|
||||
DriveName[0] = GetFirstUnusedDriveLetter();
|
||||
Log("GetFirstUnusedDriveLetter %C: ...", DriveName[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unmount all mounted volumes that belong to this drive
|
||||
// Do it in reverse so that we always end on the first volume letter
|
||||
for (i = (int)strlen(DriveLetters); i > 0; i--)
|
||||
{
|
||||
DriveName[0] = DriveLetters[i - 1];
|
||||
bRet = DeleteVolumeMountPointA(DriveName);
|
||||
Log("Delete mountpoint %s ret:%u code:%u", DriveName, bRet, GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
MountDrive = DriveName[0];
|
||||
Log("Will use '%C:' as volume mountpoint", DriveName[0]);
|
||||
|
||||
// It kind of blows, but we have to relinquish access to the physical drive
|
||||
// for VDS to be able to delete the partitions that reside on it...
|
||||
DeviceIoControl(hDrive, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, &dwSize, NULL);
|
||||
CHECK_CLOSE_HANDLE(hDrive);
|
||||
|
||||
PROGRESS_BAR_SET_POS(PT_DEL_ALL_PART);
|
||||
|
||||
if (!DeletePartitions(pPhyDrive->PhyDrive, FALSE))
|
||||
{
|
||||
Log("Notice: Could not delete partitions: %u", GetLastError());
|
||||
}
|
||||
|
||||
Log("Deleting all partitions ......................... OK");
|
||||
|
||||
PROGRESS_BAR_SET_POS(PT_LOCK_FOR_WRITE);
|
||||
|
||||
Log("Lock disk for write ............................. ");
|
||||
hDrive = GetPhysicalHandle(pPhyDrive->PhyDrive, TRUE, TRUE, FALSE);
|
||||
if (hDrive == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
Log("Failed to GetPhysicalHandle for write.");
|
||||
rc = 1;
|
||||
goto End;
|
||||
}
|
||||
|
||||
//Refresh Drive Layout
|
||||
DeviceIoControl(hDrive, IOCTL_DISK_UPDATE_PROPERTIES, NULL, 0, NULL, 0, &dwSize, NULL);
|
||||
|
||||
@@ -1326,9 +1552,16 @@ int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive)
|
||||
|
||||
PROGRESS_BAR_SET_POS(PT_FORMAT_PART1);
|
||||
|
||||
if (PartStyle == 1 && pPhyDrive->PartStyle == 0)
|
||||
{
|
||||
Log("Wait for format part1 ...");
|
||||
Sleep(1000 * 5);
|
||||
}
|
||||
|
||||
Log("Formatting part1 exFAT ...");
|
||||
if (0 != FormatPart1exFAT(pPhyDrive->SizeInBytes))
|
||||
{
|
||||
Log("FormatPart1exFAT failed.");
|
||||
rc = 1;
|
||||
goto End;
|
||||
}
|
||||
@@ -1337,78 +1570,127 @@ int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive)
|
||||
Log("Writing part2 FAT img ...");
|
||||
if (0 != FormatPart2Fat(hDrive, MBR.PartTbl[1].StartSectorId))
|
||||
{
|
||||
Log("FormatPart2Fat failed.");
|
||||
rc = 1;
|
||||
goto End;
|
||||
}
|
||||
|
||||
PROGRESS_BAR_SET_POS(PT_WRITE_STG1_IMG);
|
||||
Log("Writting Boot Image ............................. ");
|
||||
if (WriteGrubStage1ToPhyDrive(hDrive) != 0)
|
||||
if (WriteGrubStage1ToPhyDrive(hDrive, PartStyle) != 0)
|
||||
{
|
||||
Log("WriteGrubStage1ToPhyDrive failed.");
|
||||
rc = 1;
|
||||
goto End;
|
||||
}
|
||||
|
||||
|
||||
PROGRESS_BAR_SET_POS(PT_WRITE_PART_TABLE);
|
||||
Log("Writting Partition Table ........................ ");
|
||||
SetFilePointer(hDrive, 0, NULL, FILE_BEGIN);
|
||||
if (!WriteFile(hDrive, &MBR, sizeof(MBR), &dwSize, NULL))
|
||||
|
||||
if (PartStyle)
|
||||
{
|
||||
rc = 1;
|
||||
Log("Write MBR Failed, dwSize:%u ErrCode:%u", dwSize, GetLastError());
|
||||
goto End;
|
||||
VTOY_GPT_HDR BackupHead;
|
||||
LARGE_INTEGER liCurrentPosition;
|
||||
|
||||
SET_FILE_POS(pPhyDrive->SizeInBytes - 512);
|
||||
VentoyFillBackupGptHead(pGptInfo, &BackupHead);
|
||||
if (!WriteFile(hDrive, &BackupHead, sizeof(VTOY_GPT_HDR), &dwSize, NULL))
|
||||
{
|
||||
rc = 1;
|
||||
Log("Write GPT Backup Head Failed, dwSize:%u (%u) ErrCode:%u", dwSize, sizeof(VTOY_GPT_INFO), GetLastError());
|
||||
goto End;
|
||||
}
|
||||
|
||||
SET_FILE_POS(pPhyDrive->SizeInBytes - 512 * 33);
|
||||
if (!WriteFile(hDrive, pGptInfo->PartTbl, sizeof(pGptInfo->PartTbl), &dwSize, NULL))
|
||||
{
|
||||
rc = 1;
|
||||
Log("Write GPT Backup Part Table Failed, dwSize:%u (%u) ErrCode:%u", dwSize, sizeof(VTOY_GPT_INFO), GetLastError());
|
||||
goto End;
|
||||
}
|
||||
|
||||
SET_FILE_POS(0);
|
||||
if (!WriteFile(hDrive, pGptInfo, sizeof(VTOY_GPT_INFO), &dwSize, NULL))
|
||||
{
|
||||
rc = 1;
|
||||
Log("Write GPT Info Failed, dwSize:%u (%u) ErrCode:%u", dwSize, sizeof(VTOY_GPT_INFO), GetLastError());
|
||||
goto End;
|
||||
}
|
||||
|
||||
Log("Write GPT Info OK ...");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!WriteFile(hDrive, &MBR, sizeof(MBR), &dwSize, NULL))
|
||||
{
|
||||
rc = 1;
|
||||
Log("Write MBR Failed, dwSize:%u ErrCode:%u", dwSize, GetLastError());
|
||||
goto End;
|
||||
}
|
||||
Log("Write MBR OK ...");
|
||||
}
|
||||
|
||||
Log("Write MBR OK ...");
|
||||
|
||||
//Refresh Drive Layout
|
||||
DeviceIoControl(hDrive, IOCTL_DISK_UPDATE_PROPERTIES, NULL, 0, NULL, 0, &dwSize, NULL);
|
||||
|
||||
End:
|
||||
CHECK_CLOSE_HANDLE(hDrive);
|
||||
|
||||
PROGRESS_BAR_SET_POS(PT_MOUNT_VOLUME);
|
||||
Log("Mounting Ventoy Partition ....................... ");
|
||||
Sleep(1000);
|
||||
|
||||
state = 0;
|
||||
memset(DriveLetters, 0, sizeof(DriveLetters));
|
||||
GetLettersBelongPhyDrive(pPhyDrive->PhyDrive, DriveLetters, sizeof(DriveLetters));
|
||||
Log("Logical drive letter after write ventoy: <%s>", DriveLetters);
|
||||
|
||||
for (i = 0; i < sizeof(DriveLetters) && DriveLetters[i]; i++)
|
||||
if (rc == 0)
|
||||
{
|
||||
DriveName[0] = DriveLetters[i];
|
||||
if (IsVentoyLogicalDrive(DriveName[0]))
|
||||
Log("Mounting Ventoy Partition ....................... ");
|
||||
Sleep(1000);
|
||||
|
||||
state = 0;
|
||||
memset(DriveLetters, 0, sizeof(DriveLetters));
|
||||
GetLettersBelongPhyDrive(pPhyDrive->PhyDrive, DriveLetters, sizeof(DriveLetters));
|
||||
Log("Logical drive letter after write ventoy: <%s>", DriveLetters);
|
||||
|
||||
for (i = 0; i < sizeof(DriveLetters) && DriveLetters[i]; i++)
|
||||
{
|
||||
Log("%s is ventoy part2, delete mountpoint", DriveName);
|
||||
DeleteVolumeMountPointA(DriveName);
|
||||
DriveName[0] = DriveLetters[i];
|
||||
if (IsVentoyLogicalDrive(DriveName[0]))
|
||||
{
|
||||
Log("%s is ventoy part2, delete mountpoint", DriveName);
|
||||
DeleteVolumeMountPointA(DriveName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("%s is ventoy part1, already mounted", DriveName);
|
||||
state = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (state != 1)
|
||||
{
|
||||
Log("%s is ventoy part1, already mounted", DriveName);
|
||||
state = 1;
|
||||
Log("need to mount ventoy part1...");
|
||||
if (0 == GetVentoyVolumeName(pPhyDrive->PhyDrive, MBR.PartTbl[0].StartSectorId, DriveLetters, sizeof(DriveLetters), FALSE))
|
||||
{
|
||||
DriveName[0] = MountDrive;
|
||||
bRet = SetVolumeMountPointA(DriveName, DriveLetters);
|
||||
Log("SetVolumeMountPoint <%s> <%s> bRet:%u code:%u", DriveName, DriveLetters, bRet, GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Failed to find ventoy volume");
|
||||
}
|
||||
}
|
||||
Log("OK\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
FindProcessOccupyDisk(hDrive, pPhyDrive);
|
||||
}
|
||||
|
||||
if (state != 1)
|
||||
if (pGptInfo)
|
||||
{
|
||||
Log("need to mount ventoy part1...");
|
||||
if (0 == GetVentoyVolumeName(pPhyDrive->PhyDrive, MBR.PartTbl[0].StartSectorId, DriveLetters, sizeof(DriveLetters), FALSE))
|
||||
{
|
||||
DriveName[0] = MountDrive;
|
||||
bRet = SetVolumeMountPointA(DriveName, DriveLetters);
|
||||
Log("SetVolumeMountPoint <%s> <%s> bRet:%u code:%u", DriveName, DriveLetters, bRet, GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Failed to find ventoy volume");
|
||||
}
|
||||
free(pGptInfo);
|
||||
}
|
||||
|
||||
Log("OK\n");
|
||||
|
||||
CHECK_CLOSE_HANDLE(hDrive);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1424,14 +1706,14 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive)
|
||||
BOOL bRet;
|
||||
CHAR DriveName[] = "?:\\";
|
||||
CHAR DriveLetters[MAX_PATH] = { 0 };
|
||||
UINT32 StartSector;
|
||||
UINT64 StartSector;
|
||||
UINT64 ReservedMB = 0;
|
||||
MBR_HEAD BootImg;
|
||||
MBR_HEAD MBR;
|
||||
VTOY_GPT_INFO *pGptInfo = NULL;
|
||||
|
||||
StartSector = (UINT32)(pPhyDrive->SizeInBytes / 512 - VENTOY_EFI_PART_SIZE / 512);
|
||||
|
||||
Log("UpdateVentoy2PhyDrive PhyDrive%d <<%s %s %dGB>>",
|
||||
pPhyDrive->PhyDrive, pPhyDrive->VendorId, pPhyDrive->ProductId,
|
||||
Log("UpdateVentoy2PhyDrive %s PhyDrive%d <<%s %s %dGB>>",
|
||||
pPhyDrive->PartStyle ? "GPT" : "MBR", pPhyDrive->PhyDrive, pPhyDrive->VendorId, pPhyDrive->ProductId,
|
||||
GetHumanReadableGBSize(pPhyDrive->SizeInBytes));
|
||||
|
||||
PROGRESS_BAR_SET_POS(PT_LOCK_FOR_CLEAN);
|
||||
@@ -1445,8 +1727,41 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Read MBR
|
||||
ReadFile(hDrive, &MBR, sizeof(MBR), &dwSize, NULL);
|
||||
if (pPhyDrive->PartStyle)
|
||||
{
|
||||
pGptInfo = malloc(sizeof(VTOY_GPT_INFO));
|
||||
if (!pGptInfo)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(pGptInfo, 0, sizeof(VTOY_GPT_INFO));
|
||||
|
||||
// Read GPT Info
|
||||
SetFilePointer(hDrive, 0, NULL, FILE_BEGIN);
|
||||
ReadFile(hDrive, pGptInfo, sizeof(VTOY_GPT_INFO), &dwSize, NULL);
|
||||
|
||||
//MBR will be used to compare with local boot image
|
||||
memcpy(&MBR, &pGptInfo->MBR, sizeof(MBR_HEAD));
|
||||
|
||||
StartSector = pGptInfo->PartTbl[1].StartLBA;
|
||||
Log("GPT StartSector in PartTbl:%llu", (ULONGLONG)StartSector);
|
||||
|
||||
ReservedMB = (pPhyDrive->SizeInBytes / 512 - (StartSector + VENTOY_EFI_PART_SIZE / 512) - 33) / 2048;
|
||||
Log("GPT Reserved Disk Space:%llu MB", (ULONGLONG)ReservedMB);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Read MBR
|
||||
SetFilePointer(hDrive, 0, NULL, FILE_BEGIN);
|
||||
ReadFile(hDrive, &MBR, sizeof(MBR), &dwSize, NULL);
|
||||
|
||||
StartSector = MBR.PartTbl[1].StartSectorId;
|
||||
Log("MBR StartSector in PartTbl:%llu", (ULONGLONG)StartSector);
|
||||
|
||||
ReservedMB = (pPhyDrive->SizeInBytes / 512 - (StartSector + VENTOY_EFI_PART_SIZE / 512)) / 2048;
|
||||
Log("MBR Reserved Disk Space:%llu MB", (ULONGLONG)ReservedMB);
|
||||
}
|
||||
|
||||
GetLettersBelongPhyDrive(pPhyDrive->PhyDrive, DriveLetters, sizeof(DriveLetters));
|
||||
|
||||
@@ -1564,7 +1879,7 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive)
|
||||
}
|
||||
|
||||
Log("Updating Boot Image ............................. ");
|
||||
if (WriteGrubStage1ToPhyDrive(hDrive) != 0)
|
||||
if (WriteGrubStage1ToPhyDrive(hDrive, pPhyDrive->PartStyle) != 0)
|
||||
{
|
||||
rc = 1;
|
||||
goto End;
|
||||
@@ -1575,6 +1890,10 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive)
|
||||
|
||||
// Use Old UUID
|
||||
memcpy(BootImg.BootCode + 0x180, MBR.BootCode + 0x180, 16);
|
||||
if (pPhyDrive->PartStyle)
|
||||
{
|
||||
BootImg.BootCode[92] = 0x22;
|
||||
}
|
||||
|
||||
if (ForceMBR == FALSE && memcmp(BootImg.BootCode, MBR.BootCode, 440) == 0)
|
||||
{
|
||||
@@ -1591,24 +1910,43 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive)
|
||||
Log("Write Boot Image ret:%u dwSize:%u Error:%u", bRet, dwSize, LASTERR);
|
||||
}
|
||||
|
||||
if (0x00 == MBR.PartTbl[0].Active && 0x80 == MBR.PartTbl[1].Active)
|
||||
if (pPhyDrive->PartStyle == 0)
|
||||
{
|
||||
Log("Need to chage 1st partition active and 2nd partition inactive.");
|
||||
if (0x00 == MBR.PartTbl[0].Active && 0x80 == MBR.PartTbl[1].Active)
|
||||
{
|
||||
Log("Need to chage 1st partition active and 2nd partition inactive.");
|
||||
|
||||
MBR.PartTbl[0].Active = 0x80;
|
||||
MBR.PartTbl[1].Active = 0x00;
|
||||
MBR.PartTbl[0].Active = 0x80;
|
||||
MBR.PartTbl[1].Active = 0x00;
|
||||
|
||||
SetFilePointer(hDrive, 0, NULL, FILE_BEGIN);
|
||||
bRet = WriteFile(hDrive, &MBR, 512, &dwSize, NULL);
|
||||
Log("Write NEW MBR ret:%u dwSize:%u Error:%u", bRet, dwSize, LASTERR);
|
||||
SetFilePointer(hDrive, 0, NULL, FILE_BEGIN);
|
||||
bRet = WriteFile(hDrive, &MBR, 512, &dwSize, NULL);
|
||||
Log("Write NEW MBR ret:%u dwSize:%u Error:%u", bRet, dwSize, LASTERR);
|
||||
}
|
||||
}
|
||||
|
||||
//Refresh Drive Layout
|
||||
DeviceIoControl(hDrive, IOCTL_DISK_UPDATE_PROPERTIES, NULL, 0, NULL, 0, &dwSize, NULL);
|
||||
|
||||
End:
|
||||
|
||||
if (rc == 0)
|
||||
{
|
||||
Log("OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
FindProcessOccupyDisk(hDrive, pPhyDrive);
|
||||
}
|
||||
|
||||
CHECK_CLOSE_HANDLE(hDrive);
|
||||
|
||||
if (pGptInfo)
|
||||
{
|
||||
free(pGptInfo);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user