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.

176 lines
5.1 KiB

  1. /*
  2. * WORKUTIL.C
  3. *
  4. * RSM Service : Utilities for servicing work items
  5. *
  6. * Author: ErvinP
  7. *
  8. * (c) 2001 Microsoft Corporation
  9. *
  10. */
  11. #include <windows.h>
  12. #include <stdlib.h>
  13. #include <wtypes.h>
  14. #include <ntmsapi.h>
  15. #include "..\..\..\rsm\tools\reskit\rsm_config\winioctl.h"
  16. #include "internal.h"
  17. #include "resource.h"
  18. #include "debug.h"
  19. BOOL SendIoctlSync( HANDLE hDevice,
  20. DWORD dwIoControlCode,
  21. LPVOID lpInBuffer,
  22. DWORD nInBufferSize,
  23. LPVOID lpOutBuffer,
  24. DWORD nOutBufferSize,
  25. LPDWORD lpBytesReturned,
  26. DWORD timeoutMillisec)
  27. {
  28. DWORD status;
  29. DWORD startTime;
  30. startTime = GetTickCount();
  31. do
  32. {
  33. BOOL ok;
  34. ok = DeviceIoControl(hDevice,
  35. dwIoControlCode,
  36. lpInBuffer,
  37. nInBufferSize,
  38. lpOutBuffer,
  39. nOutBufferSize,
  40. lpBytesReturned,
  41. NULL);
  42. if (ok){
  43. status = NO_ERROR;
  44. break;
  45. }
  46. else {
  47. BOOL done;
  48. // BUGBUG - check for shutdown
  49. status = GetLastError();
  50. switch (status){
  51. case ERROR_NOT_READY:
  52. case ERROR_DRIVE_LOCKED:
  53. case ERROR_BUSY_DRIVE:
  54. case ERROR_BUSY:
  55. Sleep(3000);
  56. done = FALSE;
  57. break;
  58. default:
  59. done = TRUE;
  60. break;
  61. }
  62. if (!done){
  63. break;
  64. }
  65. }
  66. }
  67. while (GetTickCount() - startTime < timeoutMillisec);
  68. return status;
  69. }
  70. DWORD ChangerMoveMedium(HANDLE libHandle,
  71. DWORD TrnsElementOffset,
  72. ELEMENT_TYPE SrcElementType,
  73. DWORD SrcElementOffset,
  74. ELEMENT_TYPE DstElementType,
  75. DWORD DstElementOffset,
  76. BOOLEAN Flip,
  77. ULONG Timeout, // NOT USED
  78. DWORD timeoutval)
  79. {
  80. DWORD status;
  81. DWORD byteCount = 0;
  82. CHANGER_MOVE_MEDIUM LibMoveMedium;
  83. LibMoveMedium.Transport.ElementType = ChangerTransport;
  84. LibMoveMedium.Transport.ElementAddress = 0;
  85. LibMoveMedium.Source.ElementType = SrcElementType;
  86. LibMoveMedium.Source.ElementAddress = SrcElementOffset;
  87. LibMoveMedium.Destination.ElementType = DstElementType;
  88. LibMoveMedium.Destination.ElementAddress = DstElementOffset;
  89. LibMoveMedium.Flip = Flip;
  90. status = SendIoctlSync(libHandle,
  91. IOCTL_CHANGER_MOVE_MEDIUM,
  92. &LibMoveMedium,
  93. sizeof(CHANGER_MOVE_MEDIUM),
  94. NULL,
  95. 0,
  96. &byteCount,
  97. timeoutval);
  98. return status;
  99. }
  100. DWORD ChangerSetAccess(HANDLE libHandle,
  101. ELEMENT_TYPE ElementType,
  102. ULONG ElementOffset,
  103. ULONG Control,
  104. DWORD timeoutval)
  105. {
  106. DWORD status;
  107. DWORD byteCount = 0;
  108. CHANGER_SET_ACCESS libSetSecurity;
  109. libSetSecurity.Element.ElementType = ElementType;
  110. libSetSecurity.Element.ElementAddress = ElementOffset;
  111. libSetSecurity.Control = Control;
  112. status = SendIoctlSync(libHandle,
  113. IOCTL_CHANGER_SET_ACCESS,
  114. &libSetSecurity,
  115. sizeof(CHANGER_SET_ACCESS),
  116. NULL,
  117. 0,
  118. &byteCount,
  119. timeoutval);
  120. return status;
  121. }
  122. DWORD ChangerSetPosition(HANDLE libHandle,
  123. DWORD TrnsElementOffset,
  124. ELEMENT_TYPE DstElementType,
  125. DWORD DstElementOffset,
  126. BOOLEAN Flip,
  127. ULONG Timeout, // NOT USED
  128. DWORD timeoutval)
  129. {
  130. DWORD status;
  131. DWORD byteCount = 0;
  132. CHANGER_SET_POSITION LibSetPosition;
  133. LibSetPosition.Transport.ElementType = ChangerTransport;
  134. LibSetPosition.Transport.ElementAddress = 0;
  135. LibSetPosition.Destination.ElementType = DstElementType;
  136. LibSetPosition.Destination.ElementAddress = DstElementOffset;
  137. LibSetPosition.Flip = Flip;
  138. status = SendIoctlSync(libHandle,
  139. IOCTL_CHANGER_SET_POSITION,
  140. &LibSetPosition, sizeof(CHANGER_SET_POSITION),
  141. NULL,
  142. 0,
  143. &byteCount,
  144. timeoutval);
  145. return status;
  146. }