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.

146 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. spti.h
  5. Abstract:
  6. These are the structures and defines that are used in the
  7. SPTI.C.
  8. Author:
  9. Revision History:
  10. --*/
  11. #include <sptlib.h>
  12. #include <conio.h> // for printf, _getch, etc.
  13. #include <strsafe.h> // safer string functions
  14. #if defined(_X86_)
  15. #define PAGE_SIZE 0x1000
  16. #define PAGE_SHIFT 12L
  17. #elif defined(_AMD64_)
  18. #define PAGE_SIZE 0x1000
  19. #define PAGE_SHIFT 12L
  20. #elif defined(_IA64_)
  21. #define PAGE_SIZE 0x2000
  22. #define PAGE_SHIFT 13L
  23. #else
  24. // undefined platform?
  25. #define PAGE_SIZE 0x1000
  26. #define PAGE_SHIFT 12L
  27. #endif
  28. #define MAXIMUM_BUFFER_SIZE 0x990 // 2448, largest single CD sector size, smaller than one page
  29. #define MIN(_a,_b) (((_a) <= (_b)) ? (_a) : (_b))
  30. #define MAX(_a,_b) (((_a) >= (_b)) ? (_a) : (_b))
  31. //
  32. // neat little hacks to count number of bits set
  33. //
  34. __inline ULONG CountOfSetBits(ULONG _X)
  35. { ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; }
  36. __inline ULONG CountOfSetBits32(ULONG32 _X)
  37. { ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; }
  38. __inline ULONG CountOfSetBits64(ULONG64 _X)
  39. { ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; }
  40. #define SET_FLAG(Flags, Bit) ((Flags) |= (Bit))
  41. #define CLEAR_FLAG(Flags, Bit) ((Flags) &= ~(Bit))
  42. #define TEST_FLAG(Flags, Bit) (((Flags) & (Bit)) != 0)
  43. #define BOOLEAN_TO_STRING(_b_) \
  44. ( (_b_) ? "True" : "False" )
  45. typedef struct SPT_ALIGNED_MEMORY {
  46. PVOID A; // aligned pointer
  47. PVOID U; // unaligned pointer
  48. PUCHAR File; // file allocated from
  49. ULONG Line; // line number allocated from
  50. } SPT_ALIGNED_MEMORY, *PSPT_ALIGNED_MEMORY;
  51. //
  52. // Allocates a device-aligned buffer
  53. //
  54. #define AllocateAlignedBuffer(Allocation,AlignmentMask,Size) \
  55. pAllocateAlignedBuffer(Allocation,AlignmentMask,Size,__FILE__, __LINE__)
  56. BOOL
  57. pAllocateAlignedBuffer(
  58. PSPT_ALIGNED_MEMORY Allocation,
  59. ULONG AlignmentMask,
  60. SIZE_T AllocationSize,
  61. PUCHAR File,
  62. ULONG Line
  63. );
  64. //
  65. // Free's a previously-allocated aligned buffer
  66. //
  67. VOID
  68. FreeAlignedBuffer(
  69. PSPT_ALIGNED_MEMORY Allocation
  70. );
  71. //
  72. // Prints a buffer to the screen in hex and ASCII
  73. //
  74. VOID
  75. PrintBuffer(
  76. IN PVOID InputBuffer,
  77. IN SIZE_T Size
  78. );
  79. //
  80. // Prints the formatted message for a given error code
  81. //
  82. VOID
  83. PrintError(
  84. ULONG Error
  85. );
  86. //
  87. // Prints the device descriptor in a formatted manner
  88. //
  89. VOID
  90. PrintDeviceDescriptor(
  91. PSTORAGE_DEVICE_DESCRIPTOR DeviceDescriptor
  92. );
  93. //
  94. // Prints the adapter descriptor in a formatted manner
  95. //
  96. VOID
  97. PrintAdapterDescriptor(
  98. PSTORAGE_ADAPTER_DESCRIPTOR AdapterDescriptor
  99. );
  100. //
  101. // Gets (and prints) the device and adapter descriptor
  102. // for a device. Returns the alignment mask (required
  103. // for allocating a properly aligned buffer).
  104. //
  105. BOOL
  106. GetAlignmentMaskForDevice(
  107. HANDLE DeviceHandle,
  108. PULONG AlignmentMask
  109. );
  110. #if 0
  111. VOID PrintInquiryData(PVOID);
  112. VOID PrintStatusResults(BOOL, DWORD, PSCSI_PASS_THROUGH_WITH_BUFFERS, ULONG);
  113. VOID PrintSenseInfo(PSCSI_PASS_THROUGH_WITH_BUFFERS);
  114. #endif //0