How can i enumerate a list of all logical volumes on a disk? I want the name of the volume that is suitable for opening with CreateFile
.
I've used the FindFirstVolume
/FindNextVolume
API to enumerate a list of volumes. It returns a list of names such as:
\\?\Volume{0b777018-3313-11e2-8ccd-806e6f6e6963}\
\\?\Volume{0b777019-3313-11e2-8ccd-806e6f6e6963}\
\\?\Volume{758a2cf2-cf3a-11e4-8dce-c86000d0b92a}\
\\?\Volume{4f81d34b-34f4-11e2-9f6e-c86000d0b92a}\
But none of those volume names are valid volume names. That is, none of those names can be passed to CreateFile
to open the volume:
0x00000003 (The system cannot find the path specified)
The question might be how do i convert the thing returned by FindFirstVolume
into a volume name?
But the real question is how do i enumerate volumes in the first place?
\\.\C:
?I wasn't asking how to hard-code a volume name; i was asking how to enumerate volume names.
Besides, not every volume has a drive letter, e.g.:
\\?\Volume{0b777019-3313-11e2-8ccd-806e6f6e6963}\
==> \\.\C:
\\?\Volume{758a2cf2-cf3a-11e4-8dce-c86000d0b92a}\
==> \\.\D:
\\?\Volume{0b777018-3313-11e2-8ccd-806e6f6e6963}\
==> the system reserved volume with no drive letter
\\?\Volume{4f81d34b-34f4-11e2-9f6e-c86000d0b92a}\
==> a CD ROM that is mounted in a folder
I swear there is an API to enumerate volumes.
The problem with GetLogicalDriveStrings function is that it only returns logical drives:
C:\
D:\
and not volumes. In my case it misses two volumes:
that FindFirstVolume
does correctly return.
Volume names must begin with the letter “d” followed by a number (for example, d0 ). Instead of specifying the full volume name, such as /dev/md/dsk/d1 , you can often use an abbreviated volume name, such as d1 , with any meta* command. Like physical slices, volumes have logical names that appear in the file system.
The easiest way to view all volume GUIDs on your system, is to run the "mountvol" command in command prompt. * Note: "mountvol" command is used to create, delete, or list a volume mount point. But if you give the command with any arguments lists all the Volume GUIDs.
Volume{GUID}\" where GUID is a globally unique identifier (GUID) that identifies the volume. A volume GUID path is sometimes referred to as a unique volume name, because a volume GUID path can refer only to one volume. However, this term is misleading, because a volume can have more than one volume GUID path.
The answer to your question is hidden inside Naming a Volume. When using a volume GUID path, the rules are slightly different:
All volume and mounted folder functions that take a volume GUID path as an input parameter require the trailing backslash. [...] but this is not the case with the CreateFile function. You can open a volume by calling CreateFile and omit the trailing backslash from the volume name you specify. CreateFile processes a volume GUID path with an appended backslash as the root directory of the volume.
The solution is easy: Strip the trailing backslash from a volume GUID path to open the volume using CreateFile
.
In other words, while volume management functions such as:
do take the full volume name returned by FindFirstVolume
/FindNextVolume
, CreateFile requires the returned trailing backslash removed:
\\?\Volume{0b777018-3313-11e2-8ccd-806e6f6e6963}
\\?\Volume{0b777019-3313-11e2-8ccd-806e6f6e6963}
\\?\Volume{758a2cf2-cf3a-11e4-8dce-c86000d0b92a}
\\?\Volume{4f81d34b-34f4-11e2-9f6e-c86000d0b92a}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With