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.

205 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. main.c
  5. Abstract:
  6. Implements a small utility that fills the disk for purposes of free space
  7. testing.
  8. Author:
  9. Jim Schmidt (jimschm) 18-Aug-2000
  10. Revision History:
  11. <full name> (<alias>) <date> <comments>
  12. --*/
  13. #include "pch.h"
  14. #include "wininet.h"
  15. #include <lm.h>
  16. HANDLE g_hHeap;
  17. HINSTANCE g_hInst;
  18. BOOL
  19. Init (
  20. VOID
  21. )
  22. {
  23. g_hHeap = GetProcessHeap();
  24. g_hInst = GetModuleHandle (NULL);
  25. UtInitialize (NULL);
  26. return TRUE;
  27. }
  28. VOID
  29. Terminate (
  30. VOID
  31. )
  32. {
  33. UtTerminate ();
  34. }
  35. VOID
  36. HelpAndExit (
  37. VOID
  38. )
  39. {
  40. //
  41. // This routine is called whenever command line args are wrong
  42. //
  43. fprintf (
  44. stderr,
  45. "Command Line Syntax:\n\n"
  46. " filler <free_space> [/D:<drive>] [/C:<cmdline> [/M]]\n"
  47. " filler /Q [/D:<drive>]\n"
  48. "\nDescription:\n\n"
  49. " filler creates a file (bigfile.dat) on the current or specified\n"
  50. " drive, leaving only the specified amount of free space on the drive.\n"
  51. "\nArguments:\n\n"
  52. " free_space Specifies the amount of free space to leave on\n"
  53. " disk.\n"
  54. " /D Specifies the drive letter to fill (i.e. /D:C)\n"
  55. " /Q Queries the free space on the disk\n"
  56. " /C Executes command line specified in <cmdline>\n"
  57. " /M Issue message box if command line alters disk space\n"
  58. );
  59. exit (1);
  60. }
  61. INT
  62. __cdecl
  63. _tmain (
  64. INT argc,
  65. PCTSTR argv[]
  66. )
  67. {
  68. TCHAR curDir[MAX_PATH];
  69. TCHAR curFileS[MAX_PATH];
  70. TCHAR curFileD[MAX_PATH];
  71. PCTSTR cmdLine = NULL;
  72. PCTSTR cmdPtr = NULL;
  73. TCHAR newCmdLine[MAX_PATH];
  74. GetCurrentDirectory (ARRAYSIZE(curDir), curDir);
  75. cmdLine = GetCommandLine ();
  76. if (!cmdLine) {
  77. _tprintf ("Error while getting the command line.\n");
  78. exit (-1);
  79. }
  80. cmdPtr = _tcsstr (cmdLine, TEXT("scanstate"));
  81. if (!cmdPtr) {
  82. _tprintf ("Error while getting the command line.\n");
  83. exit (-1);
  84. }
  85. StringCopyAB (newCmdLine, cmdLine, cmdPtr);
  86. StringCat (newCmdLine, TEXT("scanstate_a.exe"));
  87. cmdPtr = _tcschr (cmdPtr, TEXT(' '));
  88. if (!cmdPtr) {
  89. _tprintf ("Error while getting the command line.\n");
  90. exit (-1);
  91. }
  92. StringCat (newCmdLine, cmdPtr);
  93. //
  94. // Begin processing
  95. //
  96. if (!Init()) {
  97. exit (-1);
  98. }
  99. //
  100. // Do work here
  101. //
  102. {
  103. BOOL result = FALSE;
  104. STARTUPINFO startupInfo;
  105. PROCESS_INFORMATION processInformation;
  106. DWORD exitCode = -1;
  107. StringCopy (curFileS, curDir);
  108. StringCopy (AppendWack (curFileS), TEXT("guitrn_a.dll"));
  109. StringCopy (curFileD, curDir);
  110. StringCopy (AppendWack (curFileD), TEXT("guitrn.dll"));
  111. CopyFile (curFileS, curFileD, FALSE);
  112. StringCopy (curFileS, curDir);
  113. StringCopy (AppendWack (curFileS), TEXT("unctrn_a.dll"));
  114. StringCopy (curFileD, curDir);
  115. StringCopy (AppendWack (curFileD), TEXT("unctrn.dll"));
  116. CopyFile (curFileS, curFileD, FALSE);
  117. StringCopy (curFileS, curDir);
  118. StringCopy (AppendWack (curFileS), TEXT("script_a.dll"));
  119. StringCopy (curFileD, curDir);
  120. StringCopy (AppendWack (curFileD), TEXT("script.dll"));
  121. CopyFile (curFileS, curFileD, FALSE);
  122. StringCopy (curFileS, curDir);
  123. StringCopy (AppendWack (curFileS), TEXT("sysmod_a.dll"));
  124. StringCopy (curFileD, curDir);
  125. StringCopy (AppendWack (curFileD), TEXT("sysmod.dll"));
  126. CopyFile (curFileS, curFileD, FALSE);
  127. StringCopy (curFileS, curDir);
  128. StringCopy (AppendWack (curFileS), TEXT("migism_a.dll"));
  129. StringCopy (curFileD, curDir);
  130. StringCopy (AppendWack (curFileD), TEXT("migism.dll"));
  131. CopyFile (curFileS, curFileD, FALSE);
  132. ZeroMemory (&startupInfo, sizeof (STARTUPINFO));
  133. startupInfo.cb = sizeof (STARTUPINFO);
  134. ZeroMemory (&processInformation, sizeof (PROCESS_INFORMATION));
  135. result = CreateProcess (
  136. NULL,
  137. newCmdLine,
  138. NULL,
  139. NULL,
  140. FALSE,
  141. 0,
  142. NULL,
  143. NULL,
  144. &startupInfo,
  145. &processInformation
  146. );
  147. if (result && processInformation.hProcess && (processInformation.hProcess != INVALID_HANDLE_VALUE)) {
  148. WaitForSingleObject (processInformation.hProcess, INFINITE);
  149. if (!GetExitCodeProcess (processInformation.hProcess, &exitCode)) {
  150. exitCode = -1;
  151. }
  152. exit (exitCode);
  153. }
  154. }
  155. //
  156. // End of processing
  157. //
  158. Terminate();
  159. return 0;
  160. }