Compare commits

...

60 Commits

Author SHA1 Message Date
longpanda
fb7008f49a 1.0.31 release 2020-12-23 19:49:12 +08:00
longpanda
463d0b2004 rebuild lz4cat64 2020-12-22 22:41:31 +08:00
longpanda
4707b76bb2 Rebuild some binaries with musl-libc to avoid virus false positive (issue #660) 2020-12-22 21:21:44 +08:00
longpanda
ff0ad76d8d add support for latest blackarch distro (issue #654) 2020-12-17 16:40:53 +08:00
longpanda
c8b2cca7c2 add support for austrumi (issue #637) 2020-12-17 16:12:46 +08:00
longpanda
afbeba7cf5 fix issue #614 2020-12-17 16:11:17 +08:00
BL4CKH47H4CK3R
bb3789f6fc Set default label from ventoy to Ventoy (#656)
Windows version has default label Ventoy instead of ventoy.
Commited just for beautifications !
2020-12-17 12:33:02 +08:00
longpanda
ea8a9e83ab workaround for 2TB+ disk 2020-12-16 23:08:36 +08:00
longpanda
8b9901a6a5 add austrumi support.(issue #637) 2020-12-15 17:42:15 +08:00
longpanda
0ac83bffda support Anarchy Linux 1.3.1 issue #642 2020-12-15 16:21:41 +08:00
longpanda
40c0504dfb 1.0.30 release 2020-12-12 17:42:45 +08:00
longpanda
ebaa4d954a IA32 ARM64 support 2020-12-12 07:56:52 +08:00
longpanda
2936666a78 Code Optimize 2020-12-12 07:40:33 +08:00
longpanda
784e3ae879 add class for submenu of 'Ventoy UEFI Utilities' 2020-11-26 14:51:13 +08:00
longpanda
d8fbd79dda 1.0.29 release 2020-11-19 20:45:17 +08:00
David P
8c192a1807 grub.cfg: add support for new Parabola ISOs (#590) 2020-11-16 11:48:41 +08:00
longpanda
e8d17f9bb1 1.0.28 release 2020-11-14 12:29:01 +08:00
longpanda
2283c3e8b0 update README.md 2020-11-13 22:15:24 +08:00
longpanda
8bbd5a14a3 最近收到一些特殊的错误报告,最后证明是非标准的Ventoy环境的原因。尤其是单分区下环境下使用 Ventoy 。
虽然 Ventoy 显示了 Unofficial 的标注信息,但是用户并不会关心,仍然会认为是 Ventoy 的问题。

Ventoy 从一开始就是一个整体的设计,并没有考虑过集成在其他bootloader或分区环境中。
Ventoy 的验证和后续新功能开发也都不会考虑这种非标准的使用方式。

因此,我决定禁止 Ventoy 在非标准环境下的使用,并且不再接受放开检查的请求。

当然,这个只是Ventoy的默认行为。Ventoy仍然是100%开源的,如果你希望把Ventoy应用在自己的环境中,你可以fork一个分支,然后修改源代码实现。
2020-11-13 16:39:15 +08:00
Victor B
f7d7db6a18 Fix typo in BuildVentoyFromSource.txt (#580) 2020-11-09 15:25:19 +08:00
longpanda
147a23c9dd 1.0.27 release 2020-10-31 19:06:30 +08:00
longpanda
062c71b972 fix a bug about VTOY_DEFAULT_IMAGE in treeview mode issue #555 2020-10-31 13:38:13 +08:00
longpanda
78ab7a0759 1.0.26 release 2020-10-24 06:26:57 +08:00
longpanda
3ebd58c9df support original order in image_list plugin 2020-10-22 09:34:46 +08:00
longpanda
ce6d379564 1.0.25 release 2020-10-21 20:33:15 +08:00
longpanda
40fdfa66b9 Optimization for Linux vDisk boot in Legacy BIOS mode 2020-10-21 17:45:44 +08:00
longpanda
9ddee7394d support different themes for Legacy BIOS mode and UEFI mode 2020-10-21 17:15:31 +08:00
longpanda
c9b316a757 Fix bug for VTOY_DEFAULT_IMAGE in TreeView mode when VTOY_DEFAULT_SEARCH_ROOT was set. 2020-10-21 13:17:29 +08:00
longpanda
1ba23bcdff add image_list plugin 2020-10-21 10:23:58 +08:00
longpanda
6630ab3585 1.0.24 release 2020-10-17 15:56:54 +08:00
longpanda
c0d478c2dd 1.0.23 release 2020-10-16 20:26:24 +08:00
longpanda
0217c5a923 fix issue #521
blackarch boot failed
2020-10-15 17:50:22 +08:00
longpanda
97312d351e fix issue #516
Arch 2020.10.1 iso boot failed in UEFI mode.
2020-10-09 19:57:35 +08:00
David P
906dc4cd41 fix Parabola EFI booting (#508) 2020-10-09 09:41:04 +08:00
longpanda
82a8b59bc7 fix issue #512
show file with name .iso
2020-10-08 17:13:40 +08:00
longpanda
b53e1fb8a8 1.0.22 release 2020-09-27 22:20:37 +08:00
longpanda
84abffc424 theme 2020-09-27 17:31:02 +08:00
longpanda
bf4e014023 linux raw boot 2020-09-27 17:23:59 +08:00
longpanda
4f840ed673 Merge branch 'master' of https://github.com/ventoy/Ventoy 2020-09-26 00:05:27 +08:00
longpanda
d02f184a8d add support for linux vdisk(vhd/vdi/raw) 2020-09-26 00:04:56 +08:00
longpanda
774e38928f update VentoyWorker.sh for nvme 2020-09-18 11:49:18 +08:00
David P
0faba673a5 fix Parabola systemd-boot loader (#473) 2020-09-14 09:56:12 +08:00
longpanda
3c649b281f update README.md 2020-09-13 14:47:44 +08:00
longpanda
5f409a1208 Fix a bug with error message null src bitmap in grub_video_bitmap_create_scaled 2020-09-13 14:43:57 +08:00
longpanda
9eb334d99a 1.0.21 release 2020-09-12 22:31:21 +08:00
longpanda
260a3269b7 Merge branch 'master' of https://github.com/ventoy/Ventoy
# Conflicts:
#	INSTALL/ventoy/ventoy.cpio
2020-09-12 02:49:39 +08:00
longpanda
a287bf8907 vhd boot
live cd
fix bug
2020-09-12 02:46:44 +08:00
longpanda
48a1b80be0 update 2020-09-03 16:45:18 +08:00
longpanda
b9ef72fbe9 Fix issue #456 2020-09-03 16:43:21 +08:00
longpanda
390507fff7 Fix issue #456 2020-09-03 16:40:26 +08:00
longpanda
a29bdfbc3c LiveCD 2020-09-03 07:46:36 +08:00
longpanda
21735f92d6 Merge branch 'master' of https://github.com/ventoy/Ventoy 2020-09-02 19:29:43 +08:00
longpanda
9a8d4d0227 update 2020-09-02 19:29:19 +08:00
longpanda
6ebe77792c Update README.md 2020-08-30 21:59:09 +08:00
longpanda
d678e54956 1.0.20 release 2020-08-30 16:34:20 +08:00
longpanda
8dce0adda6 update for new release 2020-08-29 13:12:46 +08:00
Dylan M. Taylor
1bf3e73373 Add Continuous Integration to the Project using GitHub Actions (#410)
* Create GitHub Action File for CI

* Rename c-cpp.yml to ci.yml

* Update ci.yml

* Update ci.yml

* Update ci.yml

* Update ci.yml

* Update ci.yml

* Update ci.yml

* Update ci.yml

* Update ci.yml

* Update ci.yml

* Update ci.yml
2020-08-23 21:28:56 +08:00
longpanda
a9996d6761 Update README.md 2020-08-23 16:15:02 +08:00
longpanda
dafea731c8 Update README.md 2020-08-23 16:05:27 +08:00
longpanda
6d093e88e7 update languages.ini
Add hebrew language, translated by chaim-chv
2020-08-17 22:50:55 +08:00
668 changed files with 21019 additions and 2490 deletions

24
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,24 @@
name: Ventoy CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run docker-compose up
run: docker-compose up
- uses: actions/upload-artifact@v2
with:
name: ventoy-linux
path: INSTALL/ventoy-*linux*
- uses: actions/upload-artifact@v2
with:
name: ventoy-windows
path: INSTALL/ventoy-*windows*

File diff suppressed because it is too large Load Diff

1166
BUSYBOX/aarch64_xzcat.config Normal file

File diff suppressed because it is too large Load Diff

36
BUSYBOX/build.txt Normal file
View File

@@ -0,0 +1,36 @@
======== How to build ash/hexdump/xzcat for aarch64 ========
#How to get ash.config/hexdump.cofig/xzcat.config
#ARCH=arm64 CROSS_COMPILE=aarch64-linux- make allnoconfig
#ARCH=arm64 CROSS_COMPILE=aarch64-linux- make menuconfig
#----> enable static build
#----> enable xzcat
#get aarch64_xzcat.config
tar xf busybox-1.32.0.tar.bz2
cd busybox-1.32.0
copy aarch64_xzcat.config as .config
ARCH=arm64 CROSS_COMPILE=aarch64-linux- make
rename ./busybox to xzcat
======== How to build ash/hexdump/xzcat for x86_64 ==========
#How to get ash.config/hexdump.cofig/xzcat.config
#make allnoconfig
#make menuconfig
#----> enable static build
#----> enable xzcat
#get x86_64_xzcat.config
tar xf busybox-1.32.0.tar.bz2
cd busybox-1.32.0
copy x86_64_xzcat.config as .config
modify Makefile
CC = gcc -specs "/usr/local/musl/lib/musl-gcc.specs"
MODFLAGS = -DMODULE -specs "/usr/local/musl/lib/musl-gcc.specs"
make
rename ./busybox to xzcat

View File

@@ -2,17 +2,24 @@
DSTDIR=../../IMG/cpio/ventoy/busybox DSTDIR=../../IMG/cpio/ventoy/busybox
rm -f vtchmod32 vtchmod64 rm -f vtchmod32 vtchmod64 vtchmod64_musl vtchmodaa64
rm -f $DSTDIR/vtchmod32 $DSTDIR/vtchmod64 rm -f $DSTDIR/vtchmod32 $DSTDIR/vtchmod64 $DSTDIR/vtchmodaa64
/opt/diet32/bin/diet gcc -Os -m32 vtchmod.c -o vtchmod32 /opt/diet32/bin/diet gcc -Os -m32 vtchmod.c -o vtchmod32
/opt/diet64/bin/diet gcc -Os vtchmod.c -o vtchmod64 /opt/diet64/bin/diet gcc -Os vtchmod.c -o vtchmod64
aarch64-linux-gcc -Os -static vtchmod.c -o vtchmodaa64
aarch64-linux-strip --strip-all vtchmodaa64
gcc -specs "/usr/local/musl/lib/musl-gcc.specs" -Os -static vtchmod.c -o vtchmod64_musl
strip --strip-all vtchmod64_musl
chmod 777 vtchmod32 chmod 777 vtchmod32
chmod 777 vtchmod64 chmod 777 vtchmod64
chmod 777 vtchmodaa64
chmod 777 vtchmod64_musl
cp -a vtchmod32 $DSTDIR/ cp -a vtchmod32 $DSTDIR/
cp -a vtchmod64 $DSTDIR/ cp -a vtchmod64 $DSTDIR/
cp -a vtchmodaa64 $DSTDIR/
cp -a vtchmod64_musl $DSTDIR/

Binary file not shown.

BIN
BUSYBOX/chmod/vtchmodaa64 Normal file

Binary file not shown.

1181
BUSYBOX/config Normal file

File diff suppressed because it is too large Load Diff

1166
BUSYBOX/x86_64_ash.config Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

1166
BUSYBOX/x86_64_xzcat.config Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,49 +1,60 @@
Build a static linked, small dmsetup tool Build a static linked, small dmsetup tool
======== Source Code ======== ======== Source Code ========
use an old version of dmsetup use an old version of dmsetup
http://vault.centos.org/5.3/os/SRPMS/device-mapper-1.02.28-2.el5.src.rpm http://vault.centos.org/5.3/os/SRPMS/device-mapper-1.02.28-2.el5.src.rpm
https://www.fefe.de/dietlibc/dietlibc-0.34.tar.xz https://www.fefe.de/dietlibc/dietlibc-0.34.tar.xz
======== Build Envrioment ======== ======== Build Envrioment ========
build for 32bit, static linked with dietlibc build for 32bit, static linked with dietlibc
1. install centos 6.10 i386 with CentOS-6.10-i386-bin-DVD1.iso 1. install centos 6.10 i386 with CentOS-6.10-i386-bin-DVD1.iso
2. yum install gcc kernel-devel package 2. yum install gcc kernel-devel package
3. install dietc libc (just make && make install) 3. install dietc libc (just make && make install)
4. export PATH=$PATH:/opt/diet/bin 4. export PATH=$PATH:/opt/diet/bin
======== Build Step ======== ======== Build Step ========
1. extract device mapper source code 1. extract device mapper source code
2. CC="diet gcc" ./configure --disable-nls --disable-selinux --disable-shared 2. CC="diet gcc" ./configure --disable-nls --disable-selinux --disable-shared
3. modify include/configure.h file 3. modify include/configure.h file
--- delete the line with "#define malloc rpl_malloc" --- delete the line with "#define malloc rpl_malloc"
--- add 2 defines as follow: --- add 2 defines as follow:
#ifndef UINT32_MAX #ifndef UINT32_MAX
#define UINT32_MAX (4294967295U) #define UINT32_MAX (4294967295U)
#endif #endif
#ifndef UINT64_C #ifndef UINT64_C
#define UINT64_C(c) c ## ULL #define UINT64_C(c) c ## ULL
#endif #endif
4. make 4. make
5. strip dmsetup/dmsetup 5. strip dmsetup/dmsetup
6. get dmsetup/dmsetup as the dmsetup32 binary file 6. get dmsetup/dmsetup as the dmsetup32 binary file
======================== Build for 64bit dmsetup ========================= ======================== Build for 64bit dmsetup =========================
https://www.uclibc.org/downloads/binaries/0.9.30.1/mini-native-x86_64.tar.bz2 1. extract device mapper source code
1. extract device mapper source code 2. ./configure --disable-nls --disable-selinux --disable-shared --enable-static_link CC='gcc -specs /usr/local/musl/lib/musl-gcc.specs'
2. extract mini-native-x86_64.tar.bz2 3. touch include/linux/limits.h include/linux/types.h
3. chroot to mini-native-x86_64 echo '#include <sys/mount.h>' > include/linux/fs.h
3. ./configure --disable-nls --disable-selinux --disable-shared --enable-static_link 4. make
4. make 5. strip --strip-all dmsetup/dmsetup.static
5. strip dmsetup/dmsetup.static 6. get dmsetup/dmsetup.static as the dmsetup64 binary file
6. get dmsetup/dmsetup.static as the dmsetup64 binary file
======================== Build for arm64 dmsetup =========================
1. extract device mapper source code
2. ./configure CC=aarch64-linux-gcc --target=arm --host=x86_64-linux-gnu --disable-nls --disable-selinux --disable-shared --enable-static_link
3. modify include/configure.h file
--- delete the line with "#define malloc rpl_malloc"
4. make
5. aarch64-linux-strip dmsetup/dmsetup.static
6. get dmsetup/dmsetup.static as the dmsetupaa64 binary file

Binary file not shown.

BIN
DMSETUP/dmsetupaa64 Normal file

Binary file not shown.

View File

@@ -1,220 +1,248 @@
========================================== ==========================================
1. Compile Enviroment 1. Compile Enviroment
========================================== ==========================================
My build envrioment is CentOS 7.8 x86_64. So here I first explain how to create the build environment from scratch. My build envrioment is CentOS 7.8 x86_64. So here I first explain how to create the build environment from scratch.
Because Ventoy is based on many open source projects, so the envrioment is important. I suggest you test it on a virtual machine first. Because Ventoy is based on many open source projects, so the environment is important. I suggest you test it on a virtual machine first.
1.1 Install CentOS 7.8 1.1 Install CentOS 7.8
I use CentOS-7-x86_64-Everything-2003.iso and select Minimal install I use CentOS-7-x86_64-Everything-2003.iso and select Minimal install
1.2 Install Packages 1.2 Install Packages
yum install \ yum install \
libXpm net-tools bzip2 wget vim gcc gcc-c++ samba dos2unix glibc-devel glibc.i686 glibc-devel.i686 \ libXpm net-tools bzip2 wget vim gcc gcc-c++ samba dos2unix glibc-devel glibc.i686 glibc-devel.i686 \
mpfr.i686 mpfr-devel.i686 zlib.i686 rsync autogen autoconf automake libtool gettext* bison binutils \ mpfr.i686 mpfr-devel.i686 zlib.i686 rsync autogen autoconf automake libtool gettext* bison binutils \
flex device-mapper-devel SDL libpciaccess libusb freetype freetype-devel gnu-free-* qemu-* virt-* \ 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 \ 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 iscsi-initiator-utils grub2-tools zip nasm acpica-tools glibc-static zlib-static
========================================== ==========================================
2. Download Source Code 2. Download Source Code
========================================== ==========================================
2.1 Download Ventoy source code from github and decompress it. 2.1 Download Ventoy source code from github and decompress it.
Next I assume that you have unzipped the code into the /home directory (check /home/Ventoy-master/README.md file for the directory level). Next I assume that you have unzipped the code into the /home directory (check /home/Ventoy-master/README.md file for the directory level).
2.2 Download third-part source code 2.2 Download third-part source code
https://www.fefe.de/dietlibc/dietlibc-0.34.tar.xz ===> /home/Ventoy-master/DOC/dietlibc-0.34.tar.xz https://www.fefe.de/dietlibc/dietlibc-0.34.tar.xz ===> /home/Ventoy-master/DOC/dietlibc-0.34.tar.xz
https://ftp.gnu.org/gnu/grub/grub-2.04.tar.xz ===> /home/Ventoy-master/GRUB2/grub-2.04.tar.xz https://musl.libc.org/releases/musl-1.2.1.tar.gz ===> /home/Ventoy-master/DOC/musl-1.2.1.tar.gz
https://codeload.github.com/tianocore/edk2/zip/edk2-stable201911 ===> /home/Ventoy-master/EDK2/edk2-edk2-stable201911.zip https://ftp.gnu.org/gnu/grub/grub-2.04.tar.xz ===> /home/Ventoy-master/GRUB2/grub-2.04.tar.xz
https://codeload.github.com/relan/exfat/zip/v1.3.0 ===> /home/Ventoy-master/ExFAT/exfat-1.3.0.zip https://codeload.github.com/tianocore/edk2/zip/edk2-stable201911 ===> /home/Ventoy-master/EDK2/edk2-edk2-stable201911.zip
https://codeload.github.com/libfuse/libfuse/zip/fuse-2.9.9 ===> /home/Ventoy-master/ExFAT/libfuse-fuse-2.9.9.zip https://codeload.github.com/relan/exfat/zip/v1.3.0 ===> /home/Ventoy-master/ExFAT/exfat-1.3.0.zip
https://codeload.github.com/libfuse/libfuse/zip/fuse-2.9.9 ===> /home/Ventoy-master/ExFAT/libfuse-fuse-2.9.9.zip
https://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/aarch64-linux-gnu/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz ===> /opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz
https://toolchains.bootlin.com/downloads/releases/toolchains/aarch64/tarballs/aarch64--uclibc--stable-2020.08-1.tar.bz2 ===> /opt/aarch64--uclibc--stable-2020.08-1.tar.bz2
==========================================
3. All in one script 2.3 Prepare third-part tools
========================================== cd /home/Ventoy-master/DOC/
I have made the whole build process in all_in_one.sh, you can run this script to build and pack ventoy. tar xf musl-1.2.1.tar.gz
If you want to compile a certain part separately, you can continue to refer to the later chapters of this text. cd musl-1.2.1
./configure && make install
cd /home/Ventoy-master/INSTALL
sh all_in_one.sh tar xf /opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz -C /opt
tar xf /opt/aarch64--uclibc--stable-2020.08-1.tar.bz2 -C /opt
It should be noted that, some part of Ventoy has 32bit&64bit version (like 4.9 4.10 4.11 follows)
all_in_one.sh only build 64bit version of them, if you want to rebuild the 32bit verison. You should create a 32bit CentOS environment and build them. 2.4 Set PATH envrioment
Fortunately these parts are few modified, you only need to build once or you can directly use the binary I have built. export PATH=$PATH:/opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin:/opt/aarch64--uclibc--stable-2020.08-1/bin
better to add this line to /root/.bashrc and relogin as root
Besides, after a fully compile and pack, you can only build the part you modified (for example grub2) and run ventoy_pack.sh to generate the package.
==========================================
3. All in one script
========================================== ==========================================
4. Build every part of Ventoy I have made the whole build process in all_in_one.sh, you can run this script to build and pack ventoy.
========================================== If you want to compile a certain part separately, you can continue to refer to the later chapters of this text.
4.1 == Build grub2 ==
cd /home/Ventoy-master/GRUB2 cd /home/Ventoy-master/INSTALL
sh buildgrub.sh sh all_in_one.sh
4.2 == Build ipxe.krn == It should be noted that, some part of Ventoy has 32bit&64bit version (like 4.9 4.10 4.11 follows)
cd /home/Ventoy-master/IPXE all_in_one.sh only build 64bit version of them, if you want to rebuild the 32bit verison. You should create a 32bit CentOS environment and build them.
sh buildipxe.sh Fortunately these parts are few modified, you only need to build once or you can directly use the binary I have built.
4.3 == Build Ventoy2Disk.exe == Besides, after a fully compile and pack, you can only build the part you modified (for example grub2) and run ventoy_pack.sh to generate the package.
Ventoy2Disk.exe is the installer in Windows platform. And it must be built in Windows with Microsoft Visual Studio (2013+).
Open /home/Ventoy-master/Ventoy2Disk/Ventoy2Disk.sln with Visual Studio and build it.
4.4 == Build vtoyjump64.exe/vtoyjump32.exe == ==========================================
vtoyjump64.exe/vtoyjump32.exe is used to mount iso file in windows PE. You should install Microsoft Visual Studio (2013+) to build it. 4. Build every part of Ventoy
Open /home/Ventoy-master/vtoyjump/vtoyjump.sln with Visual Studio and build it (64&32). ==========================================
4.1 == Build grub2 ==
4.5 == Build dmsetup == cd /home/Ventoy-master/GRUB2
Please refer to DMSETUP/build.txt sh buildgrub.sh
4.6 == Build ventoy_x64.efi == 4.2 == Build ipxe.krn ==
cd /home/Ventoy-master/EDK2 cd /home/Ventoy-master/IPXE
sh buildedk.sh sh buildipxe.sh
4.7 == Build VtoyTool == 4.3 == Build Ventoy2Disk.exe ==
cd /home/Ventoy-master/VtoyTool Ventoy2Disk.exe is the installer in Windows platform. And it must be built in Windows with Microsoft Visual Studio (2013+).
sh build.sh Open /home/Ventoy-master/Ventoy2Disk/Ventoy2Disk.sln with Visual Studio and build it.
4.8 == Build vtoyfat == 4.4 == Build vtoyjump64.exe/vtoyjump32.exe ==
cd /home/Ventoy-master/vtoyfat/fat_io_lib vtoyjump64.exe/vtoyjump32.exe is used to mount iso file in windows PE. You should install Microsoft Visual Studio (2013+) to build it.
sh buildlib.sh Open /home/Ventoy-master/vtoyjump/vtoyjump.sln with Visual Studio and build it (64&32).
cd /home/Ventoy-master/vtoyfat
sh build.sh 4.5 == Build dmsetup ==
Please refer to DMSETUP/build.txt
4.9 == Build exfat-util ==
cd /home/Ventoy-master/ExFAT 4.6 == Build ventoy_x64.efi ==
sh buidlibfuse.sh cd /home/Ventoy-master/EDK2
sh buidexfat.sh sh buildedk.sh
After that, copy EXFAT/shared/mkexfatfs ===> /home/Ventoy-master/INSTALL/tool/mkexfatfs_64 4.7 == Build VtoyTool ==
After that, copy EXFAT/shared/mount.exfat-fuse ===> /home/Ventoy-master/INSTALL/tool/mount.exfat-fuse_64 cd /home/Ventoy-master/VtoyTool
sh build.sh
Use the same build step to build exfat-util 32bit in a 32bit CentOS system and get mkexfatfs_32 and mount.exfat-fuse_32
4.8 == Build vtoyfat ==
4.10 == Build vtoy_fuse_iso_64/vtoy_fuse_iso_32 == cd /home/Ventoy-master/vtoyfat/fat_io_lib
cd /home/Ventoy-master/FUSEISO sh buildlib.sh
sh build_libfuse.sh cd /home/Ventoy-master/vtoyfat
sh build.sh sh build.sh
Use the same build step to build in a 32bit CentOS system and get vtoy_fuse_iso_32 4.9 == Build exfat-util ==
cd /home/Ventoy-master/ExFAT
4.11 == Build unsquashfs_64/unsquashfs_32 == sh buidlibfuse.sh
cd /home/Ventoy-master/SQUASHFS/SRC sh buidexfat.sh
sh build_lz4.sh
sh build_lzma.sh After that, copy EXFAT/shared/mkexfatfs ===> /home/Ventoy-master/INSTALL/tool/mkexfatfs_64
sh build_lzo.sh After that, copy EXFAT/shared/mount.exfat-fuse ===> /home/Ventoy-master/INSTALL/tool/mount.exfat-fuse_64
sh build_zstd.sh
Use the same build step to build exfat-util 32bit in a 32bit CentOS system and get mkexfatfs_32 and mount.exfat-fuse_32
cd /home/Ventoy-master/SQUASHFS/squashfs-tools-4.4/squashfs-tools
sh build.sh 4.10 == Build vtoy_fuse_iso_64/vtoy_fuse_iso_32 ==
cd /home/Ventoy-master/FUSEISO
Use the same build step to build in a 32bit CentOS system and get unsquashfs_32 sh build_libfuse.sh
sh build.sh
4.12 == Build vblade_64/vblade_32 ==
cd /home/Ventoy-master/VBLADE/vblade-master Use the same build step to build in a 32bit CentOS system and get vtoy_fuse_iso_32
sh build.sh
4.11 == Build unsquashfs_64/unsquashfs_32 ==
4.13 == Build zstdcat == cd /home/Ventoy-master/SQUASHFS/SRC
Please refer to ZSTD/build.txt sh build_lz4.sh
sh build_lzma.sh
4.14 == Build vtoy_gen_uuid == sh build_lzo.sh
cd /home/Ventoy-master/GenUUID sh build_zstd.sh
sh build.sh
cd /home/Ventoy-master/SQUASHFS/squashfs-tools-4.4/squashfs-tools
4.15 == Build xzminidec32 == sh build.sh
cd /home/Ventoy-master/Ventoy2Disk/Ventoy2Disk/xz-embedded-20130513/userspace
make -f ventoy_makefile Use the same build step to build in a 32bit CentOS system and get unsquashfs_32
strip --strip-all xzminidec
4.12 == Build vblade_64/vblade_32 ==
4.16 == Build xzminidec64 == cd /home/Ventoy-master/VBLADE/vblade-master
cd /home/Ventoy-master/Ventoy2Disk/Ventoy2Disk/xz-embedded-20130513/userspace sh build.sh
make -f ventoy_makefile64
strip --strip-all xzminidec 4.13 == Build zstdcat ==
Please refer to ZSTD/build.txt
4.17 == Build iso9660_x64.efi ==
This efi driver is from https://github.com/pbatard/efifs 4.14 == Build vtoy_gen_uuid ==
Follow all the build instructions in this project. I modified 3 files (the original and modified source are at /home/Ventoy-master/EDK2/efiffs) cd /home/Ventoy-master/GenUUID
sh build.sh
4.18 IMG/cpio/ventoy/busybox/64h
https://www.uclibc.org/downloads/binaries/0.9.30.1/mini-native-x86_64.tar.bz2 4.15 == Build xzminidec32 ==
https://busybox.net/downloads/busybox-1.32.0.tar.bz2 cd /home/Ventoy-master/Ventoy2Disk/Ventoy2Disk/xz-embedded-20130513/userspace
use BUSYBOX/64h.config and uclibc to build busybox-1.32 make -f ventoy_makefile
strip --strip-all xzminidec
========================================== 4.16 == Build xzminidec64 ==
5. Binaries cd /home/Ventoy-master/Ventoy2Disk/Ventoy2Disk/xz-embedded-20130513/userspace
========================================== make -f ventoy_makefile64
There some binaries in Ventoy install package. These files are downloaded from other open source project's website, such as busybox. strip --strip-all xzminidec
Here is the list of the binaries, their SHA-256 and the download urls:
4.17 == Build iso9660_x64.efi ==
5.1 IMG/cpio/ventoy/tool/lz4cat This efi driver is from https://github.com/pbatard/efifs
https://create.stephan-brumme.com/smallz4 smallz4cat-x32-v1.4 Follow all the build instructions in this project. I modified 3 files (the original and modified source are at /home/Ventoy-master/EDK2/efiffs)
SHA-256: 13d293ddeedb469f51da41167f79b2cbdb904e681716f6e6191b233dbb162438
4.18 IMG/cpio/ventoy/busybox/64h
5.2 IMG/cpio/ventoy/tool/ar https://www.uclibc.org/downloads/binaries/0.9.30.1/mini-native-x86_64.tar.bz2
https://busybox.net/downloads/binaries/1.30.0-i686 busybox_AR https://busybox.net/downloads/busybox-1.32.0.tar.bz2
SHA-256: f29b7d81a983c0c85d22496f4a833c18f2528a1b666eb7d47c93084c1ed66ae0 use BUSYBOX/x86_64_ash.config and uclibc to build busybox-1.32
5.3 IMG/cpio/ventoy/tool/inotifyd 4.19 == Build lunzip32/lunzip64 ==
https://busybox.net/downloads/binaries/1.30.0-i686 busybox_INOTIFYD http://mirror.yongbok.net/nongnu/lzip/lunzip/lunzip-1.11.tar.gz
SHA-256: 3532162a8695e91a1ed9ddea28b2cb22259a90e93d5d9c4a517b6c36842c686f PATH=$PATH:/opt/diet/bin
./configure --disable-nls CC='diet gcc -nostdinc'
5.4 IMG/cpio/ventoy/busybox/ash make
https://busybox.net/downloads/binaries/1.27.1-i686 busybox_ASH strip --strip-all lunzip
SHA-256: 44a6274bca580c2758ffc173fc76d18bb855b1fe8dcf70efd9ee75cbd57dee97
#aarch64
5.5 IMG/cpio/ventoy/busybox/tmpxz ./configure --disable-nls CC='aarch64-buildroot-linux-uclibc-gcc -static'
https://busybox.net/downloads/binaries/1.27.1-i686 busybox_XZ make
SHA-256: f6cdb6293680424c29b89bde0685ca27f455166c9b302cd6082ef90681456291 aarch64-buildroot-linux-uclibc-strip --strip-all lunzip
5.6 INSTALL/tool/xzcat
https://busybox.net/downloads/binaries/1.30.0-i686/ busybox_XZCAT
SHA-256: 7399db642c2beaf52a16ab5264ffc55cfd1ff5699a524f63e5d48edf84e20f44 ==========================================
5. Binaries
5.7 INSTALL/tool/hexdump ==========================================
https://busybox.net/downloads/binaries/1.30.0-i686/ busybox_HEXDUMP There some binaries in Ventoy install package. These files are downloaded from other open source project's website, such as busybox.
SHA-256: cde08b6a2cf5ad914f05203e18e3f7c2ed6060a63604e3d75536f19b55e8e0af Here is the list of the binaries, their SHA-256 and the download urls:
5.8 imdisk 5.1 IMG/cpio/ventoy/tool/lz4cat
download http://www.ltr-data.se/files/imdiskinst.exe and extract it by 7zip. https://create.stephan-brumme.com/smallz4 smallz4cat-x32-v1.4
SHA-256: 13d293ddeedb469f51da41167f79b2cbdb904e681716f6e6191b233dbb162438
INSTALL/ventoy/imdisk/64/imdisk.sys --> sys/amd64/imdisk.sys SHA-256: 6702202220268787e361f5a82dae53362c8e6c6dcd240bb01b44dd77ae0788da
INSTALL/ventoy/imdisk/64/imdisk.exe --> cli/amd64/imdisk.exe SHA-256: 9759175380af836869443e5f21ce2e33022125d154bc6b3d1c04dc36b190de04 5.2 IMG/cpio/ventoy/tool/ar
INSTALL/ventoy/imdisk/64/imdisk.cpl --> cpl/amd64/imdisk.cpl SHA-256: aea2ebbea2b073c947263744962af8a3eab025ff4c9d825c543e380e738a4c99 https://busybox.net/downloads/binaries/1.30.0-i686 busybox_AR
SHA-256: f29b7d81a983c0c85d22496f4a833c18f2528a1b666eb7d47c93084c1ed66ae0
INSTALL/ventoy/imdisk/32/imdisk.sys --> sys/i386/imdisk.sys SHA-256: a94caec2f71a924d6a914c093ad4b905d7cfdea3f515ed48aaa8c3950b2dc191
INSTALL/ventoy/imdisk/32/imdisk.exe --> cli/i386/imdisk.exe SHA-256: 33b53858e2139704cf603b115a3e5e1dfd4daeaaed4d3e03c633f2df3b55dbaa 5.3 IMG/cpio/ventoy/tool/inotifyd
INSTALL/ventoy/imdisk/32/imdisk.cpl --> cpl/i386/imdisk.cpl SHA-256: b781d3e2d286ac8bf548f44e50cbbb3fe78203296e41e4d2e73b407668f88f2d https://busybox.net/downloads/binaries/1.30.0-i686 busybox_INOTIFYD
SHA-256: 3532162a8695e91a1ed9ddea28b2cb22259a90e93d5d9c4a517b6c36842c686f
5.9 INSTALL/ventoy/memdisk
https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.tar.gz 5.4 IMG/cpio/ventoy/busybox/ash
decompress it and memdisk is at syslinux-6.03/bios/memdisk/memdisk https://busybox.net/downloads/binaries/1.27.1-i686 busybox_ASH
SHA-256: 3f6cd656b8a14109cd3f906fee2dd2e75418f983a5e1bfdb64f44f7765588cbb SHA-256: 44a6274bca580c2758ffc173fc76d18bb855b1fe8dcf70efd9ee75cbd57dee97
5.5 IMG/cpio/ventoy/busybox/tmpxz
5.10 UEFIinSecureBoot https://busybox.net/downloads/binaries/1.27.1-i686 busybox_XZ
https://github.com/ValdikSS/Super-UEFIinSecureBoot-Disk/releases Super-UEFIinSecureBoot-Disk_minimal_v3.zip SHA-256: f6cdb6293680424c29b89bde0685ca27f455166c9b302cd6082ef90681456291
unzip it and get Super-UEFIinSecureBoot-Disk_minimal.img, extract the img by 7zip.
5.6 INSTALL/tool/i386/xzcat
INSTALL/EFI/BOOT/BOOTX64.EFI --> EFI/BOOT/BOOTX64.EFI SHA-256: 475552c7476ad45e42344eee8b30d44c264d200ac2468428aa86fc8795fb6e34 https://busybox.net/downloads/binaries/1.30.0-i686/ busybox_XZCAT
INSTALL/EFI/BOOT/grubx64.efi --> EFI/BOOT/grubx64.efi SHA-256: 25d858157349dc52fa70f3cdf5c62fe1e0bae37ddfc3a6b6528af9a3c745775f SHA-256: 7399db642c2beaf52a16ab5264ffc55cfd1ff5699a524f63e5d48edf84e20f44
INSTALL/EFI/BOOT/MokManager.efi --> EFI/BOOT/MokManager.efi SHA-256: 3bf1f46cee0832355c7dd1dba880dea9bcaa78cc44375a1559d43bc9db18933b
5.7 INSTALL/tool/i386/hexdump
https://busybox.net/downloads/binaries/1.30.0-i686/ busybox_HEXDUMP
5.11 INSTALL/tool/ash SHA-256: cde08b6a2cf5ad914f05203e18e3f7c2ed6060a63604e3d75536f19b55e8e0af
https://busybox.net/downloads/binaries/1.31.0-i686-uclibc/ busybox_ASH
SHA-256: 2943f02f85fee0c9551aec47110a558a73f919c032b3c51e56d6f197b5ec4d7b 5.8 imdisk
download http://www.ltr-data.se/files/imdiskinst.exe and extract it by 7zip.
5.12 7za.exe
download from https://www.7-zip.org/a/7z1900-extra.7z INSTALL/ventoy/imdisk/64/imdisk.sys --> sys/amd64/imdisk.sys SHA-256: 6702202220268787e361f5a82dae53362c8e6c6dcd240bb01b44dd77ae0788da
ISNTALL/ventoy/7z/64/7za.exe SHA-256: 8117e40ee7f824f63373a4f5625bb62749f69159d0c449b3ce2f35aad3b83549 INSTALL/ventoy/imdisk/64/imdisk.exe --> cli/amd64/imdisk.exe SHA-256: 9759175380af836869443e5f21ce2e33022125d154bc6b3d1c04dc36b190de04
ISNTALL/ventoy/7z/32/7za.exe SHA-256: ea308c76a2f927b160a143d94072b0dce232e04b751f0c6432a94e05164e716d INSTALL/ventoy/imdisk/64/imdisk.cpl --> cpl/amd64/imdisk.cpl SHA-256: aea2ebbea2b073c947263744962af8a3eab025ff4c9d825c543e380e738a4c99
INSTALL/ventoy/imdisk/32/imdisk.sys --> sys/i386/imdisk.sys SHA-256: a94caec2f71a924d6a914c093ad4b905d7cfdea3f515ed48aaa8c3950b2dc191
INSTALL/ventoy/imdisk/32/imdisk.exe --> cli/i386/imdisk.exe SHA-256: 33b53858e2139704cf603b115a3e5e1dfd4daeaaed4d3e03c633f2df3b55dbaa
INSTALL/ventoy/imdisk/32/imdisk.cpl --> cpl/i386/imdisk.cpl SHA-256: b781d3e2d286ac8bf548f44e50cbbb3fe78203296e41e4d2e73b407668f88f2d
5.9 INSTALL/ventoy/memdisk
https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.tar.gz
decompress it and memdisk is at syslinux-6.03/bios/memdisk/memdisk
SHA-256: 3f6cd656b8a14109cd3f906fee2dd2e75418f983a5e1bfdb64f44f7765588cbb
5.10 UEFIinSecureBoot
https://github.com/ValdikSS/Super-UEFIinSecureBoot-Disk/releases Super-UEFIinSecureBoot-Disk_minimal_v3.zip
unzip it and get Super-UEFIinSecureBoot-Disk_minimal.img, extract the img by 7zip.
INSTALL/EFI/BOOT/BOOTX64.EFI --> EFI/BOOT/BOOTX64.EFI SHA-256: 475552c7476ad45e42344eee8b30d44c264d200ac2468428aa86fc8795fb6e34
INSTALL/EFI/BOOT/grubx64.efi --> EFI/BOOT/grubx64.efi SHA-256: 25d858157349dc52fa70f3cdf5c62fe1e0bae37ddfc3a6b6528af9a3c745775f
INSTALL/EFI/BOOT/MokManager.efi --> EFI/BOOT/MokManager.efi SHA-256: 3bf1f46cee0832355c7dd1dba880dea9bcaa78cc44375a1559d43bc9db18933b
5.11 INSTALL/tool/ash
https://busybox.net/downloads/binaries/1.31.0-i686-uclibc/ busybox_ASH
SHA-256: 2943f02f85fee0c9551aec47110a558a73f919c032b3c51e56d6f197b5ec4d7b
5.12 7za.exe
download from https://www.7-zip.org/a/7z1900-extra.7z
ISNTALL/ventoy/7z/64/7za.exe SHA-256: 8117e40ee7f824f63373a4f5625bb62749f69159d0c449b3ce2f35aad3b83549
ISNTALL/ventoy/7z/32/7za.exe SHA-256: ea308c76a2f927b160a143d94072b0dce232e04b751f0c6432a94e05164e716d

29
DOC/LoopExBuild.txt Normal file
View File

@@ -0,0 +1,29 @@
1. LAKKA dm-mod.ko
LaKKa config
https://github.com/libretro/Lakka-LibreELEC/releases download source code
\projects\Generic\linux\linux.x86_64.conf
Linux Kernel
linux-4.11.12.tar.xz & patch-4.11.12-rt14.patch.xz
patch -p1 < ../patch-4.11.12-rt14
make menuconfig
select device mapper as module
make -j 16
get drivers\md\dm-mod.ko
2. LibreELEC dm-mod.ko
LibreELEC config
https://github.com/LibreELEC/LibreELEC.tv/releases download source code
\projects\Generic\linux\linux.x86_64.conf
Linux Kernel
linux-5.1.6.tar.xz
make menuconfig
select device mapper as module
make -j 16
get drivers\md\dm-mod.ko

View File

@@ -37,7 +37,9 @@
#include <Ventoy.h> #include <Ventoy.h>
BOOLEAN gDebugPrint = FALSE; BOOLEAN gDebugPrint = FALSE;
BOOLEAN gDotEfiBoot = FALSE;
BOOLEAN gLoadIsoEfi = FALSE; BOOLEAN gLoadIsoEfi = FALSE;
BOOLEAN gIsoUdf = FALSE;
ventoy_ram_disk g_ramdisk_param; ventoy_ram_disk g_ramdisk_param;
ventoy_chain_head *g_chain; ventoy_chain_head *g_chain;
ventoy_img_chunk *g_chunk; ventoy_img_chunk *g_chunk;
@@ -49,11 +51,13 @@ ventoy_virt_chunk *g_virt_chunk;
UINT32 g_virt_chunk_num; UINT32 g_virt_chunk_num;
vtoy_block_data gBlockData; vtoy_block_data gBlockData;
static grub_env_get_pf grub_env_get = NULL; static grub_env_get_pf grub_env_get = NULL;
static grub_env_set_pf grub_env_set = NULL;
ventoy_grub_param_file_replace *g_file_replace_list = NULL; ventoy_grub_param_file_replace *g_file_replace_list = NULL;
ventoy_efi_file_replace g_efi_file_replace; ventoy_efi_file_replace g_efi_file_replace;
CONST CHAR16 gIso9660EfiDriverPath[] = ISO9660_EFI_DRIVER_PATH; CONST CHAR16 gIso9660EfiDriverPath[] = ISO9660_EFI_DRIVER_PATH;
CONST CHAR16 gUdfEfiDriverPath[] = UDF_EFI_DRIVER_PATH;
BOOLEAN g_fix_windows_1st_cdrom_issue = FALSE; BOOLEAN g_fix_windows_1st_cdrom_issue = FALSE;
@@ -67,10 +71,28 @@ CONST CHAR16 *gEfiBootFileName[] =
{ {
L"@", L"@",
EFI_REMOVABLE_MEDIA_FILE_NAME, EFI_REMOVABLE_MEDIA_FILE_NAME,
#if defined (MDE_CPU_IA32)
L"\\EFI\\BOOT\\GRUBIA32.EFI",
L"\\EFI\\BOOT\\BOOTia32.EFI",
L"\\EFI\\BOOT\\bootia32.efi",
L"\\efi\\boot\\bootia32.efi",
#elif defined (MDE_CPU_X64)
L"\\EFI\\BOOT\\GRUBX64.EFI", L"\\EFI\\BOOT\\GRUBX64.EFI",
L"\\EFI\\BOOT\\BOOTx64.EFI", L"\\EFI\\BOOT\\BOOTx64.EFI",
L"\\EFI\\BOOT\\bootx64.efi", L"\\EFI\\BOOT\\bootx64.efi",
L"\\efi\\boot\\bootx64.efi", L"\\efi\\boot\\bootx64.efi",
#elif defined (MDE_CPU_ARM)
L"\\EFI\\BOOT\\GRUBARM.EFI",
L"\\EFI\\BOOT\\BOOTarm.EFI",
L"\\EFI\\BOOT\\bootarm.efi",
L"\\efi\\boot\\bootarm.efi",
#elif defined (MDE_CPU_AARCH64)
L"\\EFI\\BOOT\\GRUBAA64.EFI",
L"\\EFI\\BOOT\\BOOTaa64.EFI",
L"\\EFI\\BOOT\\bootaa64.efi",
L"\\efi\\boot\\bootaa64.efi",
#endif
}; };
VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...) VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...)
@@ -271,19 +293,33 @@ static int ventoy_update_image_location(ventoy_os_param *param)
} }
CopyMem(&location->guid, &param->guid, sizeof(ventoy_guid)); CopyMem(&location->guid, &param->guid, sizeof(ventoy_guid));
location->image_sector_size = 2048; location->image_sector_size = gSector512Mode ? 512 : 2048;
location->disk_sector_size = g_chain->disk_sector_size; location->disk_sector_size = g_chain->disk_sector_size;
location->region_count = g_img_chunk_num; location->region_count = g_img_chunk_num;
region = location->regions; region = location->regions;
for (i = 0; i < g_img_chunk_num; i++) if (gSector512Mode)
{ {
region->image_sector_count = chunk->img_end_sector - chunk->img_start_sector + 1; for (i = 0; i < g_img_chunk_num; i++)
region->image_start_sector = chunk->img_start_sector; {
region->disk_start_sector = chunk->disk_start_sector; region->image_sector_count = chunk->disk_end_sector - chunk->disk_start_sector + 1;
region++; region->image_start_sector = chunk->img_start_sector * 4;
chunk++; region->disk_start_sector = chunk->disk_start_sector;
region++;
chunk++;
}
}
else
{
for (i = 0; i < g_img_chunk_num; i++)
{
region->image_sector_count = chunk->img_end_sector - chunk->img_start_sector + 1;
region->image_start_sector = chunk->img_start_sector;
region->disk_start_sector = chunk->disk_start_sector;
region++;
chunk++;
}
} }
return 0; return 0;
@@ -376,6 +412,36 @@ EFI_STATUS EFIAPI ventoy_delete_variable(VOID)
return Status; return Status;
} }
#if (VENTOY_DEVICE_WARN != 0)
STATIC VOID ventoy_warn_invalid_device(VOID)
{
STATIC BOOLEAN flag = FALSE;
if (flag)
{
return;
}
flag = TRUE;
gST->ConOut->ClearScreen(gST->ConOut);
gST->ConOut->OutputString(gST->ConOut, VTOY_WARNING L"\r\n");
gST->ConOut->OutputString(gST->ConOut, VTOY_WARNING L"\r\n");
gST->ConOut->OutputString(gST->ConOut, VTOY_WARNING L"\r\n\r\n\r\n");
gST->ConOut->OutputString(gST->ConOut, L"This is NOT a standard Ventoy device and is NOT supported.\r\n\r\n");
gST->ConOut->OutputString(gST->ConOut, L"You should follow the official instructions in https://www.ventoy.net\r\n");
gST->ConOut->OutputString(gST->ConOut, L"\r\n\r\nWill exit after 10 seconds ...... ");
sleep(10);
}
#else
STATIC VOID ventoy_warn_invalid_device(VOID)
{
}
#endif
STATIC EFI_STATUS EFIAPI ventoy_load_image STATIC EFI_STATUS EFIAPI ventoy_load_image
( (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
@@ -418,6 +484,7 @@ STATIC EFI_STATUS EFIAPI ventoy_find_iso_disk(IN EFI_HANDLE ImageHandle)
UINTN i = 0; UINTN i = 0;
UINTN Count = 0; UINTN Count = 0;
UINT64 DiskSize = 0; UINT64 DiskSize = 0;
MBR_HEAD *pMBR = NULL;
UINT8 *pBuffer = NULL; UINT8 *pBuffer = NULL;
EFI_HANDLE *Handles; EFI_HANDLE *Handles;
EFI_STATUS Status = EFI_SUCCESS; EFI_STATUS Status = EFI_SUCCESS;
@@ -461,6 +528,18 @@ 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) if (CompareMem(g_chain->os_param.vtoy_disk_guid, pBuffer + 0x180, 16) == 0)
{ {
pMBR = (MBR_HEAD *)pBuffer;
if (pMBR->PartTbl[0].FsFlag != 0xEE)
{
if (pMBR->PartTbl[0].StartSectorId != 2048 ||
pMBR->PartTbl[1].SectorCount != 65536 ||
pMBR->PartTbl[1].StartSectorId != pMBR->PartTbl[0].StartSectorId + pMBR->PartTbl[0].SectorCount)
{
debug("Failed to check disk part table");
ventoy_warn_invalid_device();
}
}
gBlockData.RawBlockIoHandle = Handles[i]; gBlockData.RawBlockIoHandle = Handles[i];
gBlockData.pRawBlockIo = pBlockIo; gBlockData.pRawBlockIo = pBlockIo;
gBS->OpenProtocol(Handles[i], &gEfiDevicePathProtocolGuid, gBS->OpenProtocol(Handles[i], &gEfiDevicePathProtocolGuid,
@@ -549,12 +628,23 @@ STATIC EFI_STATUS EFIAPI ventoy_load_isoefi_driver(IN EFI_HANDLE ImageHandle)
EFI_HANDLE Image = NULL; EFI_HANDLE Image = NULL;
EFI_STATUS Status = EFI_SUCCESS; EFI_STATUS Status = EFI_SUCCESS;
CHAR16 LogVar[4] = L"5"; CHAR16 LogVar[4] = L"5";
Status = ventoy_load_image(ImageHandle, gBlockData.pDiskFsDevPath, if (gIsoUdf)
gIso9660EfiDriverPath, {
sizeof(gIso9660EfiDriverPath), Status = ventoy_load_image(ImageHandle, gBlockData.pDiskFsDevPath,
&Image); gUdfEfiDriverPath,
debug("load iso efi driver status:%r", Status); sizeof(gUdfEfiDriverPath),
&Image);
debug("load iso UDF efi driver status:%r", Status);
}
else
{
Status = ventoy_load_image(ImageHandle, gBlockData.pDiskFsDevPath,
gIso9660EfiDriverPath,
sizeof(gIso9660EfiDriverPath),
&Image);
debug("load iso 9660 efi driver status:%r", Status);
}
if (gDebugPrint) if (gDebugPrint)
{ {
@@ -580,6 +670,7 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
UINT32 old_cnt = 0; UINT32 old_cnt = 0;
UINTN size = 0; UINTN size = 0;
UINT8 chksum = 0; UINT8 chksum = 0;
const char *pEnv = NULL;
CHAR16 *pPos = NULL; CHAR16 *pPos = NULL;
CHAR16 *pCmdLine = NULL; CHAR16 *pCmdLine = NULL;
EFI_STATUS Status = EFI_SUCCESS; EFI_STATUS Status = EFI_SUCCESS;
@@ -602,11 +693,21 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
{ {
gDebugPrint = TRUE; gDebugPrint = TRUE;
} }
if (StrStr(pCmdLine, L"dotefi"))
{
gDotEfiBoot = TRUE;
}
if (StrStr(pCmdLine, L"isoefi=on")) if (StrStr(pCmdLine, L"isoefi=on"))
{ {
gLoadIsoEfi = TRUE; gLoadIsoEfi = TRUE;
} }
if (StrStr(pCmdLine, L"iso_udf"))
{
gIsoUdf = TRUE;
}
pPos = StrStr(pCmdLine, L"FirstTry=@"); pPos = StrStr(pCmdLine, L"FirstTry=@");
if (pPos) if (pPos)
@@ -642,8 +743,20 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
} }
pGrubParam = (ventoy_grub_param *)StrHexToUintn(pPos + StrLen(L"env_param=")); pGrubParam = (ventoy_grub_param *)StrHexToUintn(pPos + StrLen(L"env_param="));
grub_env_set = pGrubParam->grub_env_set;
grub_env_get = pGrubParam->grub_env_get; grub_env_get = pGrubParam->grub_env_get;
pEnv = grub_env_get("VTOY_CHKDEV_RESULT_STRING");
if (!pEnv)
{
return EFI_INVALID_PARAMETER;
}
if (pEnv[0] != '0' || pEnv[1] != 0)
{
ventoy_warn_invalid_device();
return EFI_INVALID_PARAMETER;
}
g_file_replace_list = &pGrubParam->file_replace; g_file_replace_list = &pGrubParam->file_replace;
old_cnt = g_file_replace_list->old_file_cnt; old_cnt = g_file_replace_list->old_file_cnt;
debug("file replace: magic:0x%x virtid:%u name count:%u <%a> <%a> <%a> <%a>", debug("file replace: magic:0x%x virtid:%u name count:%u <%a> <%a> <%a> <%a>",
@@ -664,6 +777,11 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
debug("memory addr:%p size:%lu", chain, size); debug("memory addr:%p size:%lu", chain, size);
if (StrStr(pCmdLine, L"sector512"))
{
gSector512Mode = TRUE;
}
if (StrStr(pCmdLine, L"memdisk")) if (StrStr(pCmdLine, L"memdisk"))
{ {
g_iso_data_buf = (UINT8 *)chain + sizeof(ventoy_chain_head); g_iso_data_buf = (UINT8 *)chain + sizeof(ventoy_chain_head);
@@ -906,6 +1024,11 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
if (Find == 0) if (Find == 0)
{ {
if (gDotEfiBoot)
{
break;
}
debug("Fs not found, now wait and retry..."); debug("Fs not found, now wait and retry...");
sleep(2); sleep(2);
} }
@@ -945,7 +1068,11 @@ EFI_STATUS EFIAPI VentoyEfiMain
gST->ConOut->ClearScreen(gST->ConOut); gST->ConOut->ClearScreen(gST->ConOut);
ventoy_clear_input(); ventoy_clear_input();
ventoy_parse_cmdline(ImageHandle); Status = ventoy_parse_cmdline(ImageHandle);
if (EFI_ERROR(Status))
{
return Status;
}
if (gMemdiskMode) if (gMemdiskMode)
{ {
@@ -972,39 +1099,55 @@ EFI_STATUS EFIAPI VentoyEfiMain
{ {
gBS->UnloadImage(gBlockData.IsoDriverImage); gBS->UnloadImage(gBlockData.IsoDriverImage);
} }
gBS->DisconnectController(gBlockData.Handle, NULL, NULL);
gBS->UninstallMultipleProtocolInterfaces(gBlockData.Handle,
&gEfiBlockIoProtocolGuid, &gBlockData.BlockIo,
&gEfiDevicePathProtocolGuid, gBlockData.Path,
NULL);
} }
else else
{ {
ventoy_save_variable(); ventoy_save_variable();
ventoy_find_iso_disk(ImageHandle); Status = ventoy_find_iso_disk(ImageHandle);
if (!EFI_ERROR(Status))
if (gLoadIsoEfi)
{ {
ventoy_find_iso_disk_fs(ImageHandle); if (gLoadIsoEfi)
ventoy_load_isoefi_driver(ImageHandle); {
ventoy_find_iso_disk_fs(ImageHandle);
ventoy_load_isoefi_driver(ImageHandle);
}
ventoy_debug_pause();
ventoy_install_blockio(ImageHandle, g_chain->virt_img_size_in_bytes);
ventoy_debug_pause();
Status = ventoy_boot(ImageHandle);
} }
ventoy_debug_pause();
ventoy_install_blockio(ImageHandle, g_chain->virt_img_size_in_bytes);
ventoy_debug_pause();
Status = ventoy_boot(ImageHandle);
ventoy_clean_env(); ventoy_clean_env();
} }
if (EFI_NOT_FOUND == Status) if (FALSE == gDotEfiBoot)
{ {
gST->ConOut->OutputString(gST->ConOut, L"No bootfile found for UEFI!\r\n"); if (EFI_NOT_FOUND == Status)
gST->ConOut->OutputString(gST->ConOut, L"Maybe the image does not support " VENTOY_UEFI_DESC L"!\r\n"); {
sleep(30); gST->ConOut->OutputString(gST->ConOut, L"No bootfile found for UEFI!\r\n");
gST->ConOut->OutputString(gST->ConOut, L"Maybe the image does not support " VENTOY_UEFI_DESC L"!\r\n");
sleep(30);
}
} }
ventoy_clear_input(); ventoy_clear_input();
gST->ConOut->ClearScreen(gST->ConOut); gST->ConOut->ClearScreen(gST->ConOut);
if (gDotEfiBoot && (EFI_NOT_FOUND == Status))
{
grub_env_set("vtoy_dotefi_retry", "YES");
}
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@@ -168,23 +168,33 @@ typedef struct ventoy_virt_chunk
#define VTOY_BLOCK_DEVICE_PATH_GUID \ #define VTOY_BLOCK_DEVICE_PATH_GUID \
{ 0x37b87ac6, 0xc180, 0x4583, { 0xa7, 0x05, 0x41, 0x4d, 0xa8, 0xf7, 0x7e, 0xd2 }} { 0x37b87ac6, 0xc180, 0x4583, { 0xa7, 0x05, 0x41, 0x4d, 0xa8, 0xf7, 0x7e, 0xd2 }}
#define ISO9660_EFI_DRIVER_PATH L"\\ventoy\\iso9660_x64.efi"
#define VTOY_BLOCK_DEVICE_PATH_NAME L"ventoy" #define VTOY_BLOCK_DEVICE_PATH_NAME L"ventoy"
#if defined (MDE_CPU_IA32) #if defined (MDE_CPU_IA32)
#define VENTOY_UEFI_DESC L"IA32 UEFI" #define VENTOY_UEFI_DESC L"IA32 UEFI"
#define ISO9660_EFI_DRIVER_PATH L"\\ventoy\\iso9660_ia32.efi"
#define UDF_EFI_DRIVER_PATH L"\\ventoy\\udf_ia32.efi"
#elif defined (MDE_CPU_X64) #elif defined (MDE_CPU_X64)
#define VENTOY_UEFI_DESC L"X64 UEFI" #define VENTOY_UEFI_DESC L"X64 UEFI"
#define ISO9660_EFI_DRIVER_PATH L"\\ventoy\\iso9660_x64.efi"
#define UDF_EFI_DRIVER_PATH L"\\ventoy\\udf_x64.efi"
#elif defined (MDE_CPU_EBC) #elif defined (MDE_CPU_EBC)
#elif defined (MDE_CPU_ARM) #elif defined (MDE_CPU_ARM)
#define VENTOY_UEFI_DESC L"ARM UEFI" #define VENTOY_UEFI_DESC L"ARM UEFI"
#define ISO9660_EFI_DRIVER_PATH L"\\ventoy\\iso9660_arm.efi"
#define UDF_EFI_DRIVER_PATH L"\\ventoy\\udf_arm.efi"
#elif defined (MDE_CPU_AARCH64) #elif defined (MDE_CPU_AARCH64)
#define VENTOY_UEFI_DESC L"ARM64 UEFI" #define VENTOY_UEFI_DESC L"ARM64 UEFI"
#define ISO9660_EFI_DRIVER_PATH L"\\ventoy\\iso9660_aa64.efi"
#define UDF_EFI_DRIVER_PATH L"\\ventoy\\udf_aa64.efi"
#else #else
#error Unknown Processor Type #error Unknown Processor Type
#endif #endif
#define VENTOY_DEVICE_WARN 1
#define VTOY_WARNING L"!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!"
typedef struct ventoy_sector_flag typedef struct ventoy_sector_flag
{ {
UINT8 flag; // 0:init 1:mem 2:remap UINT8 flag; // 0:init 1:mem 2:remap
@@ -227,6 +237,7 @@ if (gDebugPrint) \
gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &__Index);\ gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &__Index);\
} }
typedef int (*grub_env_set_pf)(const char *name, const char *val);
typedef const char * (*grub_env_get_pf)(const char *name); typedef const char * (*grub_env_get_pf)(const char *name);
typedef int (*grub_env_printf_pf)(const char *fmt, ...); typedef int (*grub_env_printf_pf)(const char *fmt, ...);
@@ -255,6 +266,7 @@ typedef struct ventoy_grub_param_file_replace
typedef struct ventoy_grub_param typedef struct ventoy_grub_param
{ {
grub_env_get_pf grub_env_get; grub_env_get_pf grub_env_get;
grub_env_set_pf grub_env_set;
ventoy_grub_param_file_replace file_replace; ventoy_grub_param_file_replace file_replace;
grub_env_printf_pf grub_env_printf; grub_env_printf_pf grub_env_printf;
}ventoy_grub_param; }ventoy_grub_param;
@@ -273,6 +285,32 @@ typedef struct ventoy_iso9660_override
UINT32 size_be; UINT32 size_be;
}ventoy_iso9660_override; }ventoy_iso9660_override;
typedef struct PART_TABLE
{
UINT8 Active; // 0x00 0x80
UINT8 StartHead;
UINT16 StartSector : 6;
UINT16 StartCylinder : 10;
UINT8 FsFlag;
UINT8 EndHead;
UINT16 EndSector : 6;
UINT16 EndCylinder : 10;
UINT32 StartSectorId;
UINT32 SectorCount;
}PART_TABLE;
typedef struct MBR_HEAD
{
UINT8 BootCode[446];
PART_TABLE PartTbl[4];
UINT8 Byte55;
UINT8 ByteAA;
}MBR_HEAD;
#pragma pack() #pragma pack()
@@ -338,6 +376,7 @@ extern ventoy_efi_file_replace g_efi_file_replace;
extern ventoy_sector_flag *g_sector_flag; extern ventoy_sector_flag *g_sector_flag;
extern UINT32 g_sector_flag_num; extern UINT32 g_sector_flag_num;
extern BOOLEAN gMemdiskMode; extern BOOLEAN gMemdiskMode;
extern BOOLEAN gSector512Mode;
extern UINTN g_iso_buf_size; extern UINTN g_iso_buf_size;
extern UINT8 *g_iso_data_buf; extern UINT8 *g_iso_data_buf;
extern ventoy_grub_param_file_replace *g_file_replace_list; extern ventoy_grub_param_file_replace *g_file_replace_list;

View File

@@ -1,81 +1,81 @@
#************************************************************************************ #************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net> # Copyright (c) 2020, longpanda <admin@ventoy.net>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as # modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the # published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version. # License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, but # This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of # WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details. # General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>. # along with this program; if not, see <http://www.gnu.org/licenses/>.
# #
#************************************************************************************ #************************************************************************************
[Defines] [Defines]
INF_VERSION = 0x00010005 INF_VERSION = 0x00010005
BASE_NAME = Ventoy BASE_NAME = Ventoy
FILE_GUID = 1c3a0915-09dc-49c2-873d-0aaaa7733299 FILE_GUID = 1c3a0915-09dc-49c2-873d-0aaaa7733299
MODULE_TYPE = UEFI_APPLICATION MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0 VERSION_STRING = 1.0
ENTRY_POINT = VentoyEfiMain ENTRY_POINT = VentoyEfiMain
[Sources] [Sources]
Ventoy.h Ventoy.h
Ventoy.c Ventoy.c
VentoyDebug.c VentoyDebug.c
VentoyProtocol.c VentoyProtocol.c
[Packages] [Packages]
MdePkg/MdePkg.dec MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec MdeModulePkg/MdeModulePkg.dec
ShellPkg/ShellPkg.dec ShellPkg/ShellPkg.dec
[LibraryClasses] [LibraryClasses]
UefiApplicationEntryPoint UefiApplicationEntryPoint
UefiLib UefiLib
DebugLib DebugLib
[Guids] [Guids]
gShellVariableGuid gShellVariableGuid
gEfiVirtualCdGuid gEfiVirtualCdGuid
gEfiFileInfoGuid gEfiFileInfoGuid
[Protocols] [Protocols]
gEfiLoadedImageProtocolGuid gEfiLoadedImageProtocolGuid
gEfiBlockIoProtocolGuid gEfiBlockIoProtocolGuid
gEfiDevicePathProtocolGuid gEfiDevicePathProtocolGuid
gEfiSimpleFileSystemProtocolGuid gEfiSimpleFileSystemProtocolGuid
gEfiRamDiskProtocolGuid gEfiRamDiskProtocolGuid
gEfiAbsolutePointerProtocolGuid gEfiAbsolutePointerProtocolGuid
gEfiAcpiTableProtocolGuid gEfiAcpiTableProtocolGuid
gEfiBlockIo2ProtocolGuid gEfiBlockIo2ProtocolGuid
gEfiBusSpecificDriverOverrideProtocolGuid gEfiBusSpecificDriverOverrideProtocolGuid
gEfiComponentNameProtocolGuid gEfiComponentNameProtocolGuid
gEfiComponentName2ProtocolGuid gEfiComponentName2ProtocolGuid
gEfiDriverBindingProtocolGuid gEfiDriverBindingProtocolGuid
gEfiDiskIoProtocolGuid gEfiDiskIoProtocolGuid
gEfiDiskIo2ProtocolGuid gEfiDiskIo2ProtocolGuid
gEfiGraphicsOutputProtocolGuid gEfiGraphicsOutputProtocolGuid
gEfiHiiConfigAccessProtocolGuid gEfiHiiConfigAccessProtocolGuid
gEfiHiiFontProtocolGuid gEfiHiiFontProtocolGuid
gEfiLoadFileProtocolGuid gEfiLoadFileProtocolGuid
gEfiLoadFile2ProtocolGuid gEfiLoadFile2ProtocolGuid
gEfiLoadedImageProtocolGuid gEfiLoadedImageProtocolGuid
gEfiLoadedImageDevicePathProtocolGuid gEfiLoadedImageDevicePathProtocolGuid
gEfiPciIoProtocolGuid gEfiPciIoProtocolGuid
gEfiSerialIoProtocolGuid gEfiSerialIoProtocolGuid
gEfiSimpleTextInProtocolGuid gEfiSimpleTextInProtocolGuid
gEfiSimpleTextInputExProtocolGuid gEfiSimpleTextInputExProtocolGuid
gEfiSimpleTextOutProtocolGuid gEfiSimpleTextOutProtocolGuid

View File

@@ -39,6 +39,7 @@
UINT8 *g_iso_data_buf = NULL; UINT8 *g_iso_data_buf = NULL;
UINTN g_iso_buf_size = 0; UINTN g_iso_buf_size = 0;
BOOLEAN gMemdiskMode = FALSE; BOOLEAN gMemdiskMode = FALSE;
BOOLEAN gSector512Mode = FALSE;
ventoy_sector_flag *g_sector_flag = NULL; ventoy_sector_flag *g_sector_flag = NULL;
UINT32 g_sector_flag_num = 0; UINT32 g_sector_flag_num = 0;
@@ -68,6 +69,10 @@ STATIC EFI_INPUT_READ_KEY g_org_read_key = NULL;
STATIC EFI_LOCATE_HANDLE g_org_locate_handle = NULL; STATIC EFI_LOCATE_HANDLE g_org_locate_handle = NULL;
STATIC UINT8 g_sector_buf[2048];
STATIC EFI_BLOCK_READ g_sector_2048_read = NULL;
STATIC EFI_BLOCK_WRITE g_sector_2048_write = NULL;
BOOLEAN ventoy_is_cdrom_dp_exist(VOID) BOOLEAN ventoy_is_cdrom_dp_exist(VOID)
{ {
UINTN i = 0; UINTN i = 0;
@@ -156,10 +161,19 @@ STATIC EFI_STATUS EFIAPI ventoy_read_iso_sector
{ {
MapLba = (Sector - pchunk->img_start_sector) * 4 + pchunk->disk_start_sector; MapLba = (Sector - pchunk->img_start_sector) * 4 + pchunk->disk_start_sector;
} }
else else if (g_chain->disk_sector_size == 1024)
{ {
MapLba = (Sector - pchunk->img_start_sector) * 2048 / g_chain->disk_sector_size + pchunk->disk_start_sector; MapLba = (Sector - pchunk->img_start_sector) * 2 + pchunk->disk_start_sector;
} }
else if (g_chain->disk_sector_size == 2048)
{
MapLba = (Sector - pchunk->img_start_sector) + pchunk->disk_start_sector;
}
else if (g_chain->disk_sector_size == 4096)
{
MapLba = ((Sector - pchunk->img_start_sector) >> 1) + pchunk->disk_start_sector;
}
secLeft = pchunk->img_end_sector + 1 - Sector; secLeft = pchunk->img_end_sector + 1 - Sector;
secRead = (Count < secLeft) ? Count : secLeft; secRead = (Count < secLeft) ? Count : secLeft;
@@ -241,6 +255,96 @@ STATIC EFI_STATUS EFIAPI ventoy_read_iso_sector
return EFI_SUCCESS; return EFI_SUCCESS;
} }
STATIC EFI_STATUS EFIAPI ventoy_write_iso_sector
(
IN UINT64 Sector,
IN UINTN Count,
IN VOID *Buffer
)
{
EFI_STATUS Status = EFI_SUCCESS;
EFI_LBA MapLba = 0;
UINT32 i = 0;
UINTN secLeft = 0;
UINTN secRead = 0;
UINT64 ReadStart = 0;
UINT64 ReadEnd = 0;
UINT8 *pCurBuf = (UINT8 *)Buffer;
ventoy_img_chunk *pchunk = g_chunk;
EFI_BLOCK_IO_PROTOCOL *pRawBlockIo = gBlockData.pRawBlockIo;
debug("write iso sector %lu count %u", Sector, Count);
ReadStart = Sector * 2048;
ReadEnd = (Sector + Count) * 2048;
for (i = 0; Count > 0 && i < g_img_chunk_num; i++, pchunk++)
{
if (Sector >= pchunk->img_start_sector && Sector <= pchunk->img_end_sector)
{
if (g_chain->disk_sector_size == 512)
{
MapLba = (Sector - pchunk->img_start_sector) * 4 + pchunk->disk_start_sector;
}
else if (g_chain->disk_sector_size == 1024)
{
MapLba = (Sector - pchunk->img_start_sector) * 2 + pchunk->disk_start_sector;
}
else if (g_chain->disk_sector_size == 2048)
{
MapLba = (Sector - pchunk->img_start_sector) + pchunk->disk_start_sector;
}
else if (g_chain->disk_sector_size == 4096)
{
MapLba = ((Sector - pchunk->img_start_sector) >> 1) + pchunk->disk_start_sector;
}
secLeft = pchunk->img_end_sector + 1 - Sector;
secRead = (Count < secLeft) ? Count : secLeft;
Status = pRawBlockIo->WriteBlocks(pRawBlockIo, pRawBlockIo->Media->MediaId,
MapLba, secRead * 2048, pCurBuf);
if (EFI_ERROR(Status))
{
debug("Raw disk write block failed %r LBA:%lu Count:%u", Status, MapLba, secRead);
return Status;
}
Count -= secRead;
Sector += secRead;
pCurBuf += secRead * 2048;
}
}
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI ventoy_block_io_ramdisk_write
(
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
IN VOID *Buffer
)
{
(VOID)This;
(VOID)MediaId;
(VOID)Lba;
(VOID)BufferSize;
(VOID)Buffer;
if (!gSector512Mode)
{
return EFI_WRITE_PROTECTED;
}
CopyMem(g_iso_data_buf + (Lba * 2048), Buffer, BufferSize);
return EFI_SUCCESS;
}
EFI_STATUS EFIAPI ventoy_block_io_ramdisk_read EFI_STATUS EFIAPI ventoy_block_io_ramdisk_read
( (
IN EFI_BLOCK_IO_PROTOCOL *This, IN EFI_BLOCK_IO_PROTOCOL *This,
@@ -434,12 +538,21 @@ EFI_STATUS EFIAPI ventoy_block_io_write
IN VOID *Buffer IN VOID *Buffer
) )
{ {
UINT32 secNum = 0;
UINT64 offset = 0;
(VOID)This; (VOID)This;
(VOID)MediaId; (VOID)MediaId;
(VOID)Lba;
(VOID)BufferSize; if (!gSector512Mode)
(VOID)Buffer; {
return EFI_WRITE_PROTECTED; return EFI_WRITE_PROTECTED;
}
secNum = BufferSize / 2048;
offset = Lba * 2048;
return ventoy_write_iso_sector(Lba, secNum, Buffer);
} }
EFI_STATUS EFIAPI ventoy_block_io_flush(IN EFI_BLOCK_IO_PROTOCOL *This) EFI_STATUS EFIAPI ventoy_block_io_flush(IN EFI_BLOCK_IO_PROTOCOL *This)
@@ -571,6 +684,126 @@ end:
return Status; return Status;
} }
EFI_STATUS EFIAPI ventoy_block_io_read_512
(
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
OUT VOID *Buffer
)
{
EFI_LBA Mod;
UINTN ReadSize;
UINT8 *CurBuf = NULL;
EFI_STATUS Status = EFI_SUCCESS;
debug("ventoy_block_io_read_512 %lu %lu\n", Lba, BufferSize / 512);
CurBuf = (UINT8 *)Buffer;
Mod = Lba % 4;
if (Mod > 0)
{
Status |= g_sector_2048_read(This, MediaId, Lba / 4, 2048, g_sector_buf);
if (BufferSize <= (4 - Mod) * 512)
{
CopyMem(CurBuf, g_sector_buf + Mod * 512, BufferSize);
return EFI_SUCCESS;
}
else
{
ReadSize = (4 - Mod) * 512;
CopyMem(CurBuf, g_sector_buf + Mod * 512, ReadSize);
CurBuf += ReadSize;
Lba += (4 - Mod);
BufferSize -= ReadSize;
}
}
if (BufferSize >= 2048)
{
ReadSize = BufferSize / 2048 * 2048;
Status |= g_sector_2048_read(This, MediaId, Lba / 4, ReadSize, CurBuf);
CurBuf += ReadSize;
Lba += ReadSize / 512;
BufferSize -= ReadSize;
}
if (BufferSize > 0)
{
Status |= g_sector_2048_read(This, MediaId, Lba / 4, 2048, g_sector_buf);
CopyMem(CurBuf, g_sector_buf, BufferSize);
}
return Status;
}
EFI_STATUS EFIAPI ventoy_block_io_write_512
(
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
IN VOID *Buffer
)
{
EFI_LBA Mod;
UINTN ReadSize;
UINT8 *CurBuf = NULL;
EFI_STATUS Status = EFI_SUCCESS;
debug("ventoy_block_io_write_512 %lu %lu\n", Lba, BufferSize / 512);
CurBuf = (UINT8 *)Buffer;
Mod = Lba % 4;
if (Mod > 0)
{
Status |= g_sector_2048_read(This, MediaId, Lba / 4, 2048, g_sector_buf);
if (BufferSize <= (4 - Mod) * 512)
{
CopyMem(g_sector_buf + Mod * 512, CurBuf, BufferSize);
return g_sector_2048_write(This, MediaId, Lba / 4, 2048, g_sector_buf);
}
else
{
ReadSize = (4 - Mod) * 512;
CopyMem(g_sector_buf + Mod * 512, CurBuf, ReadSize);
g_sector_2048_write(This, MediaId, Lba / 4, 2048, g_sector_buf);
CurBuf += ReadSize;
Lba += (4 - Mod);
BufferSize -= ReadSize;
}
}
if (BufferSize >= 2048)
{
ReadSize = BufferSize / 2048 * 2048;
Status |= g_sector_2048_write(This, MediaId, Lba / 4, ReadSize, CurBuf);
CurBuf += ReadSize;
Lba += ReadSize / 512;
BufferSize -= ReadSize;
}
if (BufferSize > 0)
{
Status |= g_sector_2048_read(This, MediaId, Lba / 4, 2048, g_sector_buf);
CopyMem(g_sector_buf, CurBuf, BufferSize);
g_sector_2048_write(This, MediaId, Lba / 4, 2048, g_sector_buf);
}
return Status;
}
EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 ImgSize) EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 ImgSize)
{ {
EFI_STATUS Status = EFI_SUCCESS; EFI_STATUS Status = EFI_SUCCESS;
@@ -580,9 +813,18 @@ EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 Im
debug("install block io protocol %p", ImageHandle); debug("install block io protocol %p", ImageHandle);
ventoy_debug_pause(); ventoy_debug_pause();
if (gSector512Mode)
{
gBlockData.Media.BlockSize = 512;
gBlockData.Media.LastBlock = ImgSize / 512 - 1;
}
else
{
gBlockData.Media.BlockSize = 2048;
gBlockData.Media.LastBlock = ImgSize / 2048 - 1;
}
gBlockData.Media.BlockSize = 2048;
gBlockData.Media.LastBlock = ImgSize / 2048 - 1;
gBlockData.Media.ReadOnly = TRUE; gBlockData.Media.ReadOnly = TRUE;
gBlockData.Media.MediaPresent = 1; gBlockData.Media.MediaPresent = 1;
gBlockData.Media.LogicalBlocksPerPhysicalBlock = 1; gBlockData.Media.LogicalBlocksPerPhysicalBlock = 1;
@@ -590,8 +832,20 @@ EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 Im
pBlockIo->Revision = EFI_BLOCK_IO_PROTOCOL_REVISION3; pBlockIo->Revision = EFI_BLOCK_IO_PROTOCOL_REVISION3;
pBlockIo->Media = &(gBlockData.Media); pBlockIo->Media = &(gBlockData.Media);
pBlockIo->Reset = ventoy_block_io_reset; pBlockIo->Reset = ventoy_block_io_reset;
pBlockIo->ReadBlocks = gMemdiskMode ? ventoy_block_io_ramdisk_read : ventoy_block_io_read;
pBlockIo->WriteBlocks = ventoy_block_io_write; if (gSector512Mode)
{
g_sector_2048_read = gMemdiskMode ? ventoy_block_io_ramdisk_read : ventoy_block_io_read;
g_sector_2048_write = gMemdiskMode ? ventoy_block_io_ramdisk_write : ventoy_block_io_write;
pBlockIo->ReadBlocks = ventoy_block_io_read_512;
pBlockIo->WriteBlocks = ventoy_block_io_write_512;
}
else
{
pBlockIo->ReadBlocks = gMemdiskMode ? ventoy_block_io_ramdisk_read : ventoy_block_io_read;
pBlockIo->WriteBlocks = ventoy_block_io_write;
}
pBlockIo->FlushBlocks = ventoy_block_io_flush; pBlockIo->FlushBlocks = ventoy_block_io_flush;
Status = gBS->InstallMultipleProtocolInterfaces(&gBlockData.Handle, Status = gBS->InstallMultipleProtocolInterfaces(&gBlockData.Handle,
@@ -603,10 +857,10 @@ EFI_STATUS EFIAPI ventoy_install_blockio(IN EFI_HANDLE ImageHandle, IN UINT64 Im
{ {
return Status; return Status;
} }
Status = ventoy_connect_driver(gBlockData.Handle, L"Disk I/O Driver"); Status = ventoy_connect_driver(gBlockData.Handle, L"Disk I/O Driver");
debug("Connect disk IO driver %r", Status); debug("Connect disk IO driver %r", Status);
Status = ventoy_connect_driver(gBlockData.Handle, L"Partition Driver"); Status = ventoy_connect_driver(gBlockData.Handle, L"Partition Driver");
debug("Connect partition driver %r", Status); debug("Connect partition driver %r", Status);
if (EFI_ERROR(Status)) if (EFI_ERROR(Status))

View File

@@ -79,6 +79,14 @@ STATIC EFI_STATUS ParseCmdline(IN EFI_HANDLE ImageHandle)
SetMem(pCmdLine, pImageInfo->LoadOptionsSize + 4, 0); SetMem(pCmdLine, pImageInfo->LoadOptionsSize + 4, 0);
CopyMem(pCmdLine, pImageInfo->LoadOptions, pImageInfo->LoadOptionsSize); CopyMem(pCmdLine, pImageInfo->LoadOptions, pImageInfo->LoadOptionsSize);
if (StrStr(pCmdLine, L"vtoyefitest"))
{
gST->ConOut->OutputString(gST->ConOut, L"\r\n##########################");
gST->ConOut->OutputString(gST->ConOut, L"\r\n######### VTOY #########");
gST->ConOut->OutputString(gST->ConOut, L"\r\n##########################");
return EFI_SUCCESS;
}
if (StrStr(pCmdLine, L"debug")) if (StrStr(pCmdLine, L"debug"))
{ {
gVtoyDebugPrint = TRUE; gVtoyDebugPrint = TRUE;
@@ -100,8 +108,9 @@ STATIC EFI_STATUS ParseCmdline(IN EFI_HANDLE ImageHandle)
} }
gCurFeature = pPos + StrLen(L"feature="); gCurFeature = pPos + StrLen(L"feature=");
gCmdLine = pCmdLine; gCmdLine = pCmdLine;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@@ -116,7 +125,7 @@ EFI_STATUS EFIAPI VtoyUtilEfiMain
ParseCmdline(ImageHandle); ParseCmdline(ImageHandle);
for (i = 0; i < ARRAY_SIZE(gFeatureList); i++) for (i = 0; gCurFeature && i < ARRAY_SIZE(gFeatureList); i++)
{ {
Len = StrLen(gFeatureList[i].Cmd); Len = StrLen(gFeatureList[i].Cmd);
if (StrnCmp(gFeatureList[i].Cmd, gCurFeature, Len) == 0) if (StrnCmp(gFeatureList[i].Cmd, gCurFeature, Len) == 0)
@@ -127,8 +136,11 @@ EFI_STATUS EFIAPI VtoyUtilEfiMain
} }
} }
FreePool(gCmdLine); if (gCmdLine)
gCmdLine = NULL; {
FreePool(gCmdLine);
gCmdLine = NULL;
}
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@@ -24,6 +24,7 @@
#pragma pack(1) #pragma pack(1)
typedef EFI_STATUS (*VTOY_UTIL_PROC_PF)(IN EFI_HANDLE ImageHandle, IN CONST CHAR16 *CmdLine); typedef EFI_STATUS (*VTOY_UTIL_PROC_PF)(IN EFI_HANDLE ImageHandle, IN CONST CHAR16 *CmdLine);
typedef int (*grub_env_set_pf)(const char *name, const char *val);
typedef const char * (*grub_env_get_pf)(const char *name); typedef const char * (*grub_env_get_pf)(const char *name);
typedef int (*grub_env_printf_pf)(const char *fmt, ...); typedef int (*grub_env_printf_pf)(const char *fmt, ...);
@@ -38,6 +39,7 @@ typedef struct ventoy_grub_param_file_replace
typedef struct ventoy_grub_param typedef struct ventoy_grub_param
{ {
grub_env_get_pf grub_env_get; grub_env_get_pf grub_env_get;
grub_env_set_pf grub_env_set;
ventoy_grub_param_file_replace file_replace; ventoy_grub_param_file_replace file_replace;
grub_env_printf_pf grub_env_printf; grub_env_printf_pf grub_env_printf;
}ventoy_grub_param; }ventoy_grub_param;

View File

@@ -743,8 +743,8 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
if (!ctx.filename && dirent.namelen == 1 && name[0] == 1) if (!ctx.filename && dirent.namelen == 1 && name[0] == 1)
ctx.filename = (char *) ".."; ctx.filename = (char *) "..";
if (g_fs_name_nocase) if (g_fs_name_nocase)
ctx.type |= GRUB_FSHELP_CASE_INSENSITIVE; ctx.type |= GRUB_FSHELP_CASE_INSENSITIVE;
/* The filename was not stored in a rock ridge entry. Read it /* The filename was not stored in a rock ridge entry. Read it
from the iso9660 filesystem. */ from the iso9660 filesystem. */

View File

@@ -70,10 +70,10 @@ SetLogging(VOID)
CHAR16 LogVar[4]; CHAR16 LogVar[4];
UINTN i, LogVarSize = sizeof(LogVar); UINTN i, LogVarSize = sizeof(LogVar);
i = LogVarSize; i = LogVarSize;
Status = RT->GetVariable(L"FS_NAME_NOCASE", &ShellVariable, NULL, &i, LogVar); Status = RT->GetVariable(L"FS_NAME_NOCASE", &ShellVariable, NULL, &i, LogVar);
if (Status == EFI_SUCCESS) if (Status == EFI_SUCCESS)
g_fs_name_nocase = 1; g_fs_name_nocase = 1;
Status = RT->GetVariable(L"FS_LOGGING", &ShellVariable, NULL, &LogVarSize, LogVar); Status = RT->GetVariable(L"FS_LOGGING", &ShellVariable, NULL, &LogVarSize, LogVar);
if (Status == EFI_SUCCESS) if (Status == EFI_SUCCESS)

View File

@@ -0,0 +1 @@
1

13
EfiISO/mkefiiso.sh Normal file
View File

@@ -0,0 +1,13 @@
#!/bin/sh
rm -f ventoy_efiboot.img.*
cd ISO
mkisofs -R -D -sysid VENTOY -V VENTOY -P "longpanda admin@ventoy.net" -p 'https://www.ventoy.net' -o ../ventoy_efiboot.img ./
cd ..
xz --check=crc32 ventoy_efiboot.img
rm -f ../INSTALL/ventoy/ventoy_efiboot.img.xz
cp -a ventoy_efiboot.img.xz ../INSTALL/ventoy/

View File

@@ -0,0 +1,32 @@
#!/bin/bash
CUR="$PWD"
if ! [ -e LIBFUSE ]; then
./buidlibfuse.sh
fi
rm -f EXFAT/shared/*
rm -rf exfat-1.3.0
unzip exfat-1.3.0.zip
sed "/printf.*VERSION/a\ if (access(\"/etc/initrd-release\", F_OK) >= 0) argv[0][0] = '@';" -i exfat-1.3.0/fuse/main.c
cd exfat-1.3.0
autoreconf --install
./configure --prefix="$CUR" CFLAGS='-O2 -D_FILE_OFFSET_BITS=64' FUSE_CFLAGS="-I$CUR/LIBFUSE/include/" FUSE_LIBS="$CUR/LIBFUSE/lib/libfuse.a -lpthread -ldl"
make
strip --strip-all fuse/mount.exfat-fuse
strip --strip-all mkfs/mkexfatfs
cp fuse/mount.exfat-fuse ../EXFAT/shared/mount.exfat-fuse
cp mkfs/mkexfatfs ../EXFAT/shared/mkexfatfs
cd ..
rm -rf exfat-1.3.0

View File

@@ -0,0 +1,29 @@
#!/bin/bash
CUR="$PWD"
rm -rf libfuse
rm -rf LIBFUSE
if [ -e mirrors-libfuse-fuse-2.9.9.zip ]; then
unzip mirrors-libfuse-fuse-2.9.9.zip
cd libfuse
else
unzip libfuse-fuse-2.9.9.zip
cd libfuse-fuse-2.9.9
fi
./makeconf.sh
./configure --prefix="$CUR/LIBFUSE"
sed '/#define *__u64/d' -i include/fuse_kernel.h
sed '/#define *__s64/d' -i include/fuse_kernel.h
sed 's/__u64/uint64_t/g' -i include/fuse_kernel.h
sed 's/__s64/int64_t/g' -i include/fuse_kernel.h
make -j 16
make install
cd ..
rm -rf libfuse

View File

@@ -11,6 +11,10 @@ else
opt=-lrt opt=-lrt
fi fi
#
# use mini-native-x86_64 UCLIBC to build for x86_64
#
export C_INCLUDE_PATH=$LIBFUSE_DIR/include export C_INCLUDE_PATH=$LIBFUSE_DIR/include
rm -f $name rm -f $name

21
FUSEISO/build_aarch64.sh Normal file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
CUR="$PWD"
LIBFUSE_DIR=$CUR/LIBFUSE
name=vtoy_fuse_iso_aa64
export C_INCLUDE_PATH=$LIBFUSE_DIR/include
rm -f $name
aarch64-buildroot-linux-uclibc-gcc -static -O2 -D_FILE_OFFSET_BITS=64 vtoy_fuse_iso.c -o $name $LIBFUSE_DIR/lib/libfuse.a
if [ -e $name ]; then
echo -e "\n############### SUCCESS $name ##################\n"
else
echo -e "\n############### FAILED $name ##################\n"
fi
aarch64-buildroot-linux-uclibc-strip --strip-all $name

View File

@@ -7,6 +7,8 @@
# #
# #
# use mini-native-x86_64 UCLIBC to build for x86_64
CUR="$PWD" CUR="$PWD"
LIBFUSE_DIR=$CUR/LIBFUSE LIBFUSE_DIR=$CUR/LIBFUSE

View File

@@ -0,0 +1,46 @@
#!/bin/bash
#
#
# Package Dependency:
# gcc automake autoconf gettext gettext-devel libtool unzip
#
#
CUR="$PWD"
LIBFUSE_DIR=$CUR/LIBFUSE
rm -rf libfuse
rm -rf $LIBFUSE_DIR
# please download https://codeload.github.com/libfuse/libfuse/zip/fuse-2.9.9
if [ -e ../ExFAT/mirrors-libfuse-fuse-2.9.9.zip ]; then
rm -rf libfuse
unzip ../ExFAT/mirrors-libfuse-fuse-2.9.9.zip
cd libfuse
elif [ -e ../ExFAT/libfuse-fuse-2.9.9.zip ]; then
rm -rf libfuse-fuse-2.9.9
unzip ../ExFAT/libfuse-fuse-2.9.9.zip
cd libfuse-fuse-2.9.9
else
echo "Please download mirrors-libfuse-fuse-2.9.9.zip first"
exit 1
fi
./makeconf.sh
sed '/#define *__u64/d' -i include/fuse_kernel.h
sed '/#define *__s64/d' -i include/fuse_kernel.h
sed 's/__u64/uint64_t/g' -i include/fuse_kernel.h
sed 's/__s64/int64_t/g' -i include/fuse_kernel.h
./configure --prefix="$LIBFUSE_DIR" --host=aarch64 CC=aarch64-buildroot-linux-uclibc-gcc
make -j 16
make install
cd ..
rm -rf libfuse

BIN
FUSEISO/vtoy_fuse_iso_aa64 Normal file

Binary file not shown.

View File

@@ -1591,6 +1591,7 @@ module = {
common = ventoy/ventoy_linux.c; common = ventoy/ventoy_linux.c;
common = ventoy/ventoy_unix.c; common = ventoy/ventoy_unix.c;
common = ventoy/ventoy_windows.c; common = ventoy/ventoy_windows.c;
common = ventoy/ventoy_vhd.c;
common = ventoy/ventoy_plugin.c; common = ventoy/ventoy_plugin.c;
common = ventoy/ventoy_json.c; common = ventoy/ventoy_json.c;
common = ventoy/lzx.c; common = ventoy/lzx.c;

View File

@@ -479,7 +479,7 @@ LOCAL(stop):
jmp LOCAL(stop) jmp LOCAL(stop)
ventoy_uuid: .ascii "XXXXXXXXXXXXXXXX" ventoy_uuid: .ascii "XXXXXXXXXXXXXXXX"
notification_string: .asciz "GR" notification_string: .asciz "VT"
geometry_error_string: .asciz "Ge" geometry_error_string: .asciz "Ge"
hd_probe_error_string: .asciz "HD" hd_probe_error_string: .asciz "HD"
read_error_string: .asciz "Rd" read_error_string: .asciz "Rd"

View File

@@ -0,0 +1,353 @@
/* search.c - search devices based on a file or a filesystem label */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,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/>.
*/
#include <grub/types.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/device.h>
#include <grub/file.h>
#include <grub/env.h>
#include <grub/command.h>
#include <grub/search.h>
#include <grub/i18n.h>
#include <grub/disk.h>
#include <grub/partition.h>
GRUB_MOD_LICENSE ("GPLv3+");
static int g_no_vtoyefi_part = 0;
static char g_vtoyefi_dosname[64];
static char g_vtoyefi_gptname[64];
struct cache_entry
{
struct cache_entry *next;
char *key;
char *value;
};
static struct cache_entry *cache;
/* Context for FUNC_NAME. */
struct search_ctx
{
const char *key;
const char *var;
int no_floppy;
char **hints;
unsigned nhints;
int count;
int is_cache;
};
/* Helper for FUNC_NAME. */
static int
iterate_device (const char *name, void *data)
{
struct search_ctx *ctx = data;
int found = 0;
/* Skip floppy drives when requested. */
if (ctx->no_floppy &&
name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9')
return 1;
if (g_no_vtoyefi_part && (grub_strcmp(name, g_vtoyefi_dosname) == 0 || grub_strcmp(name, g_vtoyefi_gptname) == 0)) {
return 0;
}
#ifdef DO_SEARCH_FS_UUID
#define compare_fn grub_strcasecmp
#else
#define compare_fn grub_strcmp
#endif
#ifdef DO_SEARCH_FILE
{
char *buf;
grub_file_t file;
buf = grub_xasprintf ("(%s)%s", name, ctx->key);
if (! buf)
return 1;
file = grub_file_open (buf, GRUB_FILE_TYPE_FS_SEARCH
| GRUB_FILE_TYPE_NO_DECOMPRESS);
if (file)
{
found = 1;
grub_file_close (file);
}
grub_free (buf);
}
#else
{
/* SEARCH_FS_UUID or SEARCH_LABEL */
grub_device_t dev;
grub_fs_t fs;
char *quid;
dev = grub_device_open (name);
if (dev)
{
fs = grub_fs_probe (dev);
#ifdef DO_SEARCH_FS_UUID
#define read_fn fs_uuid
#else
#define read_fn fs_label
#endif
if (fs && fs->read_fn)
{
fs->read_fn (dev, &quid);
if (grub_errno == GRUB_ERR_NONE && quid)
{
if (compare_fn (quid, ctx->key) == 0)
found = 1;
grub_free (quid);
}
}
grub_device_close (dev);
}
}
#endif
if (!ctx->is_cache && found && ctx->count == 0)
{
struct cache_entry *cache_ent;
cache_ent = grub_malloc (sizeof (*cache_ent));
if (cache_ent)
{
cache_ent->key = grub_strdup (ctx->key);
cache_ent->value = grub_strdup (name);
if (cache_ent->value && cache_ent->key)
{
cache_ent->next = cache;
cache = cache_ent;
}
else
{
grub_free (cache_ent->value);
grub_free (cache_ent->key);
grub_free (cache_ent);
grub_errno = GRUB_ERR_NONE;
}
}
else
grub_errno = GRUB_ERR_NONE;
}
if (found)
{
ctx->count++;
if (ctx->var)
grub_env_set (ctx->var, name);
else
grub_printf (" %s", name);
}
grub_errno = GRUB_ERR_NONE;
return (found && ctx->var);
}
/* Helper for FUNC_NAME. */
static int
part_hook (grub_disk_t disk, const grub_partition_t partition, void *data)
{
struct search_ctx *ctx = data;
char *partition_name, *devname;
int ret;
partition_name = grub_partition_get_name (partition);
if (! partition_name)
return 1;
devname = grub_xasprintf ("%s,%s", disk->name, partition_name);
grub_free (partition_name);
if (!devname)
return 1;
ret = iterate_device (devname, ctx);
grub_free (devname);
return ret;
}
/* Helper for FUNC_NAME. */
static void
try (struct search_ctx *ctx)
{
unsigned i;
struct cache_entry **prev;
struct cache_entry *cache_ent;
for (prev = &cache, cache_ent = *prev; cache_ent;
prev = &cache_ent->next, cache_ent = *prev)
if (compare_fn (cache_ent->key, ctx->key) == 0)
break;
if (cache_ent)
{
ctx->is_cache = 1;
if (iterate_device (cache_ent->value, ctx))
{
ctx->is_cache = 0;
return;
}
ctx->is_cache = 0;
/* Cache entry was outdated. Remove it. */
if (!ctx->count)
{
*prev = cache_ent->next;
grub_free (cache_ent->key);
grub_free (cache_ent->value);
grub_free (cache_ent);
}
}
for (i = 0; i < ctx->nhints; i++)
{
char *end;
if (!ctx->hints[i][0])
continue;
end = ctx->hints[i] + grub_strlen (ctx->hints[i]) - 1;
if (*end == ',')
*end = 0;
if (iterate_device (ctx->hints[i], ctx))
{
if (!*end)
*end = ',';
return;
}
if (!*end)
{
grub_device_t dev;
int ret;
dev = grub_device_open (ctx->hints[i]);
if (!dev)
{
if (!*end)
*end = ',';
continue;
}
if (!dev->disk)
{
grub_device_close (dev);
if (!*end)
*end = ',';
continue;
}
ret = grub_partition_iterate (dev->disk, part_hook, ctx);
if (!*end)
*end = ',';
grub_device_close (dev);
if (ret)
return;
}
}
grub_device_iterate (iterate_device, ctx);
}
void
FUNC_NAME (const char *key, const char *var, int no_floppy,
char **hints, unsigned nhints)
{
struct search_ctx ctx = {
.key = key,
.var = var,
.no_floppy = no_floppy,
.hints = hints,
.nhints = nhints,
.count = 0,
.is_cache = 0
};
grub_fs_autoload_hook_t saved_autoload;
g_no_vtoyefi_part = 0;
if (grub_env_get("VTOY_SEARCH_NO_VTOYEFI"))
{
grub_snprintf(g_vtoyefi_dosname, sizeof(g_vtoyefi_dosname), "%s,msdos2", grub_env_get("vtoydev"));
grub_snprintf(g_vtoyefi_gptname, sizeof(g_vtoyefi_gptname), "%s,gpt2", grub_env_get("vtoydev"));
g_no_vtoyefi_part = 1;
}
/* First try without autoloading if we're setting variable. */
if (var)
{
saved_autoload = grub_fs_autoload_hook;
grub_fs_autoload_hook = 0;
try (&ctx);
/* Restore autoload hook. */
grub_fs_autoload_hook = saved_autoload;
/* Retry with autoload if nothing found. */
if (grub_errno == GRUB_ERR_NONE && ctx.count == 0)
try (&ctx);
}
else
try (&ctx);
if (grub_errno == GRUB_ERR_NONE && ctx.count == 0)
grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device: %s", key);
}
static grub_err_t
grub_cmd_do_search (grub_command_t cmd __attribute__ ((unused)), int argc,
char **args)
{
if (argc == 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
FUNC_NAME (args[0], argc == 1 ? 0 : args[1], 0, (args + 2),
argc > 2 ? argc - 2 : 0);
return grub_errno;
}
static grub_command_t cmd;
#ifdef DO_SEARCH_FILE
GRUB_MOD_INIT(search_fs_file)
#elif defined (DO_SEARCH_FS_UUID)
GRUB_MOD_INIT(search_fs_uuid)
#else
GRUB_MOD_INIT(search_label)
#endif
{
cmd =
grub_register_command (COMMAND_NAME, grub_cmd_do_search,
N_("NAME [VARIABLE] [HINTS]"),
HELP_MESSAGE);
}
#ifdef DO_SEARCH_FILE
GRUB_MOD_FINI(search_fs_file)
#elif defined (DO_SEARCH_FS_UUID)
GRUB_MOD_FINI(search_fs_uuid)
#else
GRUB_MOD_FINI(search_label)
#endif
{
grub_unregister_command (cmd);
}

View File

@@ -0,0 +1,839 @@
/* theme_loader.c - Theme file loader for gfxmenu. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 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/types.h>
#include <grub/file.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/video.h>
#include <grub/gui_string_util.h>
#include <grub/bitmap.h>
#include <grub/bitmap_scale.h>
#include <grub/gfxwidgets.h>
#include <grub/gfxmenu_view.h>
#include <grub/gui.h>
#include <grub/color.h>
#include <grub/env.h>
static grub_err_t
parse_proportional_spec (const char *value, signed *abs, grub_fixed_signed_t *prop);
/* Construct a new box widget using ABSPATTERN to find the pixmap files for
it, storing the new box instance at *BOXPTR.
PATTERN should be of the form: "(hd0,0)/somewhere/style*.png".
The '*' then gets substituted with the various pixmap names that the
box uses. */
static grub_err_t
recreate_box_absolute (grub_gfxmenu_box_t *boxptr, const char *abspattern)
{
char *prefix;
char *suffix;
char *star;
grub_gfxmenu_box_t box;
star = grub_strchr (abspattern, '*');
if (! star)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"missing `*' in box pixmap pattern `%s'", abspattern);
/* Prefix: Get the part before the '*'. */
prefix = grub_malloc (star - abspattern + 1);
if (! prefix)
return grub_errno;
grub_memcpy (prefix, abspattern, star - abspattern);
prefix[star - abspattern] = '\0';
/* Suffix: Everything after the '*' is the suffix. */
suffix = star + 1;
box = grub_gfxmenu_create_box (prefix, suffix);
grub_free (prefix);
if (! box)
return grub_errno;
if (*boxptr)
(*boxptr)->destroy (*boxptr);
*boxptr = box;
return grub_errno;
}
/* Construct a new box widget using PATTERN to find the pixmap files for it,
storing the new widget at *BOXPTR. PATTERN should be of the form:
"somewhere/style*.png". The '*' then gets substituted with the various
pixmap names that the widget uses.
Important! The value of *BOXPTR must be initialized! It must either
(1) Be 0 (a NULL pointer), or
(2) Be a pointer to a valid 'grub_gfxmenu_box_t' instance.
In this case, the previous instance is destroyed. */
grub_err_t
grub_gui_recreate_box (grub_gfxmenu_box_t *boxptr,
const char *pattern, const char *theme_dir)
{
char *abspattern;
/* Check arguments. */
if (! pattern)
{
/* If no pixmap pattern is given, then just create an empty box. */
if (*boxptr)
(*boxptr)->destroy (*boxptr);
*boxptr = grub_gfxmenu_create_box (0, 0);
return grub_errno;
}
if (! theme_dir)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"styled box missing theme directory");
/* Resolve to an absolute path. */
abspattern = grub_resolve_relative_path (theme_dir, pattern);
if (! abspattern)
return grub_errno;
/* Create the box. */
recreate_box_absolute (boxptr, abspattern);
grub_free (abspattern);
return grub_errno;
}
static grub_err_t
theme_get_unsigned_int_from_proportional (const char *value,
unsigned absolute_value,
unsigned int *parsed_value)
{
grub_err_t err;
grub_fixed_signed_t frac;
signed pixels;
err = parse_proportional_spec (value, &pixels, &frac);
if (err != GRUB_ERR_NONE)
return err;
int result = grub_fixed_sfs_multiply (absolute_value, frac) + pixels;
if (result < 0)
result = 0;
*parsed_value = result;
return GRUB_ERR_NONE;
}
/* Set the specified property NAME on the view to the given string VALUE.
The caller is responsible for the lifetimes of NAME and VALUE. */
static grub_err_t
theme_set_string (grub_gfxmenu_view_t view,
const char *name,
const char *value,
const char *theme_dir,
const char *filename,
int line_num,
int col_num)
{
if (! grub_strcmp ("title-font", name))
view->title_font = grub_font_get (value);
else if (! grub_strcmp ("message-font", name))
view->message_font = grub_font_get (value);
else if (! grub_strcmp ("terminal-font", name))
{
grub_free (view->terminal_font_name);
view->terminal_font_name = grub_strdup (value);
if (! view->terminal_font_name)
return grub_errno;
}
else if (! grub_strcmp ("title-color", name))
grub_video_parse_color (value, &view->title_color);
else if (! grub_strcmp ("message-color", name))
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 ("desktop-image", name))
{
struct grub_video_bitmap *raw_bitmap;
char *path;
path = grub_resolve_relative_path (theme_dir, value);
if (! path)
return grub_errno;
if (grub_video_bitmap_load (&raw_bitmap, path) != GRUB_ERR_NONE)
{
grub_free (path);
return grub_errno;
}
grub_free(path);
grub_video_bitmap_destroy (view->raw_desktop_image);
view->raw_desktop_image = raw_bitmap;
}
else if (! grub_strcmp ("desktop-image-scale-method", name))
{
if (! value || ! grub_strcmp ("stretch", value))
view->desktop_image_scale_method =
GRUB_VIDEO_BITMAP_SELECTION_METHOD_STRETCH;
else if (! grub_strcmp ("crop", value))
view->desktop_image_scale_method =
GRUB_VIDEO_BITMAP_SELECTION_METHOD_CROP;
else if (! grub_strcmp ("padding", value))
view->desktop_image_scale_method =
GRUB_VIDEO_BITMAP_SELECTION_METHOD_PADDING;
else if (! grub_strcmp ("fitwidth", value))
view->desktop_image_scale_method =
GRUB_VIDEO_BITMAP_SELECTION_METHOD_FITWIDTH;
else if (! grub_strcmp ("fitheight", value))
view->desktop_image_scale_method =
GRUB_VIDEO_BITMAP_SELECTION_METHOD_FITHEIGHT;
else
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"Unsupported scale method: %s",
value);
}
else if (! grub_strcmp ("desktop-image-h-align", name))
{
if (! grub_strcmp ("left", value))
view->desktop_image_h_align = GRUB_VIDEO_BITMAP_H_ALIGN_LEFT;
else if (! grub_strcmp ("center", value))
view->desktop_image_h_align = GRUB_VIDEO_BITMAP_H_ALIGN_CENTER;
else if (! grub_strcmp ("right", value))
view->desktop_image_h_align = GRUB_VIDEO_BITMAP_H_ALIGN_RIGHT;
else
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"Unsupported horizontal align method: %s",
value);
}
else if (! grub_strcmp ("desktop-image-v-align", name))
{
if (! grub_strcmp ("top", value))
view->desktop_image_v_align = GRUB_VIDEO_BITMAP_V_ALIGN_TOP;
else if (! grub_strcmp ("center", value))
view->desktop_image_v_align = GRUB_VIDEO_BITMAP_V_ALIGN_CENTER;
else if (! grub_strcmp ("bottom", value))
view->desktop_image_v_align = GRUB_VIDEO_BITMAP_V_ALIGN_BOTTOM;
else
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"Unsupported vertical align method: %s",
value);
}
else if (! grub_strcmp ("desktop-color", name))
grub_video_parse_color (value, &view->desktop_color);
else if (! grub_strcmp ("terminal-box", name))
{
grub_err_t err;
err = grub_gui_recreate_box (&view->terminal_box, value, theme_dir);
if (err != GRUB_ERR_NONE)
return err;
}
else if (! grub_strcmp ("terminal-border", name))
{
view->terminal_border = grub_strtoul (value, 0, 10);
if (grub_errno)
return grub_errno;
}
else if (! grub_strcmp ("terminal-left", name))
{
unsigned int tmp;
int err = theme_get_unsigned_int_from_proportional (value,
view->screen.width,
&tmp);
if (err != GRUB_ERR_NONE)
return err;
view->terminal_rect.x = tmp;
}
else if (! grub_strcmp ("terminal-top", name))
{
unsigned int tmp;
int err = theme_get_unsigned_int_from_proportional (value,
view->screen.height,
&tmp);
if (err != GRUB_ERR_NONE)
return err;
view->terminal_rect.y = tmp;
}
else if (! grub_strcmp ("terminal-width", name))
{
unsigned int tmp;
int err = theme_get_unsigned_int_from_proportional (value,
view->screen.width,
&tmp);
if (err != GRUB_ERR_NONE)
return err;
view->terminal_rect.width = tmp;
}
else if (! grub_strcmp ("terminal-height", name))
{
unsigned int tmp;
int err = theme_get_unsigned_int_from_proportional (value,
view->screen.height,
&tmp);
if (err != GRUB_ERR_NONE)
return err;
view->terminal_rect.height = tmp;
}
else if (! grub_strcmp ("title-text", name))
{
grub_free (view->title_text);
view->title_text = grub_strdup (value);
if (! view->title_text)
return grub_errno;
}
else
{
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"%s:%d:%d unknown property `%s'",
filename, line_num, col_num, name);
}
return grub_errno;
}
struct parsebuf
{
char *buf;
int pos;
int len;
int line_num;
int col_num;
const char *filename;
char *theme_dir;
grub_gfxmenu_view_t view;
};
static int
has_more (struct parsebuf *p)
{
return p->pos < p->len;
}
static int
read_char (struct parsebuf *p)
{
if (has_more (p))
{
char c;
c = p->buf[p->pos++];
if (c == '\n')
{
p->line_num++;
p->col_num = 1;
}
else
{
p->col_num++;
}
return c;
}
else
return -1;
}
static int
peek_char (struct parsebuf *p)
{
if (has_more (p))
return p->buf[p->pos];
else
return -1;
}
static int
is_whitespace (char c)
{
return (c == ' '
|| c == '\t'
|| c == '\r'
|| c == '\n'
|| c == '\f');
}
static void
skip_whitespace (struct parsebuf *p)
{
while (has_more (p) && is_whitespace(peek_char (p)))
read_char (p);
}
static void
advance_to_next_line (struct parsebuf *p)
{
int c;
/* Eat characters up to the newline. */
do
{
c = read_char (p);
}
while (c != -1 && c != '\n');
}
static int
is_identifier_char (int c)
{
return (c != -1
&& (grub_isalpha(c)
|| grub_isdigit(c)
|| c == '_'
|| c == '-'));
}
static char *
read_identifier (struct parsebuf *p)
{
/* Index of the first character of the identifier in p->buf. */
int start;
/* Next index after the last character of the identifer in p->buf. */
int end;
skip_whitespace (p);
/* Capture the start of the identifier. */
start = p->pos;
/* Scan for the end. */
while (is_identifier_char (peek_char (p)))
read_char (p);
end = p->pos;
if (end - start < 1)
return 0;
return grub_new_substring (p->buf, start, end);
}
static char *
read_expression (struct parsebuf *p)
{
int start;
int end;
skip_whitespace (p);
if (peek_char (p) == '"')
{
/* Read as a quoted string.
The quotation marks are not included in the expression value. */
/* Skip opening quotation mark. */
read_char (p);
start = p->pos;
while (has_more (p) && peek_char (p) != '"')
read_char (p);
end = p->pos;
/* Skip the terminating quotation mark. */
read_char (p);
}
else if (peek_char (p) == '(')
{
/* Read as a parenthesized string -- for tuples/coordinates. */
/* The parentheses are included in the expression value. */
int c;
start = p->pos;
do
{
c = read_char (p);
}
while (c != -1 && c != ')');
end = p->pos;
}
else if (has_more (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)))
read_char (p);
end = p->pos;
}
else
{
/* The end of the theme file has been reached. */
grub_error (GRUB_ERR_IO, "%s:%d:%d expression expected in theme file",
p->filename, p->line_num, p->col_num);
return 0;
}
return grub_new_substring (p->buf, start, end);
}
static grub_err_t
parse_proportional_spec (const char *value, signed *abs, grub_fixed_signed_t *prop)
{
signed num;
const char *ptr;
int sig = 0;
*abs = 0;
*prop = 0;
ptr = value;
while (*ptr)
{
sig = 0;
while (*ptr == '-' || *ptr == '+')
{
if (*ptr == '-')
sig = !sig;
ptr++;
}
num = grub_strtoul (ptr, (char **) &ptr, 0);
if (grub_errno)
return grub_errno;
if (sig)
num = -num;
if (*ptr == '%')
{
*prop += grub_fixed_fsf_divide (grub_signed_to_fixed (num), 100);
ptr++;
}
else
*abs += num;
}
return GRUB_ERR_NONE;
}
/* Read a GUI object specification from the theme file.
Any components created will be added to the GUI container PARENT. */
static grub_err_t
read_object (struct parsebuf *p, grub_gui_container_t parent)
{
grub_video_rect_t bounds;
char *name;
name = read_identifier (p);
if (! name)
goto cleanup;
grub_gui_component_t component = 0;
if (grub_strcmp (name, "label") == 0)
{
component = grub_gui_label_new ();
}
else if (grub_strcmp (name, "image") == 0)
{
component = grub_gui_image_new ();
}
else if (grub_strcmp (name, "vbox") == 0)
{
component = (grub_gui_component_t) grub_gui_vbox_new ();
}
else if (grub_strcmp (name, "hbox") == 0)
{
component = (grub_gui_component_t) grub_gui_hbox_new ();
}
else if (grub_strcmp (name, "canvas") == 0)
{
component = (grub_gui_component_t) grub_gui_canvas_new ();
}
else if (grub_strcmp (name, "progress_bar") == 0)
{
component = grub_gui_progress_bar_new ();
}
else if (grub_strcmp (name, "circular_progress") == 0)
{
component = grub_gui_circular_progress_new ();
}
else if (grub_strcmp (name, "boot_menu") == 0)
{
component = grub_gui_list_new ();
}
else
{
/* Unknown type. */
grub_error (GRUB_ERR_IO, "%s:%d:%d unknown object type `%s'",
p->filename, p->line_num, p->col_num, name);
goto cleanup;
}
if (! component)
goto cleanup;
/* Inform the component about the theme so it can find its resources. */
component->ops->set_property (component, "theme_dir", p->theme_dir);
component->ops->set_property (component, "theme_path", p->filename);
/* Add the component as a child of PARENT. */
bounds.x = 0;
bounds.y = 0;
bounds.width = -1;
bounds.height = -1;
component->ops->set_bounds (component, &bounds);
parent->ops->add (parent, component);
skip_whitespace (p);
if (read_char (p) != '{')
{
grub_error (GRUB_ERR_IO,
"%s:%d:%d expected `{' after object type name `%s'",
p->filename, p->line_num, p->col_num, name);
goto cleanup;
}
while (has_more (p))
{
skip_whitespace (p);
/* Check whether the end has been encountered. */
if (peek_char (p) == '}')
{
/* Skip the closing brace. */
read_char (p);
break;
}
if (peek_char (p) == '#')
{
/* Skip comments. */
advance_to_next_line (p);
continue;
}
if (peek_char (p) == '+')
{
/* Skip the '+'. */
read_char (p);
/* Check whether this component is a container. */
if (component->ops->is_instance (component, "container"))
{
/* Read the sub-object recursively and add it as a child. */
if (read_object (p, (grub_gui_container_t) component) != 0)
goto cleanup;
/* After reading the sub-object, resume parsing, expecting
another property assignment or sub-object definition. */
continue;
}
else
{
grub_error (GRUB_ERR_IO,
"%s:%d:%d attempted to add object to non-container",
p->filename, p->line_num, p->col_num);
goto cleanup;
}
}
char *property;
property = read_identifier (p);
if (! property)
{
grub_error (GRUB_ERR_IO, "%s:%d:%d identifier expected in theme file",
p->filename, p->line_num, p->col_num);
goto cleanup;
}
skip_whitespace (p);
if (read_char (p) != '=')
{
grub_error (GRUB_ERR_IO,
"%s:%d:%d expected `=' after property name `%s'",
p->filename, p->line_num, p->col_num, property);
grub_free (property);
goto cleanup;
}
skip_whitespace (p);
char *value;
value = read_expression (p);
if (! value)
{
grub_free (property);
goto cleanup;
}
/* Handle the property value. */
if (grub_strcmp (property, "left") == 0)
parse_proportional_spec (value, &component->x, &component->xfrac);
else if (grub_strcmp (property, "top") == 0)
parse_proportional_spec (value, &component->y, &component->yfrac);
else if (grub_strcmp (property, "width") == 0)
parse_proportional_spec (value, &component->w, &component->wfrac);
else if (grub_strcmp (property, "height") == 0)
parse_proportional_spec (value, &component->h, &component->hfrac);
else
/* General property handling. */
component->ops->set_property (component, property, value);
grub_free (value);
grub_free (property);
if (grub_errno != GRUB_ERR_NONE)
goto cleanup;
}
cleanup:
grub_free (name);
return grub_errno;
}
static grub_err_t
read_property (struct parsebuf *p)
{
char *name;
/* Read the property name. */
name = read_identifier (p);
if (! name)
{
advance_to_next_line (p);
return grub_errno;
}
/* Skip whitespace before separator. */
skip_whitespace (p);
/* Read separator. */
if (read_char (p) != ':')
{
grub_error (GRUB_ERR_IO,
"%s:%d:%d missing separator after property name `%s'",
p->filename, p->line_num, p->col_num, name);
goto done;
}
/* Skip whitespace after separator. */
skip_whitespace (p);
/* Get the value based on its type. */
if (peek_char (p) == '"')
{
/* String value (e.g., '"My string"'). */
char *value = read_expression (p);
if (! value)
{
grub_error (GRUB_ERR_IO, "%s:%d:%d missing property value",
p->filename, p->line_num, p->col_num);
goto done;
}
/* If theme_set_string results in an error, grub_errno will be returned
below. */
theme_set_string (p->view, name, value, p->theme_dir,
p->filename, p->line_num, p->col_num);
grub_free (value);
}
else
{
grub_error (GRUB_ERR_IO,
"%s:%d:%d property value invalid; "
"enclose literal values in quotes (\")",
p->filename, p->line_num, p->col_num);
goto done;
}
done:
grub_free (name);
return grub_errno;
}
/* 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_file_t file;
struct parsebuf p;
p.view = view;
p.theme_dir = grub_get_dirname (theme_path);
file = grub_file_open (theme_path, GRUB_FILE_TYPE_THEME);
if (! file)
{
grub_free (p.theme_dir);
return grub_errno;
}
p.len = grub_file_size (file);
p.buf = grub_malloc (p.len + 4096);
p.pos = 0;
p.line_num = 1;
p.col_num = 1;
p.filename = theme_path;
if (! p.buf)
{
grub_file_close (file);
grub_free (p.theme_dir);
return grub_errno;
}
if (grub_file_read (file, p.buf, p.len) != p.len)
{
grub_free (p.buf);
grub_file_close (file);
grub_free (p.theme_dir);
return grub_errno;
}
{
const char *checkret = grub_env_get("VTOY_CHKDEV_RESULT_STRING");
if (checkret == NULL || checkret[0] != '0')
{
p.len += grub_snprintf(p.buf + p.len, 4096, "\n+ hbox{\n left = 1%%\n top = 90%%\n"
" + label {text = \"[Unofficial Ventoy]\" color = \"red\" align = \"left\"}\n"
"}\n");
}
}
if (view->canvas)
view->canvas->component.ops->destroy (view->canvas);
view->canvas = grub_gui_canvas_new ();
if (!view->canvas)
goto fail;
((grub_gui_component_t) view->canvas)
->ops->set_bounds ((grub_gui_component_t) view->canvas,
&view->screen);
while (has_more (&p))
{
/* Skip comments (lines beginning with #). */
if (peek_char (&p) == '#')
{
advance_to_next_line (&p);
continue;
}
/* Find the first non-whitespace character. */
skip_whitespace (&p);
/* Handle the content. */
if (peek_char (&p) == '+')
{
/* Skip the '+'. */
read_char (&p);
read_object (&p, view->canvas);
}
else
{
read_property (&p);
}
if (grub_errno != GRUB_ERR_NONE)
goto fail;
}
/* Set the new theme path. */
grub_free (view->theme_path);
view->theme_path = grub_strdup (theme_path);
goto cleanup;
fail:
if (view->canvas)
{
view->canvas->component.ops->destroy (view->canvas);
view->canvas = 0;
}
cleanup:
grub_free (p.buf);
grub_file_close (file);
grub_free (p.theme_dir);
return grub_errno;
}

