Commit 4e8d8b2e authored by longpanda's avatar longpanda
Browse files

Fix Windows 11 error 0x80070001. (#3010 #3029 #3105)

parent 60d88cb7
...@@ -442,7 +442,7 @@ int ventoy_fill_gpt(uint64_t size, uint64_t reserve, int align4k, VTOY_GPT_INFO ...@@ -442,7 +442,7 @@ int ventoy_fill_gpt(uint64_t size, uint64_t reserve, int align4k, VTOY_GPT_INFO
ventoy_gen_preudo_uuid(&(Table[1].PartGuid)); ventoy_gen_preudo_uuid(&(Table[1].PartGuid));
Table[1].StartLBA = Table[0].LastLBA + 1; Table[1].StartLBA = Table[0].LastLBA + 1;
Table[1].LastLBA = Table[1].StartLBA + VTOYEFI_PART_BYTES / 512 - 1; Table[1].LastLBA = Table[1].StartLBA + VTOYEFI_PART_BYTES / 512 - 1;
Table[1].Attr = 0xC000000000000001ULL; Table[1].Attr = 0x8000000000000000ULL;
ventoy_fill_gpt_partname(Table[1].Name, "VTOYEFI"); ventoy_fill_gpt_partname(Table[1].Name, "VTOYEFI");
#if 0 #if 0
......
...@@ -727,6 +727,7 @@ static void * ventoy_update_thread(void *data) ...@@ -727,6 +727,7 @@ static void * ventoy_update_thread(void *data)
MBR_HEAD MBR; MBR_HEAD MBR;
ventoy_disk *disk = NULL; ventoy_disk *disk = NULL;
ventoy_thread_data *thread = (ventoy_thread_data *)data; ventoy_thread_data *thread = (ventoy_thread_data *)data;
VTOY_GPT_INFO *pstGPT = NULL;
vdebug("ventoy_update_thread run ...\n"); vdebug("ventoy_update_thread run ...\n");
...@@ -790,6 +791,34 @@ static void * ventoy_update_thread(void *data) ...@@ -790,6 +791,34 @@ static void * ventoy_update_thread(void *data)
vlog("No need to update MBR\n"); vlog("No need to update MBR\n");
} }
if (disk->vtoydata.partition_style)
{
pstGPT = (VTOY_GPT_INFO *)malloc(sizeof(VTOY_GPT_INFO));
memset(pstGPT, 0, sizeof(VTOY_GPT_INFO));
offset = lseek(fd, 0, SEEK_SET);
len = read(fd, pstGPT, sizeof(VTOY_GPT_INFO));
vlog("Read GPT table offset:%llu len:%llu ...\n", (_ull)offset, (_ull)len);
if (pstGPT->PartTbl[1].Attr != 0x8000000000000000ULL)
{
vlog("Update EFI part attr from 0x%016llx to 0x%016llx\n",
pstGPT->PartTbl[1].Attr, 0x8000000000000000ULL);
pstGPT->PartTbl[1].Attr = 0x8000000000000000ULL;
pstGPT->Head.Crc = 0;
pstGPT->Head.Crc = ventoy_crc32(&(pstGPT->Head), pstGPT->Head.Length);
ventoy_write_gpt_part_table(fd, disk->size_in_byte, pstGPT);
}
else
{
vlog("No need to update EFI part attr\n");
}
free(pstGPT);
}
g_current_progress = PT_SYNC_DATA1; g_current_progress = PT_SYNC_DATA1;
vlog("fsync data1...\n"); vlog("fsync data1...\n");
......
...@@ -2520,7 +2520,7 @@ int PartitionResizeForVentoy(PHY_DRIVE_INFO *pPhyDrive) ...@@ -2520,7 +2520,7 @@ int PartitionResizeForVentoy(PHY_DRIVE_INFO *pPhyDrive)
pGPT->PartTbl[1].StartLBA = pGPT->PartTbl[0].LastLBA + 1; pGPT->PartTbl[1].StartLBA = pGPT->PartTbl[0].LastLBA + 1;
pGPT->PartTbl[1].LastLBA = pGPT->PartTbl[1].StartLBA + VENTOY_EFI_PART_SIZE / 512 - 1; pGPT->PartTbl[1].LastLBA = pGPT->PartTbl[1].StartLBA + VENTOY_EFI_PART_SIZE / 512 - 1;
pGPT->PartTbl[1].Attr = 0xC000000000000001ULL; pGPT->PartTbl[1].Attr = VENTOY_EFI_PART_ATTR;
memcpy(pGPT->PartTbl[1].Name, L"VTOYEFI", 7 * 2); memcpy(pGPT->PartTbl[1].Name, L"VTOYEFI", 7 * 2);
//Update CRC //Update CRC
...@@ -2797,6 +2797,7 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int TryId) ...@@ -2797,6 +2797,7 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int TryId)
BOOL CleanDisk = FALSE; BOOL CleanDisk = FALSE;
BOOL DelEFI = FALSE; BOOL DelEFI = FALSE;
BOOL bWriteBack = TRUE; BOOL bWriteBack = TRUE;
BOOL bUpdateEFIAttr = FALSE;
HANDLE hVolume; HANDLE hVolume;
HANDLE hDrive; HANDLE hDrive;
DWORD Status; DWORD Status;
...@@ -2906,6 +2907,12 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int TryId) ...@@ -2906,6 +2907,12 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int TryId)
Log("TryId=%d EFI GPT partition type is 0x%llx", TryId, pPhyDrive->Part2GPTAttr); Log("TryId=%d EFI GPT partition type is 0x%llx", TryId, pPhyDrive->Part2GPTAttr);
PROGRESS_BAR_SET_POS(PT_DEL_ALL_PART); PROGRESS_BAR_SET_POS(PT_DEL_ALL_PART);
if (pGptInfo->PartTbl[1].Attr != VENTOY_EFI_PART_ATTR)
{
bUpdateEFIAttr = TRUE;
}
if (TryId == 1) if (TryId == 1)
{ {
Log("Change GPT partition type to ESP"); Log("Change GPT partition type to ESP");
...@@ -2917,8 +2924,8 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int TryId) ...@@ -2917,8 +2924,8 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int TryId)
} }
else if (TryId == 2) else if (TryId == 2)
{ {
Log("Change GPT partition attribute"); Log("Try2 Change GPT partition attribute to 0x%016llx", VENTOY_EFI_PART_ATTR & 0xFFFFFFFFFFFFFFFEULL);
if (DISK_ChangeVtoyEFIAttr(pPhyDrive->PhyDrive, StartSector * 512ULL, 0x8000000000000001)) if (DISK_ChangeVtoyEFIAttr(pPhyDrive->PhyDrive, StartSector * 512ULL, VENTOY_EFI_PART_ATTR & 0xFFFFFFFFFFFFFFFEULL))
{ {
ChangeAttr = TRUE; ChangeAttr = TRUE;
Sleep(2000); Sleep(2000);
...@@ -3253,15 +3260,16 @@ End: ...@@ -3253,15 +3260,16 @@ End:
DISK_ChangeVtoyEFI2Basic(pPhyDrive->PhyDrive, StartSector * 512); DISK_ChangeVtoyEFI2Basic(pPhyDrive->PhyDrive, StartSector * 512);
} }
if (pPhyDrive->PartStyle == 1) if (pPhyDrive->PartStyle == 1)
{ {
if (ChangeAttr || ((pPhyDrive->Part2GPTAttr >> 56) != 0xC0)) if (ChangeAttr || bUpdateEFIAttr)
{ {
Log("Change EFI partition attr %u <0x%llx> to <0x%llx>", ChangeAttr, pPhyDrive->Part2GPTAttr, 0xC000000000000001ULL); Log("Change EFI partition attr %u <0x%llx> to <0x%llx>", ChangeAttr, pGptInfo->PartTbl[1].Attr, VENTOY_EFI_PART_ATTR);
if (DISK_ChangeVtoyEFIAttr(pPhyDrive->PhyDrive, StartSector * 512ULL, 0xC000000000000001ULL)) if (DISK_ChangeVtoyEFIAttr(pPhyDrive->PhyDrive, StartSector * 512ULL, VENTOY_EFI_PART_ATTR))
{ {
Log("Change EFI partition attr success"); Log("Change EFI partition attr success");
pPhyDrive->Part2GPTAttr = 0xC000000000000001ULL; pPhyDrive->Part2GPTAttr = VENTOY_EFI_PART_ATTR;
} }
else else
{ {
......
...@@ -982,7 +982,7 @@ int VentoyFillGpt(UINT64 DiskSizeBytes, VTOY_GPT_INFO *pInfo) ...@@ -982,7 +982,7 @@ int VentoyFillGpt(UINT64 DiskSizeBytes, VTOY_GPT_INFO *pInfo)
CoCreateGuid(&(Table[1].PartGuid)); CoCreateGuid(&(Table[1].PartGuid));
Table[1].StartLBA = Table[0].LastLBA + 1; Table[1].StartLBA = Table[0].LastLBA + 1;
Table[1].LastLBA = Table[1].StartLBA + VENTOY_EFI_PART_SIZE / 512 - 1; Table[1].LastLBA = Table[1].StartLBA + VENTOY_EFI_PART_SIZE / 512 - 1;
Table[1].Attr = 0xC000000000000001ULL; Table[1].Attr = VENTOY_EFI_PART_ATTR;
memcpy(Table[1].Name, L"VTOYEFI", 7 * 2); memcpy(Table[1].Name, L"VTOYEFI", 7 * 2);
#if 0 #if 0
......
...@@ -34,6 +34,9 @@ typedef enum VTOY_FS ...@@ -34,6 +34,9 @@ typedef enum VTOY_FS
#define FAT32_MAX_LIMIT (32 * 1073741824ULL) #define FAT32_MAX_LIMIT (32 * 1073741824ULL)
#define VENTOY_EFI_PART_ATTR 0x8000000000000000ULL
#define SIZE_1KB (1024) #define SIZE_1KB (1024)
#define SIZE_1GB (1024 * 1024 * 1024) #define SIZE_1GB (1024 * 1024 * 1024)
#define SIZE_1TB (1024ULL * 1024ULL * 1024ULL * 1024ULL) #define SIZE_1TB (1024ULL * 1024ULL * 1024ULL * 1024ULL)
......
...@@ -599,7 +599,7 @@ static int update_part_table(char *disk, UINT64 part2start) ...@@ -599,7 +599,7 @@ static int update_part_table(char *disk, UINT64 part2start)
PartTbl[1].StartLBA = PartTbl[0].LastLBA + 1; PartTbl[1].StartLBA = PartTbl[0].LastLBA + 1;
PartTbl[1].LastLBA = PartTbl[1].StartLBA + VENTOY_EFI_PART_SIZE / 512 - 1; PartTbl[1].LastLBA = PartTbl[1].StartLBA + VENTOY_EFI_PART_SIZE / 512 - 1;
PartTbl[1].Attr = 0xC000000000000001ULL; PartTbl[1].Attr = VENTOY_EFI_PART_ATTR;
PartTbl[1].Name[0] = 'V'; PartTbl[1].Name[0] = 'V';
PartTbl[1].Name[1] = 'T'; PartTbl[1].Name[1] = 'T';
PartTbl[1].Name[2] = 'O'; PartTbl[1].Name[2] = 'O';
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#ifndef __VTOYCLI_H__ #ifndef __VTOYCLI_H__
#define __VTOYCLI_H__ #define __VTOYCLI_H__
#define VENTOY_EFI_PART_ATTR 0xC000000000000001ULL #define VENTOY_EFI_PART_ATTR 0x8000000000000000ULL
#define SIZE_1MB (1024 * 1024) #define SIZE_1MB (1024 * 1024)
#define VENTOY_EFI_PART_SIZE (32 * SIZE_1MB) #define VENTOY_EFI_PART_SIZE (32 * SIZE_1MB)
......
...@@ -244,7 +244,7 @@ int DumpGptInfo(VTOY_GPT_INFO *pGptInfo) ...@@ -244,7 +244,7 @@ int DumpGptInfo(VTOY_GPT_INFO *pGptInfo)
return 0; return 0;
} }
#define VENTOY_EFI_PART_ATTR 0xC000000000000001ULL #define VENTOY_EFI_PART_ATTR 0x8000000000000000ULL
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment