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.

231 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: sscget.c
  23. Description: sscget 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 HOST file name\n");
  40. printf(" where filename2 is the destination VPC 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. HostFile = argv[1];
  92. VpcFile = argv[2];
  93. // open/create the Host file
  94. if(!DeviceIoControl(
  95. hDevice, // HANDLE hDevice, // handle to device of interest
  96. IOCTL_VXCHANGE_OPEN_FILE, // DWORD dwIoControlCode, // control code of operation to perform
  97. HostFile, // LPVOID lpInBuffer, // pointer to buffer to supply input data
  98. MAX_PATH, // DWORD nInBufferSize, // size of input buffer
  99. NULL, // LPVOID lpOutBuffer, // pointer to buffer to receive output data
  100. 0, // DWORD nOutBufferSize, // size of output buffer
  101. &BytesDone, // LPDWORD lpBytesReturned, // pointer to variable to receive output byte count
  102. NULL // LPOVERLAPPED lpOverlapped // pointer to overlapped structure for asynchronous operation
  103. ))
  104. {
  105. printf("%s error: Can't open the Host file %s\n", argv[0], HostFile);
  106. CloseHandle(hDevice);
  107. return 5;
  108. }
  109. // open/create the Vpc file
  110. if ((hVpc = CreateFile(VpcFile,
  111. GENERIC_WRITE,
  112. FILE_SHARE_WRITE,
  113. NULL,
  114. CREATE_ALWAYS,
  115. FILE_ATTRIBUTE_NORMAL,
  116. NULL
  117. )) == ((HANDLE)-1))
  118. {
  119. printf("%s error: Can't open the Vpc file %s\n", argv[0], VpcFile);
  120. CloseHandle(hDevice);
  121. CloseHandle(hVpc);
  122. return 4;
  123. }
  124. #define DATA_BUFFER_SIZE 4096
  125. // allocate 4096 bytes of memory and commit the pages
  126. Data = (unsigned char *)VirtualAlloc(NULL, DATA_BUFFER_SIZE, MEM_COMMIT, PAGE_READWRITE);
  127. if (Data == NULL)
  128. {
  129. printf("%s error: Can't allocate memory for data buffers\n", argv[0]);
  130. CloseHandle(hDevice);
  131. CloseHandle(hVpc);
  132. return 6;
  133. }
  134. rc = TRUE;
  135. // read from the source file and write to destination
  136. while (rc)
  137. {
  138. // read data from the Host file
  139. if(!DeviceIoControl(
  140. hDevice, // HANDLE hDevice, // handle to device of interest
  141. IOCTL_VXCHANGE_READ_FILE, // DWORD dwIoControlCode, // control code of operation to perform
  142. NULL, // LPVOID lpInBuffer, // pointer to buffer to supply input data
  143. 0, // DWORD nInBufferSize, // size of input buffer
  144. Data, // LPVOID lpOutBuffer, // pointer to buffer to receive output data
  145. DATA_BUFFER_SIZE, // DWORD nOutBufferSize, // size of output buffer
  146. &BytesDone, // LPDWORD lpBytesReturned, // pointer to variable to receive output byte count
  147. NULL // LPOVERLAPPED lpOverlapped // pointer to overlapped structure for asynchronous operation
  148. ))
  149. {
  150. printf("%s error: Can't read from the Host file %s\n", argv[0], HostFile);
  151. CloseHandle(hDevice);
  152. CloseHandle(hVpc);
  153. return 5;
  154. }
  155. if (BytesDone < DATA_BUFFER_SIZE)
  156. rc = FALSE;
  157. // write data to the Vpc file
  158. if (!WriteFile(
  159. hVpc,
  160. Data,
  161. BytesDone,
  162. &BytesDone,
  163. NULL))
  164. {
  165. printf("%s error: Can't write to the Vpc file %s\n", argv[0], VpcFile);
  166. CloseHandle(hDevice);
  167. CloseHandle(hVpc);
  168. return 6;
  169. }
  170. }
  171. // close the Vpc file
  172. CloseHandle(hVpc);
  173. // close the Host file
  174. if(!DeviceIoControl(
  175. hDevice, // HANDLE hDevice, // handle to device of interest
  176. IOCTL_VXCHANGE_CLOSE_FILE, // DWORD dwIoControlCode, // control code of operation to perform
  177. NULL, // LPVOID lpInBuffer, // pointer to buffer to supply input data
  178. 0, // DWORD nInBufferSize, // size of input buffer
  179. NULL, // LPVOID lpOutBuffer, // pointer to buffer to receive output data
  180. 0, // DWORD nOutBufferSize, // size of output buffer
  181. &BytesDone, // LPDWORD lpBytesReturned, // pointer to variable to receive output byte count
  182. NULL // LPOVERLAPPED lpOverlapped // pointer to overlapped structure for asynchronous operation
  183. ))
  184. {
  185. printf("%s error: Can't close the Host file %s\n", argv[0], HostFile);
  186. CloseHandle(hDevice);
  187. CloseHandle(hVpc);
  188. return 9;
  189. }
  190. CloseHandle(hDevice);
  191. return 0;
  192. }