c++linuxdrives

How to match linux device path to windows drive name?


I'm writing an application that on some stage performs low-level disk operations in Linux environment. The app actually consists of 2 parts, one runs on Windows and interacts with a user and another is a linux part that runs from a LiveCD. User makes a choice of Windows drive letters and then a linux part performs actions with corresponding partitions. The problem is finding a match between a Windows drive letter (like C:) and a linux device name (like /dev/sda1). This is my current solution that I rate as ugly:

There are a couple of problems in this scheme:

Any ideas on how to improve this schema? Perhaps there is another way to determine windows names without writing all the data in windows app?

P.S. The language of the app is C++. I can't change this.


Solution

  • Partitions have UUIDs associated with them. I don't know how to find these in Windows but in linux you can find the UUID for each partition with:

    sudo vol_id -u device (e.g. /dev/sda1)

    If there is an equivilent function in Windows you could simply store the UUIDs for whatever partition they pick then iterate through all known partitions in linux and match the UUIDs.

    Edit: This may be a linux-only thing, and it may speficially be the volid util that generates these from something (instead of reading off meta-data for the drive). Having said that, there is nothing stopping you getting the source for volid and checking out what it does.