1. Add new options for Windows CLI mode.

2. Add tip message for 4k native disk.
This commit is contained in:
longpanda 2023-01-13 20:55:40 +08:00
parent e0132ac4b5
commit 4df793e021
46 changed files with 509 additions and 76 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -194,6 +194,19 @@ if [ "$MODE" = "install" -a -z "$NONDESTRUCTIVE" ]; then
fi
fi
if [ "$PARTTOOL" = "parted" ]; then
if parted $DISK p | grep -i -q 'sector size.*4096.*4096'; then
vterr "Currently Ventoy does not support 4K native device."
exit 1
fi
else
if fdisk -l $DISK | grep -i -q 'sector size.*4096.*4096'; then
vterr "Currently Ventoy does not support 4K native device."
exit 1
fi
fi
version=$(get_disk_ventoy_version $DISK)
if [ $? -eq 0 ]; then
if [ -z "$FORCE" ]; then

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -492,7 +492,7 @@ format_ventoy_disk_gpt() {
for i in 0 1 2 3 4 5 6 7 8 9; do
check_umount_disk "$PART2"
if mkfs.vfat -F 16 -n VTOYEFI $PART2; then
if mkfs.vfat -F 16 -n VTOYEFI -s 1 $PART2; then
echo 'success'
break
else

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -169,8 +169,27 @@ sed 's/.*SCRIPT_DEL_THIS \(.*\)/\1/g' -i $tmpdir/WebUI/index.html
#32MB disk img
dd status=none if=$LOOP of=$tmpdir/ventoy/ventoy.disk.img bs=512 count=$VENTOY_SECTOR_NUM skip=$part2_start_sector
#4k image
# echo "make 4K img ..."
# dd status=none if=/dev/zero of=$tmpdir/ventoy/ventoy_4k.disk.img bs=1M count=32
# mkfs.vfat -F 16 -n VTOYEFI -s 1 -S 4096 $tmpdir/ventoy/ventoy_4k.disk.img
# vDIR1=$(mktemp -d)
# vDIR2=$(mktemp -d)
# mount $tmpdir/ventoy/ventoy.disk.img $vDIR1
# mount $tmpdir/ventoy/ventoy_4k.disk.img $vDIR2
# cp -a $vDIR1/* $vDIR2/
# umount $vDIR1
# umount $vDIR2
# rm -rf $vDIR1 $vDIR2
# xz --check=crc32 $tmpdir/ventoy/ventoy_4k.disk.img
xz --check=crc32 $tmpdir/ventoy/ventoy.disk.img
losetup -d $LOOP && rm -f img.bin
rm -f ventoy-${curver}-linux.tar.gz

View File

@ -60,6 +60,7 @@
"STR_PART_CLUSTER":"حجم الكتلة",
"STR_PART_CLUSTER_DEFAULT":"القيمة الافتراضية للنظام",
"STR_DONATE":"يتبرع",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -124,6 +125,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"Ianə",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -188,6 +190,7 @@
"STR_PART_CLUSTER":"클러스터 크기",
"STR_PART_CLUSTER_DEFAULT":"시스템 기본값",
"STR_DONATE":"기부",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -252,6 +255,7 @@
"STR_PART_CLUSTER":"簇大小",
"STR_PART_CLUSTER_DEFAULT":"系统默认值",
"STR_DONATE":"捐助",
"STR_4KN_UNSUPPORTED":"目前 Ventoy 不支持原生 4K 扇区的磁盘。",
"STRXXX":""
},
@ -316,6 +320,7 @@
"STR_PART_CLUSTER":"Klynge størrelse",
"STR_PART_CLUSTER_DEFAULT":"System Standard Værdi",
"STR_DONATE":"Donering",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -380,6 +385,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"Donate",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -444,6 +450,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"შემოწირულობა",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX": ""
},
@ -508,6 +515,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"اهداء",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -572,6 +580,7 @@
"STR_PART_CLUSTER":"Wielkość klastra",
"STR_PART_CLUSTER_DEFAULT":"Wartość domyślna systemu",
"STR_DONATE":"Podarować",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -636,6 +645,7 @@
"STR_PART_CLUSTER":"Tamanho do cluster",
"STR_PART_CLUSTER_DEFAULT":"Valor padrão do sistema",
"STR_DONATE":"Doar",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -700,6 +710,7 @@
"STR_PART_CLUSTER":"Sektör Boyutu",
"STR_PART_CLUSTER_DEFAULT":"Sistem varsayılan değeri",
"STR_DONATE":"Ventoy'a Bağış yap",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -764,6 +775,7 @@
"STR_PART_CLUSTER":"Clustergröße",
"STR_PART_CLUSTER_DEFAULT":"Systemstandardwert",
"STR_DONATE":"Spenden",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -828,6 +840,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"Donate",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -892,6 +905,7 @@
"STR_PART_CLUSTER":"Taille de cluster",
"STR_PART_CLUSTER_DEFAULT":"Valeur par défaut du système",
"STR_DONATE":"Faire un don",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -956,6 +970,7 @@
"STR_PART_CLUSTER":"Velikost clusteru",
"STR_PART_CLUSTER_DEFAULT":"Výchozí hodnota systému",
"STR_DONATE":"Darovat",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -1019,6 +1034,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"Darovať",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -1083,6 +1099,7 @@
"STR_PART_CLUSTER":"Tamaño de cluster",
"STR_PART_CLUSTER_DEFAULT":"Valor predeterminado del sistema",
"STR_DONATE":"Donar",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -1147,6 +1164,7 @@
"STR_PART_CLUSTER":"Tamaño de cluster",
"STR_PART_CLUSTER_DEFAULT":"Valor predeterminado del sistema",
"STR_DONATE":"Donar",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -1211,6 +1229,7 @@
"STR_PART_CLUSTER":"Размер кластера:",
"STR_PART_CLUSTER_DEFAULT":"Системное значение по умолчанию",
"STR_DONATE":"Пожертвовать",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -1275,6 +1294,7 @@
"STR_PART_CLUSTER":"ক্লাস্টারের আকার",
"STR_PART_CLUSTER_DEFAULT":"সিস্টেমের ডিফল্ট মান",
"STR_DONATE":"দান করুন",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -1339,6 +1359,7 @@
"STR_PART_CLUSTER":"क्लस्टर साइज",
"STR_PART_CLUSTER_DEFAULT":"सिस्टम डिफ़ॉल्ट मान",
"STR_DONATE":"दान करें",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -1403,6 +1424,7 @@
"STR_PART_CLUSTER":"Clustergrootte",
"STR_PART_CLUSTER_DEFAULT":"Standaardwaarde systeem",
"STR_DONATE":"Doneer",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -1467,6 +1489,7 @@
"STR_PART_CLUSTER":"Dimensiunea clusterului",
"STR_PART_CLUSTER_DEFAULT":"Valoarea implicită a sistemului",
"STR_DONATE":"Donează",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -1531,6 +1554,7 @@
"STR_PART_CLUSTER":"クラスターサイズ",
"STR_PART_CLUSTER_DEFAULT":"システムのデフォルト値",
"STR_DONATE":"寄付",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -1595,6 +1619,7 @@
"STR_PART_CLUSTER":"Dimensione del cluster",
"STR_PART_CLUSTER_DEFAULT":"Valore predefinito di sistema",
"STR_DONATE":"Donare",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -1659,6 +1684,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"Donirajte",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -1723,6 +1749,7 @@
"STR_PART_CLUSTER":"Klaszter méret",
"STR_PART_CLUSTER_DEFAULT":"Rendszer alapérték",
"STR_DONATE":"Adományoz",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -1787,6 +1814,7 @@
"STR_PART_CLUSTER":"簇的大小",
"STR_PART_CLUSTER_DEFAULT":"系統默認值",
"STR_DONATE":"捐助",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -1851,6 +1879,7 @@
"STR_PART_CLUSTER":"Veličina klastera",
"STR_PART_CLUSTER_DEFAULT":"Podrazumevana sistemska vrednost",
"STR_DONATE":"Donirajte",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -1915,6 +1944,7 @@
"STR_PART_CLUSTER":"Величина кластера",
"STR_PART_CLUSTER_DEFAULT":"Подразумевана системска вредност",
"STR_DONATE":"Донирајте",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -1979,6 +2009,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"บริจาค",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -2043,6 +2074,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"donere",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -2107,6 +2139,7 @@
"STR_PART_CLUSTER":"Cỡ Cluster",
"STR_PART_CLUSTER_DEFAULT":"Theo mặc định hệ thống",
"STR_DONATE":"Thưởng tác giả",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -2171,6 +2204,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"paaukoti",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -2235,6 +2269,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"донира",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -2299,6 +2334,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"לִתְרוֹם",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -2363,6 +2399,7 @@
"STR_PART_CLUSTER":"Tamanho do cluster",
"STR_PART_CLUSTER_DEFAULT":"Valor predefinido do sistema",
"STR_DONATE":"Doar",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -2427,6 +2464,7 @@
"STR_PART_CLUSTER":"Ukuran Kelompok",
"STR_PART_CLUSTER_DEFAULT":"Nilai Standar Sistem",
"STR_DONATE":"Donasi sukarela",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -2491,6 +2529,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"Donere",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -2555,6 +2594,7 @@
"STR_PART_CLUSTER":"Розмір кластера",
"STR_PART_CLUSTER_DEFAULT":"Системне значення за умовчанням",
"STR_DONATE":"Пожертвуйте",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -2619,6 +2659,7 @@
"STR_PART_CLUSTER":"Μέγεθος συμπλέγματος",
"STR_PART_CLUSTER_DEFAULT":"Προεπιλεγμένη τιμή συστήματος",
"STR_DONATE":"Προσφέρω",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -2684,6 +2725,7 @@
"STR_PART_CLUSTER":"Klusterstorlek",
"STR_PART_CLUSTER_DEFAULT":"Systemets standardvärde",
"STR_DONATE":"Donera",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -2748,6 +2790,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"Donirajte",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -2812,6 +2855,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"Дарете",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -2876,6 +2920,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"Նվիրաբերել",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -2940,6 +2985,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"Lahjoittaa",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -3004,6 +3050,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"Doa",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -3068,6 +3115,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"Donar",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -3133,6 +3181,7 @@
"STR_PART_CLUSTER":"Cluster Size",
"STR_PART_CLUSTER_DEFAULT":"System Default Value",
"STR_DONATE":"შემოწირულობა",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -3197,6 +3246,7 @@
"STR_PART_CLUSTER":"கொத்து அளவு",
"STR_PART_CLUSTER_DEFAULT":"கணினி இயல்புநிலை மதிப்பு",
"STR_DONATE":"தானம் செய்",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
},
@ -3261,6 +3311,7 @@
"STR_PART_CLUSTER":"Памер кластара",
"STR_PART_CLUSTER_DEFAULT":"Сістэмнае значэнне па змаўчанні",
"STR_DONATE":"Ахвяраваць",
"STR_4KN_UNSUPPORTED":"Currently Ventoy does not support 4K native device.",
"STRXXX":""
}

