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.

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