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.

261 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. main.c
  5. Abstract:
  6. simple bvt-like test code for SR.SYS.
  7. Author:
  8. Paul McDaniel (paulmcd) 07-Mar-2000
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #define NtStatusToWin32Status( Status ) \
  13. ( ( (Status) == STATUS_SUCCESS ) \
  14. ? NO_ERROR \
  15. : RtlNtStatusToDosError( Status ) )
  16. ULONG Shutdown = 0;
  17. HANDLE ControlHandle = NULL;
  18. DWORD
  19. WINAPI
  20. NotifyThread(
  21. LPVOID pParameter
  22. )
  23. {
  24. union
  25. {
  26. SR_NOTIFICATION_RECORD Record;
  27. UCHAR Buffer[1024*4];
  28. } NotifyRecord;
  29. ULONG Error;
  30. ULONG Length;
  31. OVERLAPPED Overlapped;
  32. ZeroMemory(&Overlapped, sizeof(Overlapped));
  33. Overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  34. while (Shutdown == 0)
  35. {
  36. ResetEvent(Overlapped.hEvent);
  37. if (ControlHandle == NULL)
  38. {
  39. Sleep(100);
  40. continue;
  41. }
  42. Error = SrWaitForNotification( ControlHandle,
  43. (PVOID)&NotifyRecord,
  44. sizeof(NotifyRecord),
  45. &Overlapped );
  46. if (Error == ERROR_IO_PENDING)
  47. {
  48. if (GetOverlappedResult(ControlHandle, &Overlapped, &Length, TRUE))
  49. {
  50. Error = 0;
  51. }
  52. else
  53. {
  54. Error = GetLastError();
  55. }
  56. }
  57. if (Error != 0)
  58. {
  59. printf("\n!SrWaitForNotification failed %d\n", Error);
  60. }
  61. else
  62. {
  63. printf( "\n-SrWaitForNotification(%ls, %d)\n",
  64. NotifyRecord.Record.VolumeName.Buffer,
  65. NotifyRecord.Record.NotificationType );
  66. }
  67. }
  68. CloseHandle(Overlapped.hEvent);
  69. Shutdown = 2;
  70. return 0;
  71. }
  72. int __cdecl main(int argc, char ** argv)
  73. {
  74. ULONG Error = 0;
  75. UCHAR Char;
  76. ULONG Number;
  77. HANDLE ThreadHandle;
  78. //
  79. // Start the monitor process
  80. //
  81. printf("started...\n" );
  82. Error = SrCreateControlHandle(SR_OPTION_OVERLAPPED, &ControlHandle);
  83. if (Error != 0)
  84. {
  85. printf("!SrCreateControlHandle failed %d\n", Error);
  86. return Error;
  87. }
  88. ThreadHandle = CreateThread(NULL, 0, NotifyThread, NULL, 0, NULL);
  89. CloseHandle(ThreadHandle);
  90. while (Shutdown == 0)
  91. {
  92. printf("0=open,1=start,2=stop,3=new_restore_point,4=close,5=quit,6=reload,7=disable: ");
  93. Char = (UCHAR)_getche();
  94. printf("\n");
  95. switch (Char)
  96. {
  97. case '0':
  98. if (ControlHandle != NULL)
  99. {
  100. printf("already open!\n");
  101. break;
  102. }
  103. Error = SrCreateControlHandle(SR_OPTION_OVERLAPPED, &ControlHandle);
  104. if (Error != 0)
  105. {
  106. printf("!SrCreateControlHandle failed %d\n", Error);
  107. return Error;
  108. }
  109. break;
  110. case '1':
  111. Error = SrStartMonitoring(ControlHandle);
  112. if (Error != 0)
  113. {
  114. printf("!SrStartMonitoring failed %d\n", Error);
  115. }
  116. else
  117. {
  118. printf("-SrStartMonitoring \n");
  119. }
  120. break;
  121. case '2':
  122. Error = SrStopMonitoring(ControlHandle);
  123. if (Error != 0)
  124. {
  125. printf("!SrStopMonitoring failed %d\n", Error);
  126. }
  127. else
  128. {
  129. printf("-SrStopMonitoring \n");
  130. }
  131. break;
  132. case '3':
  133. Error = SrCreateRestorePoint(ControlHandle, &Number);
  134. if (Error != 0)
  135. {
  136. printf("!SrCreateRestorePoint failed %d\n", Error);
  137. }
  138. else
  139. {
  140. printf("-SrCreateRestorePoint(%d)\n", Number);
  141. }
  142. break;
  143. case '4':
  144. if (ControlHandle == NULL)
  145. {
  146. printf ("already closed!\n");
  147. break;
  148. }
  149. CloseHandle(ControlHandle);
  150. ControlHandle = NULL;
  151. break;
  152. case '5':
  153. printf("quit...\n");
  154. Shutdown = 1;
  155. break;
  156. case '6':
  157. Error = SrReloadConfiguration(ControlHandle);
  158. if (Error != 0)
  159. {
  160. printf("!SrReloadConfiguration failed %d\n", Error);
  161. }
  162. else
  163. {
  164. printf("-SrReloadConfiguration\n");
  165. }
  166. break;
  167. case '7':
  168. Error = SrDisableVolume(ControlHandle, L"\\??\\D:");
  169. if (Error != 0)
  170. {
  171. printf("!SrDisableVolume failed %d\n", Error);
  172. }
  173. else
  174. {
  175. printf("-SrDisableVolume\n");
  176. }
  177. break;
  178. };
  179. }
  180. CloseHandle(ControlHandle);
  181. //
  182. // wait for our thread to die
  183. //
  184. while (Shutdown < 2)
  185. Sleep(0);
  186. return 0;
  187. }