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.

154 lines
3.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998 - 2000.
  5. //
  6. // File: vmapdump.cxx
  7. //
  8. // Contents: VMAP dump utility
  9. //
  10. // History: 22 Jan 1998 AlanW Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include <vmap.hxx>
  16. DECLARE_INFOLEVEL(ci)
  17. unsigned fVerbose = 0;
  18. int VMapDump( char * pszPath );
  19. int __cdecl main( int argc, char * argv[] )
  20. {
  21. char * pszFile = argv[1];
  22. unsigned cFail = 0;
  23. for ( int i = 1; i < argc; i++ )
  24. {
  25. if ( argv[i][0] == '-' )
  26. {
  27. switch ( argv[i][1] )
  28. {
  29. case 'v':
  30. case 'V':
  31. fVerbose = 1;
  32. break;
  33. #if 0
  34. case 'm':
  35. case 'M':
  36. fReadMetadata = TRUE;
  37. break;
  38. case 'f':
  39. case 'F':
  40. i++;
  41. if ( cField < cMaxFields )
  42. aiField[cField++] = strtol( argv[i], 0, 10 );
  43. break;
  44. #endif // 0
  45. default:
  46. fprintf(stderr, "Usage: file ...\n");
  47. exit(2);
  48. }
  49. continue;
  50. }
  51. else
  52. {
  53. pszFile = argv[i];
  54. cFail += VMapDump(pszFile);
  55. }
  56. }
  57. return cFail != 0;
  58. }
  59. int VMapDump( char * pszPath )
  60. {
  61. HANDLE h = CreateFileA( pszPath,
  62. GENERIC_READ,
  63. FILE_SHARE_READ,
  64. 0,
  65. OPEN_EXISTING,
  66. 0,
  67. 0 );
  68. if ( INVALID_HANDLE_VALUE == h )
  69. {
  70. printf( "Can't open file %s. Error %u\n", pszPath, GetLastError() );
  71. return 1;
  72. }
  73. printf( "fileaddr rec\tparent\ttype\n"
  74. "\t\tvirtual scope\n"
  75. "\t\tphysical scope\n" );
  76. ULONG cbRead;
  77. CVMapDesc VMapDesc;
  78. for ( unsigned i = 0; ; i++ )
  79. {
  80. if ( ! ReadFile( h, &VMapDesc, sizeof VMapDesc, &cbRead, 0 ) )
  81. {
  82. fprintf(stderr, "Error %d reading %s\n", GetLastError(), pszPath );
  83. CloseHandle( h );
  84. return 1;
  85. }
  86. if (cbRead == 0)
  87. break;
  88. if (VMapDesc.IsFree())
  89. continue;
  90. printf("%08x %d.\t%d\t%03x",
  91. i*sizeof VMapDesc, i,
  92. VMapDesc.Parent(), VMapDesc.RootType() );
  93. if (VMapDesc.IsManual())
  94. printf(" ManualRoot");
  95. if (VMapDesc.IsAutomatic())
  96. printf(" AutomaticRoot");
  97. if (VMapDesc.IsInUse())
  98. printf(" UsedRoot");
  99. if (VMapDesc.IsNNTP())
  100. printf(" NNTPRoot");
  101. if (VMapDesc.IsNonIndexedVDir())
  102. printf(" NonIndexedVDir");
  103. if (VMapDesc.IsIMAP())
  104. printf(" IMAPRoot");
  105. printf("\n");
  106. unsigned cchVirtual = VMapDesc.VirtualLength();
  107. unsigned cchPhysical = VMapDesc.PhysicalLength();
  108. if (cchVirtual > MAX_PATH)
  109. {
  110. fprintf(stderr, "Error - Virtual path len too long, %d\n", cchVirtual );
  111. cchVirtual = MAX_PATH;
  112. }
  113. if (cchPhysical > MAX_PATH)
  114. {
  115. fprintf(stderr, "Error - Physical path len too long, %d\n", cchPhysical );
  116. cchPhysical = MAX_PATH;
  117. }
  118. printf("\t\t%*.64ws\n\t\t%*.64ws\n",
  119. cchVirtual, VMapDesc.VirtualPath(),
  120. cchPhysical, VMapDesc.PhysicalPath() );
  121. }
  122. CloseHandle( h );
  123. return 0;
  124. }