mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-09-17 09:21:15 +00:00
Compare commits
88 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
b9b6852631 | ||
|
4a44a82840 | ||
|
f2e82862ab | ||
|
368151aa3b | ||
|
b5dcaecffe | ||
|
a4cfbd6799 | ||
|
ab964932cb | ||
|
bcc81d31db | ||
|
91330b97bf | ||
|
fe7b9abcff | ||
|
68d3b55167 | ||
|
e1c26567a1 | ||
|
4131d95cef | ||
|
8c18f91ac1 | ||
|
73fabd0c65 | ||
|
0c140cf378 | ||
|
293f677cbf | ||
|
4bf43ab9d4 | ||
|
9eeb94e8b5 | ||
|
f4987fd7f4 | ||
|
157c6f13ec | ||
|
6a506ee7f3 | ||
|
32643ecdbb | ||
|
d2e5930520 | ||
|
944f376ffe | ||
|
d402338ade | ||
|
d938100eeb | ||
|
a4200ed99e | ||
|
e4ccd5115e | ||
|
cdb727dd22 | ||
|
6b4093fb93 | ||
|
21450d4a56 | ||
|
164c8d6505 | ||
|
37e7a539f9 | ||
|
b5a649f96f | ||
|
443a1344f2 | ||
|
d3de1a91f8 | ||
|
580ad598f6 | ||
|
0891e34d47 | ||
|
4d777090cb | ||
|
b0568922d2 | ||
|
69b6bb8fca | ||
|
3d686c27d7 | ||
|
90ba217ec7 | ||
|
fab070ef64 | ||
|
b3869b6894 | ||
|
563214ed40 | ||
|
b67f738b00 | ||
|
a9c539572b | ||
|
32602a79ab | ||
|
863eafd2cc | ||
|
0f135b6646 | ||
|
675c24ffa3 | ||
|
cd309eb663 | ||
|
5cdd6540a4 | ||
|
fde2e4430c | ||
|
9a471f4956 | ||
|
1f3b3afa35 | ||
|
6947f2a047 | ||
|
0a15e4e427 | ||
|
e763d7590f | ||
|
f842d46f90 | ||
|
cc1cc6c301 | ||
|
9f3d209798 | ||
|
fc742244ab | ||
|
3e66227dae | ||
|
f32d342f66 | ||
|
09d7ae68e7 | ||
|
68fefbc1fc | ||
|
8d893d4c94 | ||
|
84798a4f7a | ||
|
87f88eeb2b | ||
|
7b2615744c | ||
|
d7faff4438 | ||
|
f15dfd7409 | ||
|
09162e8d97 | ||
|
eb8fcc8f30 | ||
|
5fcb3971bc | ||
|
e47e4484ce | ||
|
7e26decb31 | ||
|
e713946fd0 | ||
|
a93b0f6656 | ||
|
836e1aa11e | ||
|
154bbc6e5f | ||
|
d151e74336 | ||
|
df87cafdfb | ||
|
09494a5b23 | ||
|
e15a1c5ece |
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: ['https://www.ventoy.net/en/donation.html'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
custom: ['https://www.paypal.me/ventoy', 'https://www.ventoy.net/en/donation.html'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
|
2
.github/ISSUE_TEMPLATE/issue_template.yml
vendored
2
.github/ISSUE_TEMPLATE/issue_template.yml
vendored
@@ -21,7 +21,7 @@ body:
|
||||
attributes:
|
||||
label: Ventoy Version
|
||||
description: What version of ventoy are you running?
|
||||
placeholder: 1.0.56
|
||||
placeholder: 1.0.63
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
|
101
.github/ISSUE_TEMPLATE/success_image_report.yml
vendored
Normal file
101
.github/ISSUE_TEMPLATE/success_image_report.yml
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
name: Success Image Report
|
||||
description: To report an image file that boot successfully in Ventoy and is not yet listed in https://www.ventoy.net/en/isolist.html
|
||||
title: "[Success Image Report]: "
|
||||
assignees:
|
||||
- octocat
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
I list all the successfully tested image files in the official website: https://www.ventoy.net/en/isolist.html
|
||||
If you successfully test an image file which is not listed in the above page, you can tell me and I will be very glad to add it to the tested list.
|
||||
- type: checkboxes
|
||||
id: faq
|
||||
attributes:
|
||||
label: Official Website List
|
||||
description: Have you checked the list at [https://www.ventoy.net/en/isolist.html](https://www.ventoy.net/en/isolist.html) and the image file is not listed?
|
||||
options:
|
||||
- label: I have checked the list in official website and the image file is not listed there.
|
||||
required: true
|
||||
- type: input
|
||||
id: version
|
||||
attributes:
|
||||
label: Ventoy Version
|
||||
description: What version of ventoy did you test with the image file.
|
||||
placeholder: 1.0.57
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: bios
|
||||
attributes:
|
||||
label: BIOS Mode
|
||||
description: In which BIOS mode did you successfully test the image file? (It's recommended to test in both mode)
|
||||
options:
|
||||
- Legacy BIOS Mode
|
||||
- UEFI Mode
|
||||
- Both
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: partstyle
|
||||
attributes:
|
||||
label: Partition Style
|
||||
description: Which partition style did you use with Ventoy?
|
||||
options:
|
||||
- MBR
|
||||
- GPT
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: filename
|
||||
attributes:
|
||||
label: Image file name
|
||||
description: The successfully tested image file name.
|
||||
placeholder: xxxx.iso
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: checksum
|
||||
attributes:
|
||||
label: Image file checksum type
|
||||
description:
|
||||
options:
|
||||
- MD5
|
||||
- SHA1
|
||||
- SHA256
|
||||
- SHA512
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: checkvalue
|
||||
attributes:
|
||||
label: Image file checksum value
|
||||
description: What is the image file checksum value corresponding to the above checksum type?
|
||||
placeholder: xxxx
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: link
|
||||
attributes:
|
||||
label: Image file download link (if applicable)
|
||||
description: What is the image file download link?
|
||||
placeholder: https://xxx
|
||||
validations:
|
||||
required: false
|
||||
- type: input
|
||||
id: testenv
|
||||
attributes:
|
||||
label: Test envrionment
|
||||
description: The manufacturer/model and other details about your computer (or VM).
|
||||
placeholder: Lenovo Thinkpad T420 laptop
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: details
|
||||
attributes:
|
||||
label: More Details?
|
||||
description: You can give more details here.
|
||||
value: "This image file booted successfully in Ventoy."
|
||||
validations:
|
||||
required: false
|
||||
|
@@ -59,6 +59,9 @@ static grub_env_set_pf grub_env_set = NULL;
|
||||
ventoy_grub_param_file_replace *g_file_replace_list = NULL;
|
||||
ventoy_efi_file_replace g_efi_file_replace;
|
||||
|
||||
ventoy_grub_param_file_replace *g_img_replace_list = NULL;
|
||||
ventoy_efi_file_replace g_img_file_replace;
|
||||
|
||||
CONST CHAR16 gIso9660EfiDriverPath[] = ISO9660_EFI_DRIVER_PATH;
|
||||
CONST CHAR16 gUdfEfiDriverPath[] = UDF_EFI_DRIVER_PATH;
|
||||
|
||||
@@ -707,6 +710,35 @@ STATIC EFI_STATUS EFIAPI ventoy_load_isoefi_driver(IN EFI_HANDLE ImageHandle)
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
STATIC EFI_STATUS ventoy_proc_img_replace_name(ventoy_grub_param_file_replace *replace)
|
||||
{
|
||||
UINT32 i;
|
||||
char tmp[256];
|
||||
|
||||
if (replace->magic != GRUB_IMG_REPLACE_MAGIC)
|
||||
{
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
if (replace->old_file_name[0][0] == 0)
|
||||
{
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
AsciiStrCpyS(tmp, sizeof(tmp), replace->old_file_name[0]);
|
||||
|
||||
for (i = 0; i < 256 && tmp[i]; i++)
|
||||
{
|
||||
if (tmp[i] == '/')
|
||||
{
|
||||
tmp[i] = '\\';
|
||||
}
|
||||
}
|
||||
|
||||
AsciiStrCpyS(replace->old_file_name[0], 256, tmp);
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
|
||||
{
|
||||
UINT32 i = 0;
|
||||
@@ -817,6 +849,19 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
|
||||
old_cnt > 3 ? g_file_replace_list->old_file_name[3] : ""
|
||||
);
|
||||
|
||||
g_img_replace_list = &pGrubParam->img_replace;
|
||||
ventoy_proc_img_replace_name(g_img_replace_list);
|
||||
old_cnt = g_img_replace_list->old_file_cnt;
|
||||
debug("img replace: magic:0x%x virtid:%u name count:%u <%a> <%a> <%a> <%a>",
|
||||
g_img_replace_list->magic,
|
||||
g_img_replace_list->new_file_virtual_id,
|
||||
old_cnt,
|
||||
old_cnt > 0 ? g_img_replace_list->old_file_name[0] : "",
|
||||
old_cnt > 1 ? g_img_replace_list->old_file_name[1] : "",
|
||||
old_cnt > 2 ? g_img_replace_list->old_file_name[2] : "",
|
||||
old_cnt > 3 ? g_img_replace_list->old_file_name[3] : ""
|
||||
);
|
||||
|
||||
pPos = StrStr(pCmdLine, L"mem:");
|
||||
chain = (ventoy_chain_head *)StrHexToUintn(pPos + 4);
|
||||
|
||||
@@ -1050,7 +1095,8 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
|
||||
gST->ConIn->Reset(gST->ConIn, FALSE);
|
||||
}
|
||||
|
||||
if (g_file_replace_list && g_file_replace_list->magic == GRUB_FILE_REPLACE_MAGIC)
|
||||
if ((g_file_replace_list && g_file_replace_list->magic == GRUB_FILE_REPLACE_MAGIC) ||
|
||||
(g_img_replace_list && g_img_replace_list->magic == GRUB_IMG_REPLACE_MAGIC))
|
||||
{
|
||||
ventoy_wrapper_push_openvolume(pFile->OpenVolume);
|
||||
pFile->OpenVolume = ventoy_wrapper_open_volume;
|
||||
|
@@ -243,6 +243,7 @@ typedef int (*grub_env_printf_pf)(const char *fmt, ...);
|
||||
#pragma pack(1)
|
||||
|
||||
#define GRUB_FILE_REPLACE_MAGIC 0x1258BEEF
|
||||
#define GRUB_IMG_REPLACE_MAGIC 0x1259BEEF
|
||||
|
||||
typedef struct ventoy_efi_file_replace
|
||||
{
|
||||
@@ -267,6 +268,7 @@ typedef struct ventoy_grub_param
|
||||
grub_env_get_pf grub_env_get;
|
||||
grub_env_set_pf grub_env_set;
|
||||
ventoy_grub_param_file_replace file_replace;
|
||||
ventoy_grub_param_file_replace img_replace;
|
||||
grub_env_printf_pf grub_env_printf;
|
||||
}ventoy_grub_param;
|
||||
|
||||
@@ -396,6 +398,7 @@ 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_efi_file_replace g_img_file_replace;
|
||||
extern ventoy_sector_flag *g_sector_flag;
|
||||
extern UINT32 g_sector_flag_num;
|
||||
extern BOOLEAN gMemdiskMode;
|
||||
@@ -403,6 +406,7 @@ extern BOOLEAN gSector512Mode;
|
||||
extern UINTN g_iso_buf_size;
|
||||
extern UINT8 *g_iso_data_buf;
|
||||
extern ventoy_grub_param_file_replace *g_file_replace_list;
|
||||
extern ventoy_grub_param_file_replace *g_img_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;
|
||||
|
@@ -37,6 +37,9 @@
|
||||
#include <Protocol/DriverBinding.h>
|
||||
#include <Ventoy.h>
|
||||
|
||||
#define ASSIGN_REPLACE(This, replace) \
|
||||
replace = (This->FlushEx == ventoy_wrapper_file_flush_ex) ? &g_efi_file_replace : &g_img_file_replace
|
||||
|
||||
UINT8 *g_iso_data_buf = NULL;
|
||||
UINTN g_iso_buf_size = 0;
|
||||
BOOLEAN gMemdiskMode = FALSE;
|
||||
@@ -1245,6 +1248,15 @@ ventoy_wrapper_file_flush_ex(EFI_FILE_HANDLE This, EFI_FILE_IO_TOKEN *Token)
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/* Ex version */
|
||||
STATIC EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_flush_ex_img(EFI_FILE_HANDLE This, EFI_FILE_IO_TOKEN *Token)
|
||||
{
|
||||
(VOID)This;
|
||||
(VOID)Token;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
STATIC EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_write(EFI_FILE_HANDLE This, UINTN *Len, VOID *Data)
|
||||
@@ -1270,19 +1282,20 @@ ventoy_wrapper_file_close(EFI_FILE_HANDLE This)
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
STATIC EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_set_pos(EFI_FILE_HANDLE This, UINT64 Position)
|
||||
{
|
||||
(VOID)This;
|
||||
|
||||
if (Position <= g_efi_file_replace.FileSizeBytes)
|
||||
ventoy_efi_file_replace *replace = NULL;
|
||||
|
||||
ASSIGN_REPLACE(This, replace);
|
||||
|
||||
if (Position <= replace->FileSizeBytes)
|
||||
{
|
||||
g_efi_file_replace.CurPos = Position;
|
||||
replace->CurPos = Position;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_efi_file_replace.CurPos = g_efi_file_replace.FileSizeBytes;
|
||||
replace->CurPos = replace->FileSizeBytes;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
@@ -1291,9 +1304,11 @@ ventoy_wrapper_file_set_pos(EFI_FILE_HANDLE This, UINT64 Position)
|
||||
STATIC EFI_STATUS EFIAPI
|
||||
ventoy_wrapper_file_get_pos(EFI_FILE_HANDLE This, UINT64 *Position)
|
||||
{
|
||||
(VOID)This;
|
||||
ventoy_efi_file_replace *replace = NULL;
|
||||
|
||||
*Position = g_efi_file_replace.CurPos;
|
||||
ASSIGN_REPLACE(This, replace);
|
||||
|
||||
*Position = replace->CurPos;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
@@ -1303,6 +1318,9 @@ 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;
|
||||
ventoy_efi_file_replace *replace = NULL;
|
||||
|
||||
ASSIGN_REPLACE(This, replace);
|
||||
|
||||
debug("ventoy_wrapper_file_get_info ... %u", *Len);
|
||||
|
||||
@@ -1320,8 +1338,8 @@ ventoy_wrapper_file_get_info(EFI_FILE_HANDLE This, EFI_GUID *Type, UINTN *Len, V
|
||||
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->FileSize = replace->FileSizeBytes;
|
||||
Info->PhysicalSize = replace->FileSizeBytes;
|
||||
Info->Attribute = EFI_FILE_READ_ONLY;
|
||||
//Info->FileName = EFI_FILE_READ_ONLY;
|
||||
|
||||
@@ -1335,23 +1353,24 @@ ventoy_wrapper_file_read(EFI_FILE_HANDLE This, UINTN *Len, VOID *Data)
|
||||
{
|
||||
EFI_LBA Lba;
|
||||
UINTN ReadLen = *Len;
|
||||
|
||||
(VOID)This;
|
||||
ventoy_efi_file_replace *replace = NULL;
|
||||
|
||||
ASSIGN_REPLACE(This, replace);
|
||||
|
||||
debug("ventoy_wrapper_file_read ... %u", *Len);
|
||||
|
||||
if (g_efi_file_replace.CurPos + ReadLen > g_efi_file_replace.FileSizeBytes)
|
||||
if (replace->CurPos + ReadLen > replace->FileSizeBytes)
|
||||
{
|
||||
ReadLen = g_efi_file_replace.FileSizeBytes - g_efi_file_replace.CurPos;
|
||||
ReadLen = replace->FileSizeBytes - replace->CurPos;
|
||||
}
|
||||
|
||||
Lba = g_efi_file_replace.CurPos / 2048 + g_efi_file_replace.BlockIoSectorStart;
|
||||
Lba = replace->CurPos / 2048 + replace->BlockIoSectorStart;
|
||||
|
||||
ventoy_block_io_read(NULL, 0, Lba, ReadLen, Data);
|
||||
|
||||
*Len = ReadLen;
|
||||
|
||||
g_efi_file_replace.CurPos += ReadLen;
|
||||
replace->CurPos += ReadLen;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
@@ -1362,7 +1381,7 @@ ventoy_wrapper_file_read_ex(IN EFI_FILE_PROTOCOL *This, IN OUT EFI_FILE_IO_TOKEN
|
||||
return ventoy_wrapper_file_read(This, &(Token->BufferSize), Token->Buffer);
|
||||
}
|
||||
|
||||
STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL *File)
|
||||
STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL *File, BOOLEAN Img)
|
||||
{
|
||||
File->Revision = EFI_FILE_PROTOCOL_REVISION2;
|
||||
File->Open = ventoy_wrapper_fs_open;
|
||||
@@ -1378,7 +1397,7 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_procotol(EFI_FILE_PROTOCOL *File)
|
||||
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;
|
||||
File->FlushEx = Img ? ventoy_wrapper_file_flush_ex_img : ventoy_wrapper_file_flush_ex;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
@@ -1397,6 +1416,7 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open
|
||||
UINT64 Sectors = 0;
|
||||
EFI_STATUS Status = EFI_SUCCESS;
|
||||
CHAR8 TmpName[256];
|
||||
CHAR8 OldName[256];
|
||||
ventoy_virt_chunk *virt = NULL;
|
||||
|
||||
debug("## ventoy_wrapper_file_open <%s> ", Name);
|
||||
@@ -1417,6 +1437,7 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
if (g_file_replace_list && g_file_replace_list->magic == GRUB_FILE_REPLACE_MAGIC &&
|
||||
g_file_replace_list->new_file_virtual_id < g_virt_chunk_num)
|
||||
{
|
||||
@@ -1427,7 +1448,7 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open
|
||||
{
|
||||
g_original_fclose(*New);
|
||||
*New = &g_efi_file_replace.WrapperHandle;
|
||||
ventoy_wrapper_file_procotol(*New);
|
||||
ventoy_wrapper_file_procotol(*New, FALSE);
|
||||
|
||||
virt = g_virt_chunk + g_file_replace_list->new_file_virtual_id;
|
||||
|
||||
@@ -1453,6 +1474,49 @@ STATIC EFI_STATUS EFIAPI ventoy_wrapper_file_open
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (g_img_replace_list && g_img_replace_list->magic == GRUB_IMG_REPLACE_MAGIC &&
|
||||
g_img_replace_list->new_file_virtual_id < g_virt_chunk_num)
|
||||
{
|
||||
AsciiSPrint(TmpName, sizeof(TmpName), "%s", Name);
|
||||
for (j = 0; j < g_img_replace_list->old_file_cnt; j++)
|
||||
{
|
||||
AsciiStrCpyS(OldName, sizeof(OldName), g_img_replace_list[i].old_file_name[j]);
|
||||
if ((0 == AsciiStrCmp(OldName, TmpName)) ||
|
||||
(AsciiStrnCmp(OldName, "\\loader\\entries\\", 16) == 0 &&
|
||||
AsciiStrCmp(OldName + 16, TmpName) == 0
|
||||
)
|
||||
)
|
||||
{
|
||||
g_original_fclose(*New);
|
||||
*New = &g_img_file_replace.WrapperHandle;
|
||||
ventoy_wrapper_file_procotol(*New, TRUE);
|
||||
|
||||
virt = g_virt_chunk + g_img_replace_list->new_file_virtual_id;
|
||||
|
||||
Sectors = (virt->mem_sector_end - virt->mem_sector_start) + (virt->remap_sector_end - virt->remap_sector_start);
|
||||
|
||||
g_img_file_replace.BlockIoSectorStart = virt->mem_sector_start;
|
||||
g_img_file_replace.FileSizeBytes = Sectors * 2048;
|
||||
|
||||
if (gDebugPrint)
|
||||
{
|
||||
debug("## ventoy_wrapper_file_open2 <%s> BlockStart:%lu Sectors:%lu Bytes:%lu", Name,
|
||||
g_img_file_replace.BlockIoSectorStart, Sectors, Sectors * 2048);
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
|
||||
if (StrCmp(Name, L"\\loader\\entries") == 0)
|
||||
{
|
||||
(*New)->Open = ventoy_wrapper_file_open;
|
||||
}
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
@@ -41,6 +41,7 @@ typedef struct ventoy_grub_param
|
||||
grub_env_get_pf grub_env_get;
|
||||
grub_env_set_pf grub_env_set;
|
||||
ventoy_grub_param_file_replace file_replace;
|
||||
ventoy_grub_param_file_replace img_replace;
|
||||
grub_env_printf_pf grub_env_printf;
|
||||
}ventoy_grub_param;
|
||||
#pragma pack()
|
||||
|
@@ -94,7 +94,7 @@ hash_file (grub_file_t file, const gcry_md_spec_t *hash, void *result)
|
||||
{
|
||||
total += r;
|
||||
div = grub_divmod64(total * 100, (grub_uint64_t)file->size, &ro);
|
||||
grub_printf("\rCalculating %d%% ", (int)div);
|
||||
grub_printf("\rCalculating %s %d%% ", hash->name, (int)div);
|
||||
grub_refresh();
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,7 @@ hash_file (grub_file_t file, const gcry_md_spec_t *hash, void *result)
|
||||
grub_free (context);
|
||||
if (progress)
|
||||
{
|
||||
grub_printf("\rCalculating 100%% \n\r\n");
|
||||
grub_printf("\rCalculating %s 100%% \n\r\n", hash->name);
|
||||
grub_refresh();
|
||||
}
|
||||
return GRUB_ERR_NONE;
|
||||
@@ -224,6 +224,8 @@ grub_cmd_hashsum (struct grub_extcmd_context *ctxt,
|
||||
int keep = state[3].set;
|
||||
int uncompress = state[4].set;
|
||||
unsigned unread = 0;
|
||||
int len = 0;
|
||||
char hashsum[256];
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE (aliases); i++)
|
||||
if (grub_strcmp (ctxt->extcmd->cmd->name, aliases[i].name) == 0)
|
||||
@@ -282,8 +284,12 @@ grub_cmd_hashsum (struct grub_extcmd_context *ctxt,
|
||||
continue;
|
||||
}
|
||||
for (j = 0; j < hash->mdlen; j++)
|
||||
grub_printf ("%02x", ((grub_uint8_t *) result)[j]);
|
||||
{
|
||||
grub_printf ("%02x", ((grub_uint8_t *) result)[j]);
|
||||
len += grub_snprintf(hashsum + len, sizeof(hashsum) - len, "%02x", ((grub_uint8_t *) result)[j]);
|
||||
}
|
||||
grub_printf (" %s\n", args[i]);
|
||||
grub_env_set("VT_LAST_CHECK_SUM", hashsum);
|
||||
}
|
||||
|
||||
if (unread)
|
||||
|
@@ -402,15 +402,24 @@ int g_menu_update_mode = 0;
|
||||
int g_ventoy_tip_label_enable = 0;
|
||||
const char * g_ventoy_tip_msg1 = NULL;
|
||||
const char * g_ventoy_tip_msg2 = NULL;
|
||||
char g_ventoy_theme_path[256] = {0};
|
||||
static const char *g_ventoy_cur_img_path = NULL;
|
||||
static void menu_set_chosen_tip(grub_menu_t menu, int entry)
|
||||
{
|
||||
int i;
|
||||
img_info *img;
|
||||
menu_tip *tip;
|
||||
grub_menu_entry_t e = grub_menu_get_entry (menu, entry);
|
||||
|
||||
if (g_ventoy_theme_path[0])
|
||||
{
|
||||
grub_env_set("theme", g_ventoy_theme_path);
|
||||
}
|
||||
|
||||
g_ventoy_tip_msg1 = g_ventoy_tip_msg2 = NULL;
|
||||
if (e && e->id && grub_strncmp(e->id, "VID_", 4) == 0)
|
||||
{
|
||||
g_ventoy_theme_path[0] = 0;
|
||||
img = (img_info *)(void *)grub_strtoul(e->id + 4, NULL, 16);
|
||||
if (img)
|
||||
{
|
||||
@@ -419,6 +428,27 @@ static void menu_set_chosen_tip(grub_menu_t menu, int entry)
|
||||
g_ventoy_cur_img_path = img->path;
|
||||
}
|
||||
}
|
||||
else if (e && e->id && grub_strncmp(e->id, "DIR_", 4) == 0)
|
||||
{
|
||||
g_ventoy_theme_path[0] = 0;
|
||||
for (i = 0; i < e->argc; i++)
|
||||
{
|
||||
if (e->args[i] && grub_strncmp(e->args[i], "_VTIP_", 6) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i < e->argc)
|
||||
{
|
||||
tip = (menu_tip *)(void *)grub_strtoul(e->args[i] + 6, NULL, 16);
|
||||
if (tip)
|
||||
{
|
||||
g_ventoy_tip_msg1 = tip->tip1;
|
||||
g_ventoy_tip_msg2 = tip->tip2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -913,6 +943,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
goto refresh;
|
||||
|
||||
case (GRUB_TERM_CTRL | 'h'):
|
||||
case 'h':
|
||||
{
|
||||
cmdstr = grub_env_get("VTOY_HELP_CMD");
|
||||
if (cmdstr)
|
||||
@@ -926,6 +957,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
break;
|
||||
}
|
||||
case (GRUB_TERM_CTRL | 'm'):
|
||||
case 'm':
|
||||
{
|
||||
if (g_ventoy_cur_img_path)
|
||||
{
|
||||
|
113
GRUB2/MOD_SRC/grub-2.04/grub-core/script/function.c
Normal file
113
GRUB2/MOD_SRC/grub-2.04/grub-core/script/function.c
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2005,2007,2009,2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/misc.h>
|
||||
#include <grub/script_sh.h>
|
||||
#include <grub/parser.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/charset.h>
|
||||
|
||||
grub_script_function_t grub_script_function_list;
|
||||
|
||||
grub_script_function_t
|
||||
grub_script_function_create (struct grub_script_arg *functionname_arg,
|
||||
struct grub_script *cmd)
|
||||
{
|
||||
grub_script_function_t func;
|
||||
grub_script_function_t *p;
|
||||
|
||||
func = (grub_script_function_t) grub_malloc (sizeof (*func));
|
||||
if (! func)
|
||||
return 0;
|
||||
|
||||
func->name = grub_strdup (functionname_arg->str);
|
||||
if (! func->name)
|
||||
{
|
||||
grub_free (func);
|
||||
return 0;
|
||||
}
|
||||
|
||||
func->func = cmd;
|
||||
|
||||
/* Keep the list sorted for simplicity. */
|
||||
p = &grub_script_function_list;
|
||||
while (*p)
|
||||
{
|
||||
if (grub_strcmp ((*p)->name, func->name) >= 0)
|
||||
break;
|
||||
|
||||
p = &((*p)->next);
|
||||
}
|
||||
|
||||
/* If the function already exists, overwrite the old function. */
|
||||
if (*p && grub_strcmp ((*p)->name, func->name) == 0)
|
||||
{
|
||||
grub_script_function_t q;
|
||||
|
||||
q = *p;
|
||||
grub_script_free (q->func);
|
||||
q->func = cmd;
|
||||
grub_free (func);
|
||||
func = q;
|
||||
}
|
||||
else
|
||||
{
|
||||
func->next = *p;
|
||||
*p = func;
|
||||
}
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
void
|
||||
grub_script_function_remove (const char *name)
|
||||
{
|
||||
grub_script_function_t *p, q;
|
||||
|
||||
for (p = &grub_script_function_list, q = *p; q; p = &(q->next), q = q->next)
|
||||
if (grub_strcmp (name, q->name) == 0)
|
||||
{
|
||||
*p = q->next;
|
||||
grub_free (q->name);
|
||||
grub_script_free (q->func);
|
||||
grub_free (q);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
grub_script_function_t
|
||||
grub_script_function_find (char *functionname)
|
||||
{
|
||||
grub_script_function_t func;
|
||||
|
||||
for (func = grub_script_function_list; func; func = func->next)
|
||||
if (grub_strcmp (functionname, func->name) == 0)
|
||||
break;
|
||||
|
||||
if (! func)
|
||||
{
|
||||
char tmp[64];
|
||||
grub_strncpy (tmp, functionname, 63);
|
||||
tmp[63] = 0;
|
||||
/* Avoid truncating inside UTF-8 character. */
|
||||
tmp[grub_getend (tmp, tmp + grub_strlen (tmp))] = 0;
|
||||
grub_error (GRUB_ERR_UNKNOWN_COMMAND, N_("can't find command `%s'"), tmp);
|
||||
}
|
||||
|
||||
return func;
|
||||
}
|
@@ -51,35 +51,11 @@
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_uint8_t g_check_mbr_data[440] = {
|
||||
static grub_uint8_t g_check_mbr_data[] = {
|
||||
0xEB, 0x63, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFA, 0x90, 0x90, 0xF6, 0xC2, 0x80, 0x74, 0x05, 0xF6, 0xC2, 0x70,
|
||||
0x74, 0x02, 0xB2, 0x80, 0xEA, 0x79, 0x7C, 0x00, 0x00, 0x31, 0xC0, 0x8E, 0xD8, 0x8E, 0xD0, 0xBC,
|
||||
0x00, 0x20, 0xFB, 0xA0, 0x64, 0x7C, 0x3C, 0xFF, 0x74, 0x02, 0x88, 0xC2, 0x52, 0xBE, 0x90, 0x7D,
|
||||
0xE8, 0x16, 0x01, 0xBE, 0x05, 0x7C, 0xB4, 0x41, 0xBB, 0xAA, 0x55, 0xCD, 0x13, 0x5A, 0x52, 0x72,
|
||||
0x3D, 0x81, 0xFB, 0x55, 0xAA, 0x75, 0x37, 0x83, 0xE1, 0x01, 0x74, 0x32, 0x31, 0xC0, 0x89, 0x44,
|
||||
0x04, 0x40, 0x88, 0x44, 0xFF, 0x89, 0x44, 0x02, 0xC7, 0x04, 0x10, 0x00, 0x66, 0x8B, 0x1E, 0x5C,
|
||||
0x7C, 0x66, 0x89, 0x5C, 0x08, 0x66, 0x8B, 0x1E, 0x60, 0x7C, 0x66, 0x89, 0x5C, 0x0C, 0xC7, 0x44,
|
||||
0x06, 0x00, 0x70, 0xB4, 0x42, 0xCD, 0x13, 0x72, 0x05, 0xBB, 0x00, 0x70, 0xEB, 0x76, 0xB4, 0x08,
|
||||
0xCD, 0x13, 0x73, 0x0D, 0x5A, 0x84, 0xD2, 0x0F, 0x83, 0xD8, 0x00, 0xBE, 0x96, 0x7D, 0xE9, 0x82,
|
||||
0x00, 0x66, 0x0F, 0xB6, 0xC6, 0x88, 0x64, 0xFF, 0x40, 0x66, 0x89, 0x44, 0x04, 0x0F, 0xB6, 0xD1,
|
||||
0xC1, 0xE2, 0x02, 0x88, 0xE8, 0x88, 0xF4, 0x40, 0x89, 0x44, 0x08, 0x0F, 0xB6, 0xC2, 0xC0, 0xE8,
|
||||
0x02, 0x66, 0x89, 0x04, 0x66, 0xA1, 0x60, 0x7C, 0x66, 0x09, 0xC0, 0x75, 0x4E, 0x66, 0xA1, 0x5C,
|
||||
0x7C, 0x66, 0x31, 0xD2, 0x66, 0xF7, 0x34, 0x88, 0xD1, 0x31, 0xD2, 0x66, 0xF7, 0x74, 0x04, 0x3B,
|
||||
0x44, 0x08, 0x7D, 0x37, 0xFE, 0xC1, 0x88, 0xC5, 0x30, 0xC0, 0xC1, 0xE8, 0x02, 0x08, 0xC1, 0x88,
|
||||
0xD0, 0x5A, 0x88, 0xC6, 0xBB, 0x00, 0x70, 0x8E, 0xC3, 0x31, 0xDB, 0xB8, 0x01, 0x02, 0xCD, 0x13,
|
||||
0x72, 0x1E, 0x8C, 0xC3, 0x60, 0x1E, 0xB9, 0x00, 0x01, 0x8E, 0xDB, 0x31, 0xF6, 0xBF, 0x00, 0x80,
|
||||
0x8E, 0xC6, 0xFC, 0xF3, 0xA5, 0x1F, 0x61, 0xFF, 0x26, 0x5A, 0x7C, 0xBE, 0x93, 0x7D, 0xEB, 0x03,
|
||||
0xBE, 0x99, 0x7D, 0xE8, 0x33, 0x00, 0xBE, 0x9C, 0x7D, 0xE8, 0x2D, 0x00, 0xCD, 0x18, 0xEB, 0xFE,
|
||||
0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x56, 0x54, 0x00, 0x47, 0x65, 0x00, 0x48, 0x44, 0x00, 0x52, 0x64, 0x00, 0x20, 0x45, 0x72, 0x0D,
|
||||
0x0A, 0x00, 0xBB, 0x01, 0x00, 0xB4, 0x0E, 0xCD, 0x10, 0xAC, 0x3C, 0x00, 0x75, 0xF4, 0xC3, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
initrd_info *g_initrd_img_list = NULL;
|
||||
@@ -655,12 +631,8 @@ static int ventoy_check_official_device(grub_device_t dev)
|
||||
grub_memset(mbr, 0, 512);
|
||||
grub_disk_read(disk, 0, 0, 512, mbr);
|
||||
grub_disk_close(disk);
|
||||
|
||||
g_check_mbr_data[92] = mbr[92];
|
||||
g_check_mbr_data[102] = mbr[102];
|
||||
g_check_mbr_data[103] = mbr[103];
|
||||
grub_memcpy(g_check_mbr_data + 0x180, mbr + 0x180, 16);
|
||||
if (grub_memcmp(g_check_mbr_data, mbr, 440))
|
||||
|
||||
if (grub_memcmp(g_check_mbr_data, mbr, 0x30) || grub_memcmp(g_check_mbr_data + 0x30, mbr + 0x190, 16))
|
||||
{
|
||||
return ventoy_set_check_result(12);
|
||||
}
|
||||
@@ -918,6 +890,38 @@ static grub_err_t ventoy_cmd_strbegin(grub_extcmd_context_t ctxt, int argc, char
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t ventoy_cmd_strcasebegin(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
char *c0, *c1;
|
||||
|
||||
(void)ctxt;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
c0 = args[0];
|
||||
c1 = args[1];
|
||||
|
||||
while (*c0 && *c1)
|
||||
{
|
||||
if ((*c0 != *c1) && (*c0 != grub_toupper(*c1)))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
c0++;
|
||||
c1++;
|
||||
}
|
||||
|
||||
if (*c1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t ventoy_cmd_incr(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
long value_long = 0;
|
||||
@@ -1834,7 +1838,7 @@ static int ventoy_collect_img_files(const char *filename, const struct grub_dirh
|
||||
|
||||
img->alias = ventoy_plugin_get_menu_alias(vtoy_alias_image_file, img->path);
|
||||
|
||||
tip = ventoy_plugin_get_menu_tip(img->path);
|
||||
tip = ventoy_plugin_get_menu_tip(vtoy_tip_image_file, img->path);
|
||||
if (tip)
|
||||
{
|
||||
img->tip1 = tip->tip1;
|
||||
@@ -2035,7 +2039,8 @@ static int ventoy_dynamic_tree_menu(img_iterator_node *node)
|
||||
const char *dir_class = NULL;
|
||||
const char *dir_alias = NULL;
|
||||
img_iterator_node *child = NULL;
|
||||
|
||||
const menu_tip *tip = NULL;
|
||||
|
||||
if (node->isocnt == 0 || node->done == 1)
|
||||
{
|
||||
return 0;
|
||||
@@ -2075,20 +2080,22 @@ static int ventoy_dynamic_tree_menu(img_iterator_node *node)
|
||||
dir_class = "vtoydir";
|
||||
}
|
||||
|
||||
tip = ventoy_plugin_get_menu_tip(vtoy_tip_directory, node->dir);
|
||||
|
||||
dir_alias = ventoy_plugin_get_menu_alias(vtoy_alias_directory, node->dir);
|
||||
if (dir_alias)
|
||||
{
|
||||
if (g_tree_view_menu_style == 0)
|
||||
{
|
||||
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos,
|
||||
"submenu \"%-10s %s\" --class=\"%s\" --id=\"DIR_%s\" {\n",
|
||||
"DIR", dir_alias, dir_class, node->dir + offset);
|
||||
"submenu \"%-10s %s\" --class=\"%s\" --id=\"DIR_%s\" _VTIP_%p {\n",
|
||||
"DIR", dir_alias, dir_class, node->dir + offset, tip);
|
||||
}
|
||||
else
|
||||
{
|
||||
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos,
|
||||
"submenu \"%s\" --class=\"%s\" --id=\"DIR_%s\" {\n",
|
||||
dir_alias, dir_class, node->dir + offset);
|
||||
"submenu \"%s\" --class=\"%s\" --id=\"DIR_%s\" _VTIP_%p {\n",
|
||||
dir_alias, dir_class, node->dir + offset, tip);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -2098,14 +2105,14 @@ static int ventoy_dynamic_tree_menu(img_iterator_node *node)
|
||||
if (g_tree_view_menu_style == 0)
|
||||
{
|
||||
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos,
|
||||
"submenu \"%-10s [%s]\" --class=\"%s\" --id=\"DIR_%s\" {\n",
|
||||
"DIR", dir_alias, dir_class, node->dir + offset);
|
||||
"submenu \"%-10s [%s]\" --class=\"%s\" --id=\"DIR_%s\" _VTIP_%p {\n",
|
||||
"DIR", dir_alias, dir_class, node->dir + offset, tip);
|
||||
}
|
||||
else
|
||||
{
|
||||
vtoy_ssprintf(g_tree_script_buf, g_tree_script_pos,
|
||||
"submenu \"[%s]\" --class=\"%s\" --id=\"DIR_%s\" {\n",
|
||||
dir_alias, dir_class, node->dir + offset);
|
||||
"submenu \"[%s]\" --class=\"%s\" --id=\"DIR_%s\" _VTIP_%p {\n",
|
||||
dir_alias, dir_class, node->dir + offset, tip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2669,6 +2676,22 @@ grub_uint32_t ventoy_get_iso_boot_catlog(grub_file_t file)
|
||||
return desc.sector;
|
||||
}
|
||||
|
||||
static grub_uint32_t ventoy_get_bios_eltorito_rba(grub_file_t file, grub_uint32_t sector)
|
||||
{
|
||||
grub_uint8_t buf[512];
|
||||
|
||||
grub_file_seek(file, sector * 2048);
|
||||
grub_file_read(file, buf, sizeof(buf));
|
||||
|
||||
if (buf[0] == 0x01 && buf[1] == 0x00 &&
|
||||
buf[30] == 0x55 && buf[31] == 0xaa && buf[32] == 0x88)
|
||||
{
|
||||
return *((grub_uint32_t *)(buf + 40));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ventoy_has_efi_eltorito(grub_file_t file, grub_uint32_t sector)
|
||||
{
|
||||
int i;
|
||||
@@ -2946,6 +2969,7 @@ static grub_err_t ventoy_cmd_img_sector(grub_extcmd_context_t ctxt, int argc, ch
|
||||
}
|
||||
|
||||
grub_memset(&g_grub_param->file_replace, 0, sizeof(g_grub_param->file_replace));
|
||||
grub_memset(&g_grub_param->img_replace, 0, sizeof(g_grub_param->img_replace));
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
@@ -2977,15 +3001,21 @@ static grub_err_t ventoy_select_conf_replace(grub_extcmd_context_t ctxt, int arg
|
||||
debug("Find conf replace for %s\n", args[1]);
|
||||
|
||||
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "(loop)%s", node->orgconf);
|
||||
if (!file)
|
||||
if (file)
|
||||
{
|
||||
offset = grub_iso9660_get_last_file_dirent_pos(file);
|
||||
grub_file_close(file);
|
||||
}
|
||||
else if (node->img > 0)
|
||||
{
|
||||
offset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
debug("<(loop)%s> NOT exist\n", node->orgconf);
|
||||
goto end;
|
||||
}
|
||||
|
||||
offset = grub_iso9660_get_last_file_dirent_pos(file);
|
||||
grub_file_close(file);
|
||||
|
||||
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", args[0], node->newconf);
|
||||
if (!file)
|
||||
{
|
||||
@@ -3008,6 +3038,13 @@ static grub_err_t ventoy_select_conf_replace(grub_extcmd_context_t ctxt, int arg
|
||||
g_conf_replace_node = node;
|
||||
g_conf_replace_offset = offset + 2;
|
||||
|
||||
if (node->img > 0)
|
||||
{
|
||||
g_grub_param->img_replace.magic = GRUB_IMG_REPLACE_MAGIC;
|
||||
g_grub_param->img_replace.old_name_cnt = 1;
|
||||
grub_snprintf(g_grub_param->img_replace.old_file_name[0], 256, "%s", node->orgconf);
|
||||
}
|
||||
|
||||
debug("conf_replace OK: newlen: %d\n", g_conf_replace_new_len);
|
||||
|
||||
end:
|
||||
@@ -4820,7 +4857,7 @@ static int ventoy_chk_case_file(const char *filename, const struct grub_dirhook_
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (0 == info->dir && grub_strncasecmp(filename, "ventoy.json", 11) == 0)
|
||||
if (0 == info->dir && grub_strcasecmp(filename, "ventoy.json") == 0)
|
||||
{
|
||||
grub_snprintf(g_json_case_mis_path, 32, "%s/%s", (char *)data, filename);
|
||||
return 1;
|
||||
@@ -4840,7 +4877,7 @@ static int ventoy_chk_case_dir(const char *filename, const struct grub_dirhook_i
|
||||
|
||||
if (info->dir && (filename[0] == 'v' || filename[0] == 'V'))
|
||||
{
|
||||
if (grub_strncasecmp(filename, "ventoy", 6) == 0)
|
||||
if (grub_strcasecmp(filename, "ventoy") == 0)
|
||||
{
|
||||
grub_snprintf(path, sizeof(path), "/%s", filename);
|
||||
fs_dir->fs->fs_dir(fs_dir->dev, path, ventoy_chk_case_file, path);
|
||||
@@ -4961,26 +4998,71 @@ static grub_err_t grub_cmd_gptpriority(grub_extcmd_context_t ctxt, int argc, cha
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* <BEGIN>: Deleted by longpanda, 20210916 PN:XX LABEL:XX */
|
||||
#if 0
|
||||
void ventoy_tip_set_menu_label(const char *vid)
|
||||
static grub_err_t grub_cmd_syslinux_nojoliet(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
img_info *node;
|
||||
int ret = 1;
|
||||
int joliet = 0;
|
||||
grub_file_t file = NULL;
|
||||
grub_uint32_t loadrba = 0;
|
||||
grub_uint32_t boot_catlog = 0;
|
||||
grub_uint8_t sector[512];
|
||||
boot_info_table *info = NULL;
|
||||
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
|
||||
g_ventoy_tip_msg1 = g_ventoy_tip_msg2 = NULL;
|
||||
if (vid)
|
||||
/* This also trigger a iso9660 fs parse */
|
||||
if (ventoy_check_file_exist("(loop)/isolinux/isolinux.cfg"))
|
||||
{
|
||||
node = (img_info *)(void *)grub_strtoul(vid + 4, NULL, 16);
|
||||
if (node)
|
||||
{
|
||||
g_ventoy_tip_msg1 = node->tip1;
|
||||
g_ventoy_tip_msg2 = node->tip2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
joliet = grub_iso9660_is_joliet();
|
||||
if (joliet == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
file = grub_file_open(args[0], VENTOY_FILE_TYPE);
|
||||
if (!file)
|
||||
{
|
||||
debug("failed to open %s\n", args[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
boot_catlog = ventoy_get_iso_boot_catlog(file);
|
||||
if (boot_catlog == 0)
|
||||
{
|
||||
debug("no bootcatlog found %u\n", boot_catlog);
|
||||
goto out;
|
||||
}
|
||||
|
||||
loadrba = ventoy_get_bios_eltorito_rba(file, boot_catlog);
|
||||
if (loadrba == 0)
|
||||
{
|
||||
debug("no bios eltorito rba found %u\n", loadrba);
|
||||
goto out;
|
||||
}
|
||||
|
||||
grub_file_seek(file, loadrba * 2048);
|
||||
grub_file_read(file, sector, 512);
|
||||
|
||||
info = (boot_info_table *)sector;
|
||||
if (info->bi_data0 == 0x7c6ceafa &&
|
||||
info->bi_data1 == 0x90900000 &&
|
||||
info->bi_PrimaryVolumeDescriptor == 16 &&
|
||||
info->bi_BootFileLocation == loadrba)
|
||||
{
|
||||
debug("bootloader is syslinux, %u.\n", loadrba);
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
out:
|
||||
|
||||
grub_file_close(file);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
return ret;
|
||||
}
|
||||
#endif /* #if 0 */
|
||||
/* <END> : Deleted by longpanda, 20210916 PN:XX LABEL:XX */
|
||||
|
||||
int ventoy_env_init(void)
|
||||
{
|
||||
@@ -5037,6 +5119,7 @@ static cmd_para ventoy_cmds[] =
|
||||
{ "vt_mod", ventoy_cmd_mod, 0, NULL, "{Int} {Int} {Var}", "mod integer variable", NULL },
|
||||
{ "vt_strstr", ventoy_cmd_strstr, 0, NULL, "", "", NULL },
|
||||
{ "vt_str_begin", ventoy_cmd_strbegin, 0, NULL, "", "", NULL },
|
||||
{ "vt_str_casebegin", ventoy_cmd_strcasebegin, 0, NULL, "", "", NULL },
|
||||
{ "vt_debug", ventoy_cmd_debug, 0, NULL, "{on|off}", "turn debug on/off", NULL },
|
||||
{ "vtdebug", ventoy_cmd_debug, 0, NULL, "{on|off}", "turn debug on/off", NULL },
|
||||
{ "vtbreak", ventoy_cmd_break, 0, NULL, "{level}", "set debug break", NULL },
|
||||
@@ -5142,6 +5225,7 @@ static cmd_para ventoy_cmds[] =
|
||||
{ "vt_unix_reset", ventoy_cmd_unix_reset, 0, NULL, "", "", NULL },
|
||||
{ "vt_unix_replace_conf", ventoy_cmd_unix_replace_conf, 0, NULL, "", "", NULL },
|
||||
{ "vt_unix_replace_ko", ventoy_cmd_unix_replace_ko, 0, NULL, "", "", NULL },
|
||||
{ "vt_unix_ko_fillmap", ventoy_cmd_unix_ko_fillmap, 0, NULL, "", "", NULL },
|
||||
{ "vt_unix_fill_image_desc", ventoy_cmd_unix_fill_image_desc, 0, NULL, "", "", NULL },
|
||||
{ "vt_unix_gzip_new_ko", ventoy_cmd_unix_gzip_newko, 0, NULL, "", "", NULL },
|
||||
{ "vt_unix_chain_data", ventoy_cmd_unix_chain_data, 0, NULL, "", "", NULL },
|
||||
@@ -5156,6 +5240,8 @@ static cmd_para ventoy_cmds[] =
|
||||
{ "vt_sel_wimboot", ventoy_cmd_sel_wimboot, 0, NULL, "", "", NULL },
|
||||
{ "vt_set_wim_load_prompt", ventoy_cmd_set_wim_prompt, 0, NULL, "", "", NULL },
|
||||
{ "vt_set_theme", ventoy_cmd_set_theme, 0, NULL, "", "", NULL },
|
||||
{ "vt_set_theme_path", ventoy_cmd_set_theme_path, 0, NULL, "", "", NULL },
|
||||
{ "vt_select_theme_cfg", ventoy_cmd_select_theme_cfg, 0, NULL, "", "", NULL },
|
||||
|
||||
{ "vt_get_efi_vdisk_offset", ventoy_cmd_get_efivdisk_offset, 0, NULL, "", "", NULL },
|
||||
{ "vt_search_replace_initrd", ventoy_cmd_search_replace_initrd, 0, NULL, "", "", NULL },
|
||||
@@ -5164,6 +5250,7 @@ static cmd_para ventoy_cmds[] =
|
||||
{ "vt_check_json_path_case", ventoy_cmd_chk_json_pathcase, 0, NULL, "", "", NULL },
|
||||
{ "vt_append_extra_sector", ventoy_cmd_append_ext_sector, 0, NULL, "", "", NULL },
|
||||
{ "gptpriority", grub_cmd_gptpriority, 0, NULL, "", "", NULL },
|
||||
{ "vt_syslinux_need_nojoliet", grub_cmd_syslinux_nojoliet, 0, NULL, "", "", NULL },
|
||||
};
|
||||
|
||||
int ventoy_register_all_cmd(void)
|
||||
|
@@ -199,6 +199,18 @@ typedef struct ventoy_iso9660_vd
|
||||
grub_uint32_t space;
|
||||
}ventoy_iso9660_vd;
|
||||
|
||||
/* https://wiki.osdev.org/El-Torito */
|
||||
typedef struct boot_info_table
|
||||
{
|
||||
grub_uint32_t bi_data0;
|
||||
grub_uint32_t bi_data1;
|
||||
grub_uint32_t bi_PrimaryVolumeDescriptor;
|
||||
grub_uint32_t bi_BootFileLocation;
|
||||
grub_uint32_t bi_BootFileLength;
|
||||
grub_uint32_t bi_Checksum;
|
||||
grub_uint8_t bi_Reserved[40];
|
||||
}boot_info_table;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#define img_type_start 0
|
||||
@@ -550,6 +562,7 @@ typedef struct plugin_entry
|
||||
const char *key;
|
||||
ventoy_plugin_entry_pf entryfunc;
|
||||
ventoy_plugin_check_pf checkfunc;
|
||||
int flag;
|
||||
}plugin_entry;
|
||||
|
||||
typedef struct replace_fs_dir
|
||||
@@ -883,8 +896,11 @@ typedef struct menu_alias
|
||||
struct menu_alias *next;
|
||||
}menu_alias;
|
||||
|
||||
#define vtoy_tip_image_file 0
|
||||
#define vtoy_tip_directory 1
|
||||
typedef struct menu_tip
|
||||
{
|
||||
int type;
|
||||
int pathlen;
|
||||
char isopath[256];
|
||||
char tip1[1024];
|
||||
@@ -925,6 +941,7 @@ typedef struct custom_boot
|
||||
typedef struct conf_replace
|
||||
{
|
||||
int pathlen;
|
||||
int img;
|
||||
char isopath[256];
|
||||
char orgconf[256];
|
||||
char newconf[256];
|
||||
@@ -1049,7 +1066,7 @@ 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_injection(const char *isopath);
|
||||
const char * ventoy_plugin_get_menu_alias(int type, const char *isopath);
|
||||
const menu_tip * ventoy_plugin_get_menu_tip(const char *isopath);
|
||||
const menu_tip * ventoy_plugin_get_menu_tip(int type, const char *isopath);
|
||||
const char * ventoy_plugin_get_menu_class(int type, const char *name, const char *path);
|
||||
int ventoy_plugin_check_memdisk(const char *isopath);
|
||||
int ventoy_plugin_get_image_list_index(int type, const char *name);
|
||||
@@ -1060,6 +1077,8 @@ int ventoy_get_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, gr
|
||||
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_set_theme(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_set_theme_path(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_select_theme_cfg(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_check_password(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);
|
||||
@@ -1071,6 +1090,7 @@ int ventoy_get_disk_guid(const char *filename, grub_uint8_t *guid, grub_uint8_t
|
||||
grub_err_t ventoy_cmd_unix_reset(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_unix_replace_ko(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_unix_ko_fillmap(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_unix_fill_image_desc(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_unix_gzip_newko(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_unix_freebsd_ver(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
@@ -1109,5 +1129,29 @@ int ventoy_chain_file_read(const char *path, int offset, int len, void *buf);
|
||||
|
||||
#define ret_goto_end(a) ret = a; goto end;
|
||||
|
||||
extern ventoy_grub_param *g_grub_param;
|
||||
|
||||
#pragma pack(1)
|
||||
#define VENTOY_UNIX_SEG_MAGIC0 0x11223344
|
||||
#define VENTOY_UNIX_SEG_MAGIC1 0x55667788
|
||||
#define VENTOY_UNIX_SEG_MAGIC2 0x99aabbcc
|
||||
#define VENTOY_UNIX_SEG_MAGIC3 0xddeeff00
|
||||
#define VENTOY_UNIX_MAX_SEGNUM 40960
|
||||
struct g_ventoy_seg {
|
||||
grub_uint64_t seg_start_bytes;
|
||||
grub_uint64_t seg_end_bytes;
|
||||
};
|
||||
|
||||
struct g_ventoy_map{
|
||||
grub_uint32_t magic1[4];
|
||||
grub_uint32_t magic2[4];
|
||||
grub_uint64_t segnum;
|
||||
grub_uint64_t disksize;
|
||||
grub_uint8_t diskuuid[16];
|
||||
struct g_ventoy_seg seglist[VENTOY_UNIX_MAX_SEGNUM];
|
||||
grub_uint32_t magic3[4];
|
||||
};
|
||||
#pragma pack()
|
||||
|
||||
#endif /* __VENTOY_DEF_H__ */
|
||||
|
||||
|
@@ -691,6 +691,7 @@ static grub_uint32_t ventoy_linux_get_virt_chunk_size(void)
|
||||
static void ventoy_linux_fill_virt_data( grub_uint64_t isosize, ventoy_chain_head *chain)
|
||||
{
|
||||
int id = 0;
|
||||
int virtid = 0;
|
||||
initrd_info *node;
|
||||
grub_uint64_t sector;
|
||||
grub_uint32_t offset;
|
||||
@@ -738,6 +739,7 @@ static void ventoy_linux_fill_virt_data( grub_uint64_t isosize, ventoy_chain_
|
||||
offset += g_ventoy_cpio_size;
|
||||
sector += cpio_secs + initrd_secs;
|
||||
cur++;
|
||||
virtid++;
|
||||
}
|
||||
|
||||
/* Lenovo EasyStartup need an addional sector for boundary check */
|
||||
@@ -759,6 +761,7 @@ static void ventoy_linux_fill_virt_data( grub_uint64_t isosize, ventoy_chain_
|
||||
offset += VTOY_APPEND_EXT_SIZE;
|
||||
sector += cpio_secs;
|
||||
cur++;
|
||||
virtid++;
|
||||
}
|
||||
|
||||
if (g_conf_replace_offset > 0)
|
||||
@@ -776,9 +779,15 @@ static void ventoy_linux_fill_virt_data( grub_uint64_t isosize, ventoy_chain_
|
||||
|
||||
chain->virt_img_size_in_bytes += g_conf_replace_new_len_align;
|
||||
|
||||
if (g_grub_param->img_replace.magic == GRUB_IMG_REPLACE_MAGIC)
|
||||
{
|
||||
g_grub_param->img_replace.new_file_virtual_id = virtid;
|
||||
}
|
||||
|
||||
offset += g_conf_replace_new_len_align;
|
||||
sector += cpio_secs;
|
||||
cur++;
|
||||
virtid++;
|
||||
}
|
||||
|
||||
return;
|
||||
|
@@ -57,6 +57,7 @@ static auto_memdisk *g_auto_memdisk_head = NULL;
|
||||
static image_list *g_image_list_head = NULL;
|
||||
static conf_replace *g_conf_replace_head = NULL;
|
||||
|
||||
static int g_theme_id = 0;
|
||||
static int g_theme_num = 0;
|
||||
static theme_list *g_theme_head = NULL;
|
||||
static int g_theme_random = vtoy_theme_random_boot_second;
|
||||
@@ -281,6 +282,7 @@ static int ventoy_plugin_theme_check(VTOY_JSON *json, const char *isodisk)
|
||||
static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
const char *value;
|
||||
char val[64];
|
||||
char filepath[256];
|
||||
VTOY_JSON *node = NULL;
|
||||
theme_list *tail = NULL;
|
||||
@@ -366,6 +368,18 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
grub_snprintf(val, sizeof(val), "%d", g_theme_num);
|
||||
grub_env_set("VTOY_THEME_COUNT", val);
|
||||
grub_env_export("VTOY_THEME_COUNT");
|
||||
if (g_theme_num > 0)
|
||||
{
|
||||
vtoy_json_get_int(json->pstChild, "default_file", &g_theme_id);
|
||||
if (g_theme_id > g_theme_num || g_theme_id < 0)
|
||||
{
|
||||
g_theme_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
value = vtoy_json_get_string_ex(json->pstChild, "gfxmode");
|
||||
if (value)
|
||||
@@ -1478,6 +1492,7 @@ static int ventoy_plugin_menualias_entry(VTOY_JSON *json, const char *isodisk)
|
||||
|
||||
static int ventoy_plugin_menutip_check(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int type;
|
||||
const char *path = NULL;
|
||||
const char *tip = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
@@ -1511,20 +1526,41 @@ static int ventoy_plugin_menutip_check(VTOY_JSON *json, const char *isodisk)
|
||||
pNode = vtoy_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "tips");
|
||||
for (pNode = pNode->pstChild; pNode; pNode = pNode->pstNext)
|
||||
{
|
||||
type = vtoy_tip_image_file;
|
||||
path = vtoy_json_get_string_ex(pNode->pstChild, "image");
|
||||
if (!path)
|
||||
{
|
||||
path = vtoy_json_get_string_ex(pNode->pstChild, "dir");
|
||||
type = vtoy_tip_directory;
|
||||
}
|
||||
|
||||
if (path && path[0] == '/')
|
||||
{
|
||||
if (grub_strchr(path, '*'))
|
||||
if (vtoy_tip_image_file == type)
|
||||
{
|
||||
grub_printf("image: <%s> [ * ]\n", path);
|
||||
}
|
||||
else if (ventoy_check_file_exist("%s%s", isodisk, path))
|
||||
{
|
||||
grub_printf("image: <%s> [ OK ]\n", path);
|
||||
if (grub_strchr(path, '*'))
|
||||
{
|
||||
grub_printf("image: <%s> [ * ]\n", path);
|
||||
}
|
||||
else 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
|
||||
{
|
||||
grub_printf("image: <%s> [ NOT EXIST ]\n", path);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
tip = vtoy_json_get_string_ex(pNode->pstChild, "tip");
|
||||
@@ -1558,6 +1594,7 @@ static int ventoy_plugin_menutip_check(VTOY_JSON *json, const char *isodisk)
|
||||
|
||||
static int ventoy_plugin_menutip_entry(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int type;
|
||||
const char *path = NULL;
|
||||
const char *tip = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
@@ -1610,12 +1647,20 @@ static int ventoy_plugin_menutip_entry(VTOY_JSON *json, const char *isodisk)
|
||||
|
||||
for (pNode = pNode->pstChild; pNode; pNode = pNode->pstNext)
|
||||
{
|
||||
type = vtoy_tip_image_file;
|
||||
path = vtoy_json_get_string_ex(pNode->pstChild, "image");
|
||||
if (!path)
|
||||
{
|
||||
path = vtoy_json_get_string_ex(pNode->pstChild, "dir");
|
||||
type = vtoy_tip_directory;
|
||||
}
|
||||
|
||||
if (path && path[0] == '/')
|
||||
{
|
||||
node = grub_zalloc(sizeof(menu_tip));
|
||||
if (node)
|
||||
{
|
||||
node->type = type;
|
||||
node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", path);
|
||||
|
||||
tip = vtoy_json_get_string_ex(pNode->pstChild, "tip");
|
||||
@@ -2005,6 +2050,7 @@ static int ventoy_plugin_custom_boot_check(VTOY_JSON *json, const char *isodisk)
|
||||
|
||||
static int ventoy_plugin_conf_replace_entry(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int img = 0;
|
||||
const char *isof = NULL;
|
||||
const char *orgf = NULL;
|
||||
const char *newf = NULL;
|
||||
@@ -2042,6 +2088,11 @@ static int ventoy_plugin_conf_replace_entry(VTOY_JSON *json, const char *isodisk
|
||||
node = grub_zalloc(sizeof(conf_replace));
|
||||
if (node)
|
||||
{
|
||||
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "img", &img))
|
||||
{
|
||||
node->img = img;
|
||||
}
|
||||
|
||||
node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", isof);
|
||||
grub_snprintf(node->orgconf, sizeof(node->orgconf), "%s", orgf);
|
||||
grub_snprintf(node->newconf, sizeof(node->newconf), "%s", newf);
|
||||
@@ -2064,6 +2115,7 @@ static int ventoy_plugin_conf_replace_entry(VTOY_JSON *json, const char *isodisk
|
||||
|
||||
static int ventoy_plugin_conf_replace_check(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int img = 0;
|
||||
const char *isof = NULL;
|
||||
const char *orgf = NULL;
|
||||
const char *newf = NULL;
|
||||
@@ -2133,7 +2185,7 @@ static int ventoy_plugin_conf_replace_check(VTOY_JSON *json, const char *isodisk
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("new:<%s> [OK]\n", newf);
|
||||
grub_printf("new1:<%s> [OK]\n", newf);
|
||||
}
|
||||
grub_file_close(file);
|
||||
}
|
||||
@@ -2141,6 +2193,12 @@ static int ventoy_plugin_conf_replace_check(VTOY_JSON *json, const char *isodisk
|
||||
{
|
||||
grub_printf("new:<%s> [NOT Exist]\n", newf);
|
||||
}
|
||||
|
||||
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "img", &img))
|
||||
{
|
||||
grub_printf("img:<%d>\n", img);
|
||||
}
|
||||
|
||||
grub_printf("\n");
|
||||
}
|
||||
}
|
||||
@@ -2325,45 +2383,59 @@ static int ventoy_plugin_image_list_check(VTOY_JSON *json, const char *isodisk)
|
||||
|
||||
static plugin_entry g_plugin_entries[] =
|
||||
{
|
||||
{ "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_tip", ventoy_plugin_menutip_entry, ventoy_plugin_menutip_check },
|
||||
{ "menu_class", ventoy_plugin_menuclass_entry, ventoy_plugin_menuclass_check },
|
||||
{ "injection", ventoy_plugin_injection_entry, ventoy_plugin_injection_check },
|
||||
{ "auto_memdisk", ventoy_plugin_auto_memdisk_entry, ventoy_plugin_auto_memdisk_check },
|
||||
{ "image_list", ventoy_plugin_image_list_entry, ventoy_plugin_image_list_check },
|
||||
{ "image_blacklist", ventoy_plugin_image_list_entry, ventoy_plugin_image_list_check },
|
||||
{ "conf_replace", ventoy_plugin_conf_replace_entry, ventoy_plugin_conf_replace_check },
|
||||
{ "dud", ventoy_plugin_dud_entry, ventoy_plugin_dud_check },
|
||||
{ "password", ventoy_plugin_pwd_entry, ventoy_plugin_pwd_check },
|
||||
{ "custom_boot", ventoy_plugin_custom_boot_entry, ventoy_plugin_custom_boot_check },
|
||||
{ "control", ventoy_plugin_control_entry, ventoy_plugin_control_check, 0 },
|
||||
{ "theme", ventoy_plugin_theme_entry, ventoy_plugin_theme_check, 0 },
|
||||
{ "auto_install", ventoy_plugin_auto_install_entry, ventoy_plugin_auto_install_check, 0 },
|
||||
{ "persistence", ventoy_plugin_persistence_entry, ventoy_plugin_persistence_check, 0 },
|
||||
{ "menu_alias", ventoy_plugin_menualias_entry, ventoy_plugin_menualias_check, 0 },
|
||||
{ "menu_tip", ventoy_plugin_menutip_entry, ventoy_plugin_menutip_check, 0 },
|
||||
{ "menu_class", ventoy_plugin_menuclass_entry, ventoy_plugin_menuclass_check, 0 },
|
||||
{ "injection", ventoy_plugin_injection_entry, ventoy_plugin_injection_check, 0 },
|
||||
{ "auto_memdisk", ventoy_plugin_auto_memdisk_entry, ventoy_plugin_auto_memdisk_check, 0 },
|
||||
{ "image_list", ventoy_plugin_image_list_entry, ventoy_plugin_image_list_check, 0 },
|
||||
{ "image_blacklist", ventoy_plugin_image_list_entry, ventoy_plugin_image_list_check, 0 },
|
||||
{ "conf_replace", ventoy_plugin_conf_replace_entry, ventoy_plugin_conf_replace_check, 0 },
|
||||
{ "dud", ventoy_plugin_dud_entry, ventoy_plugin_dud_check, 0 },
|
||||
{ "password", ventoy_plugin_pwd_entry, ventoy_plugin_pwd_check, 0 },
|
||||
{ "custom_boot", ventoy_plugin_custom_boot_entry, ventoy_plugin_custom_boot_check, 0 },
|
||||
};
|
||||
|
||||
static int ventoy_parse_plugin_config(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int i;
|
||||
char key[128];
|
||||
VTOY_JSON *cur = json;
|
||||
VTOY_JSON *cur = NULL;
|
||||
|
||||
grub_snprintf(g_iso_disk_name, sizeof(g_iso_disk_name), "%s", isodisk);
|
||||
|
||||
while (cur)
|
||||
for (cur = json; cur; cur = cur->pstNext)
|
||||
{
|
||||
for (i = 0; i < (int)ARRAY_SIZE(g_plugin_entries); i++)
|
||||
{
|
||||
grub_snprintf(key, sizeof(key), "%s_%s", g_plugin_entries[i].key, g_arch_mode_suffix);
|
||||
if (grub_strcmp(g_plugin_entries[i].key, cur->pcName) == 0 || grub_strcmp(key, cur->pcName) == 0)
|
||||
if (g_plugin_entries[i].flag == 0 && grub_strcmp(key, cur->pcName) == 0)
|
||||
{
|
||||
debug("Plugin entry for %s\n", g_plugin_entries[i].key);
|
||||
g_plugin_entries[i].entryfunc(cur, isodisk);
|
||||
g_plugin_entries[i].flag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cur = cur->pstNext;
|
||||
for (cur = json; cur; cur = cur->pstNext)
|
||||
{
|
||||
for (i = 0; i < (int)ARRAY_SIZE(g_plugin_entries); i++)
|
||||
{
|
||||
if (g_plugin_entries[i].flag == 0 && grub_strcmp(g_plugin_entries[i].key, cur->pcName) == 0)
|
||||
{
|
||||
debug("Plugin entry for %s\n", g_plugin_entries[i].key);
|
||||
g_plugin_entries[i].entryfunc(cur, isodisk);
|
||||
g_plugin_entries[i].flag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -2372,7 +2444,9 @@ static int ventoy_parse_plugin_config(VTOY_JSON *json, const char *isodisk)
|
||||
grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int ret = 0;
|
||||
int offset = 0;
|
||||
char *buf = NULL;
|
||||
grub_uint8_t *code = NULL;
|
||||
grub_file_t file;
|
||||
VTOY_JSON *json = NULL;
|
||||
|
||||
@@ -2409,9 +2483,25 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
code = (grub_uint8_t *)buf;
|
||||
if (code[0] == 0xef && code[1] == 0xbb && code[2] == 0xbf)
|
||||
{
|
||||
offset = 3; /* Skip UTF-8 BOM */
|
||||
}
|
||||
else if ((code[0] == 0xff && code[1] == 0xfe) || (code[0] == 0xfe && code[1] == 0xff))
|
||||
{
|
||||
grub_env_set("VTOY_PLUGIN_SYNTAX_ERROR", "1");
|
||||
grub_env_export("VTOY_PLUGIN_SYNTAX_ERROR");
|
||||
|
||||
ret = vtoy_json_parse(json, buf);
|
||||
grub_env_set("VTOY_PLUGIN_ENCODE_ERROR", "1");
|
||||
grub_env_export("VTOY_PLUGIN_ENCODE_ERROR");
|
||||
|
||||
debug("Failed to parse json string %d\n", ret);
|
||||
grub_free(buf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = vtoy_json_parse(json, buf + offset);
|
||||
if (ret)
|
||||
{
|
||||
grub_env_set("VTOY_PLUGIN_SYNTAX_ERROR", "1");
|
||||
@@ -2709,7 +2799,7 @@ const char * ventoy_plugin_get_menu_alias(int type, const char *isopath)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const menu_tip * ventoy_plugin_get_menu_tip(const char *isopath)
|
||||
const menu_tip * ventoy_plugin_get_menu_tip(int type, const char *isopath)
|
||||
{
|
||||
int len;
|
||||
menu_tip *node = NULL;
|
||||
@@ -2722,7 +2812,8 @@ const menu_tip * ventoy_plugin_get_menu_tip(const char *isopath)
|
||||
len = (int)grub_strlen(isopath);
|
||||
for (node = g_menu_tip_head; node; node = node->next)
|
||||
{
|
||||
if (node->pathlen == len && ventoy_strcmp(node->isopath, isopath) == 0)
|
||||
if (node->type == type && node->pathlen &&
|
||||
node->pathlen == len && ventoy_strcmp(node->isopath, isopath) == 0)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
@@ -3157,7 +3248,7 @@ grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, ch
|
||||
grub_snprintf(key, sizeof(key), "%s_%s", args[1], g_arch_mode_suffix);
|
||||
for (node = json->pstChild; node; node = node->pstNext)
|
||||
{
|
||||
if (grub_strcmp(node->pcName, args[1]) == 0 || grub_strcmp(node->pcName, key) == 0)
|
||||
if (grub_strcmp(node->pcName, key) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -3165,8 +3256,19 @@ grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, ch
|
||||
|
||||
if (!node)
|
||||
{
|
||||
grub_printf("%s is NOT found in ventoy.json\n", args[1]);
|
||||
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++)
|
||||
@@ -3189,6 +3291,65 @@ end:
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_select_theme_cfg(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int pos = 0;
|
||||
int bufsize = 0;
|
||||
char *name = NULL;
|
||||
char *buf = NULL;
|
||||
theme_list *node = NULL;
|
||||
|
||||
(void)argc;
|
||||
(void)args;
|
||||
(void)ctxt;
|
||||
|
||||
if (g_theme_single_file[0])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (g_theme_num < 2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bufsize = (g_theme_num + 1) * 1024;
|
||||
buf = grub_malloc(bufsize);
|
||||
if (!buf)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (node = g_theme_head; node; node = node->next)
|
||||
{
|
||||
name = grub_strstr(node->theme.path, ")/");
|
||||
if (name)
|
||||
{
|
||||
name++;
|
||||
}
|
||||
else
|
||||
{
|
||||
name = node->theme.path;
|
||||
}
|
||||
|
||||
pos += grub_snprintf(buf + pos, bufsize - pos,
|
||||
"menuentry \"%s\" --class=debug_theme_item --class=debug_theme_select --class=F5tool {\n"
|
||||
"vt_set_theme_path \"%s\"\n"
|
||||
"}\n",
|
||||
name, node->theme.path);
|
||||
}
|
||||
|
||||
pos += grub_snprintf(buf + pos, bufsize - pos,
|
||||
"menuentry 'Return to previous menu [Esc]' --class=vtoyret VTOY_RET {\n"
|
||||
"echo 'Return ...'\n"
|
||||
"}\n");
|
||||
|
||||
grub_script_execute_sourcecode(buf);
|
||||
grub_free(buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_set_theme(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
grub_uint32_t i = 0;
|
||||
@@ -3213,6 +3374,17 @@ grub_err_t ventoy_cmd_set_theme(grub_extcmd_context_t ctxt, int argc, char **arg
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (g_theme_id > 0 && g_theme_id <= g_theme_num)
|
||||
{
|
||||
for (i = 0; i < (grub_uint32_t)(g_theme_id - 1) && node; i++)
|
||||
{
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
grub_env_set("theme", node->theme.path);
|
||||
goto end;
|
||||
}
|
||||
|
||||
grub_memset(&datetime, 0, sizeof(datetime));
|
||||
grub_get_datetime(&datetime);
|
||||
@@ -3244,7 +3416,25 @@ grub_err_t ventoy_cmd_set_theme(grub_extcmd_context_t ctxt, int argc, char **arg
|
||||
grub_env_set("theme", node->theme.path);
|
||||
|
||||
end:
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
extern char g_ventoy_theme_path[256];
|
||||
grub_err_t ventoy_cmd_set_theme_path(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
(void)argc;
|
||||
(void)ctxt;
|
||||
|
||||
if (argc == 0)
|
||||
{
|
||||
g_ventoy_theme_path[0] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_snprintf(g_ventoy_theme_path, sizeof(g_ventoy_theme_path), "%s", args[0]);
|
||||
}
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
|
@@ -47,6 +47,11 @@ char *g_conf_new_data = NULL;
|
||||
int g_mod_new_len = 0;
|
||||
char *g_mod_new_data = NULL;
|
||||
|
||||
int g_mod_search_magic = 0;
|
||||
|
||||
int g_ko_fillmap_len = 0;
|
||||
char *g_ko_fillmap_data = NULL;
|
||||
|
||||
grub_uint64_t g_mod_override_offset = 0;
|
||||
grub_uint64_t g_conf_override_offset = 0;
|
||||
|
||||
@@ -82,6 +87,15 @@ static grub_uint32_t ventoy_unix_get_override_chunk_count(void)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
if (g_ko_fillmap_len > 0)
|
||||
{
|
||||
count += (g_ko_fillmap_len / 512);
|
||||
if ((g_ko_fillmap_len % 512) > 0)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
@@ -121,15 +135,50 @@ static grub_uint32_t ventoy_unix_get_virt_chunk_size(void)
|
||||
return size;
|
||||
}
|
||||
|
||||
static void ventoy_unix_fill_override_data( grub_uint64_t isosize, void *override)
|
||||
static void ventoy_unix_fill_map_data(ventoy_chain_head *chain, struct g_ventoy_map *map)
|
||||
{
|
||||
grub_uint32_t i;
|
||||
ventoy_img_chunk *chunk = NULL;
|
||||
|
||||
debug("Fill unix map data: <%llu> <%u> %p\n",
|
||||
(unsigned long long)chain->os_param.vtoy_disk_size, g_img_chunk_list.cur_chunk, map);
|
||||
|
||||
map->magic1[0] = map->magic2[0] = VENTOY_UNIX_SEG_MAGIC0;
|
||||
map->magic1[1] = map->magic2[1] = VENTOY_UNIX_SEG_MAGIC1;
|
||||
map->magic1[2] = map->magic2[2] = VENTOY_UNIX_SEG_MAGIC2;
|
||||
map->magic1[3] = map->magic2[3] = VENTOY_UNIX_SEG_MAGIC3;
|
||||
|
||||
map->disksize = chain->os_param.vtoy_disk_size;
|
||||
grub_memcpy(map->diskuuid, chain->os_param.vtoy_disk_guid, 16);
|
||||
|
||||
map->segnum = g_img_chunk_list.cur_chunk;
|
||||
if (g_img_chunk_list.cur_chunk > VENTOY_UNIX_MAX_SEGNUM)
|
||||
{
|
||||
debug("####[FAIL] Too many segments for the ISO file %u\n", g_img_chunk_list.cur_chunk);
|
||||
map->segnum = VENTOY_UNIX_MAX_SEGNUM;
|
||||
}
|
||||
|
||||
for (i = 0; i < (grub_uint32_t)(map->segnum); i++)
|
||||
{
|
||||
chunk = g_img_chunk_list.chunk + i;
|
||||
map->seglist[i].seg_start_bytes = chunk->disk_start_sector * 512ULL;
|
||||
map->seglist[i].seg_end_bytes = (chunk->disk_end_sector + 1) * 512ULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void ventoy_unix_fill_override_data( grub_uint64_t isosize, ventoy_chain_head *chain)
|
||||
{
|
||||
int i;
|
||||
int left;
|
||||
char *data = NULL;
|
||||
grub_uint64_t offset;
|
||||
grub_uint64_t sector;
|
||||
ventoy_override_chunk *cur;
|
||||
ventoy_iso9660_override *dirent;
|
||||
|
||||
sector = (isosize + 2047) / 2048;
|
||||
|
||||
cur = (ventoy_override_chunk *)override;
|
||||
cur = (ventoy_override_chunk *)((char *)chain + chain->override_chunk_offset);
|
||||
|
||||
if (g_conf_new_len > 0)
|
||||
{
|
||||
@@ -142,12 +191,12 @@ static void ventoy_unix_fill_override_data( grub_uint64_t isosize, void *over
|
||||
dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector);
|
||||
dirent->size_be = grub_swap_bytes32(dirent->size);
|
||||
sector += (dirent->size + 2047) / 2048;
|
||||
cur++;
|
||||
}
|
||||
|
||||
if (g_mod_new_len > 0)
|
||||
{
|
||||
/* mod.ko */
|
||||
cur++;
|
||||
cur->img_offset = g_mod_override_offset;
|
||||
cur->override_size = sizeof(ventoy_iso9660_override);
|
||||
dirent = (ventoy_iso9660_override *)cur->override_data;
|
||||
@@ -156,6 +205,37 @@ static void ventoy_unix_fill_override_data( grub_uint64_t isosize, void *over
|
||||
dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector);
|
||||
dirent->size_be = grub_swap_bytes32(dirent->size);
|
||||
sector += (dirent->size + 2047) / 2048;
|
||||
cur++;
|
||||
}
|
||||
|
||||
if (g_ko_fillmap_len > 0)
|
||||
{
|
||||
data = g_ko_fillmap_data;
|
||||
offset = g_mod_override_offset;
|
||||
|
||||
ventoy_unix_fill_map_data(chain, (struct g_ventoy_map *)data);
|
||||
|
||||
for (i = 0; i < g_ko_fillmap_len / 512; i++)
|
||||
{
|
||||
cur->img_offset = offset;
|
||||
cur->override_size = 512;
|
||||
grub_memcpy(cur->override_data, data, 512);
|
||||
|
||||
offset += 512;
|
||||
data += 512;
|
||||
cur++;
|
||||
}
|
||||
|
||||
left = (g_ko_fillmap_len % 512);
|
||||
if (left > 0)
|
||||
{
|
||||
cur->img_offset = offset;
|
||||
cur->override_size = left;
|
||||
grub_memcpy(cur->override_data, data, left);
|
||||
|
||||
offset += left;
|
||||
cur++;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -182,6 +262,11 @@ static void ventoy_unix_fill_virt_data( grub_uint64_t isosize, ventoy_chain_h
|
||||
|
||||
if (g_mod_new_len > 0)
|
||||
{
|
||||
if (g_mod_search_magic > 0)
|
||||
{
|
||||
ventoy_unix_fill_map_data(chain, (struct g_ventoy_map *)(g_mod_new_data + g_mod_search_magic));
|
||||
}
|
||||
|
||||
ventoy_unix_fill_virt(g_mod_new_data, g_mod_new_len);
|
||||
}
|
||||
|
||||
@@ -210,6 +295,12 @@ static int ventoy_freebsd_append_conf(char *buf, const char *isopath)
|
||||
vtoy_ssprintf(buf, pos, "ventoy_load=\"%s\"\n", "YES");
|
||||
vtoy_ssprintf(buf, pos, "ventoy_name=\"%s\"\n", g_ko_mod_path);
|
||||
|
||||
if (g_mod_search_magic)
|
||||
{
|
||||
debug("hint.ventoy NO need\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
disk = isofile->device->disk;
|
||||
|
||||
ventoy_get_disk_guid(isofile->name, disk_guid, disk_sig);
|
||||
@@ -232,8 +323,8 @@ static int ventoy_freebsd_append_conf(char *buf, const char *isopath)
|
||||
(ulonglong)((chunk->disk_end_sector + 1) * 512));
|
||||
}
|
||||
|
||||
out:
|
||||
grub_file_close(isofile);
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
@@ -258,13 +349,16 @@ grub_err_t ventoy_cmd_unix_reset(grub_extcmd_context_t ctxt, int argc, char **ar
|
||||
(void)argc;
|
||||
(void)args;
|
||||
|
||||
g_mod_search_magic = 0;
|
||||
g_conf_new_len = 0;
|
||||
g_mod_new_len = 0;
|
||||
g_mod_override_offset = 0;
|
||||
g_conf_override_offset = 0;
|
||||
g_ko_fillmap_len = 0;
|
||||
|
||||
check_free(g_mod_new_data, grub_free);
|
||||
check_free(g_conf_new_data, grub_free);
|
||||
check_free(g_ko_fillmap_data, grub_free);
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
@@ -624,6 +718,27 @@ grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, ch
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
static int ventoy_unix_search_magic(char *data, int len)
|
||||
{
|
||||
int i;
|
||||
grub_uint32_t *magic = NULL;
|
||||
|
||||
for (i = 0; i < len; i += 65536)
|
||||
{
|
||||
magic = (grub_uint32_t *)(data + i);
|
||||
if (magic[0] == VENTOY_UNIX_SEG_MAGIC0 && magic[1] == VENTOY_UNIX_SEG_MAGIC1 &&
|
||||
magic[2] == VENTOY_UNIX_SEG_MAGIC2 && magic[3] == VENTOY_UNIX_SEG_MAGIC3)
|
||||
{
|
||||
debug("unix find search magic at 0x%x loop:%d\n", i, (i >> 16));
|
||||
g_mod_search_magic = i;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
debug("unix can not find search magic\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_unix_replace_ko(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
char *data;
|
||||
@@ -673,10 +788,73 @@ grub_err_t ventoy_cmd_unix_replace_ko(grub_extcmd_context_t ctxt, int argc, char
|
||||
|
||||
g_mod_new_data = data;
|
||||
g_mod_new_len = (int)file->size;
|
||||
|
||||
ventoy_unix_search_magic(g_mod_new_data, g_mod_new_len);
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_unix_ko_fillmap(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int i;
|
||||
grub_file_t file;
|
||||
grub_uint32_t magic[4];
|
||||
grub_uint32_t len;
|
||||
|
||||
(void)ctxt;
|
||||
|
||||
if (argc != 1)
|
||||
{
|
||||
debug("Fillmap ko invalid argc %d\n", argc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
debug("Fillmap ko %s\n", args[0]);
|
||||
|
||||
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "(loop)%s", args[0]);
|
||||
if (file)
|
||||
{
|
||||
grub_file_read(file, magic, 4); /* read for trigger */
|
||||
g_mod_override_offset = grub_iso9660_get_last_read_pos(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
debug("Can't find replace ko file from %s\n", args[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < (int)(file->size); i += 65536)
|
||||
{
|
||||
magic[0] = 0;
|
||||
grub_file_seek(file, i);
|
||||
grub_file_read(file, magic, sizeof(magic));
|
||||
|
||||
if (magic[0] == VENTOY_UNIX_SEG_MAGIC0 && magic[1] == VENTOY_UNIX_SEG_MAGIC1 &&
|
||||
magic[2] == VENTOY_UNIX_SEG_MAGIC2 && magic[3] == VENTOY_UNIX_SEG_MAGIC3)
|
||||
{
|
||||
debug("unix find search magic at 0x%x loop:%d\n", i, (i >> 16));
|
||||
g_mod_override_offset += i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
len = (grub_uint32_t)OFFSET_OF(struct g_ventoy_map, seglist) +
|
||||
(sizeof(struct g_ventoy_seg) * g_img_chunk_list.cur_chunk);
|
||||
|
||||
g_ko_fillmap_len = (int)len;
|
||||
g_ko_fillmap_data = grub_malloc(len);
|
||||
if (!g_ko_fillmap_data)
|
||||
{
|
||||
g_ko_fillmap_len = 0;
|
||||
debug("Failed to malloc fillmap data\n");
|
||||
}
|
||||
|
||||
debug("Fillmap ko segnum:%u, override len:%u data:%p\n", g_img_chunk_list.cur_chunk, len, g_ko_fillmap_data);
|
||||
|
||||
grub_file_close(file);
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_unix_fill_image_desc(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int i;
|
||||
@@ -908,7 +1086,7 @@ grub_err_t ventoy_cmd_unix_chain_data(grub_extcmd_context_t ctxt, int argc, char
|
||||
/* part 4: override chunk */
|
||||
chain->override_chunk_offset = chain->img_chunk_offset + img_chunk_size;
|
||||
chain->override_chunk_num = override_count;
|
||||
ventoy_unix_fill_override_data(isosize, (char *)chain + chain->override_chunk_offset);
|
||||
ventoy_unix_fill_override_data(isosize, chain);
|
||||
|
||||
/* part 5: virt chunk */
|
||||
chain->virt_chunk_offset = chain->override_chunk_offset + override_size;
|
||||
|
@@ -242,6 +242,7 @@ typedef struct ventoy_img_chunk_list
|
||||
#pragma pack(1)
|
||||
|
||||
#define GRUB_FILE_REPLACE_MAGIC 0x1258BEEF
|
||||
#define GRUB_IMG_REPLACE_MAGIC 0x1259BEEF
|
||||
|
||||
typedef const char * (*grub_env_get_pf)(const char *name);
|
||||
typedef int (*grub_env_set_pf)(const char *name, const char *val);
|
||||
@@ -260,6 +261,7 @@ typedef struct ventoy_grub_param
|
||||
grub_env_get_pf grub_env_get;
|
||||
grub_env_set_pf grub_env_set;
|
||||
ventoy_grub_param_file_replace file_replace;
|
||||
ventoy_grub_param_file_replace img_replace;
|
||||
grub_env_printf_pf grub_env_printf;
|
||||
}ventoy_grub_param;
|
||||
|
||||
|
@@ -29,13 +29,21 @@ for i in 0 1 2 3 4 5 6 7 8 9; do
|
||||
fi
|
||||
done
|
||||
|
||||
ventoy_extract_vtloopex ${vtdiskname}2 crux
|
||||
# no need since 3.6.1
|
||||
$BUSYBOX_PATH/modprobe dax > /dev/null 2>&1
|
||||
$BUSYBOX_PATH/modprobe dm-mod > /dev/null 2>&1
|
||||
|
||||
if $GREP -q 'device-mapper' /proc/devices; then
|
||||
vtlog "dm-mod module check success ..."
|
||||
else
|
||||
vtlog "Need to load dm-mod module ..."
|
||||
ventoy_extract_vtloopex ${vtdiskname}2 crux
|
||||
|
||||
vtKver=$(uname -r)
|
||||
vtLoopExDir=$VTOY_PATH/vtloopex/crux/vtloopex
|
||||
vtKver=$(uname -r)
|
||||
vtLoopExDir=$VTOY_PATH/vtloopex/crux/vtloopex
|
||||
|
||||
ventoy_check_install_module_xz $vtLoopExDir/dm-mod/$vtKver/64/dax.ko
|
||||
ventoy_check_install_module_xz $vtLoopExDir/dm-mod/$vtKver/64/dm-mod.ko
|
||||
ventoy_check_install_module_xz $vtLoopExDir/dm-mod/$vtKver/64/dax.ko
|
||||
ventoy_check_install_module_xz $vtLoopExDir/dm-mod/$vtKver/64/dm-mod.ko
|
||||
fi
|
||||
|
||||
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2"
|
||||
|
82
IMG/cpio/ventoy/hook/debian/minios-disk.sh
Normal file
82
IMG/cpio/ventoy/hook/debian/minios-disk.sh
Normal file
@@ -0,0 +1,82 @@
|
||||
#!/ventoy/busybox/sh
|
||||
#************************************************************************************
|
||||
# Copyright (c) 2020, longpanda <admin@ventoy.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
. /ventoy/hook/ventoy-hook-lib.sh
|
||||
|
||||
vtlog "####### $0 $* ########"
|
||||
|
||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||
|
||||
|
||||
ventoy_os_install_dmsetup_by_fuse() {
|
||||
vtlog "ventoy_os_install_dmsetup_by_fuse $*"
|
||||
|
||||
mkdir -p $VTOY_PATH/mnt/fuse $VTOY_PATH/mnt/iso $VTOY_PATH/mnt/squashfs
|
||||
|
||||
vtoydm -p -f $VTOY_PATH/ventoy_image_map -d $1 > $VTOY_PATH/ventoy_dm_table
|
||||
vtoy_fuse_iso -f $VTOY_PATH/ventoy_dm_table -m $VTOY_PATH/mnt/fuse
|
||||
|
||||
mount -t iso9660 $VTOY_PATH/mnt/fuse/ventoy.iso $VTOY_PATH/mnt/iso
|
||||
mount -t squashfs $VTOY_PATH/mnt/iso/minios/01-core*.sb $VTOY_PATH/mnt/squashfs
|
||||
|
||||
KoName=$(ls $VTOY_PATH/mnt/squashfs/lib/modules/$2/kernel/drivers/md/dm-mod.ko*)
|
||||
vtlog "insmod $KoName"
|
||||
insmod $KoName
|
||||
|
||||
umount $VTOY_PATH/mnt/squashfs
|
||||
umount $VTOY_PATH/mnt/iso
|
||||
umount $VTOY_PATH/mnt/fuse
|
||||
}
|
||||
|
||||
|
||||
ventoy_os_install_dmsetup() {
|
||||
vtlog "ventoy_os_install_dmsetup"
|
||||
|
||||
if grep -q 'device-mapper' /proc/devices; then
|
||||
vtlog "device-mapper module already loaded"
|
||||
return;
|
||||
fi
|
||||
|
||||
vtKerVer=$(uname -r)
|
||||
|
||||
if modprobe fuse 2>>$VTLOG; then
|
||||
ventoy_os_install_dmsetup_by_fuse $1 $vtKerVer
|
||||
fi
|
||||
}
|
||||
|
||||
vtdiskname=$(get_ventoy_disk_name)
|
||||
if [ "$vtdiskname" = "unknown" ]; then
|
||||
vtlog "ventoy disk not found"
|
||||
PATH=$VTPATH_OLD
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if check_usb_disk_ready "$vtdiskname"; then
|
||||
vtlog "check_usb_disk_ready ok"
|
||||
else
|
||||
vtlog "check_usb_disk_ready error"
|
||||
PATH=$VTPATH_OLD
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ventoy_os_install_dmsetup $vtdiskname
|
||||
|
||||
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
|
||||
|
||||
PATH=$VTPATH_OLD
|
24
IMG/cpio/ventoy/hook/debian/minios-hook.sh
Normal file
24
IMG/cpio/ventoy/hook/debian/minios-hook.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/ventoy/busybox/sh
|
||||
#************************************************************************************
|
||||
# Copyright (c) 2020, longpanda <admin@ventoy.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
if [ -f /lib/livekitlib ] && $GREP -q 'debug_log.*find_data_try' /lib/livekitlib; then
|
||||
$SED "/debug_log.*find_data_try/a\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/minios-disk.sh" -i /lib/livekitlib
|
||||
else
|
||||
$SED "/find_data/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/minios-disk.sh" -i /init
|
||||
fi
|
@@ -47,8 +47,29 @@ ventoy_os_install_dmsetup_by_fuse() {
|
||||
umount $VTOY_PATH/mnt/fuse
|
||||
}
|
||||
|
||||
|
||||
wait_for_usb_disk_ready
|
||||
while [ -n "Y" ]; do
|
||||
vtdiskname=$(get_ventoy_disk_name)
|
||||
if [ "$vtdiskname" = "unknown" ]; then
|
||||
vtlog "ventoy disk not found"
|
||||
if [ -r /proc/sys/kernel/hotplug ]; then
|
||||
echo /sbin/mdev > /proc/sys/kernel/hotplug
|
||||
fi
|
||||
mdev -s
|
||||
sleep 1
|
||||
else
|
||||
if check_usb_disk_ready "$vtdiskname"; then
|
||||
vtlog "check_usb_disk_ready $vtdiskname ok"
|
||||
break
|
||||
else
|
||||
vtlog "check_usb_disk_ready $vtdiskname error"
|
||||
if [ -r /proc/sys/kernel/hotplug ]; then
|
||||
echo /sbin/mdev > /proc/sys/kernel/hotplug
|
||||
fi
|
||||
mdev -s
|
||||
sleep 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
vtdiskname=$(get_ventoy_disk_name)
|
||||
if [ "$vtdiskname" = "unknown" ]; then
|
||||
|
@@ -56,6 +56,10 @@ ventoy_get_debian_distro() {
|
||||
echo 'slax'; return
|
||||
fi
|
||||
|
||||
if $GREP -q 'minios/' /proc/cmdline; then
|
||||
echo 'minios'; return
|
||||
fi
|
||||
|
||||
if $GREP -q 'PVE ' /proc/version; then
|
||||
echo 'pve'; return
|
||||
fi
|
||||
|
BIN
IMG/vtloopex/LibreELEC/vtloopex/dm-mod/5.10.76/64/dm-mod.ko.xz
Normal file
BIN
IMG/vtloopex/LibreELEC/vtloopex/dm-mod/5.10.76/64/dm-mod.ko.xz
Normal file
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
size=1024
|
||||
fstype=ext4
|
||||
@@ -7,13 +7,14 @@ config=''
|
||||
outputfile=persistence.dat
|
||||
|
||||
print_usage() {
|
||||
echo 'Usage: CreatePersistentImg.sh [ -s size ] [ -t fstype ] [ -l LABEL ] [ -c CFG ]'
|
||||
echo 'Usage: sudo ./CreatePersistentImg.sh [ -s size ] [ -t fstype ] [ -l LABEL ] [ -c CFG ] [ -e ]'
|
||||
echo ' OPTION: (optional)'
|
||||
echo ' -s size in MB, default is 1024'
|
||||
echo ' -t filesystem type, default is ext4 ext2/ext3/ext4/xfs are supported now'
|
||||
echo ' -l label, default is casper-rw'
|
||||
echo ' -c configfile name inside the persistence file. File content is "/ union"'
|
||||
echo ' -o outputfile name, default is persistence.dat'
|
||||
echo ' -e enable encryption, disabled by default (only few distros support this)'
|
||||
echo ''
|
||||
}
|
||||
|
||||
@@ -33,6 +34,9 @@ while [ -n "$1" ]; do
|
||||
elif [ "$1" = "-o" ]; then
|
||||
shift
|
||||
outputfile=$1
|
||||
elif [ "$1" = "-e" ]; then
|
||||
read -s -p "Encryption passphrase: " passphrase
|
||||
echo
|
||||
elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
||||
print_usage
|
||||
exit 0
|
||||
@@ -86,6 +90,13 @@ freeloop=$(losetup -f)
|
||||
|
||||
losetup $freeloop "$outputfile"
|
||||
|
||||
if [ ! -z "$passphrase" ]; then
|
||||
printf "$passphrase" | cryptsetup -q --verbose luksFormat $freeloop -
|
||||
printf "$passphrase" | cryptsetup -q --verbose luksOpen $freeloop persist_decrypted -
|
||||
_freeloop=$freeloop
|
||||
freeloop="/dev/mapper/persist_decrypted"
|
||||
fi
|
||||
|
||||
mkfs -t $fstype $fsopt -L $label $freeloop
|
||||
|
||||
sync
|
||||
@@ -104,4 +115,9 @@ if [ -n "$config" ]; then
|
||||
rm -rf ./persist_tmp_mnt
|
||||
fi
|
||||
|
||||
if [ ! -z "$passphrase" ]; then
|
||||
cryptsetup luksClose $freeloop
|
||||
freeloop=$_freeloop
|
||||
fi
|
||||
|
||||
losetup -d $freeloop
|
||||
|
12
INSTALL/FOR_X64_ARM.txt
Normal file
12
INSTALL/FOR_X64_ARM.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
============ Ventoy2Disk.exe for x86_64/ARM/ARM64 =================
|
||||
Ventoy2Disk.exe is a x86_32 application and supports both 32-bit and 64-bit Windows PC with intel/amd processor.
|
||||
Since 1.0.58, Ventoy also provides Ventoy2Disk_X64.exe/Ventoy2Disk_ARM.exe/Ventoy2Disk_ARM64.exe you can use them if needed.
|
||||
These exe files are in altexe directory of the installation package.
|
||||
You must copy them to the upper directory to use them. (The same location with Ventoy2Disk.exe)
|
||||
|
||||
|
||||
============ x86_64/ARM/ARM64 版本 Ventoy2Disk.exe =================
|
||||
默认的 Ventoy2Disk.exe 是32位x86程序,同时支持最常见的32位和64位Windows系统,绝大部分情况下使用它就可以。
|
||||
从1.0.58版本开始,Ventoy还同时提供了 Ventoy2Disk_X64.exe/Ventoy2Disk_ARM.exe/Ventoy2Disk_ARM64.exe 可以根据需要使用。
|
||||
这些文件位于安装包内的altexe目录下,使用时需要将其拷贝到上一层目录(即和 Ventoy2Disk.exe 同一位置)。
|
||||
|
@@ -22,6 +22,11 @@ Please refer https://www.ventoy.net/en/doc_start.html for details.
|
||||
2. open your browser and visit http://127.0.0.1:24680
|
||||
|
||||
|
||||
========== VentoyPlugson.sh ===============
|
||||
1. sudo sh VentoyPlugson.sh
|
||||
2. open your browser and visit http://127.0.0.1:24681
|
||||
|
||||
|
||||
========= VentoyGUI ===================
|
||||
VentoyGUI is native GUI program for Linux (GTK/QT)
|
||||
1. Just double-click the file (e.g. VentoyGUI.x86_64)
|
||||
|
Binary file not shown.
@@ -46,23 +46,25 @@ echo "############# Ventoy2Disk $* [$TOOLDIR] ################" >> ./log.txt
|
||||
date >> ./log.txt
|
||||
|
||||
#decompress tool
|
||||
if [ -f ./tool/$TOOLDIR/ash ]; then
|
||||
echo "no need to decompress tools" >> ./log.txt
|
||||
else
|
||||
cd ./tool/$TOOLDIR
|
||||
|
||||
echo "decompress tools" >> ./log.txt
|
||||
cd ./tool/$TOOLDIR
|
||||
|
||||
ls *.xz > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
[ -f ./xzcat ] && chmod +x ./xzcat
|
||||
|
||||
|
||||
for file in $(ls *.xz); do
|
||||
echo "decompress $file" >> ./log.txt
|
||||
xzcat $file > ${file%.xz}
|
||||
[ -f ./${file%.xz} ] && chmod +x ./${file%.xz}
|
||||
[ -f ./$file ] && rm -f ./$file
|
||||
done
|
||||
cd ../../
|
||||
|
||||
chmod +x -R ./tool/$TOOLDIR
|
||||
fi
|
||||
|
||||
cd ../../
|
||||
chmod +x -R ./tool/$TOOLDIR
|
||||
|
||||
|
||||
if [ -f /bin/bash ]; then
|
||||
/bin/bash ./tool/VentoyWorker.sh $*
|
||||
else
|
||||
|
BIN
INSTALL/Ventoy2Disk_ARM.exe
Normal file
BIN
INSTALL/Ventoy2Disk_ARM.exe
Normal file
Binary file not shown.
BIN
INSTALL/Ventoy2Disk_ARM64.exe
Normal file
BIN
INSTALL/Ventoy2Disk_ARM64.exe
Normal file
Binary file not shown.
BIN
INSTALL/Ventoy2Disk_X64.exe
Normal file
BIN
INSTALL/Ventoy2Disk_X64.exe
Normal file
Binary file not shown.
218
INSTALL/VentoyPlugson.sh
Normal file
218
INSTALL/VentoyPlugson.sh
Normal file
@@ -0,0 +1,218 @@
|
||||
#!/bin/sh
|
||||
|
||||
. ./tool/ventoy_lib.sh
|
||||
|
||||
print_usage() {
|
||||
echo 'Usage: sudo sh VentoyPlugson.sh [OPTION] /dev/sdX'
|
||||
echo ' OPTION: (optional)'
|
||||
echo ' -H x.x.x.x http server IP address (default is 127.0.0.1)'
|
||||
echo ' -P PORT http server PORT (default is 24681)'
|
||||
echo ' -h print this help'
|
||||
echo ''
|
||||
}
|
||||
|
||||
uid=$(id -u)
|
||||
if [ $uid -ne 0 ]; then
|
||||
echo "Please use sudo or run the script as root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
OLDDIR=$(pwd)
|
||||
|
||||
machine=$(uname -m)
|
||||
if echo $machine | egrep -q 'aarch64|arm64'; then
|
||||
TOOLDIR=aarch64
|
||||
elif echo $machine | egrep -q 'x86_64|amd64'; then
|
||||
TOOLDIR=x86_64
|
||||
elif echo $machine | egrep -q 'mips64'; then
|
||||
TOOLDIR=mips64el
|
||||
elif echo $machine | egrep -q 'i[3-6]86'; then
|
||||
TOOLDIR=i386
|
||||
else
|
||||
echo "Unsupported machine type $machine"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if ! [ -f "$OLDDIR/tool/plugson.tar.xz" ]; then
|
||||
echo "Please run under the correct directory!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "############# VentoyPlugson $* [$TOOLDIR] ################" >> ./VentoyPlugson.log
|
||||
date >> ./VentoyPlugson.log
|
||||
|
||||
echo "decompress tools" >> ./VentoyPlugson.log
|
||||
cd ./tool/$TOOLDIR
|
||||
|
||||
ls *.xz > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
[ -f ./xzcat ] && chmod +x ./xzcat
|
||||
|
||||
for file in $(ls *.xz); do
|
||||
echo "decompress $file" >> ./VentoyPlugson.log
|
||||
xzcat $file > ${file%.xz}
|
||||
[ -f ./${file%.xz} ] && chmod +x ./${file%.xz}
|
||||
[ -f ./$file ] && rm -f ./$file
|
||||
done
|
||||
fi
|
||||
|
||||
cd ../../
|
||||
chmod +x -R ./tool/$TOOLDIR
|
||||
|
||||
if ! [ -f "$OLDDIR/tool/$TOOLDIR/Plugson" ]; then
|
||||
echo "$OLDDIR/tool/$TOOLDIR/Plugson does not exist!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
PATH=./tool/$TOOLDIR:$PATH
|
||||
|
||||
HOST="127.0.0.1"
|
||||
PORT=24681
|
||||
|
||||
while [ -n "$1" ]; do
|
||||
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
||||
print_usage
|
||||
exit 0
|
||||
elif [ "$1" = "-H" ]; then
|
||||
shift
|
||||
if echo $1 | grep -q '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'; then
|
||||
HOST="$1"
|
||||
else
|
||||
echo "Invalid host $1"
|
||||
exit 1
|
||||
fi
|
||||
elif [ "$1" = "-P" ]; then
|
||||
shift
|
||||
if [ $1 -gt 0 -a $1 -le 65535 ]; then
|
||||
PORT="$1"
|
||||
else
|
||||
echo "Invalid port $1"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
DISK=$1
|
||||
fi
|
||||
|
||||
shift
|
||||
done
|
||||
|
||||
if [ -z "$DISK" ]; then
|
||||
print_usage
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if ps -ef | grep "tool/$TOOLDIR/Plugson.*$HOST.*$PORT" | grep -q -v grep; then
|
||||
echo "Another ventoy server is running now, please close it first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if echo $DISK | grep -q "[a-z]d[a-z][1-9]"; then
|
||||
DISK=${DISK:0:-1}
|
||||
fi
|
||||
|
||||
if echo $DISK | egrep -q "/dev/nvme|/dev/mmcblk/dev/nbd"; then
|
||||
if echo $DISK | grep -q "p[1-9]$"; then
|
||||
DISK=${DISK:0:-2}
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -b "$DISK" ]; then
|
||||
echo "$DISK does NOT exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
version=$(get_disk_ventoy_version $DISK)
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Ventoy version in Disk: $version"
|
||||
|
||||
vtPart1Type=$(dd if=$DISK bs=1 count=1 skip=450 status=none | hexdump -n1 -e '1/1 "%02X"')
|
||||
if [ "$vtPart1Type" = "EE" ]; then
|
||||
echo "Disk Partition Style : GPT"
|
||||
partstyle=1
|
||||
else
|
||||
echo "Disk Partition Style : MBR"
|
||||
partstyle=0
|
||||
fi
|
||||
|
||||
if check_disk_secure_boot $DISK; then
|
||||
echo "Secure Boot Support : YES"
|
||||
secureboot=1
|
||||
else
|
||||
echo "Secure Boot Support : NO"
|
||||
secureboot=0
|
||||
fi
|
||||
else
|
||||
echo "$DISK is NOT Ventoy disk."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PART1=$(get_disk_part_name $DISK 1)
|
||||
|
||||
if grep -q "^$PART1 " /proc/mounts; then
|
||||
mtpnt=$(grep "^$PART1 " /proc/mounts | awk '{print $2}')
|
||||
fstype=$(grep "^$PART1 " /proc/mounts | awk '{print $3}')
|
||||
|
||||
if echo $fstype | grep -q -i 'fuse'; then
|
||||
if hexdump -C -n 16 $PART1 | grep -q -i "EXFAT"; then
|
||||
fstype="exFAT"
|
||||
elif hexdump -C -n 16 $PART1 | grep -q -i "NTFS"; then
|
||||
fstype="NTFS"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$PART1 is mounted at $mtpnt $fstype"
|
||||
else
|
||||
echo "$PART1 is NOT mounted, please mount it first!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -d "$mtpnt/ventoy" ]; then
|
||||
echo "ventoy directory exist OK"
|
||||
else
|
||||
echo "create ventoy directory"
|
||||
mkdir -p "$mtpnt/ventoy"
|
||||
if [ -d "$mtpnt/ventoy" ]; then
|
||||
chmod -R 0755 "$mtpnt/ventoy"
|
||||
else
|
||||
echo "Failed to create directory $mtpnt/ventoy"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
#change current directory to Ventoy disk
|
||||
cd "$mtpnt"
|
||||
$OLDDIR/tool/$TOOLDIR/Plugson "$HOST" "$PORT" "$OLDDIR" "$DISK" $version "$fstype" $partstyle $secureboot &
|
||||
wID=$!
|
||||
sleep 1
|
||||
|
||||
if [ -f /proc/$wID/maps ]; then
|
||||
echo ""
|
||||
echo "==============================================================="
|
||||
if [ "$LANG" = "zh_CN.UTF-8" ]; then
|
||||
echo " Ventoy Plugson Server 已经启动 ..."
|
||||
echo " 请打开浏览器,访问 http://${HOST}:${PORT}"
|
||||
else
|
||||
echo " Ventoy Plugson Server is running ..."
|
||||
echo " Please open your browser and visit http://${HOST}:${PORT}"
|
||||
fi
|
||||
echo "==============================================================="
|
||||
echo ""
|
||||
echo "################## Press Ctrl + C to exit #####################"
|
||||
echo ""
|
||||
|
||||
wait $wID
|
||||
fi
|
||||
|
||||
|
||||
if [ -n "$OLDDIR" ]; then
|
||||
CURDIR=$(pwd)
|
||||
if [ "$CURDIR" != "$OLDDIR" ]; then
|
||||
cd "$OLDDIR"
|
||||
fi
|
||||
fi
|
@@ -38,13 +38,10 @@ sh buildedk.sh >> $LOG 2>&1 || exit 1
|
||||
#cd $VTOY_PATH/VtoyTool
|
||||
#sh build.sh || exit 1
|
||||
|
||||
#cd $VTOY_PATH/vtoyfat/fat_io_lib
|
||||
#cd $VTOY_PATH/vtoycli/fat_io_lib
|
||||
#sh buildlib.sh
|
||||
|
||||
#cd $VTOY_PATH/vtoyfat
|
||||
#sh build.sh || exit 1
|
||||
|
||||
#cd $VTOY_PATH/vtoygpt
|
||||
#cd $VTOY_PATH/vtoycli
|
||||
#sh build.sh || exit 1
|
||||
|
||||
#cd $VTOY_PATH/FUSEISO
|
||||
|
@@ -1,30 +1,116 @@
|
||||
menuentry "Calculate md5sum" --class=checksum_md5 {
|
||||
md5sum "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}"
|
||||
|
||||
echo -e "\n\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
}
|
||||
|
||||
menuentry "Calculate sha1sum" --class=checksum_sha1 {
|
||||
sha1sum "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}"
|
||||
|
||||
echo -e "\n\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
}
|
||||
if [ -e "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}.md5" ]; then
|
||||
set default=0
|
||||
menuentry "Calculate and check md5sum" --class=checksum_md5 {
|
||||
md5sum "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}"
|
||||
|
||||
vt_1st_line "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}.md5" vtReadChecksum
|
||||
|
||||
if vt_str_casebegin "$vtReadChecksum" "$VT_LAST_CHECK_SUM"; then
|
||||
echo -e "\n\nCheck MD5 value with .md5 file. [ OK ]"
|
||||
else
|
||||
echo -e "\n\nCheck MD5 value with .md5 file. [ FAIL ]"
|
||||
echo "The MD5 value in .md5 file is:"
|
||||
echo "$vtReadChecksum"
|
||||
fi
|
||||
|
||||
echo -e "\n\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
}
|
||||
else
|
||||
menuentry "Calculate md5sum" --class=checksum_md5 {
|
||||
md5sum "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}"
|
||||
|
||||
echo -e "\n\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
}
|
||||
fi
|
||||
|
||||
menuentry "Calculate sha256sum" --class=checksum_sha256 {
|
||||
sha256sum "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}"
|
||||
|
||||
echo -e "\n\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
}
|
||||
if [ -e "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}.sha1" ]; then
|
||||
set default=1
|
||||
menuentry "Calculate and check sha1sum" --class=checksum_sha1 {
|
||||
sha1sum "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}"
|
||||
|
||||
vt_1st_line "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}.sha1" vtReadChecksum
|
||||
|
||||
if vt_str_casebegin "$vtReadChecksum" "$VT_LAST_CHECK_SUM"; then
|
||||
echo -e "\n\nCheck SHA1 value with .sha1 file. [ OK ]"
|
||||
else
|
||||
echo -e "\n\nCheck SHA1 value with .sha1 file. [ FAIL ]"
|
||||
echo "The SHA1 value in .sha1 file is:"
|
||||
echo "$vtReadChecksum"
|
||||
fi
|
||||
|
||||
echo -e "\n\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
}
|
||||
else
|
||||
menuentry "Calculate sha1sum" --class=checksum_sha1 {
|
||||
sha1sum "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}"
|
||||
|
||||
echo -e "\n\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
}
|
||||
fi
|
||||
|
||||
|
||||
|
||||
if [ -e "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}.sha256" ]; then
|
||||
set default=2
|
||||
menuentry "Calculate and check sha256sum" --class=checksum_sha256 {
|
||||
sha256sum "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}"
|
||||
|
||||
vt_1st_line "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}.sha256" vtReadChecksum
|
||||
|
||||
if vt_str_casebegin "$vtReadChecksum" "$VT_LAST_CHECK_SUM"; then
|
||||
echo -e "\n\nCheck SHA256 value with .sha256 file. [ OK ]"
|
||||
else
|
||||
echo -e "\n\nCheck SHA256 value with .sha256 file. [ FAIL ]"
|
||||
echo "The SHA256 value in .sha256 file is:"
|
||||
echo "$vtReadChecksum"
|
||||
fi
|
||||
|
||||
echo -e "\n\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
}
|
||||
else
|
||||
menuentry "Calculate sha256sum" --class=checksum_sha256 {
|
||||
sha256sum "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}"
|
||||
|
||||
echo -e "\n\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
}
|
||||
fi
|
||||
|
||||
|
||||
|
||||
if [ -e "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}.sha512" ]; then
|
||||
set default=3
|
||||
menuentry "Calculate and check sha512sum" --class=checksum_sha512{
|
||||
sha512sum "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}"
|
||||
|
||||
vt_1st_line "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}.sha512" vtReadChecksum
|
||||
|
||||
if vt_str_casebegin "$vtReadChecksum" "$VT_LAST_CHECK_SUM"; then
|
||||
echo -e "\n\nCheck SHA512 value with .sha512 file. [ OK ]"
|
||||
else
|
||||
echo -e "\n\nCheck SHA512 value with .sha512 file. [ FAIL ]"
|
||||
echo "The SHA512 value in .sha512 file is:"
|
||||
echo "$vtReadChecksum"
|
||||
fi
|
||||
|
||||
echo -e "\n\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
}
|
||||
else
|
||||
menuentry "Calculate sha512sum" --class=checksum_sha512{
|
||||
sha512sum "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}"
|
||||
|
||||
echo -e "\n\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
}
|
||||
fi
|
||||
|
||||
menuentry "Calculate sha512sum" --class=checksum_sha512{
|
||||
sha512sum "${vtoy_iso_part}${VTOY_CHKSUM_FILE_PATH}"
|
||||
|
||||
echo -e "\n\npress ENTER to exit ..."
|
||||
read vtInputKey
|
||||
}
|
||||
|
||||
menuentry 'Return to previous menu [Esc]' --class=vtoyret VTOY_RET {
|
||||
echo 'Return ...'
|
||||
|
@@ -38,6 +38,12 @@ submenu "Screen Display Mode" --class=debug_screen_mode --class=F5tool {
|
||||
}
|
||||
}
|
||||
|
||||
if [ $VTOY_THEME_COUNT -gt 1 ]; then
|
||||
submenu "Theme Select" --class=debug_theme_select --class=F5tool {
|
||||
vt_select_theme_cfg
|
||||
}
|
||||
fi
|
||||
|
||||
if [ "$grub_platform" != "pc" ]; then
|
||||
submenu 'Ventoy UEFI Utilities' --class=debug_util --class=F5tool {
|
||||
menuentry 'Show EFI Drivers' --class=debug_util_efidrv --class=debug_util --class=F5tool {
|
||||
|
@@ -129,6 +129,9 @@ function get_os_type {
|
||||
elif [ -e (loop)/bin/freebsd-version ]; then
|
||||
set vtoy_os=Unix
|
||||
set vt_unix_type=FreeBSD
|
||||
elif [ -e (loop)/boot/kernel/geom_ventoy.ko ]; then
|
||||
set vtoy_os=Unix
|
||||
set vt_unix_type=FreeBSD
|
||||
elif vt_str_begin "$vt_system_id" "DragonFly"; then
|
||||
set vtoy_os=Unix
|
||||
set vt_unix_type=DragonFly
|
||||
@@ -154,9 +157,7 @@ function vt_check_compatible_pe {
|
||||
#Check for PE without external tools
|
||||
#set compatible if ISO file is less than 80MB
|
||||
if [ $vt_chosen_size -gt 33554432 -a $vt_chosen_size -le 83886080 ]; then
|
||||
set ventoy_compatible=YES
|
||||
elif [ -e $1/WEPE/WEPE.INI ]; then
|
||||
set ventoy_compatible=YES
|
||||
set ventoy_compatible=YES
|
||||
fi
|
||||
|
||||
return
|
||||
@@ -165,6 +166,8 @@ function vt_check_compatible_pe {
|
||||
function vt_check_compatible_linux {
|
||||
if vt_str_begin "$vt_volume_id" "embootkit"; then
|
||||
set ventoy_compatible=YES
|
||||
elif [ -e "$1/casper/tinycore.gz" ]; then
|
||||
set ventoy_compatible=YES
|
||||
fi
|
||||
|
||||
return
|
||||
@@ -233,6 +236,8 @@ function distro_specify_initrd_file {
|
||||
vt_linux_specify_initrd_file /initrd.gz
|
||||
elif [ -e (loop)/slax/boot/initrfs.img ]; then
|
||||
vt_linux_specify_initrd_file /slax/boot/initrfs.img
|
||||
elif [ -e (loop)/minios/boot/initrfs.img ]; then
|
||||
vt_linux_specify_initrd_file /minios/boot/initrfs.img
|
||||
elif [ -e (loop)/pmagic/initrd.img ]; then
|
||||
vt_linux_specify_initrd_file /pmagic/initrd.img
|
||||
elif [ -e (loop)/boot/initrd.xz ]; then
|
||||
@@ -355,6 +360,8 @@ function distro_specify_initrd_file_phase2 {
|
||||
vt_linux_specify_initrd_file /porteus/initrd.xz
|
||||
elif [ -f (loop)/pyabr/boot/initrfs.img ]; then
|
||||
vt_linux_specify_initrd_file /pyabr/boot/initrfs.img
|
||||
elif [ -f (loop)/initrd0.img ]; then
|
||||
vt_linux_specify_initrd_file /initrd0.img
|
||||
|
||||
fi
|
||||
}
|
||||
@@ -416,6 +423,11 @@ function ventoy_freebsd_proc {
|
||||
set vtFreeBsdDistro=FreeBSD
|
||||
set vt_freebsd_ver=xx
|
||||
|
||||
if [ -e (loop)/boot/kernel/geom_ventoy.ko ]; then
|
||||
vt_unix_ko_fillmap /boot/kernel/geom_ventoy.ko
|
||||
return
|
||||
fi
|
||||
|
||||
if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
|
||||
ventoy_get_ghostbsd_ver "$1" "${chosen_path}"
|
||||
elif vt_strstr "$vt_volume_id" "FREENAS"; then
|
||||
@@ -711,7 +723,9 @@ function uefi_linux_menu_func {
|
||||
elif [ -e (loop)/syslinux/alt0/full.cz ]; then
|
||||
vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
|
||||
set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
|
||||
|
||||
|
||||
elif vt_str_begin "$vt_volume_id" "SolusLive"; then
|
||||
vt_add_replace_file 0 "initrd"
|
||||
|
||||
fi
|
||||
|
||||
@@ -1015,14 +1029,13 @@ function legacy_linux_menu_func {
|
||||
loopback loop "$1$2"
|
||||
fi
|
||||
|
||||
if [ -f (loop)/isolinux/isolinux.cfg ]; then
|
||||
if vt_iso9660_isjoliet; then
|
||||
vt_iso9660_nojoliet 1
|
||||
loopback -d loop
|
||||
loopback loop "$1$2"
|
||||
fi
|
||||
|
||||
if vt_syslinux_need_nojoliet "$1$2"; then
|
||||
vt_iso9660_nojoliet 1
|
||||
loopback -d loop
|
||||
loopback loop "$1$2"
|
||||
fi
|
||||
|
||||
|
||||
vt_load_cpio $vtoy_path "$2" "$1" "busybox=$ventoy_busybox_ver"
|
||||
|
||||
vt_linux_clear_initrd
|
||||
@@ -2009,7 +2022,7 @@ function img_unsupport_menuentry {
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
set VENTOY_VERSION="1.0.56"
|
||||
set VENTOY_VERSION="1.0.63"
|
||||
|
||||
#ACPI not compatible with Window7/8, so disable by default
|
||||
set VTOY_PARAM_NO_ACPI=1
|
||||
@@ -2123,10 +2136,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 F4:Localboot F5:Tools F6:ExMenu Ctrl+h:Help"
|
||||
set VTOY_HOTKEY_TIP="h:Help F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Tools F6:ExMenu"
|
||||
else
|
||||
set VTOY_F3_CMD="vt_dynamic_menu 1 0"
|
||||
set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Tools F6:ExMenu Ctrl+h:Help"
|
||||
set VTOY_HOTKEY_TIP="h:Help F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Tools F6:ExMenu"
|
||||
fi
|
||||
|
||||
|
||||
@@ -2177,12 +2190,19 @@ fi
|
||||
|
||||
if [ -n "$VTOY_PLUGIN_SYNTAX_ERROR" ]; then
|
||||
clear
|
||||
echo -e "\n Syntax error detected in ventoy.json, please check! \n"
|
||||
echo -e " ventoy.json 文件中有语法错误,所有配置都不会生效,请检查!\n"
|
||||
if [ -n "$VTOY_PLUGIN_ENCODE_ERROR" ]; then
|
||||
echo -e "\n Encoding type for ventoy.json is not supported, please convert to UTF-8.\n"
|
||||
echo -e " ventoy.json 文件编码格式不支持,请转换为 UTF-8 编码格式!\n"
|
||||
else
|
||||
echo -e "\n Syntax error detected in ventoy.json, please check! \n"
|
||||
echo -e " ventoy.json 文件中有语法错误,所有配置都不会生效,请检查!\n"
|
||||
fi
|
||||
|
||||
echo -e "\n press ENTER to continue (请按 回车 键继续) ..."
|
||||
read vtInputKey
|
||||
read vtInputKey
|
||||
fi
|
||||
|
||||
|
||||
for vtTFile in ventoy.json ventoy_grub.cfg; do
|
||||
if [ -f $vtoy_efi_part/ventoy/$vtTFile ]; then
|
||||
clear
|
||||
|
18
INSTALL/grub/help/de_DE.txt
Normal file
18
INSTALL/grub/help/de_DE.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
h - Zeigt dieses Hilfe Menu
|
||||
F1 - Memdisk Modus (Nur für kleine WinPE/LiveCD ISO/IMG)
|
||||
F2 - Neustarten/Herunterfahren
|
||||
F3 - Menu wechsel zwischen Baum <-> Listen Ansicht
|
||||
F4 - Windows/Linux vom lokalem Datenträger starten
|
||||
F5 - Dienstprogramme
|
||||
F6 - Benutzerdefiniertes Grub2-Menü laden
|
||||
F7 - Wechseln zwischen GUI-Modus <-> TEXT-Modus
|
||||
|
||||
m - Prüfsummencheck Image Dateien (md5/sha1/sha256/sha512)
|
||||
Ctrl+w - WIMBOOT Modus (Nur für Standard Windows ISO)
|
||||
Ctrl+r - Grub2 Modus (Nur für einige Linux distros)
|
||||
Ctrl+i - Kompatibilitäts Modus (Nur für Fehleranalyse)
|
||||
Ctrl+u - Lade ISO efi Treiber (Nur für Fehleranalyse, darf nicht offiziel benutzt werden)
|
||||
|
||||
|
||||
|
||||
Drücke ESC für Zurück ......
|
@@ -1,4 +1,4 @@
|
||||
Ctrl+h - Display this help information
|
||||
h - Display this help information
|
||||
F1 - Memdisk Mode (Only for small WinPE/LiveCD ISO/IMG)
|
||||
F2 - Reboot/Power off
|
||||
F3 - Switch menu mode between Treeview <-> ListView
|
||||
@@ -7,10 +7,12 @@ F5 - Utilities
|
||||
F6 - Load Custom Grub2 Menu
|
||||
F7 - Switch between GUI Mode <-> TEXT Mode
|
||||
|
||||
Ctrl+m - Checksum image files (md5/sha1/sha256/sha512)
|
||||
m - Checksum image files (md5/sha1/sha256/sha512)
|
||||
Ctrl+w - WIMBOOT Mode (Only for standard Windows ISO)
|
||||
Ctrl+r - Grub2 Mode (Only for some Linux distros)
|
||||
Ctrl+i - Compatible Mode (Just only for test)
|
||||
Ctrl+i - Compatible Mode (Just only for debug)
|
||||
Ctrl+u - Load ISO efi driver (Just only for debug, can not be used officially)
|
||||
|
||||
|
||||
|
||||
Press ESC to return ......
|
||||
|
16
INSTALL/grub/help/fr_FR.txt
Normal file
16
INSTALL/grub/help/fr_FR.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
h - Afficher cette aide
|
||||
F1 - Mode Memdisk (Seulement pour WinPE/LiveCD ISO/IMG)
|
||||
F2 - Redémarrer/arrêter
|
||||
F3 - Basculer l'affichage 'Vue en arbre' <-> 'Vue en liste'
|
||||
F4 - Démarrer le système Windows/Linux local
|
||||
F5 - Utilitaires
|
||||
F6 - Charger le menu Grub2 personnalisé
|
||||
F7 - Basculer entre le mode graphique <-> mode texte
|
||||
|
||||
m - Somme de contrôle des images (md5/sha1/sha256/sha512)
|
||||
Ctrl+w - Mode WIMBOOT (seulement pour les images standards Windows)
|
||||
Ctrl+r - Mode Grub2 (seulement pour quelques Linux)
|
||||
Ctrl+i - Mode Compatible (seulement à fins de tests)
|
||||
Ctrl+u - Load ISO efi driver (Just only for debug, can not be used officially)
|
||||
|
||||
Appuyer sur Echap pour sortir ......
|
17
INSTALL/grub/help/hr_HR.txt
Normal file
17
INSTALL/grub/help/hr_HR.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
h - Prikazuje ove informacije
|
||||
F1 - Memdisk način rada (samo za male WinPE/LiveCD imidž fajlove)
|
||||
F2 - Ponovno pokretanje/isključivanje
|
||||
F3 - Mijenja meni između TreeView <-> ListView
|
||||
F4 - Pokreće Windows/Linux na lokalnom disku
|
||||
F5 - Postavke
|
||||
F6 - Učitava prilagođen GRUB2 meni
|
||||
F7 - Mijenja između GUI načina rada <-> TEXT načina rada
|
||||
|
||||
m - Generira kontrolnu sumu odabranog imidž fajla (md5/sha1/sha256/sha512)
|
||||
Ctrl + w - WIMBOOT način rada (samo za standardne Windows imidž fajlove)
|
||||
Ctrl + r - GRUB2 način rada (samo za neke Linux distribucije)
|
||||
Ctrl + i - Kompatibilni način rada (samo za testiranje)
|
||||
Ctrl + u - Load ISO efi driver (Just only for debug, can not be used officially)
|
||||
|
||||
|
||||
Pritisnite ESC za povratak...
|
18
INSTALL/grub/help/id_ID.txt
Normal file
18
INSTALL/grub/help/id_ID.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
h - Tampilkan bantuan informasi ini
|
||||
F1 - Mode Memdisk (Hanya untuk ukuran WinPE/LiveCD ISO/IMG yang kecil)
|
||||
F2 - Mulai ulang/Matikan
|
||||
F3 - Beralih mode menu antara Treeview <-> ListView
|
||||
F4 - Jalankan (boot) Windows/Linux pada disk lokal
|
||||
F5 - Alat Utilitas
|
||||
F6 - Memuat ubah suai Grub2 Menu
|
||||
F7 - Beralih antara mode GUI <-> Mode TEXT
|
||||
|
||||
m - Periksa berkas files (md5/sha1/sha256/sha512)
|
||||
Ctrl+w - Mode WIMBOOT (Hanya untuk berkas ISO Windows standar)
|
||||
Ctrl+r - Mode Grub2 (Hanya untuk distro Linux tertentu)
|
||||
Ctrl+i - Mode Kompatibel/Compatible (Hanya untuk debug saja)
|
||||
Ctrl+u - Memuat ISO efi driver (Hanya untuk debug saja, tidak dapat dipakai secara umum)
|
||||
|
||||
|
||||
|
||||
Tekan ESC untuk kembali ......
|
18
INSTALL/grub/help/ja_JP.txt
Normal file
18
INSTALL/grub/help/ja_JP.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
h - この画面を表示する
|
||||
F1 - 主記憶装置上に記憶域を作成する(容量の小さなWinPE・LiveCD専用)
|
||||
F2 - 再起動・電源断
|
||||
F3 - 表示形式を切り替える(一覧 ↔ 階層)
|
||||
F4 - 手元の記憶装置にあるOSを起動する
|
||||
F5 - 諸機能
|
||||
F6 - Grub2の構成を読み込む
|
||||
F7 - 操作形式を切り替える(GUI ↔ CUI)
|
||||
|
||||
m - イメージの検査合計を計算する (md5/sha1/sha256/sha512)
|
||||
Ctrl+w - WIMBOOTモード(標準的なWindows ISO専用)
|
||||
Ctrl+r - Grub2モード(一部のLinuxディストリビューション専用)
|
||||
Ctrl+i - 互換モード(開発用)
|
||||
Ctrl+u - ISO efiドライバーを読み取る(開発用,非公式)
|
||||
|
||||
|
||||
|
||||
この画面を閉じるにはESCを押してください
|
17
INSTALL/grub/help/pt_PT.txt
Normal file
17
INSTALL/grub/help/pt_PT.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
h - Mostra esta informação de ajuda
|
||||
F1 - Modo Memdisk (Apenas para pequenos WinPE/LiveCD ISO/IMG)
|
||||
F2 - Reiniciar/Desligar
|
||||
F3 - Alternar o modo menu entre Vista de árvore <-> Vista de lista
|
||||
F4 - Arrancar o Windows/Linux em disco local
|
||||
F5 - Utilitários
|
||||
F6 - Carregar menu Grub2 personalizado
|
||||
F7 - Alternar entre Modo GUI <-> Modo TEXTO
|
||||
|
||||
m - Checksum ficheiros de imagem (md5/sha1/sha256/sha512)
|
||||
Ctrl+w - Modo WIMBOOT (Apenas para Windows ISO padrão)
|
||||
Ctrl+r - Modo Grub2 (Apenas para algumas distros Linux)
|
||||
Ctrl+i - Modo Compatível (Apenas para depuração)
|
||||
Ctrl+u - Carregar o controlador ISO efi (Apenas para depuração, não pode ser utilizado oficialmente)
|
||||
|
||||
|
||||
Prima ESC para voltar ......
|
17
INSTALL/grub/help/sr_CY.txt
Normal file
17
INSTALL/grub/help/sr_CY.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
h - Приказује ове информације
|
||||
F1 - Memdisk начин рада (само за мале WinPE/LiveCD имиџ фајлове)
|
||||
F2 - Поновно покретање/искључивање
|
||||
F3 - Мијења мени између TreeView <-> ListView
|
||||
F4 - Покреће Windows/Linux на локалном диску
|
||||
F5 - Поставке
|
||||
F6 - Учитава прилагођен GRUB2 мени
|
||||
F7 - Мијења између GUI начина рада <-> TEXT начина рада
|
||||
|
||||
m - Генерира контролну суму одабраног имиџ фајла (md5/sha1/sha256/sha512)
|
||||
Ctrl + w - WIMBOOT начин рада (само за стандардне Windows имиџ фајлове)
|
||||
Ctrl + r - GRUB2 начин рада (само за неке Linux дистрибуције)
|
||||
Ctrl + i - Компатибилни начин рада (само за тестиранје)
|
||||
Ctrl + u - Load ISO efi driver (Just only for debug, can not be used officially)
|
||||
|
||||
|
||||
Притисните ESC за повратак...
|
17
INSTALL/grub/help/sr_SR.txt
Normal file
17
INSTALL/grub/help/sr_SR.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
h - Prikazuje ove informacije
|
||||
F1 - Memdisk način rada (samo za male WinPE/LiveCD imidž fajlove)
|
||||
F2 - Ponovno pokretanje/isključivanje
|
||||
F3 - Mijenja meni između TreeView <-> ListView
|
||||
F4 - Pokreće Windows/Linux na lokalnom disku
|
||||
F5 - Postavke
|
||||
F6 - Učitava prilagođen GRUB2 meni
|
||||
F7 - Mijenja između GUI načina rada <-> TEXT načina rada
|
||||
|
||||
m - Generira kontrolnu sumu odabranog imidž fajla (md5/sha1/sha256/sha512)
|
||||
Ctrl + w - WIMBOOT način rada (samo za standardne Windows imidž fajlove)
|
||||
Ctrl + r - GRUB2 način rada (samo za neke Linux distribucije)
|
||||
Ctrl + i - Kompatibilni način rada (samo za testiranje)
|
||||
Ctrl+u - Load ISO efi driver (Just only for debug, can not be used officially)
|
||||
|
||||
|
||||
Pritisnite ESC za povratak...
|
@@ -1,4 +1,4 @@
|
||||
Ctrl+h - Yardım bilgilerini göster
|
||||
h - Yardım bilgilerini göster
|
||||
F1 - Memdisk Modu başlatır(Yalnızca küçük WinPE/LiveCD ISO/IMG ler için bu modu kullanabilirsiniz)
|
||||
F2 - Bilgisayarı Yeniden Başlat/Kapat
|
||||
F3 - Ventoy Menü modu olarak,Klasör görünümü(Treeview) ile Liste görünümü(ListView) arasında geçiş yapmayı sağlar.
|
||||
@@ -7,10 +7,11 @@ F5 - Ventoy Araçlar menüsü
|
||||
F6 - Özelleştirilmiş Grub2 menüsünü yükler
|
||||
F7 - Grafik Modu(GUI Mode) ile Metin Modu(Text Mode) arasında geçiş yapmayı sağlar
|
||||
|
||||
Ctrl+m - İndirilen imaj dosyalarının hatasız indirildiğini teyit etmek için "md5/sha1/sha256/sha512" değerlerini kontrol etmeyi sağlar
|
||||
m - İndirilen imaj dosyalarının hatasız indirildiğini teyit etmek için "md5/sha1/sha256/sha512" değerlerini kontrol etmeyi sağlar
|
||||
Ctrl+w - WIMBOOT Modu çalıştırmayı sağlar(Sadece normal Windows ISO ları için)
|
||||
Ctrl+r - Grub2 Modu çalıştırmayı sağlar (Sadece bazı Linux dağıtımları için)
|
||||
Ctrl+i - Uyumluluk Modu'nu (Compatible Mode) çalıştırmayı sağlar (Sadece bazı çalışmayan ISO ları test etmek için bu modu kullanabilirsiniz)
|
||||
Ctrl+i - Uyumluluk Modu'nu (Compatible Mode) çalıştırmayı sağlar (Sadece hata ayıklama için bu modu kullanabilirsiniz)
|
||||
Ctrl+u - ISO efi sürücüsünü yükler(Sadece hata ayıklama için bu mod kullanılabilir, resmi olarak kullanılamaz)
|
||||
|
||||
|
||||
Geriye dönmek için ESC tuşuna basınız......
|
||||
|
@@ -1,4 +1,4 @@
|
||||
Ctrl+h - 显示本帮助信息
|
||||
h - 显示本帮助信息
|
||||
F1 - 把文件加载到内存启动(只适用于文件很小的 WinPE/LiveCD等)
|
||||
F2 - 电源操作 (重启、关机)
|
||||
F3 - 菜单显示模式切换。可在列表模式和目录模式之间自由切换。
|
||||
@@ -7,9 +7,11 @@ F5 - 各类工具
|
||||
F6 - 加载自定义 GRUB2 菜单。
|
||||
F7 - 界面在文本模式和图形模式之间切换。
|
||||
|
||||
Ctrl+m - 计算文件校验值(md5/sha1/sha256/sha512)
|
||||
m - 计算文件校验值(md5/sha1/sha256/sha512)
|
||||
Ctrl+w - WIMBOOT 模式 (只适用于标准的 Windows ISO文件)
|
||||
Ctrl+r - Grub2 模式 (只适用于常见的一些 Linux 系统ISO文件)
|
||||
Ctrl+i - 兼容模式 (只用作调试目的,不能正式使用)
|
||||
Ctrl+u - 加载 ISO efi 驱动(只用作调试目的,不能正式使用)
|
||||
|
||||
|
||||
按 ESC 键返回 ......
|
||||
|
@@ -76,6 +76,11 @@ else
|
||||
terminal_output console
|
||||
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
|
||||
boot
|
||||
elif [ -f ($vtoydev,$partid)/efi/Microsoft/Boot/bootmgfw.efi ]; then
|
||||
set root=($vtoydev,$partid)
|
||||
terminal_output console
|
||||
chainloader /efi/Microsoft/Boot/bootmgfw.efi
|
||||
boot
|
||||
fi
|
||||
else
|
||||
break
|
||||
@@ -87,6 +92,10 @@ else
|
||||
terminal_output console
|
||||
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
|
||||
boot
|
||||
elif 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
|
||||
|
@@ -16,6 +16,7 @@ print_usage() {
|
||||
echo ' -s/-S enable/disable secure boot support (default is disabled)'
|
||||
echo ' -g use GPT partition style, default is MBR (only for install)'
|
||||
echo ' -L Label of the 1st exfat partition (default is Ventoy)'
|
||||
echo ' -n try non-destructive installation (only for install)'
|
||||
echo ''
|
||||
}
|
||||
|
||||
@@ -28,6 +29,8 @@ while [ -n "$1" ]; do
|
||||
elif [ "$1" = "-I" ]; then
|
||||
MODE="install"
|
||||
FORCE="Y"
|
||||
elif [ "$1" = "-n" ]; then
|
||||
NONDESTRUCTIVE="Y"
|
||||
elif [ "$1" = "-u" ]; then
|
||||
MODE="update"
|
||||
elif [ "$1" = "-l" ]; then
|
||||
@@ -162,7 +165,7 @@ if [ -d ./tmp_mnt ]; then
|
||||
fi
|
||||
|
||||
|
||||
if [ "$MODE" = "install" ]; then
|
||||
if [ "$MODE" = "install" -a -z "$NONDESTRUCTIVE" ]; then
|
||||
vtdebug "install Ventoy ..."
|
||||
|
||||
if [ -n "$VTGPT" ]; then
|
||||
@@ -255,7 +258,10 @@ if [ "$MODE" = "install" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! dd if=/dev/zero of=$DISK bs=1 count=512 status=none conv=fsync; then
|
||||
# check and umount
|
||||
check_umount_disk "$DISK"
|
||||
|
||||
if ! dd if=/dev/zero of=$DISK bs=64 count=512 status=none conv=fsync; then
|
||||
vterr "Write data to $DISK failed, please check whether it's in use."
|
||||
exit 1
|
||||
fi
|
||||
@@ -281,10 +287,29 @@ if [ "$MODE" = "install" ]; then
|
||||
PART1=$(get_disk_part_name $DISK 1)
|
||||
PART2=$(get_disk_part_name $DISK 2)
|
||||
|
||||
mkexfatfs -n "$VTNEW_LABEL" -s $cluster_sectors ${PART1}
|
||||
#clean part2
|
||||
dd status=none conv=fsync if=/dev/zero of=$DISK bs=512 count=32 seek=$part2_start_sector
|
||||
|
||||
vtinfo "writing data to disk ..."
|
||||
|
||||
#format part1
|
||||
wait_and_create_part ${PART1} ${PART2}
|
||||
if [ -b ${PART1} ]; then
|
||||
vtinfo "Format partition 1 ${PART1} ..."
|
||||
mkexfatfs -n "$VTNEW_LABEL" -s $cluster_sectors ${PART1}
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "mkexfatfs failed, now retry..."
|
||||
mkexfatfs -n "$VTNEW_LABEL" -s $cluster_sectors ${PART1}
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "######### mkexfatfs failed, exit ########"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "mkexfatfs success"
|
||||
fi
|
||||
else
|
||||
vterr "${PART1} NOT exist"
|
||||
fi
|
||||
|
||||
vtinfo "writing data to disk ..."
|
||||
dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=446
|
||||
|
||||
if [ -n "$VTGPT" ]; then
|
||||
@@ -314,51 +339,181 @@ if [ "$MODE" = "install" ]; then
|
||||
sync
|
||||
|
||||
vtinfo "esp partition processing ..."
|
||||
|
||||
sleep 1
|
||||
check_umount_disk "$DISK"
|
||||
|
||||
if [ "$SECUREBOOT" != "YES" ]; then
|
||||
mkdir ./tmp_mnt
|
||||
|
||||
vtdebug "mounting part2 ...."
|
||||
for tt in 1 2 3 4 5; do
|
||||
if mount ${PART2} ./tmp_mnt > /dev/null 2>&1; then
|
||||
vtdebug "mounting part2 success"
|
||||
break
|
||||
fi
|
||||
|
||||
check_umount_disk "$DISK"
|
||||
sleep 2
|
||||
done
|
||||
|
||||
rm -f ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
|
||||
rm -f ./tmp_mnt/EFI/BOOT/grubx64.efi
|
||||
rm -f ./tmp_mnt/EFI/BOOT/BOOTIA32.EFI
|
||||
rm -f ./tmp_mnt/EFI/BOOT/grubia32.efi
|
||||
rm -f ./tmp_mnt/EFI/BOOT/MokManager.efi
|
||||
rm -f ./tmp_mnt/EFI/BOOT/mmia32.efi
|
||||
rm -f ./tmp_mnt/ENROLL_THIS_KEY_IN_MOKMANAGER.cer
|
||||
mv ./tmp_mnt/EFI/BOOT/grubx64_real.efi ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
|
||||
mv ./tmp_mnt/EFI/BOOT/grubia32_real.efi ./tmp_mnt/EFI/BOOT/BOOTIA32.EFI
|
||||
|
||||
sync
|
||||
|
||||
for tt in 1 2 3; do
|
||||
if umount ./tmp_mnt; then
|
||||
vtdebug "umount part2 success"
|
||||
rm -rf ./tmp_mnt
|
||||
break
|
||||
else
|
||||
vtdebug "umount part2 failed, now retry..."
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
if [ "$SECUREBOOT" != "YES" ]; then
|
||||
sleep 2
|
||||
check_umount_disk "$DISK"
|
||||
vtoycli partresize -s $DISK $part2_start_sector
|
||||
fi
|
||||
|
||||
echo ""
|
||||
vtinfo "Install Ventoy to $DISK successfully finished."
|
||||
echo ""
|
||||
|
||||
elif [ "$MODE" = "install" -a -n "$NONDESTRUCTIVE" ]; then
|
||||
vtdebug "non-destructive install Ventoy ..."
|
||||
|
||||
version=$(get_disk_ventoy_version $DISK)
|
||||
if [ $? -eq 0 ]; then
|
||||
if [ -z "$FORCE" ]; then
|
||||
vtwarn "$DISK already contains a Ventoy with version $version."
|
||||
vtwarn "You can not do and don not need non-destructive installation."
|
||||
vtwarn ""
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
disk_sector_num=$(cat /sys/block/${DISK#/dev/}/size)
|
||||
disk_size_gb=$(expr $disk_sector_num / 2097152)
|
||||
|
||||
if vtoycli partresize -t $DISK; then
|
||||
OldStyle="GPT"
|
||||
else
|
||||
OldStyle="MBR"
|
||||
fi
|
||||
|
||||
#Print disk info
|
||||
echo "Disk : $DISK"
|
||||
parted -s $DISK p 2>&1 | grep Model
|
||||
echo "Size : $disk_size_gb GB"
|
||||
echo "Style: $OldStyle"
|
||||
echo ''
|
||||
|
||||
vtwarn "Attention:"
|
||||
vtwarn "Ventoy will try non-destructive installation on $DISK if possible."
|
||||
echo ""
|
||||
|
||||
read -p 'Continue? (y/n) ' Answer
|
||||
if [ "$Answer" != "y" ]; then
|
||||
if [ "$Answer" != "Y" ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $disk_sector_num -le $VENTOY_SECTOR_NUM ]; then
|
||||
vterr "No enough space in disk $DISK"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PART1=$(get_disk_part_name $DISK 1)
|
||||
PART2=$(get_disk_part_name $DISK 2)
|
||||
|
||||
#Part1 size in MB aligned with 4KB
|
||||
PART1_SECTORS=$(cat /sys/class/block/${PART1#/dev/}/size)
|
||||
PART1_4K=$(expr $PART1_SECTORS / 8)
|
||||
PART1_MB=$(expr $PART1_4K / 256)
|
||||
PART1_NEW_MB=$(expr $PART1_MB - 32)
|
||||
|
||||
echo "$PART1 is ${PART1_MB}MB"
|
||||
|
||||
#check partition layout
|
||||
echo "check partition layout ..."
|
||||
vtoycli partresize -c $DISK
|
||||
vtRet=$?
|
||||
if [ $vtRet -eq 0 ]; then
|
||||
exit 1
|
||||
else
|
||||
# check and umount
|
||||
check_umount_disk "$DISK"
|
||||
sleep 1
|
||||
check_umount_disk "$DISK"
|
||||
|
||||
if [ $vtRet -eq 1 ]; then
|
||||
echo "Free space enough, start install..."
|
||||
part2_start_sector=$(expr $PART1_SECTORS + 2048)
|
||||
elif [ $vtRet -eq 2 ]; then
|
||||
echo "We need to shrink partition 1 firstly ..."
|
||||
|
||||
PART1_BLKID=$(blkid $PART1)
|
||||
blkid $PART1
|
||||
|
||||
if echo $PART1_BLKID | egrep -q -i 'TYPE=ntfs|TYPE=.ntfs'; then
|
||||
echo "Partition 1 contains NTFS filesystem"
|
||||
|
||||
which ntfsresize
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "###[FAIL] ntfsresize not found. Please install ntfs-3g package."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "ntfsfix -b -d $PART1 ..."
|
||||
ntfsfix -b -d $PART1
|
||||
|
||||
echo "ntfsresize --size ${PART1_NEW_MB}Mi $PART1 ..."
|
||||
ntfsresize -f --size ${PART1_NEW_MB}Mi $PART1
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "###[FAIL] ntfsresize failed."
|
||||
exit 1
|
||||
fi
|
||||
elif echo $PART1_BLKID | egrep -q -i 'TYPE=ext[2-4]|TYPE=.ext[2-4]'; then
|
||||
echo "Partition 1 contains EXT filesystem"
|
||||
|
||||
which resize2fs
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "###[FAIL] resize2fs not found. Please install e2fsprogs package."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "e2fsck -f $PART1 ..."
|
||||
e2fsck -f $PART1
|
||||
|
||||
echo "resize2fs $PART1 ${PART1_NEW_MB}M ..."
|
||||
resize2fs $PART1 ${PART1_NEW_MB}M
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "###[FAIL] resize2fs failed."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "###[FAIL] Unsupported filesystem in partition 1."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sync
|
||||
PART1_NEW_END_MB=$(expr $PART1_NEW_MB + 1)
|
||||
part2_start_sector=$(expr $PART1_NEW_END_MB \* 2048)
|
||||
fi
|
||||
fi
|
||||
|
||||
vtinfo "writing data to disk part2_start=$part2_start_sector ..."
|
||||
|
||||
dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=440
|
||||
|
||||
if [ "$OldStyle" = "GPT" ]; then
|
||||
echo -en '\x22' | dd status=none of=$DISK conv=fsync bs=1 count=1 seek=92
|
||||
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
|
||||
xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1
|
||||
fi
|
||||
|
||||
xzcat ./ventoy/ventoy.disk.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start_sector
|
||||
|
||||
#test UUID
|
||||
testUUIDStr=$(vtoy_gen_uuid | hexdump -C)
|
||||
vtdebug "test uuid: $testUUIDStr"
|
||||
|
||||
#disk uuid
|
||||
vtoy_gen_uuid | dd status=none conv=fsync of=${DISK} seek=384 bs=1 count=16
|
||||
|
||||
vtinfo "sync data ..."
|
||||
sync
|
||||
|
||||
vtinfo "esp partition processing ..."
|
||||
if [ "$SECUREBOOT" != "YES" ]; then
|
||||
vtoycli partresize -s $DISK $part2_start_sector
|
||||
fi
|
||||
|
||||
vtinfo "update partition table $DISK $part2_start_sector ..."
|
||||
vtoycli partresize -p $DISK $part2_start_sector
|
||||
if [ $? -eq 0 ]; then
|
||||
sync
|
||||
echo ""
|
||||
vtinfo "Ventoy non-destructive installation on $DISK successfully finished."
|
||||
echo ""
|
||||
else
|
||||
echo ""
|
||||
vterr "Ventoy non-destructive installation on $DISK failed."
|
||||
echo ""
|
||||
fi
|
||||
|
||||
else
|
||||
vtdebug "update Ventoy ..."
|
||||
@@ -441,47 +596,13 @@ else
|
||||
check_umount_disk "$DISK"
|
||||
|
||||
xzcat ./ventoy/ventoy.disk.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start
|
||||
|
||||
sync
|
||||
|
||||
vtinfo "esp partition processing ..."
|
||||
if [ "$SECUREBOOT" != "YES" ]; then
|
||||
mkdir ./tmp_mnt
|
||||
|
||||
vtdebug "mounting part2 ...."
|
||||
for tt in 1 2 3 4 5; do
|
||||
check_umount_disk "$DISK"
|
||||
|
||||
if mount ${PART2} ./tmp_mnt > /dev/null 2>&1; then
|
||||
vtdebug "mounting part2 success"
|
||||
break
|
||||
else
|
||||
vtdebug "mounting part2 failed, now wait and retry..."
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
|
||||
rm -f ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
|
||||
rm -f ./tmp_mnt/EFI/BOOT/grubx64.efi
|
||||
rm -f ./tmp_mnt/EFI/BOOT/BOOTIA32.EFI
|
||||
rm -f ./tmp_mnt/EFI/BOOT/grubia32.efi
|
||||
rm -f ./tmp_mnt/EFI/BOOT/MokManager.efi
|
||||
rm -f ./tmp_mnt/EFI/BOOT/mmia32.efi
|
||||
rm -f ./tmp_mnt/ENROLL_THIS_KEY_IN_MOKMANAGER.cer
|
||||
mv ./tmp_mnt/EFI/BOOT/grubx64_real.efi ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
|
||||
mv ./tmp_mnt/EFI/BOOT/grubia32_real.efi ./tmp_mnt/EFI/BOOT/BOOTIA32.EFI
|
||||
|
||||
sync
|
||||
|
||||
for tt in 1 2 3; do
|
||||
if umount ./tmp_mnt > /dev/null 2>&1; then
|
||||
vtdebug "umount part2 success"
|
||||
rm -rf ./tmp_mnt
|
||||
break
|
||||
else
|
||||
vtdebug "umount part2 failed, now retry..."
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
sleep 2
|
||||
check_umount_disk "$DISK"
|
||||
vtoycli partresize -s $DISK $part2_start
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
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/tool/i386/vtoycli
Normal file
BIN
INSTALL/tool/i386/vtoycli
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/tool/mips64el/vtoycli
Normal file
BIN
INSTALL/tool/mips64el/vtoycli
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -68,10 +68,10 @@ check_tool_work_ok() {
|
||||
return
|
||||
fi
|
||||
|
||||
if vtoyfat -T; then
|
||||
vtdebug "vtoyfat test ok ..."
|
||||
if vtoycli fat -T; then
|
||||
vtdebug "vtoycli fat test ok ..."
|
||||
else
|
||||
vtdebug "vtoyfat test fail ..."
|
||||
vtdebug "vtoycli fat test fail ..."
|
||||
ventoy_false
|
||||
return
|
||||
fi
|
||||
@@ -183,7 +183,7 @@ check_disk_secure_boot() {
|
||||
|
||||
PART2=$(get_disk_part_name $1 2)
|
||||
|
||||
vtoyfat -s $PART2
|
||||
vtoycli fat -s $PART2
|
||||
}
|
||||
|
||||
get_disk_ventoy_version() {
|
||||
@@ -195,7 +195,7 @@ get_disk_ventoy_version() {
|
||||
|
||||
PART2=$(get_disk_part_name $1 2)
|
||||
|
||||
ParseVer=$(vtoyfat $PART2)
|
||||
ParseVer=$(vtoycli fat $PART2)
|
||||
if [ $? -eq 0 ]; then
|
||||
vtdebug "Ventoy version in $PART2 is $ParseVer"
|
||||
echo $ParseVer
|
||||
@@ -206,6 +206,48 @@ get_disk_ventoy_version() {
|
||||
ventoy_false
|
||||
}
|
||||
|
||||
wait_and_create_part() {
|
||||
vPART1=$1
|
||||
vPART2=$2
|
||||
echo 'Wait for partitions ...'
|
||||
for i in 0 1 2 3 4 5 6 7 8 9; do
|
||||
if ls -l $vPART1 2>/dev/null | grep -q '^b'; then
|
||||
if ls -l $vPART2 2>/dev/null | grep -q '^b'; then
|
||||
break
|
||||
fi
|
||||
else
|
||||
echo "Wait for $vPART1/$vPART2 ..."
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
|
||||
if ls -l $vPART1 2>/dev/null | grep -q '^b'; then
|
||||
echo "$vPART1 exist OK"
|
||||
else
|
||||
MajorMinor=$(sed "s/:/ /" /sys/class/block/${vPART1#/dev/}/dev)
|
||||
echo "mknod -m 0660 $vPART1 b $MajorMinor ..."
|
||||
mknod -m 0660 $vPART1 b $MajorMinor
|
||||
fi
|
||||
|
||||
if ls -l $vPART2 2>/dev/null | grep -q '^b'; then
|
||||
echo "$vPART2 exist OK"
|
||||
else
|
||||
MajorMinor=$(sed "s/:/ /" /sys/class/block/${vPART2#/dev/}/dev)
|
||||
echo "mknod -m 0660 $vPART2 b $MajorMinor ..."
|
||||
mknod -m 0660 $vPART2 b $MajorMinor
|
||||
fi
|
||||
|
||||
if ls -l $vPART1 2>/dev/null | grep -q '^b'; then
|
||||
if ls -l $vPART2 2>/dev/null | grep -q '^b'; then
|
||||
echo "partition exist OK"
|
||||
fi
|
||||
else
|
||||
echo "[FAIL] $vPART1/$vPART2 does not exist"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
format_ventoy_disk_mbr() {
|
||||
reserve_mb=$1
|
||||
DISK=$2
|
||||
@@ -241,6 +283,11 @@ format_ventoy_disk_mbr() {
|
||||
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 $PART1 ]; then
|
||||
echo "delete $PART1"
|
||||
rm -f $PART1
|
||||
fi
|
||||
|
||||
if [ -e $PART2 ]; then
|
||||
echo "delete $PART2"
|
||||
rm -f $PART2
|
||||
@@ -293,27 +340,34 @@ EOF
|
||||
sleep 3
|
||||
echo "Done"
|
||||
|
||||
echo 'mkfs on disk partitions ...'
|
||||
for i in 1 2 3 4 5 6 7; do
|
||||
if [ -b $PART2 ]; then
|
||||
|
||||
echo 'Wait for partitions ...'
|
||||
for i in 0 1 2 3 4 5 6 7 8 9; do
|
||||
if [ -b $PART1 -a -b $PART2 ]; then
|
||||
break
|
||||
else
|
||||
echo "wait $PART2 ..."
|
||||
echo "Wait for $PART1/$PART2 ..."
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
mknod -m 0660 $PART2 b $MajorMinor
|
||||
fi
|
||||
|
||||
if [ -b $PART1 -a -b $PART2 ]; then
|
||||
echo "partition exist OK"
|
||||
else
|
||||
echo "[FAIL] $PART1/$PART2 does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "create efi fat fs $PART2 ..."
|
||||
@@ -366,6 +420,11 @@ format_ventoy_disk_gpt() {
|
||||
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 $PART1 ]; then
|
||||
echo "delete $PART1"
|
||||
rm -f $PART1
|
||||
fi
|
||||
|
||||
if [ -e $PART2 ]; then
|
||||
echo "delete $PART2"
|
||||
rm -f $PART2
|
||||
@@ -391,7 +450,7 @@ format_ventoy_disk_gpt() {
|
||||
|
||||
sync
|
||||
|
||||
vtoygpt -f $DISK
|
||||
vtoycli gpt -f $DISK
|
||||
sync
|
||||
|
||||
udevadm trigger --name-match=$DISK >/dev/null 2>&1
|
||||
@@ -399,27 +458,33 @@ format_ventoy_disk_gpt() {
|
||||
sleep 3
|
||||
echo "Done"
|
||||
|
||||
echo 'mkfs on disk partitions ...'
|
||||
for i in 1 2 3 4 5 6 7; do
|
||||
if [ -b $PART2 ]; then
|
||||
echo 'Wait for partitions ...'
|
||||
for i in 0 1 2 3 4 5 6 7 8 9; do
|
||||
if [ -b $PART1 -a -b $PART2 ]; then
|
||||
break
|
||||
else
|
||||
echo "wait $PART2 ..."
|
||||
echo "Wait for $PART1/$PART2 ..."
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
mknod -m 0660 $PART2 b $MajorMinor
|
||||
fi
|
||||
|
||||
if [ -b $PART1 -a -b $PART2 ]; then
|
||||
echo "partition exist OK"
|
||||
else
|
||||
echo "[FAIL] $PART1/$PART2 does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "create efi fat fs $PART2 ..."
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
INSTALL/tool/x86_64/vtoycli
Normal file
BIN
INSTALL/tool/x86_64/vtoycli
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
INSTALL/ventoy/7z/32/7za.xz
Normal file
BIN
INSTALL/ventoy/7z/32/7za.xz
Normal file
Binary file not shown.
Binary file not shown.
BIN
INSTALL/ventoy/7z/64/7za.xz
Normal file
BIN
INSTALL/ventoy/7z/64/7za.xz
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -36,6 +36,11 @@ sh language.sh || exit 1
|
||||
sh build.sh
|
||||
cd -
|
||||
|
||||
cd ../Plugson
|
||||
sh build.sh
|
||||
sh pack.sh
|
||||
cd -
|
||||
|
||||
|
||||
LOOP=$(losetup -f)
|
||||
|
||||
@@ -72,6 +77,13 @@ ls -1 ./grub/ | grep -v 'grub\.cfg' | while read line; do
|
||||
cp $OPT ./grub/$line $tmpmnt/grub/
|
||||
done
|
||||
|
||||
#tar help txt
|
||||
cd $tmpmnt/grub/
|
||||
tar czf help.tar.gz ./help/
|
||||
rm -rf ./help
|
||||
cd ../../
|
||||
|
||||
|
||||
cp $OPT ./ventoy $tmpmnt/
|
||||
cp $OPT ./EFI $tmpmnt/
|
||||
cp $OPT ./tool/ENROLL_THIS_KEY_IN_MOKMANAGER.cer $tmpmnt/
|
||||
@@ -82,9 +94,9 @@ mkdir -p $tmpmnt/tool
|
||||
# cp $OPT ./tool/x86_64/mount.exfat-fuse $tmpmnt/tool/mount.exfat-fuse_x86_64
|
||||
# cp $OPT ./tool/aarch64/mount.exfat-fuse $tmpmnt/tool/mount.exfat-fuse_aarch64
|
||||
# to save space
|
||||
cp $OPT ./tool/i386/vtoygpt $tmpmnt/tool/mount.exfat-fuse_i386
|
||||
cp $OPT ./tool/x86_64/vtoygpt $tmpmnt/tool/mount.exfat-fuse_x86_64
|
||||
cp $OPT ./tool/aarch64/vtoygpt $tmpmnt/tool/mount.exfat-fuse_aarch64
|
||||
dd status=none bs=1024 count=16 if=./tool/i386/vtoycli of=$tmpmnt/tool/mount.exfat-fuse_i386
|
||||
dd status=none bs=1024 count=16 if=./tool/x86_64/vtoycli of=$tmpmnt/tool/mount.exfat-fuse_x86_64
|
||||
dd status=none bs=1024 count=16 if=./tool/aarch64/vtoycli of=$tmpmnt/tool/mount.exfat-fuse_aarch64
|
||||
|
||||
|
||||
rm -f $tmpmnt/grub/i386-pc/*.img
|
||||
@@ -105,6 +117,7 @@ cp $OPT ./tool $tmpdir/
|
||||
rm -f $tmpdir/ENROLL_THIS_KEY_IN_MOKMANAGER.cer
|
||||
cp $OPT Ventoy2Disk.sh $tmpdir/
|
||||
cp $OPT VentoyWeb.sh $tmpdir/
|
||||
cp $OPT VentoyPlugson.sh $tmpdir/
|
||||
cp $OPT VentoyGUI* $tmpdir/
|
||||
|
||||
|
||||
@@ -114,6 +127,7 @@ cp $OPT CreatePersistentImg.sh $tmpdir/
|
||||
cp $OPT ExtendPersistentImg.sh $tmpdir/
|
||||
dos2unix -q $tmpdir/Ventoy2Disk.sh
|
||||
dos2unix -q $tmpdir/VentoyWeb.sh
|
||||
dos2unix -q $tmpdir/VentoyPlugson.sh
|
||||
|
||||
|
||||
dos2unix -q $tmpdir/CreatePersistentImg.sh
|
||||
@@ -152,6 +166,7 @@ find $tmpdir/ -type d -exec chmod 755 "{}" +
|
||||
find $tmpdir/ -type f -exec chmod 644 "{}" +
|
||||
chmod +x $tmpdir/Ventoy2Disk.sh
|
||||
chmod +x $tmpdir/VentoyWeb.sh
|
||||
chmod +x $tmpdir/VentoyPlugson.sh
|
||||
chmod +x $tmpdir/VentoyGUI*
|
||||
|
||||
cp $OPT $LANG_DIR/languages.json $tmpdir/tool/
|
||||
@@ -165,7 +180,16 @@ tar -czvf ventoy-${curver}-linux.tar.gz $tmpdir
|
||||
|
||||
|
||||
rm -f ventoy-${curver}-windows.zip
|
||||
cp $OPT Ventoy2Disk*.exe $tmpdir/
|
||||
|
||||
cp $OPT Ventoy2Disk.exe $tmpdir/
|
||||
cp $OPT VentoyPlugson.exe $tmpdir/
|
||||
cp $OPT FOR_X64_ARM.txt $tmpdir/
|
||||
mkdir -p $tmpdir/altexe
|
||||
cp $OPT Ventoy2Disk_*.exe $tmpdir/altexe/
|
||||
|
||||
|
||||
|
||||
cp $OPT $tmpdir/tool/plugson.tar.xz $tmpdir/ventoy/
|
||||
cp $OPT $LANG_DIR/languages.json $tmpdir/ventoy/
|
||||
rm -rf $tmpdir/tool
|
||||
rm -f $tmpdir/*.sh
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -157,7 +157,9 @@ if [ "$1" = "VENTOY_I386_QT_BUILD" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -f /opt/CentOS8/LinuxGUI/build.sh ]; then
|
||||
mount --bind /home/share/Ventoy/LinuxGUI /opt/CentOS8/LinuxGUI
|
||||
fi
|
||||
|
||||
chroot /opt/CentOS8 sh /buildqt.sh
|
||||
force_copy ./Ventoy2Disk.qt5_32 ../INSTALL/tool/i386/Ventoy2Disk.qt5
|
||||
|
78
Plugson/build.sh
Normal file
78
Plugson/build.sh
Normal file
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$1" = "sim" ]; then
|
||||
exopt="-DVENTOY_SIM"
|
||||
fi
|
||||
|
||||
build_func() {
|
||||
libsuffix=$2
|
||||
toolDir=$3
|
||||
|
||||
XXFLAG='-std=gnu99 -D_FILE_OFFSET_BITS=64'
|
||||
XXLIB=""
|
||||
|
||||
echo "CC=$1 libsuffix=$libsuffix toolDir=$toolDir"
|
||||
|
||||
echo "CC civetweb.o"
|
||||
$1 $XXFLAG -c -Wall -Wextra -Wshadow -Wformat-security -Winit-self \
|
||||
-Wmissing-prototypes -O2 -DLINUX \
|
||||
-I./src/Lib/libhttp/include \
|
||||
-DNDEBUG -DNO_CGI -DNO_CACHING -DNO_SSL -DSQLITE_DISABLE_LFS -DSSL_ALREADY_INITIALIZED \
|
||||
-DUSE_STACK_SIZE=102400 -DNDEBUG -fPIC \
|
||||
./src/Lib/libhttp/include/civetweb.c \
|
||||
-o ./civetweb.o
|
||||
|
||||
echo "CC plugson.o"
|
||||
$1 $XXFLAG -O2 $exopt -Wall -Wno-unused-function -DSTATIC=static -DINIT= \
|
||||
-I./src \
|
||||
-I./src/Core \
|
||||
-I./src/Web \
|
||||
-I./src/Include \
|
||||
-I./src/Lib/libhttp/include \
|
||||
-I./src/Lib/fat_io_lib/include \
|
||||
-I./src/Lib/xz-embedded/linux/include \
|
||||
-I./src/Lib/xz-embedded/linux/include/linux \
|
||||
-I./src/Lib/xz-embedded/userspace \
|
||||
-I ./src/Lib/exfat/src/libexfat \
|
||||
-I ./src/Lib/exfat/src/mkfs \
|
||||
-I ./src/Lib/fat_io_lib \
|
||||
\
|
||||
-L ./src/Lib/fat_io_lib/lib \
|
||||
src/main_linux.c \
|
||||
src/Core/ventoy_crc32.c \
|
||||
src/Core/ventoy_disk.c \
|
||||
src/Core/ventoy_disk_linux.c \
|
||||
src/Core/ventoy_json.c \
|
||||
src/Core/ventoy_log.c \
|
||||
src/Core/ventoy_md5.c \
|
||||
src/Core/ventoy_util.c \
|
||||
src/Core/ventoy_util_linux.c \
|
||||
src/Web/*.c \
|
||||
src/Lib/xz-embedded/linux/lib/decompress_unxz.c \
|
||||
src/Lib/fat_io_lib/*.c \
|
||||
$XXLIB \
|
||||
-l pthread \
|
||||
./civetweb.o \
|
||||
-o Plugson$libsuffix
|
||||
|
||||
rm -f *.o
|
||||
|
||||
if [ "$libsuffix" = "aa64" ]; then
|
||||
aarch64-linux-gnu-strip Plugson$libsuffix
|
||||
elif [ "$libsuffix" = "m64e" ]; then
|
||||
mips-linux-gnu-strip Plugson$libsuffix
|
||||
else
|
||||
strip Plugson$libsuffix
|
||||
fi
|
||||
|
||||
rm -f ../INSTALL/tool/$toolDir/Plugson
|
||||
cp -a Plugson$libsuffix ../INSTALL/tool/$toolDir/Plugson
|
||||
|
||||
}
|
||||
|
||||
build_func "gcc" '64' 'x86_64'
|
||||
|
||||
build_func "gcc -m32" '32' 'i386'
|
||||
build_func "aarch64-linux-gnu-gcc" 'aa64' 'aarch64'
|
||||
build_func "mips-linux-gnu-gcc -mips64r2 -mabi=64" 'm64e' 'mips64el'
|
||||
|
39
Plugson/pack.sh
Normal file
39
Plugson/pack.sh
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ -n "$PKG_DATE" ]; then
|
||||
plugson_verion=$PKG_DATE
|
||||
else
|
||||
plugson_verion=$(date '+%Y%m%d %H:%M:%S')
|
||||
fi
|
||||
|
||||
sed "s#.*plugson_build_date.*# <b id=\"plugson_build_date\">$plugson_verion</b>#" -i ./www/index.html
|
||||
|
||||
if [ ! -f ./vs/VentoyPlugson/Release/VentoyPlugson.exe ]; then
|
||||
echo "NO VentoyPlugson.exe found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f ./www.tar.xz ]; then
|
||||
rm -f ./www.tar.xz
|
||||
fi
|
||||
|
||||
[ -f ./www/helplist ] && rm -f ./www/helplist
|
||||
ls -1 ../INSTALL/grub/help/ | while read line; do
|
||||
echo -n ${line:0:5} >> ./www/helplist
|
||||
done
|
||||
echo -n "$plugson_verion" > ./www/buildtime
|
||||
|
||||
tar cf www.tar www
|
||||
xz --check=crc32 www.tar
|
||||
|
||||
rm -f ../INSTALL/VentoyPlugson.exe
|
||||
cp -a ./vs/VentoyPlugson/Release/VentoyPlugson.exe ../INSTALL/VentoyPlugson.exe
|
||||
|
||||
rm -f ../INSTALL/tool/plugson.tar.xz
|
||||
mv ./www.tar.xz ../INSTALL/tool/plugson.tar.xz
|
||||
|
||||
echo ""
|
||||
echo "========= SUCCESS ==========="
|
||||
echo ""
|
||||
|
||||
|
304
Plugson/src/Core/ventoy_crc32.c
Normal file
304
Plugson/src/Core/ventoy_crc32.c
Normal file
@@ -0,0 +1,304 @@
|
||||
/******************************************************************************
|
||||
* crc32.c ---- ventoy crc32
|
||||
*
|
||||
* Copyright (c) 2021, 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
#include <Windows.h>
|
||||
#define uint32_t UINT32
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
static uint32_t g_crc_table[256] = {
|
||||
0x00000000,
|
||||
0x77073096,
|
||||
0xEE0E612C,
|
||||
0x990951BA,
|
||||
0x076DC419,
|
||||
0x706AF48F,
|
||||
0xE963A535,
|
||||
0x9E6495A3,
|
||||
0x0EDB8832,
|
||||
0x79DCB8A4,
|
||||
0xE0D5E91E,
|
||||
0x97D2D988,
|
||||
0x09B64C2B,
|
||||
0x7EB17CBD,
|
||||
0xE7B82D07,
|
||||
0x90BF1D91,
|
||||
0x1DB71064,
|
||||
0x6AB020F2,
|
||||
0xF3B97148,
|
||||
0x84BE41DE,
|
||||
0x1ADAD47D,
|
||||
0x6DDDE4EB,
|
||||
0xF4D4B551,
|
||||
0x83D385C7,
|
||||
0x136C9856,
|
||||
0x646BA8C0,
|
||||
0xFD62F97A,
|
||||
0x8A65C9EC,
|
||||
0x14015C4F,
|
||||
0x63066CD9,
|
||||
0xFA0F3D63,
|
||||
0x8D080DF5,
|
||||
0x3B6E20C8,
|
||||
0x4C69105E,
|
||||
0xD56041E4,
|
||||
0xA2677172,
|
||||
0x3C03E4D1,
|
||||
0x4B04D447,
|
||||
0xD20D85FD,
|
||||
0xA50AB56B,
|
||||
0x35B5A8FA,
|
||||
0x42B2986C,
|
||||
0xDBBBC9D6,
|
||||
0xACBCF940,
|
||||
0x32D86CE3,
|
||||
0x45DF5C75,
|
||||
0xDCD60DCF,
|
||||
0xABD13D59,
|
||||
0x26D930AC,
|
||||
0x51DE003A,
|
||||
0xC8D75180,
|
||||
0xBFD06116,
|
||||
0x21B4F4B5,
|
||||
0x56B3C423,
|
||||
0xCFBA9599,
|
||||
0xB8BDA50F,
|
||||
0x2802B89E,
|
||||
0x5F058808,
|
||||
0xC60CD9B2,
|
||||
0xB10BE924,
|
||||
0x2F6F7C87,
|
||||
0x58684C11,
|
||||
0xC1611DAB,
|
||||
0xB6662D3D,
|
||||
0x76DC4190,
|
||||
0x01DB7106,
|
||||
0x98D220BC,
|
||||
0xEFD5102A,
|
||||
0x71B18589,
|
||||
0x06B6B51F,
|
||||
0x9FBFE4A5,
|
||||
0xE8B8D433,
|
||||
0x7807C9A2,
|
||||
0x0F00F934,
|
||||
0x9609A88E,
|
||||
0xE10E9818,
|
||||
0x7F6A0DBB,
|
||||
0x086D3D2D,
|
||||
0x91646C97,
|
||||
0xE6635C01,
|
||||
0x6B6B51F4,
|
||||
0x1C6C6162,
|
||||
0x856530D8,
|
||||
0xF262004E,
|
||||
0x6C0695ED,
|
||||
0x1B01A57B,
|
||||
0x8208F4C1,
|
||||
0xF50FC457,
|
||||
0x65B0D9C6,
|
||||
0x12B7E950,
|
||||
0x8BBEB8EA,
|
||||
0xFCB9887C,
|
||||
0x62DD1DDF,
|
||||
0x15DA2D49,
|
||||
0x8CD37CF3,
|
||||
0xFBD44C65,
|
||||
0x4DB26158,
|
||||
0x3AB551CE,
|
||||
0xA3BC0074,
|
||||
0xD4BB30E2,
|
||||
0x4ADFA541,
|
||||
0x3DD895D7,
|
||||
0xA4D1C46D,
|
||||
0xD3D6F4FB,
|
||||
0x4369E96A,
|
||||
0x346ED9FC,
|
||||
0xAD678846,
|
||||
0xDA60B8D0,
|
||||
0x44042D73,
|
||||
0x33031DE5,
|
||||
0xAA0A4C5F,
|
||||
0xDD0D7CC9,
|
||||
0x5005713C,
|
||||
0x270241AA,
|
||||
0xBE0B1010,
|
||||
0xC90C2086,
|
||||
0x5768B525,
|
||||
0x206F85B3,
|
||||
0xB966D409,
|
||||
0xCE61E49F,
|
||||
0x5EDEF90E,
|
||||
0x29D9C998,
|
||||
0xB0D09822,
|
||||
0xC7D7A8B4,
|
||||
0x59B33D17,
|
||||
0x2EB40D81,
|
||||
0xB7BD5C3B,
|
||||
0xC0BA6CAD,
|
||||
0xEDB88320,
|
||||
0x9ABFB3B6,
|
||||
0x03B6E20C,
|
||||
0x74B1D29A,
|
||||
0xEAD54739,
|
||||
0x9DD277AF,
|
||||
0x04DB2615,
|
||||
0x73DC1683,
|
||||
0xE3630B12,
|
||||
0x94643B84,
|
||||
0x0D6D6A3E,
|
||||
0x7A6A5AA8,
|
||||
0xE40ECF0B,
|
||||
0x9309FF9D,
|
||||
0x0A00AE27,
|
||||
0x7D079EB1,
|
||||
0xF00F9344,
|
||||
0x8708A3D2,
|
||||
0x1E01F268,
|
||||
0x6906C2FE,
|
||||
0xF762575D,
|
||||
0x806567CB,
|
||||
0x196C3671,
|
||||
0x6E6B06E7,
|
||||
0xFED41B76,
|
||||
0x89D32BE0,
|
||||
0x10DA7A5A,
|
||||
0x67DD4ACC,
|
||||
0xF9B9DF6F,
|
||||
0x8EBEEFF9,
|
||||
0x17B7BE43,
|
||||
0x60B08ED5,
|
||||
0xD6D6A3E8,
|
||||
0xA1D1937E,
|
||||
0x38D8C2C4,
|
||||
0x4FDFF252,
|
||||
0xD1BB67F1,
|
||||
0xA6BC5767,
|
||||
0x3FB506DD,
|
||||
0x48B2364B,
|
||||
0xD80D2BDA,
|
||||
0xAF0A1B4C,
|
||||
0x36034AF6,
|
||||
0x41047A60,
|
||||
0xDF60EFC3,
|
||||
0xA867DF55,
|
||||
0x316E8EEF,
|
||||
0x4669BE79,
|
||||
0xCB61B38C,
|
||||
0xBC66831A,
|
||||
0x256FD2A0,
|
||||
0x5268E236,
|
||||
0xCC0C7795,
|
||||
0xBB0B4703,
|
||||
0x220216B9,
|
||||
0x5505262F,
|
||||
0xC5BA3BBE,
|
||||
0xB2BD0B28,
|
||||
0x2BB45A92,
|
||||
0x5CB36A04,
|
||||
0xC2D7FFA7,
|
||||
0xB5D0CF31,
|
||||
0x2CD99E8B,
|
||||
0x5BDEAE1D,
|
||||
0x9B64C2B0,
|
||||
0xEC63F226,
|
||||
0x756AA39C,
|
||||
0x026D930A,
|
||||
0x9C0906A9,
|
||||
0xEB0E363F,
|
||||
0x72076785,
|
||||
0x05005713,
|
||||
0x95BF4A82,
|
||||
0xE2B87A14,
|
||||
0x7BB12BAE,
|
||||
0x0CB61B38,
|
||||
0x92D28E9B,
|
||||
0xE5D5BE0D,
|
||||
0x7CDCEFB7,
|
||||
0x0BDBDF21,
|
||||
0x86D3D2D4,
|
||||
0xF1D4E242,
|
||||
0x68DDB3F8,
|
||||
0x1FDA836E,
|
||||
0x81BE16CD,
|
||||
0xF6B9265B,
|
||||
0x6FB077E1,
|
||||
0x18B74777,
|
||||
0x88085AE6,
|
||||
0xFF0F6A70,
|
||||
0x66063BCA,
|
||||
0x11010B5C,
|
||||
0x8F659EFF,
|
||||
0xF862AE69,
|
||||
0x616BFFD3,
|
||||
0x166CCF45,
|
||||
0xA00AE278,
|
||||
0xD70DD2EE,
|
||||
0x4E048354,
|
||||
0x3903B3C2,
|
||||
0xA7672661,
|
||||
0xD06016F7,
|
||||
0x4969474D,
|
||||
0x3E6E77DB,
|
||||
0xAED16A4A,
|
||||
0xD9D65ADC,
|
||||
0x40DF0B66,
|
||||
0x37D83BF0,
|
||||
0xA9BCAE53,
|
||||
0xDEBB9EC5,
|
||||
0x47B2CF7F,
|
||||
0x30B5FFE9,
|
||||
0xBDBDF21C,
|
||||
0xCABAC28A,
|
||||
0x53B39330,
|
||||
0x24B4A3A6,
|
||||
0xBAD03605,
|
||||
0xCDD70693,
|
||||
0x54DE5729,
|
||||
0x23D967BF,
|
||||
0xB3667A2E,
|
||||
0xC4614AB8,
|
||||
0x5D681B02,
|
||||
0x2A6F2B94,
|
||||
0xB40BBE37,
|
||||
0xC30C8EA1,
|
||||
0x5A05DF1B,
|
||||
0x2D02EF8D
|
||||
};
|
||||
|
||||
uint32_t ventoy_crc32(void *Buffer, uint32_t Length)
|
||||
{
|
||||
uint32_t i;
|
||||
uint8_t *Ptr = Buffer;
|
||||
uint32_t Crc = 0xFFFFFFFF;
|
||||
|
||||
for (i = 0; i < Length; i++, Ptr++)
|
||||
{
|
||||
Crc = (Crc >> 8) ^ g_crc_table[(uint8_t) Crc ^ *Ptr];
|
||||
}
|
||||
|
||||
return Crc ^ 0xffffffff;
|
||||
}
|
||||
|
207
Plugson/src/Core/ventoy_define.h
Normal file
207
Plugson/src/Core/ventoy_define.h
Normal file
@@ -0,0 +1,207 @@
|
||||
/******************************************************************************
|
||||
* ventoy_define.h
|
||||
*
|
||||
* Copyright (c) 2021, 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 __VENTOY_DEFINE_H__
|
||||
#define __VENTOY_DEFINE_H__
|
||||
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
#include <windows.h>
|
||||
#include <stdint.h>
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
#include <linux/limits.h>
|
||||
#endif
|
||||
|
||||
#define LOG_FILE "VentoyPlugson.log"
|
||||
|
||||
#define SIZE_1MB 1048576
|
||||
#define SIZE_1GB 1073741824
|
||||
#define JSON_BUF_MAX (8 * SIZE_1MB)
|
||||
#define TAR_BUF_MAX (8 * SIZE_1MB)
|
||||
|
||||
#define VTOYIMG_PART_START_BYTES (1024 * 1024)
|
||||
#define VTOYIMG_PART_START_SECTOR 2048
|
||||
|
||||
#define VTOYEFI_PART_BYTES (32 * 1024 * 1024)
|
||||
#define VTOYEFI_PART_SECTORS 65536
|
||||
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct vtoy_guid
|
||||
{
|
||||
uint32_t data1;
|
||||
uint16_t data2;
|
||||
uint16_t data3;
|
||||
uint8_t data4[8];
|
||||
}vtoy_guid;
|
||||
|
||||
typedef struct PART_TABLE
|
||||
{
|
||||
uint8_t Active; // 0x00 0x80
|
||||
|
||||
uint8_t StartHead;
|
||||
uint16_t StartSector : 6;
|
||||
uint16_t StartCylinder : 10;
|
||||
|
||||
uint8_t FsFlag;
|
||||
|
||||
uint8_t EndHead;
|
||||
uint16_t EndSector : 6;
|
||||
uint16_t EndCylinder : 10;
|
||||
|
||||
uint32_t StartSectorId;
|
||||
uint32_t SectorCount;
|
||||
}PART_TABLE;
|
||||
|
||||
typedef struct MBR_HEAD
|
||||
{
|
||||
uint8_t BootCode[446];
|
||||
PART_TABLE PartTbl[4];
|
||||
uint8_t Byte55;
|
||||
uint8_t ByteAA;
|
||||
}MBR_HEAD;
|
||||
|
||||
typedef struct VTOY_GPT_HDR
|
||||
{
|
||||
char Signature[8]; /* EFI PART */
|
||||
uint8_t Version[4];
|
||||
uint32_t Length;
|
||||
uint32_t Crc;
|
||||
uint8_t Reserved1[4];
|
||||
uint64_t EfiStartLBA;
|
||||
uint64_t EfiBackupLBA;
|
||||
uint64_t PartAreaStartLBA;
|
||||
uint64_t PartAreaEndLBA;
|
||||
vtoy_guid DiskGuid;
|
||||
uint64_t PartTblStartLBA;
|
||||
uint32_t PartTblTotNum;
|
||||
uint32_t PartTblEntryLen;
|
||||
uint32_t PartTblCrc;
|
||||
uint8_t Reserved2[420];
|
||||
}VTOY_GPT_HDR;
|
||||
|
||||
typedef struct VTOY_GPT_PART_TBL
|
||||
{
|
||||
vtoy_guid PartType;
|
||||
vtoy_guid PartGuid;
|
||||
uint64_t StartLBA;
|
||||
uint64_t LastLBA;
|
||||
uint64_t Attr;
|
||||
uint16_t Name[36];
|
||||
}VTOY_GPT_PART_TBL;
|
||||
|
||||
typedef struct VTOY_GPT_INFO
|
||||
{
|
||||
MBR_HEAD MBR;
|
||||
VTOY_GPT_HDR Head;
|
||||
VTOY_GPT_PART_TBL PartTbl[128];
|
||||
}VTOY_GPT_INFO;
|
||||
#pragma pack()
|
||||
|
||||
|
||||
#define MBR_PART_STYLE 0
|
||||
#define GPT_PART_STYLE 1
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct ventoy_guid
|
||||
{
|
||||
uint32_t data1;
|
||||
uint16_t data2;
|
||||
uint16_t data3;
|
||||
uint8_t data4[8];
|
||||
}ventoy_guid;
|
||||
#pragma pack()
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
#define VLOG_LOG 1
|
||||
#define VLOG_DEBUG 2
|
||||
|
||||
#define ulong unsigned long
|
||||
#define _ll long long
|
||||
#define _ull unsigned long long
|
||||
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
#define strlcpy(dst, src) strcpy_s(dst, sizeof(dst), src)
|
||||
#define scnprintf(dst, len, fmt, ...) sprintf_s(dst, len, fmt, ##__VA_ARGS__)
|
||||
|
||||
#define vlog(fmt, ...) ventoy_syslog(VLOG_LOG, fmt, ##__VA_ARGS__)
|
||||
#define vdebug(fmt, ...) ventoy_syslog(VLOG_DEBUG, fmt, ##__VA_ARGS__)
|
||||
|
||||
#define localtime_r(a,b) localtime_s(b,a)
|
||||
|
||||
#define LASTERR GetLastError()
|
||||
|
||||
#define CHECK_CLOSE_HANDLE(Handle) \
|
||||
{\
|
||||
if (Handle != INVALID_HANDLE_VALUE) \
|
||||
{\
|
||||
CloseHandle(Handle); \
|
||||
Handle = INVALID_HANDLE_VALUE; \
|
||||
}\
|
||||
}
|
||||
|
||||
#else
|
||||
#define strlcpy(dst, src) strncpy(dst, src, sizeof(dst) - 1)
|
||||
#define scnprintf(dst, len, fmt, args...) snprintf(dst, len, fmt, ##args)
|
||||
|
||||
#define vlog(fmt, args...) ventoy_syslog(VLOG_LOG, fmt, ##args)
|
||||
#define vdebug(fmt, args...) ventoy_syslog(VLOG_DEBUG, fmt, ##args)
|
||||
|
||||
#define MAX_PATH PATH_MAX
|
||||
|
||||
#endif
|
||||
|
||||
#define CHECK_FREE(p) \
|
||||
{\
|
||||
if (p)\
|
||||
{\
|
||||
free(p); \
|
||||
(p) = NULL; \
|
||||
}\
|
||||
}
|
||||
|
||||
void ventoy_syslog(int level, const char *Fmt, ...);
|
||||
void ventoy_set_loglevel(int level);
|
||||
uint32_t ventoy_crc32(void *Buffer, uint32_t Length);
|
||||
|
||||
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
static __inline void * zalloc(size_t n)
|
||||
#else
|
||||
static inline void * zalloc(size_t n)
|
||||
#endif
|
||||
{
|
||||
void *p = malloc(n);
|
||||
if (p) memset(p, 0, n);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
#endif /* __VENTOY_DEFINE_H__ */
|
||||
|
24
Plugson/src/Core/ventoy_disk.c
Normal file
24
Plugson/src/Core/ventoy_disk.c
Normal file
@@ -0,0 +1,24 @@
|
||||
/******************************************************************************
|
||||
* ventoy_disk.c ---- ventoy disk
|
||||
* Copyright (c) 2021, 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
|
166
Plugson/src/Core/ventoy_disk.h
Normal file
166
Plugson/src/Core/ventoy_disk.h
Normal file
@@ -0,0 +1,166 @@
|
||||
/******************************************************************************
|
||||
* ventoy_disk.h
|
||||
*
|
||||
* Copyright (c) 2021, 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 __VENTOY_DISK_H__
|
||||
#define __VENTOY_DISK_H__
|
||||
|
||||
#define MAX_DISK 256
|
||||
typedef struct ventoy_disk
|
||||
{
|
||||
char devname[64];
|
||||
|
||||
int pathcase;
|
||||
char cur_fsname[64];
|
||||
char cur_capacity[64];
|
||||
char cur_model[256];
|
||||
char cur_ventoy_ver[64];
|
||||
int cur_secureboot;
|
||||
int cur_part_style;
|
||||
|
||||
}ventoy_disk;
|
||||
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
|
||||
|
||||
|
||||
#else
|
||||
|
||||
typedef enum
|
||||
{
|
||||
VTOY_DEVICE_UNKNOWN = 0,
|
||||
VTOY_DEVICE_SCSI,
|
||||
VTOY_DEVICE_USB,
|
||||
VTOY_DEVICE_IDE,
|
||||
VTOY_DEVICE_DAC960,
|
||||
VTOY_DEVICE_CPQARRAY,
|
||||
VTOY_DEVICE_FILE,
|
||||
VTOY_DEVICE_ATARAID,
|
||||
VTOY_DEVICE_I2O,
|
||||
VTOY_DEVICE_UBD,
|
||||
VTOY_DEVICE_DASD,
|
||||
VTOY_DEVICE_VIODASD,
|
||||
VTOY_DEVICE_SX8,
|
||||
VTOY_DEVICE_DM,
|
||||
VTOY_DEVICE_XVD,
|
||||
VTOY_DEVICE_SDMMC,
|
||||
VTOY_DEVICE_VIRTBLK,
|
||||
VTOY_DEVICE_AOE,
|
||||
VTOY_DEVICE_MD,
|
||||
VTOY_DEVICE_LOOP,
|
||||
VTOY_DEVICE_NVME,
|
||||
VTOY_DEVICE_RAM,
|
||||
VTOY_DEVICE_PMEM,
|
||||
|
||||
VTOY_DEVICE_END
|
||||
}ventoy_dev_type;
|
||||
|
||||
/* from <linux/major.h> */
|
||||
#define IDE0_MAJOR 3
|
||||
#define IDE1_MAJOR 22
|
||||
#define IDE2_MAJOR 33
|
||||
#define IDE3_MAJOR 34
|
||||
#define IDE4_MAJOR 56
|
||||
#define IDE5_MAJOR 57
|
||||
#define SCSI_CDROM_MAJOR 11
|
||||
#define SCSI_DISK0_MAJOR 8
|
||||
#define SCSI_DISK1_MAJOR 65
|
||||
#define SCSI_DISK2_MAJOR 66
|
||||
#define SCSI_DISK3_MAJOR 67
|
||||
#define SCSI_DISK4_MAJOR 68
|
||||
#define SCSI_DISK5_MAJOR 69
|
||||
#define SCSI_DISK6_MAJOR 70
|
||||
#define SCSI_DISK7_MAJOR 71
|
||||
#define SCSI_DISK8_MAJOR 128
|
||||
#define SCSI_DISK9_MAJOR 129
|
||||
#define SCSI_DISK10_MAJOR 130
|
||||
#define SCSI_DISK11_MAJOR 131
|
||||
#define SCSI_DISK12_MAJOR 132
|
||||
#define SCSI_DISK13_MAJOR 133
|
||||
#define SCSI_DISK14_MAJOR 134
|
||||
#define SCSI_DISK15_MAJOR 135
|
||||
#define COMPAQ_SMART2_MAJOR 72
|
||||
#define COMPAQ_SMART2_MAJOR1 73
|
||||
#define COMPAQ_SMART2_MAJOR2 74
|
||||
#define COMPAQ_SMART2_MAJOR3 75
|
||||
#define COMPAQ_SMART2_MAJOR4 76
|
||||
#define COMPAQ_SMART2_MAJOR5 77
|
||||
#define COMPAQ_SMART2_MAJOR6 78
|
||||
#define COMPAQ_SMART2_MAJOR7 79
|
||||
#define COMPAQ_SMART_MAJOR 104
|
||||
#define COMPAQ_SMART_MAJOR1 105
|
||||
#define COMPAQ_SMART_MAJOR2 106
|
||||
#define COMPAQ_SMART_MAJOR3 107
|
||||
#define COMPAQ_SMART_MAJOR4 108
|
||||
#define COMPAQ_SMART_MAJOR5 109
|
||||
#define COMPAQ_SMART_MAJOR6 110
|
||||
#define COMPAQ_SMART_MAJOR7 111
|
||||
#define DAC960_MAJOR 48
|
||||
#define ATARAID_MAJOR 114
|
||||
#define I2O_MAJOR1 80
|
||||
#define I2O_MAJOR2 81
|
||||
#define I2O_MAJOR3 82
|
||||
#define I2O_MAJOR4 83
|
||||
#define I2O_MAJOR5 84
|
||||
#define I2O_MAJOR6 85
|
||||
#define I2O_MAJOR7 86
|
||||
#define I2O_MAJOR8 87
|
||||
#define UBD_MAJOR 98
|
||||
#define DASD_MAJOR 94
|
||||
#define VIODASD_MAJOR 112
|
||||
#define AOE_MAJOR 152
|
||||
#define SX8_MAJOR1 160
|
||||
#define SX8_MAJOR2 161
|
||||
#define XVD_MAJOR 202
|
||||
#define SDMMC_MAJOR 179
|
||||
#define LOOP_MAJOR 7
|
||||
#define MD_MAJOR 9
|
||||
#define BLKEXT_MAJOR 259
|
||||
#define RAM_MAJOR 1
|
||||
|
||||
#define SCSI_BLK_MAJOR(M) ( \
|
||||
(M) == SCSI_DISK0_MAJOR \
|
||||
|| (M) == SCSI_CDROM_MAJOR \
|
||||
|| ((M) >= SCSI_DISK1_MAJOR && (M) <= SCSI_DISK7_MAJOR) \
|
||||
|| ((M) >= SCSI_DISK8_MAJOR && (M) <= SCSI_DISK15_MAJOR))
|
||||
|
||||
#define IDE_BLK_MAJOR(M) \
|
||||
((M) == IDE0_MAJOR || \
|
||||
(M) == IDE1_MAJOR || \
|
||||
(M) == IDE2_MAJOR || \
|
||||
(M) == IDE3_MAJOR || \
|
||||
(M) == IDE4_MAJOR || \
|
||||
(M) == IDE5_MAJOR)
|
||||
|
||||
#define SX8_BLK_MAJOR(M) ((M) >= SX8_MAJOR1 && (M) <= SX8_MAJOR2)
|
||||
#define I2O_BLK_MAJOR(M) ((M) >= I2O_MAJOR1 && (M) <= I2O_MAJOR8)
|
||||
#define CPQARRAY_BLK_MAJOR(M) \
|
||||
(((M) >= COMPAQ_SMART2_MAJOR && (M) <= COMPAQ_SMART2_MAJOR7) || \
|
||||
(COMPAQ_SMART_MAJOR <= (M) && (M) <= COMPAQ_SMART_MAJOR7))
|
||||
|
||||
#endif
|
||||
|
||||
int ventoy_disk_init(void);
|
||||
void ventoy_disk_exit(void);
|
||||
int ventoy_get_disk_info(char **argv);
|
||||
const ventoy_disk * ventoy_get_disk_list(int *num);
|
||||
const ventoy_disk * ventoy_get_disk_node(int id);
|
||||
int CheckRuntimeEnvironment(char Letter, ventoy_disk *disk);
|
||||
|
||||
#endif /* __VENTOY_DISK_H__ */
|
||||
|
607
Plugson/src/Core/ventoy_disk_linux.c
Normal file
607
Plugson/src/Core/ventoy_disk_linux.c
Normal file
@@ -0,0 +1,607 @@
|
||||
/******************************************************************************
|
||||
* ventoy_disk.c ---- ventoy disk
|
||||
* Copyright (c) 2021, 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <linux/fs.h>
|
||||
#include <dirent.h>
|
||||
#include <time.h>
|
||||
#include <ventoy_define.h>
|
||||
#include <ventoy_disk.h>
|
||||
#include <ventoy_util.h>
|
||||
#include <fat_filelib.h>
|
||||
|
||||
static int g_fatlib_media_fd = 0;
|
||||
static uint64_t g_fatlib_media_offset = 0;
|
||||
|
||||
static const char *g_ventoy_dev_type_str[VTOY_DEVICE_END] =
|
||||
{
|
||||
"unknown", "scsi", "USB", "ide", "dac960",
|
||||
"cpqarray", "file", "ataraid", "i2o",
|
||||
"ubd", "dasd", "viodasd", "sx8", "dm",
|
||||
"xvd", "sd/mmc", "virtblk", "aoe",
|
||||
"md", "loopback", "nvme", "brd", "pmem"
|
||||
};
|
||||
|
||||
static const char * ventoy_get_dev_type_name(ventoy_dev_type type)
|
||||
{
|
||||
return (type < VTOY_DEVICE_END) ? g_ventoy_dev_type_str[type] : "unknown";
|
||||
}
|
||||
|
||||
static int ventoy_check_blk_major(int major, const char *type)
|
||||
{
|
||||
int flag = 0;
|
||||
int valid = 0;
|
||||
int devnum = 0;
|
||||
int len = 0;
|
||||
char line[64];
|
||||
char *pos = NULL;
|
||||
FILE *fp = NULL;
|
||||
|
||||
fp = fopen("/proc/devices", "r");
|
||||
if (!fp)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = (int)strlen(type);
|
||||
while (fgets(line, sizeof(line), fp))
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
pos = strchr(line, ' ');
|
||||
if (pos)
|
||||
{
|
||||
devnum = (int)strtol(line, NULL, 10);
|
||||
if (devnum == major)
|
||||
{
|
||||
if (strncmp(pos + 1, type, len) == 0)
|
||||
{
|
||||
valid = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (strncmp(line, "Block devices:", 14) == 0)
|
||||
{
|
||||
flag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return valid;
|
||||
}
|
||||
|
||||
static int ventoy_get_disk_devnum(const char *name, int *major, int* minor)
|
||||
{
|
||||
int rc;
|
||||
char *pos;
|
||||
char devnum[16] = {0};
|
||||
|
||||
rc = ventoy_get_sys_file_line(devnum, sizeof(devnum), "/sys/block/%s/dev", name);
|
||||
if (rc)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
pos = strstr(devnum, ":");
|
||||
if (!pos)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
*major = (int)strtol(devnum, NULL, 10);
|
||||
*minor = (int)strtol(pos + 1, NULL, 10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ventoy_dev_type ventoy_get_dev_type(const char *name, int major, int minor)
|
||||
{
|
||||
int rc;
|
||||
char syspath[128];
|
||||
char dstpath[256];
|
||||
|
||||
memset(syspath, 0, sizeof(syspath));
|
||||
memset(dstpath, 0, sizeof(dstpath));
|
||||
|
||||
scnprintf(syspath, sizeof(syspath), "/sys/block/%s", name);
|
||||
rc = readlink(syspath, dstpath, sizeof(dstpath) - 1);
|
||||
if (rc > 0 && strstr(dstpath, "/usb"))
|
||||
{
|
||||
return VTOY_DEVICE_USB;
|
||||
}
|
||||
|
||||
if (SCSI_BLK_MAJOR(major) && (minor % 0x10 == 0))
|
||||
{
|
||||
return VTOY_DEVICE_SCSI;
|
||||
}
|
||||
else if (IDE_BLK_MAJOR(major) && (minor % 0x40 == 0))
|
||||
{
|
||||
return VTOY_DEVICE_IDE;
|
||||
}
|
||||
else if (major == DAC960_MAJOR && (minor % 0x8 == 0))
|
||||
{
|
||||
return VTOY_DEVICE_DAC960;
|
||||
}
|
||||
else if (major == ATARAID_MAJOR && (minor % 0x10 == 0))
|
||||
{
|
||||
return VTOY_DEVICE_ATARAID;
|
||||
}
|
||||
else if (major == AOE_MAJOR && (minor % 0x10 == 0))
|
||||
{
|
||||
return VTOY_DEVICE_AOE;
|
||||
}
|
||||
else if (major == DASD_MAJOR && (minor % 0x4 == 0))
|
||||
{
|
||||
return VTOY_DEVICE_DASD;
|
||||
}
|
||||
else if (major == VIODASD_MAJOR && (minor % 0x8 == 0))
|
||||
{
|
||||
return VTOY_DEVICE_VIODASD;
|
||||
}
|
||||
else if (SX8_BLK_MAJOR(major) && (minor % 0x20 == 0))
|
||||
{
|
||||
return VTOY_DEVICE_SX8;
|
||||
}
|
||||
else if (I2O_BLK_MAJOR(major) && (minor % 0x10 == 0))
|
||||
{
|
||||
return VTOY_DEVICE_I2O;
|
||||
}
|
||||
else if (CPQARRAY_BLK_MAJOR(major) && (minor % 0x10 == 0))
|
||||
{
|
||||
return VTOY_DEVICE_CPQARRAY;
|
||||
}
|
||||
else if (UBD_MAJOR == major && (minor % 0x10 == 0))
|
||||
{
|
||||
return VTOY_DEVICE_UBD;
|
||||
}
|
||||
else if (XVD_MAJOR == major && (minor % 0x10 == 0))
|
||||
{
|
||||
return VTOY_DEVICE_XVD;
|
||||
}
|
||||
else if (SDMMC_MAJOR == major && (minor % 0x8 == 0))
|
||||
{
|
||||
return VTOY_DEVICE_SDMMC;
|
||||
}
|
||||
else if (ventoy_check_blk_major(major, "virtblk"))
|
||||
{
|
||||
return VTOY_DEVICE_VIRTBLK;
|
||||
}
|
||||
else if (major == LOOP_MAJOR)
|
||||
{
|
||||
return VTOY_DEVICE_LOOP;
|
||||
}
|
||||
else if (major == MD_MAJOR)
|
||||
{
|
||||
return VTOY_DEVICE_MD;
|
||||
}
|
||||
else if (major == RAM_MAJOR)
|
||||
{
|
||||
return VTOY_DEVICE_RAM;
|
||||
}
|
||||
else if (strstr(name, "nvme") && ventoy_check_blk_major(major, "blkext"))
|
||||
{
|
||||
return VTOY_DEVICE_NVME;
|
||||
}
|
||||
else if (strstr(name, "pmem") && ventoy_check_blk_major(major, "blkext"))
|
||||
{
|
||||
return VTOY_DEVICE_PMEM;
|
||||
}
|
||||
|
||||
return VTOY_DEVICE_END;
|
||||
}
|
||||
|
||||
static int ventoy_is_possible_blkdev(const char *name)
|
||||
{
|
||||
if (name[0] == '.')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* /dev/ramX */
|
||||
if (name[0] == 'r' && name[1] == 'a' && name[2] == 'm')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* /dev/zramX */
|
||||
if (name[0] == 'z' && name[1] == 'r' && name[2] == 'a' && name[3] == 'm')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* /dev/loopX */
|
||||
if (name[0] == 'l' && name[1] == 'o' && name[2] == 'o' && name[3] == 'p')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* /dev/dm-X */
|
||||
if (name[0] == 'd' && name[1] == 'm' && name[2] == '-' && isdigit(name[3]))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* /dev/srX */
|
||||
if (name[0] == 's' && name[1] == 'r' && isdigit(name[2]))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint64_t ventoy_get_disk_size_in_byte(const char *disk)
|
||||
{
|
||||
int fd;
|
||||
int rc;
|
||||
unsigned long long size = 0;
|
||||
char diskpath[256] = {0};
|
||||
char sizebuf[64] = {0};
|
||||
|
||||
// Try 1: get size from sysfs
|
||||
scnprintf(diskpath, sizeof(diskpath) - 1, "/sys/block/%s/size", disk);
|
||||
if (access(diskpath, F_OK) >= 0)
|
||||
{
|
||||
vdebug("get disk size from sysfs for %s\n", disk);
|
||||
|
||||
fd = open(diskpath, O_RDONLY | O_BINARY);
|
||||
if (fd >= 0)
|
||||
{
|
||||
read(fd, sizebuf, sizeof(sizebuf));
|
||||
size = strtoull(sizebuf, NULL, 10);
|
||||
close(fd);
|
||||
return (uint64_t)(size * 512);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vdebug("%s not exist \n", diskpath);
|
||||
}
|
||||
|
||||
// Try 2: get size from ioctl
|
||||
scnprintf(diskpath, sizeof(diskpath) - 1, "/dev/%s", disk);
|
||||
fd = open(diskpath, O_RDONLY);
|
||||
if (fd >= 0)
|
||||
{
|
||||
vdebug("get disk size from ioctl for %s\n", disk);
|
||||
rc = ioctl(fd, BLKGETSIZE64, &size);
|
||||
if (rc == -1)
|
||||
{
|
||||
size = 0;
|
||||
vdebug("failed to ioctl %d\n", rc);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
vdebug("failed to open %s %d\n", diskpath, errno);
|
||||
}
|
||||
|
||||
vdebug("disk %s size %llu bytes\n", disk, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
int ventoy_get_disk_vendor(const char *name, char *vendorbuf, int bufsize)
|
||||
{
|
||||
return ventoy_get_sys_file_line(vendorbuf, bufsize, "/sys/block/%s/device/vendor", name);
|
||||
}
|
||||
|
||||
int ventoy_get_disk_model(const char *name, char *modelbuf, int bufsize)
|
||||
{
|
||||
return ventoy_get_sys_file_line(modelbuf, bufsize, "/sys/block/%s/device/model", name);
|
||||
}
|
||||
|
||||
static int fatlib_media_sector_read(uint32 sector, uint8 *buffer, uint32 sector_count)
|
||||
{
|
||||
lseek(g_fatlib_media_fd, (sector + g_fatlib_media_offset) * 512ULL, SEEK_SET);
|
||||
read(g_fatlib_media_fd, buffer, sector_count * 512);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int fatlib_is_secure_boot_enable(void)
|
||||
{
|
||||
void *flfile = NULL;
|
||||
|
||||
flfile = fl_fopen("/EFI/BOOT/grubx64_real.efi", "rb");
|
||||
if (flfile)
|
||||
{
|
||||
vlog("/EFI/BOOT/grubx64_real.efi find, secure boot in enabled\n");
|
||||
fl_fclose(flfile);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
vlog("/EFI/BOOT/grubx64_real.efi not exist\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fatlib_get_ventoy_version(char *verbuf, int bufsize)
|
||||
{
|
||||
int rc = 1;
|
||||
int size = 0;
|
||||
char *buf = NULL;
|
||||
char *pos = NULL;
|
||||
char *end = NULL;
|
||||
void *flfile = NULL;
|
||||
|
||||
flfile = fl_fopen("/grub/grub.cfg", "rb");
|
||||
if (flfile)
|
||||
{
|
||||
fl_fseek(flfile, 0, SEEK_END);
|
||||
size = (int)fl_ftell(flfile);
|
||||
|
||||
fl_fseek(flfile, 0, SEEK_SET);
|
||||
|
||||
buf = malloc(size + 1);
|
||||
if (buf)
|
||||
{
|
||||
fl_fread(buf, 1, size, flfile);
|
||||
buf[size] = 0;
|
||||
|
||||
pos = strstr(buf, "VENTOY_VERSION=");
|
||||
if (pos)
|
||||
{
|
||||
pos += strlen("VENTOY_VERSION=");
|
||||
if (*pos == '"')
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
|
||||
end = pos;
|
||||
while (*end != 0 && *end != '"' && *end != '\r' && *end != '\n')
|
||||
{
|
||||
end++;
|
||||
}
|
||||
|
||||
*end = 0;
|
||||
|
||||
scnprintf(verbuf, bufsize - 1, "%s", pos);
|
||||
rc = 0;
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
|
||||
fl_fclose(flfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
vdebug("No grub.cfg found\n");
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* <BEGIN>: Deleted by longpanda, 20211028 PN:XX LABEL:XX */
|
||||
#if 0
|
||||
int ventoy_get_vtoy_data(ventoy_disk *info, int *ppartstyle)
|
||||
{
|
||||
int i;
|
||||
int fd;
|
||||
int len;
|
||||
int rc = 1;
|
||||
int ret = 1;
|
||||
int part_style;
|
||||
uint64_t part1_start_sector;
|
||||
uint64_t part1_sector_count;
|
||||
uint64_t part2_start_sector;
|
||||
uint64_t part2_sector_count;
|
||||
uint64_t preserved_space;
|
||||
char name[64] = {0};
|
||||
disk_ventoy_data *vtoy = NULL;
|
||||
VTOY_GPT_INFO *gpt = NULL;
|
||||
|
||||
vtoy = &(info->vtoydata);
|
||||
gpt = &(vtoy->gptinfo);
|
||||
memset(vtoy, 0, sizeof(disk_ventoy_data));
|
||||
|
||||
vdebug("ventoy_get_vtoy_data %s\n", info->disk_path);
|
||||
|
||||
if (info->size_in_byte < (2 * VTOYEFI_PART_BYTES))
|
||||
{
|
||||
vdebug("disk %s is too small %llu\n", info->disk_path, (_ull)info->size_in_byte);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fd = open(info->disk_path, O_RDONLY | O_BINARY);
|
||||
if (fd < 0)
|
||||
{
|
||||
vdebug("failed to open %s %d\n", info->disk_path, errno);
|
||||
return 1;
|
||||
}
|
||||
|
||||
len = (int)read(fd, &(vtoy->gptinfo), sizeof(VTOY_GPT_INFO));
|
||||
if (len != sizeof(VTOY_GPT_INFO))
|
||||
{
|
||||
vdebug("failed to read %s %d\n", info->disk_path, errno);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (gpt->MBR.Byte55 != 0x55 || gpt->MBR.ByteAA != 0xAA)
|
||||
{
|
||||
vdebug("Invalid mbr magic 0x%x 0x%x\n", gpt->MBR.Byte55, gpt->MBR.ByteAA);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (gpt->MBR.PartTbl[0].FsFlag == 0xEE && strncmp(gpt->Head.Signature, "EFI PART", 8) == 0)
|
||||
{
|
||||
part_style = GPT_PART_STYLE;
|
||||
if (ppartstyle)
|
||||
{
|
||||
*ppartstyle = part_style;
|
||||
}
|
||||
|
||||
if (gpt->PartTbl[0].StartLBA == 0 || gpt->PartTbl[1].StartLBA == 0)
|
||||
{
|
||||
vdebug("NO ventoy efi part layout <%llu %llu>\n",
|
||||
(_ull)gpt->PartTbl[0].StartLBA,
|
||||
(_ull)gpt->PartTbl[1].StartLBA);
|
||||
goto end;
|
||||
}
|
||||
|
||||
for (i = 0; i < 36; i++)
|
||||
{
|
||||
name[i] = (char)(gpt->PartTbl[1].Name[i]);
|
||||
}
|
||||
if (strcmp(name, "VTOYEFI"))
|
||||
{
|
||||
vdebug("Invalid efi part2 name <%s>\n", name);
|
||||
goto end;
|
||||
}
|
||||
|
||||
part1_start_sector = gpt->PartTbl[0].StartLBA;
|
||||
part1_sector_count = gpt->PartTbl[0].LastLBA - part1_start_sector + 1;
|
||||
part2_start_sector = gpt->PartTbl[1].StartLBA;
|
||||
part2_sector_count = gpt->PartTbl[1].LastLBA - part2_start_sector + 1;
|
||||
|
||||
preserved_space = info->size_in_byte - (part2_start_sector + part2_sector_count + 33) * 512;
|
||||
}
|
||||
else
|
||||
{
|
||||
part_style = MBR_PART_STYLE;
|
||||
if (ppartstyle)
|
||||
{
|
||||
*ppartstyle = part_style;
|
||||
}
|
||||
|
||||
part1_start_sector = gpt->MBR.PartTbl[0].StartSectorId;
|
||||
part1_sector_count = gpt->MBR.PartTbl[0].SectorCount;
|
||||
part2_start_sector = gpt->MBR.PartTbl[1].StartSectorId;
|
||||
part2_sector_count = gpt->MBR.PartTbl[1].SectorCount;
|
||||
|
||||
preserved_space = info->size_in_byte - (part2_start_sector + part2_sector_count) * 512;
|
||||
}
|
||||
|
||||
if (part1_start_sector != VTOYIMG_PART_START_SECTOR ||
|
||||
part2_sector_count != VTOYEFI_PART_SECTORS ||
|
||||
(part1_start_sector + part1_sector_count) != part2_start_sector)
|
||||
{
|
||||
vdebug("Not valid ventoy partition layout [%llu %llu] [%llu %llu]\n",
|
||||
part1_start_sector, part1_sector_count, part2_start_sector, part2_sector_count);
|
||||
goto end;
|
||||
}
|
||||
|
||||
vdebug("ventoy partition layout check OK: [%llu %llu] [%llu %llu]\n",
|
||||
part1_start_sector, part1_sector_count, part2_start_sector, part2_sector_count);
|
||||
|
||||
vtoy->ventoy_valid = 1;
|
||||
|
||||
vdebug("now check secure boot for %s ...\n", info->disk_path);
|
||||
|
||||
g_fatlib_media_fd = fd;
|
||||
g_fatlib_media_offset = part2_start_sector;
|
||||
fl_init();
|
||||
|
||||
if (0 == fl_attach_media(fatlib_media_sector_read, NULL))
|
||||
{
|
||||
ret = fatlib_get_ventoy_version(vtoy->ventoy_ver, sizeof(vtoy->ventoy_ver));
|
||||
if (ret == 0 && vtoy->ventoy_ver[0])
|
||||
{
|
||||
vtoy->secure_boot_flag = fatlib_is_secure_boot_enable();
|
||||
}
|
||||
else
|
||||
{
|
||||
vdebug("fatlib_get_ventoy_version failed %d\n", ret);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vdebug("fl_attach_media failed\n");
|
||||
}
|
||||
|
||||
fl_shutdown();
|
||||
g_fatlib_media_fd = -1;
|
||||
g_fatlib_media_offset = 0;
|
||||
|
||||
if (vtoy->ventoy_ver[0] == 0)
|
||||
{
|
||||
vtoy->ventoy_ver[0] = '?';
|
||||
}
|
||||
|
||||
if (0 == vtoy->ventoy_valid)
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
|
||||
lseek(fd, 2040 * 512, SEEK_SET);
|
||||
read(fd, vtoy->rsvdata, sizeof(vtoy->rsvdata));
|
||||
|
||||
vtoy->preserved_space = preserved_space;
|
||||
vtoy->partition_style = part_style;
|
||||
vtoy->part2_start_sector = part2_start_sector;
|
||||
|
||||
rc = 0;
|
||||
end:
|
||||
vtoy_safe_close_fd(fd);
|
||||
return rc;
|
||||
}
|
||||
#endif /* #if 0 */
|
||||
/* <END> : Deleted by longpanda, 20211028 PN:XX LABEL:XX */
|
||||
|
||||
|
||||
int ventoy_get_disk_info(char **argv)
|
||||
{
|
||||
uint64_t size;
|
||||
char vendor[128];
|
||||
char model[128];
|
||||
char *disk = argv[4];
|
||||
|
||||
if (strncmp(argv[4], "/dev/", 4) == 0)
|
||||
{
|
||||
disk += 4;
|
||||
}
|
||||
ventoy_get_disk_vendor(disk, vendor, sizeof(vendor));
|
||||
ventoy_get_disk_model(disk, model, sizeof(model));
|
||||
|
||||
scnprintf(g_sysinfo.cur_model, sizeof(g_sysinfo.cur_model), "%s %s [%s]", vendor, model, argv[4]);
|
||||
strlcpy(g_sysinfo.cur_ventoy_ver, argv[5]);
|
||||
strlcpy(g_sysinfo.cur_fsname, argv[6]);
|
||||
g_sysinfo.cur_part_style = (int)strtol(argv[7], NULL, 10);
|
||||
g_sysinfo.cur_secureboot = (int)strtol(argv[8], NULL, 10);
|
||||
|
||||
size = ventoy_get_disk_size_in_byte(disk);
|
||||
scnprintf(g_sysinfo.cur_capacity, sizeof(g_sysinfo.cur_capacity), "%dGB", (int)ventoy_get_human_readable_gb(size));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ventoy_disk_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ventoy_disk_exit(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
88
Plugson/src/Core/ventoy_disk_windows.c
Normal file
88
Plugson/src/Core/ventoy_disk_windows.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/******************************************************************************
|
||||
* ventoy_disk.c ---- ventoy disk
|
||||
* Copyright (c) 2021, 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 <windows.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include <ventoy_define.h>
|
||||
#include <ventoy_disk.h>
|
||||
#include <ventoy_util.h>
|
||||
#include <fat_filelib.h>
|
||||
|
||||
static int g_disk_num = 0;
|
||||
ventoy_disk *g_disk_list = NULL;
|
||||
|
||||
int ventoy_disk_init(void)
|
||||
{
|
||||
char Letter = 'A';
|
||||
DWORD Drives = GetLogicalDrives();
|
||||
|
||||
vlog("ventoy disk init ...\n");
|
||||
|
||||
g_disk_list = zalloc(sizeof(ventoy_disk) * MAX_DISK);
|
||||
|
||||
while (Drives)
|
||||
{
|
||||
if (Drives & 0x01)
|
||||
{
|
||||
if (CheckRuntimeEnvironment(Letter, g_disk_list + g_disk_num) == 0)
|
||||
{
|
||||
g_disk_list[g_disk_num].devname[0] = Letter;
|
||||
g_disk_num++;
|
||||
vlog("%C: is ventoy disk\n", Letter);
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(g_disk_list + g_disk_num, 0, sizeof(ventoy_disk));
|
||||
vlog("%C: is NOT ventoy disk\n", Letter);
|
||||
}
|
||||
}
|
||||
|
||||
Letter++;
|
||||
Drives >>= 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ventoy_disk_exit(void)
|
||||
{
|
||||
vlog("ventoy disk exit ...\n");
|
||||
|
||||
check_free(g_disk_list);
|
||||
g_disk_list = NULL;
|
||||
g_disk_num = 0;
|
||||
}
|
||||
|
||||
const ventoy_disk * ventoy_get_disk_list(int *num)
|
||||
{
|
||||
*num = g_disk_num;
|
||||
return g_disk_list;
|
||||
}
|
||||
|
||||
const ventoy_disk * ventoy_get_disk_node(int id)
|
||||
{
|
||||
if (id >= 0 && id < g_disk_num)
|
||||
{
|
||||
return g_disk_list + id;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
803
Plugson/src/Core/ventoy_json.c
Normal file
803
Plugson/src/Core/ventoy_json.c
Normal file
@@ -0,0 +1,803 @@
|
||||
/******************************************************************************
|
||||
* ventoy_json.c
|
||||
*
|
||||
* Copyright (c) 2021, 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <linux/limits.h>
|
||||
#endif
|
||||
#include <ventoy_define.h>
|
||||
#include <ventoy_util.h>
|
||||
#include <ventoy_json.h>
|
||||
|
||||
static void vtoy_json_free(VTOY_JSON *pstJsonHead)
|
||||
{
|
||||
VTOY_JSON *pstNext = NULL;
|
||||
|
||||
while (NULL != pstJsonHead)
|
||||
{
|
||||
pstNext = pstJsonHead->pstNext;
|
||||
if ((pstJsonHead->enDataType < JSON_TYPE_BUTT) && (NULL != pstJsonHead->pstChild))
|
||||
{
|
||||
vtoy_json_free(pstJsonHead->pstChild);
|
||||
}
|
||||
|
||||
free(pstJsonHead);
|
||||
pstJsonHead = pstNext;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static char *vtoy_json_skip(const char *pcData)
|
||||
{
|
||||
while ((NULL != pcData) && ('\0' != *pcData) && (*pcData <= 32))
|
||||
{
|
||||
pcData++;
|
||||
}
|
||||
|
||||
return (char *)pcData;
|
||||
}
|
||||
|
||||
VTOY_JSON *vtoy_json_find_item
|
||||
(
|
||||
VTOY_JSON *pstJson,
|
||||
JSON_TYPE enDataType,
|
||||
const char *szKey
|
||||
)
|
||||
{
|
||||
while (NULL != pstJson)
|
||||
{
|
||||
if ((enDataType == pstJson->enDataType) &&
|
||||
(0 == strcmp(szKey, pstJson->pcName)))
|
||||
{
|
||||
return pstJson;
|
||||
}
|
||||
pstJson = pstJson->pstNext;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int vtoy_json_parse_number
|
||||
(
|
||||
VTOY_JSON *pstJson,
|
||||
const char *pcData,
|
||||
const char **ppcEnd
|
||||
)
|
||||
{
|
||||
unsigned long Value;
|
||||
|
||||
Value = strtoul(pcData, (char **)ppcEnd, 10);
|
||||
if (*ppcEnd == pcData)
|
||||
{
|
||||
vdebug("Failed to parse json number %s.\n", pcData);
|
||||
return JSON_FAILED;
|
||||
}
|
||||
|
||||
pstJson->enDataType = JSON_TYPE_NUMBER;
|
||||
pstJson->unData.lValue = Value;
|
||||
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
static int vtoy_json_parse_string
|
||||
(
|
||||
char *pcNewStart,
|
||||
char *pcRawStart,
|
||||
VTOY_JSON *pstJson,
|
||||
const char *pcData,
|
||||
const char **ppcEnd
|
||||
)
|
||||
{
|
||||
uint32_t uiLen = 0;
|
||||
const char *pcPos = NULL;
|
||||
const char *pcTmp = pcData + 1;
|
||||
|
||||
*ppcEnd = pcData;
|
||||
|
||||
if ('\"' != *pcData)
|
||||
{
|
||||
return JSON_FAILED;
|
||||
}
|
||||
|
||||
pcPos = strchr(pcTmp, '\"');
|
||||
if ((NULL == pcPos) || (pcPos < pcTmp))
|
||||
{
|
||||
vdebug("Invalid string %s.\n", pcData);
|
||||
return JSON_FAILED;
|
||||
}
|
||||
|
||||
if (*(pcPos - 1) == '\\')
|
||||
{
|
||||
for (pcPos++; *pcPos; pcPos++)
|
||||
{
|
||||
if (*pcPos == '"' && *(pcPos - 1) != '\\')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (*pcPos == 0 || pcPos < pcTmp)
|
||||
{
|
||||
vdebug("Invalid quotes string %s.", pcData);
|
||||
return JSON_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
*ppcEnd = pcPos + 1;
|
||||
uiLen = (uint32_t)(unsigned long)(pcPos - pcTmp);
|
||||
|
||||
pstJson->enDataType = JSON_TYPE_STRING;
|
||||
pstJson->unData.pcStrVal = pcNewStart + (pcTmp - pcRawStart);
|
||||
pstJson->unData.pcStrVal[uiLen] = '\0';
|
||||
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
static int vtoy_json_parse_array
|
||||
(
|
||||
char *pcNewStart,
|
||||
char *pcRawStart,
|
||||
VTOY_JSON *pstJson,
|
||||
const char *pcData,
|
||||
const char **ppcEnd
|
||||
)
|
||||
{
|
||||
int Ret = JSON_SUCCESS;
|
||||
VTOY_JSON *pstJsonChild = NULL;
|
||||
VTOY_JSON *pstJsonItem = NULL;
|
||||
const char *pcTmp = pcData + 1;
|
||||
|
||||
*ppcEnd = pcData;
|
||||
pstJson->enDataType = JSON_TYPE_ARRAY;
|
||||
|
||||
if ('[' != *pcData)
|
||||
{
|
||||
return JSON_FAILED;
|
||||
}
|
||||
|
||||
pcTmp = vtoy_json_skip(pcTmp);
|
||||
|
||||
if (']' == *pcTmp)
|
||||
{
|
||||
*ppcEnd = pcTmp + 1;
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
JSON_NEW_ITEM(pstJson->pstChild, JSON_FAILED);
|
||||
|
||||
Ret = vtoy_json_parse_value(pcNewStart, pcRawStart, pstJson->pstChild, pcTmp, ppcEnd);
|
||||
if (JSON_SUCCESS != Ret)
|
||||
{
|
||||
vdebug("Failed to parse array child.\n");
|
||||
return JSON_FAILED;
|
||||
}
|
||||
|
||||
pstJsonChild = pstJson->pstChild;
|
||||
pcTmp = vtoy_json_skip(*ppcEnd);
|
||||
while ((NULL != pcTmp) && (',' == *pcTmp))
|
||||
{
|
||||
JSON_NEW_ITEM(pstJsonItem, JSON_FAILED);
|
||||
pstJsonChild->pstNext = pstJsonItem;
|
||||
pstJsonItem->pstPrev = pstJsonChild;
|
||||
pstJsonChild = pstJsonItem;
|
||||
|
||||
Ret = vtoy_json_parse_value(pcNewStart, pcRawStart, pstJsonChild, vtoy_json_skip(pcTmp + 1), ppcEnd);
|
||||
if (JSON_SUCCESS != Ret)
|
||||
{
|
||||
vdebug("Failed to parse array child.\n");
|
||||
return JSON_FAILED;
|
||||
}
|
||||
pcTmp = vtoy_json_skip(*ppcEnd);
|
||||
}
|
||||
|
||||
if ((NULL != pcTmp) && (']' == *pcTmp))
|
||||
{
|
||||
*ppcEnd = pcTmp + 1;
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ppcEnd = pcTmp;
|
||||
return JSON_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
static int vtoy_json_parse_object
|
||||
(
|
||||
char *pcNewStart,
|
||||
char *pcRawStart,
|
||||
VTOY_JSON *pstJson,
|
||||
const char *pcData,
|
||||
const char **ppcEnd
|
||||
)
|
||||
{
|
||||
int Ret = JSON_SUCCESS;
|
||||
VTOY_JSON *pstJsonChild = NULL;
|
||||
VTOY_JSON *pstJsonItem = NULL;
|
||||
const char *pcTmp = pcData + 1;
|
||||
|
||||
*ppcEnd = pcData;
|
||||
pstJson->enDataType = JSON_TYPE_OBJECT;
|
||||
|
||||
if ('{' != *pcData)
|
||||
{
|
||||
return JSON_FAILED;
|
||||
}
|
||||
|
||||
pcTmp = vtoy_json_skip(pcTmp);
|
||||
if ('}' == *pcTmp)
|
||||
{
|
||||
*ppcEnd = pcTmp + 1;
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
JSON_NEW_ITEM(pstJson->pstChild, JSON_FAILED);
|
||||
|
||||
Ret = vtoy_json_parse_string(pcNewStart, pcRawStart, pstJson->pstChild, pcTmp, ppcEnd);
|
||||
if (JSON_SUCCESS != Ret)
|
||||
{
|
||||
vdebug("Failed to parse array child.\n");
|
||||
return JSON_FAILED;
|
||||
}
|
||||
|
||||
pstJsonChild = pstJson->pstChild;
|
||||
pstJsonChild->pcName = pstJsonChild->unData.pcStrVal;
|
||||
pstJsonChild->unData.pcStrVal = NULL;
|
||||
|
||||
pcTmp = vtoy_json_skip(*ppcEnd);
|
||||
if ((NULL == pcTmp) || (':' != *pcTmp))
|
||||
{
|
||||
*ppcEnd = pcTmp;
|
||||
return JSON_FAILED;
|
||||
}
|
||||
|
||||
Ret = vtoy_json_parse_value(pcNewStart, pcRawStart, pstJsonChild, vtoy_json_skip(pcTmp + 1), ppcEnd);
|
||||
if (JSON_SUCCESS != Ret)
|
||||
{
|
||||
vdebug("Failed to parse array child.\n");
|
||||
return JSON_FAILED;
|
||||
}
|
||||
|
||||
pcTmp = vtoy_json_skip(*ppcEnd);
|
||||
while ((NULL != pcTmp) && (',' == *pcTmp))
|
||||
{
|
||||
JSON_NEW_ITEM(pstJsonItem, JSON_FAILED);
|
||||
pstJsonChild->pstNext = pstJsonItem;
|
||||
pstJsonItem->pstPrev = pstJsonChild;
|
||||
pstJsonChild = pstJsonItem;
|
||||
|
||||
Ret = vtoy_json_parse_string(pcNewStart, pcRawStart, pstJsonChild, vtoy_json_skip(pcTmp + 1), ppcEnd);
|
||||
if (JSON_SUCCESS != Ret)
|
||||
{
|
||||
vdebug("Failed to parse array child.\n");
|
||||
return JSON_FAILED;
|
||||
}
|
||||
|
||||
pcTmp = vtoy_json_skip(*ppcEnd);
|
||||
pstJsonChild->pcName = pstJsonChild->unData.pcStrVal;
|
||||
pstJsonChild->unData.pcStrVal = NULL;
|
||||
if ((NULL == pcTmp) || (':' != *pcTmp))
|
||||
{
|
||||
*ppcEnd = pcTmp;
|
||||
return JSON_FAILED;
|
||||
}
|
||||
|
||||
Ret = vtoy_json_parse_value(pcNewStart, pcRawStart, pstJsonChild, vtoy_json_skip(pcTmp + 1), ppcEnd);
|
||||
if (JSON_SUCCESS != Ret)
|
||||
{
|
||||
vdebug("Failed to parse array child.\n");
|
||||
return JSON_FAILED;
|
||||
}
|
||||
|
||||
pcTmp = vtoy_json_skip(*ppcEnd);
|
||||
}
|
||||
|
||||
if ((NULL != pcTmp) && ('}' == *pcTmp))
|
||||
{
|
||||
*ppcEnd = pcTmp + 1;
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ppcEnd = pcTmp;
|
||||
return JSON_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
int vtoy_json_parse_value
|
||||
(
|
||||
char *pcNewStart,
|
||||
char *pcRawStart,
|
||||
VTOY_JSON *pstJson,
|
||||
const char *pcData,
|
||||
const char **ppcEnd
|
||||
)
|
||||
{
|
||||
pcData = vtoy_json_skip(pcData);
|
||||
|
||||
switch (*pcData)
|
||||
{
|
||||
case 'n':
|
||||
{
|
||||
if (0 == strncmp(pcData, "null", 4))
|
||||
{
|
||||
pstJson->enDataType = JSON_TYPE_NULL;
|
||||
*ppcEnd = pcData + 4;
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'f':
|
||||
{
|
||||
if (0 == strncmp(pcData, "false", 5))
|
||||
{
|
||||
pstJson->enDataType = JSON_TYPE_BOOL;
|
||||
pstJson->unData.lValue = 0;
|
||||
*ppcEnd = pcData + 5;
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 't':
|
||||
{
|
||||
if (0 == strncmp(pcData, "true", 4))
|
||||
{
|
||||
pstJson->enDataType = JSON_TYPE_BOOL;
|
||||
pstJson->unData.lValue = 1;
|
||||
*ppcEnd = pcData + 4;
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '\"':
|
||||
{
|
||||
return vtoy_json_parse_string(pcNewStart, pcRawStart, pstJson, pcData, ppcEnd);
|
||||
}
|
||||
case '[':
|
||||
{
|
||||
return vtoy_json_parse_array(pcNewStart, pcRawStart, pstJson, pcData, ppcEnd);
|
||||
}
|
||||
case '{':
|
||||
{
|
||||
return vtoy_json_parse_object(pcNewStart, pcRawStart, pstJson, pcData, ppcEnd);
|
||||
}
|
||||
case '-':
|
||||
{
|
||||
return vtoy_json_parse_number(pstJson, pcData, ppcEnd);
|
||||
}
|
||||
default :
|
||||
{
|
||||
if (*pcData >= '0' && *pcData <= '9')
|
||||
{
|
||||
return vtoy_json_parse_number(pstJson, pcData, ppcEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*ppcEnd = pcData;
|
||||
vdebug("Invalid json data %u.\n", (uint8_t)(*pcData));
|
||||
return JSON_FAILED;
|
||||
}
|
||||
|
||||
VTOY_JSON * vtoy_json_create(void)
|
||||
{
|
||||
VTOY_JSON *pstJson = NULL;
|
||||
|
||||
pstJson = (VTOY_JSON *)zalloc(sizeof(VTOY_JSON));
|
||||
if (NULL == pstJson)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pstJson;
|
||||
}
|
||||
|
||||
int vtoy_json_parse(VTOY_JSON *pstJson, const char *szJsonData)
|
||||
{
|
||||
uint32_t uiMemSize = 0;
|
||||
int Ret = JSON_SUCCESS;
|
||||
char *pcNewBuf = NULL;
|
||||
const char *pcEnd = NULL;
|
||||
|
||||
uiMemSize = strlen(szJsonData) + 1;
|
||||
pcNewBuf = (char *)malloc(uiMemSize);
|
||||
if (NULL == pcNewBuf)
|
||||
{
|
||||
vdebug("Failed to alloc new buf.\n");
|
||||
return JSON_FAILED;
|
||||
}
|
||||
memcpy(pcNewBuf, szJsonData, uiMemSize);
|
||||
pcNewBuf[uiMemSize - 1] = 0;
|
||||
|
||||
Ret = vtoy_json_parse_value(pcNewBuf, (char *)szJsonData, pstJson, szJsonData, &pcEnd);
|
||||
if (JSON_SUCCESS != Ret)
|
||||
{
|
||||
vdebug("Failed to parse json data start=%p, end=%p.\n", szJsonData, pcEnd);
|
||||
return JSON_FAILED;
|
||||
}
|
||||
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
int vtoy_json_parse_ex(VTOY_JSON *pstJson, const char *szJsonData, int szLen)
|
||||
{
|
||||
uint32_t uiMemSize = 0;
|
||||
int Ret = JSON_SUCCESS;
|
||||
char *pcNewBuf = NULL;
|
||||
const char *pcEnd = NULL;
|
||||
|
||||
uiMemSize = (uint32_t)szLen;
|
||||
pcNewBuf = (char *)malloc(uiMemSize + 1);
|
||||
if (NULL == pcNewBuf)
|
||||
{
|
||||
vdebug("Failed to alloc new buf.\n");
|
||||
return JSON_FAILED;
|
||||
}
|
||||
memcpy(pcNewBuf, szJsonData, szLen);
|
||||
pcNewBuf[uiMemSize] = 0;
|
||||
|
||||
Ret = vtoy_json_parse_value(pcNewBuf, (char *)szJsonData, pstJson, szJsonData, &pcEnd);
|
||||
if (JSON_SUCCESS != Ret)
|
||||
{
|
||||
vdebug("Failed to parse json data start=%p, end=%p\n", szJsonData, pcEnd);
|
||||
return JSON_FAILED;
|
||||
}
|
||||
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
int vtoy_json_scan_parse
|
||||
(
|
||||
const VTOY_JSON *pstJson,
|
||||
uint32_t uiParseNum,
|
||||
VTOY_JSON_PARSE_S *pstJsonParse
|
||||
)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
const VTOY_JSON *pstJsonCur = NULL;
|
||||
VTOY_JSON_PARSE_S *pstCurParse = NULL;
|
||||
|
||||
for (pstJsonCur = pstJson; NULL != pstJsonCur; pstJsonCur = pstJsonCur->pstNext)
|
||||
{
|
||||
if ((JSON_TYPE_OBJECT == pstJsonCur->enDataType) ||
|
||||
(JSON_TYPE_ARRAY == pstJsonCur->enDataType))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (i = 0, pstCurParse = NULL; i < uiParseNum; i++)
|
||||
{
|
||||
if (0 == strcmp(pstJsonParse[i].pcKey, pstJsonCur->pcName))
|
||||
{
|
||||
pstCurParse = pstJsonParse + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL == pstCurParse)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (pstJsonCur->enDataType)
|
||||
{
|
||||
case JSON_TYPE_NUMBER:
|
||||
{
|
||||
if (sizeof(uint32_t) == pstCurParse->uiBufSize)
|
||||
{
|
||||
*(uint32_t *)(pstCurParse->pDataBuf) = (uint32_t)pstJsonCur->unData.lValue;
|
||||
}
|
||||
else if (sizeof(uint16_t) == pstCurParse->uiBufSize)
|
||||
{
|
||||
*(uint16_t *)(pstCurParse->pDataBuf) = (uint16_t)pstJsonCur->unData.lValue;
|
||||
}
|
||||
else if (sizeof(uint8_t) == pstCurParse->uiBufSize)
|
||||
{
|
||||
*(uint8_t *)(pstCurParse->pDataBuf) = (uint8_t)pstJsonCur->unData.lValue;
|
||||
}
|
||||
else if ((pstCurParse->uiBufSize > sizeof(uint64_t)))
|
||||
{
|
||||
scnprintf((char *)pstCurParse->pDataBuf, pstCurParse->uiBufSize, "%llu",
|
||||
(unsigned long long)(pstJsonCur->unData.lValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
vdebug("Invalid number data buf size %u.\n", pstCurParse->uiBufSize);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case JSON_TYPE_STRING:
|
||||
{
|
||||
scnprintf((char *)pstCurParse->pDataBuf, pstCurParse->uiBufSize, "%s", pstJsonCur->unData.pcStrVal);
|
||||
break;
|
||||
}
|
||||
case JSON_TYPE_BOOL:
|
||||
{
|
||||
*(uint8_t *)(pstCurParse->pDataBuf) = (pstJsonCur->unData.lValue) > 0 ? 1 : 0;
|
||||
break;
|
||||
}
|
||||
default :
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
int vtoy_json_scan_array
|
||||
(
|
||||
VTOY_JSON *pstJson,
|
||||
const char *szKey,
|
||||
VTOY_JSON **ppstArrayItem
|
||||
)
|
||||
{
|
||||
VTOY_JSON *pstJsonItem = NULL;
|
||||
|
||||
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_ARRAY, szKey);
|
||||
if (NULL == pstJsonItem)
|
||||
{
|
||||
vdebug("Key %s is not found in json data.\n", szKey);
|
||||
return JSON_NOT_FOUND;
|
||||
}
|
||||
|
||||
*ppstArrayItem = pstJsonItem;
|
||||
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
int vtoy_json_scan_array_ex
|
||||
(
|
||||
VTOY_JSON *pstJson,
|
||||
const char *szKey,
|
||||
VTOY_JSON **ppstArrayItem
|
||||
)
|
||||
{
|
||||
VTOY_JSON *pstJsonItem = NULL;
|
||||
|
||||
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_ARRAY, szKey);
|
||||
if (NULL == pstJsonItem)
|
||||
{
|
||||
vdebug("Key %s is not found in json data.\n", szKey);
|
||||
return JSON_NOT_FOUND;
|
||||
}
|
||||
|
||||
*ppstArrayItem = pstJsonItem->pstChild;
|
||||
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
int vtoy_json_scan_object
|
||||
(
|
||||
VTOY_JSON *pstJson,
|
||||
const char *szKey,
|
||||
VTOY_JSON **ppstObjectItem
|
||||
)
|
||||
{
|
||||
VTOY_JSON *pstJsonItem = NULL;
|
||||
|
||||
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_OBJECT, szKey);
|
||||
if (NULL == pstJsonItem)
|
||||
{
|
||||
vdebug("Key %s is not found in json data.\n", szKey);
|
||||
return JSON_NOT_FOUND;
|
||||
}
|
||||
|
||||
*ppstObjectItem = pstJsonItem;
|
||||
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
int vtoy_json_get_int
|
||||
(
|
||||
VTOY_JSON *pstJson,
|
||||
const char *szKey,
|
||||
int *piValue
|
||||
)
|
||||
{
|
||||
VTOY_JSON *pstJsonItem = NULL;
|
||||
|
||||
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_NUMBER, szKey);
|
||||
if (NULL == pstJsonItem)
|
||||
{
|
||||
//vdebug("Key %s is not found in json data.\n", szKey);
|
||||
return JSON_NOT_FOUND;
|
||||
}
|
||||
|
||||
*piValue = (int)pstJsonItem->unData.lValue;
|
||||
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
int vtoy_json_get_uint
|
||||
(
|
||||
VTOY_JSON *pstJson,
|
||||
const char *szKey,
|
||||
uint32_t *puiValue
|
||||
)
|
||||
{
|
||||
VTOY_JSON *pstJsonItem = NULL;
|
||||
|
||||
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_NUMBER, szKey);
|
||||
if (NULL == pstJsonItem)
|
||||
{
|
||||
vdebug("Key %s is not found in json data.\n", szKey);
|
||||
return JSON_NOT_FOUND;
|
||||
}
|
||||
|
||||
*puiValue = (uint32_t)pstJsonItem->unData.lValue;
|
||||
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
int vtoy_json_get_uint64
|
||||
(
|
||||
VTOY_JSON *pstJson,
|
||||
const char *szKey,
|
||||
uint64_t *pui64Value
|
||||
)
|
||||
{
|
||||
VTOY_JSON *pstJsonItem = NULL;
|
||||
|
||||
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_NUMBER, szKey);
|
||||
if (NULL == pstJsonItem)
|
||||
{
|
||||
vdebug("Key %s is not found in json data.\n", szKey);
|
||||
return JSON_NOT_FOUND;
|
||||
}
|
||||
|
||||
*pui64Value = (uint64_t)pstJsonItem->unData.lValue;
|
||||
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
int vtoy_json_get_bool
|
||||
(
|
||||
VTOY_JSON *pstJson,
|
||||
const char *szKey,
|
||||
uint8_t *pbValue
|
||||
)
|
||||
{
|
||||
VTOY_JSON *pstJsonItem = NULL;
|
||||
|
||||
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_BOOL, szKey);
|
||||
if (NULL == pstJsonItem)
|
||||
{
|
||||
vdebug("Key %s is not found in json data.\n", szKey);
|
||||
return JSON_NOT_FOUND;
|
||||
}
|
||||
|
||||
*pbValue = pstJsonItem->unData.lValue > 0 ? 1 : 0;
|
||||
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
int vtoy_json_get_string
|
||||
(
|
||||
VTOY_JSON *pstJson,
|
||||
const char *szKey,
|
||||
uint32_t uiBufLen,
|
||||
char *pcBuf
|
||||
)
|
||||
{
|
||||
VTOY_JSON *pstJsonItem = NULL;
|
||||
|
||||
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_STRING, szKey);
|
||||
if (NULL == pstJsonItem)
|
||||
{
|
||||
//vdebug("Key %s is not found in json data.\n", szKey);
|
||||
return JSON_NOT_FOUND;
|
||||
}
|
||||
|
||||
scnprintf(pcBuf, uiBufLen, "%s", pstJsonItem->unData.pcStrVal);
|
||||
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
const char * vtoy_json_get_string_ex(VTOY_JSON *pstJson, const char *szKey)
|
||||
{
|
||||
VTOY_JSON *pstJsonItem = NULL;
|
||||
|
||||
if ((NULL == pstJson) || (NULL == szKey))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_STRING, szKey);
|
||||
if (NULL == pstJsonItem)
|
||||
{
|
||||
//vdebug("Key %s is not found in json data.\n", szKey);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pstJsonItem->unData.pcStrVal;
|
||||
}
|
||||
|
||||
int vtoy_json_destroy(VTOY_JSON *pstJson)
|
||||
{
|
||||
if (NULL == pstJson)
|
||||
{
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
if (NULL != pstJson->pstChild)
|
||||
{
|
||||
vtoy_json_free(pstJson->pstChild);
|
||||
}
|
||||
|
||||
if (NULL != pstJson->pstNext)
|
||||
{
|
||||
vtoy_json_free(pstJson->pstNext);
|
||||
}
|
||||
|
||||
free(pstJson);
|
||||
|
||||
return JSON_SUCCESS;
|
||||
}
|
||||
|
||||
int vtoy_json_escape_string(char *buf, int buflen, const char *str, int newline)
|
||||
{
|
||||
char last = 0;
|
||||
int count = 0;
|
||||
|
||||
*buf++ = '"';
|
||||
count++;
|
||||
|
||||
while (*str)
|
||||
{
|
||||
if (*str == '"' && last != '\\')
|
||||
{
|
||||
*buf = '\\';
|
||||
count++;
|
||||
buf++;
|
||||
}
|
||||
|
||||
*buf = *str;
|
||||
count++;
|
||||
buf++;
|
||||
|
||||
last = *str;
|
||||
str++;
|
||||
}
|
||||
|
||||
*buf++ = '"';
|
||||
count++;
|
||||
|
||||
*buf++ = ',';
|
||||
count++;
|
||||
|
||||
if (newline)
|
||||
{
|
||||
*buf++ = '\n';
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
436
Plugson/src/Core/ventoy_json.h
Normal file
436
Plugson/src/Core/ventoy_json.h
Normal file
@@ -0,0 +1,436 @@
|
||||
/******************************************************************************
|
||||
* ventoy_json.h
|
||||
*
|
||||
* Copyright (c) 2021, 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 __VENTOY_JSON_H__
|
||||
#define __VENTOY_JSON_H__
|
||||
|
||||
#define JSON_NEW_ITEM(pstJson, ret) \
|
||||
{ \
|
||||
(pstJson) = (VTOY_JSON *)zalloc(sizeof(VTOY_JSON)); \
|
||||
if (NULL == (pstJson)) \
|
||||
{ \
|
||||
vdebug("Failed to alloc memory for json."); \
|
||||
return (ret); \
|
||||
} \
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
#define ssprintf(curpos, buf, len, fmt, ...) \
|
||||
curpos += scnprintf(buf + curpos, len - curpos, fmt, ##__VA_ARGS__)
|
||||
|
||||
#define VTOY_JSON_IS_SKIPABLE(c) (((c) <= 32) ? 1 : 0)
|
||||
|
||||
#define VTOY_JSON_PRINT_PREFIX(uiDepth, ...) \
|
||||
{ \
|
||||
uint32_t _uiLoop = 0; \
|
||||
for (_uiLoop = 0; _uiLoop < (uiDepth); _uiLoop++) \
|
||||
{ \
|
||||
ssprintf(uiCurPos, pcBuf, uiBufLen, " "); \
|
||||
} \
|
||||
ssprintf(uiCurPos, pcBuf, uiBufLen, ##__VA_ARGS__); \
|
||||
}
|
||||
#else
|
||||
|
||||
#define ssprintf(curpos, buf, len, fmt, args...) \
|
||||
curpos += scnprintf(buf + curpos, len - curpos, fmt, ##args)
|
||||
|
||||
#define VTOY_JSON_IS_SKIPABLE(c) (((c) <= 32) ? 1 : 0)
|
||||
|
||||
#define VTOY_JSON_PRINT_PREFIX(uiDepth, args...) \
|
||||
{ \
|
||||
uint32_t _uiLoop = 0; \
|
||||
for (_uiLoop = 0; _uiLoop < (uiDepth); _uiLoop++) \
|
||||
{ \
|
||||
ssprintf(uiCurPos, pcBuf, uiBufLen, " "); \
|
||||
} \
|
||||
ssprintf(uiCurPos, pcBuf, uiBufLen, ##args); \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#define VTOY_JSON_SUCCESS_RET "{ \"result\" : \"success\" }"
|
||||
#define VTOY_JSON_FAILED_RET "{ \"result\" : \"failed\" }"
|
||||
#define VTOY_JSON_INVALID_RET "{ \"result\" : \"invalidfmt\" }"
|
||||
#define VTOY_JSON_TOKEN_ERR_RET "{ \"result\" : \"tokenerror\" }"
|
||||
#define VTOY_JSON_EXIST_RET "{ \"result\" : \"exist\" }"
|
||||
#define VTOY_JSON_TIMEOUT_RET "{ \"result\" : \"timeout\" }"
|
||||
#define VTOY_JSON_BUSY_RET "{ \"result\" : \"busy\" }"
|
||||
#define VTOY_JSON_INUSE_RET "{ \"result\" : \"inuse\" }"
|
||||
#define VTOY_JSON_NOTFOUND_RET "{ \"result\" : \"notfound\" }"
|
||||
#define VTOY_JSON_NOTRUNNING_RET "{ \"result\" : \"notrunning\" }"
|
||||
#define VTOY_JSON_NOT_READY_RET "{ \"result\" : \"notready\" }"
|
||||
#define VTOY_JSON_NOT_SUPPORT_RET "{ \"result\" : \"notsupport\" }"
|
||||
#define VTOY_JSON_MBR_2TB_RET "{ \"result\" : \"mbr2tb\" }"
|
||||
#define VTOY_JSON_INVALID_RSV_RET "{ \"result\" : \"reserve_invalid\" }"
|
||||
#define VTOY_JSON_FILE_NOT_FOUND_RET "{ \"result\" : \"file_not_found\" }"
|
||||
|
||||
typedef enum tagJSON_TYPE
|
||||
{
|
||||
JSON_TYPE_NUMBER = 0,
|
||||
JSON_TYPE_STRING,
|
||||
JSON_TYPE_BOOL,
|
||||
JSON_TYPE_ARRAY,
|
||||
JSON_TYPE_OBJECT,
|
||||
JSON_TYPE_NULL,
|
||||
JSON_TYPE_BUTT
|
||||
}JSON_TYPE;
|
||||
|
||||
typedef struct tagVTOY_JSON
|
||||
{
|
||||
struct tagVTOY_JSON *pstPrev;
|
||||
struct tagVTOY_JSON *pstNext;
|
||||
struct tagVTOY_JSON *pstChild;
|
||||
|
||||
JSON_TYPE enDataType;
|
||||
union
|
||||
{
|
||||
char *pcStrVal;
|
||||
int iNumVal;
|
||||
uint64_t lValue;
|
||||
}unData;
|
||||
|
||||
char *pcName;
|
||||
}VTOY_JSON;
|
||||
|
||||
#define VTOY_JSON_FMT_BEGIN(uiCurPos, pcBuf, uiBufLen) \
|
||||
{\
|
||||
uint32_t __uiCurPos = (uiCurPos);\
|
||||
uint32_t __uiBufLen = (uiBufLen);\
|
||||
char *__pcBuf = (pcBuf);
|
||||
|
||||
#define VTOY_JSON_FMT_END(uiCurPos) \
|
||||
(uiCurPos) = __uiCurPos;\
|
||||
}
|
||||
|
||||
#define VTOY_JSON_FMT_OBJ_BEGIN() ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "{")
|
||||
#define VTOY_JSON_FMT_OBJ_BEGIN_L(P) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s{", P)
|
||||
#define VTOY_JSON_FMT_OBJ_BEGIN_N() ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "{\n")
|
||||
#define VTOY_JSON_FMT_OBJ_BEGIN_LN(P) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s{\n", P)
|
||||
|
||||
#define VTOY_JSON_FMT_OBJ_END() \
|
||||
{\
|
||||
if (',' == *(__pcBuf + (__uiCurPos - 1)))\
|
||||
{\
|
||||
__uiCurPos -= 1;\
|
||||
}\
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "}");\
|
||||
}
|
||||
|
||||
#define VTOY_JSON_FMT_OBJ_ENDEX() \
|
||||
{\
|
||||
if (',' == *(__pcBuf + (__uiCurPos - 1)))\
|
||||
{\
|
||||
__uiCurPos -= 1;\
|
||||
}\
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "},");\
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define VTOY_JSON_FMT_KEY(Key) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\":", (Key))
|
||||
#define VTOY_JSON_FMT_KEY_L(P, Key) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\":", P, (Key))
|
||||
|
||||
|
||||
#define VTOY_JSON_FMT_ITEM(Item) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\",", (Item))
|
||||
#define VTOY_JSON_FMT_ITEM_L(P, Item) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\",", P, (Item))
|
||||
#define VTOY_JSON_FMT_ITEM_LN(P, Item) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\",\n", P, (Item))
|
||||
#define VTOY_JSON_FMT_ITEM_PATH_LN(P, Item) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\",\n", P, ventoy_real_path(Item))
|
||||
|
||||
#define VTOY_JSON_FMT_COMA() ssprintf(__uiCurPos, __pcBuf, __uiBufLen, ",")
|
||||
#define VTOY_JSON_FMT_COMA_N(cnt) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, ",\n")
|
||||
#define VTOY_JSON_FMT_COMA_N_CNT(cnt) if ((cnt) > 0) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, ",\n")
|
||||
|
||||
|
||||
#define VTOY_JSON_FMT_APPEND_BEGIN() \
|
||||
{ \
|
||||
if ('}' == *(__pcBuf + (__uiCurPos - 1)))\
|
||||
{\
|
||||
__uiCurPos -= 1;\
|
||||
}\
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, ",");\
|
||||
}
|
||||
|
||||
#define VTOY_JSON_FMT_APPEND_END() \
|
||||
{ \
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "}");\
|
||||
}
|
||||
|
||||
#define VTOY_JSON_FMT_ARY_BEGIN() ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "[")
|
||||
#define VTOY_JSON_FMT_ARY_BEGIN_N() ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "[\n")
|
||||
|
||||
#define VTOY_JSON_FMT_ARY_END() \
|
||||
{\
|
||||
if (',' == *(__pcBuf + (__uiCurPos - 1)))\
|
||||
{\
|
||||
__uiCurPos -= 1;\
|
||||
}\
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "]");\
|
||||
}
|
||||
#define VTOY_JSON_FMT_ARY_ENDEX() \
|
||||
{\
|
||||
if (',' == *(__pcBuf + (__uiCurPos - 1)))\
|
||||
{\
|
||||
__uiCurPos -= 1;\
|
||||
}\
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "],");\
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define VTOY_JSON_FMT_OBJ_END_L(P) \
|
||||
{\
|
||||
if ('\n' == *(__pcBuf + (__uiCurPos - 1)) && ',' == *(__pcBuf + (__uiCurPos - 2)))\
|
||||
{\
|
||||
*(__pcBuf + (__uiCurPos - 2)) = '\n';\
|
||||
__uiCurPos -= 1;\
|
||||
}\
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s}%s", P);\
|
||||
}
|
||||
#define VTOY_JSON_FMT_OBJ_ENDEX_L(P) \
|
||||
{\
|
||||
if ('\n' == *(__pcBuf + (__uiCurPos - 1)) && ',' == *(__pcBuf + (__uiCurPos - 2)))\
|
||||
{\
|
||||
*(__pcBuf + (__uiCurPos - 2)) = '\n';\
|
||||
__uiCurPos -= 1;\
|
||||
}\
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s},%s", P);\
|
||||
}
|
||||
|
||||
#define VTOY_JSON_FMT_OBJ_END_LN(P) \
|
||||
{\
|
||||
if ('\n' == *(__pcBuf + (__uiCurPos - 1)) && ',' == *(__pcBuf + (__uiCurPos - 2)))\
|
||||
{\
|
||||
*(__pcBuf + (__uiCurPos - 2)) = '\n';\
|
||||
__uiCurPos -= 1;\
|
||||
}\
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s}\n", P);\
|
||||
}
|
||||
#define VTOY_JSON_FMT_OBJ_ENDEX_LN(P) \
|
||||
{\
|
||||
if ('\n' == *(__pcBuf + (__uiCurPos - 1)) && ',' == *(__pcBuf + (__uiCurPos - 2)))\
|
||||
{\
|
||||
*(__pcBuf + (__uiCurPos - 2)) = '\n';\
|
||||
__uiCurPos -= 1;\
|
||||
}\
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s},\n", P);\
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#define VTOY_JSON_FMT_ARY_END_L(P) \
|
||||
{\
|
||||
if ('\n' == *(__pcBuf + (__uiCurPos - 1)) && ',' == *(__pcBuf + (__uiCurPos - 2)))\
|
||||
{\
|
||||
*(__pcBuf + (__uiCurPos - 2)) = '\n';\
|
||||
__uiCurPos -= 1;\
|
||||
}\
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s]", P);\
|
||||
}
|
||||
|
||||
#define VTOY_JSON_FMT_ARY_END_LN(P) \
|
||||
{\
|
||||
if ('\n' == *(__pcBuf + (__uiCurPos - 1)) && ',' == *(__pcBuf + (__uiCurPos - 2)))\
|
||||
{\
|
||||
*(__pcBuf + (__uiCurPos - 2)) = '\n';\
|
||||
__uiCurPos -= 1;\
|
||||
}\
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s]\n", P);\
|
||||
}
|
||||
|
||||
#define VTOY_JSON_FMT_ARY_ENDEX_L(P) \
|
||||
{\
|
||||
if ('\n' == *(__pcBuf + (__uiCurPos - 1)) && ',' == *(__pcBuf + (__uiCurPos - 2)))\
|
||||
{\
|
||||
*(__pcBuf + (__uiCurPos - 2)) = '\n';\
|
||||
__uiCurPos -= 1;\
|
||||
}\
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s],", P);\
|
||||
}
|
||||
|
||||
|
||||
#define VTOY_JSON_FMT_ARY_ENDEX_LN(P) \
|
||||
{\
|
||||
if ('\n' == *(__pcBuf + (__uiCurPos - 1)) && ',' == *(__pcBuf + (__uiCurPos - 2)))\
|
||||
{\
|
||||
*(__pcBuf + (__uiCurPos - 2)) = '\n';\
|
||||
__uiCurPos -= 1;\
|
||||
}\
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s],\n", P);\
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#define VTOY_JSON_FMT_UINT64(Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": %llu,", Key, (_ull)Val)
|
||||
|
||||
#define VTOY_JSON_FMT_ULONG(Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": %lu,", Key, Val)
|
||||
#define VTOY_JSON_FMT_LONG(Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": %ld,", Key, Val)
|
||||
|
||||
#define VTOY_JSON_FMT_UINT(Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": %u,", Key, Val)
|
||||
#define VTOY_JSON_FMT_UINT_N(Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": %u,\n", Key, Val)
|
||||
#define VTOY_JSON_FMT_UINT_L(P, Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\": %u,", P, Key, Val)
|
||||
#define VTOY_JSON_FMT_UINT_LN(P, Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\": %u,\n", P, Key, Val)
|
||||
|
||||
|
||||
#define VTOY_JSON_FMT_STRUINT(Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": \"%u\",", Key, Val)
|
||||
#define VTOY_JSON_FMT_STRUINT_N(Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": \"%u\",\n", Key, Val)
|
||||
#define VTOY_JSON_FMT_STRUINT_L(P, Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\": \"%u\",", P, Key, Val)
|
||||
#define VTOY_JSON_FMT_STRUINT_LN(P, Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\": \"%u\",\n", P, Key, Val)
|
||||
|
||||
#define VTOY_JSON_FMT_STRSINT(Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": \"%d\",", Key, Val)
|
||||
#define VTOY_JSON_FMT_STRSINT_N(Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": \"%d\",\n", Key, Val)
|
||||
#define VTOY_JSON_FMT_STRSINT_L(P, Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\": \"%d\",", P, Key, Val)
|
||||
#define VTOY_JSON_FMT_STRSINT_LN(P, Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\": \"%d\",\n", P, Key, Val)
|
||||
|
||||
#define VTOY_JSON_FMT_CTRL_INT(Prefix, Key, Field) \
|
||||
if (def->Field != data->Field) \
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s{ \"%s\": \"%d\" },\n", Prefix, Key, data->Field)
|
||||
|
||||
#define VTOY_JSON_FMT_CTRL_STRN(P, Key, Field) \
|
||||
if (strcmp(def->Field, data->Field)) \
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s{ \"%s\": \"%s\" },\n", P, Key, data->Field)
|
||||
|
||||
#define VTOY_JSON_FMT_CTRL_STRN_STR(P, Key, ptr) \
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s{ \"%s\": \"%s\" },\n", P, Key, ptr)
|
||||
|
||||
#define VTOY_JSON_FMT_CTRL_PUB_STRN(P, Key, Field) \
|
||||
if (strcmp(def->Field, g_pub_path)) \
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s{ \"%s\": \"%s\" },\n", P, Key, g_pub_path)
|
||||
|
||||
|
||||
#define VTOY_JSON_FMT_DIFF_STRN(P, Key, Field) \
|
||||
if (strcmp(def->Field, data->Field)) \
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\": \"%s\",\n", P, Key, data->Field)
|
||||
|
||||
|
||||
#define VTOY_JSON_FMT_STRINT64(Key, Val) \
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": \"%llu\",", Key, Val)
|
||||
|
||||
#define VTOY_JSON_FMT_SINT(Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": %d,", Key, Val)
|
||||
#define VTOY_JSON_FMT_SINT_N(Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": %d,\n", Key, Val)
|
||||
#define VTOY_JSON_FMT_SINT_L(P, Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\": %d,", P, Key, Val)
|
||||
#define VTOY_JSON_FMT_SINT_LN(P, Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\": %d,\n", P, Key, Val)
|
||||
|
||||
#define VTOY_JSON_FMT_DUBL(Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": %.1lf,", Key, Val)
|
||||
#define VTOY_JSON_FMT_DUBL2(Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": %10.02lf,", Key, Val)
|
||||
|
||||
#define VTOY_JSON_FMT_STRN(Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": \"%s\",", Key, Val)
|
||||
#define VTOY_JSON_FMT_STRN_N(Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": \"%s\",\n", Key, Val)
|
||||
#define VTOY_JSON_FMT_STRN_L(P, Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\": \"%s\",", P, Key, Val)
|
||||
#define VTOY_JSON_FMT_STRN_LN(P, Key, Val) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\": \"%s\",\n", P, Key, Val)
|
||||
#define VTOY_JSON_FMT_STRN_PATH_LN(P, Key, Val) \
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\": \"%s\",\n", P, Key, ventoy_real_path(Val))
|
||||
|
||||
int vtoy_json_escape_string(char *buf, int buflen, const char *str, int newline);
|
||||
|
||||
#define VTOY_JSON_FMT_STRN_EX_LN(P, Key, Val) \
|
||||
{\
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "%s\"%s\": ", P, Key);\
|
||||
__uiCurPos += vtoy_json_escape_string(__pcBuf + __uiCurPos, __uiBufLen - __uiCurPos, Val, 1);\
|
||||
}
|
||||
|
||||
|
||||
#define VTOY_JSON_FMT_NULL(Key) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": null,", Key)
|
||||
|
||||
#define VTOY_JSON_FMT_TRUE(Key) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": true,", (Key))
|
||||
#define VTOY_JSON_FMT_FALSE(Key) ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": false,", (Key))
|
||||
|
||||
#define VTOY_JSON_FMT_BOOL(Key, Val) \
|
||||
{\
|
||||
if (0 == (Val))\
|
||||
{\
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": false,", (Key));\
|
||||
}\
|
||||
else \
|
||||
{\
|
||||
ssprintf(__uiCurPos, __pcBuf, __uiBufLen, "\"%s\": true,", (Key));\
|
||||
}\
|
||||
}
|
||||
|
||||
typedef struct tagVTOY_JSON_PARSE
|
||||
{
|
||||
char *pcKey;
|
||||
void *pDataBuf;
|
||||
uint32_t uiBufSize;
|
||||
}VTOY_JSON_PARSE_S;
|
||||
|
||||
#define JSON_SUCCESS 0
|
||||
#define JSON_FAILED 1
|
||||
#define JSON_NOT_FOUND 2
|
||||
|
||||
int vtoy_json_parse_value
|
||||
(
|
||||
char *pcNewStart,
|
||||
char *pcRawStart,
|
||||
VTOY_JSON *pstJson,
|
||||
const char *pcData,
|
||||
const char **ppcEnd
|
||||
);
|
||||
VTOY_JSON * vtoy_json_create(void);
|
||||
int vtoy_json_parse(VTOY_JSON *pstJson, const char *szJsonData);
|
||||
int vtoy_json_parse_ex(VTOY_JSON *pstJson, const char *szJsonData, int szLen);
|
||||
int vtoy_json_destroy(VTOY_JSON *pstJson);
|
||||
VTOY_JSON *vtoy_json_find_item
|
||||
(
|
||||
VTOY_JSON *pstJson,
|
||||
JSON_TYPE enDataType,
|
||||
const char *szKey
|
||||
);
|
||||
int vtoy_json_scan_parse
|
||||
(
|
||||
const VTOY_JSON *pstJson,
|
||||
uint32_t uiParseNum,
|
||||
VTOY_JSON_PARSE_S *pstJsonParse
|
||||
);
|
||||
int vtoy_json_get_int
|
||||
(
|
||||
VTOY_JSON *pstJson,
|
||||
const char *szKey,
|
||||
int *piValue
|
||||
);
|
||||
int vtoy_json_get_uint
|
||||
(
|
||||
VTOY_JSON *pstJson,
|
||||
const char *szKey,
|
||||
uint32_t *puiValue
|
||||
);
|
||||
int vtoy_json_get_uint64
|
||||
(
|
||||
VTOY_JSON *pstJson,
|
||||
const char *szKey,
|
||||
uint64_t *pui64Value
|
||||
);
|
||||
int vtoy_json_get_bool
|
||||
(
|
||||
VTOY_JSON *pstJson,
|
||||
const char *szKey,
|
||||
uint8_t *pbValue
|
||||
);
|
||||
int vtoy_json_get_string
|
||||
(
|
||||
VTOY_JSON *pstJson,
|
||||
const char *szKey,
|
||||
uint32_t uiBufLen,
|
||||
char *pcBuf
|
||||
);
|
||||
const char * vtoy_json_get_string_ex(VTOY_JSON *pstJson, const char *szKey);
|
||||
|
||||
#endif /* __VENTOY_JSON_H__ */
|
||||
|
151
Plugson/src/Core/ventoy_log.c
Normal file
151
Plugson/src/Core/ventoy_log.c
Normal file
@@ -0,0 +1,151 @@
|
||||
/******************************************************************************
|
||||
* ventoy_log.c ---- ventoy log
|
||||
*
|
||||
* Copyright (c) 2021, 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <ventoy_define.h>
|
||||
#include <ventoy_util.h>
|
||||
|
||||
extern char g_log_file[MAX_PATH];
|
||||
static int g_ventoy_log_level = VLOG_DEBUG;
|
||||
static pthread_mutex_t g_log_mutex;
|
||||
|
||||
int ventoy_log_init(void)
|
||||
{
|
||||
if (ventoy_get_file_size(g_log_file) >= SIZE_1MB)
|
||||
{
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
DeleteFileA(g_log_file);
|
||||
#else
|
||||
remove(g_log_file);
|
||||
#endif
|
||||
}
|
||||
|
||||
pthread_mutex_init(&g_log_mutex, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ventoy_log_exit(void)
|
||||
{
|
||||
pthread_mutex_destroy(&g_log_mutex);
|
||||
}
|
||||
|
||||
void ventoy_set_loglevel(int level)
|
||||
{
|
||||
g_ventoy_log_level = level;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ventoy_syslog_printf(const char *Fmt, ...)
|
||||
{
|
||||
char log[512];
|
||||
va_list arg;
|
||||
time_t stamp;
|
||||
struct tm ttm;
|
||||
FILE *fp;
|
||||
|
||||
time(&stamp);
|
||||
localtime_r(&stamp, &ttm);
|
||||
|
||||
va_start(arg, Fmt);
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
vsnprintf_s(log, 512, _TRUNCATE, Fmt, arg);
|
||||
#else
|
||||
vsnprintf(log, 512, Fmt, arg);
|
||||
#endif
|
||||
va_end(arg);
|
||||
|
||||
pthread_mutex_lock(&g_log_mutex);
|
||||
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
fopen_s(&fp, g_log_file, "a+");
|
||||
#else
|
||||
fp = fopen(g_log_file, "a+");
|
||||
#endif
|
||||
|
||||
if (fp)
|
||||
{
|
||||
fprintf(fp, "[%04u/%02u/%02u %02u:%02u:%02u] %s",
|
||||
ttm.tm_year, ttm.tm_mon + 1, ttm.tm_mday,
|
||||
ttm.tm_hour, ttm.tm_min, ttm.tm_sec,
|
||||
log);
|
||||
fclose(fp);
|
||||
|
||||
#ifdef VENTOY_SIM
|
||||
printf("[%04u/%02u/%02u %02u:%02u:%02u] %s",
|
||||
ttm.tm_year, ttm.tm_mon + 1, ttm.tm_mday,
|
||||
ttm.tm_hour, ttm.tm_min, ttm.tm_sec,
|
||||
log);
|
||||
#endif
|
||||
}
|
||||
pthread_mutex_unlock(&g_log_mutex);
|
||||
}
|
||||
|
||||
void ventoy_syslog(int level, const char *Fmt, ...)
|
||||
{
|
||||
char log[512];
|
||||
va_list arg;
|
||||
time_t stamp;
|
||||
struct tm ttm;
|
||||
FILE *fp;
|
||||
|
||||
if (level > g_ventoy_log_level)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
time(&stamp);
|
||||
localtime_r(&stamp, &ttm);
|
||||
|
||||
va_start(arg, Fmt);
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
vsnprintf_s(log, 512, _TRUNCATE, Fmt, arg);
|
||||
#else
|
||||
vsnprintf(log, 512, Fmt, arg);
|
||||
#endif
|
||||
va_end(arg);
|
||||
|
||||
pthread_mutex_lock(&g_log_mutex);
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
fopen_s(&fp, g_log_file, "a+");
|
||||
#else
|
||||
fp = fopen(g_log_file, "a+");
|
||||
#endif
|
||||
if (fp)
|
||||
{
|
||||
fprintf(fp, "[%04u/%02u/%02u %02u:%02u:%02u] %s",
|
||||
ttm.tm_year + 1900, ttm.tm_mon + 1, ttm.tm_mday,
|
||||
ttm.tm_hour, ttm.tm_min, ttm.tm_sec,
|
||||
log);
|
||||
fclose(fp);
|
||||
|
||||
#ifdef VENTOY_SIM
|
||||
printf("[%04u/%02u/%02u %02u:%02u:%02u] %s",
|
||||
ttm.tm_year + 1900, ttm.tm_mon + 1, ttm.tm_mday,
|
||||
ttm.tm_hour, ttm.tm_min, ttm.tm_sec,
|
||||
log);
|
||||
#endif
|
||||
}
|
||||
pthread_mutex_unlock(&g_log_mutex);
|
||||
}
|
||||
|
166
Plugson/src/Core/ventoy_md5.c
Normal file
166
Plugson/src/Core/ventoy_md5.c
Normal file
@@ -0,0 +1,166 @@
|
||||
/******************************************************************************
|
||||
* ventoy_md5.c ---- ventoy md5
|
||||
*
|
||||
* Copyright (c) 2021, 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
const static uint32_t k[64] =
|
||||
{
|
||||
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
|
||||
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
|
||||
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
|
||||
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
|
||||
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
|
||||
0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
|
||||
0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
|
||||
0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
|
||||
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
|
||||
0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
|
||||
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
|
||||
0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
|
||||
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
|
||||
0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
|
||||
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
|
||||
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
|
||||
};
|
||||
|
||||
const static uint32_t r[] =
|
||||
{
|
||||
7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
|
||||
5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
|
||||
4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
|
||||
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21
|
||||
};
|
||||
|
||||
#define LEFTROTATE(x, c) (((x) << (c)) | ((x) >> (32 - (c))))
|
||||
#define to_bytes(val, bytes) *((uint32_t *)(bytes)) = (val)
|
||||
|
||||
#define ROTATE_CALC() \
|
||||
{\
|
||||
temp = d; \
|
||||
d = c; \
|
||||
c = b; \
|
||||
b = b + LEFTROTATE((a + f + k[i] + w[g]), r[i]); \
|
||||
a = temp; \
|
||||
}
|
||||
|
||||
void ventoy_md5(const void *data, uint32_t len, uint8_t *md5)
|
||||
{
|
||||
uint32_t h0, h1, h2, h3;
|
||||
uint32_t w[16];
|
||||
uint32_t a, b, c, d, i, f, g, temp;
|
||||
uint32_t offset, mod, delta;
|
||||
uint8_t postbuf[128] = {0};
|
||||
|
||||
// Initialize variables - simple count in nibbles:
|
||||
h0 = 0x67452301;
|
||||
h1 = 0xefcdab89;
|
||||
h2 = 0x98badcfe;
|
||||
h3 = 0x10325476;
|
||||
|
||||
//Pre-processing:
|
||||
//append "1" bit to message
|
||||
//append "0" bits until message length in bits <20><> 448 (mod 512)
|
||||
//append length mod (2^64) to message
|
||||
|
||||
mod = len % 64;
|
||||
if (mod)
|
||||
{
|
||||
memcpy(postbuf, (const uint8_t *)data + len - mod, mod);
|
||||
}
|
||||
|
||||
postbuf[mod] = 0x80;
|
||||
if (mod < 56)
|
||||
{
|
||||
to_bytes(len * 8, postbuf + 56);
|
||||
to_bytes(len >> 29, postbuf + 60);
|
||||
delta = 64;
|
||||
}
|
||||
else
|
||||
{
|
||||
to_bytes(len * 8, postbuf + 120);
|
||||
to_bytes(len >> 29, postbuf + 124);
|
||||
delta = 128;
|
||||
}
|
||||
|
||||
len -= mod;
|
||||
|
||||
for (offset = 0; offset < len + delta; offset += 64)
|
||||
{
|
||||
if (offset < len)
|
||||
{
|
||||
memcpy(w, (const uint8_t *)data + offset, 64);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(w, postbuf + offset - len, 64);
|
||||
}
|
||||
|
||||
// Initialize hash value for this chunk:
|
||||
a = h0;
|
||||
b = h1;
|
||||
c = h2;
|
||||
d = h3;
|
||||
|
||||
// Main loop:
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
f = (b & c) | ((~b) & d);
|
||||
g = i;
|
||||
ROTATE_CALC();
|
||||
}
|
||||
|
||||
for (i = 16; i < 32; i++)
|
||||
{
|
||||
f = (d & b) | ((~d) & c);
|
||||
g = (5 * i + 1) % 16;
|
||||
ROTATE_CALC();
|
||||
}
|
||||
|
||||
for (i = 32; i < 48; i++)
|
||||
{
|
||||
f = b ^ c ^ d;
|
||||
g = (3 * i + 5) % 16;
|
||||
ROTATE_CALC();
|
||||
}
|
||||
|
||||
for (i = 48; i < 64; i++)
|
||||
{
|
||||
f = c ^ (b | (~d));
|
||||
g = (7 * i) % 16;
|
||||
ROTATE_CALC();
|
||||
}
|
||||
|
||||
// Add this chunk's hash to result so far:
|
||||
h0 += a;
|
||||
h1 += b;
|
||||
h2 += c;
|
||||
h3 += d;
|
||||
}
|
||||
|
||||
//var char md5[16] := h0 append h1 append h2 append h3 //(Output is in little-endian)
|
||||
to_bytes(h0, md5);
|
||||
to_bytes(h1, md5 + 4);
|
||||
to_bytes(h2, md5 + 8);
|
||||
to_bytes(h3, md5 + 12);
|
||||
}
|
||||
|
260
Plugson/src/Core/ventoy_util.c
Normal file
260
Plugson/src/Core/ventoy_util.c
Normal file
@@ -0,0 +1,260 @@
|
||||
/******************************************************************************
|
||||
* ventoy_util.c ---- ventoy util
|
||||
* Copyright (c) 2021, 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <ventoy_define.h>
|
||||
#include <ventoy_util.h>
|
||||
|
||||
|
||||
static int g_tar_filenum = 0;
|
||||
static char *g_tar_buffer = NULL;
|
||||
static ventoy_file *g_tar_filelist = NULL;
|
||||
|
||||
SYSINFO g_sysinfo;
|
||||
|
||||
unsigned char *g_unxz_buffer = NULL;
|
||||
int g_unxz_len = 0;
|
||||
|
||||
void unxz_error(char *x)
|
||||
{
|
||||
vlog("%s\n", x);
|
||||
}
|
||||
|
||||
int unxz_flush(void *src, unsigned int size)
|
||||
{
|
||||
memcpy(g_unxz_buffer + g_unxz_len, src, size);
|
||||
g_unxz_len += (int)size;
|
||||
|
||||
return (int)size;
|
||||
}
|
||||
|
||||
|
||||
uint64_t ventoy_get_human_readable_gb(uint64_t SizeBytes)
|
||||
{
|
||||
int i;
|
||||
int Pow2 = 1;
|
||||
double Delta;
|
||||
double GB = SizeBytes * 1.0 / 1000 / 1000 / 1000;
|
||||
|
||||
if ((SizeBytes % SIZE_1GB) == 0)
|
||||
{
|
||||
return (uint64_t)(SizeBytes / SIZE_1GB);
|
||||
}
|
||||
|
||||
for (i = 0; i < 12; i++)
|
||||
{
|
||||
if (Pow2 > GB)
|
||||
{
|
||||
Delta = (Pow2 - GB) / Pow2;
|
||||
}
|
||||
else
|
||||
{
|
||||
Delta = (GB - Pow2) / Pow2;
|
||||
}
|
||||
|
||||
if (Delta < 0.05)
|
||||
{
|
||||
return Pow2;
|
||||
}
|
||||
|
||||
Pow2 <<= 1;
|
||||
}
|
||||
|
||||
return (uint64_t)GB;
|
||||
}
|
||||
|
||||
ventoy_file * ventoy_tar_find_file(const char *path)
|
||||
{
|
||||
int i;
|
||||
int len;
|
||||
ventoy_file *node = g_tar_filelist;
|
||||
|
||||
len = (int)strlen(path);
|
||||
|
||||
for (i = 0; i < g_tar_filenum; i++, node++)
|
||||
{
|
||||
if (node->pathlen == len && memcmp(node->path, path, len) == 0)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
if (node->pathlen > len)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int ventoy_decompress_tar(char *tarbuf, int buflen, int *tarsize)
|
||||
{
|
||||
int rc = 1;
|
||||
int inused = 0;
|
||||
int BufLen = 0;
|
||||
unsigned char *buffer = NULL;
|
||||
char tarxz[MAX_PATH];
|
||||
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
scnprintf(tarxz, sizeof(tarxz), "%s\\ventoy\\%s", g_ventoy_dir, PLUGSON_TXZ);
|
||||
#else
|
||||
scnprintf(tarxz, sizeof(tarxz), "%s/tool/%s", g_ventoy_dir, PLUGSON_TXZ);
|
||||
#endif
|
||||
|
||||
if (ventoy_read_file_to_buf(tarxz, 0, (void **)&buffer, &BufLen))
|
||||
{
|
||||
vlog("Failed to read file <%s>\n", tarxz);
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_unxz_buffer = (unsigned char *)tarbuf;
|
||||
g_unxz_len = 0;
|
||||
|
||||
unxz(buffer, BufLen, NULL, unxz_flush, NULL, &inused, unxz_error);
|
||||
vlog("xzlen:%u rawdata size:%d\n", BufLen, g_unxz_len);
|
||||
|
||||
if (inused != BufLen)
|
||||
{
|
||||
vlog("Failed to unxz data %d %d\n", inused, BufLen);
|
||||
rc = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
*tarsize = g_unxz_len;
|
||||
rc = 0;
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int ventoy_www_init(void)
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int size = 0;
|
||||
int tarsize = 0;
|
||||
int offset = 0;
|
||||
ventoy_file *node = NULL;
|
||||
ventoy_file *node2 = NULL;
|
||||
VENTOY_TAR_HEAD *pHead = NULL;
|
||||
ventoy_file tmpnode;
|
||||
|
||||
if (!g_tar_filelist)
|
||||
{
|
||||
g_tar_filelist = malloc(VENTOY_FILE_MAX * sizeof(ventoy_file));
|
||||
g_tar_buffer = malloc(TAR_BUF_MAX);
|
||||
g_tar_filenum = 0;
|
||||
}
|
||||
|
||||
if ((!g_tar_filelist) || (!g_tar_buffer))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ventoy_decompress_tar(g_tar_buffer, TAR_BUF_MAX, &tarsize))
|
||||
{
|
||||
vlog("Failed to decompress tar\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
pHead = (VENTOY_TAR_HEAD *)g_tar_buffer;
|
||||
node = g_tar_filelist;
|
||||
|
||||
while (g_tar_filenum < VENTOY_FILE_MAX && size < tarsize && memcmp(pHead->magic, TMAGIC, 5) == 0)
|
||||
{
|
||||
if (pHead->typeflag == REGTYPE)
|
||||
{
|
||||
node->size = (int)strtol(pHead->size, NULL, 8);
|
||||
node->pathlen = (int)scnprintf(node->path, MAX_PATH, "%s", pHead->name);
|
||||
node->addr = pHead + 1;
|
||||
|
||||
if (node->pathlen == 13 && strcmp(pHead->name, "www/buildtime") == 0)
|
||||
{
|
||||
scnprintf(g_sysinfo.buildtime, sizeof(g_sysinfo.buildtime), "%s", (char *)node->addr);
|
||||
vlog("Plugson buildtime %s\n", g_sysinfo.buildtime);
|
||||
}
|
||||
|
||||
offset = 512 + VENTOY_UP_ALIGN(node->size, 512);
|
||||
|
||||
node++;
|
||||
g_tar_filenum++;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = 512;
|
||||
}
|
||||
|
||||
pHead = (VENTOY_TAR_HEAD *)((char *)pHead + offset);
|
||||
size += offset;
|
||||
}
|
||||
|
||||
|
||||
//sort
|
||||
for (i = 0; i < g_tar_filenum; i++)
|
||||
for (j = i + 1; j < g_tar_filenum; j++)
|
||||
{
|
||||
node = g_tar_filelist + i;
|
||||
node2 = g_tar_filelist + j;
|
||||
|
||||
if (node->pathlen > node2->pathlen)
|
||||
{
|
||||
memcpy(&tmpnode, node, sizeof(ventoy_file));
|
||||
memcpy(node, node2, sizeof(ventoy_file));
|
||||
memcpy(node2, &tmpnode, sizeof(ventoy_file));
|
||||
}
|
||||
}
|
||||
|
||||
vlog("Total extract %d files from tar file.\n", g_tar_filenum);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ventoy_www_exit(void)
|
||||
{
|
||||
check_free(g_tar_filelist);
|
||||
check_free(g_tar_buffer);
|
||||
g_tar_filelist = NULL;
|
||||
g_tar_buffer = NULL;
|
||||
g_tar_filenum = 0;
|
||||
}
|
||||
|
||||
|
||||
void ventoy_get_json_path(char *path, char *backup)
|
||||
{
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
scnprintf(path, 64, "%C:\\ventoy\\ventoy.json", g_cur_dir[0]);
|
||||
if (backup)
|
||||
{
|
||||
scnprintf(backup, 64, "%C:\\ventoy\\ventoy_backup.json", g_cur_dir[0]);
|
||||
}
|
||||
#else
|
||||
scnprintf(path, 64, "%s/ventoy/ventoy.json", g_cur_dir);
|
||||
if (backup)
|
||||
{
|
||||
scnprintf(backup, 64, "%s/ventoy/ventoy_backup.json", g_cur_dir);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
202
Plugson/src/Core/ventoy_util.h
Normal file
202
Plugson/src/Core/ventoy_util.h
Normal file
@@ -0,0 +1,202 @@
|
||||
/******************************************************************************
|
||||
* ventoy_util.h
|
||||
*
|
||||
* Copyright (c) 2021, 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 __VENTOY_UTIL_H__
|
||||
#define __VENTOY_UTIL_H__
|
||||
|
||||
#define PLUGSON_TXZ "plugson.tar.xz"
|
||||
|
||||
#define check_free(p) if (p) free(p)
|
||||
#define vtoy_safe_close_fd(fd) \
|
||||
{\
|
||||
if ((fd) >= 0) \
|
||||
{ \
|
||||
close(fd); \
|
||||
(fd) = -1; \
|
||||
}\
|
||||
}
|
||||
|
||||
extern char g_cur_dir[MAX_PATH];
|
||||
extern char g_ventoy_dir[MAX_PATH];
|
||||
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
|
||||
typedef HANDLE pthread_mutex_t;
|
||||
|
||||
static __inline int pthread_mutex_init(pthread_mutex_t *mutex, void *unused)
|
||||
{
|
||||
(void)unused;
|
||||
*mutex = CreateMutex(NULL, FALSE, NULL);
|
||||
return *mutex == NULL ? -1 : 0;
|
||||
}
|
||||
|
||||
static __inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
|
||||
{
|
||||
return CloseHandle(*mutex) == 0 ? -1 : 0;
|
||||
}
|
||||
|
||||
static __inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
|
||||
{
|
||||
return ReleaseMutex(*mutex) == 0 ? -1 : 0;
|
||||
}
|
||||
|
||||
static __inline int pthread_mutex_lock(pthread_mutex_t *mutex)
|
||||
{
|
||||
return WaitForSingleObject(*mutex, INFINITE) == WAIT_OBJECT_0 ? 0 : -1;
|
||||
}
|
||||
|
||||
int ventoy_path_case(char *path, int slash);
|
||||
|
||||
#else
|
||||
int ventoy_get_sys_file_line(char *buffer, int buflen, const char *fmt, ...);
|
||||
|
||||
#define UINT8 uint8_t
|
||||
#define UINT16 uint16_t
|
||||
#define UINT32 uint32_t
|
||||
#define UINT64 uint64_t
|
||||
|
||||
static inline int ventoy_path_case(char *path, int slash)
|
||||
{
|
||||
(void)path;
|
||||
(void)slash;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#define LANGUAGE_EN 0
|
||||
#define LANGUAGE_CN 1
|
||||
|
||||
typedef struct SYSINFO
|
||||
{
|
||||
char buildtime[128];
|
||||
int syntax_error;
|
||||
|
||||
int language;
|
||||
int pathcase;
|
||||
char cur_fsname[64];
|
||||
char cur_capacity[64];
|
||||
char cur_model[256];
|
||||
char cur_ventoy_ver[64];
|
||||
int cur_secureboot;
|
||||
int cur_part_style;
|
||||
|
||||
char ip[32];
|
||||
char port[16];
|
||||
}SYSINFO;
|
||||
|
||||
extern SYSINFO g_sysinfo;
|
||||
|
||||
|
||||
|
||||
|
||||
#define TMAGIC "ustar"
|
||||
|
||||
#define REGTYPE '0'
|
||||
#define AREGTYPE '\0'
|
||||
#define LNKTYPE '1'
|
||||
#define CHRTYPE '3'
|
||||
#define BLKTYPE '4'
|
||||
#define DIRTYPE '5'
|
||||
#define FIFOTYPE '6'
|
||||
#define CONTTYPE '7'
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct tag_tar_head
|
||||
{
|
||||
char name[100];
|
||||
char mode[8];
|
||||
char uid[8];
|
||||
char gid[8];
|
||||
char size[12];
|
||||
char mtime[12];
|
||||
char chksum[8];
|
||||
char typeflag;
|
||||
char linkname[100];
|
||||
char magic[6];
|
||||
char version[2];
|
||||
char uname[32];
|
||||
char gname[32];
|
||||
char devmajor[8];
|
||||
char devminor[8];
|
||||
char prefix[155];
|
||||
char padding[12];
|
||||
}VENTOY_TAR_HEAD;
|
||||
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#define VENTOY_UP_ALIGN(N, align) (((N) + ((align) - 1)) / (align) * (align))
|
||||
#define VENTOY_FILE_MAX 2048
|
||||
|
||||
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
#define million_sleep(a) Sleep(a)
|
||||
#else
|
||||
#define million_sleep(a) usleep((a) * 1000)
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct ventoy_file
|
||||
{
|
||||
int size;
|
||||
char path[MAX_PATH];
|
||||
int pathlen;
|
||||
void *addr;
|
||||
}ventoy_file;
|
||||
|
||||
|
||||
|
||||
int ventoy_is_file_exist(const char *fmt, ...);
|
||||
int ventoy_is_directory_exist(const char *fmt, ...);
|
||||
void ventoy_gen_preudo_uuid(void *uuid);
|
||||
uint64_t ventoy_get_human_readable_gb(uint64_t SizeBytes);
|
||||
void ventoy_md5(const void *data, uint32_t len, uint8_t *md5);
|
||||
int ventoy_is_disk_mounted(const char *devpath);
|
||||
int unxz(unsigned char *in, int in_size,
|
||||
int (*fill)(void *dest, unsigned int size),
|
||||
int (*flush)(void *src, unsigned int size),
|
||||
unsigned char *out, int *in_used,
|
||||
void (*error)(char *x));
|
||||
int ventoy_read_file_to_buf(const char *FileName, int ExtLen, void **Bufer, int *BufLen);
|
||||
int ventoy_write_buf_to_file(const char *FileName, void *Bufer, int BufLen);
|
||||
const char * ventoy_get_os_language(void);
|
||||
int ventoy_get_file_size(const char *file);
|
||||
int ventoy_www_init(void);
|
||||
void ventoy_www_exit(void);
|
||||
int ventoy_decompress_tar(char *tarbuf, int buflen, int *tarsize);
|
||||
ventoy_file * ventoy_tar_find_file(const char *path);
|
||||
void ventoy_get_json_path(char *path, char *backup);
|
||||
int ventoy_copy_file(const char *a, const char *b);
|
||||
|
||||
typedef int (*ventoy_http_writeback_pf)(void);
|
||||
|
||||
int ventoy_start_writeback_thread(ventoy_http_writeback_pf callback);
|
||||
void ventoy_stop_writeback_thread(void);
|
||||
void ventoy_set_writeback_event(void);
|
||||
|
||||
|
||||
extern unsigned char *g_unxz_buffer;
|
||||
extern int g_unxz_len;
|
||||
void unxz_error(char *x);
|
||||
int unxz_flush(void *src, unsigned int size);
|
||||
|
||||
#endif /* __VENTOY_UTIL_H__ */
|
||||
|
343
Plugson/src/Core/ventoy_util_linux.c
Normal file
343
Plugson/src/Core/ventoy_util_linux.c
Normal file
@@ -0,0 +1,343 @@
|
||||
/******************************************************************************
|
||||
* ventoy_util_linux.c ---- ventoy util
|
||||
* Copyright (c) 2021, 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/mount.h>
|
||||
#include <linux/fs.h>
|
||||
#include <dirent.h>
|
||||
#include <time.h>
|
||||
#include <ventoy_define.h>
|
||||
#include <ventoy_util.h>
|
||||
|
||||
void ventoy_gen_preudo_uuid(void *uuid)
|
||||
{
|
||||
int i;
|
||||
int fd;
|
||||
|
||||
fd = open("/dev/urandom", O_RDONLY | O_BINARY);
|
||||
if (fd < 0)
|
||||
{
|
||||
srand(time(NULL));
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
*((uint16_t *)uuid + i) = (uint16_t)(rand() & 0xFFFF);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
read(fd, uuid, 16);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
int ventoy_get_sys_file_line(char *buffer, int buflen, const char *fmt, ...)
|
||||
{
|
||||
int len;
|
||||
char c;
|
||||
char path[256];
|
||||
va_list arg;
|
||||
|
||||
va_start(arg, fmt);
|
||||
vsnprintf(path, 256, fmt, arg);
|
||||
va_end(arg);
|
||||
|
||||
if (access(path, F_OK) >= 0)
|
||||
{
|
||||
FILE *fp = fopen(path, "r");
|
||||
memset(buffer, 0, buflen);
|
||||
len = (int)fread(buffer, 1, buflen - 1, fp);
|
||||
fclose(fp);
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
c = buffer[len - 1];
|
||||
if (c == '\r' || c == '\n' || c == ' ' || c == '\t')
|
||||
{
|
||||
buffer[len - 1] = 0;
|
||||
len--;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
vdebug("%s not exist \n", path);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int ventoy_is_disk_mounted(const char *devpath)
|
||||
{
|
||||
int len;
|
||||
int mount = 0;
|
||||
char line[512];
|
||||
FILE *fp = NULL;
|
||||
|
||||
fp = fopen("/proc/mounts", "r");
|
||||
if (!fp)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = (int)strlen(devpath);
|
||||
while (fgets(line, sizeof(line), fp))
|
||||
{
|
||||
if (strncmp(line, devpath, len) == 0)
|
||||
{
|
||||
mount = 1;
|
||||
vdebug("%s mounted <%s>\n", devpath, line);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
fclose(fp);
|
||||
return mount;
|
||||
}
|
||||
|
||||
const char * ventoy_get_os_language(void)
|
||||
{
|
||||
const char *env = getenv("LANG");
|
||||
|
||||
if (env && strncasecmp(env, "zh_CN", 5) == 0)
|
||||
{
|
||||
return "cn";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "en";
|
||||
}
|
||||
}
|
||||
|
||||
int ventoy_is_file_exist(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
struct stat sb;
|
||||
char fullpath[MAX_PATH];
|
||||
|
||||
va_start (ap, fmt);
|
||||
vsnprintf(fullpath, MAX_PATH, fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
if (stat(fullpath, &sb))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (S_ISREG(sb.st_mode))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ventoy_is_directory_exist(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
struct stat sb;
|
||||
char fullpath[MAX_PATH];
|
||||
|
||||
va_start (ap, fmt);
|
||||
vsnprintf(fullpath, MAX_PATH, fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
if (stat(fullpath, &sb))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (S_ISDIR(sb.st_mode))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ventoy_get_file_size(const char *file)
|
||||
{
|
||||
int Size = -1;
|
||||
struct stat stStat;
|
||||
|
||||
if (stat(file, &stStat) >= 0)
|
||||
{
|
||||
Size = (int)(stStat.st_size);
|
||||
}
|
||||
|
||||
return Size;
|
||||
}
|
||||
|
||||
|
||||
int ventoy_write_buf_to_file(const char *FileName, void *Bufer, int BufLen)
|
||||
{
|
||||
int fd;
|
||||
int rc;
|
||||
ssize_t size;
|
||||
|
||||
fd = open(FileName, O_CREAT | O_RDWR | O_TRUNC, 0755);
|
||||
if (fd < 0)
|
||||
{
|
||||
vlog("Failed to open file %s %d\n", FileName, errno);
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = fchmod(fd, 0755);
|
||||
if (rc)
|
||||
{
|
||||
vlog("Failed to chmod <%s> %d\n", FileName, errno);
|
||||
}
|
||||
|
||||
size = write(fd, Bufer, BufLen);
|
||||
if ((int)size != BufLen)
|
||||
{
|
||||
close(fd);
|
||||
vlog("write file %s failed %d err:%d\n", FileName, (int)size, errno);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fsync(fd);
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static volatile int g_thread_stop = 0;
|
||||
static pthread_t g_writeback_thread;
|
||||
static pthread_mutex_t g_writeback_mutex;
|
||||
static pthread_cond_t g_writeback_cond;
|
||||
static void * ventoy_local_thread_run(void* data)
|
||||
{
|
||||
ventoy_http_writeback_pf callback = (ventoy_http_writeback_pf)data;
|
||||
|
||||
while (1)
|
||||
{
|
||||
pthread_mutex_lock(&g_writeback_mutex);
|
||||
pthread_cond_wait(&g_writeback_cond, &g_writeback_mutex);
|
||||
|
||||
if (g_thread_stop)
|
||||
{
|
||||
pthread_mutex_unlock(&g_writeback_mutex);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
callback();
|
||||
pthread_mutex_unlock(&g_writeback_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ventoy_set_writeback_event(void)
|
||||
{
|
||||
pthread_cond_signal(&g_writeback_cond);
|
||||
}
|
||||
|
||||
int ventoy_start_writeback_thread(ventoy_http_writeback_pf callback)
|
||||
{
|
||||
g_thread_stop = 0;
|
||||
pthread_mutex_init(&g_writeback_mutex, NULL);
|
||||
pthread_cond_init(&g_writeback_cond, NULL);
|
||||
|
||||
pthread_create(&g_writeback_thread, NULL, ventoy_local_thread_run, callback);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ventoy_stop_writeback_thread(void)
|
||||
{
|
||||
g_thread_stop = 1;
|
||||
pthread_cond_signal(&g_writeback_cond);
|
||||
|
||||
pthread_join(g_writeback_thread, NULL);
|
||||
|
||||
|
||||
pthread_cond_destroy(&g_writeback_cond);
|
||||
pthread_mutex_destroy(&g_writeback_mutex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int ventoy_read_file_to_buf(const char *FileName, int ExtLen, void **Bufer, int *BufLen)
|
||||
{
|
||||
int FileSize;
|
||||
FILE *fp = NULL;
|
||||
void *Data = NULL;
|
||||
|
||||
fp = fopen(FileName, "rb");
|
||||
if (fp == NULL)
|
||||
{
|
||||
vlog("Failed to open file %s", FileName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fseek(fp, 0, SEEK_END);
|
||||
FileSize = (int)ftell(fp);
|
||||
|
||||
Data = malloc(FileSize + ExtLen);
|
||||
if (!Data)
|
||||
{
|
||||
fclose(fp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
fread(Data, 1, FileSize, fp);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
*Bufer = Data;
|
||||
*BufLen = FileSize;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ventoy_copy_file(const char *a, const char *b)
|
||||
{
|
||||
int len = 0;
|
||||
char *buf = NULL;
|
||||
|
||||
if (0 == ventoy_read_file_to_buf(a, 0, (void **)&buf, &len))
|
||||
{
|
||||
ventoy_write_buf_to_file(b, buf, len);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user