Initial original import from: fuse-2.4.2-2.fc4
[captive.git] / src / libcaptive / cc / dirtypages.c
1 /* $Id$
2  * reactos Cache Manager (Cc*) cache handling 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 "privatebcbpin.h"
23
24
25 /**
26  * CcGetDirtyPages:
27  * @LogHandle: Arbitrary pointer to match with value passed to CcSetLogHandleForFile().
28  * %NULL value is permitted (considered as regular matching value by libcaptive).
29  * @DirtyPageRoutine: #PDIRTY_PAGE_ROUTINE type to call on each dirty page(s).
30  * %NULL value is forbidden.
31  * @Context1: User data to pass to @DirtyPageRoutine.
32  * %NULL value is permitted.
33  * @Context2: User data to pass to @DirtyPageRoutine.
34  *
35  * Searches through the list of dirty #PUBLIC_BCB s of files assigned to @LogHandle
36  * by CcSetLogHandleForFile(). Any clean #PUBLIC_BCB s are ignored
37  * by this function. Function will scan through all #PUBLIC_BCB mapping of each such page
38  * and it will detect its oldest and newest LSN (Logical Sequence Number). Unset
39  * LSN is considered as value 0. Value 0 is returned only if no other LSN is valid
40  * for such case, otherwise such void value 0 is ignored (and oldest and newest LSN
41  * returned are being equal in the case only single LSN was found).
42  *
43  * Found pages are coalesced as much as possible during calls of @DirtyPageRoutine.
44  * Coalescable ranges must have the same detected both oldest and newest LSNs.
45  *
46  * Returns: Oldest LSN across all the #FileObject s found for the given @LogHandle.
47  * Function returns value %0 if no appropriate LSN was found.
48  * libcaptive must return #gint64 instead of the official #LARGE_INTEGER
49  * as W32 expects it as value in EAX:EDX but GCC returns the structure address in EAX.
50  *
51  * VERIFIED: func called in runs for each FileObject, FileOffset sorted desc.
52  */
53 gint64 /* instead of LARGE_INTEGER */ CcGetDirtyPages(IN PVOID LogHandle,
54                 IN PDIRTY_PAGE_ROUTINE DirtyPageRoutine,IN PVOID Context1,IN PVOID Context2)
55 {
56 gint64 r;
57
58         g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"enter: CcGetDirtyPages: LogHandle=0x%lX,DirtyPageRoutine=0x%lX,Context1=0x%lX,Context2=0x%lX",
59                         (long)LogHandle,(long)DirtyPageRoutine,(long)Context1,(long)Context2);
60
61         /* 'LogHandle' may be NULL */
62         g_return_val_if_fail(DirtyPageRoutine!=NULL,0);
63
64         /* W32 undocumented: What does mean LogHandle==NULL?
65          * It is expected to clear the 'LogHandle' settings.
66          * Otherwise it would cause multiple active 'LogHandle's for some NT4 NTFS drives
67          * as reported by Nerijus Baliunas in: <20040106005157.7E5C060BE@mx.ktv.lt>
68          */
69
70         captive_shared_cache_map_set_LogHandle(NULL,LogHandle);
71
72         r=captive_shared_cache_map_CcGetDirtyPages(DirtyPageRoutine,Context1,Context2);
73
74         g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"leave: CcGetDirtyPages: r=0x%lX",(long)r);
75
76         return r;
77 }