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.

168 lines
4.7 KiB

  1. // enumoid.c
  2. #include "oidtst.h"
  3. void
  4. FsTestDumpObjIdIndexEntries (
  5. IN PFILE_OBJECTID_INFORMATION ObjIdInfo,
  6. IN ULONG_PTR LengthInBytes
  7. )
  8. {
  9. ULONG ReturnedCount;
  10. ULONG Idx;
  11. ReturnedCount = (ULONG) LengthInBytes / sizeof( FILE_OBJECTID_INFORMATION );
  12. printf( "\n\nFound %x object id index entries", ReturnedCount );
  13. for (Idx = 0; Idx < ReturnedCount; Idx += 1) {
  14. printf( "\nEntry %x", Idx );
  15. FsTestHexDump( (UCHAR *)&ObjIdInfo[Idx].ObjectId, 16 );
  16. FsTestHexDump( (UCHAR *)&ObjIdInfo[Idx].ExtendedInfo, 16 );
  17. }
  18. }
  19. int
  20. FsTestEnumerateOids (
  21. IN HANDLE hFile
  22. )
  23. {
  24. IO_STATUS_BLOCK IoStatusBlock;
  25. NTSTATUS Status;
  26. FILE_OBJECTID_INFORMATION ObjIdInfo[4];
  27. BOOLEAN ReturnSingleEntry = TRUE;
  28. FILE_INFORMATION_CLASS InfoClass = FileObjectIdInformation;
  29. Status = NtQueryDirectoryFile( hFile,
  30. NULL, // Event
  31. NULL, // ApcRoutine
  32. NULL, // ApcContext
  33. &IoStatusBlock,
  34. &ObjIdInfo[0],
  35. sizeof(ObjIdInfo),
  36. InfoClass,
  37. ReturnSingleEntry,
  38. NULL, // FileName
  39. TRUE ); // RestartScan
  40. if (Status == STATUS_SUCCESS) {
  41. FsTestDumpObjIdIndexEntries( &ObjIdInfo[0], IoStatusBlock.Information );
  42. }
  43. while (Status == STATUS_SUCCESS) {
  44. RtlFillMemory( ObjIdInfo, sizeof(ObjIdInfo), 0x51 );
  45. Status = NtQueryDirectoryFile( hFile,
  46. NULL, // Event
  47. NULL, // ApcRoutine
  48. NULL, // ApcContext
  49. &IoStatusBlock,
  50. &ObjIdInfo[0],
  51. sizeof(ObjIdInfo),
  52. InfoClass,
  53. ReturnSingleEntry,
  54. NULL, // FileName
  55. FALSE ); // RestartScan
  56. if (Status == STATUS_SUCCESS) {
  57. FsTestDumpObjIdIndexEntries( &ObjIdInfo[0], IoStatusBlock.Information );
  58. }
  59. }
  60. printf( "\n" );
  61. return FsTestDecipherStatus( Status );
  62. }
  63. VOID
  64. _cdecl
  65. main (
  66. int argc,
  67. char *argv[]
  68. )
  69. {
  70. HANDLE hFile;
  71. char Buffer[80];
  72. char Buff2[4];
  73. //
  74. // Get parameters
  75. //
  76. if (argc < 2) {
  77. printf("This program enumerates the object ids (if any) for a volume (ntfs only).\n\n");
  78. printf("usage: %s driveletter\n", argv[0]);
  79. return;
  80. }
  81. strcpy( Buffer, argv[1] );
  82. strcat( Buffer, "\\$Extend\\$ObjId:$O:$INDEX_ALLOCATION" );
  83. hFile = CreateFile( Buffer,
  84. GENERIC_READ,
  85. FILE_SHARE_READ,
  86. NULL,
  87. OPEN_EXISTING,
  88. FILE_FLAG_BACKUP_SEMANTICS | SECURITY_IMPERSONATION,
  89. NULL );
  90. if ( hFile == INVALID_HANDLE_VALUE ) {
  91. printf( "Error opening directory %s (dec) %d\n", Buffer, GetLastError() );
  92. return;
  93. }
  94. printf( "\nUsing directory:%s\n", Buffer );
  95. FsTestEnumerateOids( hFile );
  96. CloseHandle( hFile );
  97. return;
  98. }
  99. #if 0
  100. //// graveyard
  101. void
  102. foobar() {
  103. UNICODE_STRING FakeFileName;
  104. UCHAR Buffer[16];
  105. FakeFileName.Length = FakeFileName.MaximumLength = 16;
  106. FakeFileName.Buffer = &Buffer[0];
  107. RtlZeroMemory( FakeFileName.Buffer, 16 );
  108. strcpy( FakeFileName.Buffer, "oidC" );
  109. printf( "\nWe'll restart from oid:" );
  110. FsTestHexDump( FakeFileName.Buffer, 16 );
  111. RtlFillMemory( ObjIdInfo, sizeof(ObjIdInfo), 0x51 );
  112. Status = NtQueryDirectoryFile( hFile,
  113. NULL, // Event
  114. NULL, // ApcRoutine
  115. NULL, // ApcContext
  116. &IoStatusBlock,
  117. &ObjIdInfo[0],
  118. sizeof(ObjIdInfo),
  119. InfoClass,
  120. ReturnSingleEntry,
  121. &FakeFileName, // FileName
  122. FALSE ); // RestartScan
  123. if (Status == STATUS_SUCCESS) {
  124. FsTestDumpQuotaIndexEntries( QuotaInfo[0], IoStatusBlock.Information );
  125. }
  126. }
  127. #endif