How to map a Linux device path to a Windows disk name?

I am writing an application that at some point performs low-level disk operations in a Linux environment. The application actually consists of 2 parts, one runs on Windows and interacts with the user, and the other is the Linux part that runs from LiveCD. The user selects the letters of the Windows disk, and then part of Linux performs actions with the corresponding partitions. The problem is finding a match between the letter of the Windows drive (for example, C :) and the name of the linux device (for example / dev / sda1). This is my current solution, which I rate as ugly:

  • store information about partitions (for example, drive letter, number of blocks, disk serial number, etc.) in Windows in some predetermined location (i.e. the root of the system partition).

  • read the list of partitions from / proc / partition. Get only those partitions that have a large number of SCSI or IDE hard drives and a minor number that identifies them as real partitions, not whole disks.

  • Try installing each of them with ntfs or vfat file systems. Check if the mounted partition contains information stored in the Windows application.

  • Having found the necessary information written by the Windows application, make an actual match. For each partition found in / proc / partitions, the serial number of the drive (via the HDIO_GET_IDENTITY system call), the number of blocks (from / proc / partition) and the disk offset (/ sys / blocks / drive_path / username / start) is acquired, compare this to Windows and if it matches, save the Windows drive letter along with the Linux device name.

:

  • . Windows, Linux .

  • Linux IDE SCSI. , , , USB FireWire. , .

  • : HDIO_GET_IDENTITY IDE SATA.

  • /sys/block hack , IDE SATA.

, ? , Windows?

P.S. - ++. .

+3
6

UUID, . , Windows, Linux UUID :

sudo vol_id -u (,/dev/sda1)

Windows , UUID , , Linux UUID.

: Linux-, volid, - ( ). , , volid , .

+1

UUID

, , , GPT (Guid Partition Table), MBR , 99% ?

+2

, , , GPT (Guid ), MBR , 99% ?

linux, .. NTFS . , vol_id . , - , .

+1

UUID, . , Windows, Linux UUID :

sudo vol_id -u (,/dev/sda1)

Windows , UUID , , Linux UUID.

, ! vol_id ( udev tarball), , FAT (32) NTFS UUUD, , . , fat32 ntfs, .

+1

- (, ..), - , .

, , Windows , Windows. , Windows , , C:. , . Windows , , , .

GUI- Linux, Window/Linux. , , , . , .

- , Linux Windows. Windows, . , , Windows , .

, , , Linux, . .

0

Windows " NTFS", UUID Linux.

" NTFS" Windows:

  • XP: fsutil.exe fsinfo ntfsinfo C:

  • ++

    HANDLE fileHandle = CreateFile(L"\\\\.\\C:", // or use syntax "\\?\Volume{GUID}" 
                                   GENERIC_READ,
                                   FILE_SHARE_READ|FILE_SHARE_WRITE,
                                   NULL,
                                   OPEN_EXISTING,
                                   NULL,
                                   NULL);
    DWORD i;
    NTFS_VOLUME_DATA_BUFFER ntfsInfo;
    DeviceIoControl(fileHandle, 
                    FSCTL_GET_NTFS_VOLUME_DATA, 
                    NULL, 
                    0, 
                    &ntfsInfo,
                    sizeof(ntfsInfo), 
                    &i, 
                    NULL));
    cout << "UUID is " << std::hex << ntfsInfo.VolumeSerialNumber.HighPart << std::hex << ntfsInfo.VolumeSerialNumber.LowPart << endl;
    

UUID Linux:

  • ls -l/dev/disk/by-uuid
  • ls -l / dev / disk / by-label
  • blkid / dev / sda1
0
source

Source: https://habr.com/ru/post/1696473/


All Articles