[RDBSS]
[reactos.git] / reactos / sdk / lib / drivers / rdbsslib / rdbss.c
index 43c89c6..f3771cf 100644 (file)
@@ -743,53 +743,6 @@ __RxWriteReleaseResources(
     }
 }
 
-NTSTATUS
-NTAPI
-RxAcquireExclusiveFcbResourceInMRx(
-    _Inout_ PMRX_FCB Fcb)
-{
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
-}
-
-BOOLEAN
-NTAPI
-RxAcquireFcbForLazyWrite(
-    PVOID Context,
-    BOOLEAN Wait)
-{
-    UNIMPLEMENTED;
-    return FALSE;
-}
-
-BOOLEAN
-NTAPI
-RxAcquireFcbForReadAhead(
-    PVOID Context,
-    BOOLEAN Wait)
-{
-    UNIMPLEMENTED;
-    return FALSE;
-}
-
-VOID
-NTAPI
-RxAcquireFileForNtCreateSection(
-    PFILE_OBJECT FileObject)
-{
-    UNIMPLEMENTED;
-}
-
-NTSTATUS
-NTAPI
-RxAcquireForCcFlush(
-    PFILE_OBJECT FileObject,
-    PDEVICE_OBJECT DeviceObject)
-{
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
-}
-
 /*
  * @implemented
  */
