ReactOS 0.4.16-dev-1019-g2c2cdfd
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)
 
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  )

◆ 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
static PDEVICE_UNIT CdDrive
Definition: xboxdisk.c:20

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

◆ XboxDiskGetCacheableBlockCount()

ULONG XboxDiskGetCacheableBlockCount ( UCHAR  DriveNumber)

Definition at line 120 of file xboxdisk.c.

121{
122 PDEVICE_UNIT DeviceUnit;
123
124 DeviceUnit = XboxDiskDriveNumberToDeviceUnit(DriveNumber);
125 if (!DeviceUnit)
126 return 1; // Unknown count.
127
128 /*
129 * If LBA is supported then the block size will be 64 sectors (32k).
130 * If not then the block size is the size of one track.
131 */
132 if (DeviceUnit->Flags & ATA_DEVICE_LBA)
133 return 64;
134 else
135 return DeviceUnit->SectorsPerTrack;
136}
#define ATA_DEVICE_LBA
Definition: hwide.h:31
Data structure for the ATA device.
Definition: hwide.h:12
ULONG SectorsPerTrack
Definition: hwide.h:20
ULONG Flags
Definition: hwide.h:29
static PDEVICE_UNIT XboxDiskDriveNumberToDeviceUnit(UCHAR DriveNumber)
Definition: xboxdisk.c:60

Referenced by MachInit().

◆ XboxDiskGetDriveGeometry()

BOOLEAN XboxDiskGetDriveGeometry ( UCHAR  DriveNumber,
PGEOMETRY  Geometry 
)

Definition at line 100 of file xboxdisk.c.

101{
102 PDEVICE_UNIT DeviceUnit;
103
104 TRACE("XboxDiskGetDriveGeometry(0x%x)\n", DriveNumber);
105
106 DeviceUnit = XboxDiskDriveNumberToDeviceUnit(DriveNumber);
107 if (!DeviceUnit)
108 return FALSE;
109
110 Geometry->Cylinders = DeviceUnit->Cylinders;
111 Geometry->Heads = DeviceUnit->Heads;
112 Geometry->SectorsPerTrack = DeviceUnit->SectorsPerTrack;
113 Geometry->BytesPerSector = DeviceUnit->SectorSize;
114 Geometry->Sectors = DeviceUnit->TotalSectors;
115
116 return TRUE;
117}
#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 81 of file xboxdisk.c.

86{
87 PDEVICE_UNIT DeviceUnit;
88
89 TRACE("XboxDiskReadLogicalSectors() DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d Buffer: 0x%x\n",
90 DriveNumber, SectorNumber, SectorCount, Buffer);
91
92 DeviceUnit = XboxDiskDriveNumberToDeviceUnit(DriveNumber);
93 if (!DeviceUnit)
94 return FALSE;
95
96 return AtaReadLogicalSectors(DeviceUnit, SectorNumber, SectorCount, Buffer);
97}
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 XboxDiskDriveNumberToDeviceUnit(), and XboxDiskInit().

◆ HardDrive

PDEVICE_UNIT HardDrive = NULL
static

Definition at line 19 of file xboxdisk.c.

Referenced by XboxDiskDriveNumberToDeviceUnit(), and XboxDiskInit().