add support to freebsd

pull/283/head
longpanda 4 years ago
parent 036e9cc167
commit d80a008c04

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

@ -305,6 +305,18 @@ static grub_err_t ventoy_cmd_break(grub_extcmd_context_t ctxt, int argc, char **
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
static grub_err_t ventoy_cmd_strstr(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
if (argc != 2)
{
return 1;
}
return (grub_strstr(args[0], args[1])) ? 0 : 1;
}
static grub_err_t ventoy_cmd_incr(grub_extcmd_context_t ctxt, int argc, char **args)
{
long value_long = 0;
@ -1389,7 +1401,7 @@ static grub_err_t ventoy_cmd_chosen_img_path(grub_extcmd_context_t ctxt, int arg
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
static 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_disk_t disk;
char *device_name;
@ -1484,7 +1496,7 @@ int ventoy_has_efi_eltorito(grub_file_t file, grub_uint32_t sector)
return 1;
}
if (buf[i] == 0x91 && buf[i + 1] == 0x00 && x86count == 1)
if ((buf[i] == 0x90 || buf[i] == 0x91) && buf[i + 1] == 0x00 && x86count == 1)
{
debug("0x9100 assume %s efi eltorito offset %d 0x%02x\n", file->name, i, buf[i]);
return 1;
@ -2231,6 +2243,50 @@ static grub_err_t ventoy_cmd_find_bootable_hdd(grub_extcmd_context_t ctxt, int a
return 0;
}
static grub_err_t ventoy_cmd_parse_volume(grub_extcmd_context_t ctxt, int argc, char **args)
{
int len;
grub_file_t file;
char buf[64];
ventoy_iso9660_vd pvd;
(void)ctxt;
(void)argc;
if (argc != 3)
{
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s sysid volid \n", cmd_raw_name);
}
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
if (!file)
{
debug("failed to open file %s\n", args[0]);
return 0;
}
grub_file_seek(file, 16 * 2048);
len = (int)grub_file_read(file, &pvd, sizeof(pvd));
if (len != sizeof(pvd))
{
debug("failed to read pvd %d\n", len);
goto end;
}
grub_memset(buf, 0, sizeof(buf));
grub_memcpy(buf, pvd.sys, sizeof(pvd.sys));
ventoy_set_env(args[1], buf);
grub_memset(buf, 0, sizeof(buf));
grub_memcpy(buf, pvd.vol, sizeof(pvd.vol));
ventoy_set_env(args[2], buf);
end:
grub_file_close(file);
return 0;
}
grub_uint64_t ventoy_grub_get_file_size(const char *fmt, ...)
{
grub_uint64_t size = 0;
@ -2353,6 +2409,7 @@ static int ventoy_env_init(void)
static cmd_para ventoy_cmds[] =
{
{ "vt_incr", ventoy_cmd_incr, 0, NULL, "{Var} {INT}", "Increase integer variable", NULL },
{ "vt_strstr", ventoy_cmd_strstr, 0, NULL, "", "", NULL },
{ "vt_debug", ventoy_cmd_debug, 0, NULL, "{on|off}", "turn debug on/off", NULL },
{ "vtdebug", ventoy_cmd_debug, 0, NULL, "{on|off}", "turn debug on/off", NULL },
{ "vtbreak", ventoy_cmd_break, 0, NULL, "{level}", "set debug break", NULL },
@ -2410,6 +2467,13 @@ static cmd_para ventoy_cmds[] =
{ "vt_load_plugin", ventoy_cmd_load_plugin, 0, NULL, "", "", NULL },
{ "vt_check_plugin_json", ventoy_cmd_plugin_check_json, 0, NULL, "", "", NULL },
{ "vt_parse_iso_volume", ventoy_cmd_parse_volume, 0, NULL, "", "", NULL },
{ "vt_unix_parse_freebsd_ver", ventoy_cmd_unix_freebsd_ver, 0, NULL, "", "", NULL },
{ "vt_unix_reset", ventoy_cmd_unix_reset, 0, NULL, "", "", NULL },
{ "vt_unix_replace_conf", ventoy_cmd_unix_replace_conf, 0, NULL, "", "", NULL },
{ "vt_unix_replace_ko", ventoy_cmd_unix_replace_ko, 0, NULL, "", "", NULL },
{ "vt_unix_chain_data", ventoy_cmd_unix_chain_data, 0, NULL, "", "", NULL },
};

@ -123,6 +123,16 @@ typedef struct ventoy_udf_override
grub_uint32_t position;
}ventoy_udf_override;
typedef struct ventoy_iso9660_vd
{
grub_uint8_t type;
grub_uint8_t id[5];
grub_uint8_t ver;
grub_uint8_t res;
char sys[32];
char vol[32];
}ventoy_iso9660_vd;
#pragma pack()
#define img_type_iso 0
@ -667,6 +677,24 @@ extern int g_ventoy_iso_uefi_drv;
extern int g_ventoy_case_insensitive;
extern grub_uint8_t g_ventoy_chain_type;
#define ventoy_unix_fill_virt(new_data, new_len) \
{ \
data_secs = (new_len + 2047) / 2048; \
cur->mem_sector_start = sector; \
cur->mem_sector_end = cur->mem_sector_start + data_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, new_data, new_len); \
cur++; \
sector += data_secs; \
offset += new_len; \
chain->virt_img_size_in_bytes += data_secs * 2048; \
}
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);
@ -687,6 +715,12 @@ grub_err_t ventoy_cmd_linux_get_main_initrd_index(grub_extcmd_context_t ctxt, in
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_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);
int ventoy_get_disk_guid(const char *filename, grub_uint8_t *guid);
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_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);
#endif /* __VENTOY_DEF_H__ */

