]> mj.ucw.cz Git - libucw.git/commitdiff
Position caching didn't work with multiple files.
authorMartin Mares <mj@ucw.cz>
Sat, 13 Nov 1999 18:55:12 +0000 (18:55 +0000)
committerMartin Mares <mj@ucw.cz>
Sat, 13 Nov 1999 18:55:12 +0000 (18:55 +0000)
lib/pagecache.c

index 162916204c0fd3e5c6f60f96ba78a6b7afe84e4f..871babe3d91297582c97d92dd2454de8ea7ba8fc 100644 (file)
@@ -29,6 +29,7 @@ struct page_cache {
   list *hash_table;                    /* List heads corresponding to hash buckets */
 #ifndef SHERLOCK_HAVE_PREAD
   sh_off_t pos;                                /* Current position in the file */
+  int pos_fd;                          /* FD the position corresponds to */
 #endif
 };
 
@@ -54,6 +55,9 @@ pgc_open(uns page_size, uns max_pages)
   c->hash_table = xmalloc(sizeof(list) * c->hash_size);
   for(i=0; i<c->hash_size; i++)
     init_list(&c->hash_table[i]);
+#ifndef SHERLOCK_HAVE_PREAD
+  c->pos_fd = -1;
+#endif
   return c;
 }
 
@@ -106,10 +110,11 @@ flush_page(struct page_cache *c, struct page *p)
 #ifdef SHERLOCK_HAVE_PREAD
   s = pwrite(fd, p->data, c->page_size, pos);
 #else
-  if (c->pos != pos)
+  if (c->pos != pos || c->pos_fd != fd)
     sh_seek(fd, pos, SEEK_SET);
   s = write(fd, p->data, c->page_size);
-  c->pos += s;
+  c->pos = pos + s;
+  c->pos_fd = fd;
 #endif
   if (s < 0)
     die("pgc_write(%d): %m", fd);
@@ -244,10 +249,11 @@ pgc_read(struct page_cache *c, int fd, sh_off_t pos)
 #ifdef SHERLOCK_HAVE_PREAD
       s = pread(fd, p->data, c->page_size, pos);
 #else
-      if (c->pos != pos)
+      if (c->pos != pos || c->pos_fd != fd)
        sh_seek(fd, pos, SEEK_SET);
       s = read(fd, p->data, c->page_size);
-      c->pos += s;
+      c->pos = pos + s;
+      c->pos_fd = fd;
 #endif
       if (s < 0)
        die("pgc_read(%d): %m", fd);