1.0.10 release

pull/123/head v1.0.10
longpanda 4 years ago
parent fe0dda6904
commit 84c500666a

@ -374,7 +374,7 @@ static int ventoy_is_mbr_match(ventoy_mbr_head *head)
return 0;
}
if (head->PartTbl[0].FsFlag != 0x07 || head->PartTbl[0].StartSectorId != 2048) {
if (head->PartTbl[0].StartSectorId != 2048) {
return 0;
}

File diff suppressed because it is too large Load Diff

@ -965,10 +965,8 @@ grub_fat_dir (grub_device_t device, const char *path, grub_fs_dir_hook_t hook,
info.dir = !! (ctxt.dir.attr & GRUB_FAT_ATTR_DIRECTORY);
info.case_insensitive = 1;
#ifdef MODE_EXFAT
if (!info.dir)
info.size = ctxt.dir.file_size;
#endif
#ifdef MODE_EXFAT
if (!ctxt.dir.have_stream)
@ -1276,54 +1274,6 @@ GRUB_MOD_FINI(fat)
#ifdef MODE_EXFAT
static int grub_fat_add_chunk(ventoy_img_chunk_list *chunk_list, grub_uint64_t sector, grub_uint64_t size, grub_uint32_t log_sector_size)
{
ventoy_img_chunk *last_chunk;
ventoy_img_chunk *new_chunk;
if (chunk_list->cur_chunk == 0)
{
chunk_list->chunk[0].img_start_sector = 0;
chunk_list->chunk[0].img_end_sector = (size >> 11) - 1;
chunk_list->chunk[0].disk_start_sector = sector;
chunk_list->chunk[0].disk_end_sector = sector + (size >> log_sector_size) - 1;
chunk_list->cur_chunk = 1;
return 0;
}
last_chunk = chunk_list->chunk + chunk_list->cur_chunk - 1;
if (last_chunk->disk_end_sector + 1 == sector)
{
last_chunk->img_end_sector += (size >> 11);
last_chunk->disk_end_sector += (size >> log_sector_size);
return 0;
}
if (chunk_list->cur_chunk == chunk_list->max_chunk)
{
new_chunk = grub_realloc(chunk_list->chunk, chunk_list->max_chunk * 2 * sizeof(ventoy_img_chunk));
if (NULL == new_chunk)
{
return -1;
}
chunk_list->chunk = new_chunk;
chunk_list->max_chunk *= 2;
/* issue: update last_chunk */
last_chunk = chunk_list->chunk + chunk_list->cur_chunk - 1;
}
new_chunk = chunk_list->chunk + chunk_list->cur_chunk;
new_chunk->img_start_sector = last_chunk->img_end_sector + 1;
new_chunk->img_end_sector = new_chunk->img_start_sector + (size >> 11) - 1;
new_chunk->disk_start_sector = sector;
new_chunk->disk_end_sector = sector + (size >> log_sector_size) - 1;
chunk_list->cur_chunk++;
return 0;
}
int grub_fat_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_img_chunk_list *chunk_list)
{
grub_size_t size;
@ -1433,7 +1383,7 @@ int grub_fat_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_i
if (size > len)
size = len;
grub_fat_add_chunk(chunk_list, sector, size, disk->log_sector_size);
grub_disk_blocklist_read(chunk_list, sector, size, disk->log_sector_size);
len -= size;
logical_cluster++;

File diff suppressed because it is too large Load Diff

@ -1152,6 +1152,8 @@ grub_udf_dir_iter (const char *filename, enum grub_fshelp_filetype filetype,
info.mtime -= 60 * tz;
}
if (!info.dir)
info.size = U64 (node->block.fe.file_size);
grub_free (node);
return ctx->hook (filename, &info, ctx->hook_data);
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,600 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003,2004,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* GRUB 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.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/disk.h>
#include <grub/err.h>
#include <grub/mm.h>
#include <grub/types.h>
#include <grub/partition.h>
#include <grub/misc.h>
#include <grub/time.h>
#include <grub/file.h>
#include <grub/i18n.h>
#include <grub/ventoy.h>
#define GRUB_CACHE_TIMEOUT 2
/* The last time the disk was used. */
static grub_uint64_t grub_last_time = 0;
struct grub_disk_cache grub_disk_cache_table[GRUB_DISK_CACHE_NUM];
void (*grub_disk_firmware_fini) (void);
int grub_disk_firmware_is_tainted;
#if DISK_CACHE_STATS
static unsigned long grub_disk_cache_hits;
static unsigned long grub_disk_cache_misses;
void
grub_disk_cache_get_performance (unsigned long *hits, unsigned long *misses)
{
*hits = grub_disk_cache_hits;
*misses = grub_disk_cache_misses;
}
#endif
grub_err_t (*grub_disk_write_weak) (grub_disk_t disk,
grub_disk_addr_t sector,
grub_off_t offset,
grub_size_t size,
const void *buf);
#include "disk_common.c"
void
grub_disk_cache_invalidate_all (void)
{
unsigned i;
for (i = 0; i < GRUB_DISK_CACHE_NUM; i++)
{
struct grub_disk_cache *cache = grub_disk_cache_table + i;
if (cache->data && ! cache->lock)
{
grub_free (cache->data);
cache->data = 0;
}
}
}
static char *
grub_disk_cache_fetch (unsigned long dev_id, unsigned long disk_id,
grub_disk_addr_t sector)
{
struct grub_disk_cache *cache;
unsigned cache_index;
cache_index = grub_disk_cache_get_index (dev_id, disk_id, sector);
cache = grub_disk_cache_table + cache_index;
if (cache->dev_id == dev_id && cache->disk_id == disk_id
&& cache->sector == sector)
{
cache->lock = 1;
#if DISK_CACHE_STATS
grub_disk_cache_hits++;
#endif
return cache->data;
}
#if DISK_CACHE_STATS
grub_disk_cache_misses++;
#endif
return 0;
}
static void
grub_disk_cache_unlock (unsigned long dev_id, unsigned long disk_id,
grub_disk_addr_t sector)
{
struct grub_disk_cache *cache;
unsigned cache_index;
cache_index = grub_disk_cache_get_index (dev_id, disk_id, sector);
cache = grub_disk_cache_table + cache_index;
if (cache->dev_id == dev_id && cache->disk_id == disk_id
&& cache->sector == sector)
cache->lock = 0;
}
static grub_err_t
grub_disk_cache_store (unsigned long dev_id, unsigned long disk_id,
grub_disk_addr_t sector, const char *data)
{
unsigned cache_index;
struct grub_disk_cache *cache;
cache_index = grub_disk_cache_get_index (dev_id, disk_id, sector);
cache = grub_disk_cache_table + cache_index;
cache->lock = 1;
grub_free (cache->data);
cache->data = 0;
cache->lock = 0;
cache->data = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
if (! cache->data)
return grub_errno;
grub_memcpy (cache->data, data,
GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
cache->dev_id = dev_id;
cache->disk_id = disk_id;
cache->sector = sector;
return GRUB_ERR_NONE;
}
grub_disk_dev_t grub_disk_dev_list;
void
grub_disk_dev_register (grub_disk_dev_t dev)
{
dev->next = grub_disk_dev_list;
grub_disk_dev_list = dev;
}
void
grub_disk_dev_unregister (grub_disk_dev_t dev)
{
grub_disk_dev_t *p, q;
for (p = &grub_disk_dev_list, q = *p; q; p = &(q->next), q = q->next)
if (q == dev)
{
*p = q->next;
break;
}
}
/* Return the location of the first ',', if any, which is not
escaped by a '\'. */
static const char *
find_part_sep (const char *name)
{
const char *p = name;
char c;
while ((c = *p++) != '\0')
{
if (c == '\\' && *p == ',')
p++;
else if (c == ',')
return p - 1;
}
return NULL;
}
grub_disk_t
grub_disk_open (const char *name)
{
const char *p;
grub_disk_t disk;
grub_disk_dev_t dev;
char *raw = (char *) name;
grub_uint64_t current_time;
grub_dprintf ("disk", "Opening `%s'...\n", name);
disk = (grub_disk_t) grub_zalloc (sizeof (*disk));
if (! disk)
return 0;
disk->log_sector_size = GRUB_DISK_SECTOR_BITS;
/* Default 1MiB of maximum agglomerate. */
disk->max_agglomerate = 1048576 >> (GRUB_DISK_SECTOR_BITS
+ GRUB_DISK_CACHE_BITS);
p = find_part_sep (name);
if (p)
{
grub_size_t len = p - name;
raw = grub_malloc (len + 1);
if (! raw)
goto fail;
grub_memcpy (raw, name, len);
raw[len] = '\0';
disk->name = grub_strdup (raw);
}
else
disk->name = grub_strdup (name);
if (! disk->name)
goto fail;
for (dev = grub_disk_dev_list; dev; dev = dev->next)
{
if ((dev->disk_open) (raw, disk) == GRUB_ERR_NONE)
break;
else if (grub_errno == GRUB_ERR_UNKNOWN_DEVICE)
grub_errno = GRUB_ERR_NONE;
else
goto fail;
}
if (! dev)
{
grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("disk `%s' not found"),
name);
goto fail;
}
if (disk->log_sector_size > GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS
|| disk->log_sector_size < GRUB_DISK_SECTOR_BITS)
{
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"sector sizes of %d bytes aren't supported yet",
(1 << disk->log_sector_size));
goto fail;
}
disk->dev = dev;
if (p)
{
disk->partition = grub_partition_probe (disk, p + 1);
if (! disk->partition)
{
/* TRANSLATORS: It means that the specified partition e.g.
hd0,msdos1=/dev/sda1 doesn't exist. */
grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("no such partition"));
goto fail;
}
}
/* The cache will be invalidated about 2 seconds after a device was
closed. */
current_time = grub_get_time_ms ();
if (current_time > (grub_last_time
+ GRUB_CACHE_TIMEOUT * 1000))
grub_disk_cache_invalidate_all ();
grub_last_time = current_time;
fail:
if (raw && raw != name)
grub_free (raw);
if (grub_errno != GRUB_ERR_NONE)
{
grub_error_push ();
grub_dprintf ("disk", "Opening `%s' failed.\n", name);
grub_error_pop ();
grub_disk_close (disk);
return 0;
}
return disk;
}
void
grub_disk_close (grub_disk_t disk)
{
grub_partition_t part;
grub_dprintf ("disk", "Closing `%s'.\n", disk->name);
if (disk->dev && disk->dev->disk_close)
(disk->dev->disk_close) (disk);
/* Reset the timer. */
grub_last_time = grub_get_time_ms ();
while (disk->partition)
{
part = disk->partition->parent;
grub_free (disk->partition);
disk->partition = part;
}
grub_free ((void *) disk->name);
grub_free (disk);
}
/* Small read (less than cache size and not pass across cache unit boundaries).
sector is already adjusted and is divisible by cache unit size.
*/
static grub_err_t
grub_disk_read_small_real (grub_disk_t disk, grub_disk_addr_t sector,
grub_off_t offset, grub_size_t size, void *buf)
{
char *data;
char *tmp_buf;
/* Fetch the cache. */
data = grub_disk_cache_fetch (disk->dev->id, disk->id, sector);
if (data)
{
/* Just copy it! */
grub_memcpy (buf, data + offset, size);
grub_disk_cache_unlock (disk->dev->id, disk->id, sector);
return GRUB_ERR_NONE;
}
/* Allocate a temporary buffer. */
tmp_buf = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
if (! tmp_buf)
return grub_errno;
/* Otherwise read data from the disk actually. */
if (disk->total_sectors == GRUB_DISK_SIZE_UNKNOWN
|| sector + GRUB_DISK_CACHE_SIZE
< (disk->total_sectors << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)))
{
grub_err_t err;
err = (disk->dev->disk_read) (disk, transform_sector (disk, sector),
1U << (GRUB_DISK_CACHE_BITS
+ GRUB_DISK_SECTOR_BITS
- disk->log_sector_size), tmp_buf);
if (!err)
{
/* Copy it and store it in the disk cache. */
grub_memcpy (buf, tmp_buf + offset, size);
grub_disk_cache_store (disk->dev->id, disk->id,
sector, tmp_buf);
grub_free (tmp_buf);
return GRUB_ERR_NONE;
}
}
grub_free (tmp_buf);
grub_errno = GRUB_ERR_NONE;
{
/* Uggh... Failed. Instead, just read necessary data. */
unsigned num;
grub_disk_addr_t aligned_sector;
sector += (offset >> GRUB_DISK_SECTOR_BITS);
offset &= ((1 << GRUB_DISK_SECTOR_BITS) - 1);
aligned_sector = (sector & ~((1ULL << (disk->log_sector_size
- GRUB_DISK_SECTOR_BITS))
- 1));
offset += ((sector - aligned_sector) << GRUB_DISK_SECTOR_BITS);
num = ((size + offset + (1ULL << (disk->log_sector_size))
- 1) >> (disk->log_sector_size));
tmp_buf = grub_malloc (num << disk->log_sector_size);
if (!tmp_buf)
return grub_errno;
if ((disk->dev->disk_read) (disk, transform_sector (disk, aligned_sector),
num, tmp_buf))
{
grub_error_push ();
grub_dprintf ("disk", "%s read failed\n", disk->name);
grub_error_pop ();
grub_free (tmp_buf);
return grub_errno;
}
grub_memcpy (buf, tmp_buf + offset, size);
grub_free (tmp_buf);
return GRUB_ERR_NONE;
}
}
static grub_err_t
grub_disk_read_small (grub_disk_t disk, grub_disk_addr_t sector,
grub_off_t offset, grub_size_t size, void *buf)
{
grub_err_t err;
err = grub_disk_read_small_real (disk, sector, offset, size, buf);
if (err)
return err;
if (disk->read_hook)
(disk->read_hook) (sector + (offset >> GRUB_DISK_SECTOR_BITS),
offset & (GRUB_DISK_SECTOR_SIZE - 1),
size, disk->read_hook_data);
return GRUB_ERR_NONE;
}
grub_err_t grub_disk_blocklist_read(void *chunklist, grub_uint64_t sector,
grub_uint64_t size, grub_uint32_t log_sector_size)
{
ventoy_img_chunk *last_chunk = NULL;
ventoy_img_chunk *new_chunk = NULL;
ventoy_img_chunk_list *chunk_list = (ventoy_img_chunk_list *)chunklist;
if (chunk_list->cur_chunk == 0)
{
chunk_list->chunk[0].img_start_sector = 0;
chunk_list->chunk[0].img_end_sector = (size >> 11) - 1;
chunk_list->chunk[0].disk_start_sector = sector;
chunk_list->chunk[0].disk_end_sector = sector + (size >> log_sector_size) - 1;
chunk_list->cur_chunk = 1;
return 0;
}
last_chunk = chunk_list->chunk + chunk_list->cur_chunk - 1;
if (last_chunk->disk_end_sector + 1 == sector)
{
last_chunk->img_end_sector += (size >> 11);
last_chunk->disk_end_sector += (size >> log_sector_size);
return 0;
}
if (chunk_list->cur_chunk == chunk_list->max_chunk)
{
new_chunk = grub_realloc(chunk_list->chunk, chunk_list->max_chunk * 2 * sizeof(ventoy_img_chunk));
if (NULL == new_chunk)
{
return -1;
}
chunk_list->chunk = new_chunk;
chunk_list->max_chunk *= 2;
/* issue: update last_chunk */
last_chunk = chunk_list->chunk + chunk_list->cur_chunk - 1;
}
new_chunk = chunk_list->chunk + chunk_list->cur_chunk;
new_chunk->img_start_sector = last_chunk->img_end_sector + 1;
new_chunk->img_end_sector = new_chunk->img_start_sector + (size >> 11) - 1;
new_chunk->disk_start_sector = sector;
new_chunk->disk_end_sector = sector + (size >> log_sector_size) - 1;
chunk_list->cur_chunk++;
return 0;
}
/* Read data from the disk. */
grub_err_t
grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_off_t offset, grub_size_t size, void *buf)
{
if (disk->read_hook == (grub_disk_read_hook_t)grub_disk_blocklist_read)
{
return grub_disk_blocklist_read((ventoy_img_chunk_list *)disk->read_hook_data, sector, size, disk->log_sector_size);
}
/* First of all, check if the region is within the disk. */
if (grub_disk_adjust_range (disk, &sector, &offset, size) != GRUB_ERR_NONE)
{
grub_error_push ();
grub_dprintf ("disk", "Read out of range: sector 0x%llx (%s).\n",
(unsigned long long) sector, grub_errmsg);
grub_error_pop ();
return grub_errno;
}
/* First read until first cache boundary. */
if (offset || (sector & (GRUB_DISK_CACHE_SIZE - 1)))
{
grub_disk_addr_t start_sector;
grub_size_t pos;
grub_err_t err;
grub_size_t len;
start_sector = sector & ~((grub_disk_addr_t) GRUB_DISK_CACHE_SIZE - 1);
pos = (sector - start_sector) << GRUB_DISK_SECTOR_BITS;
len = ((GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS)
- pos - offset);
if (len > size)
len = size;
err = grub_disk_read_small (disk, start_sector,
offset + pos, len, buf);
if (err)
return err;
buf = (char *) buf + len;
size -= len;
offset += len;
sector += (offset >> GRUB_DISK_SECTOR_BITS);
offset &= ((1 << GRUB_DISK_SECTOR_BITS) - 1);
}
/* Until SIZE is zero... */
while (size >= (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS))
{
char *data = NULL;
grub_disk_addr_t agglomerate;
grub_err_t err;
/* agglomerate read until we find a first cached entry. */
for (agglomerate = 0; agglomerate
< (size >> (GRUB_DISK_SECTOR_BITS + GRUB_DISK_CACHE_BITS))
&& agglomerate < disk->max_agglomerate;
agglomerate++)
{
data = grub_disk_cache_fetch (disk->dev->id, disk->id,
sector + (agglomerate
<< GRUB_DISK_CACHE_BITS));
if (data)
break;
}
if (data)
{
grub_memcpy ((char *) buf
+ (agglomerate << (GRUB_DISK_CACHE_BITS
+ GRUB_DISK_SECTOR_BITS)),
data, GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS);
grub_disk_cache_unlock (disk->dev->id, disk->id,
sector + (agglomerate
<< GRUB_DISK_CACHE_BITS));
}
if (agglomerate)
{
grub_disk_addr_t i;
err = (disk->dev->disk_read) (disk, transform_sector (disk, sector),
agglomerate << (GRUB_DISK_CACHE_BITS
+ GRUB_DISK_SECTOR_BITS
- disk->log_sector_size),
buf);
if (err)
return err;
for (i = 0; i < agglomerate; i ++)
grub_disk_cache_store (disk->dev->id, disk->id,
sector + (i << GRUB_DISK_CACHE_BITS),
(char *) buf
+ (i << (GRUB_DISK_CACHE_BITS
+ GRUB_DISK_SECTOR_BITS)));
if (disk->read_hook)
(disk->read_hook) (sector, 0, agglomerate << (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS),
disk->read_hook_data);
sector += agglomerate << GRUB_DISK_CACHE_BITS;
size -= agglomerate << (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS);
buf = (char *) buf
+ (agglomerate << (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS));
}
if (data)
{
if (disk->read_hook)
(disk->read_hook) (sector, 0, (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS),
disk->read_hook_data);
sector += GRUB_DISK_CACHE_SIZE;
buf = (char *) buf + (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS);
size -= (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS);
}
}
/* And now read the last part. */
if (size)
{
grub_err_t err;
err = grub_disk_read_small (disk, sector, 0, size, buf);
if (err)
return err;
}
return grub_errno;
}
grub_uint64_t
grub_disk_get_size (grub_disk_t disk)
{
if (disk->partition)
return grub_partition_get_len (disk->partition);
else if (disk->total_sectors != GRUB_DISK_SIZE_UNKNOWN)
return disk->total_sectors << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS);
else
return GRUB_DISK_SIZE_UNKNOWN;
}

