xref: /haiku/headers/os/drivers/fs_cache.h (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
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, transaction_notification_hook hook, void *data);
23 extern status_t cache_abort_transaction(void *_cache, int32 id);
24 extern int32 cache_detach_sub_transaction(void *_cache, int32 id, transaction_notification_hook hook, void *data);
25 extern status_t cache_abort_sub_transaction(void *_cache, int32 id);
26 extern status_t cache_start_sub_transaction(void *_cache, int32 id);
27 extern status_t cache_next_block_in_transaction(void *_cache, int32 id, uint32 *_cookie,
28 					off_t *_blockNumber, void **_data, void **_unchangedData);
29 extern int32 cache_blocks_in_transaction(void *_cache, int32 id);
30 extern int32 cache_blocks_in_sub_transaction(void *_cache, int32 id);
31 
32 /* block cache */
33 extern void block_cache_delete(void *_cache, bool allowWrites);
34 extern void *block_cache_create(int fd, off_t numBlocks, size_t blockSize);
35 extern status_t block_cache_sync(void *_cache);
36 
37 extern status_t block_cache_make_writable(void *_cache, off_t blockNumber, int32 transaction);
38 extern void *block_cache_get_writable_etc(void *_cache, off_t blockNumber, off_t base,
39 					off_t length, int32 transaction);
40 extern void *block_cache_get_writable(void *_cache, off_t blockNumber, int32 transaction);
41 extern void *block_cache_get_empty(void *_cache, off_t blockNumber, int32 transaction);
42 extern const void *block_cache_get_etc(void *_cache, off_t blockNumber, off_t base, off_t length);
43 extern const void *block_cache_get(void *_cache, off_t blockNumber);
44 extern status_t block_cache_set_dirty(void *_cache, off_t blockNumber, bool isDirty, int32 transaction);
45 extern void block_cache_put(void *_cache, off_t blockNumber);
46 
47 /* file cache */
48 extern void *file_cache_create(mount_id mountID, vnode_id vnodeID, off_t size, int fd);
49 extern void file_cache_delete(void *_cacheRef);
50 extern status_t file_cache_set_size(void *_cacheRef, off_t size);
51 extern status_t file_cache_sync(void *_cache);
52 extern status_t file_cache_invalidate_file_map(void *_cacheRef, off_t offset, off_t size);
53 
54 extern status_t file_cache_read_pages(void *_cacheRef, off_t offset,
55 					const iovec *vecs, size_t count, size_t *_numBytes);
56 extern status_t file_cache_write_pages(void *_cacheRef, off_t offset,
57 					const iovec *vecs, size_t count, size_t *_numBytes);
58 extern status_t file_cache_read(void *_cacheRef, off_t offset, void *bufferBase, size_t *_size);
59 extern status_t file_cache_write(void *_cacheRef, off_t offset, const void *buffer, size_t *_size);
60 
61 #ifdef __cplusplus
62 }
63 #endif
64 
65 #endif	/* _FS_CACHE_H */
66