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.

225 lines
6.9 KiB

  1. #include "ulib.hxx"
  2. #include "frsio.hxx"
  3. #include "drive.hxx"
  4. #include "ifssys.hxx"
  5. #include "ntfssa.hxx"
  6. #include "frs.hxx"
  7. #include "attrib.hxx"
  8. #include "mftfile.hxx"
  9. #include "bitfrs.hxx"
  10. #include "ntfsbit.hxx"
  11. #include "upfile.hxx"
  12. #include "upcase.hxx"
  13. #include "diskedit.h"
  14. extern "C" {
  15. #include <stdio.h>
  16. }
  17. extern PLOG_IO_DP_DRIVE Drive;
  18. STATIC ULONG FileNumber = 0;
  19. BOOLEAN
  20. FRS_IO::Setup(
  21. IN PMEM Mem,
  22. IN PLOG_IO_DP_DRIVE Drive,
  23. IN HANDLE Application,
  24. IN HWND WindowHandle,
  25. OUT PBOOLEAN Error
  26. )
  27. {
  28. NTFS_SA ntfssa;
  29. MESSAGE msg;
  30. HMEM hmem;
  31. if (!DialogBox((HINSTANCE)Application, TEXT("ReadFrsBox"),
  32. WindowHandle, ReadFrs)) {
  33. *Error = FALSE;
  34. return FALSE;
  35. }
  36. *Error = TRUE;
  37. _drive = Drive;
  38. if (!_drive) {
  39. return FALSE;
  40. }
  41. if (!ntfssa.Initialize(_drive, &msg) ||
  42. !ntfssa.Read() ||
  43. !hmem.Initialize() ||
  44. !_frs.Initialize(&hmem, _drive,
  45. ntfssa.QueryMftStartingLcn(),
  46. ntfssa.QueryClusterFactor(),
  47. ntfssa.QueryVolumeSectors(),
  48. ntfssa.QueryFrsSize(),
  49. NULL) ||
  50. !_frs.Read() ||
  51. !_frs.SafeQueryAttribute($DATA, &_mftdata, &_mftdata) ||
  52. !_frs.Initialize(Mem, &_mftdata, FileNumber,
  53. ntfssa.QueryClusterFactor(),
  54. ntfssa.QueryVolumeSectors(),
  55. ntfssa.QueryFrsSize(),
  56. NULL)) {
  57. return FALSE;
  58. }
  59. swprintf(_header_text, TEXT("DiskEdit - File Record 0x%X"), FileNumber);
  60. return TRUE;
  61. }
  62. BOOLEAN
  63. FRS_IO::Read(
  64. OUT PULONG pError
  65. )
  66. {
  67. *pError = 0;
  68. if (NULL == _drive) {
  69. return FALSE;
  70. }
  71. if (!_frs.Read()) {
  72. *pError = _drive->QueryLastNtStatus();
  73. return FALSE;
  74. }
  75. return TRUE;
  76. }
  77. BOOLEAN
  78. FRS_IO::Write(
  79. )
  80. {
  81. return _drive ? _frs.Write() : FALSE;
  82. }
  83. PVOID
  84. FRS_IO::GetBuf(
  85. OUT PULONG Size
  86. )
  87. {
  88. if (Size) {
  89. *Size = _frs.QuerySize();
  90. }
  91. return *((PVOID*) ((PCHAR) &_frs + 2*sizeof(PVOID)));
  92. }
  93. PTCHAR
  94. FRS_IO::GetHeaderText(
  95. )
  96. {
  97. return _header_text;
  98. }
  99. INT_PTR
  100. ReadFrs(
  101. IN HWND hDlg,
  102. IN UINT message,
  103. IN WPARAM wParam,
  104. IN LPARAM lParam
  105. )
  106. {
  107. UNREFERENCED_PARAMETER(lParam);
  108. switch (message) {
  109. case WM_INITDIALOG:
  110. SetDlgItemText( hDlg, IDVOLUME, Drive->GetNtDriveName()->GetWSTR() );
  111. CheckDlgButton( hDlg, IDRADIO1, BST_CHECKED );
  112. return TRUE;
  113. case WM_COMMAND:
  114. if (LOWORD(wParam) == IDCANCEL) {
  115. EndDialog(hDlg, FALSE);
  116. return TRUE;
  117. }
  118. if (LOWORD(wParam) == IDOK) {
  119. TCHAR buf[1024];
  120. INT n;
  121. n = GetDlgItemText(hDlg, IDTEXT, buf, sizeof(buf)/sizeof(TCHAR));
  122. buf[n] = 0;
  123. if (IsDlgButtonChecked( hDlg, IDRADIO2)) {
  124. swscanf(buf, TEXT("%x"), &FileNumber);
  125. } else {
  126. DSTRING path;
  127. NTFS_SA ntfssa;
  128. MESSAGE msg;
  129. NTFS_MFT_FILE mft;
  130. NTFS_BITMAP_FILE bitmap_file;
  131. NTFS_ATTRIBUTE bitmap_attribute;
  132. NTFS_BITMAP volume_bitmap;
  133. NTFS_UPCASE_FILE upcase_file;
  134. NTFS_ATTRIBUTE upcase_attribute;
  135. NTFS_UPCASE_TABLE upcase_table;
  136. NTFS_FILE_RECORD_SEGMENT file_record;
  137. BOOLEAN error;
  138. BOOLEAN system_file;
  139. if (!path.Initialize(buf)) {
  140. wsprintf(buf, TEXT("Out of memory"));
  141. MessageBox(hDlg, buf, TEXT("DiskEdit"), MB_OK|MB_ICONEXCLAMATION);
  142. return FALSE;
  143. } else if (!Drive ||
  144. !ntfssa.Initialize(Drive, &msg) ||
  145. !ntfssa.Read() ||
  146. !mft.Initialize(Drive, ntfssa.QueryMftStartingLcn(),
  147. ntfssa.QueryClusterFactor(),
  148. ntfssa.QueryFrsSize(),
  149. ntfssa.QueryVolumeSectors(), NULL, NULL) ||
  150. !mft.Read() ||
  151. !bitmap_file.Initialize(mft.GetMasterFileTable()) ||
  152. !bitmap_file.Read() ||
  153. !bitmap_file.QueryAttribute(&bitmap_attribute, &error, $DATA) ||
  154. !volume_bitmap.Initialize(ntfssa.QueryVolumeSectors() /
  155. (ULONG) ntfssa.QueryClusterFactor(), FALSE, NULL, 0) ||
  156. !volume_bitmap.Read(&bitmap_attribute) ||
  157. !upcase_file.Initialize(mft.GetMasterFileTable()) ||
  158. !upcase_file.Read() ||
  159. !upcase_file.QueryAttribute(&upcase_attribute, &error, $DATA) ||
  160. !upcase_table.Initialize(&upcase_attribute) ||
  161. !mft.Initialize(Drive, ntfssa.QueryMftStartingLcn(),
  162. ntfssa.QueryClusterFactor(),
  163. ntfssa.QueryFrsSize(),
  164. ntfssa.QueryVolumeSectors(),
  165. &volume_bitmap,
  166. &upcase_table) ||
  167. !mft.Read()) {
  168. swprintf(buf, TEXT("Could not init NTFS data structures"));
  169. MessageBox(hDlg, buf, TEXT("DiskEdit"), MB_OK|MB_ICONEXCLAMATION);
  170. return FALSE;
  171. } else if (!ntfssa.QueryFrsFromPath(&path, mft.GetMasterFileTable(),
  172. &volume_bitmap, &file_record, &system_file, &error)) {
  173. wsprintf(buf, TEXT("File not found."));
  174. MessageBox(hDlg, buf, TEXT("DiskEdit"), MB_OK|MB_ICONINFORMATION);
  175. return FALSE;
  176. } else {
  177. FileNumber = file_record.QueryFileNumber().GetLowPart();
  178. }
  179. }
  180. EndDialog(hDlg, TRUE);
  181. return TRUE;
  182. }
  183. break;
  184. }
  185. return FALSE;
  186. }