View File

@@ -0,0 +1,647 @@
/* view.c - Graphical menu interface MVC view. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 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/types.h>
#include <grub/file.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/normal.h>
#include <grub/video.h>
#include <grub/gfxterm.h>
#include <grub/bitmap.h>
#include <grub/bitmap_scale.h>
#include <grub/term.h>
#include <grub/gfxwidgets.h>
#include <grub/time.h>
#include <grub/menu.h>
#include <grub/menu_viewer.h>
#include <grub/gfxmenu_view.h>
#include <grub/gui_string_util.h>
#include <grub/icon_manager.h>
#include <grub/i18n.h>
static void
init_terminal (grub_gfxmenu_view_t view);
static void
init_background (grub_gfxmenu_view_t view);
static grub_gfxmenu_view_t term_view;
/* Create a new view object, loading the theme specified by THEME_PATH and
associating MODEL with the view. */
grub_gfxmenu_view_t
grub_gfxmenu_view_new (const char *theme_path,
int width, int height)
{
grub_gfxmenu_view_t view;
grub_font_t default_font;
grub_video_rgba_color_t default_fg_color;
grub_video_rgba_color_t default_bg_color;
view = grub_malloc (sizeof (*view));
if (! view)
return 0;
while (grub_gfxmenu_timeout_notifications)
{
struct grub_gfxmenu_timeout_notify *p;
p = grub_gfxmenu_timeout_notifications;
grub_gfxmenu_timeout_notifications = grub_gfxmenu_timeout_notifications->next;
grub_free (p);
}
view->screen.x = 0;
view->screen.y = 0;
view->screen.width = width;
view->screen.height = height;
view->need_to_check_sanity = 1;
view->terminal_border = 3;
view->terminal_rect.width = view->screen.width * 7 / 10;
view->terminal_rect.height = view->screen.height * 7 / 10;
view->terminal_rect.x = view->screen.x + (view->screen.width
- view->terminal_rect.width) / 2;
view->terminal_rect.y = view->screen.y + (view->screen.height
- view->terminal_rect.height) / 2;
default_font = grub_font_get ("Unknown Regular 16");
default_fg_color = grub_video_rgba_color_rgb (0, 0, 0);
default_bg_color = grub_video_rgba_color_rgb (255, 255, 255);
view->canvas = 0;
view->title_font = default_font;
view->message_font = default_font;
view->terminal_font_name = grub_strdup ("Fixed 10");
view->title_color = default_fg_color;
view->message_color = default_bg_color;
view->message_bg_color = default_fg_color;
view->raw_desktop_image = 0;
view->scaled_desktop_image = 0;
view->desktop_image_scale_method = GRUB_VIDEO_BITMAP_SELECTION_METHOD_STRETCH;
view->desktop_image_h_align = GRUB_VIDEO_BITMAP_H_ALIGN_CENTER;
view->desktop_image_v_align = GRUB_VIDEO_BITMAP_V_ALIGN_CENTER;
view->desktop_color = default_bg_color;
view->terminal_box = grub_gfxmenu_create_box (0, 0);
view->title_text = grub_strdup (_("GRUB Boot Menu"));
view->progress_message_text = 0;
view->theme_path = 0;
/* Set the timeout bar's frame. */
view->progress_message_frame.width = view->screen.width * 4 / 5;
view->progress_message_frame.height = 50;
view->progress_message_frame.x = view->screen.x
+ (view->screen.width - view->progress_message_frame.width) / 2;
view->progress_message_frame.y = view->screen.y
+ view->screen.height - 90 - 20 - view->progress_message_frame.height;
if (grub_gfxmenu_view_load_theme (view, theme_path) != 0)
{
grub_gfxmenu_view_destroy (view);
return 0;
}
return view;
}
/* Destroy the view object. All used memory is freed. */
void
grub_gfxmenu_view_destroy (grub_gfxmenu_view_t view)
{
if (!view)
return;
while (grub_gfxmenu_timeout_notifications)
{
struct grub_gfxmenu_timeout_notify *p;
p = grub_gfxmenu_timeout_notifications;
grub_gfxmenu_timeout_notifications = grub_gfxmenu_timeout_notifications->next;
grub_free (p);
}
grub_video_bitmap_destroy (view->raw_desktop_image);
grub_video_bitmap_destroy (view->scaled_desktop_image);
if (view->terminal_box)
view->terminal_box->destroy (view->terminal_box);
grub_free (view->terminal_font_name);
grub_free (view->title_text);
grub_free (view->progress_message_text);
grub_free (view->theme_path);
if (view->canvas)
view->canvas->component.ops->destroy (view->canvas);
grub_free (view);
}
static void
redraw_background (grub_gfxmenu_view_t view,
const grub_video_rect_t *bounds)
{
if (view->scaled_desktop_image)
{
struct grub_video_bitmap *img = view->scaled_desktop_image;
grub_video_blit_bitmap (img, GRUB_VIDEO_BLIT_REPLACE,
bounds->x, bounds->y,
bounds->x - view->screen.x,
bounds->y - view->screen.y,
bounds->width, bounds->height);
}
else
{
grub_video_fill_rect (grub_video_map_rgba_color (view->desktop_color),
bounds->x, bounds->y,
bounds->width, bounds->height);
}
}
static void
draw_title (grub_gfxmenu_view_t view)
{
if (! view->title_text)
return;
/* Center the title. */
int title_width = grub_font_get_string_width (view->title_font,
view->title_text);
int x = (view->screen.width - title_width) / 2;
int y = 40 + grub_font_get_ascent (view->title_font);
grub_font_draw_string (view->title_text,
view->title_font,
grub_video_map_rgba_color (view->title_color),
x, y);
}
struct progress_value_data
{
int visible;
int start;
int end;
int value;
};
struct grub_gfxmenu_timeout_notify *grub_gfxmenu_timeout_notifications;
static void
update_timeouts (int visible, int start, int value, int end)
{
struct grub_gfxmenu_timeout_notify *cur;
for (cur = grub_gfxmenu_timeout_notifications; cur; cur = cur->next)
cur->set_state (cur->self, visible, start, value, end);
}
static void
redraw_timeouts (struct grub_gfxmenu_view *view)
{
struct grub_gfxmenu_timeout_notify *cur;
for (cur = grub_gfxmenu_timeout_notifications; cur; cur = cur->next)
{
grub_video_rect_t bounds;
cur->self->ops->get_bounds (cur->self, &bounds);
grub_video_set_area_status (GRUB_VIDEO_AREA_ENABLED);
grub_gfxmenu_view_redraw (view, &bounds);
}
}
void
grub_gfxmenu_print_timeout (int timeout, void *data)
{
struct grub_gfxmenu_view *view = data;
if (view->first_timeout == -1)
view->first_timeout = timeout;
update_timeouts (1, -view->first_timeout, -timeout, 0);
redraw_timeouts (view);
grub_video_swap_buffers ();
if (view->double_repaint)
redraw_timeouts (view);
}
void
grub_gfxmenu_clear_timeout (void *data)
{
struct grub_gfxmenu_view *view = data;
update_timeouts (0, 1, 0, 0);
redraw_timeouts (view);
grub_video_swap_buffers ();
if (view->double_repaint)
redraw_timeouts (view);
}
static void
update_menu_visit (grub_gui_component_t component,
void *userdata)
{
grub_gfxmenu_view_t view;
view = userdata;
if (component->ops->is_instance (component, "list"))
{
grub_gui_list_t list = (grub_gui_list_t) component;
list->ops->set_view_info (list, view);
}
}
/* Update any boot menu components with the current menu model and
theme path. */
static void
update_menu_components (grub_gfxmenu_view_t view)
{
grub_gui_iterate_recursively ((grub_gui_component_t) view->canvas,
update_menu_visit, view);
}
static void
refresh_menu_visit (grub_gui_component_t component,
void *userdata)
{
grub_gfxmenu_view_t view;
view = userdata;
if (component->ops->is_instance (component, "list"))
{
grub_gui_list_t list = (grub_gui_list_t) component;
list->ops->refresh_list (list, view);
}
}
/* Refresh list information (useful for submenus) */
static void
refresh_menu_components (grub_gfxmenu_view_t view)
{
grub_gui_iterate_recursively ((grub_gui_component_t) view->canvas,
refresh_menu_visit, view);
}
static void
draw_message (grub_gfxmenu_view_t view)
{
char *text = view->progress_message_text;
grub_video_rect_t f = view->progress_message_frame;
if (! text)
return;
grub_font_t font = view->message_font;
grub_video_color_t color = grub_video_map_rgba_color (view->message_color);
/* Border. */
grub_video_fill_rect (color,
f.x-1, f.y-1, f.width+2, f.height+2);
/* Fill. */
grub_video_fill_rect (grub_video_map_rgba_color (view->message_bg_color),
f.x, f.y, f.width, f.height);
/* Center the text. */
int text_width = grub_font_get_string_width (font, text);
int x = f.x + (f.width - text_width) / 2;
int y = (f.y + (f.height - grub_font_get_descent (font)) / 2
+ grub_font_get_ascent (font) / 2);
grub_font_draw_string (text, font, color, x, y);
}
void
grub_gfxmenu_view_redraw (grub_gfxmenu_view_t view,
const grub_video_rect_t *region)
{
if (grub_video_have_common_points (&view->terminal_rect, region))
grub_gfxterm_schedule_repaint ();
grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);
grub_video_area_status_t area_status;
grub_video_get_area_status (&area_status);
if (area_status == GRUB_VIDEO_AREA_ENABLED)
grub_video_set_region (region->x, region->y,
region->width, region->height);
redraw_background (view, region);
if (view->canvas)
view->canvas->component.ops->paint (view->canvas, region);
draw_title (view);
if (grub_video_have_common_points (&view->progress_message_frame, region))
draw_message (view);
if (area_status == GRUB_VIDEO_AREA_ENABLED)
grub_video_set_area_status (GRUB_VIDEO_AREA_ENABLED);
}
void
grub_gfxmenu_view_draw (grub_gfxmenu_view_t view)
{
init_terminal (view);
init_background (view);
/* Clear the screen; there may be garbage left over in video memory. */
grub_video_fill_rect (grub_video_map_rgb (0, 0, 0),
view->screen.x, view->screen.y,
view->screen.width, view->screen.height);
grub_video_swap_buffers ();
if (view->double_repaint)
grub_video_fill_rect (grub_video_map_rgb (0, 0, 0),
view->screen.x, view->screen.y,
view->screen.width, view->screen.height);
refresh_menu_components (view);
update_menu_components (view);
grub_video_set_area_status (GRUB_VIDEO_AREA_DISABLED);
grub_gfxmenu_view_redraw (view, &view->screen);
grub_video_swap_buffers ();
if (view->double_repaint)
{
grub_video_set_area_status (GRUB_VIDEO_AREA_DISABLED);
grub_gfxmenu_view_redraw (view, &view->screen);
}
}
static void
redraw_menu_visit (grub_gui_component_t component,
void *userdata)
{
grub_gfxmenu_view_t view;
view = userdata;
if (component->ops->is_instance (component, "list"))
{
grub_video_rect_t bounds;
component->ops->get_bounds (component, &bounds);
grub_video_set_area_status (GRUB_VIDEO_AREA_ENABLED);
grub_gfxmenu_view_redraw (view, &bounds);
}
}
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);
grub_video_swap_buffers ();
if (view->double_repaint)
{
grub_gui_iterate_recursively ((grub_gui_component_t) view->canvas,
redraw_menu_visit, view);
}
}
void
grub_gfxmenu_set_chosen_entry (int entry, void *data)
{
grub_gfxmenu_view_t view = data;
view->selected = entry;
grub_gfxmenu_redraw_menu (view);
}
static void
grub_gfxmenu_draw_terminal_box (void)
{
grub_gfxmenu_box_t term_box;
term_box = term_view->terminal_box;
if (!term_box)
return;
grub_video_set_area_status (GRUB_VIDEO_AREA_DISABLED);
term_box->set_content_size (term_box, term_view->terminal_rect.width,
term_view->terminal_rect.height);
term_box->draw (term_box,
term_view->terminal_rect.x - term_box->get_left_pad (term_box),
term_view->terminal_rect.y - term_box->get_top_pad (term_box));
}
static void
get_min_terminal (grub_font_t terminal_font,
unsigned int border_width,
unsigned int *min_terminal_width,
unsigned int *min_terminal_height)
{
struct grub_font_glyph *glyph;
glyph = grub_font_get_glyph (terminal_font, 'M');
*min_terminal_width = (glyph? glyph->device_width : 8) * 80
+ 2 * border_width;
*min_terminal_height = grub_font_get_max_char_height (terminal_font) * 24
+ 2 * border_width;
}
static void
terminal_sanity_check (grub_gfxmenu_view_t view)
{
if (!view->need_to_check_sanity)
return;
/* terminal_font was checked before in the init_terminal function. */
grub_font_t terminal_font = grub_font_get (view->terminal_font_name);
/* Non-negative numbers below. */
int scr_x = view->screen.x;
int scr_y = view->screen.y;
int scr_width = view->screen.width;
int scr_height = view->screen.height;
int term_x = view->terminal_rect.x;
int term_y = view->terminal_rect.y;
int term_width = view->terminal_rect.width;
int term_height = view->terminal_rect.height;
/* Check that border_width isn't too big. */
unsigned int border_width = view->terminal_border;
unsigned int min_terminal_width;
unsigned int min_terminal_height;
get_min_terminal (terminal_font, border_width,
&min_terminal_width, &min_terminal_height);
if (border_width > 3 && ((int) min_terminal_width >= scr_width
|| (int) min_terminal_height >= scr_height))
{
border_width = 3;
get_min_terminal (terminal_font, border_width,
&min_terminal_width, &min_terminal_height);
}
/* Sanity checks. */
if (term_width > scr_width)
term_width = scr_width;
if (term_height > scr_height)
term_height = scr_height;
if (scr_width <= (int) min_terminal_width
|| scr_height <= (int) min_terminal_height)
{
/* The screen resulution is too low. Use all space, except a small border
to show the user, that it is a window. Then center the window. */
term_width = scr_width - 6 * border_width;
term_height = scr_height - 6 * border_width;
term_x = scr_x + (scr_width - term_width) / 2;
term_y = scr_y + (scr_height - term_height) / 2;
}
else if (term_width < (int) min_terminal_width
|| term_height < (int) min_terminal_height)
{
/* The screen resolution is big enough. Make sure, that terminal screen
dimensions aren't less than minimal values. Then center the window. */
term_width = (int) min_terminal_width;
term_height = (int) min_terminal_height;
term_x = scr_x + (scr_width - term_width) / 2;
term_y = scr_y + (scr_height - term_height) / 2;
}
/* At this point w and h are satisfying. */
if (term_x + term_width > scr_width)
term_x = scr_width - term_width;
if (term_y + term_height > scr_height)
term_y = scr_height - term_height;
/* Write down corrected data. */
view->terminal_rect.x = (unsigned int) term_x;
view->terminal_rect.y = (unsigned int) term_y;
view->terminal_rect.width = (unsigned int) term_width;
view->terminal_rect.height = (unsigned int) term_height;
view->terminal_border = border_width;
view->need_to_check_sanity = 0;
}
static void
init_terminal (grub_gfxmenu_view_t view)
{
grub_font_t terminal_font;
terminal_font = grub_font_get (view->terminal_font_name);
if (!terminal_font)
{
grub_error (GRUB_ERR_BAD_FONT, "no font loaded");
return;
}
/* Check that terminal window size and position are sane. */
terminal_sanity_check (view);
term_view = view;
/* Note: currently there is no API for changing the gfxterm font
on the fly, so whatever font the initially loaded theme specifies
will be permanent. */
grub_gfxterm_set_window (GRUB_VIDEO_RENDER_TARGET_DISPLAY,
view->terminal_rect.x,
view->terminal_rect.y,
view->terminal_rect.width,
view->terminal_rect.height,
view->double_repaint,
terminal_font,
view->terminal_border);
grub_gfxterm_decorator_hook = grub_gfxmenu_draw_terminal_box;
}
static void
init_background (grub_gfxmenu_view_t view)
{
if (view->scaled_desktop_image || (!view->raw_desktop_image))
return;
struct grub_video_bitmap *scaled_bitmap;
if (view->desktop_image_scale_method ==
GRUB_VIDEO_BITMAP_SELECTION_METHOD_STRETCH)
grub_video_bitmap_create_scaled (&scaled_bitmap,
view->screen.width,
view->screen.height,
view->raw_desktop_image,
GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST);
else
grub_video_bitmap_scale_proportional (&scaled_bitmap,
view->screen.width,
view->screen.height,
view->raw_desktop_image,
GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST,
view->desktop_image_scale_method,
view->desktop_image_v_align,
view->desktop_image_h_align);
if (! scaled_bitmap)
return;
view->scaled_desktop_image = scaled_bitmap;
}
/* FIXME: previously notifications were displayed in special case.
Is it necessary?
*/
#if 0
/* Sets MESSAGE as the progress message for the view.
MESSAGE can be 0, in which case no message is displayed. */
static void
set_progress_message (grub_gfxmenu_view_t view, const char *message)
{
grub_free (view->progress_message_text);
if (message)
view->progress_message_text = grub_strdup (message);
else
view->progress_message_text = 0;
}
static void
notify_booting (grub_menu_entry_t entry, void *userdata)
{
grub_gfxmenu_view_t view = (grub_gfxmenu_view_t) userdata;
char *s = grub_malloc (100 + grub_strlen (entry->title));
if (!s)
return;
grub_sprintf (s, "Booting '%s'", entry->title);
set_progress_message (view, s);
grub_free (s);
grub_gfxmenu_view_redraw (view, &view->progress_message_frame);
grub_video_swap_buffers ();
if (view->double_repaint)
grub_gfxmenu_view_redraw (view, &view->progress_message_frame);
}
static void
notify_fallback (grub_menu_entry_t entry, void *userdata)
{
grub_gfxmenu_view_t view = (grub_gfxmenu_view_t) userdata;
char *s = grub_malloc (100 + grub_strlen (entry->title));
if (!s)
return;
grub_sprintf (s, "Falling back to '%s'", entry->title);
set_progress_message (view, s);
grub_free (s);
grub_gfxmenu_view_redraw (view, &view->progress_message_frame);
grub_video_swap_buffers ();
if (view->double_repaint)
grub_gfxmenu_view_redraw (view, &view->progress_message_frame);
}
static void
notify_execution_failure (void *userdata __attribute__ ((unused)))
{
}
static struct grub_menu_execute_callback execute_callback =
{
.notify_booting = notify_booting,
.notify_fallback = notify_fallback,
.notify_failure = notify_execution_failure
};
#endif

