mountmgr: Allow querying a Unix device by device ID.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2020-03-27 10:32:30 -05:00 committed by Alexandre Julliard
parent cf174edfd9
commit 54f93b9bb9
4 changed files with 64 additions and 20 deletions

View File

@ -1617,6 +1617,18 @@ NTSTATUS remove_dos_device( int letter, const char *udi )
return status;
}
enum mountmgr_fs_type get_mountmgr_fs_type(enum fs_type fs_type)
{
switch (fs_type)
{
case FS_ISO9660: return MOUNTMGR_FS_TYPE_ISO9660;
case FS_UDF: return MOUNTMGR_FS_TYPE_UDF;
case FS_FAT1216: return MOUNTMGR_FS_TYPE_FAT;
case FS_FAT32: return MOUNTMGR_FS_TYPE_FAT32;
default: return MOUNTMGR_FS_TYPE_NTFS;
}
}
/* query information about an existing dos drive, by letter or udi */
NTSTATUS query_dos_device( int letter, enum device_type *type, enum mountmgr_fs_type *fs_type,
char **device, char **mount_point )
@ -1631,18 +1643,37 @@ NTSTATUS query_dos_device( int letter, enum device_type *type, enum mountmgr_fs_
if (drive->drive != letter) continue;
disk_device = drive->volume->device;
if (type) *type = disk_device->type;
if (fs_type)
{
switch (drive->volume->fs_type)
{
case FS_ISO9660: *fs_type = MOUNTMGR_FS_TYPE_ISO9660; break;
case FS_UDF: *fs_type = MOUNTMGR_FS_TYPE_UDF; break;
case FS_FAT1216: *fs_type = MOUNTMGR_FS_TYPE_FAT; break;
case FS_FAT32: *fs_type = MOUNTMGR_FS_TYPE_FAT32; break;
default: *fs_type = MOUNTMGR_FS_TYPE_NTFS; break;
}
*fs_type = drive->volume->fs_type;
}
if (fs_type) *fs_type = get_mountmgr_fs_type( drive->volume->fs_type );
if (device) *device = strdupA( disk_device->unix_device );
if (mount_point) *mount_point = strdupA( disk_device->unix_mount );
status = STATUS_SUCCESS;
break;
}
LeaveCriticalSection( &device_section );
return status;
}
/* query information about an existing unix device, by dev_t */
NTSTATUS query_unix_device( ULONGLONG unix_dev, enum device_type *type,
enum mountmgr_fs_type *fs_type, char **device, char **mount_point )
{
NTSTATUS status = STATUS_NO_SUCH_DEVICE;
struct volume *volume;
struct disk_device *disk_device;
struct stat st;
EnterCriticalSection( &device_section );
LIST_FOR_EACH_ENTRY( volume, &volumes_list, struct volume, entry )
{
disk_device = volume->device;
if (!disk_device->unix_device
|| stat( disk_device->unix_device, &st ) < 0
|| st.st_rdev != unix_dev)
continue;
if (type) *type = disk_device->type;
if (fs_type) *fs_type = get_mountmgr_fs_type( volume->fs_type );
if (device) *device = strdupA( disk_device->unix_device );
if (mount_point) *mount_point = strdupA( disk_device->unix_mount );
status = STATUS_SUCCESS;

View File

@ -299,9 +299,19 @@ static NTSTATUS query_unix_drive( void *buff, SIZE_T insize,
enum device_type device_type;
char *ptr;
if (letter < 'a' || letter > 'z') return STATUS_INVALID_PARAMETER;
if (!letter)
{
if ((status = query_unix_device( input->unix_dev, &device_type,
&fs_type, &device, &mount_point )))
return status;
}
else
{
if (letter < 'a' || letter > 'z') return STATUS_INVALID_PARAMETER;
if ((status = query_dos_device( letter - 'a', &device_type, &fs_type, &device, &mount_point ))) return status;
}
if ((status = query_dos_device( letter - 'a', &device_type, &fs_type, &device, &mount_point ))) return status;
switch (device_type)
{
case DEVICE_UNKNOWN: type = DRIVE_UNKNOWN; break;

View File

@ -59,6 +59,8 @@ extern NTSTATUS add_dos_device( int letter, const char *udi, const char *device,
extern NTSTATUS remove_dos_device( int letter, const char *udi ) DECLSPEC_HIDDEN;
extern NTSTATUS query_dos_device( int letter, enum device_type *type, enum mountmgr_fs_type *fs_type,
char **device, char **mount_point ) DECLSPEC_HIDDEN;
extern NTSTATUS query_unix_device( ULONGLONG unix_dev, enum device_type *type,
enum mountmgr_fs_type *fs_type, char **device, char **mount_point ) DECLSPEC_HIDDEN;
extern NTSTATUS WINAPI harddisk_driver_entry( DRIVER_OBJECT *driver, UNICODE_STRING *path ) DECLSPEC_HIDDEN;
extern NTSTATUS WINAPI serial_driver_entry( DRIVER_OBJECT *driver, UNICODE_STRING *path ) DECLSPEC_HIDDEN;
extern NTSTATUS WINAPI parallel_driver_entry( DRIVER_OBJECT *driver, UNICODE_STRING *path ) DECLSPEC_HIDDEN;

View File

@ -63,12 +63,13 @@ enum mountmgr_fs_type
struct mountmgr_unix_drive
{
ULONG size;
ULONG type;
ULONG fs_type;
WCHAR letter;
USHORT mount_point_offset;
USHORT device_offset;
ULONG size;
ULONG type;
ULONG fs_type;
ULONGLONG unix_dev;
WCHAR letter;
USHORT mount_point_offset;
USHORT device_offset;
};
#define IOCTL_MOUNTMGR_QUERY_DHCP_REQUEST_PARAMS CTL_CODE(MOUNTMGRCONTROLTYPE, 64, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)