xref: /haiku/headers/os/drivers/fs_cache.h (revision 4612433715fc0477740693682ec4a642c1a4c6e1)
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  /* 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  
57  /* block cache */
58  extern void block_cache_delete(void *_cache, bool allowWrites);
59  extern void *block_cache_create(int fd, off_t numBlocks, size_t blockSize,
60  					bool readOnly);
61  extern status_t block_cache_sync(void *_cache);
62  extern status_t block_cache_sync_etc(void *_cache, off_t blockNumber,
63  					size_t numBlocks);
64  extern status_t block_cache_make_writable(void *_cache, off_t blockNumber,
65  					int32 transaction);
66  extern void *block_cache_get_writable_etc(void *_cache, off_t blockNumber,
67  					off_t base, off_t length, int32 transaction);
68  extern void *block_cache_get_writable(void *_cache, off_t blockNumber,
69  					int32 transaction);
70  extern void *block_cache_get_empty(void *_cache, off_t blockNumber,
71  					int32 transaction);
72  extern const void *block_cache_get_etc(void *_cache, off_t blockNumber,
73  					off_t base, off_t length);
74  extern const void *block_cache_get(void *_cache, off_t blockNumber);
75  extern status_t block_cache_set_dirty(void *_cache, off_t blockNumber,
76  					bool isDirty, int32 transaction);
77  extern void block_cache_put(void *_cache, off_t blockNumber);
78  
79  /* file cache */
80  extern void *file_cache_create(dev_t mountID, ino_t vnodeID, off_t size);
81  extern void file_cache_delete(void *_cacheRef);
82  extern void file_cache_enable(void *_cacheRef);
83  extern bool file_cache_is_enabled(void *_cacheRef);
84  extern status_t file_cache_disable(void *_cacheRef);
85  extern status_t file_cache_set_size(void *_cacheRef, off_t size);
86  extern status_t file_cache_sync(void *_cache);
87  
88  extern status_t file_cache_read(void *_cacheRef, void *cookie, off_t offset,
89  					void *bufferBase, size_t *_size);
90  extern status_t file_cache_write(void *_cacheRef, void *cookie, off_t offset,
91  					const void *buffer, size_t *_size);
92  
93  /* file map */
94  extern void *file_map_create(dev_t mountID, ino_t vnodeID, off_t size);
95  extern void file_map_delete(void *_map);
96  extern void file_map_set_size(void *_map, off_t size);
97  extern void file_map_invalidate(void *_map, off_t offset, off_t size);
98  extern status_t file_map_set_mode(void *_map, uint32 mode);
99  extern status_t file_map_translate(void *_map, off_t offset, size_t size,
100  					struct file_io_vec *vecs, size_t *_count, size_t align);
101  
102  #ifdef __cplusplus
103  }
104  #endif
105  
106  #endif	/* _FS_CACHE_H */
107