@@ -23,7 +23,7 @@ CreateDisk(
2323 IO_STATUS_BLOCK Iosb ;
2424 NTSTATUS Status ;
2525
26- DPRINT1 ("CreateDisk(%lu %p)\n" , DiskNumber , DiskInfo );
26+ DPRINT ("CreateDisk(%lu %p)\n" , DiskNumber , DiskInfo );
2727
2828 StringCchPrintfW (DstPath , ARRAYSIZE (DstPath ),
2929 L"\\Device\\Harddisk%lu\\Partition0" ,
@@ -64,23 +64,17 @@ CreateDisk(
6464 goto done ;
6565 }
6666
67- CurrentDisk -> PartitionStyle = DiskInfo -> PartitionStyle ;
68-
6967 /* Free the layout buffer */
7068 if (CurrentDisk -> LayoutBuffer )
71- {
7269 RtlFreeHeap (RtlGetProcessHeap (), 0 , CurrentDisk -> LayoutBuffer );
73- CurrentDisk -> LayoutBuffer = NULL ;
74- CurrentDisk -> ExtendedPartition = NULL ;
75- }
76-
77- ReadLayoutBuffer (FileHandle , CurrentDisk );
7870
79- DPRINT1 ("PartitionCount: %lu\n" , CurrentDisk -> LayoutBuffer -> PartitionCount );
71+ CurrentDisk -> LayoutBuffer = NULL ;
72+ CurrentDisk -> ExtendedPartition = NULL ;
73+ CurrentDisk -> Dirty = FALSE;
74+ CurrentDisk -> NewDisk = TRUE;
75+ CurrentDisk -> PartitionStyle = DiskInfo -> PartitionStyle ;
8076
81- #ifdef DUMP_PARTITION_TABLE
82- DumpPartitionTable (CurrentDisk );
83- #endif
77+ ReadLayoutBuffer (FileHandle , CurrentDisk );
8478
8579done :
8680 if (FileHandle )
@@ -112,7 +106,7 @@ ConvertGPT(
112106 return TRUE;
113107 }
114108
115- if (CurrentDisk -> LayoutBuffer -> PartitionCount != 0 )
109+ if (GetPrimaryPartitionCount ( CurrentDisk ) != 0 )
116110 {
117111 ConResPuts (StdOut , IDS_CONVERT_GPT_NOT_EMPTY );
118112 return TRUE;
@@ -134,13 +128,18 @@ ConvertGPT(
134128 Status = CreateDisk (CurrentDisk -> DiskNumber , & DiskInfo );
135129 if (!NT_SUCCESS (Status ))
136130 {
137-
138- }
139- else
140- {
141- ConResPuts (StdOut , IDS_CONVERT_GPT_SUCCESS );
131+ DPRINT1 ("CreateDisk() failed!\n" );
132+ return TRUE;
142133 }
143134
135+ CurrentDisk -> StartSector .QuadPart = AlignDown (CurrentDisk -> LayoutBuffer -> Gpt .StartingUsableOffset .QuadPart / CurrentDisk -> BytesPerSector ,
136+ CurrentDisk -> SectorAlignment ) + (ULONGLONG )CurrentDisk -> SectorAlignment ;
137+ CurrentDisk -> EndSector .QuadPart = AlignDown (CurrentDisk -> StartSector .QuadPart + (CurrentDisk -> LayoutBuffer -> Gpt .UsableLength .QuadPart / CurrentDisk -> BytesPerSector ) - 1 ,
138+ CurrentDisk -> SectorAlignment );
139+
140+ ScanForUnpartitionedGptDiskSpace (CurrentDisk );
141+ ConResPuts (StdOut , IDS_CONVERT_GPT_SUCCESS );
142+
144143 return TRUE;
145144}
146145
@@ -168,7 +167,7 @@ ConvertMBR(
168167 return TRUE;
169168 }
170169
171- if (CurrentDisk -> LayoutBuffer -> PartitionCount != 0 )
170+ if (GetPrimaryPartitionCount ( CurrentDisk ) != 0 )
172171 {
173172 ConResPuts (StdOut , IDS_CONVERT_MBR_NOT_EMPTY );
174173 return TRUE;
@@ -180,12 +179,15 @@ ConvertMBR(
180179 Status = CreateDisk (CurrentDisk -> DiskNumber , & DiskInfo );
181180 if (!NT_SUCCESS (Status ))
182181 {
183-
184- }
185- else
186- {
187- ConResPuts (StdOut , IDS_CONVERT_MBR_SUCCESS );
182+ DPRINT1 ("CreateDisk() failed!\n" );
183+ return TRUE;
188184 }
189185
186+ CurrentDisk -> StartSector .QuadPart = (ULONGLONG )CurrentDisk -> SectorAlignment ;
187+ CurrentDisk -> EndSector .QuadPart = min (CurrentDisk -> SectorCount .QuadPart , 0x100000000 ) - 1 ;
188+
189+ ScanForUnpartitionedMbrDiskSpace (CurrentDisk );
190+ ConResPuts (StdOut , IDS_CONVERT_MBR_SUCCESS );
191+
190192 return TRUE;
191193}
0 commit comments