1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  *     Copyright 2010 Couchbase, Inc
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  */
17 
18 #ifndef _JSAHN_BLOCKCACHE_H
19 #define _JSAHN_BLOCKCACHE_H
20 
21 #include "filemgr.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 typedef enum {
28     BCACHE_REQ_CLEAN,
29     BCACHE_REQ_DIRTY
30 } bcache_dirty_t;
31 
32 void bcache_init(int nblock, int blocksize);
33 int bcache_read(struct filemgr *file, bid_t bid, void *buf);
34 void bcache_invalidate_block(struct filemgr *file, bid_t bid);
35 int bcache_write(struct filemgr *file, bid_t bid, void *buf, bcache_dirty_t dirty);
36 int bcache_write_partial(struct filemgr *file, bid_t bid, void *buf, size_t offset, size_t len);
37 void bcache_remove_dirty_blocks(struct filemgr *file);
38 void bcache_remove_clean_blocks(struct filemgr *file);
39 bool bcache_remove_file(struct filemgr *file);
40 fdb_status bcache_flush(struct filemgr *file);
41 void bcache_shutdown();
42 uint64_t bcache_get_num_free_blocks();
43 void bcache_print_items();
44 void bcache_update_file_status(struct filemgr *file, file_status_t status);
45 
46 #ifdef __cplusplus
47 }
48 #endif
49 
50 #endif
51