mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-05-30 06:45:40 -04:00
1. Add new options for Windows CLI mode.
2. Add tip message for 4k native disk.
This commit is contained in:
parent
e0132ac4b5
commit
4df793e021
46 changed files with 509 additions and 76 deletions
|
@ -137,6 +137,7 @@ typedef struct ventoy_disk
|
|||
char disk_model[256]; // Sandisk/Kingston ...
|
||||
char human_readable_size[32];
|
||||
|
||||
int is4kn;
|
||||
int major;
|
||||
int minor;
|
||||
int type;
|
||||
|
|
|
@ -260,6 +260,33 @@ static int ventoy_is_possible_blkdev(const char *name)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int ventoy_is_disk_4k_native(const char *disk)
|
||||
{
|
||||
int fd;
|
||||
int rc = 0;
|
||||
int logsector = 0;
|
||||
int physector = 0;
|
||||
char diskpath[256] = {0};
|
||||
|
||||
snprintf(diskpath, sizeof(diskpath) - 1, "/dev/%s", disk);
|
||||
|
||||
fd = open(diskpath, O_RDONLY | O_BINARY);
|
||||
if (fd >= 0)
|
||||
{
|
||||
ioctl(fd, BLKSSZGET, &logsector);
|
||||
ioctl(fd, BLKPBSZGET, &physector);
|
||||
|
||||
if (logsector == 4096 && physector == 4096)
|
||||
{
|
||||
rc = 1;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
vdebug("is 4k native disk <%s> <%d>\n", disk, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
uint64_t ventoy_get_disk_size_in_byte(const char *disk)
|
||||
{
|
||||
int fd;
|
||||
|
@ -591,6 +618,7 @@ int ventoy_get_disk_info(const char *name, ventoy_disk *info)
|
|||
scnprintf(info->part2_path, "/dev/%s2", name);
|
||||
}
|
||||
|
||||
info->is4kn = ventoy_is_disk_4k_native(name);
|
||||
info->size_in_byte = ventoy_get_disk_size_in_byte(name);
|
||||
|
||||
ventoy_get_disk_devnum(name, &info->major, &info->minor);
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
#define VTOY_JSON_NOT_READY_RET "{ \"result\" : \"notready\" }"
|
||||
#define VTOY_JSON_NOT_SUPPORT_RET "{ \"result\" : \"notsupport\" }"
|
||||
#define VTOY_JSON_MBR_2TB_RET "{ \"result\" : \"mbr2tb\" }"
|
||||
#define VTOY_JSON_4KN_RET "{ \"result\" : \"4kn\" }"
|
||||
#define VTOY_JSON_INVALID_RSV_RET "{ \"result\" : \"reserve_invalid\" }"
|
||||
#define VTOY_JSON_FILE_NOT_FOUND_RET "{ \"result\" : \"file_not_found\" }"
|
||||
|
||||
|
|
|
@ -579,3 +579,68 @@ int ventoy_fill_mbr(uint64_t size, uint64_t reserve, int align4k, MBR_HEAD *pMBR
|
|||
return 0;
|
||||
}
|
||||
|
||||
int ventoy_fill_mbr_4k(uint64_t size, uint64_t reserve, int align4k, MBR_HEAD *pMBR)
|
||||
{
|
||||
ventoy_guid Guid;
|
||||
uint32_t DiskSignature;
|
||||
uint32_t DiskSectorCount;
|
||||
uint32_t PartSectorCount;
|
||||
uint32_t PartStartSector;
|
||||
uint32_t ReservedSector;
|
||||
|
||||
VentoyGetLocalBootImg(pMBR);
|
||||
|
||||
ventoy_gen_preudo_uuid(&Guid);
|
||||
|
||||
memcpy(&DiskSignature, &Guid, sizeof(uint32_t));
|
||||
|
||||
vdebug("Disk signature: 0x%08x\n", DiskSignature);
|
||||
|
||||
memcpy(pMBR->BootCode + 0x1B8, &DiskSignature, 4);
|
||||
memcpy(pMBR->BootCode + 0x180, &Guid, 16);
|
||||
|
||||
if (size / 4096 > 0xFFFFFFFF)
|
||||
{
|
||||
DiskSectorCount = 0xFFFFFFFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
DiskSectorCount = (uint32_t)(size / 4096);
|
||||
}
|
||||
|
||||
if (reserve <= 0)
|
||||
{
|
||||
ReservedSector = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ReservedSector = (uint32_t)(reserve / 4096);
|
||||
}
|
||||
|
||||
// check aligned with 4KB
|
||||
vdebug("no need to align with 4KB for 4K native disk\n");
|
||||
|
||||
vlog("ReservedSector: %u\n", ReservedSector);
|
||||
|
||||
//Part1
|
||||
PartStartSector = VTOYIMG_PART_START_SECTOR >> 3;
|
||||
PartSectorCount = DiskSectorCount - ReservedSector - VTOYEFI_PART_BYTES / 4096 - PartStartSector;
|
||||
VentoyFillMBRLocation(size, PartStartSector, PartSectorCount, pMBR->PartTbl);
|
||||
|
||||
pMBR->PartTbl[0].Active = 0x80; // bootable
|
||||
pMBR->PartTbl[0].FsFlag = 0x07; // exFAT/NTFS/HPFS
|
||||
|
||||
//Part2
|
||||
PartStartSector += PartSectorCount;
|
||||
PartSectorCount = VTOYEFI_PART_BYTES / 4096;
|
||||
VentoyFillMBRLocation(size, PartStartSector, PartSectorCount, pMBR->PartTbl + 1);
|
||||
|
||||
pMBR->PartTbl[1].Active = 0x00;
|
||||
pMBR->PartTbl[1].FsFlag = 0xEF; // EFI System Partition
|
||||
|
||||
pMBR->Byte55 = 0x55;
|
||||
pMBR->ByteAA = 0xAA;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ const char * ventoy_get_local_version(void);
|
|||
int ventoy_fill_gpt(uint64_t size, uint64_t reserve, int align4k, VTOY_GPT_INFO *gpt);
|
||||
int ventoy_fill_mbr(uint64_t size, uint64_t reserve, int align4k, MBR_HEAD *pMBR);
|
||||
int VentoyGetLocalBootImg(MBR_HEAD *pMBR);
|
||||
int ventoy_fill_mbr_4k(uint64_t size, uint64_t reserve, int align4k, MBR_HEAD *pMBR);
|
||||
|
||||
#endif /* __VENTOY_UTIL_H__ */
|
||||
|
||||
|
|
|
@ -661,6 +661,12 @@ void on_button_install_clicked(GtkWidget *widget, gpointer data)
|
|||
|
||||
cur = g_disk_list + active;
|
||||
|
||||
if (cur->is4kn)
|
||||
{
|
||||
msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "STR_4KN_UNSUPPORTED");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ventoy_code_get_cur_part_style() == 0 && cur->size_in_byte > 2199023255552ULL)
|
||||
{
|
||||
msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "STR_DISK_2TB_MBR_ERROR");
|
||||
|
|
|
@ -512,6 +512,14 @@ void Ventoy2DiskWindow::on_ButtonInstall_clicked()
|
|||
}
|
||||
|
||||
cur = g_disk_list + index;
|
||||
|
||||
if (cur->is4kn)
|
||||
{
|
||||
lang_string("STR_4KN_UNSUPPORTED", msg);
|
||||
QMessageBox::critical(NULL, title_err, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ventoy_code_get_cur_part_style() == 0 && cur->size_in_byte > 2199023255552ULL)
|
||||
{
|
||||
lang_string("STR_DISK_2TB_MBR_ERROR", msg);
|
||||
|
|
|
@ -1122,6 +1122,13 @@ static int ventoy_api_install(struct mg_connection *conn, VTOY_JSON *json)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (disk->is4kn)
|
||||
{
|
||||
vlog("disk %s is 4k native, not supported.\n", diskname);
|
||||
ventoy_json_result(conn, VTOY_JSON_4KN_RET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
scnprintf(path, "/sys/block/%s", diskname);
|
||||
if (access(path, F_OK) < 0)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue