Beispiel #1
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()));
            }
        }
        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()));
            }
        }