3 * Copyright (C) 2011-2012 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 * COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS kernel
21 * FILE: drivers/filesystem/mountmgr/device.c
22 * PURPOSE: Mount Manager - Device Control
23 * PROGRAMMER: Pierre Schweitzer (pierre.schweitzer@reactos.org)
26 /* INCLUDES *****************************************************************/
37 MountMgrChangeNotify(IN PDEVICE_EXTENSION DeviceExtension
,
42 PIO_STACK_LOCATION Stack
;
43 PMOUNTMGR_CHANGE_NOTIFY_INFO ChangeNotify
;
45 /* Get the I/O buffer */
46 Stack
= IoGetCurrentIrpStackLocation(Irp
);
47 ChangeNotify
= (PMOUNTMGR_CHANGE_NOTIFY_INFO
)Irp
->AssociatedIrp
.SystemBuffer
;
50 if (Stack
->Parameters
.DeviceIoControl
.OutputBufferLength
< sizeof(MOUNTMGR_CHANGE_NOTIFY_INFO
) ||
51 Stack
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(MOUNTMGR_CHANGE_NOTIFY_INFO
))
53 return STATUS_INVALID_PARAMETER
;
56 /* If epic number doesn't match, just return now one */
57 if (DeviceExtension
->EpicNumber
!= ChangeNotify
->EpicNumber
)
59 ChangeNotify
->EpicNumber
= DeviceExtension
->EpicNumber
;
60 Irp
->IoStatus
.Information
= 0;
61 return STATUS_SUCCESS
;
64 /* If IRP is to be canceled, forget about that */
65 IoAcquireCancelSpinLock(&OldIrql
);
68 Status
= STATUS_CANCELLED
;
70 /* Otherwise queue the IRP to be notified with the next epic number change */
73 InsertTailList(&(DeviceExtension
->IrpListHead
), &(Irp
->Tail
.Overlay
.ListEntry
));
74 IoMarkIrpPending(Irp
);
75 IoSetCancelRoutine(Irp
, MountMgrCancel
);
76 Status
= STATUS_PENDING
;
78 IoReleaseCancelSpinLock(OldIrql
);
87 MountmgrWriteNoAutoMount(IN PDEVICE_EXTENSION DeviceExtension
)
89 ULONG Value
= DeviceExtension
->NoAutoMount
;
91 return RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE
,
92 DeviceExtension
->RegistryPath
.Buffer
,
104 MountMgrSetAutoMount(IN PDEVICE_EXTENSION DeviceExtension
,
107 PIO_STACK_LOCATION Stack
;
108 PMOUNTMGR_SET_AUTO_MOUNT SetState
;
110 Stack
= IoGetCurrentIrpStackLocation(Irp
);
112 if (Stack
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(MOUNTMGR_SET_AUTO_MOUNT
))
114 Irp
->IoStatus
.Information
= 0;
115 return STATUS_INVALID_PARAMETER
;
118 /* Only change if there's a real difference */
119 SetState
= (PMOUNTMGR_SET_AUTO_MOUNT
)Irp
->AssociatedIrp
.SystemBuffer
;
120 if (SetState
->NewState
== !DeviceExtension
->NoAutoMount
)
122 Irp
->IoStatus
.Information
= 0;
123 return STATUS_SUCCESS
;
126 /* Set new state; ! on purpose */
127 DeviceExtension
->NoAutoMount
= !SetState
->NewState
;
128 Irp
->IoStatus
.Information
= 0;
129 return MountmgrWriteNoAutoMount(DeviceExtension
);
136 MountMgrQueryAutoMount(IN PDEVICE_EXTENSION DeviceExtension
,
139 PIO_STACK_LOCATION Stack
;
140 PMOUNTMGR_QUERY_AUTO_MOUNT QueryState
;
142 Stack
= IoGetCurrentIrpStackLocation(Irp
);
144 if (Stack
->Parameters
.DeviceIoControl
.OutputBufferLength
< sizeof(MOUNTMGR_QUERY_AUTO_MOUNT
))
146 Irp
->IoStatus
.Information
= 0;
147 return STATUS_INVALID_PARAMETER
;
150 QueryState
= (PMOUNTMGR_QUERY_AUTO_MOUNT
)Irp
->AssociatedIrp
.SystemBuffer
;
151 QueryState
->CurrentState
= !DeviceExtension
->NoAutoMount
;
152 Irp
->IoStatus
.Information
= sizeof(MOUNTMGR_QUERY_AUTO_MOUNT
);
154 return STATUS_SUCCESS
;
162 ScrubRegistryRoutine(IN PWSTR ValueName
,
165 IN ULONG ValueLength
,
167 IN PVOID EntryContext
)
170 PLIST_ENTRY NextEntry
;
171 PDEVICE_INFORMATION DeviceInfo
;
172 PBOOLEAN Continue
= EntryContext
;
173 PDEVICE_EXTENSION DeviceExtension
= Context
;
175 if (ValueType
!= REG_BINARY
)
177 return STATUS_SUCCESS
;
180 /* Delete values for devices that don't have the matching unique ID */
181 if (!IsListEmpty(&(DeviceExtension
->DeviceListHead
)))
183 for (NextEntry
= DeviceExtension
->DeviceListHead
.Flink
;
184 NextEntry
!= &(DeviceExtension
->DeviceListHead
);
185 NextEntry
= NextEntry
->Flink
)
187 DeviceInfo
= CONTAINING_RECORD(NextEntry
,
191 if (!DeviceInfo
->UniqueId
|| DeviceInfo
->UniqueId
->UniqueIdLength
!= ValueLength
)
196 if (RtlCompareMemory(DeviceInfo
->UniqueId
->UniqueId
, ValueData
, ValueLength
) == ValueLength
)
198 return STATUS_SUCCESS
;
203 /* Wrong unique ID, scrub it */
204 Status
= RtlDeleteRegistryValue(RTL_REGISTRY_ABSOLUTE
,
207 if (!NT_SUCCESS(Status
))
210 return STATUS_UNSUCCESSFUL
;
221 MountMgrScrubRegistry(IN PDEVICE_EXTENSION DeviceExtension
)
225 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
229 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
230 QueryTable
[0].QueryRoutine
= ScrubRegistryRoutine
;
231 QueryTable
[0].EntryContext
= &Continue
;
234 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
249 MountMgrCreatePoint(IN PDEVICE_EXTENSION DeviceExtension
,
253 PIO_STACK_LOCATION Stack
;
254 PMOUNTMGR_CREATE_POINT_INPUT Point
;
255 UNICODE_STRING DeviceName
, SymbolicName
;
257 Stack
= IoGetCurrentIrpStackLocation(Irp
);
259 if (Stack
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(MOUNTMGR_CREATE_POINT_INPUT
))
261 return STATUS_INVALID_PARAMETER
;
264 Point
= (PMOUNTMGR_CREATE_POINT_INPUT
)Irp
->AssociatedIrp
.SystemBuffer
;
266 MaxLength
= MAX((Point
->DeviceNameOffset
+ Point
->DeviceNameLength
),
267 (Point
->SymbolicLinkNameLength
+ Point
->SymbolicLinkNameOffset
));
268 if (MaxLength
>= Stack
->Parameters
.DeviceIoControl
.InputBufferLength
)
270 return STATUS_INVALID_PARAMETER
;
273 /* Get all the strings and call the worker */
274 SymbolicName
.Length
= Point
->SymbolicLinkNameLength
;
275 SymbolicName
.MaximumLength
= Point
->SymbolicLinkNameLength
;
276 DeviceName
.Length
= Point
->DeviceNameLength
;
277 DeviceName
.MaximumLength
= Point
->DeviceNameLength
;
278 SymbolicName
.Buffer
= (PVOID
)((ULONG_PTR
)Point
+ Point
->SymbolicLinkNameOffset
);
279 DeviceName
.Buffer
= (PVOID
)((ULONG_PTR
)Point
+ Point
->DeviceNameOffset
);
281 return MountMgrCreatePointWorker(DeviceExtension
, &SymbolicName
, &DeviceName
);
288 MountMgrCheckUnprocessedVolumes(IN PDEVICE_EXTENSION DeviceExtension
,
291 PLIST_ENTRY NextEntry
;
292 PDEVICE_INFORMATION DeviceInformation
;
293 NTSTATUS ArrivalStatus
, Status
= STATUS_SUCCESS
;
295 UNREFERENCED_PARAMETER(Irp
);
297 /* No offline volumes, nothing more to do */
298 if (IsListEmpty(&(DeviceExtension
->OfflineDeviceListHead
)))
300 KeReleaseSemaphore(&(DeviceExtension
->DeviceLock
), IO_NO_INCREMENT
, 1, FALSE
);
301 return STATUS_SUCCESS
;
304 KeReleaseSemaphore(&(DeviceExtension
->DeviceLock
), IO_NO_INCREMENT
, 1, FALSE
);
306 /* Reactivate all the offline volumes */
307 while (!IsListEmpty(&(DeviceExtension
->OfflineDeviceListHead
)))
309 NextEntry
= RemoveHeadList(&(DeviceExtension
->OfflineDeviceListHead
));
310 DeviceInformation
= CONTAINING_RECORD(NextEntry
, DEVICE_INFORMATION
, DeviceListEntry
);
312 ArrivalStatus
= MountMgrMountedDeviceArrival(DeviceExtension
,
313 &(DeviceInformation
->SymbolicName
),
314 DeviceInformation
->Volume
);
315 /* Then, remove them dead information */
316 MountMgrFreeDeadDeviceInfo(DeviceInformation
);
318 if (NT_SUCCESS(Status
))
320 Status
= ArrivalStatus
;
331 IsFtVolume(IN PUNICODE_STRING SymbolicName
)
336 PFILE_OBJECT FileObject
;
337 IO_STATUS_BLOCK IoStatusBlock
;
338 PARTITION_INFORMATION PartitionInfo
;
339 PDEVICE_OBJECT DeviceObject
, FileDeviceObject
;
341 /* Get device object */
342 Status
= IoGetDeviceObjectPointer(SymbolicName
,
343 FILE_READ_ATTRIBUTES
,
346 if (!NT_SUCCESS(Status
))
351 /* Get attached device */
352 FileDeviceObject
= FileObject
->DeviceObject
;
353 DeviceObject
= IoGetAttachedDeviceReference(FileDeviceObject
);
355 /* FT volume can't be removable */
356 if (FileDeviceObject
->Characteristics
& FILE_REMOVABLE_MEDIA
)
358 ObDereferenceObject(DeviceObject
);
359 ObDereferenceObject(FileObject
);
363 ObDereferenceObject(FileObject
);
365 /* Get partition information */
366 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
367 Irp
= IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_PARTITION_INFO
,
372 sizeof(PartitionInfo
),
378 ObDereferenceObject(DeviceObject
);
382 Status
= IoCallDriver(DeviceObject
, Irp
);
383 if (Status
== STATUS_PENDING
)
385 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
386 Status
= IoStatusBlock
.Status
;
389 ObDereferenceObject(DeviceObject
);
390 if (!NT_SUCCESS(Status
))
395 /* Check if this is a FT volume */
396 return IsRecognizedPartition(PartitionInfo
.PartitionType
);
403 ProcessSuggestedDriveLetters(IN PDEVICE_EXTENSION DeviceExtension
)
405 WCHAR NameBuffer
[DRIVE_LETTER_LENGTH
/ sizeof(WCHAR
)];
406 PLIST_ENTRY NextEntry
;
407 UNICODE_STRING SymbolicName
;
408 PDEVICE_INFORMATION DeviceInformation
;
410 /* No devices? Nothing to do! */
411 if (IsListEmpty(&(DeviceExtension
->DeviceListHead
)))
416 /* For all the devices */
417 for (NextEntry
= DeviceExtension
->DeviceListHead
.Flink
;
418 NextEntry
!= &(DeviceExtension
->DeviceListHead
);
419 NextEntry
= NextEntry
->Flink
)
421 DeviceInformation
= CONTAINING_RECORD(NextEntry
, DEVICE_INFORMATION
, DeviceListEntry
);
423 /* If no drive letter */
424 if (DeviceInformation
->SuggestedDriveLetter
== (UCHAR
)-1)
426 /* Ensure it has no entry yet */
427 if (!HasDriveLetter(DeviceInformation
) &&
428 !HasNoDriveLetterEntry(DeviceInformation
->UniqueId
))
431 CreateNoDriveLetterEntry(DeviceInformation
->UniqueId
);
434 DeviceInformation
->SuggestedDriveLetter
= 0;
436 /* Suggested letter & no entry */
437 else if (DeviceInformation
->SuggestedDriveLetter
&&
438 !HasNoDriveLetterEntry(DeviceInformation
->UniqueId
))
440 /* Just create a mount point */
441 SymbolicName
.Buffer
= NameBuffer
;
442 RtlCopyMemory(NameBuffer
, DosDevices
.Buffer
, DosDevices
.Length
);
443 NameBuffer
[LETTER_POSITION
] = DeviceInformation
->SuggestedDriveLetter
;
444 NameBuffer
[COLON_POSITION
] = L
':';
445 SymbolicName
.Length
=
446 SymbolicName
.MaximumLength
= DRIVE_LETTER_LENGTH
;
448 MountMgrCreatePointWorker(DeviceExtension
, &SymbolicName
, &(DeviceInformation
->DeviceName
));
457 MountMgrNextDriveLetterWorker(IN PDEVICE_EXTENSION DeviceExtension
,
458 IN PUNICODE_STRING DeviceName
,
459 OUT PMOUNTMGR_DRIVE_LETTER_INFORMATION DriveLetterInfo
)
463 PLIST_ENTRY NextEntry
;
464 PMOUNTDEV_UNIQUE_ID UniqueId
;
465 BOOLEAN Removable
, GptDriveLetter
;
466 PDEVICE_INFORMATION DeviceInformation
;
467 WCHAR NameBuffer
[DRIVE_LETTER_LENGTH
];
468 PSYMLINK_INFORMATION SymlinkInformation
;
469 UNICODE_STRING TargetDeviceName
, SymbolicName
;
471 /* First, process suggested letters */
472 if (!DeviceExtension
->ProcessedSuggestions
)
474 ProcessSuggestedDriveLetters(DeviceExtension
);
475 DeviceExtension
->ProcessedSuggestions
= TRUE
;
478 /* Then, get information about the device */
479 Status
= QueryDeviceInformation(DeviceName
, &TargetDeviceName
, NULL
, &Removable
, &GptDriveLetter
, NULL
, NULL
, NULL
);
480 if (!NT_SUCCESS(Status
))
485 /* Ensure we have such device */
486 NextEntry
= DeviceExtension
->DeviceListHead
.Flink
;
487 while (NextEntry
!= &(DeviceExtension
->DeviceListHead
))
489 DeviceInformation
= CONTAINING_RECORD(NextEntry
, DEVICE_INFORMATION
, DeviceListEntry
);
491 if (RtlCompareUnicodeString(&(DeviceInformation
->DeviceName
), &TargetDeviceName
, TRUE
) == 0)
496 NextEntry
= NextEntry
->Flink
;
499 if (NextEntry
== &(DeviceExtension
->DeviceListHead
))
501 FreePool(TargetDeviceName
.Buffer
);
502 return STATUS_OBJECT_NAME_NOT_FOUND
;
505 /* Now, mark we have assigned a letter (assumption) */
506 DeviceInformation
->LetterAssigned
=
507 DriveLetterInfo
->DriveLetterWasAssigned
= TRUE
;
509 /* Browse all the symlink to see if there's already a drive letter */
510 NextEntry
= DeviceInformation
->SymbolicLinksListHead
.Flink
;
511 while (NextEntry
!= &(DeviceInformation
->SymbolicLinksListHead
))
513 SymlinkInformation
= CONTAINING_RECORD(NextEntry
, SYMLINK_INFORMATION
, SymbolicLinksListEntry
);
515 /* This is a driver letter & online one, forget about new drive eltter */
516 if (IsDriveLetter(&(SymlinkInformation
->Name
)) && SymlinkInformation
->Online
)
518 DriveLetterInfo
->DriveLetterWasAssigned
= FALSE
;
519 DriveLetterInfo
->CurrentDriveLetter
= (CHAR
)SymlinkInformation
->Name
.Buffer
[LETTER_POSITION
];
523 NextEntry
= NextEntry
->Flink
;
526 /* If we didn't find a drive letter online
527 * ensure there's no GPT drive letter nor no drive entry
529 if (NextEntry
== &(DeviceInformation
->SymbolicLinksListHead
))
531 if (GptDriveLetter
|| HasNoDriveLetterEntry(DeviceInformation
->UniqueId
))
533 DriveLetterInfo
->DriveLetterWasAssigned
= FALSE
;
534 DriveLetterInfo
->CurrentDriveLetter
= 0;
540 /* No, ensure that the device is not automonted nor removable */
541 if (!DeviceExtension
->NoAutoMount
&& !Removable
)
543 if (DriveLetterInfo
->DriveLetterWasAssigned
)
545 DriveLetterInfo
->DriveLetterWasAssigned
= FALSE
;
546 DriveLetterInfo
->CurrentDriveLetter
= 0;
552 if (!DriveLetterInfo
->DriveLetterWasAssigned
)
557 /* Now everything is fine, start processing */
559 if (RtlPrefixUnicodeString(&DeviceFloppy
, &TargetDeviceName
, TRUE
))
561 /* If the device is a floppy, start with letter A */
564 else if (RtlPrefixUnicodeString(&DeviceCdRom
, &TargetDeviceName
, TRUE
))
566 /* If the device is a CD-ROM, start with letter D */
571 /* Finally, if it's a disk, use C */
575 /* We cannot set NO drive letter */
576 ASSERT(DeviceInformation
->SuggestedDriveLetter
!= (UCHAR
)-1);
578 /* If we don't have suggested letter but it's a FT volume, fail */
579 if (!DeviceInformation
->SuggestedDriveLetter
&& IsFtVolume(&(DeviceInformation
->DeviceName
)))
581 DriveLetterInfo
->DriveLetterWasAssigned
= FALSE
;
582 DriveLetterInfo
->CurrentDriveLetter
= 0;
588 RtlCopyMemory(NameBuffer
, DosDevices
.Buffer
, DosDevices
.Length
);
589 NameBuffer
[COLON_POSITION
] = L
':';
590 SymbolicName
.Buffer
= NameBuffer
;
591 SymbolicName
.Length
=
592 SymbolicName
.MaximumLength
= DRIVE_LETTER_LENGTH
;
594 /* It's all prepared, create mount point */
595 if (DeviceInformation
->SuggestedDriveLetter
)
597 DriveLetterInfo
->CurrentDriveLetter
= DeviceInformation
->SuggestedDriveLetter
;
598 NameBuffer
[LETTER_POSITION
] = DeviceInformation
->SuggestedDriveLetter
;
600 Status
= MountMgrCreatePointWorker(DeviceExtension
, &SymbolicName
, &TargetDeviceName
);
601 if (NT_SUCCESS(Status
))
607 /* It failed with this letter... Try another one! */
608 for (DriveLetterInfo
->CurrentDriveLetter
= DriveLetter
;
609 DriveLetterInfo
->CurrentDriveLetter
<= L
'Z';
610 DriveLetterInfo
->CurrentDriveLetter
++)
612 NameBuffer
[LETTER_POSITION
] = DeviceInformation
->SuggestedDriveLetter
;
614 Status
= MountMgrCreatePointWorker(DeviceExtension
, &SymbolicName
, &TargetDeviceName
);
615 if (NT_SUCCESS(Status
))
621 /* We failed setting a letter */
622 if (DriveLetterInfo
->CurrentDriveLetter
> L
'Z')
624 DriveLetterInfo
->DriveLetterWasAssigned
= FALSE
;
625 DriveLetterInfo
->CurrentDriveLetter
= 0;
627 /* Try at least to add a no drive letter entry */
628 Status
= QueryDeviceInformation(&TargetDeviceName
, NULL
, &UniqueId
, NULL
, NULL
, NULL
, NULL
, NULL
);
629 if (NT_SUCCESS(Status
))
631 CreateNoDriveLetterEntry(UniqueId
);
637 FreePool(TargetDeviceName
.Buffer
);
639 return STATUS_SUCCESS
;
647 MountMgrNextDriveLetter(IN PDEVICE_EXTENSION DeviceExtension
,
651 PIO_STACK_LOCATION Stack
;
652 UNICODE_STRING DeviceName
;
653 PMOUNTMGR_DRIVE_LETTER_TARGET DriveLetterTarget
;
654 MOUNTMGR_DRIVE_LETTER_INFORMATION DriveLetterInformation
;
656 Stack
= IoGetNextIrpStackLocation(Irp
);
659 if (Stack
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(MOUNTMGR_DRIVE_LETTER_TARGET
) ||
660 Stack
->Parameters
.DeviceIoControl
.OutputBufferLength
< sizeof(MOUNTMGR_DRIVE_LETTER_INFORMATION
))
662 return STATUS_INVALID_PARAMETER
;
665 DriveLetterTarget
= (PMOUNTMGR_DRIVE_LETTER_TARGET
)Irp
->AssociatedIrp
.SystemBuffer
;
666 if (DriveLetterTarget
->DeviceNameLength
+ sizeof(USHORT
) > Stack
->Parameters
.DeviceIoControl
.InputBufferLength
)
668 return STATUS_INVALID_PARAMETER
;
671 /* Call the worker */
672 DeviceName
.Buffer
= DriveLetterTarget
->DeviceName
;
674 DeviceName
.MaximumLength
= DriveLetterTarget
->DeviceNameLength
;
676 Status
= MountMgrNextDriveLetterWorker(DeviceExtension
, &DeviceName
,
677 &DriveLetterInformation
);
678 if (NT_SUCCESS(Status
))
680 *(PMOUNTMGR_DRIVE_LETTER_INFORMATION
)Irp
->AssociatedIrp
.SystemBuffer
=
681 DriveLetterInformation
;
682 Irp
->IoStatus
.Information
= sizeof(MOUNTMGR_DRIVE_LETTER_INFORMATION
);
693 MountMgrQuerySystemVolumeNameQueryRoutine(IN PWSTR ValueName
,
696 IN ULONG ValueLength
,
698 IN PVOID EntryContext
)
700 UNICODE_STRING ValueString
;
701 PUNICODE_STRING SystemVolumeName
;
703 UNREFERENCED_PARAMETER(ValueName
);
704 UNREFERENCED_PARAMETER(ValueLength
);
705 UNREFERENCED_PARAMETER(EntryContext
);
707 if (ValueType
!= REG_SZ
)
709 return STATUS_SUCCESS
;
712 RtlInitUnicodeString(&ValueString
, ValueData
);
713 SystemVolumeName
= Context
;
715 /* Return a string containing system volume name */
716 SystemVolumeName
->Length
= ValueString
.Length
;
717 SystemVolumeName
->MaximumLength
= ValueString
.Length
+ sizeof(WCHAR
);
718 SystemVolumeName
->Buffer
= AllocatePool(SystemVolumeName
->MaximumLength
);
719 if (SystemVolumeName
->Buffer
)
721 RtlCopyMemory(SystemVolumeName
->Buffer
, ValueData
, ValueString
.Length
);
722 SystemVolumeName
->Buffer
[ValueString
.Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
725 return STATUS_SUCCESS
;
733 MountMgrQuerySystemVolumeName(OUT PUNICODE_STRING SystemVolumeName
)
735 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
737 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
738 QueryTable
[0].QueryRoutine
= MountMgrQuerySystemVolumeNameQueryRoutine
;
739 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
;
740 QueryTable
[0].Name
= L
"SystemPartition";
742 SystemVolumeName
->Buffer
= NULL
;
744 RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
745 L
"\\Registry\\Machine\\System\\Setup",
750 if (SystemVolumeName
->Buffer
)
752 return STATUS_SUCCESS
;
755 return STATUS_UNSUCCESSFUL
;
762 MountMgrAssignDriveLetters(IN PDEVICE_EXTENSION DeviceExtension
)
765 PLIST_ENTRY NextEntry
;
766 UNICODE_STRING SystemVolumeName
;
767 PDEVICE_INFORMATION DeviceInformation
;
768 MOUNTMGR_DRIVE_LETTER_INFORMATION DriveLetterInformation
;
770 /* First, get system volume name */
771 Status
= MountMgrQuerySystemVolumeName(&SystemVolumeName
);
773 /* If there are no device, it's all done */
774 if (IsListEmpty(&(DeviceExtension
->DeviceListHead
)))
776 if (NT_SUCCESS(Status
))
778 FreePool(SystemVolumeName
.Buffer
);
784 /* Now, for all the devices... */
785 for (NextEntry
= DeviceExtension
->DeviceListHead
.Flink
;
786 NextEntry
!= &(DeviceExtension
->DeviceListHead
);
787 NextEntry
= NextEntry
->Flink
)
789 DeviceInformation
= CONTAINING_RECORD(NextEntry
, DEVICE_INFORMATION
, DeviceListEntry
);
791 /* If the device doesn't have a letter assigned, do it! */
792 if (!DeviceInformation
->LetterAssigned
)
794 MountMgrNextDriveLetterWorker(DeviceExtension
,
795 &(DeviceInformation
->DeviceName
),
796 &DriveLetterInformation
);
799 /* If it was the system volume */
800 if (NT_SUCCESS(Status
) && RtlEqualUnicodeString(&SystemVolumeName
, &(DeviceInformation
->DeviceName
), TRUE
))
802 /* Keep track of it */
803 DeviceExtension
->DriveLetterData
= AllocatePool(DeviceInformation
->UniqueId
->UniqueIdLength
+
804 sizeof(MOUNTDEV_UNIQUE_ID
));
805 if (DeviceExtension
->DriveLetterData
)
807 RtlCopyMemory(DeviceExtension
->DriveLetterData
,
808 DeviceInformation
->UniqueId
,
809 DeviceInformation
->UniqueId
->UniqueIdLength
+ sizeof(MOUNTDEV_UNIQUE_ID
));
812 /* If it was not automount, ensure it gets mounted */
813 if (!DeviceExtension
->NoAutoMount
)
815 DeviceExtension
->NoAutoMount
= TRUE
;
817 MountMgrNextDriveLetterWorker(DeviceExtension
,
818 &(DeviceInformation
->DeviceName
),
819 &DriveLetterInformation
);
821 DeviceExtension
->NoAutoMount
= FALSE
;
826 if (NT_SUCCESS(Status
))
828 FreePool(SystemVolumeName
.Buffer
);
833 MountMgrQueryDosVolumePath(IN PDEVICE_EXTENSION DeviceExtension
,
836 UNREFERENCED_PARAMETER(DeviceExtension
);
837 UNREFERENCED_PARAMETER(Irp
);
838 return STATUS_NOT_IMPLEMENTED
;
842 MountMgrQueryDosVolumePaths(IN PDEVICE_EXTENSION DeviceExtension
,
845 UNREFERENCED_PARAMETER(DeviceExtension
);
846 UNREFERENCED_PARAMETER(Irp
);
847 return STATUS_NOT_IMPLEMENTED
;
854 MountMgrKeepLinksWhenOffline(IN PDEVICE_EXTENSION DeviceExtension
,
858 PIO_STACK_LOCATION Stack
;
859 UNICODE_STRING SymbolicName
;
860 PMOUNTMGR_TARGET_NAME Target
;
861 PDEVICE_INFORMATION DeviceInformation
;
863 Stack
= IoGetNextIrpStackLocation(Irp
);
866 if (Stack
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(MOUNTMGR_TARGET_NAME
))
868 return STATUS_INVALID_PARAMETER
;
871 Target
= (PMOUNTMGR_TARGET_NAME
)Irp
->AssociatedIrp
.SystemBuffer
;
872 if (Target
->DeviceNameLength
+ sizeof(USHORT
) > Stack
->Parameters
.DeviceIoControl
.InputBufferLength
)
874 return STATUS_INVALID_PARAMETER
;
877 SymbolicName
.Length
=
878 SymbolicName
.MaximumLength
= Target
->DeviceNameLength
;
879 SymbolicName
.Buffer
= Target
->DeviceName
;
881 /* Find the associated device */
882 Status
= FindDeviceInfo(DeviceExtension
, &SymbolicName
, FALSE
, &DeviceInformation
);
883 if (!NT_SUCCESS(Status
))
888 /* Mark we want to keep links */
889 DeviceInformation
->KeepLinks
= TRUE
;
891 return STATUS_SUCCESS
;
898 MountMgrVolumeArrivalNotification(IN PDEVICE_EXTENSION DeviceExtension
,
903 PIO_STACK_LOCATION Stack
;
904 UNICODE_STRING SymbolicName
;
905 PMOUNTMGR_TARGET_NAME Target
;
907 Stack
= IoGetNextIrpStackLocation(Irp
);
910 if (Stack
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(MOUNTMGR_TARGET_NAME
))
912 return STATUS_INVALID_PARAMETER
;
915 Target
= (PMOUNTMGR_TARGET_NAME
)Irp
->AssociatedIrp
.SystemBuffer
;
916 if (Target
->DeviceNameLength
+ sizeof(USHORT
) > Stack
->Parameters
.DeviceIoControl
.InputBufferLength
)
918 return STATUS_INVALID_PARAMETER
;
921 SymbolicName
.Length
=
922 SymbolicName
.MaximumLength
= Target
->DeviceNameLength
;
923 SymbolicName
.Buffer
= Target
->DeviceName
;
925 /* Disable hard errors */
926 OldState
= PsGetThreadHardErrorsAreDisabled(PsGetCurrentThread());
927 PsSetThreadHardErrorsAreDisabled(PsGetCurrentThread(), TRUE
);
929 /* Call real worker */
930 Status
= MountMgrMountedDeviceArrival(DeviceExtension
, &SymbolicName
, TRUE
);
932 PsSetThreadHardErrorsAreDisabled(PsGetCurrentThread(), OldState
);
941 MountMgrQueryPoints(IN PDEVICE_EXTENSION DeviceExtension
,
945 PIO_STACK_LOCATION Stack
;
946 PMOUNTDEV_UNIQUE_ID UniqueId
;
947 PMOUNTMGR_MOUNT_POINT MountPoint
;
948 UNICODE_STRING SymbolicName
, DeviceName
;
950 Stack
= IoGetNextIrpStackLocation(Irp
);
952 /* Validate input... */
953 if (Stack
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(MOUNTMGR_MOUNT_POINT
))
955 return STATUS_INVALID_PARAMETER
;
958 MountPoint
= (PMOUNTMGR_MOUNT_POINT
)Irp
->AssociatedIrp
.SystemBuffer
;
959 if (!MountPoint
->SymbolicLinkNameLength
)
961 MountPoint
->SymbolicLinkNameOffset
= 0;
964 if (!MountPoint
->UniqueIdLength
)
966 MountPoint
->UniqueIdOffset
= 0;
969 if (!MountPoint
->DeviceNameLength
)
971 MountPoint
->DeviceNameOffset
= 0;
974 /* Addresses can't be odd */
975 if ((MountPoint
->SymbolicLinkNameOffset
& 1) ||
976 (MountPoint
->SymbolicLinkNameLength
& 1))
978 return STATUS_INVALID_PARAMETER
;
981 if ((MountPoint
->UniqueIdOffset
& 1) ||
982 (MountPoint
->UniqueIdLength
& 1))
984 return STATUS_INVALID_PARAMETER
;
987 if ((MountPoint
->DeviceNameOffset
& 1) ||
988 (MountPoint
->DeviceNameLength
& 1))
990 return STATUS_INVALID_PARAMETER
;
993 /* We can't go beyond */
994 if (((ULONG
)MountPoint
->SymbolicLinkNameLength
+ MountPoint
->UniqueIdLength
+
995 MountPoint
->DeviceNameLength
) < Stack
->Parameters
.DeviceIoControl
.InputBufferLength
)
997 return STATUS_INVALID_PARAMETER
;
1000 if (Stack
->Parameters
.DeviceIoControl
.OutputBufferLength
< sizeof(MOUNTMGR_MOUNT_POINTS
))
1002 return STATUS_INVALID_PARAMETER
;
1005 /* If caller provided a Symlink, use it */
1006 if (MountPoint
->SymbolicLinkNameLength
!= 0)
1008 if (MountPoint
->SymbolicLinkNameLength
> MAXSHORT
)
1010 return STATUS_INVALID_PARAMETER
;
1013 SymbolicName
.Length
= MountPoint
->SymbolicLinkNameLength
;
1014 SymbolicName
.MaximumLength
= MountPoint
->SymbolicLinkNameLength
+ sizeof(WCHAR
);
1015 SymbolicName
.Buffer
= AllocatePool(SymbolicName
.MaximumLength
);
1016 if (!SymbolicName
.Buffer
)
1018 return STATUS_INSUFFICIENT_RESOURCES
;
1021 RtlCopyMemory(SymbolicName
.Buffer
,
1022 (PWSTR
)((ULONG_PTR
)MountPoint
+ MountPoint
->SymbolicLinkNameOffset
),
1023 SymbolicName
.Length
);
1024 SymbolicName
.Buffer
[SymbolicName
.Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1026 /* Query links using it */
1027 Status
= QueryPointsFromSymbolicLinkName(DeviceExtension
, &SymbolicName
, Irp
);
1028 FreePool(SymbolicName
.Buffer
);
1030 /* If user provided an unique ID */
1031 else if (MountPoint
->UniqueIdLength
!= 0)
1033 UniqueId
= AllocatePool(MountPoint
->UniqueIdLength
+ sizeof(MOUNTDEV_UNIQUE_ID
));
1036 return STATUS_INSUFFICIENT_RESOURCES
;
1039 UniqueId
->UniqueIdLength
= MountPoint
->UniqueIdLength
;
1040 RtlCopyMemory(UniqueId
->UniqueId
,
1041 (PVOID
)((ULONG_PTR
)MountPoint
+ MountPoint
->UniqueIdOffset
),
1042 MountPoint
->UniqueIdLength
);
1044 /* Query links using it */
1045 Status
= QueryPointsFromMemory(DeviceExtension
, Irp
, UniqueId
, NULL
);
1048 /* If caller provided a device name */
1049 else if (MountPoint
->DeviceNameLength
!= 0)
1051 if (MountPoint
->DeviceNameLength
> MAXSHORT
)
1053 return STATUS_INVALID_PARAMETER
;
1056 DeviceName
.Length
= MountPoint
->DeviceNameLength
;
1057 DeviceName
.MaximumLength
= MountPoint
->DeviceNameLength
+ sizeof(WCHAR
);
1058 DeviceName
.Buffer
= AllocatePool(DeviceName
.MaximumLength
);
1059 if (!DeviceName
.Buffer
)
1061 return STATUS_INSUFFICIENT_RESOURCES
;
1064 RtlCopyMemory(DeviceName
.Buffer
,
1065 (PWSTR
)((ULONG_PTR
)MountPoint
+ MountPoint
->DeviceNameOffset
),
1067 DeviceName
.Buffer
[DeviceName
.Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1069 /* Query links using it */
1070 Status
= QueryPointsFromMemory(DeviceExtension
, Irp
, NULL
, &DeviceName
);
1071 FreePool(DeviceName
.Buffer
);
1075 /* Otherwise, query all links */
1076 Status
= QueryPointsFromMemory(DeviceExtension
, Irp
, NULL
, NULL
);
1086 MountMgrDeletePoints(IN PDEVICE_EXTENSION DeviceExtension
,
1091 BOOLEAN CreateNoDrive
;
1092 PIO_STACK_LOCATION Stack
;
1093 PMOUNTDEV_UNIQUE_ID UniqueId
;
1094 PMOUNTMGR_MOUNT_POINT MountPoint
;
1095 PMOUNTMGR_MOUNT_POINTS MountPoints
;
1096 UNICODE_STRING SymbolicName
, DeviceName
;
1098 Stack
= IoGetNextIrpStackLocation(Irp
);
1100 /* Validate input */
1101 if (Stack
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(MOUNTMGR_MOUNT_POINT
))
1103 return STATUS_INVALID_PARAMETER
;
1107 MountPoint
= (PMOUNTMGR_MOUNT_POINT
)Irp
->AssociatedIrp
.SystemBuffer
;
1108 CreateNoDrive
= (MountPoint
->SymbolicLinkNameOffset
&& MountPoint
->SymbolicLinkNameLength
);
1110 Status
= MountMgrQueryPoints(DeviceExtension
, Irp
);
1111 if (!NT_SUCCESS(Status
))
1116 /* For all the points matching the request */
1117 MountPoints
= (PMOUNTMGR_MOUNT_POINTS
)Irp
->AssociatedIrp
.SystemBuffer
;
1118 for (Link
= 0; Link
< MountPoints
->NumberOfMountPoints
; Link
++)
1120 SymbolicName
.Length
= MountPoints
->MountPoints
[Link
].SymbolicLinkNameLength
;
1121 SymbolicName
.MaximumLength
= SymbolicName
.Length
+ sizeof(WCHAR
);
1122 SymbolicName
.Buffer
= AllocatePool(SymbolicName
.MaximumLength
);
1123 if (!SymbolicName
.Buffer
)
1125 return STATUS_INSUFFICIENT_RESOURCES
;
1128 RtlCopyMemory(SymbolicName
.Buffer
,
1129 (PWSTR
)((ULONG_PTR
)MountPoints
+ MountPoints
->MountPoints
[Link
].SymbolicLinkNameOffset
),
1130 SymbolicName
.Length
);
1131 SymbolicName
.Buffer
[SymbolicName
.Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1133 /* Create a no drive entry for the drive letters */
1134 if (CreateNoDrive
&& IsDriveLetter(&SymbolicName
))
1136 UniqueId
= AllocatePool(MountPoints
->MountPoints
[Link
].UniqueIdLength
+ sizeof(MOUNTDEV_UNIQUE_ID
));
1139 UniqueId
->UniqueIdLength
= MountPoints
->MountPoints
[Link
].UniqueIdLength
;
1140 RtlCopyMemory(UniqueId
->UniqueId
,
1141 (PMOUNTDEV_UNIQUE_ID
)((ULONG_PTR
)MountPoints
+ MountPoints
->MountPoints
[Link
].UniqueIdOffset
),
1142 MountPoints
->MountPoints
[Link
].UniqueIdLength
);
1144 CreateNoDriveLetterEntry(UniqueId
);
1149 /* If there are no link any more, and no need to create a no drive entry */
1150 if (Link
== 0 && !CreateNoDrive
)
1152 /* Then, delete everything */
1153 UniqueId
= AllocatePool(MountPoints
->MountPoints
[Link
].UniqueIdLength
);
1156 RtlCopyMemory(UniqueId
,
1157 (PMOUNTDEV_UNIQUE_ID
)((ULONG_PTR
)MountPoints
+ MountPoints
->MountPoints
[Link
].UniqueIdOffset
),
1158 MountPoints
->MountPoints
[Link
].UniqueIdLength
);
1160 DeleteNoDriveLetterEntry(UniqueId
);
1165 /* Delete all the information about the mount point */
1166 GlobalDeleteSymbolicLink(&SymbolicName
);
1167 DeleteSymbolicLinkNameFromMemory(DeviceExtension
, &SymbolicName
, FALSE
);
1168 RtlDeleteRegistryValue(RTL_REGISTRY_ABSOLUTE
, DatabasePath
, SymbolicName
.Buffer
);
1169 FreePool(SymbolicName
.Buffer
);
1171 /* Notify the change */
1172 DeviceName
.Length
= DeviceName
.MaximumLength
=
1173 MountPoints
->MountPoints
[Link
].DeviceNameLength
;
1174 DeviceName
.Buffer
= (PWSTR
)((ULONG_PTR
)MountPoints
+ MountPoints
->MountPoints
[Link
].DeviceNameOffset
);
1175 MountMgrNotifyNameChange(DeviceExtension
, &DeviceName
, TRUE
);
1178 MountMgrNotify(DeviceExtension
);
1187 MountMgrDeletePointsDbOnly(IN PDEVICE_EXTENSION DeviceExtension
,
1192 UNICODE_STRING SymbolicName
;
1193 PMOUNTDEV_UNIQUE_ID UniqueId
;
1194 PMOUNTMGR_MOUNT_POINTS MountPoints
;
1197 Status
= MountMgrQueryPoints(DeviceExtension
, Irp
);
1198 if (!NT_SUCCESS(Status
))
1203 MountPoints
= (PMOUNTMGR_MOUNT_POINTS
)Irp
->AssociatedIrp
.SystemBuffer
;
1204 if (MountPoints
->NumberOfMountPoints
== 0)
1209 /* For all the mount points */
1210 for (Link
= 0; Link
< MountPoints
->NumberOfMountPoints
; Link
++)
1212 SymbolicName
.Length
= MountPoints
->MountPoints
[Link
].SymbolicLinkNameLength
;
1213 SymbolicName
.MaximumLength
= SymbolicName
.Length
+ sizeof(WCHAR
);
1214 SymbolicName
.Buffer
= AllocatePool(SymbolicName
.MaximumLength
);
1215 if (!SymbolicName
.Buffer
)
1217 return STATUS_INSUFFICIENT_RESOURCES
;
1220 RtlCopyMemory(SymbolicName
.Buffer
,
1221 (PWSTR
)((ULONG_PTR
)MountPoints
+ MountPoints
->MountPoints
[Link
].SymbolicLinkNameOffset
),
1222 SymbolicName
.Length
);
1223 SymbolicName
.Buffer
[SymbolicName
.Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1225 /* If the only mount point is a drive letter, then create a no letter drive entry */
1226 if (MountPoints
->NumberOfMountPoints
== 1 && IsDriveLetter(&SymbolicName
))
1228 UniqueId
= AllocatePool(MountPoints
->MountPoints
[Link
].UniqueIdLength
+ sizeof(MOUNTDEV_UNIQUE_ID
));
1231 UniqueId
->UniqueIdLength
= MountPoints
->MountPoints
[Link
].UniqueIdLength
;
1232 RtlCopyMemory(UniqueId
->UniqueId
,
1233 (PMOUNTDEV_UNIQUE_ID
)((ULONG_PTR
)MountPoints
+ MountPoints
->MountPoints
[Link
].UniqueIdOffset
),
1234 MountPoints
->MountPoints
[Link
].UniqueIdLength
);
1236 CreateNoDriveLetterEntry(UniqueId
);
1241 /* Simply delete mount point from DB */
1242 DeleteSymbolicLinkNameFromMemory(DeviceExtension
, &SymbolicName
, TRUE
);
1243 RtlDeleteRegistryValue(RTL_REGISTRY_ABSOLUTE
, DatabasePath
, SymbolicName
.Buffer
);
1244 FreePool(SymbolicName
.Buffer
);
1254 MountMgrVolumeMountPointChanged(IN PDEVICE_EXTENSION DeviceExtension
,
1256 IN NTSTATUS LockStatus
,
1257 OUT PUNICODE_STRING SourceDeviceName
,
1258 OUT PUNICODE_STRING SourceSymbolicName
,
1259 OUT PUNICODE_STRING TargetVolumeName
)
1263 PFILE_OBJECT FileObject
;
1264 PIO_STACK_LOCATION Stack
;
1265 ULONG Length
, SavedLength
;
1266 BOOLEAN FOReferenced
= FALSE
;
1267 IO_STATUS_BLOCK IoStatusBlock
;
1268 OBJECT_ATTRIBUTES ObjectAttributes
;
1269 PDEVICE_INFORMATION DeviceInformation
;
1270 OBJECT_NAME_INFORMATION ObjectNameInfo
;
1271 FILE_FS_DEVICE_INFORMATION FsDeviceInfo
;
1272 PFILE_NAME_INFORMATION FileNameInfo
= NULL
;
1273 PMOUNTMGR_VOLUME_MOUNT_POINT VolumeMountPoint
;
1274 POBJECT_NAME_INFORMATION ObjectNameInfoPtr
= NULL
;
1275 UNICODE_STRING SourceVolumeName
, TargetDeviceName
;
1277 Stack
= IoGetNextIrpStackLocation(Irp
);
1279 /* Validate input */
1280 if (Stack
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(MOUNTMGR_VOLUME_MOUNT_POINT
))
1282 return STATUS_INVALID_PARAMETER
;
1285 VolumeMountPoint
= (PMOUNTMGR_VOLUME_MOUNT_POINT
)Irp
->AssociatedIrp
.SystemBuffer
;
1287 if (((ULONG
)VolumeMountPoint
->SourceVolumeNameLength
+ VolumeMountPoint
->TargetVolumeNameLength
) <
1288 Stack
->Parameters
.DeviceIoControl
.InputBufferLength
)
1290 return STATUS_INVALID_PARAMETER
;
1293 /* Get source volume name */
1294 SourceVolumeName
.Length
=
1295 SourceVolumeName
.MaximumLength
= VolumeMountPoint
->SourceVolumeNameLength
;
1296 SourceVolumeName
.Buffer
= (PWSTR
)((ULONG_PTR
)VolumeMountPoint
+ VolumeMountPoint
->SourceVolumeNameOffset
);
1298 InitializeObjectAttributes(&ObjectAttributes
,
1300 OBJ_KERNEL_HANDLE
| OBJ_CASE_INSENSITIVE
,
1305 Status
= ZwOpenFile(&Handle
,
1306 SYNCHRONIZE
| FILE_READ_ATTRIBUTES
,
1309 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1310 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_OPEN_REPARSE_POINT
);
1311 if (!NT_SUCCESS(Status
))
1316 TargetDeviceName
.Buffer
= NULL
;
1318 /* Query its attributes */
1319 Status
= ZwQueryVolumeInformationFile(Handle
,
1322 sizeof(FsDeviceInfo
),
1323 FileFsDeviceInformation
);
1324 if (!NT_SUCCESS(Status
))
1329 if (FsDeviceInfo
.DeviceType
!= FILE_DEVICE_DISK
&& FsDeviceInfo
.DeviceType
!= FILE_DEVICE_VIRTUAL_DISK
)
1334 if (FsDeviceInfo
.Characteristics
!= (FILE_REMOTE_DEVICE
| FILE_REMOVABLE_MEDIA
))
1340 Status
= ObReferenceObjectByHandle(Handle
, 0, IoFileObjectType
, KernelMode
, (PVOID
*)&FileObject
, NULL
);
1341 if (!NT_SUCCESS(Status
))
1345 FOReferenced
= TRUE
;
1348 FileNameInfo
= AllocatePool(sizeof(FILE_NAME_INFORMATION
));
1351 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1355 Status
= ZwQueryInformationFile(Handle
, &IoStatusBlock
, FileNameInfo
,
1356 sizeof(FILE_NAME_INFORMATION
),
1357 FileNameInformation
);
1358 if (Status
== STATUS_BUFFER_OVERFLOW
)
1360 /* Now we have real length, use it */
1361 Length
= FileNameInfo
->FileNameLength
;
1362 FreePool(FileNameInfo
);
1364 FileNameInfo
= AllocatePool(sizeof(FILE_NAME_INFORMATION
) + Length
);
1367 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1371 /* Really query file name */
1372 Status
= ZwQueryInformationFile(Handle
, &IoStatusBlock
, FileNameInfo
,
1373 sizeof(FILE_NAME_INFORMATION
) + Length
,
1374 FileNameInformation
);
1377 if (!NT_SUCCESS(Status
))
1382 /* Get symbolic name */
1383 ObjectNameInfoPtr
= &ObjectNameInfo
;
1384 SavedLength
= sizeof(OBJECT_NAME_INFORMATION
);
1385 Status
= ObQueryNameString(FileObject
->DeviceObject
, ObjectNameInfoPtr
, sizeof(OBJECT_NAME_INFORMATION
), &Length
);
1386 if (Status
== STATUS_INFO_LENGTH_MISMATCH
)
1388 /* Once again, with proper size, it works better */
1389 ObjectNameInfoPtr
= AllocatePool(Length
);
1390 if (!ObjectNameInfoPtr
)
1392 Status
= STATUS_INSUFFICIENT_RESOURCES
;
1396 SavedLength
= Length
;
1397 Status
= ObQueryNameString(FileObject
->DeviceObject
, ObjectNameInfoPtr
, SavedLength
, &Length
);
1400 if (!NT_SUCCESS(Status
))
1405 /* Now, query the device name */
1406 Status
= QueryDeviceInformation(&ObjectNameInfoPtr
->Name
, SourceDeviceName
,
1407 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1408 if (!NT_SUCCESS(Status
))
1413 /* For target volume name, use input */
1414 TargetVolumeName
->Length
=
1415 TargetVolumeName
->MaximumLength
= VolumeMountPoint
->TargetVolumeNameLength
;
1416 TargetVolumeName
->Buffer
= (PWSTR
)((ULONG_PTR
)VolumeMountPoint
+ VolumeMountPoint
->TargetVolumeNameOffset
);
1418 /* Query its device name */
1419 Status
= QueryDeviceInformation(TargetVolumeName
, &TargetDeviceName
,
1420 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1421 if (!NT_SUCCESS(Status
))
1426 /* Return symbolic name */
1427 SourceSymbolicName
->Length
=
1428 SourceSymbolicName
->MaximumLength
= (USHORT
)FileNameInfo
->FileNameLength
;
1429 SourceSymbolicName
->Buffer
= (PWSTR
)FileNameInfo
;
1430 /* memmove allows memory overlap */
1431 RtlMoveMemory(SourceSymbolicName
->Buffer
, FileNameInfo
->FileName
, SourceSymbolicName
->Length
);
1432 FileNameInfo
= NULL
;
1434 /* Notify the change */
1435 MountMgrNotify(DeviceExtension
);
1436 MountMgrNotifyNameChange(DeviceExtension
, &TargetDeviceName
, TRUE
);
1438 /* If we are locked, sync databases if possible */
1439 if (NT_SUCCESS(LockStatus
))
1441 Status
= FindDeviceInfo(DeviceExtension
, SourceDeviceName
, FALSE
, &DeviceInformation
);
1442 if (NT_SUCCESS(Status
))
1444 ReconcileThisDatabaseWithMaster(DeviceExtension
, DeviceInformation
);
1448 Status
= STATUS_PENDING
;
1453 if (TargetDeviceName
.Buffer
)
1455 FreePool(TargetDeviceName
.Buffer
);
1458 if (ObjectNameInfoPtr
&& ObjectNameInfoPtr
!= &ObjectNameInfo
)
1460 FreePool(ObjectNameInfoPtr
);
1465 FreePool(FileNameInfo
);
1470 ObDereferenceObject(FileObject
);
1477 MountMgrVolumeMountPointCreated(IN PDEVICE_EXTENSION DeviceExtension
,
1479 IN NTSTATUS LockStatus
)
1481 UNREFERENCED_PARAMETER(DeviceExtension
);
1482 UNREFERENCED_PARAMETER(Irp
);
1483 UNREFERENCED_PARAMETER(LockStatus
);
1484 return STATUS_NOT_IMPLEMENTED
;
1488 MountMgrVolumeMountPointDeleted(IN PDEVICE_EXTENSION DeviceExtension
,
1490 IN NTSTATUS LockStatus
)
1492 UNREFERENCED_PARAMETER(DeviceExtension
);
1493 UNREFERENCED_PARAMETER(Irp
);
1494 UNREFERENCED_PARAMETER(LockStatus
);
1495 return STATUS_NOT_IMPLEMENTED
;
1503 MountMgrDeviceControl(IN PDEVICE_OBJECT DeviceObject
,
1506 PIO_STACK_LOCATION Stack
;
1507 NTSTATUS Status
, LockStatus
;
1508 PDEVICE_EXTENSION DeviceExtension
;
1510 Stack
= IoGetNextIrpStackLocation(Irp
);
1511 DeviceExtension
= DeviceObject
->DeviceExtension
;
1513 KeWaitForSingleObject(&(DeviceExtension
->DeviceLock
), Executive
, KernelMode
, FALSE
, NULL
);
1515 switch (Stack
->Parameters
.DeviceIoControl
.IoControlCode
)
1517 case IOCTL_MOUNTMGR_CREATE_POINT
:
1518 Status
= MountMgrCreatePoint(DeviceExtension
, Irp
);
1521 case IOCTL_MOUNTMGR_DELETE_POINTS
:
1522 Status
= MountMgrDeletePoints(DeviceExtension
, Irp
);
1525 case IOCTL_MOUNTMGR_QUERY_POINTS
:
1526 Status
= MountMgrQueryPoints(DeviceExtension
, Irp
);
1529 case IOCTL_MOUNTMGR_DELETE_POINTS_DBONLY
:
1530 Status
= MountMgrDeletePointsDbOnly(DeviceExtension
, Irp
);
1533 case IOCTL_MOUNTMGR_NEXT_DRIVE_LETTER
:
1534 Status
= MountMgrNextDriveLetter(DeviceExtension
, Irp
);
1537 case IOCTL_MOUNTMGR_AUTO_DL_ASSIGNMENTS
:
1538 DeviceExtension
->AutomaticDriveLetter
= TRUE
;
1539 Status
= STATUS_SUCCESS
;
1541 MountMgrAssignDriveLetters(DeviceExtension
);
1542 ReconcileAllDatabasesWithMaster(DeviceExtension
);
1543 WaitForOnlinesToComplete(DeviceExtension
);
1546 case IOCTL_MOUNTMGR_VOLUME_MOUNT_POINT_CREATED
:
1547 KeReleaseSemaphore(&(DeviceExtension
->DeviceLock
), IO_NO_INCREMENT
, 1, FALSE
);
1549 LockStatus
= WaitForRemoteDatabaseSemaphore(DeviceExtension
);
1550 KeWaitForSingleObject(&(DeviceExtension
->DeviceLock
), Executive
, KernelMode
, FALSE
, NULL
);
1551 Status
= MountMgrVolumeMountPointCreated(DeviceExtension
, Irp
, LockStatus
);
1552 if (NT_SUCCESS(LockStatus
))
1554 ReleaseRemoteDatabaseSemaphore(DeviceExtension
);
1559 case IOCTL_MOUNTMGR_VOLUME_MOUNT_POINT_DELETED
:
1560 KeReleaseSemaphore(&(DeviceExtension
->DeviceLock
), IO_NO_INCREMENT
, 1, FALSE
);
1562 LockStatus
= WaitForRemoteDatabaseSemaphore(DeviceExtension
);
1563 KeWaitForSingleObject(&(DeviceExtension
->DeviceLock
), Executive
, KernelMode
, FALSE
, NULL
);
1564 Status
= MountMgrVolumeMountPointDeleted(DeviceExtension
, Irp
, LockStatus
);
1565 if (NT_SUCCESS(LockStatus
))
1567 ReleaseRemoteDatabaseSemaphore(DeviceExtension
);
1572 case IOCTL_MOUNTMGR_CHANGE_NOTIFY
:
1573 Status
= MountMgrChangeNotify(DeviceExtension
, Irp
);
1576 case IOCTL_MOUNTMGR_KEEP_LINKS_WHEN_OFFLINE
:
1577 Status
= MountMgrKeepLinksWhenOffline(DeviceExtension
, Irp
);
1580 case IOCTL_MOUNTMGR_CHECK_UNPROCESSED_VOLUMES
:
1581 Status
= MountMgrCheckUnprocessedVolumes(DeviceExtension
, Irp
);
1584 case IOCTL_MOUNTMGR_VOLUME_ARRIVAL_NOTIFICATION
:
1585 KeReleaseSemaphore(&(DeviceExtension
->DeviceLock
), IO_NO_INCREMENT
, 1, FALSE
);
1586 Status
= MountMgrVolumeArrivalNotification(DeviceExtension
, Irp
);
1589 case IOCTL_MOUNTMGR_QUERY_DOS_VOLUME_PATH
:
1590 Status
= MountMgrQueryDosVolumePath(DeviceExtension
, Irp
);
1593 case IOCTL_MOUNTMGR_QUERY_DOS_VOLUME_PATHS
:
1594 Status
= MountMgrQueryDosVolumePaths(DeviceExtension
, Irp
);
1597 case IOCTL_MOUNTMGR_SCRUB_REGISTRY
:
1598 Status
= MountMgrScrubRegistry(DeviceExtension
);
1601 case IOCTL_MOUNTMGR_QUERY_AUTO_MOUNT
:
1602 Status
= MountMgrQueryAutoMount(DeviceExtension
, Irp
);
1605 case IOCTL_MOUNTMGR_SET_AUTO_MOUNT
:
1606 Status
= MountMgrSetAutoMount(DeviceExtension
, Irp
);
1610 Status
= STATUS_INVALID_DEVICE_REQUEST
;
1613 KeReleaseSemaphore(&(DeviceExtension
->DeviceLock
), IO_NO_INCREMENT
, 1, FALSE
);
1615 if (Status
!= STATUS_PENDING
)
1623 Irp
->IoStatus
.Status
= Status
;
1624 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);