Initial original import from: fuse-2.4.2-2.fc4
[captive.git] / src / libcaptive / cc / misc.c
1 /* $Id$
2  * reactos Cache Manager (Cc*) misc of libcaptive
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
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
8  * 
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.
13  * 
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
17  */
18
19
20 #include "config.h"
21
22 #include <glib/gmessages.h>
23 #include "reactos/ddk/status.h"
24 #include "reactos/ddk/iotypes.h"
25 #include "sharedcachemap.h"
26
27
28 /**
29  * CcCanIWrite:
30  * @FileObject: Initialized open #FileObject to map.
31  * %NULL value is forbidden.
32  * @BytesToWrite: Amount of data to be asked whether it will be accepted.
33  * Value %0 is permitted.
34  * @Wait: Whether disk waiting would be permitted during the forthcoming write call.
35  * @Retrying: Use %TRUE iff calling this function for the second and further times for one request.
36  *
37  * Asks cache manager if it would currently accept write request to @FileObject
38  * of @BytesToWrite bytes with @Wait condition.
39  * libcaptive will always accept any writes. This function is a NOP.
40  *
41  * Returns: libcaptive always returns %TRUE.
42  */
43 BOOLEAN CcCanIWrite(IN PFILE_OBJECT FileObject,IN ULONG BytesToWrite,IN BOOLEAN Wait,IN BOOLEAN Retrying)
44 {
45 BOOLEAN r;
46
47         g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"enter: CcCanIWrite: FileObject=0x%lX,BytesToWrite=0x%lX,Wait=%d,Retrying=%d",
48                         (long)FileObject,BytesToWrite,Wait,Retrying);
49
50         g_return_val_if_fail(FileObject!=NULL,FALSE);
51         g_return_val_if_fail(Wait==TRUE || Wait==FALSE,FALSE);  /* Prevent 'Wait' upgrade to 'Flags'. */
52         g_return_val_if_fail(Retrying==TRUE || Retrying==FALSE,FALSE);
53
54         /* sanity check */
55         g_assert(FileObject->SectionObjectPointer!=NULL);
56         /* 'FileObject->SectionObjectPointer->SharedCacheMap' may be NULL */
57
58         r=TRUE;
59
60         g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"leave: CcCanIWrite: r=%d",r);
61
62         return r;
63 }
64
65
66 /**
67  * CcSetReadAheadGranularity:
68  * @FileObject: Initialized open #FileObject to map.
69  * %NULL value is forbidden.
70  * @Granularity: Suggested size of the cache element.
71  * Value must be larger or requal to %PAGE_SIZE and it must be even power of two.
72  *
73  * libcaptive does not implement any caching and therefore this function
74  * is a NOP there.
75  */
76 VOID CcSetReadAheadGranularity(IN PFILE_OBJECT FileObject,IN ULONG Granularity)
77 {
78         g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"enter: CcSetReadAheadGranularity: FileObject=0x%lX,Granularity=0x%lX",
79                         (long)FileObject,Granularity);
80
81         g_return_if_fail(FileObject!=NULL);
82         g_return_if_fail(Granularity>=PAGE_SIZE);
83         g_return_if_fail((Granularity&(Granularity-1))==0);     /* Power of two */
84
85         /* NOP; no caching by libcaptive */
86
87         /* sanity check */
88         captive_FileObject_to_SharedCacheMap(FileObject);
89
90         g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"leave: CcSetReadAheadGranularity");
91 }
92
93
94 /**
95  * CcSetAdditionalCacheAttributes:
96  * @FileObject: Initialized open #FileObject to map.
97  * %NULL value is forbidden.
98  * @DisableReadAhead: Read-ahead should not be done by Cache Manager.
99  * @DisableWriteBehind: Write-behind should not be done by Cache Manager.
100  *
101  * libcaptive does not implement any caching and therefore this function
102  * is a NOP there.
103  */
104 VOID CcSetAdditionalCacheAttributes(IN PFILE_OBJECT FileObject,IN BOOLEAN DisableReadAhead,IN BOOLEAN DisableWriteBehind)
105 {
106         g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"enter: CcSetAdditionalCacheAttributes: FileObject=0x%lX,DisableReadAhead=%d,DisableWriteBehind=%d",
107                         (long)FileObject,DisableReadAhead,DisableWriteBehind);
108
109         g_return_if_fail(FileObject!=NULL);
110
111         /* NOP; no caching by libcaptive */
112
113         g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"leave: CcSetAdditionalCacheAttributes");
114 }
115
116
117 VOID FsRtlIncrementCcFastReadNoWait(VOID)
118 {
119         /* FIXME: {{%fs:[0]}+0x4E0}:LONG++ */
120 }
121
122
123 NTSTATUS CcWaitForCurrentLazyWriterActivity(VOID)
124 {
125 NTSTATUS r;
126
127         g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"enter: CcWaitForCurrentLazyWriterActivity");
128
129         r=STATUS_SUCCESS;
130
131         g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"leave: CcWaitForCurrentLazyWriterActivity: r=0x%lX",(long)r);
132
133         return r;
134 }