1 #ifndef FILE_CACHE_H
2 #define FILE_CACHE_H
3 
4 /* Create a new file cache. It works very much like file-backed mmap()ed
5    memory, but it works more nicely with remote filesystems (no SIGBUS). */
6 struct file_cache *file_cache_new(int fd);
7 struct file_cache *file_cache_new_path(int fd, const char *path);
8 /* Destroy the cache and set cache pointer to NULL. */
9 void file_cache_free(struct file_cache **cache);
10 
11 /* Change cached file descriptor. Invalidates the whole cache. */
12 void file_cache_set_fd(struct file_cache *cache, int fd);
13 
14 /* Change the memory allocated for the cache. This can be used to immediately
15    set the maximum size so there's no need to grow the memory area with
16    possibly slow copying. */
17 int file_cache_set_size(struct file_cache *cache, uoff_t size);
18 
19 /* Read data from file, returns how many bytes was actually read or -1 if
20    error occurred. */
21 ssize_t file_cache_read(struct file_cache *cache, uoff_t offset, size_t size);
22 
23 /* Returns pointer to beginning of cached file. Only parts of the returned
24    memory that are valid are the ones that have been file_cache_read().
25    Note that the pointer may become invalid after calling file_cache_read(). */
26 const void *file_cache_get_map(struct file_cache *cache, size_t *size_r);
27 
28 /* Update cached memory area. Mark fully written pages as cached. */
29 void file_cache_write(struct file_cache *cache, const void *data, size_t size,
30 		      uoff_t offset);
31 
32 /* Invalidate cached memory area. It will be read again next time it's tried
33    to be accessed. */
34 void file_cache_invalidate(struct file_cache *cache,
35 			   uoff_t offset, uoff_t size);
36 
37 #endif
38