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.

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