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.

108 lines
2.6 KiB

  1. /*****************************************************************************************************************
  2. FILENAME: Devio.cpp
  3. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  4. */
  5. #include "stdafx.h"
  6. #ifdef BOOTIME
  7. #include "Offline.h"
  8. #else
  9. #include <windows.h>
  10. #endif
  11. extern "C" {
  12. #include "SysStruc.h"
  13. }
  14. #ifdef DFRG
  15. #include "DfrgCmn.h"
  16. #include "DfrgEngn.h"
  17. #endif
  18. #include "ErrMacro.h"
  19. #include "DevIo.h"
  20. /****************************************************************************************************************
  21. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  22. ROUTINE DESCRIPTION:
  23. GLOBAL VARIABLES:
  24. None.
  25. INPUT:
  26. RETURN:
  27. /**/
  28. BOOL
  29. WINAPI
  30. ESDeviceIoControl(
  31. IN HANDLE hDevice,
  32. IN DWORD dwIoControlCode,
  33. IN LPVOID lpInBuffer,
  34. IN DWORD nInBufferSize,
  35. IN OUT LPVOID lpOutBuffer,
  36. IN OUT DWORD nOutBufferSize,
  37. OUT LPDWORD lpBytesReturned,
  38. IN OUT LPOVERLAPPED lpOverlapped
  39. )
  40. {
  41. NTSTATUS Status;
  42. IO_STATUS_BLOCK Iosb;
  43. EF_ASSERT(hDevice != NULL && dwIoControlCode != 0);
  44. Status = NtFsControlFile(hDevice,
  45. NULL,
  46. NULL, // APC routine
  47. NULL, // APC Context
  48. &Iosb,
  49. dwIoControlCode, // IoControlCode
  50. lpInBuffer, // Buffer for data to the FS
  51. nInBufferSize, // InputBuffer Length
  52. lpOutBuffer, // OutputBuffer for data from the FS
  53. nOutBufferSize // OutputBuffer Length
  54. );
  55. if ( Status == STATUS_PENDING) {
  56. // Operation must complete before return & Iosb destroyed
  57. Status = NtWaitForSingleObject( hDevice, FALSE, NULL );
  58. if ( NT_SUCCESS(Status)) {
  59. Status = Iosb.Status;
  60. }
  61. }
  62. if ( NT_SUCCESS(Status) ) {
  63. *lpBytesReturned = PtrToUlong((PVOID)Iosb.Information);
  64. return TRUE;
  65. }
  66. else {
  67. // Handle warning value STATUS_BUFFER_OVERFLOW somewhat correctly
  68. if ( !NT_ERROR(Status) ) {
  69. *lpBytesReturned = PtrToUlong((PVOID)Iosb.Information);
  70. }
  71. if(Status == STATUS_BUFFER_OVERFLOW){
  72. SetLastError(ERROR_MORE_DATA);
  73. }
  74. if(Status == STATUS_ALREADY_COMMITTED){
  75. SetLastError(ERROR_RETRY);
  76. }
  77. if(Status == STATUS_INVALID_PARAMETER){
  78. SetLastError(ERROR_INVALID_PARAMETER);
  79. }
  80. if(Status == STATUS_END_OF_FILE){
  81. SetLastError(ERROR_HANDLE_EOF);
  82. }
  83. // BaseSetLastNTError(Status);
  84. return FALSE;
  85. }
  86. }