File size: 1,166 Bytes
1c4658f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Text;
using FastSeek.Core.Mft;

namespace FastSeek.Core.Utils;

public static class Drives
{
    public static List<NtfsDrive> GetNtfsDrives()
    {
        var drives = new List<NtfsDrive>();
        var buffer = new char[256];
        var len = NativeMethods.GetLogicalDriveStrings((uint)buffer.Length, buffer);
        if (len == 0) return drives;

        var all = new string(buffer, 0, (int)len).Split('\0', StringSplitOptions.RemoveEmptyEntries);
        foreach (var root in all)
        {
            if (!IsNtfs(root)) continue;
            var letter = root[0];
            drives.Add(new NtfsDrive
            {
                Letter = letter,
                Root = root,
                DevicePath = $"\\\\.\\{letter}:"
            });
        }
        return drives;
    }

    private static bool IsNtfs(string root)
    {
        var fs = new char[32];
        var ok = NativeMethods.GetVolumeInformation(root, null, 0, out _, out _, out _, fs, (uint)fs.Length);
        if (!ok) return false;
        var fsName = new string(fs).TrimEnd('\0');
        return fsName.StartsWith("NTFS", StringComparison.OrdinalIgnoreCase);
    }
}