ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

part_xbox.c
Go to the documentation of this file.
00001 /* $Id: part_xbox.c 43124 2009-09-23 20:59:08Z hpoussin $
00002  *
00003  * COPYRIGHT:     See COPYING in the top level directory
00004  * PROJECT:       ReactOS kernel
00005  * FILE:          hal/halx86/xbox/part_xbox.c
00006  * PURPOSE:       Xbox specific handling of partition tables
00007  * PROGRAMMER:    Ge van Geldorp (gvg@reactos.com)
00008  * UPDATE HISTORY:
00009  *             2004/12/04: Created
00010  */
00011 
00012 /* INCLUDES *****************************************************************/
00013 
00014 #include "halxbox.h"
00015 
00016 #define NDEBUG
00017 #include <debug.h>
00018 
00019 #define XBOX_SIGNATURE_SECTOR 3
00020 #define XBOX_SIGNATURE        ('B' | ('R' << 8) | ('F' << 16) | ('R' << 24))
00021 #define PARTITION_SIGNATURE   0xaa55
00022 
00023 /* VARIABLES ***************************************************************/
00024 
00025 static pHalExamineMBR NtoskrnlExamineMBR;
00026 static pHalIoReadPartitionTable NtoskrnlIoReadPartitionTable;
00027 static pHalIoSetPartitionInformation NtoskrnlIoSetPartitionInformation;
00028 static pHalIoWritePartitionTable NtoskrnlIoWritePartitionTable;
00029 
00030 static struct
00031 {
00032     ULONG SectorStart;
00033     ULONG SectorCount;
00034     CHAR PartitionType;
00035 } XboxPartitions[] =
00036 {
00037     /* This is in the \Device\Harddisk0\Partition.. order used by the Xbox kernel */
00038     { 0x0055F400, 0x0098f800, PARTITION_FAT32  }, /* Store, E: */
00039     { 0x00465400, 0x000FA000, PARTITION_FAT_16 }, /* System, C: */
00040     { 0x00000400, 0x00177000, PARTITION_FAT_16 }, /* Cache1, X: */
00041     { 0x00177400, 0x00177000, PARTITION_FAT_16 }, /* Cache2, Y: */
00042     { 0x002EE400, 0x00177000, PARTITION_FAT_16 }  /* Cache3, Z: */
00043 };
00044 
00045 #define XBOX_PARTITION_COUNT (sizeof(XboxPartitions) / sizeof(XboxPartitions[0]))
00046 
00047 /* FUNCTIONS ***************************************************************/
00048 
00049 
00050 static NTSTATUS
00051 HalpXboxReadSector(IN PDEVICE_OBJECT DeviceObject,
00052                    IN ULONG SectorSize,
00053                    IN PLARGE_INTEGER SectorOffset,
00054                    OUT PVOID Sector)
00055 {
00056     IO_STATUS_BLOCK StatusBlock;
00057     KEVENT Event;
00058     PIRP Irp;
00059     NTSTATUS Status;
00060 
00061     DPRINT("HalpXboxReadSector(%p %lu 0x%08x%08x %p)\n",
00062            DeviceObject, SectorSize, SectorOffset->u.HighPart, SectorOffset->u.LowPart, Sector);
00063 
00064     ASSERT(DeviceObject);
00065     ASSERT(Sector);
00066 
00067     KeInitializeEvent(&Event,
00068                       NotificationEvent,
00069                       FALSE);
00070 
00071     /* Read the sector */
00072     Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
00073                                        DeviceObject,
00074                                        Sector,
00075                                        SectorSize,
00076                                        SectorOffset,
00077                                        &Event,
00078                                        &StatusBlock);
00079     if (!Irp) return STATUS_INSUFFICIENT_RESOURCES;
00080 
00081     Status = IoCallDriver(DeviceObject,
00082                           Irp);
00083     if (Status == STATUS_PENDING)
00084     {
00085         KeWaitForSingleObject(&Event,
00086                               Executive,
00087                               KernelMode,
00088                               FALSE,
00089                               NULL);
00090         Status = StatusBlock.Status;
00091     }
00092 
00093     if (!NT_SUCCESS(Status))
00094     {
00095         DPRINT("Reading sector failed (Status 0x%08lx)\n", Status);
00096         return Status;
00097     }
00098 
00099     return Status;
00100 }
00101 
00102 static NTSTATUS FASTCALL
00103 HalpXboxDeviceHasXboxPartitioning(IN PDEVICE_OBJECT DeviceObject,
00104                                   IN ULONG SectorSize,
00105                                   OUT BOOLEAN *HasXboxPartitioning)
00106 {
00107     PVOID SectorData;
00108     LARGE_INTEGER Offset;
00109     NTSTATUS Status;
00110 
00111     DPRINT("HalpXboxDeviceHasXboxPartitioning(%p %lu %p)\n",
00112            DeviceObject,
00113            SectorSize,
00114            HasXboxPartitioning);
00115 
00116     SectorData = ExAllocatePool(PagedPool, SectorSize);
00117     if (!SectorData)
00118     {
00119         return STATUS_NO_MEMORY;
00120     }
00121 
00122     Offset.QuadPart = XBOX_SIGNATURE_SECTOR * SectorSize;
00123     Status = HalpXboxReadSector(DeviceObject, SectorSize, &Offset, SectorData);
00124     if (! NT_SUCCESS(Status))
00125     {
00126         return Status;
00127     }
00128 
00129     DPRINT("Signature 0x%02x 0x%02x 0x%02x 0x%02x\n",
00130            *((UCHAR *) SectorData), *((UCHAR *) SectorData + 1), *((UCHAR *) SectorData + 2), *((UCHAR *) SectorData + 3));
00131     *HasXboxPartitioning = (XBOX_SIGNATURE == *((ULONG *) SectorData));
00132     ExFreePool(SectorData);
00133     DPRINT("%s partitioning found\n", *HasXboxPartitioning ? "Xbox" : "MBR");
00134 
00135     return STATUS_SUCCESS;
00136 }
00137 
00138 static VOID FASTCALL
00139 HalpXboxExamineMBR(IN PDEVICE_OBJECT DeviceObject,
00140                    IN ULONG SectorSize,
00141                    IN ULONG MBRTypeIdentifier,
00142                    OUT PVOID *Buffer)
00143 {
00144     BOOLEAN HasXboxPartitioning;
00145     NTSTATUS Status;
00146 
00147     DPRINT("HalpXboxExamineMBR(%p %lu %lx %p)\n",
00148            DeviceObject,
00149            SectorSize,
00150            MBRTypeIdentifier,
00151            Buffer);
00152 
00153     *Buffer = NULL;
00154 
00155     Status = HalpXboxDeviceHasXboxPartitioning(DeviceObject, SectorSize, &HasXboxPartitioning);
00156     if (! NT_SUCCESS(Status))
00157     {
00158         return;
00159     }
00160 
00161     if (! HasXboxPartitioning)
00162     {
00163         DPRINT("Delegating to standard MBR code\n");
00164         NtoskrnlExamineMBR(DeviceObject, SectorSize, MBRTypeIdentifier, Buffer);
00165         return;
00166     }
00167 
00168     /* Buffer already set to NULL */
00169     return;
00170 }
00171 
00172 static NTSTATUS FASTCALL
00173 HalpXboxIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
00174                              IN ULONG SectorSize,
00175                              IN BOOLEAN ReturnRecognizedPartitions,
00176                              OUT PDRIVE_LAYOUT_INFORMATION *PartitionBuffer)
00177 {
00178     BOOLEAN HasXboxPartitioning;
00179     NTSTATUS Status;
00180     ULONG Part;
00181     PPARTITION_INFORMATION PartInfo;
00182 
00183     DPRINT("HalpXboxIoReadPartitionTable(%p %lu %x %p)\n",
00184            DeviceObject,
00185            SectorSize,
00186            ReturnRecognizedPartitions,
00187            PartitionBuffer);
00188 
00189     Status = HalpXboxDeviceHasXboxPartitioning(DeviceObject, SectorSize, &HasXboxPartitioning);
00190     if (! NT_SUCCESS(Status))
00191     {
00192         return Status;
00193     }
00194 
00195     if (! HasXboxPartitioning)
00196     {
00197         DPRINT("Delegating to standard MBR code\n");
00198         return NtoskrnlIoReadPartitionTable(DeviceObject, SectorSize,
00199                                             ReturnRecognizedPartitions, PartitionBuffer);
00200     }
00201 
00202     *PartitionBuffer = (PDRIVE_LAYOUT_INFORMATION)ExAllocatePoolWithTag(
00203                         PagedPool,
00204                         sizeof(DRIVE_LAYOUT_INFORMATION) +
00205                         XBOX_PARTITION_COUNT * sizeof(PARTITION_INFORMATION),
00206                         'SYSF');
00207     if (NULL == *PartitionBuffer)
00208     {
00209         return STATUS_NO_MEMORY;
00210     }
00211     (*PartitionBuffer)->PartitionCount = XBOX_PARTITION_COUNT;
00212     (*PartitionBuffer)->Signature = PARTITION_SIGNATURE;
00213     for (Part = 0; Part < XBOX_PARTITION_COUNT; Part++)
00214     {
00215         PartInfo = (*PartitionBuffer)->PartitionEntry + Part;
00216         PartInfo->StartingOffset.QuadPart = (ULONGLONG) XboxPartitions[Part].SectorStart *
00217                                             (ULONGLONG) SectorSize;
00218         PartInfo->PartitionLength.QuadPart = (ULONGLONG) XboxPartitions[Part].SectorCount *
00219                                              (ULONGLONG) SectorSize;
00220         PartInfo->HiddenSectors = 0;
00221         PartInfo->PartitionNumber = Part + 1;
00222         PartInfo->PartitionType = XboxPartitions[Part].PartitionType;
00223         PartInfo->BootIndicator = FALSE;
00224         PartInfo->RecognizedPartition = TRUE;
00225         PartInfo->RewritePartition = FALSE;
00226         DPRINT(" %ld: nr: %d boot: %1x type: %x start: 0x%I64x count: 0x%I64x rec: %d\n",
00227                Part,
00228                PartInfo->PartitionNumber,
00229                PartInfo->BootIndicator,
00230                PartInfo->PartitionType,
00231                PartInfo->StartingOffset.QuadPart,
00232                PartInfo->PartitionLength.QuadPart,
00233                PartInfo->RecognizedPartition);
00234     }
00235 
00236     return STATUS_SUCCESS;
00237 }
00238 
00239 static NTSTATUS FASTCALL
00240 HalpXboxIoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject,
00241                                   IN ULONG SectorSize,
00242                                   IN ULONG PartitionNumber,
00243                                   IN ULONG PartitionType)
00244 {
00245     BOOLEAN HasXboxPartitioning;
00246     NTSTATUS Status;
00247 
00248     DPRINT("HalpXboxIoSetPartitionInformation(%p %lu %lu %lu)\n",
00249            DeviceObject,
00250            SectorSize,
00251            PartitionNumber,
00252            PartitionType);
00253 
00254     Status = HalpXboxDeviceHasXboxPartitioning(DeviceObject, SectorSize, &HasXboxPartitioning);
00255     if (! NT_SUCCESS(Status))
00256     {
00257         return Status;
00258     }
00259 
00260     if (!HasXboxPartitioning)
00261     {
00262         DPRINT("Delegating to standard MBR code\n");
00263         return NtoskrnlIoSetPartitionInformation(DeviceObject, SectorSize,
00264                                                  PartitionNumber, PartitionType);
00265     }
00266 
00267     /* Can't change the partitioning */
00268     DPRINT1("Xbox partitions are fixed, can't change them\n");
00269     return STATUS_ACCESS_DENIED;
00270 }
00271 
00272 static NTSTATUS FASTCALL
00273 HalpXboxIoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject,
00274                               IN ULONG SectorSize,
00275                               IN ULONG SectorsPerTrack,
00276                               IN ULONG NumberOfHeads,
00277                               IN PDRIVE_LAYOUT_INFORMATION PartitionBuffer)
00278 {
00279     BOOLEAN HasXboxPartitioning;
00280     NTSTATUS Status;
00281 
00282     DPRINT("HalpXboxIoWritePartitionTable(%p %lu %lu %lu %p)\n",
00283            DeviceObject,
00284            SectorSize,
00285            SectorsPerTrack,
00286            NumberOfHeads,
00287            PartitionBuffer);
00288 
00289     Status = HalpXboxDeviceHasXboxPartitioning(DeviceObject, SectorSize, &HasXboxPartitioning);
00290     if (! NT_SUCCESS(Status))
00291     {
00292         return Status;
00293     }
00294 
00295     if (!HasXboxPartitioning)
00296     {
00297         DPRINT("Delegating to standard MBR code\n");
00298         return NtoskrnlIoWritePartitionTable(DeviceObject, SectorSize,
00299                                              SectorsPerTrack, NumberOfHeads,
00300                                              PartitionBuffer);
00301     }
00302 
00303     /* Can't change the partitioning */
00304     DPRINT1("Xbox partitions are fixed, can't change them\n");
00305     return STATUS_ACCESS_DENIED;
00306 }
00307 
00308 #define HalExamineMBR                   HALDISPATCH->HalExamineMBR
00309 #define HalIoReadPartitionTable         HALDISPATCH->HalIoReadPartitionTable
00310 #define HalIoSetPartitionInformation    HALDISPATCH->HalIoSetPartitionInformation
00311 #define HalIoWritePartitionTable        HALDISPATCH->HalIoWritePartitionTable
00312 
00313 void
00314 HalpXboxInitPartIo(void)
00315 {
00316     NtoskrnlExamineMBR = HalExamineMBR;
00317     HalExamineMBR = HalpXboxExamineMBR;
00318     NtoskrnlIoReadPartitionTable = HalIoReadPartitionTable;
00319     HalIoReadPartitionTable = HalpXboxIoReadPartitionTable;
00320     NtoskrnlIoSetPartitionInformation = HalIoSetPartitionInformation;
00321     HalIoSetPartitionInformation = HalpXboxIoSetPartitionInformation;
00322     NtoskrnlIoWritePartitionTable = HalIoWritePartitionTable;
00323     HalIoWritePartitionTable = HalpXboxIoWritePartitionTable;
00324 }
00325 
00326 /* EOF */

Generated on Sun May 27 2012 04:28:45 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.