Source code of Windows XP (NT5)
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
4.2 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. hardlink.cpp
  5. Abstract:
  6. The class that manages hardlinks for one volume. Assumes one class object
  7. will be created per volume.
  8. Author:
  9. Stefan R. Steiner [ssteiner] 3-30-2000
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #include "hardlink.h"
  14. VOID
  15. CFsdHardLinkListEntry::AddFile(
  16. IN const CBsString& cwsDirPath,
  17. IN const CBsString& cwsFileName
  18. )
  19. {
  20. SFsdHLFileName sFileName;
  21. sFileName.cwsDirPath = cwsDirPath;
  22. sFileName.cwsFileName = cwsFileName;
  23. m_cFilesLinkedTogetherList.AddTail( sFileName );
  24. }
  25. VOID
  26. CFsdHardLinkListEntry::PrintEntry(
  27. IN FILE *fpOut,
  28. IN INT cVolMountPointOffset
  29. )
  30. {
  31. fwprintf( fpOut, L"\tLinks to file: %u, links found: %u %s\n", m_sExtendedInfo.lNumberOfLinks,
  32. m_cFilesLinkedTogetherList.Size(),
  33. m_sExtendedInfo.lNumberOfLinks == (LONG)m_cFilesLinkedTogetherList.Size() ? L"" : L" - MISMATCH" );
  34. SFsdHLFileName sFileName;
  35. CVssDLListIterator< SFsdHLFileName > cListEntryIter( m_cFilesLinkedTogetherList );
  36. while( cListEntryIter.GetNext( sFileName ) )
  37. fwprintf( fpOut, L"\t\t%s%s\n", sFileName.cwsDirPath.c_str() + cVolMountPointOffset,
  38. sFileName.cwsFileName.c_str() );
  39. }
  40. CFsdHardLinkManager::~CFsdHardLinkManager()
  41. {
  42. //
  43. // Need to delete all CFsdHardLinkListEntry objects
  44. //
  45. ULONGLONG ullFileIndex;
  46. CFsdHardLinkListEntry *pcListEntry;
  47. m_cHardLinkFilesList.StartEnum();
  48. while ( m_cHardLinkFilesList.GetNextEnum( &ullFileIndex, &pcListEntry ) )
  49. {
  50. delete pcListEntry;
  51. }
  52. m_cHardLinkFilesList.EndEnum();
  53. }
  54. VOID
  55. CFsdHardLinkManager::PrintHardLinkInfo()
  56. {
  57. //
  58. // Need to iterate through all hard link entries
  59. //
  60. ULONGLONG ullFileIndex;
  61. CFsdHardLinkListEntry *pcListEntry;
  62. m_cHardLinkFilesList.StartEnum();
  63. while ( m_cHardLinkFilesList.GetNextEnum( &ullFileIndex, &pcListEntry ) )
  64. {
  65. pcListEntry->PrintEntry( m_pcParams->GetDumpFile(), m_cVolMountPointOffset );
  66. }
  67. m_cHardLinkFilesList.EndEnum();
  68. }
  69. BOOL
  70. CFsdHardLinkManager::IsHardLinkInList(
  71. IN ULONGLONG ullFileIndex,
  72. IN const CBsString& cwsDirPath,
  73. IN const CBsString& cwsFileName,
  74. OUT WIN32_FILE_ATTRIBUTE_DATA *psFileAttributeData,
  75. OUT SFileExtendedInfo *psExtendedInfo
  76. )
  77. {
  78. //
  79. // Search the hard link list to see if the file index is already in
  80. // the list.
  81. //
  82. CFsdHardLinkListEntry *pcLinkEntry;
  83. if ( m_cHardLinkFilesList.Find( ullFileIndex, &pcLinkEntry ) )
  84. {
  85. //
  86. // Found it. Add file name to the entry and get the stored attributes.
  87. //
  88. pcLinkEntry->AddFile( cwsDirPath, cwsFileName );
  89. pcLinkEntry->GetAttributes( psFileAttributeData, psExtendedInfo );
  90. if ( m_pcParams->m_bPrintDebugInfo )
  91. wprintf( L"IsHardLinkInList: FOUND ullFileIndex: %016I64x, file '%s%s', num in list: %u, num lnks: %d\n",
  92. ullFileIndex, cwsDirPath.c_str(), cwsFileName.c_str(), pcLinkEntry->m_cFilesLinkedTogetherList.Size(),
  93. psExtendedInfo->lNumberOfLinks );
  94. return TRUE;
  95. }
  96. return FALSE;
  97. }
  98. VOID
  99. CFsdHardLinkManager::AddHardLinkToList(
  100. IN ULONGLONG ullFileIndex,
  101. IN const CBsString& cwsDirPath,
  102. IN const CBsString& cwsFileName,
  103. IN WIN32_FILE_ATTRIBUTE_DATA *psFileAttributeData,
  104. IN SFileExtendedInfo *psExtendedInfo
  105. )
  106. {
  107. CFsdHardLinkListEntry *pcLinkEntry;
  108. //
  109. // Add it. Create a new entry and add the entry to the list
  110. //
  111. pcLinkEntry = new CFsdHardLinkListEntry(
  112. cwsDirPath,
  113. cwsFileName,
  114. psFileAttributeData,
  115. psExtendedInfo );
  116. if ( pcLinkEntry == NULL )
  117. throw E_OUTOFMEMORY;
  118. if ( m_cHardLinkFilesList.Insert( ullFileIndex, pcLinkEntry ) != BSHASHMAP_NO_ERROR )
  119. m_pcParams->ErrPrint( L"CFsdHardLinkManager::AddHardLinkToList - Error adding to hard-link file list" );
  120. if ( m_pcParams->m_bPrintDebugInfo )
  121. wprintf( L" AddHardLinkToList: ullFileIndex: %016I64x, file '%s%s', num lnks: %d\n",
  122. ullFileIndex, cwsDirPath.c_str(), cwsFileName.c_str(), psExtendedInfo->lNumberOfLinks );
  123. }