xref: /haiku/headers/os/drivers/fs_cache.h (revision 4fc4f2c8aeefd8548dc95f51af64beabc07a4ec5)
15c03270bSAxel Dörfler /*
2*4fc4f2c8SAxel 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 
14*4fc4f2c8SAxel Dörfler enum {
15*4fc4f2c8SAxel Dörfler 	TRANSACTION_WRITTEN,
16*4fc4f2c8SAxel Dörfler 	TRANSACTION_ABORTED,
17*4fc4f2c8SAxel Dörfler 	TRANSACTION_ENDED
18*4fc4f2c8SAxel Dörfler };
19*4fc4f2c8SAxel Dörfler 
20*4fc4f2c8SAxel Dörfler typedef void (*transaction_notification_hook)(int32 id, int32 event,
21*4fc4f2c8SAxel Dörfler 	void *data);
22060b0282SAxel Dörfler 
23a1978b5cSAxel Dörfler #ifdef __cplusplus
24a1978b5cSAxel Dörfler extern "C" {
25a1978b5cSAxel Dörfler #endif
26a1978b5cSAxel Dörfler 
27060b0282SAxel Dörfler /* transactions */
2886c3e70cSAxel Dörfler extern int32 cache_start_transaction(void *_cache);
2986c3e70cSAxel Dörfler extern status_t cache_sync_transaction(void *_cache, int32 id);
301fbe3ccdSIngo Weinhold extern status_t cache_end_transaction(void *_cache, int32 id,
311fbe3ccdSIngo Weinhold 					transaction_notification_hook hook, void *data);
3286c3e70cSAxel Dörfler extern status_t cache_abort_transaction(void *_cache, int32 id);
331fbe3ccdSIngo Weinhold extern int32 cache_detach_sub_transaction(void *_cache, int32 id,
341fbe3ccdSIngo Weinhold 					transaction_notification_hook hook, void *data);
3586c3e70cSAxel Dörfler extern status_t cache_abort_sub_transaction(void *_cache, int32 id);
3686c3e70cSAxel Dörfler extern status_t cache_start_sub_transaction(void *_cache, int32 id);
37*4fc4f2c8SAxel Dörfler extern status_t cache_add_transaction_listener(void *_cache, int32 id,
38*4fc4f2c8SAxel Dörfler 					transaction_notification_hook hook, void *data);
39*4fc4f2c8SAxel Dörfler extern status_t cache_remove_transaction_listener(void *_cache, int32 id,
40*4fc4f2c8SAxel Dörfler 					transaction_notification_hook hook, void *data);
411fbe3ccdSIngo Weinhold extern status_t cache_next_block_in_transaction(void *_cache, int32 id,
421fbe3ccdSIngo Weinhold 					uint32 *_cookie, off_t *_blockNumber, void **_data,
431fbe3ccdSIngo Weinhold 					void **_unchangedData);
44ca7c5a9eSAxel Dörfler extern int32 cache_blocks_in_transaction(void *_cache, int32 id);
45ca7c5a9eSAxel Dörfler extern int32 cache_blocks_in_sub_transaction(void *_cache, int32 id);
46060b0282SAxel Dörfler 
47060b0282SAxel Dörfler /* block cache */
48060b0282SAxel Dörfler extern void block_cache_delete(void *_cache, bool allowWrites);
491fbe3ccdSIngo Weinhold extern void *block_cache_create(int fd, off_t numBlocks, size_t blockSize,
501fbe3ccdSIngo Weinhold 					bool readOnly);
51060b0282SAxel Dörfler extern status_t block_cache_sync(void *_cache);
525c03270bSAxel Dörfler extern status_t block_cache_sync_etc(void *_cache, off_t blockNumber,
535c03270bSAxel Dörfler 					size_t numBlocks);
541fbe3ccdSIngo Weinhold extern status_t block_cache_make_writable(void *_cache, off_t blockNumber,
551fbe3ccdSIngo Weinhold 					int32 transaction);
561fbe3ccdSIngo Weinhold extern void *block_cache_get_writable_etc(void *_cache, off_t blockNumber,
571fbe3ccdSIngo Weinhold 					off_t base, off_t length, int32 transaction);
581fbe3ccdSIngo Weinhold extern void *block_cache_get_writable(void *_cache, off_t blockNumber,
591fbe3ccdSIngo Weinhold 					int32 transaction);
601fbe3ccdSIngo Weinhold extern void *block_cache_get_empty(void *_cache, off_t blockNumber,
611fbe3ccdSIngo Weinhold 					int32 transaction);
621fbe3ccdSIngo Weinhold extern const void *block_cache_get_etc(void *_cache, off_t blockNumber,
631fbe3ccdSIngo Weinhold 					off_t base, off_t length);
64060b0282SAxel Dörfler extern const void *block_cache_get(void *_cache, off_t blockNumber);
651fbe3ccdSIngo Weinhold extern status_t block_cache_set_dirty(void *_cache, off_t blockNumber,
661fbe3ccdSIngo Weinhold 					bool isDirty, int32 transaction);
67060b0282SAxel Dörfler extern void block_cache_put(void *_cache, off_t blockNumber);
68060b0282SAxel Dörfler 
69a1978b5cSAxel Dörfler /* file cache */
703d268edaSAxel Dörfler extern void *file_cache_create(dev_t mountID, ino_t vnodeID, off_t size);
71a1978b5cSAxel Dörfler extern void file_cache_delete(void *_cacheRef);
72a1978b5cSAxel Dörfler extern status_t file_cache_set_size(void *_cacheRef, off_t size);
7386c3e70cSAxel Dörfler extern status_t file_cache_sync(void *_cache);
74a1978b5cSAxel Dörfler 
753d268edaSAxel Dörfler extern status_t file_cache_read(void *_cacheRef, void *cookie, off_t offset,
763d268edaSAxel Dörfler 					void *bufferBase, size_t *_size);
773d268edaSAxel Dörfler extern status_t file_cache_write(void *_cacheRef, void *cookie, off_t offset,
781fbe3ccdSIngo Weinhold 					const void *buffer, size_t *_size);
79a1978b5cSAxel Dörfler 
803d268edaSAxel Dörfler /* file map */
814a31d30eSAxel Dörfler extern void *file_map_create(dev_t mountID, ino_t vnodeID, off_t size);
823d268edaSAxel Dörfler extern void file_map_delete(void *_map);
833d268edaSAxel Dörfler extern void file_map_set_size(void *_map, off_t size);
843d268edaSAxel Dörfler extern void file_map_invalidate(void *_map, off_t offset, off_t size);
853d268edaSAxel Dörfler extern status_t file_map_translate(void *_map, off_t offset, size_t size,
863d268edaSAxel Dörfler 					struct file_io_vec *vecs, size_t *_count);
873d268edaSAxel Dörfler 
88a1978b5cSAxel Dörfler #ifdef __cplusplus
89a1978b5cSAxel Dörfler }
90a1978b5cSAxel Dörfler #endif
91a1978b5cSAxel Dörfler 
92a1978b5cSAxel Dörfler #endif	/* _FS_CACHE_H */
93