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.

271 lines
6.4 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #define BUFFER_LENGTH 128
  9. //
  10. // This program is a hack until we have a proper GUI interface for mounting
  11. // double space volumes.
  12. //
  13. // davidgoe [David Goebel] Oct 11, 1993.
  14. //
  15. VOID
  16. __cdecl
  17. main (argc, argv)
  18. int argc;
  19. char *argv[];
  20. {
  21. UCHAR DasdName[7] = "\\\\.\\";
  22. UCHAR HostDrive[3];
  23. UCHAR OemBuffer[13] = "DBLSPACE.";
  24. ULONG SequenceNumber = 0;
  25. BOOLEAN SetHostDrive = FALSE;
  26. HANDLE Handle;
  27. UCHAR TmpBuffer[BUFFER_LENGTH];
  28. ULONG Length, i;
  29. //
  30. // Extract the parameters and check their validity.
  31. //
  32. if ((argc < 2) || (argc > 6) || ((argc & 1) != 0)) {
  33. parameter_error:
  34. printf("Syntax - %s Drive: [-h HostDrive:] [-s SequenceNumber]\n", argv[0]);
  35. return;
  36. }
  37. argv[1][0] = toupper(argv[1][0]);
  38. DasdName[4] = argv[1][0];
  39. DasdName[5] = argv[1][1];
  40. DasdName[6] = argv[1][2];
  41. if ((DasdName[4] < 'A') || (DasdName[4] > 'Z') ||
  42. (DasdName[5] != ':') ||
  43. (DasdName[6] != 0)) {
  44. goto parameter_error;
  45. }
  46. // temp, reject floppies.
  47. /*
  48. if (DasdName[4] < 'C') {
  49. printf("%s does not currently support floppies.\n", argv[0]);
  50. return;
  51. }
  52. */
  53. for (i = 2; i < (ULONG)argc; i+=2) {
  54. if (argv[2][0] != '-') {
  55. goto parameter_error;
  56. } else {
  57. PUCHAR LeftOver;
  58. if (argv[i][2] != 0) {
  59. goto parameter_error;
  60. }
  61. switch(argv[i][1]) {
  62. case 'h':
  63. case 'H':
  64. argv[i+1][0] = toupper(argv[i+1][0]);
  65. strncpy(HostDrive, argv[i+1], 3);
  66. if ((HostDrive[0] < 'A') || (HostDrive[0] > 'Z') ||
  67. (HostDrive[1] != ':') ||
  68. (HostDrive[2] != 0)) {
  69. printf("Illegal argument for 'HostDrive:' of %s.\n\n", argv[i+1]);
  70. goto parameter_error;
  71. }
  72. SetHostDrive = TRUE;
  73. break;
  74. case 's':
  75. case 'S':
  76. SequenceNumber = strtol(argv[i+1], &LeftOver, 10);
  77. if (*LeftOver != 0) {
  78. printf("Illegal argument for 'SequenceNumber:' of %s.\n\n", argv[i+1]);
  79. goto parameter_error;
  80. }
  81. if (SequenceNumber > 254) {
  82. printf("Sequnce number must be in the range 0-254.\n");
  83. goto parameter_error;
  84. }
  85. break;
  86. default:
  87. printf("Illegal option %s specifed.\n", argv[i]);
  88. goto parameter_error;
  89. }
  90. }
  91. }
  92. //
  93. // First check for a conflict on the host drive letter.
  94. //
  95. if (SetHostDrive && (QueryDosDevice(HostDrive, &TmpBuffer[0], BUFFER_LENGTH) != 0)) {
  96. printf("Conflict with host drive. Drive %s already exists.\n", HostDrive);
  97. goto parameter_error;
  98. }
  99. //
  100. // Try to open the drive DASD.
  101. //
  102. Handle = CreateFile( DasdName,
  103. GENERIC_READ,
  104. FILE_SHARE_READ | FILE_SHARE_WRITE,
  105. NULL,
  106. OPEN_EXISTING,
  107. 0,
  108. 0 );
  109. if (Handle == INVALID_HANDLE_VALUE) {
  110. printf("Open of %s failed with error %d.\n", argv[1], GetLastError());
  111. printf("You must be administrator to run dsmount.\n");
  112. return;
  113. }
  114. //
  115. // Now build the unicode filename and attempt the mount.
  116. //
  117. {
  118. OEM_STRING OemCvfName;
  119. UNICODE_STRING UnicodeCvfName;
  120. PFILE_MOUNT_DBLS_BUFFER MountFsctl;
  121. UCHAR MountBuffer[sizeof(FILE_MOUNT_DBLS_BUFFER) + 12*sizeof(WCHAR)];
  122. RXSTATUS Status;
  123. IO_STATUS_BLOCK IoStatus;
  124. MountFsctl = (PFILE_MOUNT_DBLS_BUFFER)MountBuffer;
  125. sprintf(&OemBuffer[9], "%03d", SequenceNumber);
  126. OemCvfName.Length =
  127. OemCvfName.MaximumLength = 12;
  128. OemCvfName.Buffer = OemBuffer;
  129. UnicodeCvfName.MaximumLength = 13*sizeof(WCHAR);
  130. UnicodeCvfName.Buffer = &MountFsctl->CvfName[0];
  131. Status = RtlOemStringToUnicodeString( &UnicodeCvfName, &OemCvfName, FALSE );
  132. if (!NT_SUCCESS(Status)) {
  133. printf("Unicode conversion failed with error 0x%08lx.\n", Status);
  134. CloseHandle( Handle);
  135. return;
  136. }
  137. MountFsctl->CvfNameLength = UnicodeCvfName.Length;
  138. //
  139. // Now issue the DevIoCtrl.
  140. //
  141. Status = NtFsControlFile( Handle,
  142. NULL,
  143. NULL,
  144. NULL,
  145. &IoStatus,
  146. FSCTL_MOUNT_DBLS_VOLUME,
  147. MountFsctl,
  148. 64,
  149. NULL,
  150. 0 );
  151. if (!NT_SUCCESS(Status) || !NT_SUCCESS(IoStatus.Status)) {
  152. if (NT_SUCCESS(Status)) {
  153. Status = IoStatus.Status;
  154. }
  155. printf("Mount failed with error 0x%08lx.\n", Status);
  156. CloseHandle( Handle);
  157. return;
  158. }
  159. }
  160. CloseHandle( Handle);
  161. //
  162. // First get the original base name.
  163. //
  164. Length = QueryDosDevice(argv[1], &TmpBuffer[0], BUFFER_LENGTH);
  165. //
  166. // Now make the host drive link.
  167. //
  168. if (SetHostDrive && !DefineDosDevice( DDD_RAW_TARGET_PATH, &HostDrive[0], &TmpBuffer[0] )) {
  169. printf("Create Host Drive Failed with error: %d\n", GetLastError());
  170. return;
  171. }
  172. //
  173. // and finally create the compressed drive link.
  174. //
  175. TmpBuffer[Length-2] = '.';
  176. RtlCopyMemory( &TmpBuffer[Length-1], OemBuffer, 13 );
  177. if (!DefineDosDevice( DDD_RAW_TARGET_PATH, argv[1], &TmpBuffer[0] )) {
  178. printf("Create Compressed Drive Failed with error: %d\n", GetLastError());
  179. return;
  180. }
  181. //
  182. // Tell the user what we did.
  183. //
  184. printf("The compressed volume file %s\\DBLSPACE.%03d was mounted as %s.\n",
  185. argv[1], SequenceNumber, argv[1]);
  186. if (SetHostDrive) {
  187. printf("The host drive %s contains the original uncompressed volume.\n",
  188. HostDrive);
  189. } else {
  190. printf("No host drive was specified, thus none was created.\n");
  191. }
  192. return;
  193. }