15c03270bSAxel Dörfler /* 293845aecSAxel Dörfler * Copyright 2004-2020, 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 223c1a3047SAxel Dörfler /* file map modes */ 233c1a3047SAxel Dörfler enum { 243c1a3047SAxel Dörfler FILE_MAP_CACHE_ON_DEMAND = 0x01, /* default mode */ 253c1a3047SAxel Dörfler FILE_MAP_CACHE_ALL = 0x02 263c1a3047SAxel Dörfler }; 273c1a3047SAxel 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 */ 365b812019SAxel Dörfler extern int32 cache_start_transaction(void *cache); 375b812019SAxel Dörfler extern status_t cache_sync_transaction(void *cache, int32 id); 385b812019SAxel Dörfler extern status_t cache_end_transaction(void *cache, int32 id, 391fbe3ccdSIngo Weinhold transaction_notification_hook hook, void *data); 405b812019SAxel Dörfler extern status_t cache_abort_transaction(void *cache, int32 id); 415b812019SAxel Dörfler extern int32 cache_detach_sub_transaction(void *cache, int32 id, 421fbe3ccdSIngo Weinhold transaction_notification_hook hook, void *data); 435b812019SAxel Dörfler extern status_t cache_abort_sub_transaction(void *cache, int32 id); 445b812019SAxel Dörfler extern status_t cache_start_sub_transaction(void *cache, int32 id); 455b812019SAxel 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); 485b812019SAxel Dörfler extern status_t cache_remove_transaction_listener(void *cache, int32 id, 494fc4f2c8SAxel Dörfler transaction_notification_hook hook, void *data); 505b812019SAxel Dörfler 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); 535b812019SAxel Dörfler extern int32 cache_blocks_in_transaction(void *cache, int32 id); 545b812019SAxel Dörfler extern int32 cache_blocks_in_main_transaction(void *cache, int32 id); 555b812019SAxel Dörfler extern int32 cache_blocks_in_sub_transaction(void *cache, int32 id); 561750cd1eShyche extern bool cache_has_block_in_transaction(void* cache, int32 id, off_t blockNumber); 57060b0282SAxel Dörfler 58060b0282SAxel Dörfler /* block cache */ 595b812019SAxel Dörfler extern void block_cache_delete(void *cache, bool allowWrites); 601fbe3ccdSIngo Weinhold extern void *block_cache_create(int fd, off_t numBlocks, size_t blockSize, 611fbe3ccdSIngo Weinhold bool readOnly); 625b812019SAxel Dörfler extern status_t block_cache_sync(void *cache); 635b812019SAxel Dörfler extern status_t block_cache_sync_etc(void *cache, off_t blockNumber, 645c03270bSAxel Dörfler size_t numBlocks); 655b812019SAxel Dörfler extern void block_cache_discard(void *cache, off_t blockNumber, 665b812019SAxel Dörfler size_t numBlocks); 675b812019SAxel Dörfler extern status_t block_cache_make_writable(void *cache, off_t blockNumber, 681fbe3ccdSIngo Weinhold int32 transaction); 6993845aecSAxel Dörfler extern status_t block_cache_get_writable_etc(void *cache, off_t blockNumber, 7016ecdb59SAugustin Cavalier int32 transaction, void** _block); 715b812019SAxel Dörfler extern void *block_cache_get_writable(void *cache, off_t blockNumber, 721fbe3ccdSIngo Weinhold int32 transaction); 735b812019SAxel Dörfler extern void *block_cache_get_empty(void *cache, off_t blockNumber, 741fbe3ccdSIngo Weinhold int32 transaction); 7593845aecSAxel Dörfler extern status_t block_cache_get_etc(void *cache, off_t blockNumber, 7616ecdb59SAugustin Cavalier const void** _block); 775b812019SAxel Dörfler extern const void *block_cache_get(void *cache, off_t blockNumber); 785b812019SAxel Dörfler extern status_t block_cache_set_dirty(void *cache, off_t blockNumber, 791fbe3ccdSIngo Weinhold bool isDirty, int32 transaction); 805b812019SAxel Dörfler extern void block_cache_put(void *cache, off_t blockNumber); 81*9bb1816cSJim906 extern status_t block_cache_prefetch(void* cache, off_t blockNumber, size_t* _numBlocks); 82060b0282SAxel Dörfler 83a1978b5cSAxel Dörfler /* file cache */ 843d268edaSAxel Dörfler extern void *file_cache_create(dev_t mountID, ino_t vnodeID, off_t size); 855b812019SAxel Dörfler extern void file_cache_delete(void *cacheRef); 865b812019SAxel Dörfler extern void file_cache_enable(void *cacheRef); 875b812019SAxel Dörfler extern bool file_cache_is_enabled(void *cacheRef); 885b812019SAxel Dörfler extern status_t file_cache_disable(void *cacheRef); 895b812019SAxel Dörfler extern status_t file_cache_set_size(void *cacheRef, off_t size); 905b812019SAxel Dörfler extern status_t file_cache_sync(void *cache); 91a1978b5cSAxel Dörfler 925b812019SAxel Dörfler extern status_t file_cache_read(void *cacheRef, void *cookie, off_t offset, 933d268edaSAxel Dörfler void *bufferBase, size_t *_size); 945b812019SAxel Dörfler extern status_t file_cache_write(void *cacheRef, void *cookie, off_t offset, 951fbe3ccdSIngo Weinhold const void *buffer, size_t *_size); 96a1978b5cSAxel Dörfler 973d268edaSAxel Dörfler /* file map */ 984a31d30eSAxel Dörfler extern void *file_map_create(dev_t mountID, ino_t vnodeID, off_t size); 995b812019SAxel Dörfler extern void file_map_delete(void *map); 1005b812019SAxel Dörfler extern void file_map_set_size(void *map, off_t size); 1015b812019SAxel Dörfler extern void file_map_invalidate(void *map, off_t offset, off_t size); 1025b812019SAxel Dörfler extern status_t file_map_set_mode(void *map, uint32 mode); 1035b812019SAxel Dörfler extern status_t file_map_translate(void *map, off_t offset, size_t size, 10446124337SIngo Weinhold struct file_io_vec *vecs, size_t *_count, size_t align); 1053d268edaSAxel Dörfler 106ee1a1571SIngo Weinhold /* entry cache */ 107ee1a1571SIngo Weinhold extern status_t entry_cache_add(dev_t mountID, ino_t dirID, const char* name, 108ee1a1571SIngo Weinhold ino_t nodeID); 109efb0a3a8SMichael Lotz extern status_t entry_cache_add_missing(dev_t mountID, ino_t dirID, 110efb0a3a8SMichael Lotz const char* name); 111ee1a1571SIngo Weinhold extern status_t entry_cache_remove(dev_t mountID, ino_t dirID, 112ee1a1571SIngo Weinhold const char* name); 113ee1a1571SIngo Weinhold 114a1978b5cSAxel Dörfler #ifdef __cplusplus 115a1978b5cSAxel Dörfler } 116a1978b5cSAxel Dörfler #endif 117a1978b5cSAxel Dörfler 118a1978b5cSAxel Dörfler #endif /* _FS_CACHE_H */ 119