Пример #1
0
        private void GetRootFrnEntry(string drive, Dictionary <ulong, FileEntry> directories)
        {
            string driveRoot = string.Concat("\\\\.\\", drive);

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

            if (hRoot.ToInt32() != WinApi.INVALID_HANDLE_VALUE)
            {
                WinApi.BY_HANDLE_FILE_INFORMATION fi = new WinApi.BY_HANDLE_FILE_INFORMATION();
                bool bRtn = WinApi.GetFileInformationByHandle(hRoot, out fi);
                if (bRtn)
                {
                    ulong fileIndexHigh = (ulong)fi.FileIndexHigh;
                    ulong indexRoot     = (fileIndexHigh << 32) | fi.FileIndexLow;

                    FileEntry f = new FileEntry(driveRoot, 0);
                    directories.Add(indexRoot, f);
                }
                else
                {
                    throw new IOException("GetFileInformationbyHandle() returned invalid handle",
                                          new Win32Exception(Marshal.GetLastWin32Error()));
                }
                WinApi.CloseHandle(hRoot);
            }
            else
            {
                throw new IOException("Unable to get root frn entry", new Win32Exception(Marshal.GetLastWin32Error()));
            }
        }
Пример #2
0
        private void GetRootFrnEntry(string drive, Dictionary<ulong, FileEntry> directories)
        {
            string driveRoot = string.Concat ("\\\\.\\", drive);
            driveRoot = string.Concat (driveRoot, Path.DirectorySeparatorChar);
            IntPtr hRoot = WinApi.CreateFile (driveRoot,
                0,
                WinApi.FILE_SHARE_READ | WinApi.FILE_SHARE_WRITE,
                IntPtr.Zero,
                WinApi.OPEN_EXISTING,
                WinApi.FILE_FLAG_BACKUP_SEMANTICS,
                IntPtr.Zero
            );

            if (hRoot.ToInt32 () != WinApi.INVALID_HANDLE_VALUE) {
                WinApi.BY_HANDLE_FILE_INFORMATION fi = new WinApi.BY_HANDLE_FILE_INFORMATION ();
                bool bRtn = WinApi.GetFileInformationByHandle (hRoot, out fi);
                if (bRtn) {
                    ulong fileIndexHigh = (ulong)fi.FileIndexHigh;
                    ulong indexRoot = (fileIndexHigh << 32) | fi.FileIndexLow;

                    FileEntry f = new FileEntry (driveRoot, 0);
                    directories.Add (indexRoot, f);
                } else {
                    throw new IOException ("GetFileInformationbyHandle() returned invalid handle",
                        new Win32Exception (Marshal.GetLastWin32Error ()));
                }
                WinApi.CloseHandle (hRoot);
            } else {
                throw new IOException ("Unable to get root frn entry", new Win32Exception (Marshal.GetLastWin32Error ()));
            }
        }