ReactOS 0.4.16-dev-1946-g52006dd
xboxdisk.c File Reference
#include <freeldr.h>
#include <hwide.h>
#include <debug.h>
Include dependency graph for xboxdisk.c:

Go to the source code of this file.

Functions

 DBG_DEFAULT_CHANNEL (DISK)
 
static VOID XboxDiskInit (VOID)
 
static PDEVICE_UNIT XboxDiskDriveNumberToDeviceUnit (UCHAR DriveNumber)
 
CONFIGURATION_TYPE DiskGetConfigType (_In_ UCHAR DriveNumber)
 
BOOLEAN XboxDiskReadLogicalSectors (IN UCHAR DriveNumber, IN ULONGLONG SectorNumber, IN ULONG SectorCount, OUT PVOID Buffer)
 
BOOLEAN XboxDiskGetDriveGeometry (UCHAR DriveNumber, PGEOMETRY Geometry)
 
ULONG XboxDiskGetCacheableBlockCount (UCHAR DriveNumber)
 

Variables

static PDEVICE_UNIT HardDrive = NULL
 
static PDEVICE_UNIT CdDrive = NULL
 
static BOOLEAN AtaInitialized = FALSE
 

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( DISK  )

◆ DiskGetConfigType()

CONFIGURATION_TYPE DiskGetConfigType ( _In_ UCHAR  DriveNumber)

Definition at line 81 of file xboxdisk.c.

83{
84 PDEVICE_UNIT DeviceUnit;
85
86 DeviceUnit = XboxDiskDriveNumberToDeviceUnit(DriveNumber);
87 if (!DeviceUnit)
88 return -1; // MaximumType;
89
90 if (DeviceUnit == CdDrive) // (DeviceUnit->Flags & ATA_DEVICE_ATAPI)
91 return CdromController;
92 else // if (DeviceUnit == HardDrive)
93 return DiskPeripheral;
94}
@ DiskPeripheral
Definition: arc.h:138
@ CdromController
Definition: arc.h:128
Data structure for the ATA device.
Definition: hwide.h:12
static PDEVICE_UNIT XboxDiskDriveNumberToDeviceUnit(UCHAR DriveNumber)
Definition: xboxdisk.c:60
static PDEVICE_UNIT CdDrive
Definition: xboxdisk.c:20

◆ XboxDiskDriveNumberToDeviceUnit()

static PDEVICE_UNIT XboxDiskDriveNumberToDeviceUnit ( UCHAR  DriveNumber)
inlinestatic

Definition at line 60 of file xboxdisk.c.

61{
62 /* Xbox has only 1 IDE controller and no floppy */
63 if (DriveNumber < 0x80 || (DriveNumber & 0x0F) >= 2)
64 return NULL;
65
66 if (!AtaInitialized)
68
69 /* HDD */
70 if ((DriveNumber == 0x80) && HardDrive)
71 return HardDrive;
72
73 /* CD */
74 if (((DriveNumber & 0xF0) > 0x80) && CdDrive)
75 return CdDrive;
76
77 return NULL;
78}
#define NULL
Definition: types.h:112
static PDEVICE_UNIT HardDrive
Definition: xboxdisk.c:19
static BOOLEAN AtaInitialized
Definition: xboxdisk.c:21
static VOID XboxDiskInit(VOID)
Definition: xboxdisk.c:27

Referenced by DiskGetConfigType(), XboxDiskGetCacheableBlockCount(), XboxDiskGetDriveGeometry(), and XboxDiskReadLogicalSectors().

◆ XboxDiskGetCacheableBlockCount()

ULONG XboxDiskGetCacheableBlockCount ( UCHAR  DriveNumber)

Definition at line 136 of file xboxdisk.c.

137{
138 PDEVICE_UNIT DeviceUnit;
139
140 DeviceUnit = XboxDiskDriveNumberToDeviceUnit(DriveNumber);
141 if (!DeviceUnit)
142 return 1; // Unknown count.
143
144 /*
145 * If LBA is supported then the block size will be 64 sectors (32k).
146 * If not then the block size is the size of one track.
147 */
148 if (DeviceUnit->Flags & ATA_DEVICE_LBA)
149 return 64;
150 else
151 return DeviceUnit->SectorsPerTrack;
152}
#define ATA_DEVICE_LBA
Definition: hwide.h:31
ULONG SectorsPerTrack
Definition: hwide.h:20
ULONG Flags
Definition: hwide.h:29

Referenced by MachInit().

◆ XboxDiskGetDriveGeometry()

BOOLEAN XboxDiskGetDriveGeometry ( UCHAR  DriveNumber,
PGEOMETRY  Geometry 
)

Definition at line 116 of file xboxdisk.c.

