[BTRFS]
[reactos.git] / reactos / drivers / filesystems / btrfs / cache.c
1 /* Copyright (c) Mark Harmstone 2016
2 *
3 * This file is part of WinBtrfs.
4 *
5 * WinBtrfs is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public Licence as published by
7 * the Free Software Foundation, either version 3 of the Licence, or
8 * (at your option) any later version.
9 *
10 * WinBtrfs is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public Licence for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public Licence
16 * along with WinBtrfs. If not, see <http://www.gnu.org/licenses/>. */
17
18 #include "btrfs_drv.h"
19 #include <wdm.h>
20
21 CACHE_MANAGER_CALLBACKS* cache_callbacks;
22
23 static BOOLEAN STDCALL acquire_for_lazy_write(PVOID Context, BOOLEAN Wait) {
24 PFILE_OBJECT FileObject = Context;
25 fcb* fcb = FileObject->FsContext;
26
27 TRACE("(%p, %u)\n", Context, Wait);
28
29 if (!fcb || FileObject->Flags & FO_CLEANUP_COMPLETE)
30 return FALSE;
31
32 fcb->lazy_writer_thread = KeGetCurrentThread();
33
34 return TRUE;
35 }
36
37 static void STDCALL release_from_lazy_write(PVOID Context) {
38 PFILE_OBJECT FileObject = Context;
39 fcb* fcb = FileObject->FsContext;
40
41 TRACE("(%p)\n", Context);
42
43 if (!fcb || FileObject->Flags & FO_CLEANUP_COMPLETE)
44 return;
45
46 fcb->lazy_writer_thread = NULL;
47 }
48
49 static BOOLEAN STDCALL acquire_for_read_ahead(PVOID Context, BOOLEAN Wait) {
50 TRACE("(%p, %u)\n", Context, Wait);
51
52 return TRUE;
53 }
54
55 static void STDCALL release_from_read_ahead(PVOID Context) {
56 TRACE("(%p)\n", Context);
57 }
58
59 NTSTATUS STDCALL init_cache() {
60 cache_callbacks = ExAllocatePoolWithTag(NonPagedPool, sizeof(CACHE_MANAGER_CALLBACKS), ALLOC_TAG);
61 if (!cache_callbacks) {
62 ERR("out of memory\n");
63 return STATUS_INSUFFICIENT_RESOURCES;
64 }
65
66 cache_callbacks->AcquireForLazyWrite = acquire_for_lazy_write;
67 cache_callbacks->ReleaseFromLazyWrite = release_from_lazy_write;
68 cache_callbacks->AcquireForReadAhead = acquire_for_read_ahead;
69 cache_callbacks->ReleaseFromReadAhead = release_from_read_ahead;
70
71 return STATUS_SUCCESS;
72 }
73
74 void STDCALL free_cache() {
75 ExFreePool(cache_callbacks);
76 }