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.

145 lines
2.6 KiB

  1. #include "ulib.hxx"
  2. #include "chainio.hxx"
  3. #include "diskedit.h"
  4. #include "rfatsa.hxx"
  5. extern "C" {
  6. #include <stdio.h>
  7. }
  8. STATIC USHORT StartingCluster = 0;
  9. BOOLEAN
  10. CHAIN_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. REAL_FAT_SA fatsa;
  20. MESSAGE msg;
  21. proc = MakeProcInstance((FARPROC) ReadChain, Application);
  22. if (!DialogBox((HINSTANCE)Application, TEXT("ReadChainBox"),
  23. WindowHandle, (DLGPROC) proc)) {
  24. *Error = FALSE;
  25. return FALSE;
  26. }
  27. FreeProcInstance(proc);
  28. *Error = TRUE;
  29. _drive = Drive;
  30. if (!_drive ||
  31. !StartingCluster ||
  32. !fatsa.Initialize(_drive, &msg) ||
  33. !fatsa.FAT_SA::Read() ||
  34. !_cluster.Initialize(Mem, _drive, &fatsa,
  35. fatsa.GetFat(), StartingCluster)) {
  36. return FALSE;
  37. }
  38. _buffer = _cluster.GetBuf();
  39. _buffer_size = fatsa.QuerySectorsPerCluster()*_drive->QuerySectorSize()*
  40. _cluster.QueryLength();
  41. wsprintf(_header_text, TEXT("DiskEdit - Starting Cluster 0x%X"), StartingCluster);
  42. return TRUE;
  43. }
  44. BOOLEAN
  45. CHAIN_IO::Read(
  46. OUT PULONG pError
  47. )
  48. {
  49. *pError = 0;
  50. if (NULL == _drive) {
  51. return FALSE;
  52. }
  53. if (!_cluster.Read()) {
  54. *pError = _drive->QueryLastNtStatus();
  55. return FALSE;
  56. }
  57. return TRUE;
  58. }
  59. BOOLEAN
  60. CHAIN_IO::Write(
  61. )
  62. {
  63. return _drive ? _cluster.Write() : FALSE;
  64. }
  65. PVOID
  66. CHAIN_IO::GetBuf(
  67. OUT PULONG Size
  68. )
  69. {
  70. if (Size) {
  71. *Size = _buffer_size;
  72. }
  73. return _buffer;
  74. }
  75. PTCHAR
  76. CHAIN_IO::GetHeaderText(
  77. )
  78. {
  79. return _header_text;
  80. }
  81. BOOL
  82. ReadChain(
  83. IN HWND hDlg,
  84. IN UINT message,
  85. IN UINT wParam,
  86. IN LONG lParam
  87. )
  88. {
  89. UNREFERENCED_PARAMETER(lParam);
  90. ULONG tmp;
  91. switch (message) {
  92. case WM_INITDIALOG:
  93. return TRUE;
  94. case WM_COMMAND:
  95. if (LOWORD(wParam) == IDCANCEL) {
  96. EndDialog(hDlg, FALSE);
  97. return TRUE;
  98. }
  99. if (LOWORD(wParam) == IDOK) {
  100. TCHAR buf[1024];
  101. INT n;
  102. n = GetDlgItemText(hDlg, IDTEXT, buf, sizeof(buf)/sizeof(TCHAR));
  103. buf[n] = 0;
  104. swscanf(buf, TEXT("%x"), &tmp);
  105. StartingCluster = (USHORT) tmp;
  106. EndDialog(hDlg, TRUE);
  107. return TRUE;
  108. }
  109. break;
  110. }
  111. return FALSE;
  112. }