Rewritten Cache Manager to better match its W32 original behaviour
[captive.git] / src / libcaptive / cc / misc.c
diff --git a/src/libcaptive/cc/misc.c b/src/libcaptive/cc/misc.c
new file mode 100644 (file)
index 0000000..ad90a51
--- /dev/null
@@ -0,0 +1,115 @@
+/* $Id$
+ * reactos Cache Manager (Cc*) misc of libcaptive
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#include "config.h"
+
+#include <glib/gmessages.h>
+#include "reactos/ddk/status.h"
+#include "reactos/ddk/iotypes.h"
+#include "sharedcachemap.h"
+
+
+/**
+ * CcCanIWrite:
+ * @FileObject: Initialized open #FileObject to map.
+ * %NULL value is forbidden.
+ * @BytesToWrite: Amount of data to be asked whether it will be accepted.
+ * Value %0 is permitted.
+ * @Wait: Whether disk waiting would be permitted during the forthcoming write call.
+ * @Retrying: Use %TRUE iff calling this function for the second and further times for one request.
+ *
+ * Asks cache manager if it would currently accept write request to @FileObject
+ * of @BytesToWrite bytes with @Wait condition.
+ * libcaptive will always accept any writes. This function is a NOP.
+ *
+ * Returns: libcaptive always returns %TRUE.
+ */
+BOOLEAN CcCanIWrite(IN PFILE_OBJECT FileObject,IN ULONG BytesToWrite,IN BOOLEAN Wait,IN BOOLEAN Retrying)
+{
+       g_return_val_if_fail(FileObject!=NULL,FALSE);
+       g_return_val_if_fail(Wait==TRUE || Wait==FALSE,FALSE);  /* Prevent 'Wait' upgrade to 'Flags'. */
+       g_return_val_if_fail(Retrying==TRUE || Retrying==FALSE,FALSE);
+
+       g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"%s: FileObject=%p,BytesToWrite=0x%lX,Wait=%d,Retrying=%d",G_STRLOC,
+                       FileObject,(gulong)BytesToWrite,(gint)Wait,(gint)Retrying);
+
+       /* sanity check */
+       captive_FileObject_to_SharedCacheMap(FileObject);
+
+       return TRUE;
+}
+
+
+/**
+ * CcSetReadAheadGranularity:
+ * @FileObject: Initialized open #FileObject to map.
+ * %NULL value is forbidden.
+ * @Granularity: Suggested size of the cache element.
+ * Value must be larger or requal to %PAGE_SIZE and it must be even power of two.
+ *
+ * libcaptive does not implement any caching and therefore this function
+ * is a NOP there.
+ */
+VOID CcSetReadAheadGranularity(IN PFILE_OBJECT FileObject,IN ULONG Granularity)
+{
+       g_return_if_fail(FileObject!=NULL);
+       g_return_if_fail(Granularity>=PAGE_SIZE);
+       g_return_if_fail((Granularity&(Granularity-1))==0);     /* Power of two */
+
+       g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"%s: FileObject=%p,Granularity=0x%lX",G_STRLOC,
+                       FileObject,(gulong)Granularity);
+
+       /* NOP; no caching by libcaptive */
+
+       /* sanity check */
+       captive_FileObject_to_SharedCacheMap(FileObject);
+}
+
+
+/**
+ * CcSetAdditionalCacheAttributes:
+ * @FileObject: Initialized open #FileObject to map.
+ * %NULL value is forbidden.
+ * @DisableReadAhead: Read-ahead should not be done by Cache Manager.
+ * @DisableWriteBehind: Write-behind should not be done by Cache Manager.
+ *
+ * libcaptive does not implement any caching and therefore this function
+ * is a NOP there.
+ */
+VOID CcSetAdditionalCacheAttributes(IN PFILE_OBJECT FileObject,IN BOOLEAN DisableReadAhead,IN BOOLEAN DisableWriteBehind)
+{
+       g_return_if_fail(FileObject!=NULL);
+
+       g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"%s: FileObject=%p,DisableReadAhead=%s,DisableWriteBehind=%s",G_STRLOC,
+                       FileObject,(DisableReadAhead ? "TRUE" : "FALSE"),(DisableWriteBehind ? "TRUE" : "FALSE"));
+
+       /* NOP; no caching by libcaptive */
+}
+
+
+VOID FsRtlIncrementCcFastReadNoWait(VOID)
+{
+       /* FIXME: {{%fs:[0]}+0x4E0}:LONG++ */
+}
+
+
+NTSTATUS CcWaitForCurrentLazyWriterActivity(VOID)
+{
+       return STATUS_SUCCESS;
+}