Skip to content

Commit b2c1dd8

Browse files
committed
[DISKPART] Fix the drive letter deletion code
The remove and assign commands work properly now.
1 parent 9d5c0bf commit b2c1dd8

1 file changed

Lines changed: 7 additions & 14 deletions

File tree

base/system/diskpart/mountmgr.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ AssignDriveLetter(
219219
DeviceName,
220220
DeviceNameLength);
221221

222-
DPRINT1("\n");
223222
Status = OpenMountManager(&MountMgrHandle, GENERIC_READ | GENERIC_WRITE);
224223
if (!NT_SUCCESS(Status))
225224
{
@@ -228,7 +227,6 @@ DPRINT1("\n");
228227
goto done;
229228
}
230229

231-
DPRINT1("\n");
232230
Status = NtDeviceIoControlFile(MountMgrHandle,
233231
NULL,
234232
NULL,
@@ -246,7 +244,6 @@ DPRINT1("\n");
246244
goto done;
247245
}
248246

249-
DPRINT1("\n");
250247
done:
251248
if (MountMgrHandle)
252249
NtClose(MountMgrHandle);
@@ -270,7 +267,7 @@ AssignNextDriveLetter(
270267
NTSTATUS Status;
271268
BOOL Ret = TRUE;
272269

273-
DPRINT1("AssignNextDriveLetter(%S %p)\n", DeviceName, DriveLetter);
270+
DPRINT("AssignNextDriveLetter(%S %p)\n", DeviceName, DriveLetter);
274271

275272
DeviceNameLength = wcslen(DeviceName) * sizeof(WCHAR);
276273

@@ -288,7 +285,6 @@ AssignNextDriveLetter(
288285
DeviceName,
289286
DeviceNameLength);
290287

291-
DPRINT1("\n");
292288
Status = OpenMountManager(&MountMgrHandle, GENERIC_READ | GENERIC_WRITE);
293289
if (!NT_SUCCESS(Status))
294290
{
@@ -297,7 +293,6 @@ DPRINT1("\n");
297293
goto done;
298294
}
299295

300-
DPRINT1("\n");
301296
Status = NtDeviceIoControlFile(MountMgrHandle,
302297
NULL,
303298
NULL,
@@ -315,7 +310,6 @@ DPRINT1("\n");
315310
goto done;
316311
}
317312

318-
DPRINT1("\n");
319313
done:
320314
if (MountMgrHandle)
321315
NtClose(MountMgrHandle);
@@ -342,12 +336,13 @@ DeleteDriveLetter(
342336
PMOUNTMGR_MOUNT_POINTS OutputBuffer = NULL;
343337
WCHAR DosDeviceName[30];
344338
ULONG InputBufferLength, DosDeviceNameLength;
339+
ULONG OutputBufferLength = 0x1000;
345340
HANDLE MountMgrHandle = NULL;
346341
IO_STATUS_BLOCK Iosb;
347342
NTSTATUS Status;
348343
BOOL Ret = TRUE;
349344

350-
DPRINT1("DeleteDriveLetter(%c)\n", DriveLetter);
345+
DPRINT("DeleteDriveLetter(%c)\n", DriveLetter);
351346

352347
/* Setup the device name of the letter to delete */
353348
swprintf(DosDeviceName, L"\\DosDevices\\%c:", DriveLetter);
@@ -363,21 +358,21 @@ DeleteDriveLetter(
363358
}
364359

365360
/* Fill it in */
366-
// RtlZeroMemory(InputBuffer, InputBufferLength);
367361
InputBuffer->SymbolicLinkNameOffset = sizeof(MOUNTMGR_MOUNT_POINT);
368362
InputBuffer->SymbolicLinkNameLength = DosDeviceNameLength;
369363
RtlCopyMemory(&InputBuffer[1], DosDeviceName, DosDeviceNameLength);
370364

371365
/* Allocate big enough output buffer (we don't care about the output) */
372-
OutputBuffer = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, 0x1000);
366+
OutputBuffer = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, OutputBufferLength);
373367
if (OutputBuffer == NULL)
374368
{
375369
DPRINT1("OutputBuffer allocation failed!\n");
376370
Ret = FALSE;
377371
goto done;
378372
}
379373

380-
DPRINT1("\n");
374+
OutputBuffer->Size = OutputBufferLength;
375+
381376
Status = OpenMountManager(&MountMgrHandle, GENERIC_READ | GENERIC_WRITE);
382377
if (!NT_SUCCESS(Status))
383378
{
@@ -386,7 +381,6 @@ DPRINT1("\n");
386381
goto done;
387382
}
388383

389-
DPRINT1("\n");
390384
Status = NtDeviceIoControlFile(MountMgrHandle,
391385
NULL,
392386
NULL,
@@ -396,15 +390,14 @@ DPRINT1("\n");
396390
InputBuffer,
397391
InputBufferLength,
398392
OutputBuffer,
399-
0x1000);
393+
OutputBufferLength);
400394
if (!NT_SUCCESS(Status))
401395
{
402396
DPRINT1("NtDeviceIoControlFile() failed (Status 0x%08lx)\n", Status);
403397
Ret = FALSE;
404398
goto done;
405399
}
406400

407-
DPRINT1("\n");
408401
done:
409402
if (MountMgrHandle)
410403
NtClose(MountMgrHandle);

0 commit comments

Comments
 (0)