1 /* Copyright (c) Mark Harmstone 2016
3 * This file is part of WinBtrfs.
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.
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.
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/>. */
18 #include "btrfs_drv.h"
21 CACHE_MANAGER_CALLBACKS
* cache_callbacks
;
23 static BOOLEAN STDCALL
acquire_for_lazy_write(PVOID Context
, BOOLEAN Wait
) {
24 PFILE_OBJECT FileObject
= Context
;
25 fcb
* fcb
= FileObject
->FsContext
;
27 TRACE("(%p, %u)\n", Context
, Wait
);
29 if (!fcb
|| FileObject
->Flags
& FO_CLEANUP_COMPLETE
)
32 fcb
->lazy_writer_thread
= KeGetCurrentThread();
37 static void STDCALL
release_from_lazy_write(PVOID Context
) {
38 PFILE_OBJECT FileObject
= Context
;
39 fcb
* fcb
= FileObject
->FsContext
;
41 TRACE("(%p)\n", Context
);
43 if (!fcb
|| FileObject
->Flags
& FO_CLEANUP_COMPLETE
)
46 fcb
->lazy_writer_thread
= NULL
;
49 static BOOLEAN STDCALL
acquire_for_read_ahead(PVOID Context
, BOOLEAN Wait
) {
50 TRACE("(%p, %u)\n", Context
, Wait
);
55 static void STDCALL
release_from_read_ahead(PVOID Context
) {
56 TRACE("(%p)\n", Context
);
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
;
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
;
71 return STATUS_SUCCESS
;
74 void STDCALL
free_cache() {
75 ExFreePool(cache_callbacks
);