View File

@ -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;

View File

@ -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);

View File

@ -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\" }"

View File

@ -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;
}

View File

@ -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__ */

View File

@ -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");

View File

@ -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);

View File

@ -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)
{

View File

@ -761,6 +761,8 @@
vtoy_in_progress = true;
progressDisableItem(vtoy_in_progress);
queryProgress(1);
}else if (data.result === '4kn') {
ventoy_display_alert('error', vtoy_cur_language.STR_4KN_UNSUPPORTED);
} else {
ventoy_display_alert('error', vtoy_cur_language.STR_INSTALL_FAILED);
}

View File

@ -86,9 +86,10 @@ build_func() {
}
build_func "gcc" '64' 'x86_64' 'gtk2'
build_func "gcc" '64' 'x86_64' 'gtk3'
build_func "gcc" '64' 'x86_64' 'gtk2'
build_func "gcc -m32" '32' 'i386' 'gtk2'
build_func "gcc -m32" '32' 'i386' 'gtk3'

View File

@ -94,6 +94,8 @@ typedef enum STR_ID
STR_DONATE, //54
STR_4KN_UNSUPPORTED, //55
STR_ID_MAX
}STR_ID;

View File

@ -139,7 +139,7 @@ static DWORD GetVentoyVolumeName(int PhyDrive, UINT64 StartSectorId, CHAR *NameB
return Status;
}
static int GetLettersBelongPhyDrive(int PhyDrive, char *DriveLetters, size_t Length)
int GetLettersBelongPhyDrive(int PhyDrive, char *DriveLetters, size_t Length)
{
int n = 0;
DWORD DataSize = 0;
@ -355,6 +355,7 @@ int GetAllPhysicalDriveInfo(PHY_DRIVE_INFO *pDriveList, DWORD *pDriveCount)
STORAGE_PROPERTY_QUERY Query;
STORAGE_DESCRIPTOR_HEADER DevDescHeader;
STORAGE_DEVICE_DESCRIPTOR *pDevDesc;
STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR diskAlignment;
int PhyDriveId[VENTOY_MAX_PHY_DRIVE];
Count = GetPhysicalDriveCount();
@ -468,12 +469,35 @@ int GetAllPhysicalDriveInfo(PHY_DRIVE_INFO *pDriveList, DWORD *pDriveCount)
continue;
}
memset(&Query, 0, sizeof(STORAGE_PROPERTY_QUERY));
Query.PropertyId = StorageAccessAlignmentProperty;
Query.QueryType = PropertyStandardQuery;
memset(&diskAlignment, 0, sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR));
bRet = DeviceIoControl(Handle,
IOCTL_STORAGE_QUERY_PROPERTY,
&Query,
sizeof(STORAGE_PROPERTY_QUERY),
&diskAlignment,
sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR),
&dwBytes,
NULL);
if (!bRet)
{
Log("DeviceIoControl3 error:%u dwBytes:%u", LASTERR, dwBytes);
}
CurDrive->PhyDrive = i;
CurDrive->SizeInBytes = LengthInfo.Length.QuadPart;
CurDrive->DeviceType = pDevDesc->DeviceType;
CurDrive->RemovableMedia = pDevDesc->RemovableMedia;
CurDrive->BusType = pDevDesc->BusType;
CurDrive->BytesPerLogicalSector = diskAlignment.BytesPerLogicalSector;
CurDrive->BytesPerPhysicalSector = diskAlignment.BytesPerPhysicalSector;
if (pDevDesc->VendorIdOffset)
{
safe_strcpy(CurDrive->VendorId, (char *)pDevDesc + pDevDesc->VendorIdOffset);
@ -508,9 +532,10 @@ int GetAllPhysicalDriveInfo(PHY_DRIVE_INFO *pDriveList, DWORD *pDriveCount)
for (i = 0, CurDrive = pDriveList; i < (int)DriveCount; i++, CurDrive++)
{
Log("PhyDrv:%d BusType:%-4s Removable:%u Size:%dGB(%llu) Name:%s %s",
Log("PhyDrv:%d BusType:%-4s Removable:%u Size:%dGB(%llu) Sector:%u/%u Name:%s %s",
CurDrive->PhyDrive, GetBusTypeString(CurDrive->BusType), CurDrive->RemovableMedia,
GetHumanReadableGBSize(CurDrive->SizeInBytes), CurDrive->SizeInBytes,
CurDrive->BytesPerLogicalSector, CurDrive->BytesPerPhysicalSector,
CurDrive->VendorId, CurDrive->ProductId);
}
@ -2351,30 +2376,37 @@ int PartitionResizeForVentoy(PHY_DRIVE_INFO *pPhyDrive)
Sleep(2000);
//Refresh disk list
PhyDrive = pPhyDrive->PhyDrive;
if (g_CLI_Mode)
{
Log("### Ventoy non-destructive CLI installation successfully finished.");
}
else
{
//Refresh disk list
PhyDrive = pPhyDrive->PhyDrive;
Log("#### Now Refresh PhyDrive ####");
Ventoy2DiskDestroy();
Ventoy2DiskInit();
Log("#### Now Refresh PhyDrive ####");
Ventoy2DiskDestroy();
Ventoy2DiskInit();
pPhyDrive = GetPhyDriveInfoByPhyDrive(PhyDrive);
if (pPhyDrive)
{
if (pPhyDrive->VentoyVersion[0] == 0)
{
Log("After process the Ventoy version is still invalid");
goto End;
}
pPhyDrive = GetPhyDriveInfoByPhyDrive(PhyDrive);
if (pPhyDrive)
{
if (pPhyDrive->VentoyVersion[0] == 0)
{
Log("After process the Ventoy version is still invalid");
goto End;
}
Log("### Ventoy non-destructive installation successfully finished <%s>", pPhyDrive->VentoyVersion);
}
else
{
Log("### Ventoy non-destructive installation successfully finished <not found>");
}
Log("### Ventoy non-destructive installation successfully finished <%s>", pPhyDrive->VentoyVersion);
}
else
{
Log("### Ventoy non-destructive installation successfully finished <not found>");
}
InitComboxCtrl(g_DialogHwnd, PhyDrive);
InitComboxCtrl(g_DialogHwnd, PhyDrive);
}
rc = 0;

View File

@ -40,6 +40,56 @@ void TraceOut(const char *Fmt, ...)
}
}
typedef struct LogBuf
{
int Len;
char szBuf[1024];
struct LogBuf* next;
}LogBuf;
static BOOL g_LogCache = FALSE;
static LogBuf* g_LogHead = NULL;
static LogBuf* g_LogTail = NULL;
void LogCache(BOOL cache)
{
g_LogCache = cache;
}
void LogFlush(void)
{
FILE* File = NULL;
LogBuf* Node = NULL;
LogBuf* Next = NULL;
if (g_CLI_Mode)
{
fopen_s(&File, VENTOY_CLI_LOG, "a+");
}
else
{
fopen_s(&File, VENTOY_FILE_LOG, "a+");
}
if (File)
{
for (Node = g_LogHead; Node; Node = Node->next)
{
fwrite(Node->szBuf, 1, Node->Len, File);
fwrite("\n", 1, 1, File);
}
fclose(File);
}
for (Node = g_LogHead; Node; Node = Next)
{
Next = Node->next;
free(Node);
}
g_LogHead = g_LogTail = NULL;
}
void Log(const char *Fmt, ...)
{
va_list Arg;
@ -59,6 +109,30 @@ void Log(const char *Fmt, ...)
Len += vsnprintf_s(szBuf + Len, sizeof(szBuf)-Len - 1, sizeof(szBuf)-Len-1, Fmt, Arg);
va_end(Arg);
if (g_LogCache)
{
LogBuf* Node = NULL;
Node = malloc(sizeof(LogBuf));
if (Node)
{
memcpy(Node->szBuf, szBuf, Len);
Node->next = NULL;
Node->Len = Len;
if (g_LogTail)
{
g_LogTail->next = Node;
g_LogTail = Node;
}
else
{
g_LogHead = g_LogTail = Node;
}
}
return;
}
if (g_CLI_Mode)
{
fopen_s(&File, VENTOY_CLI_LOG, "a+");

View File

@ -176,6 +176,9 @@ typedef struct PHY_DRIVE_INFO
CHAR SerialNumber[128];
STORAGE_BUS_TYPE BusType;
DWORD BytesPerLogicalSector;
DWORD BytesPerPhysicalSector;
CHAR DriveLetters[64];
int VentoyFsClusterSize;
@ -234,6 +237,8 @@ extern int g_FilterUSB;
void TraceOut(const char *Fmt, ...);
void Log(const char *Fmt, ...);
void LogCache(BOOL cache);
void LogFlush(void);
BOOL IsPathExist(BOOL Dir, const char *Fmt, ...);
void DumpWindowsVersion(void);
const CHAR* GetLocalVentoyVersion(void);
@ -370,6 +375,15 @@ BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes, MBR_HEAD* pMBR, UINT64* Pa
int GetVentoyFsNameInPhyDrive(PHY_DRIVE_INFO* CurDrive);
void CLISetReserveSpace(int MB);
void CLI_UpdatePercent(int Pos);
int GetLettersBelongPhyDrive(int PhyDrive, char* DriveLetters, size_t Length);
PHY_DRIVE_INFO* CLI_PhyDrvInfo(void);
#define UTF8_Log(fmt, wstr) \
{\
memset(TmpPathA, 0, sizeof(TmpPathA));\
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, TmpPathA, sizeof(TmpPathA), NULL, NULL);\
Log(fmt, TmpPathA);\
}
#define VTSI_SUPPORT 1

Binary file not shown.

View File

@ -17,12 +17,16 @@ typedef struct CLI_CFG
int PartStyle;
int ReserveMB;
BOOL USBCheck;
BOOL NonDest;
int fstype;
}CLI_CFG;
BOOL g_CLI_Mode = FALSE;
static int g_CLI_OP;
static int g_CLI_PhyDrive;
static PHY_DRIVE_INFO* g_CLI_PhyDrvInfo = NULL;
static int CLI_GetPhyDriveInfo(int PhyDrive, PHY_DRIVE_INFO* pInfo)
{
BOOL bRet;
@ -33,6 +37,7 @@ static int CLI_GetPhyDriveInfo(int PhyDrive, PHY_DRIVE_INFO* pInfo)
STORAGE_PROPERTY_QUERY Query;
STORAGE_DESCRIPTOR_HEADER DevDescHeader;
STORAGE_DEVICE_DESCRIPTOR* pDevDesc;
STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR diskAlignment;
safe_sprintf(PhyDrivePath, "\\\\.\\PhysicalDrive%d", PhyDrive);
Handle = CreateFileA(PhyDrivePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
@ -103,12 +108,35 @@ static int CLI_GetPhyDriveInfo(int PhyDrive, PHY_DRIVE_INFO* pInfo)
return 1;
}
memset(&Query, 0, sizeof(STORAGE_PROPERTY_QUERY));
Query.PropertyId = StorageAccessAlignmentProperty;
Query.QueryType = PropertyStandardQuery;
memset(&diskAlignment, 0, sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR));
bRet = DeviceIoControl(Handle,
IOCTL_STORAGE_QUERY_PROPERTY,
&Query,
sizeof(STORAGE_PROPERTY_QUERY),
&diskAlignment,
sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR),
&dwBytes,
NULL);
if (!bRet)
{
Log("DeviceIoControl3 error:%u dwBytes:%u", LASTERR, dwBytes);
}
pInfo->PhyDrive = PhyDrive;
pInfo->SizeInBytes = LengthInfo.Length.QuadPart;
pInfo->DeviceType = pDevDesc->DeviceType;
pInfo->RemovableMedia = pDevDesc->RemovableMedia;
pInfo->BusType = pDevDesc->BusType;
pInfo->BytesPerLogicalSector = diskAlignment.BytesPerLogicalSector;
pInfo->BytesPerPhysicalSector = diskAlignment.BytesPerPhysicalSector;
if (pDevDesc->VendorIdOffset)
{
safe_strcpy(pInfo->VendorId, (char*)pDevDesc + pDevDesc->VendorIdOffset);
@ -143,12 +171,14 @@ static int CLI_GetPhyDriveInfo(int PhyDrive, PHY_DRIVE_INFO* pInfo)
static int CLI_CheckParam(int argc, char** argv, PHY_DRIVE_INFO* pDrvInfo, CLI_CFG *pCfg)
{
int i;
int fstype = VTOY_FS_EXFAT;
int op = -1;
char* opt = NULL;
int PhyDrive = -1;
int PartStyle = 0;
int ReserveMB = 0;
BOOL USBCheck = TRUE;
BOOL NonDest = FALSE;
MBR_HEAD MBR;
UINT64 Part2GPTAttr = 0;
UINT64 Part2StartSector = 0;
@ -176,6 +206,10 @@ static int CLI_CheckParam(int argc, char** argv, PHY_DRIVE_INFO* pDrvInfo, CLI_C
{
USBCheck = FALSE;
}
else if (_stricmp(opt, "/NonDest") == 0)
{
NonDest = TRUE;
}
else if (_strnicmp(opt, "/Drive:", 7) == 0)
{
Log("Get PhyDrive by logical drive %C:", opt[7]);
@ -189,6 +223,17 @@ static int CLI_CheckParam(int argc, char** argv, PHY_DRIVE_INFO* pDrvInfo, CLI_C
{
ReserveMB = (int)strtol(opt + 3, NULL, 10);
}
else if (_strnicmp(opt, "/FS:", 4) == 0)
{
if (_stricmp(opt + 4, "NTFS") == 0)
{
fstype = VTOY_FS_NTFS;
}
else if (_stricmp(opt + 4, "FAT32") == 0)
{
fstype = VTOY_FS_FAT32;
}
}
}
if (op < 0 || PhyDrive < 0)
@ -197,10 +242,10 @@ static int CLI_CheckParam(int argc, char** argv, PHY_DRIVE_INFO* pDrvInfo, CLI_C
return 1;
}
Log("Ventoy CLI %s PhyDrive:%d %s SecureBoot:%d ReserveSpace:%dMB USBCheck:%u",
Log("Ventoy CLI %s PhyDrive:%d %s SecureBoot:%d ReserveSpace:%dMB USBCheck:%u FS:%s NonDest:%d",
op == 0 ? "install" : "update",
PhyDrive, PartStyle ? "GPT" : "MBR",
g_SecureBoot, ReserveMB, USBCheck
g_SecureBoot, ReserveMB, USBCheck, GetVentoyFsFmtNameByTypeA(fstype), NonDest
);
if (CLI_GetPhyDriveInfo(PhyDrive, pDrvInfo))
@ -231,14 +276,51 @@ static int CLI_CheckParam(int argc, char** argv, PHY_DRIVE_INFO* pDrvInfo, CLI_C
}
}
if (op == 0 && NonDest)
{
GetLettersBelongPhyDrive(PhyDrive, pDrvInfo->DriveLetters, sizeof(pDrvInfo->DriveLetters));
}
pCfg->op = op;
pCfg->PartStyle = PartStyle;
pCfg->ReserveMB = ReserveMB;
pCfg->USBCheck = USBCheck;
pCfg->NonDest = NonDest;
pCfg->fstype = fstype;
return 0;
}
static int Ventoy_CLI_NonDestInstall(PHY_DRIVE_INFO* pDrvInfo, CLI_CFG* pCfg)
{
int rc;
int TryId = 1;
Log("Ventoy_CLI_NonDestInstall start ...");
if (pDrvInfo->BytesPerLogicalSector == 4096 && pDrvInfo->BytesPerPhysicalSector == 4096)
{
Log("Ventoy does not support 4k native disk.");
rc = 1;
goto out;
}
if (!PartResizePreCheck(NULL))
{
Log("#### Part Resize PreCheck Failed ####");
rc = 1;
goto out;
}
rc = PartitionResizeForVentoy(pDrvInfo);
out:
Log("Ventoy_CLI_NonDestInstall [%s]", rc == 0 ? "SUCCESS" : "FAILED");
return rc;
}
static int Ventoy_CLI_Install(PHY_DRIVE_INFO* pDrvInfo, CLI_CFG *pCfg)
{
int rc;
@ -246,11 +328,20 @@ static int Ventoy_CLI_Install(PHY_DRIVE_INFO* pDrvInfo, CLI_CFG *pCfg)
Log("Ventoy_CLI_Install start ...");
if (pDrvInfo->BytesPerLogicalSector == 4096 && pDrvInfo->BytesPerPhysicalSector == 4096)
{
Log("Ventoy does not support 4k native disk.");
rc = 1;
goto out;
}
if (pCfg->ReserveMB > 0)
{
CLISetReserveSpace(pCfg->ReserveMB);
}
SetVentoyFsType(pCfg->fstype);
rc = InstallVentoy2PhyDrive(pDrvInfo, pCfg->PartStyle, TryId++);
if (rc)
{
@ -274,6 +365,9 @@ static int Ventoy_CLI_Install(PHY_DRIVE_INFO* pDrvInfo, CLI_CFG *pCfg)
}
}
SetVentoyFsType(VTOY_FS_EXFAT);
out:
Log("Ventoy_CLI_Install [%s]", rc == 0 ? "SUCCESS" : "FAILED");
return rc;
@ -351,6 +445,11 @@ static void CLI_WriteDoneFile(int ret)
}
}
PHY_DRIVE_INFO* CLI_PhyDrvInfo(void)
{
return g_CLI_PhyDrvInfo;
}
/*
* Ventoy2Disk.exe VTOYCLI { /I | /U } { /Drive:F: | /PhyDrive:1 } /GPT /NoSB /R:4096 /NoUSBCheck
*
@ -364,7 +463,7 @@ int VentoyCLIMain(int argc, char** argv)
DeleteFileA(VENTOY_CLI_PERCENT);
DeleteFileA(VENTOY_CLI_DONE);
pDrvInfo = (PHY_DRIVE_INFO*)malloc(sizeof(PHY_DRIVE_INFO));
g_CLI_PhyDrvInfo = pDrvInfo = (PHY_DRIVE_INFO*)malloc(sizeof(PHY_DRIVE_INFO));
if (!pDrvInfo)
{
goto end;
@ -388,7 +487,16 @@ int VentoyCLIMain(int argc, char** argv)
if (CliCfg.op == 0)
{
ret = Ventoy_CLI_Install(pDrvInfo, &CliCfg);
if (CliCfg.NonDest)
{
ret = Ventoy_CLI_NonDestInstall(pDrvInfo, &CliCfg);
}
else
{
AlertSuppressInit();
SetAlertPromptHookEnable(TRUE);
ret = Ventoy_CLI_Install(pDrvInfo, &CliCfg);
}
}
else
{