The current implementation of the GetDriveTypeW/A function relies on native system calls (such as fstatfs() in Linux) to determine the actual type of the drive, disregarding any configuration set through the mounts manager (wincfg). This patch changes the priority, giving precedence to the mounts manager configuration, making the user responsible for mapping drives. System calls will only be used if the drive is not explicitly configured by the user. I acknowledge that this is a breaking change, but I believe it enforces the correct behavior for GetDriveType.
Resolves: https://forum.winehq.org/viewtopic.php?t=38909
-- v5: fix: support custom cdrom labels
From: robert robert.ayrapetyan@gmail.com
--- dlls/kernelbase/volume.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/dlls/kernelbase/volume.c b/dlls/kernelbase/volume.c index d4895228525..623892e3bc7 100644 --- a/dlls/kernelbase/volume.c +++ b/dlls/kernelbase/volume.c @@ -127,7 +127,11 @@ static DWORD get_mountmgr_drive_type( LPCWSTR root ) DWORD br;
memset( &data, 0, sizeof(data) ); - if (root) data.letter = root[0]; + if (root) + { + if (wcslen(root) < 3 || root[1] != ':' || root[2] != '\') return DRIVE_UNKNOWN; + data.letter = root[0]; + } else { WCHAR curdir[MAX_PATH]; @@ -580,13 +584,13 @@ UINT WINAPI DECLSPEC_HOTPATCH GetDriveTypeW( LPCWSTR root ) HANDLE handle; UINT ret;
+ ret = get_mountmgr_drive_type( root ); + if (ret != DRIVE_UNKNOWN) { + return ret; + } + if (!open_device_root( root, &handle )) { - /* CD ROM devices do not necessarily have a volume, but a drive type */ - ret = get_mountmgr_drive_type( root ); - if (ret == DRIVE_CDROM || ret == DRIVE_REMOVABLE) - return ret; - return DRIVE_NO_ROOT_DIR; }
From: robert robert.ayrapetyan@gmail.com
--- dlls/kernel32/volume.c | 2 +- programs/winecfg/driveui.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/dlls/kernel32/volume.c b/dlls/kernel32/volume.c index 54fc65343ad..299f6772a37 100644 --- a/dlls/kernel32/volume.c +++ b/dlls/kernel32/volume.c @@ -265,6 +265,7 @@ BOOL WINAPI SetVolumeLabelW( LPCWSTR root, LPCWSTR label ) break; case DRIVE_REMOVABLE: case DRIVE_FIXED: + case DRIVE_CDROM: { WCHAR labelW[] = L"A:\.windows-label";
@@ -291,7 +292,6 @@ BOOL WINAPI SetVolumeLabelW( LPCWSTR root, LPCWSTR label ) } case DRIVE_REMOTE: case DRIVE_RAMDISK: - case DRIVE_CDROM: SetLastError( ERROR_ACCESS_DENIED ); break; } diff --git a/programs/winecfg/driveui.c b/programs/winecfg/driveui.c index 611c467b082..913e54f572d 100644 --- a/programs/winecfg/driveui.c +++ b/programs/winecfg/driveui.c @@ -176,7 +176,7 @@ static void enable_labelserial_box(HWND dialog, int mode) disable(IDC_EDIT_DEVICE); disable(IDC_BUTTON_BROWSE_DEVICE); disable(IDC_EDIT_SERIAL); - disable(IDC_EDIT_LABEL); + enable(IDC_EDIT_LABEL); break;
case BOX_MODE_NORMAL: