3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: hal/halx86/xbox/part_xbox.c
6 * PURPOSE: Xbox specific handling of partition tables
7 * PROGRAMMER: Ge van Geldorp (gvg@reactos.com)
12 /* INCLUDES *****************************************************************/
17 #include <ddk/ntdddisk.h>
20 #include <internal/debug.h>
23 #define XBOX_SIGNATURE_SECTOR 3
24 #define XBOX_SIGNATURE ('B' | ('R' << 8) | ('F' << 16) | ('R' << 24))
25 #define PARTITION_SIGNATURE 0xaa55
27 /* VARIABLES ***************************************************************/
29 static pHalExamineMBR NtoskrnlExamineMBR
;
30 static pHalIoReadPartitionTable NtoskrnlIoReadPartitionTable
;
31 static pHalIoSetPartitionInformation NtoskrnlIoSetPartitionInformation
;
32 static pHalIoWritePartitionTable NtoskrnlIoWritePartitionTable
;
41 /* This is in the \Device\Harddisk0\Partition.. order used by the Xbox kernel */
42 { 0x0055F400, 0x0098f800, PARTITION_FAT32
}, /* Store, E: */
43 { 0x00465400, 0x000FA000, PARTITION_FAT_16
}, /* System, C: */
44 { 0x00000400, 0x00177000, PARTITION_FAT_16
}, /* Cache1, X: */
45 { 0x00177400, 0x00177000, PARTITION_FAT_16
}, /* Cache2, Y: */
46 { 0x002EE400, 0x00177000, PARTITION_FAT_16
} /* Cache3, Z: */
49 #define XBOX_PARTITION_COUNT (sizeof(XboxPartitions) / sizeof(XboxPartitions[0]))
51 /* FUNCTIONS ***************************************************************/
55 HalpXboxReadSector(IN PDEVICE_OBJECT DeviceObject
,
57 IN PLARGE_INTEGER SectorOffset
,
60 IO_STATUS_BLOCK StatusBlock
;
65 DPRINT("HalpXboxReadSector(%p %lu 0x%08x%08x %p)\n",
66 DeviceObject
, SectorSize
, SectorOffset
->u
.HighPart
, SectorOffset
->u
.LowPart
, Sector
);
71 KeInitializeEvent(&Event
,
76 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_READ
,
84 Status
= IoCallDriver(DeviceObject
,
86 if (Status
== STATUS_PENDING
)
88 KeWaitForSingleObject(&Event
,
93 Status
= StatusBlock
.Status
;
96 if (!NT_SUCCESS(Status
))
98 DPRINT("Reading sector failed (Status 0x%08lx)\n",
106 static NTSTATUS FASTCALL
107 HalpXboxDeviceHasXboxPartitioning(PDEVICE_OBJECT DeviceObject
,
109 BOOLEAN
*HasXboxPartitioning
)
112 LARGE_INTEGER Offset
;
115 DPRINT("HalpXboxDeviceHasXboxPartitioning(%p %lu %p)\n",
118 HasXboxPartitioning
);
120 SectorData
= ExAllocatePool(PagedPool
, SectorSize
);
121 if (NULL
== SectorData
)
123 return STATUS_NO_MEMORY
;
126 Offset
.QuadPart
= XBOX_SIGNATURE_SECTOR
* SectorSize
;
127 Status
= HalpXboxReadSector(DeviceObject
, SectorSize
, &Offset
, SectorData
);
128 if (! NT_SUCCESS(Status
))
133 DPRINT("Signature 0x%02x 0x%02x 0x%02x 0x%02x\n",
134 *((UCHAR
*) SectorData
), *((UCHAR
*) SectorData
+ 1), *((UCHAR
*) SectorData
+ 2), *((UCHAR
*) SectorData
+ 3));
135 *HasXboxPartitioning
= (XBOX_SIGNATURE
== *((ULONG
*) SectorData
));
136 ExFreePool(SectorData
);
137 DPRINT("%s partitioning found\n", *HasXboxPartitioning
? "Xbox" : "MBR");
139 return STATUS_SUCCESS
;
143 HalpXboxExamineMBR(IN PDEVICE_OBJECT DeviceObject
,
145 IN ULONG MBRTypeIdentifier
,
148 BOOLEAN HasXboxPartitioning
;
151 DPRINT("HalpXboxExamineMBR(%p %lu %lx %p)\n",
159 Status
= HalpXboxDeviceHasXboxPartitioning(DeviceObject
, SectorSize
, &HasXboxPartitioning
);
160 if (! NT_SUCCESS(Status
))
165 if (! HasXboxPartitioning
)
167 DPRINT("Delegating to standard MBR code\n");
168 NtoskrnlExamineMBR(DeviceObject
, SectorSize
, MBRTypeIdentifier
, Buffer
);
172 /* Buffer already set to NULL */
176 static NTSTATUS FASTCALL
177 HalpXboxIoReadPartitionTable(PDEVICE_OBJECT DeviceObject
,
179 BOOLEAN ReturnRecognizedPartitions
,
180 PDRIVE_LAYOUT_INFORMATION
*PartitionBuffer
)
182 BOOLEAN HasXboxPartitioning
;
185 PPARTITION_INFORMATION PartInfo
;
187 DPRINT("HalpXboxIoReadPartitionTable(%p %lu %x %p)\n",
190 ReturnRecognizedPartitions
,
193 Status
= HalpXboxDeviceHasXboxPartitioning(DeviceObject
, SectorSize
, &HasXboxPartitioning
);
194 if (! NT_SUCCESS(Status
))
199 if (! HasXboxPartitioning
)
201 DPRINT("Delegating to standard MBR code\n");
202 return NtoskrnlIoReadPartitionTable(DeviceObject
, SectorSize
,
203 ReturnRecognizedPartitions
, PartitionBuffer
);
206 *PartitionBuffer
= (PDRIVE_LAYOUT_INFORMATION
)
207 ExAllocatePool(PagedPool
,
208 sizeof(DRIVE_LAYOUT_INFORMATION
) +
209 XBOX_PARTITION_COUNT
* sizeof(PARTITION_INFORMATION
));
210 if (NULL
== *PartitionBuffer
)
212 return STATUS_NO_MEMORY
;
214 (*PartitionBuffer
)->PartitionCount
= XBOX_PARTITION_COUNT
;
215 (*PartitionBuffer
)->Signature
= PARTITION_SIGNATURE
;
216 for (Part
= 0; Part
< XBOX_PARTITION_COUNT
; Part
++)
218 PartInfo
= (*PartitionBuffer
)->PartitionEntry
+ Part
;
219 PartInfo
->StartingOffset
.QuadPart
= (ULONGLONG
) XboxPartitions
[Part
].SectorStart
*
220 (ULONGLONG
) SectorSize
;
221 PartInfo
->PartitionLength
.QuadPart
= (ULONGLONG
) XboxPartitions
[Part
].SectorCount
*
222 (ULONGLONG
) SectorSize
;
223 PartInfo
->HiddenSectors
= 0;
224 PartInfo
->PartitionNumber
= Part
+ 1;
225 PartInfo
->PartitionType
= XboxPartitions
[Part
].PartitionType
;
226 PartInfo
->BootIndicator
= FALSE
;
227 PartInfo
->RecognizedPartition
= TRUE
;
228 PartInfo
->RewritePartition
= FALSE
;
229 DPRINT(" %ld: nr: %d boot: %1x type: %x start: 0x%I64x count: 0x%I64x rec: %d\n",
231 PartInfo
->PartitionNumber
,
232 PartInfo
->BootIndicator
,
233 PartInfo
->PartitionType
,
234 PartInfo
->StartingOffset
.QuadPart
,
235 PartInfo
->PartitionLength
.QuadPart
,
236 PartInfo
->RecognizedPartition
);
239 return STATUS_SUCCESS
;
242 static NTSTATUS FASTCALL
243 HalpXboxIoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject
,
245 IN ULONG PartitionNumber
,
246 IN ULONG PartitionType
)
248 BOOLEAN HasXboxPartitioning
;
251 DPRINT("HalpXboxIoSetPartitionInformation(%p %lu %lu %lu)\n",
257 Status
= HalpXboxDeviceHasXboxPartitioning(DeviceObject
, SectorSize
, &HasXboxPartitioning
);
258 if (! NT_SUCCESS(Status
))
263 if (! HasXboxPartitioning
)
265 DPRINT("Delegating to standard MBR code\n");
266 return NtoskrnlIoSetPartitionInformation(DeviceObject
, SectorSize
,
267 PartitionNumber
, PartitionType
);
270 /* Can't change the partitioning */
271 DPRINT1("Xbox partitions are fixed, can't change them\n");
272 return STATUS_ACCESS_DENIED
;
275 static NTSTATUS FASTCALL
276 HalpXboxIoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject
,
278 IN ULONG SectorsPerTrack
,
279 IN ULONG NumberOfHeads
,
280 IN PDRIVE_LAYOUT_INFORMATION PartitionBuffer
)
282 BOOLEAN HasXboxPartitioning
;
285 DPRINT("HalpXboxIoWritePartitionTable(%p %lu %lu %lu %p)\n",
292 Status
= HalpXboxDeviceHasXboxPartitioning(DeviceObject
, SectorSize
, &HasXboxPartitioning
);
293 if (! NT_SUCCESS(Status
))
298 if (! HasXboxPartitioning
)
300 DPRINT("Delegating to standard MBR code\n");
301 return NtoskrnlIoWritePartitionTable(DeviceObject
, SectorSize
,
302 SectorsPerTrack
, NumberOfHeads
,
306 /* Can't change the partitioning */
307 DPRINT1("Xbox partitions are fixed, can't change them\n");
308 return STATUS_ACCESS_DENIED
;
311 #define HalExamineMBR HALDISPATCH->HalExamineMBR
314 HalpXboxInitPartIo(void)
316 NtoskrnlExamineMBR
= HalExamineMBR
;
317 HalExamineMBR
= HalpXboxExamineMBR
;
318 NtoskrnlIoReadPartitionTable
= HalIoReadPartitionTable
;
319 HalIoReadPartitionTable
= HalpXboxIoReadPartitionTable
;
320 NtoskrnlIoSetPartitionInformation
= HalIoSetPartitionInformation
;
321 HalIoSetPartitionInformation
= HalpXboxIoSetPartitionInformation
;
322 NtoskrnlIoWritePartitionTable
= HalIoWritePartitionTable
;
323 HalIoWritePartitionTable
= HalpXboxIoWritePartitionTable
;