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.

425 lines
9.2 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. utils.c
  5. Abstract:
  6. Common utility routines for clusters resources
  7. Author:
  8. John Vert (jvert) 12/15/1996
  9. Revision History:
  10. --*/
  11. #include "clusres.h"
  12. #include "clusrtl.h"
  13. #include "clusudef.h"
  14. DWORD
  15. ClusResOpenDriver(
  16. HANDLE *Handle,
  17. LPWSTR DriverName
  18. )
  19. /*++
  20. Routine Description:
  21. This function opens a specified IO drivers.
  22. Arguments:
  23. Handle - pointer to location where the opened drivers handle is
  24. returned.
  25. DriverName - name of the driver to be opened.
  26. Return Value:
  27. Windows Error Code.
  28. --*/
  29. {
  30. OBJECT_ATTRIBUTES objectAttributes;
  31. IO_STATUS_BLOCK ioStatusBlock;
  32. UNICODE_STRING nameString;
  33. NTSTATUS status;
  34. *Handle = NULL;
  35. //
  36. // Open a Handle to the IP driver.
  37. //
  38. RtlInitUnicodeString(&nameString, DriverName);
  39. InitializeObjectAttributes(
  40. &objectAttributes,
  41. &nameString,
  42. OBJ_CASE_INSENSITIVE,
  43. (HANDLE) NULL,
  44. (PSECURITY_DESCRIPTOR) NULL
  45. );
  46. status = NtCreateFile(
  47. Handle,
  48. SYNCHRONIZE | FILE_READ_DATA | FILE_WRITE_DATA,
  49. &objectAttributes,
  50. &ioStatusBlock,
  51. NULL,
  52. FILE_ATTRIBUTE_NORMAL,
  53. FILE_SHARE_READ | FILE_SHARE_WRITE,
  54. FILE_OPEN_IF,
  55. 0,
  56. NULL,
  57. 0
  58. );
  59. return( RtlNtStatusToDosError( status ) );
  60. } // ClusResOpenDriver
  61. NTSTATUS
  62. ClusResDoIoctl(
  63. HANDLE Handle,
  64. DWORD IoctlCode,
  65. PVOID Request,
  66. DWORD RequestSize,
  67. PVOID Response,
  68. PDWORD ResponseSize
  69. )
  70. /*++
  71. Routine Description:
  72. Utility routine used to issue a filtering ioctl to the tcpip driver.
  73. Arguments:
  74. Handle - An open file handle on which to issue the request.
  75. IoctlCode - The IOCTL opcode.
  76. Request - A pointer to the input buffer.
  77. RequestSize - Size of the input buffer.
  78. Response - A pointer to the output buffer.
  79. ResponseSize - On input, the size in bytes of the output buffer.
  80. On output, the number of bytes returned in the output buffer.
  81. Return Value:
  82. NT Status Code.
  83. --*/
  84. {
  85. IO_STATUS_BLOCK ioStatusBlock;
  86. NTSTATUS status;
  87. ioStatusBlock.Information = 0;
  88. status = NtDeviceIoControlFile(
  89. Handle, // Driver handle
  90. NULL, // Event
  91. NULL, // APC Routine
  92. NULL, // APC context
  93. &ioStatusBlock, // Status block
  94. IoctlCode, // Control code
  95. Request, // Input buffer
  96. RequestSize, // Input buffer size
  97. Response, // Output buffer
  98. *ResponseSize // Output buffer size
  99. );
  100. if (status == STATUS_PENDING) {
  101. status = NtWaitForSingleObject(
  102. Handle,
  103. TRUE,
  104. NULL
  105. );
  106. }
  107. if (status == STATUS_SUCCESS) {
  108. status = ioStatusBlock.Status;
  109. *ResponseSize = (DWORD)ioStatusBlock.Information;
  110. }
  111. else {
  112. *ResponseSize = 0;
  113. }
  114. return(status);
  115. } // ClusResDoIoctl
  116. VOID
  117. ClusResLogEventWithName0(
  118. IN HKEY hResourceKey,
  119. IN DWORD LogLevel,
  120. IN DWORD LogModule,
  121. IN LPSTR FileName,
  122. IN DWORD LineNumber,
  123. IN DWORD MessageId,
  124. IN DWORD dwByteCount,
  125. IN PVOID lpBytes
  126. )
  127. /*++
  128. Routine Description:
  129. Logs an event to the eventlog. The display name of the resource is retrieved
  130. and passed as the first insertion string.
  131. Arguments:
  132. hResourceKey - Supplies the cluster resource key.
  133. LogLevel - Supplies the logging level, one of
  134. LOG_CRITICAL 1
  135. LOG_UNUSUAL 2
  136. LOG_NOISE 3
  137. LogModule - Supplies the module ID.
  138. FileName - Supplies the filename of the caller
  139. LineNumber - Supplies the line number of the caller
  140. MessageId - Supplies the message ID to be logged.
  141. dwByteCount - Supplies the number of error-specific bytes to log. If this
  142. is zero, lpBytes is ignored.
  143. lpBytes - Supplies the error-specific bytes to log.
  144. Return Value:
  145. ERROR_SUCCESS if successful
  146. Win32 error code otherwise
  147. --*/
  148. {
  149. DWORD BufSize;
  150. DWORD Status;
  151. WCHAR ResourceName[80];
  152. DWORD dwType;
  153. //
  154. // Get the display name for this resource.
  155. //
  156. BufSize = sizeof(ResourceName);
  157. Status = ClusterRegQueryValue( hResourceKey,
  158. CLUSREG_NAME_RES_NAME,
  159. &dwType,
  160. (LPBYTE)ResourceName,
  161. &BufSize );
  162. if (Status != ERROR_SUCCESS) {
  163. ResourceName[0] = '\0';
  164. } else {
  165. ResourceName[79] = '\0';
  166. }
  167. ClusterLogEvent1(LogLevel,
  168. LogModule,
  169. FileName,
  170. LineNumber,
  171. MessageId,
  172. dwByteCount,
  173. lpBytes,
  174. ResourceName);
  175. return;
  176. }
  177. VOID
  178. ClusResLogEventWithName1(
  179. IN HKEY hResourceKey,
  180. IN DWORD LogLevel,
  181. IN DWORD LogModule,
  182. IN LPSTR FileName,
  183. IN DWORD LineNumber,
  184. IN DWORD MessageId,
  185. IN DWORD dwByteCount,
  186. IN PVOID lpBytes,
  187. IN LPCWSTR Arg1
  188. )
  189. /*++
  190. Routine Description:
  191. Logs an event to the eventlog. The display name of the resource is retrieved
  192. and passed as the first insertion string.
  193. Arguments:
  194. hResourceKey - Supplies the cluster resource key.
  195. LogLevel - Supplies the logging level, one of
  196. LOG_CRITICAL 1
  197. LOG_UNUSUAL 2
  198. LOG_NOISE 3
  199. LogModule - Supplies the module ID.
  200. FileName - Supplies the filename of the caller
  201. LineNumber - Supplies the line number of the caller
  202. MessageId - Supplies the message ID to be logged.
  203. dwByteCount - Supplies the number of error-specific bytes to log. If this
  204. is zero, lpBytes is ignored.
  205. lpBytes - Supplies the error-specific bytes to log.
  206. Arg1 - Supplies an insertion string
  207. Return Value:
  208. ERROR_SUCCESS if successful
  209. Win32 error code otherwise
  210. --*/
  211. {
  212. DWORD BufSize;
  213. DWORD Status;
  214. WCHAR ResourceName[80];
  215. DWORD dwType;
  216. //
  217. // Get the display name for this resource.
  218. //
  219. BufSize = sizeof(ResourceName);
  220. Status = ClusterRegQueryValue( hResourceKey,
  221. CLUSREG_NAME_RES_NAME,
  222. &dwType,
  223. (LPBYTE)ResourceName,
  224. &BufSize );
  225. if (Status != ERROR_SUCCESS) {
  226. ResourceName[0] = '\0';
  227. } else {
  228. ResourceName[79] = '\0';
  229. }
  230. ClusterLogEvent2(LogLevel,
  231. LogModule,
  232. FileName,
  233. LineNumber,
  234. MessageId,
  235. dwByteCount,
  236. lpBytes,
  237. ResourceName,
  238. Arg1);
  239. return;
  240. }
  241. VOID
  242. ClusResLogEventWithName2(
  243. IN HKEY hResourceKey,
  244. IN DWORD LogLevel,
  245. IN DWORD LogModule,
  246. IN LPSTR FileName,
  247. IN DWORD LineNumber,
  248. IN DWORD MessageId,
  249. IN DWORD dwByteCount,
  250. IN PVOID lpBytes,
  251. IN LPCWSTR Arg1,
  252. IN LPCWSTR Arg2
  253. )
  254. /*++
  255. Routine Description:
  256. Logs an event to the eventlog. The display name of the resource is retrieved
  257. and passed as the first insertion string.
  258. Arguments:
  259. hResourceKey - Supplies the cluster resource key.
  260. LogLevel - Supplies the logging level, one of
  261. LOG_CRITICAL 1
  262. LOG_UNUSUAL 2
  263. LOG_NOISE 3
  264. LogModule - Supplies the module ID.
  265. FileName - Supplies the filename of the caller
  266. LineNumber - Supplies the line number of the caller
  267. MessageId - Supplies the message ID to be logged.
  268. dwByteCount - Supplies the number of error-specific bytes to log. If this
  269. is zero, lpBytes is ignored.
  270. lpBytes - Supplies the error-specific bytes to log.
  271. Arg1 - Supplies an insertion string
  272. Arg2 - Supplies the second insertion string
  273. Return Value:
  274. ERROR_SUCCESS if successful
  275. Win32 error code otherwise
  276. --*/
  277. {
  278. DWORD BufSize;
  279. DWORD Status;
  280. WCHAR ResourceName[80];
  281. DWORD dwType;
  282. //
  283. // Get the display name for this resource.
  284. //
  285. BufSize = sizeof(ResourceName);
  286. Status = ClusterRegQueryValue( hResourceKey,
  287. CLUSREG_NAME_RES_NAME,
  288. &dwType,
  289. (LPBYTE)ResourceName,
  290. &BufSize );
  291. if (Status != ERROR_SUCCESS) {
  292. ResourceName[0] = '\0';
  293. } else {
  294. ResourceName[79] = '\0';
  295. }
  296. ClusterLogEvent3(LogLevel,
  297. LogModule,
  298. FileName,
  299. LineNumber,
  300. MessageId,
  301. dwByteCount,
  302. lpBytes,
  303. ResourceName,
  304. Arg1,
  305. Arg2);
  306. return;
  307. }