xref: /haiku/headers/os/drivers/fs_cache.h (revision e6b30aee0fd7a23d6a6baab9f3718945a0cd838a)
1 /*
2  * Copyright 2004-2008, Haiku Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _FS_CACHE_H
6 #define _FS_CACHE_H
7 
8 /*! File System File and Block Caches */
9 
10 
11 #include <fs_interface.h>
12 
13 
14 enum {
15 	TRANSACTION_WRITTEN,
16 	TRANSACTION_ABORTED,
17 	TRANSACTION_ENDED
18 };
19 
20 typedef void (*transaction_notification_hook)(int32 id, int32 event,
21 	void *data);
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* transactions */
28 extern int32 cache_start_transaction(void *_cache);
29 extern status_t cache_sync_transaction(void *_cache, int32 id);
30 extern status_t cache_end_transaction(void *_cache, int32 id,
31 					transaction_notification_hook hook, void *data);
32 extern status_t cache_abort_transaction(void *_cache, int32 id);
33 extern int32 cache_detach_sub_transaction(void *_cache, int32 id,
34 					transaction_notification_hook hook, void *data);
35 extern status_t cache_abort_sub_transaction(void *_cache, int32 id);
36 extern status_t cache_start_sub_transaction(void *_cache, int32 id);
37 extern status_t cache_add_transaction_listener(void *_cache, int32 id,
38 					transaction_notification_hook hook, void *data);
39 extern status_t cache_remove_transaction_listener(void *_cache, int32 id,
40 					transaction_notification_hook hook, void *data);
41 extern status_t cache_next_block_in_transaction(void *_cache, int32 id,
42 					bool mainOnly, long *_cookie, off_t *_blockNumber,
43 					void **_data, void **_unchangedData);
44 extern int32 cache_blocks_in_transaction(void *_cache, int32 id);
45 extern int32 cache_blocks_in_main_transaction(void *_cache, int32 id);
46 extern int32 cache_blocks_in_sub_transaction(void *_cache, int32 id);
47 
48 /* block cache */
49 extern void block_cache_delete(void *_cache, bool allowWrites);
50 extern void *block_cache_create(int fd, off_t numBlocks, size_t blockSize,
51 					bool readOnly);
52 extern status_t block_cache_sync(void *_cache);
53 extern status_t block_cache_sync_etc(void *_cache, off_t blockNumber,
54 					size_t numBlocks);
55 extern status_t block_cache_make_writable(void *_cache, off_t blockNumber,
56 					int32 transaction);
57 extern void *block_cache_get_writable_etc(void *_cache, off_t blockNumber,
58 					off_t base, off_t length, int32 transaction);
59 extern void *block_cache_get_writable(void *_cache, off_t blockNumber,
60 					int32 transaction);
61 extern void *block_cache_get_empty(void *_cache, off_t blockNumber,
62 					int32 transaction);
63 extern const void *block_cache_get_etc(void *_cache, off_t blockNumber,
64 					off_t base, off_t length);
65 extern const void *block_cache_get(void *_cache, off_t blockNumber);
66 extern status_t block_cache_set_dirty(void *_cache, off_t blockNumber,
67 					bool isDirty, int32 transaction);
68 extern void block_cache_put(void *_cache, off_t blockNumber);
69 
70 /* file cache */
71 extern void *file_cache_create(dev_t mountID, ino_t vnodeID, off_t size);
72 extern void file_cache_delete(void *_cacheRef);
73 extern status_t file_cache_set_size(void *_cacheRef, off_t size);
74 extern status_t file_cache_sync(void *_cache);
75 
76 extern status_t file_cache_read(void *_cacheRef, void *cookie, off_t offset,
77 					void *bufferBase, size_t *_size);
78 extern status_t file_cache_write(void *_cacheRef, void *cookie, off_t offset,
79 					const void *buffer, size_t *_size);
80 
81 /* file map */
82 extern void *file_map_create(dev_t mountID, ino_t vnodeID, off_t size);
83 extern void file_map_delete(void *_map);
84 extern void file_map_set_size(void *_map, off_t size);
85 extern void file_map_invalidate(void *_map, off_t offset, off_t size);
86 extern status_t file_map_translate(void *_map, off_t offset, size_t size,
87 					struct file_io_vec *vecs, size_t *_count);
88 
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 #endif	/* _FS_CACHE_H */
94