diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:36:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:36:47 +0000 |
commit | 0441d265f2bb9da249c7abf333f0f771fadb4ab5 (patch) | |
tree | 3f3789daa2f6db22da6e55e92bee0062a7d613fe /src/lib/file-cache.h | |
parent | Initial commit. (diff) | |
download | dovecot-0441d265f2bb9da249c7abf333f0f771fadb4ab5.tar.xz dovecot-0441d265f2bb9da249c7abf333f0f771fadb4ab5.zip |
Adding upstream version 1:2.3.21+dfsg1.upstream/1%2.3.21+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib/file-cache.h')
-rw-r--r-- | src/lib/file-cache.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/lib/file-cache.h b/src/lib/file-cache.h new file mode 100644 index 0000000..afffbd4 --- /dev/null +++ b/src/lib/file-cache.h @@ -0,0 +1,37 @@ +#ifndef FILE_CACHE_H +#define FILE_CACHE_H + +/* Create a new file cache. It works very much like file-backed mmap()ed + memory, but it works more nicely with remote filesystems (no SIGBUS). */ +struct file_cache *file_cache_new(int fd); +struct file_cache *file_cache_new_path(int fd, const char *path); +/* Destroy the cache and set cache pointer to NULL. */ +void file_cache_free(struct file_cache **cache); + +/* Change cached file descriptor. Invalidates the whole cache. */ +void file_cache_set_fd(struct file_cache *cache, int fd); + +/* Change the memory allocated for the cache. This can be used to immediately + set the maximum size so there's no need to grow the memory area with + possibly slow copying. */ +int file_cache_set_size(struct file_cache *cache, uoff_t size); + +/* Read data from file, returns how many bytes was actually read or -1 if + error occurred. */ +ssize_t file_cache_read(struct file_cache *cache, uoff_t offset, size_t size); + +/* Returns pointer to beginning of cached file. Only parts of the returned + memory that are valid are the ones that have been file_cache_read(). + Note that the pointer may become invalid after calling file_cache_read(). */ +const void *file_cache_get_map(struct file_cache *cache, size_t *size_r); + +/* Update cached memory area. Mark fully written pages as cached. */ +void file_cache_write(struct file_cache *cache, const void *data, size_t size, + uoff_t offset); + +/* Invalidate cached memory area. It will be read again next time it's tried + to be accessed. */ +void file_cache_invalidate(struct file_cache *cache, + uoff_t offset, uoff_t size); + +#endif |