1 /* File System File and Block Caches 2 * 3 * Copyright 2004, Haiku Inc. All Rights Reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef _FS_CACHE_H 7 #define _FS_CACHE_H 8 9 10 #include <fs_interface.h> 11 12 13 typedef void (*transaction_notification_hook)(int32 id, void *data); 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 /* transactions */ 20 extern int32 cache_start_transaction(void *_cache); 21 extern status_t cache_sync_transaction(void *_cache, int32 id); 22 extern status_t cache_end_transaction(void *_cache, int32 id, transaction_notification_hook hook, void *data); 23 extern status_t cache_abort_transaction(void *_cache, int32 id); 24 extern int32 cache_detach_sub_transaction(void *_cache, int32 id); 25 extern status_t cache_abort_sub_transaction(void *_cache, int32 id); 26 extern status_t cache_start_sub_transaction(void *_cache, int32 id); 27 extern status_t cache_next_block_in_transaction(void *_cache, int32 id, uint32 *_cookie, 28 off_t *_blockNumber, void **_data, void **_unchangedData); 29 30 /* block cache */ 31 extern void block_cache_delete(void *_cache, bool allowWrites); 32 extern void *block_cache_create(int fd, off_t numBlocks, size_t blockSize); 33 extern status_t block_cache_sync(void *_cache); 34 35 extern status_t block_cache_make_writable(void *_cache, off_t blockNumber, int32 transaction); 36 extern void *block_cache_get_writable_etc(void *_cache, off_t blockNumber, off_t base, 37 off_t length, int32 transaction); 38 extern void *block_cache_get_writable(void *_cache, off_t blockNumber, int32 transaction); 39 extern void *block_cache_get_empty(void *_cache, off_t blockNumber, int32 transaction); 40 extern const void *block_cache_get_etc(void *_cache, off_t blockNumber, off_t base, off_t length); 41 extern const void *block_cache_get(void *_cache, off_t blockNumber); 42 extern status_t block_cache_set_dirty(void *_cache, off_t blockNumber, bool isDirty, int32 transaction); 43 extern void block_cache_put(void *_cache, off_t blockNumber); 44 45 /* file cache */ 46 extern void *file_cache_create(mount_id mountID, vnode_id vnodeID, off_t size, int fd); 47 extern void file_cache_delete(void *_cacheRef); 48 extern status_t file_cache_set_size(void *_cacheRef, off_t size); 49 extern status_t file_cache_sync(void *_cache); 50 51 extern status_t file_cache_read_pages(void *_cacheRef, off_t offset, 52 const iovec *vecs, size_t count, size_t *_numBytes); 53 extern status_t file_cache_write_pages(void *_cacheRef, off_t offset, 54 const iovec *vecs, size_t count, size_t *_numBytes); 55 extern status_t file_cache_read(void *_cacheRef, off_t offset, void *bufferBase, size_t *_size); 56 extern status_t file_cache_write(void *_cacheRef, off_t offset, const void *buffer, size_t *_size); 57 58 #ifdef __cplusplus 59 } 60 #endif 61 62 #endif /* _FS_CACHE_H */ 63