file-cache.h revision f7e0daedc6838c45df6b2a0724a57662b92e7df4
9f8559a5ac7b53b83378c894de6578773dc1e392Timo Sirainen/* Create a new file cache. It works very much like file-backed mmap()ed
9f8559a5ac7b53b83378c894de6578773dc1e392Timo Sirainen memory, but it works more nicely with remote filesystems (no SIGBUS). */
e641c9f656f1788ca6226ef0d60b2d592e2ca6d1Stephan Bosch/* Destroy the cache and set cache pointer to NULL. */
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschvoid file_cache_free(struct file_cache **cache);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch/* Change cached file descriptor. Invalidates the whole cache. */
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschvoid file_cache_set_fd(struct file_cache *cache, int fd);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch/* Change the memory allocated for the cache. This can be used to immediately
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch set the maximum size so there's no need to grow the memory area with
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Bosch possibly slow copying. */
1e653c7406ec0b062c0bacfdf2e7568a3f860500Stephan Boschint file_cache_set_size(struct file_cache *cache, uoff_t size);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch/* Read data from file, returns how many bytes was actually read or -1 if
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch error occurred. */
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschssize_t file_cache_read(struct file_cache *cache, uoff_t offset, size_t size);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch/* Returns pointer to beginning of cached file. Only parts of the returned
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch memory that are valid are the ones that have been file_cache_read().
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch Note that the pointer may become invalid after calling file_cache_read(). */
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschconst void *file_cache_get_map(struct file_cache *cache, size_t *size_r);
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch/* Update cached memory area. Mark fully written pages as cached. */
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Boschvoid file_cache_write(struct file_cache *cache, const void *data, size_t size,
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch/* Invalidate cached memory area. It will be read again next time it's tried
5394bed8aaef2a6c1c870a34a23a7824e1f370bbStephan Bosch to be accessed. */