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.

136 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. FARPROC proc;
  19. proc = MakeProcInstance((FARPROC) ReadSectors, Application);
  20. if (!DialogBox((HINSTANCE)Application, TEXT("ReadSectorsBox"),
  21. WindowHandle, (DLGPROC) proc)) {
  22. *Error = FALSE;
  23. return FALSE;
  24. }
  25. FreeProcInstance(proc);
  26. *Error = TRUE;
  27. _drive = Drive;
  28. if (!NumSectors || !_drive) {
  29. return FALSE;
  30. }
  31. if (!_secrun.Initialize(Mem, _drive, StartSector, NumSectors)) {
  32. return FALSE;
  33. }
  34. swprintf(_header_text, TEXT("DiskEdit - Sector 0x%X for 0x%X"),
  35. StartSector, NumSectors);
  36. return TRUE;
  37. }
  38. BOOLEAN
  39. SECTOR_IO::Read(
  40. OUT PULONG pError
  41. )
  42. {
  43. *pError = 0;
  44. if (NULL == _drive) {
  45. return FALSE;
  46. }
  47. if (!_secrun.Read()) {
  48. *pError = _drive->QueryLastNtStatus();
  49. return FALSE;
  50. }
  51. return TRUE;
  52. }
  53. BOOLEAN
  54. SECTOR_IO::Write(
  55. )
  56. {
  57. return _drive ? _secrun.Write() : FALSE;
  58. }
  59. PVOID
  60. SECTOR_IO::GetBuf(
  61. OUT PULONG Size
  62. )
  63. {
  64. if (Size) {
  65. *Size = _drive ? (_drive->QuerySectorSize()*_secrun.QueryLength()) : 0;
  66. }
  67. return _secrun.GetBuf();
  68. }
  69. PTCHAR
  70. SECTOR_IO::GetHeaderText(
  71. )
  72. {
  73. return _header_text;
  74. }
  75. BOOL
  76. ReadSectors(
  77. IN HWND hDlg,
  78. IN UINT message,
  79. IN UINT wParam,
  80. IN LONG lParam
  81. )
  82. {
  83. switch (message) {
  84. case WM_INITDIALOG:
  85. return TRUE;
  86. case WM_COMMAND:
  87. if (LOWORD(wParam) == IDCANCEL) {
  88. EndDialog(hDlg, FALSE);
  89. return TRUE;
  90. }
  91. if (LOWORD(wParam) == IDOK) {
  92. TCHAR buf[1024];
  93. INT n;
  94. n = GetDlgItemText(hDlg, IDTEXT, buf, sizeof(buf)/sizeof(TCHAR));
  95. buf[n] = 0;
  96. swscanf(buf, TEXT("%x"), &StartSector);
  97. n = GetDlgItemText(hDlg, IDTEXT2, buf, sizeof(buf)/sizeof(TCHAR));
  98. buf[n] = 0;
  99. swscanf(buf, TEXT("%x"), &NumSectors);
  100. EndDialog(hDlg, TRUE);
  101. return TRUE;
  102. }
  103. break;
  104. }
  105. return FALSE;
  106. }