Initial original import from: fuse-2.4.2-2.fc4
[captive.git] / src / libcaptive / cc / bcbrepin.c
1 /* $Id$
2  * reactos Cache Manager (Cc*) map/pin Bcb CcRepin*() 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 "privatebcb.h"
23 #include "reactos/ddk/status.h"
24 #include "privatebcbpin.h"
25
26
27 /**
28  * CcRepinBcb:
29  * @Bcb: #PUBLIB_BCB to be repinned.
30  * %NULL value is forbidden.
31  *
32  * Increases usecount on @Bcb. You must call CcUnpinRepinnedBcb() for such @Bcb
33  * afterwards before returning from the #IRP handling.
34  *
35  * libcaptive does not differentiate between CcUnpinData() and CcUnpinRepinnedBcb().
36  * W32 differentiates.
37  *
38  * This call does not set the buffer as dirty - such buffer will not be flushed automatically.
39  *
40  */
41 VOID CcRepinBcb(IN PVOID Bcb)
42 {
43 CaptivePrivateBcbObject *captive_private_bcb_object;
44
45         g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"enter: CcRepinBcb: Bcb=0x%lX",(long)Bcb);
46
47         g_return_if_fail(Bcb!=NULL);
48
49         captive_private_bcb_object=captive_PublicBcb_to_PrivateBcbObject(Bcb);
50
51         g_object_ref(captive_private_bcb_object);
52
53         g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"leave: CcRepinBcb");
54 }
55
56
57 /**
58  * CcUnpinRepinnedBcb:
59  * @Bcb: #PUBLIB_BCB to be unpinned from CcRepinBcb().
60  * %NULL value is forbidden.
61  * @WriteThrough: %TRUE if the buffer should be flushed before finishing this function.
62  * @IoStatus: #PIO_STATUS_BLOCK to return status of this operation.
63  * %NULL value is forbidden. libcaptive always returns %STATUS_SUCCESS here.
64  *
65  * Dereferencing of @Bcb after application of CcRepinBcb().
66  *
67  * This call does not set the buffer as dirty although it will flush the buffers
68  * already set as dirty. Any flushes will be postponed after return from #IRP
69  * handling by the filesystem driver if not requested to be synchronous by @WriteThrough.
70  */
71 VOID CcUnpinRepinnedBcb(IN PVOID Bcb,IN BOOLEAN WriteThrough,IN PIO_STATUS_BLOCK IoStatus)
72 {
73 CaptivePrivateBcbObject *captive_private_bcb_object;
74
75         g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"enter: CcUnpinRepinnedBcb: Bcb=0x%lX,WriteThrough=%d",
76                         (long)Bcb,WriteThrough);
77
78         g_return_if_fail(Bcb!=NULL);
79         g_return_if_fail(IoStatus!=NULL);
80
81         captive_private_bcb_object=captive_PublicBcb_to_PrivateBcbObject(Bcb);
82
83         IoStatus->Status=STATUS_SUCCESS;
84         IoStatus->Information=0;
85
86         if (WriteThrough) {     /* FIXME: WriteThrough even if we do not do the last unref? */
87 CaptivePrivateBcbPinObject *captive_private_bcb_pin_object;
88
89                 captive_private_bcb_pin_object=CAPTIVE_PRIVATE_BCB_PIN_OBJECT(captive_private_bcb_object);
90                 if (captive_private_bcb_pin_object_is_dirty(captive_private_bcb_pin_object)) {
91                         captive_private_bcb_pin_object_flush(captive_private_bcb_pin_object);
92                         IoStatus->Information=PAGE_SIZE;
93                         }
94                 }
95
96         g_object_unref(captive_private_bcb_object);
97
98         g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"leave: CcUnpinRepinnedBcb: IoStatus->Status=0x%lX,IoStatus->Information=0x%lX",
99                         (!IoStatus ? -1 : (long)IoStatus->Status),(!IoStatus ? -1 : (long)IoStatus->Information));
100 }