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.

256 lines
6.0 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. disk.c
  5. Abstract:
  6. Test harness for the disk.cpp module
  7. Author:
  8. John Vert (jvert) 10/10/1996
  9. Revision History:
  10. --*/
  11. #include "stdlib.h"
  12. #include "disk.h"
  13. VOID
  14. DiskFatalError(
  15. IN DWORD MessageId,
  16. IN DWORD ErrCode,
  17. IN LPSTR File,
  18. IN DWORD Line
  19. );
  20. class CTestApp : public CWinApp
  21. {
  22. public:
  23. CTestApp::CTestApp();
  24. virtual BOOL InitInstance();
  25. DECLARE_MESSAGE_MAP()
  26. };
  27. BEGIN_MESSAGE_MAP(CTestApp, CWinApp)
  28. //{{AFX_MSG_MAP(CTestApp)
  29. // NOTE - the ClassWizard will add and remove mapping macros here.
  30. // DO NOT EDIT what you see in these blocks of generated code!
  31. //}}AFX_MSG
  32. END_MESSAGE_MAP()
  33. CTestApp TestApp;
  34. CTestApp::CTestApp()
  35. {
  36. }
  37. VOID
  38. OutputPhysicalPartition(
  39. IN CPhysicalPartition *Partition,
  40. IN DWORD Indent
  41. )
  42. {
  43. LARGE_INTEGER EndingOffset;
  44. DWORD i;
  45. for (i=0; i<Indent; i++) {
  46. printf(" ");
  47. }
  48. printf("%d(%d): ",
  49. Partition->m_Info.PartitionNumber,
  50. Partition->m_Info.PartitionType);
  51. EndingOffset.QuadPart = Partition->m_Info.StartingOffset.QuadPart +
  52. Partition->m_Info.PartitionLength.QuadPart;
  53. if (Partition->m_Info.StartingOffset.HighPart > 0) {
  54. printf("%lx%08lx - ",
  55. Partition->m_Info.StartingOffset.HighPart,
  56. Partition->m_Info.StartingOffset.LowPart);
  57. } else {
  58. printf("%lx - ",Partition->m_Info.StartingOffset.LowPart);
  59. }
  60. if (EndingOffset.HighPart > 0) {
  61. printf("%lx%08lx - ",
  62. EndingOffset.HighPart,
  63. EndingOffset.LowPart);
  64. } else {
  65. printf("%lx - ",EndingOffset.LowPart);
  66. }
  67. printf(" (%dMB)\n", Partition->m_Info.PartitionLength.QuadPart / (1024*1024));
  68. }
  69. VOID
  70. OutputPhysicalDisk(
  71. IN CPhysicalDisk *Disk,
  72. IN DWORD Indent
  73. )
  74. {
  75. DWORD i;
  76. for (i=0; i<Indent; i++) {
  77. printf(" ");
  78. }
  79. printf("%ws Harddisk%d (%08lx) ",
  80. Disk->m_Identifier,
  81. Disk->m_DiskNumber,
  82. Disk->m_Signature);
  83. if (Disk->m_IsSCSI) {
  84. printf("port %d, bus %d, TID %d\n",
  85. Disk->m_ScsiAddress.PortNumber,
  86. Disk->m_ScsiAddress.PathId,
  87. Disk->m_ScsiAddress.TargetId);
  88. } else {
  89. printf(" not SCSI\n");
  90. }
  91. //
  92. // Dump out all the partitions
  93. //
  94. POSITION pos = Disk->m_PartitionList.GetHeadPosition();
  95. while (pos != NULL) {
  96. OutputPhysicalPartition(Disk->m_PartitionList.GetNext(pos), Indent+4);
  97. }
  98. }
  99. VOID
  100. OutputLogicalDisk(
  101. IN CLogicalDrive *Drive,
  102. IN DWORD Indent
  103. )
  104. {
  105. DWORD i;
  106. for (i=0; i<Indent; i++) {
  107. printf(" ");
  108. }
  109. printf("%c: %-16ws\t(%s)\t(%s)\n",
  110. Drive->m_DriveLetter,
  111. (LPCTSTR)Drive->m_VolumeLabel,
  112. Drive->m_IsNTFS ? " NTFS " : "not NTFS",
  113. Drive->m_IsSticky ? " sticky " : "not sticky");
  114. printf("\t%ws\n",(LPCTSTR)Drive->m_Identifier);
  115. }
  116. BOOL
  117. CTestApp::InitInstance()
  118. {
  119. CDiskConfig Config;
  120. BOOL Success;
  121. PFT_INFO ftInfo;
  122. LARGE_INTEGER startingOffset;
  123. LARGE_INTEGER partLength;
  124. DWORD status;
  125. //#define DISKINFO_TEST
  126. #ifdef DISKINFO_TEST
  127. ftInfo = DiskGetFtInfo();
  128. status = DiskAddDiskInfo( ftInfo, 0, 0x385849FB);
  129. printf( "DiskAddDisk status = %u\n", status);
  130. startingOffset.QuadPart = 0x4000;
  131. partLength.QuadPart = 0xFF4FC000I64;
  132. status = DiskAddDriveLetter( ftInfo, 0x385849FB, startingOffset, partLength, 'C');
  133. printf("AddDriveLetter for C: %u\n", status);
  134. startingOffset.QuadPart = 0xFF504000I64;
  135. partLength.QuadPart = 0x5FC000I64;
  136. status = DiskAddDriveLetter( ftInfo, 0x385849FB, startingOffset, partLength, 'G');
  137. printf("AddDriveLetter for G: %u\n", status);
  138. status = DiskAddDiskInfo( ftInfo, 1, 0x19B25E84);
  139. printf( "DiskAddDisk status = %u\n", status);
  140. startingOffset.QuadPart = 0x4000I64;
  141. partLength.QuadPart = 0x7FCFC000I64;
  142. status = DiskAddDriveLetter( ftInfo, 0x19B25E84, startingOffset, partLength, 'D');
  143. printf("AddDriveLetter for D: %u\n", status);
  144. startingOffset.QuadPart = 0x7FD00000I64;
  145. partLength.QuadPart = 0x7FE00000I64;
  146. status = DiskAddDriveLetter( ftInfo, 0x19B25E84, startingOffset, partLength, 'E');
  147. printf("AddDriveLetter for E: %u\n", status);
  148. DiskFreeFtInfo( ftInfo );
  149. return 1;
  150. #endif // DISKINFO_TEST
  151. //
  152. // Initialize the disk configuration
  153. //
  154. Success = Config.Initialize();
  155. if (!Success) {
  156. fprintf(stderr, "Disk initialization failed\n");
  157. }
  158. //
  159. // Display the physical disk configuration
  160. //
  161. printf("Physical disk configuration\n");
  162. POSITION pos = Config.m_PhysicalDisks.GetStartPosition();
  163. while( pos != NULL )
  164. {
  165. CPhysicalDisk* pDisk;
  166. int Index;
  167. Config.m_PhysicalDisks.GetNextAssoc( pos, Index, pDisk );
  168. OutputPhysicalDisk(pDisk,4);
  169. }
  170. //
  171. // Display the logical disk configuration
  172. //
  173. printf("\nLogical disk configuration\n");
  174. pos = Config.m_LogicalDrives.GetStartPosition();
  175. while( pos != NULL )
  176. {
  177. CLogicalDrive* pDisk;
  178. WCHAR Letter;
  179. Config.m_LogicalDrives.GetNextAssoc( pos, Letter, pDisk );
  180. OutputLogicalDisk(pDisk,4);
  181. }
  182. return(1);
  183. }
  184. VOID
  185. DiskErrorFatal(
  186. INT MessageId,
  187. DWORD Error,
  188. LPSTR File,
  189. DWORD Line
  190. )
  191. {
  192. fprintf(stderr, "A fatal error occurred.\n");
  193. fprintf(stderr, "\tMessage %d\n",MessageId);
  194. fprintf(stderr, "\tErrCode %d\n",Error);
  195. fprintf(stderr, "\tFile %s\n, line %d",File, Line);
  196. exit(1);
  197. }
  198. VOID
  199. DiskErrorLogInfo(
  200. PCHAR Format,
  201. ...
  202. )
  203. {
  204. CHAR Buffer[256];
  205. DWORD Bytes;
  206. va_list ArgList;
  207. va_start(ArgList, Format);
  208. vprintf(Format, ArgList);
  209. va_end(ArgList);
  210. }