xref: /haiku/headers/os/drivers/fs_cache.h (revision 1fbe3ccd4eb6f5388a2dc4ab2907a49acc24bd88)
1a1978b5cSAxel Dörfler /* File System File and Block Caches
29de65b05SAxel Dörfler  *
3c9955bf0SAxel Dörfler  * Copyright 2004-2005, Haiku Inc. All Rights Reserved.
49de65b05SAxel Dörfler  * Distributed under the terms of the MIT License.
5a1978b5cSAxel Dörfler  */
6a1978b5cSAxel Dörfler #ifndef _FS_CACHE_H
7a1978b5cSAxel Dörfler #define _FS_CACHE_H
8a1978b5cSAxel Dörfler 
9a1978b5cSAxel Dörfler 
10a1978b5cSAxel Dörfler #include <fs_interface.h>
11a1978b5cSAxel Dörfler 
12a1978b5cSAxel Dörfler 
139de65b05SAxel Dörfler typedef void (*transaction_notification_hook)(int32 id, void *data);
14060b0282SAxel Dörfler 
15a1978b5cSAxel Dörfler #ifdef __cplusplus
16a1978b5cSAxel Dörfler extern "C" {
17a1978b5cSAxel Dörfler #endif
18a1978b5cSAxel Dörfler 
19060b0282SAxel Dörfler /* transactions */
2086c3e70cSAxel Dörfler extern int32 cache_start_transaction(void *_cache);
2186c3e70cSAxel Dörfler extern status_t cache_sync_transaction(void *_cache, int32 id);
22*1fbe3ccdSIngo Weinhold extern status_t cache_end_transaction(void *_cache, int32 id,
23*1fbe3ccdSIngo Weinhold 					transaction_notification_hook hook, void *data);
2486c3e70cSAxel Dörfler extern status_t cache_abort_transaction(void *_cache, int32 id);
25*1fbe3ccdSIngo Weinhold extern int32 cache_detach_sub_transaction(void *_cache, int32 id,
26*1fbe3ccdSIngo Weinhold 					transaction_notification_hook hook, void *data);
2786c3e70cSAxel Dörfler extern status_t cache_abort_sub_transaction(void *_cache, int32 id);
2886c3e70cSAxel Dörfler extern status_t cache_start_sub_transaction(void *_cache, int32 id);
29*1fbe3ccdSIngo Weinhold extern status_t cache_next_block_in_transaction(void *_cache, int32 id,
30*1fbe3ccdSIngo Weinhold 					uint32 *_cookie, off_t *_blockNumber, void **_data,
31*1fbe3ccdSIngo Weinhold 					void **_unchangedData);
32ca7c5a9eSAxel Dörfler extern int32 cache_blocks_in_transaction(void *_cache, int32 id);
33ca7c5a9eSAxel Dörfler extern int32 cache_blocks_in_sub_transaction(void *_cache, int32 id);
34060b0282SAxel Dörfler 
35060b0282SAxel Dörfler /* block cache */
36060b0282SAxel Dörfler extern void block_cache_delete(void *_cache, bool allowWrites);
37*1fbe3ccdSIngo Weinhold extern void *block_cache_create(int fd, off_t numBlocks, size_t blockSize,
38*1fbe3ccdSIngo Weinhold 					bool readOnly);
39060b0282SAxel Dörfler extern status_t block_cache_sync(void *_cache);
40060b0282SAxel Dörfler 
41*1fbe3ccdSIngo Weinhold extern status_t block_cache_make_writable(void *_cache, off_t blockNumber,
42*1fbe3ccdSIngo Weinhold 					int32 transaction);
43*1fbe3ccdSIngo Weinhold extern void *block_cache_get_writable_etc(void *_cache, off_t blockNumber,
44*1fbe3ccdSIngo Weinhold 					off_t base, off_t length, int32 transaction);
45*1fbe3ccdSIngo Weinhold extern void *block_cache_get_writable(void *_cache, off_t blockNumber,
46*1fbe3ccdSIngo Weinhold 					int32 transaction);
47*1fbe3ccdSIngo Weinhold extern void *block_cache_get_empty(void *_cache, off_t blockNumber,
48*1fbe3ccdSIngo Weinhold 					int32 transaction);
49*1fbe3ccdSIngo Weinhold extern const void *block_cache_get_etc(void *_cache, off_t blockNumber,
50*1fbe3ccdSIngo Weinhold 					off_t base, off_t length);
51060b0282SAxel Dörfler extern const void *block_cache_get(void *_cache, off_t blockNumber);
52*1fbe3ccdSIngo Weinhold extern status_t block_cache_set_dirty(void *_cache, off_t blockNumber,
53*1fbe3ccdSIngo Weinhold 					bool isDirty, int32 transaction);
54060b0282SAxel Dörfler extern void block_cache_put(void *_cache, off_t blockNumber);
55060b0282SAxel Dörfler 
56a1978b5cSAxel Dörfler /* file cache */
57*1fbe3ccdSIngo Weinhold extern void *file_cache_create(mount_id mountID, vnode_id vnodeID, off_t size,
58*1fbe3ccdSIngo Weinhold 					int fd);
59a1978b5cSAxel Dörfler extern void file_cache_delete(void *_cacheRef);
60a1978b5cSAxel Dörfler extern status_t file_cache_set_size(void *_cacheRef, off_t size);
6186c3e70cSAxel Dörfler extern status_t file_cache_sync(void *_cache);
62*1fbe3ccdSIngo Weinhold extern status_t file_cache_invalidate_file_map(void *_cacheRef, off_t offset,
63*1fbe3ccdSIngo Weinhold 					off_t size);
64a1978b5cSAxel Dörfler 
65a1978b5cSAxel Dörfler extern status_t file_cache_read_pages(void *_cacheRef, off_t offset,
66a1978b5cSAxel Dörfler 					const iovec *vecs, size_t count, size_t *_numBytes);
67a1978b5cSAxel Dörfler extern status_t file_cache_write_pages(void *_cacheRef, off_t offset,
68a1978b5cSAxel Dörfler 					const iovec *vecs, size_t count, size_t *_numBytes);
69*1fbe3ccdSIngo Weinhold extern status_t file_cache_read(void *_cacheRef, off_t offset, void *bufferBase,
70*1fbe3ccdSIngo Weinhold 					size_t *_size);
71*1fbe3ccdSIngo Weinhold extern status_t file_cache_write(void *_cacheRef, off_t offset,
72*1fbe3ccdSIngo Weinhold 					const void *buffer, size_t *_size);
73a1978b5cSAxel Dörfler 
74a1978b5cSAxel Dörfler #ifdef __cplusplus
75a1978b5cSAxel Dörfler }
76a1978b5cSAxel Dörfler #endif
77a1978b5cSAxel Dörfler 
78a1978b5cSAxel Dörfler #endif	/* _FS_CACHE_H */
79