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.

162 lines
5.0 KiB

  1. // Copyright (c) 1996-1999 Microsoft Corporation
  2. //+-------------------------------------------------------------------------
  3. //
  4. // Microsoft Windows
  5. //
  6. // File: objidenm.cxx
  7. //
  8. // Contents: CObjId enumeration from a volume
  9. //
  10. // Classes: CObjIdEnumerator
  11. //
  12. // History: 18-Nov-96 BillMo Created.
  13. // 09-Jun-97 WeiruC Modified. Skip volume id entries in
  14. // NTFS object id table.
  15. //
  16. // Notes:
  17. //
  18. // Codework:
  19. //
  20. //--------------------------------------------------------------------------
  21. #include "pch.cxx"
  22. #pragma hdrstop
  23. #include "trklib.hxx"
  24. //+----------------------------------------------------------------------------
  25. //
  26. // CObjIdEnumerator::Initialize
  27. //
  28. // Prepare to enumerate the object IDs on a volume. This opens a handle
  29. // to the object ID index directory.
  30. //
  31. //+----------------------------------------------------------------------------
  32. BOOL
  33. CObjIdEnumerator::Initialize(const TCHAR *ptszVolumeDeviceName)
  34. {
  35. TCHAR tszDirPath[MAX_PATH];
  36. _tcscpy( tszDirPath, ptszVolumeDeviceName);
  37. _tcscat( tszDirPath, TEXT("\\$Extend\\$ObjId:$O:$INDEX_ALLOCATION") );
  38. _hDir = CreateFile( tszDirPath,
  39. GENERIC_READ,
  40. FILE_SHARE_READ,
  41. NULL,
  42. OPEN_EXISTING,
  43. FILE_FLAG_BACKUP_SEMANTICS | SECURITY_IMPERSONATION,
  44. NULL );
  45. return( INVALID_HANDLE_VALUE != _hDir );
  46. }
  47. //+----------------------------------------------------------------------------
  48. //
  49. // CObjIdEnumerator::UnInitialize
  50. //
  51. // Close the handle to the object ID index directory.
  52. //
  53. //+----------------------------------------------------------------------------
  54. void
  55. CObjIdEnumerator::UnInitialize()
  56. {
  57. if( INVALID_HANDLE_VALUE != _hDir )
  58. CloseHandle(_hDir);
  59. _hDir = INVALID_HANDLE_VALUE;
  60. }
  61. //+----------------------------------------------------------------------------
  62. //
  63. // CObjIdEnumerator::Find
  64. //
  65. // This private method is used by the public FindFirst and FindNext
  66. // methods. This method queries the object ID index directory
  67. // for a set of entries and puts the result into _ObjIdInfo. It then
  68. // takes the first real entry and puts it into the caller-provided parameters
  69. // (the object ID and birth ID). To start enumerating from the top of the
  70. // index, fRestart is set by the caller.
  71. //
  72. //+----------------------------------------------------------------------------
  73. BOOL
  74. CObjIdEnumerator::Find( CObjId * pobjid, CDomainRelativeObjId * pdroidBirth, BOOL fRestart )
  75. {
  76. NTSTATUS Status;
  77. IO_STATUS_BLOCK IoStatusBlock;
  78. BOOL fObjFound = FALSE;
  79. // Loop until we find a real entry.
  80. do
  81. {
  82. // Query the object ID index for a set of entries.
  83. Status = NtQueryDirectoryFile( _hDir,
  84. NULL, // Event
  85. NULL, // ApcRoutine
  86. NULL, // ApcContext
  87. &IoStatusBlock,
  88. _ObjIdInfo,
  89. sizeof(_ObjIdInfo),
  90. FileObjectIdInformation,
  91. FALSE, // ReturnSingleEntry
  92. NULL, // FileName
  93. fRestart != 0); // RestartScan
  94. if(NT_SUCCESS(Status) && IoStatusBlock.Information != 0)
  95. {
  96. fRestart = FALSE;
  97. // Update the count of entries and the cursor into the entries.
  98. _cbObjIdInfo = (ULONG)IoStatusBlock.Information;
  99. _pObjIdInfo = _ObjIdInfo;
  100. TrkAssert( _cbObjIdInfo % sizeof(*_pObjIdInfo) == 0 );
  101. TrkAssert( _cbObjIdInfo <= sizeof(_ObjIdInfo) );
  102. // In the NTFS's ObjectID table is a record which represents
  103. // not the file object id but the volume id. We skip this record.
  104. while( _pObjIdInfo < &_ObjIdInfo[_cbObjIdInfo / sizeof(_ObjIdInfo[0])]
  105. &&
  106. (_pObjIdInfo->FileReference & FILEREF_MASK) == FILEREF_VOL )
  107. {
  108. _pObjIdInfo++;
  109. }
  110. // If we haven't exhausted the objects in the buffer, take the next
  111. // one and return it to the caller.
  112. if(_pObjIdInfo < &_ObjIdInfo[_cbObjIdInfo / sizeof(_ObjIdInfo[0])])
  113. {
  114. UnloadFileObjectIdInfo( *_pObjIdInfo, pobjid, pdroidBirth );
  115. _pObjIdInfo ++;
  116. fObjFound = TRUE;
  117. break;
  118. }
  119. }
  120. else
  121. {
  122. break;
  123. }
  124. } while(TRUE);
  125. if(TRUE == fObjFound)
  126. {
  127. return(TRUE);
  128. }
  129. else
  130. {
  131. _cbObjIdInfo = 0;
  132. return(FALSE);
  133. }
  134. }