]> mj.ucw.cz Git - libucw.git/blob - lib/pagecache.h
malloc -> xmalloc.
[libucw.git] / lib / pagecache.h
1 /*
2  *      Sherlock Library -- File Page Cache
3  *
4  *      (c) 1999--2002 Martin Mares <mj@ucw.cz>
5  */
6
7 #ifndef _SHERLOCK_PAGECACHE_H
8 #define _SHERLOCK_PAGECACHE_H
9
10 #include "lib/lists.h"
11
12 struct page_cache;
13
14 struct page {
15   node n;                               /* Node in page list */
16   node hn;                              /* Node in hash table */
17   sh_off_t pos;
18   uns fd;
19   uns flags;
20   uns lock_count;
21   byte data[0];
22 };
23
24 #define PG_FLAG_DIRTY           1
25 #define PG_FLAG_VALID           2
26
27 struct page_cache *pgc_open(uns page_size, uns max_pages);
28 void pgc_close(struct page_cache *);
29 void pgc_debug(struct page_cache *, int mode);
30 void pgc_flush(struct page_cache *);                            /* Write all unwritten pages */
31 void pgc_cleanup(struct page_cache *);                          /* Deallocate all unused buffers */
32 struct page *pgc_read(struct page_cache *, int fd, sh_off_t);   /* Read page and lock it */
33 struct page *pgc_get(struct page_cache *, int fd, sh_off_t);    /* Get page for writing */
34 struct page *pgc_get_zero(struct page_cache *, int fd, sh_off_t); /* ... and clear it */
35 void pgc_put(struct page_cache *, struct page *);               /* Release page */
36 void pgc_mark_dirty(struct page_cache *, struct page *);        /* Mark locked page as dirty */
37 byte *pgc_read_data(struct page_cache *, int fd, sh_off_t, uns *);      /* Partial reading */
38
39 #endif