mountmgr: Set the drive letter at creation time.

This commit is contained in:
Alexandre Julliard 2009-07-22 18:25:38 +02:00
parent 6880b4d175
commit 968161e106

View File

@ -337,13 +337,14 @@ static void delete_volume( struct volume *volume )
} }
/* create the disk device for a given volume */ /* create the disk device for a given volume */
static NTSTATUS create_dos_device( const char *udi, enum device_type type, struct dos_drive **drive_ret ) static NTSTATUS create_dos_device( const char *udi, int letter, enum device_type type,
struct dos_drive **drive_ret )
{ {
struct dos_drive *drive; struct dos_drive *drive;
NTSTATUS status; NTSTATUS status;
if (!(drive = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*drive) ))) return STATUS_NO_MEMORY; if (!(drive = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*drive) ))) return STATUS_NO_MEMORY;
drive->drive = -1; drive->drive = letter;
drive->mount = NULL; drive->mount = NULL;
if (!(status = create_volume( udi, type, &drive->volume ))) if (!(status = create_volume( udi, type, &drive->volume )))
@ -562,9 +563,8 @@ static void create_drive_devices(void)
} }
} }
if (!create_dos_device( NULL, drive_type, &drive )) if (!create_dos_device( NULL, i, drive_type, &drive ))
{ {
drive->drive = i;
set_volume_info( drive->volume, drive, device, link, drive_type, get_default_uuid(i) ); set_volume_info( drive->volume, drive, device, link, drive_type, get_default_uuid(i) );
} }
else else
@ -616,6 +616,7 @@ NTSTATUS add_dos_device( int letter, const char *udi, const char *device,
const char *mount_point, enum device_type type, const GUID *guid ) const char *mount_point, enum device_type type, const GUID *guid )
{ {
char *path, *p; char *path, *p;
HKEY hkey;
NTSTATUS status = STATUS_SUCCESS; NTSTATUS status = STATUS_SUCCESS;
struct dos_drive *drive, *next; struct dos_drive *drive, *next;
@ -647,7 +648,7 @@ NTSTATUS add_dos_device( int letter, const char *udi, const char *device,
if (drive->drive == letter) delete_dos_device( drive ); if (drive->drive == letter) delete_dos_device( drive );
} }
if ((status = create_dos_device( udi, type, &drive ))) goto done; if ((status = create_dos_device( udi, letter, type, &drive ))) goto done;
found: found:
if (!guid) guid = get_default_uuid( letter ); if (!guid) guid = get_default_uuid( letter );
@ -657,32 +658,28 @@ found:
set_drive_letter( drive, letter ); set_drive_letter( drive, letter );
set_volume_info( drive->volume, drive, device, mount_point, type, guid ); set_volume_info( drive->volume, drive, device, mount_point, type, guid );
if (drive->drive != -1) TRACE( "added device %c: udi %s for %s on %s type %u\n",
'a' + drive->drive, wine_dbgstr_a(udi), wine_dbgstr_a(device),
wine_dbgstr_a(mount_point), type );
/* hack: force the drive type in the registry */
if (!RegCreateKeyW( HKEY_LOCAL_MACHINE, drives_keyW, &hkey ))
{ {
HKEY hkey; const WCHAR *type_name = drive_types[type];
WCHAR name[3] = {'a',':',0};
TRACE( "added device %c: udi %s for %s on %s type %u\n", name[0] += drive->drive;
'a' + drive->drive, wine_dbgstr_a(udi), wine_dbgstr_a(device), if (!type_name[0] && type == DEVICE_HARDDISK) type_name = drive_types[DEVICE_FLOPPY];
wine_dbgstr_a(mount_point), type ); if (type_name[0])
RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)type_name,
/* hack: force the drive type in the registry */ (strlenW(type_name) + 1) * sizeof(WCHAR) );
if (!RegCreateKeyW( HKEY_LOCAL_MACHINE, drives_keyW, &hkey )) else
{ RegDeleteValueW( hkey, name );
const WCHAR *type_name = drive_types[type]; RegCloseKey( hkey );
WCHAR name[3] = {'a',':',0};
name[0] += drive->drive;
if (!type_name[0] && type == DEVICE_HARDDISK) type_name = drive_types[DEVICE_FLOPPY];
if (type_name[0])
RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)type_name,
(strlenW(type_name) + 1) * sizeof(WCHAR) );
else
RegDeleteValueW( hkey, name );
RegCloseKey( hkey );
}
if (udi) send_notify( drive->drive, DBT_DEVICEARRIVAL );
} }
if (udi) send_notify( drive->drive, DBT_DEVICEARRIVAL );
done: done:
RtlFreeHeap( GetProcessHeap(), 0, path ); RtlFreeHeap( GetProcessHeap(), 0, path );
return status; return status;