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.

236 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1992-2000 Microsoft Corporation
  3. Module Name:
  4. SecList.cxx
  5. Abstract:
  6. Sector list utility
  7. Author:
  8. Bill McJohn (billmc) 30-July-92
  9. Revision History:
  10. --*/
  11. #define _NTAPI_ULIB_
  12. #include "ulib.hxx"
  13. #include "wstring.hxx"
  14. #include "path.hxx"
  15. #include "smsg.hxx"
  16. #include "system.hxx"
  17. #include "ifssys.hxx"
  18. #include "substrng.hxx"
  19. #include "ulibcl.hxx"
  20. #include "keyboard.hxx"
  21. #include "fatvol.hxx"
  22. #include "fatsa.hxx"
  23. #include "rfatsa.hxx"
  24. #include "fat.hxx"
  25. extern "C" {
  26. #include <stdio.h>
  27. }
  28. BOOLEAN HexOutput = FALSE;
  29. BOOLEAN
  30. FatSecList(
  31. PWSTRING NtDriveName,
  32. PPATH TargetPath,
  33. PMESSAGE Message
  34. )
  35. {
  36. LOG_IO_DP_DRIVE Drive;
  37. REAL_FAT_SA FatSa;
  38. PFAT Fat;
  39. ULONG SectorsPerCluster, Sector, i;
  40. ULONG Cluster;
  41. if( !Drive.Initialize( NtDriveName, Message ) ||
  42. !FatSa.Initialize( &Drive, Message ) ||
  43. !FatSa.FAT_SA::Read() ||
  44. !(Fat = FatSa.GetFat()) ) {
  45. return FALSE;
  46. }
  47. SectorsPerCluster = FatSa.QuerySectorsPerCluster();
  48. Cluster = FatSa.QueryFileStartingCluster( TargetPath->GetPathString() );
  49. if( Cluster == 1 || Cluster == 0xFFFF ) {
  50. printf( "File not found.\n" );
  51. return FALSE;
  52. }
  53. if( Cluster == 0 ) {
  54. // Zero-length file.
  55. //
  56. return TRUE;
  57. }
  58. while( TRUE ) {
  59. Sector = (Cluster - FirstDiskCluster) * SectorsPerCluster +
  60. FatSa.QueryStartDataLbn();
  61. for( i = 0; i < SectorsPerCluster; i++ ) {
  62. if( HexOutput ) {
  63. printf( "0x%x\n", Sector + i );
  64. } else {
  65. printf( "%d\n", Sector + i );
  66. }
  67. }
  68. if( Fat->IsEndOfChain( Cluster ) ) {
  69. break;
  70. }
  71. Cluster = Fat->QueryEntry( Cluster );
  72. }
  73. return TRUE;
  74. }
  75. int __cdecl
  76. main(
  77. int argc,
  78. char **argv
  79. )
  80. /*++
  81. --*/
  82. {
  83. WCHAR PathString[512];
  84. STR DisplayBuffer[512];
  85. PATH Path;
  86. DSTRING NtDriveName, FsName, HpfsString, NtfsString, FatString;
  87. STREAM_MESSAGE Message;
  88. PWSTRING DosDriveName;
  89. NTSTATUS Status;
  90. BOOLEAN Result;
  91. ULONG i, Length;
  92. if( argc < 2 ) {
  93. printf( "usage: %s full-path [-x]\n", argv[0] );
  94. exit(1);
  95. }
  96. if( argc >= 3 &&
  97. argv[2][0] == '-' &&
  98. argv[2][1] == 'x' ) {
  99. HexOutput = TRUE;
  100. }
  101. if (!Message.Initialize(Get_Standard_Output_Stream(),
  102. Get_Standard_Input_Stream())) {
  103. printf( "Can't initialize MESSAGE object.\n" );
  104. exit(1);
  105. }
  106. // Convert argv[1] to a WSTR using brute force.
  107. //
  108. Length = strlen( argv[1] );
  109. for( i = 0; i < Length; i++ ) {
  110. PathString[i] = argv[1][i];
  111. }
  112. PathString[Length] = 0;
  113. if( !Path.Initialize( PathString, TRUE ) ) {
  114. printf( "Unable to initialize path object.\n" );
  115. exit(1);
  116. }
  117. // Get the drive from the path and convert it to
  118. // an NTFS name.
  119. //
  120. if( (DosDriveName = Path.QueryDevice()) == NULL ) {
  121. DELETE( DosDriveName );
  122. printf( "Cannot get drive from path.\n" );
  123. exit(1);
  124. }
  125. if (!IFS_SYSTEM::DosDriveNameToNtDriveName(DosDriveName, &NtDriveName)) {
  126. DELETE(DosDriveName);
  127. return 1;
  128. }
  129. DELETE( DosDriveName );
  130. // Determine the file system on the drive.
  131. //
  132. if (!IFS_SYSTEM::QueryFileSystemName(&NtDriveName, &FsName, &Status)) {
  133. printf( "Cannot determine NT Drive name. (Status = 0x%x\n)", Status );
  134. exit(1);
  135. }
  136. if( !FsName.QuerySTR( 0, TO_END, DisplayBuffer, 512 ) ) {
  137. printf( "QuerySTR failed.\n" );
  138. exit(1);
  139. }
  140. if( !FatString.Initialize( "FAT" ) ||
  141. !NtfsString.Initialize( "NTFS" ) ) {
  142. printf( "Can't initialize file-system name strings.\n" );
  143. exit(1);
  144. }
  145. if( FsName.Stricmp( &FatString ) == 0 ) {
  146. Result = FatSecList( &NtDriveName, &Path, &Message );
  147. } else if( FsName.Stricmp( &NtfsString ) == 0 ) {
  148. printf( "NTFS is not supported.\n" );
  149. exit(1);
  150. }
  151. if( Result ) {
  152. exit(0);
  153. } else {
  154. printf( "Seclist failed.\n" );
  155. exit(1);
  156. }
  157. //NOTREACHED
  158. return 0;
  159. }