View File

@@ -485,6 +485,11 @@ static int ventoy_boot_opt_filter(char *opt)
return 1; return 1;
} }
if (grub_strcmp(opt, "vga=current") == 0)
{
return 1;
}
if (grub_strncmp(opt, "rdinit=", 7) == 0) if (grub_strncmp(opt, "rdinit=", 7) == 0)
{ {
if (grub_strcmp(opt, "rdinit=/vtoy/vtoy") != 0) if (grub_strcmp(opt, "rdinit=/vtoy/vtoy") != 0)
@@ -1224,7 +1229,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
linux_mem_size = 0; linux_mem_size = 0;
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
#ifdef GRUB_MACHINE_PCBIOS #ifdef GRUB_MACHINE_PCBIOS
if (grub_memcmp (argv[i], "vga=", 4) == 0) if (grub_memcmp (argv[i], "vga=", 4) == 0 && (grub_memcmp (argv[i], "vga=current", 11) != 0))
{ {
/* Video mode selection support. */ /* Video mode selection support. */
char *val = argv[i] + 4; char *val = argv[i] + 4;

View File

@@ -969,19 +969,28 @@ static struct grub_menu_execute_callback execution_callback =
static grub_err_t static grub_err_t
show_menu (grub_menu_t menu, int nested, int autobooted) show_menu (grub_menu_t menu, int nested, int autobooted)
{ {
const char *def;
def = grub_env_get("VTOY_DEFAULT_IMAGE");
while (1) while (1)
{ {
int boot_entry; int boot_entry;
grub_menu_entry_t e; grub_menu_entry_t e;
int auto_boot; int auto_boot;
boot_entry = run_menu (menu, nested, &auto_boot); boot_entry = run_menu (menu, nested, &auto_boot);
if (boot_entry < 0) if (boot_entry < 0)
break; break;
g_ventoy_last_entry = boot_entry; if (auto_boot && def && grub_strcmp(def, "VTOY_EXIT") == 0) {
if (g_ventoy_menu_esc) grub_exit();
break; }
if (autobooted == 0 && auto_boot == 0) {
g_ventoy_last_entry = boot_entry;
if (g_ventoy_menu_esc)
break;
}
e = grub_menu_get_entry (menu, boot_entry); e = grub_menu_get_entry (menu, boot_entry);
if (! e) if (! e)
@@ -999,6 +1008,9 @@ show_menu (grub_menu_t menu, int nested, int autobooted)
grub_menu_execute_entry (e, 0); grub_menu_execute_entry (e, 0);
if (autobooted) if (autobooted)
break; break;
if (2 == e->argc && e->args && e->args[1] && grub_strncmp(e->args[1], "VTOY_RUN_RET", 12) == 0)
break;
} }
return GRUB_ERR_NONE; return GRUB_ERR_NONE;

View File

@@ -190,10 +190,17 @@ command-line or ESC to discard edits and return to the GRUB menu."),
} }
else else
{ {
char szLine[128];
const char *checkret = grub_env_get("VTOY_CHKDEV_RESULT_STRING");
if (checkret == NULL || checkret[0] != '0') {
grub_snprintf(szLine, sizeof(szLine), "%s [Unofficial Ventoy]", grub_env_get("VTOY_TEXT_MENU_VER"));
} else {
grub_snprintf(szLine, sizeof(szLine), "%s", grub_env_get("VTOY_TEXT_MENU_VER"));
}
ret += grub_print_message_indented_real("\n", STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); ret += grub_print_message_indented_real("\n", STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run);
ret += grub_print_message_indented_real(grub_env_get("VTOY_TEXT_MENU_VER"), ret += grub_print_message_indented_real(szLine, STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run);
STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run);
ret += grub_print_message_indented_real("\n", STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); ret += grub_print_message_indented_real("\n", STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run);
ret += grub_print_message_indented_real(grub_env_get("VTOY_HOTKEY_TIP"), ret += grub_print_message_indented_real(grub_env_get("VTOY_HOTKEY_TIP"),

File diff suppressed because it is too large Load Diff

View File

@@ -28,7 +28,9 @@
#define VTOY_FILT_MIN_FILE_SIZE 32768 #define VTOY_FILT_MIN_FILE_SIZE 32768
#define VTOY_SIZE_1GB 1073741824 #define VTOY_SIZE_1GB 1073741824
#define VTOY_SIZE_512KB (512 * 1024) #define VTOY_SIZE_1MB (1024 * 1024)
#define VTOY_SIZE_512KB (512 * 1024)
#define VTOY_SIZE_1KB 1024
#define JSON_SUCCESS 0 #define JSON_SUCCESS 0
#define JSON_FAILED 1 #define JSON_FAILED 1
@@ -48,6 +50,22 @@
#define ventoy_get_env(key) ventoy_env_op1(get, key) #define ventoy_get_env(key) ventoy_env_op1(get, key)
#define ventoy_set_env(key, val) ventoy_env_op2(set, key, val) #define ventoy_set_env(key, val) ventoy_env_op2(set, key, val)
#define VTOY_WARNING "!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!"
#define VTOY_PLAT_I386_UEFI 0x49413332
#define VTOY_PLAT_ARM64_UEFI 0x41413634
#define VTOY_PLAT_X86_64_UEFI 0x55454649
#define VTOY_PLAT_X86_LEGACY 0x42494f53
#define VTOY_PWD_CORRUPTED(err) \
{\
grub_printf("\n\n Password corrupted, will reboot after 5 seconds.\n\n"); \
grub_refresh(); \
grub_sleep(5); \
grub_exit(); \
return (err);\
}
typedef struct ventoy_initrd_ctx typedef struct ventoy_initrd_ctx
{ {
const char *path_prefix; const char *path_prefix;
@@ -99,6 +117,18 @@ typedef int (*grub_char_check_func)(int c);
#define ventoy_is_decimal(str) ventoy_string_check(str, grub_isdigit) #define ventoy_is_decimal(str) ventoy_string_check(str, grub_isdigit)
#pragma pack(1)
typedef struct ventoy_patch_vhd
{
grub_uint8_t part_offset_or_guid[16];
grub_uint32_t reserved1;
grub_uint32_t part_type;
grub_uint8_t disk_signature_or_guid[16];
grub_uint8_t reserved2[16];
grub_uint8_t vhd_file_path[1];
}ventoy_patch_vhd;
#pragma pack()
// El Torito Boot Record Volume Descriptor // El Torito Boot Record Volume Descriptor
#pragma pack(1) #pragma pack(1)
typedef struct eltorito_descriptor typedef struct eltorito_descriptor
@@ -137,10 +167,12 @@ typedef struct ventoy_iso9660_vd
#pragma pack() #pragma pack()
#define img_type_iso 0 #define img_type_iso 0
#define img_type_wim 1 #define img_type_wim 1
#define img_type_efi 2 #define img_type_efi 2
#define img_type_img 3 #define img_type_img 3
#define img_type_vhd 4
#define img_type_vtoy 5
typedef struct img_info typedef struct img_info
{ {
@@ -154,6 +186,7 @@ typedef struct img_info
int id; int id;
int type; int type;
int plugin_list_index;
grub_uint64_t size; grub_uint64_t size;
int select; int select;
int unsupport; int unsupport;
@@ -174,6 +207,8 @@ typedef struct img_iterator_node
int done; int done;
int select; int select;
int plugin_list_index;
struct img_iterator_node *parent; struct img_iterator_node *parent;
struct img_iterator_node *firstchild; struct img_iterator_node *firstchild;
@@ -218,6 +253,7 @@ extern ventoy_guid g_ventoy_guid;
extern ventoy_img_chunk_list g_img_chunk_list; extern ventoy_img_chunk_list g_img_chunk_list;
extern ventoy_img_chunk_list g_wimiso_chunk_list; extern ventoy_img_chunk_list g_wimiso_chunk_list;
extern char *g_wimiso_path; extern char *g_wimiso_path;
extern char g_arch_mode_suffix[64];
extern int g_ventoy_debug; extern int g_ventoy_debug;
void ventoy_debug(const char *fmt, ...); void ventoy_debug(const char *fmt, ...);
@@ -469,6 +505,8 @@ 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_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_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_load_cpio(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); 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); int ventoy_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, const char *name);
grub_file_t ventoy_grub_file_open(enum grub_file_type type, const char *fmt, ...); grub_file_t ventoy_grub_file_open(enum grub_file_type type, const char *fmt, ...);
@@ -480,6 +518,7 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a
grub_err_t ventoy_cmd_wimdows_reset(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_wimdows_reset(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_wim_check_bootable(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_dump_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_dump_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args);
VTOY_JSON *vtoy_json_find_item VTOY_JSON *vtoy_json_find_item
@@ -603,8 +642,88 @@ typedef struct ventoy_mbr_head
grub_uint8_t Byte55; grub_uint8_t Byte55;
grub_uint8_t ByteAA; grub_uint8_t ByteAA;
}ventoy_mbr_head; }ventoy_mbr_head;
typedef struct ventoy_gpt_head
{
char Signature[8]; /* EFI PART */
grub_uint8_t Version[4];
grub_uint32_t Length;
grub_uint32_t Crc;
grub_uint8_t Reserved1[4];
grub_uint64_t EfiStartLBA;
grub_uint64_t EfiBackupLBA;
grub_uint64_t PartAreaStartLBA;
grub_uint64_t PartAreaEndLBA;
grub_uint8_t DiskGuid[16];
grub_uint64_t PartTblStartLBA;
grub_uint32_t PartTblTotNum;
grub_uint32_t PartTblEntryLen;
grub_uint32_t PartTblCrc;
grub_uint8_t Reserved2[420];
}ventoy_gpt_head;
typedef struct ventoy_gpt_part_tbl
{
grub_uint8_t PartType[16];
grub_uint8_t PartGuid[16];
grub_uint64_t StartLBA;
grub_uint64_t LastLBA;
grub_uint64_t Attr;
grub_uint16_t Name[36];
}ventoy_gpt_part_tbl;
typedef struct ventoy_gpt_info
{
ventoy_mbr_head MBR;
ventoy_gpt_head Head;
ventoy_gpt_part_tbl PartTbl[128];
}ventoy_gpt_info;
typedef struct vhd_footer_t
{
char cookie[8]; // Cookie
grub_uint32_t features; // Features
grub_uint32_t ffversion; // File format version
grub_uint32_t dataoffset; // Data offset
grub_uint32_t timestamp; // Timestamp
grub_uint32_t creatorapp; // Creator application
grub_uint32_t creatorver; // Creator version
grub_uint32_t creatorhos; // Creator host OS
grub_uint32_t origsize; // Original size
grub_uint32_t currsize; // Current size
grub_uint32_t diskgeom; // Disk geometry
grub_uint32_t disktype; // Disk type
grub_uint32_t checksum; // Checksum
grub_uint8_t uniqueid[16]; // Unique ID
grub_uint8_t savedst; // Saved state
}vhd_footer_t;
#define VDI_IMAGE_FILE_INFO "<<< Oracle VM VirtualBox Disk Image >>>\n"
/** Image signature. */
#define VDI_IMAGE_SIGNATURE (0xbeda107f)
typedef struct VDIPREHEADER
{
/** Just text info about image type, for eyes only. */
char szFileInfo[64];
/** The image signature (VDI_IMAGE_SIGNATURE). */
grub_uint32_t u32Signature;
/** The image version (VDI_IMAGE_VERSION). */
grub_uint32_t u32Version;
} VDIPREHEADER, *PVDIPREHEADER;
#pragma pack() #pragma pack()
typedef struct ventoy_video_mode
{
grub_uint32_t width;
grub_uint32_t height;
grub_uint32_t bpp;
}ventoy_video_mode;
typedef struct file_fullpath typedef struct file_fullpath
{ {
char path[256]; char path[256];
@@ -623,6 +742,24 @@ typedef struct install_template
struct install_template *next; struct install_template *next;
}install_template; }install_template;
typedef struct dudfile
{
int size;
char *buf;
}dudfile;
typedef struct dud
{
int pathlen;
char isopath[256];
int dudnum;
file_fullpath *dudpath;
dudfile *files;
struct dud *next;
}dud;
typedef struct persistence_config typedef struct persistence_config
{ {
int pathlen; int pathlen;
@@ -662,6 +799,17 @@ typedef struct menu_class
struct menu_class *next; struct menu_class *next;
}menu_class; }menu_class;
#define vtoy_max_replace_file_size (2 * 1024 * 1024)
typedef struct conf_replace
{
int pathlen;
char isopath[256];
char orgconf[256];
char newconf[256];
struct conf_replace *next;
}conf_replace;
typedef struct injection_config typedef struct injection_config
{ {
int pathlen; int pathlen;
@@ -671,6 +819,45 @@ typedef struct injection_config
struct injection_config *next; struct injection_config *next;
}injection_config; }injection_config;
typedef struct auto_memdisk
{
int pathlen;
char isopath[256];
struct auto_memdisk *next;
}auto_memdisk;
typedef struct image_list
{
int pathlen;
char isopath[256];
struct image_list *next;
}image_list;
#define VTOY_PASSWORD_NONE 0
#define VTOY_PASSWORD_TXT 1
#define VTOY_PASSWORD_MD5 2
#define VTOY_PASSWORD_SALT_MD5 3
typedef struct vtoy_password
{
int type;
char text[128];
char salt[64];
grub_uint8_t md5[16];
}vtoy_password;
typedef struct menu_password
{
int pathlen;
char isopath[256];
vtoy_password password;
struct menu_password *next;
}menu_password;
extern int g_ventoy_menu_esc; extern int g_ventoy_menu_esc;
extern int g_ventoy_suppress_esc; extern int g_ventoy_suppress_esc;
extern int g_ventoy_last_entry; extern int g_ventoy_last_entry;
@@ -679,7 +866,15 @@ extern int g_ventoy_iso_raw;
extern int g_ventoy_iso_uefi_drv; extern int g_ventoy_iso_uefi_drv;
extern int g_ventoy_case_insensitive; extern int g_ventoy_case_insensitive;
extern grub_uint8_t g_ventoy_chain_type; extern grub_uint8_t g_ventoy_chain_type;
extern int g_vhdboot_enable;
extern int g_plugin_image_list;
extern ventoy_gpt_info *g_ventoy_part_info;
extern grub_uint64_t g_conf_replace_offset;
extern grub_uint64_t g_svd_replace_offset;
extern conf_replace *g_conf_replace_node;
extern grub_uint8_t *g_conf_replace_new_buf;
extern int g_conf_replace_new_len;
extern int g_conf_replace_new_len_align;
#define ventoy_unix_fill_virt(new_data, new_len) \ #define ventoy_unix_fill_virt(new_data, new_len) \
{ \ { \
@@ -710,21 +905,35 @@ int ventoy_plugin_get_persistent_chunklist(const char *isopath, int index, vento
const char * ventoy_plugin_get_injection(const char *isopath); const char * ventoy_plugin_get_injection(const char *isopath);
const char * ventoy_plugin_get_menu_alias(int type, const char *isopath); const char * ventoy_plugin_get_menu_alias(int type, const char *isopath);
const char * ventoy_plugin_get_menu_class(int type, const char *name); const char * ventoy_plugin_get_menu_class(int type, const char *name);
int ventoy_plugin_check_memdisk(const char *isopath);
int ventoy_plugin_get_image_list_index(int type, const char *name);
conf_replace * ventoy_plugin_find_conf_replace(const char *iso);
dud * ventoy_plugin_find_dud(const char *iso);
int ventoy_plugin_load_dud(dud *node, const char *isopart);
int ventoy_get_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start); int ventoy_get_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start); int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
void ventoy_plugin_dump_persistence(void); void ventoy_plugin_dump_persistence(void);
grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_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); grub_err_t ventoy_cmd_linux_get_main_initrd_index(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_collect_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_collect_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_wim_patch_count(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_wim_patch_count(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_locate_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_locate_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_unix_chain_data(grub_extcmd_context_t ctxt, int argc, char **args); 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); 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_reset(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_unix_replace_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_replace_ko(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_unix_freebsd_ver(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_unix_freebsd_ver(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_parse_freenas_ver(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_parse_freenas_ver(grub_extcmd_context_t ctxt, int argc, char **args);
int ventoy_check_device_result(int ret);
int ventoy_check_device(grub_device_t dev);
void ventoy_debug_dump_guid(const char *prefix, grub_uint8_t *guid);
grub_err_t ventoy_cmd_load_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_raw_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char **args);
int ventoy_check_password(const vtoy_password *pwd, int retry);
#endif /* __VENTOY_DEF_H__ */ #endif /* __VENTOY_DEF_H__ */

View File

@@ -333,6 +333,7 @@ end:
static grub_err_t ventoy_grub_cfg_initrd_collect(const char *fileName) static grub_err_t ventoy_grub_cfg_initrd_collect(const char *fileName)
{ {
int i = 0; int i = 0;
int dollar = 0;
grub_file_t file = NULL; grub_file_t file = NULL;
char *buf = NULL; char *buf = NULL;
char *start = NULL; char *start = NULL;
@@ -388,13 +389,18 @@ static grub_err_t ventoy_grub_cfg_initrd_collect(const char *fileName)
{ {
break; break;
} }
dollar = 0;
for (i = 0; i < 255 && (0 == ventoy_is_word_end(*start)); i++) for (i = 0; i < 255 && (0 == ventoy_is_word_end(*start)); i++)
{ {
img->name[i] = *start++; img->name[i] = *start++;
if (img->name[i] == '$')
{
dollar = 1;
}
} }
if (ventoy_find_initrd_by_name(g_initrd_img_list, img->name)) if (dollar == 1 || ventoy_find_initrd_by_name(g_initrd_img_list, img->name))
{ {
grub_free(img); grub_free(img);
} }
@@ -625,9 +631,30 @@ int ventoy_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, co
return headlen; return headlen;
} }
static grub_uint32_t ventoy_linux_get_virt_chunk_count(void)
{
grub_uint32_t count = g_valid_initrd_count;
if (g_conf_replace_offset > 0)
{
count++;
}
return count;
}
static grub_uint32_t ventoy_linux_get_virt_chunk_size(void) static grub_uint32_t ventoy_linux_get_virt_chunk_size(void)
{ {
return (sizeof(ventoy_virt_chunk) + g_ventoy_cpio_size) * g_valid_initrd_count; grub_uint32_t size;
size = (sizeof(ventoy_virt_chunk) + g_ventoy_cpio_size) * g_valid_initrd_count;
if (g_conf_replace_offset > 0)
{
size += sizeof(ventoy_virt_chunk) + g_conf_replace_new_len_align;
}
return size;
} }
static void ventoy_linux_fill_virt_data( grub_uint64_t isosize, ventoy_chain_head *chain) static void ventoy_linux_fill_virt_data( grub_uint64_t isosize, ventoy_chain_head *chain)
@@ -646,7 +673,7 @@ static void ventoy_linux_fill_virt_data( grub_uint64_t isosize, ventoy_chain_
sector = (isosize + 2047) / 2048; sector = (isosize + 2047) / 2048;
cpio_secs = g_ventoy_cpio_size / 2048; cpio_secs = g_ventoy_cpio_size / 2048;
offset = g_valid_initrd_count * sizeof(ventoy_virt_chunk); offset = ventoy_linux_get_virt_chunk_count() * sizeof(ventoy_virt_chunk);
cur = (ventoy_virt_chunk *)override; cur = (ventoy_virt_chunk *)override;
for (node = g_initrd_img_list; node; node = node->next) for (node = g_initrd_img_list; node; node = node->next)
@@ -682,12 +709,61 @@ static void ventoy_linux_fill_virt_data( grub_uint64_t isosize, ventoy_chain_
cur++; cur++;
} }
if (g_conf_replace_offset > 0)
{
cpio_secs = g_conf_replace_new_len_align / 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_memcpy(override + offset, g_conf_replace_new_buf, g_conf_replace_new_len);
chain->virt_img_size_in_bytes += g_conf_replace_new_len_align;
offset += g_conf_replace_new_len_align;
sector += cpio_secs;
cur++;
}
return; return;
} }
static grub_uint32_t ventoy_linux_get_override_chunk_count(void)
{
grub_uint32_t count = g_valid_initrd_count;
if (g_conf_replace_offset > 0)
{
count++;
}
if (g_svd_replace_offset > 0)
{
count++;
}
return count;
}
static grub_uint32_t ventoy_linux_get_override_chunk_size(void) static grub_uint32_t ventoy_linux_get_override_chunk_size(void)
{ {
return sizeof(ventoy_override_chunk) * g_valid_initrd_count; int count = g_valid_initrd_count;
if (g_conf_replace_offset > 0)
{
count++;
}
if (g_svd_replace_offset > 0)
{
count++;
}
return sizeof(ventoy_override_chunk) * count;
} }
static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *override) static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *override)
@@ -697,6 +773,8 @@ static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *ove
grub_uint32_t newlen; grub_uint32_t newlen;
grub_uint64_t sector; grub_uint64_t sector;
ventoy_override_chunk *cur; ventoy_override_chunk *cur;
ventoy_iso9660_override *dirent;
ventoy_udf_override *udf;
sector = (isosize + 2047) / 2048; sector = (isosize + 2047) / 2048;
@@ -712,12 +790,12 @@ static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *ove
mod = newlen % 4; mod = newlen % 4;
if (mod > 0) if (mod > 0)
{ {
newlen += 4 - mod; newlen += 4 - mod; /* cpio must align with 4 */
} }
if (node->iso_type == 0) if (node->iso_type == 0)
{ {
ventoy_iso9660_override *dirent = (ventoy_iso9660_override *)node->override_data; dirent = (ventoy_iso9660_override *)node->override_data;
node->override_length = sizeof(ventoy_iso9660_override); node->override_length = sizeof(ventoy_iso9660_override);
dirent->first_sector = (grub_uint32_t)sector; dirent->first_sector = (grub_uint32_t)sector;
@@ -729,7 +807,7 @@ static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *ove
} }
else else
{ {
ventoy_udf_override *udf = (ventoy_udf_override *)node->override_data; udf = (ventoy_udf_override *)node->override_data;
node->override_length = sizeof(ventoy_udf_override); node->override_length = sizeof(ventoy_udf_override);
udf->length = newlen; udf->length = newlen;
@@ -744,6 +822,31 @@ static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *ove
cur++; cur++;
} }
if (g_conf_replace_offset > 0)
{
cur->img_offset = g_conf_replace_offset;
cur->override_size = sizeof(ventoy_iso9660_override);
newlen = (grub_uint32_t)(g_conf_replace_new_len);
dirent = (ventoy_iso9660_override *)cur->override_data;
dirent->first_sector = (grub_uint32_t)sector;
dirent->size = newlen;
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_svd_replace_offset > 0)
{
cur->img_offset = g_svd_replace_offset;
cur->override_size = 1;
cur->override_data[0] = 0xFF;
cur++;
}
return; return;
} }
@@ -910,12 +1013,15 @@ grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc,
VENTOY_CMD_RETURN(GRUB_ERR_NONE); VENTOY_CMD_RETURN(GRUB_ERR_NONE);
} }
static int ventoy_cpio_busybox64(cpio_newc_header *head) static int ventoy_cpio_busybox64(cpio_newc_header *head, const char *file)
{ {
char *name; char *name;
int namelen; int namelen;
int offset; int offset;
int count = 0; int count = 0;
char filepath[128];
grub_snprintf(filepath, sizeof(filepath), "ventoy/busybox/%s", file);
name = (char *)(head + 1); name = (char *)(head + 1);
while (name[0] && count < 2) while (name[0] && count < 2)
@@ -925,7 +1031,7 @@ static int ventoy_cpio_busybox64(cpio_newc_header *head)
grub_memcpy(name, "ventoy/busybox/32h", 18); grub_memcpy(name, "ventoy/busybox/32h", 18);
count++; count++;
} }
else if (grub_strcmp(name, "ventoy/busybox/64h") == 0) else if (grub_strcmp(name, filepath) == 0)
{ {
grub_memcpy(name, "ventoy/busybox/ash", 18); grub_memcpy(name, "ventoy/busybox/ash", 18);
count++; count++;
@@ -944,13 +1050,68 @@ static int ventoy_cpio_busybox64(cpio_newc_header *head)
return 0; return 0;
} }
grub_err_t ventoy_cmd_cpio_busybox_64(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
(void)argc;
(void)args;
debug("ventoy_cmd_busybox_64 %d\n", argc);
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf, args[0]);
return 0;
}
grub_err_t ventoy_cmd_skip_svd(grub_extcmd_context_t ctxt, int argc, char **args)
{
int i;
grub_file_t file;
char buf[16];
(void)ctxt;
(void)argc;
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
if (!file)
{
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s\n", args[0]);
}
for (i = 0; i < 10; i++)
{
buf[0] = 0;
grub_file_seek(file, (17 + i) * 2048);
grub_file_read(file, buf, 16);
if (buf[0] == 2 && grub_strncmp(buf + 1, "CD001", 5) == 0)
{
debug("Find SVD at VD %d\n", i);
g_svd_replace_offset = (17 + i) * 2048;
break;
}
}
if (i >= 10)
{
debug("SVD not found %d\n", (int)g_svd_replace_offset);
}
grub_file_close(file);
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args) grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args)
{ {
int i;
int rc; int rc;
char *pos = NULL;
char *template_file = NULL; char *template_file = NULL;
char *template_buf = NULL; char *template_buf = NULL;
char *persistent_buf = NULL; char *persistent_buf = NULL;
char *injection_buf = NULL; char *injection_buf = NULL;
dud *dudnode = NULL;
char tmpname[128];
const char *injection_file = NULL; const char *injection_file = NULL;
grub_uint8_t *buf = NULL; grub_uint8_t *buf = NULL;
grub_uint32_t mod; grub_uint32_t mod;
@@ -961,6 +1122,7 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
grub_uint32_t template_size = 0; grub_uint32_t template_size = 0;
grub_uint32_t persistent_size = 0; grub_uint32_t persistent_size = 0;
grub_uint32_t injection_size = 0; grub_uint32_t injection_size = 0;
grub_uint32_t dud_size = 0;
grub_file_t file; grub_file_t file;
grub_file_t tmpfile; grub_file_t tmpfile;
ventoy_img_chunk_list chunk_list; ventoy_img_chunk_list chunk_list;
@@ -1054,11 +1216,30 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
debug("injection not configed %s\n", args[1]); debug("injection not configed %s\n", args[1]);
} }
g_ventoy_cpio_buf = grub_malloc(file->size + 4096 + template_size + persistent_size + injection_size + img_chunk_size); dudnode = ventoy_plugin_find_dud(args[1]);
if (dudnode)
{
debug("dud file: <%d>\n", dudnode->dudnum);
ventoy_plugin_load_dud(dudnode, args[2]);
for (i = 0; i < dudnode->dudnum; i++)
{
if (dudnode->files[i].size > 0)
{
dud_size += dudnode->files[i].size + sizeof(cpio_newc_header);
}
}
}
else
{
debug("dud not configed %s\n", args[1]);
}
g_ventoy_cpio_buf = grub_malloc(file->size + 40960 + template_size +
persistent_size + injection_size + dud_size + img_chunk_size);
if (NULL == g_ventoy_cpio_buf) if (NULL == g_ventoy_cpio_buf)
{ {
grub_file_close(file); grub_file_close(file);
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't alloc memory %llu\n", file->size + 4096 + img_chunk_size); return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't alloc memory %llu\n", file->size);
} }
grub_file_read(file, g_ventoy_cpio_buf, file->size); grub_file_read(file, g_ventoy_cpio_buf, file->size);
@@ -1100,6 +1281,18 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
injection_buf = NULL; injection_buf = NULL;
} }
if (dud_size > 0)
{
for (i = 0; i < dudnode->dudnum; i++)
{
pos = grub_strrchr(dudnode->dudpath[i].path, '.');
grub_snprintf(tmpname, sizeof(tmpname), "ventoy/ventoy_dud%d%s", i, (pos ? pos : ".iso"));
dud_size = dudnode->files[i].size;
headlen = ventoy_cpio_newc_fill_head(buf, dud_size, dudnode->files[i].buf, tmpname);
buf += headlen + ventoy_align(dud_size, 4);
}
}
/* step2: insert os param to cpio */ /* step2: insert os param to cpio */
headlen = ventoy_cpio_newc_fill_head(buf, 0, NULL, "ventoy/ventoy_os_param"); headlen = ventoy_cpio_newc_fill_head(buf, 0, NULL, "ventoy/ventoy_os_param");
padlen = sizeof(ventoy_os_param); padlen = sizeof(ventoy_os_param);
@@ -1124,7 +1317,12 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
if (grub_strcmp(args[3], "busybox=64") == 0) if (grub_strcmp(args[3], "busybox=64") == 0)
{ {
debug("cpio busybox proc %s\n", args[3]); debug("cpio busybox proc %s\n", args[3]);
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf); ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf, "64h");
}
else if (grub_strcmp(args[3], "busybox=a64") == 0)
{
debug("cpio busybox proc %s\n", args[3]);
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf, "a64");
} }
VENTOY_CMD_RETURN(GRUB_ERR_NONE); VENTOY_CMD_RETURN(GRUB_ERR_NONE);
@@ -1228,7 +1426,9 @@ grub_err_t ventoy_cmd_linux_chain_data(grub_extcmd_context_t ctxt, int argc, cha
grub_uint64_t isosize = 0; grub_uint64_t isosize = 0;
grub_uint32_t boot_catlog = 0; grub_uint32_t boot_catlog = 0;
grub_uint32_t img_chunk_size = 0; grub_uint32_t img_chunk_size = 0;
grub_uint32_t override_count = 0;
grub_uint32_t override_size = 0; grub_uint32_t override_size = 0;
grub_uint32_t virt_chunk_count = 0;
grub_uint32_t virt_chunk_size = 0; grub_uint32_t virt_chunk_size = 0;
grub_file_t file; grub_file_t file;
grub_disk_t disk; grub_disk_t disk;
@@ -1281,6 +1481,9 @@ grub_err_t ventoy_cmd_linux_chain_data(grub_extcmd_context_t ctxt, int argc, cha
} }
img_chunk_size = g_img_chunk_list.cur_chunk * sizeof(ventoy_img_chunk); img_chunk_size = g_img_chunk_list.cur_chunk * sizeof(ventoy_img_chunk);
override_count = ventoy_linux_get_override_chunk_count();
virt_chunk_count = ventoy_linux_get_virt_chunk_count();
if (ventoy_compatible) if (ventoy_compatible)
{ {
@@ -1347,20 +1550,21 @@ grub_err_t ventoy_cmd_linux_chain_data(grub_extcmd_context_t ctxt, int argc, cha
return 0; return 0;
} }
if (g_valid_initrd_count == 0) /* part 4: override chunk */
if (override_count > 0)
{ {
return 0; chain->override_chunk_offset = chain->img_chunk_offset + img_chunk_size;
chain->override_chunk_num = override_count;
ventoy_linux_fill_override_data(isosize, (char *)chain + chain->override_chunk_offset);
} }
/* part 4: override chunk */
chain->override_chunk_offset = chain->img_chunk_offset + img_chunk_size;
chain->override_chunk_num = g_valid_initrd_count;
ventoy_linux_fill_override_data(isosize, (char *)chain + chain->override_chunk_offset);
/* part 5: virt chunk */ /* part 5: virt chunk */
chain->virt_chunk_offset = chain->override_chunk_offset + override_size; if (virt_chunk_count > 0)
chain->virt_chunk_num = g_valid_initrd_count; {
ventoy_linux_fill_virt_data(isosize, chain); chain->virt_chunk_offset = chain->override_chunk_offset + override_size;
chain->virt_chunk_num = virt_chunk_count;
ventoy_linux_fill_virt_data(isosize, chain);
}
VENTOY_CMD_RETURN(GRUB_ERR_NONE); VENTOY_CMD_RETURN(GRUB_ERR_NONE);
} }

