diff --git a/INSTALL/README b/INSTALL/README index 2535f490..db836ce6 100644 --- a/INSTALL/README +++ b/INSTALL/README @@ -18,9 +18,8 @@ Please refer https://www.ventoy.net/en/doc_start.html for details. ========== VentoyWeb.sh =============== -sudo sh VentoyWeb.sh -Normally, it will popup a web browser window. -If not you can open your browser and visit http://127.0.0.1:24680 +1. sudo sh VentoyWeb.sh +2. open your browser and visit http://127.0.0.1:24680 diff --git a/INSTALL/Ventoy2Disk.exe b/INSTALL/Ventoy2Disk.exe index 770a8b1b..d831232b 100644 Binary files a/INSTALL/Ventoy2Disk.exe and b/INSTALL/Ventoy2Disk.exe differ diff --git a/INSTALL/VentoyWeb.sh b/INSTALL/VentoyWeb.sh index bb6a910a..721e419a 100644 --- a/INSTALL/VentoyWeb.sh +++ b/INSTALL/VentoyWeb.sh @@ -97,6 +97,11 @@ if [ -f ./tool/$TOOLDIR/V2DServer.xz ]; then chmod +x ./tool/$TOOLDIR/V2DServer fi + +V2DServer "$HOST" "$PORT" & +wID=$! +sleep 1 + vtVer=$(cat ventoy/version) echo "" echo "===============================================================" @@ -112,7 +117,7 @@ echo "" echo "################## Press Ctrl + C to exit #####################" echo "" -V2DServer "$HOST" "$PORT" +wait $wID if [ -n "$OLDDIR" ]; then CURDIR=$(pwd) diff --git a/INSTALL/grub/grub.cfg b/INSTALL/grub/grub.cfg index a7d44ca3..3f44dad5 100644 --- a/INSTALL/grub/grub.cfg +++ b/INSTALL/grub/grub.cfg @@ -1546,7 +1546,7 @@ function img_unsupport_menuentry { ############################################################# ############################################################# -set VENTOY_VERSION="1.0.35" +set VENTOY_VERSION="1.0.36" #ACPI not compatible with Window7/8, so disable by default set VTOY_PARAM_NO_ACPI=1 diff --git a/INSTALL/tool/VentoyWorker.sh b/INSTALL/tool/VentoyWorker.sh index ac2102c8..c820ffc4 100644 --- a/INSTALL/tool/VentoyWorker.sh +++ b/INSTALL/tool/VentoyWorker.sh @@ -125,11 +125,7 @@ if [ "$MODE" = "list" ]; then fi #check mountpoint -grep "^$DISK" /proc/mounts | while read mtline; do - mtpnt=$(echo $mtline | awk '{print $2}') - vtdebug "Trying to umount $mtpnt ..." - umount $mtpnt >/dev/null 2>&1 -done +check_umount_disk "$DISK" if grep "$DISK" /proc/mounts; then vterr "$DISK is already mounted, please umount it first!" @@ -299,6 +295,9 @@ if [ "$MODE" = "install" ]; then xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1 fi + # check and umount + check_umount_disk "$DISK" + xzcat ./ventoy/ventoy.disk.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start_sector #test UUID @@ -317,10 +316,7 @@ if [ "$MODE" = "install" ]; then vtinfo "esp partition processing ..." sleep 1 - mtpnt=$(grep "^${PART2}" /proc/mounts | awk '{print $2}') - if [ -n "$mtpnt" ]; then - umount $mtpnt >/dev/null 2>&1 - fi + check_umount_disk "$DISK" if [ "$SECUREBOOT" != "YES" ]; then mkdir ./tmp_mnt @@ -332,10 +328,7 @@ if [ "$MODE" = "install" ]; then break fi - mtpnt=$(grep "^${PART2}" /proc/mounts | awk '{print $2}') - if [ -n "$mtpnt" ]; then - umount $mtpnt >/dev/null 2>&1 - fi + check_umount_disk "$DISK" sleep 2 done @@ -349,6 +342,8 @@ if [ "$MODE" = "install" ]; then mv ./tmp_mnt/EFI/BOOT/grubx64_real.efi ./tmp_mnt/EFI/BOOT/BOOTX64.EFI mv ./tmp_mnt/EFI/BOOT/grubia32_real.efi ./tmp_mnt/EFI/BOOT/BOOTIA32.EFI + sync + for tt in 1 2 3; do if umount ./tmp_mnt; then vtdebug "umount part2 success" @@ -439,15 +434,19 @@ else dd status=none conv=fsync if=./rsvdata.bin seek=2040 bs=512 count=8 of=${DISK} rm -f ./rsvdata.bin + check_umount_disk "$DISK" + xzcat ./ventoy/ventoy.disk.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start sync - + if [ "$SECUREBOOT" != "YES" ]; then mkdir ./tmp_mnt vtdebug "mounting part2 ...." - for tt in 1 2 3 4 5; do + for tt in 1 2 3 4 5; do + check_umount_disk "$DISK" + if mount ${PART2} ./tmp_mnt > /dev/null 2>&1; then vtdebug "mounting part2 success" break @@ -467,6 +466,7 @@ else mv ./tmp_mnt/EFI/BOOT/grubx64_real.efi ./tmp_mnt/EFI/BOOT/BOOTX64.EFI mv ./tmp_mnt/EFI/BOOT/grubia32_real.efi ./tmp_mnt/EFI/BOOT/BOOTIA32.EFI + sync for tt in 1 2 3; do if umount ./tmp_mnt > /dev/null 2>&1; then diff --git a/INSTALL/tool/ventoy_lib.sh b/INSTALL/tool/ventoy_lib.sh index c108197a..a394eb14 100644 --- a/INSTALL/tool/ventoy_lib.sh +++ b/INSTALL/tool/ventoy_lib.sh @@ -97,6 +97,14 @@ get_disk_part_name() { fi } +check_umount_disk() { + DiskOrPart="$1" + grep "^${DiskOrPart}" /proc/mounts | while read mtline; do + mtpnt=$(echo $mtline | awk '{print $2}') + vtdebug "Trying to umount $mtpnt ..." + umount $mtpnt >/dev/null 2>&1 + done +} get_ventoy_version_from_cfg() { if grep -q 'set.*VENTOY_VERSION=' $1; then @@ -218,6 +226,14 @@ format_ventoy_disk_mbr() { fi part2_start_sector=$(expr $part1_end_sector + 1) + + modsector=$(expr $part2_start_sector % 8) + if [ $modsector -gt 0 ]; then + vtdebug "modsector:$modsector need to be aligned with 4KB" + part1_end_sector=$(expr $part1_end_sector - $modsector) + part2_start_sector=$(expr $part1_end_sector + 1) + fi + part2_end_sector=$(expr $part2_start_sector + $VENTOY_SECTOR_NUM - 1) export part2_start_sector @@ -302,6 +318,8 @@ EOF echo "create efi fat fs $PART2 ..." 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 echo 'success' break @@ -333,6 +351,14 @@ format_ventoy_disk_gpt() { fi part2_start_sector=$(expr $part1_end_sector + 1) + + modsector=$(expr $part2_start_sector % 8) + if [ $modsector -gt 0 ]; then + vtdebug "modsector:$modsector need to be aligned with 4KB" + part1_end_sector=$(expr $part1_end_sector - $modsector) + part2_start_sector=$(expr $part1_end_sector + 1) + fi + part2_end_sector=$(expr $part2_start_sector + $VENTOY_SECTOR_NUM - 1) export part2_start_sector @@ -397,7 +423,10 @@ format_ventoy_disk_gpt() { fi echo "create efi fat fs $PART2 ..." + 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 echo 'success' break diff --git a/LinuxGUI/Ventoy2Disk/Core/ventoy_disk.c b/LinuxGUI/Ventoy2Disk/Core/ventoy_disk.c index 4d0871b8..4df2040e 100644 --- a/LinuxGUI/Ventoy2Disk/Core/ventoy_disk.c +++ b/LinuxGUI/Ventoy2Disk/Core/ventoy_disk.c @@ -330,6 +330,7 @@ static int fatlib_is_secure_boot_enable(void) flfile = fl_fopen("/EFI/BOOT/grubx64_real.efi", "rb"); if (flfile) { + vlog("/EFI/BOOT/grubx64_real.efi find, secure boot in enabled\n"); fl_fclose(flfile); return 1; } @@ -504,7 +505,10 @@ int ventoy_get_vtoy_data(ventoy_disk *info, int *ppartstyle) goto end; } - vdebug("now check secure boot ...\n"); + vdebug("ventoy partition layout check OK: [%llu %llu] [%llu %llu]\n", + part1_start_sector, part1_sector_count, part2_start_sector, part2_sector_count); + + vdebug("now check secure boot for %s ...\n", info->disk_path); g_fatlib_media_fd = fd; g_fatlib_media_offset = part2_start_sector; @@ -546,7 +550,7 @@ int ventoy_get_vtoy_data(ventoy_disk *info, int *ppartstyle) rc = 0; end: - close(fd); + vtoy_safe_close_fd(fd); return rc; } diff --git a/LinuxGUI/Ventoy2Disk/Core/ventoy_log.c b/LinuxGUI/Ventoy2Disk/Core/ventoy_log.c index 469f843e..6e788c2f 100644 --- a/LinuxGUI/Ventoy2Disk/Core/ventoy_log.c +++ b/LinuxGUI/Ventoy2Disk/Core/ventoy_log.c @@ -80,6 +80,34 @@ void ventoy_syslog_newline(int level, const char *Fmt, ...) pthread_mutex_unlock(&g_log_mutex); } +void ventoy_syslog_printf(const char *Fmt, ...) +{ + char log[512]; + va_list arg; + time_t stamp; + struct tm ttm; + FILE *fp; + + time(&stamp); + localtime_r(&stamp, &ttm); + + va_start(arg, Fmt); + vsnprintf(log, 512, Fmt, arg); + va_end(arg); + + pthread_mutex_lock(&g_log_mutex); + fp = fopen(VTOY_LOG_FILE, "a+"); + if (fp) + { + fprintf(fp, "[%04u/%02u/%02u %02u:%02u:%02u] %s", + ttm.tm_year, ttm.tm_mon, ttm.tm_mday, + ttm.tm_hour, ttm.tm_min, ttm.tm_sec, + log); + fclose(fp); + } + pthread_mutex_unlock(&g_log_mutex); +} + void ventoy_syslog(int level, const char *Fmt, ...) { char log[512]; diff --git a/LinuxGUI/Ventoy2Disk/Core/ventoy_util.c b/LinuxGUI/Ventoy2Disk/Core/ventoy_util.c index 562c3a09..d15a4191 100644 --- a/LinuxGUI/Ventoy2Disk/Core/ventoy_util.c +++ b/LinuxGUI/Ventoy2Disk/Core/ventoy_util.c @@ -347,6 +347,7 @@ static int ventoy_fill_gpt_partname(uint16_t Name[36], const char *asciiName) int ventoy_fill_gpt(uint64_t size, uint64_t reserve, int align4k, VTOY_GPT_INFO *gpt) { uint64_t ReservedSector = 33; + uint64_t ModSectorCount = 0; uint64_t Part1SectorCount = 0; uint64_t DiskSectorCount = size / 512; VTOY_GPT_HDR *Head = &gpt->Head; @@ -362,18 +363,28 @@ int ventoy_fill_gpt(uint64_t size, uint64_t reserve, int align4k, VTOY_GPT_INFO ReservedSector += reserve / 512; } + Part1SectorCount = DiskSectorCount - ReservedSector - (VTOYEFI_PART_BYTES / 512) - 2048; + + ModSectorCount = (Part1SectorCount % 8); + if (ModSectorCount) + { + vlog("Part1SectorCount:%llu is not aligned by 4KB (%llu)\n", (_ull)Part1SectorCount, (_ull)ModSectorCount); + } + // check aligned with 4KB if (align4k) { - if (DiskSectorCount % 8) + if (ModSectorCount) { - vdebug("Disk need to align with 4KB %u\n", (uint32_t)(DiskSectorCount % 8)); - ReservedSector += (DiskSectorCount % 8); + vdebug("Disk need to align with 4KB %u\n", (uint32_t)ModSectorCount); + Part1SectorCount -= ModSectorCount; + } + else + { + vdebug("no need to align with 4KB\n"); } } - Part1SectorCount = DiskSectorCount - ReservedSector - (VTOYEFI_PART_BYTES / 512) - 2048; - memcpy(Head->Signature, "EFI PART", 8); Head->Version[2] = 0x01; Head->Length = 92; @@ -461,7 +472,7 @@ int VentoyFillMBRLocation(uint64_t DiskSizeInBytes, uint32_t StartSectorId, uint return 0; } -int ventoy_fill_mbr(uint64_t size, uint64_t reserve, int align4k, int PartStyle, MBR_HEAD *pMBR) +int ventoy_fill_mbr(uint64_t size, uint64_t reserve, int align4k, MBR_HEAD *pMBR) { ventoy_guid Guid; uint32_t DiskSignature; @@ -498,11 +509,6 @@ int ventoy_fill_mbr(uint64_t size, uint64_t reserve, int align4k, int PartStyle, ReservedSector = (uint32_t)(reserve / 512); } - if (PartStyle) - { - ReservedSector += 33; // backup GPT part table - } - // check aligned with 4KB if (align4k) { @@ -512,11 +518,14 @@ int ventoy_fill_mbr(uint64_t size, uint64_t reserve, int align4k, int PartStyle, vlog("Disk need to align with 4KB %u\n", (uint32_t)(sectors % 8)); ReservedSector += (uint32_t)(sectors % 8); } + else + { + vdebug("no need to align with 4KB\n"); + } } vlog("ReservedSector: %u\n", ReservedSector); - //Part1 PartStartSector = VTOYIMG_PART_START_SECTOR; PartSectorCount = DiskSectorCount - ReservedSector - VTOYEFI_PART_BYTES / 512 - PartStartSector; diff --git a/LinuxGUI/Ventoy2Disk/Core/ventoy_util.h b/LinuxGUI/Ventoy2Disk/Core/ventoy_util.h index eb093106..72cec62d 100644 --- a/LinuxGUI/Ventoy2Disk/Core/ventoy_util.h +++ b/LinuxGUI/Ventoy2Disk/Core/ventoy_util.h @@ -46,7 +46,7 @@ int unxz(unsigned char *in, int in_size, int ventoy_read_file_to_buf(const char *FileName, int ExtLen, void **Bufer, int *BufLen); 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, int PartStyle, MBR_HEAD *pMBR); +int ventoy_fill_mbr(uint64_t size, uint64_t reserve, int align4k, MBR_HEAD *pMBR); #endif /* __VENTOY_UTIL_H__ */ diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/API.txt b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/API.txt similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/API.txt rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/API.txt diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/COPYRIGHT.txt b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/COPYRIGHT.txt similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/COPYRIGHT.txt rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/COPYRIGHT.txt diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/Configuration.txt b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/Configuration.txt similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/Configuration.txt rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/Configuration.txt diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/History.txt b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/History.txt similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/History.txt rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/History.txt diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/License.txt b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/License.txt similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/License.txt rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/License.txt diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/Media Access API.txt b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/Media Access API.txt similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/Media Access API.txt rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/Media Access API.txt diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/buildlib.sh b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/buildlib.sh deleted file mode 100644 index dec432f7..00000000 --- a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/buildlib.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh - -rm -rf include -rm -rf lib - -cd release -gcc -O2 -D_FILE_OFFSET_BITS=64 fat*.c -c -ar -rc libfat_io_64.a *.o -rm -f *.o - - -gcc -m32 -O2 -D_FILE_OFFSET_BITS=64 fat*.c -c -ar -rc libfat_io_32.a *.o -rm -f *.o - - -aarch64-linux-gnu-gcc -O2 -D_FILE_OFFSET_BITS=64 fat*.c -c -ar -rc libfat_io_aa64.a *.o -rm -f *.o - - -cd - - - -mkdir lib -mkdir include - -mv release/*.a lib/ -cp -a release/*.h include/ - diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_access.c b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_access.c similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_access.c rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_access.c diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_access.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_access.h similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_access.h rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_access.h diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_cache.c b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_cache.c similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_cache.c rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_cache.c diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_cache.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_cache.h similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_cache.h rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_cache.h diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_defs.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_defs.h similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_defs.h rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_defs.h diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_filelib.c b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_filelib.c similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_filelib.c rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_filelib.c diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_filelib.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_filelib.h similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_filelib.h rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_filelib.h diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_format.c b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_format.c similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_format.c rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_format.c diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_format.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_format.h similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_format.h rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_format.h diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_list.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_list.h similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_list.h rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_list.h diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_misc.c b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_misc.c similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_misc.c rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_misc.c diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_misc.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_misc.h similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_misc.h rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_misc.h diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_opts.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_opts.h similarity index 83% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_opts.h rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_opts.h index ac4dc860..6db158c4 100644 --- a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_opts.h +++ b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_opts.h @@ -63,7 +63,7 @@ // Include support for formatting disks (1 / 0)? #ifndef FATFS_INC_FORMAT_SUPPORT - #define FATFS_INC_FORMAT_SUPPORT 1 + #define FATFS_INC_FORMAT_SUPPORT 0 #endif // Sector size used @@ -71,15 +71,8 @@ // Printf output (directory listing / debug) #ifndef FAT_PRINTF - // Don't include stdio, but there is a printf function available - #ifdef FAT_PRINTF_NOINC_STDIO - extern int printf(const char* ctrl1, ... ); - #define FAT_PRINTF(a) printf a - // Include stdio to use printf - #else - #include - #define FAT_PRINTF(a) printf a - #endif + void ventoy_syslog_printf(const char *Fmt, ...); + #define FAT_PRINTF(a) ventoy_syslog_printf a #endif // Time/Date support requires time.h diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_string.c b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_string.c similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_string.c rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_string.c diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_string.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_string.h similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_string.h rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_string.h diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_table.c b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_table.c similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_table.c rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_table.c diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_table.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_table.h similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_table.h rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_table.h diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_types.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_types.h similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_types.h rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_types.h diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_write.c b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_write.c similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_write.c rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_write.c diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_write.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_write.h similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/include/fat_write.h rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/fat_write.h diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/lib/libfat_io_32.a b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/lib/libfat_io_32.a deleted file mode 100644 index e68fa386..00000000 Binary files a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/lib/libfat_io_32.a and /dev/null differ diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/lib/libfat_io_64.a b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/lib/libfat_io_64.a deleted file mode 100644 index 8598a87c..00000000 Binary files a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/lib/libfat_io_64.a and /dev/null differ diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/lib/libfat_io_aa64.a b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/lib/libfat_io_aa64.a deleted file mode 100644 index 7b9b66c6..00000000 Binary files a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/lib/libfat_io_aa64.a and /dev/null differ diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/example.c b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/example.c deleted file mode 100644 index 5d30e5b6..00000000 --- a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/example.c +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include "fat_filelib.h" - -int media_init() -{ - // ... - return 1; -} - -int media_read(unsigned long sector, unsigned char *buffer, unsigned long sector_count) -{ - unsigned long i; - - for (i=0;im))) : 0 -#define fat_list_next(l, p) (p)->next -#define fat_list_prev(l, p) (p)->previous -#define fat_list_first(l) (l)->head -#define fat_list_last(l) (l)->tail -#define fat_list_for_each(l, p) for ((p) = (l)->head; (p); (p) = (p)->next) - -//----------------------------------------------------------------- -// Inline Functions -//----------------------------------------------------------------- - -//----------------------------------------------------------------- -// fat_list_init: -//----------------------------------------------------------------- -static FAT_INLINE void fat_list_init(struct fat_list *list) -{ - FAT_ASSERT(list); - - list->head = list->tail = 0; -} -//----------------------------------------------------------------- -// fat_list_remove: -//----------------------------------------------------------------- -static FAT_INLINE void fat_list_remove(struct fat_list *list, struct fat_node *node) -{ - FAT_ASSERT(list); - FAT_ASSERT(node); - - if(!node->previous) - list->head = node->next; - else - node->previous->next = node->next; - - if(!node->next) - list->tail = node->previous; - else - node->next->previous = node->previous; -} -//----------------------------------------------------------------- -// fat_list_insert_after: -//----------------------------------------------------------------- -static FAT_INLINE void fat_list_insert_after(struct fat_list *list, struct fat_node *node, struct fat_node *new_node) -{ - FAT_ASSERT(list); - FAT_ASSERT(node); - FAT_ASSERT(new_node); - - new_node->previous = node; - new_node->next = node->next; - if (!node->next) - list->tail = new_node; - else - node->next->previous = new_node; - node->next = new_node; -} -//----------------------------------------------------------------- -// fat_list_insert_before: -//----------------------------------------------------------------- -static FAT_INLINE void fat_list_insert_before(struct fat_list *list, struct fat_node *node, struct fat_node *new_node) -{ - FAT_ASSERT(list); - FAT_ASSERT(node); - FAT_ASSERT(new_node); - - new_node->previous = node->previous; - new_node->next = node; - if (!node->previous) - list->head = new_node; - else - node->previous->next = new_node; - node->previous = new_node; -} -//----------------------------------------------------------------- -// fat_list_insert_first: -//----------------------------------------------------------------- -static FAT_INLINE void fat_list_insert_first(struct fat_list *list, struct fat_node *node) -{ - FAT_ASSERT(list); - FAT_ASSERT(node); - - if (!list->head) - { - list->head = node; - list->tail = node; - node->previous = 0; - node->next = 0; - } - else - fat_list_insert_before(list, list->head, node); -} -//----------------------------------------------------------------- -// fat_list_insert_last: -//----------------------------------------------------------------- -static FAT_INLINE void fat_list_insert_last(struct fat_list *list, struct fat_node *node) -{ - FAT_ASSERT(list); - FAT_ASSERT(node); - - if (!list->tail) - fat_list_insert_first(list, node); - else - fat_list_insert_after(list, list->tail, node); -} -//----------------------------------------------------------------- -// fat_list_is_empty: -//----------------------------------------------------------------- -static FAT_INLINE int fat_list_is_empty(struct fat_list *list) -{ - FAT_ASSERT(list); - - return !list->head; -} -//----------------------------------------------------------------- -// fat_list_pop_head: -//----------------------------------------------------------------- -static FAT_INLINE struct fat_node * fat_list_pop_head(struct fat_list *list) -{ - struct fat_node * node; - - FAT_ASSERT(list); - - node = fat_list_first(list); - if (node) - fat_list_remove(list, node); - - return node; -} - -#endif - diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_misc.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_misc.h deleted file mode 100644 index 0c026343..00000000 --- a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_misc.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef __FAT_MISC_H__ -#define __FAT_MISC_H__ - -#include "fat_defs.h" -#include "fat_opts.h" - -//----------------------------------------------------------------------------- -// Defines -//----------------------------------------------------------------------------- -#define MAX_LONGFILENAME_ENTRIES 20 -#define MAX_LFN_ENTRY_LENGTH 13 - -//----------------------------------------------------------------------------- -// Macros -//----------------------------------------------------------------------------- -#define GET_32BIT_WORD(buffer, location) ( ((uint32)buffer[location+3]<<24) + ((uint32)buffer[location+2]<<16) + ((uint32)buffer[location+1]<<8) + (uint32)buffer[location+0] ) -#define GET_16BIT_WORD(buffer, location) ( ((uint16)buffer[location+1]<<8) + (uint16)buffer[location+0] ) - -#define SET_32BIT_WORD(buffer, location, value) { buffer[location+0] = (uint8)((value)&0xFF); \ - buffer[location+1] = (uint8)((value>>8)&0xFF); \ - buffer[location+2] = (uint8)((value>>16)&0xFF); \ - buffer[location+3] = (uint8)((value>>24)&0xFF); } - -#define SET_16BIT_WORD(buffer, location, value) { buffer[location+0] = (uint8)((value)&0xFF); \ - buffer[location+1] = (uint8)((value>>8)&0xFF); } - -//----------------------------------------------------------------------------- -// Structures -//----------------------------------------------------------------------------- -struct lfn_cache -{ -#if FATFS_INC_LFN_SUPPORT - // Long File Name Structure (max 260 LFN length) - uint8 String[MAX_LONGFILENAME_ENTRIES][MAX_LFN_ENTRY_LENGTH]; - uint8 Null; -#endif - uint8 no_of_strings; -}; - -//----------------------------------------------------------------------------- -// Prototypes -//----------------------------------------------------------------------------- -void fatfs_lfn_cache_init(struct lfn_cache *lfn, int wipeTable); -void fatfs_lfn_cache_entry(struct lfn_cache *lfn, uint8 *entryBuffer); -char* fatfs_lfn_cache_get(struct lfn_cache *lfn); -int fatfs_entry_lfn_text(struct fat_dir_entry *entry); -int fatfs_entry_lfn_invalid(struct fat_dir_entry *entry); -int fatfs_entry_lfn_exists(struct lfn_cache *lfn, struct fat_dir_entry *entry); -int fatfs_entry_sfn_only(struct fat_dir_entry *entry); -int fatfs_entry_is_dir(struct fat_dir_entry *entry); -int fatfs_entry_is_file(struct fat_dir_entry *entry); -int fatfs_lfn_entries_required(char *filename); -void fatfs_filename_to_lfn(char *filename, uint8 *buffer, int entry, uint8 sfnChk); -void fatfs_sfn_create_entry(char *shortfilename, uint32 size, uint32 startCluster, struct fat_dir_entry *entry, int dir); -int fatfs_lfn_create_sfn(char *sfn_output, char *filename); -int fatfs_lfn_generate_tail(char *sfn_output, char *sfn_input, uint32 tailNum); -void fatfs_convert_from_fat_time(uint16 fat_time, int *hours, int *minutes, int *seconds); -void fatfs_convert_from_fat_date(uint16 fat_date, int *day, int *month, int *year); -uint16 fatfs_convert_to_fat_time(int hours, int minutes, int seconds); -uint16 fatfs_convert_to_fat_date(int day, int month, int year); -void fatfs_print_sector(uint32 sector, uint8 *data); - -#endif diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_opts.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_opts.h deleted file mode 100644 index ac4dc860..00000000 --- a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_opts.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef __FAT_OPTS_H__ -#define __FAT_OPTS_H__ - -#ifdef FATFS_USE_CUSTOM_OPTS_FILE - #include "fat_custom.h" -#endif - -//------------------------------------------------------------- -// Configuration -//------------------------------------------------------------- - -// Is the processor little endian (1) or big endian (0) -#ifndef FATFS_IS_LITTLE_ENDIAN - #define FATFS_IS_LITTLE_ENDIAN 1 -#endif - -// Max filename Length -#ifndef FATFS_MAX_LONG_FILENAME - #define FATFS_MAX_LONG_FILENAME 260 -#endif - -// Max open files (reduce to lower memory requirements) -#ifndef FATFS_MAX_OPEN_FILES - #define FATFS_MAX_OPEN_FILES 2 -#endif - -// Number of sectors per FAT_BUFFER (min 1) -#ifndef FAT_BUFFER_SECTORS - #define FAT_BUFFER_SECTORS 1 -#endif - -// Max FAT sectors to buffer (min 1) -// (mem used is FAT_BUFFERS * FAT_BUFFER_SECTORS * FAT_SECTOR_SIZE) -#ifndef FAT_BUFFERS - #define FAT_BUFFERS 1 -#endif - -// Size of cluster chain cache (can be undefined) -// Mem used = FAT_CLUSTER_CACHE_ENTRIES * 4 * 2 -// Improves access speed considerably -//#define FAT_CLUSTER_CACHE_ENTRIES 128 - -// Include support for writing files (1 / 0)? -#ifndef FATFS_INC_WRITE_SUPPORT - #define FATFS_INC_WRITE_SUPPORT 1 -#endif - -// Support long filenames (1 / 0)? -// (if not (0) only 8.3 format is supported) -#ifndef FATFS_INC_LFN_SUPPORT - #define FATFS_INC_LFN_SUPPORT 1 -#endif - -// Support directory listing (1 / 0)? -#ifndef FATFS_DIR_LIST_SUPPORT - #define FATFS_DIR_LIST_SUPPORT 1 -#endif - -// Support time/date (1 / 0)? -#ifndef FATFS_INC_TIME_DATE_SUPPORT - #define FATFS_INC_TIME_DATE_SUPPORT 0 -#endif - -// Include support for formatting disks (1 / 0)? -#ifndef FATFS_INC_FORMAT_SUPPORT - #define FATFS_INC_FORMAT_SUPPORT 1 -#endif - -// Sector size used -#define FAT_SECTOR_SIZE 512 - -// Printf output (directory listing / debug) -#ifndef FAT_PRINTF - // Don't include stdio, but there is a printf function available - #ifdef FAT_PRINTF_NOINC_STDIO - extern int printf(const char* ctrl1, ... ); - #define FAT_PRINTF(a) printf a - // Include stdio to use printf - #else - #include - #define FAT_PRINTF(a) printf a - #endif -#endif - -// Time/Date support requires time.h -#if FATFS_INC_TIME_DATE_SUPPORT - #include -#endif - -#endif diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_string.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_string.h deleted file mode 100644 index 90ca8e05..00000000 --- a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_string.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __FILESTRING_H__ -#define __FILESTRING_H__ - -//----------------------------------------------------------------------------- -// Prototypes -//----------------------------------------------------------------------------- -int fatfs_total_path_levels(char *path); -int fatfs_get_substring(char *Path, int levelreq, char *output, int max_len); -int fatfs_split_path(char *FullPath, char *Path, int max_path, char *FileName, int max_filename); -int fatfs_compare_names(char* strA, char* strB); -int fatfs_string_ends_with_slash(char *path); -int fatfs_get_sfn_display_name(char* out, char* in); -int fatfs_get_extension(char* filename, char* out, int maxlen); -int fatfs_create_path_string(char* path, char *filename, char* out, int maxlen); - -#ifndef NULL - #define NULL 0 -#endif - -#endif diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_table.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_table.h deleted file mode 100644 index ead75f32..00000000 --- a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_table.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __FAT_TABLE_H__ -#define __FAT_TABLE_H__ - -#include "fat_opts.h" -#include "fat_misc.h" - -//----------------------------------------------------------------------------- -// Prototypes -//----------------------------------------------------------------------------- -void fatfs_fat_init(struct fatfs *fs); -int fatfs_fat_purge(struct fatfs *fs); -uint32 fatfs_find_next_cluster(struct fatfs *fs, uint32 current_cluster); -void fatfs_set_fs_info_next_free_cluster(struct fatfs *fs, uint32 newValue); -int fatfs_find_blank_cluster(struct fatfs *fs, uint32 start_cluster, uint32 *free_cluster); -int fatfs_fat_set_cluster(struct fatfs *fs, uint32 cluster, uint32 next_cluster); -int fatfs_fat_add_cluster_to_chain(struct fatfs *fs, uint32 start_cluster, uint32 newEntry); -int fatfs_free_cluster_chain(struct fatfs *fs, uint32 start_cluster); -uint32 fatfs_count_free_clusters(struct fatfs *fs); - -#endif diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_types.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_types.h deleted file mode 100644 index 5e2cca8a..00000000 --- a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_types.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef __FAT_TYPES_H__ -#define __FAT_TYPES_H__ - -// Detect 64-bit compilation on GCC -#if defined(__GNUC__) && defined(__SIZEOF_LONG__) - #if __SIZEOF_LONG__ == 8 - #define FATFS_DEF_UINT32_AS_INT - #endif -#endif - -//------------------------------------------------------------- -// System specific types -//------------------------------------------------------------- -#ifndef FATFS_NO_DEF_TYPES - typedef unsigned char uint8; - typedef unsigned short uint16; - - // If compiling on a 64-bit machine, use int as 32-bits - #ifdef FATFS_DEF_UINT32_AS_INT - typedef unsigned int uint32; - // Else for 32-bit machines & embedded systems, use long... - #else - typedef unsigned long uint32; - #endif -#endif - -#ifndef NULL - #define NULL 0 -#endif - -//------------------------------------------------------------- -// Endian Macros -//------------------------------------------------------------- -// FAT is little endian so big endian systems need to swap words - -// Little Endian - No swap required -#if FATFS_IS_LITTLE_ENDIAN == 1 - - #define FAT_HTONS(n) (n) - #define FAT_HTONL(n) (n) - -// Big Endian - Swap required -#else - - #define FAT_HTONS(n) ((((uint16)((n) & 0xff)) << 8) | (((n) & 0xff00) >> 8)) - #define FAT_HTONL(n) (((((uint32)(n) & 0xFF)) << 24) | \ - ((((uint32)(n) & 0xFF00)) << 8) | \ - ((((uint32)(n) & 0xFF0000)) >> 8) | \ - ((((uint32)(n) & 0xFF000000)) >> 24)) - -#endif - -//------------------------------------------------------------- -// Structure Packing Compile Options -//------------------------------------------------------------- -#ifdef __GNUC__ - #define STRUCT_PACK - #define STRUCT_PACK_BEGIN - #define STRUCT_PACK_END - #define STRUCT_PACKED __attribute__ ((packed)) -#else - // Other compilers may require other methods of packing structures - #define STRUCT_PACK - #define STRUCT_PACK_BEGIN - #define STRUCT_PACK_END - #define STRUCT_PACKED -#endif - -#endif diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_write.h b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_write.h deleted file mode 100644 index 5558a86e..00000000 --- a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/fat_write.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __FAT_WRITE_H__ -#define __FAT_WRITE_H__ - -#include "fat_defs.h" -#include "fat_opts.h" - -//----------------------------------------------------------------------------- -// Prototypes -//----------------------------------------------------------------------------- -int fatfs_add_file_entry(struct fatfs *fs, uint32 dirCluster, char *filename, char *shortfilename, uint32 startCluster, uint32 size, int dir); -int fatfs_add_free_space(struct fatfs *fs, uint32 *startCluster, uint32 clusters); -int fatfs_allocate_free_space(struct fatfs *fs, int newFile, uint32 *startCluster, uint32 size); - -#endif diff --git a/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/version.txt b/LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/version.txt similarity index 100% rename from LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/release/version.txt rename to LinuxGUI/Ventoy2Disk/Lib/fat_io_lib/version.txt diff --git a/LinuxGUI/Ventoy2Disk/Web/ventoy_http.c b/LinuxGUI/Ventoy2Disk/Web/ventoy_http.c index 755a08c2..e7329d8a 100644 --- a/LinuxGUI/Ventoy2Disk/Web/ventoy_http.c +++ b/LinuxGUI/Ventoy2Disk/Web/ventoy_http.c @@ -346,6 +346,8 @@ static int ventoy_clean_disk(int fd, uint64_t size) len = write(fd, buf, zerolen); vdebug("write disk at off:%llu writelen:%lld datalen:%d\n", (_ull)offset, (_ll)len, zerolen); + fsync(fd); + free(buf); return 0; } @@ -800,7 +802,7 @@ static void * ventoy_install_thread(void *data) else { vdebug("Fill MBR part table\n"); - ventoy_fill_mbr(disk->size_in_byte, thread->reserveBytes, thread->align4kb, 0, &MBR); + ventoy_fill_mbr(disk->size_in_byte, thread->reserveBytes, thread->align4kb, &MBR); Part1StartSector = MBR.PartTbl[0].StartSectorId; Part1SectorCount = MBR.PartTbl[0].SectorCount; Part2StartSector = MBR.PartTbl[1].StartSectorId; diff --git a/LinuxGUI/WebUI/index.html b/LinuxGUI/WebUI/index.html index c77ee448..8b166927 100644 --- a/LinuxGUI/WebUI/index.html +++ b/LinuxGUI/WebUI/index.html @@ -342,6 +342,7 @@ var vtoy_cur_process_disk_name; var vtoy_chrome_app_mode = (window.location.href.indexOf('chrome-app') >= 0) ? 1 : 0; + function sort_language_list() { var tmp; for (var i = 0; i < vtoy_language_data.length; i++) { diff --git a/LinuxGUI/build.sh b/LinuxGUI/build.sh index 21830acc..001c4850 100644 --- a/LinuxGUI/build.sh +++ b/LinuxGUI/build.sh @@ -5,9 +5,9 @@ build_func() { toolDir=$3 XXFLAG='-std=gnu99 -D_FILE_OFFSET_BITS=64' - XXLIB="./Ventoy2Disk/Lib/fat_io_lib/lib/libfat_io_${libsuffix}.a" + XXLIB="" - echo "CC=$1 libsuffix=$libsuffix" + echo "CC=$1 libsuffix=$libsuffix toolDir=$toolDir" $1 $XXFLAG -c -Wall -Wextra -Wshadow -Wformat-security -Winit-self \ -Wmissing-prototypes -O2 -DLINUX \ @@ -29,6 +29,7 @@ build_func() { -I./Ventoy2Disk/Lib/xz-embedded/userspace \ -I ./Ventoy2Disk/Lib/exfat/src/libexfat \ -I ./Ventoy2Disk/Lib/exfat/src/mkfs \ + -I ./Ventoy2Disk/Lib/fat_io_lib \ \ -L ./Ventoy2Disk/Lib/fat_io_lib/lib \ Ventoy2Disk/*.c \ @@ -37,6 +38,7 @@ build_func() { Ventoy2Disk/Lib/xz-embedded/linux/lib/decompress_unxz.c \ Ventoy2Disk/Lib/exfat/src/libexfat/*.c \ Ventoy2Disk/Lib/exfat/src/mkfs/*.c \ + Ventoy2Disk/Lib/fat_io_lib/*.c \ $XXLIB \ -l pthread \ ./civetweb.o \ diff --git a/Ventoy2Disk/Ventoy2Disk/Utility.c b/Ventoy2Disk/Ventoy2Disk/Utility.c index cf86fef4..800855e6 100644 --- a/Ventoy2Disk/Ventoy2Disk/Utility.c +++ b/Ventoy2Disk/Ventoy2Disk/Utility.c @@ -592,6 +592,7 @@ int VentoyFillWholeGpt(UINT64 DiskSizeBytes, VTOY_GPT_INFO *pInfo) int VentoyFillGpt(UINT64 DiskSizeBytes, VTOY_GPT_INFO *pInfo) { INT64 ReservedValue = 0; + UINT64 ModSectorCount = 0; UINT64 ReservedSector = 33; UINT64 Part1SectorCount = 0; UINT64 DiskSectorCount = DiskSizeBytes / 512; @@ -609,18 +610,28 @@ int VentoyFillGpt(UINT64 DiskSizeBytes, VTOY_GPT_INFO *pInfo) ReservedSector += ReservedValue * 2048; } + Part1SectorCount = DiskSectorCount - ReservedSector - (VENTOY_EFI_PART_SIZE / 512) - 2048; + + ModSectorCount = (Part1SectorCount % 8); + if (ModSectorCount) + { + Log("Part1SectorCount:%llu is not aligned by 4KB (%llu)", (ULONGLONG)Part1SectorCount, (ULONGLONG)ModSectorCount); + } + // check aligned with 4KB if (IsPartNeed4KBAlign()) { - if (DiskSectorCount % 8) + if (ModSectorCount) { - Log("Disk need to align with 4KB %u", (UINT32)(DiskSectorCount % 8)); - ReservedSector += (DiskSectorCount % 8); + Log("Disk need to align with 4KB %u", (UINT32)ModSectorCount); + Part1SectorCount -= ModSectorCount; + } + else + { + Log("no need to align with 4KB"); } } - Part1SectorCount = DiskSectorCount - ReservedSector - (VENTOY_EFI_PART_SIZE / 512) - 2048; - memcpy(Head->Signature, "EFI PART", 8); Head->Version[2] = 0x01; Head->Length = 92;