Leaked source code of windows server 2003
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.

119 lines
2.1 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. sys.h
  5. Abstract:
  6. Contains macros, type and function declarations
  7. used by sys.cpp
  8. Author:
  9. Ryan Burkhardt (ryanburk)
  10. Revision History:
  11. 10 May 2001 :
  12. First crack at it...
  13. --*/
  14. #ifndef _HEADER_SYS_H_
  15. #define _HEADER_SYS_H_
  16. #pragma once
  17. extern "C"
  18. {
  19. #include <nt.h>
  20. #include <ntrtl.h>
  21. #include <nturtl.h>
  22. #include <ntdddisk.h>
  23. #include <ntddstor.h>
  24. }
  25. #include <windows.h>
  26. #include <stdio.h>
  27. #include <iostream>
  28. #include <vector>
  29. #include <tchar.h>
  30. #include <string>
  31. #include <stdlib.h>
  32. #include "disk.h"
  33. //
  34. // Macros
  35. //
  36. #define ELEMENT_COUNT(x) (sizeof(x)/sizeof((x)[0]))
  37. //
  38. // forward declarations
  39. //
  40. class File;
  41. //
  42. // Types
  43. //
  44. //
  45. // Helper dump operators
  46. //
  47. inline
  48. std::ostream& operator<<(std::ostream &os, const std::wstring &str) {
  49. FILE *OutStream = (&os == &std::cerr) ? stderr : stdout;
  50. fputws(str.c_str(), OutStream);
  51. return os;
  52. }
  53. inline
  54. std::ostream& operator<<(std::ostream &os, PCTSTR str) {
  55. return os << std::wstring(str);
  56. }
  57. //
  58. // Exceptions
  59. //
  60. struct ProgramException : public std::exception {
  61. virtual void Dump(std::ostream &os) = 0;
  62. };
  63. //
  64. // Abstracts a Win32 error
  65. //
  66. struct W32Error : public ProgramException {
  67. DWORD ErrorCode;
  68. W32Error(DWORD ErrCode = GetLastError()) : ErrorCode(ErrCode){}
  69. void Dump(std::ostream &os) {
  70. WCHAR MsgBuffer[4096];
  71. MsgBuffer[0] = UNICODE_NULL;
  72. DWORD CharCount = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
  73. NULL,
  74. ErrorCode,
  75. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  76. MsgBuffer,
  77. sizeof(MsgBuffer)/sizeof(WCHAR),
  78. NULL);
  79. if (CharCount) {
  80. std::wstring Msg(MsgBuffer);
  81. os << Msg;
  82. } else {
  83. os << std::hex << ErrorCode;
  84. }
  85. }
  86. };
  87. #define SECTOR_SIZE 512
  88. #endif