File diff suppressed because it is too large Load Diff

View File

@@ -194,6 +194,7 @@ static int ventoy_freebsd_append_conf(char *buf, const char *isopath)
grub_file_t isofile; grub_file_t isofile;
char uuid[64] = {0}; char uuid[64] = {0};
ventoy_img_chunk *chunk; ventoy_img_chunk *chunk;
grub_uint8_t disk_sig[4];
grub_uint8_t disk_guid[16]; grub_uint8_t disk_guid[16];
debug("ventoy_freebsd_append_conf %s\n", isopath); debug("ventoy_freebsd_append_conf %s\n", isopath);
@@ -209,7 +210,7 @@ static int ventoy_freebsd_append_conf(char *buf, const char *isopath)
disk = isofile->device->disk; disk = isofile->device->disk;
ventoy_get_disk_guid(isofile->name, disk_guid); ventoy_get_disk_guid(isofile->name, disk_guid, disk_sig);
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
{ {
@@ -217,7 +218,8 @@ static int ventoy_freebsd_append_conf(char *buf, const char *isopath)
} }
vtoy_ssprintf(buf, pos, "hint.ventoy.0.disksize=%llu\n", (ulonglong)(disk->total_sectors * (1 << disk->log_sector_size))); vtoy_ssprintf(buf, pos, "hint.ventoy.0.disksize=%llu\n", (ulonglong)(disk->total_sectors * (1 << disk->log_sector_size)));
vtoy_ssprintf(buf, pos, "hint.ventoy.0.diskuuid=\"%s\"\n", uuid); vtoy_ssprintf(buf, pos, "hint.ventoy.0.diskuuid=\"%s\"\n", uuid);
vtoy_ssprintf(buf, pos, "hint.ventoy.0.disksignature=%02x%02x%02x%02x\n", disk_sig[0], disk_sig[1], disk_sig[2], disk_sig[3]);
vtoy_ssprintf(buf, pos, "hint.ventoy.0.segnum=%u\n", g_img_chunk_list.cur_chunk); vtoy_ssprintf(buf, pos, "hint.ventoy.0.segnum=%u\n", g_img_chunk_list.cur_chunk);
for (i = 0; i < g_img_chunk_list.cur_chunk; i++) for (i = 0; i < g_img_chunk_list.cur_chunk; i++)

