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