Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC8.0
How to get the drive letter with physical address like "\\\\.\\PHYSICALDRIVE0"?
If we give the physical address.. It should return the drive letter assigned to that drive?? help me
Posted 2-May-11 22:54pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

That is not possible because a physical drive can contain multiple drive letters.
You can however do the reverse, i.e, open a volume and get the physical drive to which it belongs.
 
Here is what you can do.
 
1. Enumerate all volumes - GetLogicalDrives.
2. Open each volume - eg. CreateFile(L"\\\\.\\C:", ...
3. Call DeviceIoControl on the handle returned by CreateFile with IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS.
  Permalink  
Comments
Gokulnath007 at 3-May-11 4:11am
   
GetLogicalDrives containing only number. How to get the individual drive letter with the logical drive function. Help me regarding this.
«_Superman_» at 3-May-11 4:16am
   
If you read the documentation properly, you can see that the number is actually a bit field where each bit represents a drive letter. You can check this as follows -
if (dwDrives & 1) A: exists.
if (dwDrives & 2) B: exists.
if (dwDrives & 4) C: exists.
 
You can get this in a for loop.
Try this -
 
for (int i = 0; i < 32; ++i)
{
if (dwDrives & (1 << i))
cout << 'A' + i << " exists\n";
}
Olivier Levrey at 3-May-11 4:41am
   
Good answer. Have a 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 205
1 Richard MacCutchan 185
2 DamithSL 170
3 Tomas Takac 146
4 OriginalGriff 132
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 3 May 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100