View File

@@ -0,0 +1,559 @@
/******************************************************************************
* ventoy_vhd.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 <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/crypto.h>
#include <grub/charset.h>
#ifdef GRUB_MACHINE_EFI
#include <grub/efi/efi.h>
#endif
#include <grub/ventoy.h>
#include "ventoy_def.h"
GRUB_MOD_LICENSE ("GPLv3+");
static int g_vhdboot_bcd_offset = 0;
static int g_vhdboot_bcd_len = 0;
static int g_vhdboot_isolen = 0;
static char *g_vhdboot_totbuf = NULL;
static char *g_vhdboot_isobuf = NULL;
static grub_uint64_t g_img_trim_head_secnum = 0;
static int ventoy_vhd_find_bcd(int *bcdoffset, int *bcdlen)
{
grub_uint32_t offset;
grub_file_t file;
char cmdbuf[128];
grub_snprintf(cmdbuf, sizeof(cmdbuf), "loopback vhdiso mem:0x%lx:size:%d", (ulong)g_vhdboot_isobuf, g_vhdboot_isolen);
grub_script_execute_sourcecode(cmdbuf);
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", "(vhdiso)/boot/bcd");
if (!file)
{
grub_printf("Failed to open bcd file in the image file\n");
return 1;
}
grub_file_read(file, &offset, 4);
offset = (grub_uint32_t)grub_iso9660_get_last_read_pos(file);
*bcdoffset = (int)offset;
*bcdlen = (int)file->size;
debug("vhdiso bcd file offset:%d len:%d\n", *bcdoffset, *bcdlen);
grub_file_close(file);
grub_script_execute_sourcecode("loopback -d vhdiso");
return 0;
}
static int ventoy_vhd_patch_path(char *vhdpath, ventoy_patch_vhd *patch1, ventoy_patch_vhd *patch2)
{
int i;
int cnt = 0;
char *pos;
grub_size_t pathlen;
const char *plat;
grub_uint16_t *unicode_path;
const grub_uint8_t winloadexe[] =
{
0x77, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x61, 0x00, 0x64, 0x00, 0x2E, 0x00,
0x65, 0x00, 0x78, 0x00, 0x65, 0x00
};
pathlen = sizeof(grub_uint16_t) * (grub_strlen(vhdpath) + 1);
debug("unicode path for <%s> len:%d\n", vhdpath, (int)pathlen);
unicode_path = grub_zalloc(pathlen);
if (!unicode_path)
{
return 0;
}
plat = grub_env_get("grub_platform");
if (plat && (plat[0] == 'e')) /* UEFI */
{
pos = g_vhdboot_isobuf + g_vhdboot_bcd_offset;
/* winload.exe ==> winload.efi */
for (i = 0; i + (int)sizeof(winloadexe) < g_vhdboot_bcd_len; i++)
{
if (*((grub_uint32_t *)(pos + i)) == 0x00690077 &&
grub_memcmp(pos + i, winloadexe, sizeof(winloadexe)) == 0)
{
pos[i + sizeof(winloadexe) - 4] = 0x66;
pos[i + sizeof(winloadexe) - 2] = 0x69;
cnt++;
}
}
debug("winload patch %d times\n", cnt);
}
for (pos = vhdpath; *pos; pos++)
{
if (*pos == '/')
{
*pos = '\\';
}
}
grub_utf8_to_utf16(unicode_path, pathlen, (grub_uint8_t *)vhdpath, -1, NULL);
grub_memcpy(patch1->vhd_file_path, unicode_path, pathlen);
grub_memcpy(patch2->vhd_file_path, unicode_path, pathlen);
return 0;
}
static int ventoy_vhd_patch_disk(ventoy_patch_vhd *patch1, ventoy_patch_vhd *patch2)
{
char efipart[16] = {0};
grub_memcpy(efipart, g_ventoy_part_info->Head.Signature, sizeof(g_ventoy_part_info->Head.Signature));
debug("part1 type: 0x%x <%s>\n", g_ventoy_part_info->MBR.PartTbl[0].FsFlag, efipart);
if (grub_strncmp(efipart, "EFI PART", 8) == 0)
{
ventoy_debug_dump_guid("GPT disk GUID: ", g_ventoy_part_info->Head.DiskGuid);
ventoy_debug_dump_guid("GPT part GUID: ", g_ventoy_part_info->PartTbl[0].PartGuid);
grub_memcpy(patch1->disk_signature_or_guid, g_ventoy_part_info->Head.DiskGuid, 16);
grub_memcpy(patch1->part_offset_or_guid, g_ventoy_part_info->PartTbl[0].PartGuid, 16);
grub_memcpy(patch2->disk_signature_or_guid, g_ventoy_part_info->Head.DiskGuid, 16);
grub_memcpy(patch2->part_offset_or_guid, g_ventoy_part_info->PartTbl[0].PartGuid, 16);
patch1->part_type = patch2->part_type = 0;
}
else
{
debug("MBR disk signature: %02x%02x%02x%02x\n",
g_ventoy_part_info->MBR.BootCode[0x1b8 + 0], g_ventoy_part_info->MBR.BootCode[0x1b8 + 1],
g_ventoy_part_info->MBR.BootCode[0x1b8 + 2], g_ventoy_part_info->MBR.BootCode[0x1b8 + 3]);
grub_memcpy(patch1->disk_signature_or_guid, g_ventoy_part_info->MBR.BootCode + 0x1b8, 4);
grub_memcpy(patch2->disk_signature_or_guid, g_ventoy_part_info->MBR.BootCode + 0x1b8, 4);
}
return 0;
}
grub_err_t ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args)
{
int rc;
ventoy_patch_vhd *patch1;
ventoy_patch_vhd *patch2;
char envbuf[64];
(void)ctxt;
(void)argc;
grub_env_unset("vtoy_vhd_buf_addr");
debug("patch vhd <%s>\n", args[0]);
if ((!g_vhdboot_enable) || (!g_vhdboot_totbuf))
{
debug("vhd boot not ready %d %p\n", g_vhdboot_enable, g_vhdboot_totbuf);
return 0;
}
rc = ventoy_vhd_find_bcd(&g_vhdboot_bcd_offset, &g_vhdboot_bcd_len);
if (rc)
{
debug("failed to get bcd location %d\n", rc);
return 0;
}
patch1 = (ventoy_patch_vhd *)(g_vhdboot_isobuf + g_vhdboot_bcd_offset + 0x495a);
patch2 = (ventoy_patch_vhd *)(g_vhdboot_isobuf + g_vhdboot_bcd_offset + 0x50aa);
ventoy_vhd_patch_disk(patch1, patch2);
ventoy_vhd_patch_path(args[0], patch1, patch2);
/* set buffer and size */
#ifdef GRUB_MACHINE_EFI
grub_snprintf(envbuf, sizeof(envbuf), "0x%lx", (ulong)g_vhdboot_totbuf);
grub_env_set("vtoy_vhd_buf_addr", envbuf);
grub_snprintf(envbuf, sizeof(envbuf), "%d", (int)(g_vhdboot_isolen + sizeof(ventoy_chain_head)));
grub_env_set("vtoy_vhd_buf_size", envbuf);
#else
grub_snprintf(envbuf, sizeof(envbuf), "0x%lx", (ulong)g_vhdboot_isobuf);
grub_env_set("vtoy_vhd_buf_addr", envbuf);
grub_snprintf(envbuf, sizeof(envbuf), "%d", g_vhdboot_isolen);
grub_env_set("vtoy_vhd_buf_size", envbuf);
#endif
return 0;
}
grub_err_t ventoy_cmd_load_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args)
{
int buflen;
grub_file_t file;
(void)ctxt;
(void)argc;
g_vhdboot_enable = 0;
grub_check_free(g_vhdboot_totbuf);
file = grub_file_open(args[0], VENTOY_FILE_TYPE);
if (!file)
{
return 0;
}
debug("load vhd boot: <%s> <%lu>\n", args[0], (ulong)file->size);
if (file->size < VTOY_SIZE_1KB * 32)
{
grub_file_close(file);
return 0;
}
g_vhdboot_isolen = (int)file->size;
buflen = (int)(file->size + sizeof(ventoy_chain_head));
#ifdef GRUB_MACHINE_EFI
g_vhdboot_totbuf = (char *)grub_efi_allocate_iso_buf(buflen);
#else
g_vhdboot_totbuf = (char *)grub_malloc(buflen);
#endif
if (!g_vhdboot_totbuf)
{
grub_file_close(file);
return 0;
}
g_vhdboot_isobuf = g_vhdboot_totbuf + sizeof(ventoy_chain_head);
grub_file_read(file, g_vhdboot_isobuf, file->size);
grub_file_close(file);
g_vhdboot_enable = 1;
return 0;
}
static int ventoy_raw_trim_head(grub_uint64_t offset)
{
grub_uint32_t i;
grub_uint32_t memsize;
grub_uint32_t imgstart = 0;
grub_uint32_t imgsecs = 0;
grub_uint64_t sectors = 0;
grub_uint64_t cursecs = 0;
grub_uint64_t delta = 0;
if ((!g_img_chunk_list.chunk) || (!offset))
{
debug("image chunk not ready %p %lu\n", g_img_chunk_list.chunk, (ulong)offset);
return 0;
}
debug("image trim head %lu\n", (ulong)offset);
for (i = 0; i < g_img_chunk_list.cur_chunk; i++)
{
cursecs = g_img_chunk_list.chunk[i].disk_end_sector + 1 - g_img_chunk_list.chunk[i].disk_start_sector;
sectors += cursecs;
if (sectors >= offset)
{
delta = cursecs - (sectors - offset);
break;
}
}
if (sectors < offset || i >= g_img_chunk_list.cur_chunk)
{
debug("Invalid size %lu %lu\n", (ulong)sectors, (ulong)offset);
return 0;
}
if (sectors == offset)
{
memsize = (g_img_chunk_list.cur_chunk - (i + 1)) * sizeof(ventoy_img_chunk);
grub_memmove(g_img_chunk_list.chunk, g_img_chunk_list.chunk + i + 1, memsize);
g_img_chunk_list.cur_chunk -= (i + 1);
}
else
{
g_img_chunk_list.chunk[i].disk_start_sector += delta;
g_img_chunk_list.chunk[i].img_start_sector += (grub_uint32_t)(delta / 4);
if (i > 0)
{
memsize = (g_img_chunk_list.cur_chunk - i) * sizeof(ventoy_img_chunk);
grub_memmove(g_img_chunk_list.chunk, g_img_chunk_list.chunk + i, memsize);
g_img_chunk_list.cur_chunk -= i;
}
}
for (i = 0; i < g_img_chunk_list.cur_chunk; i++)
{
imgsecs = g_img_chunk_list.chunk[i].img_end_sector + 1 - g_img_chunk_list.chunk[i].img_start_sector;
g_img_chunk_list.chunk[i].img_start_sector = imgstart;
g_img_chunk_list.chunk[i].img_end_sector = imgstart + (imgsecs - 1);
imgstart += imgsecs;
}
return 0;
}
grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char **args)
{
int i;
int offset = -1;
grub_file_t file;
vhd_footer_t vhdfoot;
VDIPREHEADER vdihdr;
char type[16] = {0};
ventoy_gpt_info *gpt;
(void)ctxt;
g_img_trim_head_secnum = 0;
if (argc != 4)
{
return 0;
}
file = grub_file_open(args[0], VENTOY_FILE_TYPE);
if (!file)
{
debug("Failed to open file %s\n", args[0]);
return 0;
}
grub_snprintf(type, sizeof(type), "unknown");
grub_file_seek(file, file->size - 512);
grub_file_read(file, &vhdfoot, sizeof(vhdfoot));
if (grub_strncmp(vhdfoot.cookie, "conectix", 8) == 0)
{
offset = 0;
grub_snprintf(type, sizeof(type), "vhd%u", grub_swap_bytes32(vhdfoot.disktype));
}
else
{
grub_file_seek(file, 0);
grub_file_read(file, &vdihdr, sizeof(vdihdr));
if (vdihdr.u32Signature == VDI_IMAGE_SIGNATURE &&
grub_strncmp(vdihdr.szFileInfo, VDI_IMAGE_FILE_INFO, grub_strlen(VDI_IMAGE_FILE_INFO)) == 0)
{
offset = 2 * 1048576;
g_img_trim_head_secnum = offset / 512;
grub_snprintf(type, sizeof(type), "vdi");
}
else
{
offset = 0;
grub_snprintf(type, sizeof(type), "raw");
}
}
grub_env_set(args[1], type);
debug("<%s> vtoy type: <%s> ", args[0], type);
if (offset >= 0)
{
gpt = grub_zalloc(sizeof(ventoy_gpt_info));
if (!gpt)
{
grub_env_set(args[1], "unknown");
goto end;
}
grub_file_seek(file, offset);
grub_file_read(file, gpt, sizeof(ventoy_gpt_info));
if (gpt->MBR.Byte55 != 0x55 || gpt->MBR.ByteAA != 0xAA)
{
grub_env_set(args[1], "unknown");
debug("invalid mbr signature: 0x%x 0x%x\n", gpt->MBR.Byte55, gpt->MBR.ByteAA);
goto end;
}
if (grub_memcmp(gpt->Head.Signature, "EFI PART", 8) == 0)
{
grub_env_set(args[2], "gpt");
debug("part type: %s\n", "GPT");
if (gpt->MBR.PartTbl[0].FsFlag == 0xEE)
{
for (i = 0; i < 128; i++)
{
if (grub_memcmp(gpt->PartTbl[i].PartType, "Hah!IdontNeedEFI", 16) == 0)
{
debug("part %d is grub_bios part\n", i);
grub_env_set(args[3], "1");
break;
}
else if (gpt->PartTbl[i].LastLBA == 0)
{
break;
}
}
}
}
else
{
grub_env_set(args[2], "mbr");
debug("part type: %s\n", "MBR");
for (i = 0; i < 4; i++)
{
if (gpt->MBR.PartTbl[i].FsFlag == 0xEF)
{
debug("part %d is esp part in MBR mode\n", i);
grub_env_set(args[3], "1");
break;
}
}
}
}
else
{
debug("part type: %s\n", "xxx");
}
end:
grub_check_free(gpt);
grub_file_close(file);
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_raw_chain_data(grub_extcmd_context_t ctxt, int argc, char **args)
{
grub_uint32_t size = 0;
grub_uint32_t img_chunk_size = 0;
grub_file_t file;
grub_disk_t disk;
const char *pLastChain = NULL;
ventoy_chain_head *chain;
char envbuf[64];
(void)ctxt;
(void)argc;
if (NULL == g_img_chunk_list.chunk)
{
grub_printf("ventoy not ready\n");
return 1;
}
if (g_img_trim_head_secnum > 0)
{
ventoy_raw_trim_head(g_img_trim_head_secnum);
}
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
if (!file)
{
return 1;
}
img_chunk_size = g_img_chunk_list.cur_chunk * sizeof(ventoy_img_chunk);
size = sizeof(ventoy_chain_head) + img_chunk_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_env_export("vtoy_chain_mem_addr");
grub_env_export("vtoy_chain_mem_size");
grub_memset(chain, 0, sizeof(ventoy_chain_head));
/* part 1: os parameter */
g_ventoy_chain_type = ventoy_chain_linux;
ventoy_fill_os_param(file, &(chain->os_param));
/* part 2: chain head */
disk = file->device->disk;
chain->disk_drive = disk->id;
chain->disk_sector_size = (1 << disk->log_sector_size);
chain->real_img_size_in_bytes = file->size;
if (g_img_trim_head_secnum > 0)
{
chain->real_img_size_in_bytes -= g_img_trim_head_secnum * 512;
}
chain->virt_img_size_in_bytes = chain->real_img_size_in_bytes;
chain->boot_catalog = 0;
/* part 3: image chunk */
chain->img_chunk_offset = sizeof(ventoy_chain_head);
chain->img_chunk_num = g_img_chunk_list.cur_chunk;
grub_memcpy((char *)chain + chain->img_chunk_offset, g_img_chunk_list.chunk, img_chunk_size);
grub_file_seek(file, g_img_trim_head_secnum * 512);
grub_file_read(file, chain->boot_catalog_sector, 512);
grub_file_close(file);
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}

View File

@@ -1492,7 +1492,7 @@ static grub_uint32_t ventoy_get_wim_iso_offset(const char *filepath)
grub_file_t file; grub_file_t file;
char cmdbuf[128]; char cmdbuf[128];
grub_snprintf(cmdbuf, sizeof(cmdbuf), "loopback wimiso %s", filepath); grub_snprintf(cmdbuf, sizeof(cmdbuf), "loopback wimiso \"%s\"", filepath);
grub_script_execute_sourcecode(cmdbuf); grub_script_execute_sourcecode(cmdbuf);
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", "(wimiso)/boot/boot.wim"); file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", "(wimiso)/boot/boot.wim");
@@ -1542,6 +1542,41 @@ static int ventoy_get_wim_chunklist(const char *filename, ventoy_img_chunk_list
return 0; return 0;
} }
grub_err_t ventoy_cmd_wim_check_bootable(grub_extcmd_context_t ctxt, int argc, char **args)
{
grub_uint32_t boot_index;
grub_file_t file = NULL;
wim_header *wimhdr = NULL;
(void)ctxt;
(void)argc;
wimhdr = grub_zalloc(sizeof(wim_header));
if (!wimhdr)
{
return 1;
}
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
if (!file)
{
grub_free(wimhdr);
return 1;
}
grub_file_read(file, wimhdr, sizeof(wim_header));
grub_file_close(file);
boot_index = wimhdr->boot_index;
grub_free(wimhdr);
if (boot_index == 0)
{
return 1;
}
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 ventoy_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char **args)
{ {
grub_uint32_t i = 0; grub_uint32_t i = 0;

View File

@@ -21,7 +21,7 @@
#ifndef __VENTOY_H__ #ifndef __VENTOY_H__
#define __VENTOY_H__ #define __VENTOY_H__
#define COMPILE_ASSERT(expr) extern char __compile_assert[(expr) ? 1 : -1] #define COMPILE_ASSERT(a, expr) extern char __compile_assert##a[(expr) ? 1 : -1]
#define VENTOY_COMPATIBLE_STR "VENTOY COMPATIBLE" #define VENTOY_COMPATIBLE_STR "VENTOY COMPATIBLE"
#define VENTOY_COMPATIBLE_STR_LEN 17 #define VENTOY_COMPATIBLE_STR_LEN 17
@@ -71,7 +71,7 @@ typedef struct ventoy_image_location
{ {
ventoy_guid guid; ventoy_guid guid;
/* image sector size, currently this value is always 2048 */ /* image sector size, 2048/512 */
grub_uint32_t image_sector_size; grub_uint32_t image_sector_size;
/* disk sector size, normally the value is 512 */ /* disk sector size, normally the value is 512 */
@@ -125,7 +125,9 @@ typedef struct ventoy_os_param
*/ */
grub_uint8_t vtoy_reserved[32]; // Internal use by ventoy grub_uint8_t vtoy_reserved[32]; // Internal use by ventoy
grub_uint8_t reserved[31]; grub_uint8_t vtoy_disk_signature[4];
grub_uint8_t reserved[27];
}ventoy_os_param; }ventoy_os_param;
@@ -137,11 +139,23 @@ typedef struct ventoy_windows_data
}ventoy_windows_data; }ventoy_windows_data;
typedef struct ventoy_secure_data
{
grub_uint8_t magic1[16]; /* VENTOY_GUID */
grub_uint8_t diskuuid[16];
grub_uint8_t Checksum[16];
grub_uint8_t adminSHA256[32];
grub_uint8_t reserved[4000];
grub_uint8_t magic2[16]; /* VENTOY_GUID */
}ventoy_secure_data;
#pragma pack() #pragma pack()
// compile assert check : sizeof(ventoy_os_param) must be 512 // compile assert check : sizeof(ventoy_os_param) must be 512
COMPILE_ASSERT(sizeof(ventoy_os_param) == 512); COMPILE_ASSERT(1,sizeof(ventoy_os_param) == 512);
COMPILE_ASSERT(2,sizeof(ventoy_secure_data) == 4096);
@@ -219,6 +233,7 @@ typedef struct ventoy_img_chunk_list
#define GRUB_FILE_REPLACE_MAGIC 0x1258BEEF #define GRUB_FILE_REPLACE_MAGIC 0x1258BEEF
typedef const char * (*grub_env_get_pf)(const char *name); typedef const char * (*grub_env_get_pf)(const char *name);
typedef int (*grub_env_set_pf)(const char *name, const char *val);
typedef int (*grub_env_printf_pf)(const char *fmt, ...); typedef int (*grub_env_printf_pf)(const char *fmt, ...);
typedef struct ventoy_grub_param_file_replace typedef struct ventoy_grub_param_file_replace
@@ -232,13 +247,13 @@ typedef struct ventoy_grub_param_file_replace
typedef struct ventoy_grub_param typedef struct ventoy_grub_param
{ {
grub_env_get_pf grub_env_get; grub_env_get_pf grub_env_get;
grub_env_set_pf grub_env_set;
ventoy_grub_param_file_replace file_replace; ventoy_grub_param_file_replace file_replace;
grub_env_printf_pf grub_env_printf; grub_env_printf_pf grub_env_printf;
}ventoy_grub_param; }ventoy_grub_param;
#pragma pack() #pragma pack()
int grub_ext_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_img_chunk_list *chunk_list); int grub_ext_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_img_chunk_list *chunk_list);
int grub_fat_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_img_chunk_list *chunk_list); int grub_fat_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_img_chunk_list *chunk_list);
void grub_iso9660_set_nojoliet(int nojoliet); void grub_iso9660_set_nojoliet(int nojoliet);

