ReactOS 0.4.16-dev-1025-gd3456f5
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 IN ULONGLONG SectorNumber,
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}
98
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}
118
119ULONG
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}
137
138/* 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
ULONG SectorCount
Definition: part_xbox.c:31
#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:81
ULONG XboxDiskGetCacheableBlockCount(UCHAR DriveNumber)
Definition: xboxdisk.c:120
BOOLEAN XboxDiskGetDriveGeometry(UCHAR DriveNumber, PGEOMETRY Geometry)
Definition: xboxdisk.c:100
static PDEVICE_UNIT CdDrive
Definition: xboxdisk.c:20
unsigned char UCHAR
Definition: xmlstorage.h:181