1. Change the UTF-16 languages.ini to UTF-8 languages.json

2. The update button is available even if data corrupted in VTOYEFI partition.
3. Set the default focus to No when you click Install button in Ventoy2Disk.exe.
4. Fix a BUG when booting Windows VHD(x) with the latest ventoy_vhdboot.img.
5. Support boot Windows VHD(x) files in local disk.
This commit is contained in:
longpanda 2021-05-08 14:22:37 +08:00
parent 7715bd705c
commit 849dfb463d
28 changed files with 7477 additions and 4512 deletions

View File

@ -1603,6 +1603,7 @@ module = {
module = {
name = ventoy;
common = ventoy/ventoy.c;
common = ventoy/ventoy_cmd.c;
common = ventoy/ventoy_linux.c;
common = ventoy/ventoy_unix.c;
common = ventoy/ventoy_windows.c;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -140,6 +140,7 @@ typedef struct cpio_newc_header
typedef int (*grub_char_check_func)(int c);
#define ventoy_is_decimal(str) ventoy_string_check(str, grub_isdigit)
#define OFFSET_OF(TYPE, MEMBER) ((grub_size_t) &((TYPE *)0)->MEMBER)
#pragma pack(1)
typedef struct ventoy_patch_vhd
@ -932,6 +933,8 @@ extern grub_uint8_t *g_conf_replace_new_buf;
extern int g_conf_replace_new_len;
extern int g_conf_replace_new_len_align;
extern grub_uint64_t g_ventoy_disk_size;
extern grub_uint64_t g_ventoy_disk_part_size[2];
extern grub_uint32_t g_ventoy_plat_data;
#define ventoy_unix_fill_virt(new_data, new_len) \
{ \
@ -949,12 +952,16 @@ extern grub_uint64_t g_ventoy_disk_size;
chain->virt_img_size_in_bytes += data_secs * 2048; \
}
#define ventoy_syscall0(name) grub_##name()
#define ventoy_syscall1(name, a) grub_##name(a)
char * ventoy_get_line(char *start);
int ventoy_cmp_img(img_info *img1, img_info *img2);
void ventoy_swap_img(img_info *img1, img_info *img2);
char * ventoy_plugin_get_cur_install_template(const char *isopath);
install_template * ventoy_plugin_find_install_template(const char *isopath);
persistence_config * ventoy_plugin_find_persistent(const char *isopath);
grub_uint64_t ventoy_get_vtoy_partsize(int part);
void ventoy_plugin_dump_injection(void);
void ventoy_plugin_dump_auto_install(void);
int ventoy_fill_windows_rtdata(void *buf, char *isopath);
@ -994,11 +1001,16 @@ grub_err_t ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char *
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);
int ventoy_gzip_compress(void *mem_in, int mem_in_len, void *mem_out, int mem_out_len);
grub_uint64_t ventoy_get_part1_size(ventoy_gpt_info *gpt);
int ventoy_plugin_add_custom_boot(const char *vcfgpath);
const char * ventoy_plugin_get_custom_boot(const char *isopath);
grub_err_t ventoy_cmd_dump_custom_boot(grub_extcmd_context_t ctxt, int argc, char **args);
int ventoy_gzip_compress(void *mem_in, int mem_in_len, void *mem_out, int mem_out_len);
int ventoy_load_part_table(const char *diskname);
int ventoy_env_init(void);
int ventoy_register_all_cmd(void);
int ventoy_unregister_all_cmd(void);
#define VTOY_CMD_CHECK(a) if (33554432 != g_ventoy_disk_part_size[a]) ventoy_syscall0(exit)
#endif /* __VENTOY_DEF_H__ */

View File

@ -720,7 +720,7 @@ grub_err_t ventoy_cmd_unix_fill_image_desc(grub_extcmd_context_t ctxt, int argc,
desc = (ventoy_image_desc *)(byte + i);
desc->disk_size = g_ventoy_disk_size;
desc->part1_size = ventoy_get_part1_size(g_ventoy_part_info);
desc->part1_size = g_ventoy_disk_part_size[0];
grub_memcpy(desc->disk_uuid, g_ventoy_part_info->MBR.BootCode + 0x180, 16);
grub_memcpy(desc->disk_signature, g_ventoy_part_info->MBR.BootCode + 0x1B8, 4);

View File

@ -44,14 +44,12 @@
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)
static int ventoy_vhd_find_bcd(int *bcdoffset, int *bcdlen, const char *path)
{
grub_uint32_t offset;
grub_file_t file;
@ -61,10 +59,9 @@ static int ventoy_vhd_find_bcd(int *bcdoffset, int *bcdlen)
grub_script_execute_sourcecode(cmdbuf);
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", "(vhdiso)/boot/bcd");
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "(vhdiso)%s", path);
if (!file)
{
grub_printf("Failed to open bcd file in the image file\n");
return 1;
}
@ -83,13 +80,15 @@ static int ventoy_vhd_find_bcd(int *bcdoffset, int *bcdlen)
return 0;
}
static int ventoy_vhd_patch_path(char *vhdpath, ventoy_patch_vhd *patch1, ventoy_patch_vhd *patch2)
static int ventoy_vhd_patch_path(char *vhdpath, ventoy_patch_vhd *patch1, ventoy_patch_vhd *patch2,
int bcdoffset, int bcdlen)
{
int i;
int cnt = 0;
char *pos;
grub_size_t pathlen;
const char *plat;
char *newpath = NULL;
grub_uint16_t *unicode_path;
const grub_uint8_t winloadexe[] =
{
@ -97,6 +96,11 @@ static int ventoy_vhd_patch_path(char *vhdpath, ventoy_patch_vhd *patch1, ventoy
0x65, 0x00, 0x78, 0x00, 0x65, 0x00
};
while ((*vhdpath) != '/')
{
vhdpath++;
}
pathlen = sizeof(grub_uint16_t) * (grub_strlen(vhdpath) + 1);
debug("unicode path for <%s> len:%d\n", vhdpath, (int)pathlen);
@ -110,10 +114,10 @@ static int ventoy_vhd_patch_path(char *vhdpath, ventoy_patch_vhd *patch1, ventoy
if (plat && (plat[0] == 'e')) /* UEFI */
{
pos = g_vhdboot_isobuf + g_vhdboot_bcd_offset;
pos = g_vhdboot_isobuf + bcdoffset;
/* winload.exe ==> winload.efi */
for (i = 0; i + (int)sizeof(winloadexe) < g_vhdboot_bcd_len; i++)
for (i = 0; i + (int)sizeof(winloadexe) < bcdlen; i++)
{
if (*((grub_uint32_t *)(pos + i)) == 0x00690077 &&
grub_memcmp(pos + i, winloadexe, sizeof(winloadexe)) == 0)
@ -127,7 +131,8 @@ static int ventoy_vhd_patch_path(char *vhdpath, ventoy_patch_vhd *patch1, ventoy
debug("winload patch %d times\n", cnt);
}
for (pos = vhdpath; *pos; pos++)
newpath = grub_strdup(vhdpath);
for (pos = newpath; *pos; pos++)
{
if (*pos == '/')
{
@ -135,40 +140,127 @@ static int ventoy_vhd_patch_path(char *vhdpath, ventoy_patch_vhd *patch1, ventoy
}
}
grub_utf8_to_utf16(unicode_path, pathlen, (grub_uint8_t *)vhdpath, -1, NULL);
grub_utf8_to_utf16(unicode_path, pathlen, (grub_uint8_t *)newpath, -1, NULL);
grub_memcpy(patch1->vhd_file_path, unicode_path, pathlen);
grub_memcpy(patch2->vhd_file_path, unicode_path, pathlen);
grub_free(newpath);
return 0;
}
static int ventoy_vhd_patch_disk(ventoy_patch_vhd *patch1, ventoy_patch_vhd *patch2)
static int ventoy_vhd_read_parttbl(const char *filename, ventoy_gpt_info *gpt, int *index)
{
int ret = 1;
grub_file_t file = NULL;
grub_disk_t disk = NULL;
file = grub_file_open(filename, VENTOY_FILE_TYPE);
if (!file)
{
goto end;
}
disk = grub_disk_open(file->device->disk->name);
if (!disk)
{
goto end;
}
*index = file->device->disk->partition->index;
grub_disk_read(disk, 0, 0, sizeof(ventoy_gpt_info), gpt);
ret = 0;
end:
check_free(file, grub_file_close);
check_free(disk, grub_disk_close);
return ret;
}
static int ventoy_vhd_patch_disk(const char *vhdpath, ventoy_patch_vhd *patch1, ventoy_patch_vhd *patch2)
{
int partIndex = 0;
grub_uint64_t offset = 0;
char efipart[16] = {0};
ventoy_gpt_info *gpt = NULL;
grub_memcpy(efipart, g_ventoy_part_info->Head.Signature, sizeof(g_ventoy_part_info->Head.Signature));
if (vhdpath[0] == '/')
{
gpt = g_ventoy_part_info;
partIndex = 0;
debug("This is Ventoy ISO partIndex %d %s\n", partIndex, vhdpath);
}
else
{
gpt = grub_zalloc(sizeof(ventoy_gpt_info));
ventoy_vhd_read_parttbl(vhdpath, gpt, &partIndex);
debug("This is HDD partIndex %d %s\n", partIndex, vhdpath);
}
debug("part1 type: 0x%x <%s>\n", g_ventoy_part_info->MBR.PartTbl[0].FsFlag, efipart);
grub_memcpy(efipart, gpt->Head.Signature, sizeof(gpt->Head.Signature));
grub_memset(patch1, 0, OFFSET_OF(ventoy_patch_vhd, vhd_file_path));
grub_memset(patch2, 0, OFFSET_OF(ventoy_patch_vhd, vhd_file_path));
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);
ventoy_debug_dump_guid("GPT disk GUID: ", gpt->Head.DiskGuid);
ventoy_debug_dump_guid("GPT partIndex GUID: ", gpt->PartTbl[partIndex].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);
grub_memcpy(patch1->disk_signature_or_guid, gpt->Head.DiskGuid, 16);
grub_memcpy(patch1->part_offset_or_guid, gpt->PartTbl[partIndex].PartGuid, 16);
grub_memcpy(patch2->disk_signature_or_guid, gpt->Head.DiskGuid, 16);
grub_memcpy(patch2->part_offset_or_guid, gpt->PartTbl[partIndex].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);
offset = gpt->MBR.PartTbl[partIndex].StartSectorId;
offset *= 512;
debug("MBR disk signature: %02x%02x%02x%02x Part(%d) offset:%llu\n",
gpt->MBR.BootCode[0x1b8 + 0], gpt->MBR.BootCode[0x1b8 + 1],
gpt->MBR.BootCode[0x1b8 + 2], gpt->MBR.BootCode[0x1b8 + 3],
partIndex + 1, offset);
grub_memcpy(patch1->part_offset_or_guid, &offset, 8);
grub_memcpy(patch2->part_offset_or_guid, &offset, 8);
grub_memcpy(patch1->disk_signature_or_guid, gpt->MBR.BootCode + 0x1b8, 4);
grub_memcpy(patch2->disk_signature_or_guid, gpt->MBR.BootCode + 0x1b8, 4);
patch1->part_type = patch2->part_type = 1;
}
if (gpt != g_ventoy_part_info)
{
grub_free(gpt);
}
return 0;
}
static int ventoy_find_vhdpatch_offset(int bcdoffset, int bcdlen, int *offset)
{
int i;
int cnt = 0;
grub_uint8_t *buf = (grub_uint8_t *)(g_vhdboot_isobuf + bcdoffset);
grub_uint8_t magic[16] = {
0x5C, 0x00, 0x58, 0x00, 0x58, 0x00, 0x58, 0x00, 0x58, 0x00, 0x58, 0x00, 0x58, 0x00, 0x58, 0x00
};
for (i = 0; i < bcdlen - 16 && cnt < 2; i++)
{
if (*(grub_uint32_t *)(buf + i) == 0x0058005C)
{
if (grub_memcmp(magic, buf + i, 16) == 0)
{
*offset++ = i - (int)OFFSET_OF(ventoy_patch_vhd, vhd_file_path);
cnt++;
}
}
}
return 0;
@ -177,6 +269,8 @@ static int ventoy_vhd_patch_disk(ventoy_patch_vhd *patch1, ventoy_patch_vhd *pat
grub_err_t ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args)
{
int rc;
int bcdoffset, bcdlen;
int patchoffset[2];
ventoy_patch_vhd *patch1;
ventoy_patch_vhd *patch2;
char envbuf[64];
@ -194,18 +288,39 @@ grub_err_t ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char *
return 0;
}
rc = ventoy_vhd_find_bcd(&g_vhdboot_bcd_offset, &g_vhdboot_bcd_len);
rc = ventoy_vhd_find_bcd(&bcdoffset, &bcdlen, "/boot/bcd");
if (rc)
{
debug("failed to get bcd location %d\n", rc);
return 0;
}
else
{
ventoy_find_vhdpatch_offset(bcdoffset, bcdlen, patchoffset);
patch1 = (ventoy_patch_vhd *)(g_vhdboot_isobuf + bcdoffset + patchoffset[0]);
patch2 = (ventoy_patch_vhd *)(g_vhdboot_isobuf + bcdoffset + patchoffset[1]);
debug("Find /boot/bcd (%d %d) now patch it (offset: 0x%x 0x%x) ...\n",
bcdoffset, bcdlen, patchoffset[0], patchoffset[1]);
ventoy_vhd_patch_disk(args[0], patch1, patch2);
ventoy_vhd_patch_path(args[0], patch1, patch2, bcdoffset, bcdlen);
}
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);
rc = ventoy_vhd_find_bcd(&bcdoffset, &bcdlen, "/boot/BCD");
if (rc)
{
debug("No file /boot/BCD \n");
}
else
{
ventoy_find_vhdpatch_offset(bcdoffset, bcdlen, patchoffset);
patch1 = (ventoy_patch_vhd *)(g_vhdboot_isobuf + bcdoffset + patchoffset[0]);
patch2 = (ventoy_patch_vhd *)(g_vhdboot_isobuf + bcdoffset + patchoffset[1]);
debug("Find /boot/BCD (%d %d) now patch it (offset: 0x%x 0x%x) ...\n",
bcdoffset, bcdlen, patchoffset[0], patchoffset[1]);
ventoy_vhd_patch_disk(args[0], patch1, patch2);
ventoy_vhd_patch_path(args[0], patch1, patch2, bcdoffset, bcdlen);
}
/* set buffer and size */
#ifdef GRUB_MACHINE_EFI
@ -220,7 +335,7 @@ grub_err_t ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char *
grub_env_set("vtoy_vhd_buf_size", envbuf);
#endif
return 0;
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_load_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args)

Binary file not shown.

View File

@ -131,7 +131,7 @@ function get_os_type {
function vt_check_compatible_pe {
#Check for PE without external tools
if [ -f "$1/HBCD_PE.ini" ]; then
set ventoy_compatible=YES
set ventoy_compatible=YES
fi
}
@ -1230,6 +1230,30 @@ function efi_unsupport_menuentry {
common_unsupport_menuentry
}
function vhdboot_common_func {
vt_patch_vhdboot "$1"
ventoy_debug_pause
if [ -n "$vtoy_vhd_buf_addr" ]; then
if [ "$grub_platform" = "pc" ]; then
ventoy_cli_console
linux16 $vtoy_path/memdisk iso raw
initrd16 mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
boot
ventoy_gui_console
else
ventoy_cli_console
chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi memdisk env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
boot
ventoy_gui_console
fi
else
echo "Please put the right ventoy_vhdboot.img file to the 1st partition"
ventoy_pause
fi
}
function vhd_common_menuentry {
if [ "$VTOY_VHD_NO_WARNING" != "1" ]; then
@ -1252,25 +1276,7 @@ function vhd_common_menuentry {
return
fi
vt_patch_vhdboot "$vt_chosen_path"
ventoy_debug_pause
if [ -n "$vtoy_vhd_buf_addr" ]; then
if [ "$grub_platform" = "pc" ]; then
linux16 $vtoy_path/memdisk iso raw
initrd16 mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
boot
else
ventoy_cli_console
chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi memdisk env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
boot
ventoy_gui_console
fi
else
echo "Please put the right ventoy_vhdboot.img file to the 1st partition"
ventoy_pause
fi
vhdboot_common_func "${vt_chosen_path}"
}
function vhd_unsupport_menuentry {

View File

@ -365,11 +365,15 @@ else
oldver=$(get_disk_ventoy_version $DISK)
if [ $? -ne 0 ]; then
vtwarn "$DISK does not contain Ventoy or data corrupted"
echo ""
vtwarn "Please use -i option if you want to install ventoy to $DISK"
echo ""
exit 1
if is_disk_contains_ventoy $DISK; then
oldver="Unknown"
else
vtwarn "$DISK does not contain Ventoy or data corrupted"
echo ""
vtwarn "Please use -i option if you want to install ventoy to $DISK"
echo ""
exit 1
fi
fi
#reserve secure boot option

View File

@ -151,7 +151,7 @@ tar -czvf ventoy-${curver}-linux.tar.gz $tmpdir
rm -f ventoy-${curver}-windows.zip
cp $OPT Ventoy2Disk*.exe $tmpdir/
cp $OPT $LANG_DIR/languages.ini $tmpdir/ventoy/
cp $OPT $LANG_DIR/languages.json $tmpdir/ventoy/
rm -rf $tmpdir/tool
rm -f $tmpdir/*.sh
rm -rf $tmpdir/WebUI

17
LANGUAGES/README Normal file
View File

@ -0,0 +1,17 @@
File encoding: UTF-8
language name must in the format: "Language-XXX (YYY)"
1. Language- fixed 9 characters
2. XXX: name in English
3. a space (ASCII: 0x20)
4. a left brace (ASCII: 0x28)
5. YYY: name in the specified language
6. a right brace (ASCII: 0x29)
string translation:
all the String Define
#@ will be replaced with \r\n
All the languages will be sorted by the name

17
LANGUAGES/check.sh Normal file
View File

@ -0,0 +1,17 @@
#!/bin/sh
VTOY_PATH=$1
if [ ! -f $VTOY_PATH/LANGUAGES/languages.json ]; then
exit 1
fi
gcc -DFOR_VTOY_JSON_CHECK $VTOY_PATH/Ventoy2Disk/Ventoy2Disk/VentoyJson.c -I $VTOY_PATH/Ventoy2Disk/Ventoy2Disk/ -o checkjson
./checkjson $VTOY_PATH/LANGUAGES/languages.json
ret=$?
rm -f ./checkjson
[ $ret -eq 0 ]

Binary file not shown.

1741
LANGUAGES/languages.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,37 +1,19 @@
#!/bin/bash
echo "generating languages.js ..."
VTOY_PATH=$PWD/../
iconv -f utf-16 -t utf-8 ../LANGUAGES/languages.ini | egrep -v '=STR|^;' | egrep 'Language-|STR_' > languages.js
echo "checking languages.json ..."
sh $VTOY_PATH/LANGUAGES/check.sh $VTOY_PATH || exit 1
echo "generating languages.json ..."
echo "var vtoy_language_data = " > languages.js
cat $VTOY_PATH/LANGUAGES/languages.json >> languages.js
echo ";" >> languages.js
dos2unix languages.js
sed 's/\(STR_.*\)=/"\1":/g' -i languages.js
sed "s/: *'/:\"/g" -i languages.js
sed "s/'\s*$/\",/g" -i languages.js
sed 's/\[Language-\(.*\)\].*/"STR_XXX":""},{"name":"\1",/g' -i languages.js
sed "1s/.*\},/var vtoy_language_data = \[/" -i languages.js
sed 's/\("STR_WEB_COMMUNICATION_ERR"[^,]*\)/\1,/g' -i languages.js
sed 's/,,/,/g' -i languages.js
CNT=$(grep -v -c ',$' languages.js)
if [ $CNT -gt 0 ]; then
echo "====== FAILED ========="
grep -v -n ',$' languages.js
exit 1
fi
echo '"STR_XXX":""}' >> languages.js
echo '];' >> languages.js
rm -f WebUI/static/js/languages.js
mv languages.js WebUI/static/js/
echo "====== SUCCESS =========="
echo "====== SUCCESS =========="

View File

@ -101,13 +101,19 @@ typedef enum OPT_SUBMENU
#define VTOY_MENU_LANGUAGE_BEGIN 0xB000
#define VENTOY_LANGUAGE_INI TEXT(".\\ventoy\\languages.ini")
#define VENTOY_LANGUAGE_INI TEXT(".\\ventoy\\languages.ini")
#define VENTOY_LANGUAGE_JSON TEXT(".\\ventoy\\languages.json")
#define VENTOY_LANGUAGE_INI_A ".\\ventoy\\languages.ini"
#define VENTOY_LANGUAGE_JSON_A ".\\ventoy\\languages.json"
#define VENTOY_CFG_INI TEXT(".\\Ventoy2Disk.ini")
#define VENTOY_CFG_INI_A ".\\Ventoy2Disk.ini"
#define VENTOY_MAX_LANGUAGE 200
#define GET_INI_STRING(Section, Key, Buf) GetPrivateProfileString(Section, Key, TEXT("#"), Buf, sizeof(Buf), VENTOY_LANGUAGE_INI)
typedef struct VENTOY_LANGUAGE
{
WCHAR Name[128];

View File

@ -283,6 +283,12 @@ static int FilterPhysicalDrive(PHY_DRIVE_INFO *pDriveList, DWORD DriveCount)
CurDrive->PartStyle = (MBR.PartTbl[0].FsFlag == 0xEE) ? 1 : 0;
GetVentoyVerInPhyDrive(CurDrive, Part2StartSector, CurDrive->VentoyVersion, sizeof(CurDrive->VentoyVersion), &(CurDrive->SecureBootSupport));
Log("PhyDrive %d is Ventoy Disk ver:%s SecureBoot:%u", CurDrive->PhyDrive, CurDrive->VentoyVersion, CurDrive->SecureBootSupport);
if (CurDrive->VentoyVersion[0] == 0)
{
CurDrive->VentoyVersion[0] = '?';
Log("Unknown Ventoy Version");
}
}
}

View File

@ -148,7 +148,7 @@ typedef struct PHY_DRIVE_INFO
STORAGE_BUS_TYPE BusType;
CHAR DriveLetters[64];
CHAR VentoyVersion[32];
BOOL SecureBootSupport;

View File

@ -110,6 +110,7 @@
<ClCompile Include="process.c" />
<ClCompile Include="Utility.c" />
<ClCompile Include="Ventoy2Disk.c" />
<ClCompile Include="VentoyJson.c" />
<ClCompile Include="WinDialog.c" />
<ClCompile Include="xz-embedded-20130513\linux\lib\decompress_unxz.c" />
</ItemGroup>
@ -133,6 +134,7 @@
<ClInclude Include="process.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="Ventoy2Disk.h" />
<ClInclude Include="VentoyJson.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Ventoy2Disk.rc" />

View File

@ -78,6 +78,9 @@
<ClCompile Include="crc32.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="VentoyJson.c">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Ventoy2Disk.h">
@ -137,6 +140,9 @@
<ClInclude Include="process.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="VentoyJson.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Ventoy2Disk.rc">

View File

@ -0,0 +1,771 @@
/******************************************************************************
* VentoyJson.c
*
* Copyright (c) 2021, longpanda <admin@ventoy.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifdef FOR_VTOY_JSON_CHECK
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#else
#include <Windows.h>
#include "Ventoy2Disk.h"
#endif
#include "VentoyJson.h"
static void vtoy_json_free(VTOY_JSON *pstJsonHead)
{
VTOY_JSON *pstNext = NULL;
while (NULL != pstJsonHead)
{
pstNext = pstJsonHead->pstNext;
if ((pstJsonHead->enDataType < JSON_TYPE_BUTT) && (NULL != pstJsonHead->pstChild))
{
vtoy_json_free(pstJsonHead->pstChild);
}
free(pstJsonHead);
pstJsonHead = pstNext;
}
return;
}
static char *vtoy_json_skip(const char *pcData)
{
while ((NULL != pcData) && ('\0' != *pcData) && (*pcData <= 32))
{
pcData++;
}
return (char *)pcData;
}
VTOY_JSON *vtoy_json_find_item
(
VTOY_JSON *pstJson,
JSON_TYPE enDataType,
const char *szKey
)
{
while (NULL != pstJson)
{
if ((enDataType == pstJson->enDataType) &&
(0 == strcmp(szKey, pstJson->pcName)))
{
return pstJson;
}
pstJson = pstJson->pstNext;
}
return NULL;
}
static int vtoy_json_parse_number
(
VTOY_JSON *pstJson,
const char *pcData,
const char **ppcEnd
)
{
unsigned long Value;
Value = strtoul(pcData, (char **)ppcEnd, 10);
if (*ppcEnd == pcData)
{
Log("Failed to parse json number %s.", pcData);
return JSON_FAILED;
}
pstJson->enDataType = JSON_TYPE_NUMBER;
pstJson->unData.lValue = Value;
return JSON_SUCCESS;
}
static int vtoy_json_parse_string
(
char *pcNewStart,
char *pcRawStart,
VTOY_JSON *pstJson,
const char *pcData,
const char **ppcEnd
)
{
UINT32 uiLen = 0;
const char *pcPos = NULL;
const char *pcTmp = pcData + 1;
*ppcEnd = pcData;
if ('\"' != *pcData)
{
return JSON_FAILED;
}
pcPos = strchr(pcTmp, '\"');
if ((NULL == pcPos) || (pcPos < pcTmp))
{
Log("Invalid string %s.", pcData);
return JSON_FAILED;
}
*ppcEnd = pcPos + 1;
uiLen = (UINT32)(unsigned long)(pcPos - pcTmp);
pstJson->enDataType = JSON_TYPE_STRING;
pstJson->unData.pcStrVal = pcNewStart + (pcTmp - pcRawStart);
pstJson->unData.pcStrVal[uiLen] = '\0';
return JSON_SUCCESS;
}
static int vtoy_json_parse_array
(
char *pcNewStart,
char *pcRawStart,
VTOY_JSON *pstJson,
const char *pcData,
const char **ppcEnd
)
{
int Ret = JSON_SUCCESS;
VTOY_JSON *pstJsonChild = NULL;
VTOY_JSON *pstJsonItem = NULL;
const char *pcTmp = pcData + 1;
*ppcEnd = pcData;
pstJson->enDataType = JSON_TYPE_ARRAY;
if ('[' != *pcData)
{
return JSON_FAILED;
}
pcTmp = vtoy_json_skip(pcTmp);
if (']' == *pcTmp)
{
*ppcEnd = pcTmp + 1;
return JSON_SUCCESS;
}
JSON_NEW_ITEM(pstJson->pstChild, JSON_FAILED);
Ret = vtoy_json_parse_value(pcNewStart, pcRawStart, pstJson->pstChild, pcTmp, ppcEnd);
if (JSON_SUCCESS != Ret)
{
Log("Failed to parse array child.");
return JSON_FAILED;
}
pstJsonChild = pstJson->pstChild;
pcTmp = vtoy_json_skip(*ppcEnd);
while ((NULL != pcTmp) && (',' == *pcTmp))
{
JSON_NEW_ITEM(pstJsonItem, JSON_FAILED);
pstJsonChild->pstNext = pstJsonItem;
pstJsonItem->pstPrev = pstJsonChild;
pstJsonChild = pstJsonItem;
Ret = vtoy_json_parse_value(pcNewStart, pcRawStart, pstJsonChild, vtoy_json_skip(pcTmp + 1), ppcEnd);
if (JSON_SUCCESS != Ret)
{
Log("Failed to parse array child.");
return JSON_FAILED;
}
pcTmp = vtoy_json_skip(*ppcEnd);
}
if ((NULL != pcTmp) && (']' == *pcTmp))
{
*ppcEnd = pcTmp + 1;
return JSON_SUCCESS;
}
else
{
*ppcEnd = pcTmp;
return JSON_FAILED;
}
}
static int vtoy_json_parse_object
(
char *pcNewStart,
char *pcRawStart,
VTOY_JSON *pstJson,
const char *pcData,
const char **ppcEnd
)
{
int Ret = JSON_SUCCESS;
VTOY_JSON *pstJsonChild = NULL;
VTOY_JSON *pstJsonItem = NULL;
const char *pcTmp = pcData + 1;
*ppcEnd = pcData;
pstJson->enDataType = JSON_TYPE_OBJECT;
if ('{' != *pcData)
{
return JSON_FAILED;
}
pcTmp = vtoy_json_skip(pcTmp);
if ('}' == *pcTmp)
{
*ppcEnd = pcTmp + 1;
return JSON_SUCCESS;
}
JSON_NEW_ITEM(pstJson->pstChild, JSON_FAILED);
Ret = vtoy_json_parse_string(pcNewStart, pcRawStart, pstJson->pstChild, pcTmp, ppcEnd);
if (JSON_SUCCESS != Ret)
{
Log("Failed to parse array child.");
return JSON_FAILED;
}
pstJsonChild = pstJson->pstChild;
pstJsonChild->pcName = pstJsonChild->unData.pcStrVal;
pstJsonChild->unData.pcStrVal = NULL;
pcTmp = vtoy_json_skip(*ppcEnd);
if ((NULL == pcTmp) || (':' != *pcTmp))
{
*ppcEnd = pcTmp;
return JSON_FAILED;
}
Ret = vtoy_json_parse_value(pcNewStart, pcRawStart, pstJsonChild, vtoy_json_skip(pcTmp + 1), ppcEnd);
if (JSON_SUCCESS != Ret)
{
Log("Failed to parse array child.");
return JSON_FAILED;
}
pcTmp = vtoy_json_skip(*ppcEnd);
while ((NULL != pcTmp) && (',' == *pcTmp))
{
JSON_NEW_ITEM(pstJsonItem, JSON_FAILED);
pstJsonChild->pstNext = pstJsonItem;
pstJsonItem->pstPrev = pstJsonChild;
pstJsonChild = pstJsonItem;
Ret = vtoy_json_parse_string(pcNewStart, pcRawStart, pstJsonChild, vtoy_json_skip(pcTmp + 1), ppcEnd);
if (JSON_SUCCESS != Ret)
{
Log("Failed to parse array child.");
return JSON_FAILED;
}
pcTmp = vtoy_json_skip(*ppcEnd);
pstJsonChild->pcName = pstJsonChild->unData.pcStrVal;
pstJsonChild->unData.pcStrVal = NULL;
if ((NULL == pcTmp) || (':' != *pcTmp))
{
*ppcEnd = pcTmp;
return JSON_FAILED;
}
Ret = vtoy_json_parse_value(pcNewStart, pcRawStart, pstJsonChild, vtoy_json_skip(pcTmp + 1), ppcEnd);
if (JSON_SUCCESS != Ret)
{
Log("Failed to parse array child.");
return JSON_FAILED;
}
pcTmp = vtoy_json_skip(*ppcEnd);
}
if ((NULL != pcTmp) && ('}' == *pcTmp))
{
*ppcEnd = pcTmp + 1;
return JSON_SUCCESS;
}
else
{
*ppcEnd = pcTmp;
return JSON_FAILED;
}
}
int vtoy_json_parse_value
(
char *pcNewStart,
char *pcRawStart,
VTOY_JSON *pstJson,
const char *pcData,
const char **ppcEnd
)
{
pcData = vtoy_json_skip(pcData);
switch (*pcData)
{
case 'n':
{
if (0 == strncmp(pcData, "null", 4))
{
pstJson->enDataType = JSON_TYPE_NULL;
*ppcEnd = pcData + 4;
return JSON_SUCCESS;
}
break;
}
case 'f':
{
if (0 == strncmp(pcData, "false", 5))
{
pstJson->enDataType = JSON_TYPE_BOOL;
pstJson->unData.lValue = 0;
*ppcEnd = pcData + 5;
return JSON_SUCCESS;
}
break;
}
case 't':
{
if (0 == strncmp(pcData, "true", 4))
{
pstJson->enDataType = JSON_TYPE_BOOL;
pstJson->unData.lValue = 1;
*ppcEnd = pcData + 4;
return JSON_SUCCESS;
}
break;
}
case '\"':
{
return vtoy_json_parse_string(pcNewStart, pcRawStart, pstJson, pcData, ppcEnd);
}
case '[':
{
return vtoy_json_parse_array(pcNewStart, pcRawStart, pstJson, pcData, ppcEnd);
}
case '{':
{
return vtoy_json_parse_object(pcNewStart, pcRawStart, pstJson, pcData, ppcEnd);
}
case '-':
{
return vtoy_json_parse_number(pstJson, pcData, ppcEnd);
}
default :
{
if (*pcData >= '0' && *pcData <= '9')
{
return vtoy_json_parse_number(pstJson, pcData, ppcEnd);
}
}
}
*ppcEnd = pcData;
Log("Invalid json data %u.", (UINT8)(*pcData));
return JSON_FAILED;
}
VTOY_JSON * vtoy_json_create(void)
{
VTOY_JSON *pstJson = NULL;
pstJson = (VTOY_JSON *)malloc(sizeof(VTOY_JSON));
if (NULL == pstJson)
{
return NULL;
}
memset(pstJson, 0, sizeof(VTOY_JSON));
return pstJson;
}
int vtoy_json_parse(VTOY_JSON *pstJson, const char *szJsonData)
{
UINT32 uiMemSize = 0;
int Ret = JSON_SUCCESS;
char *pcNewBuf = NULL;
const char *pcEnd = NULL;
uiMemSize = strlen(szJsonData) + 1;
pcNewBuf = (char *)malloc(uiMemSize);
if (NULL == pcNewBuf)
{
Log("Failed to alloc new buf.");
return JSON_FAILED;
}
memcpy(pcNewBuf, szJsonData, uiMemSize);
pcNewBuf[uiMemSize - 1] = 0;
Ret = vtoy_json_parse_value(pcNewBuf, (char *)szJsonData, pstJson, szJsonData, &pcEnd);
if (JSON_SUCCESS != Ret)
{
Log("Failed to parse json data start=%p, end=%p", szJsonData, pcEnd);
return JSON_FAILED;
}
return JSON_SUCCESS;
}
int vtoy_json_scan_parse
(
const VTOY_JSON *pstJson,
UINT32 uiParseNum,
JSON_PARSE *pstJsonParse
)
{
UINT32 i = 0;
const VTOY_JSON *pstJsonCur = NULL;
JSON_PARSE *pstCurParse = NULL;
for (pstJsonCur = pstJson; NULL != pstJsonCur; pstJsonCur = pstJsonCur->pstNext)
{
if ((JSON_TYPE_OBJECT == pstJsonCur->enDataType) ||
(JSON_TYPE_ARRAY == pstJsonCur->enDataType))
{
continue;
}
for (i = 0, pstCurParse = NULL; i < uiParseNum; i++)
{
if (0 == strcmp(pstJsonParse[i].pcKey, pstJsonCur->pcName))
{
pstCurParse = pstJsonParse + i;
break;
}
}
if (NULL == pstCurParse)
{
continue;
}
switch (pstJsonCur->enDataType)
{
case JSON_TYPE_NUMBER:
{
if (sizeof(UINT32) == pstCurParse->uiBufSize)
{
*(UINT32 *)(pstCurParse->pDataBuf) = (UINT32)pstJsonCur->unData.lValue;
}
else if (sizeof(UINT16) == pstCurParse->uiBufSize)
{
*(UINT16 *)(pstCurParse->pDataBuf) = (UINT16)pstJsonCur->unData.lValue;
}
else if (sizeof(UINT8) == pstCurParse->uiBufSize)
{
*(UINT8 *)(pstCurParse->pDataBuf) = (UINT8)pstJsonCur->unData.lValue;
}
else if ((pstCurParse->uiBufSize > sizeof(UINT64)))
{
sprintf_s((char *)pstCurParse->pDataBuf, pstCurParse->uiBufSize, "%llu",
(unsigned long long)(pstJsonCur->unData.lValue));
}
else
{
Log("Invalid number data buf size %u.", pstCurParse->uiBufSize);
}
break;
}
case JSON_TYPE_STRING:
{
strcpy_s((char *)pstCurParse->pDataBuf, pstCurParse->uiBufSize, pstJsonCur->unData.pcStrVal);
break;
}
case JSON_TYPE_BOOL:
{
*(UINT8 *)(pstCurParse->pDataBuf) = (pstJsonCur->unData.lValue) > 0 ? 1 : 0;
break;
}
default :
{
break;
}
}
}
return JSON_SUCCESS;
}
int vtoy_json_scan_array
(
VTOY_JSON *pstJson,
const char *szKey,
VTOY_JSON **ppstArrayItem
)
{
VTOY_JSON *pstJsonItem = NULL;
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_ARRAY, szKey);
if (NULL == pstJsonItem)
{
Log("Key %s is not found in json data.", szKey);
return JSON_NOT_FOUND;
}
*ppstArrayItem = pstJsonItem;
return JSON_SUCCESS;
}
int vtoy_json_scan_array_ex
(
VTOY_JSON *pstJson,
const char *szKey,
VTOY_JSON **ppstArrayItem
)
{
VTOY_JSON *pstJsonItem = NULL;
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_ARRAY, szKey);
if (NULL == pstJsonItem)
{
Log("Key %s is not found in json data.", szKey);
return JSON_NOT_FOUND;
}
*ppstArrayItem = pstJsonItem->pstChild;
return JSON_SUCCESS;
}
int vtoy_json_scan_object
(
VTOY_JSON *pstJson,
const char *szKey,
VTOY_JSON **ppstObjectItem
)
{
VTOY_JSON *pstJsonItem = NULL;
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_OBJECT, szKey);
if (NULL == pstJsonItem)
{
Log("Key %s is not found in json data.", szKey);
return JSON_NOT_FOUND;
}
*ppstObjectItem = pstJsonItem;
return JSON_SUCCESS;
}
int vtoy_json_get_int
(
VTOY_JSON *pstJson,
const char *szKey,
int *piValue
)
{
VTOY_JSON *pstJsonItem = NULL;
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_NUMBER, szKey);
if (NULL == pstJsonItem)
{
Log("Key %s is not found in json data.", szKey);
return JSON_NOT_FOUND;
}
*piValue = (int)pstJsonItem->unData.lValue;
return JSON_SUCCESS;
}
int vtoy_json_get_uint
(
VTOY_JSON *pstJson,
const char *szKey,
UINT32 *puiValue
)
{
VTOY_JSON *pstJsonItem = NULL;
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_NUMBER, szKey);
if (NULL == pstJsonItem)
{
Log("Key %s is not found in json data.", szKey);
return JSON_NOT_FOUND;
}
*puiValue = (UINT32)pstJsonItem->unData.lValue;
return JSON_SUCCESS;
}
int vtoy_json_get_uint64
(
VTOY_JSON *pstJson,
const char *szKey,
UINT64 *pui64Value
)
{
VTOY_JSON *pstJsonItem = NULL;
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_NUMBER, szKey);
if (NULL == pstJsonItem)
{
Log("Key %s is not found in json data.", szKey);
return JSON_NOT_FOUND;
}
*pui64Value = (UINT64)pstJsonItem->unData.lValue;
return JSON_SUCCESS;
}
int vtoy_json_get_bool
(
VTOY_JSON *pstJson,
const char *szKey,
UINT8 *pbValue
)
{
VTOY_JSON *pstJsonItem = NULL;
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_BOOL, szKey);
if (NULL == pstJsonItem)
{
Log("Key %s is not found in json data.", szKey);
return JSON_NOT_FOUND;
}
*pbValue = pstJsonItem->unData.lValue > 0 ? 1 : 0;
return JSON_SUCCESS;
}
int vtoy_json_get_string
(
VTOY_JSON *pstJson,
const char *szKey,
UINT32 uiBufLen,
char *pcBuf
)
{
VTOY_JSON *pstJsonItem = NULL;
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_STRING, szKey);
if (NULL == pstJsonItem)
{
Log("Key %s is not found in json data.", szKey);
return JSON_NOT_FOUND;
}
strcpy_s(pcBuf, uiBufLen, pstJsonItem->unData.pcStrVal);
return JSON_SUCCESS;
}
const char * vtoy_json_get_string_ex(VTOY_JSON *pstJson, const char *szKey)
{
VTOY_JSON *pstJsonItem = NULL;
if ((NULL == pstJson) || (NULL == szKey))
{
return NULL;
}
pstJsonItem = vtoy_json_find_item(pstJson, JSON_TYPE_STRING, szKey);
if (NULL == pstJsonItem)
{
Log("Key %s is not found in json data.", szKey);
return NULL;
}
return pstJsonItem->unData.pcStrVal;
}
int vtoy_json_destroy(VTOY_JSON *pstJson)
{
if (NULL == pstJson)
{
return JSON_SUCCESS;
}
if (NULL != pstJson->pstChild)
{
vtoy_json_free(pstJson->pstChild);
}
if (NULL != pstJson->pstNext)
{
vtoy_json_free(pstJson->pstNext);
}
free(pstJson);
return JSON_SUCCESS;
}
#ifdef FOR_VTOY_JSON_CHECK
int main(int argc, char**argv)
{
int ret = 1;
int FileSize;
FILE *fp;
void *Data = NULL;
VTOY_JSON *json = NULL;
fp = fopen(argv[1], "rb");
if (!fp)
{
Log("Failed to open %s\n", argv[1]);
goto out;
}
fseek(fp, 0, SEEK_END);
FileSize = (int)ftell(fp);
fseek(fp, 0, SEEK_SET);
Data = malloc(FileSize + 4);
if (!Data)
{
Log("Failed to malloc %d\n", FileSize + 4);
goto out;
}
*((char *)Data + FileSize) = 0;
fread(Data, 1, FileSize, fp);
json = vtoy_json_create();
if (!json)
{
Log("Failed vtoy_json_create\n");
goto out;
}
if (vtoy_json_parse(json, (char *)Data) != JSON_SUCCESS)
{
goto out;
}
ret = 0;
out:
if (fp) fclose(fp);
if (Data) free(Data);
if (json) vtoy_json_destroy(json);
printf("\n");
return ret;
}
#endif

View File

@ -0,0 +1,164 @@
/******************************************************************************
* VentoyJson.h
*
* Copyright (c) 2021, longpanda <admin@ventoy.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __VENTOY_JSON_H__
#define __VENTOY_JSON_H__
#ifdef FOR_VTOY_JSON_CHECK
typedef unsigned char UINT8;
typedef unsigned short UINT16;
typedef unsigned int UINT32;
typedef unsigned long long UINT64;
#define Log printf
#define strcpy_s(a, b, c) strncpy(a, c, b)
#define sprintf_s snprintf
#endif
#define JSON_SUCCESS 0
#define JSON_FAILED 1
#define JSON_NOT_FOUND 2
typedef enum _JSON_TYPE
{
JSON_TYPE_NUMBER = 0,
JSON_TYPE_STRING,
JSON_TYPE_BOOL,
JSON_TYPE_ARRAY,
JSON_TYPE_OBJECT,
JSON_TYPE_NULL,
JSON_TYPE_BUTT
}JSON_TYPE;
typedef struct _VTOY_JSON
{
struct _VTOY_JSON *pstPrev;
struct _VTOY_JSON *pstNext;
struct _VTOY_JSON *pstChild;
JSON_TYPE enDataType;
union
{
char *pcStrVal;
int iNumVal;
UINT64 lValue;
}unData;
char *pcName;
}VTOY_JSON;
typedef struct _JSON_PARSE
{
char *pcKey;
void *pDataBuf;
UINT32 uiBufSize;
}JSON_PARSE;
#define JSON_NEW_ITEM(pstJson, ret) \
{ \
(pstJson) = (VTOY_JSON *)malloc(sizeof(VTOY_JSON)); \
if (NULL == (pstJson)) \
{ \
Log("Failed to alloc memory for json.\n"); \
return (ret); \
} \
memset((pstJson), 0, sizeof(VTOY_JSON));\
}
VTOY_JSON *vtoy_json_find_item
(
VTOY_JSON *pstJson,
JSON_TYPE enDataType,
const char *szKey
);
int vtoy_json_parse_value
(
char *pcNewStart,
char *pcRawStart,
VTOY_JSON *pstJson,
const char *pcData,
const char **ppcEnd
);
VTOY_JSON * vtoy_json_create(void);
int vtoy_json_parse(VTOY_JSON *pstJson, const char *szJsonData);
int vtoy_json_scan_parse
(
const VTOY_JSON *pstJson,
UINT32 uiParseNum,
JSON_PARSE *pstJsonParse
);
int vtoy_json_scan_array
(
VTOY_JSON *pstJson,
const char *szKey,
VTOY_JSON **ppstArrayItem
);
int vtoy_json_scan_array_ex
(
VTOY_JSON *pstJson,
const char *szKey,
VTOY_JSON **ppstArrayItem
);
int vtoy_json_scan_object
(
VTOY_JSON *pstJson,
const char *szKey,
VTOY_JSON **ppstObjectItem
);
int vtoy_json_get_int
(
VTOY_JSON *pstJson,
const char *szKey,
int *piValue
);
int vtoy_json_get_uint
(
VTOY_JSON *pstJson,
const char *szKey,
UINT32 *puiValue
);
int vtoy_json_get_uint64
(
VTOY_JSON *pstJson,
const char *szKey,
UINT64 *pui64Value
);
int vtoy_json_get_bool
(
VTOY_JSON *pstJson,
const char *szKey,
UINT8 *pbValue
);
int vtoy_json_get_string
(
VTOY_JSON *pstJson,
const char *szKey,
UINT32 uiBufLen,
char *pcBuf
);
const char * vtoy_json_get_string_ex(VTOY_JSON *pstJson, const char *szKey);
int vtoy_json_destroy(VTOY_JSON *pstJson);
#endif /* __VENTOY_JSON_H__ */

Binary file not shown.

View File

@ -464,10 +464,13 @@ static int vtoy_check_device(ventoy_os_param *param, const char *device)
static int vtoy_print_os_param(ventoy_os_param *param, char *diskname)
{
int cnt = 0;
int fd, size;
int cnt = 0;
char *path = param->vtoy_img_path;
const char *fs;
char diskpath[256] = {0};
char sizebuf[64] = {0};
cnt = vtoy_find_disk_by_size(param->vtoy_disk_size, diskname);
debug("find disk by size %llu, cnt=%d...\n", (unsigned long long)param->vtoy_disk_size, cnt);
if (1 == cnt)
@ -494,6 +497,37 @@ static int vtoy_print_os_param(ventoy_os_param *param, char *diskname)
if (1 == cnt)
{
if (strstr(diskname, "nvme") || strstr(diskname, "mmc") || strstr(diskname, "nbd"))
{
snprintf(diskpath, sizeof(diskpath) - 1, "/sys/class/block/%sp2/size", diskname);
}
else
{
snprintf(diskpath, sizeof(diskpath) - 1, "/sys/class/block/%s2/size", diskname);
}
if (access(diskpath, F_OK) >= 0)
{
debug("get part size from sysfs for %s\n", diskpath);
fd = open(diskpath, O_RDONLY | O_BINARY);
if (fd >= 0)
{
read(fd, sizebuf, sizeof(sizebuf));
size = (int)strtoull(sizebuf, NULL, 10);
close(fd);
if ((size != (64 * 1024)) && (size != (8 * 1024)))
{
debug("sizebuf=<%s> size=%d\n", sizebuf, size);
return 1;
}
}
}
else
{
debug("%s not exist \n", diskpath);
}
printf("/dev/%s#%s#%s\n", diskname, fs, path);
return 0;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.