Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

442 lines
11 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. sploaddrv.c
  5. Abstract:
  6. Routines to load sets of device drivers for use during text setup.
  7. Author:
  8. Ted Miller (tedm) 13-November-1993
  9. Revision History:
  10. --*/
  11. #include "spprecmp.h"
  12. #pragma hdrstop
  13. //
  14. // Define type of routine used by the device driver set loader.
  15. // Before each driver is loaded, this routine is called with
  16. // a flag indicating whether the machine is an MCA machine and
  17. // the shortname of the driver about to be loaded. If this routine
  18. // returns FALSE, the driver is not loaded. If it returns TRUE,
  19. // the driver is loaded.
  20. //
  21. typedef
  22. BOOLEAN
  23. (*PDRIVER_VERIFY_LOAD_ROUTINE) (
  24. IN PVOID SifHandle,
  25. IN BOOLEAN IsMcaMachine,
  26. IN PWSTR DriverShortname
  27. );
  28. BOOLEAN
  29. pSpVerifyLoadDiskDrivers(
  30. IN PVOID SifHandle,
  31. IN BOOLEAN IsMcaMachine,
  32. IN PWSTR DriverShortname
  33. )
  34. {
  35. UNREFERENCED_PARAMETER(SifHandle);
  36. //
  37. // Don't load fat if setupldr loaded floppy drivers.
  38. //
  39. if(!_wcsicmp(DriverShortname,L"Fat") && SetupParameters.LoadedFloppyDrivers) {
  40. return(FALSE);
  41. }
  42. //
  43. // On an MCA machine, don't load atdisk.
  44. // On a non-MCA machine, don't load abiosdsk.
  45. //
  46. if(( IsMcaMachine && !_wcsicmp(DriverShortname,L"atdisk"))
  47. || (!IsMcaMachine && !_wcsicmp(DriverShortname,L"abiosdsk")))
  48. {
  49. return(FALSE);
  50. }
  51. //
  52. // If we get this far, the driver should be loaded.
  53. //
  54. return(TRUE);
  55. }
  56. VOID
  57. SpLoadDriverSet(
  58. IN PVOID SifHandle,
  59. IN PWSTR SifSectionName,
  60. IN PWSTR SourceDevicePath,
  61. IN PWSTR DirectoryOnSourceDevice,
  62. IN PDRIVER_VERIFY_LOAD_ROUTINE VerifyLoad OPTIONAL
  63. )
  64. /*++
  65. Routine Description:
  66. Load a set of device drivers listed in a section in the setup
  67. information file. The section is expected to be in the following form:
  68. [SectionName.Load]
  69. DriverShortname = DriverFilename
  70. DriverShortname = DriverFilename
  71. DriverShortname = DriverFilename
  72. etc.
  73. [SectionName]
  74. DriverShortname = Description
  75. DriverShortname = Description
  76. DriverShortname = Description
  77. etc.
  78. The drivers will be loaded from the setup boot media, and errors
  79. loading the drivers will be ignored.
  80. Before loading each driver, a callback routine is called to verify
  81. that the driver should actually be loaded. This allows the caller
  82. to gain a fine degree of control over which drivers are loaded.
  83. Arguments:
  84. SifHandle - supplies handle to loaded setup information file.
  85. SifSectionName - supplies name of section in setup information file
  86. listing drivers to be laoded.
  87. SourceDevicePath - supplies the device path in the nt namespace of
  88. the device from which the drivers are to be loaded.
  89. DirectoryOnSourceDevice - supplies the directory on the source device
  90. from which the drivers are to be loaded.
  91. VerifyLoad - if specified, supplies the address of a routine to be
  92. called before each driver is loaded. The routine takes a flag
  93. indicating whether the machine is an MCA machine, and the driver
  94. shortname. If the routine returns false, the driver is not loaded.
  95. If this parameter is not specified, all drivers in the section
  96. will be loaded.
  97. Return Value:
  98. None.
  99. --*/
  100. {
  101. BOOLEAN IsMcaMachine;
  102. ULONG d,DriverLoadCount;
  103. PWSTR DiskDesignator,PreviousDiskDesignator;
  104. PWSTR DriverShortname,DriverFilename,DriverDescription;
  105. PWSTR LoadSectionName;
  106. NTSTATUS Status;
  107. CLEAR_CLIENT_SCREEN();
  108. SpDisplayStatusText(SP_STAT_PLEASE_WAIT,DEFAULT_STATUS_ATTRIBUTE);
  109. //
  110. // Form the .load section name.
  111. //
  112. LoadSectionName = SpMemAlloc((wcslen(SifSectionName)*sizeof(WCHAR))+sizeof(L".Load"));
  113. wcscpy(LoadSectionName,SifSectionName);
  114. wcscat(LoadSectionName,L".Load");
  115. IsMcaMachine = FALSE;
  116. //
  117. // Set up some initial state.
  118. //
  119. PreviousDiskDesignator = L"";
  120. //
  121. // Determine the number of drivers to be loaded.
  122. //
  123. DriverLoadCount = SpCountLinesInSection(SifHandle,LoadSectionName);
  124. for(d=0; d<DriverLoadCount; d++) {
  125. PWSTR p;
  126. //
  127. // Get the driver shortname.
  128. //
  129. DriverShortname = SpGetKeyName(SifHandle,LoadSectionName,d);
  130. if(!DriverShortname) {
  131. SpFatalSifError(SifHandle,LoadSectionName,NULL,d,(ULONG)(-1));
  132. }
  133. //
  134. // Determine whether we are really supposed to load this driver.
  135. //
  136. if((p = SpGetSectionLineIndex(SifHandle,LoadSectionName,d,2)) && !_wcsicmp(p,L"noload")) {
  137. continue;
  138. }
  139. if(VerifyLoad && !VerifyLoad(SifHandle,IsMcaMachine,DriverShortname)) {
  140. continue;
  141. }
  142. //
  143. // Get a human-readable description for this driver.
  144. //
  145. DriverDescription = SpGetSectionLineIndex(SifHandle,SifSectionName,d,0);
  146. if(!DriverDescription) {
  147. SpFatalSifError(SifHandle,SifSectionName,NULL,d,0);
  148. }
  149. //
  150. // Get the driver filename.
  151. //
  152. DriverFilename = SpGetSectionLineIndex(SifHandle,LoadSectionName,d,0);
  153. if(!DriverFilename) {
  154. SpFatalSifError(SifHandle,LoadSectionName,NULL,d,0);
  155. }
  156. //
  157. // Determine the disk on which this driver resides.
  158. //
  159. DiskDesignator = SpLookUpValueForFile(
  160. SifHandle,
  161. DriverFilename,
  162. INDEX_WHICHBOOTMEDIA,
  163. TRUE
  164. );
  165. //
  166. // Prompt for the disk containing the driver.
  167. //
  168. retryload:
  169. if(_wcsicmp(DiskDesignator,PreviousDiskDesignator)) {
  170. SpPromptForSetupMedia(
  171. SifHandle,
  172. DiskDesignator,
  173. SourceDevicePath
  174. );
  175. PreviousDiskDesignator = DiskDesignator;
  176. CLEAR_CLIENT_SCREEN();
  177. SpDisplayStatusText(SP_STAT_PLEASE_WAIT,DEFAULT_STATUS_ATTRIBUTE);
  178. }
  179. //
  180. // Attempt to load the driver.
  181. //
  182. Status = SpLoadDeviceDriver(
  183. DriverDescription,
  184. SourceDevicePath,
  185. DirectoryOnSourceDevice,
  186. DriverFilename
  187. );
  188. if(Status == STATUS_NO_MEDIA_IN_DEVICE) {
  189. PreviousDiskDesignator = L"";
  190. goto retryload;
  191. }
  192. }
  193. SpMemFree(LoadSectionName);
  194. }
  195. VOID
  196. SpLoadScsiClassDrivers(
  197. IN PVOID SifHandle,
  198. IN PWSTR SourceDevicePath,
  199. IN PWSTR DirectoryOnSourceDevice
  200. )
  201. /*++
  202. Routine Description:
  203. Load scsi class drivers if setupldr has not already loaded them
  204. and there are any miniport drivers loaded.
  205. The drivers to be loaded are listed in [ScsiClass].
  206. The section is expected to be in the following form:
  207. [ScsiClass]
  208. cdrom = "SCSI CD-ROM" ,scsicdrm.sys
  209. floppy = "SCSI Floppy Disk",scsiflop.sys
  210. disk = "SCSI Disk" ,scsidisk.sys
  211. The drivers will be loaded from the setup boot media, and errors
  212. loading the drivers will be ignored.
  213. Arguments:
  214. SifHandle - supplies handle to loaded setup information file.
  215. SourceDevicePath - supplies the device path in the nt namespace of
  216. the device from which the drivers are to be loaded.
  217. DirectoryOnSourceDevice - supplies the directory on the source device
  218. where the drivers are to be found.
  219. Return Value:
  220. None.
  221. --*/
  222. {
  223. //
  224. // If setupldr loaded scsi drivers, nothing to do.
  225. // If there are no miniport drivers loaded, nothing to do.
  226. //
  227. if(!SetupParameters.LoadedScsi && LoadedScsiMiniportCount) {
  228. SpLoadDriverSet(
  229. SifHandle,
  230. SIF_SCSICLASSDRIVERS,
  231. SourceDevicePath,
  232. DirectoryOnSourceDevice,
  233. NULL
  234. );
  235. }
  236. }
  237. VOID
  238. SpLoadDiskDrivers(
  239. IN PVOID SifHandle,
  240. IN PWSTR SourceDevicePath,
  241. IN PWSTR DirectoryOnSourceDevice
  242. )
  243. /*++
  244. Routine Description:
  245. Load (non-scsi) disk class drivers and disk filesystems
  246. if setupldr has not already loaded them.
  247. The drivers to be loaded are listed in [DiskDrivers] and [FileSystems].
  248. The section is expected to be in the following form:
  249. [DiskDrivers]
  250. atdisk = "ESDI/IDE Hard DIsk",atdisk.sys
  251. abiosdsk = "Micro Channel Hard Disk",abiosdsk.sys
  252. [FileSystems]
  253. fat = "FAT File System",fastfat.sys
  254. ntfs = "Windows NT File System (NTFS)",ntfs.sys
  255. The drivers will be loaded from the setup boot media, and errors
  256. loading the drivers will be ignored.
  257. On MCA machines, atdisk will not be loaded.
  258. On non-MCA machines, abiosdsk will not be loaded.
  259. Arguments:
  260. SifHandle - supplies handle to loaded setup information file.
  261. SourceDevicePath - supplies the device path in the nt namespace of
  262. the device from which the drivers are to be loaded.
  263. DirectoryOnSourceDevice - supplies the directory on the source device
  264. where the drivers are to be found.
  265. Return Value:
  266. None.
  267. --*/
  268. {
  269. //
  270. // If setupldr loaded disk drivers, nothing to do.
  271. //
  272. if(!SetupParameters.LoadedDiskDrivers) {
  273. SpLoadDriverSet(
  274. SifHandle,
  275. SIF_DISKDRIVERS,
  276. SourceDevicePath,
  277. DirectoryOnSourceDevice,
  278. pSpVerifyLoadDiskDrivers
  279. );
  280. }
  281. //
  282. // If setupldr loaded file systems, nothing to do.
  283. //
  284. if(!SetupParameters.LoadedFileSystems) {
  285. SpLoadDriverSet(
  286. SifHandle,
  287. SIF_FILESYSTEMS,
  288. SourceDevicePath,
  289. DirectoryOnSourceDevice,
  290. pSpVerifyLoadDiskDrivers
  291. );
  292. }
  293. }
  294. VOID
  295. SpLoadCdRomDrivers(
  296. IN PVOID SifHandle,
  297. IN PWSTR SourceDevicePath,
  298. IN PWSTR DirectoryOnSourceDevice
  299. )
  300. /*++
  301. Routine Description:
  302. Load the cd-rom filesystem if setupldr has not already loaded it.
  303. The drivers to be loaded are listed in [CdRomDrivers].
  304. The section is expected to be in the following form:
  305. [CdRomDrivers]
  306. cdfs = "CD-ROM File System",cdfs.sys
  307. The drivers will be loaded from the setup boot media, and errors
  308. loading the drivers will be ignored.
  309. Arguments:
  310. SifHandle - supplies handle to loaded setup information file.
  311. SourceDevicePath - supplies the device path in the nt namespace of
  312. the device from which the drivers are to be loaded.
  313. DirectoryOnSourceDevice - supplies the directory on the source device
  314. where the drivers are to be found.
  315. Return Value:
  316. None.
  317. --*/
  318. {
  319. //
  320. // If setupldr loaded cd-rom drivers, nothing to do.
  321. //
  322. if(!SetupParameters.LoadedCdRomDrivers) {
  323. SpLoadDriverSet(
  324. SifHandle,
  325. SIF_CDROMDRIVERS,
  326. SourceDevicePath,
  327. DirectoryOnSourceDevice,
  328. NULL
  329. );
  330. }
  331. }