xref: /haiku/headers/os/drivers/fs_cache.h (revision cfc3fa87da824bdf593eb8b817a83b6376e77935)
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 /* transaction events */
15 enum {
16 	TRANSACTION_WRITTEN	= 0x01,
17 	TRANSACTION_ABORTED	= 0x02,
18 	TRANSACTION_ENDED	= 0x04,
19 	TRANSACTION_IDLE	= 0x08
20 };
21 
22 typedef void (*transaction_notification_hook)(int32 id, int32 event,
23 	void *data);
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /* transactions */
30 extern int32 cache_start_transaction(void *_cache);
31 extern status_t cache_sync_transaction(void *_cache, int32 id);
32 extern status_t cache_end_transaction(void *_cache, int32 id,
33 					transaction_notification_hook hook, void *data);
34 extern status_t cache_abort_transaction(void *_cache, int32 id);
35 extern int32 cache_detach_sub_transaction(void *_cache, int32 id,
36 					transaction_notification_hook hook, void *data);
37 extern status_t cache_abort_sub_transaction(void *_cache, int32 id);
38 extern status_t cache_start_sub_transaction(void *_cache, int32 id);
39 extern status_t cache_add_transaction_listener(void *_cache, int32 id,
40 					int32 events, transaction_notification_hook hook,
41 					void *data);
42 extern status_t cache_remove_transaction_listener(void *_cache, int32 id,
43 					transaction_notification_hook hook, void *data);
44 extern status_t cache_next_block_in_transaction(void *_cache, int32 id,
45 					bool mainOnly, long *_cookie, off_t *_blockNumber,
46 					void **_data, void **_unchangedData);
47 extern int32 cache_blocks_in_transaction(void *_cache, int32 id);
48 extern int32 cache_blocks_in_main_transaction(void *_cache, int32 id);
49 extern int32 cache_blocks_in_sub_transaction(void *_cache, int32 id);
50 
51 /* block cache */
52 extern void block_cache_delete(void *_cache, bool allowWrites);
53 extern void *block_cache_create(int fd, off_t numBlocks, size_t blockSize,
54 					bool readOnly);
55 extern status_t block_cache_sync(void *_cache);
56 extern status_t block_cache_sync_etc(void *_cache, off_t blockNumber,
57 					size_t numBlocks);
58 extern status_t block_cache_make_writable(void *_cache, off_t blockNumber,
59 					int32 transaction);
60 extern void *block_cache_get_writable_etc(void *_cache, off_t blockNumber,
61 					off_t base, off_t length, int32 transaction);
62 extern void *block_cache_get_writable(void *_cache, off_t blockNumber,
63 					int32 transaction);
64 extern void *block_cache_get_empty(void *_cache, off_t blockNumber,
65 					int32 transaction);
66 extern const void *block_cache_get_etc(void *_cache, off_t blockNumber,
67 					off_t base, off_t length);
68 extern const void *block_cache_get(void *_cache, off_t blockNumber);
69 extern status_t block_cache_set_dirty(void *_cache, off_t blockNumber,
70 					bool isDirty, int32 transaction);
71 extern void block_cache_put(void *_cache, off_t blockNumber);
72 
73 /* file cache */
74 extern void *file_cache_create(dev_t mountID, ino_t vnodeID, off_t size);
75 extern void file_cache_delete(void *_cacheRef);
76 extern status_t file_cache_set_size(void *_cacheRef, off_t size);
77 extern status_t file_cache_sync(void *_cache);
78 
79 extern status_t file_cache_read(void *_cacheRef, void *cookie, off_t offset,
80 					void *bufferBase, size_t *_size);
81 extern status_t file_cache_write(void *_cacheRef, void *cookie, off_t offset,
82 					const void *buffer, size_t *_size);
83 
84 /* file map */
85 extern void *file_map_create(dev_t mountID, ino_t vnodeID, off_t size);
86 extern void file_map_delete(void *_map);
87 extern void file_map_set_size(void *_map, off_t size);
88 extern void file_map_invalidate(void *_map, off_t offset, off_t size);
89 extern status_t file_map_translate(void *_map, off_t offset, size_t size,
90 					struct file_io_vec *vecs, size_t *_count);
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 
96 #endif	/* _FS_CACHE_H */
97