2 * reactos Cache Manager initialization functions of libcaptive
3 * Copyright (C) 2002-2003 Jan Kratochvil <project-captive@jankratochvil.net>
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; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <glib/gmessages.h>
23 #include "reactos/ntos/types.h"
24 #include "reactos/ddk/iotypes.h"
25 #include "reactos/ddk/cctypes.h"
26 #include "sharedcachemap.h"
27 #include "reactos/ddk/kefuncs.h"
31 * CcInitializeCacheMap:
32 * @FileObject: Existing file to set callbacks for. Ignored by libcaptive.
33 * %NULL value is forbidden.
34 * @FileSizes: Some file sizes suggestions. Ignored by libcaptive.
35 * %NULL value is forbidden.
36 * @PinAccess: CcPin*() functions will be used with @FileObject? Ignored by libcaptive.
37 * @CallBacks: Provided callback functions for readahead/writebehind. Ignored by libcaptive.
38 * %NULL value is forbidden.
39 * @LazyWriterContext: Value passed to functions of @CallBacks to bind with @FileObject.
40 * %NULL value is permitted.
42 * Provides support of readahead/writebehind in W32. Function should be called
43 * by W32 filesystem to offer its functions to W32 kernel. These functions
44 * are never called by libcaptive, this call is a NOP in libcaptive.
46 * VERIFIED: Double CcInitializeCacheMap() without CcUninitializeCacheMap().
48 VOID CcInitializeCacheMap(IN PFILE_OBJECT FileObject,
49 IN PCC_FILE_SIZES FileSizes,IN BOOLEAN PinAccess,IN PCACHE_MANAGER_CALLBACKS CallBacks,IN PVOID LazyWriterContext)
51 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"enter: CcInitializeCacheMap: FileObject=0x%lX,"
52 "FileSizes,->AllocationSize=0x%lX,->FileSize=0x%lX,->ValidDataLength=0x%lX,"
53 "PinAccess=%d,Callbacks,LazyWriteContext",
55 (!FileSizes ? -1 : (long)FileSizes->AllocationSize.QuadPart),
56 (!FileSizes ? -1 : (long)FileSizes->FileSize.QuadPart),
57 (!FileSizes ? -1 : (long)FileSizes->ValidDataLength.QuadPart),
60 g_return_if_fail(FileObject!=NULL);
61 g_return_if_fail(FileSizes!=NULL);
62 g_return_if_fail(CallBacks!=NULL);
64 /* VERIFIED: CcInitializeCacheMap() has already 'SectionObjectPointers' allocated. */
65 g_return_if_fail(FileObject->SectionObjectPointer!=NULL);
67 captive_shared_cache_map_get_ref(FileObject,FileSizes,PinAccess,CallBacks,LazyWriterContext);
69 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"leave: CcInitializeCacheMap");
74 * CcUninitializeCacheMap:
75 * @FileObject: File to close caching for.
76 * %NULL value is forbidden.
77 * @TruncateSize: Current file size if @FileObject was truncated to it in the meantime.
78 * @UninitializeCompleteEvent: Optional event to signal after physical write to disk.
79 * %NULL value is permitted.
81 * Close the cachine facilities from CcInitializeCacheMap().
82 * It is valid to pass @FileObject without being registered by CcInitializeCacheMap().
84 * FIXME; What to do with files with dirty blocks? Currently we fail assertion on them
85 * although I think W32 would drop such buffers (purge them - not flush them).
87 * Returns: %TRUE if the caching was closed successfuly.
88 * %FALSE if @FileObject was not registered by CcInitializeCacheMap()
89 * or if its #SharedCacheMap is still in use (such as by other #FileObject reference of
90 * the same #FCB instance).
92 BOOLEAN CcUninitializeCacheMap(IN PFILE_OBJECT FileObject,
93 IN PLARGE_INTEGER TruncateSize OPTIONAL,IN PCACHE_UNINITIALIZE_EVENT UninitializeCompleteEvent OPTIONAL)
95 CaptiveSharedCacheMapObject *SharedCacheMap;
98 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"enter: CcUninitializeCacheMap: FileObject=0x%lX,TruncateSize=0x%lX,UninitializeCompleteEvent=0x%lX",
99 (long)FileObject,(!TruncateSize ? -1 : (long)TruncateSize->QuadPart),(long)UninitializeCompleteEvent);
101 g_return_val_if_fail(FileObject!=NULL,FALSE);
102 /* assert current size ==*TruncateSize if TruncateSize */
104 if (FileObject->SectionObjectPointer && !FileObject->SectionObjectPointer->SharedCacheMap)
107 SharedCacheMap=captive_FileObject_to_SharedCacheMap(FileObject);
109 /* We may be called without preceding CcInitializeCacheMap(). */
110 if (!captive_shared_cache_map_query_w32_ref(SharedCacheMap))
113 captive_shared_cache_map_w32_unref(SharedCacheMap);
114 r=(FileObject->SectionObjectPointer->SharedCacheMap==NULL);
117 /* FIXME: should we do KePulseEvent? Are we allowed to signal from inside CcUninitializeCacheMap() ? */
118 if (UninitializeCompleteEvent)
120 &UninitializeCompleteEvent->Event, /* Event */
121 IO_NO_INCREMENT, /* Increment */
125 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"leave: CcUninitializeCacheMap: r=%d",r);
133 * @FileObject: Initialized open #FileObject to update file sizes of.
134 * %NULL value is forbidden.
135 * @FileSizes: New file sizes to update cache to.
136 * %NULL value is forbidden.
138 * Update cache properties after file sizes were updated.
139 * Probably only the exceeding pages need to be unmapped and BCBs updated
140 * if FileSizes->AllocationSize gets shrunk.
142 * #AllocationSize must not change if any map or pin Bcbs exist.
144 VOID CcSetFileSizes(IN PFILE_OBJECT FileObject,IN PCC_FILE_SIZES FileSizes)
146 CaptiveSharedCacheMapObject *SharedCacheMap;
148 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"enter: CcSetFileSizes: FileObject=0x%lX,"
149 "FileSizes,->AllocationSize=0x%lX,->FileSize=0x%lX,->ValidDataLength=0x%lX",
151 (!FileSizes ? -1 : (long)FileSizes->AllocationSize.QuadPart),
152 (!FileSizes ? -1 : (long)FileSizes->FileSize.QuadPart),
153 (!FileSizes ? -1 : (long)FileSizes->ValidDataLength.QuadPart));
155 g_return_if_fail(FileObject!=NULL);
156 g_return_if_fail(FileSizes!=NULL);
158 /* Needed by ext2fsd.sys-v0.10a: */
160 && FileObject->SectionObjectPointer
161 && FileObject->SectionObjectPointer->SharedCacheMap) {
162 SharedCacheMap=captive_FileObject_to_SharedCacheMap(FileObject);
163 captive_shared_cache_map_FileSizes_set(SharedCacheMap,FileSizes);
166 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"leave: CcSetFileSizes");