ReactOS 0.4.16-dev-297-gc569aee
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 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
25VOID
27{
28 UCHAR DetectedCount;
29 UCHAR UnitNumber;
30 PDEVICE_UNIT DeviceUnit = NULL;
31
32 if (Init & !AtaInitialized)
33 {
34 /* Find first HDD and CD */
35 AtaInit(&DetectedCount);
36 for (UnitNumber = 0; UnitNumber <= DetectedCount; UnitNumber++)
37 {
38 DeviceUnit = AtaGetDevice(UnitNumber);
39 if (DeviceUnit)
40 {
41 if (DeviceUnit->Flags & ATA_DEVICE_ATAPI)
42 {
43 if (!CdDrive)
44 CdDrive = DeviceUnit;
45 }
46 else
47 {
48 if (!HardDrive)
49 HardDrive = DeviceUnit;
50 }
51 }
52 }
54 }
55 else
56 {
57 AtaFree();
58 }
59}
60
61static inline
64{
65 /* Xbox has only 1 IDE controller and no floppy */
66 if (DriveNumber < 0x80 || (DriveNumber & 0x0F) >= 2)
67 return NULL;
68
69 if (!AtaInitialized)
71
72 /* HDD */
73 if ((DriveNumber == 0x80) && HardDrive)
74 return HardDrive;
75
76 /* CD */
77 if (((DriveNumber & 0xF0) > 0x80) && CdDrive)
78 return CdDrive;
79
80 return NULL;
81}
82
85 IN UCHAR DriveNumber,
86 IN ULONGLONG SectorNumber,
89{
90 PDEVICE_UNIT DeviceUnit;
91
92 TRACE("XboxDiskReadLogicalSectors() DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d Buffer: 0x%x\n",
93 DriveNumber, SectorNumber, SectorCount, Buffer);
94
95 DeviceUnit = XboxDiskDriveNumberToDeviceUnit(DriveNumber);
96 if (!DeviceUnit)
97 return FALSE;
98
99 return AtaAtapiReadLogicalSectorsLBA(DeviceUnit, SectorNumber, SectorCount, Buffer);
100}
101
104{
105 PDEVICE_UNIT DeviceUnit;
106
107 TRACE("XboxDiskGetDriveGeometry(0x%x)\n", DriveNumber);
108
109 DeviceUnit = XboxDiskDriveNumberToDeviceUnit(DriveNumber);
110 if (!DeviceUnit)
111 return FALSE;
112
113 Geometry->Cylinders = DeviceUnit->Cylinders;
114 Geometry->Heads = DeviceUnit->Heads;
115 Geometry->SectorsPerTrack = DeviceUnit->Sectors;
116 Geometry->BytesPerSector = DeviceUnit->SectorSize;
117 Geometry->Sectors = DeviceUnit->TotalSectors;
118
119 return TRUE;
120}
121
122ULONG
124{
125 PDEVICE_UNIT DeviceUnit;
126
127 DeviceUnit = XboxDiskDriveNumberToDeviceUnit(DriveNumber);
128 if (!DeviceUnit)
129 return 1; // Unknown count.
130
131 /*
132 * If LBA is supported then the block size will be 64 sectors (32k).
133 * If not then the block size is the size of one track.
134 */
135 if (DeviceUnit->Flags & ATA_DEVICE_LBA)
136 return 64;
137 else
138 return DeviceUnit->Sectors;
139}
140
141/* 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:178
BOOLEAN AtaAtapiReadLogicalSectorsLBA(IN OUT PDEVICE_UNIT DeviceUnit, IN ULONGLONG SectorNumber, IN ULONG SectorCount, OUT PVOID Buffer)
Definition: hwide.c:187
BOOLEAN AtaInit(OUT PUCHAR DetectedCount)
Definition: hwide.c:139
#define ATA_DEVICE_LBA
Definition: hwide.h:307
VOID AtaFree()
#define ATA_DEVICE_ATAPI
Definition: hwide.h:303
ULONG SectorCount
Definition: part_xbox.c:31
#define TRACE(s)
Definition: solgame.cpp:4
USHORT Flags
Definition: hwide.h:299
ULONG Cylinders
Definition: hwide.h:294
ULONG SectorSize
Definition: hwide.h:297
ULONG Sectors
Definition: hwide.h:296
ULONGLONG TotalSectors
Definition: hwide.h:298
ULONG Heads
Definition: hwide.h:295
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 PDEVICE_UNIT XboxDiskDriveNumberToDeviceUnit(UCHAR DriveNumber)
Definition: xboxdisk.c:63
BOOLEAN XboxDiskReadLogicalSectors(IN UCHAR DriveNumber, IN ULONGLONG SectorNumber, IN ULONG SectorCount, OUT PVOID Buffer)
Definition: xboxdisk.c:84
ULONG XboxDiskGetCacheableBlockCount(UCHAR DriveNumber)
Definition: xboxdisk.c:123
BOOLEAN XboxDiskGetDriveGeometry(UCHAR DriveNumber, PGEOMETRY Geometry)
Definition: xboxdisk.c:103
static PDEVICE_UNIT CdDrive
Definition: xboxdisk.c:20
VOID XboxDiskInit(BOOLEAN Init)
Definition: xboxdisk.c:26
unsigned char UCHAR
Definition: xmlstorage.h:181