1/*
2 * Copyright 2004-2020, 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
14enum {
15	FSSH_TRANSACTION_WRITTEN	= 0x01,
16	FSSH_TRANSACTION_ABORTED	= 0x02,
17	FSSH_TRANSACTION_ENDED		= 0x04,
18	FSSH_TRANSACTION_IDLE		= 0x08
19};
20
21/* file map modes */
22enum {
23	FSSH_FILE_MAP_CACHE_ON_DEMAND	= 0x01,	/* default mode */
24	FSSH_FILE_MAP_CACHE_ALL			= 0x02
25};
26
27typedef void (*fssh_transaction_notification_hook)(int32_t id, int32_t event,
28	void *data);
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/* transactions */
35extern int32_t			fssh_cache_start_transaction(void *_cache);
36extern fssh_status_t	fssh_cache_sync_transaction(void *_cache, int32_t id);
37extern fssh_status_t	fssh_cache_end_transaction(void *_cache, int32_t id,
38							fssh_transaction_notification_hook hook,
39							void *data);
40extern fssh_status_t	fssh_cache_abort_transaction(void *_cache, int32_t id);
41extern int32_t			fssh_cache_detach_sub_transaction(void *_cache,
42							int32_t id, fssh_transaction_notification_hook hook,
43							void *data);
44extern fssh_status_t	fssh_cache_abort_sub_transaction(void *_cache,
45							int32_t id);
46extern fssh_status_t	fssh_cache_start_sub_transaction(void *_cache,
47							int32_t id);
48extern fssh_status_t	fssh_cache_add_transaction_listener(void *_cache,
49							int32_t id, int32_t events,
50							fssh_transaction_notification_hook hook,
51							void *data);
52extern fssh_status_t	fssh_cache_remove_transaction_listener(void *_cache,
53							int32_t id, fssh_transaction_notification_hook hook,
54							void *data);
55extern fssh_status_t	fssh_cache_next_block_in_transaction(void *_cache,
56							int32_t id, bool mainOnly, long *_cookie,
57							fssh_off_t *_blockNumber, void **_data,
58							void **_unchangedData);
59extern int32_t			fssh_cache_blocks_in_transaction(void *_cache,
60							int32_t id);
61extern int32_t			fssh_cache_blocks_in_main_transaction(void *_cache,
62							int32_t id);
63extern int32_t			fssh_cache_blocks_in_sub_transaction(void *_cache,
64							int32_t id);
65extern bool				fssh_cache_has_block_in_transaction(void *_cache,
66							int32_t id, fssh_off_t blockNumber);
67
68/* block cache */
69extern void				fssh_block_cache_delete(void *_cache, bool allowWrites);
70extern void *			fssh_block_cache_create(int fd, fssh_off_t numBlocks,
71							fssh_size_t blockSize, bool readOnly);
72extern fssh_status_t	fssh_block_cache_sync(void *_cache);
73extern fssh_status_t	fssh_block_cache_sync_etc(void *_cache,
74							fssh_off_t blockNumber, fssh_size_t numBlocks);
75extern void				fssh_block_cache_discard(void *_cache,
76							fssh_off_t blockNumber, fssh_size_t numBlocks);
77extern fssh_status_t	fssh_block_cache_make_writable(void *_cache,
78							fssh_off_t blockNumber, int32_t transaction);
79extern fssh_status_t	fssh_block_cache_get_writable_etc(void *_cache,
80							fssh_off_t blockNumber, fssh_off_t base,
81							fssh_off_t length, int32_t transaction,
82							void **_block);
83extern void *			fssh_block_cache_get_writable(void *_cache,
84							fssh_off_t blockNumber, int32_t transaction);
85extern void *			fssh_block_cache_get_empty(void *_cache,
86							fssh_off_t blockNumber, int32_t transaction);
87extern fssh_status_t	fssh_block_cache_get_etc(void *_cache,
88							fssh_off_t blockNumber, fssh_off_t base,
89							fssh_off_t length, const void **_block);
90extern const void *		fssh_block_cache_get(void *_cache,
91							fssh_off_t blockNumber);
92extern fssh_status_t	fssh_block_cache_set_dirty(void *_cache,
93							fssh_off_t blockNumber, bool isDirty,
94							int32_t transaction);
95extern void				fssh_block_cache_put(void *_cache,
96							fssh_off_t blockNumber);
97
98/* file cache */
99extern void *			fssh_file_cache_create(fssh_mount_id mountID,
100							fssh_vnode_id vnodeID, fssh_off_t size);
101extern void				fssh_file_cache_delete(void *_cacheRef);
102extern void				fssh_file_cache_enable(void *_cacheRef);
103extern fssh_status_t	fssh_file_cache_disable(void *_cacheRef);
104extern bool				fssh_file_cache_is_enabled(void *_cacheRef);
105extern fssh_status_t	fssh_file_cache_set_size(void *_cacheRef,
106							fssh_off_t size);
107extern fssh_status_t	fssh_file_cache_sync(void *_cache);
108
109extern fssh_status_t	fssh_file_cache_read(void *_cacheRef, void *cookie,
110							fssh_off_t offset, void *bufferBase,
111							fssh_size_t *_size);
112extern fssh_status_t	fssh_file_cache_write(void *_cacheRef, void *cookie,
113							fssh_off_t offset, const void *buffer,
114							fssh_size_t *_size);
115
116/* file map */
117extern void *			fssh_file_map_create(fssh_mount_id mountID,
118							fssh_vnode_id vnodeID, fssh_off_t size);
119extern void				fssh_file_map_delete(void *_map);
120extern void				fssh_file_map_set_size(void *_map, fssh_off_t size);
121extern void				fssh_file_map_invalidate(void *_map, fssh_off_t offset,
122							fssh_off_t size);
123extern fssh_status_t	fssh_file_map_set_mode(void *_map, uint32_t mode);
124extern fssh_status_t	fssh_file_map_translate(void *_map, fssh_off_t offset,
125							fssh_size_t size, struct fssh_file_io_vec *vecs,
126							fssh_size_t *_count, fssh_size_t align);
127
128/* entry cache */
129extern fssh_status_t	fssh_entry_cache_add(fssh_dev_t mountID,
130							fssh_ino_t dirID, const char* name,
131							fssh_ino_t nodeID);
132extern fssh_status_t	fssh_entry_cache_add_missing(fssh_dev_t mountID,
133							fssh_ino_t dirID, const char* name);
134extern fssh_status_t	fssh_entry_cache_remove(fssh_dev_t mountID,
135							fssh_ino_t dirID, const char* name);
136
137#ifdef __cplusplus
138}
139#endif
140
141#endif	/* _FSSH_FS_CACHE_H */
142