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.

206 lines
4.7 KiB

  1. #include "ulib.hxx"
  2. #include "logrecio.hxx"
  3. #include "attrib.hxx"
  4. #include "mftfile.hxx"
  5. #include "diskedit.h"
  6. extern "C" {
  7. #include "lfs.h"
  8. #include "lfsdisk.h"
  9. #include <stdio.h>
  10. }
  11. const int three = 3;
  12. STATIC LSN Lsn;
  13. BOOLEAN
  14. LOG_RECORD_IO::Setup(
  15. IN PMEM Mem,
  16. IN PLOG_IO_DP_DRIVE Drive,
  17. IN HANDLE Application,
  18. IN HWND WindowHandle,
  19. OUT PBOOLEAN Error
  20. )
  21. {
  22. NTFS_SA ntfssa;
  23. MESSAGE msg;
  24. NTFS_MFT_FILE mft;
  25. ULONG PageOffset;
  26. LONGLONG FileOffset;
  27. BOOLEAN error;
  28. _drive = Drive;
  29. if (!DialogBox((HINSTANCE)Application, TEXT("ReadLogRecordBox"),
  30. WindowHandle, ReadLogRecord)) {
  31. *Error = FALSE;
  32. return FALSE;
  33. }
  34. *Error = TRUE;
  35. if (!_drive ||
  36. !ntfssa.Initialize(_drive, &msg) ||
  37. !ntfssa.Read() ||
  38. !mft.Initialize(_drive, ntfssa.QueryMftStartingLcn(),
  39. ntfssa.QueryClusterFactor(), ntfssa.QueryFrsSize(),
  40. ntfssa.QueryVolumeSectors(), NULL, NULL) ||
  41. !mft.Read() ||
  42. !_frs.Initialize((VCN)LOG_FILE_NUMBER, &mft) ||
  43. !_frs.Read()) {
  44. return FALSE;
  45. }
  46. if (!_frs.QueryAttribute(&_attrib, &error, $DATA, NULL)) {
  47. return FALSE;
  48. }
  49. LfsTruncateLsnToLogPage(Drive, Lsn, &FileOffset);
  50. PageOffset = LfsLsnToPageOffset(Drive, Lsn);
  51. swprintf(_header_text, TEXT("DiskEdit - Log record: page @ %x, offset %x"),
  52. (ULONG)FileOffset, PageOffset);
  53. return TRUE;
  54. }
  55. BOOLEAN
  56. LOG_RECORD_IO::Read(
  57. OUT PULONG pError
  58. )
  59. {
  60. LFS_RECORD_HEADER RecordHeader;
  61. ULONG PageOffset;
  62. LONGLONG FileOffset;
  63. ULONG bytes_read;
  64. ULONG RemainingLength, CurrentPos, ThisPagePortion;
  65. *pError = 0;
  66. (void)GetLogPageSize(_drive);
  67. LfsTruncateLsnToLogPage(_drive, Lsn, &FileOffset);
  68. PageOffset = LfsLsnToPageOffset(_drive, Lsn);
  69. //
  70. // Read in the record header to see how big the total record
  71. // is.
  72. //
  73. if (!_attrib.Read((PVOID)&RecordHeader, ULONG(PageOffset | FileOffset),
  74. LFS_RECORD_HEADER_SIZE, &bytes_read) ||
  75. bytes_read != LFS_RECORD_HEADER_SIZE) {
  76. *pError = _drive->QueryLastNtStatus();
  77. return FALSE;
  78. }
  79. _length = LFS_RECORD_HEADER_SIZE + RecordHeader.ClientDataLength;
  80. if (NULL == (_buffer = MALLOC(_length))) {
  81. *pError = (ULONG)STATUS_INSUFFICIENT_RESOURCES;
  82. return FALSE;
  83. }
  84. RemainingLength = _length;
  85. CurrentPos = 0;
  86. while (RemainingLength > 0) {
  87. ThisPagePortion = MIN(GetLogPageSize(_drive) - PageOffset,
  88. RemainingLength);
  89. if (!_attrib.Read((PUCHAR)_buffer + CurrentPos,
  90. ULONG(FileOffset | PageOffset),
  91. ThisPagePortion, &bytes_read) ||
  92. bytes_read != ThisPagePortion) {
  93. *pError = _drive->QueryLastNtStatus();
  94. return FALSE;
  95. }
  96. CurrentPos += ThisPagePortion;
  97. RemainingLength -= ThisPagePortion;
  98. FileOffset += GetLogPageSize(_drive);
  99. PageOffset = LFS_PACKED_RECORD_PAGE_HEADER_SIZE;
  100. }
  101. return TRUE;
  102. }
  103. BOOLEAN
  104. LOG_RECORD_IO::Write(
  105. )
  106. {
  107. return FALSE;
  108. }
  109. PVOID
  110. LOG_RECORD_IO::GetBuf(
  111. OUT PULONG Size
  112. )
  113. {
  114. if (Size) {
  115. *Size = _length;
  116. }
  117. return _buffer;
  118. }
  119. PTCHAR
  120. LOG_RECORD_IO::GetHeaderText(
  121. )
  122. {
  123. return _header_text;
  124. }
  125. INT_PTR
  126. ReadLogRecord(
  127. IN HWND hDlg,
  128. IN UINT message,
  129. IN WPARAM wParam,
  130. IN LPARAM lParam
  131. )
  132. {
  133. UNREFERENCED_PARAMETER(lParam);
  134. TCHAR buf[1024];
  135. PTCHAR pch;
  136. INT n;
  137. switch (message) {
  138. case WM_INITDIALOG:
  139. swprintf(buf, TEXT("%x:%x"), Lsn.HighPart, Lsn.LowPart);
  140. SetDlgItemText(hDlg, IDTEXT, buf);
  141. return TRUE;
  142. case WM_COMMAND:
  143. if (LOWORD(wParam) == IDCANCEL) {
  144. EndDialog(hDlg, FALSE);
  145. return TRUE;
  146. }
  147. if (LOWORD(wParam) == IDOK) {
  148. n = GetDlgItemText(hDlg, IDTEXT, buf, sizeof(buf)/sizeof(TCHAR));
  149. buf[n] = 0;
  150. if (NULL == (pch = wcschr(buf, ':'))) {
  151. Lsn.HighPart = 0;
  152. swscanf(buf, TEXT("%x"), &Lsn.LowPart);
  153. } else {
  154. *pch = 0;
  155. swscanf(buf, TEXT("%x"), &Lsn.HighPart);
  156. swscanf(pch + 1, TEXT("%x"), &Lsn.LowPart);
  157. *pch = ':';
  158. }
  159. EndDialog(hDlg, TRUE);
  160. return TRUE;
  161. }
  162. break;
  163. }
  164. return FALSE;
  165. }