xref: /haiku/headers/os/drivers/fs_cache.h (revision 7a1b4ef3fd2b9002c4eba1160d459eff3a27664d)
15c03270bSAxel Dörfler /*
25c03270bSAxel Dörfler  * Copyright 2004-2007, 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 
8*7a1b4ef3SAxel 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 
149de65b05SAxel Dörfler typedef void (*transaction_notification_hook)(int32 id, void *data);
15060b0282SAxel Dörfler 
16a1978b5cSAxel Dörfler #ifdef __cplusplus
17a1978b5cSAxel Dörfler extern "C" {
18a1978b5cSAxel Dörfler #endif
19a1978b5cSAxel Dörfler 
20060b0282SAxel Dörfler /* transactions */
2186c3e70cSAxel Dörfler extern int32 cache_start_transaction(void *_cache);
2286c3e70cSAxel Dörfler extern status_t cache_sync_transaction(void *_cache, int32 id);
231fbe3ccdSIngo Weinhold extern status_t cache_end_transaction(void *_cache, int32 id,
241fbe3ccdSIngo Weinhold 					transaction_notification_hook hook, void *data);
2586c3e70cSAxel Dörfler extern status_t cache_abort_transaction(void *_cache, int32 id);
261fbe3ccdSIngo Weinhold extern int32 cache_detach_sub_transaction(void *_cache, int32 id,
271fbe3ccdSIngo Weinhold 					transaction_notification_hook hook, void *data);
2886c3e70cSAxel Dörfler extern status_t cache_abort_sub_transaction(void *_cache, int32 id);
2986c3e70cSAxel Dörfler extern status_t cache_start_sub_transaction(void *_cache, int32 id);
301fbe3ccdSIngo Weinhold extern status_t cache_next_block_in_transaction(void *_cache, int32 id,
311fbe3ccdSIngo Weinhold 					uint32 *_cookie, off_t *_blockNumber, void **_data,
321fbe3ccdSIngo Weinhold 					void **_unchangedData);
33ca7c5a9eSAxel Dörfler extern int32 cache_blocks_in_transaction(void *_cache, int32 id);
34ca7c5a9eSAxel Dörfler extern int32 cache_blocks_in_sub_transaction(void *_cache, int32 id);
35060b0282SAxel Dörfler 
36060b0282SAxel Dörfler /* block cache */
37060b0282SAxel Dörfler extern void block_cache_delete(void *_cache, bool allowWrites);
381fbe3ccdSIngo Weinhold extern void *block_cache_create(int fd, off_t numBlocks, size_t blockSize,
391fbe3ccdSIngo Weinhold 					bool readOnly);
40060b0282SAxel Dörfler extern status_t block_cache_sync(void *_cache);
415c03270bSAxel Dörfler extern status_t block_cache_sync_etc(void *_cache, off_t blockNumber,
425c03270bSAxel Dörfler 					size_t numBlocks);
431fbe3ccdSIngo Weinhold extern status_t block_cache_make_writable(void *_cache, off_t blockNumber,
441fbe3ccdSIngo Weinhold 					int32 transaction);
451fbe3ccdSIngo Weinhold extern void *block_cache_get_writable_etc(void *_cache, off_t blockNumber,
461fbe3ccdSIngo Weinhold 					off_t base, off_t length, int32 transaction);
471fbe3ccdSIngo Weinhold extern void *block_cache_get_writable(void *_cache, off_t blockNumber,
481fbe3ccdSIngo Weinhold 					int32 transaction);
491fbe3ccdSIngo Weinhold extern void *block_cache_get_empty(void *_cache, off_t blockNumber,
501fbe3ccdSIngo Weinhold 					int32 transaction);
511fbe3ccdSIngo Weinhold extern const void *block_cache_get_etc(void *_cache, off_t blockNumber,
521fbe3ccdSIngo Weinhold 					off_t base, off_t length);
53060b0282SAxel Dörfler extern const void *block_cache_get(void *_cache, off_t blockNumber);
541fbe3ccdSIngo Weinhold extern status_t block_cache_set_dirty(void *_cache, off_t blockNumber,
551fbe3ccdSIngo Weinhold 					bool isDirty, int32 transaction);
56060b0282SAxel Dörfler extern void block_cache_put(void *_cache, off_t blockNumber);
57060b0282SAxel Dörfler 
58a1978b5cSAxel Dörfler /* file cache */
59*7a1b4ef3SAxel Dörfler extern void *file_cache_create(dev_t mountID, ino_t vnodeID, off_t size,
601fbe3ccdSIngo Weinhold 					int fd);
61a1978b5cSAxel Dörfler extern void file_cache_delete(void *_cacheRef);
62a1978b5cSAxel Dörfler extern status_t file_cache_set_size(void *_cacheRef, off_t size);
6386c3e70cSAxel Dörfler extern status_t file_cache_sync(void *_cache);
641fbe3ccdSIngo Weinhold extern status_t file_cache_invalidate_file_map(void *_cacheRef, off_t offset,
651fbe3ccdSIngo Weinhold 					off_t size);
66a1978b5cSAxel Dörfler 
67a1978b5cSAxel Dörfler extern status_t file_cache_read_pages(void *_cacheRef, off_t offset,
68a1978b5cSAxel Dörfler 					const iovec *vecs, size_t count, size_t *_numBytes);
69a1978b5cSAxel Dörfler extern status_t file_cache_write_pages(void *_cacheRef, off_t offset,
70a1978b5cSAxel Dörfler 					const iovec *vecs, size_t count, size_t *_numBytes);
711fbe3ccdSIngo Weinhold extern status_t file_cache_read(void *_cacheRef, off_t offset, void *bufferBase,
721fbe3ccdSIngo Weinhold 					size_t *_size);
731fbe3ccdSIngo Weinhold extern status_t file_cache_write(void *_cacheRef, off_t offset,
741fbe3ccdSIngo Weinhold 					const void *buffer, size_t *_size);
75a1978b5cSAxel Dörfler 
76a1978b5cSAxel Dörfler #ifdef __cplusplus
77a1978b5cSAxel Dörfler }
78a1978b5cSAxel Dörfler #endif
79a1978b5cSAxel Dörfler 
80a1978b5cSAxel Dörfler #endif	/* _FS_CACHE_H */
81