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.

164 lines
3.1 KiB

  1. #include "ulib.hxx"
  2. #include "ntfssa.hxx"
  3. #include "clusio.hxx"
  4. #include "diskedit.h"
  5. extern "C" {
  6. #include <stdio.h>
  7. }
  8. STATIC ULONG StartCluster = 0;
  9. STATIC ULONG NumClusters = 1;
  10. BOOLEAN
  11. CLUSTER_IO::Setup(
  12. IN PMEM Mem,
  13. IN PLOG_IO_DP_DRIVE Drive,
  14. IN HANDLE Application,
  15. IN HWND WindowHandle,
  16. OUT PBOOLEAN Error
  17. )
  18. {
  19. FARPROC proc;
  20. HMEM mem;
  21. MESSAGE msg;
  22. proc = MakeProcInstance((FARPROC) ReadClusters, Application);
  23. if (!DialogBox((HINSTANCE)Application, TEXT("ReadClustersBox"),
  24. WindowHandle, (DLGPROC) proc)) {
  25. *Error = FALSE;
  26. return FALSE;
  27. }
  28. FreeProcInstance(proc);
  29. *Error = TRUE;
  30. _drive = Drive;
  31. if (!NumClusters || !_drive) {
  32. return FALSE;
  33. }
  34. PPACKED_BOOT_SECTOR p;
  35. BIOS_PARAMETER_BLOCK bpb;
  36. ULONG ClusterFactor;
  37. //
  38. // Read the boot sector.
  39. //
  40. if (!_secrun.Initialize(&mem, _drive, 0, 1) || !_secrun.Read()) {
  41. return FALSE;
  42. }
  43. p = (PPACKED_BOOT_SECTOR)_secrun.GetBuf();
  44. UnpackBios(&bpb, &(p->PackedBpb));
  45. ClusterFactor = bpb.SectorsPerCluster;
  46. if (!_secrun.Initialize(Mem, _drive,
  47. StartCluster*ClusterFactor,
  48. NumClusters*ClusterFactor)) {
  49. return FALSE;
  50. }
  51. swprintf(_header_text, TEXT("DiskEdit - Cluster 0x%X for 0x%X"), StartCluster, NumClusters);
  52. return TRUE;
  53. }
  54. BOOLEAN
  55. CLUSTER_IO::Read(
  56. OUT PULONG pError
  57. )
  58. {
  59. *pError = 0;
  60. if (NULL == _drive) {
  61. return FALSE;
  62. }
  63. if (!_secrun.Read()) {
  64. *pError = _drive->QueryLastNtStatus();
  65. return FALSE;
  66. }
  67. return TRUE;
  68. }
  69. BOOLEAN
  70. CLUSTER_IO::Write(
  71. )
  72. {
  73. return _drive ? _secrun.Write() : FALSE;
  74. }
  75. PVOID
  76. CLUSTER_IO::GetBuf(
  77. OUT PULONG Size
  78. )
  79. {
  80. if (Size) {
  81. *Size = _drive ? (_drive->QuerySectorSize()*_secrun.QueryLength()) : 0;
  82. }
  83. return _secrun.GetBuf();
  84. }
  85. PTCHAR
  86. CLUSTER_IO::GetHeaderText(
  87. )
  88. {
  89. return _header_text;
  90. }
  91. BOOL
  92. ReadClusters(
  93. IN HWND hDlg,
  94. IN UINT message,
  95. IN UINT wParam,
  96. IN LONG lParam
  97. )
  98. {
  99. TCHAR buf[1024];
  100. switch (message) {
  101. case WM_INITDIALOG:
  102. wsprintf(buf, TEXT("%x"), StartCluster);
  103. SetDlgItemText(hDlg, IDTEXT, buf);
  104. wsprintf(buf, TEXT("%x"), NumClusters);
  105. SetDlgItemText(hDlg, IDTEXT2, buf);
  106. return TRUE;
  107. case WM_COMMAND:
  108. if (LOWORD(wParam) == IDCANCEL) {
  109. EndDialog(hDlg, FALSE);
  110. return TRUE;
  111. }
  112. if (LOWORD(wParam) == IDOK) {
  113. INT n;
  114. n = GetDlgItemText(hDlg, IDTEXT, buf, sizeof(buf)/sizeof(TCHAR));
  115. buf[n] = 0;
  116. swscanf(buf, TEXT("%x"), &StartCluster);
  117. n = GetDlgItemText(hDlg, IDTEXT2, buf, sizeof(buf)/sizeof(TCHAR));
  118. buf[n] = 0;
  119. swscanf(buf, TEXT("%x"), &NumClusters);
  120. EndDialog(hDlg, TRUE);
  121. return TRUE;
  122. }
  123. break;
  124. }
  125. return FALSE;
  126. }