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.

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