ReactOS  0.4.13-dev-92-gf251225
part_xbox.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * FILE: hal/halx86/xbox/part_xbox.c
5  * PURPOSE: Xbox specific handling of partition tables
6  * PROGRAMMER: Ge van Geldorp (gvg@reactos.com)
7  * UPDATE HISTORY:
8  * 2004/12/04: Created
9  */
10 
11 /* INCLUDES *****************************************************************/
12 
13 #include "halxbox.h"
14 
15 #define NDEBUG
16 #include <debug.h>
17 
18 #define XBOX_SIGNATURE_SECTOR 3
19 #define XBOX_SIGNATURE ('B' | ('R' << 8) | ('F' << 16) | ('R' << 24))
20 #define PARTITION_SIGNATURE 0xaa55
21 
22 /* VARIABLES ***************************************************************/
23 
28 
29 static struct
30 {
34 } XboxPartitions[] =
35 {
36  /* This is in the \Device\Harddisk0\Partition.. order used by the Xbox kernel */
37  { 0x0055F400, 0x0098f800, PARTITION_FAT32 }, /* Store, E: */
38  { 0x00465400, 0x000FA000, PARTITION_FAT_16 }, /* System, C: */
39  { 0x00000400, 0x00177000, PARTITION_FAT_16 }, /* Cache1, X: */
40  { 0x00177400, 0x00177000, PARTITION_FAT_16 }, /* Cache2, Y: */
41  { 0x002EE400, 0x00177000, PARTITION_FAT_16 } /* Cache3, Z: */
42 };
43 
44 #define XBOX_PARTITION_COUNT (sizeof(XboxPartitions) / sizeof(XboxPartitions[0]))
45 
46 /* FUNCTIONS ***************************************************************/
47 
48 
49 static NTSTATUS
53  OUT PVOID Sector)
54 {
55  IO_STATUS_BLOCK StatusBlock;
56  KEVENT Event;
57  PIRP Irp;
59 
60  DPRINT("HalpXboxReadSector(%p %lu 0x%08x%08x %p)\n",
61  DeviceObject, SectorSize, SectorOffset->u.HighPart, SectorOffset->u.LowPart, Sector);
62 
64  ASSERT(Sector);
65 
68  FALSE);
69 
70  /* Read the sector */
73  Sector,
74  SectorSize,
76  &Event,
77  &StatusBlock);
79 
81  Irp);
82  if (Status == STATUS_PENDING)
83  {
85  Executive,
86  KernelMode,
87  FALSE,
88  NULL);
89  Status = StatusBlock.Status;
90  }
91 
92  if (!NT_SUCCESS(Status))
93  {
94  DPRINT("Reading sector failed (Status 0x%08lx)\n", Status);
95  return Status;
96  }
97 
98  return Status;
99 }
100 
101 static NTSTATUS FASTCALL
104  OUT BOOLEAN *HasXboxPartitioning)
105 {
106  PVOID SectorData;
109 
110  DPRINT("HalpXboxDeviceHasXboxPartitioning(%p %lu %p)\n",
111  DeviceObject,
112  SectorSize,
113  HasXboxPartitioning);
114 
115  SectorData = ExAllocatePool(PagedPool, SectorSize);
116  if (!SectorData)
117  {
118  return STATUS_NO_MEMORY;
119  }
120 
123  if (! NT_SUCCESS(Status))
124  {
125  return Status;
126  }
127 
128  DPRINT("Signature 0x%02x 0x%02x 0x%02x 0x%02x\n",
129  *((UCHAR *) SectorData), *((UCHAR *) SectorData + 1), *((UCHAR *) SectorData + 2), *((UCHAR *) SectorData + 3));
130  *HasXboxPartitioning = (XBOX_SIGNATURE == *((ULONG *) SectorData));
131  ExFreePool(SectorData);
132  DPRINT("%s partitioning found\n", *HasXboxPartitioning ? "Xbox" : "MBR");
133 
134  return STATUS_SUCCESS;
135 }
136 
137 static VOID FASTCALL
141  OUT PVOID *Buffer)
142 {
143  BOOLEAN HasXboxPartitioning;
145 
146  DPRINT("HalpXboxExamineMBR(%p %lu %lx %p)\n",
147  DeviceObject,
148  SectorSize,
150  Buffer);
151 
152  *Buffer = NULL;
153 
155  if (! NT_SUCCESS(Status))
156  {
157  return;
158  }
159 
160  if (! HasXboxPartitioning)
161  {
162  DPRINT("Delegating to standard MBR code\n");
164  return;
165  }
166 
167  /* Buffer already set to NULL */
168  return;
169 }
170 
171 static NTSTATUS FASTCALL
176 {
177  BOOLEAN HasXboxPartitioning;
179  ULONG Part;
180  PPARTITION_INFORMATION PartInfo;
181 
182  DPRINT("HalpXboxIoReadPartitionTable(%p %lu %x %p)\n",
183  DeviceObject,
184  SectorSize,
187 
189  if (! NT_SUCCESS(Status))
190  {
191  return Status;
192  }
193 
194  if (! HasXboxPartitioning)
195  {
196  DPRINT("Delegating to standard MBR code\n");
199  }
200 
202  PagedPool,
203  sizeof(DRIVE_LAYOUT_INFORMATION) +
205  'SYSF');
206  if (NULL == *PartitionBuffer)
207  {
208  return STATUS_NO_MEMORY;
209  }
210  (*PartitionBuffer)->PartitionCount = XBOX_PARTITION_COUNT;
211  (*PartitionBuffer)->Signature = PARTITION_SIGNATURE;
212  for (Part = 0; Part < XBOX_PARTITION_COUNT; Part++)
213  {
214  PartInfo = (*PartitionBuffer)->PartitionEntry + Part;
219  PartInfo->HiddenSectors = 0;
220  PartInfo->PartitionNumber = Part + 1;
221  PartInfo->PartitionType = XboxPartitions[Part].PartitionType;
222  PartInfo->BootIndicator = FALSE;
223  PartInfo->RecognizedPartition = TRUE;
224  PartInfo->RewritePartition = FALSE;
225  DPRINT(" %ld: nr: %d boot: %1x type: %x start: 0x%I64x count: 0x%I64x rec: %d\n",
226  Part,
227  PartInfo->PartitionNumber,
228  PartInfo->BootIndicator,
229  PartInfo->PartitionType,
230  PartInfo->StartingOffset.QuadPart,
231  PartInfo->PartitionLength.QuadPart,
232  PartInfo->RecognizedPartition);
233  }
234 
235  return STATUS_SUCCESS;
236 }
237 
238 static NTSTATUS FASTCALL
243 {
244  BOOLEAN HasXboxPartitioning;
246 
247  DPRINT("HalpXboxIoSetPartitionInformation(%p %lu %lu %lu)\n",
248  DeviceObject,
249  SectorSize,
251  PartitionType);
252 
254  if (! NT_SUCCESS(Status))
255  {
256  return Status;
257  }
258 
259  if (!HasXboxPartitioning)
260  {
261  DPRINT("Delegating to standard MBR code\n");
264  }
265 
266  /* Can't change the partitioning */
267  DPRINT1("Xbox partitions are fixed, can't change them\n");
268  return STATUS_ACCESS_DENIED;
269 }
270 
271 static NTSTATUS FASTCALL
277 {
278  BOOLEAN HasXboxPartitioning;
280 
281  DPRINT("HalpXboxIoWritePartitionTable(%p %lu %lu %lu %p)\n",
282  DeviceObject,
283  SectorSize,
287 
289  if (! NT_SUCCESS(Status))
290  {
291  return Status;
292  }
293 
294  if (!HasXboxPartitioning)
295  {
296  DPRINT("Delegating to standard MBR code\n");
300  }
301 
302  /* Can't change the partitioning */
303  DPRINT1("Xbox partitions are fixed, can't change them\n");
304  return STATUS_ACCESS_DENIED;
305 }
306 
307 #define HalExamineMBR HALDISPATCH->HalExamineMBR
308 #define HalIoReadPartitionTable HALDISPATCH->HalIoReadPartitionTable
309 #define HalIoSetPartitionInformation HALDISPATCH->HalIoSetPartitionInformation
310 #define HalIoWritePartitionTable HALDISPATCH->HalIoWritePartitionTable
311 
312 void
314 {
323 }
324 
325 /* EOF */
#define PARTITION_FAT32
Definition: disk.h:95
void HalpXboxInitPartIo(void)
Definition: part_xbox.c:313
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
LARGE_INTEGER PartitionLength
Definition: ntdddisk.h:394
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ULONG SectorStart
Definition: part_xbox.c:31
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
_In_ PIRP Irp
Definition: csq.h:116
#define PARTITION_SIGNATURE
Definition: part_xbox.c:20
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
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
static VOID FASTCALL HalpXboxExamineMBR(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG MBRTypeIdentifier, OUT PVOID *Buffer)
Definition: part_xbox.c:138
#define XBOX_PARTITION_COUNT
Definition: part_xbox.c:44
_In_ ULONG _In_ ULONG _In_ ULONG NumberOfHeads
Definition: iofuncs.h:2066
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:272
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
struct _PARTITION_INFORMATION PARTITION_INFORMATION
static pHalIoSetPartitionInformation NtoskrnlIoSetPartitionInformation
Definition: part_xbox.c:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define FASTCALL
Definition: nt_native.h:50
#define HalIoReadPartitionTable
Definition: part_xbox.c:308
#define HalIoSetPartitionInformation
Definition: part_xbox.c:309
NTSTATUS(FASTCALL * pHalIoReadPartitionTable)(_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG SectorSize, _In_ BOOLEAN ReturnRecognizedPartitions, _Out_ struct _DRIVE_LAYOUT_INFORMATION **PartitionBuffer)
Definition: haltypes.h:85
_In_ ULONG _In_ ULONG SectorsPerTrack
Definition: iofuncs.h:2066
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
NTSTATUS(FASTCALL * pHalIoSetPartitionInformation)(_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG SectorSize, _In_ ULONG PartitionNumber, _In_ ULONG PartitionType)
Definition: haltypes.h:92
static NTSTATUS HalpXboxReadSector(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN PLARGE_INTEGER SectorOffset, OUT PVOID Sector)
Definition: part_xbox.c:50
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
_In_ ULONG _In_ BOOLEAN _Out_ struct _DRIVE_LAYOUT_INFORMATION ** PartitionBuffer
Definition: iofuncs.h:2048
#define SectorOffset(L)
Definition: cdprocs.h:1632
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
static struct @1485 XboxPartitions[]
#define HalIoWritePartitionTable
Definition: part_xbox.c:310
#define XBOX_SIGNATURE_SECTOR
Definition: part_xbox.c:18
#define HalExamineMBR
Definition: part_xbox.c:307
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
LARGE_INTEGER StartingOffset
Definition: ntdddisk.h:393
uint64_t ULONGLONG
Definition: typedefs.h:65
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define PARTITION_FAT_16
Definition: disk.h:90
static pHalExamineMBR NtoskrnlExamineMBR
Definition: part_xbox.c:24
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
BOOLEAN RewritePartition
Definition: ntdddisk.h:400
unsigned char UCHAR
Definition: xmlstorage.h:181
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
_In_ ULONG _In_ BOOLEAN ReturnRecognizedPartitions
Definition: iofuncs.h:2046
VOID(FASTCALL * pHalExamineMBR)(_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG SectorSize, _In_ ULONG MBRTypeIdentifier, _Out_ PVOID *Buffer)
Definition: haltypes.h:78
static NTSTATUS FASTCALL HalpXboxIoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG PartitionNumber, IN ULONG PartitionType)
Definition: part_xbox.c:239
ULONG SectorCount
Definition: part_xbox.c:32
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
static pHalIoWritePartitionTable NtoskrnlIoWritePartitionTable
Definition: part_xbox.c:27
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_In_ ULONG _In_ ULONG MBRTypeIdentifier
Definition: halfuncs.h:291
struct _DRIVE_LAYOUT_INFORMATION * PDRIVE_LAYOUT_INFORMATION
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
static NTSTATUS FASTCALL HalpXboxDeviceHasXboxPartitioning(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, OUT BOOLEAN *HasXboxPartitioning)
Definition: part_xbox.c:102
#define DPRINT1
Definition: precomp.h:8
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define OUT
Definition: typedefs.h:39
static NTSTATUS FASTCALL HalpXboxIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN BOOLEAN ReturnRecognizedPartitions, OUT PDRIVE_LAYOUT_INFORMATION *PartitionBuffer)
Definition: part_xbox.c:172
CHAR PartitionType
Definition: part_xbox.c:33
unsigned int ULONG
Definition: retypes.h:1
#define XBOX_SIGNATURE
Definition: part_xbox.c:19
BOOLEAN RecognizedPartition
Definition: ntdddisk.h:399
_In_ ULONG SectorSize
Definition: halfuncs.h:291
return STATUS_SUCCESS
Definition: btrfs.c:2725
static pHalIoReadPartitionTable NtoskrnlIoReadPartitionTable
Definition: part_xbox.c:25
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
LONGLONG QuadPart
Definition: typedefs.h:112