Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendrivemap.c
Go to the documentation of this file.
00001 /* 00002 * FreeLoader 00003 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 00020 #include <freeldr.h> 00021 #include <debug.h> 00022 00023 DBG_DEFAULT_CHANNEL(WARNING); 00024 00025 BOOLEAN DriveMapInstalled = FALSE; // Tells us if we have already installed our drive map int 13h handler code 00026 ULONG OldInt13HandlerAddress = 0; // Address of BIOS int 13h handler 00027 ULONG DriveMapHandlerAddress = 0; // Linear address of our drive map handler 00028 ULONG DriveMapHandlerSegOff = 0; // Segment:offset style address of our drive map handler 00029 00030 #ifndef _MSC_VER 00031 VOID DriveMapMapDrivesInSection(PCSTR SectionName) 00032 { 00033 CHAR SettingName[80]; 00034 CHAR SettingValue[80]; 00035 CHAR ErrorText[260]; 00036 CHAR Drive1[80]; 00037 CHAR Drive2[80]; 00038 ULONG SectionId; 00039 ULONG SectionItemCount; 00040 ULONG Index; 00041 ULONG Index2; 00042 DRIVE_MAP_LIST DriveMapList; 00043 00044 RtlZeroMemory(&DriveMapList, sizeof(DRIVE_MAP_LIST)); 00045 00046 if (!IniOpenSection(SectionName, &SectionId)) 00047 { 00048 return; 00049 } 00050 00051 // Get the number of items in this section 00052 SectionItemCount = IniGetNumSectionItems(SectionId); 00053 00054 // Loop through each one and check if its a DriveMap= setting 00055 for (Index=0; Index<SectionItemCount; Index++) 00056 { 00057 // Get the next setting from the .ini file section 00058 if (IniReadSettingByNumber(SectionId, Index, SettingName, sizeof(SettingName), SettingValue, sizeof(SettingValue))) 00059 { 00060 if (_stricmp(SettingName, "DriveMap") == 0) 00061 { 00062 // Make sure we haven't exceeded the drive map max count 00063 if (DriveMapList.DriveMapCount >= 4) 00064 { 00065 sprintf(ErrorText, "Max DriveMap count exceeded in section [%s]:\n\n%s=%s", SectionName, SettingName, SettingValue); 00066 UiMessageBox(ErrorText); 00067 continue; 00068 } 00069 00070 RtlZeroMemory(Drive1, 80); 00071 RtlZeroMemory(Drive2, 80); 00072 00073 strcpy(Drive1, SettingValue); 00074 00075 // Parse the setting value and separate a string "hd0,hd1" 00076 // into two strings "hd0" and "hd1" 00077 for (Index2=0; Index2<strlen(Drive1); Index2++) 00078 { 00079 // Check if this character is the separater character (comma - ',') 00080 if (Drive1[Index2] == ',') 00081 { 00082 Drive1[Index2] = '\0'; 00083 strcpy(Drive2, &Drive1[Index2+1]); 00084 break; 00085 } 00086 } 00087 00088 // Make sure we got good values before we add them to the map 00089 if (!DriveMapIsValidDriveString(Drive1) || !DriveMapIsValidDriveString(Drive2)) 00090 { 00091 sprintf(ErrorText, "Error in DriveMap setting in section [%s]:\n\n%s=%s", SectionName, SettingName, SettingValue); 00092 UiMessageBox(ErrorText); 00093 continue; 00094 } 00095 00096 // Add them to the map 00097 DriveMapList.DriveMap[(DriveMapList.DriveMapCount * 2)] = DriveMapGetBiosDriveNumber(Drive1); 00098 DriveMapList.DriveMap[(DriveMapList.DriveMapCount * 2)+1] = DriveMapGetBiosDriveNumber(Drive2); 00099 DriveMapList.DriveMapCount++; 00100 00101 TRACE("Mapping BIOS drive 0x%x to drive 0x%x\n", DriveMapGetBiosDriveNumber(Drive1), DriveMapGetBiosDriveNumber(Drive2)); 00102 } 00103 } 00104 } 00105 00106 if (DriveMapList.DriveMapCount) 00107 { 00108 TRACE("Installing Int13 drive map for %d drives.\n", DriveMapList.DriveMapCount); 00109 DriveMapInstallInt13Handler(&DriveMapList); 00110 } 00111 else 00112 { 00113 TRACE("Removing any previously installed Int13 drive map.\n"); 00114 DriveMapRemoveInt13Handler(); 00115 } 00116 } 00117 00118 BOOLEAN DriveMapIsValidDriveString(PCSTR DriveString) 00119 { 00120 ULONG Index; 00121 00122 // Now verify that the user has given us appropriate strings 00123 if ((strlen(DriveString) < 3) || 00124 ((DriveString[0] != 'f') && (DriveString[0] != 'F') && (DriveString[0] != 'h') && (DriveString[0] != 'H')) || 00125 ((DriveString[1] != 'd') && (DriveString[1] != 'D'))) 00126 { 00127 return FALSE; 00128 } 00129 00130 // Now verify that the user has given us appropriate numbers 00131 // Make sure that only numeric characters were given 00132 for (Index=2; Index<strlen(DriveString); Index++) 00133 { 00134 if (DriveString[Index] < '0' || DriveString[Index] > '9') 00135 { 00136 return FALSE; 00137 } 00138 } 00139 // Now make sure that they are not outrageous values (i.e. hd90874) 00140 if ((atoi(&DriveString[2]) < 0) || (atoi(&DriveString[2]) > 0xff)) 00141 { 00142 return FALSE; 00143 } 00144 00145 return TRUE; 00146 } 00147 #endif 00148 00149 UCHAR DriveMapGetBiosDriveNumber(PCSTR DeviceName) 00150 { 00151 UCHAR BiosDriveNumber = 0; 00152 00153 // If they passed in a number string then just 00154 // convert it to decimal and return it 00155 if (DeviceName[0] >= '0' && DeviceName[0] <= '9') 00156 { 00157 return atoi(DeviceName); 00158 } 00159 00160 // Convert the drive number string into a number 00161 // 'hd1' = 1 00162 BiosDriveNumber = atoi(&DeviceName[2]); 00163 00164 // If it's a hard disk then set the high bit 00165 if ((DeviceName[0] == 'h' || DeviceName[0] == 'H') && 00166 (DeviceName[1] == 'd' || DeviceName[1] == 'D')) 00167 { 00168 BiosDriveNumber |= 0x80; 00169 } 00170 00171 return BiosDriveNumber; 00172 } 00173 00174 #ifndef _MSC_VER 00175 VOID DriveMapInstallInt13Handler(PDRIVE_MAP_LIST DriveMap) 00176 { 00177 ULONG* RealModeIVT = (ULONG*)0x00000000; 00178 USHORT* BiosLowMemorySize = (USHORT*)0x00000413; 00179 00180 if (!DriveMapInstalled) 00181 { 00182 // Get the old INT 13h handler address from the vector table 00183 OldInt13HandlerAddress = RealModeIVT[0x13]; 00184 00185 // Decrease the size of low memory 00186 (*BiosLowMemorySize)--; 00187 00188 // Get linear address for drive map handler 00189 DriveMapHandlerAddress = (ULONG)(*BiosLowMemorySize) << 10; 00190 00191 // Convert to segment:offset style address 00192 DriveMapHandlerSegOff = (DriveMapHandlerAddress << 12) & 0xffff0000; 00193 } 00194 00195 // Copy the drive map structure to the proper place 00196 RtlCopyMemory(&DriveMapInt13HandlerMapList, DriveMap, sizeof(DRIVE_MAP_LIST)); 00197 00198 // Set the address of the BIOS INT 13h handler 00199 DriveMapOldInt13HandlerAddress = OldInt13HandlerAddress; 00200 00201 // Copy the code to our reserved area 00202 RtlCopyMemory((PVOID)DriveMapHandlerAddress, &DriveMapInt13HandlerStart, ((ULONG)&DriveMapInt13HandlerEnd - (ULONG)&DriveMapInt13HandlerStart)); 00203 00204 // Update the IVT 00205 RealModeIVT[0x13] = DriveMapHandlerSegOff; 00206 00207 CacheInvalidateCacheData(); 00208 DriveMapInstalled = TRUE; 00209 } 00210 00211 VOID DriveMapRemoveInt13Handler(VOID) 00212 { 00213 ULONG* RealModeIVT = (ULONG*)0x00000000; 00214 USHORT* BiosLowMemorySize = (USHORT*)0x00000413; 00215 00216 if (DriveMapInstalled) 00217 { 00218 // Get the old INT 13h handler address from the vector table 00219 RealModeIVT[0x13] = OldInt13HandlerAddress; 00220 00221 // Increase the size of low memory 00222 (*BiosLowMemorySize)++; 00223 00224 CacheInvalidateCacheData(); 00225 DriveMapInstalled = FALSE; 00226 } 00227 } 00228 #endif Generated on Sun May 27 2012 04:19:07 for ReactOS by
1.7.6.1
|