xref: /haiku/headers/os/drivers/fs_cache.h (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
1 /* File System File and Block Caches
2  *
3  * Copyright 2004-2005, Haiku Inc. All Rights Reserved.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef _FS_CACHE_H
7 #define _FS_CACHE_H
8 
9 
10 #include <fs_interface.h>
11 
12 
13 typedef void (*transaction_notification_hook)(int32 id, void *data);
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 /* transactions */
20 extern int32 cache_start_transaction(void *_cache);
21 extern status_t cache_sync_transaction(void *_cache, int32 id);
22 extern status_t cache_end_transaction(void *_cache, int32 id,
23 					transaction_notification_hook hook, void *data);
24 extern status_t cache_abort_transaction(void *_cache, int32 id);
25 extern int32 cache_detach_sub_transaction(void *_cache, int32 id,
26 					transaction_notification_hook hook, void *data);
27 extern status_t cache_abort_sub_transaction(void *_cache, int32 id);
28 extern status_t cache_start_sub_transaction(void *_cache, int32 id);
29 extern status_t cache_next_block_in_transaction(void *_cache, int32 id,
30 					uint32 *_cookie, off_t *_blockNumber, void **_data,
31 					void **_unchangedData);
32 extern int32 cache_blocks_in_transaction(void *_cache, int32 id);
33 extern int32 cache_blocks_in_sub_transaction(void *_cache, int32 id);
34 
35 /* block cache */
36 extern void block_cache_delete(void *_cache, bool allowWrites);
37 extern void *block_cache_create(int fd, off_t numBlocks, size_t blockSize,
38 					bool readOnly);
39 extern status_t block_cache_sync(void *_cache);
40 
41 extern status_t block_cache_make_writable(void *_cache, off_t blockNumber,
42 					int32 transaction);
43 extern void *block_cache_get_writable_etc(void *_cache, off_t blockNumber,
44 					off_t base, off_t length, int32 transaction);
45 extern void *block_cache_get_writable(void *_cache, off_t blockNumber,
46 					int32 transaction);
47 extern void *block_cache_get_empty(void *_cache, off_t blockNumber,
48 					int32 transaction);
49 extern const void *block_cache_get_etc(void *_cache, off_t blockNumber,
50 					off_t base, off_t length);
51 extern const void *block_cache_get(void *_cache, off_t blockNumber);
52 extern status_t block_cache_set_dirty(void *_cache, off_t blockNumber,
53 					bool isDirty, int32 transaction);
54 extern void block_cache_put(void *_cache, off_t blockNumber);
55 
56 /* file cache */
57 extern void *file_cache_create(mount_id mountID, vnode_id vnodeID, off_t size,
58 					int fd);
59 extern void file_cache_delete(void *_cacheRef);
60 extern status_t file_cache_set_size(void *_cacheRef, off_t size);
61 extern status_t file_cache_sync(void *_cache);
62 extern status_t file_cache_invalidate_file_map(void *_cacheRef, off_t offset,
63 					off_t size);
64 
65 extern status_t file_cache_read_pages(void *_cacheRef, off_t offset,
66 					const iovec *vecs, size_t count, size_t *_numBytes);
67 extern status_t file_cache_write_pages(void *_cacheRef, off_t offset,
68 					const iovec *vecs, size_t count, size_t *_numBytes);
69 extern status_t file_cache_read(void *_cacheRef, off_t offset, void *bufferBase,
70 					size_t *_size);
71 extern status_t file_cache_write(void *_cacheRef, off_t offset,
72 					const void *buffer, size_t *_size);
73 
74 #ifdef __cplusplus
75 }
76 #endif
77 
78 #endif	/* _FS_CACHE_H */
79