X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Fpagecache.c;h=57abfeea3beb50193e798d7118cd713dc9e57ffc;hb=157acec25f2e60c76607edc3d62cf23fe47f4efe;hp=b51054afce508f9c8e9ebf097a363c4e15a4aac6;hpb=86220fcbc5f0c7c17416719103a1eecbfa020db1;p=libucw.git diff --git a/lib/pagecache.c b/lib/pagecache.c index b51054af..57abfeea 100644 --- a/lib/pagecache.c +++ b/lib/pagecache.c @@ -1,19 +1,19 @@ /* * Sherlock Library -- File Page Cache * - * (c) 1999 Martin Mares + * (c) 1999--2000 Martin Mares */ +#include "lib/lib.h" +#include "lib/pagecache.h" +#include "lib/lfs.h" + #include #include #include #include #include -#include "lib.h" -#include "pagecache.h" -#include "lfs.h" - struct page_cache { list free_pages; /* LRU queue of free non-dirty pages */ list locked_pages; /* List of locked pages (starts with dirty ones) */ @@ -39,10 +39,9 @@ struct page_cache { struct page_cache * pgc_open(uns page_size, uns max_pages) { - struct page_cache *c = xmalloc(sizeof(struct page_cache)); + struct page_cache *c = xmalloc_zero(sizeof(struct page_cache)); uns i; - bzero(c, sizeof(*c)); init_list(&c->free_pages); init_list(&c->locked_pages); init_list(&c->dirty_pages); @@ -65,8 +64,8 @@ pgc_close(struct page_cache *c) ASSERT(EMPTY_LIST(c->locked_pages)); ASSERT(EMPTY_LIST(c->dirty_pages)); ASSERT(EMPTY_LIST(c->free_pages)); - free(c->hash_table); - free(c); + xfree(c->hash_table); + xfree(c); } static void @@ -103,7 +102,7 @@ flush_page(struct page_cache *c, struct page *p) ASSERT(p->flags & PG_FLAG_DIRTY); #ifdef SHERLOCK_HAVE_PREAD - s = pwrite(p->fd, p->data, c->page_size, p->pos); + s = sh_pwrite(p->fd, p->data, c->page_size, p->pos); #else if (c->pos != p->pos || c->pos_fd != p->fd) sh_seek(p->fd, p->pos, SEEK_SET); @@ -114,7 +113,7 @@ flush_page(struct page_cache *c, struct page *p) if (s < 0) die("pgc_write(%d): %m", p->fd); if (s != (int) c->page_size) - die("pgc_write(%d): incomplete page (only %d of %d)", s, c->page_size); + die("pgc_write(%d): incomplete page (only %d of %d)", p->fd, s, c->page_size); p->flags &= ~PG_FLAG_DIRTY; c->stat_write++; } @@ -251,7 +250,7 @@ pgc_cleanup(struct page_cache *c) rem_node(&p->hn); c->free_count--; c->total_count--; - free(p); + xfree(p); } ASSERT(!c->free_count); } @@ -280,7 +279,7 @@ pgc_read(struct page_cache *c, int fd, sh_off_t pos) { c->stat_miss++; #ifdef SHERLOCK_HAVE_PREAD - s = pread(fd, p->data, c->page_size, pos); + s = sh_pread(fd, p->data, c->page_size, pos); #else if (c->pos != pos || c->pos_fd != fd) sh_seek(fd, pos, SEEK_SET); @@ -291,7 +290,7 @@ pgc_read(struct page_cache *c, int fd, sh_off_t pos) if (s < 0) die("pgc_read(%d): %m", fd); if (s != (int) c->page_size) - die("pgc_read(%d): incomplete page (only %d of %d)", s, c->page_size); + die("pgc_read(%d): incomplete page (only %d of %d)", p->fd, s, c->page_size); p->flags |= PG_FLAG_VALID; } return p;