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.

210 lines
5.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: dumplog.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // Coupling:
  15. //
  16. // Notes:
  17. //
  18. // History: 2-05-2000 benl Created
  19. //
  20. //----------------------------------------------------------------------------
  21. #include <windows.h>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. typedef struct _SYSCACHE_LOG {
  25. int Event;
  26. int Flags;
  27. LONGLONG Start;
  28. LONGLONG Range;
  29. LONGLONG Result;
  30. // ULONG ulDump;
  31. } SYSCACHE_LOG, *PSYSCACHE_LOG;
  32. typedef struct _ON_DISK_SYSCACHE_LOG {
  33. ULONG SegmentNumberUnsafe;
  34. ULONG Reserved;
  35. int Event;
  36. int Flags;
  37. LONGLONG Start;
  38. LONGLONG Range;
  39. LONGLONG Result;
  40. } ON_DISK_SYSCACHE_LOG, *PON_DISK_SYSCACHE_LOG;
  41. #define SCE_VDL_CHANGE 0
  42. #define SCE_ZERO_NC 1
  43. #define SCE_ZERO_C 2
  44. #define SCE_READ 3
  45. #define SCE_WRITE 4
  46. #define SCE_ZERO_CAV 5
  47. #define SCE_ZERO_MF 6
  48. #define SCE_ZERO_FST 7
  49. #define SCE_CC_FLUSH 8
  50. #define SCE_CC_FLUSH_AND_PURGE 9
  51. #define SCE_WRITE_FILE_SIZES 10
  52. #define SCE_MAX_EVENT 11
  53. #define SCE_FLAG_WRITE 0x1
  54. #define SCE_FLAG_READ 0x2
  55. #define SCE_FLAG_PAGING 0x4
  56. #define SCE_FLAG_ASYNC 0x8
  57. #define SCE_FLAG_SET_ALLOC 0x10
  58. #define SCE_FLAG_SET_EOF 0x20
  59. #define SCE_FLAG_CANT_WAIT 0x40
  60. #define SCE_FLAG_SYNC_PAGING 0x80
  61. #define SCE_FLAG_LAZY_WRITE 0x100
  62. #define SCE_FLAG_CACHED 0x200
  63. #define SCE_FLAG_ON_DISK_READ 0x400
  64. #define SCE_FLAG_RECURSIVE 0x800
  65. #define SCE_FLAG_NON_CACHED 0x1000
  66. #define SCE_FLAG_UPDATE_FROM_DISK 0x2000
  67. #define SCE_MAX_FLAG 0x4000
  68. char * LogEvent[] =
  69. {
  70. "SCE_VDL_CHANGE",
  71. "SCE_ZERO_NC",
  72. "SCE_ZERO_C",
  73. "SCE_READ",
  74. "SCE_WRITE",
  75. "SCE_ZERO_CAV",
  76. "SCE_ZERO_MF",
  77. "SCE_ZERO_FST",
  78. "SCE_CC_FLUSH",
  79. "SCE_CC_FLUSH_AND_PURGE",
  80. "SCE_WRITE_FILE_SIZES",
  81. "SCE_MAX_EVENT"
  82. };
  83. void __cdecl main (int argc, char *argv[])
  84. {
  85. HANDLE hFile;
  86. TCHAR szName[] = "c:\\$ntfs.log";
  87. UCHAR szBuffer[ 0x1000 ];
  88. PON_DISK_SYSCACHE_LOG pEntry;
  89. ULONG ulRet;
  90. int iIndex;
  91. if (argc < 2 || argv[1][0] == '\0') {
  92. printf( "Utility to dump $ntfs.log\n" );
  93. printf( "Usage: dumpsyscachelog drive:\n" );
  94. return;
  95. }
  96. szName[0] = argv[1][0];
  97. hFile = CreateFile( szName,
  98. GENERIC_READ,
  99. FILE_SHARE_READ | FILE_SHARE_WRITE,
  100. NULL,
  101. OPEN_EXISTING,
  102. FILE_ATTRIBUTE_NORMAL,
  103. NULL );
  104. if (INVALID_HANDLE_VALUE == hFile) {
  105. printf( "Open of %s failed %d\n", szName, GetLastError() );
  106. return;
  107. }
  108. do {
  109. if (!ReadFile( hFile,
  110. &szBuffer,
  111. sizeof( szBuffer ),
  112. &ulRet,
  113. NULL )) {
  114. printf( "ReadFile failed %d\n", GetLastError() );
  115. return;
  116. }
  117. pEntry = (PON_DISK_SYSCACHE_LOG)szBuffer;
  118. for (iIndex=0; iIndex < 0x1000 / sizeof( ON_DISK_SYSCACHE_LOG ); iIndex++) {
  119. //
  120. // Breakout if the segref is 0, we're at the end of the log
  121. //
  122. if (pEntry->SegmentNumberUnsafe == 0) {
  123. return;
  124. } else {
  125. printf( "File: 0x%x ", pEntry->SegmentNumberUnsafe );
  126. }
  127. if (pEntry->Event < SCE_MAX_EVENT) {
  128. printf( "(%s)\n", LogEvent[pEntry->Event] );
  129. } else {
  130. printf( "\n" );
  131. }
  132. printf( "Flags: 0x%x (", pEntry->Flags);
  133. if (pEntry->Flags & SCE_FLAG_WRITE) {
  134. printf( "write " );
  135. }
  136. if (pEntry->Flags & SCE_FLAG_READ) {
  137. printf( "read " );
  138. }
  139. if (pEntry->Flags & SCE_FLAG_PAGING) {
  140. printf( "paging io " );
  141. }
  142. if (pEntry->Flags & SCE_FLAG_ASYNC) {
  143. printf( "asyncfileobj " );
  144. }
  145. if (pEntry->Flags & SCE_FLAG_SET_ALLOC) {
  146. printf( "setalloc " );
  147. }
  148. if (pEntry->Flags & SCE_FLAG_SET_EOF) {
  149. printf( "seteof " );
  150. }
  151. if (pEntry->Flags & SCE_FLAG_CANT_WAIT) {
  152. printf( "cantwait ");
  153. }
  154. if (pEntry->Flags & SCE_FLAG_SYNC_PAGING) {
  155. printf( "synchpaging " );
  156. }
  157. if (pEntry->Flags & SCE_FLAG_LAZY_WRITE) {
  158. printf( "lazywrite " );
  159. }
  160. if (pEntry->Flags & SCE_FLAG_CACHED) {
  161. printf( "cached " );
  162. }
  163. if (pEntry->Flags & SCE_FLAG_ON_DISK_READ) {
  164. printf( "fromdisk " );
  165. }
  166. if (pEntry->Flags & SCE_FLAG_RECURSIVE) {
  167. printf( "recursive " );
  168. }
  169. if (pEntry->Flags & SCE_FLAG_NON_CACHED) {
  170. printf( "noncached " );
  171. }
  172. if (pEntry->Flags & SCE_FLAG_UPDATE_FROM_DISK) {
  173. printf( "updatefromdisk " );
  174. }
  175. printf(")\n");
  176. printf("Start: 0x%I64x Range: 0x%I64x Result: 0x%I64x\n\n",
  177. pEntry->Start, pEntry->Range, pEntry->Result);
  178. pEntry++;
  179. } // endfor
  180. } while ( TRUE );
  181. }