ReactOS  0.4.13-dev-257-gfabbd7c
drivemap.c File Reference
#include <freeldr.h>
#include <debug.h>
Include dependency graph for drivemap.c:

Go to the source code of this file.

Functions

 DBG_DEFAULT_CHANNEL (DISK)
 
VOID DriveMapMapDrivesInSection (PCSTR SectionName)
 
BOOLEAN DriveMapIsValidDriveString (PCSTR DriveString)
 
UCHAR DriveMapGetBiosDriveNumber (PCSTR DeviceName)
 
VOID DriveMapInstallInt13Handler (PDRIVE_MAP_LIST DriveMap)
 
VOID DriveMapRemoveInt13Handler (VOID)
 

Variables

BOOLEAN DriveMapInstalled = FALSE
 
ULONG OldInt13HandlerAddress = 0
 
ULONG DriveMapHandlerAddress = 0
 
ULONG DriveMapHandlerSegOff = 0
 

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( DISK  )

◆ DriveMapGetBiosDriveNumber()

UCHAR DriveMapGetBiosDriveNumber ( PCSTR  DeviceName)

Definition at line 146 of file drivemap.c.

147 {
148  UCHAR BiosDriveNumber = 0;
149 
150  TRACE("DriveMapGetBiosDriveNumber(%s)\n", DeviceName);
151 
152  // If they passed in a number string then just
153  // convert it to decimal and return it
154  if (DeviceName[0] >= '0' && DeviceName[0] <= '9')
155  {
156  return (UCHAR)strtoul(DeviceName, NULL, 0);
157  }
158 
159  // Convert the drive number string into a number
160  // 'hd1' = 1
161  BiosDriveNumber = atoi(&DeviceName[2]);
162 
163  // If it's a hard disk then set the high bit
164  if ((DeviceName[0] == 'h' || DeviceName[0] == 'H') &&
165  (DeviceName[1] == 'd' || DeviceName[1] == 'D'))
166  {
167  BiosDriveNumber |= 0x80;
168  }
169 
170  return BiosDriveNumber;
171 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
WCHAR DeviceName[]
Definition: adapter.cpp:21
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
unsigned char UCHAR
Definition: xmlstorage.h:181
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)

Referenced by DriveMapMapDrivesInSection().

◆ DriveMapInstallInt13Handler()

VOID DriveMapInstallInt13Handler ( PDRIVE_MAP_LIST  DriveMap)

Definition at line 173 of file drivemap.c.

174 {
175  ULONG* RealModeIVT = (ULONG*)UlongToPtr(0x00000000);
176  USHORT* BiosLowMemorySize = (USHORT*)ULongToPtr(0x00000413);
177 
178  if (!DriveMapInstalled)
179  {
180  // Get the old INT 13h handler address from the vector table
181  OldInt13HandlerAddress = RealModeIVT[0x13];
182 
183  // Decrease the size of low memory
184  (*BiosLowMemorySize)--;
185 
186  // Get linear address for drive map handler
187  DriveMapHandlerAddress = (ULONG)(*BiosLowMemorySize) << 10;
188 
189  // Convert to segment:offset style address
190  DriveMapHandlerSegOff = (DriveMapHandlerAddress << 12) & 0xffff0000;
191  }
192 
193  // Copy the drive map structure to the proper place
195 
196  // Set the address of the BIOS INT 13h handler
198 
199  // Copy the code to our reserved area
203 
204  // Update the IVT
205  RealModeIVT[0x13] = DriveMapHandlerSegOff;
206 
209 }
ULONG DriveMapHandlerAddress
Definition: drivemap.c:27
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define ULongToPtr(ul)
Definition: basetsd.h:92
ULONG DriveMapOldInt13HandlerAddress
BOOLEAN DriveMapInstalled
Definition: drivemap.c:25
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG OldInt13HandlerAddress
Definition: drivemap.c:26
#define UlongToPtr(u)
Definition: config.h:106
PVOID DriveMapInt13HandlerEnd
PVOID DriveMapInt13HandlerStart
DRIVE_MAP_LIST DriveMapInt13HandlerMapList
unsigned short USHORT
Definition: pedump.c:61
VOID CacheInvalidateCacheData(VOID)
Definition: cache.c:111
unsigned int ULONG
Definition: retypes.h:1
ULONG DriveMapHandlerSegOff
Definition: drivemap.c:28

