Windows NT 4.0 source code leak
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.

218 lines
5.0 KiB

4 years ago
  1. /*****************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990 **/
  4. /*****************************************************************/
  5. /*** MAIN.C - Main entrypoint for DAMAGE
  6. *
  7. * This program is a graphic-oriented utility to display and change
  8. * file system structures. It is called "damage" because its primary
  9. * use will be to corrupt file system structures to test CHKDSK's
  10. * recovery skills. It has an option to disallow changes, though,
  11. * so that it can be used purely informationally.
  12. *
  13. * Modification history:
  14. * G.A. Jones 09/07/88 Original for Pinball testing.
  15. * G.A. Jones 09/08/88 Added get_object call.
  16. * G.A. Jones 09/13/88 Added pathname buffer.
  17. * G.A. Jones 09/19/88 Bug in parse_args - /D not recognized.
  18. * G.A. Jones 09/20/88 Message fixes.
  19. * G.A. Jones 09/21/88 Added hotfix support.
  20. * S. Hern 02/06/89 Added ability to to dump the SB_CDDAT
  21. * as a time.h-format asciiz string (/t)
  22. * S. Hern 04/20/89 Allow switching for redirected input
  23. * davidbro 04/20/89 changed /r redirection behavior
  24. * S. Hern 04/25/89 changed /r redirection behavior (see
  25. * usage code)
  26. * davidbro 05/21/89 added code to mark bad sectors on exit
  27. * davidbro 05/22/89 added /l: switch support
  28. */
  29. #include <stdio.h>
  30. #include <string.h>
  31. #include <direct.h>
  32. #include <process.h>
  33. #include "defs.h"
  34. #include "types.h"
  35. #include "globals.h"
  36. static USHORT dump_sb_cddat = 0;
  37. /*** error_msg - display error message
  38. *
  39. * This function is called to display a message to the standard
  40. * error device.
  41. *
  42. * error_msg (str)
  43. *
  44. * ENTRY str - pointer to message
  45. *
  46. * EXIT No return value
  47. *
  48. * CALLS fprintf
  49. * fflush
  50. */
  51. void error_msg (str)
  52. UCHAR *str;
  53. {
  54. fprintf (stderr, "%s\n", str); /* display the message to the error handle */
  55. fflush (stderr); /* flush the buffer to the console */
  56. }
  57. /*** exit_error - print informative message and exit
  58. *
  59. * exit_error (code)
  60. *
  61. * ENTRY code - error code number, defined in DEFS.H
  62. *
  63. * CALLS exit
  64. * error_msg
  65. * close_disk
  66. *
  67. * EFFECTS Deallocates memory
  68. * Unlocks and closes disk
  69. * Exits program
  70. *
  71. * WARNINGS Does not return
  72. */
  73. void exit_error (USHORT code)
  74. {
  75. UCHAR scratchbuf [80];
  76. #ifdef TRACE
  77. fprintf (stderr, "exit_error (%d)\n", code);
  78. fflush (stderr);
  79. #endif
  80. if (code <= MAX_ERROR_CODE)
  81. error_msg (error_messages [code]); /* display appropriate message */
  82. else {
  83. sprintf (scratchbuf, unknown_error_str, code);
  84. error_msg ((UCHAR *)scratchbuf); /* display "unknown code" message */
  85. }
  86. close_disk (); /* unlock disk, close our handle */
  87. exit (code);
  88. }
  89. void usage ()
  90. {
  91. printf (version_str);
  92. printf (timestamp_str, __DATE__, __TIME__);
  93. printf ("Usage: DAMAGE [d:] [/D]\n");
  94. printf (" d: - Pinball drive to access\n");
  95. printf (" /D - Allow changes\n");
  96. printf (" /R - Redirect input\n");
  97. printf (" /R:<filename> - Replay keystrokes from <filename>\n");
  98. printf (" /K:<filename> - Save keystrokes to <filename>\n");
  99. printf (" /L:<filename> - Log command output file\n");
  100. exit (1);
  101. }
  102. void parse_args (argc, argv)
  103. USHORT argc;
  104. UCHAR *argv [];
  105. {
  106. UCHAR *p;
  107. USHORT i;
  108. _getcwd (disk_name, 80);
  109. if (argc < 2)
  110. usage ();
  111. for (i=1; i<argc; i++) {
  112. p=_strlwr (argv [i]);
  113. if (p [1] == ':')
  114. strcpy (disk_name, p);
  115. else if (!strcmp (p, "/d"))
  116. change = 1;
  117. else if (!strcmp (p, "/t"))
  118. dump_sb_cddat = 1;
  119. else if (!strncmp (p, "/k:", 3))
  120. szKeySave = &(argv[i][3]);
  121. else if (!strcmp (p, "/r"))
  122. redirect_input = 1;
  123. else if (!strncmp (p, "/r:", 3))
  124. szKeyReplay = &(argv[i][3]);
  125. else if (!strncmp (p, "/l:", 3))
  126. szLogFile = &(argv[i][3]);
  127. else if (!strncmp (p, "/unsafe", 7 ))
  128. fUnsafe = TRUE;
  129. else
  130. usage ();
  131. }
  132. }
  133. int _CRTAPI1
  134. main (argc, argv)
  135. USHORT argc;
  136. UCHAR *argv [];
  137. {
  138. parse_args (argc, argv);
  139. if (!dump_sb_cddat) {
  140. printf (version_str);
  141. printf (timestamp_str, __DATE__, __TIME__);
  142. }
  143. if (szKeySave != NULL) {
  144. fpSave = fopen(szKeySave, "w");
  145. if (fpSave == NULL)
  146. exit_error(SAVE_ERROR);
  147. }
  148. if (szKeyReplay != NULL) {
  149. fpReplay = fopen(szKeyReplay, "r");
  150. if (fpReplay == NULL)
  151. exit_error(REPLAY_ERROR);
  152. }
  153. if (szLogFile != NULL) {
  154. fpLog = fopen(szLogFile, "a");
  155. if (fpLog == NULL) {
  156. exit_error(LOG_ERROR);
  157. }
  158. }
  159. if (!open_disk (disk_name, change)) {
  160. exit_error (OPEN_ERROR);
  161. }
  162. currobj.sec = SEC_SUPERB;
  163. currobj.len = 2L;
  164. currobj.mem = NULL;
  165. get_object ();
  166. hfmax = ((struct SuperSpare *)currobj.mem)->spb.SPB_HFMAX;
  167. memset (curpath, '\0', 1024);
  168. if (dump_sb_cddat)
  169. printf ("%s",
  170. get_time (((struct SuperSpare *)currobj.mem)->sb.SB_CDDAT));
  171. else
  172. display ();
  173. close_disk ();
  174. if (szKeySave != NULL)
  175. fclose(fpSave);
  176. if (szKeyReplay != NULL)
  177. fclose(fpReplay);
  178. if (szLogFile != NULL)
  179. fclose(fpLog);
  180. exit (0);
  181. }