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.

286 lines
6.3 KiB

  1. #include "ulib.hxx"
  2. #include "upfile.hxx"
  3. #include "upcase.hxx"
  4. #include "attrio.hxx"
  5. #include "mftfile.hxx"
  6. #include "diskedit.h"
  7. extern "C" {
  8. #include <stdio.h>
  9. }
  10. STATIC ULONG FileNumber = 0;
  11. STATIC ULONG AttributeType = 0;
  12. STATIC TCHAR Name[20];
  13. BOOLEAN
  14. ATTR_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. FARPROC proc;
  23. NTFS_SA ntfssa;
  24. MESSAGE msg;
  25. DSTRING attr_name;
  26. PCWSTRING pcAttrName;
  27. BOOLEAN error;
  28. NTFS_MFT_FILE mft;
  29. NTFS_UPCASE_FILE upcase_file;
  30. NTFS_ATTRIBUTE upcase_attribute;
  31. PNTFS_UPCASE_TABLE upcase_table = NULL;
  32. proc = MakeProcInstance((FARPROC) ReadAttribute, Application);
  33. if (!DialogBox((HINSTANCE)Application, TEXT("ReadAttributeBox"),
  34. WindowHandle, (DLGPROC) proc)) {
  35. *Error = FALSE;
  36. return FALSE;
  37. }
  38. FreeProcInstance(proc);
  39. *Error = TRUE;
  40. if (!Drive) {
  41. return FALSE;
  42. }
  43. if (!ntfssa.Initialize(Drive, &msg) ||
  44. !ntfssa.Read() ||
  45. !mft.Initialize(Drive, ntfssa.QueryMftStartingLcn(),
  46. ntfssa.QueryClusterFactor(), ntfssa.QueryFrsSize(),
  47. ntfssa.QueryVolumeSectors(), NULL, NULL) ||
  48. !mft.Read() ||
  49. !upcase_file.Initialize(mft.GetMasterFileTable()) ||
  50. !upcase_file.Read() ||
  51. !upcase_file.QueryAttribute(&upcase_attribute, &error, $DATA) ||
  52. !(upcase_table = new NTFS_UPCASE_TABLE) ||
  53. !upcase_table->Initialize(&upcase_attribute)
  54. ) {
  55. delete upcase_table;
  56. return FALSE;
  57. }
  58. mft.GetMasterFileTable()->SetUpcaseTable( upcase_table );
  59. if (0 == wcslen(Name)) {
  60. pcAttrName = NULL;
  61. } else {
  62. if (!attr_name.Initialize(Name)) {
  63. return FALSE;
  64. }
  65. pcAttrName = &attr_name;
  66. }
  67. //
  68. // NTFS_FILE_RECORD_SEGMENT::QueryAttribute can't query an
  69. // attribute list, so if that's what we're trying to read we'll
  70. // do things differently.
  71. //
  72. _attr_list_io = (AttributeType == $ATTRIBUTE_LIST);
  73. if (_attr_list_io) {
  74. if (!_hmem.Initialize()) {
  75. return FALSE;
  76. }
  77. if (!_frsstruc.Initialize(&_hmem,
  78. mft.GetMasterFileTable()->GetDataAttribute(), FileNumber,
  79. ntfssa.QueryClusterFactor(),
  80. ntfssa.QueryVolumeSectors(),
  81. ntfssa.QueryFrsSize(),
  82. NULL) ||
  83. !_frsstruc.Read()) {
  84. return FALSE;
  85. }
  86. if (!_frsstruc.QueryAttributeList(&_attr_list)) {
  87. return FALSE;
  88. }
  89. _length = _attr_list.QueryValueLength().GetLowPart();
  90. } else {
  91. if (!_frs.Initialize((VCN)FileNumber, &mft) ||
  92. !_frs.Read()) {
  93. return FALSE;
  94. }
  95. if (!_frs.QueryAttribute(&_attr, &error, AttributeType, pcAttrName)) {
  96. return FALSE;
  97. }
  98. _length = _attr.QueryValueLength().GetLowPart();
  99. }
  100. #if FALSE
  101. {
  102. TCHAR String[128];
  103. wsprintf( String, TEXT("Allocating %x"), _length );
  104. MessageBox( WindowHandle, String, TEXT("ATTR_IO::Setup"), MB_OK|MB_ICONINFORMATION );
  105. }
  106. #endif
  107. _data = Mem->Acquire(_length, Drive->QueryAlignmentMask());
  108. if (NULL == _data) {
  109. _length = min( _length, 4 * 1024 * 1024 );
  110. #if FALSE
  111. {
  112. TCHAR String[128];
  113. wsprintf( String, TEXT("Smaller allocation %x"), _length );
  114. MessageBox( WindowHandle, String, TEXT("ATTR_IO::Setup"), MB_OK|MB_ICONINFORMATION );
  115. }
  116. #endif
  117. _data = Mem->Acquire(_length, Drive->QueryAlignmentMask());
  118. if (NULL == _data) {
  119. return FALSE;
  120. }
  121. wsprintf(_header_text, TEXT("DiskEdit - Reduced Size Attribute %x, %x, \"%s\" "),
  122. FileNumber, AttributeType, Name);
  123. } else {
  124. wsprintf(_header_text, TEXT("DiskEdit - Attribute %x, %x, \"%s\" "),
  125. FileNumber, AttributeType, Name);
  126. }
  127. return TRUE;
  128. }
  129. BOOLEAN
  130. ATTR_IO::Read(
  131. OUT PULONG pError
  132. )
  133. {
  134. ULONG bytes_read;
  135. *pError = 0;
  136. if (_attr_list_io) {
  137. if (!_attr_list.ReadList()) {
  138. return FALSE;
  139. }
  140. memcpy(_data, (PVOID)_attr_list.GetNextAttributeListEntry(NULL),
  141. _length);
  142. return TRUE;
  143. }
  144. if (!_attr.Read(_data, 0, _length, &bytes_read) ||
  145. bytes_read != _length) {
  146. *pError = _drive->QueryLastNtStatus();
  147. return FALSE;
  148. }
  149. return TRUE;
  150. }
  151. BOOLEAN
  152. ATTR_IO::Write(
  153. )
  154. {
  155. ULONG bytes_written;
  156. if (_attr_list_io) {
  157. return _attr_list.WriteList(NULL);
  158. }
  159. return _attr.Write(_data, 0, _length, &bytes_written, NULL) &&
  160. bytes_written == _length;
  161. }
  162. PVOID
  163. ATTR_IO::GetBuf(
  164. OUT PULONG Size
  165. )
  166. {
  167. if (Size) {
  168. *Size = _length;
  169. }
  170. return _data;
  171. }
  172. PTCHAR
  173. ATTR_IO::GetHeaderText(
  174. )
  175. {
  176. return _header_text;
  177. }
  178. BOOL
  179. ReadAttribute(
  180. IN HWND hDlg,
  181. IN UINT message,
  182. IN UINT wParam,
  183. IN LONG lParam
  184. )
  185. {
  186. UNREFERENCED_PARAMETER(lParam);
  187. TCHAR String[128];
  188. extern struct { ULONG Code; PTCHAR Name; } TypeCodeNameTab[];
  189. HWND hCombo;
  190. INT i;
  191. switch (message) {
  192. case WM_INITDIALOG:
  193. hCombo = GetDlgItem(hDlg, IDTEXT2);
  194. for (i = 1; $END != TypeCodeNameTab[i].Code; ++i) {
  195. swprintf(String, TEXT("%x %s"), TypeCodeNameTab[i].Code,
  196. TypeCodeNameTab[i].Name);
  197. SendMessage(hCombo, CB_ADDSTRING, (WPARAM)0, (LPARAM)String);
  198. }
  199. return TRUE;
  200. case WM_COMMAND:
  201. if (LOWORD(wParam) == IDCANCEL) {
  202. EndDialog(hDlg, FALSE);
  203. return TRUE;
  204. }
  205. if (LOWORD(wParam) == IDOK) {
  206. TCHAR buf[1024];
  207. INT n;
  208. n = GetDlgItemText(hDlg, IDTEXT, buf, sizeof(buf)/sizeof(TCHAR));
  209. buf[n] = 0;
  210. swscanf(buf, TEXT("%x"), &FileNumber);
  211. n = GetDlgItemText(hDlg, IDTEXT2, buf, sizeof(buf)/sizeof(TCHAR));
  212. buf[n] = 0;
  213. swscanf(buf, TEXT("%x"), &AttributeType);
  214. n = GetDlgItemText(hDlg, IDTEXT3, buf, sizeof(buf)/sizeof(TCHAR));
  215. buf[n] = 0;
  216. wcscpy(Name, buf);
  217. EndDialog(hDlg, TRUE);
  218. return TRUE;
  219. }
  220. break;
  221. }
  222. return FALSE;
  223. }