@@ -3235,6 +3188,7 @@ RxCommonRead(
 
             if (!NT_SUCCESS(Irp->IoStatus.Status))
             {
+                Status = Irp->IoStatus.Status;
                 _SEH2_LEAVE;
             }
 
@@ -5337,6 +5291,7 @@ RxDriverEntry(
 #endif
 }
 
+#if DBG
 /*
  * @implemented
  */
@@ -5363,7 +5318,11 @@ RxDumpWantedAccess(
 {
     PAGED_CODE();
 }
+#endif
 
+/*
+ * @implemented
+ */
 BOOLEAN
 NTAPI
 RxFastIoCheckIfPossible(
@@ -5376,6 +5335,7 @@ RxFastIoCheckIfPossible(
 {
     PFCB Fcb;
     PSRV_OPEN SrvOpen;
+    LARGE_INTEGER LargeLength;
 
     PAGED_CODE();
 
@@ -5436,11 +5396,11 @@ RxFastIoCheckIfPossible(
     RxProcessChangeBufferingStateRequestsForSrvOpen(SrvOpen);
     FsRtlExitFileSystem();
 
+    LargeLength.QuadPart = Length;
+
     /* If operation to come is a read operation */
     if (CheckForReadOperation)
     {
-        LARGE_INTEGER LargeLength;
-
         /* Check that read cache is enabled */
         if (!BooleanFlagOn(Fcb->FcbState, FCB_STATE_READCACHING_ENABLED))
         {
@@ -5449,7 +5409,6 @@ RxFastIoCheckIfPossible(
         }
 
         /* Check whether there's a lock conflict */
-        LargeLength.QuadPart = Length;
         if (!FsRtlFastCheckLockForRead(&Fcb->Specific.Fcb.FileLock,
                                        FileOffset,
                                        &LargeLength,
@@ -5464,8 +5423,26 @@ RxFastIoCheckIfPossible(
         return TRUE;
     }
 
-    UNIMPLEMENTED;
-    return FALSE;
+    /* Check that write cache is enabled */
+    if (!BooleanFlagOn(Fcb->FcbState, FCB_STATE_WRITECACHING_ENABLED))
+    {
+        DPRINT1("Write caching disabled\n");
+        return FALSE;
+    }
+
+    /* Check whether there's a lock conflict */
+    if (!FsRtlFastCheckLockForWrite(&Fcb->Specific.Fcb.FileLock,
+                                    FileOffset,
+                                    &LargeLength,
+                                    LockKey,
+                                    FileObject,
+                                    PsGetCurrentProcess()))
+    {
+        DPRINT1("FsRtlFastCheckLockForWrite failed\n");
+        return FALSE;
+    }
+
+    return TRUE;
 }
 
 BOOLEAN
@@ -5536,6 +5513,9 @@ RxFastIoRead(
     return Ret;
 }
 
+/*
+ * @implemented
+ */
 BOOLEAN
 NTAPI
 RxFastIoWrite(
@@ -5548,8 +5528,39 @@ RxFastIoWrite(
     PIO_STATUS_BLOCK IoStatus,
     PDEVICE_OBJECT DeviceObject)
 {
-    UNIMPLEMENTED;
-    return FALSE;
+    PFOBX Fobx;
+    BOOLEAN Ret;
+    RX_TOPLEVELIRP_CONTEXT TopLevelContext;
+
+    PAGED_CODE();
+
+    Fobx = (PFOBX)FileObject->FsContext2;
+    if (BooleanFlagOn(Fobx->Flags, FOBX_FLAG_BAD_HANDLE))
+    {
+        return FALSE;
+    }
+
+    DPRINT("RxFastIoWrite: %p (%p, %p)\n", FileObject, FileObject->FsContext,
+                                           FileObject->FsContext2);
+    DPRINT("Writing %ld at %I64x\n", Length, FileOffset->QuadPart);
+
+    /* Prepare a TLI context */
+    ASSERT(RxIsThisTheTopLevelIrp(NULL));
+    RxInitializeTopLevelIrpContext(&TopLevelContext, (PIRP)FSRTL_FAST_IO_TOP_LEVEL_IRP,
+                                   (PRDBSS_DEVICE_OBJECT)DeviceObject);
+
+    Ret = FsRtlCopyWrite2(FileObject, FileOffset, Length, Wait, LockKey, Buffer,
+                          IoStatus, DeviceObject, &TopLevelContext);
+    if (Ret)
+    {
+        DPRINT("Write OK\n");
+    }
+    else
+    {
+        DPRINT1("Write failed!\n");
+    }
+
+    return Ret;
 }
 
 NTSTATUS
@@ -5609,6 +5620,11 @@ RxFindOrCreateFcb(
     /* If FCB was not found or is not covering full path, prepare for more work */
     if (Fcb == NULL || Fcb->FcbTableEntry.Path.Length != NetRootName->Length)
     {
+        if (Fcb != NULL)
+        {
+            DPRINT1("FCB was found and it's not covering the whole path: %wZ - %wZ\n", &Fcb->FcbTableEntry.Path, NetRootName);
+        }
+
         if (!AcquiredExclusive)
         {
             RxReleaseFcbTableLock(&NetRoot->FcbTable);
@@ -6299,7 +6315,7 @@ RxFspDispatch(
         RxContext->LastExecutionThread = PsGetCurrentThread();
         SetFlag(RxContext->Flags, (RX_CONTEXT_FLAG_IN_FSP | RX_CONTEXT_FLAG_WAIT));
 
-        DPRINT("Dispatch: MN: %d, Ctxt: %p, IRP: %p, THRD: %lx #%lx", RxContext->MinorFunction,
+        DPRINT("Dispatch: MN: %d, Ctxt: %p, IRP: %p, THRD: %lx #%lx\n", RxContext->MinorFunction,
                RxContext, RxContext->CurrentIrp, RxContext->LastExecutionThread,
                RxContext->SerialNumber);
 
@@ -7478,6 +7494,9 @@ Leave:
     return Status;
 }
 
+/*
+ * @implemented
+ */
 NTSTATUS
 NTAPI
 RxPrepareToReparseSymbolicLink(
@@ -7487,8 +7506,74 @@ RxPrepareToReparseSymbolicLink(
     BOOLEAN NewPathIsAbsolute,
     PBOOLEAN ReparseRequired)
 {
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
+    PWSTR NewBuffer;
+    USHORT NewLength;
+    PFILE_OBJECT FileObject;
+
+    /* Assume no reparse is required first */
+    *ReparseRequired = FALSE;
+
+    /* Only supported for IRP_MJ_CREATE */
+    if (RxContext->MajorFunction != IRP_MJ_CREATE)
+    {
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    /* If symbolic link is not embedded, and DELETE is specified, fail */
+    if (!SymbolicLinkEmbeddedInOldPath)
+    {
+        /* Excepted if DELETE is the only flag specified, then, open has to succeed
+         * See: https://msdn.microsoft.com/en-us/library/windows/hardware/ff554649(v=vs.85).aspx (remarks)
+         */
+        if (BooleanFlagOn(RxContext->Create.NtCreateParameters.DesiredAccess, DELETE) &&
+            BooleanFlagOn(RxContext->Create.NtCreateParameters.DesiredAccess, ~DELETE))
+        {
+            return STATUS_ACCESS_DENIED;
+        }
+    }
+
+    /* At that point, assume reparse will be required */
+    *ReparseRequired = TRUE;
+
+    /* If new path isn't absolute, it's up to us to make it absolute */
+    if (!NewPathIsAbsolute)
+    {
+        /* The prefix will be \Device\Mup */
+        NewLength = NewPath->Length + (sizeof(L"\\Device\\Mup") - sizeof(UNICODE_NULL));
+        NewBuffer = ExAllocatePoolWithTag(PagedPool | POOL_COLD_ALLOCATION, NewLength,
+                                          RX_MISC_POOLTAG);
+        if (NewBuffer == NULL)
+        {
+            return STATUS_INSUFFICIENT_RESOURCES;
+        }
+
+        /* Copy data for the new path */
+        RtlMoveMemory(NewBuffer, L"\\Device\\Mup", (sizeof(L"\\Device\\Mup") - sizeof(UNICODE_NULL)));
+        RtlMoveMemory(Add2Ptr(NewBuffer, (sizeof(L"\\Device\\Mup") - sizeof(UNICODE_NULL))),
+                      NewPath->Buffer, NewPath->Length);
+    }
+    /* Otherwise, use caller path as it */
+    else
+    {
+        NewLength = NewPath->Length;
+        NewBuffer = NewPath->Buffer;
+    }
+
+    /* Get the FILE_OBJECT we'll modify */
+    FileObject = RxContext->CurrentIrpSp->FileObject;
+
+    /* Free old path first */
+    ExFreePoolWithTag(FileObject->FileName.Buffer, 0);
+    /* And setup new one */
+    FileObject->FileName.Length = NewLength;
+    FileObject->FileName.MaximumLength = NewLength;
+    FileObject->FileName.Buffer = NewBuffer;
+
+    /* And set reparse flag */
+    SetFlag(RxContext->Create.Flags, RX_CONTEXT_CREATE_FLAG_REPARSE);
+
+    /* Done! */
+    return STATUS_SUCCESS;
 }
 
 /*
@@ -8102,40 +8187,6 @@ RxRegisterMinirdr(
     return STATUS_SUCCESS;
 }
 
-VOID
-NTAPI
-RxReleaseFcbFromLazyWrite(
-    PVOID Context)
-{
-    UNIMPLEMENTED;
-}
-
-VOID
-NTAPI
-RxReleaseFcbFromReadAhead(
-    PVOID Context)
-{
-    UNIMPLEMENTED;
-}
-
-VOID
-NTAPI
-RxReleaseFileForNtCreateSection(
-    PFILE_OBJECT FileObject)
-{
-    UNIMPLEMENTED;
-}
-
-NTSTATUS
-NTAPI
-RxReleaseForCcFlush(
-    PFILE_OBJECT FileObject,
-    PDEVICE_OBJECT DeviceObject)
-{
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
-}
-
 /*
  * @implemented
  */