title: How to match linux device path to windows drive name?
body: <p>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:</p>
  
  <ul>
  <li><p>store partitions information (i.e. drive letter, number of blocks, drive serial number etc.) in Windows in some pre-defined place (i.e. the root of the system partition).</p></li>
  <li><p>read a list of partitions from /proc/partitions. Get only those partitions that has major number for SCSI or IDE hard drives and minor number that identifies them as real partitions and not the whole disks.</p></li>
  <li><p>Try to mount each of them with either ntfs or vfat file systems. Check whether the mounted partition contains the information stored by Windows app.</p></li>
  <li><p>Upon finding the required information written by the Windows app make the actual match. For each partition found in /proc/partitions acquire drive serial number (via HDIO_GET_IDENTITY syscall), number of blocks (from /proc/partitions) and drive offset (/sys/blocks/drive_path/partition_name/start), compare this to the Windows information and if this matches - store a Windows drive letter along with a linux device name. </p></li>
  </ul>
  
  <p>There are a couple of problems in this scheme:</p>
  
  <ul>
  <li><p>This is ugly. Writing data in Windows and then reading it in Linux makes testing a nightmare.</p></li>
  <li><p>linux device major number is compared only with IDE or SCSI devices. This would probably fail, i.e. on USB or FireWire disks. It's possible to add these types of disks, but limiting the app to only known subset of possible devices seems to be rather bad idea.</p></li>
  <li><p>looks like HDIO_GET_IDENTITY works only on IDE and SATA drives.</p></li>
  <li><p>/sys/block hack may not work on other than IDE or SATA drives.</p></li>
  </ul>
  
  <p>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>
  
  <p>P.S. The language of the app is C++. I can't change this.</p>