@ -37,6 +37,7 @@
#include <grub/efi/efi.h>
#endif
#include <grub/time.h>
#include <grub/relocator.h>
#include <grub/ventoy.h>
#include "ventoy_def.h"
@ -100,6 +101,36 @@ int ventoy_is_efi_os(void)
return g_efi_os;
}
static int ventoy_get_fs_type(const char *fs)
{
if (NULL == fs)
{
return ventoy_fs_max;
}
else if (grub_strncmp(fs, "exfat", 5) == 0)
{
return ventoy_fs_exfat;
}
else if (grub_strncmp(fs, "ntfs", 4) == 0)
{
return ventoy_fs_ntfs;
}
else if (grub_strncmp(fs, "ext", 3) == 0)
{
return ventoy_fs_ext;
}
else if (grub_strncmp(fs, "xfs", 3) == 0)
{
return ventoy_fs_xfs;
}
else if (grub_strncmp(fs, "udf", 3) == 0)
{
return ventoy_fs_udf;
}
return ventoy_fs_max;
}
static int ventoy_string_check(const char *str, grub_char_check_func check)
{
if (!str)
@ -942,6 +973,12 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
goto fail;
}
if (ventoy_get_fs_type(fs->name) >= ventoy_fs_max)
{
debug("unsupported fs:<%s>\n", fs->name);
goto fail;
}
grub_memset(&g_img_iterator_head, 0, sizeof(g_img_iterator_head));
g_img_iterator_head.dirlen = 1;
@ -1212,19 +1249,7 @@ void ventoy_fill_os_param(grub_file_t file, ventoy_os_param *param)
param->vtoy_disk_size = disk->total_sectors * (1 << disk->log_sector_size);
param->vtoy_disk_part_id = disk->partition->number + 1;
if (grub_strcmp(file->fs->name, "exfat") == 0)
{
param->vtoy_disk_part_type = 0;
}
else if (grub_strcmp(file->fs->name, "ntfs") == 0)
{
param->vtoy_disk_part_type = 1;
}
else
{
param->vtoy_disk_part_type = 0xFFFF;
}
param->vtoy_disk_part_type = ventoy_get_fs_type(file->fs->name);
pos = grub_strstr(file->name, "/");
if (!pos)
@ -1251,6 +1276,52 @@ void ventoy_fill_os_param(grub_file_t file, ventoy_os_param *param)
return;
}
static int ventoy_get_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start)
{
int fs_type;
grub_uint32_t i = 0;
grub_uint32_t sector = 0;
grub_uint32_t count = 0;
grub_off_t size = 0;
grub_off_t read = 0;
fs_type = ventoy_get_fs_type(file->fs->name);
if (fs_type == ventoy_fs_exfat)
{
grub_fat_get_file_chunk(start, file, chunklist);
}
else
{
file->read_hook = (grub_disk_read_hook_t)grub_disk_blocklist_read;
file->read_hook_data = chunklist;
for (size = file->size; size > 0; size -= read)
{
read = (size > VTOY_SIZE_1GB) ? VTOY_SIZE_1GB : size;
grub_file_read(file, NULL, read);
}
for (i = 0; start > 0 && i < chunklist->cur_chunk; i++)
{
chunklist->chunk[i].disk_start_sector += start;
chunklist->chunk[i].disk_end_sector += start;
}
if (ventoy_fs_udf == fs_type)
{
for (i = 0; i < chunklist->cur_chunk; i++)
{
count = (chunklist->chunk[i].disk_end_sector + 1 - chunklist->chunk[i].disk_start_sector) >> 2;
chunklist->chunk[i].img_start_sector = sector;
chunklist->chunk[i].img_end_sector = sector + count - 1;
sector += count;
}
}
}
return 0;
}
static grub_err_t ventoy_cmd_img_sector(grub_extcmd_context_t ctxt, int argc, char **args)
{
grub_file_t file;
@ -1280,8 +1351,7 @@ static grub_err_t ventoy_cmd_img_sector(grub_extcmd_context_t ctxt, int argc, ch
g_img_chunk_list.max_chunk = DEFAULT_CHUNK_NUM;
g_img_chunk_list.cur_chunk = 0;
debug("get fat file chunk part start:%llu\n", (unsigned long long)file->device->disk->partition->start);
grub_fat_get_file_chunk(file->device->disk->partition->start, file, &g_img_chunk_list);
ventoy_get_block_list(file, &g_img_chunk_list, file->device->disk->partition->start);
grub_file_close(file);
@ -1311,6 +1381,121 @@ static grub_err_t ventoy_cmd_dump_img_sector(grub_extcmd_context_t ctxt, int arg
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
#ifdef GRUB_MACHINE_EFI
static grub_err_t ventoy_cmd_relocator_chaindata(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
(void)argc;
(void)args;
return 0;
}
#else
static grub_err_t ventoy_cmd_relocator_chaindata(grub_extcmd_context_t ctxt, int argc, char **args)
{
int rc = 0;
ulong chain_len = 0;
char *chain_data = NULL;
char *relocator_addr = NULL;
grub_relocator_chunk_t ch;
struct grub_relocator *relocator = NULL;
char envbuf[64] = { 0 };
(void)ctxt;
(void)argc;
(void)args;
if (argc != 2)
{
return 1;
}
chain_data = (char *)grub_strtoul(args[0], NULL, 16);
chain_len = grub_strtoul(args[1], NULL, 10);
relocator = grub_relocator_new ();
if (!relocator)
{
debug("grub_relocator_new failed %p %lu\n", chain_data, chain_len);
return 1;
}
rc = grub_relocator_alloc_chunk_addr (relocator, &ch,
0x100000, // GRUB_LINUX_BZIMAGE_ADDR,
chain_len);
if (rc)
{
debug("grub_relocator_alloc_chunk_addr failed %d %p %lu\n", rc, chain_data, chain_len);
grub_relocator_unload (relocator);
return 1;
}
relocator_addr = get_virtual_current_address(ch);
grub_memcpy(relocator_addr, chain_data, chain_len);
grub_relocator_unload (relocator);
grub_snprintf(envbuf, sizeof(envbuf), "0x%lx", (unsigned long)relocator_addr);
grub_env_set("vtoy_chain_relocator_addr", envbuf);
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
#endif
static grub_err_t ventoy_cmd_test_block_list(grub_extcmd_context_t ctxt, int argc, char **args)
{
grub_uint32_t i;
grub_file_t file;
ventoy_img_chunk_list chunklist;
(void)ctxt;
(void)argc;
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
if (!file)
{
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s\n", args[0]);
}
/* get image chunk data */
grub_memset(&chunklist, 0, sizeof(chunklist));
chunklist.chunk = grub_malloc(sizeof(ventoy_img_chunk) * DEFAULT_CHUNK_NUM);
if (NULL == chunklist.chunk)
{
return grub_error(GRUB_ERR_OUT_OF_MEMORY, "Can't allocate image chunk memoty\n");
}
chunklist.max_chunk = DEFAULT_CHUNK_NUM;
chunklist.cur_chunk = 0;
ventoy_get_block_list(file, &chunklist, 0);
grub_file_close(file);
grub_printf("filesystem: <%s> entry number:<%u>\n", file->fs->name, chunklist.cur_chunk);
for (i = 0; i < chunklist.cur_chunk; i++)
{
grub_printf("%llu+%llu,", (ulonglong)chunklist.chunk[i].disk_start_sector,
(ulonglong)(chunklist.chunk[i].disk_end_sector + 1 - chunklist.chunk[i].disk_start_sector));
}
grub_printf("\n==================================\n");
for (i = 0; i < chunklist.cur_chunk; i++)
{
grub_printf("%2u: [%llu %llu] - [%llu %llu]\n", i,
(ulonglong)chunklist.chunk[i].img_start_sector,
(ulonglong)chunklist.chunk[i].img_end_sector,
(ulonglong)chunklist.chunk[i].disk_start_sector,
(ulonglong)chunklist.chunk[i].disk_end_sector
);
}
grub_free(chunklist.chunk);
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
static grub_err_t ventoy_cmd_add_replace_file(grub_extcmd_context_t ctxt, int argc, char **args)
{
int i;
@ -1412,7 +1597,7 @@ static grub_err_t ventoy_cmd_dynamic_menu(grub_extcmd_context_t ctxt, int argc,
if (argc != 2)
{
debug("Invlaid argc %d\n", argc);
debug("Invalid argc %d\n", argc);
return 0;
}
@ -1635,6 +1820,8 @@ static cmd_para ventoy_cmds[] =
{ "vt_windows_chain_data", ventoy_cmd_windows_chain_data, 0, NULL, "", "", NULL },
{ "vt_add_replace_file", ventoy_cmd_add_replace_file, 0, NULL, "", "", NULL },
{ "vt_relocator_chaindata", ventoy_cmd_relocator_chaindata, 0, NULL, "", "", NULL },
{ "vt_test_block_list", ventoy_cmd_test_block_list, 0, NULL, "", "", NULL },
{ "vt_load_plugin", ventoy_cmd_load_plugin, 0, NULL, "", "", NULL },

@ -23,6 +23,8 @@
#define VTOY_MAX_SCRIPT_BUF (4 * 1024 * 1024)
#define VTOY_SIZE_1GB 1073741824
#define JSON_SUCCESS 0
#define JSON_FAILED 1
#define JSON_NOT_FOUND 2

@ -401,7 +401,7 @@ static int ventoy_update_all_hash(void *meta_data, wim_directory_entry *dir)
return 0;
}
if (dir->len == 0)
if (dir->len < sizeof(wim_directory_entry))
{
return 0;
}
@ -420,7 +420,7 @@ static int ventoy_update_all_hash(void *meta_data, wim_directory_entry *dir)
}
dir = (wim_directory_entry *)((char *)dir + dir->len);
} while (dir->len);
} while (dir->len >= sizeof(wim_directory_entry));
return 0;
}
@ -957,4 +957,3 @@ grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, c
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}

@ -0,0 +1,265 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
*
* GRUB 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.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_DISK_HEADER
#define GRUB_DISK_HEADER 1
#include <config.h>
#include <grub/symbol.h>
#include <grub/err.h>
#include <grub/types.h>
#include <grub/device.h>
/* For NULL. */
#include <grub/mm.h>
/* These are used to set a device id. When you add a new disk device,
you must define a new id for it here. */
enum grub_disk_dev_id
{
GRUB_DISK_DEVICE_BIOSDISK_ID,
GRUB_DISK_DEVICE_OFDISK_ID,
GRUB_DISK_DEVICE_LOOPBACK_ID,
GRUB_DISK_DEVICE_EFIDISK_ID,
GRUB_DISK_DEVICE_DISKFILTER_ID,
GRUB_DISK_DEVICE_HOST_ID,
GRUB_DISK_DEVICE_ATA_ID,
GRUB_DISK_DEVICE_MEMDISK_ID,
GRUB_DISK_DEVICE_NAND_ID,
GRUB_DISK_DEVICE_SCSI_ID,
GRUB_DISK_DEVICE_CRYPTODISK_ID,
GRUB_DISK_DEVICE_ARCDISK_ID,
GRUB_DISK_DEVICE_HOSTDISK_ID,
GRUB_DISK_DEVICE_PROCFS_ID,
GRUB_DISK_DEVICE_CBFSDISK_ID,
GRUB_DISK_DEVICE_UBOOTDISK_ID,
GRUB_DISK_DEVICE_XEN,
GRUB_DISK_DEVICE_OBDISK_ID,
};
struct grub_disk;
#ifdef GRUB_UTIL
struct grub_disk_memberlist;
#endif
typedef enum
{
GRUB_DISK_PULL_NONE,
GRUB_DISK_PULL_REMOVABLE,
GRUB_DISK_PULL_RESCAN,
GRUB_DISK_PULL_MAX
} grub_disk_pull_t;
typedef int (*grub_disk_dev_iterate_hook_t) (const char *name, void *data);
/* Disk device. */
struct grub_disk_dev
{
/* The device name. */
const char *name;
/* The device id used by the cache manager. */
enum grub_disk_dev_id id;
/* Call HOOK with each device name, until HOOK returns non-zero. */
int (*disk_iterate) (grub_disk_dev_iterate_hook_t hook, void *hook_data,
grub_disk_pull_t pull);
/* Open the device named NAME, and set up DISK. */
grub_err_t (*disk_open) (const char *name, struct grub_disk *disk);
/* Close the disk DISK. */
void (*disk_close) (struct grub_disk *disk);
/* Read SIZE sectors from the sector SECTOR of the disk DISK into BUF. */
grub_err_t (*disk_read) (struct grub_disk *disk, grub_disk_addr_t sector,
grub_size_t size, char *buf);
/* Write SIZE sectors from BUF into the sector SECTOR of the disk DISK. */
grub_err_t (*disk_write) (struct grub_disk *disk, grub_disk_addr_t sector,
grub_size_t size, const char *buf);
#ifdef GRUB_UTIL
struct grub_disk_memberlist *(*disk_memberlist) (struct grub_disk *disk);
const char * (*disk_raidname) (struct grub_disk *disk);
#endif
/* The next disk device. */
struct grub_disk_dev *next;
};
typedef struct grub_disk_dev *grub_disk_dev_t;
extern grub_disk_dev_t EXPORT_VAR (grub_disk_dev_list);
struct grub_partition;
typedef void (*grub_disk_read_hook_t) (grub_disk_addr_t sector,
unsigned offset, unsigned length,
void *data);
/* Disk. */
struct grub_disk
{
/* The disk name. */
const char *name;
/* The underlying disk device. */
grub_disk_dev_t dev;
/* The total number of sectors. */
grub_uint64_t total_sectors;
/* Logarithm of sector size. */
unsigned int log_sector_size;
/* Maximum number of sectors read divided by GRUB_DISK_CACHE_SIZE. */
unsigned int max_agglomerate;
/* The id used by the disk cache manager. */
unsigned long id;
/* The partition information. This is machine-specific. */
struct grub_partition *partition;
/* Called when a sector was read. OFFSET is between 0 and
the sector size minus 1, and LENGTH is between 0 and the sector size. */
grub_disk_read_hook_t read_hook;
/* Caller-specific data passed to the read hook. */
void *read_hook_data;
/* Device-specific data. */
void *data;
};
typedef struct grub_disk *grub_disk_t;
#ifdef GRUB_UTIL
struct grub_disk_memberlist
{
grub_disk_t disk;
struct grub_disk_memberlist *next;
};
typedef struct grub_disk_memberlist *grub_disk_memberlist_t;
#endif
/* The sector size. */
#define GRUB_DISK_SECTOR_SIZE 0x200
#define GRUB_DISK_SECTOR_BITS 9
/* The maximum number of disk caches. */
#define GRUB_DISK_CACHE_NUM 1021
/* The size of a disk cache in 512B units. Must be at least as big as the
largest supported sector size, currently 16K. */
#define GRUB_DISK_CACHE_BITS 6
#define GRUB_DISK_CACHE_SIZE (1 << GRUB_DISK_CACHE_BITS)
#define GRUB_DISK_MAX_MAX_AGGLOMERATE ((1 << (30 - GRUB_DISK_CACHE_BITS - GRUB_DISK_SECTOR_BITS)) - 1)
/* Return value of grub_disk_get_size() in case disk size is unknown. */
#define GRUB_DISK_SIZE_UNKNOWN 0xffffffffffffffffULL
/* This is called from the memory manager. */
void grub_disk_cache_invalidate_all (void);
void EXPORT_FUNC(grub_disk_dev_register) (grub_disk_dev_t dev);
void EXPORT_FUNC(grub_disk_dev_unregister) (grub_disk_dev_t dev);
static inline int
grub_disk_dev_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data)
{
grub_disk_dev_t p;
grub_disk_pull_t pull;
for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++)
for (p = grub_disk_dev_list; p; p = p->next)
if (p->disk_iterate && (p->disk_iterate) (hook, hook_data, pull))
return 1;
return 0;
}
grub_disk_t EXPORT_FUNC(grub_disk_open) (const char *name);
void EXPORT_FUNC(grub_disk_close) (grub_disk_t disk);
grub_err_t EXPORT_FUNC(grub_disk_blocklist_read)(void *chunklist, grub_uint64_t sector,
grub_uint64_t size, grub_uint32_t log_sector_size);
grub_err_t EXPORT_FUNC(grub_disk_read) (grub_disk_t disk,
grub_disk_addr_t sector,
grub_off_t offset,
grub_size_t size,
void *buf);
grub_err_t grub_disk_write (grub_disk_t disk,
grub_disk_addr_t sector,
grub_off_t offset,
grub_size_t size,
const void *buf);
extern grub_err_t (*EXPORT_VAR(grub_disk_write_weak)) (grub_disk_t disk,
grub_disk_addr_t sector,
grub_off_t offset,
grub_size_t size,
const void *buf);
grub_uint64_t EXPORT_FUNC(grub_disk_get_size) (grub_disk_t disk);
#if DISK_CACHE_STATS
void
EXPORT_FUNC(grub_disk_cache_get_performance) (unsigned long *hits, unsigned long *misses);
#endif
extern void (* EXPORT_VAR(grub_disk_firmware_fini)) (void);
extern int EXPORT_VAR(grub_disk_firmware_is_tainted);
static inline void
grub_stop_disk_firmware (void)
{
/* To prevent two drivers operating on the same disks. */
grub_disk_firmware_is_tainted = 1;
if (grub_disk_firmware_fini)
{
grub_disk_firmware_fini ();
grub_disk_firmware_fini = NULL;
}
}
/* Disk cache. */
struct grub_disk_cache
{
enum grub_disk_dev_id dev_id;
unsigned long disk_id;
grub_disk_addr_t sector;
char *data;
int lock;
};
extern struct grub_disk_cache EXPORT_VAR(grub_disk_cache_table)[GRUB_DISK_CACHE_NUM];
#if defined (GRUB_UTIL)
void grub_lvm_init (void);
void grub_ldm_init (void);
void grub_mdraid09_init (void);
void grub_mdraid1x_init (void);
void grub_diskfilter_init (void);
void grub_lvm_fini (void);
void grub_ldm_fini (void);
void grub_mdraid09_fini (void);
void grub_mdraid1x_fini (void);
void grub_diskfilter_fini (void);
#endif
#endif /* ! GRUB_DISK_HEADER */

