예제 #1
0
        private void GetRootHandle()
        {
            string vol = string.Concat("\\\\.\\", _drive);

            _changeJournalRootHandle = PInvokeWin32.CreateFile(vol,
                                                               PInvokeWin32.GENERIC_READ | PInvokeWin32.GENERIC_WRITE,
                                                               PInvokeWin32.FILE_SHARE_READ | PInvokeWin32.FILE_SHARE_WRITE,
                                                               IntPtr.Zero,
                                                               PInvokeWin32.OPEN_EXISTING,
                                                               0,
                                                               IntPtr.Zero);
            if (_changeJournalRootHandle.ToInt32() == PInvokeWin32.INVALID_HANDLE_VALUE)
            {
                throw new IOException("CreateFile() returned invalid handle",
                                      new Win32Exception(Marshal.GetLastWin32Error()));
            }
        }
예제 #2
0
        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()));
            }
        }