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.

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