1 /* 2 * Copyright 2004-2008, 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 enum { 15 TRANSACTION_WRITTEN, 16 TRANSACTION_ABORTED, 17 TRANSACTION_ENDED, 18 TRANSACTION_IDLE 19 }; 20 21 typedef void (*transaction_notification_hook)(int32 id, int32 event, 22 void *data); 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* transactions */ 29 extern int32 cache_start_transaction(void *_cache); 30 extern status_t cache_sync_transaction(void *_cache, int32 id); 31 extern status_t cache_end_transaction(void *_cache, int32 id, 32 transaction_notification_hook hook, void *data); 33 extern status_t cache_abort_transaction(void *_cache, int32 id); 34 extern int32 cache_detach_sub_transaction(void *_cache, int32 id, 35 transaction_notification_hook hook, void *data); 36 extern status_t cache_abort_sub_transaction(void *_cache, int32 id); 37 extern status_t cache_start_sub_transaction(void *_cache, int32 id); 38 extern status_t cache_add_transaction_listener(void *_cache, int32 id, 39 transaction_notification_hook hook, void *data); 40 extern status_t cache_remove_transaction_listener(void *_cache, int32 id, 41 transaction_notification_hook hook, void *data); 42 extern status_t cache_next_block_in_transaction(void *_cache, int32 id, 43 bool mainOnly, long *_cookie, off_t *_blockNumber, 44 void **_data, void **_unchangedData); 45 extern int32 cache_blocks_in_transaction(void *_cache, int32 id); 46 extern int32 cache_blocks_in_main_transaction(void *_cache, int32 id); 47 extern int32 cache_blocks_in_sub_transaction(void *_cache, int32 id); 48 49 /* block cache */ 50 extern void block_cache_delete(void *_cache, bool allowWrites); 51 extern void *block_cache_create(int fd, off_t numBlocks, size_t blockSize, 52 bool readOnly); 53 extern status_t block_cache_sync(void *_cache); 54 extern status_t block_cache_sync_etc(void *_cache, off_t blockNumber, 55 size_t numBlocks); 56 extern status_t block_cache_make_writable(void *_cache, off_t blockNumber, 57 int32 transaction); 58 extern void *block_cache_get_writable_etc(void *_cache, off_t blockNumber, 59 off_t base, off_t length, int32 transaction); 60 extern void *block_cache_get_writable(void *_cache, off_t blockNumber, 61 int32 transaction); 62 extern void *block_cache_get_empty(void *_cache, off_t blockNumber, 63 int32 transaction); 64 extern const void *block_cache_get_etc(void *_cache, off_t blockNumber, 65 off_t base, off_t length); 66 extern const void *block_cache_get(void *_cache, off_t blockNumber); 67 extern status_t block_cache_set_dirty(void *_cache, off_t blockNumber, 68 bool isDirty, int32 transaction); 69 extern void block_cache_put(void *_cache, off_t blockNumber); 70 71 /* file cache */ 72 extern void *file_cache_create(dev_t mountID, ino_t vnodeID, off_t size); 73 extern void file_cache_delete(void *_cacheRef); 74 extern status_t file_cache_set_size(void *_cacheRef, off_t size); 75 extern status_t file_cache_sync(void *_cache); 76 77 extern status_t file_cache_read(void *_cacheRef, void *cookie, off_t offset, 78 void *bufferBase, size_t *_size); 79 extern status_t file_cache_write(void *_cacheRef, void *cookie, off_t offset, 80 const void *buffer, size_t *_size); 81 82 /* file map */ 83 extern void *file_map_create(dev_t mountID, ino_t vnodeID, off_t size); 84 extern void file_map_delete(void *_map); 85 extern void file_map_set_size(void *_map, off_t size); 86 extern void file_map_invalidate(void *_map, off_t offset, off_t size); 87 extern status_t file_map_translate(void *_map, off_t offset, size_t size, 88 struct file_io_vec *vecs, size_t *_count); 89 90 #ifdef __cplusplus 91 } 92 #endif 93 94 #endif /* _FS_CACHE_H */ 95