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.

232 lines
8.5 KiB

  1. /*****************************************************************************
  2. Copyright (c) 1997-98 Intel Corp.
  3. All Rights Reserved.
  4. The source code contained or described herein and all documents
  5. related to the source code ("Material") are owned by Intel Corporation
  6. or its suppliers and licensors. Title to the Material remains with
  7. Intel Corporation or its suppliers and licensors. The Material
  8. contains trade secrets and proprietary and confidential information of
  9. Intel or its suppliers and licensors. The Material is protected by
  10. worldwide copyright and trade secret laws and treaty provisions. No
  11. part of the Material may be used, copied, reproduced, modified,
  12. published, uploaded, posted, transmitted, distributed, or disclosed in
  13. any way without Intel's prior express written permission.
  14. Unless otherwise expressly permitted by Intel in a separate license
  15. agreement, use of the Material is subject to the copyright notices,
  16. trademarks, warranty, use, and disclosure restrictions reflected on
  17. the outside of the media, in the documents themselves, and in the
  18. "About" or "Read Me" or similar file contained within this source
  19. code, and identified as (name of the file) . Unless otherwise
  20. expressly agreed by Intel in writing, you may not remove or alter such
  21. notices in any way.
  22. File: vxchange.c
  23. Description: VxChane Console Mode File Copy utility
  24. Revision: $Revision:$ // Do not delete or replace
  25. Notes:
  26. Major History:
  27. When Who What
  28. ---------- ---------- ----------
  29. 03/06/98 Jey Created
  30. *****************************************************************************/
  31. #include <windows.h>
  32. #include <winioctl.h>
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <vxchange.h>
  36. void print_usage(char *module)
  37. {
  38. printf("\n%s usage: filename1 filename2 \n\n",module);
  39. printf("Note: where filename1 is the source VPC file name\n");
  40. printf(" where filename2 is the destination HOST file name\n\n");
  41. }
  42. int
  43. __cdecl
  44. main(
  45. IN int argc,
  46. IN char *argv[]
  47. )
  48. {
  49. HANDLE hDevice;
  50. VxChange_Attrs_t DriverAttrs;
  51. DWORD BytesDone;
  52. unsigned char *VpcFile;
  53. unsigned char *HostFile;
  54. HANDLE hVpc;
  55. unsigned char *Data;
  56. BOOLEAN rc;
  57. if (argc < 3)
  58. {
  59. print_usage(argv[0]);
  60. return 1;
  61. }
  62. // open the kernel mode driver
  63. if ((hDevice = CreateFile("\\\\.\\VxChange",
  64. GENERIC_READ | GENERIC_WRITE,
  65. FILE_SHARE_READ | FILE_SHARE_WRITE,
  66. NULL,
  67. OPEN_EXISTING,
  68. FILE_ATTRIBUTE_NORMAL,
  69. NULL
  70. )) == ((HANDLE)-1))
  71. {
  72. printf("%s error: Can't get a handle to VxChange device\n", argv[0]);
  73. return 2;
  74. }
  75. // get the Driver Attributes
  76. if(!DeviceIoControl(
  77. hDevice, // HANDLE hDevice, // handle to device of interest
  78. IOCTL_VXCHANGE_GET_DRIVER_ATTRIBUTES, // DWORD dwIoControlCode, // control code of operation to perform
  79. NULL, // LPVOID lpInBuffer, // pointer to buffer to supply input data
  80. 0, // DWORD nInBufferSize, // size of input buffer
  81. &DriverAttrs, // LPVOID lpOutBuffer, // pointer to buffer to receive output data
  82. sizeof(VxChange_Attrs_t), // DWORD nOutBufferSize, // size of output buffer
  83. &BytesDone, // LPDWORD lpBytesReturned, // pointer to variable to receive output byte count
  84. NULL // LPOVERLAPPED lpOverlapped // pointer to overlapped structure for asynchronous operation
  85. ))
  86. {
  87. printf("%s error: Query Driver Attributes failed\n", argv[0]);
  88. CloseHandle(hDevice);
  89. return 3;
  90. }
  91. VpcFile = argv[1];
  92. HostFile = argv[2];
  93. // open/create the Vpc file
  94. if ((hVpc = CreateFile(VpcFile,
  95. GENERIC_READ,
  96. FILE_SHARE_READ,
  97. NULL,
  98. OPEN_EXISTING,
  99. FILE_ATTRIBUTE_NORMAL,
  100. NULL
  101. )) == ((HANDLE)-1))
  102. {
  103. printf("%s error: Can't open the Vpc file %s\n", argv[0], VpcFile);
  104. return 4;
  105. }
  106. // open/create the Host file
  107. if(!DeviceIoControl(
  108. hDevice, // HANDLE hDevice, // handle to device of interest
  109. IOCTL_VXCHANGE_CREATE_FILE, // DWORD dwIoControlCode, // control code of operation to perform
  110. HostFile, // LPVOID lpInBuffer, // pointer to buffer to supply input data
  111. MAX_PATH, // DWORD nInBufferSize, // size of input buffer
  112. NULL, // LPVOID lpOutBuffer, // pointer to buffer to receive output data
  113. 0, // DWORD nOutBufferSize, // size of output buffer
  114. &BytesDone, // LPDWORD lpBytesReturned, // pointer to variable to receive output byte count
  115. NULL // LPOVERLAPPED lpOverlapped // pointer to overlapped structure for asynchronous operation
  116. ))
  117. {
  118. printf("%s error: Can't open the Host file %s\n", argv[0], HostFile);
  119. CloseHandle(hDevice);
  120. CloseHandle(hVpc);
  121. return 5;
  122. }
  123. #define DATA_BUFFER_SIZE 4096
  124. // allocate 4096 bytes of memory and commit the pages
  125. Data = (unsigned char *)VirtualAlloc(NULL, DATA_BUFFER_SIZE, MEM_COMMIT, PAGE_READWRITE);
  126. if (Data == NULL)
  127. {
  128. printf("%s error: Can't allocate memory for data buffers\n", argv[0]);
  129. CloseHandle(hDevice);
  130. CloseHandle(hVpc);
  131. return 6;
  132. }
  133. rc = TRUE;
  134. // read from the source file and write to destination
  135. while (rc)
  136. {
  137. // read data from the Vpc file
  138. if (!ReadFile(
  139. hVpc,
  140. Data,
  141. DATA_BUFFER_SIZE,
  142. &BytesDone,
  143. NULL))
  144. {
  145. printf("%s error: Can't read from the Vpc file %s\n", argv[0], VpcFile);
  146. CloseHandle(hDevice);
  147. CloseHandle(hVpc);
  148. return 7;
  149. }
  150. if (BytesDone < DATA_BUFFER_SIZE)
  151. rc = FALSE;
  152. // write data to the Host file
  153. if(!DeviceIoControl(
  154. hDevice, // HANDLE hDevice, // handle to device of interest
  155. IOCTL_VXCHANGE_WRITE_FILE, // DWORD dwIoControlCode, // control code of operation to perform
  156. Data, // LPVOID lpInBuffer, // pointer to buffer to supply input data
  157. BytesDone, // DWORD nInBufferSize, // size of input buffer
  158. NULL, // LPVOID lpOutBuffer, // pointer to buffer to receive output data
  159. 0, // DWORD nOutBufferSize, // size of output buffer
  160. &BytesDone, // LPDWORD lpBytesReturned, // pointer to variable to receive output byte count
  161. NULL // LPOVERLAPPED lpOverlapped // pointer to overlapped structure for asynchronous operation
  162. ))
  163. {
  164. printf("%s error: Can't write to the Host file %s\n", argv[0], HostFile);
  165. CloseHandle(hDevice);
  166. CloseHandle(hVpc);
  167. return 8;
  168. }
  169. }
  170. // close the Vpc file
  171. CloseHandle(hVpc);
  172. // close the Host file
  173. if(!DeviceIoControl(
  174. hDevice, // HANDLE hDevice, // handle to device of interest
  175. IOCTL_VXCHANGE_CLOSE_FILE, // DWORD dwIoControlCode, // control code of operation to perform
  176. NULL, // LPVOID lpInBuffer, // pointer to buffer to supply input data
  177. 0, // DWORD nInBufferSize, // size of input buffer
  178. NULL, // LPVOID lpOutBuffer, // pointer to buffer to receive output data
  179. 0, // DWORD nOutBufferSize, // size of output buffer
  180. &BytesDone, // LPDWORD lpBytesReturned, // pointer to variable to receive output byte count
  181. NULL // LPOVERLAPPED lpOverlapped // pointer to overlapped structure for asynchronous operation
  182. ))
  183. {
  184. printf("%s error: Can't open the Host file %s\n", argv[0], HostFile);
  185. CloseHandle(hDevice);
  186. CloseHandle(hVpc);
  187. return 9;
  188. }
  189. CloseHandle(hDevice);
  190. return 0;
  191. }