문제

I need to map Boot Manager to a partition number:

 Manufacturer Recovery partition = Partition 0 
 Boot manager = Partition 1
 C:\ = Partition 2
 D:\ = Partition 3

For mounted partitions, like C:\ or D:\, I use IOCTL_STORAGE_GET_DEVICE_NUMBER to retrieve partition numbers.

Now I would like to do something similar to get the number of the Windows Boot Manager. I can't assume that the BootMgr is the 100 MB partition or the previous to the System partition.

I have had a look to IOCTLs related to disk geometry but I didn't find anything useful. I need to distinguish the Boot Manager partition from, let's say, a 100 MB manufacturer Recovery partition.

BCDEDIT.exe tool shows the info needed;

Identificador           {bootmgr}
device                  partition=\Device\HarddiskVolume1
description             Windows Boot Manager
locale                  es-ES
inherit                 {globalsettings}
extendedinput           Yes
default                 {current}
resumeobject            {5586dd33-361b-11e0-8df8-0018716eb820}
displayorder            {current}
toolsdisplayorder       {memdiag}
timeout                 30
customactions           0x1000085000001
                        0x5400000f
custom:5400000f         {1f473c8f-0c00-11e1-898d-78acc0c157a7}

I'm developing my app in C and therefore the BCDEDIT approach implies to include a COM/WMI dependency to my relatively simple application.

Please, note that I'm talking about opening a handle to BootMgr partition using "\Device\HarddiskVolume1" retrieved through WMI and then using IOCTL_STORAGE_GET_DEVICE_NUMBER:

hHandle = CreateFile ("\\\\?\\GLOBALROOT\\Device\\HarddiskVolume1", 
                        GENERIC_READ|GENERIC_WRITE,
                        FILE_SHARE_READ|FILE_SHARE_WRITE, 
                        NULL, 
                        OPEN_EXISTING, 
                        FILE_ATTRIBUTE_NORMAL,
                        NULL);

if ( hHandle != INVALID_HANDLE_VALUE )
{
    VOLUME_DISK_EXTENTS diskExtents;
    DWORD dwSize;
    BOOL iRes;

    iRes = DeviceIoControl(hHandle,
                            IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
                            NULL,
                            0,
                            (LPVOID) &diskExtents,
                            (DWORD) sizeof(diskExtents),
                            (LPDWORD) &dwSize,
                            NULL);

    if (iRes)
    {
        STORAGE_DEVICE_NUMBER deviceNumber;
        DWORD bytesReturned =  0;

        iRes = DeviceIoControl(hHandle, 
                        IOCTL_STORAGE_GET_DEVICE_NUMBER, 
                        NULL, 
                        0, 
                        &deviceNumber, 
                        sizeof(deviceNumber), 
                        &bytesReturned, NULL);

Any ideas for a simpler workaround?

도움이 되었습니까?

해결책

You can find the system volume (where Windows booted and also where bootmgr reside) by looking in the registry: HKLM\SYSTEM\Setup\SystemPartition. This will contain a name like \Device\HardDiskVolume1.

On a disk formatted by Windows 7 setup, this corresponds to the 100MB partition that starts before the partition that contains drive C:. On Windows 7, the big partition that contains drive C: is \Device\HardDiskVolume2.

다른 팁

Perhaps it is too late, but this info can help someone;

You may try to find BootIndicator partition by sending IOCTL code such as PARTITION_INFORMATION_EX for real solution.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top