Mercurial > dovecot > core-2.2
annotate src/lib/file-cache.h @ 21306:f7a5eb710cad
lib: Add file_cache_new_path() to include path in error messages.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Wed, 14 Dec 2016 19:35:05 +0200 |
parents | e4eb71ae8e96 |
children |
rev | line source |
---|---|
6410
e4eb71ae8e96
Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents:
5144
diff
changeset
|
1 #ifndef FILE_CACHE_H |
e4eb71ae8e96
Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents:
5144
diff
changeset
|
2 #define FILE_CACHE_H |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 /* Create a new file cache. It works very much like file-backed mmap()ed |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 memory, but it works more nicely with remote filesystems (no SIGBUS). */ |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 struct file_cache *file_cache_new(int fd); |
21306
f7a5eb710cad
lib: Add file_cache_new_path() to include path in error messages.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
6410
diff
changeset
|
7 struct file_cache *file_cache_new_path(int fd, const char *path); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
8 /* Destroy the cache and set cache pointer to NULL. */ |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3520
diff
changeset
|
9 void file_cache_free(struct file_cache **cache); |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 /* Change cached file descriptor. Invalidates the whole cache. */ |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 void file_cache_set_fd(struct file_cache *cache, int fd); |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 |
5144
0851c6e96852
Made file_cache_set_size() public.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
14 /* Change the memory allocated for the cache. This can be used to immediately |
0851c6e96852
Made file_cache_set_size() public.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
15 set the maximum size so there's no need to grow the memory area with |
0851c6e96852
Made file_cache_set_size() public.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
16 possibly slow copying. */ |
0851c6e96852
Made file_cache_set_size() public.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
17 int file_cache_set_size(struct file_cache *cache, uoff_t size); |
0851c6e96852
Made file_cache_set_size() public.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
18 |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 /* Read data from file, returns how many bytes was actually read or -1 if |
3520 | 20 error occurred. */ |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 ssize_t file_cache_read(struct file_cache *cache, uoff_t offset, size_t size); |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 /* Returns pointer to beginning of cached file. Only parts of the returned |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 memory that are valid are the ones that have been file_cache_read(). |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 Note that the pointer may become invalid after calling file_cache_read(). */ |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 const void *file_cache_get_map(struct file_cache *cache, size_t *size_r); |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 |
3374
8b2dd340e16d
Added file_cache_write() to update cached memory area.
Timo Sirainen <tss@iki.fi>
parents:
2933
diff
changeset
|
28 /* Update cached memory area. Mark fully written pages as cached. */ |
8b2dd340e16d
Added file_cache_write() to update cached memory area.
Timo Sirainen <tss@iki.fi>
parents:
2933
diff
changeset
|
29 void file_cache_write(struct file_cache *cache, const void *data, size_t size, |
8b2dd340e16d
Added file_cache_write() to update cached memory area.
Timo Sirainen <tss@iki.fi>
parents:
2933
diff
changeset
|
30 uoff_t offset); |
8b2dd340e16d
Added file_cache_write() to update cached memory area.
Timo Sirainen <tss@iki.fi>
parents:
2933
diff
changeset
|
31 |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 /* Invalidate cached memory area. It will be read again next time it's tried |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 to be accessed. */ |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 void file_cache_invalidate(struct file_cache *cache, |
2933
6ec86fd705a6
Changed file_cache_invalidate()'s size argument to uoff_t type.
Timo Sirainen <tss@iki.fi>
parents:
2866
diff
changeset
|
35 uoff_t offset, uoff_t size); |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 #endif |