View File

@@ -12,17 +12,35 @@ make install
PATH=$PATH:$VT_DIR/GRUB2/INSTALL/bin/:$VT_DIR/GRUB2/INSTALL/sbin/ PATH=$PATH:$VT_DIR/GRUB2/INSTALL/bin/:$VT_DIR/GRUB2/INSTALL/sbin/
net_modules_legacy="net tftp http" net_modules_legacy="net tftp http"
all_modules_legacy="date drivemap blocklist 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="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"
net_modules_uefi="efinet net tftp http" net_modules_uefi="efinet net tftp http"
all_modules_uefi="blocklist ventoy test 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="blocklist ventoy test 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_arm64_uefi="blocklist ventoy test 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"
if [ "$1" = "uefi" ]; then if [ "$1" = "uefi" ]; then
all_modules="$net_modules_uefi $all_modules_uefi " all_modules="$net_modules_uefi $all_modules_uefi "
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/EFI/BOOT/grubx64_real.efi" --format 'x86_64-efi' --compression 'auto' $all_modules_uefi 'fat' 'part_msdos'
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/EFI/BOOT/grubx64_real.efi" --format 'x86_64-efi' --compression 'auto' $all_modules_uefi
#grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi" -c "$VT_DIR/LiveCD/GRUB/embed.cfg" --prefix '/EFI/boot' --output "$VT_DIR/LiveCD/GRUB/bootx64.efi" --format 'x86_64-efi' --compression 'auto' $all_modules_uefi 'fat' 'part_msdos'
elif [ "$1" = "i386efi" ]; then
all_modules="$net_modules_uefi $all_modules_uefi "
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/i386-efi" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/EFI/BOOT/grubia32_real.efi" --format 'i386-efi' --compression 'auto' $all_modules_uefi
elif [ "$1" = "arm64" ]; then
all_modules="$net_modules_uefi $all_modules_arm64_uefi "
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/arm64-efi" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/EFI/BOOT/BOOTAA64.EFI" --format 'arm64-efi' --compression 'auto' $all_modules_arm64_uefi
else else
all_modules="$net_modules_legacy $all_modules_legacy " all_modules="$net_modules_legacy $all_modules_legacy "
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/grub/i386-pc/core.img" --format 'i386-pc' --compression 'auto' $all_modules_legacy 'fat' 'part_msdos' 'biosdisk' grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/grub/i386-pc/core.img" --format 'i386-pc' --compression 'auto' $all_modules_legacy 'fat' 'part_msdos' 'biosdisk'
#grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc" -c "$VT_DIR/LiveCD/GRUB/embed.cfg" --prefix '/EFI/boot' --output "$VT_DIR/LiveCD/GRUB/cdrom.img" --format 'i386-pc-eltorito' --compression 'auto' $all_modules_legacy 'biosdisk' 'iso9660' 'fat' 'part_msdos'
#rm -f $VT_DIR/LiveCD/GRUB/boot_hybrid.img
#cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc/boot_hybrid.img $VT_DIR/LiveCD/GRUB/boot_hybrid.img
fi fi
grub-mknetdir --modules="$all_modules" --net-directory=$VT_DIR/GRUB2/PXE --subdir=grub2 --locales=en@quot || exit 1 grub-mknetdir --modules="$all_modules" --net-directory=$VT_DIR/GRUB2/PXE --subdir=grub2 --locales=en@quot || exit 1
@@ -31,17 +49,50 @@ if [ "$1" = "uefi" ]; then
rm -f $VT_DIR/GRUB2/NBP/core.efi rm -f $VT_DIR/GRUB2/NBP/core.efi
cp -a $VT_DIR/GRUB2/PXE/grub2/x86_64-efi/core.efi $VT_DIR/GRUB2/NBP/core.efi || exit 1 cp -a $VT_DIR/GRUB2/PXE/grub2/x86_64-efi/core.efi $VT_DIR/GRUB2/NBP/core.efi || exit 1
rm -f $VT_DIR/INSTALL/grub/x86_64-efi/normal.mod rm -rf $VT_DIR/INSTALL/grub/x86_64-efi
mkdir -p $VT_DIR/INSTALL/grub/x86_64-efi
cp -a $VT_DIR/GRUB2/PXE/grub2/x86_64-efi/normal.mod $VT_DIR/INSTALL/grub/x86_64-efi/normal.mod || exit 1 cp -a $VT_DIR/GRUB2/PXE/grub2/x86_64-efi/normal.mod $VT_DIR/INSTALL/grub/x86_64-efi/normal.mod || exit 1
#copy other modules #copy other modules
ls -1 $VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi/ | egrep '\.(lst|mod)$' | while read line; do ls -1 $VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi/ | egrep '\.(lst|mod)$' | while read line; do
if ! echo $all_modules | grep -q " ${line%.mod} "; then if ! echo $all_modules | grep -q " ${line%.mod} "; then
echo "Copy $line ..." echo "Copy $line ..."
rm -f $VT_DIR/INSTALL/grub/x86_64-efi/$line
cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi/$line $VT_DIR/INSTALL/grub/x86_64-efi/ cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi/$line $VT_DIR/INSTALL/grub/x86_64-efi/
fi fi
done done
elif [ "$1" = "i386efi" ]; then
rm -f $VT_DIR/GRUB2/NBP/core.efi
cp -a $VT_DIR/GRUB2/PXE/grub2/i386-efi/core.efi $VT_DIR/GRUB2/NBP/core.efi || exit 1
rm -rf $VT_DIR/INSTALL/grub/i386-efi
mkdir -p $VT_DIR/INSTALL/grub/i386-efi
cp -a $VT_DIR/GRUB2/PXE/grub2/i386-efi/normal.mod $VT_DIR/INSTALL/grub/i386-efi/normal.mod || exit 1
#copy other modules
ls -1 $VT_DIR/GRUB2/INSTALL/lib/grub/i386-efi/ | egrep '\.(lst|mod)$' | while read line; do
if ! echo $all_modules | grep -q " ${line%.mod} "; then
echo "Copy $line ..."
cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/i386-efi/$line $VT_DIR/INSTALL/grub/i386-efi/
fi
done
elif [ "$1" = "arm64" ]; then
rm -f $VT_DIR/GRUB2/NBP/core.efi
cp -a $VT_DIR/GRUB2/PXE/grub2/arm64-efi/core.efi $VT_DIR/GRUB2/NBP/core.efi || exit 1
rm -rf $VT_DIR/INSTALL/grub/arm64-efi
mkdir -p $VT_DIR/INSTALL/grub/arm64-efi
cp -a $VT_DIR/GRUB2/PXE/grub2/arm64-efi/normal.mod $VT_DIR/INSTALL/grub/arm64-efi/normal.mod || exit 1
#copy other modules
ls -1 $VT_DIR/GRUB2/INSTALL/lib/grub/arm64-efi/ | egrep '\.(lst|mod)$' | while read line; do
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/
fi
done
else else
rm -f $VT_DIR/GRUB2/NBP/core.0 rm -f $VT_DIR/GRUB2/NBP/core.0
cp -a $VT_DIR/GRUB2/PXE/grub2/i386-pc/core.0 $VT_DIR/GRUB2/NBP/core.0 || exit 1 cp -a $VT_DIR/GRUB2/PXE/grub2/i386-pc/core.0 $VT_DIR/GRUB2/NBP/core.0 || exit 1

