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