Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ventoy committed Aug 13, 2020
1 parent 062f816 commit 9962775
Show file tree
Hide file tree
Showing 33 changed files with 1,015 additions and 38 deletions.
8 changes: 5 additions & 3 deletions FUSEISO/vtoy_fuse_iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ static int ventoy_iso_open(const char *path, struct fuse_file_info *file)
return 0;
}

static int ventoy_read_iso_sector(uint32_t sector, uint32_t num, void *buf)
static int ventoy_read_iso_sector(uint32_t sector, uint32_t num, char *buf)
{
uint32_t i = 0;
uint32_t leftSec = 0;
uint32_t readSec = 0;
off_t offset = 0;
dmtable_entry *entry = NULL;

for (i = 0; i < g_disk_entry_num && num > 0; i++)
Expand All @@ -127,14 +128,15 @@ static int ventoy_read_iso_sector(uint32_t sector, uint32_t num, void *buf)

if (sector >= entry->isoSector && sector < entry->isoSector + entry->sectorNum)
{
lseek(g_disk_fd, (entry->diskSector + (sector - entry->isoSector)) * 512, SEEK_SET);
offset = (entry->diskSector + (sector - entry->isoSector)) * 512;

leftSec = entry->sectorNum - (sector - entry->isoSector);
readSec = (leftSec > num) ? num : leftSec;

read(g_disk_fd, buf, readSec * 512);
pread(g_disk_fd, buf, readSec * 512, offset);

sector += readSec;
buf += readSec * 512;
num -= readSec;
}
}
Expand Down
Binary file modified FUSEISO/vtoy_fuse_iso_32
Binary file not shown.
Binary file modified FUSEISO/vtoy_fuse_iso_64
Binary file not shown.
10 changes: 9 additions & 1 deletion GRUB2/MOD_SRC/grub-2.04/grub-core/lib/syslinux_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ static grub_err_t
cmd_timeout (const char *line, struct syslinux_menu *menu)
{
menu->timeout = grub_strtoul (line, NULL, 0);

return GRUB_ERR_NONE;
}

Expand Down Expand Up @@ -991,6 +990,7 @@ write_entry (struct output_buffer *outbuf,

print_string ("\n");
}
print_string ("boot\n");
}
break;
case KERNEL_CHAINLOADER:
Expand Down Expand Up @@ -1433,6 +1433,7 @@ config_file (struct output_buffer *outbuf,
const char *fname, struct syslinux_menu *parent,
grub_syslinux_flavour_t flav)
{
const char *data;
grub_err_t err;
struct syslinux_menu menu;
struct syslinux_menuentry *curentry, *lentry;
Expand All @@ -1447,6 +1448,13 @@ config_file (struct output_buffer *outbuf,

menu.filename = fname;
menu.parent = parent;

data = grub_env_get("vtdebug_flag");
if (data && data[0])
{
menu.timeout = 100;
}

err = syslinux_parse_real (&menu);
if (err)
return err;
Expand Down
132 changes: 121 additions & 11 deletions GRUB2/MOD_SRC/grub-2.04/grub-core/loader/i386/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ static int ventoy_debug = 0;
static int ventoy_initrd_called = 0;
static int ventoy_linux_argc = 0;
static char **ventoy_linux_args = NULL;
static int ventoy_extra_initrd_num = 0;
static char *ventoy_extra_initrd_list[256];

static grub_err_t
grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]);

Expand Down Expand Up @@ -427,8 +430,9 @@ static void ventoy_debug_pause(void)

static int ventoy_preboot(void)
{
int i;
const char *file;
char buf[128];
char *argv[2];

if (ventoy_debug)
{
Expand All @@ -449,16 +453,28 @@ static int ventoy_preboot(void)

grub_snprintf(buf, sizeof(buf), "mem:%s:size:%s", grub_env_get("ventoy_cpio_addr"), grub_env_get("ventoy_cpio_size"));

argv[0] = buf;
argv[1] = NULL;
grub_cmd_initrd(NULL, 1, argv);
ventoy_extra_initrd_list[ventoy_extra_initrd_num++] = grub_strdup(buf);

file = grub_env_get("vtoy_img_part_file");
if (file)
{
ventoy_extra_initrd_list[ventoy_extra_initrd_num++] = grub_strdup(file);
}

if (ventoy_debug)
{
grub_printf("add initrd %s\n", buf);
grub_printf("========== initrd list ==========\n");
for (i = 0; i < ventoy_extra_initrd_num; i++)
{
grub_printf("%s\n", ventoy_extra_initrd_list[i]);
}
grub_printf("=================================\n");

ventoy_debug_pause();
}

grub_cmd_initrd(NULL, ventoy_extra_initrd_num, ventoy_extra_initrd_list);

return 0;
}

Expand All @@ -478,6 +494,13 @@ static int ventoy_boot_opt_filter(char *opt)
}
return 0;
}

