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 CaptiveSharedCacheMapObject *SharedCacheMap;
53 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"enter: CcInitializeCacheMap: FileObject=0x%lX,"
54 "FileSizes,->AllocationSize=0x%lX,->FileSize=0x%lX,->ValidDataLength=0x%lX,"
55 "PinAccess=%d,Callbacks,LazyWriteContext",
57 (!FileSizes ? -1 : (long)FileSizes->AllocationSize.QuadPart),
58 (!FileSizes ? -1 : (long)FileSizes->FileSize.QuadPart),
59 (!FileSizes ? -1 : (long)FileSizes->ValidDataLength.QuadPart),
62 g_return_if_fail(FileObject!=NULL);
63 g_return_if_fail(FileSizes!=NULL);
64 g_return_if_fail(CallBacks!=NULL);
66 /* VERIFIED: CcInitializeCacheMap() has already 'SectionObjectPointers' allocated. */
67 g_return_if_fail(FileObject->SectionObjectPointer!=NULL);
69 SharedCacheMap=captive_shared_cache_map_get_ref(FileObject,FileSizes,PinAccess,CallBacks,LazyWriterContext);
71 captive_shared_cache_map_w32_ref(SharedCacheMap);
72 g_object_unref(SharedCacheMap); /* sink */
74 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"leave: CcInitializeCacheMap");
79 * CcUninitializeCacheMap:
80 * @FileObject: File to close caching for.
81 * %NULL value is forbidden.
82 * @TruncateSize: Current file size if @FileObject was truncated to it in the meantime.
83 * @UninitializeCompleteEvent: Optional event to signal after physical write to disk.
84 * %NULL value is permitted.
86 * Close the cachine facilities from CcInitializeCacheMap().
87 * It is valid to pass @FileObject without being registered by CcInitializeCacheMap().
89 * FIXME; What to do with files with dirty blocks? Currently we fail assertion on them
90 * although I think W32 would drop such buffers (purge them - not flush them).
92 * Returns: %TRUE if the caching was closed successfuly.
93 * %FALSE if @FileObject was not registered by CcInitializeCacheMap()
94 * or if its #SharedCacheMap is still in use (such as by other #FileObject reference of
95 * the same #FCB instance).
97 BOOLEAN CcUninitializeCacheMap(IN PFILE_OBJECT FileObject,
98 IN PLARGE_INTEGER TruncateSize OPTIONAL,IN PCACHE_UNINITIALIZE_EVENT UninitializeCompleteEvent OPTIONAL)
100 CaptiveSharedCacheMapObject *SharedCacheMap;
103 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"enter: CcUninitializeCacheMap: FileObject=0x%lX,TruncateSize=0x%lX,UninitializeCompleteEvent=0x%lX",
104 (long)FileObject,(!TruncateSize ? -1 : (long)TruncateSize->QuadPart),(long)UninitializeCompleteEvent);
106 g_return_val_if_fail(FileObject!=NULL,FALSE);
107 /* assert current size ==*TruncateSize if TruncateSize */
109 if (FileObject->SectionObjectPointer && !FileObject->SectionObjectPointer->SharedCacheMap)
112 SharedCacheMap=captive_FileObject_to_SharedCacheMap(FileObject);
114 /* We may be called without preceding CcInitializeCacheMap(). */
115 if (!captive_shared_cache_map_query_w32_ref(SharedCacheMap))
118 captive_shared_cache_map_w32_unref(SharedCacheMap);
119 r=(FileObject->SectionObjectPointer->SharedCacheMap==NULL);
122 /* FIXME: should we do KePulseEvent? Are we allowed to signal from inside CcUninitializeCacheMap() ? */
123 if (UninitializeCompleteEvent)
125 &UninitializeCompleteEvent->Event, /* Event */
126 IO_NO_INCREMENT, /* Increment */
130 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"leave: CcUninitializeCacheMap: r=%d",r);
138 * @FileObject: Initialized open #FileObject to update file sizes of.
139 * %NULL value is forbidden.
140 * @FileSizes: New file sizes to update cache to.
141 * %NULL value is forbidden.
143 * Update cache properties after file sizes were updated.
144 * Probably only the exceeding pages need to be unmapped and BCBs updated
145 * if FileSizes->AllocationSize gets shrunk.
147 * #AllocationSize must not change if any map or pin Bcbs exist.
149 VOID CcSetFileSizes(IN PFILE_OBJECT FileObject,IN PCC_FILE_SIZES FileSizes)
151 CaptiveSharedCacheMapObject *SharedCacheMap;
153 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"enter: CcSetFileSizes: FileObject=0x%lX,"
154 "FileSizes,->AllocationSize=0x%lX,->FileSize=0x%lX,->ValidDataLength=0x%lX",
156 (!FileSizes ? -1 : (long)FileSizes->AllocationSize.QuadPart),
157 (!FileSizes ? -1 : (long)FileSizes->FileSize.QuadPart),
158 (!FileSizes ? -1 : (long)FileSizes->ValidDataLength.QuadPart));
160 g_return_if_fail(FileObject!=NULL);
161 g_return_if_fail(FileSizes!=NULL);
163 /* Needed by ext2fsd.sys-v0.10a: */
165 && FileObject->SectionObjectPointer
166 && FileObject->SectionObjectPointer->SharedCacheMap) {
167 SharedCacheMap=captive_FileObject_to_SharedCacheMap(FileObject);
168 captive_shared_cache_map_FileSizes_set(SharedCacheMap,FileSizes);
171 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"leave: CcSetFileSizes");