xref: /haiku/headers/os/drivers/fs_cache.h (revision 4fc4f2c8aeefd8548dc95f51af64beabc07a4ec5)
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 					uint32 *_cookie, off_t *_blockNumber, void **_data,
43 					void **_unchangedData);
44 extern int32 cache_blocks_in_transaction(void *_cache, int32 id);
45 extern int32 cache_blocks_in_sub_transaction(void *_cache, int32 id);
46 
47 /* block cache */
48 extern void block_cache_delete(void *_cache, bool allowWrites);
49 extern void *block_cache_create(int fd, off_t numBlocks, size_t blockSize,
50 					bool readOnly);
51 extern status_t block_cache_sync(void *_cache);
52 extern status_t block_cache_sync_etc(void *_cache, off_t blockNumber,
53 					size_t numBlocks);
54 extern status_t block_cache_make_writable(void *_cache, off_t blockNumber,
55 					int32 transaction);
56 extern void *block_cache_get_writable_etc(void *_cache, off_t blockNumber,
57 					off_t base, off_t length, int32 transaction);
58 extern void *block_cache_get_writable(void *_cache, off_t blockNumber,
59 					int32 transaction);
60 extern void *block_cache_get_empty(void *_cache, off_t blockNumber,
61 					int32 transaction);
62 extern const void *block_cache_get_etc(void *_cache, off_t blockNumber,
63 					off_t base, off_t length);
64 extern const void *block_cache_get(void *_cache, off_t blockNumber);
65 extern status_t block_cache_set_dirty(void *_cache, off_t blockNumber,
66 					bool isDirty, int32 transaction);
67 extern void block_cache_put(void *_cache, off_t blockNumber);
68 
69 /* file cache */
70 extern void *file_cache_create(dev_t mountID, ino_t vnodeID, off_t size);
71 extern void file_cache_delete(void *_cacheRef);
72 extern status_t file_cache_set_size(void *_cacheRef, off_t size);
73 extern status_t file_cache_sync(void *_cache);
74 
75 extern status_t file_cache_read(void *_cacheRef, void *cookie, off_t offset,
76 					void *bufferBase, size_t *_size);
77 extern status_t file_cache_write(void *_cacheRef, void *cookie, off_t offset,
78 					const void *buffer, size_t *_size);
79 
80 /* file map */
81 extern void *file_map_create(dev_t mountID, ino_t vnodeID, off_t size);
82 extern void file_map_delete(void *_map);
83 extern void file_map_set_size(void *_map, off_t size);
84 extern void file_map_invalidate(void *_map, off_t offset, off_t size);
85 extern status_t file_map_translate(void *_map, off_t offset, size_t size,
86 					struct file_io_vec *vecs, size_t *_count);
87 
88 #ifdef __cplusplus
89 }
90 #endif
91 
92 #endif	/* _FS_CACHE_H */
93