Initial commit from Ventoy@7cbdc5c

This commit is contained in:
2026-08-23 00:38:40 -04:00
commit e9a7a16826
2848 changed files with 439164 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
#!/bin/sh
rm -f vtoyfat_64
rm -f vtoyfat_32
rm -f vtoyfat_aa64
rm -f vtoyfat_m64e
gcc -O2 -D_FILE_OFFSET_BITS=64 vtoyfat_linux.c -Ifat_io_lib/include fat_io_lib/lib/libfat_io_64.a -o vtoyfat_64
gcc -m32 -O2 -D_FILE_OFFSET_BITS=64 vtoyfat_linux.c -Ifat_io_lib/include fat_io_lib/lib/libfat_io_32.a -o vtoyfat_32
aarch64-buildroot-linux-uclibc-gcc -static -O2 -D_FILE_OFFSET_BITS=64 vtoyfat_linux.c -Ifat_io_lib/include fat_io_lib/lib/libfat_io_aa64.a -o vtoyfat_aa64
mips64el-linux-musl-gcc -mips64r2 -mabi=64 -static -O2 -D_FILE_OFFSET_BITS=64 vtoyfat_linux.c -Ifat_io_lib/include fat_io_lib/lib/libfat_io_m64e.a -o vtoyfat_m64e
if [ -e vtoyfat_64 ] && [ -e vtoyfat_32 ] && [ -e vtoyfat_aa64 ] && [ -e vtoyfat_m64e ]; then
echo -e "\n===== success $name =======\n"
strip --strip-all vtoyfat_32
strip --strip-all vtoyfat_64
aarch64-buildroot-linux-uclibc-strip --strip-all vtoyfat_aa64
mips64el-linux-musl-strip --strip-all vtoyfat_m64e
[ -d ../INSTALL/tool/i386/ ] && mv vtoyfat_32 ../INSTALL/tool/i386/vtoyfat
[ -d ../INSTALL/tool/x86_64/ ] && mv vtoyfat_64 ../INSTALL/tool/x86_64/vtoyfat
[ -d ../INSTALL/tool/aarch64/ ] && mv vtoyfat_aa64 ../INSTALL/tool/aarch64/vtoyfat
[ -d ../INSTALL/tool/mips64el/ ] && mv vtoyfat_m64e ../INSTALL/tool/mips64el/vtoyfat
else
echo -e "\n===== failed =======\n"
exit 1
fi
+43
View File
@@ -0,0 +1,43 @@
#!/bin/sh
if ! [ -f fat_io_lib.zip ]; then
echo "No fat_io_lib.zip found ..."
exit 1
fi
unzip fat_io_lib.zip
rm -rf include
rm -rf lib
cd release
gcc -O2 -D_FILE_OFFSET_BITS=64 fat*.c -c
ar -rc libfat_io_64.a *.o
rm -f *.o
gcc -m32 -O2 -D_FILE_OFFSET_BITS=64 fat*.c -c
ar -rc libfat_io_32.a *.o
rm -f *.o
aarch64-linux-gnu-gcc -O2 -D_FILE_OFFSET_BITS=64 fat*.c -c
ar -rc libfat_io_aa64.a *.o
rm -f *.o
mips64el-linux-musl-gcc -mips64r2 -mabi=64 -O2 -D_FILE_OFFSET_BITS=64 fat*.c -c
ar -rc libfat_io_m64e.a *.o
rm -f *.o
cd -
mkdir lib
mkdir include
mv release/*.a lib/
cp -a release/*.h include/
Binary file not shown.
+159
View File
@@ -0,0 +1,159 @@
/******************************************************************************
* vtoyfat.c ---- Parse fat file system
*
* Copyright (c) 2020, longpanda <[email protected]>
*
* 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 <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <fat_filelib.h>
static int g_disk_fd = 0;
static int vtoy_disk_read(uint32 sector, uint8 *buffer, uint32 sector_count)
{
lseek(g_disk_fd, sector * 512, SEEK_SET);
read(g_disk_fd, buffer, sector_count * 512);
return 1;
}
static int check_secure_boot(void)
{
void *flfile = NULL;
flfile = fl_fopen("/EFI/BOOT/grubx64_real.efi", "rb");
if (flfile)
{
fl_fclose(flfile);
return 0;
}
return 1;
}
static int get_ventoy_version(void)
{
int rc = 1;
int size = 0;
char *buf = NULL;
char *pos = NULL;
char *end = NULL;
void *flfile = NULL;
flfile = fl_fopen("/grub/grub.cfg", "rb");
if (flfile)
{
fl_fseek(flfile, 0, SEEK_END);
size = (int)fl_ftell(flfile);
fl_fseek(flfile, 0, SEEK_SET);
buf = malloc(size + 1);
if (buf)
{
fl_fread(buf, 1, size, flfile);
buf[size] = 0;
pos = strstr(buf, "VENTOY_VERSION=");
if (pos)
{
pos += strlen("VENTOY_VERSION=");
if (*pos == '"')
{
pos++;
}
end = pos;
while (*end != 0 && *end != '"' && *end != '\r' && *end != '\n')
{
end++;
}
*end = 0;
printf("%s\n", pos);
rc = 0;
}
free(buf);
}
fl_fclose(flfile);
}
return rc;
}
int main(int argc, char **argv)
{
int op = 0;
int rc = 1;
char *disk;
if (argc != 2 && argc != 3)
{
printf("Usage: vtoyfat /dev/sdbs \n");
printf("Usage: vtoyfat -s /dev/sdbs \n");
return 1;
}
if (argv[1][0] == '-' && argv[1][1] == 'T')
{
return 0;
}
disk = argv[1];
if (argv[1][0] == '-' && argv[1][1] == 's')
{
op = 1;
disk = argv[2];
}
g_disk_fd = open(disk, O_RDONLY);
if (g_disk_fd < 0)
{
printf("Failed to open %s\n", disk);
return 1;
}
fl_init();
if (0 == fl_attach_media(vtoy_disk_read, NULL))
{
if (op == 0)
{
rc = get_ventoy_version();
}
else
{
rc = check_secure_boot();
}
}
fl_shutdown();
close(g_disk_fd);
return rc;
}