if (grub_strncmp(opt, "init=", 5) == 0)
{
opt[0] = 'v';
opt[1] = 't';
return 0;
}

if (ventoy_debug)
{
Expand Down Expand Up @@ -597,7 +620,7 @@ static int ventoy_bootopt_hook(int argc, char *argv[])

if (ventoy_debug)
{
ventoy_linux_args[count++] = grub_strdup("loglevel=10");
ventoy_linux_args[count++] = grub_strdup("loglevel=7");
}

ventoy_linux_argc = count;
Expand Down Expand Up @@ -663,6 +686,72 @@ grub_cmd_unset_boot_opt (grub_command_t cmd __attribute__ ((unused)),
return 0;
}

static grub_err_t
grub_cmd_extra_initrd_append (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{
int newclen = 0;
char *pos = NULL;
char *end = NULL;
char buf[256] = {0};

if (argc != 1)
{
return 1;
}

for (pos = argv[0]; *pos; pos++)
{
if (*pos == '/')
{
end = pos;
}
}

if (end)
{
/* grub2 newc bug workaround */
newclen = (int)grub_strlen(end + 1);
if ((110 + newclen) % 4 == 0)
{
grub_snprintf(buf, sizeof(buf), "newc:.%s:%s", end + 1, argv[0]);
}
else
{
grub_snprintf(buf, sizeof(buf), "newc:%s:%s", end + 1, argv[0]);
}

if (ventoy_extra_initrd_num < 256)
{
ventoy_extra_initrd_list[ventoy_extra_initrd_num++] = grub_strdup(buf);
}
}

return 0;
}

static grub_err_t
grub_cmd_extra_initrd_reset (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{
int i;

(void)argc;
(void)argv;

for (i = 0; i < ventoy_extra_initrd_num; i++)
{
if (ventoy_extra_initrd_list[i])
{
grub_free(ventoy_extra_initrd_list[i]);
}
}

grub_memset(ventoy_extra_initrd_list, 0, sizeof(ventoy_extra_initrd_list));

return 0;
}


static grub_err_t
grub_linux_boot (void)
Expand Down Expand Up @@ -1416,8 +1505,8 @@ ventoy_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{
int i;
const char *file;
char buf[64];
char *newargv[32] = {NULL};

if (ventoy_debug) grub_printf("ventoy_cmd_initrd %d\n", ventoy_linux_argc);

Expand All @@ -1430,19 +1519,37 @@ ventoy_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),

if (ventoy_debug) grub_printf("membuf=%s\n", buf);

newargv[0] = buf;
ventoy_extra_initrd_list[ventoy_extra_initrd_num++] = grub_strdup(buf);

file = grub_env_get("vtoy_img_part_file");
if (file)
{
ventoy_extra_initrd_list[ventoy_extra_initrd_num++] = grub_strdup(file);
}

for (i = 0; i < argc; i++)
{
newargv[i + 1] = argv[i];
ventoy_extra_initrd_list[ventoy_extra_initrd_num++] = grub_strdup(argv[i]);
}

ventoy_initrd_called = 1;

if (ventoy_debug)
{
grub_printf("========== initrd list ==========\n");
for (i = 0; i < ventoy_extra_initrd_num; i++)
{
grub_printf("%s\n", ventoy_extra_initrd_list[i]);
}
grub_printf("=================================\n");
}

return grub_cmd_initrd(cmd, argc + 1, newargv);
return grub_cmd_initrd(cmd, ventoy_extra_initrd_num, ventoy_extra_initrd_list);
}


static grub_command_t cmd_linux, cmd_initrd, cmd_linuxefi, cmd_initrdefi, cmd_set_bootopt, cmd_unset_bootopt;
static grub_command_t cmd_linux, cmd_initrd, cmd_linuxefi, cmd_initrdefi;
static grub_command_t cmd_set_bootopt, cmd_unset_bootopt, cmd_extra_initrd_append, cmd_extra_initrd_reset;

GRUB_MOD_INIT(linux)
{
Expand All @@ -1457,6 +1564,9 @@ GRUB_MOD_INIT(linux)
0, N_("Load initrd."));
cmd_set_bootopt = grub_register_command ("vt_set_boot_opt", grub_cmd_set_boot_opt, 0, N_("set ext boot opt"));
cmd_unset_bootopt = grub_register_command ("vt_unset_boot_opt", grub_cmd_unset_boot_opt, 0, N_("unset ext boot opt"));

cmd_extra_initrd_append = grub_register_command ("vt_img_extra_initrd_append", grub_cmd_extra_initrd_append, 0, N_(""));
cmd_extra_initrd_reset = grub_register_command ("vt_img_extra_initrd_reset", grub_cmd_extra_initrd_reset, 0, N_(""));

ventoy_linux_args = grub_zalloc(sizeof(char *) * LINUX_MAX_ARGC);

Expand Down
Loading

0 comments on commit 9962775

Please sign in to comment.