View File

@@ -1,14 +0,0 @@
#!/bin/bash
/opt/diet32/bin/diet gcc -Os -m32 vtoy_gen_uuid.c -o vtoy_gen_uuid
if [ -e vtoy_gen_uuid ]; then
echo -e '\n############### SUCCESS ###############\n'
rm -f ../INSTALL/tool/vtoy_gen_uuid
cp -a vtoy_gen_uuid ../INSTALL/tool/vtoy_gen_uuid
else
echo -e '\n############### FAILED ################\n'
exit 1
fi

View File

@@ -1,50 +0,0 @@
/******************************************************************************
* vtoy_gen_uuid.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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
int main()
{
int i;
int fd;
unsigned char uuid[16];
fd = open("/dev/random", O_RDONLY);
if (fd < 0)
{
srand(time(NULL));
for (i = 0; i < 16; i++)
{
uuid[i] = (unsigned char)(rand());
}
}
else
{
read(fd, uuid, 16);
}
fwrite(uuid, 1, 16, stdout);
return 0;
}

View File

@@ -36,15 +36,32 @@ export SED=$BUSYBOX_PATH/sed
export SLEEP=$BUSYBOX_PATH/sleep export SLEEP=$BUSYBOX_PATH/sleep
export HEAD=$BUSYBOX_PATH/head export HEAD=$BUSYBOX_PATH/head
if [ -e $BUSYBOX_PATH/64h ]; then if [ -e $BUSYBOX_PATH/32h ]; then
if [ -e $BUSYBOX_PATH/64h ]; then
#this is arm64
$BUSYBOX_PATH/xzminidecaa64 < $BUSYBOX_PATH/busyboxaa64.xz > $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/vtchmodaa64 $BUSYBOX_PATH/busybox
else
#this is x86_64
$BUSYBOX_PATH/xzminidec64 < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox
if [ -s $BUSYBOX_PATH/busybox ]; then
$BUSYBOX_PATH/vtchmod64 $BUSYBOX_PATH/busybox
else
$BUSYBOX_PATH/xzminidec64_musl < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/vtchmod64_musl $BUSYBOX_PATH/busybox
fi
fi
else
$BUSYBOX_PATH/xzminidec32 < $BUSYBOX_PATH/busybox32.xz > $BUSYBOX_PATH/busybox $BUSYBOX_PATH/xzminidec32 < $BUSYBOX_PATH/busybox32.xz > $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/vtchmod32 $BUSYBOX_PATH/busybox $BUSYBOX_PATH/vtchmod32 $BUSYBOX_PATH/busybox
else
$BUSYBOX_PATH/xzminidec64 < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/vtchmod64 $BUSYBOX_PATH/busybox
fi fi
$BUSYBOX_PATH/busybox --install $BUSYBOX_PATH if [ -e $BUSYBOX_PATH/busybox ]; then
$BUSYBOX_PATH/busybox --install $BUSYBOX_PATH
else
$BUSYBOX_PATH/tmpxz -d $BUSYBOX_PATH/busybox32.xz
$BUSYBOX_PATH/busybox32 --install $BUSYBOX_PATH
fi
export PATH=$BUSYBOX_PATH/:$VTOY_PATH/tool export PATH=$BUSYBOX_PATH/:$VTOY_PATH/tool
@@ -74,14 +91,26 @@ else
xz -d -c loop.cpio.xz | cpio -idm 2>>$VTLOG xz -d -c loop.cpio.xz | cpio -idm 2>>$VTLOG
fi fi
if [ -e $BUSYBOX_PATH/64h ]; then if [ -e $BUSYBOX_PATH/32h ]; then
echo "Use busybox32 toolkit ..." >>$VTLOG if [ -e $BUSYBOX_PATH/64h ]; then
echo "Use ARM64 busybox toolkit ..." >>$VTLOG
echo aarch64 > $VTOY_PATH/ventoy_arch
ln -s $BUSYBOX_PATH/xzminidecaa64 $BUSYBOX_PATH/xzminidec
ln -s $VTOY_PATH/tool/dmsetupaa64 $VTOY_PATH/tool/dmsetup
ln -s $VTOY_PATH/tool/lunzipaa64 $VTOY_PATH/tool/lunzip
else
echo "Use x86_64 busybox toolkit ..." >>$VTLOG
echo x86_64 > $VTOY_PATH/ventoy_arch
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
fi
else
echo "Use i386 busybox toolkit ..." >>$VTLOG
echo i386 > $VTOY_PATH/ventoy_arch
ln -s $BUSYBOX_PATH/xzminidec32 $BUSYBOX_PATH/xzminidec ln -s $BUSYBOX_PATH/xzminidec32 $BUSYBOX_PATH/xzminidec
ln -s $VTOY_PATH/tool/dmsetup32 $VTOY_PATH/tool/dmsetup ln -s $VTOY_PATH/tool/dmsetup32 $VTOY_PATH/tool/dmsetup
else ln -s $VTOY_PATH/tool/lunzip32 $VTOY_PATH/tool/lunzip
echo "Use busybox64 toolkit ..." >>$VTLOG
ln -s $BUSYBOX_PATH/xzminidec64 $BUSYBOX_PATH/xzminidec
ln -s $VTOY_PATH/tool/dmsetup64 $VTOY_PATH/tool/dmsetup
fi fi
rm -f *.xz rm -f *.xz

Binary file not shown.

BIN
IMG/cpio/ventoy/busybox/a64 Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -59,7 +59,15 @@ mkdir -p $VTOY_PATH/mnt
mount /vt_modloop $VTOY_PATH/mnt mount /vt_modloop $VTOY_PATH/mnt
KoModPath=$(find $VTOY_PATH/mnt/ -name 'dm-mod.ko*') KoModPath=$(find $VTOY_PATH/mnt/ -name 'dm-mod.ko*')
vtlog "insmod $KoModPath" vtlog "KoModPath=$KoModPath"
if modinfo $KoModPath | grep -q 'depend.*dax'; then
vtlog "First install dax mod ..."
DaxModPath=$(echo $KoModPath | sed 's#md/dm-mod#dax/dax#')
vtlog "insmod $DaxModPath"
insmod $DaxModPath
fi
insmod $KoModPath insmod $KoModPath
umount $VTOY_PATH/mnt umount $VTOY_PATH/mnt

View File

@@ -35,14 +35,32 @@ fi
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace" 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})
vtlog "blkdev_num=$blkdev_num vtDM=$vtDM ..."
while [ -n "Y" ]; do
if [ -b /dev/$vtDM ]; then
break
else
sleep 0.3
fi
done
if [ -n "$1" ]; then if [ -n "$1" ]; then
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
vtDM=$(ventoy_find_dm_id ${blkdev_num})
vtlog "ln -s /dev/$vtDM $1" vtlog "ln -s /dev/$vtDM $1"
ln -s /dev/$vtDM "$1" ln -s /dev/$vtDM "$1"
else
vtLABEL=$($BUSYBOX_PATH/blkid /dev/$vtDM | $SED 's/.*LABEL="\([^"]*\)".*/\1/')
vtlog "vtLABEL is $vtLABEL"
if [ -z "$vtLABEL" ]; then
vtLABEL=$($SED "s/.*label=\([^ ]*\)/\1/" /proc/cmdline)
vtlog "vtLABEL is $vtLABEL from cmdline"
fi
ln -s /dev/$vtDM "/dev/disk/by-label/$vtLABEL"
fi fi
# OK finish # OK finish
set_ventoy_hook_finish set_ventoy_hook_finish

