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.

198 lines
4.0 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. Error = SrWaitForNotification( ControlHandle,
  38. (PVOID)&NotifyRecord,
  39. sizeof(NotifyRecord),
  40. &Overlapped );
  41. if (Error == ERROR_IO_PENDING)
  42. {
  43. if (GetOverlappedResult(ControlHandle, &Overlapped, &Length, TRUE))
  44. {
  45. Error = 0;
  46. }
  47. else
  48. {
  49. Error = GetLastError();
  50. }
  51. }
  52. if (Error != 0)
  53. {
  54. printf("\n!SrWaitForNotification failed %d\n", Error);
  55. }
  56. else
  57. {
  58. printf( "\n-SrWaitForNotification(%ls, %d)\n",
  59. NotifyRecord.Record.VolumeName.Buffer,
  60. NotifyRecord.Record.NotificationType );
  61. }
  62. }
  63. CloseHandle(Overlapped.hEvent);
  64. Shutdown = 2;
  65. return 0;
  66. }
  67. int __cdecl main(int argc, char ** argv)
  68. {
  69. ULONG Error = 0;
  70. UCHAR Char;
  71. ULONG Number;
  72. HANDLE ThreadHandle;
  73. //
  74. // Start the monitor process
  75. //
  76. printf("started...\n" );
  77. Error = SrCreateControlHandle(SR_OPTION_OVERLAPPED, &ControlHandle);
  78. if (Error != 0)
  79. {
  80. printf("!SrCreateControlHandle failed %d\n", Error);
  81. return Error;
  82. }
  83. ThreadHandle = CreateThread(NULL, 0, NotifyThread, NULL, 0, NULL);
  84. CloseHandle(ThreadHandle);
  85. while (Shutdown == 0)
  86. {
  87. printf("1=start,2=stop,3=new_restore_point,4=quit: ");
  88. Char = (UCHAR)_getche();
  89. printf("\n");
  90. switch (Char)
  91. {
  92. case '1':
  93. Error = SrStartMonitoring(ControlHandle);
  94. if (Error != 0)
  95. {
  96. printf("!SrStartMonitoring failed %d\n", Error);
  97. }
  98. else
  99. {
  100. printf("-SrStartMonitoring \n");
  101. }
  102. break;
  103. case '2':
  104. Error = SrStopMonitoring(ControlHandle);
  105. if (Error != 0)
  106. {
  107. printf("!SrStopMonitoring failed %d\n", Error);
  108. }
  109. else
  110. {
  111. printf("-SrStopMonitoring \n");
  112. }
  113. break;
  114. case '3':
  115. Error = SrCreateRestorePoint(ControlHandle, &Number);
  116. if (Error != 0)
  117. {
  118. printf("!SrCreateRestorePoint failed %d\n", Error);
  119. }
  120. else
  121. {
  122. printf("-SrCreateRestorePoint(%d)\n", Number);
  123. }
  124. break;
  125. case '4':
  126. printf("quit...\n");
  127. Shutdown = 1;
  128. break;
  129. };
  130. }
  131. CloseHandle(ControlHandle);
  132. //
  133. // wait for our thread to die
  134. //
  135. while (Shutdown < 2)
  136. Sleep(0);
  137. return 0;
  138. }