Referenced by DriveMapMapDrivesInSection().

◆ DriveMapIsValidDriveString()

BOOLEAN DriveMapIsValidDriveString ( PCSTR  DriveString)

Definition at line 114 of file drivemap.c.

115 {
116  ULONG Index;
117 
118  // Now verify that the user has given us appropriate strings
119  if ((strlen(DriveString) < 3) ||
120  ((DriveString[0] != 'f') && (DriveString[0] != 'F') &&
121  (DriveString[0] != 'h') && (DriveString[0] != 'H')) ||
122  ((DriveString[1] != 'd') && (DriveString[1] != 'D')))
123  {
124  return FALSE;
125  }
126 
127  // Now verify that the user has given us appropriate numbers
128  // Make sure that only numeric characters were given
129  for (Index = 2; Index < strlen(DriveString); Index++)
130  {
131  if (DriveString[Index] < '0' || DriveString[Index] > '9')
132  {
133  return FALSE;
134  }
135  }
136 
137  // Now make sure that they are not outrageous values (i.e. hd90874)
138  if ((atoi(&DriveString[2]) < 0) || (atoi(&DriveString[2]) > 0xff))
139  {
140  return FALSE;
141  }
142 
143  return TRUE;
144 }
#define TRUE
Definition: types.h:120
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static const UCHAR Index[8]
Definition: usbohci.c:18
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
unsigned int ULONG
Definition: retypes.h:1

Referenced by DriveMapMapDrivesInSection().

◆ DriveMapMapDrivesInSection()

VOID DriveMapMapDrivesInSection ( PCSTR  SectionName)

Definition at line 30 of file drivemap.c.

31 {
32  CHAR SettingName[80];
33  CHAR SettingValue[80];
34  CHAR Drive1[80];
35  CHAR Drive2[80];
36  ULONG_PTR SectionId;
37  ULONG SectionItemCount;
38  ULONG Index;
39  ULONG Index2;
40  DRIVE_MAP_LIST DriveMapList;
41 
42  RtlZeroMemory(&DriveMapList, sizeof(DRIVE_MAP_LIST));
43 
44  if (!IniOpenSection(SectionName, &SectionId))
45  {
46  return;
47  }
48 
49  // Get the number of items in this section
50  SectionItemCount = IniGetNumSectionItems(SectionId);
51 
52  // Loop through each one and check if its a DriveMap= setting
53  for (Index=0; Index<SectionItemCount; Index++)
54  {
55  // Get the next setting from the .ini file section
56  if (IniReadSettingByNumber(SectionId, Index, SettingName, sizeof(SettingName), SettingValue, sizeof(SettingValue)))
57  {
58  if (_stricmp(SettingName, "DriveMap") == 0)
59  {
60  // Make sure we haven't exceeded the drive map max count
61  if (DriveMapList.DriveMapCount >= 4)
62  {
63  UiMessageBox("Max DriveMap count exceeded in section [%s]:\n\n%s=%s", SectionName, SettingName, SettingValue);
64  continue;
65  }
66 
67  RtlZeroMemory(Drive1, 80);
68  RtlZeroMemory(Drive2, 80);
69 
70  strcpy(Drive1, SettingValue);
71 
72  // Parse the setting value and separate a string "hd0,hd1"
73  // into two strings "hd0" and "hd1"
74  for (Index2=0; Index2<strlen(Drive1); Index2++)
75  {
76  // Check if this character is the separater character (comma - ',')
77  if (Drive1[Index2] == ',')
78  {
79  Drive1[Index2] = '\0';
80  strcpy(Drive2, &Drive1[Index2+1]);
81  break;
82  }
83  }
84 
85  // Make sure we got good values before we add them to the map
87  {
88  UiMessageBox("Error in DriveMap setting in section [%s]:\n\n%s=%s", SectionName, SettingName, SettingValue);
89  continue;
90  }
91 
92  // Add them to the map
93  DriveMapList.DriveMap[(DriveMapList.DriveMapCount * 2)] = DriveMapGetBiosDriveNumber(Drive1);
94  DriveMapList.DriveMap[(DriveMapList.DriveMapCount * 2)+1] = DriveMapGetBiosDriveNumber(Drive2);
95  DriveMapList.DriveMapCount++;
96 
97  TRACE("Mapping BIOS drive 0x%x to drive 0x%x\n", DriveMapGetBiosDriveNumber(Drive1), DriveMapGetBiosDriveNumber(Drive2));
98  }
99  }
100  }
101 
102  if (DriveMapList.DriveMapCount)
103  {
104  TRACE("Installing Int13 drive map for %d drives.\n", DriveMapList.DriveMapCount);
105  DriveMapInstallInt13Handler(&DriveMapList);
106  }
107  else
108  {
109  TRACE("Removing any previously installed Int13 drive map.\n");
111  }
112 }
UCHAR DriveMapCount
Definition: drivemap.h:25
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
VOID DriveMapInstallInt13Handler(PDRIVE_MAP_LIST DriveMap)
Definition: drivemap.c:173
char CHAR
Definition: xmlstorage.h:175
VOID DriveMapRemoveInt13Handler(VOID)
Definition: drivemap.c:211
#define _stricmp
Definition: cat.c:22
uint32_t ULONG_PTR
Definition: typedefs.h:63
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:347
UCHAR DriveMapGetBiosDriveNumber(PCSTR DeviceName)
Definition: drivemap.c:146
#define TRACE(s)
Definition: solgame.cpp:4
BOOLEAN IniOpenSection(PCSTR SectionName, ULONG_PTR *SectionId)
Definition: inifile.c:25
static const UCHAR Index[8]
Definition: usbohci.c:18
BOOLEAN DriveMapIsValidDriveString(PCSTR DriveString)
Definition: drivemap.c:114
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
ULONG IniGetNumSectionItems(ULONG_PTR SectionId)
Definition: inifile.c:54
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
BOOLEAN IniReadSettingByNumber(ULONG_PTR SectionId, ULONG SettingNumber, PCHAR SettingName, ULONG NameSize, PCHAR SettingValue, ULONG ValueSize)
Definition: inifile.c:114
CHAR DriveMap[8]
Definition: drivemap.h:26

