diff --git a/reactos/drivers/filters/mountmgr/mntmgr.h b/reactos/drivers/filters/mountmgr/mntmgr.h index d0cf8a96151..e51188ae4cb 100644 --- a/reactos/drivers/filters/mountmgr/mntmgr.h +++ b/reactos/drivers/filters/mountmgr/mntmgr.h @@ -13,7 +13,7 @@ #undef IsEqualGUID #endif -#define IsEqualGUID(rguid1, rguid2) (!RtlCompareMemory(rguid1, rguid2, sizeof(GUID))) +#define IsEqualGUID(rguid1, rguid2) (RtlCompareMemory(rguid1, rguid2, sizeof(GUID)) == sizeof(GUID)) #define FILE_READ_PROPERTIES 0x00000008 #define FILE_WRITE_PROPERTIES 0x00000010 diff --git a/reactos/drivers/filters/mountmgr/mountmgr.c b/reactos/drivers/filters/mountmgr/mountmgr.c index cddbcc446f5..f623976a74e 100644 --- a/reactos/drivers/filters/mountmgr/mountmgr.c +++ b/reactos/drivers/filters/mountmgr/mountmgr.c @@ -132,8 +132,8 @@ CreateNewDriveLetterName(OUT PUNICODE_STRING DriveLetter, NTSTATUS Status = STATUS_UNSUCCESSFUL; /* Allocate a big enough buffer to contain the symbolic link */ - DriveLetter->MaximumLength = sizeof(DosDevices.Buffer) + 3 * sizeof(WCHAR); - DriveLetter->Buffer = AllocatePool(sizeof(DosDevices.Buffer) + 3 * sizeof(WCHAR)); + DriveLetter->MaximumLength = DosDevices.Length + 3 * sizeof(WCHAR); + DriveLetter->Buffer = AllocatePool(DriveLetter->MaximumLength); if (!DriveLetter->Buffer) { return STATUS_INSUFFICIENT_RESOURCES; @@ -143,9 +143,9 @@ CreateNewDriveLetterName(OUT PUNICODE_STRING DriveLetter, RtlCopyUnicodeString(DriveLetter, &DosDevices); /* Update string to reflect real contents */ - DriveLetter->Length = sizeof(DosDevices.Buffer) + 2 * sizeof(WCHAR); - DriveLetter->Buffer[(sizeof(DosDevices.Buffer) + 2 * sizeof(WCHAR)) / sizeof (WCHAR)] = UNICODE_NULL; - DriveLetter->Buffer[(sizeof(DosDevices.Buffer) + sizeof(WCHAR)) / sizeof (WCHAR)] = L':'; + DriveLetter->Length = DosDevices.Length + 2 * sizeof(WCHAR); + DriveLetter->Buffer[DosDevices.Length / sizeof(WCHAR) + 2] = UNICODE_NULL; + DriveLetter->Buffer[DosDevices.Length / sizeof(WCHAR) + 1] = L':'; /* If caller wants a no drive entry */ if (Letter == (UCHAR)-1) @@ -158,7 +158,7 @@ CreateNewDriveLetterName(OUT PUNICODE_STRING DriveLetter, else if (Letter) { /* Use the letter given by the caller */ - DriveLetter->Buffer[sizeof(DosDevices.Buffer) / sizeof(WCHAR)] = (WCHAR)Letter; + DriveLetter->Buffer[DosDevices.Length / sizeof(WCHAR)] = (WCHAR)Letter; Status = GlobalCreateSymbolicLink(DriveLetter, DeviceName); if (NT_SUCCESS(Status)) { @@ -187,16 +187,18 @@ CreateNewDriveLetterName(OUT PUNICODE_STRING DriveLetter, /* Try to affect a letter (up to Z, ofc) until it's possible */ for (; Letter <= 'Z'; Letter++) { - DriveLetter->Buffer[sizeof(DosDevices.Buffer) / sizeof(WCHAR)] = (WCHAR)Letter; + DriveLetter->Buffer[DosDevices.Length / sizeof(WCHAR)] = (WCHAR)Letter; Status = GlobalCreateSymbolicLink(DriveLetter, DeviceName); if (NT_SUCCESS(Status)) { + DPRINT("Assigned drive %c: to %wZ\n", Letter, DeviceName); return Status; } } /* We failed to allocate a letter */ FreePool(DriveLetter->Buffer); + DPRINT("Failed to create a drive letter for %wZ\n", DeviceName); return Status; } @@ -558,7 +560,7 @@ QueryDeviceInformation(IN PUNICODE_STRING SymbolicName, /* Query unique ID */ KeInitializeEvent(&Event, NotificationEvent, FALSE); - Irp = IoBuildDeviceIoControlRequest(IOCTL_MOUNTDEV_QUERY_DEVICE_NAME, + Irp = IoBuildDeviceIoControlRequest(IOCTL_MOUNTDEV_QUERY_UNIQUE_ID, DeviceObject, NULL, 0, @@ -1070,7 +1072,7 @@ MountMgrMountedDeviceArrival(IN PDEVICE_EXTENSION DeviceExtension, { CurrentDevice = CONTAINING_RECORD(NextEntry, DEVICE_INFORMATION, DeviceListEntry); - if (RtlEqualUnicodeString(&(DeviceInformation->DeviceName), &TargetDeviceName, TRUE)) + if (RtlEqualUnicodeString(&(CurrentDevice->DeviceName), &TargetDeviceName, TRUE)) { break; } @@ -1876,7 +1878,7 @@ DriverEntry(IN PDRIVER_OBJECT DriverObject, &MountedDevicesGuid, DriverObject, MountMgrMountedDeviceNotification, - DeviceObject, + DeviceExtension, &(DeviceExtension->NotificationEntry)); if (!NT_SUCCESS(Status))