ReactOS 0.4.16-dev-306-g647d351
part_xbox.c
Go to the documentation of this file.
1/*
2 * PROJECT: Xbox HAL
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Xbox specific handling of partition tables
5 * COPYRIGHT: Copyright 2004 Ge van Geldorp (gvg@reactos.com)
6 * Copyright 2020 Stanislav Motylkov (x86corez@gmail.com)
7 */
8
9/* INCLUDES *****************************************************************/
10
11#include "halxbox.h"
12#include <internal/tag.h>
13
14#define NDEBUG
15#include <debug.h>
16
17#define XBOX_SIGNATURE_SECTOR 3
18#define XBOX_SIGNATURE ('B' | ('R' << 8) | ('F' << 16) | ('R' << 24))
19#define PARTITION_SIGNATURE 0xaa55
20
21/* VARIABLES ***************************************************************/
22
27
28static struct
29{
34{
35 /* This is in the \Device\Harddisk0\Partition.. order used by the Xbox kernel */
36 { 0x0055F400, 0x0098f800, PARTITION_FAT32 }, /* Store, E: */
37 { 0x00465400, 0x000FA000, PARTITION_FAT_16 }, /* System, C: */
38 { 0x00000400, 0x00177000, PARTITION_FAT_16 }, /* Cache1, X: */
39 { 0x00177400, 0x00177000, PARTITION_FAT_16 }, /* Cache2, Y: */
40 { 0x002EE400, 0x00177000, PARTITION_FAT_16 } /* Cache3, Z: */
41};
42
43#define XBOX_PARTITION_COUNT (sizeof(XboxPartitions) / sizeof(XboxPartitions[0]))
44
45/* FUNCTIONS ***************************************************************/
46
47
48static NTSTATUS
52 OUT PVOID Sector)
53{
54 IO_STATUS_BLOCK StatusBlock;
56 PIRP Irp;
58
59 DPRINT("HalpXboxReadSector(%p %lu 0x%08x%08x %p)\n",
60 DeviceObject, SectorSize, SectorOffset->u.HighPart, SectorOffset->u.LowPart, Sector);
61
63 ASSERT(Sector);
64
67 FALSE);
68
69 /* Read the sector */
72 Sector,
75 &Event,
76 &StatusBlock);
78
80 Irp);
82 {
86 FALSE,
87 NULL);
88 Status = StatusBlock.Status;
89 }
90
91 if (!NT_SUCCESS(Status))
92 {
93 DPRINT("Reading sector failed (Status 0x%08lx)\n", Status);
94 return Status;
95 }
96
97 return Status;
98}
99
100static NTSTATUS FASTCALL
103 OUT BOOLEAN *HasXboxPartitioning)
104{
105 PVOID SectorData;
108 BOOLEAN HasMBRPartitioning;
109
110 DPRINT("HalpXboxDeviceHasXboxPartitioning(%p %lu %p)\n",
113 HasXboxPartitioning);
114
116 if (!SectorData)
117 {
118 return STATUS_NO_MEMORY;
119 }
120
121 Offset.QuadPart = 0;
123 if (!NT_SUCCESS(Status))
124 {
125 goto Cleanup;
126 }
127
128 HasMBRPartitioning = (*((USHORT *)SectorData + (SectorSize / sizeof(USHORT)) - 1) == PARTITION_SIGNATURE);
129 if (HasMBRPartitioning)
130 {
131 *HasXboxPartitioning = FALSE;
132 goto Cleanup;
133 }
134
137 if (!NT_SUCCESS(Status))
138 {
139 goto Cleanup;
140 }
141
142 DPRINT("Signature 0x%02x 0x%02x 0x%02x 0x%02x\n",
143 *((UCHAR *) SectorData), *((UCHAR *) SectorData + 1), *((UCHAR *) SectorData + 2), *((UCHAR *) SectorData + 3));
144 *HasXboxPartitioning = (XBOX_SIGNATURE == *((ULONG *) SectorData));
145Cleanup:
146 ExFreePoolWithTag(SectorData, TAG_HAL_XBOX);
147 if (NT_SUCCESS(Status))
148 {
149 DPRINT("%s partitioning found\n", *HasXboxPartitioning ? "Xbox" : "MBR");
150 }
151
152 return Status;
153}
154
155static VOID FASTCALL
160{
161 BOOLEAN HasXboxPartitioning;
163
164 DPRINT("HalpXboxExamineMBR(%p %lu %lx %p)\n",
168 Buffer);
169
170 *Buffer = NULL;
171
173 if (!NT_SUCCESS(Status))
174 {
175 return;
176 }
177
178 if (!HasXboxPartitioning)
179 {
180 DPRINT("Delegating to standard MBR code\n");
182 return;
183 }
184
185 /* Buffer already set to NULL */
186 return;
187}
188
189static NTSTATUS FASTCALL
194{
195 BOOLEAN HasXboxPartitioning;
197 ULONG Part;
198 PPARTITION_INFORMATION PartInfo;
199
200 DPRINT("HalpXboxIoReadPartitionTable(%p %lu %x %p)\n",
205
207 if (!NT_SUCCESS(Status))
208 {
209 return Status;
210 }
211
212 if (!HasXboxPartitioning)
213 {
214 DPRINT("Delegating to standard MBR code\n");
217 }
218
220 PagedPool,
224 if (*PartitionBuffer == NULL)
225 {
226 return STATUS_NO_MEMORY;
227 }
228 (*PartitionBuffer)->PartitionCount = XBOX_PARTITION_COUNT;
229 (*PartitionBuffer)->Signature = PARTITION_SIGNATURE;
230 for (Part = 0; Part < XBOX_PARTITION_COUNT; Part++)
231 {
232 PartInfo = (*PartitionBuffer)->PartitionEntry + Part;
237 PartInfo->HiddenSectors = 0;
238 PartInfo->PartitionNumber = Part + 1;
239 PartInfo->PartitionType = XboxPartitions[Part].PartitionType;
240 PartInfo->BootIndicator = FALSE;
241 PartInfo->RecognizedPartition = TRUE;
242 PartInfo->RewritePartition = FALSE;
243 DPRINT(" %ld: nr: %d boot: %1x type: %x start: 0x%I64x count: 0x%I64x rec: %d\n",
244 Part,
245 PartInfo->PartitionNumber,
246 PartInfo->BootIndicator,
247 PartInfo->PartitionType,
248 PartInfo->StartingOffset.QuadPart,
249 PartInfo->PartitionLength.QuadPart,
250 PartInfo->RecognizedPartition);
251 }
252
253 return STATUS_SUCCESS;
254}
255
256static NTSTATUS FASTCALL
261{
262 BOOLEAN HasXboxPartitioning;
264
265 DPRINT("HalpXboxIoSetPartitionInformation(%p %lu %lu %lu)\n",
270
272 if (!NT_SUCCESS(Status))
273 {
274 return Status;
275 }
276
277 if (!HasXboxPartitioning)
278 {
279 DPRINT("Delegating to standard MBR code\n");
282 }
283
284 /* Can't change the partitioning */
285 DPRINT1("Xbox partitions are fixed, can't change them\n");
287}
288
289static NTSTATUS FASTCALL
295{
296 BOOLEAN HasXboxPartitioning;
298
299 DPRINT("HalpXboxIoWritePartitionTable(%p %lu %lu %lu %p)\n",
305
307 if (!NT_SUCCESS(Status))
308 {
309 return Status;
310 }
311
312 if (!HasXboxPartitioning)
313 {
314 DPRINT("Delegating to standard MBR code\n");
318 }
319
320 /* Can't change the partitioning */
321 DPRINT1("Xbox partitions are fixed, can't change them\n");
323}
324
325#define HalExamineMBR HALDISPATCH->HalExamineMBR
326#define HalIoReadPartitionTable HALDISPATCH->HalIoReadPartitionTable
327#define HalIoSetPartitionInformation HALDISPATCH->HalIoSetPartitionInformation
328#define HalIoWritePartitionTable HALDISPATCH->HalIoWritePartitionTable
329
330void
332{
341}
342
343/* EOF */
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define PARTITION_FAT32
Definition: disk.h:96
#define PARTITION_FAT_16
Definition: disk.h:91
#define SectorOffset(L)
Definition: cdprocs.h:1622
Definition: bufpool.h:45
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
static const WCHAR Cleanup[]
Definition: register.c:80
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:25
#define TAG_HAL_XBOX
Definition: halxbox.h:20
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define KernelMode
Definition: asm.h:34
#define FASTCALL
Definition: nt_native.h:50
struct _DRIVE_LAYOUT_INFORMATION * PDRIVE_LAYOUT_INFORMATION
struct _PARTITION_INFORMATION PARTITION_INFORMATION
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
@ NotificationEvent
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
#define IoCallDriver
Definition: irp.c:1225
#define XBOX_SIGNATURE_SECTOR
Definition: part_xbox.c:17
void HalpXboxInitPartIo(void)
Definition: part_xbox.c:331
static pHalIoWritePartitionTable NtoskrnlIoWritePartitionTable
Definition: part_xbox.c:26
static NTSTATUS HalpXboxReadSector(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN PLARGE_INTEGER SectorOffset, OUT PVOID Sector)
Definition: part_xbox.c:49
static NTSTATUS FASTCALL HalpXboxDeviceHasXboxPartitioning(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, OUT BOOLEAN *HasXboxPartitioning)
Definition: part_xbox.c:101
static NTSTATUS FASTCALL HalpXboxIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN BOOLEAN ReturnRecognizedPartitions, OUT PDRIVE_LAYOUT_INFORMATION *PartitionBuffer)
Definition: part_xbox.c:190
#define XBOX_PARTITION_COUNT
Definition: part_xbox.c:43
ULONG SectorStart
Definition: part_xbox.c:30
#define XBOX_SIGNATURE
Definition: part_xbox.c:18
static VOID FASTCALL HalpXboxExamineMBR(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG MBRTypeIdentifier, OUT PVOID *Buffer)
Definition: part_xbox.c:156
static struct @1543 XboxPartitions[]
#define HalIoWritePartitionTable
Definition: part_xbox.c:328
ULONG SectorCount
Definition: part_xbox.c:31
CHAR PartitionType
Definition: part_xbox.c:32
static NTSTATUS FASTCALL HalpXboxIoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG PartitionNumber, IN ULONG PartitionType)
Definition: part_xbox.c:257
#define HalExamineMBR
Definition: part_xbox.c:325
#define HalIoSetPartitionInformation
Definition: part_xbox.c:327
#define HalIoReadPartitionTable
Definition: part_xbox.c:326
static NTSTATUS FASTCALL HalpXboxIoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG SectorsPerTrack, IN ULONG NumberOfHeads, IN PDRIVE_LAYOUT_INFORMATION PartitionBuffer)
Definition: part_xbox.c:290
#define PARTITION_SIGNATURE
Definition: part_xbox.c:19
static pHalExamineMBR NtoskrnlExamineMBR
Definition: part_xbox.c:23
static pHalIoReadPartitionTable NtoskrnlIoReadPartitionTable
Definition: part_xbox.c:24
static pHalIoSetPartitionInformation NtoskrnlIoSetPartitionInformation
Definition: part_xbox.c:25
unsigned short USHORT
Definition: pedump.c:61
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
LARGE_INTEGER StartingOffset
Definition: ntdddisk.h:408
LARGE_INTEGER PartitionLength
Definition: ntdddisk.h:409
BOOLEAN RecognizedPartition
Definition: ntdddisk.h:414
BOOLEAN RewritePartition
Definition: ntdddisk.h:415
#define TAG_FILE_SYSTEM
Definition: tag.h:65
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#define OUT
Definition: typedefs.h:40
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ ULONG _In_ ULONG MBRTypeIdentifier
Definition: halfuncs.h:292
_In_ ULONG SectorSize
Definition: halfuncs.h:291
NTSTATUS(FASTCALL * pHalIoSetPartitionInformation)(_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG SectorSize, _In_ ULONG PartitionNumber, _In_ ULONG PartitionType)
Definition: haltypes.h:92
NTSTATUS(FASTCALL * pHalIoWritePartitionTable)(_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG SectorSize, _In_ ULONG SectorsPerTrack, _In_ ULONG NumberOfHeads, _In_ struct _DRIVE_LAYOUT_INFORMATION *PartitionBuffer)
Definition: haltypes.h:99
NTSTATUS(FASTCALL * pHalIoReadPartitionTable)(_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG SectorSize, _In_ BOOLEAN ReturnRecognizedPartitions, _Out_ struct _DRIVE_LAYOUT_INFORMATION **PartitionBuffer)
Definition: haltypes.h:85
VOID(FASTCALL * pHalExamineMBR)(_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG SectorSize, _In_ ULONG MBRTypeIdentifier, _Out_ PVOID *Buffer)
Definition: haltypes.h:78
_In_ ULONG _In_ ULONG _In_ ULONG NumberOfHeads
Definition: iofuncs.h:2072
_In_ ULONG _In_ BOOLEAN ReturnRecognizedPartitions
Definition: iofuncs.h:2051
_In_ ULONG _In_ ULONG SectorsPerTrack
Definition: iofuncs.h:2071
_In_ ULONG _In_ BOOLEAN _Out_ struct _DRIVE_LAYOUT_INFORMATION ** PartitionBuffer
Definition: iofuncs.h:2052
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2061
@ Executive
Definition: ketypes.h:415
unsigned char UCHAR
Definition: xmlstorage.h:181
char CHAR
Definition: xmlstorage.h:175