[MUP]
[reactos.git] / reactos / drivers / filesystems / mup / mup.c
index dadafa3..84f318a 100644 (file)
 #define NDEBUG
 #include <debug.h>
 
+NTSTATUS
+NTAPI
+DriverEntry(
+    PDRIVER_OBJECT DriverObject,
+    PUNICODE_STRING RegistryPath
+);
+
+VOID
+MupInitializeData(
+    VOID
+);
+
+VOID
+MupInitializeVcb(
+    PMUP_VCB Vcb
+);
+
+#if defined(ALLOC_PRAGMA)
+#pragma alloc_text(INIT, DriverEntry)
+#pragma alloc_text(INIT, MupInitializeData)
+#pragma alloc_text(INIT, MupInitializeVcb)
+#endif
+
 ERESOURCE MupGlobalLock;
 ERESOURCE MupPrefixTableLock;
 ERESOURCE MupCcbListLock;
@@ -53,8 +76,9 @@ NTSTATUS MupOrderedErrorList[] = { STATUS_UNSUCCESSFUL,
 
 /* FUNCTIONS ****************************************************************/
 
+INIT_SECTION
 VOID
-MupInitializeData()
+MupInitializeData(VOID)
 {
     ExInitializeResourceLite(&MupGlobalLock);
     ExInitializeResourceLite(&MupPrefixTableLock);
@@ -78,6 +102,7 @@ MupUninitializeData()
   ExDeleteResourceLite(&MupVcbLock);
 }
 
+INIT_SECTION
 VOID
 MupInitializeVcb(PMUP_VCB Vcb)
 {
@@ -108,7 +133,7 @@ MuppIsDfsEnabled(VOID)
     KeyName.MaximumLength = sizeof(L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Mup");
 
     /* Simply query registry to know whether we have to disable DFS.
-     * Unless explicitely stated in registry, we will try to enable DFS.
+     * Unless explicitly stated in registry, we will try to enable DFS.
      */
     InitializeObjectAttributes(&ObjectAttributes,
                                &KeyName,
@@ -754,14 +779,6 @@ Cleanup:
     return Status;
 }
 
-NTSTATUS
-NTAPI
-DfsVolumePassThrough(PDEVICE_OBJECT DeviceObject,
-                     PIRP Irp)
-{
-    return STATUS_NOT_IMPLEMENTED;
-}
-
 NTSTATUS
 NTAPI
 MupForwardIoRequest(PDEVICE_OBJECT DeviceObject,
@@ -948,6 +965,10 @@ InitializeProvider(PCWSTR ProviderName,
 
         Status = ZwQueryValueKey(KeyHandle, &Value, KeyValueFullInformation, Info, ResultLength, &ResultLength);
     }
+    else
+    {
+        Info = NULL;
+    }
 
     ZwClose(KeyHandle);
 
@@ -957,6 +978,7 @@ InitializeProvider(PCWSTR ProviderName,
      */
     if (NT_SUCCESS(Status))
     {
+        ASSERT(Info != NULL);
         AddUnregisteredProvider((PWSTR)((ULONG_PTR)Info + Info->DataOffset), ProviderOrder);
     }
 
@@ -1004,11 +1026,17 @@ MupGetProviderInformation(VOID)
 
         Status = ZwQueryValueKey(KeyHandle, &ProviderOrder, KeyValueFullInformation, Info, ResultLength, &ResultLength);
     }
+    else
+    {
+        Info = NULL;
+    }
 
     ZwClose(KeyHandle);
 
     if (NT_SUCCESS(Status))
     {
+        ASSERT(Info != NULL);
+
         Providers = (PWSTR)((ULONG_PTR)Info + Info->DataOffset);
         End = FALSE;
         ProviderCount = 0;
@@ -1232,13 +1260,6 @@ RegisterUncProvider(PDEVICE_OBJECT DeviceObject,
     return Status;
 }
 
-NTSTATUS
-DfsFsdFileSystemControl(PDEVICE_OBJECT DeviceObject,
-                        PIRP Irp)
-{
-    return STATUS_NOT_IMPLEMENTED;
-}
-
 NTSTATUS
 NTAPI
 MupFsControl(PDEVICE_OBJECT DeviceObject,
@@ -1328,7 +1349,7 @@ MupRerouteOpen(PFILE_OBJECT FileObject,
     RtlMoveMemory(FullPath, UncProvider->DeviceName.Buffer, UncProvider->DeviceName.Length);
     RtlMoveMemory((PWSTR)((ULONG_PTR)FullPath + UncProvider->DeviceName.Length), FileObject->FileName.Buffer, FileObject->FileName.Length);
 
-    /* And redo the path in the file oject */
+    /* And redo the path in the file object */
     ExFreePoolWithTag(FileObject->FileName.Buffer, 0);
     FileObject->FileName.Buffer = FullPath;
     FileObject->FileName.MaximumLength = TotalLength;
@@ -1342,9 +1363,9 @@ NTSTATUS
 BroadcastOpen(PIRP Irp)
 {
     PMUP_FCB Fcb;
-    PMUP_CCB Ccb;
     HANDLE Handle;
     PLIST_ENTRY Entry;
+    PMUP_CCB Ccb = NULL;
     PMUP_UNC UncProvider;
     UNICODE_STRING FullPath;
     PFILE_OBJECT FileObject;
@@ -1672,7 +1693,7 @@ MupDereferenceMasterQueryContext(PMUP_MQC MasterQueryContext)
 Complete:
     /* In finally, complete the IRP for real! */
     MasterQueryContext->Irp->IoStatus.Status = Status;
-    IofCompleteRequest(MasterQueryContext->Irp, IO_DISK_INCREMENT);
+    IoCompleteRequest(MasterQueryContext->Irp, IO_DISK_INCREMENT);
 
     MasterQueryContext->Irp = NULL;
     MupFreeMasterQueryContext(MasterQueryContext);
@@ -1721,7 +1742,7 @@ QueryPathCompletionRoutine(PDEVICE_OBJECT DeviceObject,
             }
 
             /* Otherwise, if the prefix was in the prefix table, just drop it:
-             * we have a provider which superseeds the accepted prefix, so leave
+             * we have a provider which supersedes the accepted prefix, so leave
              * room for the new prefix/provider
              */
             ExAcquireResourceExclusiveLite(&MupPrefixTableLock, TRUE);
@@ -1761,7 +1782,7 @@ QueryPathCompletionRoutine(PDEVICE_OBJECT DeviceObject,
         MasterQueryContext->LatestProvider = QueryContext->UncProvider;
         MasterQueryContext->LatestStatus = Status;
 
-        if (MasterQueryContext->FileObject->FsContext2 != DFS_MAGIC_CCB)
+        if (MasterQueryContext->FileObject->FsContext2 != (PVOID)DFS_DOWNLEVEL_OPEN_CONTEXT)
         {
             /* Allocate a buffer for the prefix */
             AcceptedPrefix = ExAllocatePoolWithTag(PagedPool, QueryResponse->LengthAccepted, TAG_MUP);
@@ -1813,7 +1834,7 @@ QueryPathCompletionRoutine(PDEVICE_OBJECT DeviceObject,
                 TableStatus = MupOrderedErrorList[0];
                 LatestPos = 0;
 
-                /* Otherwise, time to compare statuteses, between the latest failed
+                /* Otherwise, time to compare statuses, between the latest failed
                  * and the current failure.
                  * We have an order table of failed status: the deeper you go in the
                  * table, the more the error is critical.
@@ -1869,14 +1890,6 @@ Cleanup:
     return STATUS_MORE_PROCESSING_REQUIRED;
 }
 
-NTSTATUS
-DfsFsdCreate(PDEVICE_OBJECT DeviceObject,
-             PIRP Irp)
-{
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
-}
-
 NTSTATUS
 CreateRedirectedFile(PIRP Irp,
                      PFILE_OBJECT FileObject,
@@ -2002,7 +2015,7 @@ CreateRedirectedFile(PIRP Irp,
     }
 
     /* Ok, at that point, that's a regular MUP opening (if no DFS) */
-    if (!MupEnableDfs || FileObject->FsContext2 == DFS_MAGIC_CCB)
+    if (!MupEnableDfs || FileObject->FsContext2 == (PVOID)DFS_DOWNLEVEL_OPEN_CONTEXT)
     {
         /* We won't complete immediately */
         IoMarkIrpPending(Irp);
@@ -2114,7 +2127,7 @@ CreateRedirectedFile(PIRP Irp,
                     ExReleaseResourceLite(&MasterQueryContext->QueryPathListLock);
 
                     /* Query the provider !*/
-                    DPRINT1("Requeting UNC provider: %wZ\n", &UncProvider->DeviceName);
+                    DPRINT1("Requesting UNC provider: %wZ\n", &UncProvider->DeviceName);
                     DPRINT("Calling: %wZ\n", &UncProvider->DeviceObject->DriverObject->DriverName);
                     Status = IoCallDriver(UncProvider->DeviceObject, QueryIrp);
                 }
@@ -2212,12 +2225,9 @@ MupCreate(PDEVICE_OBJECT DeviceObject,
     _SEH2_TRY
     {
         /* If DFS is enabled, check if that's for DFS and is so relay */
-        if (MupEnableDfs)
+        if (MupEnableDfs && (DeviceObject->DeviceType == FILE_DEVICE_DFS || DeviceObject->DeviceType == FILE_DEVICE_DFS_FILE_SYSTEM))
         {
-            if (DeviceObject->DeviceType == FILE_DEVICE_DFS || DeviceObject->DeviceType == FILE_DEVICE_DFS_FILE_SYSTEM)
-            {
-                Status = DfsFsdCreate(DeviceObject, Irp);
-            }
+            Status = DfsFsdCreate(DeviceObject, Irp);
         }
         else
         {
@@ -2282,14 +2292,6 @@ MupCloseUncProvider(PMUP_UNC UncProvider)
     }
 }
 
-NTSTATUS
-DfsFsdCleanup(PDEVICE_OBJECT DeviceObject,
-              PIRP Irp)
-{
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
-}
-
 NTSTATUS
 NTAPI
 MupCleanup(PDEVICE_OBJECT DeviceObject,
@@ -2413,14 +2415,6 @@ MupCloseFcb(PDEVICE_OBJECT DeviceObject,
     return STATUS_SUCCESS;
 }
 
-NTSTATUS
-DfsFsdClose(PDEVICE_OBJECT DeviceObject,
-            PIRP Irp)
-{
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
-}
-
 NTSTATUS
 NTAPI
 MupClose(PDEVICE_OBJECT DeviceObject,
@@ -2492,12 +2486,6 @@ MupClose(PDEVICE_OBJECT DeviceObject,
     return Status;
 }
 
-VOID
-DfsUnload(PDRIVER_OBJECT DriverObject)
-{
-    UNIMPLEMENTED;
-}
-
 VOID
 NTAPI
 MupUnload(PDRIVER_OBJECT DriverObject)
@@ -2512,17 +2500,6 @@ MupUnload(PDRIVER_OBJECT DriverObject)
     MupUninitializeData();
 }
 
-NTSTATUS
-DfsDriverEntry(PDRIVER_OBJECT DriverObject,
-               PUNICODE_STRING RegistryPath)
-{
-    /* We don't support DFS yet, so
-     * fail to make sure it remains disabled
-     */
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
-}
-
 /*
  * FUNCTION: Called by the system to initialize the driver
  * ARGUMENTS:
@@ -2530,6 +2507,7 @@ DfsDriverEntry(PDRIVER_OBJECT DriverObject,
  *           RegistryPath = path to our configuration entries
  * RETURNS: Success or failure
  */
+INIT_SECTION
 NTSTATUS
 NTAPI
 DriverEntry(PDRIVER_OBJECT DriverObject,