ReactOS 0.4.16-dev-1946-g52006dd
xboxdisk.c
Go to the documentation of this file.
1/*
2 * PROJECT: FreeLoader
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Xbox specific disk access routines
5 * COPYRIGHT: Copyright 2004 Gé van Geldorp (gvg@reactos.com)
6 * Copyright 2019-2025 Dmitry Borisov (di.sean@protonmail.com)
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include <freeldr.h>
12#include <hwide.h>
13
14#include <debug.h>
16
17/* GLOBALS ********************************************************************/
18
22
23/* FUNCTIONS ******************************************************************/
24
25static
26VOID
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}
57
58static inline
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}
79
82 _In_ UCHAR DriveNumber)
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}
95
98 IN UCHAR DriveNumber,
99 IN ULONGLONG SectorNumber,
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}
114
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}
134
135ULONG
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}
153
154/* EOF */
unsigned char BOOLEAN
#define DBG_DEFAULT_CHANNEL(ch)
Definition: debug.h:106
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
PDEVICE_UNIT AtaGetDevice(_In_ UCHAR UnitNumber)
Definition: hwide.c:1254
BOOLEAN AtaInit(_Out_ PUCHAR DetectedCount)
Definition: hwide.c:1264
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
#define ATA_DEVICE_LBA
Definition: hwide.h:31
#define ATA_DEVICE_ATAPI
Definition: hwide.h:30
#define ASSERT(a)
Definition: mode.c:44
#define _In_
Definition: no_sal2.h:158
ULONG SectorCount
Definition: part_xbox.c:31
@ DiskPeripheral
Definition: arc.h:138
@ CdromController
Definition: arc.h:128
enum _CONFIGURATION_TYPE CONFIGURATION_TYPE
#define TRACE(s)
Definition: solgame.cpp:4
Data structure for the ATA device.
Definition: hwide.h:12
ULONG Cylinders
Definition: hwide.h:14
ULONG SectorSize
Definition: hwide.h:23
ULONG SectorsPerTrack
Definition: hwide.h:20
ULONG64 TotalSectors
Definition: hwide.h:26
ULONG Flags
Definition: hwide.h:29
ULONG Heads
Definition: hwide.h:17
Definition: disk.h:26
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
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#define OUT
Definition: typedefs.h:40
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 XboxDiskDriveNumberToDeviceUnit(UCHAR DriveNumber)
Definition: xboxdisk.c:60
BOOLEAN XboxDiskReadLogicalSectors(IN UCHAR DriveNumber, IN ULONGLONG SectorNumber, IN ULONG SectorCount, OUT PVOID Buffer)
Definition: xboxdisk.c:97
ULONG XboxDiskGetCacheableBlockCount(UCHAR DriveNumber)
Definition: xboxdisk.c:136
BOOLEAN XboxDiskGetDriveGeometry(UCHAR DriveNumber, PGEOMETRY Geometry)
Definition: xboxdisk.c:116
CONFIGURATION_TYPE DiskGetConfigType(_In_ UCHAR DriveNumber)
Definition: xboxdisk.c:81
static PDEVICE_UNIT CdDrive
Definition: xboxdisk.c:20
unsigned char UCHAR
Definition: xmlstorage.h:181