Source code of Windows XP (NT5)
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.

3451 lines
81 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. winnt.c
  5. Abstract:
  6. Top level file for DOS based NT installation program.
  7. Author:
  8. Ted Miller (tedm) 30-March-1992
  9. Revision History:
  10. --*/
  11. /*
  12. NOTES:
  13. The function of this program is to pull down a complete Windows NT
  14. installation source onto a local partition, and create a setup boot
  15. floppy. The machine is then rebooted, starting a Windows NT Setup
  16. just as if the user had used the real setup floppies or CD-ROM.
  17. The following assumptions are made:
  18. - The floppy must be provided by the user and already formatted.
  19. - The files on the network source are in the same directory layout
  20. structure that will be created in the temp directory on the local
  21. source (ie, as far as winnt is concerned, the source and target
  22. directory layout is the same).
  23. The inf file is expected to be formatted as follows:
  24. [SpaceRequirements]
  25. # BootDrive is the # bytes required free on C:.
  26. # NtDrive is the # bytes required free on the drive chosen by
  27. # the user to contain Windows NT.
  28. BootDrive =
  29. NtDrive =
  30. [Miscellaneous]
  31. # misc junk that goes nowhere else.
  32. [Directories]
  33. # Specification of the source directory structure. All directories
  34. # are relative to the directory where dos2nt.inf was found on the
  35. # remote source or the temp directory on the local source.
  36. # Loading and trailing backslashes are ignored -- to specify the root,
  37. # leave the dirctory field blank or use \.
  38. d1 =
  39. d2 = os2
  40. .
  41. .
  42. .
  43. [Files]
  44. # List of files to be copied to the local source directory.
  45. # Format is <srcdir>,<filename> where <srcdir> matches an entry in the
  46. # Directories section, and <filename> should not contain any path
  47. # characters.
  48. d1,ntoskrnl.exe
  49. d1,ntdll.dll
  50. .
  51. .
  52. .
  53. [FloppyFiles]
  54. # List of files that are to be placed on the floppy that Setup creates.
  55. # Format is same as for lines in the [Files] sections except the directory
  56. # is only used for the source -- the target path is always a:\.
  57. d1,aha154x.sys
  58. .
  59. .
  60. .
  61. */
  62. #include "winnt.h"
  63. #include <errno.h>
  64. #include <string.h>
  65. #include <dos.h>
  66. #include <stdlib.h>
  67. #include <direct.h>
  68. #include <fcntl.h>
  69. #include <ctype.h>
  70. #include <process.h>
  71. #if NEC_98
  72. #include <signal.h>
  73. #include <io.h>
  74. #endif // NEC_98
  75. #include "SetupSxs.h"
  76. //
  77. // define name of default inf file and default source path
  78. //
  79. #define DEFAULT_INF_NAME "dosnet.inf"
  80. PCHAR DrvindexInfName = "drvindex.inf";
  81. #if NEC_98
  82. //
  83. // Boot Device Information.(for /b)
  84. //
  85. typedef struct _BOOTDISKINF {
  86. UCHAR PartitionPosition; // 0-F
  87. UCHAR DA_UA; // SASI/IDE 80, SCSI A0
  88. USHORT DiskSector; // Device Format Sector Size
  89. } BOOTDISKINF, *PBOOTDISKINF;
  90. PBOOTDISKINF BootDiskInfo; // Boot Device Information of Pointer(for /b).
  91. BOOLEAN CursorOnFlag = FALSE; // For Cursor OFF
  92. USHORT Cylinders; // For Dos 3.x format
  93. UCHAR TargetDA_UA;
  94. //
  95. // Make File Pointer.
  96. //
  97. #define MAKE_FP(p,a) FP_SEG(p) = (unsigned short)((a) >> 4) & 0xffff; FP_OFF(p) = (unsigned short)((a) & 0x0f)
  98. //
  99. // Connect Device DA_UA.
  100. //
  101. typedef struct _CONNECTDAUA {
  102. UCHAR DA_UA; // SASI/IDE 80, SCSI A0
  103. } CONNECTDAUA, *PCONNECTDAUA;
  104. PCONNECTDAUA DiskDAUA; // Connect DA_UA of Pointer.
  105. PUCHAR LPTable; // DOS System of LPTable.
  106. UCHAR SupportDosVersion = 5; // LPTable Support Dos version;
  107. BOOLEAN SupportDos = TRUE;
  108. #define FLOPPY_SIZE 1457664L
  109. //
  110. // Search First Floppy Disk Drive ( 0:None Drive / 1-26:Drive# )
  111. //
  112. USHORT FirstFD;
  113. #endif // NEC_98
  114. //
  115. // Command line arguments
  116. //
  117. PCHAR CmdLineSource,CmdLineTarget,CmdLineInf,CmdLineDelete;
  118. BOOLEAN SourceGiven,TargetGiven,InfGiven,DeleteGiven;
  119. //
  120. // If the user gives a script file on the command line,
  121. // if will be appended to winnt.sif.
  122. //
  123. PCHAR DngScriptFile = NULL;
  124. //
  125. // DngSourceRootPath is the drivespec and path to the root of the source,
  126. // and never ends in \ (will be length 2 if source is the root).
  127. //
  128. // Examples: D:\foo\bar D:\foo D:
  129. //
  130. PCHAR DngSourceRootPath;
  131. PCHAR UserSpecifiedOEMShare = 0;
  132. CHAR DngTargetDriveLetter;
  133. CHAR DngSwapDriveLetter;
  134. PVOID DngInfHandle;
  135. PVOID DngDrvindexInfHandle;
  136. PCHAR LocalSourceDirName = LOCAL_SOURCE_DIRECTORY;
  137. #if NEC_98
  138. PCHAR x86DirName = "\\NEC98";
  139. #else // NEC_98
  140. PCHAR x86DirName = "\\I386";
  141. #endif // NEC_98
  142. //
  143. // If this flag is TRUE, then verify the files that are copied to
  144. // the floppy. If it is FALSE, don't. The /f switch overrides.
  145. //
  146. BOOLEAN DngFloppyVerify = TRUE;
  147. //
  148. // If this is FALSE, suppress creation of the boot floppies.
  149. //
  150. BOOLEAN DngCreateFloppies = TRUE;
  151. BOOLEAN DngFloppiesOnly = FALSE;
  152. //
  153. // If TRUE, create winnt floppies.
  154. // If FALSE, create cd/floppy floppies (no winnt.sif)
  155. //
  156. BOOLEAN DngWinntFloppies = TRUE;
  157. //
  158. // If this flag is TRUE, then check the free space on the floppy disk
  159. // before accepting it. Otherwise don't check free space.
  160. //
  161. BOOLEAN DngCheckFloppySpace = TRUE;
  162. //
  163. // Current drive when program invoked, saved so we can restore it
  164. // if the user exits early.
  165. //
  166. unsigned DngOriginalCurrentDrive;
  167. //
  168. // If this is true, we do floppyless operation,
  169. // installing an nt boot on the system partition (C:)
  170. // and starting setup from there.
  171. //
  172. BOOLEAN DngFloppyless = FALSE;
  173. //
  174. // Unattended mode, ie, skip final reboot screen.
  175. //
  176. BOOLEAN DngUnattended = FALSE;
  177. BOOLEAN DngServer = FALSE;
  178. //
  179. // Flag that indicates that we are running on Windows
  180. // (ie, not bare DOS).
  181. //
  182. BOOLEAN DngWindows = FALSE;
  183. //
  184. // Flag that indicates we want to see the accessiblity options
  185. //
  186. BOOLEAN DngAccessibility = FALSE;
  187. BOOLEAN DngMagnifier = FALSE;
  188. BOOLEAN DngTalker = FALSE;
  189. BOOLEAN DngKeyboard = FALSE;
  190. //
  191. // Flag for the 2nd CD enhancements to setup
  192. //
  193. BOOLEAN DngCopyOnlyD1TaggedFiles = TRUE;
  194. //
  195. // Flag that indicates that we are running OEM preinstall
  196. //
  197. BOOLEAN DngOemPreInstall = FALSE;
  198. PCHAR OemSystemDirectory = WINNT_OEM_DIR;
  199. PCHAR OemOptionalDirectory = WINNT_OEM_OPTIONAL_DIR;
  200. PCHAR UniquenessDatabaseFile;
  201. PCHAR UniquenessId;
  202. //
  203. // Command to execute at the end of GUI setup
  204. //
  205. PCHAR CmdToExecuteAtEndOfGui = NULL;
  206. //
  207. // Keep track of any optional dirs that the user wants
  208. // to copy
  209. //
  210. unsigned OptionalDirCount;
  211. CHAR *OptionalDirs[MAX_OPTIONALDIRS];
  212. unsigned OptionalDirFlags[MAX_OPTIONALDIRS];
  213. unsigned OptionalDirFileCount;
  214. //
  215. // Keep track of any OEM boot file specified on [OemBootFiles]
  216. // in the script file
  217. //
  218. unsigned OemBootFilesCount;
  219. CHAR *OemBootFiles[MAX_OEMBOOTFILES];
  220. //
  221. // Define the minimum disk space needed in order to copy the temporary
  222. // directories to drives formatted with all possible cluster sizes
  223. //
  224. SPACE_REQUIREMENT SpaceRequirements[] = { { "TempDirSpace512", (unsigned) 512, 0 },
  225. { "TempDirSpace1K", (unsigned) 1024, 0 },
  226. { "TempDirSpace2K", (unsigned) 2048, 0 },
  227. { "TempDirSpace4K", (unsigned) 4096, 0 },
  228. { "TempDirSpace8K", (unsigned) 8192, 0 },
  229. { "TempDirSpace16K", (unsigned)16384, 0 },
  230. { "TempDirSpace32K", (unsigned)32768, 0 }
  231. };
  232. #define TEDM
  233. #ifdef TEDM
  234. BOOLEAN DngAllowNt = FALSE;
  235. #endif
  236. VOID
  237. DnpFetchArguments(
  238. VOID
  239. );
  240. BOOLEAN
  241. DnpParseArguments(
  242. IN int argc,
  243. IN char *argv[]
  244. );
  245. VOID
  246. DnpGetAccessibilityOptions(
  247. VOID
  248. );
  249. VOID
  250. DnpValidateAndConnectToShare(
  251. FILE **InfFileHandle,
  252. FILE **DrvindexInfFileHandle
  253. );
  254. VOID
  255. DnpValidateAndInspectTarget(
  256. VOID
  257. );
  258. VOID
  259. DnpCheckMemory(
  260. VOID
  261. );
  262. VOID
  263. DnpCheckSmartdrv(
  264. VOID
  265. );
  266. BOOLEAN
  267. DnpIsValidSwapDrive(
  268. IN CHAR Drive,
  269. IN ULONG SpaceRequired
  270. );
  271. BOOLEAN
  272. DnpIsValidLocalSource(
  273. IN CHAR Drive,
  274. IN BOOLEAN CheckLocalSource,
  275. IN BOOLEAN CheckBootFiles
  276. );
  277. VOID
  278. DnpDetermineLocalSourceDrive(
  279. VOID
  280. );
  281. VOID
  282. DnpDetermineSwapDrive(
  283. VOID
  284. );
  285. #if 0
  286. BOOLEAN
  287. DnpConstructLocalSourceList(
  288. OUT PCHAR DriveList
  289. );
  290. #endif
  291. ULONG
  292. DnGetMinimumRequiredSpace(
  293. IN CHAR DriveLetter
  294. );
  295. VOID
  296. DnpReadInf(
  297. IN FILE *InfFileHandle,
  298. IN FILE *DrvindexInfFileHandle
  299. );
  300. VOID
  301. DnpCheckEnvironment(
  302. VOID
  303. );
  304. BOOLEAN
  305. RememberOptionalDir(
  306. IN PCHAR Dir,
  307. IN unsigned Flags
  308. );
  309. void
  310. _far
  311. DnInt24(
  312. unsigned deverror,
  313. unsigned errcode,
  314. unsigned _far *devhdr
  315. );
  316. VOID
  317. StartLog(
  318. VOID
  319. );
  320. // in cpu.asm
  321. #if NEC_98
  322. extern
  323. USHORT
  324. HwGetProcessorType(
  325. VOID
  326. );
  327. #else // NEC_98
  328. USHORT
  329. HwGetProcessorType(
  330. VOID
  331. );
  332. #endif // NEC_98
  333. #if NEC_98
  334. VOID
  335. CheckTargetDrive(
  336. VOID
  337. );
  338. VOID
  339. SetAutoReboot(
  340. VOID
  341. );
  342. USHORT
  343. GetSectorValue(
  344. IN UCHAR CheckDA_UA
  345. );
  346. BOOLEAN
  347. DiskSectorReadWrite(
  348. IN USHORT HDSector,
  349. IN UCHAR ReadWriteDA_UA,
  350. IN BOOLEAN ReadFlag,
  351. IN PSHORT ReadBuffer
  352. );
  353. VOID
  354. GetLPTable(
  355. IN PCHAR pLPTable
  356. );
  357. VOID
  358. ClearBootFlag(
  359. VOID
  360. );
  361. VOID
  362. BootPartitionData(
  363. VOID
  364. );
  365. BOOLEAN
  366. CheckBootDosVersion(
  367. IN UCHAR SupportDosVersion
  368. );
  369. VOID
  370. GetDaUa(VOID);
  371. VOID
  372. SearchFirstFDD(VOID);
  373. extern
  374. ULONG
  375. DnpCopyOneFile(
  376. IN PCHAR SourceName,
  377. IN PCHAR DestName,
  378. IN BOOLEAN Verify
  379. );
  380. extern
  381. PCHAR
  382. DnGetSectionLineIndex (
  383. IN PVOID INFHandle,
  384. IN PCHAR SectionName,
  385. IN unsigned LineIndex,
  386. IN unsigned ValueIndex
  387. );
  388. VOID
  389. DummyRoutine(
  390. VOID
  391. );
  392. #endif // NEC_98
  393. VOID
  394. main(
  395. IN int argc,
  396. IN char *argv[]
  397. )
  398. {
  399. FILE *f, *drvindex;
  400. #ifdef LCP
  401. USHORT codepage;
  402. #endif // def LCP
  403. #if NEC_98
  404. DngTargetDriveLetter = 0;
  405. //
  406. // CTRL + C Hook
  407. //
  408. signal(SIGINT,DummyRoutine);
  409. #else // NEC_98
  410. #ifdef LCP
  411. // Determine the local code page
  412. _asm {
  413. mov ax,06601h
  414. int 21h
  415. jnc ok
  416. xor bx,bx
  417. ok: mov codepage, bx
  418. }
  419. // If codepage does not correspond to winnt.exe's language,
  420. // start US Winnt.exe (winntus.exe)
  421. // Czech
  422. #if CS
  423. #define LANGCP (852)
  424. #else
  425. // Greek
  426. #if EL
  427. #define LANGCP (737)
  428. #else
  429. // Japanese
  430. #if JAPAN
  431. #define LANGCP (932)
  432. #else
  433. // Russian
  434. #if RU
  435. #define LANGCP (866)
  436. #else
  437. // Polish
  438. #if PL
  439. #define LANGCP (852)
  440. #else
  441. // Hungarian
  442. #if HU
  443. #define LANGCP (852)
  444. #else
  445. // Turkish
  446. #if TR
  447. #define LANGCP (857)
  448. #else
  449. // Pseudo
  450. #if PSU
  451. #define LANGCP (857)
  452. #else
  453. #error Unable to define LANGCP as no matching language was found.
  454. #endif // PSU
  455. #endif // TR
  456. #endif // HU
  457. #endif // PL
  458. #endif // RU
  459. #endif // JAPAN
  460. #endif // EL
  461. #endif // CS
  462. if (codepage != LANGCP) {
  463. argv[0] = "winntus";
  464. execv("winntus", argv);
  465. return;
  466. }
  467. #endif // def LCP
  468. #endif // NEC_98
  469. //
  470. // Parse arguments
  471. //
  472. if(!DnpParseArguments(argc,argv)) {
  473. PCHAR *p;
  474. //
  475. // Bad args. Print usage message and exit.
  476. //
  477. // If user specified /D, display message informing that the
  478. // switch is no longer supported
  479. //
  480. for( (p = DeleteGiven ? DntUsageNoSlashD : DntUsage);
  481. *p;
  482. p++) {
  483. puts(*p);
  484. }
  485. return;
  486. }
  487. //
  488. // establish int 24 handler
  489. //
  490. _harderr(DnInt24);
  491. //
  492. // determine current drive
  493. //
  494. _dos_getdrive(&DngOriginalCurrentDrive);
  495. //
  496. // Initialize screen
  497. //
  498. DnInitializeDisplay();
  499. #if NEC_98
  500. #else
  501. //
  502. // Patch boot code with translated messages.
  503. //
  504. if(!PatchMessagesIntoBootCode()) {
  505. DnFatalError(&DnsBootMsgsTooLarge);
  506. }
  507. #endif
  508. DnWriteString(DntStandardHeader);
  509. DnpDetermineSwapDrive ();
  510. if(DngUnattended) {
  511. //
  512. // Check to see if we should process the contents of
  513. // the script file.
  514. // Note that we need to process the contents of the script file
  515. // only after the video is initialized. Otherwise, we won't be able
  516. // to report fatal errors.
  517. //
  518. if (DngScriptFile) {
  519. DnpFetchArguments();
  520. }
  521. }
  522. #if 0
  523. //
  524. // /D is no longer supported
  525. //
  526. if(DeleteGiven) {
  527. DnDeleteNtTree(CmdLineDelete);
  528. }
  529. #endif
  530. DnpCheckEnvironment();
  531. #if NEC_98
  532. LPTable = MALLOC(96,TRUE);
  533. SupportDos = CheckBootDosVersion(SupportDosVersion);
  534. GetLPTable(LPTable);
  535. SearchFirstFDD();
  536. #endif // NEC_98
  537. DnpValidateAndConnectToShare(&f, &drvindex);
  538. DnpReadInf(f, drvindex);
  539. fclose(f);
  540. fclose(drvindex);
  541. if(DngAccessibility) {
  542. DnpGetAccessibilityOptions();
  543. }
  544. DnpCheckMemory();
  545. DnpCheckSmartdrv ();
  546. if(!DngFloppiesOnly) {
  547. DnpDetermineLocalSourceDrive();
  548. }
  549. #if NEC_98
  550. if(!DngFloppiesOnly) {
  551. BootDiskInfo = MALLOC(sizeof(BOOTDISKINF),TRUE);
  552. BootPartitionData();
  553. CheckTargetDrive();
  554. }
  555. #endif // NEC_98
  556. if(!DngAllowNt && DngCreateFloppies) {
  557. DnCreateBootFloppies();
  558. }
  559. if(!DngFloppiesOnly) {
  560. DnCopyFiles();
  561. #if NEC_98
  562. //
  563. // Set Auto Reboot Flag
  564. //
  565. if(DngFloppyless) {
  566. ClearBootFlag();
  567. SetAutoReboot();
  568. }
  569. FREE(BootDiskInfo);
  570. FREE(LPTable);
  571. #endif // NEC_98
  572. DnFreeINFBuffer (DngInfHandle);
  573. DnFreeINFBuffer (DngDrvindexInfHandle);
  574. DnToNtSetup();
  575. }
  576. DnFreeINFBuffer (DngInfHandle);
  577. DnFreeINFBuffer (DngDrvindexInfHandle);
  578. DnExit(0);
  579. }
  580. BOOLEAN
  581. RememberOptionalDir(
  582. IN PCHAR Dir,
  583. IN unsigned Flags
  584. )
  585. {
  586. unsigned u;
  587. for (u = 0; u < OptionalDirCount; u++) {
  588. if(!stricmp(OptionalDirs[u],Dir)) {
  589. OptionalDirFlags[u] = Flags;
  590. return (TRUE);
  591. }
  592. }
  593. //
  594. // Not already in there
  595. //
  596. if (OptionalDirCount < MAX_OPTIONALDIRS) {
  597. OptionalDirs[OptionalDirCount] = Dir;
  598. OptionalDirFlags[OptionalDirCount] = Flags;
  599. OptionalDirCount++;
  600. return (TRUE);
  601. }
  602. return (FALSE);
  603. }
  604. BOOLEAN
  605. RememberOemBootFile(
  606. IN PCHAR File
  607. )
  608. {
  609. unsigned u;
  610. for (u = 0; u < OemBootFilesCount; u++) {
  611. if(!stricmp(OemBootFiles[u],File)) {
  612. return (TRUE);
  613. }
  614. }
  615. //
  616. // Not already in there
  617. //
  618. if (OemBootFilesCount < MAX_OEMBOOTFILES) {
  619. OemBootFiles[OemBootFilesCount] = File;
  620. OemBootFilesCount++;
  621. return (TRUE);
  622. }
  623. return (FALSE);
  624. }
  625. VOID
  626. DnpFetchArguments(
  627. VOID
  628. )
  629. {
  630. PCHAR WinntSetupP = WINNT_SETUPPARAMS;
  631. PCHAR WinntYes = WINNT_A_YES;
  632. PCHAR WinntNo = WINNT_A_NO;
  633. FILE *FileHandle;
  634. int Status;
  635. PVOID ScriptHandle;
  636. PCHAR WinntUnattended = WINNT_UNATTENDED;
  637. PCHAR WinntOemPreinstall = WINNT_OEMPREINSTALL;
  638. unsigned LineNumber;
  639. //
  640. // First open the script file as a dos file
  641. //
  642. FileHandle = fopen(DngScriptFile,"rt");
  643. if(FileHandle == NULL) {
  644. //
  645. // fatal error.
  646. //
  647. DnFatalError(&DnsOpenReadScript);
  648. }
  649. //
  650. // Now open it as a INF file
  651. //
  652. LineNumber = 0;
  653. Status = DnInitINFBuffer (FileHandle, &ScriptHandle, &LineNumber);
  654. fclose(FileHandle);
  655. if(Status == ENOMEM) {
  656. DnFatalError(&DnsOutOfMemory);
  657. } else if(Status) {
  658. DnFatalError(&DnsParseScriptFile, DngScriptFile, LineNumber);
  659. }
  660. //
  661. // Find out if this is an OEM preinstall
  662. //
  663. if (DnSearchINFSection(ScriptHandle,WinntUnattended)) {
  664. if (DnGetSectionKeyExists(ScriptHandle,WinntUnattended,WinntOemPreinstall)) {
  665. PCHAR Ptr;
  666. //
  667. // OEM preinstall key exists
  668. //
  669. Ptr = DnGetSectionKeyIndex(ScriptHandle,WinntUnattended,WinntOemPreinstall,0);
  670. if (Ptr != NULL) {
  671. if (stricmp(Ptr,WinntYes) == 0) {
  672. //
  673. // This is an OEM pre-install
  674. //
  675. DngOemPreInstall = TRUE;
  676. } else {
  677. //
  678. // Assume this is not an OEM pre-install
  679. //
  680. DngOemPreInstall = FALSE;
  681. }
  682. FREE (Ptr);
  683. }
  684. }
  685. //
  686. // See if the user specified a network (or any secondary) path
  687. // for the $OEM$ files.
  688. //
  689. if( DngOemPreInstall ) {
  690. if (DnGetSectionKeyExists(ScriptHandle,WinntUnattended,WINNT_OEM_DIRLOCATION)) {
  691. PCHAR Ptr;
  692. unsigned i;
  693. //
  694. // WINNT_OEM_DIRLOCATION preinstall key exists
  695. //
  696. Ptr = DnGetSectionKeyIndex(ScriptHandle,WinntUnattended,WINNT_OEM_DIRLOCATION,0);
  697. //
  698. // Now take care of the case whether or not
  699. // the user actually appended $OEM$ onto the path.
  700. // For the case of winnt.exe, we don't want it. We
  701. // need to remove it if it's there.
  702. UserSpecifiedOEMShare = DnDupString( Ptr );
  703. FREE (Ptr);
  704. for( i = 0; i < strlen(UserSpecifiedOEMShare); i++ ) {
  705. UserSpecifiedOEMShare[i] = (UCHAR) toupper(UserSpecifiedOEMShare[i]);
  706. }
  707. Ptr = strstr( UserSpecifiedOEMShare, "$OEM$" );
  708. if( Ptr ) {
  709. //
  710. // Whack the end off...
  711. //
  712. *Ptr = 0;
  713. }
  714. }
  715. }
  716. if( DngOemPreInstall ) {
  717. //
  718. // Always add to the list of optional directories the directory
  719. // $OEM$
  720. //
  721. RememberOptionalDir(OemSystemDirectory, OPTDIR_OEMSYS);
  722. //
  723. // If this an OEM pre-install, build a list with the name of all
  724. // OEM optional directories.
  725. //
  726. if (DnSearchINFSection(ScriptHandle, WINNT_OEMOPTIONAL)) {
  727. unsigned KeyIndex;
  728. PCHAR DirName;
  729. //
  730. // Add the temporary OEM directories to the array of
  731. // temporary directories.
  732. //
  733. for( KeyIndex = 0;
  734. ((DirName = DnGetKeyName(ScriptHandle,WINNT_OEMOPTIONAL,KeyIndex)) != NULL );
  735. KeyIndex++ ) {
  736. //
  737. // We have a valid directory name
  738. //
  739. PCHAR p;
  740. if((p = DnDupString(DirName)) == NULL) {
  741. DnFatalError(&DnsOutOfMemory);
  742. }
  743. RememberOptionalDir(p, OPTDIR_OEMOPT);
  744. FREE (DirName);
  745. }
  746. }
  747. //
  748. // If this an OEM pre-install, build a list with the name of all
  749. // OEM boot files.
  750. //
  751. if (DnSearchINFSection(ScriptHandle, WINNT_OEMBOOTFILES)) {
  752. unsigned LineIndex;
  753. PCHAR FileName;
  754. //
  755. // Add the OEM boot files to the array of
  756. // OEM boot files.
  757. //
  758. for( LineIndex = 0;
  759. ((FileName = DnGetSectionLineIndex(ScriptHandle,WINNT_OEMBOOTFILES,LineIndex,0)) != NULL );
  760. LineIndex++ ) {
  761. PCHAR q;
  762. if((q = DnDupString(FileName)) == NULL) {
  763. DnFatalError(&DnsOutOfMemory);
  764. }
  765. RememberOemBootFile(q);
  766. FREE (FileName);
  767. }
  768. }
  769. }
  770. }
  771. //
  772. // We are done with the ScriptHandle for now
  773. //
  774. DnFreeINFBuffer(ScriptHandle);
  775. }
  776. BOOLEAN
  777. DnpParseArguments(
  778. IN int argc,
  779. IN char *argv[]
  780. )
  781. /*++
  782. Routine Description:
  783. Parse arguments passed to the program. Perform syntactic validation
  784. and fill in defaults where necessary.
  785. Valid arguments:
  786. /d:path - specify installation to remove
  787. (not supported anymore)
  788. /s:sharepoint[path] - specify source sharepoint and path on it
  789. /t:drive[:] - specify temporary local source drive
  790. /i:filename - specify name of inf file
  791. /o - create boot floppies only
  792. (not supported anymore)
  793. /f - turn floppy verification off
  794. (not supported anymore)
  795. /c - suppress free-space check on the floppy
  796. (not supported anymore)
  797. /x - suppress creation of the floppy altogether
  798. /b - floppyless operation
  799. (not supported anymore)
  800. /u - unattended (skip final reboot screen)
  801. /w - [undoc'ed] must be specifed when running
  802. under windows, chicago, etc.
  803. /a - enable accessibility options
  804. /2 - copy the entire source locally - all files irrespective
  805. of the d1/d2 tags. Default is only d1 tagged files.
  806. Introduced for the 2 CD install that is required tablets.
  807. Arguments:
  808. argc - # arguments
  809. argv - array of pointers to arguments
  810. Return Value:
  811. None.
  812. --*/
  813. {
  814. PCHAR arg;
  815. CHAR swit;
  816. PCHAR ArgSwitches[] = { "E", "D", "T", "I", "RX", "R", "S", NULL };
  817. PCHAR RestOfSwitch;
  818. int i;
  819. int l;
  820. //
  821. // Set the variables that are no longer
  822. // settable via the command line.
  823. //
  824. DngFloppyless = TRUE;
  825. DngCreateFloppies = FALSE;
  826. //
  827. // Skip program name
  828. //
  829. argv++;
  830. DeleteGiven = SourceGiven = TargetGiven = FALSE;
  831. OptionalDirCount = 0;
  832. CmdLineTarget = CmdLineInf = NULL;
  833. while(--argc) {
  834. if((**argv == '-') || (**argv == '/')) {
  835. swit = argv[0][1];
  836. //
  837. // Process switches that take no arguments here.
  838. //
  839. switch(swit) {
  840. case '?':
  841. return(FALSE); // force usage
  842. #if 0
  843. case 'f':
  844. case 'F':
  845. argv++;
  846. DngFloppyVerify = FALSE;
  847. continue;
  848. #endif
  849. #if 0
  850. case 'c':
  851. case 'C':
  852. argv++;
  853. DngCheckFloppySpace = FALSE;
  854. continue;
  855. #endif
  856. #if 0
  857. case 'x':
  858. case 'X':
  859. argv++;
  860. DngCreateFloppies = FALSE;
  861. continue;
  862. #endif
  863. #ifdef LOGGING
  864. case 'l':
  865. case 'L':
  866. argv++;
  867. StartLog();
  868. continue;
  869. #endif
  870. #if 0
  871. case 'o':
  872. case 'O':
  873. //
  874. // check for /Ox. /O* is a secret switch that replaces the old /o.
  875. //
  876. switch(argv[0][2]) {
  877. case 'x':
  878. case 'X':
  879. DngWinntFloppies = FALSE;
  880. case '*':
  881. break;
  882. default:
  883. return(FALSE);
  884. }
  885. argv++;
  886. DngFloppiesOnly = TRUE;
  887. continue;
  888. #endif
  889. #if 0
  890. case 'b':
  891. case 'B':
  892. argv++;
  893. DngFloppyless = TRUE;
  894. continue;
  895. #endif
  896. case 'u':
  897. case 'U':
  898. if(((argv[0][2] == 'd') || (argv[0][2] == 'D'))
  899. && ((argv[0][3] == 'f') || (argv[0][3] == 'F'))) {
  900. if((argv[0][4] == ':') && argv[0][5]) {
  901. if((arg = strchr(&argv[0][5],',')) == NULL) {
  902. arg = strchr(&argv[0][5],0);
  903. }
  904. l = arg - &argv[0][5];
  905. UniquenessId = MALLOC(l+2,TRUE);
  906. memcpy(UniquenessId,&argv[0][5],l);
  907. UniquenessId[l] = 0;
  908. if(*arg++) {
  909. if(*arg) {
  910. //
  911. // Now the rest of the param is the filename of
  912. // the uniqueness database
  913. //
  914. UniquenessDatabaseFile = DnDupString(arg);
  915. UniquenessId[l] = '*';
  916. UniquenessId[l+1] = 0;
  917. } else {
  918. return(FALSE);
  919. }
  920. }
  921. } else {
  922. return(FALSE);
  923. }
  924. } else {
  925. DngUnattended = TRUE;
  926. //
  927. // User can say -u:<file> also
  928. //
  929. if(argv[0][2] == ':') {
  930. if(argv[0][3] == 0) {
  931. return(FALSE);
  932. }
  933. if((DngScriptFile = DnDupString(&argv[0][3])) == NULL) {
  934. DnFatalError(&DnsOutOfMemory);
  935. }
  936. }
  937. }
  938. argv++;
  939. continue;
  940. case 'w':
  941. case 'W':
  942. //
  943. // This flag used to force us to run under Windows,
  944. // when doing a 386 stepping check could crash the system.
  945. // Now we don't support 386, so this check is never done.
  946. //
  947. // However we accept the arg to force us into Windows mode on DOS,
  948. // which allows someone to avoid the final reboot.
  949. //
  950. DngWindows = TRUE;
  951. argv++;
  952. continue;
  953. case 'a':
  954. case 'A':
  955. argv++;
  956. DngAccessibility = TRUE;
  957. continue;
  958. #ifdef TEDM
  959. case 'i':
  960. case 'I':
  961. if(!stricmp(argv[0]+1,"I_am_TedM")) {
  962. argv++;
  963. DngAllowNt = TRUE;
  964. continue;
  965. }
  966. #endif
  967. case '2':
  968. argv++;
  969. DngCopyOnlyD1TaggedFiles = FALSE;
  970. //_LOG(("Going to copy files irrespective of the directory tag\n"));
  971. continue;
  972. }
  973. //
  974. // Process switches that take arguments here.
  975. //
  976. //
  977. // This code taken from winnt32.c. It has the
  978. // purpose of validating the switch and determining
  979. // where the next argument lines
  980. //
  981. for (i=0; ArgSwitches[i]; i++) {
  982. l = strlen(ArgSwitches[i]);
  983. if (!strnicmp(ArgSwitches[i],&argv[0][1],l)) {
  984. //
  985. // we have a match. Next char of arg must either
  986. // be : or nul. If it's : then arg immediately
  987. // follows. Otherwise, if it's null, then arg must
  988. // be next argument
  989. //
  990. if (argv[0][1+l] == ':') {
  991. arg = &argv[0][2+l];
  992. if (*arg == '\0') {
  993. return (FALSE);
  994. }
  995. RestOfSwitch = &argv[0][2];
  996. break;
  997. } else {
  998. if (argv[0][1+l] == '\0') {
  999. if (argc <= 1) {
  1000. //
  1001. // no arguments left
  1002. //
  1003. return (FALSE);
  1004. }
  1005. RestOfSwitch = &argv[0][2];
  1006. argc--;
  1007. arg = argv[1];
  1008. argv++;
  1009. break;
  1010. } else {
  1011. //
  1012. // Do nothing here
  1013. //
  1014. NULL;
  1015. } // if ... else
  1016. } // if ... else
  1017. } // if ...
  1018. } // for
  1019. //
  1020. // Check termination condition
  1021. //
  1022. if (!ArgSwitches[i]) {
  1023. return (FALSE);
  1024. }
  1025. switch(swit) {
  1026. case 'r':
  1027. case 'R':
  1028. RememberOptionalDir(
  1029. DnDupString(arg),
  1030. ( (RestOfSwitch[0] == 'X' || RestOfSwitch[0] == 'x') ?
  1031. OPTDIR_TEMPONLY : 0 ) );
  1032. break;
  1033. case 'd':
  1034. case 'D':
  1035. //
  1036. // /D is no longer supported
  1037. //
  1038. DeleteGiven = TRUE;
  1039. return(FALSE);
  1040. #if 0
  1041. case 'd':
  1042. case 'D':
  1043. if(DeleteGiven) {
  1044. return(FALSE);
  1045. } else {
  1046. if((CmdLineDelete = DnDupString(arg)) == NULL) {
  1047. DnFatalError(&DnsOutOfMemory);
  1048. }
  1049. DeleteGiven = TRUE;
  1050. }
  1051. break;
  1052. #endif
  1053. case 's':
  1054. case 'S':
  1055. if(SourceGiven) {
  1056. return(FALSE);
  1057. } else {
  1058. if((CmdLineSource = DnDupString(arg)) == NULL) {
  1059. DnFatalError(&DnsOutOfMemory);
  1060. }
  1061. SourceGiven = TRUE;
  1062. }
  1063. break;
  1064. case 't':
  1065. case 'T':
  1066. if(TargetGiven) {
  1067. return(FALSE);
  1068. } else {
  1069. if((CmdLineTarget = DnDupString(arg)) == NULL) {
  1070. DnFatalError(&DnsOutOfMemory);
  1071. }
  1072. TargetGiven = TRUE;
  1073. }
  1074. break;
  1075. case 'i':
  1076. case 'I':
  1077. if(InfGiven) {
  1078. return(FALSE);
  1079. } else {
  1080. if((CmdLineInf = DnDupString(arg)) == NULL) {
  1081. DnFatalError(&DnsOutOfMemory);
  1082. }
  1083. InfGiven = TRUE;
  1084. }
  1085. break;
  1086. case 'E':
  1087. case 'e':
  1088. if(CmdToExecuteAtEndOfGui) {
  1089. return(FALSE);
  1090. } else {
  1091. if((CmdToExecuteAtEndOfGui = DnDupString(arg)) == NULL) {
  1092. DnFatalError(&DnsOutOfMemory);
  1093. }
  1094. }
  1095. break;
  1096. default:
  1097. return(FALSE);
  1098. }
  1099. } else {
  1100. return(FALSE);
  1101. }
  1102. argv++;
  1103. }
  1104. //
  1105. // If /u was specified, make sure /s was also given
  1106. // and force /b.
  1107. //
  1108. if(DngUnattended) {
  1109. if(!SourceGiven) {
  1110. return(FALSE);
  1111. }
  1112. DngFloppyless = TRUE;
  1113. }
  1114. if(DngFloppyless) {
  1115. //
  1116. // Force us into the floppy creation code.
  1117. //
  1118. DngCreateFloppies = TRUE;
  1119. DngWinntFloppies = TRUE;
  1120. }
  1121. return(TRUE);
  1122. }
  1123. VOID
  1124. DnpGetAccessibilityOptions(
  1125. VOID
  1126. )
  1127. /*++
  1128. Routine Description:
  1129. Ask the user which accessibility utilities to install for GUI Setup.
  1130. Arguments:
  1131. None.
  1132. Return Value:
  1133. None.
  1134. --*/
  1135. {
  1136. ULONG ValidKey[4];
  1137. ULONG Key;
  1138. CHAR Mark;
  1139. //
  1140. // Make sure the setup boot floppy we created is in the drive
  1141. // if necessary.
  1142. //
  1143. DnClearClientArea();
  1144. DnDisplayScreen(&DnsAccessibilityOptions);
  1145. DnWriteStatusText(DntEnterEqualsContinue);
  1146. ValidKey[0] = ASCI_CR;
  1147. ValidKey[1] = DN_KEY_F1;
  1148. ValidKey[2] = DN_KEY_F2;
  1149. ValidKey[3] = 0;
  1150. while((Key = DnGetValidKey(ValidKey)) != ASCI_CR) {
  1151. switch(Key) {
  1152. case DN_KEY_F1:
  1153. DngMagnifier = (BOOLEAN)!DngMagnifier;
  1154. Mark = DngMagnifier ? RADIO_ON : RADIO_OFF;
  1155. DnPositionCursor(4,7);
  1156. break;
  1157. case DN_KEY_F2:
  1158. DngTalker = (BOOLEAN)!DngTalker;
  1159. Mark = DngTalker ? RADIO_ON : RADIO_OFF;
  1160. DnPositionCursor(4,8);
  1161. break;
  1162. #if 0
  1163. case DN_KEY_F3:
  1164. DngKeyboard = (BOOLEAN)!DngKeyboard;
  1165. Mark = DngKeyboard ? RADIO_ON : RADIO_OFF;
  1166. DnPositionCursor(4,9);
  1167. break;
  1168. #endif
  1169. }
  1170. DnWriteChar(Mark);
  1171. }
  1172. }
  1173. VOID
  1174. DnpValidateAndConnectToShare(
  1175. FILE **InfFileHandle,
  1176. FILE **DrvindexInfFileHandle
  1177. )
  1178. /*++
  1179. Routine Description:
  1180. Split the source given by the user into drive and path
  1181. components. If the user did not specify a source, prompt him
  1182. for one. Look for dos2nt.inf on the source (ie, validate the
  1183. source) and keep prompting the user for a share until he enters
  1184. one which appears to be valid.
  1185. Arguments:
  1186. Return Value:
  1187. None.
  1188. --*/
  1189. {
  1190. CHAR UserString[256];
  1191. PCHAR InfFullName, DrvindexInfFullName;
  1192. PCHAR q;
  1193. BOOLEAN ValidSourcePath;
  1194. unsigned len;
  1195. DnClearClientArea();
  1196. DnWriteStatusText(NULL);
  1197. //
  1198. // Use default inf file if none specified.
  1199. //
  1200. if(!InfGiven) {
  1201. CmdLineInf = DEFAULT_INF_NAME;
  1202. }
  1203. //
  1204. // If the user did not enter a source, prompt him for one.
  1205. //
  1206. if(SourceGiven) {
  1207. strcpy(UserString,CmdLineSource);
  1208. } else {
  1209. #if NEC_98
  1210. CursorOnFlag = TRUE;
  1211. #endif // NEC_98
  1212. DnDisplayScreen(&DnsNoShareGiven);
  1213. DnWriteStatusText("%s %s",DntEnterEqualsContinue,DntF3EqualsExit);
  1214. if(getcwd(UserString,sizeof(UserString)-1) == NULL) {
  1215. UserString[0] = '\0';
  1216. }
  1217. #if NEC_98
  1218. CursorOnFlag = FALSE;
  1219. #endif // NEC_98
  1220. DnGetString(UserString,NO_SHARE_X,NO_SHARE_Y,NO_SHARE_W);
  1221. }
  1222. ValidSourcePath = FALSE;
  1223. do {
  1224. DnWriteStatusText(DntOpeningInfFile);
  1225. //
  1226. // Make a copy of the path the user typed leaving extra room.
  1227. //
  1228. DngSourceRootPath = MALLOC(256,TRUE);
  1229. if(len = strlen(UserString)) {
  1230. strcpy(DngSourceRootPath,UserString);
  1231. //
  1232. // If the user typed something like x:, then we want to
  1233. // change that to x:. so this does what he expects.
  1234. // Doing so also lets the canonicalize routine work.
  1235. //
  1236. if((DngSourceRootPath[1] == ':') && !DngSourceRootPath[2]) {
  1237. DngSourceRootPath[2] = '.';
  1238. DngSourceRootPath[3] = 0;
  1239. }
  1240. //
  1241. // Now attempt to canonicalize the name. If this doesn't work,
  1242. // then it's definitely not a valid path.
  1243. //
  1244. if(DnCanonicalizePath(DngSourceRootPath,UserString)) {
  1245. strcpy(DngSourceRootPath,UserString);
  1246. //
  1247. // If the path doesn't end with a backslash,
  1248. // append a backslash before appending the inf filename.
  1249. //
  1250. len = strlen(DngSourceRootPath);
  1251. if(DngSourceRootPath[len-1] != '\\') {
  1252. DngSourceRootPath[len] = '\\';
  1253. DngSourceRootPath[len+1] = 0;
  1254. len++;
  1255. }
  1256. InfFullName = MALLOC(len + strlen(CmdLineInf) + 1,TRUE);
  1257. strcpy(InfFullName,DngSourceRootPath);
  1258. strcat(InfFullName,CmdLineInf);
  1259. DrvindexInfFullName = MALLOC(len + strlen(DrvindexInfName) + 1,TRUE);
  1260. strcpy(DrvindexInfFullName,DngSourceRootPath);
  1261. strcat(DrvindexInfFullName,DrvindexInfName);
  1262. //
  1263. // Attempt to open the inf file on the source.
  1264. // If that fails look for it in the i386 subdirectory.
  1265. //
  1266. //_LOG(("Validate source path: trying %s\n",InfFullName));
  1267. //_LOG(("Validate source path: trying %s\n",DrvindexInfFullName));
  1268. if((*InfFileHandle = fopen(InfFullName,"rt")) != NULL){
  1269. if((*DrvindexInfFileHandle = fopen(DrvindexInfFullName,"rt")) != NULL){
  1270. ValidSourcePath = TRUE;
  1271. }
  1272. else
  1273. fclose( *InfFileHandle );
  1274. }
  1275. if(*InfFileHandle != NULL ){
  1276. //_LOG(("%s opened successfully\n",InfFullName));
  1277. }
  1278. if(*DrvindexInfFileHandle != NULL ){
  1279. //_LOG(("%s opened successfully\n",DrvindexInfFullName));
  1280. }
  1281. FREE(InfFullName);
  1282. FREE(DrvindexInfFullName);
  1283. if(!ValidSourcePath) {
  1284. InfFullName = MALLOC(len+strlen(CmdLineInf)+strlen(x86DirName)+1,TRUE);
  1285. DrvindexInfFullName = MALLOC(len+strlen(DrvindexInfName)+strlen(x86DirName)+1,TRUE);
  1286. strcpy(InfFullName,DngSourceRootPath);
  1287. strcat(InfFullName,x86DirName+1);
  1288. strcat(InfFullName,"\\");
  1289. strcpy(DrvindexInfFullName, InfFullName);
  1290. strcat(InfFullName,CmdLineInf);
  1291. strcat(DrvindexInfFullName,DrvindexInfName);
  1292. //_LOG(("Validate source path: trying %s\n",InfFullName));
  1293. if((*InfFileHandle = fopen(InfFullName,"rt")) != NULL){
  1294. if((*DrvindexInfFileHandle = fopen(DrvindexInfFullName,"rt")) != NULL){
  1295. ValidSourcePath = TRUE;
  1296. }
  1297. else
  1298. fclose( *InfFileHandle );
  1299. }
  1300. if(*InfFileHandle != NULL ){
  1301. //_LOG(("%s opened successfully\n",InfFullName));
  1302. }
  1303. if(*DrvindexInfFileHandle != NULL ){
  1304. //_LOG(("%s opened successfully\n",DrvindexInfFullName));
  1305. }
  1306. FREE(InfFullName);
  1307. FREE(DrvindexInfFullName);
  1308. if(ValidSourcePath) {
  1309. //
  1310. // Change the source to the i386 subdirectory.
  1311. //
  1312. q = DngSourceRootPath;
  1313. DngSourceRootPath = MALLOC(strlen(q)+strlen(x86DirName),TRUE);
  1314. strcpy(DngSourceRootPath,q);
  1315. strcat(DngSourceRootPath,x86DirName+1);
  1316. FREE(q);
  1317. }
  1318. }
  1319. }
  1320. }
  1321. if(!ValidSourcePath) {
  1322. FREE(DngSourceRootPath);
  1323. DnClearClientArea();
  1324. #if NEC_98
  1325. CursorOnFlag = TRUE;
  1326. #endif // NEC_98
  1327. DnDisplayScreen(&DnsBadSource);
  1328. DnWriteStatusText("%s %s",DntEnterEqualsContinue,DntF3EqualsExit);
  1329. #if NEC_98
  1330. CursorOnFlag = FALSE;
  1331. #endif // NEC_98
  1332. DnGetString(UserString,NO_SHARE_X,BAD_SHARE_Y,NO_SHARE_W);
  1333. }
  1334. } while(!ValidSourcePath);
  1335. //
  1336. // Make sure DngSourceRootPath does not end with a backslash.
  1337. // and trim the buffer down to size.
  1338. //
  1339. len = strlen(DngSourceRootPath);
  1340. if(DngSourceRootPath[len-1] == '\\') {
  1341. DngSourceRootPath[len-1] = 0;
  1342. }
  1343. if(q = DnDupString(DngSourceRootPath)) {
  1344. FREE(DngSourceRootPath);
  1345. DngSourceRootPath = q;
  1346. }
  1347. //_LOG(("Source root path is %s\n",DngSourceRootPath));
  1348. }
  1349. VOID
  1350. DnRemoveTrailingSlashes(
  1351. PCHAR Path
  1352. )
  1353. {
  1354. if (Path != NULL && Path[0] != 0) {
  1355. int Length = strlen(Path);
  1356. while (Path[Length - 1] == '\\' || Path[Length - 1] == '/') {
  1357. Length -= 1;
  1358. }
  1359. Path[Length] = 0;
  1360. }
  1361. }
  1362. VOID
  1363. DnRemoveLastPathElement(
  1364. PCHAR Path
  1365. )
  1366. {
  1367. PCHAR LastBackSlash = strrchr(Path, '\\');
  1368. if (LastBackSlash != NULL) {
  1369. *(LastBackSlash + 1) = 0;
  1370. }
  1371. }
  1372. VOID
  1373. DnpReadInf(
  1374. IN FILE *InfFileHandle,
  1375. IN FILE *DrvindexInfFileHandle
  1376. )
  1377. /*++
  1378. Routine Description:
  1379. Read the INF file. Does not return if error.
  1380. Arguments:
  1381. None.
  1382. Return Value:
  1383. None.
  1384. --*/
  1385. {
  1386. int Status;
  1387. PCHAR p;
  1388. PCHAR pchHeader;
  1389. unsigned LineNumber, DLineNumber;
  1390. DnWriteStatusText(DntReadingInf,CmdLineInf);
  1391. DnClearClientArea();
  1392. LineNumber = 0;
  1393. Status = DnInitINFBuffer (InfFileHandle, &DngInfHandle, &LineNumber);
  1394. if(Status == ENOMEM) {
  1395. DnFatalError(&DnsOutOfMemory);
  1396. } else if(Status) {
  1397. DnFatalError(&DnsBadInf);
  1398. }
  1399. DLineNumber = 0;
  1400. Status = DnInitINFBuffer (DrvindexInfFileHandle, &DngDrvindexInfHandle, &DLineNumber);
  1401. if(Status == ENOMEM) {
  1402. DnFatalError(&DnsOutOfMemory);
  1403. } else if(Status) {
  1404. DnFatalError(&DnsBadInf);
  1405. }
  1406. //
  1407. // Determine product type (workstation/server)
  1408. //
  1409. p = DnGetSectionKeyIndex(DngInfHandle,DnfMiscellaneous,"ProductType",0);
  1410. pchHeader = DntWorkstationHeader; // default to workstation
  1411. if(p && atoi(p)) {
  1412. switch(atoi(p)) {
  1413. case 4:
  1414. pchHeader = DntPersonalHeader;
  1415. break;
  1416. case 1: //server
  1417. case 2: //enterprise
  1418. case 3: //datacenter
  1419. default:
  1420. pchHeader = DntServerHeader;
  1421. DngServer = TRUE;
  1422. break;
  1423. }
  1424. }
  1425. if (p) {
  1426. FREE (p);
  1427. }
  1428. DnPositionCursor(0,0);
  1429. DnWriteString(pchHeader);
  1430. //
  1431. // Get mandatory optional components
  1432. //
  1433. LineNumber = 0;
  1434. while(p = DnGetSectionLineIndex(DngInfHandle,"OptionalSrcDirs",LineNumber++,0)) {
  1435. PCHAR q;
  1436. if((q = DnDupString(p)) == NULL) {
  1437. DnFatalError(&DnsOutOfMemory);
  1438. }
  1439. RememberOptionalDir(q, OPTDIR_TEMPONLY);
  1440. FREE (p);
  1441. }
  1442. //
  1443. // get Fusion Side By Side Assemblies ("sxs_" here for searching)
  1444. //
  1445. {
  1446. struct find_t FindData;
  1447. unsigned InfSectionLineNumber = 0;
  1448. PCHAR InfValue;
  1449. unsigned optdirFlags;
  1450. CHAR SourceDir[DOS_MAX_PATH];
  1451. PCHAR DupInfValue;
  1452. PCHAR FreeInfValue;
  1453. while(InfValue = DnGetSectionLineIndex(DngInfHandle, DnfAssemblyDirectories, InfSectionLineNumber++, 0)) {
  1454. //
  1455. // convention introduced specifically for side by side, so that
  1456. // x86 files on ia64 might come from \i386\asms instead of \ia64\asms\i386,
  1457. // depending on what dosnet.inf and syssetup.inf say:
  1458. // a path that does not start with a slash is appended to \$win_nt$.~ls\processor;
  1459. // a path that does start with a slash is appended to \$win_nt$.~ls
  1460. //
  1461. // We honor it in x86-only winnt.exe in case anyone decides to use it
  1462. // for other reasons, to keep parity in this area between winnt and winnt32.exe.
  1463. optdirFlags = OPTDIR_TEMPONLY;
  1464. strcpy(SourceDir, DngSourceRootPath); // includes trailing i386
  1465. FreeInfValue = InfValue;
  1466. if (InfValue[0] == '\\' || InfValue[0] == '/') {
  1467. optdirFlags |= OPTDIR_PLATFORM_INDEP;
  1468. // remove trailing i386
  1469. DnRemoveTrailingSlashes(SourceDir);
  1470. DnRemoveLastPathElement(SourceDir);
  1471. // remove leading slash
  1472. InfValue += 1;
  1473. }
  1474. DnpConcatPaths(SourceDir, InfValue);
  1475. //
  1476. // The asms directory is optional because there might just be asms*.cab.
  1477. //
  1478. if (_dos_findfirst(SourceDir, _A_HIDDEN|_A_SYSTEM|_A_SUBDIR, &FindData) == 0
  1479. && (FindData.attrib & _A_SUBDIR)) {
  1480. if((DupInfValue = DnDupString(InfValue)) == NULL) {
  1481. DnFatalError(&DnsOutOfMemory);
  1482. }
  1483. RememberOptionalDir(DupInfValue, optdirFlags);
  1484. FREE(FreeInfValue);
  1485. }
  1486. }
  1487. }
  1488. }
  1489. VOID
  1490. DnpCheckEnvironment(
  1491. VOID
  1492. )
  1493. /*++
  1494. Routine Description:
  1495. Verify that the following are true:
  1496. - DOS major version 5 or greater
  1497. - there is a floppy drive at a: that is 1.2 meg or greater
  1498. If any of the above are not true, abort with a fatal error.
  1499. Arguments:
  1500. None.
  1501. Return Value:
  1502. None.
  1503. --*/
  1504. {
  1505. UCHAR DeviceParams[256];
  1506. unsigned char _near * pDeviceParams = DeviceParams;
  1507. DnWriteStatusText(DntInspectingComputer);
  1508. DeviceParams[0] = 0; // get default device params
  1509. _asm {
  1510. //
  1511. // Check if we're on NT.
  1512. // The true version on NT is 5.50.
  1513. //
  1514. mov ax,3306h
  1515. sub bx,bx
  1516. int 21h
  1517. cmp bx,3205h // check for v. 5.50
  1518. jne checkwin
  1519. #ifdef TEDM
  1520. cmp DngAllowNt,1
  1521. je checkflop
  1522. #endif
  1523. bados:
  1524. push seg DnsCantRunOnNt
  1525. push offset DnsCantRunOnNt
  1526. call DnFatalError // doesn't return
  1527. checkwin:
  1528. //
  1529. // The /w switch used to be necessary since we could crash Windows
  1530. // checking the CPU stepping on a 386. However since we don't support
  1531. // 386 any more, we never do that check and we can simply detect
  1532. // whether we're on Windows. The /w switch is not necessary.
  1533. //
  1534. mov ax,1600h
  1535. int 2fh
  1536. test al,7fh
  1537. jz checkcpu
  1538. mov DngWindows,1
  1539. //
  1540. // Now check Win95. Issue int2f func 4a33.
  1541. // If ax comes back as 0 then it's win95.
  1542. //
  1543. push ds
  1544. push si
  1545. push dx
  1546. push bx
  1547. mov ax,4a33h
  1548. int 2fh
  1549. pop bx
  1550. pop dx
  1551. pop si
  1552. pop ds
  1553. cmp ax,0
  1554. jz bados
  1555. checkcpu:
  1556. //
  1557. // Check CPU type. Fail if not greater than 386.
  1558. //
  1559. call HwGetProcessorType
  1560. cmp ax,3
  1561. ja checkflop
  1562. push seg DnsRequires486
  1563. push offset DnsRequires486
  1564. call DnFatalError // doesn't return
  1565. checkflop:
  1566. //
  1567. // If this is not a floppyless installation, check for 1.2MB
  1568. // or greater A:. Get the default device params for drive A:
  1569. // and check the device type field.
  1570. //
  1571. #if NEC_98
  1572. #else // NEC_98
  1573. cmp DngFloppyless,1 // floppyless installation?
  1574. je checkdosver // yes, no floppy drive required
  1575. mov ax,440dh // ioctl
  1576. mov bl,1 // drive a:
  1577. mov cx,860h // category disk, func get params
  1578. mov dx,pDeviceParams // ds is already correct
  1579. int 21h
  1580. jnc gotdevparams
  1581. flopperr:
  1582. push seg DnsRequiresFloppy
  1583. push offset DnsRequiresFloppy
  1584. call DnFatalError // doesn't return
  1585. gotdevparams:
  1586. //
  1587. // Check to make sure that the device is removable and perform
  1588. // checks on the media type
  1589. //
  1590. mov si,pDeviceParams
  1591. test [si+2],1 // bit 0 clear if removable
  1592. jnz flopperr
  1593. #ifdef ALLOW_525
  1594. cmp [si+1],1 // media type = 1.2meg floppy?
  1595. jz checkdosver
  1596. #endif
  1597. cmp [si+1],7 // media type = 1.4meg floppy
  1598. jb flopperr // or greater?
  1599. checkdosver:
  1600. #endif // NEC_98
  1601. //
  1602. // Check DOS version >= 5.0
  1603. //
  1604. mov ax,3000h // function 30h -- get DOS version
  1605. int 21h
  1606. cmp al,5
  1607. jae checkdone // >= 5.0
  1608. //
  1609. // version < 5
  1610. //
  1611. push seg DnsBadDosVersion
  1612. push offset DnsBadDosVersion
  1613. call DnFatalError
  1614. checkdone:
  1615. }
  1616. }
  1617. VOID
  1618. DnpCheckMemory(
  1619. VOID
  1620. )
  1621. /*++
  1622. Routine Description:
  1623. Verify that enough memory is installed in the machine.
  1624. Arguments:
  1625. None.
  1626. Return Value:
  1627. None. Does not return in there's not enough memory.
  1628. --*/
  1629. {
  1630. USHORT MemoryK;
  1631. ULONG TotalMemory,RequiredMemory;
  1632. PCHAR RequiredMemoryStr;
  1633. //
  1634. // Now that servers require so much memory (64Mb), just remove this check.
  1635. // We'll catch him in textmode.
  1636. // -matth
  1637. //
  1638. return;
  1639. DnWriteStatusText(DntInspectingComputer);
  1640. //
  1641. // I cannot figure out a reliable way to determine the amount of
  1642. // memory in the machine. Int 15 func 88 is likely to be hooked by
  1643. // himem.sys or some other memory manager to return 0. DOS maintains
  1644. // the original amount of extended memory but to get to this value
  1645. // you have to execute the sysvars undocumented int21 ah=52 call, and
  1646. // even then what about versions previous to dos 4? Calling himem to
  1647. // ask for the total amount of xms memory does not give you the total
  1648. // amount of extended memory, just the amount of xms memory.
  1649. // So we'll short-circuit the memory check code by always deciding that
  1650. // there's 50MB of extended memory. This should always be big enough,
  1651. // and this way the rest of the code stays intact, ready to work if
  1652. // we figure out a way to make the memory determination. Just replace
  1653. // the following line with the check, and make sure MemoryK is set to
  1654. // the amount of extended memory in K.
  1655. //
  1656. // Update: one might be able to get the amount of extended memory by
  1657. // looking in CMOS. See the code below.
  1658. // The only problem with this is that it cannot detect more than 63MB
  1659. // of extended memory. This should be good for now, since this is
  1660. // enough even for NT server.
  1661. //
  1662. _asm {
  1663. //
  1664. // This code access to I/O ports 70H and 71H.
  1665. // But these port are different feature on NEC98.
  1666. // The 70H port is Character Display controller's port.
  1667. // So, if this code running(out 70h, 18h) on NEC98, display
  1668. // setting will be broken and garbage characters displayed.
  1669. //
  1670. #if NEC_98
  1671. push ax
  1672. push es
  1673. mov ax, 40h
  1674. mov es, ax
  1675. xor ax, ax
  1676. mov al, es:[1] // 1M - 16M memories(per 128K)
  1677. shr ax, 3 // convert MB
  1678. add ax, es:[194h] // Over 16M memories(per 1M)
  1679. mov MemoryK,ax
  1680. pop es
  1681. pop ax
  1682. #else // NEC_98
  1683. push ax
  1684. cli
  1685. mov al, 18h // get extended memory high
  1686. out 70h, al
  1687. jmp short $+2
  1688. in al, 71H
  1689. shl ax, 08H
  1690. mov al, 17H // get extended memory low
  1691. out 70H, al
  1692. jmp short $+2
  1693. in al, 71H
  1694. mov MemoryK,ax
  1695. sti
  1696. pop ax
  1697. #endif // NEC_98
  1698. }
  1699. //
  1700. // Account for conventional memory. Simplistic, but good enough.
  1701. //
  1702. #if NEC_98
  1703. MemoryK *= 1024;
  1704. MemoryK += 640;
  1705. #else // NEC_98
  1706. MemoryK += 1024;
  1707. #endif // NEC_98
  1708. TotalMemory = (ULONG)MemoryK * 1024L;
  1709. RequiredMemoryStr = DnGetSectionKeyIndex( DngInfHandle,
  1710. DnfMiscellaneous,
  1711. DnkMinimumMemory,
  1712. 0
  1713. );
  1714. //
  1715. // If the required memory is not specified in the inf, force an error
  1716. // to get someone's attention so we can fix dosnet.inf.
  1717. //
  1718. RequiredMemory = RequiredMemoryStr ? (ULONG)atol(RequiredMemoryStr) : 0xffffffff;
  1719. if (RequiredMemoryStr) {
  1720. FREE (RequiredMemoryStr);
  1721. }
  1722. if(TotalMemory < RequiredMemory) {
  1723. CHAR Decimal[10];
  1724. ULONG r;
  1725. CHAR Line1[100],Line2[100];
  1726. r = ((RequiredMemory % (1024L*1024L)) * 100L) / (1024L*1024L);
  1727. if(r) {
  1728. sprintf(Decimal,".%lu",r);
  1729. } else {
  1730. Decimal[0] = 0;
  1731. }
  1732. snprintf(Line1,sizeof(Line1),DnsNotEnoughMemory.Strings[NOMEM_LINE1],RequiredMemory/(1024L*1024L),Decimal);
  1733. DnsNotEnoughMemory.Strings[NOMEM_LINE1] = Line1;
  1734. r = ((TotalMemory % (1024L*1024L)) * 100L) / (1024L*1024L);
  1735. if(r) {
  1736. sprintf(Decimal,".%lu",r);
  1737. } else {
  1738. Decimal[0] = 0;
  1739. }
  1740. snprintf(Line2,sizeof(Line2),DnsNotEnoughMemory.Strings[NOMEM_LINE2],TotalMemory/(1024L*1024L),Decimal);
  1741. DnsNotEnoughMemory.Strings[NOMEM_LINE2] = Line2;
  1742. DnFatalError(&DnsNotEnoughMemory);
  1743. }
  1744. }
  1745. VOID
  1746. DnpCheckSmartdrv(
  1747. VOID
  1748. )
  1749. /*++
  1750. Routine Description:
  1751. Verify that SMARTDRV is installed in the machine.
  1752. Arguments:
  1753. None.
  1754. Return Value:
  1755. None. If SMARTDRV is not installed we recommend the user to install it.
  1756. They have a chance to quit setup or to go on without SMARTDRV.
  1757. --*/
  1758. {
  1759. ULONG ValidKey[3];
  1760. ULONG c;
  1761. USHORT sinst = 0;
  1762. if (!DngUnattended) {
  1763. _asm {
  1764. push ax
  1765. push bx
  1766. push cx
  1767. push dx
  1768. push di
  1769. push si
  1770. push bp
  1771. mov ax, 4a10h
  1772. xor bx, bx
  1773. mov cx, 0ebabh
  1774. int 2fh
  1775. cmp ax, 0babeh
  1776. jne final
  1777. pop bp
  1778. mov sinst, 1
  1779. push bp
  1780. final:
  1781. pop bp
  1782. pop si
  1783. pop di
  1784. pop dx
  1785. pop cx
  1786. pop bx
  1787. pop ax
  1788. }
  1789. if (!sinst) {
  1790. ValidKey[0] = ASCI_CR;
  1791. ValidKey[1] = DN_KEY_F3;
  1792. ValidKey[2] = 0;
  1793. DnClearClientArea();
  1794. DnDisplayScreen(&DnsNoSmartdrv);
  1795. DnWriteStatusText("%s %s",DntEnterEqualsContinue,DntF3EqualsExit);
  1796. while(1) {
  1797. c = DnGetValidKey(ValidKey);
  1798. if(c == ASCI_CR) {
  1799. break;
  1800. }
  1801. if(c == DN_KEY_F3) {
  1802. DnExitDialog();
  1803. }
  1804. }
  1805. DnClearClientArea();
  1806. }
  1807. }
  1808. }
  1809. void
  1810. _far
  1811. DnInt24(
  1812. unsigned deverror,
  1813. unsigned errcode,
  1814. unsigned _far *devhdr
  1815. )
  1816. /*++
  1817. Routine Description:
  1818. Int24 handler. We do not perform any special actions on a hard error;
  1819. rather we just return FAIL so the caller of the failing api will get
  1820. back an error code and take appropriate action itself.
  1821. This function should never be invoked directly.
  1822. Arguments:
  1823. deverror - supplies the device error code.
  1824. errcode - the DI register passed by MS-DOS to int 24 handlers.
  1825. devhdr - supplies pointer to the device header for the device on which
  1826. the hard error occured.
  1827. Return Value:
  1828. None.
  1829. --*/
  1830. {
  1831. _hardresume(_HARDERR_FAIL);
  1832. }
  1833. VOID
  1834. DnpDetermineSwapDrive(
  1835. VOID
  1836. )
  1837. /*++
  1838. Routine Description:
  1839. Determine the swap drive. We need to be able to write on that drive and
  1840. we need at least 500K free disk space.
  1841. Arguments:
  1842. None.
  1843. Return Value:
  1844. None. Sets the global variable DngSwapDriveLetter.
  1845. --*/
  1846. {
  1847. ULONG CheckingDrive;
  1848. CHAR SystemPartitionDriveLetter, TheDrive, DriveLetter;
  1849. DngSwapDriveLetter = '?';
  1850. #if NEC_98
  1851. SystemPartitionDriveLetter = 'A';
  1852. #else
  1853. SystemPartitionDriveLetter = 'C';
  1854. #endif
  1855. TheDrive = 0;
  1856. for( CheckingDrive = SystemPartitionDriveLetter - 'A'; CheckingDrive < ('Z' - 'A'); CheckingDrive++ ) {
  1857. DriveLetter = (CHAR)('A' + CheckingDrive);
  1858. if (DnpIsValidSwapDrive (DriveLetter, 1L * 1024 * 1024)) {
  1859. TheDrive = (CHAR)('A' + CheckingDrive);
  1860. break;
  1861. }
  1862. }
  1863. if( TheDrive == 0 ) {
  1864. //
  1865. // If there is no valid drive for the swap file, put an error message
  1866. //
  1867. DnFatalError (&DnsNoSwapDrive);
  1868. } else {
  1869. DngSwapDriveLetter = TheDrive;
  1870. }
  1871. }
  1872. BOOLEAN
  1873. DnpIsValidSwapDrive(
  1874. IN CHAR Drive,
  1875. IN ULONG SpaceRequired
  1876. )
  1877. /*++
  1878. Routine Description:
  1879. Determine if a drive is valid as a swap drive.
  1880. To be valid a drive must be extant, non-removable, local, and have
  1881. enough free space on it (as much as SpaceNeeded specifies).
  1882. Arguments:
  1883. Drive - drive letter of drive to check.
  1884. Return Value:
  1885. TRUE if Drive is valid as a swap drive. FALSE otherwise.
  1886. --*/
  1887. {
  1888. unsigned d = (unsigned)toupper(Drive) - (unsigned)'A' + 1;
  1889. struct diskfree_t DiskSpace;
  1890. ULONG SpaceAvailable;
  1891. if( DnIsDriveValid(d)
  1892. && !DnIsDriveRemote(d,NULL)
  1893. && !DnIsDriveRemovable(d))
  1894. {
  1895. //
  1896. // Check free space on the drive.
  1897. //
  1898. if(!_dos_getdiskfree(d,&DiskSpace)) {
  1899. SpaceAvailable = (ULONG)DiskSpace.avail_clusters
  1900. * (ULONG)DiskSpace.sectors_per_cluster
  1901. * (ULONG)DiskSpace.bytes_per_sector;
  1902. return( (BOOLEAN)(SpaceAvailable >= SpaceRequired) );
  1903. }
  1904. }
  1905. return(FALSE);
  1906. }
  1907. VOID
  1908. DnpDetermineLocalSourceDrive(
  1909. VOID
  1910. )
  1911. /*++
  1912. Routine Description:
  1913. Determine the local source drive, ie, the drive that will contain the
  1914. local copy of the windows nt setup source tree. The local source could
  1915. have been passed on the command line, in which case we will validate it.
  1916. If there was no drive specified, examine each drive in the system looking
  1917. for a local, fixed drive with enough free space on it (as specified in
  1918. the inf file).
  1919. Arguments:
  1920. None.
  1921. Return Value:
  1922. None. Sets the global variable DngTargetDriveLetter.
  1923. --*/
  1924. {
  1925. ULONG RequiredSpace;
  1926. ULONG CheckWhichDrives = 0, CheckingDrive;
  1927. CHAR SystemPartitionDriveLetter, TheDrive, DriveLetter;
  1928. DnRemoveLocalSourceTrees();
  1929. DnRemovePagingFiles();
  1930. //
  1931. // Get the space requirements for the main retail files
  1932. //
  1933. DnDetermineSpaceRequirements( SpaceRequirements,
  1934. sizeof( SpaceRequirements ) / sizeof( SPACE_REQUIREMENT ) );
  1935. //
  1936. // Determine the space requirements for the optional directories
  1937. // Note that DnpIterateOptionalDirs() will initialize the global variables
  1938. // TotalOptionalFileCount and TotalOptionalFileCount in dncopy.c with the
  1939. // total number of files in optional directory, and the total number of
  1940. // optional directories, respectively.
  1941. //
  1942. DngTargetDriveLetter = '?';
  1943. DnpIterateOptionalDirs(CPY_VALIDATION_PASS,
  1944. 0,
  1945. SpaceRequirements,
  1946. sizeof( SpaceRequirements ) / sizeof( SPACE_REQUIREMENT ));
  1947. DnAdjustSpaceRequirements( SpaceRequirements,
  1948. sizeof( SpaceRequirements ) / sizeof( SPACE_REQUIREMENT ));
  1949. //
  1950. // Which drives do we need to examine?
  1951. //
  1952. if( DngFloppyless ) {
  1953. //
  1954. // Need to determine the system partition. It is usually C:
  1955. // but if C: is compressed we need to find the host drive.
  1956. //
  1957. unsigned HostDrive;
  1958. if(!DngAllowNt && DnIsDriveCompressedVolume(3,&HostDrive)) {
  1959. CheckWhichDrives |= (0x1 << (HostDrive - 1));
  1960. SystemPartitionDriveLetter = (CHAR)('A' + (HostDrive - 1));
  1961. } else {
  1962. CheckWhichDrives |= (0x1 << 2);
  1963. #if NEC_98
  1964. SystemPartitionDriveLetter = 'A';
  1965. #else
  1966. SystemPartitionDriveLetter = 'C';
  1967. #endif
  1968. }
  1969. }
  1970. if( TargetGiven ) {
  1971. if( DngAllowNt ) {
  1972. DngTargetDriveLetter = (UCHAR) toupper(*CmdLineTarget);
  1973. return;
  1974. }
  1975. CheckWhichDrives |= (0x1 << ((unsigned)toupper(*CmdLineTarget) - 'A'));
  1976. } else {
  1977. CheckWhichDrives = 0xFFFFFFFF;
  1978. }
  1979. TheDrive = 0;
  1980. for( CheckingDrive = 0; CheckingDrive < ('Z' - 'A'); CheckingDrive++ ) {
  1981. //
  1982. // Do we even need to look at this drive?
  1983. //
  1984. if( !(CheckWhichDrives & (0x1 << CheckingDrive))) {
  1985. continue;
  1986. }
  1987. DriveLetter = (CHAR)('A' + CheckingDrive);
  1988. if( DnpIsValidLocalSource( DriveLetter,
  1989. TRUE, // Check for LocalSource
  1990. (BOOLEAN)(DriveLetter == SystemPartitionDriveLetter) ) ) {
  1991. if( TargetGiven ) {
  1992. if( DriveLetter == (CHAR)toupper(*CmdLineTarget) ) {
  1993. TheDrive = DriveLetter;
  1994. }
  1995. } else {
  1996. if( !TheDrive ) {
  1997. //
  1998. // Take the first catch.
  1999. //
  2000. TheDrive = DriveLetter;
  2001. }
  2002. }
  2003. if( TheDrive ) {
  2004. //
  2005. // We found a suitable drive. But are we really done?
  2006. //
  2007. if( (DngFloppyless) &&
  2008. (DriveLetter < SystemPartitionDriveLetter) ) {
  2009. //
  2010. // We will be writing some boot files and we haven't checked
  2011. // the system partition yet. Cut to the chase.
  2012. //
  2013. CheckWhichDrives = (0x1 << (SystemPartitionDriveLetter - 'A'));
  2014. } else {
  2015. break;
  2016. }
  2017. }
  2018. } else {
  2019. //
  2020. // We need to special-handle failures on the system partition.
  2021. // See if he's capable of at least taking the system boot
  2022. // files.
  2023. //
  2024. if( (DriveLetter == SystemPartitionDriveLetter) &&
  2025. (DngFloppyless) ) {
  2026. if( !DnpIsValidLocalSource( DriveLetter,
  2027. FALSE,
  2028. TRUE )) {
  2029. //
  2030. // Consider ourselves slumped over.
  2031. //
  2032. TheDrive = 0;
  2033. break;
  2034. }
  2035. }
  2036. }
  2037. }
  2038. if( TheDrive == 0 ) {
  2039. //
  2040. // If there is no valid drive for the local source, put an error
  2041. // message with the minimum space required for C:
  2042. //
  2043. if( TargetGiven ) {
  2044. RequiredSpace = DnGetMinimumRequiredSpace(*CmdLineTarget);
  2045. } else {
  2046. #if NEC_98
  2047. RequiredSpace = DnGetMinimumRequiredSpace('A');
  2048. #else
  2049. RequiredSpace = DnGetMinimumRequiredSpace('C');
  2050. #endif
  2051. }
  2052. DnFatalError(
  2053. &DnsNoLocalSrcDrives,
  2054. (unsigned)(RequiredSpace/(1024L*1024L)),
  2055. RequiredSpace
  2056. );
  2057. } else {
  2058. //
  2059. // Use the first drive on the list.
  2060. //
  2061. DngTargetDriveLetter = TheDrive;
  2062. return;
  2063. }
  2064. }
  2065. BOOLEAN
  2066. DnpIsValidLocalSource(
  2067. IN CHAR Drive,
  2068. IN BOOLEAN CheckLocalSource,
  2069. IN BOOLEAN CheckBootFiles
  2070. )
  2071. /*++
  2072. Routine Description:
  2073. Determine if a drive is valid as a local source.
  2074. To be valid a drive must be extant, non-removable, local, and have
  2075. enough free space on it.
  2076. Arguments:
  2077. Drive - drive letter of drive to check.
  2078. Return Value:
  2079. TRUE if Drive is valid as a local source. FALSE otherwise.
  2080. --*/
  2081. {
  2082. unsigned d = (unsigned)toupper(Drive) - (unsigned)'A' + 1;
  2083. struct diskfree_t DiskSpace;
  2084. ULONG SpaceAvailable, SpaceRequired, ClusterSize;
  2085. unsigned DontCare, i;
  2086. if( DnIsDriveValid(d)
  2087. && !DnIsDriveRemote(d,NULL)
  2088. && !DnIsDriveRemovable(d)
  2089. && !DnIsDriveCompressedVolume(d,&DontCare))
  2090. {
  2091. //
  2092. // Check free space on the drive.
  2093. //
  2094. if(!_dos_getdiskfree(d,&DiskSpace)) {
  2095. SpaceAvailable = (ULONG)DiskSpace.avail_clusters
  2096. * (ULONG)DiskSpace.sectors_per_cluster
  2097. * (ULONG)DiskSpace.bytes_per_sector;
  2098. ClusterSize = (ULONG)DiskSpace.sectors_per_cluster *
  2099. (ULONG)DiskSpace.bytes_per_sector;
  2100. SpaceRequired = 0;
  2101. if( CheckLocalSource ) {
  2102. for( i = 0;
  2103. i < sizeof( SpaceRequirements ) / sizeof( SPACE_REQUIREMENT );
  2104. i++ ) {
  2105. if( SpaceRequirements[i].ClusterSize == (unsigned)ClusterSize ) {
  2106. #if NEC_98
  2107. SpaceRequired += (SpaceRequirements[i].Clusters * ClusterSize + 3L * FLOPPY_SIZE);
  2108. #else
  2109. SpaceRequired += (SpaceRequirements[i].Clusters * ClusterSize);
  2110. #endif
  2111. break;
  2112. }
  2113. }
  2114. }
  2115. if( CheckBootFiles ) {
  2116. CHAR TmpBuffer[32];
  2117. PCHAR p;
  2118. sprintf( TmpBuffer, "TempDirSpace%uK", ClusterSize );
  2119. if( p = DnGetSectionKeyIndex( DngInfHandle,
  2120. DnfSpaceRequirements,
  2121. TmpBuffer,
  2122. 1 ) ) {
  2123. SpaceRequired += (ULONG)atol(p);
  2124. FREE (p);
  2125. } else {
  2126. // We missed. Fudge...
  2127. ULONG FudgeSpace = 7;
  2128. FudgeSpace *= 1024;
  2129. FudgeSpace *= 1024;
  2130. SpaceRequired += FudgeSpace;
  2131. }
  2132. }
  2133. return( (BOOLEAN)(SpaceAvailable >= SpaceRequired) );
  2134. }
  2135. }
  2136. return(FALSE);
  2137. }
  2138. #if 0
  2139. BOOLEAN
  2140. DnpConstructLocalSourceList(
  2141. OUT PCHAR DriveList
  2142. )
  2143. /*++
  2144. Routine Description:
  2145. Construct a list of drives that are valid for use as a local source.
  2146. To be valid a drive must be extant, non-removable, local, and have
  2147. enough free space on it.
  2148. The 'list' is a string with a character for each valid drive, terminated
  2149. by a nul character, ie,
  2150. CDE0
  2151. Arguments:
  2152. DriveList - receives the string in the above format.
  2153. Return Value:
  2154. FALSE if no valid drives were found. TRUE if at least one was.
  2155. --*/
  2156. {
  2157. PCHAR p = DriveList;
  2158. BOOLEAN b = FALSE;
  2159. CHAR Drive;
  2160. #if NEC_98
  2161. for(Drive='A'; Drive<='Z'; Drive++) {
  2162. #else // NEC_98
  2163. for(Drive='C'; Drive<='Z'; Drive++) {
  2164. #endif // NEC_98
  2165. if(DnpIsValidLocalSource(Drive)) {
  2166. *p++ = Drive;
  2167. b = TRUE;
  2168. }
  2169. }
  2170. *p = 0;
  2171. return(b);
  2172. }
  2173. #endif
  2174. #ifdef LOGGING
  2175. // FILE *_LogFile;
  2176. BOOLEAN LogEnabled = FALSE;
  2177. VOID
  2178. StartLog(
  2179. VOID
  2180. )
  2181. {
  2182. LogEnabled = TRUE;
  2183. }
  2184. #if 0
  2185. VOID
  2186. EndLog(
  2187. VOID
  2188. )
  2189. {
  2190. if(_LogFile) {
  2191. fclose(_LogFile);
  2192. _LogFile = NULL;
  2193. }
  2194. }
  2195. #endif
  2196. VOID
  2197. __LOG(
  2198. IN PCHAR FormatString,
  2199. ...
  2200. )
  2201. {
  2202. FILE *LogFile;
  2203. va_list arglist;
  2204. if(LogEnabled) {
  2205. LogFile = fopen("c:\\$winnt.log","at");
  2206. va_start(arglist,FormatString);
  2207. vfprintf(LogFile,FormatString,arglist);
  2208. va_end(arglist);
  2209. fclose(LogFile);
  2210. }
  2211. }
  2212. #endif // def LOGGING
  2213. ULONG
  2214. DnGetMinimumRequiredSpace(
  2215. IN CHAR DriveLetter
  2216. )
  2217. /*++
  2218. Routine Description:
  2219. Determine the minimum required free space for the local source, on a
  2220. particular drive.
  2221. Arguments:
  2222. DriveLetter - Indicates the letter of a particular drive.
  2223. Return Value:
  2224. Returns the minimum required space on the specified drive.
  2225. --*/
  2226. {
  2227. struct diskfree_t DiskFree;
  2228. unsigned ClusterSize;
  2229. unsigned i;
  2230. _dos_getdiskfree(toupper(DriveLetter)-'A'+1,&DiskFree);
  2231. ClusterSize = DiskFree.sectors_per_cluster * DiskFree.bytes_per_sector;
  2232. for( i = 0;
  2233. i < sizeof( SpaceRequirements ) / sizeof( SPACE_REQUIREMENT );
  2234. i++ ) {
  2235. if( ClusterSize == SpaceRequirements[i].ClusterSize ) {
  2236. return( ClusterSize * SpaceRequirements[i].Clusters );
  2237. }
  2238. }
  2239. //
  2240. // Return the size assuming 16k cluster
  2241. //
  2242. return ( SpaceRequirements[5].ClusterSize * SpaceRequirements[5].Clusters );
  2243. }
  2244. #if NEC_98
  2245. VOID
  2246. DummyRoutine(
  2247. VOID
  2248. )
  2249. /*++
  2250. This Founction is Dummy Routine.(CTRL + C Signal Hook Routine)
  2251. --*/
  2252. {
  2253. //
  2254. // It's Dummy Statement
  2255. //
  2256. while(TRUE){
  2257. break;
  2258. }
  2259. }
  2260. VOID
  2261. SearchFirstFDD(VOID)
  2262. {
  2263. UCHAR index;
  2264. UCHAR ReadPoint = 0;
  2265. UCHAR ReadCount = 1;
  2266. //
  2267. // Setting Read Data position.
  2268. //
  2269. if(SupportDos) {
  2270. ReadPoint = 27;
  2271. ReadCount = 2;
  2272. }
  2273. //
  2274. // Search First FDD.
  2275. //
  2276. FirstFD = 0;
  2277. for(index=0; index < 26; index++) {
  2278. if(LPTable[ReadPoint+index*ReadCount] == 0x90){
  2279. FirstFD = index + 1;
  2280. break;
  2281. }
  2282. }
  2283. if(FirstFD == 0) { DnFatalError(&DnsRequiresFloppy); }
  2284. return;
  2285. }
  2286. VOID
  2287. CheckTargetDrive(VOID)
  2288. {
  2289. UCHAR Pattern[127];
  2290. UCHAR TempBuf[1000];
  2291. UCHAR Current_Drv[3];
  2292. UCHAR chDeviceName[127];
  2293. UCHAR TargetPass[127];
  2294. CHAR Target_Drv[] = "?:\0";
  2295. unsigned line;
  2296. ULONG ValidKey[2];
  2297. ULONG c;
  2298. PCHAR FileName;
  2299. FILE *fileHandle;
  2300. BOOLEAN ExistNt = TRUE; // For Back up Directry Flag
  2301. ValidKey[0] = DN_KEY_F3;
  2302. ValidKey[1] = 0;
  2303. //
  2304. // C Drive(Current drive number)
  2305. //
  2306. sprintf(Current_Drv,"%c\0",DngTargetDriveLetter);
  2307. sprintf(TempBuf,DnsNtBootSect.Strings[2] ,Current_Drv);
  2308. strcpy(DnsNtBootSect.Strings[2] ,TempBuf);
  2309. Target_Drv[0] = DngTargetDriveLetter;
  2310. if(BootDiskInfo[0].DiskSector == (USHORT)256) {
  2311. DnClearClientArea();
  2312. DnDisplayScreen(&FormatError);
  2313. DnWriteStatusText("%s",DntF3EqualsExit);
  2314. while(1) {
  2315. c = DnGetValidKey(ValidKey);
  2316. if(c == DN_KEY_F3) {
  2317. FREE(BootDiskInfo);
  2318. DnExitDialog();
  2319. }
  2320. }
  2321. }
  2322. if(DngFloppyless) {
  2323. //
  2324. // Clear $WIN_NT$.~BT
  2325. //
  2326. chDeviceName[0] = (UCHAR)DngTargetDriveLetter;
  2327. chDeviceName[1] = (UCHAR)(':');
  2328. strcpy(chDeviceName+2,FLOPPYLESS_BOOT_ROOT);
  2329. if(access(chDeviceName,00) == 0) {
  2330. strcpy(Pattern,chDeviceName);
  2331. DnDelnode(Pattern);
  2332. remove(Pattern);
  2333. }
  2334. //
  2335. // Clear $WIN_NT$.~BU
  2336. //
  2337. memset(chDeviceName,0,sizeof(chDeviceName));
  2338. chDeviceName[0] = (UCHAR)DngTargetDriveLetter;
  2339. chDeviceName[1] = (UCHAR)(':');
  2340. strcpy(chDeviceName+2,"\\$WIN_NT$.~BU");
  2341. if(access(chDeviceName,00) == 0) {
  2342. //
  2343. // copy : \$WIN_NT$.~BU -> root directry
  2344. //
  2345. DnCopyFilesInSectionForFDless(DnfBackupFiles_PC98,chDeviceName,Target_Drv);
  2346. strcpy(Pattern,chDeviceName);
  2347. DnDelnode(Pattern);
  2348. remove(Pattern);
  2349. }
  2350. //
  2351. // Check Root Directry Files.
  2352. //
  2353. line = 0;
  2354. while(FileName = DnGetSectionLineIndex(DngInfHandle,DnfBackupFiles_PC98,line++,0)) {
  2355. memset(chDeviceName,0,sizeof(chDeviceName));
  2356. chDeviceName[0] = (UCHAR)DngTargetDriveLetter;
  2357. chDeviceName[1] = (UCHAR)(':');
  2358. chDeviceName[2] = (UCHAR)('\\');
  2359. strcpy(chDeviceName+3,FileName);
  2360. _dos_setfileattr(chDeviceName,_A_NORMAL);
  2361. if(fileHandle = fopen(chDeviceName,"r")) {
  2362. fclose(fileHandle);
  2363. } else {
  2364. ExistNt = FALSE;
  2365. FREE (FileName);
  2366. break;
  2367. }
  2368. FREE (FileName);
  2369. }
  2370. //
  2371. // Create $WIN_NT$.~BU
  2372. //
  2373. if(ExistNt) {
  2374. memset(chDeviceName,0,sizeof(chDeviceName));
  2375. sprintf(chDeviceName,"%c:\\$WIN_NT$.~BU",(UCHAR)DngTargetDriveLetter);
  2376. mkdir(chDeviceName);
  2377. //
  2378. // copy : root directry -> \$WIN_NT$.~BU
  2379. //
  2380. DnCopyFilesInSectionForFDless(DnfBackupFiles_PC98,Target_Drv,chDeviceName);
  2381. //
  2382. // Set files Attribute.
  2383. //
  2384. line = 0;
  2385. while(FileName = DnGetSectionLineIndex(DngInfHandle,DnfBackupFiles_PC98,line++,0)) {
  2386. memset(TargetPass,0,sizeof(TargetPass));
  2387. sprintf(TargetPass,"%c:\\$WIN_NT$.~BU\\",(UCHAR)DngTargetDriveLetter);
  2388. strcpy(TargetPass+16,FileName);
  2389. _dos_setfileattr(TargetPass,
  2390. _A_ARCH | _A_HIDDEN | _A_RDONLY | _A_SYSTEM
  2391. );
  2392. FREE (FileName);
  2393. }
  2394. }
  2395. }
  2396. }
  2397. VOID
  2398. GetLPTable(
  2399. IN PCHAR pLPTable
  2400. )
  2401. /*
  2402. Get LPTable in the Dos system.
  2403. */
  2404. {
  2405. _asm{
  2406. push ax
  2407. push bx
  2408. push cx
  2409. push dx
  2410. push ds
  2411. mov cx,13h
  2412. push si
  2413. lds si,pLPTable
  2414. mov dx,si
  2415. pop si
  2416. int 0dch
  2417. pop ds
  2418. pop dx
  2419. pop cx
  2420. pop bx
  2421. pop ax
  2422. }
  2423. }
  2424. VOID
  2425. ClearBootFlag(
  2426. VOID
  2427. )
  2428. {
  2429. USHORT SectorSize;
  2430. PSHORT pReadBuffer;
  2431. UCHAR CNT;
  2432. (PUCHAR)DiskDAUA = MALLOC(sizeof(CONNECTDAUA)*12,TRUE);
  2433. for(CNT = 0; CNT < 12; CNT++) {
  2434. DiskDAUA[CNT].DA_UA = (UCHAR)0x00;
  2435. }
  2436. //
  2437. // Get boot device number.
  2438. //
  2439. GetDaUa();
  2440. for(CNT=0;DiskDAUA[CNT].DA_UA != 0;CNT++) {
  2441. //
  2442. // Get Device sector size.
  2443. //
  2444. SectorSize = GetSectorValue(DiskDAUA[CNT].DA_UA);
  2445. if(SectorSize == 0) {
  2446. continue;
  2447. }
  2448. pReadBuffer = (PSHORT)MALLOC(SectorSize*2,TRUE);
  2449. DiskSectorReadWrite(SectorSize,
  2450. DiskDAUA[CNT].DA_UA,
  2451. TRUE,
  2452. pReadBuffer
  2453. );
  2454. pReadBuffer[(SectorSize-6)/2] = 0x0000;
  2455. DiskSectorReadWrite(SectorSize,
  2456. DiskDAUA[CNT].DA_UA,
  2457. FALSE,
  2458. pReadBuffer
  2459. );
  2460. FREE(pReadBuffer);
  2461. }
  2462. FREE(DiskDAUA);
  2463. }
  2464. VOID
  2465. BootPartitionData(
  2466. VOID
  2467. )
  2468. /*
  2469. Setting Boot Drive Infomation for BootDiskInfo.
  2470. */
  2471. {
  2472. UCHAR ActivePartition;
  2473. PSHORT ReadBuffers;
  2474. UCHAR SystemID;
  2475. UCHAR BootPartitionNo,CheckDosNo;
  2476. UCHAR CNT;
  2477. UCHAR ReadPoint = 0;
  2478. UCHAR ReadCount = 1;
  2479. UCHAR EndRoop = 16;
  2480. //
  2481. // Setting Read Data position.
  2482. //
  2483. if(SupportDos) {
  2484. ReadPoint = 27;
  2485. ReadCount = 2;
  2486. EndRoop = 52;
  2487. }
  2488. //
  2489. // Set Boot Device DA_UA Data value.
  2490. //
  2491. BootDiskInfo[0].DA_UA = LPTable[ReadPoint+(toupper(DngTargetDriveLetter) - 0x41)*ReadCount];
  2492. //
  2493. // Set Boot Device Sector Size.
  2494. //
  2495. BootDiskInfo[0].DiskSector = GetSectorValue(BootDiskInfo[0].DA_UA);
  2496. //
  2497. // Set Boot Drive Disk Partition Position.
  2498. //
  2499. for(CNT=ActivePartition=0;(LPTable[ReadPoint+CNT] != 0) && (CNT < EndRoop); CNT+=ReadCount) {
  2500. if(CNT > (UCHAR)(toupper(DngTargetDriveLetter)-0x41)*ReadCount)
  2501. { break; }
  2502. if((UCHAR)LPTable[ReadPoint+CNT] == BootDiskInfo[0].DA_UA) {
  2503. ActivePartition++;
  2504. }
  2505. }
  2506. ReadBuffers = (PSHORT)MALLOC(BootDiskInfo[0].DiskSector*2,TRUE);
  2507. DiskSectorReadWrite(BootDiskInfo[0].DiskSector,
  2508. BootDiskInfo[0].DA_UA,
  2509. TRUE,
  2510. ReadBuffers
  2511. );
  2512. BootPartitionNo = CheckDosNo =0;
  2513. for(CNT=0; (CNT < 16) && (ActivePartition > CheckDosNo); CNT++) {
  2514. SystemID = *((PCHAR)ReadBuffers+(BootDiskInfo[0].DiskSector+1+32*CNT));
  2515. if( (SystemID == 0x81) || // FAT12
  2516. (SystemID == 0x91) || // FAT16
  2517. (SystemID == 0xe1) || // FAT32
  2518. ((SystemID == 0xa1) && // Large partition
  2519. SupportDos))
  2520. {
  2521. CheckDosNo++;
  2522. }
  2523. BootPartitionNo++;
  2524. }
  2525. TargetDA_UA = BootDiskInfo[0].DA_UA;
  2526. Cylinders =(USHORT)*(ReadBuffers+((BootDiskInfo[0].DiskSector+10+32*(CNT-1))/2));
  2527. FREE(ReadBuffers);
  2528. BootDiskInfo[0].PartitionPosition = (UCHAR)(BootPartitionNo - 1);
  2529. }
  2530. VOID
  2531. SetAutoReboot(
  2532. VOID
  2533. )
  2534. /*++
  2535. Set Auto Reboot Flag.
  2536. --*/
  2537. {
  2538. PSHORT pReadBuffer;
  2539. pReadBuffer = (PSHORT)MALLOC(BootDiskInfo[0].DiskSector*2,TRUE);
  2540. DiskSectorReadWrite(BootDiskInfo[0].DiskSector,
  2541. BootDiskInfo[0].DA_UA,
  2542. TRUE,
  2543. pReadBuffer
  2544. );
  2545. (UCHAR)*((PCHAR)pReadBuffer+BootDiskInfo[0].DiskSector-6) = 0x80;
  2546. *((PCHAR)pReadBuffer+BootDiskInfo[0].DiskSector-5) = BootDiskInfo[0].PartitionPosition;
  2547. *((PCHAR)pReadBuffer+BootDiskInfo[0].DiskSector+32 *
  2548. BootDiskInfo[0].PartitionPosition) |= 0x80;
  2549. DiskSectorReadWrite(BootDiskInfo[0].DiskSector,
  2550. BootDiskInfo[0].DA_UA,
  2551. FALSE,
  2552. pReadBuffer
  2553. );
  2554. FREE(pReadBuffer);
  2555. }
  2556. BOOLEAN
  2557. CheckBootDosVersion(
  2558. IN UCHAR SupportDosVersion
  2559. )
  2560. /*
  2561. Get Dos Version.
  2562. */
  2563. {
  2564. union REGS inregs,outregs;
  2565. int AXValue;
  2566. inregs.x.ax = (unsigned int)0;
  2567. inregs.x.bx = (unsigned int)0;
  2568. inregs.x.cx = (unsigned int)0;
  2569. inregs.x.dx = (unsigned int)0;
  2570. outregs.x.ax = (unsigned int)0;
  2571. outregs.x.bx = (unsigned int)0;
  2572. outregs.x.cx = (unsigned int)0;
  2573. outregs.x.dx = (unsigned int)0;
  2574. inregs.h.ah = (UCHAR)0x30;
  2575. AXValue = 0;
  2576. AXValue = intdos(&inregs,&outregs);
  2577. AXValue &= 0x00ff;
  2578. if(SupportDosVersion > (UCHAR)AXValue) {
  2579. return(FALSE);
  2580. } else {
  2581. return(TRUE);
  2582. }
  2583. }
  2584. USHORT
  2585. GetSectorValue(
  2586. IN UCHAR CheckDA_UA
  2587. )
  2588. /*++
  2589. Get Sector Value.
  2590. --*/
  2591. {
  2592. USHORT PhysicalSectorSize;
  2593. UCHAR ErrFlg;
  2594. _asm{
  2595. push ax
  2596. push bx
  2597. push cx
  2598. push dx
  2599. mov ah,84h
  2600. mov al,CheckDA_UA
  2601. int 1bh
  2602. mov PhysicalSectorSize,bx
  2603. cmp ah,00h
  2604. je break0
  2605. and ax,0f000h
  2606. cmp ax,0000h
  2607. je break0
  2608. mov ErrFlg,01h
  2609. jmp break1
  2610. break0:
  2611. mov ErrFlg,00h
  2612. break1:
  2613. pop dx
  2614. pop cx
  2615. pop bx
  2616. pop ax
  2617. }
  2618. if(ErrFlg == 0) {
  2619. return(PhysicalSectorSize);
  2620. } else {
  2621. return((USHORT)0);
  2622. }
  2623. }
  2624. BOOLEAN
  2625. DiskSectorReadWrite(
  2626. IN USHORT HDSector,
  2627. IN UCHAR ReadWriteDA_UA,
  2628. IN BOOLEAN ReadFlag,
  2629. IN PSHORT OrigReadBuffer
  2630. )
  2631. {
  2632. UCHAR ahreg = 0x06;
  2633. UCHAR ErrorFlag;
  2634. USHORT ReadSectorSize;
  2635. BOOLEAN HDStatus = TRUE;
  2636. UCHAR far *pTmp;
  2637. ULONG pAddr;
  2638. PSHORT ReadBuffer, p;
  2639. ReadSectorSize = HDSector * 2;
  2640. //
  2641. // INT 1BH does not allow the buffer that beyond 64KB boundary.
  2642. // So we must prepare particular buffer for INT 1BH. Once allocate
  2643. // double size buffer and use half of them that does not on
  2644. // boundary.
  2645. //
  2646. p = MALLOC(ReadSectorSize * 2, TRUE);
  2647. pTmp = (UCHAR far *)p;
  2648. pAddr = (FP_SEG(pTmp)<<4 + FP_OFF(pTmp) & 0xffff);
  2649. //
  2650. // Check half part of buffer is on 64KB boundary.
  2651. //
  2652. if (pAddr > ((pAddr + ReadSectorSize) & 0xffff)){
  2653. ReadBuffer = p + ReadSectorSize; // Use last half part.
  2654. } else {
  2655. ReadBuffer = p; // Use first half part.
  2656. }
  2657. if(!ReadFlag) {
  2658. ahreg = 0x05;
  2659. memcpy(ReadBuffer, OrigReadBuffer, ReadSectorSize);
  2660. }
  2661. _asm{
  2662. push ax
  2663. push bx
  2664. push cx
  2665. push dx
  2666. push es
  2667. push di
  2668. ;
  2669. ; If we're running under Chicago, and we're going to be
  2670. ; writing, then we have to lock the volume before attempting
  2671. ; absolute disk I/O
  2672. ;
  2673. cmp ReadFlag,1 ; are we reading?
  2674. jae locked ; if so, skip locking step
  2675. ;
  2676. ; Make sure were running under Chicago.
  2677. ;
  2678. mov ah,30h
  2679. int 21h
  2680. cmp al,7h
  2681. jb locked ; not Chicago
  2682. ;
  2683. ; We're sure we're under Chicago, so issue new
  2684. ; Lock Logical Volume IOCTL
  2685. ;
  2686. mov ax,440dh
  2687. mov bh,1 ; level 1 lock
  2688. mov bl,ReadWriteDA_UA ; fetch drive to lock
  2689. mov cx,084bh ; Lock Logical Volume for disk category
  2690. mov dx,1 ; set permission to allow reads and writes
  2691. int 21h
  2692. ;jc locked ; ignore failure - any errors are caught below
  2693. ;mov word ptr [bp-12],1 ; we successfully locked, so we must unlock
  2694. locked:
  2695. mov bx,ReadSectorSize
  2696. mov cx,0000h
  2697. mov dx,0000h
  2698. mov ax,0000h
  2699. mov ah,ahreg
  2700. mov al,ReadWriteDA_UA
  2701. push bp
  2702. push es
  2703. push ds
  2704. pop es
  2705. les di,ReadBuffer
  2706. mov bp,di
  2707. int 1bh
  2708. pop es
  2709. pop bp
  2710. jnc warp0 ;No error
  2711. cmp ah,00h
  2712. je warp0
  2713. add ax,0f000h
  2714. cmp ax,0000h
  2715. je warp0
  2716. mov ErrorFlag,01h
  2717. jmp warp1
  2718. warp0:
  2719. mov ErrorFlag,00h
  2720. warp1:
  2721. ;unlock?
  2722. cmp ReadFlag,1 ; do we need to unlock?
  2723. jae done ; if not, then done.
  2724. mov ax,440dh
  2725. mov bl,ReadWriteDA_UA ; fetch drive to lock
  2726. ;mov bh,0
  2727. ;inc bl ; (this IOCTL uses 1-based drive numbers)
  2728. mov cx,086bh ; Unlock Logical Volume for disk category
  2729. mov dx,0
  2730. int 21h ; ignore error (hope it never happens)
  2731. done:
  2732. pop di
  2733. pop es
  2734. pop dx
  2735. pop cx
  2736. pop bx
  2737. pop ax
  2738. }
  2739. if(ReadFlag) {
  2740. memcpy(OrigReadBuffer, ReadBuffer, ReadSectorSize);
  2741. }
  2742. FREE(p);
  2743. if(ErrorFlag != 0) {
  2744. HDStatus = FALSE;
  2745. }
  2746. return(HDStatus);
  2747. }
  2748. VOID
  2749. GetDaUa(VOID)
  2750. {
  2751. UCHAR count, i = 0;
  2752. UCHAR far *ConnectEquip;
  2753. UCHAR ConnectDevice;
  2754. //
  2755. // IDE/SASI Disk Check Routine
  2756. //
  2757. MAKE_FP(ConnectEquip,(USHORT)0x55d);
  2758. ConnectDevice = *ConnectEquip;
  2759. for(count=0;count < 4;count++) {
  2760. if(ConnectDevice & (1 << count)) {
  2761. DiskDAUA[i].DA_UA = (UCHAR)(0x80 + count);
  2762. i++;
  2763. }
  2764. }
  2765. //
  2766. // SCSI Disk Check Routine
  2767. //
  2768. MAKE_FP(ConnectEquip,(USHORT)0x482);
  2769. ConnectDevice = *ConnectEquip;
  2770. for(count=0;count < 7;count++) {
  2771. if(ConnectDevice & (1 << count)) {
  2772. DiskDAUA[i].DA_UA = (UCHAR)(0xa0 + count);
  2773. i++;
  2774. }
  2775. }
  2776. }
  2777. #endif // NEC_98