Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What kind of drive is "NoRootDirectory " (System.IO.DriveType.NoRootDirectory)?

Tags:

c#

drive

In C# System.IO.DriveInfo has the property DriveType.

System.IO.DriveType is an enum:

public enum DriveType
{
    Unknown = 0,
    //
    // Summary:
    //     The drive does not have a root directory.
    NoRootDirectory = 1,
    Removable = 2,
    Fixed = 3,
    Network = 4,
    CDRom = 5,
    Ram = 6,
}

I suspect that this is a volume without a drive letter. But using:

System.IO.DriveInfo.GetDrives();

doesn't list my volume without drive letter.

Is NoRootDirectory used for any other type of volumes / drives or does System.IO.DriveInfo.GetDrives() just not show them?

like image 987
marsh-wiggle Avatar asked May 19 '16 11:05

marsh-wiggle


2 Answers

System.IO.DriveType.NoRootDirectory seems to be an misleadingly designation for "This drive letter is unused"

Testcode for all drives: All not found drives have the type DriveType.NoRootDirectory

foreach (char driveLetter in "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToArray())
{
    var driveInfo = new System.IO.DriveInfo(driveLetter.ToString() + ":\\");

    if(System.IO.DriveInfo.GetDrives().FirstOrDefault(o => o.Name[0] == driveLetter) == null)
        Console.WriteLine("// Not found: " + driveInfo.Name + " has DriveType: " + driveInfo.DriveType.ToString());
    else
        Console.WriteLine("//     found: " + driveInfo.Name + " has DriveType: " + driveInfo.DriveType.ToString());
}

Result:

// Not found: A:\ has DriveType: NoRootDirectory
// Not found: B:\ has DriveType: NoRootDirectory
//     found: C:\ has DriveType: Fixed
//     found: D:\ has DriveType: CDRom
// Not found: E:\ has DriveType: NoRootDirectory
// Not found: F:\ has DriveType: NoRootDirectory
// Not found: G:\ has DriveType: NoRootDirectory
// Not found: H:\ has DriveType: NoRootDirectory
// Not found: I:\ has DriveType: NoRootDirectory
// Not found: J:\ has DriveType: NoRootDirectory
// Not found: K:\ has DriveType: NoRootDirectory
// Not found: L:\ has DriveType: NoRootDirectory
// Not found: M:\ has DriveType: NoRootDirectory
// Not found: N:\ has DriveType: NoRootDirectory
// Not found: O:\ has DriveType: NoRootDirectory
//     found: P:\ has DriveType: Network
// Not found: Q:\ has DriveType: NoRootDirectory
//     found: R:\ has DriveType: Network
//     found: S:\ has DriveType: Network
// Not found: T:\ has DriveType: NoRootDirectory
// Not found: U:\ has DriveType: NoRootDirectory
//     found: V:\ has DriveType: Network
//     found: W:\ has DriveType: Fixed
//     found: X:\ has DriveType: Network
//     found: Y:\ has DriveType: Network
//     found: Z:\ has DriveType: Network
like image 120
marsh-wiggle Avatar answered Nov 16 '22 09:11

marsh-wiggle


I know that it's used for unassigned drive letters. You will of course not get them through GetDrives but try new System.IO.DriveInfo("B:").DriveType or such. It might be used for unformatted partitions (or unknown filesystems) as well, but I'm not totally sure (you would have to test whether you get Unknown or NoRootDirectory in that case). For completeness, you could also create garbage drives by going to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices and creating a drive X: pointing to \Device\Null for example and see what you get for those.

Actually, the documentation for the underlying WinAPI function GetDriveType is a bit clearer. It says:

The root path is invalid; for example, there is no volume mounted at the specified path.

I would translate "the root path is invalid" as "The kernel path \DosDevices\X: doesn't resolve/link to a valid filesystem directory object able to resolve a request for the path \."

Probably the sentence was written by somebody with Windows kernel knowledge. In this case I'd assume that my "garbage drives" from above would also give you this value, as well as any unassigned drive letters.

For a more detailed read about the things I just mentioned, check out http://www.osronline.com/article.cfm%5eid=107.htm if you are interested.

like image 1
CherryDT Avatar answered Nov 16 '22 08:11

CherryDT