Skip to content

Commit

Permalink
1.0.77 release
Browse files Browse the repository at this point in the history
  • Loading branch information
ventoy committed Jun 19, 2022
1 parent 8db8e07 commit b976923
Show file tree
Hide file tree
Showing 23 changed files with 1,455 additions and 208 deletions.
18 changes: 18 additions & 0 deletions GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ char *ventoy_str_last(char *str, char ch)
return last;
}

int ventoy_str_all_digit(const char *str)
{
if (NULL == str || 0 == *str)
{
return 0;
}

while (*str)
{
if (*str < '0' || *str > '9')
{
return 0;
}
}

return 1;
}

int ventoy_strcmp(const char *pattern, const char *str)
{
while (*pattern && *str)
Expand Down
147 changes: 79 additions & 68 deletions GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ static int ventoy_load_efiboot_template(char **buf, int *datalen, int *direntoff
return 0;
}

static int ventoy_set_check_result(int ret)
static int ventoy_set_check_result(int ret, const char *msg)
{
char buf[32];

Expand All @@ -497,7 +497,8 @@ static int ventoy_set_check_result(int ret)
grub_printf(VTOY_WARNING"\n");
grub_printf(VTOY_WARNING"\n\n\n");

grub_printf("This is NOT a standard Ventoy device and is NOT supported (%d).\n\n", ret);
grub_printf("This is NOT a standard Ventoy device and is NOT supported (%d).\n", ret);
grub_printf("Error message: <%s>\n\n", msg);
grub_printf("You should follow the instructions in https://www.ventoy.net to use Ventoy.\n");

grub_printf("\n\nWill exit after 10 seconds ...... ");
Expand All @@ -523,19 +524,25 @@ static int ventoy_check_official_device(grub_device_t dev)

if (dev->disk == NULL || dev->disk->partition == NULL)
{
return ventoy_set_check_result(1 | 0x1000);
return ventoy_set_check_result(1 | 0x1000, "Internal Error");
}

if (0 == ventoy_check_file_exist("(%s,2)/ventoy/ventoy.cpio", dev->disk->name) ||
0 == ventoy_check_file_exist("(%s,2)/grub/localboot.cfg", dev->disk->name) ||
0 == ventoy_check_file_exist("(%s,2)/tool/mount.exfat-fuse_aarch64", dev->disk->name))
{
#ifndef GRUB_MACHINE_EFI
if (0 == ventoy_check_file_exist("(ventoydisk)/ventoy/ventoy.cpio", dev->disk->name) ||
0 == ventoy_check_file_exist("(ventoydisk)/grub/localboot.cfg", dev->disk->name) ||
0 == ventoy_check_file_exist("(ventoydisk)/tool/mount.exfat-fuse_aarch64", dev->disk->name))
if (0 == ventoy_check_file_exist("(ventoydisk)/ventoy/ventoy.cpio", dev->disk->name))
{
return ventoy_set_check_result(2 | 0x1000);
return ventoy_set_check_result(2 | 0x1000, "File ventoy/ventoy.cpio missing in VTOYEFI partition");
}
else if (0 == ventoy_check_file_exist("(ventoydisk)/grub/localboot.cfg", dev->disk->name))
{
return ventoy_set_check_result(2 | 0x1000, "File grub/localboot.cfg missing in VTOYEFI partition");
}
else if (0 == ventoy_check_file_exist("(ventoydisk)/tool/mount.exfat-fuse_aarch64", dev->disk->name))
{
return ventoy_set_check_result(2 | 0x1000, "File tool/mount.exfat-fuse_aarch64 missing in VTOYEFI partition");
}
else
{
Expand All @@ -555,19 +562,19 @@ static int ventoy_check_official_device(grub_device_t dev)
}
if (!file)
{
return ventoy_set_check_result(3 | 0x1000);
return ventoy_set_check_result(3 | 0x1000, "File ventoy/ventoy.cpio open failed in VTOYEFI partition");
}

if (NULL == grub_strstr(file->fs->name, "fat"))
{
grub_file_close(file);
return ventoy_set_check_result(4 | 0x1000);
return ventoy_set_check_result(4 | 0x1000, "VTOYEFI partition is not FAT filesystem");
}

partition = dev->disk->partition;
if (partition->number != 0 || partition->start != 2048)
{
return ventoy_set_check_result(5);
return ventoy_set_check_result(5, "Ventoy partition is not start at 1MB");
}

if (workaround)
Expand All @@ -579,7 +586,7 @@ static int ventoy_check_official_device(grub_device_t dev)
(PartTbl[1].LastLBA + 1 - PartTbl[1].StartLBA) != 65536)
{
grub_file_close(file);
return ventoy_set_check_result(6);
return ventoy_set_check_result(6, "Disk partition layout check failed.");
}
}
else
Expand All @@ -589,7 +596,7 @@ static int ventoy_check_official_device(grub_device_t dev)
PartTbl[1].SectorCount != 65536)
{
grub_file_close(file);
return ventoy_set_check_result(6);
return ventoy_set_check_result(6, "Disk partition layout check failed.");
}
}
}
Expand All @@ -600,7 +607,7 @@ static int ventoy_check_official_device(grub_device_t dev)
if ((partition->number != 1) || (partition->len != 65536) || (offset != partition->start))
{
grub_file_close(file);
return ventoy_set_check_result(7);
return ventoy_set_check_result(7, "Disk partition layout check failed.");
}
}