@ -38,8 +38,7 @@
GRUB_MOD_LICENSE ("GPLv3+");
static char * ventoy_get_line(char *start)
char * ventoy_get_line(char *start)
{
if (start == NULL)
{

Binary file not shown.

@ -39,12 +39,17 @@ if ! [ -f ./tool/ash ]; then
if ! [ -f ./tool/ash ]; then
echo 'Failed to decompress tools ...'
cd $OLDDIR
if [ -n "$OLDDIR" ]; then
cd $OLDDIR
fi
exit 1
fi
fi
./tool/ash ./tool/VentoyWorker.sh $*
cd $OLDDIR
if [ -n "$OLDDIR" ]; then
cd $OLDDIR
fi

@ -89,6 +89,14 @@ function get_os_type {
fi
done
if [ "$vtoy_os" = "Linux" ]; then
if vt_strstr "$vt_system_id" "FreeBSD"; then
set vtoy_os=Unix
elif [ -e (loop)/bin/freebsd-version ]; then
set vtoy_os=Unix
fi
fi
if [ -n "${vtdebug_flag}" ]; then
echo ISO is $vtoy_os
fi
@ -211,6 +219,70 @@ function distro_specify_initrd_file_phase2 {
fi
}
function ventoy_freebsd_proc {
if regexp "^12_[0-9]" $vt_volume_id; then
set vt_freebsd_ver=12.x
elif regexp "^11_[0-9]" $vt_volume_id; then
set vt_freebsd_ver=11.x
elif regexp "^10_[0-9]" $vt_volume_id; then
set vt_freebsd_ver=10.x
elif [ -e (loop)/bin/freebsd-version ]; then
vt_unix_parse_freebsd_ver (loop)/bin/freebsd-version vt_userland_ver
if regexp "\"12\.[0-9]-" $vt_userland_ver; then
set vt_freebsd_ver=12.x
elif regexp "\"11\.[0-9]-" $vt_userland_ver; then
set vt_freebsd_ver=11.x
elif regexp "\"10\.[0-9]-" $vt_userland_ver; then
set vt_freebsd_ver=10.x
fi
else
set vt_freebsd_ver=12.x
fi
if file --is-i386-kfreebsd (loop)/boot/kernel/kernel; then
set vt_freebsd_bit=32
else
set vt_freebsd_bit=64
fi
if [ -n "${vtdebug_flag}" ]; then
echo "This is FreeBSD $vt_freebsd_ver ${vt_freebsd_bit}bit"
fi
for file in "geom_nop" "ipmi"; do
if [ -e (loop)/boot/kernel/${file}.ko ]; then
set vt_unix_ko=$file
break
fi
done
vt_unix_replace_ko $vt_unix_ko (vtunix)/ventoy_unix/FreeBSD/geom_ventoy_ko/$vt_freebsd_ver/$vt_freebsd_bit/geom_ventoy.ko.xz
vt_unix_replace_conf FreeBSD ${1}${chosen_path}
}
function ventoy_unix_comm_proc {
vt_unix_reset
if [ "$ventoy_compatible" = "NO" ]; then
loopback vtunix $vtoy_efi_part/ventoy/ventoy_unix.cpio
set vt_unix_type=unknown
if vt_strstr "$vt_system_id" "FreeBSD"; then
ventoy_freebsd_proc $1 ${chosen_path}
elif [ -e (loop)/bin/freebsd-version ]; then
ventoy_freebsd_proc $1 ${chosen_path}
else
if [ -n "${vtdebug_flag}" ]; then
echo "Unknown unix type"
fi
fi
fi
vt_unix_chain_data ${1}${chosen_path}
ventoy_debug_pause
}
function uefi_windows_menu_func {
vt_windows_reset
@ -330,6 +402,18 @@ function uefi_linux_menu_func {
fi
}
function uefi_unix_menu_func {
ventoy_unix_comm_proc $1 ${chosen_path}
if [ -n "$vtoy_chain_mem_addr" ]; then
ventoy_cli_console
chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
boot
else
echo "chain empty failed"
ventoy_pause
fi
}
function uefi_iso_menu_func {
@ -358,6 +442,7 @@ function uefi_iso_menu_func {
fi
loopback loop ${1}${chosen_path}
vt_parse_iso_volume ${1}${chosen_path} vt_system_id vt_volume_id
get_os_type (loop)
if [ -d (loop)/EFI ]; then
@ -382,6 +467,8 @@ function uefi_iso_menu_func {
if [ "$vtoy_os" = "Windows" ]; then
vt_check_compatible_pe (loop)
uefi_windows_menu_func $1 ${chosen_path}
elif [ "$vtoy_os" = "Unix" ]; then
uefi_unix_menu_func $1 ${chosen_path}
else
uefi_linux_menu_func $1 ${chosen_path}
fi
@ -501,6 +588,20 @@ function legacy_linux_menu_func {
fi
}
function legacy_unix_menu_func {
ventoy_unix_comm_proc $1 ${chosen_path}
if [ -n "$vtoy_chain_mem_addr" ]; then
linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
boot
else
echo "chain empty failed"
ventoy_pause
fi
}
function legacy_iso_menu_func {
if [ -d (loop)/ ]; then
@ -519,6 +620,7 @@ function legacy_iso_menu_func {
fi
loopback loop ${1}${chosen_path}
vt_parse_iso_volume ${1}${chosen_path} vt_system_id vt_volume_id
get_os_type (loop)
if [ -n "$vtcompat" ]; then
@ -535,6 +637,8 @@ function legacy_iso_menu_func {
if [ "$vtoy_os" = "Windows" ]; then
vt_check_compatible_pe (loop)
legacy_windows_menu_func $1 ${chosen_path}
elif [ "$vtoy_os" = "Unix" ]; then
legacy_unix_menu_func $1 ${chosen_path}
else
legacy_linux_menu_func $1 ${chosen_path}
fi
@ -550,6 +654,9 @@ function legacy_iso_memdisk {
}
function iso_common_menuentry {
unset vt_system_id
unset vt_volume_id
if [ "$grub_platform" = "pc" ]; then
if vt_check_mode 0; then
legacy_iso_memdisk $vtoy_iso_part

@ -129,13 +129,13 @@ is_disk_contains_ventoy() {
PART1_TYPE=$(dd if=$DISK bs=1 count=1 skip=450 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
PART2_TYPE=$(dd if=$DISK bs=1 count=1 skip=466 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
if [ "$PART1_TYPE" != "EE" ]; then
if [ "$PART2_TYPE" != "EF" ]; then
vtdebug "part2 type is $PART2_TYPE not EF"
ventoy_false
return
fi
fi
# if [ "$PART1_TYPE" != "EE" ]; then
# if [ "$PART2_TYPE" != "EF" ]; then
# vtdebug "part2 type is $PART2_TYPE not EF"
# ventoy_false
# return
# fi
# fi
# PART1_TYPE=$(dd if=$DISK bs=1 count=1 skip=450 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
# if [ "$PART1_TYPE" != "07" ]; then

Binary file not shown.

Binary file not shown.

@ -0,0 +1,13 @@
#!/bin/bash
VENTOY_PATH=$PWD/../
rm -f ventoy_unix.cpio
find ./ventoy_unix | cpio -o -H newc>ventoy_unix.cpio
echo '======== SUCCESS ============='
rm -f $VENTOY_PATH/INSTALL/ventoy/ventoy_unix.cpio
cp -a ventoy_unix.cpio $VENTOY_PATH/INSTALL/ventoy/

Binary file not shown.

@ -0,0 +1,123 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2020 longpanda <admin@ventoy.net>
* Copyright (c) 2004-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
/*
* This file is just copied from g_concat.h and replace strings
* "concat" ==> "ventoy"
* "CONCAT" ==> "VENTOY"
*/
#ifndef _G_VENTOY_H_
#define _G_VENTOY_H_
#include <sys/endian.h>
#define G_VENTOY_CLASS_NAME "VENTOY"
#define G_VENTOY_MAGIC "GEOM::VENTOY"
/*
* Version history:
* 1 - Initial version number.
* 2 - Added 'stop' command to gconcat(8).
* 3 - Added md_provider field to metadata and '-h' option to gconcat(8).
* 4 - Added md_provsize field to metadata.
*/
#define G_VENTOY_VERSION 4
#ifdef _KERNEL
#define G_VENTOY_TYPE_MANUAL 0
#define G_VENTOY_TYPE_AUTOMATIC 1
#define G_DEBUG(...) if (bootverbose) printf(__VA_ARGS__)
#define G_VENTOY_DEBUG(lvl, ...) if (g_ventoy_debug) printf(__VA_ARGS__)
#define G_VENTOY_LOGREQ(bp, ...) if (g_ventoy_debug) printf(__VA_ARGS__)
struct g_ventoy_disk {
struct g_consumer *d_consumer;
struct g_ventoy_softc *d_softc;
off_t d_start;
off_t d_end;
off_t d_map_start;
off_t d_map_end;
int d_candelete;
int d_removed;
};
struct g_ventoy_softc {
u_int sc_type; /* provider type */
struct g_geom *sc_geom;
struct g_provider *sc_provider;
uint32_t sc_id; /* concat unique ID */
struct g_ventoy_disk *sc_disks;
uint16_t sc_ndisks;
struct mtx sc_lock;
};
#define sc_name sc_geom->name
#endif /* _KERNEL */
struct g_ventoy_metadata {
char md_magic[16]; /* Magic value. */
uint32_t md_version; /* Version number. */
char md_name[16]; /* Concat name. */
uint32_t md_id; /* Unique ID. */
uint16_t md_no; /* Disk number. */
uint16_t md_all; /* Number of all disks. */
char md_provider[16]; /* Hardcoded provider. */
uint64_t md_provsize; /* Provider's size. */
};
static __inline void
ventoy_metadata_encode(const struct g_ventoy_metadata *md, u_char *data)
{
bcopy(md->md_magic, data, sizeof(md->md_magic));
le32enc(data + 16, md->md_version);
bcopy(md->md_name, data + 20, sizeof(md->md_name));
le32enc(data + 36, md->md_id);
le16enc(data + 40, md->md_no);
le16enc(data + 42, md->md_all);
bcopy(md->md_provider, data + 44, sizeof(md->md_provider));
le64enc(data + 60, md->md_provsize);
}
static __inline void
ventoy_metadata_decode(const u_char *data, struct g_ventoy_metadata *md)
{
bcopy(data, md->md_magic, sizeof(md->md_magic));
md->md_version = le32dec(data + 16);
bcopy(data + 20, md->md_name, sizeof(md->md_name));
md->md_id = le32dec(data + 36);
md->md_no = le16dec(data + 40);
md->md_all = le16dec(data + 42);
bcopy(data + 44, md->md_provider, sizeof(md->md_provider));
md->md_provsize = le64dec(data + 60);
}
#endif /* _G_VENTOY_H_ */

@ -0,0 +1,8 @@
# $FreeBSD$
.PATH: ${SRCTOP}/sys/geom/ventoy
KMOD= geom_ventoy
SRCS= g_ventoy.c
.include <bsd.kmod.mk>

@ -0,0 +1,123 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2020 longpanda <admin@ventoy.net>
* Copyright (c) 2004-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
/*
* This file is just copied from g_concat.h and replace strings
* "concat" ==> "ventoy"
* "CONCAT" ==> "VENTOY"
*/
#ifndef _G_VENTOY_H_
#define _G_VENTOY_H_
#include <sys/endian.h>
#define G_VENTOY_CLASS_NAME "VENTOY"
#define G_VENTOY_MAGIC "GEOM::VENTOY"
/*
* Version history:
* 1 - Initial version number.
* 2 - Added 'stop' command to gconcat(8).
* 3 - Added md_provider field to metadata and '-h' option to gconcat(8).
* 4 - Added md_provsize field to metadata.
*/
#define G_VENTOY_VERSION 4
#ifdef _KERNEL
#define G_VENTOY_TYPE_MANUAL 0
#define G_VENTOY_TYPE_AUTOMATIC 1
#define G_DEBUG(...) if (bootverbose) printf(__VA_ARGS__)
#define G_VENTOY_DEBUG(lvl, ...) if (g_ventoy_debug) printf(__VA_ARGS__)
#define G_VENTOY_LOGREQ(bp, ...) if (g_ventoy_debug) printf(__VA_ARGS__)
struct g_ventoy_disk {
struct g_consumer *d_consumer;
struct g_ventoy_softc *d_softc;
off_t d_start;
off_t d_end;
off_t d_map_start;
off_t d_map_end;
int d_candelete;
int d_removed;
};
struct g_ventoy_softc {
u_int sc_type; /* provider type */
struct g_geom *sc_geom;
struct g_provider *sc_provider;
uint32_t sc_id; /* concat unique ID */
struct g_ventoy_disk *sc_disks;
uint16_t sc_ndisks;
struct mtx sc_lock;
};
#define sc_name sc_geom->name
#endif /* _KERNEL */
struct g_ventoy_metadata {
char md_magic[16]; /* Magic value. */
uint32_t md_version; /* Version number. */
char md_name[16]; /* Concat name. */
uint32_t md_id; /* Unique ID. */
uint16_t md_no; /* Disk number. */
uint16_t md_all; /* Number of all disks. */
char md_provider[16]; /* Hardcoded provider. */
uint64_t md_provsize; /* Provider's size. */
};
static __inline void
ventoy_metadata_encode(const struct g_ventoy_metadata *md, u_char *data)
{
bcopy(md->md_magic, data, sizeof(md->md_magic));
le32enc(data + 16, md->md_version);
bcopy(md->md_name, data + 20, sizeof(md->md_name));
le32enc(data + 36, md->md_id);
le16enc(data + 40, md->md_no);
le16enc(data + 42, md->md_all);
bcopy(md->md_provider, data + 44, sizeof(md->md_provider));
le64enc(data + 60, md->md_provsize);
}
static __inline void
ventoy_metadata_decode(const u_char *data, struct g_ventoy_metadata *md)
{
bcopy(data, md->md_magic, sizeof(md->md_magic));
md->md_version = le32dec(data + 16);
bcopy(data + 20, md->md_name, sizeof(md->md_name));
md->md_id = le32dec(data + 36);
md->md_no = le16dec(data + 40);
md->md_all = le16dec(data + 42);
bcopy(data + 44, md->md_provider, sizeof(md->md_provider));
md->md_provsize = le64dec(data + 60);
}
#endif /* _G_VENTOY_H_ */

@ -0,0 +1,8 @@
# $FreeBSD$
.PATH: ${SRCTOP}/sys/geom/ventoy
KMOD= geom_ventoy
SRCS= g_ventoy.c
.include <bsd.kmod.mk>

@ -167,8 +167,7 @@ static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes, MBR_HEAD *pMBR, UIN
PartStartSector = MBR.PartTbl[0].StartSectorId + MBR.PartTbl[0].SectorCount;
PartSectorCount = VENTOY_EFI_PART_SIZE / 512;
if (MBR.PartTbl[1].FsFlag != 0xEF ||
MBR.PartTbl[1].StartSectorId != PartStartSector ||
if (MBR.PartTbl[1].StartSectorId != PartStartSector ||
MBR.PartTbl[1].SectorCount != PartSectorCount)
{
Log("Part2 not match [0x%x 0x%x] [%u %u] [%u %u]",

Loading…
Cancel
Save