Disk partitioning handling

svn path=/trunk/; revision=11981
This commit is contained in:
Gé van Geldorp
2004-12-08 11:42:28 +00:00
parent f4ad8be090
commit 284d5b4b23
6 changed files with 358 additions and 28 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
# $Id: Makefile,v 1.2 2004/12/04 22:52:59 gvg Exp $
# $Id: Makefile,v 1.3 2004/12/08 11:42:28 gvg Exp $
PATH_TO_TOP = ../../..
@@ -61,10 +61,10 @@ GENERIC_OBJECTS = \
timer.o
XBOX_OBJECTS = \
flashleds.o \
display_xbox.o \
font.o \
halinit_xbox.o \
part_xbox.o \
pci_xbox.o
HAL_OBJECTS = $(GENERIC_OBJECTS) $(XBOX_OBJECTS)
+4 -1
View File
@@ -1,4 +1,4 @@
/* $Id: display_xbox.c,v 1.1 2004/12/04 21:43:37 gvg Exp $
/* $Id: display_xbox.c,v 1.2 2004/12/08 11:42:28 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@@ -205,6 +205,9 @@ HalReleaseDisplayOwnership(VOID)
HalOwnsDisplay = TRUE;
HalpXboxClearScreenColor(DEFAULT_BG_COLOR);
CursorX = 0;
CursorY = 0;
}
+3 -1
View File
@@ -1,4 +1,4 @@
/* $Id: halinit_xbox.c,v 1.2 2004/12/04 22:52:59 gvg Exp $
/* $Id: halinit_xbox.c,v 1.3 2004/12/08 11:42:28 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@@ -29,6 +29,8 @@ HalpInitPhase0(VOID)
/* Setup busy waiting */
HalpCalibrateStallExecution();
HalpXboxInitPartIo();
}
/* EOF */
+2 -1
View File
@@ -1,4 +1,4 @@
/* $Id: halxbox.h,v 1.2 2004/12/04 22:52:59 gvg Exp $
/* $Id: halxbox.h,v 1.3 2004/12/08 11:42:28 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: Xbox HAL
@@ -15,6 +15,7 @@
extern BYTE XboxFont8x16[256 * 16];
void HalpXboxInitPciBus(ULONG BusNumber, PBUS_HANDLER BusHandler);
void HalpXboxInitPartIo(void);
#endif /* HALXBOX_H_INCLUDED */
+322
View File
@@ -0,0 +1,322 @@
/* $Id: part_xbox.c,v 1.1 2004/12/08 11:42:28 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: hal/halx86/xbox/part_xbox.c
* PURPOSE: Xbox specific handling of partition tables
* PROGRAMMER: Ge van Geldorp ([email protected])
* UPDATE HISTORY:
* 2004/12/04: Created
*/
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <hal.h>
#include "halxbox.h"
#define NDEBUG
#include <internal/debug.h>
#define XBOX_SIGNATURE_SECTOR 3
#define XBOX_SIGNATURE ('B' | ('R' << 8) | ('F' << 16) | ('R' << 24))
#define PARTITION_SIGNATURE 0xaa55
/* VARIABLES ***************************************************************/
static pHalExamineMBR NtoskrnlExamineMBR;
static pHalIoReadPartitionTable NtoskrnlIoReadPartitionTable;
static pHalIoSetPartitionInformation NtoskrnlIoSetPartitionInformation;
static pHalIoWritePartitionTable NtoskrnlIoWritePartitionTable;
static struct
{
ULONG SectorStart;
ULONG SectorCount;
BYTE PartitionType;
} XboxPartitions[] =
{
/* This is in the \Device\Harddisk0\Partition.. order used by the Xbox kernel */
{ 0x0055F400, 0x0098f800, PARTITION_FAT32 }, /* Store, E: */
{ 0x00465400, 0x000FA000, PARTITION_FAT_16 }, /* System, C: */
{ 0x00000400, 0x00177000, PARTITION_FAT_16 }, /* Cache1, X: */
{ 0x00177400, 0x00177000, PARTITION_FAT_16 }, /* Cache2, Y: */
{ 0x002EE400, 0x00177000, PARTITION_FAT_16 } /* Cache3, Z: */
};
#define XBOX_PARTITION_COUNT (sizeof(XboxPartitions) / sizeof(XboxPartitions[0]))
/* FUNCTIONS ***************************************************************/
static NTSTATUS
HalpXboxReadSector(IN PDEVICE_OBJECT DeviceObject,
IN ULONG SectorSize,
IN PLARGE_INTEGER SectorOffset,
IN PVOID Sector)
{
IO_STATUS_BLOCK StatusBlock;
KEVENT Event;
PIRP Irp;
NTSTATUS Status;
DPRINT("HalpXboxReadSector(%p %lu 0x%08x%08x %p)\n",
DeviceObject, SectorSize, SectorOffset->u.HighPart, SectorOffset->u.LowPart, Sector);
ASSERT(DeviceObject);
ASSERT(Sector);
KeInitializeEvent(&Event,
NotificationEvent,
FALSE);
/* Read the sector */
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
DeviceObject,
Sector,
SectorSize,
SectorOffset,
&Event,
&StatusBlock);
Status = IoCallDriver(DeviceObject,
Irp);
if (Status == STATUS_PENDING)
{
KeWaitForSingleObject(&Event,
Executive,
KernelMode,
FALSE,
NULL);
Status = StatusBlock.Status;
}
if (!NT_SUCCESS(Status))
{
DPRINT("Reading sector failed (Status 0x%08lx)\n",
Status);
return Status;
}
return Status;
}
static NTSTATUS FASTCALL
HalpXboxDeviceHasXboxPartitioning(PDEVICE_OBJECT DeviceObject,
ULONG SectorSize,
BOOLEAN *HasXboxPartitioning)
{
PVOID SectorData;
LARGE_INTEGER Offset;
NTSTATUS Status;
DPRINT("HalpXboxDeviceHasXboxPartitioning(%p %lu %p)\n",
DeviceObject,
SectorSize,
HasXboxPartitioning);
SectorData = ExAllocatePool(PagedPool, SectorSize);
if (NULL == SectorData)
{
return STATUS_NO_MEMORY;
}
Offset.QuadPart = XBOX_SIGNATURE_SECTOR * SectorSize;
Status = HalpXboxReadSector(DeviceObject, SectorSize, &Offset, SectorData);
if (! NT_SUCCESS(Status))
{
return Status;
}
DPRINT("Signature 0x%02x 0x%02x 0x%02x 0x%02x\n",
*((UCHAR *) SectorData), *((UCHAR *) SectorData + 1), *((UCHAR *) SectorData + 2), *((UCHAR *) SectorData + 3));
*HasXboxPartitioning = (XBOX_SIGNATURE == *((ULONG *) SectorData));
ExFreePool(SectorData);
DPRINT("%s partitioning found\n", *HasXboxPartitioning ? "Xbox" : "MBR");
return STATUS_SUCCESS;
}
static VOID FASTCALL
HalpXboxExamineMBR(IN PDEVICE_OBJECT DeviceObject,
IN ULONG SectorSize,
IN ULONG MBRTypeIdentifier,
OUT PVOID *Buffer)
{
BOOLEAN HasXboxPartitioning;
NTSTATUS Status;
DPRINT("HalpXboxExamineMBR(%p %lu %lx %p)\n",
DeviceObject,
SectorSize,
MBRTypeIdentifier,
Buffer);
*Buffer = NULL;
Status = HalpXboxDeviceHasXboxPartitioning(DeviceObject, SectorSize, &HasXboxPartitioning);
if (! NT_SUCCESS(Status))
{
return;
}
if (! HasXboxPartitioning)
{
DPRINT("Delegating to standard MBR code\n");
NtoskrnlExamineMBR(DeviceObject, SectorSize, MBRTypeIdentifier, Buffer);
return;
}
/* Buffer already set to NULL */
return;
}
static NTSTATUS FASTCALL
HalpXboxIoReadPartitionTable(PDEVICE_OBJECT DeviceObject,
ULONG SectorSize,
BOOLEAN ReturnRecognizedPartitions,
PDRIVE_LAYOUT_INFORMATION *PartitionBuffer)
{
BOOLEAN HasXboxPartitioning;
NTSTATUS Status;
unsigned Part;
PPARTITION_INFORMATION PartInfo;
DPRINT("HalpXboxIoReadPartitionTable(%p %lu %x %p)\n",
DeviceObject,
SectorSize,
ReturnRecognizedPartitions,
PartitionBuffer);
Status = HalpXboxDeviceHasXboxPartitioning(DeviceObject, SectorSize, &HasXboxPartitioning);
if (! NT_SUCCESS(Status))
{
return Status;
}
if (! HasXboxPartitioning)
{
DPRINT("Delegating to standard MBR code\n");
return NtoskrnlIoReadPartitionTable(DeviceObject, SectorSize,
ReturnRecognizedPartitions, PartitionBuffer);
}
*PartitionBuffer = (PDRIVE_LAYOUT_INFORMATION)
ExAllocatePool(PagedPool,
sizeof(DRIVE_LAYOUT_INFORMATION) +
XBOX_PARTITION_COUNT * sizeof(PARTITION_INFORMATION));
if (NULL == *PartitionBuffer)
{
return STATUS_NO_MEMORY;
}
(*PartitionBuffer)->PartitionCount = XBOX_PARTITION_COUNT;
(*PartitionBuffer)->Signature = PARTITION_SIGNATURE;
for (Part = 0; Part < XBOX_PARTITION_COUNT; Part++)
{
PartInfo = (*PartitionBuffer)->PartitionEntry + Part;
PartInfo->StartingOffset.QuadPart = (ULONGLONG) XboxPartitions[Part].SectorStart *
(ULONGLONG) SectorSize;
PartInfo->PartitionLength.QuadPart = (ULONGLONG) XboxPartitions[Part].SectorCount *
(ULONGLONG) SectorSize;
PartInfo->HiddenSectors = 0;
PartInfo->PartitionNumber = Part + 1;
PartInfo->PartitionType = XboxPartitions[Part].PartitionType;
PartInfo->BootIndicator = FALSE;
PartInfo->RecognizedPartition = TRUE;
PartInfo->RewritePartition = FALSE;
DPRINT(" %ld: nr: %d boot: %1x type: %x start: 0x%I64x count: 0x%I64x rec: %d\n",
Part,
PartInfo->PartitionNumber,
PartInfo->BootIndicator,
PartInfo->PartitionType,
PartInfo->StartingOffset.QuadPart,
PartInfo->PartitionLength.QuadPart,
PartInfo->RecognizedPartition);
}
return STATUS_SUCCESS;
}
static NTSTATUS FASTCALL
HalpXboxIoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject,
IN ULONG SectorSize,
IN ULONG PartitionNumber,
IN ULONG PartitionType)
{
BOOLEAN HasXboxPartitioning;
NTSTATUS Status;
DPRINT("HalpXboxIoSetPartitionInformation(%p %lu %lu %lu)\n",
DeviceObject,
SectorSize,
PartitionNumber,
PartitionType);
Status = HalpXboxDeviceHasXboxPartitioning(DeviceObject, SectorSize, &HasXboxPartitioning);
if (! NT_SUCCESS(Status))
{
return Status;
}
if (! HasXboxPartitioning)
{
DPRINT("Delegating to standard MBR code\n");
return NtoskrnlIoSetPartitionInformation(DeviceObject, SectorSize,
PartitionNumber, PartitionType);
}
/* Can't change the partitioning */
DPRINT1("Xbox partitions are fixed, can't change them\n");
return STATUS_ACCESS_DENIED;
}
static NTSTATUS FASTCALL
HalpXboxIoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject,
IN ULONG SectorSize,
IN ULONG SectorsPerTrack,
IN ULONG NumberOfHeads,
IN PDRIVE_LAYOUT_INFORMATION PartitionBuffer)
{
BOOLEAN HasXboxPartitioning;
NTSTATUS Status;
DPRINT("HalpXboxIoWritePartitionTable(%p %lu %lu %lu %p)\n",
DeviceObject,
SectorSize,
SectorsPerTrack,
NumberOfHeads,
PartitionBuffer);
Status = HalpXboxDeviceHasXboxPartitioning(DeviceObject, SectorSize, &HasXboxPartitioning);
if (! NT_SUCCESS(Status))
{
return Status;
}
if (! HasXboxPartitioning)
{
DPRINT("Delegating to standard MBR code\n");
return NtoskrnlIoWritePartitionTable(DeviceObject, SectorSize,
SectorsPerTrack, NumberOfHeads,
PartitionBuffer);
}
/* Can't change the partitioning */
DPRINT1("Xbox partitions are fixed, can't change them\n");
return STATUS_ACCESS_DENIED;
}
void
HalpXboxInitPartIo(void)
{
NtoskrnlExamineMBR = HalExamineMBR;
HalExamineMBR = HalpXboxExamineMBR;
NtoskrnlIoReadPartitionTable = HalIoReadPartitionTable;
HalIoReadPartitionTable = HalpXboxIoReadPartitionTable;
NtoskrnlIoSetPartitionInformation = HalIoSetPartitionInformation;
HalIoSetPartitionInformation = HalpXboxIoSetPartitionInformation;
NtoskrnlIoWritePartitionTable = HalIoWritePartitionTable;
HalIoWritePartitionTable = HalpXboxIoWritePartitionTable;
}
/* EOF */
+25 -23
View File
@@ -1,4 +1,4 @@
/* $Id: haltypes.h,v 1.9 2004/11/21 06:51:17 ion Exp $
/* $Id: haltypes.h,v 1.10 2004/12/08 11:42:28 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@@ -363,7 +363,7 @@ typedef enum _RESOURCE_TRANSLATION_DIRECTION {
TranslateParentToChild
} RESOURCE_TRANSLATION_DIRECTION;
typedef NTSTATUS STDCALL
typedef NTSTATUS STDCALL_FUNC
(*PTRANSLATE_RESOURCE_HANDLER)(IN PVOID Context,
IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Source,
IN RESOURCE_TRANSLATION_DIRECTION Direction,
@@ -373,7 +373,7 @@ typedef NTSTATUS STDCALL
OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Target
);
typedef NTSTATUS STDCALL
typedef NTSTATUS STDCALL_FUNC
(*PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER)(IN PVOID Context,
IN PIO_RESOURCE_DESCRIPTOR Source,
IN PDEVICE_OBJECT PhysicalDeviceObject,
@@ -470,7 +470,7 @@ typedef struct _PM_DISPATCH_TABLE {
typedef VOID STDCALL_FUNC
(*PDEVICE_CONTROL_COMPLETION)(IN PDEVICE_CONTROL_CONTEXT ControlContext);
typedef NTSTATUS STDCALL
typedef NTSTATUS STDCALL_FUNC
(*pHalDeviceControl)(IN PDEVICE_HANDLER_OBJECT DeviceHandler,
IN PDEVICE_OBJECT DeviceObject,
IN ULONG ControlCode,
@@ -479,76 +479,76 @@ typedef NTSTATUS STDCALL
IN PVOID Context,
IN PDEVICE_CONTROL_COMPLETION CompletionRoutine);
typedef VOID FASTCALL
typedef VOID FASTCALL_FUNC
(*pHalExamineMBR)(IN PDEVICE_OBJECT DeviceObject,
IN ULONG SectorSize,
IN ULONG MBRTypeIdentifier,
OUT PVOID *Buffer);
typedef VOID FASTCALL
typedef VOID FASTCALL_FUNC
(*pHalIoAssignDriveLetters)(IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
IN PSTRING NtDeviceName,
OUT PUCHAR NtSystemPath,
OUT PSTRING NtSystemPathString);
typedef NTSTATUS FASTCALL
typedef NTSTATUS FASTCALL_FUNC
(*pHalIoReadPartitionTable)(IN PDEVICE_OBJECT DeviceObject,
IN ULONG SectorSize,
IN BOOLEAN ReturnRecognizedPartitions,
OUT PDRIVE_LAYOUT_INFORMATION *PartitionBuffer);
typedef NTSTATUS FASTCALL
typedef NTSTATUS FASTCALL_FUNC
(*pHalIoSetPartitionInformation)(IN PDEVICE_OBJECT DeviceObject,
IN ULONG SectorSize,
IN ULONG PartitionNumber,
IN ULONG PartitionType);
typedef NTSTATUS FASTCALL
typedef NTSTATUS FASTCALL_FUNC
(*pHalIoWritePartitionTable)(IN PDEVICE_OBJECT DeviceObject,
IN ULONG SectorSize,
IN ULONG SectorsPerTrack,
IN ULONG NumberOfHeads,
IN PDRIVE_LAYOUT_INFORMATION PartitionBuffer);
typedef PBUS_HANDLER FASTCALL
typedef PBUS_HANDLER FASTCALL_FUNC
(*pHalHandlerForBus)(IN INTERFACE_TYPE InterfaceType,
IN ULONG BusNumber);
typedef VOID FASTCALL
typedef VOID FASTCALL_FUNC
(*pHalReferenceBusHandler)(IN PBUS_HANDLER BusHandler);
typedef NTSTATUS STDCALL
typedef NTSTATUS STDCALL_FUNC
(*pHalQuerySystemInformation)(IN HAL_QUERY_INFORMATION_CLASS InformationClass,
IN ULONG BufferSize,
IN OUT PVOID Buffer,
OUT PULONG ReturnedLength);
typedef NTSTATUS STDCALL
typedef NTSTATUS STDCALL_FUNC
(*pHalSetSystemInformation)(IN HAL_SET_INFORMATION_CLASS InformationClass,
IN ULONG BufferSize,
IN PVOID Buffer);
typedef NTSTATUS STDCALL
typedef NTSTATUS STDCALL_FUNC
(*pHalQueryBusSlots)(IN PBUS_HANDLER BusHandler,
IN ULONG BufferSize,
OUT PULONG SlotNumbers,
OUT PULONG ReturnedLength);
typedef NTSTATUS STDCALL
typedef NTSTATUS STDCALL_FUNC
(*pHalInitPnpDriver)(VOID);
typedef NTSTATUS STDCALL
typedef NTSTATUS STDCALL_FUNC
(*pHalInitPowerManagement)(IN PPM_DISPATCH_TABLE PmDriverDispatchTable,
OUT PPM_DISPATCH_TABLE *PmHalDispatchTable);
typedef struct _DMA_ADAPTER * STDCALL
typedef struct _DMA_ADAPTER * STDCALL_FUNC
(*pHalGetDmaAdapter)(IN PVOID Context,
IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
OUT PULONG NumberOfMapRegisters);
typedef NTSTATUS STDCALL
typedef NTSTATUS STDCALL_FUNC
(*pHalGetInterruptTranslator)(IN INTERFACE_TYPE ParentInterfaceType,
IN ULONG ParentBusNumber,
IN INTERFACE_TYPE BridgeInterfaceType,
@@ -557,19 +557,21 @@ typedef NTSTATUS STDCALL
OUT PTRANSLATOR_INTERFACE Translator,
OUT PULONG BridgeBusNumber);
typedef NTSTATUS STDCALL (*pHalStartMirroring)(VOID);
typedef NTSTATUS STDCALL_FUNC
(*pHalStartMirroring)(VOID);
typedef NTSTATUS STDCALL (*pHalEndMirroring)(IN ULONG PassNumber);
typedef NTSTATUS STDCALL_FUNC
(*pHalEndMirroring)(IN ULONG PassNumber);
typedef NTSTATUS STDCALL
typedef NTSTATUS STDCALL_FUNC
(*pHalMirrorPhysicalMemory)(IN PHYSICAL_ADDRESS PhysicalAddress,
IN LARGE_INTEGER NumberOfBytes);
typedef NTSTATUS STDCALL
typedef NTSTATUS STDCALL_FUNC
(*pHalMirrorVerify)(IN PHYSICAL_ADDRESS PhysicalAddress,
IN LARGE_INTEGER NumberOfBytes);
typedef VOID STDCALL
typedef VOID STDCALL_FUNC
(*pHalEndOfBoot)(VOID);