xref: /haiku/headers/os/drivers/fs_cache.h (revision 3c1a3047a49f116cf5ce5696a44a635a85dc9f15)
15c03270bSAxel Dörfler /*
24fc4f2c8SAxel Dörfler  * Copyright 2004-2008, Haiku Inc. All Rights Reserved.
39de65b05SAxel Dörfler  * Distributed under the terms of the MIT License.
4a1978b5cSAxel Dörfler  */
5a1978b5cSAxel Dörfler #ifndef _FS_CACHE_H
6a1978b5cSAxel Dörfler #define _FS_CACHE_H
7a1978b5cSAxel Dörfler 
87a1b4ef3SAxel Dörfler /*! File System File and Block Caches */
95c03270bSAxel Dörfler 
10a1978b5cSAxel Dörfler 
11a1978b5cSAxel Dörfler #include <fs_interface.h>
12a1978b5cSAxel Dörfler 
13a1978b5cSAxel Dörfler 
14e63c1170SAxel Dörfler /* transaction events */
154fc4f2c8SAxel Dörfler enum {
16e63c1170SAxel Dörfler 	TRANSACTION_WRITTEN	= 0x01,
17e63c1170SAxel Dörfler 	TRANSACTION_ABORTED	= 0x02,
18e63c1170SAxel Dörfler 	TRANSACTION_ENDED	= 0x04,
19e63c1170SAxel Dörfler 	TRANSACTION_IDLE	= 0x08
204fc4f2c8SAxel Dörfler };
214fc4f2c8SAxel Dörfler 
22*3c1a3047SAxel Dörfler /* file map modes */
23*3c1a3047SAxel Dörfler enum {
24*3c1a3047SAxel Dörfler 	FILE_MAP_CACHE_ON_DEMAND	= 0x01,	/* default mode */
25*3c1a3047SAxel Dörfler 	FILE_MAP_CACHE_ALL			= 0x02
26*3c1a3047SAxel Dörfler };
27*3c1a3047SAxel Dörfler 
284fc4f2c8SAxel Dörfler typedef void (*transaction_notification_hook)(int32 id, int32 event,
294fc4f2c8SAxel Dörfler 	void *data);
30060b0282SAxel Dörfler 
31a1978b5cSAxel Dörfler #ifdef __cplusplus
32a1978b5cSAxel Dörfler extern "C" {
33a1978b5cSAxel Dörfler #endif
34a1978b5cSAxel Dörfler 
35060b0282SAxel Dörfler /* transactions */
3686c3e70cSAxel Dörfler extern int32 cache_start_transaction(void *_cache);
3786c3e70cSAxel Dörfler extern status_t cache_sync_transaction(void *_cache, int32 id);
381fbe3ccdSIngo Weinhold extern status_t cache_end_transaction(void *_cache, int32 id,
391fbe3ccdSIngo Weinhold 					transaction_notification_hook hook, void *data);
4086c3e70cSAxel Dörfler extern status_t cache_abort_transaction(void *_cache, int32 id);
411fbe3ccdSIngo Weinhold extern int32 cache_detach_sub_transaction(void *_cache, int32 id,
421fbe3ccdSIngo Weinhold 					transaction_notification_hook hook, void *data);
4386c3e70cSAxel Dörfler extern status_t cache_abort_sub_transaction(void *_cache, int32 id);
4486c3e70cSAxel Dörfler extern status_t cache_start_sub_transaction(void *_cache, int32 id);
454fc4f2c8SAxel Dörfler extern status_t cache_add_transaction_listener(void *_cache, int32 id,
46e63c1170SAxel Dörfler 					int32 events, transaction_notification_hook hook,
47e63c1170SAxel Dörfler 					void *data);
484fc4f2c8SAxel Dörfler extern status_t cache_remove_transaction_listener(void *_cache, int32 id,
494fc4f2c8SAxel Dörfler 					transaction_notification_hook hook, void *data);
501fbe3ccdSIngo Weinhold extern status_t cache_next_block_in_transaction(void *_cache, int32 id,
515d0afa4eSAxel Dörfler 					bool mainOnly, long *_cookie, off_t *_blockNumber,
525d0afa4eSAxel Dörfler 					void **_data, void **_unchangedData);
53ca7c5a9eSAxel Dörfler extern int32 cache_blocks_in_transaction(void *_cache, int32 id);
545d0afa4eSAxel Dörfler extern int32 cache_blocks_in_main_transaction(void *_cache, int32 id);
55ca7c5a9eSAxel Dörfler extern int32 cache_blocks_in_sub_transaction(void *_cache, int32 id);
56060b0282SAxel Dörfler 
57060b0282SAxel Dörfler /* block cache */
58060b0282SAxel Dörfler extern void block_cache_delete(void *_cache, bool allowWrites);
591fbe3ccdSIngo Weinhold extern void *block_cache_create(int fd, off_t numBlocks, size_t blockSize,
601fbe3ccdSIngo Weinhold 					bool readOnly);
61060b0282SAxel Dörfler extern status_t block_cache_sync(void *_cache);
625c03270bSAxel Dörfler extern status_t block_cache_sync_etc(void *_cache, off_t blockNumber,
635c03270bSAxel Dörfler 					size_t numBlocks);
641fbe3ccdSIngo Weinhold extern status_t block_cache_make_writable(void *_cache, off_t blockNumber,
651fbe3ccdSIngo Weinhold 					int32 transaction);
661fbe3ccdSIngo Weinhold extern void *block_cache_get_writable_etc(void *_cache, off_t blockNumber,
671fbe3ccdSIngo Weinhold 					off_t base, off_t length, int32 transaction);
681fbe3ccdSIngo Weinhold extern void *block_cache_get_writable(void *_cache, off_t blockNumber,
691fbe3ccdSIngo Weinhold 					int32 transaction);
701fbe3ccdSIngo Weinhold extern void *block_cache_get_empty(void *_cache, off_t blockNumber,
711fbe3ccdSIngo Weinhold 					int32 transaction);
721fbe3ccdSIngo Weinhold extern const void *block_cache_get_etc(void *_cache, off_t blockNumber,
731fbe3ccdSIngo Weinhold 					off_t base, off_t length);
74060b0282SAxel Dörfler extern const void *block_cache_get(void *_cache, off_t blockNumber);
751fbe3ccdSIngo Weinhold extern status_t block_cache_set_dirty(void *_cache, off_t blockNumber,
761fbe3ccdSIngo Weinhold 					bool isDirty, int32 transaction);
77060b0282SAxel Dörfler extern void block_cache_put(void *_cache, off_t blockNumber);
78060b0282SAxel Dörfler 
79a1978b5cSAxel Dörfler /* file cache */
803d268edaSAxel Dörfler extern void *file_cache_create(dev_t mountID, ino_t vnodeID, off_t size);
81a1978b5cSAxel Dörfler extern void file_cache_delete(void *_cacheRef);
827491000fSIngo Weinhold extern void file_cache_enable(void *_cacheRef);
83*3c1a3047SAxel Dörfler extern bool file_cache_is_enabled(void *_cacheRef);
847491000fSIngo Weinhold extern status_t file_cache_disable(void *_cacheRef);
85a1978b5cSAxel Dörfler extern status_t file_cache_set_size(void *_cacheRef, off_t size);
8686c3e70cSAxel Dörfler extern status_t file_cache_sync(void *_cache);
87a1978b5cSAxel Dörfler 
883d268edaSAxel Dörfler extern status_t file_cache_read(void *_cacheRef, void *cookie, off_t offset,
893d268edaSAxel Dörfler 					void *bufferBase, size_t *_size);
903d268edaSAxel Dörfler extern status_t file_cache_write(void *_cacheRef, void *cookie, off_t offset,
911fbe3ccdSIngo Weinhold 					const void *buffer, size_t *_size);
92a1978b5cSAxel Dörfler 
933d268edaSAxel Dörfler /* file map */
944a31d30eSAxel Dörfler extern void *file_map_create(dev_t mountID, ino_t vnodeID, off_t size);
953d268edaSAxel Dörfler extern void file_map_delete(void *_map);
963d268edaSAxel Dörfler extern void file_map_set_size(void *_map, off_t size);
973d268edaSAxel Dörfler extern void file_map_invalidate(void *_map, off_t offset, off_t size);
98*3c1a3047SAxel Dörfler extern status_t file_map_set_mode(void *_map, uint32 mode);
993d268edaSAxel Dörfler extern status_t file_map_translate(void *_map, off_t offset, size_t size,
1003d268edaSAxel Dörfler 					struct file_io_vec *vecs, size_t *_count);
1013d268edaSAxel Dörfler 
102a1978b5cSAxel Dörfler #ifdef __cplusplus
103a1978b5cSAxel Dörfler }
104a1978b5cSAxel Dörfler #endif
105a1978b5cSAxel Dörfler 
106a1978b5cSAxel Dörfler #endif	/* _FS_CACHE_H */
107