public void EnumerateVolume( out Dictionary <UInt64, FileNameAndFrn> files, string[] fileExtensions) { files = new Dictionary <ulong, FileNameAndFrn>(); IntPtr medBuffer = IntPtr.Zero; try { GetRootFrnEntry(); GetRootHandle(); CreateChangeJournal(); SetupMFT_Enum_DataBuffer(ref medBuffer); EnumerateFiles(medBuffer, ref files, fileExtensions); } catch (Exception e) { // Log.Info(e.Message, e); Exception innerException = e.InnerException; while (innerException != null) { // Log.Info(innerException.Message, innerException); innerException = innerException.InnerException; } throw new ApplicationException("Error in EnumerateVolume()", e); } finally { if (_changeJournalRootHandle.ToInt32() != PInvokeWin32.INVALID_HANDLE_VALUE) { PInvokeWin32.CloseHandle(_changeJournalRootHandle); } if (medBuffer != IntPtr.Zero) { Marshal.FreeHGlobal(medBuffer); } } }
private void GetRootFrnEntry() { string driveRoot = string.Concat("\\\\.\\", _drive); driveRoot = string.Concat(driveRoot, Path.DirectorySeparatorChar); IntPtr hRoot = PInvokeWin32.CreateFile(driveRoot, 0, PInvokeWin32.FILE_SHARE_READ | PInvokeWin32.FILE_SHARE_WRITE, IntPtr.Zero, PInvokeWin32.OPEN_EXISTING, PInvokeWin32.FILE_FLAG_BACKUP_SEMANTICS, IntPtr.Zero); if (hRoot.ToInt32() != PInvokeWin32.INVALID_HANDLE_VALUE) { PInvokeWin32.BY_HANDLE_FILE_INFORMATION fi = new PInvokeWin32.BY_HANDLE_FILE_INFORMATION(); bool bRtn = PInvokeWin32.GetFileInformationByHandle(hRoot, out fi); if (bRtn) { UInt64 fileIndexHigh = (UInt64)fi.FileIndexHigh; UInt64 indexRoot = (fileIndexHigh << 32) | fi.FileIndexLow; FileNameAndParentFrn f = new FileNameAndParentFrn(driveRoot, 0); _directories.Add(indexRoot, f); } else { throw new IOException("GetFileInformationbyHandle() returned invalid handle", new Win32Exception(Marshal.GetLastWin32Error())); } PInvokeWin32.CloseHandle(hRoot); } else { throw new IOException("Unable to get root frn entry", new Win32Exception(Marshal.GetLastWin32Error())); } }