Referenced by LoadOperatingSystem().

◆ DriveMapRemoveInt13Handler()

VOID DriveMapRemoveInt13Handler ( VOID  )

Definition at line 211 of file drivemap.c.

212 {
213  ULONG* RealModeIVT = (ULONG*)0x00000000;
214  USHORT* BiosLowMemorySize = (USHORT*)0x00000413;
215 
216  if (DriveMapInstalled)
217  {
218  // Get the old INT 13h handler address from the vector table
219  RealModeIVT[0x13] = OldInt13HandlerAddress;
220 
221  // Increase the size of low memory
222  (*BiosLowMemorySize)++;
223 
226  }
227 }
BOOLEAN DriveMapInstalled
Definition: drivemap.c:25
ULONG OldInt13HandlerAddress
Definition: drivemap.c:26
unsigned short USHORT
Definition: pedump.c:61
VOID CacheInvalidateCacheData(VOID)
Definition: cache.c:111
unsigned int ULONG
Definition: retypes.h:1

Referenced by DriveMapMapDrivesInSection().

Variable Documentation

◆ DriveMapHandlerAddress

ULONG DriveMapHandlerAddress = 0

Definition at line 27 of file drivemap.c.

Referenced by DriveMapInstallInt13Handler().

◆ DriveMapHandlerSegOff

ULONG DriveMapHandlerSegOff = 0

Definition at line 28 of file drivemap.c.

Referenced by DriveMapInstallInt13Handler().

◆ DriveMapInstalled

BOOLEAN DriveMapInstalled = FALSE

Definition at line 25 of file drivemap.c.

Referenced by DriveMapInstallInt13Handler(), and DriveMapRemoveInt13Handler().

◆ OldInt13HandlerAddress

ULONG OldInt13HandlerAddress = 0

Definition at line 26 of file drivemap.c.

Referenced by DriveMapInstallInt13Handler(), and DriveMapRemoveInt13Handler().