[NTOSKRNL]
[reactos.git] / reactos / ntoskrnl / cc / pin.c
index d6e764a..9b71078 100644 (file)
@@ -24,13 +24,13 @@ extern NPAGED_LOOKASIDE_LIST iBcbLookasideList;
  */
 BOOLEAN
 NTAPI
-CcMapData(
+CcMapData (
     IN PFILE_OBJECT FileObject,
-       IN PLARGE_INTEGER FileOffset,
-       IN ULONG Length,
-       IN ULONG Flags,
-       OUT PVOID *pBcb,
-       OUT PVOID *pBuffer)
+    IN PLARGE_INTEGER FileOffset,
+    IN ULONG Length,
+    IN ULONG Flags,
+    OUT PVOID *pBcb,
+    OUT PVOID *pBuffer)
 {
     ULONG ReadOffset;
     BOOLEAN Valid;
@@ -61,14 +61,18 @@ CcMapData(
     {
         return FALSE;
     }
-    ROffset = ROUND_DOWN (ReadOffset, Bcb->CacheSegmentSize);
-    Status = CcRosRequestCacheSegment(Bcb, ROffset,
-                                             pBuffer, &Valid,
+
+    ROffset = ROUND_DOWN(ReadOffset, Bcb->CacheSegmentSize);
+    Status = CcRosRequestCacheSegment(Bcb,
+                                      ROffset,
+                                      pBuffer,
+                                      &Valid,
                                       &CacheSeg);
     if (!NT_SUCCESS(Status))
     {
         return FALSE;
     }
+
     if (!Valid)
     {
         if (!(Flags & MAP_WAIT))
@@ -76,10 +80,11 @@ CcMapData(
             CcRosReleaseCacheSegment(Bcb, CacheSeg, FALSE, FALSE, FALSE);
             return FALSE;
         }
+
         if (!NT_SUCCESS(ReadCacheSegment(CacheSeg)))
         {
             CcRosReleaseCacheSegment(Bcb, CacheSeg, FALSE, FALSE, FALSE);
-               return FALSE;
+            return FALSE;
         }
     }
 
@@ -90,6 +95,7 @@ CcMapData(
         CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE);
         return FALSE;
     }
+
     memset(iBcb, 0, sizeof(INTERNAL_BCB));
     iBcb->PFCB.NodeTypeCode = 0xDE45; /* Undocumented (CAPTIVE_PUBLIC_BCB_NODETYPECODE) */
     iBcb->PFCB.NodeByteSize = sizeof(PUBLIC_BCB);
@@ -99,6 +105,7 @@ CcMapData(
     iBcb->Dirty = FALSE;
     iBcb->RefCount = 1;
     *pBcb = (PVOID)iBcb;
+
     return TRUE;
 }
 
@@ -108,15 +115,14 @@ CcMapData(
 BOOLEAN
 NTAPI
 CcPinMappedData (
-       IN      PFILE_OBJECT            FileObject,
-       IN      PLARGE_INTEGER          FileOffset,
-       IN      ULONG                   Length,
-       IN      ULONG                   Flags,
-       OUT     PVOID                   * Bcb
-       )
+    IN PFILE_OBJECT FileObject,
+    IN PLARGE_INTEGER FileOffset,
+    IN ULONG Length,
+    IN ULONG Flags,
+    OUT        PVOID * Bcb)
 {
-  /* no-op for current implementation. */
-  return TRUE;
+    /* no-op for current implementation. */
+    return TRUE;
 }
 
 /*
@@ -125,22 +131,21 @@ CcPinMappedData (
 BOOLEAN
 NTAPI
 CcPinRead (
-       IN      PFILE_OBJECT            FileObject,
-       IN      PLARGE_INTEGER          FileOffset,
-       IN      ULONG                   Length,
-       IN      ULONG                   Flags,
-       OUT     PVOID                   * Bcb,
-       OUT     PVOID                   * Buffer
-       )
+    IN PFILE_OBJECT FileObject,
+    IN PLARGE_INTEGER FileOffset,
+    IN ULONG Length,
+    IN ULONG Flags,
+    OUT        PVOID * Bcb,
+    OUT        PVOID * Buffer)
 {
-  if (CcMapData(FileObject, FileOffset, Length, Flags, Bcb, Buffer))
-  {
-    if (CcPinMappedData(FileObject, FileOffset, Length, Flags, Bcb))
-      return TRUE;
-    else
-      CcUnpinData(Bcb);
-  }
-  return FALSE;
+    if (CcMapData(FileObject, FileOffset, Length, Flags, Bcb, Buffer))
+    {
+        if (CcPinMappedData(FileObject, FileOffset, Length, Flags, Bcb))
+            return TRUE;
+        else
+            CcUnpinData(Bcb);
+    }
+    return FALSE;
 }
 
 /*
@@ -149,35 +154,35 @@ CcPinRead (
 BOOLEAN
 NTAPI
 CcPreparePinWrite (
-       IN      PFILE_OBJECT            FileObject,
-       IN      PLARGE_INTEGER          FileOffset,
-       IN      ULONG                   Length,
-       IN      BOOLEAN                 Zero,
-       IN      ULONG                   Flags,
-       OUT     PVOID                   * Bcb,
-       OUT     PVOID                   * Buffer
-       )
+    IN PFILE_OBJECT FileObject,
+    IN PLARGE_INTEGER FileOffset,
+    IN ULONG Length,
+    IN BOOLEAN Zero,
+    IN ULONG Flags,
+    OUT        PVOID * Bcb,
+    OUT        PVOID * Buffer)
 {
-        /*
-         * FIXME: This is function is similar to CcPinRead, but doesn't
-         * read the data if they're not present. Instead it should just
-         * prepare the cache segments and zero them out if Zero == TRUE.
-         *
-         * For now calling CcPinRead is better than returning error or
-         * just having UNIMPLEMENTED here.
-         */
-        return CcPinRead(FileObject, FileOffset, Length, Flags, Bcb, Buffer);
+    /*
+     * FIXME: This is function is similar to CcPinRead, but doesn't
+     * read the data if they're not present. Instead it should just
+     * prepare the cache segments and zero them out if Zero == TRUE.
+     *
+     * For now calling CcPinRead is better than returning error or
+     * just having UNIMPLEMENTED here.
+     */
+    return CcPinRead(FileObject, FileOffset, Length, Flags, Bcb, Buffer);
 }
 
 /*
  * @implemented
  */
 VOID NTAPI
-CcSetDirtyPinnedData (IN PVOID Bcb,
-                     IN PLARGE_INTEGER Lsn)
+CcSetDirtyPinnedData (
+    IN PVOID Bcb,
+    IN PLARGE_INTEGER Lsn)
 {
-   PINTERNAL_BCB iBcb = Bcb;
-   iBcb->Dirty = TRUE;
+    PINTERNAL_BCB iBcb = Bcb;
+    iBcb->Dirty = TRUE;
 }
 
 
@@ -185,15 +190,20 @@ CcSetDirtyPinnedData (IN PVOID Bcb,
  * @implemented
  */
 VOID NTAPI
-CcUnpinData (IN PVOID Bcb)
+CcUnpinData (
+    IN PVOID Bcb)
 {
-  PINTERNAL_BCB iBcb = Bcb;
-  CcRosReleaseCacheSegment(iBcb->CacheSegment->Bcb, iBcb->CacheSegment, TRUE,
-                           iBcb->Dirty, FALSE);
-  if (--iBcb->RefCount == 0)
-  {
-    ExFreeToNPagedLookasideList(&iBcbLookasideList, iBcb);
-  }
+    PINTERNAL_BCB iBcb = Bcb;
+
+    CcRosReleaseCacheSegment(iBcb->CacheSegment->Bcb,
+                             iBcb->CacheSegment,
+                             TRUE,
+                             iBcb->Dirty,
+                             FALSE);
+    if (--iBcb->RefCount == 0)
+    {
+        ExFreeToNPagedLookasideList(&iBcbLookasideList, iBcb);
+    }
 }
 
 /*
@@ -202,11 +212,10 @@ CcUnpinData (IN PVOID Bcb)
 VOID
 NTAPI
 CcUnpinDataForThread (
-       IN      PVOID                   Bcb,
-       IN      ERESOURCE_THREAD        ResourceThreadId
-       )
+    IN PVOID Bcb,
+    IN ERESOURCE_THREAD ResourceThreadId)
 {
-       UNIMPLEMENTED;
+    UNIMPLEMENTED;
 }
 
 /*
@@ -215,11 +224,10 @@ CcUnpinDataForThread (
 VOID
 NTAPI
 CcRepinBcb (
-       IN      PVOID   Bcb
-       )
+    IN PVOID Bcb)
 {
-  PINTERNAL_BCB iBcb = Bcb;
-  iBcb->RefCount++;
+    PINTERNAL_BCB iBcb = Bcb;
+    iBcb->RefCount++;
 }
 
 /*
@@ -228,38 +236,37 @@ CcRepinBcb (
 VOID
 NTAPI
 CcUnpinRepinnedBcb (
-       IN      PVOID                   Bcb,
-       IN      BOOLEAN                 WriteThrough,
-       IN      PIO_STATUS_BLOCK        IoStatus
-       )
+    IN PVOID Bcb,
+    IN BOOLEAN WriteThrough,
+    IN PIO_STATUS_BLOCK IoStatus)
 {
-  PINTERNAL_BCB iBcb = Bcb;
+    PINTERNAL_BCB iBcb = Bcb;
 
-  if (--iBcb->RefCount == 0)
+    if (--iBcb->RefCount == 0)
     {
-      IoStatus->Information = 0;
-      if (WriteThrough)
+        IoStatus->Information = 0;
+        if (WriteThrough)
         {
             KeWaitForSingleObject(&iBcb->CacheSegment->Mutex,
                                   Executive,
                                   KernelMode,
                                   FALSE,
                                   NULL);
-          if (iBcb->CacheSegment->Dirty)
+            if (iBcb->CacheSegment->Dirty)
             {
-              IoStatus->Status = CcRosFlushCacheSegment(iBcb->CacheSegment);
+                IoStatus->Status = CcRosFlushCacheSegment(iBcb->CacheSegment);
             }
-          else
+            else
             {
-              IoStatus->Status = STATUS_SUCCESS;
+                IoStatus->Status = STATUS_SUCCESS;
             }
-          KeReleaseMutex(&iBcb->CacheSegment->Mutex, 0);
+            KeReleaseMutex(&iBcb->CacheSegment->Mutex, 0);
         }
-      else
+        else
         {
-          IoStatus->Status = STATUS_SUCCESS;
+            IoStatus->Status = STATUS_SUCCESS;
         }
 
-      ExFreeToNPagedLookasideList(&iBcbLookasideList, iBcb);
+        ExFreeToNPagedLookasideList(&iBcbLookasideList, iBcb);
     }
 }