117{
118 PDEVICE_UNIT DeviceUnit;
119
120 TRACE("XboxDiskGetDriveGeometry(0x%x)\n", DriveNumber);
121
122 DeviceUnit = XboxDiskDriveNumberToDeviceUnit(DriveNumber);
123 if (!DeviceUnit)
124 return FALSE;
125
126 Geometry->Cylinders = DeviceUnit->Cylinders;
127 Geometry->Heads = DeviceUnit->Heads;
128 Geometry->SectorsPerTrack = DeviceUnit->SectorsPerTrack;
129 Geometry->BytesPerSector = DeviceUnit->SectorSize;
130 Geometry->Sectors = DeviceUnit->TotalSectors;
131
132 return TRUE;
133}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define TRACE(s)
Definition: solgame.cpp:4
ULONG Cylinders
Definition: hwide.h:14
ULONG SectorSize
Definition: hwide.h:23
ULONG64 TotalSectors
Definition: hwide.h:26
ULONG Heads
Definition: hwide.h:17
ULONG BytesPerSector
Number of bytes per sector.
Definition: disk.h:30
ULONG Cylinders
Number of cylinders on the disk.
Definition: disk.h:27
ULONGLONG Sectors
Total number of disk sectors/LBA blocks.
Definition: disk.h:31
ULONG SectorsPerTrack
Number of sectors per track.
Definition: disk.h:29
ULONG Heads
Number of heads on the disk.
Definition: disk.h:28

Referenced by MachInit(), and XboxGetHarddiskConfigurationData().

◆ XboxDiskInit()

static VOID XboxDiskInit ( VOID  )
static

Definition at line 27 of file xboxdisk.c.

28{
29 UCHAR DetectedCount;
30 UCHAR UnitNumber;
31 PDEVICE_UNIT DeviceUnit = NULL;
32
34
36
37 /* Find first HDD and CD */
38 AtaInit(&DetectedCount);
39 for (UnitNumber = 0; UnitNumber <= DetectedCount; UnitNumber++)
40 {
41 DeviceUnit = AtaGetDevice(UnitNumber);
42 if (DeviceUnit)
43 {
44 if (DeviceUnit->Flags & ATA_DEVICE_ATAPI)
45 {
46 if (!CdDrive)
47 CdDrive = DeviceUnit;
48 }
49 else
50 {
51 if (!HardDrive)
52 HardDrive = DeviceUnit;
53 }
54 }
55 }
56}
PDEVICE_UNIT AtaGetDevice(_In_ UCHAR UnitNumber)
Definition: hwide.c:1254
BOOLEAN AtaInit(_Out_ PUCHAR DetectedCount)
Definition: hwide.c:1264
#define ATA_DEVICE_ATAPI
Definition: hwide.h:30
#define ASSERT(a)
Definition: mode.c:44
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by XboxDiskDriveNumberToDeviceUnit().

◆ XboxDiskReadLogicalSectors()

BOOLEAN XboxDiskReadLogicalSectors ( IN UCHAR  DriveNumber,
IN ULONGLONG  SectorNumber,
IN ULONG  SectorCount,
OUT PVOID  Buffer 
)

Definition at line 97 of file xboxdisk.c.

102{
103 PDEVICE_UNIT DeviceUnit;
104
105 TRACE("XboxDiskReadLogicalSectors() DriveNumber: 0x%x SectorNumber: %I64u SectorCount: %u Buffer: 0x%x\n",
106 DriveNumber, SectorNumber, SectorCount, Buffer);
107
108 DeviceUnit = XboxDiskDriveNumberToDeviceUnit(DriveNumber);
109 if (!DeviceUnit)
110 return FALSE;
111
112 return AtaReadLogicalSectors(DeviceUnit, SectorNumber, SectorCount, Buffer);
113}
Definition: bufpool.h:45
BOOLEAN AtaReadLogicalSectors(_In_ PDEVICE_UNIT DeviceUnit, _In_ ULONG64 SectorNumber, _In_ ULONG SectorCount, _Out_writes_bytes_all_(SectorCount *DeviceUnit->SectorSize) PVOID Buffer)
Definition: hwide.c:1215
ULONG SectorCount
Definition: part_xbox.c:31

Referenced by MachInit().

Variable Documentation

◆ AtaInitialized

BOOLEAN AtaInitialized = FALSE
static

Definition at line 21 of file xboxdisk.c.

Referenced by XboxDiskDriveNumberToDeviceUnit(), and XboxDiskInit().

◆ CdDrive

PDEVICE_UNIT CdDrive = NULL
static

Definition at line 20 of file xboxdisk.c.

Referenced by DiskGetConfigType(), XboxDiskDriveNumberToDeviceUnit(), and XboxDiskInit().

◆ HardDrive

PDEVICE_UNIT HardDrive = NULL
static

Definition at line 19 of file xboxdisk.c.

Referenced by XboxDiskDriveNumberToDeviceUnit(), and XboxDiskInit().