public KeyValuePair<ulong, FileNameAndFrn> GetRootFrn() { 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(); var bRtn = PInvokeWin32.GetFileInformationByHandle(hRoot, out fi); if (bRtn != false) { UInt64 fileIndexHigh = (UInt64)fi.FileIndexHigh; UInt64 indexRoot = (fileIndexHigh << 32) | fi.FileIndexLow; FileNameAndFrn f = new FileNameAndFrn(driveRoot, 0); return new KeyValuePair<ulong,FileNameAndFrn>(indexRoot,f); } else { throw new IOException("GetFileInformationbyHandle() returned invalid handle", new Win32Exception(Marshal.GetLastWin32Error())); } } else { throw new IOException("Unable to get root frn entry", new Win32Exception(Marshal.GetLastWin32Error())); } }
public static unsafe UInt64 GetPathFRN(string FilePath) { IntPtr hDir = PInvokeWin32.CreateFile(FilePath, 0, PInvokeWin32.FILE_SHARE_READ, IntPtr.Zero, PInvokeWin32.OPEN_EXISTING, PInvokeWin32.FILE_FLAG_BACKUP_SEMANTICS, IntPtr.Zero ); if(hDir.ToInt32() == PInvokeWin32.INVALID_HANDLE_VALUE) throw new Exception(); PInvokeWin32.BY_HANDLE_FILE_INFORMATION fi = new PInvokeWin32.BY_HANDLE_FILE_INFORMATION(); PInvokeWin32.GetFileInformationByHandle(hDir, out fi); PInvokeWin32.CloseHandle(hDir); return (fi.FileIndexHigh << 32) | fi.FileIndexLow; }