mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-09-16 17:11:13 +00:00
Compare commits
259 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
da20eb5568 | ||
|
2d76fa7303 | ||
|
8fc8cc6867 | ||
|
132649c4e5 | ||
|
c3c8100866 | ||
|
94e24e63c5 | ||
|
c19cd649d8 | ||
|
20914350fb | ||
|
8b411663cf | ||
|
01292939d3 | ||
|
dcc5889677 | ||
|
04828df028 | ||
|
2f95139c77 | ||
|
f2bb3667c4 | ||
|
791da48673 | ||
|
f683bcbd59 | ||
|
15b8b1f358 | ||
|
a20592ecd1 | ||
|
ed1aa3d5be | ||
|
8e66110374 | ||
|
f5f65aa868 | ||
|
4e5fcf211b | ||
|
9789069c0d | ||
|
1cf45ac0c5 | ||
|
40fe21f909 | ||
|
e6bdf075ca | ||
|
7c76e57bf4 | ||
|
7fe038b697 | ||
|
c01c69db3b | ||
|
0e996e74c9 | ||
|
1371159f0b | ||
|
44b38dce74 | ||
|
392d8ef4fa | ||
|
d1900c75cd | ||
|
fa7e1d5fa0 | ||
|
6ae8bf840d | ||
|
ce862da402 | ||
|
6d4f5ff00b | ||
|
ab0f25d097 | ||
|
ff14c07c4e | ||
|
f7fac26c91 | ||
|
ebae102f41 | ||
|
c3718d6001 | ||
|
d0744513a6 | ||
|
5b0fca8468 | ||
|
27918eb3f9 | ||
|
7859271b20 | ||
|
1c27c0b489 | ||
|
0f89c2767f | ||
|
d1584c10b4 | ||
|
43e921878b | ||
|
23f4f18e27 | ||
|
53b95ae17b | ||
|
e3506c0f10 | ||
|
9118d5fe45 | ||
|
f130325a9c | ||
|
1ca48923da | ||
|
730fdd5198 | ||
|
d0f3597b26 | ||
|
045f53d768 | ||
|
a173acaf17 | ||
|
96fdd594f0 | ||
|
62dc0033ad | ||
|
1c3fcbdfe9 | ||
|
7d37cab21d | ||
|
a1c6fe2d24 | ||
|
dbeb4023a2 | ||
|
58b1bbe0b5 | ||
|
86b13727ca | ||
|
006f26d07d | ||
|
9203aa1ab3 | ||
|
5291d66736 | ||
|
ba5978d298 | ||
|
7f717a7fe9 | ||
|
c57717aea2 | ||
|
be0e19fc5b | ||
|
34a36bfc3e | ||
|
82e99a3b37 | ||
|
b685431d66 | ||
|
8be8fd50b3 | ||
|
999b15c4ef | ||
|
28998edd94 | ||
|
2ad69decad | ||
|
c2cc0bd3dc | ||
|
b128a0b6d3 | ||
|
676831dbbe | ||
|
e5fa5e6d84 | ||
|
76a6b8061c | ||
|
036b58ff0c | ||
|
8e529c8559 | ||
|
b8e624b0a0 | ||
|
1f49265f29 | ||
|
25dc323522 | ||
|
446597d880 | ||
|
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 | ||
|
f5843f576b | ||
|
be5bc6f3b7 | ||
|
f3b65452f4 | ||
|
ec4b6c2a2c | ||
|
be8b6e8976 | ||
|
82b1faa132 | ||
|
52ae65f54d | ||
|
ee104bfa97 | ||
|
9cfd05811b | ||
|
0c66908935 | ||
|
f53de3bdb0 | ||
|
8516786b31 | ||
|
f7c78879c7 | ||
|
f3e267a09e | ||
|
7c1370dcb0 | ||
|
1b5aa9c61d | ||
|
d6eba15d71 | ||
|
734c7b8ac4 | ||
|
0fa25c4526 | ||
|
1473be0e4c | ||
|
cd9aa16b20 | ||
|
a9be2fd4d9 | ||
|
f354d2b733 | ||
|
aa033e1fb6 | ||
|
9351fe4f97 | ||
|
67b8a34e8c | ||
|
c18399e8b4 | ||
|
5a591c1ae7 | ||
|
e208199cca | ||
|
4c9065a60d | ||
|
4fd4977c3a | ||
|
93614c3251 | ||
|
1db0827463 | ||
|
72d0fd0dd4 | ||
|
47797f0285 | ||
|
849eb7bf2c | ||
|
32c5b5deea | ||
|
d72bb15956 | ||
|
89a34bac18 | ||
|
8cecdae8f9 | ||
|
471432fc50 | ||
|
a78e19608b | ||
|
5e97d56033 | ||
|
a5041ad43c | ||
|
3149a67599 | ||
|
d0b7927b51 | ||
|
8775684367 | ||
|
d148139227 | ||
|
dd2411d7d4 | ||
|
7db83dc0f1 | ||
|
787d950f28 | ||
|
892a819da4 | ||
|
bfc5eaebb9 | ||
|
e7d05df9fa | ||
|
ca07b52cb2 | ||
|
1a2a35f5bc | ||
|
d71514f23e | ||
|
c5af17e04e | ||
|
05e208ea2a | ||
|
112c557428 | ||
|
92db873b5c | ||
|
3c01eec4af | ||
|
5c6d18fcd4 | ||
|
84ec4b0de4 | ||
|
9615e7eaa0 | ||
|
6a244ff260 | ||
|
b5503a7375 | ||
|
0b7fa630a4 | ||
|
7babe823d6 | ||
|
6db513a067 | ||
|
bafac7479d | ||
|
d3138479d7 | ||
|
56a1543f7d | ||
|
659ac1cfe3 | ||
|
c83daa86b6 | ||
|
dfcfaa9967 | ||
|
188f9e707c |
4
.github/FUNDING.yml
vendored
4
.github/FUNDING.yml
vendored
@@ -6,7 +6,7 @@ open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
liberapay: Ventoy
|
||||
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']
|
||||
|
9
.github/ISSUE_TEMPLATE/issue_template.yml
vendored
9
.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.48
|
||||
placeholder: 1.0.72
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
@@ -63,6 +63,13 @@ body:
|
||||
placeholder: 32GB
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: vendor
|
||||
attributes:
|
||||
label: Disk Manufacturer
|
||||
description: What is the manufacturer of the disk installed with Ventoy? (e.g. SanDisk/Kingston...)
|
||||
validations:
|
||||
required: false
|
||||
- type: dropdown
|
||||
id: checksum
|
||||
attributes:
|
||||
|
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
|
||||
|
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@@ -27,6 +27,10 @@ jobs:
|
||||
with:
|
||||
name: ventoy-livecd
|
||||
path: INSTALL/ventoy-*livecd*
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: SHA256SUM
|
||||
path: INSTALL/sha256.txt
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: xxx-build-log
|
||||
|
@@ -1,9 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
DSTDIR=../../IMG/cpio/ventoy/busybox
|
||||
DSTDIR1=../../IMG/cpio_x86/ventoy/busybox
|
||||
DSTDIR2=../../IMG/cpio_arm64/ventoy/busybox
|
||||
DSTDIR3=../../IMG/cpio_mips64/ventoy/busybox
|
||||
|
||||
rm -f vtchmod32 vtchmod64 vtchmod64_musl vtchmodaa64
|
||||
rm -f $DSTDIR/vtchmod32 $DSTDIR/vtchmod64 $DSTDIR/vtchmodaa64 $DSTDIR/vtchmodm64e
|
||||
rm -f $DSTDIR1/vtchmod32 $DSTDIR1/vtchmod64 $DSTDIR2/vtchmodaa64 $DSTDIR3/vtchmodm64e
|
||||
|
||||
/opt/diet32/bin/diet gcc -Os -m32 vtchmod.c -o vtchmod32
|
||||
/opt/diet64/bin/diet gcc -Os vtchmod.c -o vtchmod64
|
||||
@@ -23,9 +25,9 @@ chmod 777 vtchmodaa64
|
||||
chmod 777 vtchmod64_musl
|
||||
chmod 777 vtchmodm64e
|
||||
|
||||
cp -a vtchmod32 $DSTDIR/
|
||||
cp -a vtchmod64 $DSTDIR/
|
||||
cp -a vtchmodaa64 $DSTDIR/
|
||||
cp -a vtchmod64_musl $DSTDIR/
|
||||
cp -a vtchmodm64e $DSTDIR/
|
||||
cp -a vtchmod32 $DSTDIR1/
|
||||
cp -a vtchmod64 $DSTDIR1/
|
||||
cp -a vtchmod64_musl $DSTDIR1/
|
||||
cp -a vtchmodaa64 $DSTDIR2/
|
||||
cp -a vtchmodm64e $DSTDIR3/
|
||||
|
||||
|
@@ -1,5 +1,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@@ -8,6 +11,24 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argv[1][0] == '-' && argv[1][1] == '6')
|
||||
{
|
||||
struct utsname buf;
|
||||
if (0 == uname(&buf))
|
||||
{
|
||||
if (strstr(buf.machine, "amd64"))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strstr(buf.machine, "x86_64"))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return chmod(argv[1], 0777);
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7
DMPATCH/Makefile
Normal file
7
DMPATCH/Makefile
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
obj-m += dm_patch.o
|
||||
|
||||
EXTRA_CFLAGS := -Wall
|
||||
|
||||
dm_patch-objs := dmpatch.o
|
||||
|
187
DMPATCH/dmpatch.c
Normal file
187
DMPATCH/dmpatch.c
Normal file
@@ -0,0 +1,187 @@
|
||||
/******************************************************************************
|
||||
* dmpatch.c ---- patch for device-mapper
|
||||
*
|
||||
* 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 <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/kallsyms.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/mempool.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/wait.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#define MAX_PATCH 4
|
||||
|
||||
#define magic_sig 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF
|
||||
|
||||
typedef int (*kprobe_reg_pf)(void *);
|
||||
typedef void (*kprobe_unreg_pf)(void *);
|
||||
typedef int (*printk_pf)(const char *fmt, ...);
|
||||
typedef int (*set_memory_attr_pf)(unsigned long addr, int numpages);
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct ko_param
|
||||
{
|
||||
unsigned char magic[16];
|
||||
unsigned long struct_size;
|
||||
unsigned long pgsize;
|
||||
unsigned long printk_addr;
|
||||
unsigned long ro_addr;
|
||||
unsigned long rw_addr;
|
||||
unsigned long reg_kprobe_addr;
|
||||
unsigned long unreg_kprobe_addr;
|
||||
unsigned long sym_get_addr;
|
||||
unsigned long sym_get_size;
|
||||
unsigned long sym_put_addr;
|
||||
unsigned long sym_put_size;
|
||||
unsigned long padding[3];
|
||||
}ko_param;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
static printk_pf kprintf = NULL;
|
||||
static set_memory_attr_pf set_mem_ro = NULL;
|
||||
static set_memory_attr_pf set_mem_rw = NULL;
|
||||
static kprobe_reg_pf reg_kprobe = NULL;
|
||||
static kprobe_unreg_pf unreg_kprobe = NULL;
|
||||
|
||||
static volatile ko_param g_ko_param =
|
||||
{
|
||||
{ magic_sig },
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
#if defined(CONFIG_X86_64)
|
||||
#define PATCH_OP_POS 3
|
||||
#define CODE_MATCH(code, i) \
|
||||
(code[i] == 0x40 && code[i + 1] == 0x80 && code[i + 2] == 0xce && code[i + 3] == 0x80)
|
||||
#elif defined(CONFIG_X86_32)
|
||||
#define PATCH_OP_POS 2
|
||||
#define CODE_MATCH(code, i) \
|
||||
(code[i] == 0x80 && code[i + 1] == 0xca && code[i + 2] == 0x80 && code[i + 3] == 0xe8)
|
||||
#else
|
||||
#error "unsupported arch"
|
||||
#endif
|
||||
|
||||
#define vdebug(fmt, args...) if(kprintf) kprintf(KERN_ERR fmt, ##args)
|
||||
|
||||
static int notrace dmpatch_replace_code(unsigned long addr, unsigned long size, int expect, const char *desc)
|
||||
{
|
||||
int i = 0;
|
||||
int cnt = 0;
|
||||
unsigned long align;
|
||||
unsigned char *patch[MAX_PATCH];
|
||||
unsigned char *opCode = (unsigned char *)addr;
|
||||
|
||||
vdebug("patch for %s 0x%lx %d\n", desc, addr, (int)size);
|
||||
|
||||
for (i = 0; i < (int)size - 4; i++)
|
||||
{
|
||||
if (CODE_MATCH(opCode, i) && cnt < MAX_PATCH)
|
||||
{
|
||||
patch[cnt] = opCode + i + PATCH_OP_POS;
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
if (cnt != expect || cnt >= MAX_PATCH)
|
||||
{
|
||||
vdebug("patch error: cnt=%d expect=%d\n", cnt, expect);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < cnt; i++)
|
||||
{
|
||||
opCode = patch[i];
|
||||
align = (unsigned long)opCode / g_ko_param.pgsize * g_ko_param.pgsize;
|
||||
|
||||
set_mem_rw(align, 1);
|
||||
*opCode = 0;
|
||||
set_mem_ro(align, 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int notrace dmpatch_init(void)
|
||||
{
|
||||
int r = 0;
|
||||
int rc = 0;
|
||||
|
||||
kprintf = (printk_pf)(g_ko_param.printk_addr);
|
||||
|
||||
vdebug("dmpatch_init start pagesize=%lu ...\n", g_ko_param.pgsize);
|
||||
|
||||
if (g_ko_param.struct_size != sizeof(ko_param))
|
||||
{
|
||||
vdebug("Invalid struct size %d %d\n", (int)g_ko_param.struct_size, (int)sizeof(ko_param));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (g_ko_param.sym_get_addr == 0 || g_ko_param.sym_put_addr == 0 ||
|
||||
g_ko_param.ro_addr == 0 || g_ko_param.rw_addr == 0)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
set_mem_ro = (set_memory_attr_pf)(g_ko_param.ro_addr);
|
||||
set_mem_rw = (set_memory_attr_pf)(g_ko_param.rw_addr);
|
||||
reg_kprobe = (kprobe_reg_pf)g_ko_param.reg_kprobe_addr;
|
||||
unreg_kprobe = (kprobe_unreg_pf)g_ko_param.unreg_kprobe_addr;
|
||||
|
||||
r = dmpatch_replace_code(g_ko_param.sym_get_addr, g_ko_param.sym_get_size, 2, "dm_get_table_device");
|
||||
if (r)
|
||||
{
|
||||
rc = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
vdebug("patch dm_get_table_device success\n");
|
||||
|
||||
r = dmpatch_replace_code(g_ko_param.sym_put_addr, g_ko_param.sym_put_size, 1, "dm_put_table_device");
|
||||
if (r)
|
||||
{
|
||||
rc = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
vdebug("patch dm_put_table_device success\n");
|
||||
|
||||
vdebug("#####################################\n");
|
||||
vdebug("######## dm patch success ###########\n");
|
||||
vdebug("#####################################\n");
|
||||
|
||||
out:
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void notrace dmpatch_exit(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
module_init(dmpatch_init);
|
||||
module_exit(dmpatch_exit);
|
||||
|
||||
|
||||
MODULE_DESCRIPTION("dmpatch driver");
|
||||
MODULE_AUTHOR("longpanda <admin@ventoy.net>");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
36
DMPATCH/readme.txt
Normal file
36
DMPATCH/readme.txt
Normal file
@@ -0,0 +1,36 @@
|
||||
1. install ubuntu 21.10
|
||||
2. apt-get install build-essential flex libncurses-dev linux-headers-generic linux-source libssl-dev ...... and so on
|
||||
3. cp /lib/modules/5.13.0-23-generic/build/Module.symvers ./
|
||||
4. /boot/config-5.13.0-23-generic as .config make oldconfig
|
||||
5. make menuconfig
|
||||
1. close CONFIG_STACKPROTECTOR
|
||||
2. close CONFIG_RETPOLINE
|
||||
|
||||
6. modify ./scripts/mod/modpost.c
|
||||
1. skip add_srcversion (just return)
|
||||
2. force add_retpoline (#ifdef --> #ifndef)
|
||||
3. force add_intree_flag
|
||||
|
||||
7. make modules_prepare LOCALVERSION=-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
|
||||
8. Append padding at the end of struct module <include/linux/module.h>
|
||||
struct module {
|
||||
enum module_state state;
|
||||
|
||||
/* Member of list of modules */
|
||||
struct list_head list;
|
||||
|
||||
/* Unique handle for this module */
|
||||
char name[MODULE_NAME_LEN];
|
||||
|
||||
....
|
||||
|
||||
char padding[1024];
|
||||
};
|
||||
|
||||
This is because struct module size is different in different kernel versions or with different CONFIG item.
|
||||
|
||||
|
||||
9. make modules M=/home/dmpatch
|
||||
10. strip --strip-debug /home/dmpatch/dm_patch.ko
|
||||
|
@@ -108,10 +108,10 @@
|
||||
cd /home/Ventoy-master/VtoyTool
|
||||
sh build.sh
|
||||
|
||||
4.8 == Build vtoyfat ==
|
||||
cd /home/Ventoy-master/vtoyfat/fat_io_lib
|
||||
4.8 == Build vtoycli ==
|
||||
cd /home/Ventoy-master/vtoycli/fat_io_lib
|
||||
sh buildlib.sh
|
||||
cd /home/Ventoy-master/vtoyfat
|
||||
cd /home/Ventoy-master/vtoycli
|
||||
sh build.sh
|
||||
|
||||
4.9 == Build exfat-util ==
|
||||
|
@@ -5,6 +5,6 @@ RUN yum -y -q install \
|
||||
mpfr.i686 mpfr-devel.i686 rsync autogen autoconf automake libtool gettext* bison binutils \
|
||||
flex device-mapper-devel SDL libpciaccess libusb freetype freetype-devel gnu-free-* qemu-* virt-* \
|
||||
libvirt* vte* NetworkManager-bluetooth brlapi fuse-devel dejavu* gnu-efi* pesign shim \
|
||||
iscsi-initiator-utils grub2-tools zip nasm acpica-tools glibc-static zlib-static xorriso
|
||||
iscsi-initiator-utils grub2-tools zip nasm acpica-tools glibc-static zlib-static xorriso lz4 squashfs-tools
|
||||
|
||||
CMD cd /ventoy/INSTALL && ls -la && sh docker_ci_build.sh
|
||||
|
@@ -249,6 +249,12 @@ EFI_STATUS EFIAPI vdisk_exit_boot_service_wrapper
|
||||
IN UINTN MapKey
|
||||
)
|
||||
{
|
||||
if (g_org_get_variable)
|
||||
{
|
||||
gRT->GetVariable = g_org_get_variable;
|
||||
g_org_get_variable = NULL;
|
||||
}
|
||||
|
||||
return g_org_exit_boot_service(ImageHandle, MapKey);
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
||||
@@ -68,6 +71,9 @@ STATIC BOOLEAN g_hook_keyboard = FALSE;
|
||||
|
||||
CHAR16 gFirstTryBootFile[256] = {0};
|
||||
|
||||
STATIC EFI_GET_VARIABLE g_org_get_variable = NULL;
|
||||
STATIC EFI_EXIT_BOOT_SERVICES g_org_exit_boot_service = NULL;
|
||||
|
||||
/* Boot filename */
|
||||
UINTN gBootFileStartIndex = 1;
|
||||
CONST CHAR16 *gEfiBootFileName[] =
|
||||
@@ -223,12 +229,14 @@ static void EFIAPI ventoy_dump_chain(ventoy_chain_head *chain)
|
||||
debug("os_param->vtoy_img_size=<%llu>", chain->os_param.vtoy_img_size);
|
||||
debug("os_param->vtoy_img_location_addr=<0x%llx>", chain->os_param.vtoy_img_location_addr);
|
||||
debug("os_param->vtoy_img_location_len=<%u>", chain->os_param.vtoy_img_location_len);
|
||||
debug("os_param->vtoy_reserved=<%u %u %u %u %u>",
|
||||
debug("os_param->vtoy_reserved=<%u %u %u %u %u %u %u>",
|
||||
g_os_param_reserved[0],
|
||||
g_os_param_reserved[1],
|
||||
g_os_param_reserved[2],
|
||||
g_os_param_reserved[3],
|
||||
g_os_param_reserved[4]
|
||||
g_os_param_reserved[4],
|
||||
g_os_param_reserved[5],
|
||||
g_os_param_reserved[6]
|
||||
);
|
||||
|
||||
ventoy_debug_pause();
|
||||
@@ -572,7 +580,7 @@ STATIC EFI_STATUS EFIAPI ventoy_find_iso_disk(IN EFI_HANDLE ImageHandle)
|
||||
if (CompareMem(g_chain->os_param.vtoy_disk_guid, pBuffer + 0x180, 16) == 0)
|
||||
{
|
||||
pMBR = (MBR_HEAD *)pBuffer;
|
||||
if (pMBR->PartTbl[0].FsFlag != 0xEE)
|
||||
if (g_os_param_reserved[6] == 0 && pMBR->PartTbl[0].FsFlag != 0xEE)
|
||||
{
|
||||
if (pMBR->PartTbl[0].StartSectorId != 2048 ||
|
||||
pMBR->PartTbl[1].SectorCount != 65536 ||
|
||||
@@ -707,6 +715,106 @@ 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;
|
||||
}
|
||||
|
||||
EFI_STATUS EFIAPI ventoy_get_variable_wrapper
|
||||
(
|
||||
IN CHAR16 *VariableName,
|
||||
IN EFI_GUID *VendorGuid,
|
||||
OUT UINT32 *Attributes, OPTIONAL
|
||||
IN OUT UINTN *DataSize,
|
||||
OUT VOID *Data OPTIONAL
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status = EFI_SUCCESS;
|
||||
|
||||
Status = g_org_get_variable(VariableName, VendorGuid, Attributes, DataSize, Data);
|
||||
if (StrCmp(VariableName, L"SecureBoot") == 0)
|
||||
{
|
||||
if ((*DataSize == 1) && Data)
|
||||
{
|
||||
*(UINT8 *)Data = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
EFI_STATUS EFIAPI ventoy_exit_boot_service_wrapper
|
||||
(
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN UINTN MapKey
|
||||
)
|
||||
{
|
||||
if (g_org_get_variable)
|
||||
{
|
||||
gRT->GetVariable = g_org_get_variable;
|
||||
g_org_get_variable = NULL;
|
||||
}
|
||||
|
||||
return g_org_exit_boot_service(ImageHandle, MapKey);
|
||||
}
|
||||
|
||||
STATIC EFI_STATUS EFIAPI ventoy_disable_secure_boot(IN EFI_HANDLE ImageHandle)
|
||||
{
|
||||
UINT8 Value = 0;
|
||||
UINTN DataSize = 1;
|
||||
EFI_STATUS Status = EFI_SUCCESS;
|
||||
|
||||
Status = gRT->GetVariable(L"SecureBoot", &gEfiGlobalVariableGuid, NULL, &DataSize, &Value);
|
||||
if (!EFI_ERROR(Status))
|
||||
{
|
||||
if (DataSize == 1 && Value == 0)
|
||||
{
|
||||
debug("Current secure boot is off, no need to disable");
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
debug("ventoy_disable_secure_boot");
|
||||
|
||||
/* step1: wrapper security protocol. */
|
||||
/* Do we still need it since we have been loaded ? */
|
||||
|
||||
|
||||
/* step2: fake SecureBoot variable */
|
||||
g_org_exit_boot_service = gBS->ExitBootServices;
|
||||
gBS->ExitBootServices = ventoy_exit_boot_service_wrapper;
|
||||
|
||||
g_org_get_variable = gRT->GetVariable;
|
||||
gRT->GetVariable = ventoy_get_variable_wrapper;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
|
||||
{
|
||||
UINT32 i = 0;
|
||||
@@ -817,6 +925,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);
|
||||
|
||||
@@ -837,6 +958,7 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
|
||||
debug("memdisk mode iso_buf_size:%u", g_iso_buf_size);
|
||||
|
||||
g_chain = chain;
|
||||
g_os_param_reserved = (UINT8 *)(g_chain->os_param.vtoy_reserved);
|
||||
gMemdiskMode = TRUE;
|
||||
}
|
||||
else
|
||||
@@ -865,6 +987,11 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
|
||||
g_hook_keyboard = TRUE;
|
||||
}
|
||||
|
||||
if (g_os_param_reserved[5] == 1 && g_os_param_reserved[2] == ventoy_chain_linux)
|
||||
{
|
||||
ventoy_disable_secure_boot(ImageHandle);
|
||||
}
|
||||
|
||||
debug("internal param: secover:%u keyboard:%u", g_fixup_iso9660_secover_enable, g_hook_keyboard);
|
||||
|
||||
for (i = 0; i < sizeof(ventoy_os_param); i++)
|
||||
@@ -1050,7 +1177,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;
|
||||
|
@@ -42,6 +42,7 @@
|
||||
DebugLib
|
||||
|
||||
[Guids]
|
||||
gEfiGlobalVariableGuid
|
||||
gShellVariableGuid
|
||||
gEfiVirtualCdGuid
|
||||
gEfiFileInfoGuid
|
||||
|
@@ -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;
|
||||
@@ -809,11 +812,6 @@ STATIC BOOLEAN ventoy_filesystem_need_wrapper(IN CONST CHAR16 *DrvName)
|
||||
*
|
||||
*/
|
||||
|
||||
if (StrStr(UpperDrvName, L"ISO9660") || StrStr(UpperDrvName, L"UDF"))
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (StrStr(UpperDrvName, L"REFIND") && StrStr(UpperDrvName, L"FILE SYSTEM"))
|
||||
{
|
||||
return TRUE;
|
||||
@@ -915,7 +913,6 @@ STATIC EFI_STATUS ventoy_find_filesystem_driverbind(VOID)
|
||||
Status = gBS->HandleProtocol(Handles[i], &gEfiComponentNameProtocolGuid, (VOID **)&NameProtocol);
|
||||
if (EFI_ERROR(Status))
|
||||
{
|
||||
debug();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1144,14 +1141,15 @@ EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 Im
|
||||
{
|
||||
gBlockData.Media.BlockSize = 512;
|
||||
gBlockData.Media.LastBlock = ImgSize / 512 - 1;
|
||||
gBlockData.Media.ReadOnly = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
gBlockData.Media.BlockSize = 2048;
|
||||
gBlockData.Media.LastBlock = ImgSize / 2048 - 1;
|
||||
gBlockData.Media.ReadOnly = TRUE;
|
||||
}
|
||||
|
||||
gBlockData.Media.ReadOnly = TRUE;
|
||||
gBlockData.Media.MediaPresent = 1;
|
||||
gBlockData.Media.LogicalBlocksPerPhysicalBlock = 1;
|
||||
|
||||
@@ -1250,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)
|
||||
@@ -1275,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;
|
||||
ventoy_efi_file_replace *replace = NULL;
|
||||
|
||||
if (Position <= g_efi_file_replace.FileSizeBytes)
|
||||
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;
|
||||
@@ -1296,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;
|
||||
}
|
||||
@@ -1308,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);
|
||||
|
||||
@@ -1325,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;
|
||||
|
||||
@@ -1340,23 +1353,24 @@ ventoy_wrapper_file_read(EFI_FILE_HANDLE This, UINTN *Len, VOID *Data)
|
||||
{
|
||||
EFI_LBA Lba;
|
||||
UINTN ReadLen = *Len;
|
||||
ventoy_efi_file_replace *replace = NULL;
|
||||
|
||||
(VOID)This;
|
||||
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;
|
||||
}
|
||||
@@ -1367,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;
|
||||
@@ -1383,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;
|
||||
}
|
||||
@@ -1402,16 +1416,28 @@ 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);
|
||||
|
||||
if ((Mode & EFI_FILE_MODE_WRITE) > 0 && StrCmp(Name, L"\\loader\\random-seed") == 0)
|
||||
{
|
||||
if (gDebugPrint)
|
||||
{
|
||||
debug("## ventoy_wrapper_file_open return NOT_FOUND for random-seed %lx", Mode);
|
||||
sleep(3);
|
||||
}
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
Status = g_original_fopen(This, New, Name, Mode, Attributes);
|
||||
if (EFI_ERROR(Status))
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
if (g_file_replace_list && g_file_replace_list->magic == GRUB_FILE_REPLACE_MAGIC &&
|
||||
g_file_replace_list->new_file_virtual_id < g_virt_chunk_num)
|
||||
{
|
||||
@@ -1422,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;
|
||||
|
||||
@@ -1448,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;
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,140 @@
|
||||
/******************************************************************************
|
||||
* VtoyDrv.c
|
||||
*
|
||||
* Copyright (c) 2020, longpanda <admin@ventoy.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/PrintLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/DevicePathLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||
#include <Library/UefiApplicationEntryPoint.h>
|
||||
#include <Protocol/LoadedImage.h>
|
||||
#include <Guid/FileInfo.h>
|
||||
#include <Guid/FileSystemInfo.h>
|
||||
#include <Protocol/BlockIo.h>
|
||||
#include <Protocol/RamDisk.h>
|
||||
#include <Protocol/SimpleFileSystem.h>
|
||||
#include <VtoyUtil.h>
|
||||
|
||||
STATIC UINTN g_EfiDriverNameCnt = 0;
|
||||
STATIC CHAR16 *g_EfiDriverNameList[1024] = { NULL };
|
||||
|
||||
STATIC EFI_STATUS AddEfiDriverName(IN CHAR16 *DriverName)
|
||||
{
|
||||
UINTN i = 0;
|
||||
|
||||
if (g_EfiDriverNameCnt >= 1024)
|
||||
{
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
for (i = 0; i < g_EfiDriverNameCnt; i++)
|
||||
{
|
||||
if (g_EfiDriverNameList[i] && StrCmp(g_EfiDriverNameList[i], DriverName) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= g_EfiDriverNameCnt)
|
||||
{
|
||||
g_EfiDriverNameList[g_EfiDriverNameCnt] = DriverName;
|
||||
g_EfiDriverNameCnt++;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
EFI_STATUS ShowEfiDrivers(IN EFI_HANDLE ImageHandle, IN CONST CHAR16 *CmdLine)
|
||||
{
|
||||
UINTN i = 0;
|
||||
UINTN Count = 0;
|
||||
CHAR16 *DriverName = NULL;
|
||||
EFI_HANDLE *Handles = NULL;
|
||||
EFI_STATUS Status = EFI_SUCCESS;
|
||||
EFI_COMPONENT_NAME_PROTOCOL *NameProtocol = NULL;
|
||||
EFI_COMPONENT_NAME2_PROTOCOL *Name2Protocol = NULL;
|
||||
|
||||
(VOID)ImageHandle;
|
||||
(VOID)CmdLine;
|
||||
|
||||
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiComponentName2ProtocolGuid,
|
||||
NULL, &Count, &Handles);
|
||||
if (EFI_ERROR(Status))
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
|
||||
for (i = 0; i < Count; i++)
|
||||
{
|
||||
Status = gBS->HandleProtocol(Handles[i], &gEfiComponentName2ProtocolGuid, (VOID **)&Name2Protocol);
|
||||
if (EFI_ERROR(Status))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
DriverName = NULL;
|
||||
Status = VtoyGetComponentName(2, Name2Protocol, &DriverName);
|
||||
if ((!EFI_ERROR(Status)) && (DriverName))
|
||||
{
|
||||
AddEfiDriverName(DriverName);
|
||||
}
|
||||
}
|
||||
|
||||
Count = 0;
|
||||
FreePool(Handles);
|
||||
Handles = NULL;
|
||||
|
||||
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiComponentNameProtocolGuid,
|
||||
NULL, &Count, &Handles);
|
||||
if (EFI_ERROR(Status))
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
|
||||
for (i = 0; i < Count; i++)
|
||||
{
|
||||
Status = gBS->HandleProtocol(Handles[i], &gEfiComponentNameProtocolGuid, (VOID **)&NameProtocol);
|
||||
if (EFI_ERROR(Status))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
DriverName = NULL;
|
||||
Status = VtoyGetComponentName(1, Name2Protocol, &DriverName);
|
||||
if ((!EFI_ERROR(Status)) && (DriverName))
|
||||
{
|
||||
AddEfiDriverName(DriverName);
|
||||
}
|
||||
}
|
||||
|
||||
FreePool(Handles);
|
||||
|
||||
for (i = 0; i < g_EfiDriverNameCnt; i++)
|
||||
{
|
||||
Printf("%2d %s\n", i, g_EfiDriverNameList[i]);
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
@@ -44,8 +44,39 @@ STATIC grub_env_printf_pf g_env_printf = NULL;
|
||||
STATIC VtoyUtilFeature gFeatureList[] =
|
||||
{
|
||||
{ L"fix_windows_mmap", FixWindowsMemhole },
|
||||
{ L"show_efi_drivers", ShowEfiDrivers },
|
||||
};
|
||||
|
||||
EFI_STATUS VtoyGetComponentName(IN UINTN Ver, IN VOID *Protocol, OUT CHAR16 **DriverName)
|
||||
{
|
||||
EFI_STATUS Status = EFI_SUCCESS;
|
||||
CHAR16 *DrvName = NULL;
|
||||
EFI_COMPONENT_NAME_PROTOCOL *NameProtocol = NULL;
|
||||
EFI_COMPONENT_NAME2_PROTOCOL *Name2Protocol = NULL;
|
||||
|
||||
if (1 == Ver)
|
||||
{
|
||||
NameProtocol = (EFI_COMPONENT_NAME_PROTOCOL *)Protocol;
|
||||
Status = NameProtocol->GetDriverName(Protocol, "en", &DrvName);
|
||||
if (EFI_ERROR(Status) || NULL == DrvName)
|
||||
{
|
||||
Status = NameProtocol->GetDriverName(Protocol, "eng", &DrvName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Name2Protocol = (EFI_COMPONENT_NAME2_PROTOCOL *)Protocol;
|
||||
Status = Name2Protocol->GetDriverName(Protocol, "en", &DrvName);
|
||||
if (EFI_ERROR(Status) || NULL == DrvName)
|
||||
{
|
||||
Status = Name2Protocol->GetDriverName(Protocol, "eng", &DrvName);
|
||||
}
|
||||
}
|
||||
|
||||
*DriverName = DrvName;
|
||||
return Status;
|
||||
}
|
||||
|
||||
VOID EFIAPI VtoyUtilDebug(IN CONST CHAR8 *Format, ...)
|
||||
{
|
||||
VA_LIST Marker;
|
||||
|
@@ -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()
|
||||
@@ -57,7 +58,9 @@ VOID EFIAPI VtoyUtilDebug(IN CONST CHAR8 *Format, ...);
|
||||
#define debug(expr, ...) if (gVtoyDebugPrint) VtoyUtilDebug("[VTOY] "expr"\n", ##__VA_ARGS__)
|
||||
#define Printf VtoyUtilDebug
|
||||
|
||||
EFI_STATUS VtoyGetComponentName(IN UINTN Ver, IN VOID *Protocol, OUT CHAR16 **DriverName);
|
||||
EFI_STATUS FixWindowsMemhole(IN EFI_HANDLE ImageHandle, IN CONST CHAR16 *CmdLine);
|
||||
EFI_STATUS ShowEfiDrivers(IN EFI_HANDLE ImageHandle, IN CONST CHAR16 *CmdLine);
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -28,6 +28,7 @@
|
||||
[Sources]
|
||||
VtoyUtil.h
|
||||
VtoyUtil.c
|
||||
VtoyDrv.c
|
||||
Memhole.c
|
||||
|
||||
[Packages]
|
||||
|
@@ -913,6 +913,12 @@ module = {
|
||||
enable = x86_64_efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = fwload;
|
||||
efi = commands/efi/fwload.c;
|
||||
enable = efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = gptsync;
|
||||
common = commands/gptsync.c;
|
||||
@@ -1123,6 +1129,21 @@ module = {
|
||||
common = commands/sleep.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = smbios;
|
||||
|
||||
common = commands/smbios.c;
|
||||
efi = commands/efi/smbios.c;
|
||||
i386_pc = commands/i386/pc/smbios.c;
|
||||
i386_coreboot = commands/i386/pc/smbios.c;
|
||||
i386_multiboot = commands/i386/pc/smbios.c;
|
||||
|
||||
enable = efi;
|
||||
enable = i386_pc;
|
||||
enable = i386_coreboot;
|
||||
enable = i386_multiboot;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = suspend;
|
||||
ieee1275 = commands/ieee1275/suspend.c;
|
||||
@@ -1610,6 +1631,7 @@ module = {
|
||||
common = ventoy/ventoy_vhd.c;
|
||||
common = ventoy/ventoy_plugin.c;
|
||||
common = ventoy/ventoy_json.c;
|
||||
common = ventoy/ventoy_browser.c;
|
||||
common = ventoy/lzx.c;
|
||||
common = ventoy/xpress.c;
|
||||
common = ventoy/huffman.c;
|
||||
@@ -1621,6 +1643,12 @@ module = {
|
||||
common = term/setkey.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = mouse;
|
||||
efi = term/efi/mouse.c;
|
||||
enable = efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = hello;
|
||||
common = hello/hello.c;
|
||||
|
205
GRUB2/MOD_SRC/grub-2.04/grub-core/commands/efi/fwload.c
Normal file
205
GRUB2/MOD_SRC/grub-2.04/grub-core/commands/efi/fwload.c
Normal file
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2022 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/efi/api.h>
|
||||
#include <grub/efi/efi.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/types.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_efi_guid_t loaded_image_guid = GRUB_EFI_LOADED_IMAGE_GUID;
|
||||
|
||||
static grub_efi_status_t
|
||||
grub_efi_connect_all (void)
|
||||
{
|
||||
grub_efi_status_t status;
|
||||
grub_efi_uintn_t handle_count;
|
||||
grub_efi_handle_t *handle_buffer;
|
||||
grub_efi_uintn_t index;
|
||||
grub_efi_boot_services_t *b;
|
||||
grub_dprintf ("efi", "Connecting ...\n");
|
||||
b = grub_efi_system_table->boot_services;
|
||||
status = efi_call_5 (b->locate_handle_buffer,
|
||||
GRUB_EFI_ALL_HANDLES, NULL, NULL,
|
||||
&handle_count, &handle_buffer);
|
||||
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
return status;
|
||||
|
||||
for (index = 0; index < handle_count; index++)
|
||||
{
|
||||
status = efi_call_4 (b->connect_controller,
|
||||
handle_buffer[index], NULL, NULL, 1);
|
||||
}
|
||||
|
||||
if (handle_buffer)
|
||||
{
|
||||
efi_call_1 (b->free_pool, handle_buffer);
|
||||
}
|
||||
return GRUB_EFI_SUCCESS;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_efi_load_driver (grub_size_t size, void *boot_image, int connect)
|
||||
{
|
||||
grub_efi_status_t status;
|
||||
grub_efi_handle_t driver_handle;
|
||||
grub_efi_boot_services_t *b;
|
||||
grub_efi_loaded_image_t *loaded_image;
|
||||
|
||||
b = grub_efi_system_table->boot_services;
|
||||
|
||||
status = efi_call_6 (b->load_image, 0, grub_efi_image_handle, NULL,
|
||||
boot_image, size, &driver_handle);
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
{
|
||||
if (status == GRUB_EFI_OUT_OF_RESOURCES)
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of resources");
|
||||
else
|
||||
grub_error (GRUB_ERR_BAD_OS, "cannot load image");
|
||||
goto fail;
|
||||
}
|
||||
loaded_image = grub_efi_get_loaded_image (driver_handle);
|
||||
if (! loaded_image)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_OS, "no loaded image available");
|
||||
goto fail;
|
||||
}
|
||||
grub_dprintf ("efi", "Registering loaded image\n");
|
||||
status = efi_call_3 (b->handle_protocol, driver_handle,
|
||||
&loaded_image_guid, (void **)&loaded_image);
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_OS, "not a dirver");
|
||||
goto fail;
|
||||
}
|
||||
grub_dprintf ("efi", "StartImage: %p\n", boot_image);
|
||||
status = efi_call_3 (b->start_image, driver_handle, NULL, NULL);
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_OS, "StartImage failed");
|
||||
goto fail;
|
||||
}
|
||||
if (connect)
|
||||
{
|
||||
status = grub_efi_connect_all ();
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_OS, "cannot connect controllers\n");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
grub_dprintf ("efi", "Driver installed\n");
|
||||
return 0;
|
||||
fail:
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static const struct grub_arg_option options_fwload[] =
|
||||
{
|
||||
{"nc", 'n', 0, N_("Loads the driver, but does not connect the driver."), 0, 0},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_fwload (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
struct grub_arg_list *state = ctxt->state;
|
||||
int connect = 1;
|
||||
grub_file_t file = 0;
|
||||
grub_efi_boot_services_t *b;
|
||||
grub_efi_status_t status;
|
||||
grub_efi_uintn_t pages = 0;
|
||||
grub_ssize_t size;
|
||||
grub_efi_physical_address_t address;
|
||||
void *boot_image = 0;
|
||||
|
||||
b = grub_efi_system_table->boot_services;
|
||||
if (argc != 1)
|
||||
goto fail;
|
||||
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE);
|
||||
if (! file)
|
||||
goto fail;
|
||||
size = grub_file_size (file);
|
||||
if (!size)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]);
|
||||
goto fail;
|
||||
}
|
||||
pages = (((grub_efi_uintn_t) size + ((1 << 12) - 1)) >> 12);
|
||||
status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_ANY_PAGES,
|
||||
GRUB_EFI_LOADER_CODE, pages, &address);
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
||||
goto fail;
|
||||
}
|
||||
boot_image = (void *) ((grub_addr_t) address);
|
||||
if (grub_file_read (file, boot_image, size) != size)
|
||||
{
|
||||
if (grub_errno == GRUB_ERR_NONE)
|
||||
grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]);
|
||||
goto fail;
|
||||
}
|
||||
grub_file_close (file);
|
||||
if (state[0].set)
|
||||
connect = 0;
|
||||
if (grub_efi_load_driver (size, boot_image, connect))
|
||||
goto fail;
|
||||
return GRUB_ERR_NONE;
|
||||
fail:
|
||||
if (file)
|
||||
grub_file_close (file);
|
||||
if (address)
|
||||
efi_call_2 (b->free_pages, address, pages);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_fwconnect (grub_extcmd_context_t ctxt __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
char **args __attribute__ ((unused)))
|
||||
{
|
||||
grub_efi_connect_all ();
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_extcmd_t cmd_fwload, cmd_fwconnect;
|
||||
|
||||
GRUB_MOD_INIT(fwload)
|
||||
{
|
||||
cmd_fwload = grub_register_extcmd ("fwload", grub_cmd_fwload, 0, N_("FILE"),
|
||||
N_("Install UEFI driver."), options_fwload);
|
||||
cmd_fwconnect = grub_register_extcmd ("fwconnect", grub_cmd_fwconnect, 0,
|
||||
NULL, N_("Connect drivers."), 0);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(fwload)
|
||||
{
|
||||
grub_unregister_extcmd (cmd_fwload);
|
||||
grub_unregister_extcmd (cmd_fwconnect);
|
||||
}
|
61
GRUB2/MOD_SRC/grub-2.04/grub-core/commands/efi/smbios.c
Normal file
61
GRUB2/MOD_SRC/grub-2.04/grub-core/commands/efi/smbios.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/* smbios.c - get smbios tables. */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2019 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/smbios.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/efi/efi.h>
|
||||
#include <grub/efi/api.h>
|
||||
|
||||
struct grub_smbios_eps *
|
||||
grub_machine_smbios_get_eps (void)
|
||||
{
|
||||
unsigned i;
|
||||
static grub_efi_packed_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
|
||||
|
||||
for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
|
||||
{
|
||||
grub_efi_packed_guid_t *guid =
|
||||
&grub_efi_system_table->configuration_table[i].vendor_guid;
|
||||
|
||||
if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_efi_packed_guid_t)))
|
||||
return (struct grub_smbios_eps *)
|
||||
grub_efi_system_table->configuration_table[i].vendor_table;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct grub_smbios_eps3 *
|
||||
grub_machine_smbios_get_eps3 (void)
|
||||
{
|
||||
unsigned i;
|
||||
static grub_efi_packed_guid_t smbios3_guid = GRUB_EFI_SMBIOS3_TABLE_GUID;
|
||||
|
||||
for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
|
||||
{
|
||||
grub_efi_packed_guid_t *guid =
|
||||
&grub_efi_system_table->configuration_table[i].vendor_guid;
|
||||
|
||||
if (! grub_memcmp (guid, &smbios3_guid, sizeof (grub_efi_packed_guid_t)))
|
||||
return (struct grub_smbios_eps3 *)
|
||||
grub_efi_system_table->configuration_table[i].vendor_table;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@@ -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)
|
||||
|
52
GRUB2/MOD_SRC/grub-2.04/grub-core/commands/i386/pc/smbios.c
Normal file
52
GRUB2/MOD_SRC/grub-2.04/grub-core/commands/i386/pc/smbios.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/* smbios.c - get smbios tables. */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2019 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/acpi.h>
|
||||
#include <grub/smbios.h>
|
||||
#include <grub/misc.h>
|
||||
|
||||
struct grub_smbios_eps *
|
||||
grub_machine_smbios_get_eps (void)
|
||||
{
|
||||
grub_uint8_t *ptr;
|
||||
|
||||
grub_dprintf ("smbios", "Looking for SMBIOS EPS. Scanning BIOS\n");
|
||||
|
||||
for (ptr = (grub_uint8_t *) 0xf0000; ptr < (grub_uint8_t *) 0x100000; ptr += 16)
|
||||
if (grub_memcmp (ptr, "_SM_", 4) == 0
|
||||
&& grub_byte_checksum (ptr, sizeof (struct grub_smbios_eps)) == 0)
|
||||
return (struct grub_smbios_eps *) ptr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct grub_smbios_eps3 *
|
||||
grub_machine_smbios_get_eps3 (void)
|
||||
{
|
||||
grub_uint8_t *ptr;
|
||||
|
||||
grub_dprintf ("smbios", "Looking for SMBIOS3 EPS. Scanning BIOS\n");
|
||||
|
||||
for (ptr = (grub_uint8_t *) 0xf0000; ptr < (grub_uint8_t *) 0x100000; ptr += 16)
|
||||
if (grub_memcmp (ptr, "_SM3_", 5) == 0
|
||||
&& grub_byte_checksum (ptr, sizeof (struct grub_smbios_eps3)) == 0)
|
||||
return (struct grub_smbios_eps3 *) ptr;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -68,7 +68,7 @@ iterate_device (const char *name, void *data)
|
||||
/* Skip floppy drives when requested. */
|
||||
if (ctx->no_floppy &&
|
||||
name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9')
|
||||
return 1;
|
||||
return 0;
|
||||
|
||||
if (g_no_vtoyefi_part && (grub_strcmp(name, g_vtoyefi_dosname) == 0 || grub_strcmp(name, g_vtoyefi_gptname) == 0)) {
|
||||
return 0;
|
||||
|
399
GRUB2/MOD_SRC/grub-2.04/grub-core/commands/smbios.c
Normal file
399
GRUB2/MOD_SRC/grub-2.04/grub-core/commands/smbios.c
Normal file
@@ -0,0 +1,399 @@
|
||||
/* smbios.c - retrieve smbios information. */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2019 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/env.h>
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/smbios.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
/* Abstract useful values found in either the SMBIOS3 or SMBIOS EPS. */
|
||||
static struct {
|
||||
grub_addr_t start;
|
||||
grub_addr_t end;
|
||||
grub_uint16_t structures;
|
||||
} table_desc;
|
||||
|
||||
static grub_extcmd_t cmd;
|
||||
|
||||
/* Locate the SMBIOS entry point structure depending on the hardware. */
|
||||
struct grub_smbios_eps *
|
||||
grub_smbios_get_eps (void)
|
||||
{
|
||||
static struct grub_smbios_eps *eps = NULL;
|
||||
|
||||
if (eps != NULL)
|
||||
return eps;
|
||||
|
||||
eps = grub_machine_smbios_get_eps ();
|
||||
|
||||
return eps;
|
||||
}
|
||||
|
||||
/* Locate the SMBIOS3 entry point structure depending on the hardware. */
|
||||
static struct grub_smbios_eps3 *
|
||||
grub_smbios_get_eps3 (void)
|
||||
{
|
||||
static struct grub_smbios_eps3 *eps = NULL;
|
||||
|
||||
if (eps != NULL)
|
||||
return eps;
|
||||
|
||||
eps = grub_machine_smbios_get_eps3 ();
|
||||
|
||||
return eps;
|
||||
}
|
||||
|
||||
static char *
|
||||
linux_string (const char *value)
|
||||
{
|
||||
char *out = grub_malloc( grub_strlen (value) + 1);
|
||||
const char *src = value;
|
||||
char *dst = out;
|
||||
|
||||
for (; *src; src++)
|
||||
if (*src > ' ' && *src < 127 && *src != ':')
|
||||
*dst++ = *src;
|
||||
|
||||
*dst = 0;
|
||||
return out;
|
||||
}
|
||||
|
||||
/*
|
||||
* These functions convert values from the various SMBIOS structure field types
|
||||
* into a string formatted to be returned to the user. They expect that the
|
||||
* structure and offset were already validated. When the requested data is
|
||||
* successfully retrieved and formatted, the pointer to the string is returned;
|
||||
* otherwise, NULL is returned on failure. Don't free the result.
|
||||
*/
|
||||
|
||||
static const char *
|
||||
grub_smbios_format_byte (const grub_uint8_t *structure, grub_uint8_t offset)
|
||||
{
|
||||
static char buffer[sizeof ("255")];
|
||||
|
||||
grub_snprintf (buffer, sizeof (buffer), "%u", structure[offset]);
|
||||
|
||||
return (const char *)buffer;
|
||||
}
|
||||
|
||||
static const char *
|
||||
grub_smbios_format_word (const grub_uint8_t *structure, grub_uint8_t offset)
|
||||
{
|
||||
static char buffer[sizeof ("65535")];
|
||||
|
||||
grub_uint16_t value = grub_get_unaligned16 (structure + offset);
|
||||
grub_snprintf (buffer, sizeof (buffer), "%u", value);
|
||||
|
||||
return (const char *)buffer;
|
||||
}
|
||||
|
||||
static const char *
|
||||
grub_smbios_format_dword (const grub_uint8_t *structure, grub_uint8_t offset)
|
||||
{
|
||||
static char buffer[sizeof ("4294967295")];
|
||||
|
||||
grub_uint32_t value = grub_get_unaligned32 (structure + offset);
|
||||
grub_snprintf (buffer, sizeof (buffer), "%" PRIuGRUB_UINT32_T, value);
|
||||
|
||||
return (const char *)buffer;
|
||||
}
|
||||
|
||||
static const char *
|
||||
grub_smbios_format_qword (const grub_uint8_t *structure, grub_uint8_t offset)
|
||||
{
|
||||
static char buffer[sizeof ("18446744073709551615")];
|
||||
|
||||
grub_uint64_t value = grub_get_unaligned64 (structure + offset);
|
||||
grub_snprintf (buffer, sizeof (buffer), "%" PRIuGRUB_UINT64_T, value);
|
||||
|
||||
return (const char *)buffer;
|
||||
}
|
||||
|
||||
static const char *
|
||||
grub_smbios_get_string (const grub_uint8_t *structure, grub_uint8_t offset)
|
||||
{
|
||||
const grub_uint8_t *ptr = structure + structure[1];
|
||||
const grub_uint8_t *table_end = (const grub_uint8_t *)table_desc.end;
|
||||
const grub_uint8_t referenced_string_number = structure[offset];
|
||||
grub_uint8_t i;
|
||||
|
||||
/* A string referenced with zero is interpreted as unset. */
|
||||
if (referenced_string_number == 0)
|
||||
return NULL;
|
||||
|
||||
/* Search the string set. */
|
||||
for (i = 1; *ptr != 0 && ptr < table_end; i++)
|
||||
if (i == referenced_string_number)
|
||||
{
|
||||
const char *str = (const char *)ptr;
|
||||
while (*ptr++ != 0)
|
||||
if (ptr >= table_end)
|
||||
return NULL; /* The string isn't terminated. */
|
||||
return str;
|
||||
}
|
||||
else
|
||||
while (*ptr++ != 0 && ptr < table_end);
|
||||
|
||||
/* The string number is greater than the number of strings in the set. */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *
|
||||
grub_smbios_format_uuid (const grub_uint8_t *structure, grub_uint8_t offset)
|
||||
{
|
||||
static char buffer[sizeof ("ffffffff-ffff-ffff-ffff-ffffffffffff")];
|
||||
const grub_uint8_t *f = structure + offset; /* little-endian fields */
|
||||
const grub_uint8_t *g = f + 8; /* byte-by-byte fields */
|
||||
|
||||
grub_snprintf (buffer, sizeof (buffer),
|
||||
"%02x%02x%02x%02x-%02x%02x-%02x%02x-"
|
||||
"%02x%02x-%02x%02x%02x%02x%02x%02x",
|
||||
f[3], f[2], f[1], f[0], f[5], f[4], f[7], f[6],
|
||||
g[0], g[1], g[2], g[3], g[4], g[5], g[6], g[7]);
|
||||
|
||||
return (const char *)buffer;
|
||||
}
|
||||
|
||||
/* List the field formatting functions and the number of bytes they need. */
|
||||
static const struct {
|
||||
const char *(*format) (const grub_uint8_t *structure, grub_uint8_t offset);
|
||||
grub_uint8_t field_length;
|
||||
} field_extractors[] = {
|
||||
{grub_smbios_format_byte, 1},
|
||||
{grub_smbios_format_word, 2},
|
||||
{grub_smbios_format_dword, 4},
|
||||
{grub_smbios_format_qword, 8},
|
||||
{grub_smbios_get_string, 1},
|
||||
{grub_smbios_format_uuid, 16}
|
||||
};
|
||||
|
||||
/* List command options, with structure field getters ordered as above. */
|
||||
#define FIRST_GETTER_OPT (3)
|
||||
#define SETTER_OPT (FIRST_GETTER_OPT + ARRAY_SIZE(field_extractors))
|
||||
#define LINUX_OPT (FIRST_GETTER_OPT + ARRAY_SIZE(field_extractors) + 1)
|
||||
|
||||
static const struct grub_arg_option options[] = {
|
||||
{"type", 't', 0, N_("Match structures with the given type."),
|
||||
N_("type"), ARG_TYPE_INT},
|
||||
{"handle", 'h', 0, N_("Match structures with the given handle."),
|
||||
N_("handle"), ARG_TYPE_INT},
|
||||
{"match", 'm', 0, N_("Select a structure when several match."),
|
||||
N_("match"), ARG_TYPE_INT},
|
||||
{"get-byte", 'b', 0, N_("Get the byte's value at the given offset."),
|
||||
N_("offset"), ARG_TYPE_INT},
|
||||
{"get-word", 'w', 0, N_("Get two bytes' value at the given offset."),
|
||||
N_("offset"), ARG_TYPE_INT},
|
||||
{"get-dword", 'd', 0, N_("Get four bytes' value at the given offset."),
|
||||
N_("offset"), ARG_TYPE_INT},
|
||||
{"get-qword", 'q', 0, N_("Get eight bytes' value at the given offset."),
|
||||
N_("offset"), ARG_TYPE_INT},
|
||||
{"get-string", 's', 0, N_("Get the string specified at the given offset."),
|
||||
N_("offset"), ARG_TYPE_INT},
|
||||
{"get-uuid", 'u', 0, N_("Get the UUID's value at the given offset."),
|
||||
N_("offset"), ARG_TYPE_INT},
|
||||
{"set", '\0', 0, N_("Store the value in the given variable name."),
|
||||
N_("variable"), ARG_TYPE_STRING},
|
||||
{"linux", '\0', 0, N_("Filter the result like linux does."),
|
||||
N_("variable"), ARG_TYPE_NONE},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
/*
|
||||
* Return a matching SMBIOS structure.
|
||||
*
|
||||
* This method can use up to three criteria for selecting a structure:
|
||||
* - The "type" field (use -1 to ignore)
|
||||
* - The "handle" field (use -1 to ignore)
|
||||
* - Which to return if several match (use 0 to ignore)
|
||||
*
|
||||
* The return value is a pointer to the first matching structure. If no
|
||||
* structures match the given parameters, NULL is returned.
|
||||
*/
|
||||
static const grub_uint8_t *
|
||||
grub_smbios_match_structure (const grub_int16_t type,
|
||||
const grub_int32_t handle,
|
||||
const grub_uint16_t match)
|
||||
{
|
||||
const grub_uint8_t *ptr = (const grub_uint8_t *)table_desc.start;
|
||||
const grub_uint8_t *table_end = (const grub_uint8_t *)table_desc.end;
|
||||
grub_uint16_t structures = table_desc.structures;
|
||||
grub_uint16_t structure_count = 0;
|
||||
grub_uint16_t matches = 0;
|
||||
|
||||
while (ptr < table_end
|
||||
&& ptr[1] >= 4 /* Valid structures include the 4-byte header. */
|
||||
&& (structure_count++ < structures || structures == 0))
|
||||
{
|
||||
grub_uint16_t structure_handle = grub_get_unaligned16 (ptr + 2);
|
||||
grub_uint8_t structure_type = ptr[0];
|
||||
|
||||
if ((handle < 0 || handle == structure_handle)
|
||||
&& (type < 0 || type == structure_type)
|
||||
&& (match == 0 || match == ++matches))
|
||||
return ptr;
|
||||
else
|
||||
{
|
||||
ptr += ptr[1];
|
||||
while ((*ptr++ != 0 || *ptr++ != 0) && ptr < table_end);
|
||||
}
|
||||
|
||||
if (structure_type == GRUB_SMBIOS_TYPE_END_OF_TABLE)
|
||||
break;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_smbios (grub_extcmd_context_t ctxt,
|
||||
int argc __attribute__ ((unused)),
|
||||
char **argv __attribute__ ((unused)))
|
||||
{
|
||||
struct grub_arg_list *state = ctxt->state;
|
||||
|
||||
grub_int16_t type = -1;
|
||||
grub_int32_t handle = -1;
|
||||
grub_uint16_t match = 0;
|
||||
grub_uint8_t offset = 0;
|
||||
|
||||
const grub_uint8_t *structure;
|
||||
const char *value;
|
||||
char *modified_value = NULL;
|
||||
grub_int32_t option;
|
||||
grub_int8_t field_type = -1;
|
||||
grub_uint8_t i;
|
||||
|
||||
if (table_desc.start == 0)
|
||||
return grub_error (GRUB_ERR_IO,
|
||||
N_("the SMBIOS entry point structure was not found"));
|
||||
|
||||
/* Read the given filtering options. */
|
||||
if (state[0].set)
|
||||
{
|
||||
option = grub_strtol (state[0].arg, NULL, 0);
|
||||
if (option < 0 || option > 255)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
N_("the type must be between 0 and 255"));
|
||||
type = (grub_int16_t)option;
|
||||
}
|
||||
if (state[1].set)
|
||||
{
|
||||
option = grub_strtol (state[1].arg, NULL, 0);
|
||||
if (option < 0 || option > 65535)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
N_("the handle must be between 0 and 65535"));
|
||||
handle = (grub_int32_t)option;
|
||||
}
|
||||
if (state[2].set)
|
||||
{
|
||||
option = grub_strtol (state[2].arg, NULL, 0);
|
||||
if (option <= 0 || option > 65535)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
N_("the match must be a positive integer"));
|
||||
match = (grub_uint16_t)option;
|
||||
}
|
||||
|
||||
/* Determine the data type of the structure field to retrieve. */
|
||||
for (i = 0; i < ARRAY_SIZE(field_extractors); i++)
|
||||
if (state[FIRST_GETTER_OPT + i].set)
|
||||
{
|
||||
if (field_type >= 0)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
N_("only one --get option is usable at a time"));
|
||||
field_type = i;
|
||||
}
|
||||
|
||||
/* Require a choice of a structure field to return. */
|
||||
if (field_type < 0)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
N_("one of the --get options is required"));
|
||||
|
||||
/* Locate a matching SMBIOS structure. */
|
||||
structure = grub_smbios_match_structure (type, handle, match);
|
||||
if (structure == NULL)
|
||||
return grub_error (GRUB_ERR_IO,
|
||||
N_("no structure matched the given options"));
|
||||
|
||||
/* Ensure the requested byte offset is inside the structure. */
|
||||
option = grub_strtol (state[FIRST_GETTER_OPT + field_type].arg, NULL, 0);
|
||||
if (option < 0 || option >= structure[1])
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE,
|
||||
N_("the given offset is outside the structure"));
|
||||
|
||||
/* Ensure the requested data type at the offset is inside the structure. */
|
||||
offset = (grub_uint8_t)option;
|
||||
if (offset + field_extractors[field_type].field_length > structure[1])
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE,
|
||||
N_("the field ends outside the structure"));
|
||||
|
||||
/* Format the requested structure field into a readable string. */
|
||||
value = field_extractors[field_type].format (structure, offset);
|
||||
if (value == NULL)
|
||||
return grub_error (GRUB_ERR_IO,
|
||||
N_("failed to retrieve the structure field"));
|
||||
|
||||
if (state[LINUX_OPT].set)
|
||||
value = modified_value = linux_string (value);
|
||||
|
||||
/* Store or print the formatted value. */
|
||||
if (state[SETTER_OPT].set)
|
||||
grub_env_set (state[SETTER_OPT].arg, value);
|
||||
else
|
||||
grub_printf ("%s\n", value);
|
||||
|
||||
grub_free(modified_value);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
GRUB_MOD_INIT(smbios)
|
||||
{
|
||||
struct grub_smbios_eps3 *eps3;
|
||||
struct grub_smbios_eps *eps;
|
||||
|
||||
if ((eps3 = grub_smbios_get_eps3 ()))
|
||||
{
|
||||
table_desc.start = (grub_addr_t)eps3->table_address;
|
||||
table_desc.end = table_desc.start + eps3->maximum_table_length;
|
||||
table_desc.structures = 0; /* SMBIOS3 drops the structure count. */
|
||||
}
|
||||
else if ((eps = grub_smbios_get_eps ()))
|
||||
{
|
||||
table_desc.start = (grub_addr_t)eps->intermediate.table_address;
|
||||
table_desc.end = table_desc.start + eps->intermediate.table_length;
|
||||
table_desc.structures = eps->intermediate.structures;
|
||||
}
|
||||
|
||||
cmd = grub_register_extcmd ("smbios", grub_cmd_smbios, 0,
|
||||
N_("[-t type] [-h handle] [-m match] "
|
||||
"(-b|-w|-d|-q|-s|-u) offset "
|
||||
"[--set variable]"),
|
||||
N_("Retrieve SMBIOS information."), options);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(smbios)
|
||||
{
|
||||
grub_unregister_extcmd (cmd);
|
||||
}
|
||||
|
1603
GRUB2/MOD_SRC/grub-2.04/grub-core/font/font.c
Normal file
1603
GRUB2/MOD_SRC/grub-2.04/grub-core/font/font.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -426,7 +426,7 @@ grub_fshelp_read_file (grub_disk_t disk, grub_fshelp_node_t node,
|
||||
if (grub_errno)
|
||||
return -1;
|
||||
}
|
||||
else if (read_hook != (grub_disk_read_hook_t)grub_disk_blocklist_read)
|
||||
else if (read_hook != (grub_disk_read_hook_t)(void *)grub_disk_blocklist_read)
|
||||
grub_memset (buf, 0, blockend);
|
||||
|
||||
buf += blocksize - skipfirst;
|
||||
|
@@ -33,6 +33,7 @@
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static int g_ventoy_no_joliet = 0;
|
||||
static int g_ventoy_cur_joliet = 0;
|
||||
static grub_uint64_t g_ventoy_last_read_pos = 0;
|
||||
static grub_uint64_t g_ventoy_last_read_offset = 0;
|
||||
static grub_uint64_t g_ventoy_last_read_dirent_pos = 0;
|
||||
@@ -451,6 +452,7 @@ grub_iso9660_mount (grub_disk_t disk)
|
||||
|
||||
data->disk = disk;
|
||||
|
||||
g_ventoy_cur_joliet = 0;
|
||||
block = 16;
|
||||
do
|
||||
{
|
||||
@@ -484,6 +486,7 @@ grub_iso9660_mount (grub_disk_t disk)
|
||||
if (0 == g_ventoy_no_joliet) {
|
||||
copy_voldesc = 1;
|
||||
data->joliet = 1;
|
||||
g_ventoy_cur_joliet = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1118,6 +1121,11 @@ void grub_iso9660_set_nojoliet(int nojoliet)
|
||||
g_ventoy_no_joliet = nojoliet;
|
||||
}
|
||||
|
||||
int grub_iso9660_is_joliet(void)
|
||||
{
|
||||
return g_ventoy_cur_joliet;
|
||||
}
|
||||
|
||||
grub_uint64_t grub_iso9660_get_last_read_pos(grub_file_t file)
|
||||
{
|
||||
(void)file;
|
||||
|
@@ -119,6 +119,8 @@ grub_gfxmenu_try (int entry, grub_menu_t menu, int nested)
|
||||
view->menu = menu;
|
||||
view->nested = nested;
|
||||
view->first_timeout = -1;
|
||||
if (menu->size)
|
||||
view->menu_title_offset = grub_zalloc (sizeof (*view->menu_title_offset) * menu->size);
|
||||
|
||||
grub_video_set_viewport (0, 0, mode_info.width, mode_info.height);
|
||||
if (view->double_repaint)
|
||||
@@ -134,6 +136,8 @@ grub_gfxmenu_try (int entry, grub_menu_t menu, int nested)
|
||||
instance->fini = grub_gfxmenu_viewer_fini;
|
||||
instance->print_timeout = grub_gfxmenu_print_timeout;
|
||||
instance->clear_timeout = grub_gfxmenu_clear_timeout;
|
||||
if (view->menu_title_offset)
|
||||
instance->scroll_chosen_entry = grub_gfxmenu_scroll_chosen_entry;
|
||||
|
||||
grub_menu_register_viewer (instance);
|
||||
|
||||
|
@@ -59,11 +59,15 @@ struct grub_gui_label
|
||||
grub_font_t font;
|
||||
grub_video_rgba_color_t color;
|
||||
int value;
|
||||
int vtoytip;
|
||||
enum align_mode align;
|
||||
};
|
||||
|
||||
typedef struct grub_gui_label *grub_gui_label_t;
|
||||
|
||||
extern const char * g_ventoy_tip_msg1;
|
||||
extern const char * g_ventoy_tip_msg2;
|
||||
|
||||
static void
|
||||
label_destroy (void *vself)
|
||||
{
|
||||
@@ -90,6 +94,7 @@ label_is_instance (void *vself __attribute__((unused)), const char *type)
|
||||
static void
|
||||
label_paint (void *vself, const grub_video_rect_t *region)
|
||||
{
|
||||
const char *text;
|
||||
grub_gui_label_t self = vself;
|
||||
|
||||
if (! self->visible)
|
||||
@@ -98,16 +103,24 @@ label_paint (void *vself, const grub_video_rect_t *region)
|
||||
if (!grub_video_have_common_points (region, &self->bounds))
|
||||
return;
|
||||
|
||||
if (self->vtoytip == 1) {
|
||||
text = g_ventoy_tip_msg1 ? g_ventoy_tip_msg1 : "";
|
||||
} else if (self->vtoytip == 2) {
|
||||
text = g_ventoy_tip_msg2 ? g_ventoy_tip_msg2 : "";
|
||||
} else {
|
||||
text = self->text;
|
||||
}
|
||||
|
||||
/* Calculate the starting x coordinate. */
|
||||
int left_x;
|
||||
if (self->align == align_left)
|
||||
left_x = 0;
|
||||
else if (self->align == align_center)
|
||||
left_x = (self->bounds.width
|
||||
- grub_font_get_string_width (self->font, self->text)) / 2;
|
||||
- grub_font_get_string_width (self->font, text)) / 2;
|
||||
else if (self->align == align_right)
|
||||
left_x = (self->bounds.width
|
||||
- grub_font_get_string_width (self->font, self->text));
|
||||
- grub_font_get_string_width (self->font, text));
|
||||
else
|
||||
return; /* Invalid alignment. */
|
||||
|
||||
@@ -116,7 +129,7 @@ label_paint (void *vself, const grub_video_rect_t *region)
|
||||
|
||||
grub_video_rect_t vpsave;
|
||||
grub_gui_set_viewport (&self->bounds, &vpsave);
|
||||
grub_font_draw_string (self->text,
|
||||
grub_font_draw_string (text,
|
||||
self->font,
|
||||
grub_video_map_rgba_color (self->color),
|
||||
left_x,
|
||||
@@ -156,8 +169,8 @@ static void
|
||||
label_get_minimal_size (void *vself, unsigned *width, unsigned *height)
|
||||
{
|
||||
grub_gui_label_t self = vself;
|
||||
*width = grub_font_get_string_width (self->font, self->text);
|
||||
*height = (grub_font_get_ascent (self->font)
|
||||
*width = grub_font_get_string_width (self->font, self->text);
|
||||
*height = (grub_font_get_ascent (self->font)
|
||||
+ grub_font_get_descent (self->font));
|
||||
}
|
||||
|
||||
@@ -255,8 +268,14 @@ label_set_property (void *vself, const char *name, const char *value)
|
||||
{
|
||||
grub_gfxmenu_timeout_unregister ((grub_gui_component_t) self);
|
||||
grub_free (self->id);
|
||||
if (value)
|
||||
if (value) {
|
||||
self->id = grub_strdup (value);
|
||||
if (grub_strcmp(value, "VTOY_MENU_TIP_1") == 0) {
|
||||
self->vtoytip = 1;
|
||||
} else if (grub_strcmp(value, "VTOY_MENU_TIP_2") == 0) {
|
||||
self->vtoytip = 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
self->id = 0;
|
||||
if (self->id && grub_strcmp (self->id, GRUB_GFXMENU_TIMEOUT_COMPONENT_ID)
|
||||
|
961
GRUB2/MOD_SRC/grub-2.04/grub-core/gfxmenu/gui_list.c
Normal file
961
GRUB2/MOD_SRC/grub-2.04/grub-core/gfxmenu/gui_list.c
Normal file
@@ -0,0 +1,961 @@
|
||||
/* gui_list.c - GUI component to display a selectable list of items. */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2008,2009 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/gui.h>
|
||||
#include <grub/gui_string_util.h>
|
||||
#include <grub/gfxmenu_view.h>
|
||||
#include <grub/gfxwidgets.h>
|
||||
#include <grub/color.h>
|
||||
#include <grub/charset.h>
|
||||
|
||||
enum scrollbar_slice_mode {
|
||||
SCROLLBAR_SLICE_WEST,
|
||||
SCROLLBAR_SLICE_CENTER,
|
||||
SCROLLBAR_SLICE_EAST
|
||||
};
|
||||
|
||||
struct grub_gui_list_impl
|
||||
{
|
||||
struct grub_gui_list list;
|
||||
|
||||
grub_gui_container_t parent;
|
||||
grub_video_rect_t bounds;
|
||||
char *id;
|
||||
int visible;
|
||||
|
||||
int icon_width;
|
||||
int icon_height;
|
||||
int item_height;
|
||||
int item_padding;
|
||||
int item_icon_space;
|
||||
int item_spacing;
|
||||
grub_font_t item_font;
|
||||
int selected_item_font_inherit;
|
||||
grub_font_t selected_item_font;
|
||||
grub_video_rgba_color_t item_color;
|
||||
int selected_item_color_inherit;
|
||||
grub_video_rgba_color_t selected_item_color;
|
||||
|
||||
int draw_scrollbar;
|
||||
int need_to_recreate_scrollbar;
|
||||
char *scrollbar_frame_pattern;
|
||||
char *scrollbar_thumb_pattern;
|
||||
grub_gfxmenu_box_t scrollbar_frame;
|
||||
grub_gfxmenu_box_t scrollbar_thumb;
|
||||
int scrollbar_thumb_overlay;
|
||||
int scrollbar_width;
|
||||
enum scrollbar_slice_mode scrollbar_slice;
|
||||
int scrollbar_left_pad;
|
||||
int scrollbar_right_pad;
|
||||
int scrollbar_top_pad;
|
||||
int scrollbar_bottom_pad;
|
||||
|
||||
int first_shown_index;
|
||||
|
||||
int need_to_recreate_boxes;
|
||||
char *theme_dir;
|
||||
char *menu_box_pattern;
|
||||
char *item_box_pattern;
|
||||
int selected_item_box_pattern_inherit;
|
||||
char *selected_item_box_pattern;
|
||||
grub_gfxmenu_box_t menu_box;
|
||||
grub_gfxmenu_box_t selected_item_box;
|
||||
grub_gfxmenu_box_t item_box;
|
||||
|
||||
grub_gfxmenu_icon_manager_t icon_manager;
|
||||
|
||||
grub_gfxmenu_view_t view;
|
||||
};
|
||||
|
||||
typedef struct grub_gui_list_impl *list_impl_t;
|
||||
|
||||
static void
|
||||
list_destroy (void *vself)
|
||||
{
|
||||
list_impl_t self = vself;
|
||||
|
||||
grub_free (self->theme_dir);
|
||||
grub_free (self->menu_box_pattern);
|
||||
grub_free (self->item_box_pattern);
|
||||
grub_free (self->selected_item_box_pattern);
|
||||
if (self->menu_box)
|
||||
self->menu_box->destroy (self->menu_box);
|
||||
if (self->item_box)
|
||||
self->item_box->destroy (self->item_box);
|
||||
if (self->selected_item_box)
|
||||
self->selected_item_box->destroy (self->selected_item_box);
|
||||
if (self->icon_manager)
|
||||
grub_gfxmenu_icon_manager_destroy (self->icon_manager);
|
||||
if (self->scrollbar_thumb)
|
||||
self->scrollbar_thumb->destroy (self->scrollbar_thumb);
|
||||
if (self->scrollbar_frame)
|
||||
self->scrollbar_frame->destroy (self->scrollbar_frame);
|
||||
grub_free (self->scrollbar_thumb_pattern);
|
||||
grub_free (self->scrollbar_frame_pattern);
|
||||
grub_free (self);
|
||||
}
|
||||
|
||||
static int
|
||||
get_num_shown_items (list_impl_t self)
|
||||
{
|
||||
int boxpad = self->item_padding;
|
||||
int item_vspace = self->item_spacing;
|
||||
int item_height = self->item_height;
|
||||
|
||||
grub_gfxmenu_box_t box = self->menu_box;
|
||||
int box_top_pad = box->get_top_pad (box);
|
||||
int box_bottom_pad = box->get_bottom_pad (box);
|
||||
grub_gfxmenu_box_t itembox = self->item_box;
|
||||
grub_gfxmenu_box_t selbox = self->selected_item_box;
|
||||
int item_top_pad = itembox->get_top_pad (itembox);
|
||||
int item_bottom_pad = itembox->get_bottom_pad (itembox);
|
||||
int sel_top_pad = selbox->get_top_pad (selbox);
|
||||
int sel_bottom_pad = selbox->get_bottom_pad (selbox);
|
||||
int max_top_pad = grub_max (item_top_pad, sel_top_pad);
|
||||
int max_bottom_pad = grub_max (item_bottom_pad, sel_bottom_pad);
|
||||
|
||||
if (item_height + item_vspace <= 0)
|
||||
return 1;
|
||||
|
||||
return (self->bounds.height + item_vspace - 2 * boxpad
|
||||
- max_top_pad - max_bottom_pad
|
||||
- box_top_pad - box_bottom_pad) / (item_height + item_vspace);
|
||||
}
|
||||
|
||||
static int
|
||||
check_boxes (list_impl_t self)
|
||||
{
|
||||
if (self->need_to_recreate_boxes)
|
||||
{
|
||||
grub_gui_recreate_box (&self->menu_box,
|
||||
self->menu_box_pattern,
|
||||
self->theme_dir);
|
||||
|
||||
grub_gui_recreate_box (&self->item_box,
|
||||
self->item_box_pattern,
|
||||
self->theme_dir);
|
||||
|
||||
grub_gui_recreate_box (&self->selected_item_box,
|
||||
self->selected_item_box_pattern,
|
||||
self->theme_dir);
|
||||
|
||||
self->need_to_recreate_boxes = 0;
|
||||
}
|
||||
|
||||
return (self->menu_box != 0 && self->selected_item_box != 0
|
||||
&& self->item_box != 0);
|
||||
}
|
||||
|
||||
static int
|
||||
check_scrollbar (list_impl_t self)
|
||||
{
|
||||
if (self->need_to_recreate_scrollbar)
|
||||
{
|
||||
grub_gui_recreate_box (&self->scrollbar_frame,
|
||||
self->scrollbar_frame_pattern,
|
||||
self->theme_dir);
|
||||
|
||||
grub_gui_recreate_box (&self->scrollbar_thumb,
|
||||
self->scrollbar_thumb_pattern,
|
||||
self->theme_dir);
|
||||
|
||||
self->need_to_recreate_scrollbar = 0;
|
||||
}
|
||||
|
||||
if (self->scrollbar_frame == 0 || self->scrollbar_thumb == 0)
|
||||
return 0;
|
||||
|
||||
/* Sanity checks. */
|
||||
grub_gfxmenu_box_t frame = self->scrollbar_frame;
|
||||
grub_gfxmenu_box_t thumb = self->scrollbar_thumb;
|
||||
grub_gfxmenu_box_t menu = self->menu_box;
|
||||
int min_width = frame->get_left_pad (frame)
|
||||
+ frame->get_right_pad (frame);
|
||||
int min_height = frame->get_top_pad (frame)
|
||||
+ frame->get_bottom_pad (frame)
|
||||
+ self->scrollbar_top_pad + self->scrollbar_bottom_pad
|
||||
+ menu->get_top_pad (menu)
|
||||
+ menu->get_bottom_pad (menu);
|
||||
if (!self->scrollbar_thumb_overlay)
|
||||
{
|
||||
min_width += thumb->get_left_pad (thumb)
|
||||
+ thumb->get_right_pad (thumb);
|
||||
min_height += thumb->get_top_pad (thumb)
|
||||
+ thumb->get_bottom_pad (thumb);
|
||||
}
|
||||
if (min_width <= self->scrollbar_width
|
||||
&& min_height <= (int) self->bounds.height)
|
||||
return 1;
|
||||
|
||||
/* Unprintable dimenstions. */
|
||||
self->draw_scrollbar = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *
|
||||
list_get_id (void *vself)
|
||||
{
|
||||
list_impl_t self = vself;
|
||||
return self->id;
|
||||
}
|
||||
|
||||
static int
|
||||
list_is_instance (void *vself __attribute__((unused)), const char *type)
|
||||
{
|
||||
return (grub_strcmp (type, "component") == 0
|
||||
|| grub_strcmp (type, "list") == 0);
|
||||
}
|
||||
|
||||
static struct grub_video_bitmap *
|
||||
get_item_icon (list_impl_t self, int item_index)
|
||||
{
|
||||
grub_menu_entry_t entry;
|
||||
entry = grub_menu_get_entry (self->view->menu, item_index);
|
||||
if (! entry)
|
||||
return 0;
|
||||
|
||||
return grub_gfxmenu_icon_manager_get_icon (self->icon_manager, entry);
|
||||
}
|
||||
|
||||
static void
|
||||
make_selected_item_visible (list_impl_t self)
|
||||
{
|
||||
int selected_index = self->view->selected;
|
||||
if (selected_index < 0)
|
||||
return; /* No item is selected. */
|
||||
int num_shown_items = get_num_shown_items (self);
|
||||
int last_shown_index = self->first_shown_index + (num_shown_items - 1);
|
||||
if (selected_index < self->first_shown_index)
|
||||
self->first_shown_index = selected_index;
|
||||
else if (selected_index > last_shown_index)
|
||||
self->first_shown_index = selected_index - (num_shown_items - 1);
|
||||
}
|
||||
|
||||
/* Draw a scrollbar on the menu. */
|
||||
static void
|
||||
draw_scrollbar (list_impl_t self,
|
||||
int value, int extent, int min, int max,
|
||||
int scrollbar_width, int scrollbar_height)
|
||||
{
|
||||
unsigned thumby, thumbheight;
|
||||
|
||||
grub_gfxmenu_box_t frame = self->scrollbar_frame;
|
||||
grub_gfxmenu_box_t thumb = self->scrollbar_thumb;
|
||||
int frame_vertical_pad = (frame->get_top_pad (frame)
|
||||
+ frame->get_bottom_pad (frame));
|
||||
int frame_horizontal_pad = (frame->get_left_pad (frame)
|
||||
+ frame->get_right_pad (frame));
|
||||
unsigned thumb_vertical_pad = (thumb->get_top_pad (thumb)
|
||||
+ thumb->get_bottom_pad (thumb));
|
||||
int thumb_horizontal_pad = (thumb->get_left_pad (thumb)
|
||||
+ thumb->get_right_pad (thumb));
|
||||
int tracktop = frame->get_top_pad (frame);
|
||||
unsigned tracklen;
|
||||
if (scrollbar_height <= frame_vertical_pad)
|
||||
tracklen = 0;
|
||||
else
|
||||
tracklen = scrollbar_height - frame_vertical_pad;
|
||||
frame->set_content_size (frame,
|
||||
scrollbar_width - frame_horizontal_pad,
|
||||
tracklen);
|
||||
if (self->scrollbar_thumb_overlay)
|
||||
{
|
||||
tracklen += thumb_vertical_pad;
|
||||
tracktop -= thumb->get_top_pad (thumb);
|
||||
}
|
||||
if (value <= min || max <= min)
|
||||
thumby = 0;
|
||||
else
|
||||
thumby = ((unsigned) tracklen * (value - min))
|
||||
/ ((unsigned) (max - min));
|
||||
if (max <= min)
|
||||
thumbheight = 1;
|
||||
else
|
||||
thumbheight = ((unsigned) (tracklen * extent)
|
||||
/ ((unsigned) (max - min))) + 1;
|
||||
/* Rare occasion: too many entries or too low height. */
|
||||
if (thumbheight < thumb_vertical_pad)
|
||||
{
|
||||
thumbheight = thumb_vertical_pad;
|
||||
if (value <= min || max <= extent
|
||||
|| tracklen <= thumb_vertical_pad)
|
||||
thumby = 0;
|
||||
else
|
||||
thumby = ((unsigned) ((tracklen - thumb_vertical_pad) * (value - min))
|
||||
/ ((unsigned)(max - extent)));
|
||||
}
|
||||
thumby += tracktop;
|
||||
int thumbx = frame->get_left_pad (frame);
|
||||
int thumbwidth = scrollbar_width - frame_horizontal_pad;
|
||||
if (!self->scrollbar_thumb_overlay)
|
||||
thumbwidth -= thumb_horizontal_pad;
|
||||
else
|
||||
thumbx -= thumb->get_left_pad (thumb);
|
||||
thumb->set_content_size (thumb, thumbwidth,
|
||||
thumbheight - thumb_vertical_pad);
|
||||
frame->draw (frame, 0, 0);
|
||||
thumb->draw (thumb, thumbx, thumby);
|
||||
}
|
||||
|
||||
/* Draw the list of items. */
|
||||
static void
|
||||
draw_menu (list_impl_t self, int num_shown_items)
|
||||
{
|
||||
if (! self->menu_box || ! self->selected_item_box || ! self->item_box)
|
||||
return;
|
||||
|
||||
int boxpad = self->item_padding;
|
||||
int icon_text_space = self->item_icon_space;
|
||||
int item_vspace = self->item_spacing;
|
||||
|
||||
int ascent = grub_font_get_ascent (self->item_font);
|
||||
int descent = grub_font_get_descent (self->item_font);
|
||||
int selected_ascent = grub_font_get_ascent (self->selected_item_font);
|
||||
int selected_descent = grub_font_get_descent (self->selected_item_font);
|
||||
int text_box_height = self->item_height;
|
||||
|
||||
make_selected_item_visible (self);
|
||||
|
||||
grub_gfxmenu_box_t itembox = self->item_box;
|
||||
grub_gfxmenu_box_t selbox = self->selected_item_box;
|
||||
int item_leftpad = itembox->get_left_pad (itembox);
|
||||
int item_rightpad = itembox->get_right_pad (itembox);
|
||||
int item_border_width = item_leftpad + item_rightpad;
|
||||
int item_toppad = itembox->get_top_pad (itembox);
|
||||
int sel_leftpad = selbox->get_left_pad (selbox);
|
||||
int sel_rightpad = selbox->get_right_pad (selbox);
|
||||
int sel_border_width = sel_leftpad + sel_rightpad;
|
||||
int sel_toppad = selbox->get_top_pad (selbox);
|
||||
|
||||
int max_leftpad = grub_max (item_leftpad, sel_leftpad);
|
||||
int max_toppad = grub_max (item_toppad, sel_toppad);
|
||||
int item_top = 0;
|
||||
int menu_index;
|
||||
int visible_index;
|
||||
struct grub_video_rect oviewport;
|
||||
|
||||
grub_video_get_viewport (&oviewport.x, &oviewport.y,
|
||||
&oviewport.width, &oviewport.height);
|
||||
grub_video_set_viewport (oviewport.x + boxpad,
|
||||
oviewport.y + boxpad,
|
||||
oviewport.width - 2 * boxpad,
|
||||
oviewport.height - 2 * boxpad);
|
||||
|
||||
int cwidth = oviewport.width - 2 * boxpad;
|
||||
|
||||
itembox->set_content_size (itembox, cwidth - item_border_width,
|
||||
text_box_height);
|
||||
selbox->set_content_size (selbox, cwidth - sel_border_width,
|
||||
text_box_height);
|
||||
|
||||
int text_left_offset = self->icon_width + icon_text_space;
|
||||
int item_text_top_offset = (text_box_height - (ascent + descent)) / 2 + ascent;
|
||||
int sel_text_top_offset = (text_box_height - (selected_ascent
|
||||
+ selected_descent)) / 2
|
||||
+ selected_ascent;
|
||||
|
||||
grub_video_rect_t svpsave, sviewport;
|
||||
sviewport.x = max_leftpad + text_left_offset;
|
||||
int text_viewport_width = cwidth - sviewport.x;
|
||||
sviewport.height = text_box_height;
|
||||
|
||||
grub_video_color_t item_color;
|
||||
grub_video_color_t sel_color;
|
||||
item_color = grub_video_map_rgba_color (self->item_color);
|
||||
sel_color = grub_video_map_rgba_color (self->selected_item_color);
|
||||
|
||||
int item_box_top_offset = max_toppad - item_toppad;
|
||||
int sel_box_top_offset = max_toppad - sel_toppad;
|
||||
int item_viewport_width = text_viewport_width - item_rightpad;
|
||||
int sel_viewport_width = text_viewport_width - sel_rightpad;
|
||||
int tmp_icon_top_offset = (text_box_height - self->icon_height) / 2;
|
||||
int item_icon_top_offset = item_toppad + tmp_icon_top_offset;
|
||||
int sel_icon_top_offset = sel_toppad + tmp_icon_top_offset;
|
||||
|
||||
for (visible_index = 0, menu_index = self->first_shown_index;
|
||||
visible_index < num_shown_items && menu_index < self->view->menu->size;
|
||||
visible_index++, menu_index++)
|
||||
{
|
||||
int is_selected = (menu_index == self->view->selected);
|
||||
struct grub_video_bitmap *icon;
|
||||
grub_font_t font;
|
||||
grub_video_color_t color;
|
||||
int text_top_offset;
|
||||
int top_pad;
|
||||
int icon_top_offset;
|
||||
int viewport_width;
|
||||
|
||||
if (is_selected)
|
||||
{
|
||||
selbox->draw (selbox, 0, item_top + sel_box_top_offset);
|
||||
font = self->selected_item_font;
|
||||
color = sel_color;
|
||||
text_top_offset = sel_text_top_offset;
|
||||
top_pad = sel_toppad;
|
||||
icon_top_offset = sel_icon_top_offset;
|
||||
viewport_width = sel_viewport_width;
|
||||
}
|
||||
else
|
||||
{
|
||||
itembox->draw (itembox, 0, item_top + item_box_top_offset);
|
||||
font = self->item_font;
|
||||
color = item_color;
|
||||
text_top_offset = item_text_top_offset;
|
||||
top_pad = item_toppad;
|
||||
icon_top_offset = item_icon_top_offset;
|
||||
viewport_width = item_viewport_width;
|
||||
}
|
||||
|
||||
icon = get_item_icon (self, menu_index);
|
||||
if (icon != 0)
|
||||
grub_video_blit_bitmap (icon, GRUB_VIDEO_BLIT_BLEND,
|
||||
max_leftpad,
|
||||
item_top + icon_top_offset,
|
||||
0, 0, self->icon_width, self->icon_height);
|
||||
|
||||
const char *item_title =
|
||||
grub_menu_get_entry (self->view->menu, menu_index)->title;
|
||||
|
||||
|
||||
int off = self->view->menu_title_offset[menu_index];
|
||||
const char *scrolled_title =
|
||||
grub_utf8_offset_code (item_title, grub_strlen (item_title), off);
|
||||
if (scrolled_title)
|
||||
item_title = scrolled_title;
|
||||
|
||||
sviewport.y = item_top + top_pad;
|
||||
sviewport.width = viewport_width;
|
||||
grub_gui_set_viewport (&sviewport, &svpsave);
|
||||
grub_font_draw_string (item_title,
|
||||
font,
|
||||
color,
|
||||
0,
|
||||
text_top_offset);
|
||||
grub_gui_restore_viewport (&svpsave);
|
||||
|
||||
item_top += text_box_height + item_vspace;
|
||||
}
|
||||
grub_video_set_viewport (oviewport.x,
|
||||
oviewport.y,
|
||||
oviewport.width,
|
||||
oviewport.height);
|
||||
}
|
||||
|
||||
static void
|
||||
list_paint (void *vself, const grub_video_rect_t *region)
|
||||
{
|
||||
list_impl_t self = vself;
|
||||
grub_video_rect_t vpsave;
|
||||
|
||||
if (! self->visible)
|
||||
return;
|
||||
if (!grub_video_have_common_points (region, &self->bounds))
|
||||
return;
|
||||
|
||||
check_boxes (self);
|
||||
|
||||
if (! self->menu_box || ! self->selected_item_box || ! self->item_box)
|
||||
return;
|
||||
|
||||
grub_gui_set_viewport (&self->bounds, &vpsave);
|
||||
{
|
||||
grub_gfxmenu_box_t box = self->menu_box;
|
||||
int box_left_pad = box->get_left_pad (box);
|
||||
int box_top_pad = box->get_top_pad (box);
|
||||
int box_right_pad = box->get_right_pad (box);
|
||||
int box_bottom_pad = box->get_bottom_pad (box);
|
||||
grub_video_rect_t vpsave2, content_rect;
|
||||
int num_shown_items = get_num_shown_items (self);
|
||||
int drawing_scrollbar = (self->draw_scrollbar
|
||||
&& (num_shown_items < self->view->menu->size)
|
||||
&& check_scrollbar (self));
|
||||
int scrollbar_width = self->scrollbar_width;
|
||||
|
||||
content_rect.x = box_left_pad;
|
||||
content_rect.y = box_top_pad;
|
||||
content_rect.width = self->bounds.width - box_left_pad - box_right_pad;
|
||||
content_rect.height = self->bounds.height - box_top_pad - box_bottom_pad;
|
||||
|
||||
box->set_content_size (box, content_rect.width, content_rect.height);
|
||||
|
||||
box->draw (box, 0, 0);
|
||||
|
||||
switch (self->scrollbar_slice)
|
||||
{
|
||||
case SCROLLBAR_SLICE_WEST:
|
||||
content_rect.x += self->scrollbar_right_pad;
|
||||
content_rect.width -= self->scrollbar_right_pad;
|
||||
break;
|
||||
case SCROLLBAR_SLICE_CENTER:
|
||||
if (drawing_scrollbar)
|
||||
content_rect.width -= scrollbar_width + self->scrollbar_left_pad
|
||||
+ self->scrollbar_right_pad;
|
||||
break;
|
||||
case SCROLLBAR_SLICE_EAST:
|
||||
content_rect.width -= self->scrollbar_left_pad;
|
||||
break;
|
||||
}
|
||||
|
||||
grub_gui_set_viewport (&content_rect, &vpsave2);
|
||||
draw_menu (self, num_shown_items);
|
||||
grub_gui_restore_viewport (&vpsave2);
|
||||
|
||||
if (drawing_scrollbar)
|
||||
{
|
||||
content_rect.y += self->scrollbar_top_pad;
|
||||
content_rect.height -= self->scrollbar_top_pad
|
||||
+ self->scrollbar_bottom_pad;
|
||||
content_rect.width = scrollbar_width;
|
||||
switch (self->scrollbar_slice)
|
||||
{
|
||||
case SCROLLBAR_SLICE_WEST:
|
||||
if (box_left_pad > scrollbar_width)
|
||||
{
|
||||
content_rect.x = box_left_pad - scrollbar_width;
|
||||
content_rect.width = scrollbar_width;
|
||||
}
|
||||
else
|
||||
{
|
||||
content_rect.x = 0;
|
||||
content_rect.width = box_left_pad;
|
||||
}
|
||||
break;
|
||||
case SCROLLBAR_SLICE_CENTER:
|
||||
content_rect.x = self->bounds.width - box_right_pad
|
||||
- scrollbar_width - self->scrollbar_right_pad;
|
||||
content_rect.width = scrollbar_width;
|
||||
break;
|
||||
case SCROLLBAR_SLICE_EAST:
|
||||
content_rect.x = self->bounds.width - box_right_pad;
|
||||
content_rect.width = box_right_pad;
|
||||
break;
|
||||
}
|
||||
|
||||
grub_gui_set_viewport (&content_rect, &vpsave2);
|
||||
draw_scrollbar (self,
|
||||
self->first_shown_index, num_shown_items,
|
||||
0, self->view->menu->size,
|
||||
scrollbar_width,
|
||||
content_rect.height);
|
||||
grub_gui_restore_viewport (&vpsave2);
|
||||
}
|
||||
}
|
||||
|
||||
grub_gui_restore_viewport (&vpsave);
|
||||
}
|
||||
|
||||
static void
|
||||
list_set_parent (void *vself, grub_gui_container_t parent)
|
||||
{
|
||||
list_impl_t self = vself;
|
||||
self->parent = parent;
|
||||
}
|
||||
|
||||
static grub_gui_container_t
|
||||
list_get_parent (void *vself)
|
||||
{
|
||||
list_impl_t self = vself;
|
||||
return self->parent;
|
||||
}
|
||||
|
||||
static void
|
||||
list_set_bounds (void *vself, const grub_video_rect_t *bounds)
|
||||
{
|
||||
list_impl_t self = vself;
|
||||
self->bounds = *bounds;
|
||||
}
|
||||
|
||||
static void
|
||||
list_get_bounds (void *vself, grub_video_rect_t *bounds)
|
||||
{
|
||||
list_impl_t self = vself;
|
||||
*bounds = self->bounds;
|
||||
}
|
||||
|
||||
static void
|
||||
list_get_minimal_size (void *vself, unsigned *width, unsigned *height)
|
||||
{
|
||||
list_impl_t self = vself;
|
||||
|
||||
if (check_boxes (self))
|
||||
{
|
||||
int boxpad = self->item_padding;
|
||||
int item_vspace = self->item_spacing;
|
||||
int item_height = self->item_height;
|
||||
int num_items = 3;
|
||||
|
||||
grub_gfxmenu_box_t box = self->menu_box;
|
||||
int box_left_pad = box->get_left_pad (box);
|
||||
int box_top_pad = box->get_top_pad (box);
|
||||
int box_right_pad = box->get_right_pad (box);
|
||||
int box_bottom_pad = box->get_bottom_pad (box);
|
||||
unsigned width_s;
|
||||
|
||||
grub_gfxmenu_box_t selbox = self->selected_item_box;
|
||||
int sel_top_pad = selbox->get_top_pad (selbox);
|
||||
int sel_bottom_pad = selbox->get_bottom_pad (selbox);
|
||||
int sel_left_pad = selbox->get_left_pad (selbox);
|
||||
int sel_right_pad = selbox->get_right_pad (selbox);
|
||||
|
||||
grub_gfxmenu_box_t itembox = self->item_box;
|
||||
int item_top_pad = itembox->get_top_pad (itembox);
|
||||
int item_bottom_pad = itembox->get_bottom_pad (itembox);
|
||||
int item_left_pad = itembox->get_left_pad (itembox);
|
||||
int item_right_pad = itembox->get_right_pad (itembox);
|
||||
|
||||
int max_left_pad = grub_max (item_left_pad, sel_left_pad);
|
||||
int max_right_pad = grub_max (item_right_pad, sel_right_pad);
|
||||
int max_top_pad = grub_max (item_top_pad, sel_top_pad);
|
||||
int max_bottom_pad = grub_max (item_bottom_pad, sel_bottom_pad);
|
||||
|
||||
*width = grub_font_get_string_width (self->item_font, "Typical OS");
|
||||
width_s = grub_font_get_string_width (self->selected_item_font,
|
||||
"Typical OS");
|
||||
if (*width < width_s)
|
||||
*width = width_s;
|
||||
|
||||
*width += 2 * boxpad + box_left_pad + box_right_pad
|
||||
+ max_left_pad + max_right_pad
|
||||
+ self->item_icon_space + self->icon_width;
|
||||
|
||||
switch (self->scrollbar_slice)
|
||||
{
|
||||
case SCROLLBAR_SLICE_WEST:
|
||||
*width += self->scrollbar_right_pad;
|
||||
break;
|
||||
case SCROLLBAR_SLICE_CENTER:
|
||||
*width += self->scrollbar_width + self->scrollbar_left_pad
|
||||
+ self->scrollbar_right_pad;
|
||||
break;
|
||||
case SCROLLBAR_SLICE_EAST:
|
||||
*width += self->scrollbar_left_pad;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Set the menu box height to fit the items. */
|
||||
*height = (item_height * num_items
|
||||
+ item_vspace * (num_items - 1)
|
||||
+ 2 * boxpad
|
||||
+ box_top_pad + box_bottom_pad
|
||||
+ max_top_pad + max_bottom_pad);
|
||||
}
|
||||
else
|
||||
{
|
||||
*width = 0;
|
||||
*height = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
list_set_property (void *vself, const char *name, const char *value)
|
||||
{
|
||||
list_impl_t self = vself;
|
||||
if (grub_strcmp (name, "item_font") == 0)
|
||||
{
|
||||
self->item_font = grub_font_get (value);
|
||||
if (self->selected_item_font_inherit)
|
||||
self->selected_item_font = self->item_font;
|
||||
}
|
||||
else if (grub_strcmp (name, "selected_item_font") == 0)
|
||||
{
|
||||
if (! value || grub_strcmp (value, "inherit") == 0)
|
||||
{
|
||||
self->selected_item_font = self->item_font;
|
||||
self->selected_item_font_inherit = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
self->selected_item_font = grub_font_get (value);
|
||||
self->selected_item_font_inherit = 0;
|
||||
}
|
||||
}
|
||||
else if (grub_strcmp (name, "item_color") == 0)
|
||||
{
|
||||
grub_video_rgba_color_t color;
|
||||
if (grub_video_parse_color (value, &color) == GRUB_ERR_NONE)
|
||||
{
|
||||
self->item_color = color;
|
||||
if (self->selected_item_color_inherit)
|
||||
self->selected_item_color = self->item_color;
|
||||
}
|
||||
}
|
||||
else if (grub_strcmp (name, "selected_item_color") == 0)
|
||||
{
|
||||
if (! value || grub_strcmp (value, "inherit") == 0)
|
||||
{
|
||||
self->selected_item_color = self->item_color;
|
||||
self->selected_item_color_inherit = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_video_rgba_color_t color;
|
||||
if (grub_video_parse_color (value, &color)
|
||||
== GRUB_ERR_NONE)
|
||||
{
|
||||
self->selected_item_color = color;
|
||||
self->selected_item_color_inherit = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (grub_strcmp (name, "icon_width") == 0)
|
||||
{
|
||||
self->icon_width = grub_strtol (value, 0, 10);
|
||||
grub_gfxmenu_icon_manager_set_icon_size (self->icon_manager,
|
||||
self->icon_width,
|
||||
self->icon_height);
|
||||
}
|
||||
else if (grub_strcmp (name, "icon_height") == 0)
|
||||
{
|
||||
self->icon_height = grub_strtol (value, 0, 10);
|
||||
grub_gfxmenu_icon_manager_set_icon_size (self->icon_manager,
|
||||
self->icon_width,
|
||||
self->icon_height);
|
||||
}
|
||||
else if (grub_strcmp (name, "item_height") == 0)
|
||||
{
|
||||
self->item_height = grub_strtol (value, 0, 10);
|
||||
}
|
||||
else if (grub_strcmp (name, "item_padding") == 0)
|
||||
{
|
||||
self->item_padding = grub_strtol (value, 0, 10);
|
||||
}
|
||||
else if (grub_strcmp (name, "item_icon_space") == 0)
|
||||
{
|
||||
self->item_icon_space = grub_strtol (value, 0, 10);
|
||||
}
|
||||
else if (grub_strcmp (name, "item_spacing") == 0)
|
||||
{
|
||||
self->item_spacing = grub_strtol (value, 0, 10);
|
||||
}
|
||||
else if (grub_strcmp (name, "visible") == 0)
|
||||
{
|
||||
self->visible = grub_strcmp (value, "false") != 0;
|
||||
}
|
||||
else if (grub_strcmp (name, "menu_pixmap_style") == 0)
|
||||
{
|
||||
self->need_to_recreate_boxes = 1;
|
||||
grub_free (self->menu_box_pattern);
|
||||
self->menu_box_pattern = value ? grub_strdup (value) : 0;
|
||||
}
|
||||
else if (grub_strcmp (name, "item_pixmap_style") == 0)
|
||||
{
|
||||
self->need_to_recreate_boxes = 1;
|
||||
grub_free (self->item_box_pattern);
|
||||
self->item_box_pattern = value ? grub_strdup (value) : 0;
|
||||
if (self->selected_item_box_pattern_inherit)
|
||||
{
|
||||
grub_free (self->selected_item_box_pattern);
|
||||
self->selected_item_box_pattern = value ? grub_strdup (value) : 0;
|
||||
}
|
||||
}
|
||||
else if (grub_strcmp (name, "selected_item_pixmap_style") == 0)
|
||||
{
|
||||
if (!value || grub_strcmp (value, "inherit") == 0)
|
||||
{
|
||||
grub_free (self->selected_item_box_pattern);
|
||||
char *tmp = self->item_box_pattern;
|
||||
self->selected_item_box_pattern = tmp ? grub_strdup (tmp) : 0;
|
||||
self->selected_item_box_pattern_inherit = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
self->need_to_recreate_boxes = 1;
|
||||
grub_free (self->selected_item_box_pattern);
|
||||
self->selected_item_box_pattern = value ? grub_strdup (value) : 0;
|
||||
self->selected_item_box_pattern_inherit = 0;
|
||||
}
|
||||
}
|
||||
else if (grub_strcmp (name, "scrollbar_frame") == 0)
|
||||
{
|
||||
self->need_to_recreate_scrollbar = 1;
|
||||
grub_free (self->scrollbar_frame_pattern);
|
||||
self->scrollbar_frame_pattern = value ? grub_strdup (value) : 0;
|
||||
}
|
||||
else if (grub_strcmp (name, "scrollbar_thumb") == 0)
|
||||
{
|
||||
self->need_to_recreate_scrollbar = 1;
|
||||
grub_free (self->scrollbar_thumb_pattern);
|
||||
self->scrollbar_thumb_pattern = value ? grub_strdup (value) : 0;
|
||||
}
|
||||
else if (grub_strcmp (name, "scrollbar_thumb_overlay") == 0)
|
||||
{
|
||||
self->scrollbar_thumb_overlay = grub_strcmp (value, "true") == 0;
|
||||
}
|
||||
else if (grub_strcmp (name, "scrollbar_width") == 0)
|
||||
{
|
||||
self->scrollbar_width = grub_strtol (value, 0, 10);
|
||||
}
|
||||
else if (grub_strcmp (name, "scrollbar_slice") == 0)
|
||||
{
|
||||
if (grub_strcmp (value, "west") == 0)
|
||||
self->scrollbar_slice = SCROLLBAR_SLICE_WEST;
|
||||
else if (grub_strcmp (value, "center") == 0)
|
||||
self->scrollbar_slice = SCROLLBAR_SLICE_CENTER;
|
||||
else if (grub_strcmp (value, "east") == 0)
|
||||
self->scrollbar_slice = SCROLLBAR_SLICE_EAST;
|
||||
}
|
||||
else if (grub_strcmp (name, "scrollbar_left_pad") == 0)
|
||||
{
|
||||
self->scrollbar_left_pad = grub_strtol (value, 0, 10);
|
||||
}
|
||||
else if (grub_strcmp (name, "scrollbar_right_pad") == 0)
|
||||
{
|
||||
self->scrollbar_right_pad = grub_strtol (value, 0, 10);
|
||||
}
|
||||
else if (grub_strcmp (name, "scrollbar_top_pad") == 0)
|
||||
{
|
||||
self->scrollbar_top_pad = grub_strtol (value, 0, 10);
|
||||
}
|
||||
else if (grub_strcmp (name, "scrollbar_bottom_pad") == 0)
|
||||
{
|
||||
self->scrollbar_bottom_pad = grub_strtol (value, 0, 10);
|
||||
}
|
||||
else if (grub_strcmp (name, "scrollbar") == 0)
|
||||
{
|
||||
self->draw_scrollbar = grub_strcmp (value, "false") != 0;
|
||||
}
|
||||
else if (grub_strcmp (name, "theme_dir") == 0)
|
||||
{
|
||||
self->need_to_recreate_boxes = 1;
|
||||
grub_free (self->theme_dir);
|
||||
self->theme_dir = value ? grub_strdup (value) : 0;
|
||||
}
|
||||
else if (grub_strcmp (name, "id") == 0)
|
||||
{
|
||||
grub_free (self->id);
|
||||
if (value)
|
||||
self->id = grub_strdup (value);
|
||||
else
|
||||
self->id = 0;
|
||||
}
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
/* Set necessary information that the gfxmenu view provides. */
|
||||
static void
|
||||
list_set_view_info (void *vself,
|
||||
grub_gfxmenu_view_t view)
|
||||
{
|
||||
list_impl_t self = vself;
|
||||
grub_gfxmenu_icon_manager_set_theme_path (self->icon_manager,
|
||||
view->theme_path);
|
||||
self->view = view;
|
||||
}
|
||||
|
||||
/* Refresh list variables */
|
||||
static void
|
||||
list_refresh_info (void *vself,
|
||||
grub_gfxmenu_view_t view)
|
||||
{
|
||||
list_impl_t self = vself;
|
||||
if (view->nested)
|
||||
self->first_shown_index = 0;
|
||||
}
|
||||
|
||||
static struct grub_gui_component_ops list_comp_ops =
|
||||
{
|
||||
.destroy = list_destroy,
|
||||
.get_id = list_get_id,
|
||||
.is_instance = list_is_instance,
|
||||
.paint = list_paint,
|
||||
.set_parent = list_set_parent,
|
||||
.get_parent = list_get_parent,
|
||||
.set_bounds = list_set_bounds,
|
||||
.get_bounds = list_get_bounds,
|
||||
.get_minimal_size = list_get_minimal_size,
|
||||
.set_property = list_set_property
|
||||
};
|
||||
|
||||
static struct grub_gui_list_ops list_ops =
|
||||
{
|
||||
.set_view_info = list_set_view_info,
|
||||
.refresh_list = list_refresh_info
|
||||
};
|
||||
|
||||
grub_gui_component_t
|
||||
grub_gui_list_new (void)
|
||||
{
|
||||
list_impl_t self;
|
||||
grub_font_t default_font;
|
||||
grub_video_rgba_color_t default_fg_color;
|
||||
|
||||
self = grub_zalloc (sizeof (*self));
|
||||
if (! self)
|
||||
return 0;
|
||||
|
||||
self->list.ops = &list_ops;
|
||||
self->list.component.ops = &list_comp_ops;
|
||||
|
||||
self->visible = 1;
|
||||
|
||||
default_font = grub_font_get ("Unknown Regular 16");
|
||||
default_fg_color = grub_video_rgba_color_rgb (0, 0, 0);
|
||||
|
||||
self->icon_width = 32;
|
||||
self->icon_height = 32;
|
||||
self->item_height = 42;
|
||||
self->item_padding = 14;
|
||||
self->item_icon_space = 4;
|
||||
self->item_spacing = 16;
|
||||
self->item_font = default_font;
|
||||
self->selected_item_font_inherit = 1; /* Default to using the item_font. */
|
||||
self->selected_item_font = default_font;
|
||||
self->item_color = default_fg_color;
|
||||
self->selected_item_color_inherit = 1; /* Default to using the item_color. */
|
||||
self->selected_item_color = default_fg_color;
|
||||
|
||||
self->draw_scrollbar = 1;
|
||||
self->need_to_recreate_scrollbar = 1;
|
||||
self->scrollbar_frame = 0;
|
||||
self->scrollbar_thumb = 0;
|
||||
self->scrollbar_frame_pattern = 0;
|
||||
self->scrollbar_thumb_pattern = 0;
|
||||
self->scrollbar_thumb_overlay = 0;
|
||||
self->scrollbar_width = 16;
|
||||
self->scrollbar_slice = SCROLLBAR_SLICE_EAST;
|
||||
self->scrollbar_left_pad = 2;
|
||||
self->scrollbar_right_pad = 0;
|
||||
self->scrollbar_top_pad = 0;
|
||||
self->scrollbar_bottom_pad = 0;
|
||||
|
||||
self->first_shown_index = 0;
|
||||
|
||||
self->need_to_recreate_boxes = 0;
|
||||
self->theme_dir = 0;
|
||||
self->menu_box_pattern = 0;
|
||||
self->item_box_pattern = 0;
|
||||
self->selected_item_box_pattern_inherit = 1;/*Default to using the item_box.*/
|
||||
self->selected_item_box_pattern = 0;
|
||||
self->menu_box = grub_gfxmenu_create_box (0, 0);
|
||||
self->item_box = grub_gfxmenu_create_box (0, 0);
|
||||
self->selected_item_box = grub_gfxmenu_create_box (0, 0);
|
||||
|
||||
self->icon_manager = grub_gfxmenu_icon_manager_new ();
|
||||
if (! self->icon_manager)
|
||||
{
|
||||
self->list.component.ops->destroy (self);
|
||||
return 0;
|
||||
}
|
||||
grub_gfxmenu_icon_manager_set_icon_size (self->icon_manager,
|
||||
self->icon_width,
|
||||
self->icon_height);
|
||||
return (grub_gui_component_t) self;
|
||||
}
|
@@ -163,6 +163,12 @@ theme_set_string (grub_gfxmenu_view_t view,
|
||||
grub_video_parse_color (value, &view->message_color);
|
||||
else if (! grub_strcmp ("message-bg-color", name))
|
||||
grub_video_parse_color (value, &view->message_bg_color);
|
||||
else if (! grub_strcmp("menu-tip-left", name))
|
||||
grub_env_set("VTOY_TIP_LEFT", value);
|
||||
else if (! grub_strcmp("menu-tip-top", name))
|
||||
grub_env_set("VTOY_TIP_TOP", value);
|
||||
else if (! grub_strcmp("menu-tip-color", name))
|
||||
grub_env_set("VTOY_TIP_COLOR", value);
|
||||
else if (! grub_strcmp ("desktop-image", name))
|
||||
{
|
||||
struct grub_video_bitmap *raw_bitmap;
|
||||
@@ -450,7 +456,8 @@ read_expression (struct parsebuf *p)
|
||||
/* Read as a single word -- for numeric values or words without
|
||||
whitespace. */
|
||||
start = p->pos;
|
||||
while (has_more (p) && ! is_whitespace (peek_char (p)))
|
||||
while (has_more (p) && ! is_whitespace (peek_char (p))
|
||||
&& peek_char (p) != '}')
|
||||
read_char (p);
|
||||
end = p->pos;
|
||||
}
|
||||
@@ -733,11 +740,14 @@ done:
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
extern int g_menu_update_mode;
|
||||
|
||||
/* Set properties on the view based on settings from the specified
|
||||
theme file. */
|
||||
grub_err_t
|
||||
grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, const char *theme_path)
|
||||
{
|
||||
int flag = 0;
|
||||
grub_file_t file;
|
||||
struct parsebuf p;
|
||||
|
||||
@@ -752,7 +762,7 @@ grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, const char *theme_path)
|
||||
}
|
||||
|
||||
p.len = grub_file_size (file);
|
||||
p.buf = grub_malloc (p.len + 4096);
|
||||
p.buf = grub_malloc (p.len + 8192);
|
||||
p.pos = 0;
|
||||
p.line_num = 1;
|
||||
p.col_num = 1;
|
||||
@@ -781,6 +791,8 @@ grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, const char *theme_path)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (view->canvas)
|
||||
view->canvas->component.ops->destroy (view->canvas);
|
||||
|
||||
@@ -791,6 +803,7 @@ grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, const char *theme_path)
|
||||
->ops->set_bounds ((grub_gui_component_t) view->canvas,
|
||||
&view->screen);
|
||||
|
||||
parse:
|
||||
while (has_more (&p))
|
||||
{
|
||||
/* Skip comments (lines beginning with #). */
|
||||
@@ -819,6 +832,40 @@ grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, const char *theme_path)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
||||
if (flag == 0)
|
||||
{
|
||||
const char *tip = grub_env_get("VTOY_MENU_TIP_ENABLE");
|
||||
if (tip && tip[0] == '1')
|
||||
{
|
||||
char tmpmsg[512];
|
||||
|
||||
grub_memset(tmpmsg, 'w', 500);
|
||||
tmpmsg[500] = 0;
|
||||
|
||||
g_menu_update_mode = 1;
|
||||
p.len += grub_snprintf(p.buf + p.len, 4096,
|
||||
"\n+ vbox{\n left = %s\n top = %s\n"
|
||||
"+ label { id=\"VTOY_MENU_TIP_1\" text = \"%s\" color = \"%s\" align = \"%s\"}\n"
|
||||
"+ label { id=\"VTOY_MENU_TIP_2\" text = \"%s\" color = \"%s\" align = \"%s\"}\n"
|
||||
"}\n",
|
||||
grub_env_get("VTOY_TIP_LEFT"),
|
||||
grub_env_get("VTOY_TIP_TOP"),
|
||||
tmpmsg,
|
||||
grub_env_get("VTOY_TIP_COLOR"),
|
||||
grub_env_get("VTOY_TIP_ALIGN"),
|
||||
tmpmsg,
|
||||
grub_env_get("VTOY_TIP_COLOR"),
|
||||
grub_env_get("VTOY_TIP_ALIGN")
|
||||
);
|
||||
|
||||
flag = 1;
|
||||
goto parse;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Set the new theme path. */
|
||||
grub_free (view->theme_path);
|
||||
view->theme_path = grub_strdup (theme_path);
|
||||
|
@@ -37,6 +37,7 @@
|
||||
#include <grub/gui_string_util.h>
|
||||
#include <grub/icon_manager.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/charset.h>
|
||||
|
||||
static void
|
||||
init_terminal (grub_gfxmenu_view_t view);
|
||||
@@ -142,6 +143,8 @@ grub_gfxmenu_view_destroy (grub_gfxmenu_view_t view)
|
||||
grub_free (view->title_text);
|
||||
grub_free (view->progress_message_text);
|
||||
grub_free (view->theme_path);
|
||||
if (view->menu_title_offset)
|
||||
grub_free (view->menu_title_offset);
|
||||
if (view->canvas)
|
||||
view->canvas->component.ops->destroy (view->canvas);
|
||||
grub_free (view);
|
||||
@@ -386,21 +389,37 @@ redraw_menu_visit (grub_gui_component_t component,
|
||||
}
|
||||
}
|
||||
|
||||
extern int g_menu_update_mode;
|
||||
|
||||
static void grub_gfxmenu_update_all(grub_gfxmenu_view_t view)
|
||||
{
|
||||
grub_video_set_area_status(GRUB_VIDEO_AREA_DISABLED);
|
||||
grub_gfxmenu_view_redraw(view, &view->screen);
|
||||
}
|
||||
|
||||
void
|
||||
grub_gfxmenu_redraw_menu (grub_gfxmenu_view_t view)
|
||||
{
|
||||
update_menu_components (view);
|
||||
|
||||
grub_gui_iterate_recursively ((grub_gui_component_t) view->canvas,
|
||||
redraw_menu_visit, view);
|
||||
if (g_menu_update_mode)
|
||||
grub_gfxmenu_update_all(view);
|
||||
else
|
||||
grub_gui_iterate_recursively ((grub_gui_component_t) view->canvas,
|
||||
redraw_menu_visit, view);
|
||||
|
||||
grub_video_swap_buffers ();
|
||||
if (view->double_repaint)
|
||||
{
|
||||
grub_gui_iterate_recursively ((grub_gui_component_t) view->canvas,
|
||||
redraw_menu_visit, view);
|
||||
if (g_menu_update_mode)
|
||||
grub_gfxmenu_update_all(view);
|
||||
else
|
||||
grub_gui_iterate_recursively ((grub_gui_component_t) view->canvas,
|
||||
redraw_menu_visit, view);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
grub_gfxmenu_set_chosen_entry (int entry, void *data)
|
||||
{
|
||||
@@ -408,6 +427,34 @@ grub_gfxmenu_set_chosen_entry (int entry, void *data)
|
||||
|
||||
view->selected = entry;
|
||||
grub_gfxmenu_redraw_menu (view);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
grub_gfxmenu_scroll_chosen_entry (void *data, int diren)
|
||||
{
|
||||
grub_gfxmenu_view_t view = data;
|
||||
const char *item_title;
|
||||
int off;
|
||||
int max;
|
||||
|
||||
if (!view->menu->size)
|
||||
return;
|
||||
|
||||
item_title = grub_menu_get_entry (view->menu, view->selected)->title;
|
||||
off = view->menu_title_offset[view->selected] + diren;
|
||||
max = grub_utf8_get_num_code (item_title, grub_strlen(item_title));
|
||||
|
||||
if (diren == 1000000)
|
||||
off = (max >= 20) ? (max - 20) : 0;
|
||||
else if (off < 0)
|
||||
off = 0;
|
||||
else if (off > max)
|
||||
off = max;
|
||||
|
||||
view->menu_title_offset[view->selected] = off;
|
||||
grub_gfxmenu_redraw_menu (view);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -471,7 +471,7 @@ grub_err_t
|
||||
grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
grub_off_t offset, grub_size_t size, void *buf)
|
||||
{
|
||||
if (disk->read_hook == (grub_disk_read_hook_t)grub_disk_blocklist_read)
|
||||
if (disk->read_hook == (grub_disk_read_hook_t)(void *)grub_disk_blocklist_read)
|
||||
{
|
||||
return grub_disk_blocklist_read((ventoy_img_chunk_list *)disk->read_hook_data, sector, size, disk->log_sector_size);
|
||||
}
|
||||
|
@@ -106,20 +106,135 @@ int ventoy_check_file_exist(const char * fmt, ...)
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct grub_vlnk
|
||||
{
|
||||
int srclen;
|
||||
char src[512];
|
||||
char dst[512];
|
||||
struct grub_vlnk *next;
|
||||
}grub_vlnk;
|
||||
|
||||
static grub_vlnk g_vtoy_vlnk;
|
||||
static grub_vlnk *g_vlnk_list;
|
||||
|
||||
int grub_file_is_vlnk_suffix(const char *name, int len)
|
||||
{
|
||||
grub_uint32_t suffix;
|
||||
|
||||
if (len > 9)
|
||||
{
|
||||
suffix = *(grub_uint32_t *)(name + len - 4);
|
||||
if (grub_strncmp(name + len - 9, ".vlnk.", 6) == 0)
|
||||
{
|
||||
/* .iso .wim .img .vhd .efi .dat */
|
||||
if (suffix == 0x6F73692E || suffix == 0x6D69772E ||
|
||||
suffix == 0x676D692E || suffix == 0x6468762E ||
|
||||
suffix == 0x6966652E || suffix == 0x7461642E)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (len > 10 && grub_strncmp(name + len - 10, ".vlnk.", 6) == 0)
|
||||
{
|
||||
/* vhdx vtoy */
|
||||
if (suffix == 0x78646876 || suffix == 0x796F7476)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int grub_file_vtoy_vlnk(const char *src, const char *dst)
|
||||
{
|
||||
if (src)
|
||||
{
|
||||
g_vtoy_vlnk.srclen = (int)grub_strlen(src);
|
||||
grub_strncpy(g_vtoy_vlnk.src, src, sizeof(g_vtoy_vlnk.src) - 1);
|
||||
grub_strncpy(g_vtoy_vlnk.dst, dst, sizeof(g_vtoy_vlnk.dst) - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_vtoy_vlnk.srclen = 0;
|
||||
g_vtoy_vlnk.src[0] = 0;
|
||||
g_vtoy_vlnk.dst[0] = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int grub_file_add_vlnk(const char *src, const char *dst)
|
||||
{
|
||||
grub_vlnk *node = NULL;
|
||||
|
||||
if (src && dst)
|
||||
{
|
||||
node = grub_zalloc(sizeof(grub_vlnk));
|
||||
if (node)
|
||||
{
|
||||
node->srclen = (int)grub_strlen(src);
|
||||
grub_strncpy(node->src, src, sizeof(node->src) - 1);
|
||||
grub_strncpy(node->dst, dst, sizeof(node->dst) - 1);
|
||||
|
||||
node->next = g_vlnk_list;
|
||||
g_vlnk_list = node;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *grub_file_get_vlnk(const char *name, int *vlnk)
|
||||
{
|
||||
int len;
|
||||
grub_vlnk *node = g_vlnk_list;
|
||||
|
||||
len = grub_strlen(name);
|
||||
|
||||
if (!grub_file_is_vlnk_suffix(name, len))
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
if (len == g_vtoy_vlnk.srclen && grub_strcmp(name, g_vtoy_vlnk.src) == 0)
|
||||
{
|
||||
*vlnk = 1;
|
||||
return g_vtoy_vlnk.dst;
|
||||
}
|
||||
|
||||
while (node)
|
||||
{
|
||||
if (node->srclen == len && grub_strcmp(name, node->src) == 0)
|
||||
{
|
||||
*vlnk = 1;
|
||||
return node->dst;
|
||||
}
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
grub_file_t
|
||||
grub_file_open (const char *name, enum grub_file_type type)
|
||||
{
|
||||
int vlnk = 0;
|
||||
grub_device_t device = 0;
|
||||
grub_file_t file = 0, last_file = 0;
|
||||
char *device_name;
|
||||
const char *file_name;
|
||||
grub_file_filter_id_t filter;
|
||||
|
||||
/* <DESC> : mem:xxx:size:xxx format in chainloader */
|
||||
if (grub_strncmp(name, GRUB_MEMFILE_MEM, grub_strlen(GRUB_MEMFILE_MEM)) == 0) {
|
||||
/* <DESC> : mem:xxx:size:xxx format in chainloader grub_strlen(GRUB_MEMFILE_MEM) */
|
||||
if (grub_strncmp(name, GRUB_MEMFILE_MEM, 4) == 0) {
|
||||
return grub_memfile_open(name);
|
||||
}
|
||||
|
||||
if ((g_vlnk_list || g_vtoy_vlnk.srclen) && (type & GRUB_FILE_TYPE_NO_VLNK) == 0)
|
||||
name = grub_file_get_vlnk(name, &vlnk);
|
||||
|
||||
device_name = grub_file_get_device_name (name);
|
||||
if (grub_errno)
|
||||
goto fail;
|
||||
@@ -141,6 +256,7 @@ grub_file_open (const char *name, enum grub_file_type type)
|
||||
goto fail;
|
||||
|
||||
file->device = device;
|
||||
file->vlnk = vlnk;
|
||||
|
||||
/* In case of relative pathnames and non-Unix systems (like Windows)
|
||||
* name of host files may not start with `/'. Blocklists for host files
|
||||
|
@@ -42,6 +42,44 @@ probe_dummy_iter (const char *filename __attribute__ ((unused)),
|
||||
return 1;
|
||||
}
|
||||
|
||||
grub_fs_t grub_fs_list_probe(grub_device_t device, const char **list)
|
||||
{
|
||||
int i;
|
||||
grub_fs_t p;
|
||||
|
||||
if (!device->disk)
|
||||
return 0;
|
||||
|
||||
for (p = grub_fs_list; p; p = p->next)
|
||||
{
|
||||
for (i = 0; list[i]; i++)
|
||||
{
|
||||
if (grub_strcmp(p->name, list[i]) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (list[i] == NULL)
|
||||
continue;
|
||||
|
||||
grub_dprintf("fs", "Detecting %s...\n", p->name);
|
||||
|
||||
(p->fs_dir) (device, "/", probe_dummy_iter, NULL);
|
||||
if (grub_errno == GRUB_ERR_NONE)
|
||||
return p;
|
||||
|
||||
grub_error_push ();
|
||||
grub_dprintf ("fs", "%s detection failed.\n", p->name);
|
||||
grub_error_pop ();
|
||||
|
||||
if (grub_errno != GRUB_ERR_BAD_FS && grub_errno != GRUB_ERR_OUT_OF_RANGE) {
|
||||
return 0;
|
||||
}
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_fs_t
|
||||
grub_fs_probe (grub_device_t device)
|
||||
{
|
||||
|
@@ -280,6 +280,13 @@ static int ventoy_boot_opt_filter(char *opt)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (grub_strncmp(opt, "dm=", 3) == 0)
|
||||
{
|
||||
opt[0] = 'D';
|
||||
opt[1] = 'M';
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ventoy_debug)
|
||||
{
|
||||
if (grub_strcmp(opt, "quiet") == 0)
|
||||
|
@@ -506,6 +506,13 @@ static int ventoy_boot_opt_filter(char *opt)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (grub_strncmp(opt, "dm=", 3) == 0)
|
||||
{
|
||||
opt[0] = 'D';
|
||||
opt[1] = 'M';
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ventoy_debug)
|
||||
{
|
||||
if (grub_strcmp(opt, "quiet") == 0)
|
||||
|
@@ -228,6 +228,13 @@ static int ventoy_boot_opt_filter(char *opt)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (grub_strncmp(opt, "dm=", 3) == 0)
|
||||
{
|
||||
opt[0] = 'D';
|
||||
opt[1] = 'M';
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ventoy_debug)
|
||||
{
|
||||
if (grub_strcmp(opt, "quiet") == 0)
|
||||
|
1352
GRUB2/MOD_SRC/grub-2.04/grub-core/normal/charset.c
Normal file
1352
GRUB2/MOD_SRC/grub-2.04/grub-core/normal/charset.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -33,6 +33,9 @@
|
||||
#include <grub/gfxterm.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/env.h>
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/ventoy.h>
|
||||
#include "ventoy/ventoy_def.h"
|
||||
|
||||
int g_ventoy_menu_refresh = 0;
|
||||
int g_ventoy_memdisk_mode = 0;
|
||||
@@ -42,10 +45,24 @@ int g_ventoy_wimboot_mode = 0;
|
||||
int g_ventoy_iso_uefi_drv = 0;
|
||||
int g_ventoy_last_entry = -1;
|
||||
int g_ventoy_suppress_esc = 0;
|
||||
int g_ventoy_suppress_esc_default = 1;
|
||||
int g_ventoy_menu_esc = 0;
|
||||
int g_ventoy_fn_mutex = 0;
|
||||
int g_ventoy_terminal_output = 0;
|
||||
|
||||
#define VTOY_COMM_HOTKEY(cmdkey) \
|
||||
if (0 == g_ventoy_fn_mutex) { \
|
||||
cmdstr = grub_env_get(cmdkey); \
|
||||
if (cmdstr) \
|
||||
{ \
|
||||
menu_fini (); \
|
||||
g_ventoy_fn_mutex = 1; \
|
||||
grub_script_execute_sourcecode(cmdstr); \
|
||||
g_ventoy_fn_mutex = 0; \
|
||||
goto refresh; \
|
||||
} \
|
||||
}
|
||||
|
||||
/* Time to delay after displaying an error message about a default/fallback
|
||||
entry failing to boot. */
|
||||
#define DEFAULT_ENTRY_ERROR_DELAY_MS 2500
|
||||
@@ -381,12 +398,76 @@ grub_menu_execute_with_fallback (grub_menu_t menu,
|
||||
|
||||
static struct grub_menu_viewer *viewers;
|
||||
|
||||
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)
|
||||
{
|
||||
g_ventoy_tip_msg1 = img->tip1;
|
||||
g_ventoy_tip_msg2 = img->tip2;
|
||||
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
|
||||
menu_set_chosen_entry (int entry)
|
||||
menu_set_chosen_entry (grub_menu_t menu, int entry)
|
||||
{
|
||||
struct grub_menu_viewer *cur;
|
||||
|
||||
menu_set_chosen_tip(menu, entry);
|
||||
for (cur = viewers; cur; cur = cur->next)
|
||||
cur->set_chosen_entry (entry, cur->data);
|
||||
}
|
||||
|
||||
static void
|
||||
menu_scroll_chosen_entry (int diren)
|
||||
{
|
||||
struct grub_menu_viewer *cur;
|
||||
for (cur = viewers; cur; cur = cur->next)
|
||||
cur->set_chosen_entry (entry, cur->data);
|
||||
if (cur->scroll_chosen_entry)
|
||||
cur->scroll_chosen_entry (cur->data, diren);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -598,10 +679,8 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
default_entry = get_entry_number (menu, "default");
|
||||
|
||||
if (g_ventoy_suppress_esc)
|
||||
default_entry = 1;
|
||||
else if (g_ventoy_last_entry >= 0 && g_ventoy_last_entry < menu->size) {
|
||||
default_entry = g_ventoy_last_entry;
|
||||
}
|
||||
default_entry = g_ventoy_suppress_esc_default;
|
||||
|
||||
/* If DEFAULT_ENTRY is not within the menu entries, fall back to
|
||||
the first entry. */
|
||||
else if (default_entry < 0 || default_entry >= menu->size)
|
||||
@@ -680,6 +759,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
current_entry = default_entry;
|
||||
|
||||
refresh:
|
||||
menu_set_chosen_tip(menu, current_entry);
|
||||
menu_init (current_entry, menu, nested);
|
||||
|
||||
/* Initialize the time. */
|
||||
@@ -732,13 +812,13 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
case GRUB_TERM_KEY_HOME:
|
||||
case GRUB_TERM_CTRL | 'a':
|
||||
current_entry = 0;
|
||||
menu_set_chosen_entry (current_entry);
|
||||
menu_set_chosen_entry (menu, current_entry);
|
||||
break;
|
||||
|
||||
case GRUB_TERM_KEY_END:
|
||||
case GRUB_TERM_CTRL | 'e':
|
||||
current_entry = menu->size - 1;
|
||||
menu_set_chosen_entry (current_entry);
|
||||
menu_set_chosen_entry (menu, current_entry);
|
||||
break;
|
||||
|
||||
case GRUB_TERM_KEY_UP:
|
||||
@@ -746,7 +826,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
case '^':
|
||||
if (current_entry > 0)
|
||||
current_entry--;
|
||||
menu_set_chosen_entry (current_entry);
|
||||
menu_set_chosen_entry (menu, current_entry);
|
||||
break;
|
||||
|
||||
case GRUB_TERM_CTRL | 'n':
|
||||
@@ -754,7 +834,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
case 'v':
|
||||
if (current_entry < menu->size - 1)
|
||||
current_entry++;
|
||||
menu_set_chosen_entry (current_entry);
|
||||
menu_set_chosen_entry (menu, current_entry);
|
||||
break;
|
||||
|
||||
case GRUB_TERM_CTRL | 'g':
|
||||
@@ -763,7 +843,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
current_entry = 0;
|
||||
else
|
||||
current_entry -= GRUB_MENU_PAGE_SIZE;
|
||||
menu_set_chosen_entry (current_entry);
|
||||
menu_set_chosen_entry (menu, current_entry);
|
||||
break;
|
||||
|
||||
case GRUB_TERM_CTRL | 'c':
|
||||
@@ -772,7 +852,20 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
current_entry += GRUB_MENU_PAGE_SIZE;
|
||||
else
|
||||
current_entry = menu->size - 1;
|
||||
menu_set_chosen_entry (current_entry);
|
||||
menu_set_chosen_entry (menu, current_entry);
|
||||
break;
|
||||
|
||||
case GRUB_TERM_KEY_RIGHT:
|
||||
menu_scroll_chosen_entry (1);
|
||||
break;
|
||||
case GRUB_TERM_KEY_LEFT:
|
||||
menu_scroll_chosen_entry (-1);
|
||||
break;
|
||||
case GRUB_TERM_CTRL | GRUB_TERM_KEY_RIGHT:
|
||||
menu_scroll_chosen_entry (1000000);
|
||||
break;
|
||||
case GRUB_TERM_CTRL | GRUB_TERM_KEY_LEFT:
|
||||
menu_scroll_chosen_entry (-1000000);
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
@@ -807,71 +900,23 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
|
||||
case GRUB_TERM_KEY_F2:
|
||||
case '2':
|
||||
if (0 == g_ventoy_fn_mutex) {
|
||||
cmdstr = grub_env_get("VTOY_F2_CMD");
|
||||
if (cmdstr)
|
||||
{
|
||||
menu_fini ();
|
||||
g_ventoy_fn_mutex = 1;
|
||||
grub_script_execute_sourcecode(cmdstr);
|
||||
g_ventoy_fn_mutex = 0;
|
||||
goto refresh;
|
||||
}
|
||||
}
|
||||
VTOY_COMM_HOTKEY("VTOY_F2_CMD");
|
||||
break;
|
||||
case GRUB_TERM_KEY_F3:
|
||||
case '3':
|
||||
if (0 == g_ventoy_fn_mutex) {
|
||||
cmdstr = grub_env_get("VTOY_F3_CMD");
|
||||
if (cmdstr)
|
||||
{
|
||||
menu_fini ();
|
||||
grub_script_execute_sourcecode(cmdstr);
|
||||
goto refresh;
|
||||
}
|
||||
}
|
||||
VTOY_COMM_HOTKEY("VTOY_F3_CMD");
|
||||
break;
|
||||
case GRUB_TERM_KEY_F4:
|
||||
case '4':
|
||||
if (0 == g_ventoy_fn_mutex) {
|
||||
cmdstr = grub_env_get("VTOY_F4_CMD");
|
||||
if (cmdstr)
|
||||
{
|
||||
menu_fini ();
|
||||
g_ventoy_fn_mutex = 1;
|
||||
grub_script_execute_sourcecode(cmdstr);
|
||||
g_ventoy_fn_mutex = 0;
|
||||
goto refresh;
|
||||
}
|
||||
}
|
||||
VTOY_COMM_HOTKEY("VTOY_F4_CMD");
|
||||
break;
|
||||
case GRUB_TERM_KEY_F5:
|
||||
case '5':
|
||||
if (0 == g_ventoy_fn_mutex) {
|
||||
cmdstr = grub_env_get("VTOY_F5_CMD");
|
||||
if (cmdstr)
|
||||
{
|
||||
menu_fini ();
|
||||
g_ventoy_fn_mutex = 1;
|
||||
grub_script_execute_sourcecode(cmdstr);
|
||||
g_ventoy_fn_mutex = 0;
|
||||
goto refresh;
|
||||
}
|
||||
}
|
||||
VTOY_COMM_HOTKEY("VTOY_F5_CMD");
|
||||
break;
|
||||
case GRUB_TERM_KEY_F6:
|
||||
case '6':
|
||||
if (0 == g_ventoy_fn_mutex) {
|
||||
cmdstr = grub_env_get("VTOY_F6_CMD");
|
||||
if (cmdstr)
|
||||
{
|
||||
menu_fini ();
|
||||
g_ventoy_fn_mutex = 1;
|
||||
grub_script_execute_sourcecode(cmdstr);
|
||||
g_ventoy_fn_mutex = 0;
|
||||
goto refresh;
|
||||
}
|
||||
}
|
||||
VTOY_COMM_HOTKEY("VTOY_F6_CMD");
|
||||
break;
|
||||
case GRUB_TERM_KEY_F7:
|
||||
menu_fini ();
|
||||
@@ -917,6 +962,40 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||
g_ventoy_menu_refresh = 1;
|
||||
goto refresh;
|
||||
|
||||
case (GRUB_TERM_CTRL | 'h'):
|
||||
case 'h':
|
||||
{
|
||||
cmdstr = grub_env_get("VTOY_HELP_CMD");
|
||||
if (cmdstr)
|
||||
{
|
||||
grub_script_execute_sourcecode(cmdstr);
|
||||
while (grub_getkey() != GRUB_TERM_ESC)
|
||||
;
|
||||
menu_fini ();
|
||||
goto refresh;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (GRUB_TERM_CTRL | 'm'):
|
||||
case 'm':
|
||||
{
|
||||
if (g_ventoy_cur_img_path)
|
||||
{
|
||||
grub_env_set("VTOY_CHKSUM_FILE_PATH", g_ventoy_cur_img_path);
|
||||
cmdstr = grub_env_get("VTOY_CHKSUM_CMD");
|
||||
if (cmdstr)
|
||||
{
|
||||
menu_fini();
|
||||
grub_script_execute_sourcecode(cmdstr);
|
||||
goto refresh;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_env_set("VTOY_CHKSUM_FILE_PATH", "X");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
int entry;
|
||||
@@ -1010,6 +1089,11 @@ show_menu (grub_menu_t menu, int nested, int autobooted)
|
||||
break;
|
||||
}
|
||||
|
||||
if (autobooted == 0 && g_ventoy_menu_esc && auto_boot) {
|
||||
g_ventoy_last_entry = boot_entry;
|
||||
break;
|
||||
}
|
||||
|
||||
e = grub_menu_get_entry (menu, boot_entry);
|
||||
if (! e)
|
||||
continue; /* Menu is empty. */
|
||||
|
@@ -42,6 +42,7 @@ struct menu_viewer_data
|
||||
TIMEOUT_TERSE_NO_MARGIN
|
||||
} timeout_msg;
|
||||
grub_menu_t menu;
|
||||
int *menu_title_offset;
|
||||
struct grub_term_output *term;
|
||||
};
|
||||
|
||||
@@ -524,6 +525,37 @@ menu_text_set_chosen_entry (int entry, void *dataptr)
|
||||
grub_term_refresh (data->term);
|
||||
}
|
||||
|
||||
static void
|
||||
menu_text_scroll_chosen_entry (void *dataptr, int diren)
|
||||
{
|
||||
struct menu_viewer_data *data = dataptr;
|
||||
const char *orig_title, *scrolled_title;
|
||||
int off;
|
||||
int selected;
|
||||
grub_menu_entry_t entry;
|
||||
|
||||
if (!data->menu->size)
|
||||
return;
|
||||
|
||||
selected = data->first + data->offset;
|
||||
entry = grub_menu_get_entry (data->menu, selected);
|
||||
orig_title = entry->title;
|
||||
off = data->menu_title_offset[selected] + diren;
|
||||
if (off < 0
|
||||
|| off > grub_utf8_get_num_code (orig_title, grub_strlen(orig_title)))
|
||||
return;
|
||||
|
||||
scrolled_title =
|
||||
grub_utf8_offset_code (orig_title, grub_strlen (orig_title), off);
|
||||
if (scrolled_title)
|
||||
entry->title = scrolled_title;
|
||||
print_entry (data->geo.first_entry_y + data->offset, 1, entry, data);
|
||||
|
||||
entry->title = orig_title;
|
||||
data->menu_title_offset[selected] = off;
|
||||
grub_term_refresh (data->term);
|
||||
}
|
||||
|
||||
static void
|
||||
menu_text_fini (void *dataptr)
|
||||
{
|
||||
@@ -531,6 +563,8 @@ menu_text_fini (void *dataptr)
|
||||
|
||||
grub_term_setcursor (data->term, 1);
|
||||
grub_term_cls (data->term);
|
||||
if (data->menu_title_offset)
|
||||
grub_free (data->menu_title_offset);
|
||||
grub_free (data);
|
||||
}
|
||||
|
||||
@@ -585,9 +619,14 @@ grub_menu_try_text (struct grub_term_output *term,
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
if (menu->size)
|
||||
data->menu_title_offset = grub_zalloc (sizeof (*data->menu_title_offset) * menu->size);
|
||||
|
||||
data->term = term;
|
||||
instance->data = data;
|
||||
instance->set_chosen_entry = menu_text_set_chosen_entry;
|
||||
if (data->menu_title_offset)
|
||||
instance->scroll_chosen_entry = menu_text_scroll_chosen_entry;
|
||||
instance->print_timeout = menu_text_print_timeout;
|
||||
instance->clear_timeout = menu_text_clear_timeout;
|
||||
instance->fini = menu_text_fini;
|
||||
|
232
GRUB2/MOD_SRC/grub-2.04/grub-core/partmap/gpt.c
Normal file
232
GRUB2/MOD_SRC/grub-2.04/grub-core/partmap/gpt.c
Normal file
@@ -0,0 +1,232 @@
|
||||
/* gpt.c - Read GUID Partition Tables (GPT). */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2005,2006,2007,2008 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/disk.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/partition.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/msdos_partition.h>
|
||||
#include <grub/gpt_partition.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_uint8_t grub_gpt_magic[8] =
|
||||
{
|
||||
0x45, 0x46, 0x49, 0x20, 0x50, 0x41, 0x52, 0x54
|
||||
};
|
||||
|
||||
static const grub_gpt_part_guid_t grub_gpt_partition_type_empty = GRUB_GPT_PARTITION_TYPE_EMPTY;
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
static const grub_gpt_part_guid_t grub_gpt_partition_type_bios_boot = GRUB_GPT_PARTITION_TYPE_BIOS_BOOT;
|
||||
#endif
|
||||
|
||||
/* 512 << 7 = 65536 byte sectors. */
|
||||
#define MAX_SECTOR_LOG 7
|
||||
|
||||
static struct grub_partition_map grub_gpt_partition_map;
|
||||
|
||||
|
||||
|
||||
grub_err_t
|
||||
grub_gpt_partition_map_iterate (grub_disk_t disk,
|
||||
grub_partition_iterate_hook_t hook,
|
||||
void *hook_data)
|
||||
{
|
||||
struct grub_partition part;
|
||||
struct grub_gpt_header gpt;
|
||||
struct grub_gpt_partentry entry;
|
||||
struct grub_msdos_partition_mbr mbr;
|
||||
grub_uint64_t entries;
|
||||
unsigned int i;
|
||||
int last_offset = 0;
|
||||
int sector_log = 0;
|
||||
|
||||
/* Read the protective MBR. */
|
||||
if (grub_disk_read (disk, 0, 0, sizeof (mbr), &mbr))
|
||||
return grub_errno;
|
||||
|
||||
/* Check if it is valid. */
|
||||
if (mbr.signature != grub_cpu_to_le16_compile_time (GRUB_PC_PARTITION_SIGNATURE))
|
||||
return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature");
|
||||
|
||||
/* Make sure the MBR is a protective MBR and not a normal MBR. */
|
||||
for (i = 0; i < 4; i++)
|
||||
if (mbr.entries[i].type == GRUB_PC_PARTITION_TYPE_GPT_DISK)
|
||||
break;
|
||||
if (i == 4)
|
||||
return grub_error (GRUB_ERR_BAD_PART_TABLE, "no GPT partition map found");
|
||||
|
||||
/* Read the GPT header. */
|
||||
for (sector_log = 0; sector_log < MAX_SECTOR_LOG; sector_log++)
|
||||
{
|
||||
if (grub_disk_read (disk, 1 << sector_log, 0, sizeof (gpt), &gpt))
|
||||
return grub_errno;
|
||||
|
||||
if (grub_memcmp (gpt.magic, grub_gpt_magic, sizeof (grub_gpt_magic)) == 0)
|
||||
break;
|
||||
}
|
||||
if (sector_log == MAX_SECTOR_LOG)
|
||||
return grub_error (GRUB_ERR_BAD_PART_TABLE, "no valid GPT header");
|
||||
|
||||
grub_dprintf ("gpt", "Read a valid GPT header\n");
|
||||
|
||||
entries = grub_le_to_cpu64 (gpt.partitions) << sector_log;
|
||||
for (i = 0; i < grub_le_to_cpu32 (gpt.maxpart); i++)
|
||||
{
|
||||
if (grub_disk_read (disk, entries, last_offset,
|
||||
sizeof (entry), &entry))
|
||||
return grub_errno;
|
||||
|
||||
if (grub_memcmp (&grub_gpt_partition_type_empty, &entry.type,
|
||||
sizeof (grub_gpt_partition_type_empty)))
|
||||
{
|
||||
/* Calculate the first block and the size of the partition. */
|
||||
part.start = grub_le_to_cpu64 (entry.start) << sector_log;
|
||||
part.len = (grub_le_to_cpu64 (entry.end)
|
||||
- grub_le_to_cpu64 (entry.start) + 1) << sector_log;
|
||||
part.offset = entries;
|
||||
part.number = i;
|
||||
part.index = last_offset;
|
||||
part.partmap = &grub_gpt_partition_map;
|
||||
part.parent = disk->partition;
|
||||
part.gpt_attrib = entry.attrib;
|
||||
|
||||
grub_dprintf ("gpt", "GPT entry %d: start=%lld, length=%lld\n", i,
|
||||
(unsigned long long) part.start,
|
||||
(unsigned long long) part.len);
|
||||
|
||||
if (hook (disk, &part, hook_data))
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
last_offset += grub_le_to_cpu32 (gpt.partentry_size);
|
||||
if (last_offset == GRUB_DISK_SECTOR_SIZE)
|
||||
{
|
||||
last_offset = 0;
|
||||
entries++;
|
||||
}
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
/* Context for gpt_partition_map_embed. */
|
||||
struct gpt_partition_map_embed_ctx
|
||||
{
|
||||
grub_disk_addr_t start, len;
|
||||
};
|
||||
|
||||
/* Helper for gpt_partition_map_embed. */
|
||||
static int
|
||||
find_usable_region (grub_disk_t disk __attribute__ ((unused)),
|
||||
const grub_partition_t p, void *data)
|
||||
{
|
||||
struct gpt_partition_map_embed_ctx *ctx = data;
|
||||
struct grub_gpt_partentry gptdata;
|
||||
grub_partition_t p2;
|
||||
|
||||
p2 = disk->partition;
|
||||
disk->partition = p->parent;
|
||||
if (grub_disk_read (disk, p->offset, p->index,
|
||||
sizeof (gptdata), &gptdata))
|
||||
{
|
||||
disk->partition = p2;
|
||||
return 0;
|
||||
}
|
||||
disk->partition = p2;
|
||||
|
||||
/* If there's an embed region, it is in a dedicated partition. */
|
||||
if (! grub_memcmp (&gptdata.type, &grub_gpt_partition_type_bios_boot, 16))
|
||||
{
|
||||
ctx->start = p->start;
|
||||
ctx->len = p->len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
gpt_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
|
||||
unsigned int max_nsectors,
|
||||
grub_embed_type_t embed_type,
|
||||
grub_disk_addr_t **sectors)
|
||||
{
|
||||
struct gpt_partition_map_embed_ctx ctx = {
|
||||
.start = 0,
|
||||
.len = 0
|
||||
};
|
||||
unsigned i;
|
||||
grub_err_t err;
|
||||
|
||||
if (embed_type != GRUB_EMBED_PCBIOS)
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"GPT currently supports only PC-BIOS embedding");
|
||||
|
||||
err = grub_gpt_partition_map_iterate (disk, find_usable_region, &ctx);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (ctx.len == 0)
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND,
|
||||
N_("this GPT partition label contains no BIOS Boot Partition;"
|
||||
" embedding won't be possible"));
|
||||
|
||||
if (ctx.len < *nsectors)
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE,
|
||||
N_("your BIOS Boot Partition is too small;"
|
||||
" embedding won't be possible"));
|
||||
|
||||
*nsectors = ctx.len;
|
||||
if (*nsectors > max_nsectors)
|
||||
*nsectors = max_nsectors;
|
||||
*sectors = grub_malloc (*nsectors * sizeof (**sectors));
|
||||
if (!*sectors)
|
||||
return grub_errno;
|
||||
for (i = 0; i < *nsectors; i++)
|
||||
(*sectors)[i] = ctx.start + i;
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Partition map type. */
|
||||
static struct grub_partition_map grub_gpt_partition_map =
|
||||
{
|
||||
.name = "gpt",
|
||||
.iterate = grub_gpt_partition_map_iterate,
|
||||
#ifdef GRUB_UTIL
|
||||
.embed = gpt_partition_map_embed
|
||||
#endif
|
||||
};
|
||||
|
||||
GRUB_MOD_INIT(part_gpt)
|
||||
{
|
||||
grub_partition_map_register (&grub_gpt_partition_map);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(part_gpt)
|
||||
{
|
||||
grub_partition_map_unregister (&grub_gpt_partition_map);
|
||||
}
|
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;
|
||||
}
|
260
GRUB2/MOD_SRC/grub-2.04/grub-core/term/efi/mouse.c
Normal file
260
GRUB2/MOD_SRC/grub-2.04/grub-core/term/efi/mouse.c
Normal file
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2022 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/env.h>
|
||||
#include <grub/efi/efi.h>
|
||||
#include <grub/efi/api.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#define GRUB_EFI_SIMPLE_POINTER_GUID \
|
||||
{ 0x31878c87, 0x0b75, 0x11d5, \
|
||||
{ 0x9a, 0x4f, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
grub_efi_int32_t x;
|
||||
grub_efi_int32_t y;
|
||||
grub_efi_int32_t z;
|
||||
grub_efi_boolean_t left;
|
||||
grub_efi_boolean_t right;
|
||||
} grub_efi_mouse_state;
|
||||
|
||||
grub_efi_mouse_state no_move = {0, 0, 0, 0, 0};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
grub_efi_uint64_t x;
|
||||
grub_efi_uint64_t y;
|
||||
grub_efi_uint64_t z;
|
||||
grub_efi_boolean_t left;
|
||||
grub_efi_boolean_t right;
|
||||
} grub_efi_mouse_mode;
|
||||
|
||||
struct grub_efi_simple_pointer_protocol
|
||||
{
|
||||
grub_efi_status_t (*reset) (struct grub_efi_simple_pointer_protocol *this,
|
||||
grub_efi_boolean_t extended_verification);
|
||||
grub_efi_status_t (*get_state) (struct grub_efi_simple_pointer_protocol *this,
|
||||
grub_efi_mouse_state *state);
|
||||
grub_efi_event_t *wait_for_input;
|
||||
grub_efi_mouse_mode *mode;
|
||||
};
|
||||
typedef struct grub_efi_simple_pointer_protocol grub_efi_simple_pointer_protocol_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
grub_efi_uintn_t count;
|
||||
grub_efi_simple_pointer_protocol_t **mouse;
|
||||
} grub_efi_mouse_prot_t;
|
||||
|
||||
static grub_int32_t
|
||||
mouse_div (grub_int32_t a, grub_uint64_t b)
|
||||
{
|
||||
grub_int32_t s = 1, q, ret;
|
||||
grub_uint64_t n = a;
|
||||
if (!b)
|
||||
return 0;
|
||||
if (a < 0)
|
||||
{
|
||||
s = -1;
|
||||
n = -a;
|
||||
}
|
||||
q = grub_divmod64 (n, b, NULL);
|
||||
ret = s * (q > 0 ? q : -q);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static grub_efi_mouse_prot_t *
|
||||
grub_efi_mouse_prot_init (void)
|
||||
{
|
||||
grub_efi_status_t status;
|
||||
grub_efi_guid_t mouse_guid = GRUB_EFI_SIMPLE_POINTER_GUID;
|
||||
grub_efi_mouse_prot_t *mouse_input = NULL;
|
||||
grub_efi_boot_services_t *b = grub_efi_system_table->boot_services;
|
||||
grub_efi_handle_t *buf;
|
||||
grub_efi_uintn_t count;
|
||||
grub_efi_uintn_t i;
|
||||
|
||||
status = efi_call_5 (b->locate_handle_buffer, GRUB_EFI_BY_PROTOCOL,
|
||||
&mouse_guid, NULL, &count, &buf);
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
{
|
||||
#ifdef MOUSE_DEBUG
|
||||
grub_printf ("ERROR: SimplePointerProtocol not found.\n");
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mouse_input = grub_malloc (sizeof (grub_efi_mouse_prot_t));
|
||||
if (!mouse_input)
|
||||
goto end;
|
||||
mouse_input->mouse = grub_malloc (count
|
||||
* sizeof (grub_efi_simple_pointer_protocol_t *));
|
||||
if (!mouse_input->mouse)
|
||||
{
|
||||
grub_free (mouse_input);
|
||||
mouse_input = NULL;
|
||||
goto end;
|
||||
}
|
||||
mouse_input->count = count;
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
efi_call_3 (b->handle_protocol,
|
||||
buf[i], &mouse_guid, (void **)&mouse_input->mouse[i]);
|
||||
#ifdef MOUSE_DEBUG
|
||||
grub_printf ("%d %p ", (int)i, mouse_input->mouse[i]);
|
||||
#endif
|
||||
efi_call_2 (mouse_input->mouse[i]->reset, mouse_input->mouse[i], 1);
|
||||
#ifdef MOUSE_DEBUG
|
||||
grub_printf
|
||||
("[%"PRIuGRUB_UINT64_T"] [%"PRIuGRUB_UINT64_T"] [%"PRIuGRUB_UINT64_T"]\n",
|
||||
mouse_input->mouse[i]->mode->x,
|
||||
mouse_input->mouse[i]->mode->y, mouse_input->mouse[i]->mode->z);
|
||||
#endif
|
||||
}
|
||||
|
||||
end:
|
||||
efi_call_1(b->free_pool, buf);
|
||||
|
||||
return mouse_input;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_efi_mouse_input_init (struct grub_term_input *term)
|
||||
{
|
||||
grub_efi_mouse_prot_t *mouse_input = NULL;
|
||||
if (term->data)
|
||||
return 0;
|
||||
mouse_input = grub_efi_mouse_prot_init ();
|
||||
if (!mouse_input)
|
||||
return GRUB_ERR_BAD_OS;
|
||||
|
||||
term->data = (void *)mouse_input;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_mouse_getkey (struct grub_term_input *term)
|
||||
{
|
||||
grub_efi_mouse_state cur;
|
||||
grub_efi_mouse_prot_t *mouse = term->data;
|
||||
//int x;
|
||||
int y;
|
||||
int delta = 0;
|
||||
const char *env;
|
||||
grub_efi_uintn_t i;
|
||||
if (!mouse)
|
||||
return GRUB_TERM_NO_KEY;
|
||||
|
||||
env = grub_env_get("mouse_delta");
|
||||
if (env)
|
||||
delta = (int)grub_strtol(env, NULL, 10);
|
||||
|
||||
for (i = 0; i < mouse->count; i++)
|
||||
{
|
||||
efi_call_2 (mouse->mouse[i]->get_state, mouse->mouse[i], &cur);
|
||||
if (grub_memcmp (&cur, &no_move, sizeof (grub_efi_mouse_state)) != 0)
|
||||
{
|
||||
y = mouse_div (cur.y, mouse->mouse[i]->mode->y);
|
||||
if (cur.left)
|
||||
return 0x0d;
|
||||
if (cur.right)
|
||||
return GRUB_TERM_ESC;
|
||||
if (y > delta)
|
||||
return GRUB_TERM_KEY_DOWN;
|
||||
if (y < -delta)
|
||||
return GRUB_TERM_KEY_UP;
|
||||
}
|
||||
}
|
||||
return GRUB_TERM_NO_KEY;
|
||||
}
|
||||
|
||||
#ifdef MOUSE_DEBUG
|
||||
static grub_err_t
|
||||
grub_cmd_mouse_test (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
char **args __attribute__ ((unused)))
|
||||
|
||||
{
|
||||
grub_efi_mouse_state cur;
|
||||
int x = 0, y = 0, z = 0;
|
||||
grub_efi_uintn_t i;
|
||||
grub_efi_mouse_prot_t *mouse = NULL;
|
||||
|
||||
mouse = grub_efi_mouse_prot_init ();
|
||||
if (!mouse)
|
||||
return grub_error (GRUB_ERR_BAD_OS, "mouse not found.\n");
|
||||
grub_printf ("Press [1] to exit.\n");
|
||||
while (1)
|
||||
{
|
||||
if (grub_getkey_noblock () == '1')
|
||||
break;
|
||||
for (i = 0; i < mouse->count; i++)
|
||||
{
|
||||
efi_call_2 (mouse->mouse[i]->get_state, mouse->mouse[i], &cur);
|
||||
if (grub_memcmp (&cur, &no_move, sizeof (grub_efi_mouse_state)) != 0)
|
||||
{
|
||||
x = mouse_div (cur.x, mouse->mouse[i]->mode->x);
|
||||
y = mouse_div (cur.y, mouse->mouse[i]->mode->y);
|
||||
z = mouse_div (cur.z, mouse->mouse[i]->mode->z);
|
||||
grub_printf ("[ID=%d] X=%d Y=%d Z=%d L=%d R=%d\n",
|
||||
(int)i, x, y, z, cur.left, cur.right);
|
||||
}
|
||||
}
|
||||
grub_refresh ();
|
||||
}
|
||||
grub_free (mouse->mouse);
|
||||
grub_free (mouse);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
static grub_command_t cmd;
|
||||
#endif
|
||||
|
||||
static struct grub_term_input grub_mouse_term_input =
|
||||
{
|
||||
.name = "mouse",
|
||||
.getkey = grub_mouse_getkey,
|
||||
.init = grub_efi_mouse_input_init,
|
||||
};
|
||||
|
||||
GRUB_MOD_INIT(mouse)
|
||||
{
|
||||
grub_term_register_input ("mouse", &grub_mouse_term_input);
|
||||
#ifdef MOUSE_DEBUG
|
||||
cmd = grub_register_command ("mouse_test", grub_cmd_mouse_test, 0,
|
||||
N_("UEFI mouse test."));
|
||||
#endif
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(mouse)
|
||||
{
|
||||
grub_term_unregister_input (&grub_mouse_term_input);
|
||||
#ifdef MOUSE_DEBUG
|
||||
grub_unregister_command (cmd);
|
||||
#endif
|
||||
}
|
@@ -35,6 +35,10 @@
|
||||
#include <grub/misc.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/memory.h>
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
#include <grub/efi/efi.h>
|
||||
#endif
|
||||
#include <grub/ventoy.h>
|
||||
#include "ventoy_def.h"
|
||||
|
||||
@@ -53,6 +57,26 @@ void ventoy_debug(const char *fmt, ...)
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
void ventoy_str_tolower(char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
*str = grub_tolower(*str);
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
void ventoy_str_toupper(char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
*str = grub_toupper(*str);
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int ventoy_strcmp(const char *pattern, const char *str)
|
||||
{
|
||||
while (*pattern && *str)
|
||||
@@ -142,8 +166,52 @@ static int ventoy_arch_mode_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
static void ventoy_get_uefi_version(char *str, grub_size_t len)
|
||||
{
|
||||
grub_efi_uint8_t uefi_minor_1, uefi_minor_2;
|
||||
|
||||
uefi_minor_1 = (grub_efi_system_table->hdr.revision & 0xffff) / 10;
|
||||
uefi_minor_2 = (grub_efi_system_table->hdr.revision & 0xffff) % 10;
|
||||
grub_snprintf(str, len, "%d.%d", (grub_efi_system_table->hdr.revision >> 16), uefi_minor_1);
|
||||
if (uefi_minor_2)
|
||||
grub_snprintf(str, len, "%s.%d", str, uefi_minor_2);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int ventoy_calc_totalmem(grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type, void *data)
|
||||
{
|
||||
grub_uint64_t *total_mem = (grub_uint64_t *)data;
|
||||
|
||||
(void)addr;
|
||||
(void)type;
|
||||
|
||||
*total_mem += size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_hwinfo_init(void)
|
||||
{
|
||||
char str[256];
|
||||
grub_uint64_t total_mem = 0;
|
||||
|
||||
grub_machine_mmap_iterate(ventoy_calc_totalmem, &total_mem);
|
||||
|
||||
grub_snprintf(str, sizeof(str), "%ld", (long)(total_mem / VTOY_SIZE_1MB));
|
||||
ventoy_env_export("grub_total_ram", str);
|
||||
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
ventoy_get_uefi_version(str, sizeof(str));
|
||||
ventoy_env_export("grub_uefi_version", str);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
GRUB_MOD_INIT(ventoy)
|
||||
{
|
||||
ventoy_hwinfo_init();
|
||||
ventoy_env_init();
|
||||
ventoy_arch_mode_init();
|
||||
ventoy_register_all_cmd();
|
||||
|
607
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_browser.c
Normal file
607
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_browser.c
Normal file
@@ -0,0 +1,607 @@
|
||||
/******************************************************************************
|
||||
* ventoy_browser.c
|
||||
*
|
||||
* Copyright (c) 2022, 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 <grub/types.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/device.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/partition.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/normal.h>
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/datetime.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/net.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/ventoy.h>
|
||||
#include "ventoy_def.h"
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#define BROWSER_MENU_BUF 65536
|
||||
|
||||
static const char *g_vtoy_dev = NULL;
|
||||
static grub_fs_t g_menu_fs = NULL;
|
||||
static char *g_menu_device = NULL;
|
||||
static grub_device_t g_menu_dev = NULL;
|
||||
static char g_menu_path_buf[1024];
|
||||
static int g_menu_path_len = 0;
|
||||
static browser_node *g_browser_list = NULL;
|
||||
|
||||
static int ventoy_browser_strcmp(char *str1, char *str2)
|
||||
{
|
||||
char *s1, *s2;
|
||||
int c1 = 0;
|
||||
int c2 = 0;
|
||||
|
||||
for (s1 = str1, s2 = str2; *s1 && *s2; s1++, s2++)
|
||||
{
|
||||
c1 = *s1;
|
||||
c2 = *s2;
|
||||
|
||||
if (0 == g_sort_case_sensitive)
|
||||
{
|
||||
if (grub_islower(c1))
|
||||
{
|
||||
c1 = c1 - 'a' + 'A';
|
||||
}
|
||||
|
||||
if (grub_islower(c2))
|
||||
{
|
||||
c2 = c2 - 'a' + 'A';
|
||||
}
|
||||
}
|
||||
|
||||
if (c1 != c2)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (c1 - c2);
|
||||
}
|
||||
|
||||
static int ventoy_browser_mbuf_alloc(browser_mbuf *mbuf)
|
||||
{
|
||||
grub_memset(mbuf, 0, sizeof(browser_mbuf));
|
||||
mbuf->buf = grub_malloc(BROWSER_MENU_BUF);
|
||||
if (!mbuf->buf)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
mbuf->pos = 0;
|
||||
mbuf->max = BROWSER_MENU_BUF;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline void ventoy_browser_mbuf_free(browser_mbuf *mbuf)
|
||||
{
|
||||
if (mbuf)
|
||||
grub_check_free(mbuf->buf)
|
||||
}
|
||||
|
||||
static inline int ventoy_browser_mbuf_extend(browser_mbuf *mbuf)
|
||||
{
|
||||
if (mbuf->max - mbuf->pos <= VTOY_SIZE_1KB)
|
||||
{
|
||||
mbuf->max += BROWSER_MENU_BUF;
|
||||
mbuf->buf = grub_realloc(mbuf->buf, mbuf->max);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static browser_node * ventoy_browser_find_top_node(int dir)
|
||||
{
|
||||
browser_node *node = NULL;
|
||||
browser_node *sel = NULL;
|
||||
|
||||
for (node = g_browser_list; node; node = node->next)
|
||||
{
|
||||
if (node->dir == dir)
|
||||
{
|
||||
if (sel)
|
||||
{
|
||||
if (ventoy_browser_strcmp(sel->filename, node->filename) > 0)
|
||||
{
|
||||
sel = node;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sel = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sel;
|
||||
}
|
||||
|
||||
static int ventoy_browser_iterate_partition(struct grub_disk *disk, const grub_partition_t partition, void *data)
|
||||
{
|
||||
char partname[64];
|
||||
char title[256];
|
||||
grub_device_t dev;
|
||||
grub_fs_t fs;
|
||||
char *Label = NULL;
|
||||
browser_mbuf *mbuf = (browser_mbuf *)data;
|
||||
|
||||
(void)data;
|
||||
|
||||
if (partition->number == 1 && g_vtoy_dev && grub_strcmp(disk->name, g_vtoy_dev) == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_snprintf(partname, sizeof(partname) - 1, "%s,%d", disk->name, partition->number + 1);
|
||||
|
||||
dev = grub_device_open(partname);
|
||||
if (!dev)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
fs = grub_fs_probe(dev);
|
||||
if (!fs)
|
||||
{
|
||||
grub_device_close(dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fs->fs_label(dev, &Label);
|
||||
|
||||
if (g_tree_view_menu_style == 0)
|
||||
{
|
||||
grub_snprintf(title, sizeof(title), "%-10s (%s,%s%d) [%s] %s %s",
|
||||
"DISK", disk->name, partition->msdostype == 0xee ? "gpt" : "msdos",
|
||||
partition->number + 1, (Label ? Label : ""), fs->name,
|
||||
grub_get_human_size(partition->len << disk->log_sector_size, GRUB_HUMAN_SIZE_SHORT));
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_snprintf(title, sizeof(title), "(%s,%s%d) [%s] %s %s",
|
||||
disk->name, partition->msdostype == 0xee ? "gpt" : "msdos",
|
||||
partition->number + 1, (Label ? Label : ""), fs->name,
|
||||
grub_get_human_size(partition->len << disk->log_sector_size, GRUB_HUMAN_SIZE_SHORT));
|
||||
}
|
||||
|
||||
if (ventoy_get_fs_type(fs->name) >= ventoy_fs_max)
|
||||
{
|
||||
browser_ssprintf(mbuf, "menuentry \"%s\" --class=vtoydisk {\n"
|
||||
" echo \"unsupported file system type!\" \n"
|
||||
" ventoy_pause\n"
|
||||
"}\n",
|
||||
title);
|
||||
}
|
||||
else
|
||||
{
|
||||
browser_ssprintf(mbuf, "menuentry \"%s\" --class=vtoydisk {\n"
|
||||
" vt_browser_dir %s,%d 0x%lx /\n"
|
||||
"}\n",
|
||||
title, disk->name, partition->number + 1, (ulong)fs);
|
||||
}
|
||||
|
||||
ventoy_browser_mbuf_extend(mbuf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_browser_iterate_disk(const char *name, void *data)
|
||||
{
|
||||
grub_disk_t disk;
|
||||
|
||||
if (name[0] != 'h')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
disk = grub_disk_open(name);
|
||||
if (disk)
|
||||
{
|
||||
grub_partition_iterate(disk, ventoy_browser_iterate_partition, data);
|
||||
grub_disk_close(disk);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_browser_valid_dirname(const char *name, int len)
|
||||
{
|
||||
if ((len == 1 && name[0] == '.') ||
|
||||
(len == 2 && name[0] == '.' && name[1] == '.'))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!ventoy_img_name_valid(name, len))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (name[0] == '$')
|
||||
{
|
||||
if (0 == grub_strncmp(name, "$RECYCLE.BIN", 12) ||
|
||||
0 == grub_strncasecmp(name, "$Extend", 7))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (len == 25 && grub_strncmp(name, "System Volume Information", 25) == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ventoy_browser_valid_filename(const char *filename, int len, int *type)
|
||||
{
|
||||
if (len < 4)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (FILE_FLT(ISO) && 0 == grub_strcasecmp(filename + len - 4, ".iso"))
|
||||
{
|
||||
*type = img_type_iso;
|
||||
}
|
||||
else if (FILE_FLT(WIM) && g_wimboot_enable && (0 == grub_strcasecmp(filename + len - 4, ".wim")))
|
||||
{
|
||||
*type = img_type_wim;
|
||||
}
|
||||
else if (FILE_FLT(VHD) && g_vhdboot_enable && (0 == grub_strcasecmp(filename + len - 4, ".vhd") ||
|
||||
(len >= 5 && 0 == grub_strcasecmp(filename + len - 5, ".vhdx"))))
|
||||
{
|
||||
*type = img_type_vhd;
|
||||
}
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
else if (FILE_FLT(EFI) && 0 == grub_strcasecmp(filename + len - 4, ".efi"))
|
||||
{
|
||||
*type = img_type_efi;
|
||||
}
|
||||
#endif
|
||||
else if (FILE_FLT(IMG) && 0 == grub_strcasecmp(filename + len - 4, ".img"))
|
||||
{
|
||||
if (len == 18 && grub_strncmp(filename, "ventoy_", 7) == 0)
|
||||
{
|
||||
if (grub_strncmp(filename + 7, "wimboot", 7) == 0 ||
|
||||
grub_strncmp(filename + 7, "vhdboot", 7) == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
*type = img_type_img;
|
||||
}
|
||||
else if (FILE_FLT(VTOY) && len >= 5 && 0 == grub_strcasecmp(filename + len - 5, ".vtoy"))
|
||||
{
|
||||
*type = img_type_vtoy;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (g_filt_dot_underscore_file && filename[0] == '.' && filename[1] == '_')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ventoy_browser_iterate_dir(const char *filename, const struct grub_dirhook_info *info, void *data)
|
||||
{
|
||||
int type;
|
||||
int len;
|
||||
browser_node *node;
|
||||
|
||||
(void)data;
|
||||
|
||||
len = grub_strlen(filename);
|
||||
|
||||
if (info->dir)
|
||||
{
|
||||
if (!ventoy_browser_valid_dirname(filename, len))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
node = grub_zalloc(sizeof(browser_node));
|
||||
if (!node)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
node->dir = 1;
|
||||
grub_strncpy(node->filename, filename, sizeof(node->filename));
|
||||
|
||||
if (g_tree_view_menu_style == 0)
|
||||
{
|
||||
grub_snprintf(node->menuentry, sizeof(node->menuentry),
|
||||
"menuentry \"%-10s [%s]\" --class=vtoydir {\n"
|
||||
" vt_browser_dir %s 0x%lx \"%s/%s\"\n"
|
||||
"}\n",
|
||||
"DIR", filename, g_menu_device, (ulong)g_menu_fs, g_menu_path_buf, filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_snprintf(node->menuentry, sizeof(node->menuentry),
|
||||
"menuentry \"[%s]\" --class=vtoydir {\n"
|
||||
" vt_browser_dir %s 0x%lx \"%s/%s\"\n"
|
||||
"}\n",
|
||||
filename, g_menu_device, (ulong)g_menu_fs, g_menu_path_buf, filename);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_uint64_t fsize = info->size;
|
||||
|
||||
if (!ventoy_browser_valid_filename(filename, len, &type))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
node = grub_zalloc(sizeof(browser_node));
|
||||
if (!node)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (fsize == 0)
|
||||
{
|
||||
struct grub_file file;
|
||||
|
||||
grub_memset(&file, 0, sizeof(file));
|
||||
file.device = g_menu_dev;
|
||||
grub_snprintf(node->menuentry, sizeof(node->menuentry), "%s/%s", g_menu_path_buf, filename);
|
||||
if (g_menu_fs->fs_open(&file, node->menuentry) == GRUB_ERR_NONE)
|
||||
{
|
||||
fsize = file.size;
|
||||
g_menu_fs->fs_close(&file);
|
||||
}
|
||||
}
|
||||
|
||||
node->dir = 0;
|
||||
grub_strncpy(node->filename, filename, sizeof(node->filename));
|
||||
|
||||
if (g_tree_view_menu_style == 0)
|
||||
{
|
||||
grub_snprintf(node->menuentry, sizeof(node->menuentry),
|
||||
"menuentry \"%-10s %s\" --class=%s {\n"
|
||||
" vt_set_fake_vlnk \"(%s)%s/%s\" %s %llu\n"
|
||||
" %s_common_menuentry\n"
|
||||
" vt_reset_fake_vlnk\n"
|
||||
"}\n",
|
||||
grub_get_human_size(fsize, GRUB_HUMAN_SIZE_SHORT), filename, g_menu_class[type],
|
||||
g_menu_device, g_menu_path_buf, filename, g_menu_prefix[type], (ulonglong)fsize,
|
||||
g_menu_prefix[type]);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_snprintf(node->menuentry, sizeof(node->menuentry),
|
||||
"menuentry \"%s\" --class=%s {\n"
|
||||
" vt_set_fake_vlnk \"(%s)%s/%s\" %s %llu\n"
|
||||
" %s_common_menuentry\n"
|
||||
" vt_reset_fake_vlnk\n"
|
||||
"}\n",
|
||||
filename, g_menu_class[type],
|
||||
g_menu_device, g_menu_path_buf, filename, g_menu_prefix[type], (ulonglong)fsize,
|
||||
g_menu_prefix[type]);
|
||||
}
|
||||
}
|
||||
|
||||
node->prev = NULL;
|
||||
node->next = g_browser_list;
|
||||
if (g_browser_list)
|
||||
{
|
||||
g_browser_list->prev = node;
|
||||
}
|
||||
g_browser_list = node;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t ventoy_browser_iso_part(void)
|
||||
{
|
||||
char cfgfile[64];
|
||||
char *buffer = NULL;
|
||||
int pos = 0;
|
||||
int buflen = 0;
|
||||
int cfglen = 0;
|
||||
|
||||
cfglen = g_tree_script_pos - g_tree_script_pre;
|
||||
buflen = cfglen + 512;
|
||||
buffer = grub_malloc(buflen);
|
||||
if (!buffer)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (g_tree_view_menu_style == 0)
|
||||
{
|
||||
pos = grub_snprintf(buffer, buflen, "menuentry \"%-10s [../]\" --class=\"vtoyret\" VTOY_RET {\n "
|
||||
" echo 'return ...' \n}\n", "<--");
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = grub_snprintf(buffer, buflen, "menuentry \"[../]\" --class=\"vtoyret\" VTOY_RET {\n "
|
||||
" echo 'return ...' \n}\n");
|
||||
}
|
||||
|
||||
grub_memcpy(buffer + pos, g_tree_script_buf + g_tree_script_pre, cfglen);
|
||||
pos += cfglen;
|
||||
|
||||
grub_snprintf(cfgfile, sizeof(cfgfile), "configfile mem:0x%lx:size:%d", (ulong)buffer, pos);
|
||||
grub_script_execute_sourcecode(cfgfile);
|
||||
|
||||
grub_free(buffer);
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_browser_dir(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int i;
|
||||
grub_fs_t fs;
|
||||
grub_device_t dev;
|
||||
char cfgfile[64];
|
||||
browser_node *node;
|
||||
browser_mbuf mbuf;
|
||||
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
|
||||
if (args[2][0] == '/' && args[2][1] == 0)
|
||||
{
|
||||
grub_snprintf(cfgfile, sizeof(cfgfile), "(%s)", args[0]);
|
||||
if (grub_strcmp(cfgfile, g_iso_path) == 0)
|
||||
{
|
||||
return ventoy_browser_iso_part();
|
||||
}
|
||||
}
|
||||
|
||||
if (!ventoy_browser_mbuf_alloc(&mbuf))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
fs = (grub_fs_t)grub_strtoul(args[1], NULL, 16);
|
||||
if (!fs)
|
||||
{
|
||||
debug("Invalid fs %s\n", args[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
dev = grub_device_open(args[0]);
|
||||
if (!dev)
|
||||
{
|
||||
debug("Failed to open device %s\n", args[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_menu_fs = fs;
|
||||
g_menu_device = args[0];
|
||||
g_menu_dev = dev;
|
||||
g_browser_list = NULL;
|
||||
|
||||
if (args[2][0] == '/' && args[2][1] == 0)
|
||||
{
|
||||
g_menu_path_len = 0;
|
||||
g_menu_path_buf[0] = 0;
|
||||
fs->fs_dir(dev, "/", ventoy_browser_iterate_dir, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_menu_path_len = grub_snprintf(g_menu_path_buf, sizeof(g_menu_path_buf), "%s", args[2]);
|
||||
fs->fs_dir(dev, g_menu_path_buf, ventoy_browser_iterate_dir, NULL);
|
||||
}
|
||||
grub_device_close(dev);
|
||||
|
||||
if (g_tree_view_menu_style == 0)
|
||||
{
|
||||
browser_ssprintf(&mbuf, "menuentry \"%-10s [../]\" --class=\"vtoyret\" VTOY_RET {\n "
|
||||
" echo 'return ...' \n}\n", "<--");
|
||||
}
|
||||
else
|
||||
{
|
||||
browser_ssprintf(&mbuf, "menuentry \"[../]\" --class=\"vtoyret\" VTOY_RET {\n "
|
||||
" echo 'return ...' \n}\n");
|
||||
}
|
||||
|
||||
for (i = 1; i >= 0; i--)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
node = ventoy_browser_find_top_node(i);
|
||||
if (node)
|
||||
{
|
||||
browser_ssprintf(&mbuf, "%s", node->menuentry);
|
||||
ventoy_browser_mbuf_extend(&mbuf);
|
||||
|
||||
if (node->prev)
|
||||
{
|
||||
node->prev->next = node->next;
|
||||
}
|
||||
if (node->next)
|
||||
{
|
||||
node->next->prev = node->prev;
|
||||
}
|
||||
|
||||
if (node == g_browser_list)
|
||||
{
|
||||
g_browser_list = node->next;
|
||||
}
|
||||
grub_free(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
g_browser_list = NULL;
|
||||
|
||||
grub_snprintf(cfgfile, sizeof(cfgfile), "configfile mem:0x%lx:size:%d", (ulong)mbuf.buf, mbuf.pos);
|
||||
grub_script_execute_sourcecode(cfgfile);
|
||||
|
||||
ventoy_browser_mbuf_free(&mbuf);
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_browser_disk(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
char cfgfile[64];
|
||||
browser_mbuf mbuf;
|
||||
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
(void)args;
|
||||
|
||||
if (!ventoy_browser_mbuf_alloc(&mbuf))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_vtoy_dev = grub_env_get("vtoydev");
|
||||
|
||||
if (g_tree_view_menu_style == 0)
|
||||
{
|
||||
browser_ssprintf(&mbuf, "menuentry \"%-10s [Return]\" --class=\"vtoyret\" VTOY_RET {\n "
|
||||
" echo 'return ...' \n}\n", "<--");
|
||||
}
|
||||
else
|
||||
{
|
||||
browser_ssprintf(&mbuf, "menuentry \"[Return]\" --class=\"vtoyret\" VTOY_RET {\n "
|
||||
" echo 'return ...' \n}\n");
|
||||
}
|
||||
|
||||
grub_disk_dev_iterate(ventoy_browser_iterate_disk, &mbuf);
|
||||
|
||||
grub_snprintf(cfgfile, sizeof(cfgfile), "configfile mem:0x%lx:size:%d", (ulong)mbuf.buf, mbuf.pos);
|
||||
grub_script_execute_sourcecode(cfgfile);
|
||||
|
||||
ventoy_browser_mbuf_free(&mbuf);
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -21,6 +21,8 @@
|
||||
#ifndef __VENTOY_DEF_H__
|
||||
#define __VENTOY_DEF_H__
|
||||
|
||||
#define VTOY_MAX_DIR_DEPTH 32
|
||||
|
||||
#define VTOY_MAX_SCRIPT_BUF (4 * 1024 * 1024)
|
||||
|
||||
#define VTOY_PART_BUF_LEN (128 * 1024)
|
||||
@@ -33,6 +35,7 @@
|
||||
#define VTOY_SIZE_4MB (4 * 1024 * 1024)
|
||||
#define VTOY_SIZE_512KB (512 * 1024)
|
||||
#define VTOY_SIZE_1KB 1024
|
||||
#define VTOY_SIZE_32KB (32 * 1024)
|
||||
|
||||
#define JSON_SUCCESS 0
|
||||
#define JSON_FAILED 1
|
||||
@@ -197,6 +200,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
|
||||
@@ -215,6 +230,8 @@ typedef struct img_info
|
||||
char name[256];
|
||||
|
||||
const char *alias;
|
||||
const char *tip1;
|
||||
const char *tip2;
|
||||
const char *class;
|
||||
const char *menu_prefix;
|
||||
|
||||
@@ -288,6 +305,7 @@ extern ventoy_guid g_ventoy_guid;
|
||||
extern ventoy_img_chunk_list g_img_chunk_list;
|
||||
extern ventoy_img_chunk_list g_wimiso_chunk_list;
|
||||
extern char *g_wimiso_path;
|
||||
extern grub_uint32_t g_wimiso_size;
|
||||
extern char g_arch_mode_suffix[64];
|
||||
extern const char *g_menu_prefix[img_type_max];
|
||||
|
||||
@@ -298,6 +316,9 @@ void ventoy_debug(const char *fmt, ...);
|
||||
#define vtoy_ssprintf(buf, pos, fmt, ...) \
|
||||
pos += grub_snprintf(buf + pos, VTOY_MAX_SCRIPT_BUF - pos, fmt, __VA_ARGS__)
|
||||
|
||||
#define browser_ssprintf(mbuf, fmt, args...) \
|
||||
(mbuf)->pos += grub_snprintf((mbuf)->buf + (mbuf)->pos, (mbuf)->max - (mbuf)->pos, fmt, ##args)
|
||||
|
||||
#define FLAG_HEADER_RESERVED 0x00000001
|
||||
#define FLAG_HEADER_COMPRESSION 0x00000002
|
||||
#define FLAG_HEADER_READONLY 0x00000004
|
||||
@@ -432,6 +453,18 @@ typedef struct wim_directory_entry
|
||||
/** No security information exists for this file */
|
||||
#define WIM_NO_SECURITY 0xffffffffUL
|
||||
|
||||
typedef struct reg_vk
|
||||
{
|
||||
grub_uint32_t res1;
|
||||
grub_uint16_t sig;
|
||||
grub_uint16_t namesize;
|
||||
grub_uint32_t datasize;
|
||||
grub_uint32_t dataoffset;
|
||||
grub_uint32_t datatype;
|
||||
grub_uint16_t flag;
|
||||
grub_uint16_t res2;
|
||||
}reg_vk;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
|
||||
@@ -534,6 +567,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
|
||||
@@ -547,6 +581,12 @@ typedef struct replace_fs_dir
|
||||
int filecnt;
|
||||
}replace_fs_dir;
|
||||
|
||||
typedef struct chk_case_fs_dir
|
||||
{
|
||||
grub_device_t dev;
|
||||
grub_fs_t fs;
|
||||
}chk_case_fs_dir;
|
||||
|
||||
int ventoy_strcmp(const char *pattern, const char *str);
|
||||
int ventoy_strncmp (const char *pattern, const char *str, grub_size_t n);
|
||||
void ventoy_fill_os_param(grub_file_t file, ventoy_os_param *param);
|
||||
@@ -562,13 +602,13 @@ grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc,
|
||||
grub_err_t ventoy_cmd_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_valid_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_append_ext_sector(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_skip_svd(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_cpio_busybox_64(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_trailer_cpio(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
int ventoy_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, const char *name);
|
||||
grub_file_t ventoy_grub_file_open(enum grub_file_type type, const char *fmt, ...);
|
||||
grub_uint64_t ventoy_grub_get_file_size(const char *fmt, ...);
|
||||
int ventoy_is_file_exist(const char *fmt, ...);
|
||||
int ventoy_is_dir_exist(const char *fmt, ...);
|
||||
int ventoy_fill_data(grub_uint32_t buflen, char *buffer);
|
||||
grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
@@ -790,6 +830,7 @@ typedef struct ventoy_video_mode
|
||||
typedef struct file_fullpath
|
||||
{
|
||||
char path[256];
|
||||
int vlnk_add;
|
||||
}file_fullpath;
|
||||
|
||||
typedef struct theme_list
|
||||
@@ -806,6 +847,7 @@ typedef struct install_template
|
||||
int pathlen;
|
||||
char isopath[256];
|
||||
|
||||
int timeout;
|
||||
int autosel;
|
||||
int cursel;
|
||||
int templatenum;
|
||||
@@ -837,6 +879,7 @@ typedef struct persistence_config
|
||||
int pathlen;
|
||||
char isopath[256];
|
||||
|
||||
int timeout;
|
||||
int autosel;
|
||||
int cursel;
|
||||
int backendnum;
|
||||
@@ -858,6 +901,20 @@ 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];
|
||||
char tip2[1024];
|
||||
|
||||
struct menu_tip *next;
|
||||
}menu_tip;
|
||||
|
||||
|
||||
#define vtoy_class_image_file 0
|
||||
#define vtoy_class_directory 1
|
||||
|
||||
@@ -889,6 +946,7 @@ typedef struct custom_boot
|
||||
typedef struct conf_replace
|
||||
{
|
||||
int pathlen;
|
||||
int img;
|
||||
char isopath[256];
|
||||
char orgconf[256];
|
||||
char newconf[256];
|
||||
@@ -953,6 +1011,7 @@ typedef struct menu_password
|
||||
|
||||
extern int g_ventoy_menu_esc;
|
||||
extern int g_ventoy_suppress_esc;
|
||||
extern int g_ventoy_suppress_esc_default;
|
||||
extern int g_ventoy_last_entry;
|
||||
extern int g_ventoy_memdisk_mode;
|
||||
extern int g_ventoy_iso_raw;
|
||||
@@ -960,6 +1019,7 @@ extern int g_ventoy_grub2_mode;
|
||||
extern int g_ventoy_wimboot_mode;
|
||||
extern int g_ventoy_iso_uefi_drv;
|
||||
extern int g_ventoy_case_insensitive;
|
||||
extern int g_ventoy_fn_mutex;
|
||||
extern grub_uint8_t g_ventoy_chain_type;
|
||||
extern int g_vhdboot_enable;
|
||||
|
||||
@@ -997,6 +1057,8 @@ extern grub_uint32_t g_ventoy_plat_data;
|
||||
#define ventoy_syscall0(name) grub_##name()
|
||||
#define ventoy_syscall1(name, a) grub_##name(a)
|
||||
|
||||
void ventoy_str_tolower(char *str);
|
||||
void ventoy_str_toupper(char *str);
|
||||
char * ventoy_get_line(char *start);
|
||||
int ventoy_cmp_img(img_info *img1, img_info *img2);
|
||||
void ventoy_swap_img(img_info *img1, img_info *img2);
|
||||
@@ -1010,6 +1072,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(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);
|
||||
@@ -1020,6 +1083,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);
|
||||
@@ -1029,8 +1094,11 @@ grub_err_t ventoy_cmd_locate_wim_patch(grub_extcmd_context_t ctxt, int argc, cha
|
||||
grub_err_t ventoy_cmd_unix_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
int ventoy_get_disk_guid(const char *filename, grub_uint8_t *guid, grub_uint8_t *signature);
|
||||
grub_err_t ventoy_cmd_unix_reset(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_unix_check_vlnk(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_grub_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);
|
||||
@@ -1067,5 +1135,76 @@ int ventoy_chain_file_read(const char *path, int offset, int len, void *buf);
|
||||
grub_env_export(env);\
|
||||
}
|
||||
|
||||
#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()
|
||||
|
||||
typedef struct ventoy_vlnk_part
|
||||
{
|
||||
grub_uint32_t disksig;
|
||||
grub_uint64_t partoffset;
|
||||
char disk[64];
|
||||
char device[64];
|
||||
grub_device_t dev;
|
||||
grub_fs_t fs;
|
||||
int probe;
|
||||
struct ventoy_vlnk_part *next;
|
||||
}ventoy_vlnk_part;
|
||||
|
||||
|
||||
typedef struct browser_mbuf
|
||||
{
|
||||
int max;
|
||||
int pos;
|
||||
char *buf;
|
||||
}browser_mbuf;
|
||||
|
||||
typedef struct browser_node
|
||||
{
|
||||
int dir;
|
||||
char menuentry[1024];
|
||||
char filename[512];
|
||||
struct browser_node *prev;
|
||||
struct browser_node *next;
|
||||
}browser_node;
|
||||
|
||||
extern char *g_tree_script_buf;
|
||||
extern int g_tree_script_pos;
|
||||
extern int g_tree_script_pre;
|
||||
extern int g_tree_view_menu_style;
|
||||
extern int g_sort_case_sensitive;
|
||||
extern int g_wimboot_enable;
|
||||
extern int g_filt_dot_underscore_file;
|
||||
extern int g_vtoy_file_flt[VTOY_FILE_FLT_BUTT];
|
||||
extern const char *g_menu_class[img_type_max];
|
||||
extern char g_iso_path[256];
|
||||
int ventoy_add_vlnk_file(char *dir, const char *name);
|
||||
grub_err_t ventoy_cmd_browser_dir(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_browser_disk(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
int ventoy_get_fs_type(const char *fs);
|
||||
int ventoy_img_name_valid(const char *filename, grub_size_t namelen);
|
||||
|
||||
#endif /* __VENTOY_DEF_H__ */
|
||||
|
||||
|
@@ -152,6 +152,23 @@ static int vtoy_json_parse_string
|
||||
return JSON_FAILED;
|
||||
}
|
||||
|
||||
if (*(pcPos - 1) == '\\')
|
||||
{
|
||||
for (pcPos++; *pcPos; pcPos++)
|
||||
{
|
||||
if (*pcPos == '"' && *(pcPos - 1) != '\\')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (*pcPos == 0 || pcPos < pcTmp)
|
||||
{
|
||||
json_debug("Invalid quotes string %s.", pcData);
|
||||
return JSON_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
*ppcEnd = pcPos + 1;
|
||||
uiLen = (grub_uint32_t)(unsigned long)(pcPos - pcTmp);
|
||||
|
||||
|
@@ -38,6 +38,9 @@
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#define VTOY_APPEND_EXT_SIZE 4096
|
||||
static int g_append_ext_sector = 0;
|
||||
|
||||
char * ventoy_get_line(char *start)
|
||||
{
|
||||
if (start == NULL)
|
||||
@@ -658,6 +661,11 @@ static grub_uint32_t ventoy_linux_get_virt_chunk_count(void)
|
||||
count++;
|
||||
}
|
||||
|
||||
if (g_append_ext_sector > 0)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -672,12 +680,18 @@ static grub_uint32_t ventoy_linux_get_virt_chunk_size(void)
|
||||
size += sizeof(ventoy_virt_chunk) + g_conf_replace_new_len_align;
|
||||
}
|
||||
|
||||
if (g_append_ext_sector > 0)
|
||||
{
|
||||
size += sizeof(ventoy_virt_chunk) + VTOY_APPEND_EXT_SIZE;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -725,6 +739,29 @@ 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 */
|
||||
if (g_append_ext_sector > 0)
|
||||
{
|
||||
cpio_secs = VTOY_APPEND_EXT_SIZE / 2048;
|
||||
|
||||
cur->mem_sector_start = sector;
|
||||
cur->mem_sector_end = cur->mem_sector_start + cpio_secs;
|
||||
cur->mem_sector_offset = offset;
|
||||
cur->remap_sector_start = 0;
|
||||
cur->remap_sector_end = 0;
|
||||
cur->org_sector_start = 0;
|
||||
|
||||
grub_memset(override + offset, 0, VTOY_APPEND_EXT_SIZE);
|
||||
|
||||
chain->virt_img_size_in_bytes += VTOY_APPEND_EXT_SIZE;
|
||||
|
||||
offset += VTOY_APPEND_EXT_SIZE;
|
||||
sector += cpio_secs;
|
||||
cur++;
|
||||
virtid++;
|
||||
}
|
||||
|
||||
if (g_conf_replace_offset > 0)
|
||||
@@ -742,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;
|
||||
@@ -944,6 +987,12 @@ static grub_err_t ventoy_linux_locate_initrd(int filt, int *filtcnt)
|
||||
}
|
||||
}
|
||||
|
||||
/* skip hdt.img */
|
||||
if (file->size <= VTOY_SIZE_1MB && grub_strcmp(node->name, "/boot/hdt.img") == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (grub_strcmp(file->fs->name, "iso9660") == 0)
|
||||
{
|
||||
node->iso_type = 0;
|
||||
@@ -1119,6 +1168,24 @@ grub_err_t ventoy_cmd_skip_svd(grub_extcmd_context_t ctxt, int argc, char **args
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_append_ext_sector(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
(void)args;
|
||||
|
||||
if (args[0][0] == '1')
|
||||
{
|
||||
g_append_ext_sector = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_append_ext_sector = 0;
|
||||
}
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int i;
|
||||
@@ -1459,9 +1526,9 @@ grub_err_t ventoy_cmd_trailer_cpio(grub_extcmd_context_t ctxt, int argc, char **
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
|
||||
grub_err_t ventoy_cmd_linux_chain_data(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int len = 0;
|
||||
int ventoy_compatible = 0;
|
||||
grub_uint32_t size = 0;
|
||||
grub_uint64_t isosize = 0;
|
||||
@@ -1501,23 +1568,31 @@ grub_err_t ventoy_cmd_linux_chain_data(grub_extcmd_context_t ctxt, int argc, cha
|
||||
|
||||
isosize = file->size;
|
||||
|
||||
boot_catlog = ventoy_get_iso_boot_catlog(file);
|
||||
if (boot_catlog)
|
||||
len = (int)grub_strlen(args[0]);
|
||||
if (len >= 4 && 0 == grub_strcasecmp(args[0] + len - 4, ".img"))
|
||||
{
|
||||
if (ventoy_is_efi_os() && (!ventoy_has_efi_eltorito(file, boot_catlog)))
|
||||
{
|
||||
grub_env_set("LoadIsoEfiDriver", "on");
|
||||
}
|
||||
debug("boot catlog %u for img file\n", boot_catlog);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ventoy_is_efi_os())
|
||||
boot_catlog = ventoy_get_iso_boot_catlog(file);
|
||||
if (boot_catlog)
|
||||
{
|
||||
grub_env_set("LoadIsoEfiDriver", "on");
|
||||
if (ventoy_is_efi_os() && (!ventoy_has_efi_eltorito(file, boot_catlog)))
|
||||
{
|
||||
grub_env_set("LoadIsoEfiDriver", "on");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return grub_error(GRUB_ERR_BAD_ARGUMENT, "File %s is not bootable", args[0]);
|
||||
if (ventoy_is_efi_os())
|
||||
{
|
||||
grub_env_set("LoadIsoEfiDriver", "on");
|
||||
}
|
||||
else
|
||||
{
|
||||
return grub_error(GRUB_ERR_BAD_ARGUMENT, "File %s is not bootable", args[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -48,6 +48,7 @@ static install_template *g_install_template_head = NULL;
|
||||
static dud *g_dud_head = NULL;
|
||||
static menu_password *g_pwd_head = NULL;
|
||||
static persistence_config *g_persistence_head = NULL;
|
||||
static menu_tip *g_menu_tip_head = NULL;
|
||||
static menu_alias *g_menu_alias_head = NULL;
|
||||
static menu_class *g_menu_class_head = NULL;
|
||||
static custom_boot *g_custom_boot_head = NULL;
|
||||
@@ -56,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;
|
||||
@@ -169,11 +171,11 @@ static int ventoy_plugin_theme_check(VTOY_JSON *json, const char *isodisk)
|
||||
grub_printf("file: %s\n", value);
|
||||
if (value[0] == '/')
|
||||
{
|
||||
exist = ventoy_is_file_exist("%s%s", isodisk, value);
|
||||
exist = ventoy_check_file_exist("%s%s", isodisk, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
exist = ventoy_is_file_exist("%s/ventoy/%s", isodisk, value);
|
||||
exist = ventoy_check_file_exist("%s/ventoy/%s", isodisk, value);
|
||||
}
|
||||
|
||||
if (exist == 0)
|
||||
@@ -193,11 +195,11 @@ static int ventoy_plugin_theme_check(VTOY_JSON *json, const char *isodisk)
|
||||
grub_printf("file: %s\n", value);
|
||||
if (value[0] == '/')
|
||||
{
|
||||
exist = ventoy_is_file_exist("%s%s", isodisk, value);
|
||||
exist = ventoy_check_file_exist("%s%s", isodisk, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
exist = ventoy_is_file_exist("%s/ventoy/%s", isodisk, value);
|
||||
exist = ventoy_check_file_exist("%s/ventoy/%s", isodisk, value);
|
||||
}
|
||||
|
||||
if (exist == 0)
|
||||
@@ -280,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 +369,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)
|
||||
{
|
||||
@@ -448,7 +463,7 @@ static int ventoy_plugin_check_path(const char *path, const char *file)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!ventoy_is_file_exist("%s%s", path, file))
|
||||
if (!ventoy_check_file_exist("%s%s", path, file))
|
||||
{
|
||||
grub_printf("%s%s does NOT exist\n", path, file);
|
||||
return 1;
|
||||
@@ -546,7 +561,7 @@ static int ventoy_plugin_parse_fullpath
|
||||
{
|
||||
debug("%s is string type data\n", node->pcName);
|
||||
|
||||
if ((node->unData.pcStrVal[0] != '/') || (!ventoy_is_file_exist("%s%s", isodisk, node->unData.pcStrVal)))
|
||||
if ((node->unData.pcStrVal[0] != '/') || (!ventoy_check_file_exist("%s%s", isodisk, node->unData.pcStrVal)))
|
||||
{
|
||||
debug("%s%s file not found\n", isodisk, node->unData.pcStrVal);
|
||||
return 1;
|
||||
@@ -581,7 +596,7 @@ static int ventoy_plugin_parse_fullpath
|
||||
|
||||
for (count = 0, child = node->pstChild; child; child = child->pstNext)
|
||||
{
|
||||
if (ventoy_is_file_exist("%s%s", isodisk, child->unData.pcStrVal))
|
||||
if (ventoy_check_file_exist("%s%s", isodisk, child->unData.pcStrVal))
|
||||
{
|
||||
grub_snprintf(path->path, sizeof(path->path), "%s", child->unData.pcStrVal);
|
||||
path++;
|
||||
@@ -601,6 +616,7 @@ static int ventoy_plugin_auto_install_check(VTOY_JSON *json, const char *isodisk
|
||||
{
|
||||
int pathnum = 0;
|
||||
int autosel = 0;
|
||||
int timeout = 0;
|
||||
char *pos = NULL;
|
||||
const char *iso = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
@@ -637,6 +653,18 @@ static int ventoy_plugin_auto_install_check(VTOY_JSON *json, const char *isodisk
|
||||
grub_printf("autosel: %d [FAIL]\n", autosel);
|
||||
}
|
||||
}
|
||||
|
||||
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout))
|
||||
{
|
||||
if (timeout >= 0)
|
||||
{
|
||||
grub_printf("timeout: %d [OK]\n", timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("timeout: %d [FAIL]\n", timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -661,6 +689,18 @@ static int ventoy_plugin_auto_install_check(VTOY_JSON *json, const char *isodisk
|
||||
grub_printf("autosel: %d [FAIL]\n", autosel);
|
||||
}
|
||||
}
|
||||
|
||||
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout))
|
||||
{
|
||||
if (timeout >= 0)
|
||||
{
|
||||
grub_printf("timeout: %d [OK]\n", timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("timeout: %d [FAIL]\n", timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -681,6 +721,7 @@ static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk
|
||||
int type = 0;
|
||||
int pathnum = 0;
|
||||
int autosel = 0;
|
||||
int timeout = 0;
|
||||
const char *iso = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
install_template *node = NULL;
|
||||
@@ -728,6 +769,7 @@ static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk
|
||||
node->templatenum = pathnum;
|
||||
|
||||
node->autosel = -1;
|
||||
node->timeout = -1;
|
||||
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "autosel", &autosel))
|
||||
{
|
||||
if (autosel >= 0 && autosel <= pathnum)
|
||||
@@ -736,6 +778,14 @@ static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk
|
||||
}
|
||||
}
|
||||
|
||||
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout))
|
||||
{
|
||||
if (timeout >= 0)
|
||||
{
|
||||
node->timeout = timeout;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_install_template_head)
|
||||
{
|
||||
node->next = g_install_template_head;
|
||||
@@ -910,7 +960,7 @@ static int ventoy_plugin_parse_pwdstr(char *pwdstr, vtoy_password *pwd)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (len - 1 - (int)(long)(pos - pwdstr) != 32)
|
||||
if (len - 1 - ((long)pos - (long)pwdstr) != 32)
|
||||
{
|
||||
if (NULL == pwd) grub_printf("Invalid md5 salt password format %s\n", pwdstr);
|
||||
return 1;
|
||||
@@ -1174,6 +1224,7 @@ static int ventoy_plugin_pwd_check(VTOY_JSON *json, const char *isodisk)
|
||||
static int ventoy_plugin_persistence_check(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int autosel = 0;
|
||||
int timeout = 0;
|
||||
int pathnum = 0;
|
||||
char *pos = NULL;
|
||||
const char *iso = NULL;
|
||||
@@ -1212,6 +1263,18 @@ static int ventoy_plugin_persistence_check(VTOY_JSON *json, const char *isodisk)
|
||||
grub_printf("autosel: %d [FAIL]\n", autosel);
|
||||
}
|
||||
}
|
||||
|
||||
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout))
|
||||
{
|
||||
if (timeout >= 0)
|
||||
{
|
||||
grub_printf("timeout: %d [OK]\n", timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("timeout: %d [FAIL]\n", timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1230,6 +1293,7 @@ static int ventoy_plugin_persistence_check(VTOY_JSON *json, const char *isodisk)
|
||||
static int ventoy_plugin_persistence_entry(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int autosel = 0;
|
||||
int timeout = 0;
|
||||
int pathnum = 0;
|
||||
const char *iso = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
@@ -1272,6 +1336,7 @@ static int ventoy_plugin_persistence_entry(VTOY_JSON *json, const char *isodisk)
|
||||
node->backendnum = pathnum;
|
||||
|
||||
node->autosel = -1;
|
||||
node->timeout = -1;
|
||||
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "autosel", &autosel))
|
||||
{
|
||||
if (autosel >= 0 && autosel <= pathnum)
|
||||
@@ -1280,6 +1345,14 @@ static int ventoy_plugin_persistence_entry(VTOY_JSON *json, const char *isodisk)
|
||||
}
|
||||
}
|
||||
|
||||
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout))
|
||||
{
|
||||
if (timeout >= 0)
|
||||
{
|
||||
node->timeout = timeout;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_persistence_head)
|
||||
{
|
||||
node->next = g_persistence_head;
|
||||
@@ -1328,7 +1401,7 @@ static int ventoy_plugin_menualias_check(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
grub_printf("image: <%s> [ * ]\n", path);
|
||||
}
|
||||
else if (ventoy_is_file_exist("%s%s", isodisk, path))
|
||||
else if (ventoy_check_file_exist("%s%s", isodisk, path))
|
||||
{
|
||||
grub_printf("image: <%s> [ OK ]\n", path);
|
||||
}
|
||||
@@ -1417,6 +1490,207 @@ static int ventoy_plugin_menualias_entry(VTOY_JSON *json, const char *isodisk)
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
(void)isodisk;
|
||||
|
||||
if (json->enDataType != JSON_TYPE_OBJECT)
|
||||
{
|
||||
grub_printf("Not object %d\n", json->enDataType);
|
||||
return 1;
|
||||
}
|
||||
|
||||
tip = vtoy_json_get_string_ex(json->pstChild, "left");
|
||||
if (tip)
|
||||
{
|
||||
grub_printf("left: <%s>\n", tip);
|
||||
}
|
||||
|
||||
tip = vtoy_json_get_string_ex(json->pstChild, "top");
|
||||
if (tip)
|
||||
{
|
||||
grub_printf("top: <%s>\n", tip);
|
||||
}
|
||||
|
||||
tip = vtoy_json_get_string_ex(json->pstChild, "color");
|
||||
if (tip)
|
||||
{
|
||||
grub_printf("color: <%s>\n", tip);
|
||||
}
|
||||
|
||||
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 (vtoy_tip_image_file == type)
|
||||
{
|
||||
if (grub_strchr(path, '*'))
|
||||
{
|
||||
grub_printf("image: <%s> [ * ]\n", path);
|
||||
}
|
||||
else if (ventoy_check_file_exist("%s%s", isodisk, path))
|
||||
{
|
||||
grub_printf("image: <%s> [ OK ]\n", path);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("image: <%s> [ NOT EXIST ]\n", path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ventoy_is_dir_exist("%s%s", isodisk, path))
|
||||
{
|
||||
grub_printf("dir: <%s> [ OK ]\n", path);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("dir: <%s> [ NOT EXIST ]\n", path);
|
||||
}
|
||||
}
|
||||
|
||||
tip = vtoy_json_get_string_ex(pNode->pstChild, "tip");
|
||||
if (tip)
|
||||
{
|
||||
grub_printf("tip: <%s>\n", tip);
|
||||
}
|
||||
else
|
||||
{
|
||||
tip = vtoy_json_get_string_ex(pNode->pstChild, "tip1");
|
||||
if (tip)
|
||||
grub_printf("tip1: <%s>\n", tip);
|
||||
else
|
||||
grub_printf("tip1: <NULL>\n");
|
||||
|
||||
tip = vtoy_json_get_string_ex(pNode->pstChild, "tip2");
|
||||
if (tip)
|
||||
grub_printf("tip2: <%s>\n", tip);
|
||||
else
|
||||
grub_printf("tip2: <NULL>\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("image: <%s> [ INVALID ]\n", path);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
menu_tip *node = NULL;
|
||||
menu_tip *next = NULL;
|
||||
|
||||
(void)isodisk;
|
||||
|
||||
if (json->enDataType != JSON_TYPE_OBJECT)
|
||||
{
|
||||
debug("Not object %d\n", json->enDataType);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pNode = vtoy_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "tips");
|
||||
if (pNode == NULL)
|
||||
{
|
||||
debug("Not tips found\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (g_menu_tip_head)
|
||||
{
|
||||
for (node = g_menu_tip_head; node; node = next)
|
||||
{
|
||||
next = node->next;
|
||||
grub_free(node);
|
||||
}
|
||||
|
||||
g_menu_tip_head = NULL;
|
||||
}
|
||||
|
||||
tip = vtoy_json_get_string_ex(json->pstChild, "left");
|
||||
if (tip)
|
||||
{
|
||||
grub_env_set("VTOY_TIP_LEFT", tip);
|
||||
}
|
||||
|
||||
tip = vtoy_json_get_string_ex(json->pstChild, "top");
|
||||
if (tip)
|
||||
{
|
||||
grub_env_set("VTOY_TIP_TOP", tip);
|
||||
}
|
||||
|
||||
tip = vtoy_json_get_string_ex(json->pstChild, "color");
|
||||
if (tip)
|
||||
{
|
||||
grub_env_set("VTOY_TIP_COLOR", tip);
|
||||
}
|
||||
|
||||
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");
|
||||
if (tip)
|
||||
{
|
||||
grub_snprintf(node->tip1, 1000, "%s", tip);
|
||||
}
|
||||
else
|
||||
{
|
||||
tip = vtoy_json_get_string_ex(pNode->pstChild, "tip1");
|
||||
if (tip)
|
||||
grub_snprintf(node->tip1, 1000, "%s", tip);
|
||||
|
||||
tip = vtoy_json_get_string_ex(pNode->pstChild, "tip2");
|
||||
if (tip)
|
||||
grub_snprintf(node->tip2, 1000, "%s", tip);
|
||||
}
|
||||
|
||||
if (g_menu_tip_head)
|
||||
{
|
||||
node->next = g_menu_tip_head;
|
||||
}
|
||||
|
||||
g_menu_tip_head = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_injection_check(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
@@ -1776,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;
|
||||
@@ -1813,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);
|
||||
@@ -1835,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;
|
||||
@@ -1904,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);
|
||||
}
|
||||
@@ -1912,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");
|
||||
}
|
||||
}
|
||||
@@ -2096,44 +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_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;
|
||||
@@ -2142,13 +2444,20 @@ 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;
|
||||
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
|
||||
grub_env_set("VTOY_TIP_LEFT", "10%");
|
||||
grub_env_set("VTOY_TIP_TOP", "80%+5");
|
||||
grub_env_set("VTOY_TIP_COLOR", "blue");
|
||||
grub_env_set("VTOY_TIP_ALIGN", "left");
|
||||
|
||||
file = ventoy_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "%s/ventoy/ventoy.json", args[0]);
|
||||
if (!file)
|
||||
{
|
||||
@@ -2174,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");
|
||||
|
||||
grub_env_set("VTOY_PLUGIN_ENCODE_ERROR", "1");
|
||||
grub_env_export("VTOY_PLUGIN_ENCODE_ERROR");
|
||||
|
||||
ret = vtoy_json_parse(json, buf);
|
||||
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");
|
||||
@@ -2205,6 +2530,15 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a
|
||||
}
|
||||
}
|
||||
|
||||
if (g_menu_tip_head)
|
||||
{
|
||||
grub_env_set("VTOY_MENU_TIP_ENABLE", "1");
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_env_unset("VTOY_MENU_TIP_ENABLE");
|
||||
}
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
@@ -2350,6 +2684,8 @@ persistence_config * ventoy_plugin_find_persistent(const char *isopath)
|
||||
int ventoy_plugin_get_persistent_chunklist(const char *isopath, int index, ventoy_img_chunk_list *chunk_list)
|
||||
{
|
||||
int rc = 1;
|
||||
int len = 0;
|
||||
char *path = NULL;
|
||||
grub_uint64_t start = 0;
|
||||
grub_file_t file = NULL;
|
||||
persistence_config *node = NULL;
|
||||
@@ -2370,10 +2706,22 @@ int ventoy_plugin_get_persistent_chunklist(const char *isopath, int index, vento
|
||||
return 1;
|
||||
}
|
||||
|
||||
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", g_iso_disk_name, node->backendpath[index].path);
|
||||
path = node->backendpath[index].path;
|
||||
|
||||
if (node->backendpath[index].vlnk_add == 0)
|
||||
{
|
||||
len = grub_strlen(path);
|
||||
if (len > 9 && grub_strncmp(path + len - 9, ".vlnk.dat", 9) == 0)
|
||||
{
|
||||
ventoy_add_vlnk_file(NULL, path);
|
||||
node->backendpath[index].vlnk_add = 1;
|
||||
}
|
||||
}
|
||||
|
||||
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", g_iso_disk_name, path);
|
||||
if (!file)
|
||||
{
|
||||
debug("Failed to open file %s%s\n", g_iso_disk_name, node->backendpath[index].path);
|
||||
debug("Failed to open file %s%s\n", g_iso_disk_name, path);
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -2465,6 +2813,29 @@ const char * ventoy_plugin_get_menu_alias(int type, const char *isopath)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const menu_tip * ventoy_plugin_get_menu_tip(int type, const char *isopath)
|
||||
{
|
||||
int len;
|
||||
menu_tip *node = NULL;
|
||||
|
||||
if (!g_menu_tip_head)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = (int)grub_strlen(isopath);
|
||||
for (node = g_menu_tip_head; node; node = node->next)
|
||||
{
|
||||
if (node->type == type && node->pathlen &&
|
||||
node->pathlen == len && ventoy_strcmp(node->isopath, isopath) == 0)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char * ventoy_plugin_get_menu_class(int type, const char *name, const char *path)
|
||||
{
|
||||
int namelen;
|
||||
@@ -2891,7 +3262,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;
|
||||
}
|
||||
@@ -2899,8 +3270,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++)
|
||||
@@ -2923,6 +3305,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;
|
||||
@@ -2948,6 +3389,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);
|
||||
|
||||
@@ -2978,7 +3430,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,12 @@ 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_unix_vlnk_boot = 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;
|
||||
|
||||
@@ -83,6 +89,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 +136,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 +192,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 +206,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,19 +263,25 @@ 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);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int ventoy_freebsd_append_conf(char *buf, const char *isopath)
|
||||
static int ventoy_freebsd_append_conf(char *buf, const char *isopath, const char *alias)
|
||||
{
|
||||
int pos = 0;
|
||||
grub_uint32_t i;
|
||||
grub_disk_t disk;
|
||||
grub_file_t isofile;
|
||||
char uuid[64] = {0};
|
||||
const char *val = NULL;
|
||||
ventoy_img_chunk *chunk;
|
||||
grub_uint8_t disk_sig[4];
|
||||
grub_uint8_t disk_guid[16];
|
||||
@@ -210,6 +297,30 @@ 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 (alias)
|
||||
{
|
||||
vtoy_ssprintf(buf, pos, "hint.ventoy.0.alias=\"%s\"\n", alias);
|
||||
}
|
||||
|
||||
if (g_unix_vlnk_boot)
|
||||
{
|
||||
vtoy_ssprintf(buf, pos, "hint.ventoy.0.vlnk=%d\n", 1);
|
||||
}
|
||||
|
||||
val = ventoy_get_env("VTOY_UNIX_REMOUNT");
|
||||
if (val && val[0] == '1' && val[1] == 0)
|
||||
{
|
||||
vtoy_ssprintf(buf, pos, "hint.ventoy.0.remount=%d\n", 1);
|
||||
}
|
||||
|
||||
if (g_mod_search_magic)
|
||||
{
|
||||
debug("hint.ventoy NO need\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
debug("Fill hint.ventoy info\n");
|
||||
|
||||
disk = isofile->device->disk;
|
||||
|
||||
ventoy_get_disk_guid(isofile->name, disk_guid, disk_sig);
|
||||
@@ -232,8 +343,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 +369,38 @@ grub_err_t ventoy_cmd_unix_reset(grub_extcmd_context_t ctxt, int argc, char **ar
|
||||
(void)argc;
|
||||
(void)args;
|
||||
|
||||
g_unix_vlnk_boot = 0;
|
||||
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);
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_unix_check_vlnk(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
grub_file_t file;
|
||||
|
||||
(void)ctxt;
|
||||
|
||||
if (argc != 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
file = grub_file_open(args[0], VENTOY_FILE_TYPE);
|
||||
if (file)
|
||||
{
|
||||
g_unix_vlnk_boot = file->vlnk;
|
||||
grub_file_close(file);
|
||||
}
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
@@ -553,6 +689,109 @@ out:
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_unix_replace_grub_conf(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int len = 0;
|
||||
grub_uint32_t i;
|
||||
char *data;
|
||||
char *pos;
|
||||
const char *val = NULL;
|
||||
grub_uint64_t offset;
|
||||
grub_file_t file;
|
||||
char extcfg[512];
|
||||
const char *confile = NULL;
|
||||
const char * loader_conf[] =
|
||||
{
|
||||
"/boot/grub/grub.cfg",
|
||||
};
|
||||
|
||||
(void)ctxt;
|
||||
|
||||
if (argc != 1 && argc != 2)
|
||||
{
|
||||
debug("Replace conf invalid argc %d\n", argc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(loader_conf) / sizeof(loader_conf[0]); i++)
|
||||
{
|
||||
if (ventoy_get_file_override(loader_conf[i], &offset) == 0)
|
||||
{
|
||||
confile = loader_conf[i];
|
||||
g_conf_override_offset = offset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (confile == NULL)
|
||||
{
|
||||
debug("Can't find grub.cfg file from %u locations\n", i);
|
||||
return 1;
|
||||
}
|
||||
|
||||
file = ventoy_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "(loop)/%s", confile);
|
||||
if (!file)
|
||||
{
|
||||
debug("Failed to open %s \n", confile);
|
||||
return 1;
|
||||
}
|
||||
|
||||
debug("old grub2 conf file size:%d\n", (int)file->size);
|
||||
|
||||
data = grub_malloc(VTOY_MAX_SCRIPT_BUF);
|
||||
if (!data)
|
||||
{
|
||||
grub_file_close(file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
grub_file_read(file, data, file->size);
|
||||
grub_file_close(file);
|
||||
|
||||
g_conf_new_data = data;
|
||||
g_conf_new_len = (int)file->size;
|
||||
|
||||
pos = grub_strstr(data, "kfreebsd /boot/kernel/kernel");
|
||||
if (pos)
|
||||
{
|
||||
pos += grub_strlen("kfreebsd /boot/kernel/kernel");
|
||||
if (grub_strncmp(pos, ".gz", 3) == 0)
|
||||
{
|
||||
pos += 3;
|
||||
}
|
||||
|
||||
if (argc == 2)
|
||||
{
|
||||
vtoy_ssprintf(extcfg, len, ";kfreebsd_module_elf %s; set kFreeBSD.hint.ventoy.0.alias=\"%s\"", args[0], args[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
vtoy_ssprintf(extcfg, len, ";kfreebsd_module_elf %s", args[0]);
|
||||
}
|
||||
|
||||
if (g_unix_vlnk_boot)
|
||||
{
|
||||
vtoy_ssprintf(extcfg, len, ";set kFreeBSD.hint.ventoy.0.vlnk=%d", 1);
|
||||
}
|
||||
|
||||
val = ventoy_get_env("VTOY_UNIX_REMOUNT");
|
||||
if (val && val[0] == '1' && val[1] == 0)
|
||||
{
|
||||
vtoy_ssprintf(extcfg, len, ";set kFreeBSD.hint.ventoy.0.remount=%d", 1);
|
||||
}
|
||||
|
||||
grub_memmove(pos + len, pos, (int)(file->size - (pos - data)));
|
||||
grub_memcpy(pos, extcfg, len);
|
||||
g_conf_new_len += len;
|
||||
}
|
||||
else
|
||||
{
|
||||
debug("no kfreebsd found\n");
|
||||
}
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
grub_uint32_t i;
|
||||
@@ -568,7 +807,7 @@ grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, ch
|
||||
|
||||
(void)ctxt;
|
||||
|
||||
if (argc != 2)
|
||||
if (argc != 2 && argc != 3)
|
||||
{
|
||||
debug("Replace conf invalid argc %d\n", argc);
|
||||
return 1;
|
||||
@@ -597,7 +836,7 @@ grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, ch
|
||||
return 1;
|
||||
}
|
||||
|
||||
debug("old conf file size:%d\n", (int)file->size);
|
||||
debug("old conf file <%s> size:%d\n", confile, (int)file->size);
|
||||
|
||||
data = grub_malloc(VTOY_MAX_SCRIPT_BUF);
|
||||
if (!data)
|
||||
@@ -614,7 +853,7 @@ grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, ch
|
||||
|
||||
if (grub_strcmp(args[0], "FreeBSD") == 0)
|
||||
{
|
||||
g_conf_new_len += ventoy_freebsd_append_conf(data + file->size, args[1]);
|
||||
g_conf_new_len += ventoy_freebsd_append_conf(data + file->size, args[1], (argc > 2) ? args[2] : NULL);
|
||||
}
|
||||
else if (grub_strcmp(args[0], "DragonFly") == 0)
|
||||
{
|
||||
@@ -624,6 +863,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 += 4096)
|
||||
{
|
||||
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 >> 12));
|
||||
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;
|
||||
@@ -674,6 +934,69 @@ 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);
|
||||
}
|
||||
|
||||
@@ -908,7 +1231,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;
|
||||
|
@@ -667,6 +667,11 @@ grub_err_t ventoy_cmd_raw_chain_data(grub_extcmd_context_t ctxt, int argc, char
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (grub_strncmp(args[0], g_iso_path, grub_strlen(g_iso_path)))
|
||||
{
|
||||
file->vlnk = 1;
|
||||
}
|
||||
|
||||
img_chunk_size = g_img_chunk_list.cur_chunk * sizeof(ventoy_img_chunk);
|
||||
|
||||
size = sizeof(ventoy_chain_head) + img_chunk_size;
|
||||
|
@@ -375,6 +375,7 @@ grub_err_t ventoy_cmd_sel_wimboot(grub_extcmd_context_t ctxt, int argc, char **a
|
||||
|
||||
g_ventoy_menu_esc = 1;
|
||||
g_ventoy_suppress_esc = 1;
|
||||
g_ventoy_suppress_esc_default = 1;
|
||||
|
||||
grub_snprintf(configfile, sizeof(configfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)buf, size);
|
||||
grub_script_execute_sourcecode(configfile);
|
||||
@@ -658,28 +659,6 @@ static wim_directory_entry * search_full_wim_dirent
|
||||
return search;
|
||||
}
|
||||
|
||||
static wim_directory_entry * search_replace_wim_dirent(void *meta_data, wim_directory_entry *dir)
|
||||
{
|
||||
wim_directory_entry *wim_dirent = NULL;
|
||||
const char *pecmd_path[] = { "Windows", "System32", "pecmd.exe", NULL };
|
||||
const char *winpeshl_path[] = { "Windows", "System32", "winpeshl.exe", NULL };
|
||||
|
||||
wim_dirent = search_full_wim_dirent(meta_data, dir, pecmd_path);
|
||||
debug("search pecmd.exe %p\n", wim_dirent);
|
||||
if (wim_dirent)
|
||||
{
|
||||
return wim_dirent;
|
||||
}
|
||||
|
||||
wim_dirent = search_full_wim_dirent(meta_data, dir, winpeshl_path);
|
||||
debug("search winpeshl.exe %p\n", wim_dirent);
|
||||
if (wim_dirent)
|
||||
{
|
||||
return wim_dirent;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static wim_lookup_entry * ventoy_find_look_entry(wim_header *header, wim_lookup_entry *lookup, wim_hash *hash)
|
||||
@@ -697,6 +676,245 @@ static wim_lookup_entry * ventoy_find_look_entry(wim_header *header, wim_lookup_
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int parse_registry_setup_cmdline
|
||||
(
|
||||
grub_file_t file,
|
||||
wim_header *head,
|
||||
wim_lookup_entry *lookup,
|
||||
void *meta_data,
|
||||
wim_directory_entry *dir,
|
||||
char *buf,
|
||||
grub_uint32_t buflen
|
||||
)
|
||||
{
|
||||
char c;
|
||||
int ret = 0;
|
||||
grub_uint32_t i = 0;
|
||||
grub_uint32_t reglen = 0;
|
||||
wim_hash zerohash;
|
||||
reg_vk *regvk = NULL;
|
||||
wim_lookup_entry *look = NULL;
|
||||
wim_directory_entry *wim_dirent = NULL;
|
||||
char *decompress_data = NULL;
|
||||
const char *reg_path[] = { "Windows", "System32", "config", "SYSTEM", NULL };
|
||||
|
||||
wim_dirent = search_full_wim_dirent(meta_data, dir, reg_path);
|
||||
debug("search reg SYSTEM %p\n", wim_dirent);
|
||||
if (!wim_dirent)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
grub_memset(&zerohash, 0, sizeof(zerohash));
|
||||
if (grub_memcmp(&zerohash, wim_dirent->hash.sha1, sizeof(wim_hash)) == 0)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
look = ventoy_find_look_entry(head, lookup, &wim_dirent->hash);
|
||||
if (!look)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
reglen = (grub_uint32_t)look->resource.raw_size;
|
||||
debug("find system lookup entry_id:%ld raw_size:%u\n",
|
||||
((long)look - (long)lookup) / sizeof(wim_lookup_entry), reglen);
|
||||
|
||||
if (0 != ventoy_read_resource(file, head, &(look->resource), (void **)&(decompress_data)))
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
if (grub_strncmp(decompress_data + 0x1000, "hbin", 4))
|
||||
{
|
||||
ret_goto_end(5);
|
||||
}
|
||||
|
||||
for (i = 0x1000; i + sizeof(reg_vk) < reglen; i += 8)
|
||||
{
|
||||
regvk = (reg_vk *)(decompress_data + i);
|
||||
if (regvk->sig == 0x6B76 && regvk->namesize == 7 &&
|
||||
regvk->datatype == 1 && regvk->flag == 1)
|
||||
{
|
||||
if (grub_strncasecmp((char *)(regvk + 1), "cmdline", 7) == 0)
|
||||
{
|
||||
debug("find registry cmdline i:%u offset:(0x%x)%u size:(0x%x)%u\n",
|
||||
i, regvk->dataoffset, regvk->dataoffset, regvk->datasize, regvk->datasize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (i + sizeof(reg_vk) >= reglen || regvk == NULL)
|
||||
{
|
||||
ret_goto_end(6);
|
||||
}
|
||||
|
||||
if (regvk->datasize == 0 || (regvk->datasize & 0x80000000) > 0 ||
|
||||
regvk->dataoffset == 0 || regvk->dataoffset == 0xFFFFFFFF)
|
||||
{
|
||||
ret_goto_end(7);
|
||||
}
|
||||
|
||||
if (regvk->datasize / 2 >= buflen)
|
||||
{
|
||||
ret_goto_end(8);
|
||||
}
|
||||
|
||||
debug("start offset is 0x%x(%u)\n", 0x1000 + regvk->dataoffset + 4, 0x1000 + regvk->dataoffset + 4);
|
||||
|
||||
for (i = 0; i < regvk->datasize; i+=2)
|
||||
{
|
||||
c = (char)(*(grub_uint16_t *)(decompress_data + 0x1000 + regvk->dataoffset + 4 + i));
|
||||
*buf++ = c;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
end:
|
||||
grub_check_free(decompress_data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int parse_custom_setup_path(char *cmdline, const char **path, char *exefile)
|
||||
{
|
||||
int i = 0;
|
||||
int len = 0;
|
||||
char *pos1 = NULL;
|
||||
char *pos2 = NULL;
|
||||
|
||||
if ((cmdline[0] == 'x' || cmdline[0] == 'X') && cmdline[1] == ':')
|
||||
{
|
||||
pos1 = pos2 = cmdline + 3;
|
||||
|
||||
while (i < VTOY_MAX_DIR_DEPTH && *pos2)
|
||||
{
|
||||
while (*pos2 && *pos2 != '\\' && *pos2 != '/')
|
||||
{
|
||||
pos2++;
|
||||
}
|
||||
|
||||
path[i++] = pos1;
|
||||
|
||||
if (*pos2 == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
*pos2 = 0;
|
||||
pos1 = pos2 + 1;
|
||||
pos2 = pos1;
|
||||
}
|
||||
|
||||
if (i == 0 || i >= VTOY_MAX_DIR_DEPTH)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
path[i++] = "Windows";
|
||||
path[i++] = "System32";
|
||||
path[i++] = cmdline;
|
||||
}
|
||||
|
||||
pos1 = (char *)path[i - 1];
|
||||
while (*pos1 != ' ' && *pos1 != '\t' && *pos1)
|
||||
{
|
||||
pos1++;
|
||||
}
|
||||
*pos1 = 0;
|
||||
|
||||
len = (int)grub_strlen(path[i - 1]);
|
||||
if (len < 4 || grub_strcasecmp(path[i - 1] + len - 4, ".exe") != 0)
|
||||
{
|
||||
grub_snprintf(exefile, 256, "%s.exe", path[i - 1]);
|
||||
path[i - 1] = exefile;
|
||||
}
|
||||
|
||||
|
||||
debug("custom setup: %d <%s>\n", i, path[i - 1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static wim_directory_entry * search_replace_wim_dirent
|
||||
(
|
||||
grub_file_t file,
|
||||
wim_header *head,
|
||||
wim_lookup_entry *lookup,
|
||||
void *meta_data,
|
||||
wim_directory_entry *dir
|
||||
)
|
||||
{
|
||||
int ret;
|
||||
char exefile[256] = {0};
|
||||
char cmdline[256] = {0};
|
||||
wim_directory_entry *wim_dirent = NULL;
|
||||
wim_directory_entry *pecmd_dirent = NULL;
|
||||
const char *peset_path[] = { "Windows", "System32", "peset.exe", NULL };
|
||||
const char *pecmd_path[] = { "Windows", "System32", "pecmd.exe", NULL };
|
||||
const char *winpeshl_path[] = { "Windows", "System32", "winpeshl.exe", NULL };
|
||||
const char *custom_path[VTOY_MAX_DIR_DEPTH + 1] = { NULL };
|
||||
|
||||
pecmd_dirent = search_full_wim_dirent(meta_data, dir, pecmd_path);
|
||||
debug("search pecmd.exe %p\n", pecmd_dirent);
|
||||
|
||||
if (pecmd_dirent)
|
||||
{
|
||||
ret = parse_registry_setup_cmdline(file, head, lookup, meta_data, dir, cmdline, sizeof(cmdline) - 1);
|
||||
if (0 == ret)
|
||||
{
|
||||
debug("registry setup cmdline:<%s>\n", cmdline);
|
||||
|
||||
if (grub_strncasecmp(cmdline, "PECMD", 5) == 0)
|
||||
{
|
||||
wim_dirent = pecmd_dirent;
|
||||
}
|
||||
else if (grub_strncasecmp(cmdline, "PESET", 5) == 0)
|
||||
{
|
||||
wim_dirent = search_full_wim_dirent(meta_data, dir, peset_path);
|
||||
debug("search peset.exe %p\n", wim_dirent);
|
||||
}
|
||||
else if (grub_strncasecmp(cmdline, "WINPESHL", 8) == 0)
|
||||
{
|
||||
wim_dirent = search_full_wim_dirent(meta_data, dir, winpeshl_path);
|
||||
debug("search winpeshl.exe %p\n", wim_dirent);
|
||||
}
|
||||
else if (0 == parse_custom_setup_path(cmdline, custom_path, exefile))
|
||||
{
|
||||
wim_dirent = search_full_wim_dirent(meta_data, dir, custom_path);
|
||||
debug("search custom path %p\n", wim_dirent);
|
||||
}
|
||||
|
||||
if (wim_dirent)
|
||||
{
|
||||
return wim_dirent;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
debug("registry setup cmdline failed : %d\n", ret);
|
||||
}
|
||||
}
|
||||
|
||||
wim_dirent = pecmd_dirent;
|
||||
if (wim_dirent)
|
||||
{
|
||||
return wim_dirent;
|
||||
}
|
||||
|
||||
wim_dirent = search_full_wim_dirent(meta_data, dir, winpeshl_path);
|
||||
debug("search winpeshl.exe %p\n", wim_dirent);
|
||||
if (wim_dirent)
|
||||
{
|
||||
return wim_dirent;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static wim_lookup_entry * ventoy_find_meta_entry(wim_header *header, wim_lookup_entry *lookup)
|
||||
{
|
||||
grub_uint32_t i = 0;
|
||||
@@ -832,6 +1050,7 @@ int ventoy_fill_windows_rtdata(void *buf, char *isopath)
|
||||
{
|
||||
char *pos = NULL;
|
||||
char *script = NULL;
|
||||
const char *env = NULL;
|
||||
ventoy_windows_data *data = (ventoy_windows_data *)buf;
|
||||
|
||||
grub_memset(data, 0, sizeof(ventoy_windows_data));
|
||||
@@ -871,6 +1090,12 @@ int ventoy_fill_windows_rtdata(void *buf, char *isopath)
|
||||
debug("injection archive not configed %s\n", pos);
|
||||
}
|
||||
|
||||
env = grub_env_get("VTOY_WIN11_BYPASS_CHECK");
|
||||
if (env && env[0] == '1' && env[1] == 0)
|
||||
{
|
||||
data->windows11_bypass_check = 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1008,8 +1233,16 @@ static int ventoy_wimdows_locate_wim(const char *disk, wim_patch *patch)
|
||||
rootdir = (wim_directory_entry *)(decompress_data + 8);
|
||||
}
|
||||
|
||||
|
||||
debug("read lookup offset:%llu size:%llu\n", (ulonglong)head->lookup.offset, (ulonglong)head->lookup.raw_size);
|
||||
lookup = grub_malloc(head->lookup.raw_size);
|
||||
grub_file_seek(file, head->lookup.offset);
|
||||
grub_file_read(file, lookup, head->lookup.raw_size);
|
||||
|
||||
|
||||
|
||||
/* search winpeshl.exe dirent entry */
|
||||
search = search_replace_wim_dirent(decompress_data, rootdir);
|
||||
search = search_replace_wim_dirent(file, head, lookup, decompress_data, rootdir);
|
||||
if (!search)
|
||||
{
|
||||
debug("Failed to find replace file %p\n", search);
|
||||
@@ -1041,10 +1274,6 @@ static int ventoy_wimdows_locate_wim(const char *disk, wim_patch *patch)
|
||||
grub_memcpy(&patch->old_hash, search->hash.sha1, sizeof(wim_hash));
|
||||
}
|
||||
|
||||
debug("read lookup offset:%llu size:%llu\n", (ulonglong)head->lookup.offset, (ulonglong)head->lookup.raw_size);
|
||||
lookup = grub_malloc(head->lookup.raw_size);
|
||||
grub_file_seek(file, head->lookup.offset);
|
||||
grub_file_read(file, lookup, head->lookup.raw_size);
|
||||
|
||||
/* find and extact winpeshl.exe */
|
||||
patch->replace_look = ventoy_find_look_entry(head, lookup, &patch->old_hash);
|
||||
@@ -1765,21 +1994,12 @@ static grub_uint32_t ventoy_get_wim_iso_offset(const char *filepath)
|
||||
return imgoffset;
|
||||
}
|
||||
|
||||
static int ventoy_get_wim_chunklist(const char *filename, ventoy_img_chunk_list *wimchunk, grub_uint64_t *wimsize)
|
||||
static int ventoy_get_wim_chunklist(grub_file_t wimfile, ventoy_img_chunk_list *wimchunk)
|
||||
{
|
||||
grub_file_t wimfile;
|
||||
|
||||
wimfile = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", filename);
|
||||
if (!wimfile)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
grub_memset(wimchunk, 0, sizeof(ventoy_img_chunk_list));
|
||||
wimchunk->chunk = grub_malloc(sizeof(ventoy_img_chunk) * DEFAULT_CHUNK_NUM);
|
||||
if (NULL == wimchunk->chunk)
|
||||
{
|
||||
grub_file_close(wimfile);
|
||||
return grub_error(GRUB_ERR_OUT_OF_MEMORY, "Can't allocate image chunk memoty\n");
|
||||
}
|
||||
|
||||
@@ -1788,9 +2008,6 @@ static int ventoy_get_wim_chunklist(const char *filename, ventoy_img_chunk_list
|
||||
|
||||
ventoy_get_block_list(wimfile, wimchunk, wimfile->device->disk->partition->start);
|
||||
|
||||
*wimsize = wimfile->size;
|
||||
grub_file_close(wimfile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1829,7 +2046,7 @@ grub_err_t ventoy_cmd_wim_check_bootable(grub_extcmd_context_t ctxt, int argc, c
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
static grub_err_t ventoy_vlnk_wim_chain_data(grub_file_t wimfile)
|
||||
{
|
||||
grub_uint32_t i = 0;
|
||||
grub_uint32_t imgoffset = 0;
|
||||
@@ -1850,10 +2067,7 @@ grub_err_t ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char
|
||||
ventoy_img_chunk_list wimchunk;
|
||||
char envbuf[128];
|
||||
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
|
||||
debug("wim chain data begin <%s> ...\n", args[0]);
|
||||
debug("vlnk wim chain data begin <%s> ...\n", wimfile->name);
|
||||
|
||||
if (NULL == g_wimiso_chunk_list.chunk || NULL == g_wimiso_path)
|
||||
{
|
||||
@@ -1868,11 +2082,177 @@ grub_err_t ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (0 != ventoy_get_wim_chunklist(args[0], &wimchunk, &wimsize))
|
||||
if (0 != ventoy_get_wim_chunklist(wimfile, &wimchunk))
|
||||
{
|
||||
grub_printf("Failed to get wim chunklist\n");
|
||||
return 1;
|
||||
}
|
||||
wimsize = wimfile->size;
|
||||
|
||||
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", g_wimiso_path);
|
||||
if (!file)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
boot_catlog = ventoy_get_iso_boot_catlog(file);
|
||||
|
||||
img_chunk1_size = g_wimiso_chunk_list.cur_chunk * sizeof(ventoy_img_chunk);
|
||||
img_chunk2_size = wimchunk.cur_chunk * sizeof(ventoy_img_chunk);
|
||||
override_size = sizeof(ventoy_override_chunk) + g_wimiso_size;
|
||||
|
||||
size = sizeof(ventoy_chain_head) + img_chunk1_size + img_chunk2_size + override_size;
|
||||
|
||||
pLastChain = grub_env_get("vtoy_chain_mem_addr");
|
||||
if (pLastChain)
|
||||
{
|
||||
chain = (ventoy_chain_head *)grub_strtoul(pLastChain, NULL, 16);
|
||||
if (chain)
|
||||
{
|
||||
debug("free last chain memory %p\n", chain);
|
||||
grub_free(chain);
|
||||
}
|
||||
}
|
||||
|
||||
chain = grub_malloc(size);
|
||||
if (!chain)
|
||||
{
|
||||
grub_printf("Failed to alloc chain memory size %u\n", size);
|
||||
grub_file_close(file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
grub_snprintf(envbuf, sizeof(envbuf), "0x%lx", (unsigned long)chain);
|
||||
grub_env_set("vtoy_chain_mem_addr", envbuf);
|
||||
grub_snprintf(envbuf, sizeof(envbuf), "%u", size);
|
||||
grub_env_set("vtoy_chain_mem_size", envbuf);
|
||||
|
||||
grub_memset(chain, 0, sizeof(ventoy_chain_head));
|
||||
|
||||
/* part 1: os parameter */
|
||||
g_ventoy_chain_type = ventoy_chain_wim;
|
||||
ventoy_fill_os_param(wimfile, &(chain->os_param));
|
||||
|
||||
/* part 2: chain head */
|
||||
disk = wimfile->device->disk;
|
||||
chain->disk_drive = disk->id;
|
||||
chain->disk_sector_size = (1 << disk->log_sector_size);
|
||||
chain->real_img_size_in_bytes = ventoy_align_2k(file->size) + ventoy_align_2k(wimsize);
|
||||
chain->virt_img_size_in_bytes = chain->real_img_size_in_bytes;
|
||||
chain->boot_catalog = boot_catlog;
|
||||
|
||||
if (!ventoy_is_efi_os())
|
||||
{
|
||||
grub_file_seek(file, boot_catlog * 2048);
|
||||
grub_file_read(file, chain->boot_catalog_sector, sizeof(chain->boot_catalog_sector));
|
||||
}
|
||||
|
||||
/* part 3: image chunk */
|
||||
chain->img_chunk_offset = sizeof(ventoy_chain_head);
|
||||
chain->img_chunk_num = g_wimiso_chunk_list.cur_chunk + wimchunk.cur_chunk;
|
||||
grub_memcpy((char *)chain + chain->img_chunk_offset, g_wimiso_chunk_list.chunk, img_chunk1_size);
|
||||
|
||||
chunknode = (ventoy_img_chunk *)((char *)chain + chain->img_chunk_offset);
|
||||
for (i = 0; i < g_wimiso_chunk_list.cur_chunk; i++)
|
||||
{
|
||||
chunknode->disk_end_sector = chunknode->disk_end_sector - chunknode->disk_start_sector;
|
||||
chunknode->disk_start_sector = 0;
|
||||
chunknode++;
|
||||
}
|
||||
|
||||
/* fs cluster size >= 2048, so don't need to proc align */
|
||||
|
||||
/* align by 2048 */
|
||||
chunknode = wimchunk.chunk + wimchunk.cur_chunk - 1;
|
||||
i = (chunknode->disk_end_sector + 1 - chunknode->disk_start_sector) % 4;
|
||||
if (i)
|
||||
{
|
||||
chunknode->disk_end_sector += 4 - i;
|
||||
}
|
||||
|
||||
isosector = (grub_uint32_t)((file->size + 2047) / 2048);
|
||||
for (i = 0; i < wimchunk.cur_chunk; i++)
|
||||
{
|
||||
chunknode = wimchunk.chunk + i;
|
||||
chunknode->img_start_sector = isosector;
|
||||
chunknode->img_end_sector = chunknode->img_start_sector +
|
||||
((chunknode->disk_end_sector + 1 - chunknode->disk_start_sector) / 4) - 1;
|
||||
isosector = chunknode->img_end_sector + 1;
|
||||
}
|
||||
|
||||
grub_memcpy((char *)chain + chain->img_chunk_offset + img_chunk1_size, wimchunk.chunk, img_chunk2_size);
|
||||
|
||||
/* part 4: override chunk */
|
||||
chain->override_chunk_offset = chain->img_chunk_offset + img_chunk1_size + img_chunk2_size;
|
||||
chain->override_chunk_num = 1;
|
||||
|
||||
override = (ventoy_override_chunk *)((char *)chain + chain->override_chunk_offset);
|
||||
override->img_offset = 0;
|
||||
override->override_size = g_wimiso_size;
|
||||
|
||||
grub_file_seek(file, 0);
|
||||
grub_file_read(file, override->override_data, file->size);
|
||||
|
||||
dirent = (ventoy_iso9660_override *)(override->override_data + imgoffset);
|
||||
dirent->first_sector = (grub_uint32_t)((file->size + 2047) / 2048);
|
||||
dirent->size = (grub_uint32_t)(wimsize);
|
||||
dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector);
|
||||
dirent->size_be = grub_swap_bytes32(dirent->size);
|
||||
|
||||
debug("imgoffset=%u first_sector=0x%x size=0x%x\n", imgoffset, dirent->first_sector, dirent->size);
|
||||
|
||||
if (ventoy_is_efi_os() == 0)
|
||||
{
|
||||
ventoy_windows_drive_map(chain);
|
||||
}
|
||||
|
||||
grub_file_close(file);
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
static grub_err_t ventoy_normal_wim_chain_data(grub_file_t wimfile)
|
||||
{
|
||||
grub_uint32_t i = 0;
|
||||
grub_uint32_t imgoffset = 0;
|
||||
grub_uint32_t size = 0;
|
||||
grub_uint32_t isosector = 0;
|
||||
grub_uint64_t wimsize = 0;
|
||||
grub_uint32_t boot_catlog = 0;
|
||||
grub_uint32_t img_chunk1_size = 0;
|
||||
grub_uint32_t img_chunk2_size = 0;
|
||||
grub_uint32_t override_size = 0;
|
||||
grub_file_t file;
|
||||
grub_disk_t disk;
|
||||
const char *pLastChain = NULL;
|
||||
ventoy_chain_head *chain;
|
||||
ventoy_iso9660_override *dirent;
|
||||
ventoy_img_chunk *chunknode;
|
||||
ventoy_override_chunk *override;
|
||||
ventoy_img_chunk_list wimchunk;
|
||||
char envbuf[128];
|
||||
|
||||
debug("normal wim chain data begin <%s> ...\n", wimfile->name);
|
||||
|
||||
if (NULL == g_wimiso_chunk_list.chunk || NULL == g_wimiso_path)
|
||||
{
|
||||
grub_printf("ventoy not ready\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
imgoffset = ventoy_get_wim_iso_offset(g_wimiso_path);
|
||||
if (imgoffset == 0)
|
||||
{
|
||||
grub_printf("image offset not found\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (0 != ventoy_get_wim_chunklist(wimfile, &wimchunk))
|
||||
{
|
||||
grub_printf("Failed to get wim chunklist\n");
|
||||
return 1;
|
||||
}
|
||||
wimsize = wimfile->size;
|
||||
|
||||
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", g_wimiso_path);
|
||||
if (!file)
|
||||
@@ -1985,6 +2365,33 @@ grub_err_t ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
grub_err_t ret;
|
||||
grub_file_t wimfile;
|
||||
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
|
||||
wimfile = grub_file_open(args[0], VENTOY_FILE_TYPE);
|
||||
if (!wimfile)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (wimfile->vlnk)
|
||||
{
|
||||
ret = ventoy_vlnk_wim_chain_data(wimfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = ventoy_normal_wim_chain_data(wimfile);
|
||||
}
|
||||
|
||||
grub_file_close(wimfile);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ventoy_chain_file_size(const char *path)
|
||||
{
|
||||
int size;
|
||||
|
329
GRUB2/MOD_SRC/grub-2.04/include/grub/charset.h
Normal file
329
GRUB2/MOD_SRC/grub-2.04/include/grub/charset.h
Normal file
@@ -0,0 +1,329 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_CHARSET_HEADER
|
||||
#define GRUB_CHARSET_HEADER 1
|
||||
|
||||
#include <grub/types.h>
|
||||
|
||||
#define GRUB_UINT8_1_LEADINGBIT 0x80
|
||||
#define GRUB_UINT8_2_LEADINGBITS 0xc0
|
||||
#define GRUB_UINT8_3_LEADINGBITS 0xe0
|
||||
#define GRUB_UINT8_4_LEADINGBITS 0xf0
|
||||
#define GRUB_UINT8_5_LEADINGBITS 0xf8
|
||||
#define GRUB_UINT8_6_LEADINGBITS 0xfc
|
||||
#define GRUB_UINT8_7_LEADINGBITS 0xfe
|
||||
|
||||
#define GRUB_UINT8_1_TRAILINGBIT 0x01
|
||||
#define GRUB_UINT8_2_TRAILINGBITS 0x03
|
||||
#define GRUB_UINT8_3_TRAILINGBITS 0x07
|
||||
#define GRUB_UINT8_4_TRAILINGBITS 0x0f
|
||||
#define GRUB_UINT8_5_TRAILINGBITS 0x1f
|
||||
#define GRUB_UINT8_6_TRAILINGBITS 0x3f
|
||||
|
||||
#define GRUB_MAX_UTF8_PER_UTF16 4
|
||||
/* You need at least one UTF-8 byte to have one UTF-16 word.
|
||||
You need at least three UTF-8 bytes to have 2 UTF-16 words (surrogate pairs).
|
||||
*/
|
||||
#define GRUB_MAX_UTF16_PER_UTF8 1
|
||||
#define GRUB_MAX_UTF8_PER_CODEPOINT 4
|
||||
|
||||
#define GRUB_UCS2_LIMIT 0x10000
|
||||
#define GRUB_UTF16_UPPER_SURROGATE(code) \
|
||||
(0xD800 | ((((code) - GRUB_UCS2_LIMIT) >> 10) & 0x3ff))
|
||||
#define GRUB_UTF16_LOWER_SURROGATE(code) \
|
||||
(0xDC00 | (((code) - GRUB_UCS2_LIMIT) & 0x3ff))
|
||||
|
||||
/* Process one character from UTF8 sequence.
|
||||
At beginning set *code = 0, *count = 0. Returns 0 on failure and
|
||||
1 on success. *count holds the number of trailing bytes. */
|
||||
static inline int
|
||||
grub_utf8_process (grub_uint8_t c, grub_uint32_t *code, int *count)
|
||||
{
|
||||
if (*count)
|
||||
{
|
||||
if ((c & GRUB_UINT8_2_LEADINGBITS) != GRUB_UINT8_1_LEADINGBIT)
|
||||
{
|
||||
*count = 0;
|
||||
/* invalid */
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*code <<= 6;
|
||||
*code |= (c & GRUB_UINT8_6_TRAILINGBITS);
|
||||
(*count)--;
|
||||
/* Overlong. */
|
||||
if ((*count == 1 && *code <= 0x1f)
|
||||
|| (*count == 2 && *code <= 0xf))
|
||||
{
|
||||
*code = 0;
|
||||
*count = 0;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((c & GRUB_UINT8_1_LEADINGBIT) == 0)
|
||||
{
|
||||
*code = c;
|
||||
return 1;
|
||||
}
|
||||
if ((c & GRUB_UINT8_3_LEADINGBITS) == GRUB_UINT8_2_LEADINGBITS)
|
||||
{
|
||||
*count = 1;
|
||||
*code = c & GRUB_UINT8_5_TRAILINGBITS;
|
||||
/* Overlong */
|
||||
if (*code <= 1)
|
||||
{
|
||||
*count = 0;
|
||||
*code = 0;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if ((c & GRUB_UINT8_4_LEADINGBITS) == GRUB_UINT8_3_LEADINGBITS)
|
||||
{
|
||||
*count = 2;
|
||||
*code = c & GRUB_UINT8_4_TRAILINGBITS;
|
||||
return 1;
|
||||
}
|
||||
if ((c & GRUB_UINT8_5_LEADINGBITS) == GRUB_UINT8_4_LEADINGBITS)
|
||||
{
|
||||
*count = 3;
|
||||
*code = c & GRUB_UINT8_3_TRAILINGBITS;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Convert a (possibly null-terminated) UTF-8 string of at most SRCSIZE
|
||||
bytes (if SRCSIZE is -1, it is ignored) in length to a UTF-16 string.
|
||||
Return the number of characters converted. DEST must be able to hold
|
||||
at least DESTSIZE characters. If an invalid sequence is found, return -1.
|
||||
If SRCEND is not NULL, then *SRCEND is set to the next byte after the
|
||||
last byte used in SRC. */
|
||||
static inline grub_size_t
|
||||
grub_utf8_to_utf16 (grub_uint16_t *dest, grub_size_t destsize,
|
||||
const grub_uint8_t *src, grub_size_t srcsize,
|
||||
const grub_uint8_t **srcend)
|
||||
{
|
||||
grub_uint16_t *p = dest;
|
||||
int count = 0;
|
||||
grub_uint32_t code = 0;
|
||||
|
||||
if (srcend)
|
||||
*srcend = src;
|
||||
|
||||
while (srcsize && destsize)
|
||||
{
|
||||
int was_count = count;
|
||||
if (srcsize != (grub_size_t)-1)
|
||||
srcsize--;
|
||||
if (!grub_utf8_process (*src++, &code, &count))
|
||||
{
|
||||
code = '?';
|
||||
count = 0;
|
||||
/* Character c may be valid, don't eat it. */
|
||||
if (was_count)
|
||||
src--;
|
||||
}
|
||||
if (count != 0)
|
||||
continue;
|
||||
if (code == 0)
|
||||
break;
|
||||
if (destsize < 2 && code >= GRUB_UCS2_LIMIT)
|
||||
break;
|
||||
if (code >= GRUB_UCS2_LIMIT)
|
||||
{
|
||||
*p++ = GRUB_UTF16_UPPER_SURROGATE (code);
|
||||
*p++ = GRUB_UTF16_LOWER_SURROGATE (code);
|
||||
destsize -= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
*p++ = code;
|
||||
destsize--;
|
||||
}
|
||||
}
|
||||
|
||||
if (srcend)
|
||||
*srcend = src;
|
||||
return p - dest;
|
||||
}
|
||||
|
||||
/* Determine the last position where the UTF-8 string [beg, end) can
|
||||
be safely cut. */
|
||||
static inline grub_size_t
|
||||
grub_getend (const char *beg, const char *end)
|
||||
{
|
||||
const char *ptr;
|
||||
for (ptr = end - 1; ptr >= beg; ptr--)
|
||||
if ((*ptr & GRUB_UINT8_2_LEADINGBITS) != GRUB_UINT8_1_LEADINGBIT)
|
||||
break;
|
||||
if (ptr < beg)
|
||||
return 0;
|
||||
if ((*ptr & GRUB_UINT8_1_LEADINGBIT) == 0)
|
||||
return ptr + 1 - beg;
|
||||
if ((*ptr & GRUB_UINT8_3_LEADINGBITS) == GRUB_UINT8_2_LEADINGBITS
|
||||
&& ptr + 2 <= end)
|
||||
return ptr + 2 - beg;
|
||||
if ((*ptr & GRUB_UINT8_4_LEADINGBITS) == GRUB_UINT8_3_LEADINGBITS
|
||||
&& ptr + 3 <= end)
|
||||
return ptr + 3 - beg;
|
||||
if ((*ptr & GRUB_UINT8_5_LEADINGBITS) == GRUB_UINT8_4_LEADINGBITS
|
||||
&& ptr + 4 <= end)
|
||||
return ptr + 4 - beg;
|
||||
/* Invalid character or incomplete. Cut before it. */
|
||||
return ptr - beg;
|
||||
}
|
||||
|
||||
/* Convert UTF-16 to UTF-8. */
|
||||
static inline grub_uint8_t *
|
||||
grub_utf16_to_utf8 (grub_uint8_t *dest, const grub_uint16_t *src,
|
||||
grub_size_t size)
|
||||
{
|
||||
grub_uint32_t code_high = 0;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
grub_uint32_t code = *src++;
|
||||
|
||||
if (code_high)
|
||||
{
|
||||
if (code >= 0xDC00 && code <= 0xDFFF)
|
||||
{
|
||||
/* Surrogate pair. */
|
||||
code = ((code_high - 0xD800) << 10) + (code - 0xDC00) + 0x10000;
|
||||
|
||||
*dest++ = (code >> 18) | 0xF0;
|
||||
*dest++ = ((code >> 12) & 0x3F) | 0x80;
|
||||
*dest++ = ((code >> 6) & 0x3F) | 0x80;
|
||||
*dest++ = (code & 0x3F) | 0x80;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Error... */
|
||||
*dest++ = '?';
|
||||
/* *src may be valid. Don't eat it. */
|
||||
src--;
|
||||
}
|
||||
|
||||
code_high = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (code <= 0x007F)
|
||||
*dest++ = code;
|
||||
else if (code <= 0x07FF)
|
||||
{
|
||||
*dest++ = (code >> 6) | 0xC0;
|
||||
*dest++ = (code & 0x3F) | 0x80;
|
||||
}
|
||||
else if (code >= 0xD800 && code <= 0xDBFF)
|
||||
{
|
||||
code_high = code;
|
||||
continue;
|
||||
}
|
||||
else if (code >= 0xDC00 && code <= 0xDFFF)
|
||||
{
|
||||
/* Error... */
|
||||
*dest++ = '?';
|
||||
}
|
||||
else if (code < 0x10000)
|
||||
{
|
||||
*dest++ = (code >> 12) | 0xE0;
|
||||
*dest++ = ((code >> 6) & 0x3F) | 0x80;
|
||||
*dest++ = (code & 0x3F) | 0x80;
|
||||
}
|
||||
else
|
||||
{
|
||||
*dest++ = (code >> 18) | 0xF0;
|
||||
*dest++ = ((code >> 12) & 0x3F) | 0x80;
|
||||
*dest++ = ((code >> 6) & 0x3F) | 0x80;
|
||||
*dest++ = (code & 0x3F) | 0x80;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
#define GRUB_MAX_UTF8_PER_LATIN1 2
|
||||
|
||||
/* Convert Latin1 to UTF-8. */
|
||||
static inline grub_uint8_t *
|
||||
grub_latin1_to_utf8 (grub_uint8_t *dest, const grub_uint8_t *src,
|
||||
grub_size_t size)
|
||||
{
|
||||
while (size--)
|
||||
{
|
||||
if (!(*src & 0x80))
|
||||
*dest++ = *src;
|
||||
else
|
||||
{
|
||||
*dest++ = (*src >> 6) | 0xC0;
|
||||
*dest++ = (*src & 0x3F) | 0x80;
|
||||
}
|
||||
src++;
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/* Convert UCS-4 to UTF-8. */
|
||||
char *grub_ucs4_to_utf8_alloc (const grub_uint32_t *src, grub_size_t size);
|
||||
|
||||
int
|
||||
grub_is_valid_utf8 (const grub_uint8_t *src, grub_size_t srcsize);
|
||||
|
||||
grub_ssize_t grub_utf8_to_ucs4_alloc (const char *msg,
|
||||
grub_uint32_t **unicode_msg,
|
||||
grub_uint32_t **last_position);
|
||||
|
||||
/* Returns the number of bytes the string src would occupy is converted
|
||||
to UTF-8, excluding \0. */
|
||||
grub_size_t
|
||||
grub_get_num_of_utf8_bytes (const grub_uint32_t *src, grub_size_t size);
|
||||
|
||||
/* Converts UCS-4 to UTF-8. Returns the number of bytes effectively written
|
||||
excluding the trailing \0. */
|
||||
grub_size_t
|
||||
grub_ucs4_to_utf8 (const grub_uint32_t *src, grub_size_t size,
|
||||
grub_uint8_t *dest, grub_size_t destsize);
|
||||
grub_size_t grub_utf8_to_ucs4 (grub_uint32_t *dest, grub_size_t destsize,
|
||||
const grub_uint8_t *src, grub_size_t srcsize,
|
||||
const grub_uint8_t **srcend);
|
||||
/* Returns -2 if not enough space, -1 on invalid character. */
|
||||
grub_ssize_t
|
||||
grub_encode_utf8_character (grub_uint8_t *dest, grub_uint8_t *destend,
|
||||
grub_uint32_t code);
|
||||
|
||||
const grub_uint32_t *
|
||||
grub_unicode_get_comb_start (const grub_uint32_t *str,
|
||||
const grub_uint32_t *cur);
|
||||
|
||||
int
|
||||
grub_utf8_get_num_code (const char *src, grub_size_t srcsize);
|
||||
|
||||
const char *
|
||||
grub_utf8_offset_code (const char *src, grub_size_t srcsize, int num);
|
||||
|
||||
#endif
|
@@ -314,6 +314,11 @@
|
||||
{ 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
|
||||
}
|
||||
|
||||
#define GRUB_EFI_SMBIOS3_TABLE_GUID \
|
||||
{ 0xf2fd1544, 0x9794, 0x4a2c, \
|
||||
{ 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94 } \
|
||||
}
|
||||
|
||||
#define GRUB_EFI_SAL_TABLE_GUID \
|
||||
{ 0xeb9d2d32, 0x2d88, 0x11d3, \
|
||||
{ 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
|
||||
|
@@ -132,7 +132,8 @@ enum grub_file_type
|
||||
|
||||
/* --skip-sig is specified. */
|
||||
GRUB_FILE_TYPE_SKIP_SIGNATURE = 0x10000,
|
||||
GRUB_FILE_TYPE_NO_DECOMPRESS = 0x20000
|
||||
GRUB_FILE_TYPE_NO_DECOMPRESS = 0x20000,
|
||||
GRUB_FILE_TYPE_NO_VLNK = 0x40000,
|
||||
};
|
||||
|
||||
/* File description. */
|
||||
@@ -141,6 +142,8 @@ struct grub_file
|
||||
/* File name. */
|
||||
char *name;
|
||||
|
||||
int vlnk;
|
||||
|
||||
/* The underlying device. */
|
||||
grub_device_t device;
|
||||
|
||||
@@ -213,6 +216,11 @@ grub_ssize_t EXPORT_FUNC(grub_file_read) (grub_file_t file, void *buf,
|
||||
grub_off_t EXPORT_FUNC(grub_file_seek) (grub_file_t file, grub_off_t offset);
|
||||
grub_err_t EXPORT_FUNC(grub_file_close) (grub_file_t file);
|
||||
|
||||
int EXPORT_FUNC(grub_file_is_vlnk_suffix)(const char *name, int len);
|
||||
int EXPORT_FUNC(grub_file_add_vlnk)(const char *src, const char *dst);
|
||||
int EXPORT_FUNC(grub_file_vtoy_vlnk)(const char *src, const char *dst);
|
||||
const char * EXPORT_FUNC(grub_file_get_vlnk)(const char *name, int *vlnk);
|
||||
|
||||
/* Return value of grub_file_size() in case file size is unknown. */
|
||||
#define GRUB_FILE_SIZE_UNKNOWN 0xffffffffffffffffULL
|
||||
|
||||
|
@@ -128,5 +128,6 @@ grub_fs_unregister (grub_fs_t fs)
|
||||
#define FOR_FILESYSTEMS(var) FOR_LIST_ELEMENTS((var), (grub_fs_list))
|
||||
|
||||
grub_fs_t EXPORT_FUNC(grub_fs_probe) (grub_device_t device);
|
||||
grub_fs_t EXPORT_FUNC(grub_fs_list_probe) (grub_device_t device, const char **list);
|
||||
|
||||
#endif /* ! GRUB_FS_HEADER */
|
||||
|
128
GRUB2/MOD_SRC/grub-2.04/include/grub/gfxmenu_view.h
Normal file
128
GRUB2/MOD_SRC/grub-2.04/include/grub/gfxmenu_view.h
Normal file
@@ -0,0 +1,128 @@
|
||||
/* gfxmenu_view.h - gfxmenu view interface. */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2008,2009 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_GFXMENU_VIEW_HEADER
|
||||
#define GRUB_GFXMENU_VIEW_HEADER 1
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/menu.h>
|
||||
#include <grub/font.h>
|
||||
#include <grub/gfxwidgets.h>
|
||||
|
||||
struct grub_gfxmenu_view; /* Forward declaration of opaque type. */
|
||||
typedef struct grub_gfxmenu_view *grub_gfxmenu_view_t;
|
||||
|
||||
|
||||
grub_gfxmenu_view_t grub_gfxmenu_view_new (const char *theme_path,
|
||||
int width, int height);
|
||||
|
||||
void grub_gfxmenu_view_destroy (grub_gfxmenu_view_t view);
|
||||
|
||||
/* Set properties on the view based on settings from the specified
|
||||
theme file. */
|
||||
grub_err_t grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view,
|
||||
const char *theme_path);
|
||||
|
||||
grub_err_t grub_gui_recreate_box (grub_gfxmenu_box_t *boxptr,
|
||||
const char *pattern, const char *theme_dir);
|
||||
|
||||
void grub_gfxmenu_view_draw (grub_gfxmenu_view_t view);
|
||||
|
||||
void
|
||||
grub_gfxmenu_redraw_menu (grub_gfxmenu_view_t view);
|
||||
|
||||
void
|
||||
grub_gfxmenu_redraw_timeout (grub_gfxmenu_view_t view);
|
||||
|
||||
void
|
||||
grub_gfxmenu_view_redraw (grub_gfxmenu_view_t view,
|
||||
const grub_video_rect_t *region);
|
||||
|
||||
void
|
||||
grub_gfxmenu_clear_timeout (void *data);
|
||||
void
|
||||
grub_gfxmenu_print_timeout (int timeout, void *data);
|
||||
void
|
||||
grub_gfxmenu_set_chosen_entry (int entry, void *data);
|
||||
void
|
||||
grub_gfxmenu_scroll_chosen_entry (void *data, int diren);
|
||||
|
||||
grub_err_t grub_font_draw_string (const char *str,
|
||||
grub_font_t font,
|
||||
grub_video_color_t color,
|
||||
int left_x, int baseline_y);
|
||||
int grub_font_get_string_width (grub_font_t font,
|
||||
const char *str);
|
||||
|
||||
|
||||
/* Implementation details -- this should not be used outside of the
|
||||
view itself. */
|
||||
|
||||
#include <grub/video.h>
|
||||
#include <grub/bitmap.h>
|
||||
#include <grub/bitmap_scale.h>
|
||||
#include <grub/gui.h>
|
||||
#include <grub/gfxwidgets.h>
|
||||
#include <grub/icon_manager.h>
|
||||
|
||||
/* Definition of the private representation of the view. */
|
||||
struct grub_gfxmenu_view
|
||||
{
|
||||
grub_video_rect_t screen;
|
||||
|
||||
int need_to_check_sanity;
|
||||
grub_video_rect_t terminal_rect;
|
||||
int terminal_border;
|
||||
|
||||
grub_font_t title_font;
|
||||
grub_font_t message_font;
|
||||
char *terminal_font_name;
|
||||
grub_video_rgba_color_t title_color;
|
||||
grub_video_rgba_color_t message_color;
|
||||
grub_video_rgba_color_t message_bg_color;
|
||||
struct grub_video_bitmap *raw_desktop_image;
|
||||
struct grub_video_bitmap *scaled_desktop_image;
|
||||
grub_video_bitmap_selection_method_t desktop_image_scale_method;
|
||||
grub_video_bitmap_h_align_t desktop_image_h_align;
|
||||
grub_video_bitmap_v_align_t desktop_image_v_align;
|
||||
grub_video_rgba_color_t desktop_color;
|
||||
grub_gfxmenu_box_t terminal_box;
|
||||
char *title_text;
|
||||
char *progress_message_text;
|
||||
char *theme_path;
|
||||
|
||||
grub_gui_container_t canvas;
|
||||
|
||||
int double_repaint;
|
||||
|
||||
int selected;
|
||||
|
||||
grub_video_rect_t progress_message_frame;
|
||||
|
||||
grub_menu_t menu;
|
||||
|
||||
int nested;
|
||||
|
||||
int first_timeout;
|
||||
|
||||
int *menu_title_offset;
|
||||
};
|
||||
|
||||
#endif /* ! GRUB_GFXMENU_VIEW_HEADER */
|
49
GRUB2/MOD_SRC/grub-2.04/include/grub/menu_viewer.h
Normal file
49
GRUB2/MOD_SRC/grub-2.04/include/grub/menu_viewer.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/* menu_viewer.h - Interface to menu viewer implementations. */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2009 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_MENU_VIEWER_HEADER
|
||||
#define GRUB_MENU_VIEWER_HEADER 1
|
||||
|
||||
#include <grub/err.h>
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/menu.h>
|
||||
#include <grub/term.h>
|
||||
|
||||
struct grub_menu_viewer
|
||||
{
|
||||
struct grub_menu_viewer *next;
|
||||
void *data;
|
||||
void (*set_chosen_entry) (int entry, void *data);
|
||||
void (*scroll_chosen_entry) (void *data, int diren);
|
||||
void (*print_timeout) (int timeout, void *data);
|
||||
void (*clear_timeout) (void *data);
|
||||
void (*fini) (void *fini);
|
||||
};
|
||||
|
||||
void grub_menu_register_viewer (struct grub_menu_viewer *viewer);
|
||||
|
||||
grub_err_t
|
||||
grub_menu_try_text (struct grub_term_output *term,
|
||||
int entry, grub_menu_t menu, int nested);
|
||||
|
||||
extern grub_err_t (*grub_gfxmenu_try_hook) (int entry, grub_menu_t menu,
|
||||
int nested);
|
||||
|
||||
#endif /* GRUB_MENU_VIEWER_HEADER */
|
141
GRUB2/MOD_SRC/grub-2.04/include/grub/partition.h
Normal file
141
GRUB2/MOD_SRC/grub-2.04/include/grub/partition.h
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2004,2006,2007 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_PART_HEADER
|
||||
#define GRUB_PART_HEADER 1
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/list.h>
|
||||
|
||||
struct grub_disk;
|
||||
|
||||
typedef struct grub_partition *grub_partition_t;
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
typedef enum
|
||||
{
|
||||
GRUB_EMBED_PCBIOS
|
||||
} grub_embed_type_t;
|
||||
#endif
|
||||
|
||||
typedef int (*grub_partition_iterate_hook_t) (struct grub_disk *disk,
|
||||
const grub_partition_t partition,
|
||||
void *data);
|
||||
|
||||
/* Partition map type. */
|
||||
struct grub_partition_map
|
||||
{
|
||||
/* The next partition map type. */
|
||||
struct grub_partition_map *next;
|
||||
struct grub_partition_map **prev;
|
||||
|
||||
/* The name of the partition map type. */
|
||||
const char *name;
|
||||
|
||||
/* Call HOOK with each partition, until HOOK returns non-zero. */
|
||||
grub_err_t (*iterate) (struct grub_disk *disk,
|
||||
grub_partition_iterate_hook_t hook, void *hook_data);
|
||||
#ifdef GRUB_UTIL
|
||||
/* Determine sectors available for embedding. */
|
||||
grub_err_t (*embed) (struct grub_disk *disk, unsigned int *nsectors,
|
||||
unsigned int max_nsectors,
|
||||
grub_embed_type_t embed_type,
|
||||
grub_disk_addr_t **sectors);
|
||||
#endif
|
||||
};
|
||||
typedef struct grub_partition_map *grub_partition_map_t;
|
||||
|
||||
/* Partition description. */
|
||||
struct grub_partition
|
||||
{
|
||||
/* The partition number. */
|
||||
int number;
|
||||
|
||||
/* The start sector (relative to parent). */
|
||||
grub_disk_addr_t start;
|
||||
|
||||
/* The length in sector units. */
|
||||
grub_uint64_t len;
|
||||
|
||||
/* The offset of the partition table. */
|
||||
grub_disk_addr_t offset;
|
||||
|
||||
/* The index of this partition in the partition table. */
|
||||
int index;
|
||||
|
||||
/* Parent partition (physically contains this partition). */
|
||||
struct grub_partition *parent;
|
||||
|
||||
/* The type partition map. */
|
||||
grub_partition_map_t partmap;
|
||||
|
||||
/* The type of partition whne it's on MSDOS.
|
||||
Used for embedding detection. */
|
||||
grub_uint8_t msdostype;
|
||||
|
||||
/* The attrib field for GPT. Needed for priority detection. */
|
||||
grub_uint64_t gpt_attrib;
|
||||
};
|
||||
|
||||
grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk *disk,
|
||||
const char *str);
|
||||
int EXPORT_FUNC(grub_partition_iterate) (struct grub_disk *disk,
|
||||
grub_partition_iterate_hook_t hook,
|
||||
void *hook_data);
|
||||
char *EXPORT_FUNC(grub_partition_get_name) (const grub_partition_t partition);
|
||||
|
||||
|
||||
extern grub_partition_map_t EXPORT_VAR(grub_partition_map_list);
|
||||
|
||||
#ifndef GRUB_LST_GENERATOR
|
||||
static inline void
|
||||
grub_partition_map_register (grub_partition_map_t partmap)
|
||||
{
|
||||
grub_list_push (GRUB_AS_LIST_P (&grub_partition_map_list),
|
||||
GRUB_AS_LIST (partmap));
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void
|
||||
grub_partition_map_unregister (grub_partition_map_t partmap)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST (partmap));
|
||||
}
|
||||
|
||||
#define FOR_PARTITION_MAPS(var) FOR_LIST_ELEMENTS((var), (grub_partition_map_list))
|
||||
|
||||
|
||||
static inline grub_disk_addr_t
|
||||
grub_partition_get_start (const grub_partition_t p)
|
||||
{
|
||||
grub_partition_t part;
|
||||
grub_uint64_t part_start = 0;
|
||||
|
||||
for (part = p; part; part = part->parent)
|
||||
part_start += part->start;
|
||||
|
||||
return part_start;
|
||||
}
|
||||
|
||||
static inline grub_uint64_t
|
||||
grub_partition_get_len (const grub_partition_t p)
|
||||
{
|
||||
return p->len;
|
||||
}
|
||||
|
||||
#endif /* ! GRUB_PART_HEADER */
|
@@ -121,6 +121,9 @@ typedef struct ventoy_os_param
|
||||
* vtoy_reserved[2]: vtoy_chain_type 0:Linux 1:Windows 2:wimfile
|
||||
* vtoy_reserved[3]: vtoy_iso_format 0:iso9660 1:udf
|
||||
* vtoy_reserved[4]: vtoy_windows_cd_prompt
|
||||
* vtoy_reserved[5]: vtoy_linux_remount
|
||||
* vtoy_reserved[6]: vtoy_vlnk
|
||||
* vtoy_reserved[7~10]: vtoy_disk_sig[4] used for vlnk
|
||||
*
|
||||
*/
|
||||
grub_uint8_t vtoy_reserved[32]; // Internal use by ventoy
|
||||
@@ -135,7 +138,8 @@ typedef struct ventoy_windows_data
|
||||
{
|
||||
char auto_install_script[384];
|
||||
char injection_archive[384];
|
||||
grub_uint8_t reserved[256];
|
||||
grub_uint8_t windows11_bypass_check;
|
||||
grub_uint8_t reserved[255];
|
||||
}ventoy_windows_data;
|
||||
|
||||
|
||||
@@ -149,11 +153,23 @@ typedef struct ventoy_secure_data
|
||||
grub_uint8_t magic2[16]; /* VENTOY_GUID */
|
||||
}ventoy_secure_data;
|
||||
|
||||
|
||||
typedef struct ventoy_vlnk
|
||||
{
|
||||
ventoy_guid guid; // VENTOY_GUID
|
||||
grub_uint32_t crc32; // crc32
|
||||
grub_uint32_t disk_signature;
|
||||
grub_uint64_t part_offset; // in bytes
|
||||
char filepath[384];
|
||||
grub_uint8_t reserved[96];
|
||||
}ventoy_vlnk;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
// compile assert check : sizeof(ventoy_os_param) must be 512
|
||||
COMPILE_ASSERT(1,sizeof(ventoy_os_param) == 512);
|
||||
COMPILE_ASSERT(2,sizeof(ventoy_secure_data) == 4096);
|
||||
COMPILE_ASSERT(3,sizeof(ventoy_vlnk) == 512);
|
||||
|
||||
|
||||
|
||||
@@ -241,6 +257,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);
|
||||
@@ -259,6 +276,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;
|
||||
|
||||
@@ -267,6 +285,7 @@ typedef struct ventoy_grub_param
|
||||
int grub_ext_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_img_chunk_list *chunk_list);
|
||||
int grub_fat_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_img_chunk_list *chunk_list);
|
||||
void grub_iso9660_set_nojoliet(int nojoliet);
|
||||
int grub_iso9660_is_joliet(void);
|
||||
grub_uint64_t grub_iso9660_get_last_read_pos(grub_file_t file);
|
||||
grub_uint64_t grub_iso9660_get_last_file_dirent_pos(grub_file_t file);
|
||||
grub_uint64_t grub_udf_get_file_offset(grub_file_t file);
|
||||
|
@@ -12,10 +12,10 @@ make install
|
||||
PATH=$PATH:$VT_DIR/GRUB2/INSTALL/bin/:$VT_DIR/GRUB2/INSTALL/sbin/
|
||||
|
||||
net_modules_legacy="net tftp http"
|
||||
all_modules_legacy="file setkey date drivemap blocklist regexp newc vga_text ntldr search at_keyboard usb_keyboard gcry_md5 hashsum gzio xzio lzopio lspci pci ext2 xfs ventoy chain read halt iso9660 linux16 test true sleep reboot echo videotest videoinfo videotest_checksum video_colors video_cirrus video_bochs vga vbe video_fb font video gettext extcmd terminal linux minicmd help configfile tr trig boot biosdisk disk ls tar squash4 password_pbkdf2 all_video png jpeg part_gpt part_msdos fat exfat ntfs loopback gzio normal udf gfxmenu gfxterm gfxterm_background gfxterm_menu"
|
||||
all_modules_legacy="file setkey date drivemap blocklist regexp newc vga_text ntldr search at_keyboard usb_keyboard gcry_md5 hashsum gzio xzio lzopio lspci pci ext2 xfs ventoy chain read halt iso9660 linux16 test true sleep reboot echo videotest videoinfo videotest_checksum video_colors video_cirrus video_bochs vga vbe video_fb font video gettext extcmd terminal linux minicmd help configfile tr trig boot biosdisk disk ls tar squash4 password_pbkdf2 all_video png jpeg part_gpt part_msdos fat exfat ntfs loopback gzio normal udf gfxmenu gfxterm gfxterm_background gfxterm_menu smbios"
|
||||
|
||||
net_modules_uefi="efinet net tftp http"
|
||||
all_modules_uefi="file setkey blocklist ventoy test true regexp newc search at_keyboard usb_keyboard gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux relocator jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop efi_uga video_bochs video_cirrus video video_fb gfxterm_background gfxterm_menu"
|
||||
all_modules_uefi="file setkey blocklist ventoy test true regexp newc search at_keyboard usb_keyboard gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux relocator jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop efi_uga video_bochs video_cirrus video video_fb gfxterm_background gfxterm_menu mouse fwload smbios"
|
||||
|
||||
all_modules_arm64_uefi="file setkey blocklist ventoy test true regexp newc search gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop video video_fb gfxterm_background gfxterm_menu"
|
||||
|
||||
@@ -97,6 +97,8 @@ elif [ "$1" = "arm64" ]; then
|
||||
if ! echo $all_modules | grep -q " ${line%.mod} "; then
|
||||
echo "Copy $line ..."
|
||||
cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/arm64-efi/$line $VT_DIR/INSTALL/grub/arm64-efi/
|
||||
xz $VT_DIR/INSTALL/grub/arm64-efi/$line
|
||||
mv $VT_DIR/INSTALL/grub/arm64-efi/${line}.xz $VT_DIR/INSTALL/grub/arm64-efi/${line}
|
||||
fi
|
||||
done
|
||||
elif [ "$1" = "mips64el" ]; then
|
||||
|
@@ -1165,6 +1165,7 @@ main (int argc, char *argv[])
|
||||
break;
|
||||
case GRUB_INSTALL_PLATFORM_MIPS64EL_EFI:
|
||||
efi_file = "grubmips64el.efi";
|
||||
break;
|
||||
case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
|
||||
efi_file = "grubriscv32.efi";
|
||||
break;
|
||||
|
@@ -48,6 +48,12 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$VTOY_ARCH" = "i386" ]; then
|
||||
if $BUSYBOX_PATH/vtchmod32 -6; then
|
||||
export VTOY_ARCH=x86_64
|
||||
fi
|
||||
fi
|
||||
|
||||
echo $VTOY_ARCH > $VTOY_PATH/ventoy_arch
|
||||
|
||||
|
||||
@@ -81,6 +87,7 @@ export PATH=$BUSYBOX_PATH/:$VTOY_PATH/tool
|
||||
|
||||
export VTOY_BREAK_LEVEL=$(hexdump -n 1 -s 449 -e '1/1 "%02x"' $VTOY_PATH/ventoy_os_param)
|
||||
export VTOY_DEBUG_LEVEL=$(hexdump -n 1 -s 450 -e '1/1 "%02x"' $VTOY_PATH/ventoy_os_param)
|
||||
export VTOY_LINUX_REMOUNT=$(hexdump -n 1 -s 454 -e '1/1 "%02x"' $VTOY_PATH/ventoy_os_param)
|
||||
|
||||
#Fixme: busybox shell output redirect seems to have some bug in rhel5
|
||||
if uname -a | grep -q el5; then
|
||||
@@ -108,6 +115,8 @@ fi
|
||||
|
||||
if [ "$VTOY_ARCH" = "x86_64" ]; then
|
||||
echo "Use x86_64 busybox toolkit ..." >>$VTLOG
|
||||
$BUSYBOX_PATH/xzcat $BUSYBOX_PATH/xzcat64_musl.xz > $BUSYBOX_PATH/xzcat_musl
|
||||
$BUSYBOX_PATH/chmod +x $BUSYBOX_PATH/xzcat_musl
|
||||
ln -s $BUSYBOX_PATH/xzminidec64 $BUSYBOX_PATH/xzminidec
|
||||
ln -s $VTOY_PATH/tool/dmsetup64 $VTOY_PATH/tool/dmsetup
|
||||
ln -s $VTOY_PATH/tool/lunzip64 $VTOY_PATH/tool/lunzip
|
||||
@@ -117,6 +126,8 @@ if [ "$VTOY_ARCH" = "x86_64" ]; then
|
||||
ln -s $VTOY_PATH/tool/zstdcat64 $VTOY_PATH/tool/zstdcat
|
||||
elif [ "$VTOY_ARCH" = "i386" ]; then
|
||||
echo "Use i386 busybox toolkit ..." >>$VTLOG
|
||||
$BUSYBOX_PATH/xzcat $BUSYBOX_PATH/xzcat32_musl.xz > $BUSYBOX_PATH/xzcat_musl
|
||||
$BUSYBOX_PATH/chmod +x $BUSYBOX_PATH/xzcat_musl
|
||||
ln -s $BUSYBOX_PATH/xzminidec32 $BUSYBOX_PATH/xzminidec
|
||||
ln -s $VTOY_PATH/tool/dmsetup32 $VTOY_PATH/tool/dmsetup
|
||||
ln -s $VTOY_PATH/tool/lunzip32 $VTOY_PATH/tool/lunzip
|
||||
|
@@ -49,7 +49,12 @@ done
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
vtlog "ln -s /dev/$vtDM $1"
|
||||
ln -s /dev/$vtDM "$1"
|
||||
|
||||
if [ -e "$1" ]; then
|
||||
vtlog "$1 already exist"
|
||||
else
|
||||
ln -s /dev/$vtDM "$1"
|
||||
fi
|
||||
else
|
||||
vtLABEL=$($BUSYBOX_PATH/blkid /dev/$vtDM | $SED 's/.*LABEL="\([^"]*\)".*/\1/')
|
||||
vtlog "vtLABEL is $vtLABEL"
|
||||
@@ -59,7 +64,11 @@ else
|
||||
vtlog "vtLABEL is $vtLABEL from cmdline"
|
||||
fi
|
||||
|
||||
ln -s /dev/$vtDM "/dev/disk/by-label/$vtLABEL"
|
||||
if [ -e "/dev/disk/by-label/$vtLABEL" ]; then
|
||||
vtlog "$1 already exist"
|
||||
else
|
||||
ln -s /dev/$vtDM "/dev/disk/by-label/$vtLABEL"
|
||||
fi
|
||||
fi
|
||||
|
||||
# OK finish
|
||||
|
@@ -20,7 +20,7 @@
|
||||
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
||||
|
||||
if $GREP -q '^"$mount_handler"' /init; then
|
||||
echo 'use mount_handler ...' >> $VTLOG
|
||||
echo 'use mount_handler1 ...' >> $VTLOG
|
||||
|
||||
vthookfile=/hooks/archiso
|
||||
|
||||
@@ -37,6 +37,9 @@ if $GREP -q '^"$mount_handler"' /init; then
|
||||
if [ -f $vthookfile ]; then
|
||||
$SED '/while ! poll_device "${dev}"/a\ if /ventoy/busybox/sh /ventoy/hook/arch/ventoy-timeout.sh ${dev}; then break; fi' -i $vthookfile
|
||||
fi
|
||||
elif $GREP -q '^$mount_handler' /init; then
|
||||
echo 'use mount_handler2 ...' >> $VTLOG
|
||||
$SED "/^\$mount_handler/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ventoy-disk.sh" -i /init
|
||||
|
||||
elif $GREP -q '^KEEP_SEARCHING' /init; then
|
||||
echo 'KEEP_SEARCHING found ...' >> $VTLOG
|
||||
|
@@ -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"
|
||||
|
@@ -54,8 +54,15 @@ fi
|
||||
if [ -f $VTOY_PATH/autoinstall ]; then
|
||||
echo "Do auto install ..." >> $VTLOG
|
||||
|
||||
if $GREP -q "^mount /proc$" /init; then
|
||||
$SED "/^mount \/proc/a export file=$VTOY_PATH/autoinstall; export auto='true'; export priority='critical'" -i /init
|
||||
if $GREP -q '^autoinstall:' $VTOY_PATH/autoinstall; then
|
||||
echo "cloud-init auto install ..." >> $VTLOG
|
||||
if $GREP -q "maybe_break init" /init; then
|
||||
$SED "/maybe_break init/i $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/ventoy-cloud-init.sh \$rootmnt" -i /init
|
||||
fi
|
||||
else
|
||||
if $GREP -q "^mount /proc$" /init; then
|
||||
$SED "/^mount \/proc/a export file=$VTOY_PATH/autoinstall; export auto='true'; export priority='critical'" -i /init
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
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
|
@@ -22,19 +22,46 @@ porteus_hook() {
|
||||
$SED "/searching *for *\$CFG *file/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/porteus-disk.sh" -i $1
|
||||
}
|
||||
|
||||
if $GREP -q exfat /proc/filesystems; then
|
||||
vtPath=$($VTOY_PATH/tool/vtoydump -p $VTOY_PATH/ventoy_os_param)
|
||||
vtPath=$($VTOY_PATH/tool/vtoydump -p $VTOY_PATH/ventoy_os_param)
|
||||
echo $vtPath | $GREP -q " "
|
||||
_vtRet1=$?
|
||||
|
||||
$GREP -q exfat /proc/filesystems
|
||||
_vtRet2=$?
|
||||
|
||||
echo "_vtRet1=$_vtRet1 _vtRet2=$_vtRet2 ..." >> $VTLOG
|
||||
|
||||
if [ $_vtRet1 -ne 0 -a $_vtRet2 -eq 0 ]; then
|
||||
vtFindFlag=0
|
||||
$GREP '`value from`' /usr/* -r | $AWK -F: '{print $1}' | while read vtline; do
|
||||
echo "hooking $vtline ..." >> $VTLOG
|
||||
$SED "s#\`value from\`#$vtPath#g" -i $vtline
|
||||
vtFindFlag=1
|
||||
done
|
||||
|
||||
if [ $vtFindFlag -eq 0 ]; then
|
||||
if $GREP -q '`value from`' /linuxrc; then
|
||||
if $GREP -q "searching *for *\$CFG *file" /linuxrc; then
|
||||
echo "hooking linuxrc CFG..." >> $VTLOG
|
||||
$SED "/searching *for *\$CFG *file/i$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/porteus-path.sh" -i /linuxrc
|
||||
$SED "/searching *for *\$CFG *file/iFROM=\$(cat /porteus-from)" -i /linuxrc
|
||||
$SED "/searching *for *\$CFG *file/iISO=\$(cat /porteus-from)" -i /linuxrc
|
||||
vtFindFlag=1
|
||||
else
|
||||
echo "hooking linuxrc SGN..." >> $VTLOG
|
||||
$SED "/searching *for *\$SGN *file/i$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/porteus-path.sh" -i /linuxrc
|
||||
$SED "/searching *for *\$SGN *file/iFROM=\$(cat /porteus-from)" -i /linuxrc
|
||||
$SED "/searching *for *\$SGN *file/iISO=\$(cat /porteus-from)" -i /linuxrc
|
||||
vtFindFlag=1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
else
|
||||
for vtfile in '/init' '/linuxrc' ; do
|
||||
for vtfile in '/linuxrc' '/init'; do
|
||||
if [ -e $vtfile ]; then
|
||||
if ! $GREP -q ventoy $vtfile; then
|
||||
echo "hooking $vtfile ..." >> $VTLOG
|
||||
echo "hooking disk $vtfile ..." >> $VTLOG
|
||||
porteus_hook $vtfile
|
||||
fi
|
||||
fi
|
||||
|
38
IMG/cpio/ventoy/hook/debian/porteus-path.sh
Normal file
38
IMG/cpio/ventoy/hook/debian/porteus-path.sh
Normal file
@@ -0,0 +1,38 @@
|
||||
#!/ventoy/busybox/sh
|
||||
#************************************************************************************
|
||||
# Copyright (c) 2020, longpanda <admin@ventoy.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
. /ventoy/hook/ventoy-hook-lib.sh
|
||||
|
||||
vtlog "####### $0 $* ########"
|
||||
|
||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||
|
||||
wait_for_usb_disk_ready
|
||||
|
||||
vtdiskname=$(get_ventoy_disk_name)
|
||||
|
||||
vtPath=$(vtoydump -p $VTOY_PATH/ventoy_os_param)
|
||||
|
||||
if echo $vtdiskname | egrep -q "nvme|mmc|nbd"; then
|
||||
echo ${vtdiskname}p1${vtPath} > /porteus-from
|
||||
else
|
||||
echo ${vtdiskname}1${vtPath} > /porteus-from
|
||||
fi
|
||||
|
||||
PATH=$VTPATH_OLD
|
@@ -27,6 +27,33 @@ vtlog "####### $0 $* ########"
|
||||
|
||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||
|
||||
ventoy_os_install_dmsetup_by_fuse() {
|
||||
vtlog "ventoy_os_install_dmsetup_by_fuse $*"
|
||||
|
||||
mkdir -p $VTOY_PATH/mnt/fuse $VTOY_PATH/mnt/iso $VTOY_PATH/mnt/squashfs
|
||||
|
||||
vtoydm -p -f $VTOY_PATH/ventoy_image_map -d $1 > $VTOY_PATH/ventoy_dm_table
|
||||
vtoy_fuse_iso -f $VTOY_PATH/ventoy_dm_table -m $VTOY_PATH/mnt/fuse
|
||||
|
||||
mount -t iso9660 $VTOY_PATH/mnt/fuse/ventoy.iso $VTOY_PATH/mnt/iso
|
||||
|
||||
sfsfile=$(ls $VTOY_PATH/mnt/iso/*.sfs)
|
||||
|
||||
mount -t squashfs $sfsfile $VTOY_PATH/mnt/squashfs
|
||||
|
||||
kVer=$(uname -r)
|
||||
KoName=$(ls $VTOY_PATH/mnt/squashfs/lib/modules/$kVer/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
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
wait_for_usb_disk_ready
|
||||
|
||||
vtdiskname=$(get_ventoy_disk_name)
|
||||
@@ -36,6 +63,12 @@ if [ "$vtdiskname" = "unknown" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if grep -q 'device-mapper' /proc/devices; then
|
||||
vtlog "device-mapper module exist"
|
||||
else
|
||||
ventoy_os_install_dmsetup_by_fuse $vtdiskname
|
||||
fi
|
||||
|
||||
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
|
||||
|
||||
if ! [ -e $VTOY_DM_PATH ]; then
|
||||
|
@@ -18,8 +18,15 @@
|
||||
#************************************************************************************
|
||||
|
||||
$SED '1 apmedia=usbhd' -i /init
|
||||
$SED "/^ *HAVE_PARTS=/a\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/puppy-disk.sh" -i /init
|
||||
$SED "/^ *HAVE_PARTS=/a\ HAVE_PARTS='ventoy|iso9660'" -i /init
|
||||
|
||||
if $GREP -q 'HAVE_PARTS=' /init; then
|
||||
$SED "/^ *HAVE_PARTS=/a\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/puppy-disk.sh" -i /init
|
||||
$SED "/^ *HAVE_PARTS=/a\ HAVE_PARTS='ventoy|iso9660'" -i /init
|
||||
elif $GREP -q 'LESSPARTS=' /init; then
|
||||
$SED "/^ *LESSPARTS=/a\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/puppy-disk.sh" -i /init
|
||||
$SED "/^ *LESSPARTS=/a\ LESSPARTS='ventoy|iso9660'" -i /init
|
||||
fi
|
||||
|
||||
|
||||
if [ -f /DISTRO_SPECS ]; then
|
||||
if ! [ -d /dev ]; then
|
||||
|
91
IMG/cpio/ventoy/hook/debian/pyabr-disk.sh
Normal file
91
IMG/cpio/ventoy/hook/debian/pyabr-disk.sh
Normal file
@@ -0,0 +1,91 @@
|
||||
#!/ventoy/busybox/sh
|
||||
#************************************************************************************
|
||||
# Copyright (c) 2020, longpanda <admin@ventoy.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
. /ventoy/hook/ventoy-hook-lib.sh
|
||||
|
||||
if is_ventoy_hook_finished; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
vtlog "####### $0 $* ########"
|
||||
|
||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||
|
||||
ventoy_os_install_dmsetup_by_fuse() {
|
||||
vtlog "ventoy_os_install_dmsetup_by_fuse $*"
|
||||
|
||||
mkdir -p $VTOY_PATH/mnt/fuse $VTOY_PATH/mnt/iso $VTOY_PATH/mnt/squashfs
|
||||
|
||||
vtoydm -p -f $VTOY_PATH/ventoy_image_map -d $1 > $VTOY_PATH/ventoy_dm_table
|
||||
vtoy_fuse_iso -f $VTOY_PATH/ventoy_dm_table -m $VTOY_PATH/mnt/fuse
|
||||
|
||||
mount -t iso9660 $VTOY_PATH/mnt/fuse/ventoy.iso $VTOY_PATH/mnt/iso
|
||||
mount -t squashfs $VTOY_PATH/mnt/iso/pyabr/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
|
||||
}
|
||||
|
||||
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
|
||||
vtlog "ventoy disk not found"
|
||||
PATH=$VTPATH_OLD
|
||||
exit 0
|
||||
fi
|
||||
|
||||
modprobe fuse
|
||||
modprobe cuse
|
||||
|
||||
vtKver=$(uname -r)
|
||||
ventoy_os_install_dmsetup_by_fuse $vtdiskname $vtKver
|
||||
|
||||
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
|
||||
|
||||
PATH=$VTPATH_OLD
|
||||
|
||||
set_ventoy_hook_finish
|
20
IMG/cpio/ventoy/hook/debian/pyabr-hook.sh
Normal file
20
IMG/cpio/ventoy/hook/debian/pyabr-hook.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/ventoy/busybox/sh
|
||||
#************************************************************************************
|
||||
# Copyright (c) 2020, longpanda <admin@ventoy.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
$SED "/find_data/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/pyabr-disk.sh" -i /init
|
@@ -23,6 +23,11 @@ $SED "s#.*livefs_root=.*find_livefs.*#$BUSYBOX_PATH/mount -t iso9660 /dev/mapper
|
||||
if [ -e /init ] && $GREP -q '^mountroot$' /init; then
|
||||
echo "Here before mountroot ..." >> $VTLOG
|
||||
$SED "/^mountroot$/i\\$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/disk_mount_hook.sh" -i /init
|
||||
|
||||
if [ -f /scripts/init-premount/ORDER ]; then
|
||||
$SED "/\/scripts\/init-premount\/partitioning/,+1d" -i /scripts/init-premount/ORDER
|
||||
fi
|
||||
|
||||
else
|
||||
echo "Use default hook ..." >> $VTLOG
|
||||
ventoy_systemd_udevd_work_around
|
||||
|
@@ -41,18 +41,18 @@ ventoy_os_install_dmsetup() {
|
||||
fi
|
||||
|
||||
# install md-modules
|
||||
LINE=$($GREP ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list)
|
||||
LINE=$($GREP -i ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list)
|
||||
if [ $? -eq 0 ]; then
|
||||
LINTCNT=$($GREP -c ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list)
|
||||
LINTCNT=$($GREP -i -c ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list)
|
||||
if [ $LINTCNT -gt 1 ]; then
|
||||
vtlog "more than one pkgs, need to filter..."
|
||||
VER=$($BUSYBOX_PATH/uname -r)
|
||||
|
||||
LINE=$($GREP ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list | $GREP $VER)
|
||||
LINTCNT=$($GREP ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list | $GREP -c $VER)
|
||||
LINE=$($GREP -i ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list | $GREP -i $VER)
|
||||
LINTCNT=$($GREP -i ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list | $GREP -i -c $VER)
|
||||
if [ $LINTCNT -gt 1 ]; then
|
||||
vtlog "Still more than one pkgs, use the first one..."
|
||||
LINE=$($GREP ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list | $GREP -m1 $VER)
|
||||
LINE=$($GREP -i ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list | $GREP -i -m1 $VER)
|
||||
fi
|
||||
fi
|
||||
install_udeb_from_line "$LINE" ${vt_usb_disk}
|
||||
|
63
IMG/cpio/ventoy/hook/debian/ventoy-cloud-init.sh
Normal file
63
IMG/cpio/ventoy/hook/debian/ventoy-cloud-init.sh
Normal file
@@ -0,0 +1,63 @@
|
||||
#!/ventoy/busybox/sh
|
||||
#************************************************************************************
|
||||
# Copyright (c) 2020, longpanda <admin@ventoy.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
. /ventoy/hook/ventoy-hook-lib.sh
|
||||
|
||||
vtlog "####### $0 $* ########"
|
||||
|
||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||
|
||||
newroot=$1
|
||||
|
||||
dd if=/dev/zero of=$newroot/tmp/cidata.img bs=1M count=8 status=none
|
||||
freeloop=$(losetup -f)
|
||||
|
||||
losetup $freeloop $newroot/tmp/cidata.img
|
||||
|
||||
mkfs.vfat -n CIDATA $freeloop
|
||||
|
||||
mkdir /tmpcidata
|
||||
mount $newroot/tmp/cidata.img /tmpcidata
|
||||
|
||||
vtSplit=$(grep VENTOY_META_DATA_SPLIT $VTOY_PATH/autoinstall | wc -l)
|
||||
if [ $vtSplit -eq 1 ]; then
|
||||
vtlog "split autoinstall script to user-data and meta-data"
|
||||
vtLine=$(grep -n VENTOY_META_DATA_SPLIT $VTOY_PATH/autoinstall | awk -F: '{print $1}')
|
||||
vtLine1=$(expr $vtLine - 1)
|
||||
vtLine2=$(expr $vtLine + 1)
|
||||
vtlog "Line number: $vtLine $vtLine1 $vtLine2"
|
||||
sed -n "1,${vtLine1}p" $VTOY_PATH/autoinstall >/tmpcidata/user-data
|
||||
sed -n "${vtLine2},\$p" $VTOY_PATH/autoinstall >/tmpcidata/meta-data
|
||||
else
|
||||
vtlog "only user-data avaliable"
|
||||
cp -a $VTOY_PATH/autoinstall /tmpcidata/user-data
|
||||
touch /tmpcidata/meta-data
|
||||
fi
|
||||
|
||||
|
||||
umount /tmpcidata
|
||||
rm -rf /tmpcidata
|
||||
|
||||
vtCMD=$(cat /proc/cmdline)
|
||||
echo "autoinstall $vtCMD" > $newroot/tmp/kcmdline
|
||||
mount --bind $newroot/tmp/kcmdline /proc/cmdline
|
||||
|
||||
|
||||
PATH=$VTPATH_OLD
|
||||
|
@@ -35,7 +35,7 @@ ventoy_get_debian_distro() {
|
||||
fi
|
||||
|
||||
if [ -e /init ]; then
|
||||
if $GREP -q PUPPYSFS /init; then
|
||||
if $EGREP -q 'PUPPYSFS|PUPPYFILE' /init; then
|
||||
if $GREP -q VEKETSFS /init; then
|
||||
echo 'veket'; return
|
||||
else
|
||||
@@ -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
|
||||
@@ -94,6 +98,10 @@ ventoy_get_debian_distro() {
|
||||
echo 'mocaccino'; return
|
||||
fi
|
||||
|
||||
if $GREP -q '/pyabr/' /proc/cmdline; then
|
||||
echo 'pyabr'; return
|
||||
fi
|
||||
|
||||
echo 'default'
|
||||
}
|
||||
|
||||
|
7
IMG/cpio/ventoy/hook/default/export.list
Normal file
7
IMG/cpio/ventoy/hook/default/export.list
Normal file
@@ -0,0 +1,7 @@
|
||||
preseed/file
|
||||
debian-installer/locale
|
||||
console-keymaps-at/keymap
|
||||
keyboard-configuration/xkb-keymap
|
||||
keyboard-configuration/layout
|
||||
simple-cdd/profiles
|
||||
vga
|
83
IMG/cpio/ventoy/hook/easystartup/disk_hook.sh
Normal file
83
IMG/cpio/ventoy/hook/easystartup/disk_hook.sh
Normal file
@@ -0,0 +1,83 @@
|
||||
#!/ventoy/busybox/sh
|
||||
#************************************************************************************
|
||||
# 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/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
. /ventoy/hook/ventoy-hook-lib.sh
|
||||
|
||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||
|
||||
get_rhel_ver() {
|
||||
if uname -m | grep -q '64'; then
|
||||
machine='_X64'
|
||||
fi
|
||||
|
||||
if grep -q '6[.]1' /etc/redhat-release; then
|
||||
echo "RHAS6U1$machine"; return
|
||||
fi
|
||||
|
||||
echo "RHAS6U1$machine"
|
||||
}
|
||||
|
||||
install_dm_mod_ko() {
|
||||
# dump iso file location
|
||||
vtoydm -i -f $VTOY_PATH/ventoy_image_map -d ${vtdiskname} > $VTOY_PATH/iso_file_list
|
||||
|
||||
sysver=$(get_rhel_ver)
|
||||
vtlog "sysver=$sysver"
|
||||
|
||||
LINE=$(grep "$sysver" -n -m1 $VTOY_PATH/iso_file_list | awk -F: '{print $1}')
|
||||
vtlog "LINE=$LINE"
|
||||
|
||||
LINE=$(sed -n "$LINE,\$p" $VTOY_PATH/iso_file_list | grep -m1 'initrd.img')
|
||||
vtlog "LINE=$LINE"
|
||||
|
||||
sector=$(echo $LINE | $AWK '{print $(NF-1)}')
|
||||
length=$(echo $LINE | $AWK '{print $NF}')
|
||||
vtlog "sector=$sector length=$length"
|
||||
|
||||
mkdir xxx
|
||||
vtoydm -e -f $VTOY_PATH/ventoy_image_map -d ${vtdiskname} -s $sector -l $length -o ./xxx.img
|
||||
|
||||
cd xxx/
|
||||
zcat ../xxx.img | cpio -idmu
|
||||
ko=$(find -name dm-mod.ko*)
|
||||
vtlog "ko=$ko ..."
|
||||
insmod $ko
|
||||
|
||||
cd ../
|
||||
rm -f xxx.img
|
||||
rm -rf xxx
|
||||
}
|
||||
|
||||
vtdiskname=$(get_ventoy_disk_name)
|
||||
vtlog "vtdiskname=$vtdiskname ..."
|
||||
if [ "$vtdiskname" = "unknown" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if grep -q 'device-mapper' /proc/devices; then
|
||||
vtlog "device-mapper module check ko"
|
||||
else
|
||||
install_dm_mod_ko
|
||||
fi
|
||||
|
||||
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
|
||||
|
||||
ln -s /dev/dm-0 /dev/root
|
||||
|
||||
PATH=$VTPATH_OLD
|
23
IMG/cpio/ventoy/hook/easystartup/ventoy-hook.sh
Normal file
23
IMG/cpio/ventoy/hook/easystartup/ventoy-hook.sh
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/ventoy/busybox/sh
|
||||
#************************************************************************************
|
||||
# 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/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
||||
|
||||
$SED "s#^CDROM=.*#CDROM=/dev/dm-0#" -i /init
|
||||
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/easystartup/ventoy-initqueue.sh /initqueue/ventoy.sh
|
20
IMG/cpio/ventoy/hook/easystartup/ventoy-initqueue.sh
Normal file
20
IMG/cpio/ventoy/hook/easystartup/ventoy-initqueue.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/ventoy/busybox/sh
|
||||
#************************************************************************************
|
||||
# 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/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
/ventoy/busybox/sh /ventoy/hook/easystartup/disk_hook.sh $*
|
@@ -92,7 +92,8 @@ if [ -f /etc/system-release ]; then
|
||||
vtNeedRepo="yes"
|
||||
fi
|
||||
fi
|
||||
if $GREP -q el8 /proc/version; then
|
||||
|
||||
if $GREP -q 'el[89]' /proc/version; then
|
||||
vtNeedRepo="yes"
|
||||
fi
|
||||
|
||||
@@ -102,6 +103,8 @@ if $GREP -i -q Fedora /proc/version; then
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "vtNeedRepo=$vtNeedRepo" >> $VTLOG
|
||||
|
||||
if [ "$vtNeedRepo" = "yes" ]; then
|
||||
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-repo.sh /lib/dracut/hooks/pre-pivot/99-ventoy-repo.sh
|
||||
fi
|
||||
|
@@ -36,3 +36,7 @@ else
|
||||
fi
|
||||
|
||||
/ventoy/busybox/sh /ventoy/hook/suse/udev_disk_hook.sh "${vtpart2#/dev/}"
|
||||
|
||||
if $GREP -q 'mediacheck=1' /proc/cmdline; then
|
||||
ventoy_copy_device_mapper "${vtdiskname}"
|
||||
fi
|
||||
|
@@ -30,6 +30,8 @@ SLEEP=$BUSYBOX_PATH/sleep
|
||||
HEAD=$BUSYBOX_PATH/head
|
||||
VTOY_DM_PATH=/dev/mapper/ventoy
|
||||
VTOY_DEBUG_LEVEL=$($BUSYBOX_PATH/hexdump -n 1 -s 450 -e '1/1 "%02x"' $VTOY_PATH/ventoy_os_param)
|
||||
VTOY_LINUX_REMOUNT=$($BUSYBOX_PATH/hexdump -n 1 -s 454 -e '1/1 "%02x"' $VTOY_PATH/ventoy_os_param)
|
||||
VTOY_VLNK_BOOT=$($BUSYBOX_PATH/hexdump -n 1 -s 455 -e '1/1 "%02x"' $VTOY_PATH/ventoy_os_param)
|
||||
|
||||
if [ "$VTOY_DEBUG_LEVEL" = "01" ]; then
|
||||
if [ -e /dev/console ]; then
|
||||
@@ -65,11 +67,15 @@ set_ventoy_hook_finish() {
|
||||
}
|
||||
|
||||
get_ventoy_disk_name() {
|
||||
line=$($VTOY_PATH/tool/vtoydump -f /ventoy/ventoy_os_param)
|
||||
if [ $? -eq 0 ]; then
|
||||
echo ${line%%#*}
|
||||
if [ "$VTOY_VLNK_BOOT" = "01" ]; then
|
||||
$VTOY_PATH/tool/vtoydump -t /ventoy/ventoy_os_param
|
||||
else
|
||||
echo "unknown"
|
||||
line=$($VTOY_PATH/tool/vtoydump -f /ventoy/ventoy_os_param)
|
||||
if [ $? -eq 0 ]; then
|
||||
echo ${line%%#*}
|
||||
else
|
||||
echo "unknown"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -120,14 +126,6 @@ check_usb_disk_ready() {
|
||||
[ -e "${vtpart2}" ]
|
||||
}
|
||||
|
||||
is_ventoy_disk() {
|
||||
if $VTOY_PATH/tool/vtoydump -f $VTOY_PATH/ventoy_os_param -c "$1"; then
|
||||
$BUSYBOX_PATH/true
|
||||
else
|
||||
$BUSYBOX_PATH/false
|
||||
fi
|
||||
}
|
||||
|
||||
not_ventoy_disk() {
|
||||
if echo $1 | $EGREP -q "nvme.*p$|mmc.*p$|nbd.*p$"; then
|
||||
vtDiskName=${1:0:-1}
|
||||
@@ -135,10 +133,15 @@ not_ventoy_disk() {
|
||||
vtDiskName=$1
|
||||
fi
|
||||
|
||||
if $VTOY_PATH/tool/vtoydump -f $VTOY_PATH/ventoy_os_param -c "$vtDiskName"; then
|
||||
$BUSYBOX_PATH/false
|
||||
if [ "$VTOY_VLNK_BOOT" = "01" ]; then
|
||||
vtVtoyDisk=$($VTOY_PATH/tool/vtoydump -t $VTOY_PATH/ventoy_os_param)
|
||||
[ "$vtVtoyDisk" != "/dev/$vtDiskName" ]
|
||||
else
|
||||
$BUSYBOX_PATH/true
|
||||
if $VTOY_PATH/tool/vtoydump -f $VTOY_PATH/ventoy_os_param -c "$vtDiskName"; then
|
||||
$BUSYBOX_PATH/false
|
||||
else
|
||||
$BUSYBOX_PATH/true
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -220,6 +223,147 @@ ventoy_check_dm_module() {
|
||||
fi
|
||||
}
|
||||
|
||||
ventoy_need_dm_patch() {
|
||||
if [ "$VTOY_LINUX_REMOUNT" != "01" ]; then
|
||||
if $GREP -q 'VTOY_LINUX_REMOUNT=1' /proc/cmdline; then
|
||||
:
|
||||
else
|
||||
$BUSYBOX_PATH/false; return
|
||||
fi
|
||||
fi
|
||||
|
||||
if $GREP -q 'device-mapper' /proc/devices; then
|
||||
:
|
||||
else
|
||||
$BUSYBOX_PATH/false; return
|
||||
fi
|
||||
|
||||
if $GREP -q 'dm_patch' /proc/modules; then
|
||||
$BUSYBOX_PATH/false; return
|
||||
fi
|
||||
|
||||
vtMajorVer=$($BUSYBOX_PATH/uname -r | $AWK -F. '{print $1}')
|
||||
vtMinorVer=$($BUSYBOX_PATH/uname -r | $AWK -F. '{print $2}')
|
||||
|
||||
if [ $vtMajorVer -lt 3 ]; then
|
||||
$BUSYBOX_PATH/false; return
|
||||
elif [ $vtMajorVer -eq 3 -a $vtMinorVer -lt 10 ]; then
|
||||
$BUSYBOX_PATH/false; return
|
||||
fi
|
||||
|
||||
|
||||
$BUSYBOX_PATH/true
|
||||
}
|
||||
|
||||
ventoy_dm_patch() {
|
||||
vtMType=$($BUSYBOX_PATH/uname -m)
|
||||
|
||||
vtlog "######### ventoy_dm_patch ############"
|
||||
|
||||
if echo $vtMType | $EGREP -i -q "x86.64|amd64"; then
|
||||
vtKoName=dm_patch_64.ko
|
||||
elif echo $vtMType | $EGREP -i -q "i[3-6]86"; then
|
||||
vtKoName=dm_patch_32.ko
|
||||
else
|
||||
vtlog "unsupported machine type $vtMType"
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -f $VTOY_PATH/tool/$vtKoName ]; then
|
||||
vtlog "/ventoy/tool/$vtKoName exist OK"
|
||||
else
|
||||
vtlog "/ventoy/tool/$vtKoName NOT exist"
|
||||
return
|
||||
fi
|
||||
|
||||
$CAT /proc/kallsyms | $BUSYBOX_PATH/sort > $VTOY_PATH/kallsyms
|
||||
|
||||
vtLine=$($VTOY_PATH/tool/vtoyksym dm_get_table_device $VTOY_PATH/kallsyms)
|
||||
get_addr=$(echo $vtLine | $AWK '{print $1}')
|
||||
get_size=$(echo $vtLine | $AWK '{print $2}')
|
||||
|
||||
vtLine=$($VTOY_PATH/tool/vtoyksym dm_put_table_device $VTOY_PATH/kallsyms)
|
||||
put_addr=$(echo $vtLine | $AWK '{print $1}')
|
||||
put_size=$(echo $vtLine | $AWK '{print $2}')
|
||||
|
||||
ro_addr=$($GREP ' set_memory_ro$' /proc/kallsyms | $AWK '{print $1}')
|
||||
rw_addr=$($GREP ' set_memory_rw$' /proc/kallsyms | $AWK '{print $1}')
|
||||
kprobe_reg_addr=$($GREP ' register_kprobe$' /proc/kallsyms | $AWK '{print $1}')
|
||||
kprobe_unreg_addr=$($GREP ' unregister_kprobe$' /proc/kallsyms | $AWK '{print $1}')
|
||||
|
||||
if [ "$VTOY_DEBUG_LEVEL" = "01" ]; then
|
||||
printk_addr=$($GREP ' printk$' /proc/kallsyms | $AWK '{print $1}')
|
||||
vtDebug="-v"
|
||||
else
|
||||
printk_addr=0
|
||||
fi
|
||||
|
||||
#printk_addr=$($GREP ' printk$' /proc/kallsyms | $AWK '{print $1}')
|
||||
#vtDebug="-v"
|
||||
|
||||
vtlog get_addr=$get_addr get_size=$get_size
|
||||
vtlog put_addr=$put_addr put_size=$put_size
|
||||
vtlog kprobe_reg_addr=$kprobe_reg_addr kprobe_unreg_addr=$kprobe_unreg_addr
|
||||
vtlog ro_addr=$ro_addr rw_addr=$rw_addr printk_addr=$printk_addr
|
||||
|
||||
if [ "$get_addr" = "0" -o "$put_addr" = "0" ]; then
|
||||
vtlog "Invalid symbol address"
|
||||
return
|
||||
fi
|
||||
if [ "$ro_addr" = "0" -o "$rw_addr" = "0" ]; then
|
||||
vtlog "Invalid symbol address"
|
||||
return
|
||||
fi
|
||||
|
||||
|
||||
vtKv=$($BUSYBOX_PATH/uname -r)
|
||||
|
||||
if [ ! -d /lib/modules/$vtKv ]; then
|
||||
vtlog "No modules directory found"
|
||||
return
|
||||
elif [ -d /lib/modules/$vtKv/kernel/fs ]; then
|
||||
vtModPath=$($FIND /lib/modules/$vtKv/kernel/fs/ -name "*.ko*" | $HEAD -n1)
|
||||
else
|
||||
vtModPath=$($FIND /lib/modules/$vtKv/kernel/ -name "xfs.ko*" | $HEAD -n1)
|
||||
fi
|
||||
|
||||
if [ -z "$vtModPath" ]; then
|
||||
vtModPath=$($FIND /lib/modules/$vtKv/kernel/ -name "*.ko*" | $HEAD -n1)
|
||||
fi
|
||||
|
||||
vtModName=$($BUSYBOX_PATH/basename $vtModPath)
|
||||
|
||||
vtlog "template module is $vtModPath $vtModName"
|
||||
|
||||
if [ -z "$vtModPath" ]; then
|
||||
vtlog "No template module found"
|
||||
return
|
||||
elif echo $vtModPath | $GREP -q "[.]ko$"; then
|
||||
$BUSYBOX_PATH/cp -a $vtModPath $VTOY_PATH/$vtModName
|
||||
elif echo $vtModPath | $GREP -q "[.]ko[.]xz$"; then
|
||||
$BUSYBOX_PATH/xzcat $vtModPath > $VTOY_PATH/$vtModName
|
||||
elif echo $vtModPath | $GREP -q "[.]ko[.]gz$"; then
|
||||
$BUSYBOX_PATH/zcat $vtModPath > $VTOY_PATH/$vtModName
|
||||
else
|
||||
vtlog "unsupport module type"
|
||||
return
|
||||
fi
|
||||
|
||||
#step1: modify vermagic/mod crc/relocation
|
||||
$VTOY_PATH/tool/vtoykmod -u $VTOY_PATH/tool/$vtKoName $VTOY_PATH/$vtModName $vtDebug
|
||||
|
||||
#step2: fill parameters
|
||||
vtPgsize=$($VTOY_PATH/tool/vtoyksym -p)
|
||||
$VTOY_PATH/tool/vtoykmod -f $VTOY_PATH/tool/$vtKoName $vtPgsize 0x$printk_addr 0x$ro_addr 0x$rw_addr $get_addr $get_size $put_addr $put_size 0x$kprobe_reg_addr 0x$kprobe_unreg_addr $vtDebug
|
||||
|
||||
$BUSYBOX_PATH/insmod $VTOY_PATH/tool/$vtKoName
|
||||
|
||||
if $GREP -q 'dm_patch' /proc/modules; then
|
||||
echo "done" > $VTOY_PATH/dm_patch_done
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
create_ventoy_device_mapper() {
|
||||
vtlog "create_ventoy_device_mapper $*"
|
||||
|
||||
@@ -238,11 +382,28 @@ create_ventoy_device_mapper() {
|
||||
fi
|
||||
|
||||
$VTOY_PATH/tool/vtoydm -p -f $VTOY_PATH/ventoy_image_map -d $1 > $VTOY_PATH/ventoy_dm_table
|
||||
|
||||
|
||||
vtLevel1=$($CAT /proc/sys/kernel/printk | $AWK '{print $1}')
|
||||
vtLevel2=$($CAT /proc/sys/kernel/printk | $AWK '{print $2}')
|
||||
vtLevel3=$($CAT /proc/sys/kernel/printk | $AWK '{print $3}')
|
||||
vtLevel4=$($CAT /proc/sys/kernel/printk | $AWK '{print $4}')
|
||||
if ventoy_need_dm_patch; then
|
||||
ventoy_dm_patch
|
||||
#suppress printk message
|
||||
echo 0 $vtLevel2 0 $vtLevel4 > /proc/sys/kernel/printk
|
||||
fi
|
||||
|
||||
if [ -z "$2" ]; then
|
||||
$VT_DM_BIN create ventoy $VTOY_PATH/ventoy_dm_table >>$VTLOG 2>&1
|
||||
else
|
||||
$VT_DM_BIN "$2" create ventoy $VTOY_PATH/ventoy_dm_table >>$VTLOG 2>&1
|
||||
fi
|
||||
|
||||
if ventoy_need_dm_patch; then
|
||||
#recover printk level
|
||||
echo $vtLevel1 $vtLevel2 $vtLevel3 $vtLevel4 > /proc/sys/kernel/printk
|
||||
fi
|
||||
}
|
||||
|
||||
create_persistent_device_mapper() {
|
||||
@@ -263,7 +424,23 @@ create_persistent_device_mapper() {
|
||||
fi
|
||||
|
||||
$VTOY_PATH/tool/vtoydm -p -f $VTOY_PATH/ventoy_persistent_map -d $1 > $VTOY_PATH/persistent_dm_table
|
||||
|
||||
|
||||
vtLevel1=$($CAT /proc/sys/kernel/printk | $AWK '{print $1}')
|
||||
vtLevel2=$($CAT /proc/sys/kernel/printk | $AWK '{print $2}')
|
||||
vtLevel3=$($CAT /proc/sys/kernel/printk | $AWK '{print $3}')
|
||||
vtLevel4=$($CAT /proc/sys/kernel/printk | $AWK '{print $4}')
|
||||
if [ -f $VTOY_PATH/dm_patch_done ]; then
|
||||
#suppress printk message
|
||||
echo 0 $vtLevel2 0 $vtLevel4 > /proc/sys/kernel/printk
|
||||
fi
|
||||
|
||||
$VT_DM_BIN create vtoy_persistent $VTOY_PATH/persistent_dm_table >>$VTLOG 2>&1
|
||||
|
||||
if [ -f $VTOY_PATH/dm_patch_done ]; then
|
||||
#recover printk level
|
||||
echo $vtLevel1 $vtLevel2 $vtLevel3 $vtLevel4 > /proc/sys/kernel/printk
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -493,6 +670,22 @@ ventoy_create_persistent_link() {
|
||||
fi
|
||||
}
|
||||
|
||||
ventoy_partname_to_diskname() {
|
||||
if echo $1 | $EGREP -q "nvme.*p[0-9]$|mmc.*p[0-9]$|nbd.*p[0-9]$"; then
|
||||
echo -n "${1:0:-2}"
|
||||
else
|
||||
echo -n "${1:0:-1}"
|
||||
fi
|
||||
}
|
||||
|
||||
ventoy_diskname_to_partname() {
|
||||
if echo $1 | $EGREP -q "nvme.*p[0-9]$|mmc.*p[0-9]$|nbd.*p[0-9]$"; then
|
||||
echo -n "${1}p$2"
|
||||
else
|
||||
echo -n "${1}$2"
|
||||
fi
|
||||
}
|
||||
|
||||
ventoy_udev_disk_common_hook() {
|
||||
if echo $1 | $EGREP -q "nvme.*p[0-9]$|mmc.*p[0-9]$|nbd.*p[0-9]$"; then
|
||||
VTDISK="${1:0:-2}"
|
||||
@@ -541,6 +734,10 @@ ventoy_udev_disk_common_hook() {
|
||||
create_persistent_device_mapper "/dev/$VTDISK"
|
||||
ventoy_create_persistent_link
|
||||
fi
|
||||
|
||||
if $GREP -q 'dm_patch' /proc/modules; then
|
||||
$BUSYBOX_PATH/rmmod dm_patch
|
||||
fi
|
||||
}
|
||||
|
||||
ventoy_create_dev_ventoy_part() {
|
||||
@@ -550,6 +747,15 @@ ventoy_create_dev_ventoy_part() {
|
||||
if [ -e /vtoy_dm_table ]; then
|
||||
vtPartid=1
|
||||
|
||||
vtLevel1=$($CAT /proc/sys/kernel/printk | $AWK '{print $1}')
|
||||
vtLevel2=$($CAT /proc/sys/kernel/printk | $AWK '{print $2}')
|
||||
vtLevel3=$($CAT /proc/sys/kernel/printk | $AWK '{print $3}')
|
||||
vtLevel4=$($CAT /proc/sys/kernel/printk | $AWK '{print $4}')
|
||||
if [ -f $VTOY_PATH/dm_patch_done ]; then
|
||||
#suppress printk message
|
||||
echo 0 $vtLevel2 0 $vtLevel4 > /proc/sys/kernel/printk
|
||||
fi
|
||||
|
||||
$CAT /vtoy_dm_table | while read vtline; do
|
||||
echo $vtline > /ventoy/dm_table_part${vtPartid}
|
||||
$VTOY_PATH/tool/dmsetup create ventoy${vtPartid} /ventoy/dm_table_part${vtPartid}
|
||||
@@ -559,6 +765,36 @@ ventoy_create_dev_ventoy_part() {
|
||||
|
||||
vtPartid=$(expr $vtPartid + 1)
|
||||
done
|
||||
|
||||
if [ -f $VTOY_PATH/dm_patch_done ]; then
|
||||
#recover printk level
|
||||
echo $vtLevel1 $vtLevel2 $vtLevel3 $vtLevel4 > /proc/sys/kernel/printk
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
ventoy_create_chromeos_ventoy_part() {
|
||||
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | $GREP ventoy | $SED 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
|
||||
$BUSYBOX_PATH/mknod -m 0666 /dev/ventoy b $blkdev_num
|
||||
|
||||
if [ -e /vtoy_dm_table ]; then
|
||||
vtPartid=1
|
||||
|
||||
$CAT /vtoy_dm_table | while read vtline; do
|
||||
echo $vtline > /ventoy/dm_table_part${vtPartid}
|
||||
|
||||
if [ $vtPartid -eq $1 ]; then
|
||||
$VTOY_PATH/tool/dmsetup create ventoy${vtPartid} /ventoy/dm_table_part${vtPartid} --readonly
|
||||
else
|
||||
$VTOY_PATH/tool/dmsetup create ventoy${vtPartid} /ventoy/dm_table_part${vtPartid}
|
||||
fi
|
||||
|
||||
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | $GREP ventoy${vtPartid} | $SED 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
|
||||
$BUSYBOX_PATH/mknod -m 0666 /dev/ventoy${vtPartid} b $blkdev_num
|
||||
|
||||
vtPartid=$(expr $vtPartid + 1)
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -573,7 +809,12 @@ is_inotify_ventoy_part() {
|
||||
fi
|
||||
|
||||
if [ -e /dev/$vtShortName ]; then
|
||||
$VTOY_PATH/tool/vtoydump -f $VTOY_PATH/ventoy_os_param -c $vtShortName
|
||||
if [ "$VTOY_VLNK_BOOT" = "01" ]; then
|
||||
vtOrgDiskName=$($VTOY_PATH/tool/vtoydump -t $VTOY_PATH/ventoy_os_param)
|
||||
[ "$vtOrgDiskName" = "/dev/$vtShortName" ]
|
||||
else
|
||||
$VTOY_PATH/tool/vtoydump -f $VTOY_PATH/ventoy_os_param -c $vtShortName
|
||||
fi
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
@@ -77,12 +77,16 @@ ventoy_unpack_initramfs() {
|
||||
if [ "${vtx:5}" = "xzcat" ]; then
|
||||
rm -f $VTOY_PATH/xzlog
|
||||
${vtx:5} $vtfile 2> $VTOY_PATH/xzlog | (cpio -idmu 2>>$VTLOG; cat > $vttmp)
|
||||
|
||||
if grep -q 'corrupted data' $VTOY_PATH/xzlog; then
|
||||
echo 'xzcat failed, now try xzminidec...' >> $VTLOG
|
||||
cat $vtfile | xzminidec | (cpio -idmu 2>>$VTLOG; cat > $vttmp)
|
||||
fi
|
||||
rm -f $VTOY_PATH/xzlog
|
||||
cat $vtfile | xzminidec 2> $VTOY_PATH/xzlog | (cpio -idmu 2>>$VTLOG; cat > $vttmp)
|
||||
|
||||
if grep -q 'limit' $VTOY_PATH/xzlog; then
|
||||
echo 'xzminidec failed, now try xzcat_musl ...' >> $VTLOG
|
||||
xzcat_musl $vtfile | (cpio -idmu 2>>$VTLOG; cat > $vttmp)
|
||||
fi
|
||||
fi
|
||||
else
|
||||
${vtx:5} $vtfile | (cpio -idmu 2>>$VTLOG; cat > $vttmp)
|
||||
fi
|
||||
|
205
IMG/cpio/ventoy/loop/cloudready/ventoy-hook.sh
Normal file
205
IMG/cpio/ventoy/loop/cloudready/ventoy-hook.sh
Normal file
@@ -0,0 +1,205 @@
|
||||
#!/ventoy/busybox/sh
|
||||
#************************************************************************************
|
||||
# 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/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
. /ventoy/hook/ventoy-hook-lib.sh
|
||||
|
||||
vtlog "####### $0 $* ########"
|
||||
|
||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||
|
||||
mkdir /sys
|
||||
mount -t sysfs sys /sys
|
||||
mdev -s
|
||||
sleep 2
|
||||
|
||||
while [ -n "Y" ]; do
|
||||
usb_disk=$(get_ventoy_disk_name)
|
||||
|
||||
if echo $usb_disk | egrep -q "nvme|mmc|nbd"; then
|
||||
vtpart2=${usb_disk}p2
|
||||
else
|
||||
vtpart2=${usb_disk}2
|
||||
fi
|
||||
|
||||
if [ -e "${vtpart2}" ]; then
|
||||
break
|
||||
else
|
||||
sleep 2
|
||||
mdev -s
|
||||
fi
|
||||
done
|
||||
|
||||
vtdiskname=$(get_ventoy_disk_name)
|
||||
if [ "$vtdiskname" = "unknown" ]; then
|
||||
vtlog "ventoy disk not found"
|
||||
PATH=$VTPATH_OLD
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
|
||||
|
||||
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
|
||||
vtDM=$(ventoy_find_dm_id ${blkdev_num})
|
||||
echo -n $vtDM > /ventoy/vtDM
|
||||
|
||||
ventoy_create_chromeos_ventoy_part 3
|
||||
mdev -s
|
||||
|
||||
vtlog "copy out the e2fsck program ..."
|
||||
|
||||
copy_lib() {
|
||||
cp -a /ventoy_rdroot/usr/lib64/$1 /usr/lib64/
|
||||
cp -a /ventoy_rdroot/lib64/$1 /lib64/
|
||||
}
|
||||
|
||||
mkdir /ventoy_rdroot
|
||||
mkdir -p /lib /lib64 /usr/lib64 /sbin
|
||||
|
||||
mount -o ro /dev/ventoy3 /ventoy_rdroot >>$VTLOG 2>&1
|
||||
cp -a /ventoy_rdroot/sbin/e2fsck /sbin/
|
||||
cp -a /ventoy_rdroot/sbin/dmsetup /sbin/
|
||||
|
||||
copy_lib libext2fs*
|
||||
copy_lib libcom_err*
|
||||
copy_lib libe2p*
|
||||
copy_lib libblk*
|
||||
copy_lib libuuid*
|
||||
copy_lib libdl.*
|
||||
copy_lib libdl-*
|
||||
copy_lib libc.*
|
||||
copy_lib libc-*
|
||||
copy_lib libpthread*
|
||||
copy_lib ld-*
|
||||
copy_lib libdevmapper*
|
||||
copy_lib libudev*
|
||||
copy_lib libm.*
|
||||
copy_lib libm-*
|
||||
copy_lib librt*
|
||||
copy_lib libpopt*
|
||||
copy_lib libgpg-error*
|
||||
copy_lib libselinux*
|
||||
copy_lib libsepol*
|
||||
copy_lib libpcre*
|
||||
copy_lib libcap*
|
||||
copy_lib libdw*
|
||||
copy_lib libgcc_s*
|
||||
copy_lib libattr*
|
||||
copy_lib libelf*
|
||||
copy_lib libz.*
|
||||
copy_lib libbz2*
|
||||
copy_lib libgcrypt*
|
||||
copy_lib liblvm*
|
||||
|
||||
ln -s /lib64/libdevmapper.so.1.02 /lib64/libdevmapper.so.1.02.1
|
||||
|
||||
umount /ventoy_rdroot
|
||||
|
||||
vtlog "========================================="
|
||||
vtlog "===== e2fsck -y -v /dev/ventoy1 ====="
|
||||
e2fsck -y -v /dev/ventoy1 >>$VTLOG 2>&1
|
||||
#vtlog "===== e2fsck -y -v /dev/ventoy3 ====="
|
||||
#e2fsck -y -v /dev/ventoy3 >>$VTLOG 2>&1
|
||||
vtlog "===== e2fsck -y -v /dev/ventoy8 ====="
|
||||
e2fsck -y -v /dev/ventoy8 >>$VTLOG 2>&1
|
||||
vtlog "========================================="
|
||||
|
||||
/sbin/dmsetup --version >>$VTLOG 2>&1
|
||||
veritysetup --version >>$VTLOG 2>&1
|
||||
|
||||
vtlog "proc devtmpfs ..."
|
||||
mkdir /newdev
|
||||
mount -t devtmpfs dev /newdev
|
||||
|
||||
cp -a /dev/mapper/ventoy* /newdev/mapper/
|
||||
cp -a /dev/ventoy* /newdev/
|
||||
|
||||
if [ "$VTOY_VLNK_BOOT" = "01" ]; then
|
||||
vtLine=$($VTOY_PATH/tool/vtoydump -f /ventoy/ventoy_os_param)
|
||||
vtdiskname=${vtLine%%#*}
|
||||
fi
|
||||
|
||||
vtshortname="${vtdiskname#/dev/}"
|
||||
mv /newdev/${vtshortname} /newdev/backup_${vtshortname}
|
||||
cp -a /dev/ventoy /newdev/${vtshortname}
|
||||
|
||||
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
|
||||
if [ -e /dev/ventoy${i} ]; then
|
||||
if echo $vtdiskname | egrep -q "nvme|mmc|nbd"; then
|
||||
vtpart=p$i
|
||||
else
|
||||
vtpart=$i
|
||||
fi
|
||||
|
||||
if [ -e /newdev/${vtshortname}${vtpart} ]; then
|
||||
mv /newdev/${vtshortname}${vtpart} /newdev/backup_${vtshortname}${vtpart}
|
||||
fi
|
||||
|
||||
cp -a /dev/ventoy${i} /newdev/${vtshortname}${vtpart}
|
||||
|
||||
if [ $i -eq 3 ]; then
|
||||
[ -e /dev/${vtshortname}${vtpart} ] && rm -f /dev/${vtshortname}${vtpart}
|
||||
cp -a /dev/ventoy${i} /dev/${vtshortname}${vtpart}
|
||||
vt_root_dev="/dev/${vtshortname}${vtpart}"
|
||||
vtlog "vt_root_dev=$vt_root_dev"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
# if grep -q 'DM=' /proc/cmdline; then
|
||||
# vtlog "Boot verified image ..."
|
||||
|
||||
# dmP1=$(sed "s/.*\(0 [0-9]* verity\).*/\1/" /proc/cmdline)
|
||||
# alg=$(sed "s/.*alg=\([^ ]*\).*/\1/" /proc/cmdline)
|
||||
# hexdigest=$(sed "s/.*root_hexdigest=\([0-9a-fA-F][0-9a-fA-F]*\).*/\1/" /proc/cmdline)
|
||||
# salt=$(sed "s/.*salt=\([0-9a-fA-F][0-9a-fA-F]*\).*/\1/" /proc/cmdline)
|
||||
# hashstart=$(sed "s/.*hashstart=\([0-9][0-9]*\).*/\1/" /proc/cmdline)
|
||||
|
||||
#512 to 4096
|
||||
# blocknum=$(expr $hashstart / 8)
|
||||
# hashoffset=$(expr $hashstart \* 512)
|
||||
|
||||
# vtlog "veritysetup create vroot $vt_root_dev $vt_root_dev $hexdigest --data-block-size=4096 --hash-block-size=4096 --data-blocks=$blocknum --hash-offset=$hashoffset --salt=$salt --hash=$alg --no-superblock --format=0"
|
||||
# veritysetup create vroot $vt_root_dev $vt_root_dev $hexdigest --data-block-size=4096 --hash-block-size=4096 --data-blocks=$blocknum --hash-offset=$hashoffset --salt=$salt --hash=$alg --no-superblock --format=0
|
||||
# sleep 1
|
||||
# mdev -s
|
||||
|
||||
# blkdev_num=$(dmsetup ls | grep vroot | sed 's/.*(\([0-9][0-9]*\),[^0-9]*\([0-9][0-9]*\).*/\1:\2/')
|
||||
# vtDM=$(ventoy_find_dm_id ${blkdev_num})
|
||||
# vtlog "blkdev_num=$blkdev_num vtDM=$vtDM"
|
||||
|
||||
# if [ -b /dev/$vtDM ]; then
|
||||
# veritysetup status vroot >> $VTLOG 2>&1
|
||||
# mount -o ro /dev/$vtDM /ventoy_rdroot
|
||||
# else
|
||||
# mount -o ro $vt_root_dev /ventoy_rdroot
|
||||
# fi
|
||||
# else
|
||||
# vtlog "Boot normal image ..."
|
||||
# mount -o ro $vt_root_dev /ventoy_rdroot
|
||||
# fi
|
||||
|
||||
vtlog "Boot normal image ..."
|
||||
mount -o ro $vt_root_dev /ventoy_rdroot
|
||||
|
||||
cp -a $VTLOG /newdev/ventoy.log
|
||||
umount /newdev
|
||||
mount -t devtmpfs dev /ventoy_rdroot/dev
|
||||
|
||||
PATH=$VTPATH_OLD
|
47
IMG/cpio/ventoy/loop/esysrescue/ventoy-disk.sh
Normal file
47
IMG/cpio/ventoy/loop/esysrescue/ventoy-disk.sh
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/ventoy/busybox/sh
|
||||
#************************************************************************************
|
||||
# Copyright (c) 2020, longpanda <admin@ventoy.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
. /ventoy/hook/ventoy-hook-lib.sh
|
||||
|
||||
if is_ventoy_hook_finished; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
vtlog "####### $0 $* ########"
|
||||
|
||||
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
|
||||
|
||||
wait_for_usb_disk_ready
|
||||
|
||||
vtdiskname=$(get_ventoy_disk_name)
|
||||
if [ "$vtdiskname" = "unknown" ]; then
|
||||
vtlog "ventoy disk not found"
|
||||
PATH=$VTPATH_OLD
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
|
||||
|
||||
ventoy_create_dev_ventoy_part
|
||||
|
||||
ln -s "../../ventoy1" /dev/disk/by-label/ESYSRESCUE
|
||||
|
||||
PATH=$VTPATH_OLD
|
||||
|
||||
set_ventoy_hook_finish
|
26
IMG/cpio/ventoy/loop/esysrescue/ventoy-hook.sh
Normal file
26
IMG/cpio/ventoy/loop/esysrescue/ventoy-hook.sh
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/ventoy/busybox/sh
|
||||
#************************************************************************************
|
||||
# Copyright (c) 2020, longpanda <admin@ventoy.net>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#************************************************************************************
|
||||
|
||||
. $VTOY_PATH/hook/ventoy-os-lib.sh
|
||||
|
||||
$SED "/maybe_break premount/i\ $BUSYBOX_PATH/sh $VTOY_PATH/loop/esysrescue/ventoy-disk.sh" -i /init
|
||||
|
||||
if [ -f /scripts/casper-bottom/09format_esr_data_partition ]; then
|
||||
$SED '/mkfs.vfat.*edev.3/icp -a /dev/dm-3 /dev/ventoy3' -i /scripts/casper-bottom/09format_esr_data_partition
|
||||
fi
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user