View File

@@ -21,11 +21,23 @@
if $GREP -q '^"$mount_handler"' /init; then if $GREP -q '^"$mount_handler"' /init; then
echo 'use mount_handler ...' >> $VTLOG echo 'use mount_handler ...' >> $VTLOG
$SED "/^\"\$mount_handler\"/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ventoy-disk.sh \"\$archisodevice\"" -i /init
if [ -f /hooks/archiso ]; then vthookfile=/hooks/archiso
$SED '/while ! poll_device "${dev}"/a\ if /ventoy/busybox/sh /ventoy/hook/arch/ventoy-timeout.sh ${dev}; then break; fi' -i /hooks/archiso
if [ -e /hooks/miso ]; then
vthookfile=/hooks/miso
$SED "/^\"\$mount_handler\"/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ventoy-disk.sh \"\$misodevice\"" -i /init
elif [ -e /hooks/artix ]; then
vthookfile=/hooks/artix
$SED "/^\"\$mount_handler\"/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ventoy-disk.sh \"\$artixdevice\"" -i /init
else
$SED "/^\"\$mount_handler\"/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ventoy-disk.sh \"\$archisodevice\"" -i /init
fi fi
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 '^KEEP_SEARCHING' /init; then elif $GREP -q '^KEEP_SEARCHING' /init; then
echo 'KEEP_SEARCHING found ...' >> $VTLOG echo 'KEEP_SEARCHING found ...' >> $VTLOG
$SED "/^KEEP_SEARCHING/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ovios-disk.sh " -i /init $SED "/^KEEP_SEARCHING/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ovios-disk.sh " -i /init

View File

@@ -0,0 +1,51 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
mkdir /sys
mount -t sysfs sys /sys
wait_for_usb_disk_ready
vtdiskname=$(get_ventoy_disk_name)
if [ "$vtdiskname" = "unknown" ]; then
vtlog "ventoy disk not found"
PATH=$VTPATH_OLD
exit 0
fi
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
blkdev_num_mknod=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
vtDM=$(ventoy_find_dm_id ${blkdev_num})
vtlog "blkdev_num=$blkdev_num blkdev_num_mknod=$blkdev_num_mknod vtDM=$vtDM"
if [ -b /dev/$vtDM ]; then
vtlog "dev already exist ..."
else
vtlog "mknode dev ..."
mknod -m 660 /dev/$vtDM b $blkdev_num_mknod
fi
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,26 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
$BUSYBOX_PATH/mkdir /dev
$BUSYBOX_PATH/mknod -m 660 /dev/console b 5 1
$SED "/for device in/i $BUSYBOX_PATH/sh $VTOY_PATH/hook/aryalinux/disk_hook.sh" -i /init
#$SED "/for device in/i exec $BUSYBOX_PATH/sh" -i /init

View File

@@ -0,0 +1,48 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
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"
# blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
# blkdev_num_mknod=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
# vtDM=$(ventoy_find_dm_id ${blkdev_num})
# vtlog "blkdev_num=$blkdev_num blkdev_num_mknod=$blkdev_num_mknod vtDM=$vtDM"
# if [ -b /dev/$vtDM ]; then
# vtlog "dev already exist ..."
# else
# vtlog "mknode dev ..."
# mknod -m 660 /dev/$vtDM b $blkdev_num_mknod
# fi
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,24 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
$SED "/^ *mdev *-s/a $BUSYBOX_PATH/sh $VTOY_PATH/hook/austrumi/disk_hook.sh" -i /init
$SED "s/BOOT_TYPE=livecd/BOOT_TYPE=usb/g" -i /init

View File

@@ -0,0 +1,25 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
ventoy_set_inotify_script blackPanther/ventoy-inotifyd-hook.sh
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/blackPanther/ventoy-inotifyd-start.sh /lib/dracut/hooks/pre-udev/00-ventoy-inotifyd-start.sh
$SED "s#printf\(.*\)\$CMDLINE#printf\1 root=/dev/dm-0 \$CMDLINE root=/dev/dm-0#" -i /lib/dracut-lib.sh

View File

@@ -0,0 +1,46 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
if is_ventoy_hook_finished; then
exit 0
fi
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
if is_inotify_ventoy_part $3; then
vtlog "##### INOTIFYD: $2/$3 is created (YES) ..."
vtlog "find ventoy partition ..."
$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh $3 noreplace
blkdev_num_dev=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
if ! [ -e /dev/dm-0 ]; then
mknod -m 660 /dev/dm-0 b $blkdev_num_dev
fi
blackPanther-root /dev/dm-0
set_ventoy_hook_finish
else
vtlog "##### INOTIFYD: $2/$3 is created (NO) ..."
fi
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,32 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
vtHook=$($CAT $VTOY_PATH/inotifyd-hook-script.txt)
vtdisk=$(get_ventoy_disk_name)
if [ "$vtdisk" = "unknown" ]; then
vtlog "... start inotifyd listen $vtHook ..."
$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $vtHook /dev:n 2>&- &
else
vtlog "... $vtdisk already exist ..."
$BUSYBOX_PATH/sh $vtHook n /dev "${vtdisk#/dev/}2"
fi

View File

@@ -29,7 +29,7 @@ for i in 0 1 2 3 4 5 6 7 8 9; do
fi fi
done done
ventoy_extract_vtloopex /dev/${vtdiskname#/dev/}2 crux ventoy_extract_vtloopex ${vtdiskname}2 crux
vtLoopExDir=$VTOY_PATH/vtloopex/crux/vtloopex vtLoopExDir=$VTOY_PATH/vtloopex/crux/vtloopex
$BUSYBOX_PATH/xz -d $vtLoopExDir/dm-mod/$(uname -r)/64/dax.ko.xz $BUSYBOX_PATH/xz -d $vtLoopExDir/dm-mod/$(uname -r)/64/dax.ko.xz

View File

@@ -33,12 +33,11 @@ if [ -e /init ] && $GREP -q '^mountroot$' /init; then
fi fi
elif [ -e "$CD_DETECT" ]; then elif [ -e "$CD_DETECT" ]; then
echo "$CD_DETECT exist, now add hook in it..." >> $VTLOG echo "$CD_DETECT exist, now add hook in it..." >> $VTLOG
$SED "1 a $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/disk_mount_hook.sh" -i "$CD_DETECT" $SED "1 a $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/disk_mount_hook.sh" -i "$CD_DETECT"
TITLE_LINE=$($GREP -m1 '^hw-detect.*detect_progress_title' "$CD_DETECT")
if [ $? -eq 0 ]; then if [ -e /bin/list-devices ]; then
echo "add $TITLE_LINE for hook" >> $VTLOG mv /bin/list-devices /bin/list-devices-bk
$SED "1 a$TITLE_LINE" -i "$CD_DETECT" cp -a /ventoy/hook/debian/list-devices /bin/list-devices
fi fi
elif [ -e /init ] && $GREP -q '/start-udev$' /init; then elif [ -e /init ] && $GREP -q '/start-udev$' /init; then
echo "Here use notify ..." >> $VTLOG echo "Here use notify ..." >> $VTLOG
@@ -60,3 +59,21 @@ if [ -f $VTOY_PATH/autoinstall ]; then
fi fi
fi fi
#for ARMA aka Omoikane
if [ -f /mod.img ] && [ -f /mod/fs/cramfs.ko ]; then
echo "mount mod.img and install dm-mod.ko" >> $VTLOG
$BUSYBOX_PATH/insmod /mod/fs/cramfs.ko
$BUSYBOX_PATH/mkdir $VTOY_PATH/modmnt
$BUSYBOX_PATH/mount /mod.img $VTOY_PATH/modmnt
$BUSYBOX_PATH/insmod $VTOY_PATH/modmnt/md/dm-mod.ko
$BUSYBOX_PATH/umount $VTOY_PATH/modmnt
$BUSYBOX_PATH/rmmod cramfs
fi
#for siduction-patience-nox-
if [ -f /scripts/fll ]; then
$SED "/unset FINGERED/a\\echo '/dev/mapper/ventoy';return;" -i /scripts/fll
fi

View File

@@ -0,0 +1,68 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
ventoy_os_install_dmsetup_by_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=$VTOY_PATH/mnt/iso/casper/filesystem.squashfs
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)
if [ "$vtdiskname" = "unknown" ]; then
vtlog "ventoy disk not found"
PATH=$VTPATH_OLD
exit 0
fi
if ! grep -q 'device-mapper' /proc/devices; then
ventoy_os_install_dmsetup_by_fuse $vtdiskname
fi
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
PATH=$VTPATH_OLD
# OK finish
set_ventoy_hook_finish

View 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/>.
#
#************************************************************************************
if [ -e /init ] && $GREP -q '^mountroot$' /init; then
echo "Here before mountroot ..." >> $VTLOG
$SED "/^mountroot$/i\\$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/kylin-disk.sh" -i /init
$SED "/^mountroot$/i\\export LIVEMEDIA=/dev/mapper/ventoy" -i /init
$SED "/^mountroot$/i\\export LIVE_MEDIA=/dev/mapper/ventoy" -i /init
fi

View File

@@ -0,0 +1,9 @@
#! /bin/sh
if [ "$1" = "usb-partition" -a -z "$2" ]; then
if [ -f /ventoy/list-devices-usb-part ]; then
cat /ventoy/list-devices-usb-part
fi
fi
/bin/list-devices-bk $*

View File

@@ -0,0 +1,43 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
if is_ventoy_hook_finished; then
exit 0
fi
vtlog "####### $0 $* ########"
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
wait_for_usb_disk_ready
vtdiskname=$(get_ventoy_disk_name)
if [ "$vtdiskname" = "unknown" ]; then
vtlog "ventoy disk not found"
PATH=$VTPATH_OLD
exit 0
fi
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
PATH=$VTPATH_OLD
set_ventoy_hook_finish

View File

@@ -0,0 +1,21 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
$SED "/^for DEVICE in/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/mll-disk.sh" -i /etc/02_overlay.sh

View File

@@ -42,6 +42,7 @@ if ! [ -e $VTOY_DM_PATH ]; then
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/') blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
mknod -m 0666 $VTOY_DM_PATH b $blkdev_num mknod -m 0666 $VTOY_DM_PATH b $blkdev_num
fi fi
cp -a $VTOY_DM_PATH /dev/ventoy
PATH=$VTPATH_OLD PATH=$VTPATH_OLD

View File

@@ -19,4 +19,4 @@
$SED '1 apmedia=usbhd' -i /init $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\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/puppy-disk.sh" -i /init
$SED "/^ *HAVE_PARTS=/a\ HAVE_PARTS='mapper/ventoy|iso9660'" -i /init $SED "/^ *HAVE_PARTS=/a\ HAVE_PARTS='ventoy|iso9660'" -i /init

View File

@@ -47,7 +47,13 @@ ventoy_os_install_dmsetup() {
if [ $LINTCNT -gt 1 ]; then if [ $LINTCNT -gt 1 ]; then
vtlog "more than one pkgs, need to filter..." vtlog "more than one pkgs, need to filter..."
VER=$($BUSYBOX_PATH/uname -r) VER=$($BUSYBOX_PATH/uname -r)
LINE=$($GREP ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list | $GREP $VER) 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)
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)
fi
fi fi
install_udeb_from_line "$LINE" ${vt_usb_disk} install_udeb_from_line "$LINE" ${vt_usb_disk}
fi fi
@@ -127,15 +133,7 @@ else
vtlog "boot=, or casper, don't mount" vtlog "boot=, or casper, don't mount"
else else
vtlog "No boot param, need to mount" vtlog "No boot param, need to mount"
$BUSYBOX_PATH/mkdir /cdrom echo /dev/$1 > /ventoy/list-devices-usb-part
if [ -b $VTOY_DM_PATH ]; then
vtlog "mount $VTOY_DM_PATH ..."
$BUSYBOX_PATH/mount -t iso9660 $VTOY_DM_PATH /cdrom
else
vtlog "mount /dev/$1 ..."
$BUSYBOX_PATH/mount -t iso9660 /dev/$1 /cdrom
fi
fi fi
fi fi

View File

@@ -35,6 +35,8 @@ ventoy_get_debian_distro() {
else else
echo 'puppy'; return echo 'puppy'; return
fi fi
elif $GREP -m1 -q 'Minimal.*Linux.*Live' /init; then
echo 'mll'; return
fi fi
fi fi
@@ -68,6 +70,10 @@ ventoy_get_debian_distro() {
echo 'vyos'; return echo 'vyos'; return
fi fi
if $GREP -q 'kylin' /proc/version; then
echo 'kylin'; return
fi
echo 'default' echo 'default'
} }
@@ -76,10 +82,10 @@ DISTRO=$(ventoy_get_debian_distro)
echo "##### distribution = $DISTRO ######" >> $VTLOG echo "##### distribution = $DISTRO ######" >> $VTLOG
. $VTOY_PATH/hook/debian/${DISTRO}-hook.sh . $VTOY_PATH/hook/debian/${DISTRO}-hook.sh
if [ -f /bin/env2debconf ]; then
$SED "1a /bin/sh $VTOY_PATH/hook/debian/ventoy_env2debconf.sh" -i /bin/env2debconf
$SED "s#in *\$(set)#in \$(cat /ventoy/envset)#" -i /bin/env2debconf
fi

View File

@@ -0,0 +1,33 @@
#!/bin/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/>.
#
#************************************************************************************
PATH=$PATH:/ventoy/busybox
set > /ventoy/tmpenvset
for i in $(cat /proc/cmdline); do
if echo $i | grep -q "="; then
vtKey=${i%=*}
if ! grep -q "^$vtKey" /ventoy/tmpenvset; then
echo $i >> /ventoy/envset
fi
fi
done
cat /ventoy/tmpenvset >> /ventoy/envset

View File

@@ -22,3 +22,12 @@
ventoy_systemd_udevd_work_around ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k" ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k"
if [ -f /init ]; then
vtSize=$($BUSYBOX_PATH/stat -c '%s' /init)
if ! [ -L /init ]; then
if [ $vtSize -eq 0 ]; then
rm -f /init
fi
fi
fi

View File

@@ -0,0 +1,41 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
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_extract_vtloopex ${vtdiskname}2 dragora
vtLoopExDir=$VTOY_PATH/vtloopex/dragora/vtloopex
$BUSYBOX_PATH/xz -d $vtLoopExDir/dm-mod/$(uname -r)/64/dm-mod.ko.xz
$BUSYBOX_PATH/insmod $vtLoopExDir/dm-mod/$(uname -r)/64/dm-mod.ko
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,22 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
$SED "/iso9660/i $BUSYBOX_PATH/sh $VTOY_PATH/hook/dragora/disk_hook.sh" -i /init

View File

@@ -21,6 +21,9 @@
if $GREP -q kaspersky /proc/version; then if $GREP -q kaspersky /proc/version; then
$SED "/sysresccd_stage1_normal[^(]*$/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/gentoo/disk_hook.sh" -i /init $SED "/sysresccd_stage1_normal[^(]*$/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/gentoo/disk_hook.sh" -i /init
if [ -f /ventoy/ventoy_persistent_map ]; then
$SED "/sysresccd_parsecmdline[^(]*$/a\ BACKSTORE_CMD='LABEL=casper-rw,noloop'" -i /init
fi
elif [ -d /etc/udev/rules.d ] || [ -d /lib/udev/rules.d ]; then elif [ -d /etc/udev/rules.d ] || [ -d /lib/udev/rules.d ]; then
ventoy_systemd_udevd_work_around ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k noreplace" ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k noreplace"

View File

@@ -0,0 +1,27 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
$SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE root=/dev/dm-0#" -i /lib/dracut-lib.sh
$BUSYBOX_PATH/rm -f /usr/lib/systemd/system-generators/systemd-fstab-generator /lib/systemd/system-generators/systemd-fstab-generator
ventoy_set_inotify_script lunar/ventoy-inotifyd-hook.sh
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/lunar/ventoy-inotifyd-start.sh /lib/dracut/hooks/pre-udev/01-ventoy-inotifyd-start.sh

View File

@@ -0,0 +1,45 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
if is_ventoy_hook_finished; then
exit 0
fi
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
if is_inotify_ventoy_part $3; then
vtlog "##### INOTIFYD: $2/$3 is created (YES) ..."
vtlog "find ventoy partition ..."
$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh $3 noreplace
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
vtDM=$(ventoy_find_dm_id ${blkdev_num})
mount -t iso9660 /dev/$vtDM /sysroot
set_ventoy_hook_finish
else
vtlog "##### INOTIFYD: $2/$3 is created (NO) ..."
fi
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,31 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
vtHook=$($CAT $VTOY_PATH/inotifyd-hook-script.txt)
vtdisk=$(get_ventoy_disk_name)
if [ "$vtdisk" = "unknown" ]; then
vtlog "... start inotifyd listen $vtHook ..."
$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $vtHook /dev:n 2>&- &
else
vtlog "... $vtdisk already exist ..."
$BUSYBOX_PATH/sh $vtHook n /dev "${vtdisk#/dev/}2"
fi

View File

@@ -0,0 +1,66 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
vtlog "######### $0 $* ############"
if is_ventoy_hook_finished; then
exit 0
fi
wait_for_usb_disk_ready
vtdiskname=$(get_ventoy_disk_name)
if [ "$vtdiskname" = "unknown" ]; then
vtlog "ventoy disk not found"
exit 0
fi
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
vtDM=$(ventoy_find_dm_id ${blkdev_num})
vtlog "blkdev_num=$blkdev_num vtDM=$vtDM ..."
while [ -n "Y" ]; do
if [ -b /dev/$vtDM ]; then
break
else
sleep 0.3
fi
done
if [ -n "$1" ]; then
vtlog "ln -s /dev/$vtDM $1"
ln -s /dev/$vtDM "$1"
else
vtLABEL=$($BUSYBOX_PATH/blkid /dev/$vtDM | $SED 's/.*LABEL="\([^"]*\)".*/\1/')
vtlog "vtLABEL is $vtLABEL"
if [ -z "$vtLABEL" ]; then
vtLABEL=$($SED "s/.*label=\([^ ]*\)/\1/" /proc/cmdline)
vtlog "vtLABEL is $vtLABEL from cmdline"
fi
ln -s /dev/$vtDM "/dev/disk/by-label/$vtLABEL"
fi
# OK finish
set_ventoy_hook_finish

View File

@@ -28,8 +28,22 @@ else
$CAT $VTOY_PATH/hook/default/13-dm-disk.rules > "$DISTRO_UDEV_DIR/13-dm-disk.rules" $CAT $VTOY_PATH/hook/default/13-dm-disk.rules > "$DISTRO_UDEV_DIR/13-dm-disk.rules"
fi fi
if $GREP -q '^"$mount_handler"' /init; then
if $GREP -q '^mount_setup$' init; then echo 'use mount_handler ...' >> $VTLOG
vthookfile=/hooks/archiso
if [ -e /hooks/miso ]; then
vthookfile=/hooks/miso
$SED "/^\"\$mount_handler\"/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/manjaro/ventoy-disk.sh \"\$misodevice\"" -i /init
else
$SED "/^\"\$mount_handler\"/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/manjaro/ventoy-disk.sh \"\$archisodevice\"" -i /init
fi
if [ -f $vthookfile ]; then
$SED '/while ! poll_device "${dev}"/a\ if /ventoy/busybox/sh /ventoy/hook/manjaro/ventoy-timeout.sh ${dev}; then break; fi' -i $vthookfile
fi
elif $GREP -q '^mount_setup$' init; then
echo "Here use notify ..." >> $VTLOG echo "Here use notify ..." >> $VTLOG
ventoy_set_inotify_script manjaro/ventoy-inotifyd-hook.sh ventoy_set_inotify_script manjaro/ventoy-inotifyd-hook.sh

View File

@@ -0,0 +1,34 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
$SED 's#/dev/cdrom#/dev/ventoy#' -i /installer/isoInstaller.py
ventoy_set_inotify_script photon/ventoy-inotifyd-hook.sh
[ -d /dev ] || $BUSYBOX_PATH/mkdir /dev
[ -d /sys ] || $BUSYBOX_PATH/mkdir /sys
$BUSYBOX_PATH/mount -t devtmpfs -o mode=0755,noexec,nosuid,strictatime devtmpfs /dev
$BUSYBOX_PATH/mount -t sysfs sys /sys
$BUSYBOX_PATH/rm -f /init
$BUSYBOX_PATH/sh $VTOY_PATH/hook/photon/ventoy-inotifyd-start.sh

View File

@@ -0,0 +1,43 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
if is_ventoy_hook_finished; then
exit 0
fi
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
if is_inotify_ventoy_part $3; then
vtlog "##### INOTIFYD: $2/$3 is created (YES) ..."
vtlog "find ventoy partition ..."
$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh $3 noreplace
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
mknod -m 0660 /dev/ventoy b $blkdev_num
set_ventoy_hook_finish
else
vtlog "##### INOTIFYD: $2/$3 is created (NO) ..."
fi
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,31 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
vtHook=$($CAT $VTOY_PATH/inotifyd-hook-script.txt)
vtdisk=$(get_ventoy_disk_name)
if [ "$vtdisk" = "unknown" ]; then
vtlog "... start inotifyd listen $vtHook ..."
$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $vtHook /dev:n 2>&- &
else
vtlog "... $vtdisk already exist ..."
$BUSYBOX_PATH/sh $vtHook n /dev "${vtdisk#/dev/}2"
fi

View File

@@ -0,0 +1,47 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
if is_ventoy_hook_finished; then
exit 0
fi
vtlog "####### $0 $* ########"
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
wait_for_usb_disk_ready
vtdiskname=$(get_ventoy_disk_name)
if [ "$vtdiskname" = "unknown" ]; then
vtlog "ventoy disk not found"
PATH=$VTPATH_OLD
exit 0
fi
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
blkdev_num=$(dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
mknod -m 660 /dev/ventoy b $blkdev_num
PATH=$VTPATH_OLD
set_ventoy_hook_finish

View File

@@ -0,0 +1,24 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
$SED "/^\"\$mount_handler\"/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/pisilinux/ventoy-disk.sh" -i /init
$SED "/^\"\$mount_handler\"/i\ export root=/dev/ventoy" -i /init

View 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
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
wait_for_usb_disk_ready
vtdiskname=$(get_ventoy_disk_name)
if [ "$vtdiskname" = "unknown" ]; then
vtlog "ventoy disk not found"
PATH=$VTPATH_OLD
exit 0
fi
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
mknod -m 0660 /dev/ventoy b $blkdev_num
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,24 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
$SED "/export *CMDLINE/i CMDLINE=\"root=/dev/ventoy \${CMDLINE}\"" -i /etc/rc.d/init.d/rc.S
$SED "1a $BUSYBOX_PATH/sh $VTOY_PATH/hook/ploplinux/disk_hook.sh" -i /etc/rc.d/init.d/rootmount

View 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
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
wait_for_usb_disk_ready
vtdiskname=$(get_ventoy_disk_name)
if [ "$vtdiskname" = "unknown" ]; then
vtlog "ventoy disk not found"
PATH=$VTPATH_OLD
exit 0
fi
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
vtDM=$(ventoy_find_dm_id ${blkdev_num})
echo -n "/dev/$vtDM" > /ventoy/rootdev
PATH=$VTPATH_OLD

Some files were not shown because too many files have changed in this diff Show More