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.

78 lines
2.3 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <ntddft2.h>
  4. #include <ftapi.h>
  5. HANDLE
  6. FtOpenPartition(
  7. IN ULONG Signature,
  8. IN LONGLONG Offset
  9. )
  10. /*++
  11. Routine Description:
  12. This routine opens the given logical disk.
  13. Arguments:
  14. Signature - Supplies the disk signature.
  15. Offset - Supplies the partition offset.
  16. Return Value:
  17. INVALID_HANDLE_VALUE - Failure.
  18. Otherwise - A handle to the given disk.
  19. --*/
  20. {
  21. UNICODE_STRING string;
  22. OBJECT_ATTRIBUTES oa;
  23. NTSTATUS status;
  24. HANDLE handle;
  25. IO_STATUS_BLOCK ioStatus;
  26. FT_QUERY_NT_DEVICE_NAME_FOR_PARTITION_INPUT input;
  27. ULONG outputSize;
  28. FT_QUERY_NT_DEVICE_NAME_FOR_PARTITION_OUTPUT output[200];
  29. RtlInitUnicodeString(&string, L"\\Device\\FtControl");
  30. InitializeObjectAttributes(&oa, &string, OBJ_CASE_INSENSITIVE, 0, 0);
  31. status = NtOpenFile(&handle,
  32. SYNCHRONIZE | FILE_READ_DATA | FILE_WRITE_DATA,
  33. &oa, &ioStatus, FILE_SHARE_READ | FILE_SHARE_WRITE,
  34. FILE_SYNCHRONOUS_IO_ALERT);
  35. if (!NT_SUCCESS(status)) {
  36. return (HANDLE) -1;
  37. }
  38. input.Signature = Signature;
  39. input.Offset = Offset;
  40. outputSize = 200*sizeof(FT_QUERY_NT_DEVICE_NAME_FOR_PARTITION_OUTPUT);
  41. status = NtDeviceIoControlFile(handle, 0, NULL, NULL, &ioStatus,
  42. FT_QUERY_NT_DEVICE_NAME_FOR_PARTITION,
  43. &input, sizeof(input), output, outputSize);
  44. NtClose(handle);
  45. if (!NT_SUCCESS(status)) {
  46. return (HANDLE) -1;
  47. }
  48. string.MaximumLength = string.Length =
  49. output[0].NumberOfCharactersInNtDeviceName*sizeof(WCHAR);
  50. string.Buffer = output[0].NtDeviceName;
  51. InitializeObjectAttributes(&oa, &string, OBJ_CASE_INSENSITIVE, 0, 0);
  52. status = NtOpenFile(&handle,
  53. SYNCHRONIZE | FILE_READ_DATA | FILE_WRITE_DATA,
  54. &oa, &ioStatus, FILE_SHARE_READ | FILE_SHARE_WRITE,
  55. FILE_SYNCHRONOUS_IO_ALERT);
  56. if (!NT_SUCCESS(status)) {
  57. return (HANDLE) -1;
  58. }
  59. return handle;
  60. }