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.

391 lines
8.2 KiB

  1. #include "brian.h"
  2. //
  3. // Global variables
  4. //
  5. BUFFER_ELEMENT Buffers[MAX_BUFFERS];
  6. HANDLE BufferEvent = NULL;
  7. //
  8. // Control if debug prints go to the debug screen or the console. By
  9. // default they go to the debug screen. In Synchronous mode they go
  10. // to the console.
  11. //
  12. ULONG (*DbgPrintLocation)(PCH Format,...) = DbgPrint;
  13. //
  14. // Flag if we are in Synchronous mode or not. In Synchronous mode all
  15. // commands (except OPLOCKS) are executed Synchronously with the shell.
  16. // The default mode is NOT Synchronous mode.
  17. //
  18. BOOLEAN SynchronousCmds = FALSE;
  19. //
  20. // If set do to give the BSHELL prompt
  21. //
  22. BOOLEAN BatchMode = FALSE;
  23. //
  24. // Prototypes
  25. //
  26. int
  27. ParseCmdLine (
  28. int argc,
  29. char *argv[]
  30. );
  31. void
  32. DisplayUsage();
  33. //
  34. // Main Routine
  35. //
  36. #if i386
  37. __cdecl
  38. #endif
  39. main(
  40. int argc,
  41. char *argv[],
  42. char *envp[]
  43. )
  44. {
  45. BOOLEAN ExitWhile = FALSE;
  46. UCHAR Buffer[256];
  47. PCHAR ParamString;
  48. ULONG ParamStringLen;
  49. InitBuffers();
  50. InitHandles();
  51. InitEvents();
  52. if (!ParseCmdLine( argc, argv ))
  53. return STATUS_SUCCESS;
  54. while (!ExitWhile) {
  55. ParamString = Buffer;
  56. if (!BatchMode) {
  57. printf( "\nBSHELL> " );
  58. if (gets( ParamString ) == NULL) //exit on error
  59. return;
  60. printf( " " );
  61. } else {
  62. if (gets( ParamString ) == NULL) //exit on error
  63. return;
  64. printf("BSHELL> %s\n",ParamString);
  65. }
  66. fflush( stdout );
  67. ParamStringLen = strlen( ParamString );
  68. switch (AnalyzeBuffer( &ParamString, &ParamStringLen )) {
  69. case SHELL_EXIT:
  70. ExitWhile = TRUE;
  71. break;
  72. case SHELL_OPEN:
  73. InputOpenFile( ParamString + ParamStringLen );
  74. break;
  75. case SHELL_CLEAR_BUFFER:
  76. InputClearBuffer( ParamString + ParamStringLen );
  77. break;
  78. case SHELL_DISPLAY_BYTES:
  79. InputDisplayBuffer( ParamString + ParamStringLen, sizeof( CHAR ));
  80. break;
  81. case SHELL_DISPLAY_WORDS:
  82. InputDisplayBuffer( ParamString + ParamStringLen, sizeof( WCHAR ));
  83. break;
  84. case SHELL_DISPLAY_DWORDS:
  85. InputDisplayBuffer( ParamString + ParamStringLen, sizeof( ULONG ));
  86. break;
  87. case SHELL_COPY_BUFFER:
  88. InputCopyBuffer( ParamString + ParamStringLen );
  89. break;
  90. case SHELL_ALLOC_MEM:
  91. InputAllocMem( ParamString + ParamStringLen );
  92. break;
  93. case SHELL_DEALLOC_MEM:
  94. InputDeallocMem( ParamString + ParamStringLen );
  95. break;
  96. case SHELL_FILL_BUFFER:
  97. InputFillBuffer( ParamString + ParamStringLen );
  98. break;
  99. case SHELL_FILL_BUFFER_USN:
  100. InputFillBufferUsn( ParamString + ParamStringLen );
  101. break;
  102. case SHELL_PUT_EA:
  103. InputPutEaName( ParamString + ParamStringLen );
  104. break;
  105. case SHELL_FILL_EA:
  106. InputFillEaBuffer( ParamString + ParamStringLen );
  107. break;
  108. case SHELL_DISPLAY_HANDLE:
  109. InputDisplayHandle( ParamString + ParamStringLen );
  110. break;
  111. case SHELL_CLOSE_HANDLE:
  112. InputCloseIndex( ParamString + ParamStringLen );
  113. break;
  114. case SHELL_CANCEL_IO:
  115. InputCancelIndex( ParamString + ParamStringLen );
  116. break;
  117. case SHELL_READ_FILE:
  118. InputRead( ParamString + ParamStringLen );
  119. break;
  120. case SHELL_PAUSE:
  121. InputPause( ParamString + ParamStringLen );
  122. break;
  123. case SHELL_QUERY_EAS:
  124. InputQueryEa( ParamString + ParamStringLen );
  125. break;
  126. case SHELL_SET_EAS:
  127. InputSetEa( ParamString + ParamStringLen );
  128. break;
  129. case SHELL_BREAK:
  130. InputBreak( ParamString + ParamStringLen );
  131. break;
  132. case SHELL_OPLOCK:
  133. InputOplock( ParamString + ParamStringLen );
  134. break;
  135. case SHELL_WRITE:
  136. InputWrite( ParamString + ParamStringLen );
  137. break;
  138. case SHELL_QDIR:
  139. InputQDir( ParamString + ParamStringLen );
  140. break;
  141. case SHELL_DISPLAY_QDIR:
  142. InputDisplayQDir( ParamString + ParamStringLen );
  143. break;
  144. case SHELL_QFILE:
  145. InputQFile( ParamString + ParamStringLen );
  146. break;
  147. case SHELL_DISPLAY_QFILE:
  148. InputDisplayQFile( ParamString + ParamStringLen );
  149. break;
  150. case SHELL_NOTIFY_CHANGE:
  151. InputNotifyChange( ParamString + ParamStringLen );
  152. break;
  153. case SHELL_ENTER_TIME:
  154. InputEnterTime( ParamString + ParamStringLen );
  155. break;
  156. case SHELL_DISPLAY_TIME:
  157. InputDisplayTime( ParamString + ParamStringLen );
  158. break;
  159. case SHELL_SETFILE:
  160. InputSetFile( ParamString + ParamStringLen );
  161. break;
  162. case SHELL_QUERY_VOLUME:
  163. InputQVolume( ParamString + ParamStringLen );
  164. break;
  165. case SHELL_DISPLAY_QVOL:
  166. InputDisplayQVolume( ParamString + ParamStringLen );
  167. break;
  168. case SHELL_SET_VOLUME:
  169. InputSetVolume( ParamString + ParamStringLen );
  170. break;
  171. case SHELL_FSCTRL:
  172. InputFsctrl( ParamString + ParamStringLen );
  173. break;
  174. case SHELL_SPARSE:
  175. InputSparse( ParamString + ParamStringLen );
  176. break;
  177. case SHELL_USN:
  178. InputUsn( ParamString + ParamStringLen );
  179. break;
  180. case SHELL_REPARSE:
  181. InputReparse( ParamString + ParamStringLen );
  182. break;
  183. case SHELL_IOCTL:
  184. InputDevctrl( ParamString + ParamStringLen );
  185. break;
  186. default :
  187. //
  188. // Print out the possible command.
  189. //
  190. CommandSummary();
  191. }
  192. }
  193. UninitEvents();
  194. UninitBuffers();
  195. UninitHandles();
  196. return STATUS_SUCCESS;
  197. UNREFERENCED_PARAMETER( envp );
  198. }
  199. int
  200. ParseCmdLine (
  201. int argc,
  202. char *argv[]
  203. )
  204. {
  205. int i,j;
  206. char *cp;
  207. for (i=1; i < argc; i++) {
  208. cp = argv[i];
  209. //
  210. // See if a switch was specified
  211. //
  212. if (cp[0] == '-' || cp[0] == '/') {
  213. for (j=1; cp[j] != 0; j++) {
  214. switch (cp[j]) {
  215. //
  216. // Handle the "synchronous" switch
  217. //
  218. case 's':
  219. case 'S':
  220. SynchronousCmds = TRUE;
  221. DbgPrintLocation = printf;
  222. break;
  223. //
  224. // Handle the "prompt" switch
  225. //
  226. case 'b':
  227. case 'B':
  228. BatchMode = TRUE;
  229. SynchronousCmds = TRUE;
  230. DbgPrintLocation = printf;
  231. break;
  232. //
  233. // Display usage for unknown switch
  234. //
  235. case 'h':
  236. case 'H':
  237. case '?':
  238. default:
  239. DisplayUsage();
  240. return FALSE;
  241. }
  242. }
  243. } else {
  244. //
  245. // Display usage for unknown parameters
  246. //
  247. DisplayUsage();
  248. return FALSE;
  249. }
  250. }
  251. return TRUE;
  252. }
  253. void
  254. DisplayUsage()
  255. {
  256. printf("\nUsage: bshell [/bs]\n"
  257. " /b - Execute in batch mode (which also sets synchronous mode)\n"
  258. " /s - Execute commands synchronously\n"
  259. );
  260. }