1 /* 2 * Copyright 2004-2008, Haiku Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _FSSH_FS_CACHE_H 6 #define _FSSH_FS_CACHE_H 7 8 //! File System File and Block Caches 9 10 11 #include "fssh_fs_interface.h" 12 13 14 enum { 15 FSSH_TRANSACTION_WRITTEN = 0x01, 16 FSSH_TRANSACTION_ABORTED = 0x02, 17 FSSH_TRANSACTION_ENDED = 0x04, 18 FSSH_TRANSACTION_IDLE = 0x08 19 }; 20 21 typedef void (*fssh_transaction_notification_hook)(int32_t id, int32_t event, 22 void *data); 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* transactions */ 29 extern int32_t fssh_cache_start_transaction(void *_cache); 30 extern fssh_status_t fssh_cache_sync_transaction(void *_cache, int32_t id); 31 extern fssh_status_t fssh_cache_end_transaction(void *_cache, int32_t id, 32 fssh_transaction_notification_hook hook, 33 void *data); 34 extern fssh_status_t fssh_cache_abort_transaction(void *_cache, int32_t id); 35 extern int32_t fssh_cache_detach_sub_transaction(void *_cache, 36 int32_t id, fssh_transaction_notification_hook hook, 37 void *data); 38 extern fssh_status_t fssh_cache_abort_sub_transaction(void *_cache, 39 int32_t id); 40 extern fssh_status_t fssh_cache_start_sub_transaction(void *_cache, 41 int32_t id); 42 extern fssh_status_t fssh_cache_add_transaction_listener(void *_cache, 43 int32_t id, int32_t events, 44 fssh_transaction_notification_hook hook, 45 void *data); 46 extern fssh_status_t fssh_cache_remove_transaction_listener(void *_cache, 47 int32_t id, fssh_transaction_notification_hook hook, 48 void *data); 49 extern fssh_status_t fssh_cache_next_block_in_transaction(void *_cache, 50 int32_t id, bool mainOnly, long *_cookie, 51 fssh_off_t *_blockNumber, void **_data, 52 void **_unchangedData); 53 extern int32_t fssh_cache_blocks_in_transaction(void *_cache, 54 int32_t id); 55 extern int32_t fssh_cache_blocks_in_main_transaction(void *_cache, 56 int32_t id); 57 extern int32_t fssh_cache_blocks_in_sub_transaction(void *_cache, 58 int32_t id); 59 60 /* block cache */ 61 extern void fssh_block_cache_delete(void *_cache, bool allowWrites); 62 extern void * fssh_block_cache_create(int fd, fssh_off_t numBlocks, 63 fssh_size_t blockSize, bool readOnly); 64 extern fssh_status_t fssh_block_cache_sync(void *_cache); 65 extern fssh_status_t fssh_block_cache_sync_etc(void *_cache, 66 fssh_off_t blockNumber, fssh_size_t numBlocks); 67 extern fssh_status_t fssh_block_cache_make_writable(void *_cache, 68 fssh_off_t blockNumber, int32_t transaction); 69 extern void * fssh_block_cache_get_writable_etc(void *_cache, 70 fssh_off_t blockNumber, fssh_off_t base, 71 fssh_off_t length, int32_t transaction); 72 extern void * fssh_block_cache_get_writable(void *_cache, 73 fssh_off_t blockNumber, int32_t transaction); 74 extern void * fssh_block_cache_get_empty(void *_cache, 75 fssh_off_t blockNumber, int32_t transaction); 76 extern const void * fssh_block_cache_get_etc(void *_cache, 77 fssh_off_t blockNumber, fssh_off_t base, 78 fssh_off_t length); 79 extern const void * fssh_block_cache_get(void *_cache, 80 fssh_off_t blockNumber); 81 extern fssh_status_t fssh_block_cache_set_dirty(void *_cache, 82 fssh_off_t blockNumber, bool isDirty, 83 int32_t transaction); 84 extern void fssh_block_cache_put(void *_cache, 85 fssh_off_t blockNumber); 86 87 /* file cache */ 88 extern void * fssh_file_cache_create(fssh_mount_id mountID, 89 fssh_vnode_id vnodeID, fssh_off_t size); 90 extern void fssh_file_cache_delete(void *_cacheRef); 91 extern fssh_status_t fssh_file_cache_set_size(void *_cacheRef, 92 fssh_off_t size); 93 extern fssh_status_t fssh_file_cache_sync(void *_cache); 94 95 extern fssh_status_t fssh_file_cache_read(void *_cacheRef, void *cookie, 96 fssh_off_t offset, void *bufferBase, 97 fssh_size_t *_size); 98 extern fssh_status_t fssh_file_cache_write(void *_cacheRef, void *cookie, 99 fssh_off_t offset, const void *buffer, 100 fssh_size_t *_size); 101 102 /* file map */ 103 extern void * fssh_file_map_create(fssh_mount_id mountID, 104 fssh_vnode_id vnodeID, fssh_off_t size); 105 extern void fssh_file_map_delete(void *_map); 106 extern void fssh_file_map_set_size(void *_map, fssh_off_t size); 107 extern void fssh_file_map_invalidate(void *_map, fssh_off_t offset, 108 fssh_off_t size); 109 extern fssh_status_t fssh_file_map_translate(void *_map, fssh_off_t offset, 110 fssh_size_t size, struct fssh_file_io_vec *vecs, 111 fssh_size_t *_count); 112 113 #ifdef __cplusplus 114 } 115 #endif 116 117 #endif /* _FSSH_FS_CACHE_H */ 118