ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

fs.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       See COPYING in the top level directory
00003  * PROJECT:         ReactOS kernel
00004  * FILE:            ntoskrnl/cc/fs.c
00005  * PURPOSE:         Implements cache managers functions useful for File Systems
00006  *
00007  * PROGRAMMERS:     Alex Ionescu
00008  */
00009 
00010 /* INCLUDES ******************************************************************/
00011 
00012 #include <ntoskrnl.h>
00013 #define NDEBUG
00014 #include <debug.h>
00015 
00016 #ifndef VACB_MAPPING_GRANULARITY
00017 #define VACB_MAPPING_GRANULARITY (256 * 1024)
00018 #endif
00019 
00020 /* GLOBALS   *****************************************************************/
00021 
00022 extern KGUARDED_MUTEX ViewLock;
00023 extern ULONG DirtyPageCount;
00024 
00025 NTSTATUS CcRosInternalFreeCacheSegment(PCACHE_SEGMENT CacheSeg);
00026 
00027 /* FUNCTIONS *****************************************************************/
00028 
00029 /*
00030  * @unimplemented
00031  */
00032 LARGE_INTEGER
00033 NTAPI
00034 CcGetDirtyPages (
00035     IN  PVOID           LogHandle,
00036     IN  PDIRTY_PAGE_ROUTINE DirtyPageRoutine,
00037     IN  PVOID           Context1,
00038     IN  PVOID           Context2
00039     )
00040 {
00041     LARGE_INTEGER i;
00042     UNIMPLEMENTED;
00043     i.QuadPart = 0;
00044     return i;
00045 }
00046 
00047 /*
00048  * @implemented
00049  */
00050 PFILE_OBJECT
00051 NTAPI
00052 CcGetFileObjectFromBcb (
00053     IN  PVOID   Bcb
00054     )
00055 {
00056     PINTERNAL_BCB iBcb = (PINTERNAL_BCB)Bcb;
00057     return iBcb->CacheSegment->Bcb->FileObject;
00058 }
00059 
00060 /*
00061  * @unimplemented
00062  */
00063 LARGE_INTEGER
00064 NTAPI
00065 CcGetLsnForFileObject (
00066     IN  PFILE_OBJECT    FileObject,
00067     OUT PLARGE_INTEGER  OldestLsn OPTIONAL
00068     )
00069 {
00070     LARGE_INTEGER i;
00071     UNIMPLEMENTED;
00072     i.QuadPart = 0;
00073     return i;
00074 }
00075 
00076 /*
00077  * @unimplemented
00078  */
00079 VOID
00080 NTAPI
00081 CcInitializeCacheMap (
00082     IN  PFILE_OBJECT            FileObject,
00083     IN  PCC_FILE_SIZES          FileSizes,
00084     IN  BOOLEAN             PinAccess,
00085     IN  PCACHE_MANAGER_CALLBACKS    CallBacks,
00086     IN  PVOID               LazyWriterContext
00087     )
00088 {
00089     ASSERT(FileObject);
00090     ASSERT(FileSizes);
00091 
00092     /* Call old ROS cache init function */
00093     CcRosInitializeFileCache(FileObject,
00094         /*PAGE_SIZE*/ VACB_MAPPING_GRANULARITY, CallBacks,
00095         LazyWriterContext);
00096 }
00097 
00098 /*
00099  * @unimplemented
00100  */
00101 BOOLEAN
00102 NTAPI
00103 CcIsThereDirtyData (
00104     IN  PVPB    Vpb
00105     )
00106 {
00107     UNIMPLEMENTED;
00108     return FALSE;
00109 }
00110 
00111 /*
00112  * @unimplemented
00113  */
00114 BOOLEAN
00115 NTAPI
00116 CcPurgeCacheSection (
00117     IN  PSECTION_OBJECT_POINTERS    SectionObjectPointer,
00118     IN  PLARGE_INTEGER          FileOffset OPTIONAL,
00119     IN  ULONG               Length,
00120     IN  BOOLEAN             UninitializeCacheMaps
00121     )
00122 {
00123     //UNIMPLEMENTED;
00124     return FALSE;
00125 }
00126 
00127 
00128 /*
00129  * @implemented
00130  */
00131 VOID NTAPI
00132 CcSetFileSizes (IN PFILE_OBJECT FileObject,
00133         IN PCC_FILE_SIZES FileSizes)
00134 {
00135   KIRQL oldirql;
00136   PBCB Bcb;
00137   PLIST_ENTRY current_entry;
00138   PCACHE_SEGMENT current;
00139   LIST_ENTRY FreeListHead;
00140   NTSTATUS Status;
00141 
00142   DPRINT("CcSetFileSizes(FileObject 0x%p, FileSizes 0x%p)\n",
00143      FileObject, FileSizes);
00144   DPRINT("AllocationSize %d, FileSize %d, ValidDataLength %d\n",
00145          (ULONG)FileSizes->AllocationSize.QuadPart,
00146          (ULONG)FileSizes->FileSize.QuadPart,
00147          (ULONG)FileSizes->ValidDataLength.QuadPart);
00148 
00149   Bcb = FileObject->SectionObjectPointer->SharedCacheMap;
00150 
00151   /*
00152    * It is valid to call this function on file objects that weren't
00153    * initialized for caching. In this case it's simple no-op.
00154    */
00155   if (Bcb == NULL)
00156      return;
00157 
00158   if (FileSizes->AllocationSize.QuadPart < Bcb->AllocationSize.QuadPart)
00159   {
00160      InitializeListHead(&FreeListHead);
00161      KeAcquireGuardedMutex(&ViewLock);
00162      KeAcquireSpinLock(&Bcb->BcbLock, &oldirql);
00163 
00164      current_entry = Bcb->BcbSegmentListHead.Flink;
00165      while (current_entry != &Bcb->BcbSegmentListHead)
00166      {
00167     current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT, BcbSegmentListEntry);
00168     current_entry = current_entry->Flink;
00169     if (current->FileOffset > FileSizes->AllocationSize.QuadPart ||
00170         (current->FileOffset == 0 && FileSizes->AllocationSize.QuadPart == 0))
00171     {
00172            if (current->ReferenceCount == 0 || (current->ReferenceCount == 1 && current->Dirty))
00173        {
00174               RemoveEntryList(&current->BcbSegmentListEntry);
00175               RemoveEntryList(&current->CacheSegmentListEntry);
00176               RemoveEntryList(&current->CacheSegmentLRUListEntry);
00177               if (current->Dirty)
00178               {
00179                  RemoveEntryList(&current->DirtySegmentListEntry);
00180                  DirtyPageCount -= Bcb->CacheSegmentSize / PAGE_SIZE;
00181               }
00182           InsertHeadList(&FreeListHead, &current->BcbSegmentListEntry);
00183        }
00184        else
00185        {
00186           DPRINT1("Anyone has referenced a cache segment behind the new size.\n");
00187           KeBugCheck(CACHE_MANAGER);
00188        }
00189     }
00190      }
00191 
00192      Bcb->AllocationSize = FileSizes->AllocationSize;
00193      Bcb->FileSize = FileSizes->FileSize;
00194      KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
00195      KeReleaseGuardedMutex(&ViewLock);
00196 
00197      current_entry = FreeListHead.Flink;
00198      while(current_entry != &FreeListHead)
00199      {
00200         current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT, BcbSegmentListEntry);
00201         current_entry = current_entry->Flink;
00202         Status = CcRosInternalFreeCacheSegment(current);
00203         if (!NT_SUCCESS(Status))
00204         {
00205            DPRINT1("CcRosInternalFreeCacheSegment failed, status = %x\n", Status);
00206        KeBugCheck(CACHE_MANAGER);
00207         }
00208      }
00209   }
00210   else
00211   {
00212      KeAcquireSpinLock(&Bcb->BcbLock, &oldirql);
00213      Bcb->AllocationSize = FileSizes->AllocationSize;
00214      Bcb->FileSize = FileSizes->FileSize;
00215      KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
00216   }
00217 }
00218 
00219 /*
00220  * @unimplemented
00221  */
00222 VOID
00223 NTAPI
00224 CcSetLogHandleForFile (
00225     IN  PFILE_OBJECT    FileObject,
00226     IN  PVOID       LogHandle,
00227     IN  PFLUSH_TO_LSN   FlushToLsnRoutine
00228     )
00229 {
00230     UNIMPLEMENTED;
00231 }
00232 
00233 /*
00234  * @unimplemented
00235  */
00236 BOOLEAN
00237 NTAPI
00238 CcUninitializeCacheMap (
00239     IN  PFILE_OBJECT            FileObject,
00240     IN  PLARGE_INTEGER          TruncateSize OPTIONAL,
00241     IN  PCACHE_UNINITIALIZE_EVENT   UninitializeCompleteEvent OPTIONAL
00242     )
00243 {
00244 #if 0
00245     UNIMPLEMENTED;
00246     return FALSE;
00247 #else
00248     return NT_SUCCESS(CcRosReleaseFileCache(FileObject));
00249 #endif
00250 }
00251 
00252 BOOLEAN
00253 NTAPI
00254 CcGetFileSizes
00255 (IN PFILE_OBJECT FileObject,
00256  IN PCC_FILE_SIZES FileSizes)
00257 {
00258   PBCB Bcb;
00259     
00260   Bcb = FileObject->SectionObjectPointer->SharedCacheMap;
00261 
00262   if (!Bcb)
00263       return FALSE;
00264 
00265   FileSizes->AllocationSize = Bcb->AllocationSize;
00266   FileSizes->FileSize = FileSizes->ValidDataLength = Bcb->FileSize;
00267   return TRUE;
00268 }

Generated on Mon May 28 2012 04:18:55 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.