1.0.18 release

pull/283/head v1.0.18
longpanda 4 years ago
parent 4cb9134e5c
commit 433d854aab

@ -2243,6 +2243,47 @@ static grub_err_t ventoy_cmd_find_bootable_hdd(grub_extcmd_context_t ctxt, int a
return 0;
}
static grub_err_t ventoy_cmd_read_1st_line(grub_extcmd_context_t ctxt, int argc, char **args)
{
int len = 1024;
grub_file_t file;
char *buf = NULL;
(void)ctxt;
(void)argc;
if (argc != 2)
{
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s file var \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;
}
buf = grub_malloc(len);
if (!buf)
{
goto end;
}
buf[len - 1] = 0;
grub_file_read(file, buf, len - 1);
ventoy_get_line(buf);
ventoy_set_env(args[1], buf);
end:
grub_check_free(buf);
grub_file_close(file);
return 0;
}
static grub_err_t ventoy_cmd_parse_volume(grub_extcmd_context_t ctxt, int argc, char **args)
{
int len;
@ -2287,6 +2328,44 @@ end:
return 0;
}
static grub_err_t ventoy_cmd_parse_create_date(grub_extcmd_context_t ctxt, int argc, char **args)
{
int len;
grub_file_t file;
char buf[64];
(void)ctxt;
(void)argc;
if (argc != 2)
{
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s var \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_memset(buf, 0, sizeof(buf));
grub_file_seek(file, 16 * 2048 + 813);
len = (int)grub_file_read(file, buf, 17);
if (len != 17)
{
debug("failed to read create date %d\n", len);
goto end;
}
ventoy_set_env(args[1], buf);
end:
grub_file_close(file);
return 0;
}
grub_uint64_t ventoy_grub_get_file_size(const char *fmt, ...)
{
grub_uint64_t size = 0;
@ -2468,7 +2547,10 @@ 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_1st_line", ventoy_cmd_read_1st_line, 0, NULL, "", "", NULL },
{ "vt_parse_iso_volume", ventoy_cmd_parse_volume, 0, NULL, "", "", NULL },
{ "vt_parse_iso_create_date", ventoy_cmd_parse_create_date, 0, NULL, "", "", NULL },
{ "vt_parse_freenas_ver", ventoy_cmd_parse_freenas_ver, 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 },

@ -721,6 +721,7 @@ grub_err_t ventoy_cmd_unix_reset(grub_extcmd_context_t ctxt, int argc, char **ar
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);
grub_err_t ventoy_cmd_parse_freenas_ver(grub_extcmd_context_t ctxt, int argc, char **args);
#endif /* __VENTOY_DEF_H__ */

@ -17,10 +17,8 @@ all_modules_legacy="date drivemap blocklist vga_text ntldr search at_keyboard us
net_modules_uefi="efinet net tftp http"
all_modules_uefi="blocklist ventoy test 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_extra_modules="elf macho offsetio regexp file"
if [ "$1" = "uefi" ]; then
all_modules="$net_modules_uefi $all_modules_uefi $all_extra_modules "
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'
else
all_modules="$net_modules_legacy $all_modules_legacy "

@ -20,5 +20,11 @@
$SED "s#.*livefs_root=.*find_livefs.*#$BUSYBOX_PATH/mount -t iso9660 /dev/mapper/ventoy \$mountpoint; livefs_root=\$mountpoint#" -i /usr/lib/live/boot/9990-main.sh
$SED "s#.*livefs_root=.*find_livefs.*#$BUSYBOX_PATH/mount -t iso9660 /dev/mapper/ventoy \$mountpoint; livefs_root=\$mountpoint#" -i /usr/bin/boot/9990-main.sh
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/debian/udev_disk_hook.sh %k"
if [ -e /init ] && $GREP -q '^mountroot$' /init; then
echo "Here before mountroot ..." >> $VTLOG
$SED "/^mountroot$/i\\$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/disk_mount_hook.sh" -i /init
else
echo "Use default hook ..." >> $VTLOG
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/debian/udev_disk_hook.sh %k"
fi

Binary file not shown.

@ -92,8 +92,20 @@ function get_os_type {
if [ "$vtoy_os" = "Linux" ]; then
if vt_strstr "$vt_system_id" "FreeBSD"; then
set vtoy_os=Unix
set vt_unix_type=FreeBSD
elif [ -e (loop)/bin/freebsd-version ]; then
set vtoy_os=Unix
set vt_unix_type=FreeBSD
elif [ -e (loop)/boot/kernel/kernel ]; then
if file --is-x86-kfreebsd (loop)/boot/kernel/kernel; then
set vtoy_os=Unix
set vt_unix_type=FreeBSD
elif file --is-x86-knetbsd (loop)/boot/kernel/kernel; then
set vtoy_os=Unix
set vt_unix_type=NetBSD
fi
fi
fi
@ -219,44 +231,101 @@ function distro_specify_initrd_file_phase2 {
fi
}
function ventoy_get_ghostbsd_ver {
# vt_parse_iso_create_date $1/${chosen_path} vt_create_date
# if regexp "^202005" "$vt_create_date"; then
# set vt_freebsd_ver=12.x
# fi
set vt_freebsd_ver=12.x
}
function ventoy_get_freenas_ver {
set vt_freebsd_ver=11.x
if [ -e (loop)/FreeNAS-MANIFEST ]; then
vt_parse_freenas_ver (loop)/FreeNAS-MANIFEST vt_freenas_ver
if regexp "^13\.[0-9]" "$vt_freenas_ver"; then
set vt_freebsd_ver=13.x
elif regexp "^12\.[0-9]" "$vt_freenas_ver"; then
set vt_freebsd_ver=12.x
elif regexp "^11\.[0-9]" "$vt_freenas_ver"; then
set vt_freebsd_ver=11.x
fi
fi
}
function ventoy_freebsd_proc {
if regexp "^12_[0-9]" $vt_volume_id; then
if vt_strstr "$vt_volume_id" "GHOSTBSD"; then
ventoy_get_ghostbsd_ver $1 ${chosen_path}
elif vt_strstr "$vt_volume_id" "FREENAS"; then
ventoy_get_freenas_ver $1 ${chosen_path}
elif regexp "^13_[0-9]" "$vt_volume_id"; then
set vt_freebsd_ver=13.x
elif regexp "^12_[0-9]" "$vt_volume_id"; then
set vt_freebsd_ver=12.x
elif regexp "^11_[0-9]" $vt_volume_id; then
elif regexp "^11_[0-9]" "$vt_volume_id"; then
set vt_freebsd_ver=11.x
elif regexp "^10_[0-9]" $vt_volume_id; then
elif regexp "^10_[0-9]" "$vt_volume_id"; then
set vt_freebsd_ver=10.x
elif regexp "^9_[0-9]" "$vt_volume_id"; then
set vt_freebsd_ver=9.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
if regexp "\"13\.[0-9]-" "$vt_userland_ver"; then
set vt_freebsd_ver=13.x
elif regexp "\"12\.[0-9]-" "$vt_userland_ver"; then
set vt_freebsd_ver=12.x
elif regexp "\"11\.[0-9]-" $vt_userland_ver; then
elif regexp "\"11\.[0-9]-" "$vt_userland_ver"; then
set vt_freebsd_ver=11.x
elif regexp "\"10\.[0-9]-" $vt_userland_ver; then
elif regexp "\"10\.[0-9]-" "$vt_userland_ver"; then
set vt_freebsd_ver=10.x
elif regexp "\"9\.[0-9]-" "$vt_userland_ver"; then
set vt_freebsd_ver=9.x
fi
elif [ -e (loop)/README.TXT ]; then
vt_1st_line (loop)/README.TXT vt_freebsd_line1
if regexp "FreeBSD 13\.[0-9]-" "$vt_freebsd_line1"; then
set vt_freebsd_ver=13.x
elif regexp "FreeBSD 12\.[0-9]-" "$vt_freebsd_line1"; then
set vt_freebsd_ver=12.x
elif regexp "FreeBSD 11\.[0-9]-" "$vt_freebsd_line1"; then
set vt_freebsd_ver=11.x
elif regexp "FreeBSD 10\.[0-9]-" "$vt_freebsd_line1"; then
set vt_freebsd_ver=10.x
elif regexp "FreeBSD 9\.[0-9]-" "$vt_freebsd_line1"; then
set vt_freebsd_ver=9.x
fi
elif vt_strstr "${chosen_path}" "MidnightBSD"; then
set vt_freebsd_ver=9.x
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
set vt_freebsd_bit=64
for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
if [ -e (loop)/$file ]; then
if file --is-i386-kfreebsd (loop)/$file; then
set vt_freebsd_bit=32
fi
break
fi
done
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
unset vt_unix_mod_path
for file in "/COPYRIGHT" "/FreeNAS-MANIFEST" "/version"; do
if [ -e (loop)${file} ]; then
set vt_unix_mod_path=${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_ko $vt_unix_mod_path (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}
}
@ -266,11 +335,13 @@ function ventoy_unix_comm_proc {
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}
if [ "$vt_unix_type" = "FreeBSD" ]; then
ventoy_freebsd_proc $1 ${chosen_path}
elif [ "$vt_unix_type" = "NetBSD" ]; then
echo "NetBSD not supported"
else
if [ -n "${vtdebug_flag}" ]; then
echo "Unknown unix type"
@ -731,7 +802,7 @@ function efi_unsupport_menuentry {
#############################################################
#############################################################
set VENTOY_VERSION="1.0.17"
set VENTOY_VERSION="1.0.18"
# Default menu display mode, you can change it as you want.
# 0: List mode

Binary file not shown.

@ -118,7 +118,7 @@ ehci: cs5536 usb boot
crypto:
part_bsd: part_msdos
cs5536:
ventoy: ext2 fshelp font crypto exfat udf extcmd normal gcry_sha1 iso9660
ventoy: ext2 fshelp crypto font exfat udf extcmd normal gcry_sha1 iso9660
gcry_sha512: crypto
password: crypto normal
fshelp:

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,117 @@
/*-
* 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$
*/
#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>

@ -27,14 +27,6 @@
* SUCH DAMAGE.
*/
/*
* This file is just copied from g_concat.h and replace strings
* "concat" ==> "ventoy"
* "CONCAT" ==> "VENTOY"
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

@ -29,12 +29,6 @@
* $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_

@ -27,14 +27,6 @@
* SUCH DAMAGE.
*/
/*
* This file is just copied from g_concat.h and replace strings
* "concat" ==> "ventoy"
* "CONCAT" ==> "VENTOY"
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

@ -29,12 +29,6 @@
* $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_

@ -0,0 +1,117 @@
/*-
* 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$
*/
#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,117 @@
/*-
* 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$
*/
#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>
Loading…
Cancel
Save