mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-06-03 00:19:56 -04:00
initial commit
This commit is contained in:
parent
2090c6fa97
commit
05a1b863a6
487 changed files with 114253 additions and 0 deletions
15
vtoyfat/build.sh
Normal file
15
vtoyfat/build.sh
Normal file
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh
|
||||
|
||||
rm -f vtoyfat_64
|
||||
rm -f vtoyfat_32
|
||||
|
||||
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
|
||||
|
||||
if [ -e vtoyfat_64 ] && [ -e vtoyfat_32 ]; then
|
||||
echo -e "\n===== success $name =======\n"
|
||||
[ -d ../INSTALL/tool/ ] && mv vtoyfat_32 ../INSTALL/tool/ && mv vtoyfat_64 ../INSTALL/tool/
|
||||
else
|
||||
echo -e "\n===== failed =======\n"
|
||||
exit 1
|
||||
fi
|
3
vtoyfat/fat_io_lib/README.txt
Normal file
3
vtoyfat/fat_io_lib/README.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
========= About fat_io_lib =========
|
||||
1. Download fat_io_lib source code from http://ultra-embedded.com/releases/fat_io_lib.zip
|
||||
2. decompress the code and run buildlib.sh
|
25
vtoyfat/fat_io_lib/buildlib.sh
Normal file
25
vtoyfat/fat_io_lib/buildlib.sh
Normal file
|
@ -0,0 +1,25 @@
|
|||
#!/bin/sh
|
||||
|
||||
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
|
||||
|
||||
|
||||
cd -
|
||||
|
||||
mkdir lib
|
||||
mkdir include
|
||||
|
||||
mv release/*.a lib/
|
||||
cp -a release/*.h include/
|
||||
|
||||
|
127
vtoyfat/vtoyfat_linux.c
Normal file
127
vtoyfat/vtoyfat_linux.c
Normal file
|
@ -0,0 +1,127 @@
|
|||
/******************************************************************************
|
||||
* vtoyfat.c ---- Parse fat file system
|
||||
*
|
||||
* 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 <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 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 rc = 1;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
printf("Usage: vtoyfat /dev/sdb \n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argv[1][0] == '-' && argv[1][1] == 'T')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
g_disk_fd = open(argv[1], O_RDONLY);
|
||||
if (g_disk_fd < 0)
|
||||
{
|
||||
printf("Failed to open %s\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fl_init();
|
||||
|
||||
if (0 == fl_attach_media(vtoy_disk_read, NULL))
|
||||
{
|
||||
rc = get_ventoy_version();
|
||||
}
|
||||
|
||||
fl_shutdown();
|
||||
|
||||
close(g_disk_fd);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue