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.

133 lines
2.4 KiB

  1. #include "ulib.hxx"
  2. #include "secio.hxx"
  3. #include "diskedit.h"
  4. extern "C" {
  5. #include <stdio.h>
  6. }
  7. STATIC ULONG StartSector = 0;
  8. STATIC ULONG NumSectors = 0;
  9. BOOLEAN
  10. SECTOR_IO::Setup(
  11. IN PMEM Mem,
  12. IN PLOG_IO_DP_DRIVE Drive,
  13. IN HANDLE Application,
  14. IN HWND WindowHandle,
  15. OUT PBOOLEAN Error
  16. )
  17. {
  18. if (!DialogBox((HINSTANCE)Application, TEXT("ReadSectorsBox"),
  19. WindowHandle, ReadSectors)) {
  20. *Error = FALSE;
  21. return FALSE;
  22. }
  23. *Error = TRUE;
  24. _drive = Drive;
  25. if (!NumSectors || !_drive) {
  26. return FALSE;
  27. }
  28. if (!_secrun.Initialize(Mem, _drive, StartSector, NumSectors)) {
  29. return FALSE;
  30. }
  31. swprintf(_header_text, TEXT("DiskEdit - Sector 0x%X for 0x%X"),
  32. StartSector, NumSectors);
  33. return TRUE;
  34. }
  35. BOOLEAN
  36. SECTOR_IO::Read(
  37. OUT PULONG pError
  38. )
  39. {
  40. *pError = 0;
  41. if (NULL == _drive) {
  42. return FALSE;
  43. }
  44. if (!_secrun.Read()) {
  45. *pError = _drive->QueryLastNtStatus();
  46. return FALSE;
  47. }
  48. return TRUE;
  49. }
  50. BOOLEAN
  51. SECTOR_IO::Write(
  52. )
  53. {
  54. return _drive ? _secrun.Write() : FALSE;
  55. }
  56. PVOID
  57. SECTOR_IO::GetBuf(
  58. OUT PULONG Size
  59. )
  60. {
  61. if (Size) {
  62. *Size = _drive ? (_drive->QuerySectorSize()*_secrun.QueryLength()) : 0;
  63. }
  64. return _secrun.GetBuf();
  65. }
  66. PTCHAR
  67. SECTOR_IO::GetHeaderText(
  68. )
  69. {
  70. return _header_text;
  71. }
  72. INT_PTR
  73. ReadSectors(
  74. IN HWND hDlg,
  75. IN UINT message,
  76. IN WPARAM wParam,
  77. IN LPARAM lParam
  78. )
  79. {
  80. switch (message) {
  81. case WM_INITDIALOG:
  82. return TRUE;
  83. case WM_COMMAND:
  84. if (LOWORD(wParam) == IDCANCEL) {
  85. EndDialog(hDlg, FALSE);
  86. return TRUE;
  87. }
  88. if (LOWORD(wParam) == IDOK) {
  89. TCHAR buf[1024];
  90. INT n;
  91. n = GetDlgItemText(hDlg, IDTEXT, buf, sizeof(buf)/sizeof(TCHAR));
  92. buf[n] = 0;
  93. swscanf(buf, TEXT("%x"), &StartSector);
  94. n = GetDlgItemText(hDlg, IDTEXT2, buf, sizeof(buf)/sizeof(TCHAR));
  95. buf[n] = 0;
  96. swscanf(buf, TEXT("%x"), &NumSectors);
  97. EndDialog(hDlg, TRUE);
  98. return TRUE;
  99. }
  100. break;
  101. }
  102. return FALSE;
  103. }