@ -28,6 +28,17 @@
#define VENTOY_GUID { 0x77772020, 0x2e77, 0x6576, { 0x6e, 0x74, 0x6f, 0x79, 0x2e, 0x6e, 0x65, 0x74 }}
typedef enum ventoy_fs_type
{
ventoy_fs_exfat = 0, /* 0: exfat */
ventoy_fs_ntfs, /* 1: NTFS */
ventoy_fs_ext, /* 2: ext2/ext3/ext4 */
ventoy_fs_xfs, /* 3: XFS */
ventoy_fs_udf, /* 4: UDF */
ventoy_fs_max
}ventoy_fs_type;
#pragma pack(1)
typedef struct ventoy_guid

Binary file not shown.

Binary file not shown.

@ -9,12 +9,16 @@ fi
. ./tool/ventoy_lib.sh
print_usage() {
echo 'Usage: VentoyInstaller.sh OPTION /dev/sdX'
echo ' OPTION:'
echo 'Usage: Ventoy2Disk.sh CMD [ OPTION ] /dev/sdX'
echo ' CMD:'
echo ' -i install ventoy to sdX (fail if disk already installed with ventoy)'
echo ' -u update ventoy in sdX'
echo ' -I force install ventoy to sdX (no matter installed or not)'
echo ''
echo ' OPTION: (optional)'
echo ' -s enable secure boot support (default is disabled)'
echo ''
}
echo ''
@ -38,6 +42,7 @@ while [ -n "$1" ]; do
SECUREBOOT="YES"
else
if ! [ -b "$1" ]; then
vterr "$1 is NOT a valid device"
print_usage
cd $OLDDIR
exit 1
@ -54,13 +59,25 @@ if [ -z "$MODE" ]; then
exit 1
fi
if [ -z "$SUDO_USER" ]; then
if [ "$USER" != "root" ]; then
vterr "EUID is $EUID root permission is required."
echo ''
cd $OLDDIR
exit 1
fi
if ! [ -b "$DISK" ]; then
vterr "Disk $DISK does not exist"
cd $OLDDIR
exit 1
fi
if [ -e /sys/class/block/${DISK#/dev/}/start ]; then
vterr "$DISK is a partition, please use the whole disk"
cd $OLDDIR
exit 1
fi
if dd if="$DISK" of=/dev/null bs=1 count=1 >/dev/null 2>&1; then
vtdebug "root permission check ok ..."
else
vterr "Failed to access $DISK, maybe root privilege is needed!"
echo ''
cd $OLDDIR
exit 1
fi
vtdebug "MODE=$MODE FORCE=$FORCE"
@ -93,20 +110,6 @@ if ! check_tool_work_ok; then
exit 1
fi
if ! [ -b "$DISK" ]; then
vterr "Disk $DISK does not exist"
cd $OLDDIR
exit 1
fi
if [ -e /sys/class/block/${DISK#/dev/}/start ]; then
vterr "$DISK is a partition, please use the whole disk"
cd $OLDDIR
exit 1
fi
grep "^$DISK" /proc/mounts | while read mtline; do
mtpnt=$(echo $mtline | awk '{print $DISK}')
vtdebug "Trying to umount $mtpnt ..."
@ -242,6 +245,7 @@ if [ "$MODE" = "install" ]; then
rm -f ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
rm -f ./tmp_mnt/EFI/BOOT/grubx64.efi
rm -f ./tmp_mnt/EFI/BOOT/MokManager.efi
rm -f ./tmp_mnt/ENROLL_THIS_KEY_IN_MOKMANAGER.cer
mv ./tmp_mnt/EFI/BOOT/grubx64_real.efi ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
umount ./tmp_mnt
@ -305,6 +309,7 @@ else
rm -f ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
rm -f ./tmp_mnt/EFI/BOOT/grubx64.efi
rm -f ./tmp_mnt/EFI/BOOT/MokManager.efi
rm -f ./tmp_mnt/ENROLL_THIS_KEY_IN_MOKMANAGER.cer
mv ./tmp_mnt/EFI/BOOT/grubx64_real.efi ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
umount ./tmp_mnt

@ -50,6 +50,21 @@ function get_os_type {
fi
}
function vt_check_pe {
unset VT_PE_SUPPORT
if [ -f $1/HBCD_PE.ini ]; then
set ventoy_compatible=YES
set VT_PE_SUPPORT=YES
elif [ -f $1/easyu.flg ]; then
set VT_PE_SUPPORT=YES
elif [ -f $1/USM.ICO ]; then
set VT_PE_SUPPORT=YES
elif [ -d $1/USM_TOOL ]; then
set VT_PE_SUPPORT=YES
fi
}
function locate_initrd {
vt_linux_locate_initrd
@ -62,7 +77,8 @@ function locate_initrd {
function find_wim_file {
unset ventoy_wim_file
for file in "sources/boot.wim" "sources/BOOT.WIM" "Sources/Win10PEx64.WIM" "boot/BOOT.WIM" "winpe_x64.wim"; do
for file in "sources/boot.wim" "sources/BOOT.WIM" "Sources/Win10PEx64.WIM" "boot/BOOT.WIM" \
"winpe_x64.wim" "boot/10pex64.wim" "BOOT/USM1PE6L.WIM" "BOOT/USM1PE6F.WIM"; do
if [ -e $1/$file ]; then
set ventoy_wim_file=$1/$file
break
@ -114,6 +130,8 @@ function distro_specify_initrd_file_phase2 {
vt_linux_specify_initrd_file /isolinux/initramfs
elif [ -f (loop)/boot/iniramfs.igz ]; then
vt_linux_specify_initrd_file /boot/iniramfs.igz
elif [ -f (loop)/initrd-x86_64 ]; then
vt_linux_specify_initrd_file /initrd-x86_64
fi
}
@ -248,10 +266,11 @@ function uefi_iso_menu_func {
vt_img_sector ${1}${chosen_path}
if [ "$vtoy_os" = "Windows" ]; then
if [ "$ventoy_fs_probe" = "iso9660" ]; then
set ventoy_compatible=YES
elif [ -f (loop)/HBCD_PE.ini ]; then
set ventoy_compatible=YES
vt_check_pe (loop)
if [ "$VT_PE_SUPPORT" != "YES" ]; then
if [ "$ventoy_fs_probe" = "iso9660" ]; then
set ventoy_compatible=YES
fi
fi
uefi_windows_menu_func $1 ${chosen_path}
@ -293,8 +312,7 @@ function legacy_windows_menu_func {
fi
if [ -n "$vtoy_chain_mem_addr" ]; then
linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft
initrd16 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
boot
else
echo "chain empty failed"
@ -349,9 +367,8 @@ function legacy_linux_menu_func {
sleep 5
fi
if [ -n "$vtoy_chain_mem_addr" ]; then
linux16 $vtoy_path/ipxe.krn ${vtdebug_flag}
initrd16 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
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"
@ -389,10 +406,11 @@ function legacy_iso_menu_func {
vt_img_sector ${1}${chosen_path}
if [ "$vtoy_os" = "Windows" ]; then
if [ "$ventoy_fs_probe" = "iso9660" ]; then
set ventoy_compatible=YES
elif [ -f (loop)/HBCD_PE.ini ]; then
set ventoy_compatible=YES
vt_check_pe (loop)
if [ "$VT_PE_SUPPORT" != "YES" ]; then
if [ "$ventoy_fs_probe" = "iso9660" ]; then
set ventoy_compatible=YES
fi
fi
legacy_windows_menu_func $1 ${chosen_path}
@ -435,7 +453,7 @@ function common_menuentry {
#############################################################
#############################################################
set VENTOY_VERSION="1.0.09"
set VENTOY_VERSION="1.0.9Y"
# Default menu display mode, you can change it as you want.

Binary file not shown.

@ -14,16 +14,6 @@ ventoy_true() {
}
ventoy_is_linux64() {
if [ -e /lib64 ]; then
ventoy_true
return
fi
if [ -e /usr/lib64 ]; then
ventoy_true
return
fi
if uname -a | egrep -q 'x86_64|amd64'; then
ventoy_true
return
@ -165,12 +155,12 @@ is_disk_contains_ventoy() {
return
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
vtdebug "part1 type is $PART2_TYPE not 07"
ventoy_false
return
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
# vtdebug "part1 type is $PART2_TYPE not 07"
# ventoy_false
# return
# fi
if [ -e /sys/class/block/${PART1#/dev/}/start ]; then
PART1_START=$(cat /sys/class/block/${PART1#/dev/}/start)

Binary file not shown.

Binary file not shown.

@ -117,6 +117,10 @@ static void cmdline_strip ( char *cmdline, const char *cruft ) {
*/
static int cmdline_init ( void ) {
userptr_t cmdline_user;
userptr_t chainaddr;
char *pos1;
char *pos2;
int chainlen;
char *cmdline;
size_t len;
int rc;
@ -129,6 +133,23 @@ static int cmdline_init ( void ) {
cmdline_user = phys_to_user ( cmdline_phys );
len = ( strlen_user ( cmdline_user, 0 ) + 1 /* NUL */ );
pos1 = strstr((char *)cmdline_user, "mem:");
if (pos1)
{
pos2 = strstr(pos1, ":size:");
if (pos2)
{
*pos2 = 0;
chainaddr = phys_to_user(strtoul(pos1 + 4 + 2, NULL, 16)); // skip 0x prefix in hex number
chainlen = (int)strtoul(pos2 + 6, NULL, 10);
*pos2 = ':';
g_initrd_addr = (void *)umalloc(chainlen);
g_initrd_len = chainlen;
memcpy_user((userptr_t)g_initrd_addr, 0, chainaddr, 0, chainlen);
}
}
/* Allocate and copy command line */
cmdline_copy = malloc ( len );
if ( ! cmdline_copy ) {
@ -137,6 +158,9 @@ static int cmdline_init ( void ) {
rc = -ENOMEM;
goto err_alloc_cmdline_copy;
}
g_cmdline_copy = cmdline_copy;
cmdline = cmdline_copy;
copy_from_user ( cmdline, cmdline_user, 0, len );
DBGC ( colour, "RUNTIME found command line \"%s\" at %08x\n",
@ -221,11 +245,6 @@ static int initrd_init ( void ) {
memcpy_user ( image->data, 0, phys_to_user ( initrd_phys ), 0,
initrd_len );
g_initrd_addr = (void *)image->data;
g_initrd_len = image->len;
g_cmdline_copy = cmdline_copy;
/* Mark initrd as consumed */
initrd_phys = 0;

@ -126,11 +126,8 @@ void hide_umalloc ( physaddr_t start, physaddr_t end ) {
*
*/
void hide_textdata ( void ) {
/* Deleted by longpanda */
#if 0
hide_region ( &hidemem_textdata, virt_to_phys ( _textdata ),
virt_to_phys ( _etextdata ) );
#endif
}
/**

Binary file not shown.

@ -130,8 +130,7 @@ static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes)
PartStartSector = 2048;
PartSectorCount = (UINT32)((SizeBytes - VENTOY_EFI_PART_SIZE - SIZE_1MB) / 512);
if (MBR.PartTbl[0].FsFlag != 0x07 ||
MBR.PartTbl[0].StartSectorId != PartStartSector ||
if (MBR.PartTbl[0].StartSectorId != PartStartSector ||
MBR.PartTbl[0].SectorCount != PartSectorCount)
{
Log("Part1 not match %u %u", PartStartSector, PartSectorCount);

@ -43,6 +43,17 @@ typedef unsigned char uint8_t;
#define VENTOY_GUID { 0x77772020, 0x2e77, 0x6576, { 0x6e, 0x74, 0x6f, 0x79, 0x2e, 0x6e, 0x65, 0x74 }}
typedef enum ventoy_fs_type
{
ventoy_fs_exfat = 0, /* 0: exfat */
ventoy_fs_ntfs, /* 1: NTFS */
ventoy_fs_ext, /* 2: ext2/ext3/ext4 */
ventoy_fs_xfs, /* 3: XFS */
ventoy_fs_udf, /* 4: UDF */
ventoy_fs_max
}ventoy_fs_type;
#pragma pack(1)
typedef struct ventoy_guid
@ -130,6 +141,11 @@ static int verbose = 0;
static ventoy_guid vtoy_guid = VENTOY_GUID;
static const char *g_ventoy_fs[ventoy_fs_max] =
{
"exfat", "ntfs", "ext*", "xfs", "udf"
};
static int vtoy_check_os_param(ventoy_os_param *param)
{
uint32_t i;
@ -410,14 +426,10 @@ static int vtoy_print_os_param(ventoy_os_param *param, char *diskname)
cnt = vtoy_find_disk_by_guid(param->vtoy_disk_guid, diskname);
debug("find 0 disk by size, try with guid cnt=%d...\n", cnt);
}
if (param->vtoy_disk_part_type == 0)
{
fs = "exfat";
}
else if (param->vtoy_disk_part_type == 0)
if (param->vtoy_disk_part_type < ventoy_fs_max)
{
fs = "ntfs";
fs = g_ventoy_fs[param->vtoy_disk_part_type];
}
else
{

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save