xref: /haiku/headers/os/drivers/fs_cache.h (revision 079c69cbfd7cd3c97baae91332251c8388a8bb02)
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 					int fd);
61 extern void file_cache_delete(void *_cacheRef);
62 extern status_t file_cache_set_size(void *_cacheRef, off_t size);
63 extern status_t file_cache_sync(void *_cache);
64 extern status_t file_cache_invalidate_file_map(void *_cacheRef, off_t offset,
65 					off_t size);
66 
67 extern status_t file_cache_read_pages(void *_cacheRef, off_t offset,
68 					const iovec *vecs, size_t count, size_t *_numBytes);
69 extern status_t file_cache_write_pages(void *_cacheRef, off_t offset,
70 					const iovec *vecs, size_t count, size_t *_numBytes);
71 extern status_t file_cache_read(void *_cacheRef, off_t offset, void *bufferBase,
72 					size_t *_size);
73 extern status_t file_cache_write(void *_cacheRef, off_t offset,
74 					const void *buffer, size_t *_size);
75 
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 #endif	/* _FS_CACHE_H */
81