file-cache.h revision 1098fc409a45e7603701dc94635927a673bee0c1
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen#ifndef __FILE_CACHE_H
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen#define __FILE_CACHE_H
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen/* Create a new file cache. It works very much like file-backed mmap()ed
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen memory, but it works more nicely with remote filesystems (no SIGBUS). */
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainenstruct file_cache *file_cache_new(int fd);
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainenvoid file_cache_free(struct file_cache *cache);
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen/* Change cached file descriptor. Invalidates the whole cache. */
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainenvoid file_cache_set_fd(struct file_cache *cache, int fd);
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen/* Read data from file, returns how many bytes was actually read or -1 if
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen error occured. */
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainenssize_t file_cache_read(struct file_cache *cache, uoff_t offset, size_t size);
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen/* Returns pointer to beginning of cached file. Only parts of the returned
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen memory that are valid are the ones that have been file_cache_read().
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen Note that the pointer may become invalid after calling file_cache_read(). */
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainenconst void *file_cache_get_map(struct file_cache *cache, size_t *size_r);
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen/* Invalidate cached memory area. It will be read again next time it's tried
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen to be accessed. */
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainenvoid file_cache_invalidate(struct file_cache *cache,
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen uoff_t offset, size_t size);
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen#endif