1 /* 2 * Copyright 2004-2020, 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 /* transaction events */ 15 enum { 16 TRANSACTION_WRITTEN = 0x01, 17 TRANSACTION_ABORTED = 0x02, 18 TRANSACTION_ENDED = 0x04, 19 TRANSACTION_IDLE = 0x08 20 }; 21 22 /* file map modes */ 23 enum { 24 FILE_MAP_CACHE_ON_DEMAND = 0x01, /* default mode */ 25 FILE_MAP_CACHE_ALL = 0x02 26 }; 27 28 typedef void (*transaction_notification_hook)(int32 id, int32 event, 29 void *data); 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 /* transactions */ 36 extern int32 cache_start_transaction(void *cache); 37 extern status_t cache_sync_transaction(void *cache, int32 id); 38 extern status_t cache_end_transaction(void *cache, int32 id, 39 transaction_notification_hook hook, void *data); 40 extern status_t cache_abort_transaction(void *cache, int32 id); 41 extern int32 cache_detach_sub_transaction(void *cache, int32 id, 42 transaction_notification_hook hook, void *data); 43 extern status_t cache_abort_sub_transaction(void *cache, int32 id); 44 extern status_t cache_start_sub_transaction(void *cache, int32 id); 45 extern status_t cache_add_transaction_listener(void *cache, int32 id, 46 int32 events, transaction_notification_hook hook, 47 void *data); 48 extern status_t cache_remove_transaction_listener(void *cache, int32 id, 49 transaction_notification_hook hook, void *data); 50 extern status_t cache_next_block_in_transaction(void *cache, int32 id, 51 bool mainOnly, long *_cookie, off_t *_blockNumber, 52 void **_data, void **_unchangedData); 53 extern int32 cache_blocks_in_transaction(void *cache, int32 id); 54 extern int32 cache_blocks_in_main_transaction(void *cache, int32 id); 55 extern int32 cache_blocks_in_sub_transaction(void *cache, int32 id); 56 extern bool cache_has_block_in_transaction(void* cache, int32 id, off_t blockNumber); 57 58 /* block cache */ 59 extern void block_cache_delete(void *cache, bool allowWrites); 60 extern void *block_cache_create(int fd, off_t numBlocks, size_t blockSize, 61 bool readOnly); 62 extern status_t block_cache_sync(void *cache); 63 extern status_t block_cache_sync_etc(void *cache, off_t blockNumber, 64 size_t numBlocks); 65 extern void block_cache_discard(void *cache, off_t blockNumber, 66 size_t numBlocks); 67 extern status_t block_cache_make_writable(void *cache, off_t blockNumber, 68 int32 transaction); 69 extern status_t block_cache_get_writable_etc(void *cache, off_t blockNumber, 70 int32 transaction, void** _block); 71 extern void *block_cache_get_writable(void *cache, off_t blockNumber, 72 int32 transaction); 73 extern void *block_cache_get_empty(void *cache, off_t blockNumber, 74 int32 transaction); 75 extern status_t block_cache_get_etc(void *cache, off_t blockNumber, 76 const void** _block); 77 extern const void *block_cache_get(void *cache, off_t blockNumber); 78 extern status_t block_cache_set_dirty(void *cache, off_t blockNumber, 79 bool isDirty, int32 transaction); 80 extern void block_cache_put(void *cache, off_t blockNumber); 81 extern status_t block_cache_prefetch(void* cache, off_t blockNumber, size_t* _numBlocks); 82 83 /* file cache */ 84 extern void *file_cache_create(dev_t mountID, ino_t vnodeID, off_t size); 85 extern void file_cache_delete(void *cacheRef); 86 extern void file_cache_enable(void *cacheRef); 87 extern bool file_cache_is_enabled(void *cacheRef); 88 extern status_t file_cache_disable(void *cacheRef); 89 extern status_t file_cache_set_size(void *cacheRef, off_t size); 90 extern status_t file_cache_sync(void *cache); 91 92 extern status_t file_cache_read(void *cacheRef, void *cookie, off_t offset, 93 void *bufferBase, size_t *_size); 94 extern status_t file_cache_write(void *cacheRef, void *cookie, off_t offset, 95 const void *buffer, size_t *_size); 96 97 /* file map */ 98 extern void *file_map_create(dev_t mountID, ino_t vnodeID, off_t size); 99 extern void file_map_delete(void *map); 100 extern void file_map_set_size(void *map, off_t size); 101 extern void file_map_invalidate(void *map, off_t offset, off_t size); 102 extern status_t file_map_set_mode(void *map, uint32 mode); 103 extern status_t file_map_translate(void *map, off_t offset, size_t size, 104 struct file_io_vec *vecs, size_t *_count, size_t align); 105 106 /* entry cache */ 107 extern status_t entry_cache_add(dev_t mountID, ino_t dirID, const char* name, 108 ino_t nodeID); 109 extern status_t entry_cache_add_missing(dev_t mountID, ino_t dirID, 110 const char* name); 111 extern status_t entry_cache_remove(dev_t mountID, ino_t dirID, 112 const char* name); 113 114 #ifdef __cplusplus 115 } 116 #endif 117 118 #endif /* _FS_CACHE_H */ 119