Exemplo n.º 1
0
        public void EnumerateVolume(out Dictionary <UInt64, FileNameAndParentFrn> files, string[] fileExtensions)
        {
            files = new Dictionary <ulong, FileNameAndParentFrn>();
            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() != MFTReader.INVALID_HANDLE_VALUE)
                {
                    MFTReader.CloseHandle(_changeJournalRootHandle);
                }
                if (medBuffer != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(medBuffer);
                }
            }
        }
Exemplo n.º 2
0
        private void GetRootFrnEntry()
        {
            string driveRoot = string.Concat("\\\\.\\", _drive);

            driveRoot = string.Concat(driveRoot, Path.DirectorySeparatorChar);
            IntPtr hRoot = MFTReader.CreateFile(driveRoot,
                                                0,
                                                MFTReader.FILE_SHARE_READ | MFTReader.FILE_SHARE_WRITE,
                                                IntPtr.Zero,
                                                MFTReader.OPEN_EXISTING,
                                                MFTReader.FILE_FLAG_BACKUP_SEMANTICS,
                                                IntPtr.Zero);

            if (hRoot.ToInt32() != MFTReader.INVALID_HANDLE_VALUE)
            {
                MFTReader.BY_HANDLE_FILE_INFORMATION fi = new MFTReader.BY_HANDLE_FILE_INFORMATION();
                bool bRtn = MFTReader.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()));
                }
                MFTReader.CloseHandle(hRoot);
            }
            else
            {
                throw new IOException("Unable to get root frn entry", new Win32Exception(Marshal.GetLastWin32Error()));
            }
        }