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.

223 lines
5.3 KiB

  1. #include "brian.h"
  2. VOID
  3. CancelIndex (
  4. IN USHORT Index,
  5. IN BOOLEAN DisplayParameters,
  6. IN BOOLEAN VerboseResults
  7. );
  8. VOID
  9. InputCancelIndex (
  10. IN PCHAR ParamBuffer
  11. )
  12. {
  13. BOOLEAN Verbose;
  14. BOOLEAN HandleFound;
  15. BOOLEAN DisplayParms;
  16. ULONG ThisHandleIndex;
  17. //
  18. // Set the defaults.
  19. //
  20. Verbose = TRUE;
  21. DisplayParms = FALSE;
  22. HandleFound = FALSE;
  23. //
  24. // While there is more input, analyze the parameter and update the
  25. // open flags.
  26. //
  27. while (TRUE) {
  28. ULONG DummyCount;
  29. //
  30. // Swallow leading white spaces.
  31. //
  32. ParamBuffer = SwallowWhite( ParamBuffer, &DummyCount );
  33. if (*ParamBuffer) {
  34. //
  35. // If the next parameter is legal then check the paramter value.
  36. // Update the parameter value.
  37. //
  38. if((*ParamBuffer == '-'
  39. || *ParamBuffer == '/')
  40. && (ParamBuffer++, *ParamBuffer != '\0')) {
  41. //
  42. // Switch on the next character.
  43. //
  44. switch (*ParamBuffer) {
  45. //
  46. // Recover a handle.
  47. //
  48. case 'i' :
  49. case 'I' :
  50. //
  51. // Move to the next character, as long as there
  52. // are no white spaces continue analyzing letters.
  53. // On the first bad letter, skip to the next
  54. // parameter.
  55. //
  56. ParamBuffer++;
  57. ThisHandleIndex = AsciiToInteger( ParamBuffer );
  58. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  59. HandleFound = TRUE;
  60. break;
  61. case 'v' :
  62. case 'V' :
  63. //
  64. // Legal values for params are T/t or F/f.
  65. //
  66. ParamBuffer++;
  67. if (*ParamBuffer == 'T'
  68. || *ParamBuffer == 't') {
  69. Verbose = TRUE;
  70. ParamBuffer++;
  71. } else if (*ParamBuffer == 'F'
  72. || *ParamBuffer == 'f') {
  73. Verbose = FALSE;
  74. ParamBuffer++;
  75. }
  76. break;
  77. case 'y' :
  78. case 'Y' :
  79. //
  80. // Set the display parms flag and jump over this
  81. // character.
  82. //
  83. DisplayParms = TRUE;
  84. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  85. break;
  86. default :
  87. //
  88. // Swallow to the next white space and continue the
  89. // loop.
  90. //
  91. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  92. }
  93. //
  94. // Else the text is invalid, skip the entire block.
  95. //
  96. //
  97. } else {
  98. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  99. }
  100. //
  101. // Else break.
  102. //
  103. } else {
  104. break;
  105. }
  106. }
  107. //
  108. // If the file name wasn't found, then display the syntax message
  109. // and set verbose to FALSE.
  110. //
  111. if( !HandleFound ) {
  112. printf( "\n Usage: can [options]*\n" );
  113. printf( "\n Options:" );
  114. printf( "\n -i<index number> Input a index to cancel" );
  115. printf( "\n -v[t|f] Verbose mode for subsequent handles" );
  116. printf( "\n -y Display parameters before call" );
  117. printf( "\n\n" );
  118. } else {
  119. CancelIndex( (USHORT) ThisHandleIndex,
  120. DisplayParms,
  121. Verbose );
  122. }
  123. return;
  124. }
  125. VOID
  126. CancelIndex (
  127. IN USHORT Index,
  128. IN BOOLEAN DisplayParameters,
  129. IN BOOLEAN VerboseResults
  130. )
  131. {
  132. NTSTATUS Status;
  133. IO_STATUS_BLOCK Iosb;
  134. Iosb.Status = 0;
  135. Iosb.Information = 0;
  136. //
  137. // Display parameters if requested.
  138. //
  139. if (DisplayParameters) {
  140. printf( "\nCancel Index Parameters" );
  141. printf( "\n\tIndex -> %04x", Index );
  142. printf( "\n\n" );
  143. }
  144. if (Index >= MAX_HANDLES) {
  145. printf( "\n\tCancel Index: Invalid index value" );
  146. Status = STATUS_INVALID_HANDLE;
  147. } else if (!Handles[Index].Used) {
  148. printf( "\n\tCancelIndex: Index is unused" );
  149. Status = STATUS_INVALID_HANDLE;
  150. } else {
  151. Status = NtCancelIoFile( Handles[Index].Handle, &Iosb );
  152. if (VerboseResults) {
  153. printf( "\nCancelIndex: Status -> %08lx\n", Status );
  154. if (NT_SUCCESS( Status )) {
  155. printf( "\nCancelIndex: Iosb.Information -> %08lx", Iosb.Information );
  156. printf( "\nCancelIndex: Iosb.Status -> %08lx", Iosb.Status );
  157. }
  158. printf( "\n" );
  159. }
  160. }
  161. return;
  162. }