Expand All @@ -612,21 +619,21 @@ static int ventoy_check_official_device(grub_device_t dev)
dev2 = grub_device_open(devname);
if (!dev2)
{
return ventoy_set_check_result(8);
return ventoy_set_check_result(8, "Disk open failed");
}

fs = grub_fs_probe(dev2);
if (!fs)
{
grub_device_close(dev2);
return ventoy_set_check_result(9);
return ventoy_set_check_result(9, "FS probe failed");
}

fs->fs_label(dev2, &label);
if ((!label) || grub_strncmp("VTOYEFI", label, 7))
{
grub_device_close(dev2);
return ventoy_set_check_result(10);
return ventoy_set_check_result(10, "Partition name is not VTOYEFI");
}

grub_device_close(dev2);
Expand All @@ -636,7 +643,7 @@ static int ventoy_check_official_device(grub_device_t dev)
disk = grub_disk_open(dev->disk->name);
if (!disk)
{
return ventoy_set_check_result(11);
return ventoy_set_check_result(11, "Disk open failed");
}

grub_memset(mbr, 0, 512);
Expand All @@ -645,10 +652,10 @@ static int ventoy_check_official_device(grub_device_t dev)

if (grub_memcmp(g_check_mbr_data, mbr, 0x30) || grub_memcmp(g_check_mbr_data + 0x30, mbr + 0x190, 16))
{
return ventoy_set_check_result(12);
return ventoy_set_check_result(12, "MBR check failed");
}

return ventoy_set_check_result(0);
return ventoy_set_check_result(0, NULL);
}

static int ventoy_check_ignore_flag(const char *filename, const struct grub_dirhook_info *info, void *data)
Expand Down Expand Up @@ -3367,58 +3374,19 @@ static grub_err_t ventoy_select_conf_replace(grub_extcmd_context_t ctxt, int arg
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}

static int ventoy_is_builtin_var(const char *var)
{
int i;
const char *c;
const char *builtin_vars_full[] =
{
"VT_DISK_1ST_NONVTOY",
"VT_DISK_1ST_NONUSB",
NULL
};

for (i = 0; builtin_vars_full[i]; i++)
{
if (grub_strcmp(builtin_vars_full[i], var) == 0)
{
return 1;
}
}

if (grub_strncmp(var, "VT_DISK_CLOSEST_", 16) == 0)
{
c = var + 16;
while (*c)
{
if (*c < '0' || *c > '9')
{
break;
}
c++;
}

if (*c == 0 && c != (var + 16))
{
return 1;
}
}

return 0;
}

