private void GetRootHandle(string drive) { string vol = string.Concat("\\\\.\\", drive); _changeJournalRootHandle = NativeWrapper.CreateFile(vol, NativeWrapper.GENERIC_READ | NativeWrapper.GENERIC_WRITE, NativeWrapper.FILE_SHARE_READ | NativeWrapper.FILE_SHARE_WRITE, IntPtr.Zero, NativeWrapper.OPEN_EXISTING, 0, IntPtr.Zero); if (_changeJournalRootHandle.ToInt32() == NativeWrapper.INVALID_HANDLE_VALUE) { throw new IOException("CreateFile() returned invalid handle", new Win32Exception(Marshal.GetLastWin32Error())); } }
private void GetRootFrnEntry(string drive) { string driveRoot = string.Concat("\\\\.\\", drive); driveRoot = string.Concat(driveRoot, Path.DirectorySeparatorChar); IntPtr hRoot = NativeWrapper.CreateFile(driveRoot, 0, NativeWrapper.FILE_SHARE_READ | NativeWrapper.FILE_SHARE_WRITE, IntPtr.Zero, NativeWrapper.OPEN_EXISTING, NativeWrapper.FILE_FLAG_BACKUP_SEMANTICS, IntPtr.Zero); if (hRoot.ToInt32() != NativeWrapper.INVALID_HANDLE_VALUE) { BY_HANDLE_FILE_INFORMATION fi = new BY_HANDLE_FILE_INFORMATION(); bool bRtn = NativeWrapper.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())); } NativeWrapper.CloseHandle(hRoot); } else { throw new IOException("Unable to get root frn entry", new Win32Exception(Marshal.GetLastWin32Error())); } }