static int ventoy_var_expand(int *flag, const char *var, char *expand, int len)
static int ventoy_var_expand(int *record, int *flag, const char *var, char *expand, int len)
{
int i = 0;
int n = 0;
char c;
const char *ch = var;

*record = 0;
expand[0] = 0;

while (*ch)
{
if (*ch == '_' || (*ch >= '0' && *ch <= '9') || (*ch >= 'A' && *ch <= 'Z'))
if (*ch == '_' || (*ch >= '0' && *ch <= '9') || (*ch >= 'A' && *ch <= 'Z') || (*ch >= 'a' && *ch <= 'z'))
{
ch++;
n++;
Expand All @@ -3436,16 +3404,16 @@ static int ventoy_var_expand(int *flag, const char *var, char *expand, int len)
goto end;
}

if (ventoy_is_builtin_var(var))
if (grub_strncmp(var, "VT_", 3) == 0) /* built-in variables */
{

}
else
{
if (*flag == 0)
{
*flag = 1;
grub_printf("\n=================== Parameter Expansion ===================\n\n");
grub_printf("\n=================== Variables Expansion ===================\n\n");
}

grub_printf("<%s>: ", var);
Expand All @@ -3460,6 +3428,7 @@ static int ventoy_var_expand(int *flag, const char *var, char *expand, int len)
{
grub_printf("\n");
grub_refresh();
*record = 1;
break;
}
}
Expand Down Expand Up @@ -3503,6 +3472,7 @@ static int ventoy_auto_install_var_expand(install_template *node)
{
int pos = 0;
int flag = 0;
int record = 0;
int newlen = 0;
char *start = NULL;
char *end = NULL;
Expand All @@ -3511,6 +3481,8 @@ static int ventoy_auto_install_var_expand(install_template *node)
char *nextline = NULL;
grub_uint8_t *code = NULL;
char value[512];
var_node *CurNode = NULL;
var_node *pVarList = NULL;

code = (grub_uint8_t *)node->filebuf;

Expand Down Expand Up @@ -3563,8 +3535,33 @@ static int ventoy_auto_install_var_expand(install_template *node)
*start = *end = 0;
VTOY_APPEND_NEWBUF(curline);

value[sizeof(value) - 1] = 0;
ventoy_var_expand(&flag, start + 2, value, sizeof(value) - 1);
for (CurNode = pVarList; CurNode; CurNode = CurNode->next)
{
if (grub_strcmp(start + 2, CurNode->var) == 0)
{
grub_snprintf(value, sizeof(value) - 1, "%s", CurNode->val);
break;
}
}

if (!CurNode)
{
value[sizeof(value) - 1] = 0;
ventoy_var_expand(&record, &flag, start + 2, value, sizeof(value) - 1);

if (record)
{
CurNode = grub_zalloc(sizeof(var_node));
if (CurNode)
{
grub_snprintf(CurNode->var, sizeof(CurNode->var), "%s", start + 2);
grub_snprintf(CurNode->val, sizeof(CurNode->val), "%s", value);
CurNode->next = pVarList;
pVarList = CurNode;
}
}
}

VTOY_APPEND_NEWBUF(value);

VTOY_APPEND_NEWBUF(end + 2);
Expand All @@ -3573,14 +3570,28 @@ static int ventoy_auto_install_var_expand(install_template *node)
{
VTOY_APPEND_NEWBUF(curline);
}

newbuf[pos++] = '\n';

if (pos > 0 && newbuf[pos - 1] == '\r')
{
newbuf[pos - 1] = '\n';
}
else
{
newbuf[pos++] = '\n';
}
}

grub_free(node->filebuf);
node->filebuf = newbuf;
node->filelen = pos;

while (pVarList)
{
CurNode = pVarList->next;
grub_free(pVarList);
pVarList = CurNode;
}

return 0;
}

Expand Down
9 changes: 9 additions & 0 deletions GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ typedef struct chk_case_fs_dir
grub_fs_t fs;
}chk_case_fs_dir;

int ventoy_str_all_digit(const char *str);
int ventoy_strcmp(const char *pattern, const char *str);
int ventoy_strncmp (const char *pattern, const char *str, grub_size_t n);
void ventoy_fill_os_param(grub_file_t file, ventoy_os_param *param);
Expand Down Expand Up @@ -1208,6 +1209,14 @@ typedef struct browser_node
struct browser_node *next;
}browser_node;

typedef struct var_node
{
char var[128];
char val[256];

struct var_node *next;
}var_node;

extern char *g_tree_script_buf;
extern int g_tree_script_pos;
extern int g_tree_script_pre;
Expand Down
4 changes: 4 additions & 0 deletions IMG/cpio/ventoy/hook/debian/disk_mount_hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ fi

vtlog "${vtdiskname#/dev/}2 found..."
$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/udev_disk_hook.sh "${vtdiskname#/dev/}2"

if [ -f /ventoy/autoinstall ]; then
sh /ventoy/hook/default/auto_install_varexp.sh /ventoy/autoinstall
fi
5 changes: 5 additions & 0 deletions IMG/cpio/ventoy/hook/debian/ventoy-cloud-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ if [ $vtSplit -eq 1 ]; then
vtlog "Line number: $vtLine $vtLine1 $vtLine2"
sed -n "1,${vtLine1}p" $VTOY_PATH/autoinstall >/tmpcidata/user-data
sed -n "${vtLine2},\$p" $VTOY_PATH/autoinstall >/tmpcidata/meta-data

sh /ventoy/hook/default/auto_install_varexp.sh /tmpcidata/user-data
sh /ventoy/hook/default/auto_install_varexp.sh /tmpcidata/meta-data
else
vtlog "only user-data avaliable"
cp -a $VTOY_PATH/autoinstall /tmpcidata/user-data
touch /tmpcidata/meta-data

sh /ventoy/hook/default/auto_install_varexp.sh /tmpcidata/user-data
fi


Expand Down
Loading

0 comments on commit b976923

Please sign in to comment.