diff -ur rrdtool-trunk-3/src/rrd.h rrdtool-trunk-4/src/rrd.h
--- rrdtool-trunk-3/src/rrd.h	2008-10-15 16:35:33.000000000 +0100
+++ rrdtool-trunk-4/src/rrd.h	2008-10-15 16:41:25.000000000 +0100
@@ -79,16 +79,21 @@
 
 /* information about an rrd file */
     typedef struct rrd_file_t {
-        int       fd;   /* file descriptor if this rrd file */
-        char     *file_start;   /* start address of an open rrd file */
         off_t     header_len;   /* length of the header of this rrd file */
         off_t     file_len; /* total size of the rrd file */
         off_t     pos;  /* current pos in file */
+        void      *pvt;
+    } rrd_file_t;
+
+/* information used for the conventional file access methods */
+    typedef struct rrd_simple_file_t {
+        int       fd;  /* file descriptor of this rrd file */
 #ifdef HAVE_MMAP
+        char     *file_start;   /* start address of an open rrd file */
         int       mm_prot;
         int       mm_flags;
 #endif
-    } rrd_file_t;
+    } rrd_simple_file_t;
 
 /* rrd info interface */
     typedef struct rrd_blob_t {
diff -ur rrdtool-trunk-3/src/rrd_open.c rrdtool-trunk-4/src/rrd_open.c
--- rrdtool-trunk-3/src/rrd_open.c	2008-10-15 16:35:50.000000000 +0100
+++ rrdtool-trunk-4/src/rrd_open.c	2008-10-15 17:14:23.000000000 +0100
@@ -38,7 +38,7 @@
 		rrd_set_error(#dst " malloc"); \
 		goto out_nullify_head; \
 	} \
-        got = read (rrd_file->fd, dst, wanted); \
+        got = read (rrd_simple_file->fd, dst, wanted); \
 	if (got != wanted) { \
 		rrd_set_error("short read while reading header " #dst); \
                 goto out_nullify_head; \
@@ -76,6 +76,7 @@
     off_t     offset = 0;
     struct stat statb;
     rrd_file_t *rrd_file = NULL;
+    rrd_simple_file_t *rrd_simple_file = NULL;
     off_t     newfile_size = 0;
 
     if ((rdwr & RRD_CREAT) && (rdwr & RRD_CREAT_SETSIZE)) {
@@ -93,6 +94,14 @@
     }
     memset(rrd_file, 0, sizeof(rrd_file_t));
 
+    rrd_file->pvt = malloc(sizeof(rrd_simple_file_t));
+    if(rrd_file->pvt == NULL) {
+        rrd_set_error("allocating rrd_simple_file for '%s'", file_name);
+        return NULL;
+    }
+    memset(rrd_file->pvt, 0, sizeof(rrd_simple_file_t));
+    rrd_simple_file = (rrd_simple_file_t *)rrd_file->pvt;
+
 #ifdef DEBUG
     if ((rdwr & (RRD_READONLY | RRD_READWRITE)) ==
         (RRD_READONLY | RRD_READWRITE)) {
@@ -103,16 +112,16 @@
 #endif
 
 #ifdef HAVE_MMAP
-    rrd_file->mm_prot = PROT_READ;
-    rrd_file->mm_flags = 0;
+    rrd_simple_file->mm_prot = PROT_READ;
+    rrd_simple_file->mm_flags = 0;
 #endif
 
     if (rdwr & RRD_READONLY) {
         flags |= O_RDONLY;
 #ifdef HAVE_MMAP
-        rrd_file->mm_flags = MAP_PRIVATE;
+        rrd_simple_file->mm_flags = MAP_PRIVATE;
 # ifdef MAP_NORESERVE
-        rrd_file->mm_flags |= MAP_NORESERVE;  /* readonly, so no swap backing needed */
+        rrd_simple_file->mm_flags |= MAP_NORESERVE;  /* readonly, so no swap backing needed */
 # endif
 #endif
     } else {
@@ -120,8 +129,8 @@
             mode |= S_IWUSR;
             flags |= O_RDWR;
 #ifdef HAVE_MMAP
-            rrd_file->mm_flags = MAP_SHARED;
-            rrd_file->mm_prot |= PROT_WRITE;
+            rrd_simple_file->mm_flags = MAP_SHARED;
+            rrd_simple_file->mm_prot |= PROT_WRITE;
 #endif
         }
         if (rdwr & RRD_CREAT) {
@@ -130,24 +139,24 @@
     }
     if (rdwr & RRD_READAHEAD) {
 #ifdef MAP_POPULATE
-        rrd_file->mm_flags |= MAP_POPULATE;   /* populate ptes and data */
+        rrd_simple_file->mm_flags |= MAP_POPULATE;   /* populate ptes and data */
 #endif
 #if defined MAP_NONBLOCK
-        rrd_file->mm_flags |= MAP_NONBLOCK;   /* just populate ptes */
+        rrd_simple_file->mm_flags |= MAP_NONBLOCK;   /* just populate ptes */
 #endif
     }
 #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
     flags |= O_BINARY;
 #endif
 
-    if ((rrd_file->fd = open(file_name, flags, mode)) < 0) {
+    if ((rrd_simple_file->fd = open(file_name, flags, mode)) < 0) {
         rrd_set_error("opening '%s': %s", file_name, rrd_strerror(errno));
         goto out_free;
     }
 
     /* Better try to avoid seeks as much as possible. stat may be heavy but
      * many concurrent seeks are even worse.  */
-    if (newfile_size == 0 && ((fstat(rrd_file->fd, &statb)) < 0)) {
+    if (newfile_size == 0 && ((fstat(rrd_simple_file->fd, &statb)) < 0)) {
         rrd_set_error("fstat '%s': %s", file_name, rrd_strerror(errno));
         goto out_close;
     }
@@ -155,22 +164,22 @@
         rrd_file->file_len = statb.st_size;
     } else {
         rrd_file->file_len = newfile_size;
-        lseek(rrd_file->fd, newfile_size - 1, SEEK_SET);
-        write(rrd_file->fd, "\0", 1);   /* poke */
-        lseek(rrd_file->fd, 0, SEEK_SET);
+        lseek(rrd_simple_file->fd, newfile_size - 1, SEEK_SET);
+        write(rrd_simple_file->fd, "\0", 1);   /* poke */
+        lseek(rrd_simple_file->fd, 0, SEEK_SET);
     }
 #ifdef HAVE_POSIX_FADVISE
     /* In general we need no read-ahead when dealing with rrd_files.
        When we stop reading, it is highly unlikely that we start up again.
        In this manner we actually save time and diskaccess (and buffer cache).
        Thanks to Dave Plonka for the Idea of using POSIX_FADV_RANDOM here. */
-    posix_fadvise(rrd_file->fd, 0, 0, POSIX_FADV_RANDOM);
+    posix_fadvise(rrd_simple_file->fd, 0, 0, POSIX_FADV_RANDOM);
 #endif
 
 /*
         if (rdwr & RRD_READWRITE)
         {
-           if (setvbuf((rrd_file->fd),NULL,_IONBF,2)) {
+           if (setvbuf((rrd_simple_file->fd),NULL,_IONBF,2)) {
                   rrd_set_error("failed to disable the stream buffer\n");
                   return (-1);
            }
@@ -180,11 +189,11 @@
 #ifdef HAVE_MMAP
     if(rrd_file->file_len == 0 && (rdwr & RRD_CREAT))
     {
-        rrd_file->file_start = NULL;
+        rrd_simple_file->file_start = NULL;
         goto out_done;
     }
-    data = mmap(0, rrd_file->file_len, rrd_file->mm_prot, rrd_file->mm_flags,
-                rrd_file->fd, offset);
+    data = mmap(0, rrd_file->file_len, rrd_simple_file->mm_prot, rrd_simple_file->mm_flags,
+                rrd_simple_file->fd, offset);
 
     /* lets see if the first read worked */
     if (data == MAP_FAILED) {
@@ -192,7 +201,7 @@
                       rrd_strerror(errno));
         goto out_close;
     }
-    rrd_file->file_start = data;
+    rrd_simple_file->file_start = data;
     if (rdwr & RRD_CREAT) {
         memset(data, DNAN, newfile_size - 1);
         goto out_done;
@@ -311,8 +320,9 @@
     if (data != MAP_FAILED)
       munmap(data, rrd_file->file_len);
 #endif
-    close(rrd_file->fd);
+    close(rrd_simple_file->fd);
   out_free:
+    free(rrd_file->pvt);
     free(rrd_file);
     return NULL;
 }
@@ -325,6 +335,8 @@
     rrd_file_t *rrd_file,
     char *mark)
 {
+    rrd_simple_file_t *rrd_simple_file;
+    rrd_simple_file = (rrd_simple_file_t *)rrd_file->pvt;
 #ifdef HAVE_MMAP
     /* pretty print blocks in core */
     off_t     off;
@@ -336,7 +348,7 @@
     vec = malloc(off);
     if (vec != NULL) {
         memset(vec, 0, off);
-        if (mincore(rrd_file->file_start, rrd_file->file_len, vec) == 0) {
+        if (mincore(rrd_simple_file->file_start, rrd_file->file_len, vec) == 0) {
             int       prev;
             unsigned  is_in = 0, was_in = 0;
 
@@ -370,16 +382,18 @@
  * returns 0 on success
  */
 int rrd_lock(
-    rrd_file_t *file)
+    rrd_file_t *rrd_file)
 {
     int       rcstat;
+    rrd_simple_file_t *rrd_simple_file;
+    rrd_simple_file = (rrd_simple_file_t *)rrd_file->pvt;
 
     {
 #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
         struct _stat st;
 
-        if (_fstat(file->fd, &st) == 0) {
-            rcstat = _locking(file->fd, _LK_NBLCK, st.st_size);
+        if (_fstat(rrd_simple_file->fd, &st) == 0) {
+            rcstat = _locking(rrd_simple_file->fd, _LK_NBLCK, st.st_size);
         } else {
             rcstat = -1;
         }
@@ -391,7 +405,7 @@
         lock.l_start = 0;   /* start of file */
         lock.l_whence = SEEK_SET;   /* end of file */
 
-        rcstat = fcntl(file->fd, F_SETLK, &lock);
+        rcstat = fcntl(rrd_simple_file->fd, F_SETLK, &lock);
 #endif
     }
 
@@ -404,6 +418,7 @@
     rrd_file_t *rrd_file,
     rrd_t *rrd)
 {
+    rrd_simple_file_t *rrd_simple_file = (rrd_simple_file_t *)rrd_file->pvt;
 #if defined USE_MADVISE || defined HAVE_POSIX_FADVISE
     off_t dontneed_start;
     off_t rra_start;
@@ -432,12 +447,12 @@
                        * rrd->stat_head->ds_cnt * sizeof(rrd_value_t));
         if (active_block > dontneed_start) {
 #ifdef USE_MADVISE
-            madvise(rrd_file->file_start + dontneed_start,
+            madvise(rrd_simple_file->file_start + dontneed_start,
                     active_block - dontneed_start - 1, MADV_DONTNEED);
 #endif
 /* in linux at least only fadvise DONTNEED seems to purge pages from cache */
 #ifdef HAVE_POSIX_FADVISE
-            posix_fadvise(rrd_file->fd, dontneed_start,
+            posix_fadvise(rrd_simple_file->fd, dontneed_start,
                           active_block - dontneed_start - 1,
                           POSIX_FADV_DONTNEED);
 #endif
@@ -457,11 +472,11 @@
 
     if (dontneed_start < rrd_file->file_len) {
 #ifdef USE_MADVISE
-	    madvise(rrd_file->file_start + dontneed_start,
+	    madvise(rrd_simple_file->file_start + dontneed_start,
 		    rrd_file->file_len - dontneed_start, MADV_DONTNEED);
 #endif
 #ifdef HAVE_POSIX_FADVISE
-	    posix_fadvise(rrd_file->fd, dontneed_start,
+	    posix_fadvise(rrd_simple_file->fd, dontneed_start,
 			  rrd_file->file_len - dontneed_start,
 			  POSIX_FADV_DONTNEED);
 #endif
@@ -481,21 +496,24 @@
     rrd_file_t *rrd_file)
 {
     int       ret;
+    rrd_simple_file_t *rrd_simple_file;
+    rrd_simple_file = (rrd_simple_file_t *)rrd_file->pvt;
 
 #ifdef HAVE_MMAP
-    ret = msync(rrd_file->file_start, rrd_file->file_len, MS_ASYNC);
+    ret = msync(rrd_simple_file->file_start, rrd_file->file_len, MS_ASYNC);
     if (ret != 0)
         rrd_set_error("msync rrd_file: %s", rrd_strerror(errno));
-    if(rrd_file->file_start != NULL)
+    if(rrd_simple_file->file_start != NULL)
     {
-        ret = munmap(rrd_file->file_start, rrd_file->file_len);
+        ret = munmap(rrd_simple_file->file_start, rrd_file->file_len);
         if (ret != 0)
             rrd_set_error("munmap rrd_file: %s", rrd_strerror(errno));
     }
 #endif
-    ret = close(rrd_file->fd);
+    ret = close(rrd_simple_file->fd);
     if (ret != 0)
         rrd_set_error("closing file: %s", rrd_strerror(errno));
+    free(rrd_file->pvt);
     free(rrd_file);
     rrd_file = NULL;
     return ret;
@@ -510,6 +528,8 @@
     int whence)
 {
     off_t     ret = 0;
+    rrd_simple_file_t *rrd_simple_file;
+    rrd_simple_file = (rrd_simple_file_t *)rrd_file->pvt;
 
 #ifdef HAVE_MMAP
     if (whence == SEEK_SET)
@@ -519,7 +539,7 @@
     else if (whence == SEEK_END)
         rrd_file->pos = rrd_file->file_len + off;
 #else
-    ret = lseek(rrd_file->fd, off, whence);
+    ret = lseek(rrd_simple_file->fd, off, whence);
     if (ret < 0)
         rrd_set_error("lseek: %s", rrd_strerror(errno));
     rrd_file->pos = ret;
@@ -546,6 +566,7 @@
     void *buf,
     size_t count)
 {
+    rrd_simple_file_t *rrd_simple_file = (rrd_simple_file_t *)rrd_file->pvt;
 #ifdef HAVE_MMAP
     size_t    _cnt = count;
     ssize_t   _surplus;
@@ -561,16 +582,16 @@
     if (_cnt == 0)
         return 0;       /* EOF */
     /* mmap should have been done already, but check just in case ... */
-    if(rrd_file->file_start == NULL)
+    if(rrd_simple_file->file_start == NULL)
         return -1;
-    buf = memcpy(buf, rrd_file->file_start + rrd_file->pos, _cnt);
+    buf = memcpy(buf, rrd_simple_file->file_start + rrd_file->pos, _cnt);
 
     rrd_file->pos += _cnt;  /* mimmic read() semantics */
     return _cnt;
 #else
     ssize_t   ret;
 
-    ret = read(rrd_file->fd, buf, count);
+    ret = read(rrd_simple_file->fd, buf, count);
     if (ret > 0)
         rrd_file->pos += ret;   /* mimmic read() semantics */
     return ret;
@@ -579,7 +600,7 @@
 
 
 /* Write count bytes from buffer buf to the current position
- * rrd_file->pos of rrd_file->fd.
+ * rrd_file->pos of rrd_simple_file->fd.
  * Returns the number of bytes written or <0 on error.  */
 
 ssize_t rrd_write(
@@ -587,6 +608,7 @@
     const void *buf,
     size_t count)
 {
+    rrd_simple_file_t *rrd_simple_file = (rrd_simple_file_t *)rrd_file->pvt;
 #ifdef HAVE_MMAP
     int old_size = rrd_file->file_len;
     int new_size = rrd_file->file_len;
@@ -599,30 +621,30 @@
     {
         new_size = rrd_file->pos + count; 
         rrd_file->file_len = new_size;
-        lseek(rrd_file->fd, new_size - 1, SEEK_SET);
-        write(rrd_file->fd, "\0", 1);   /* poke */
-        lseek(rrd_file->fd, 0, SEEK_SET);
-        if(rrd_file->file_start == NULL)
+        lseek(rrd_simple_file->fd, new_size - 1, SEEK_SET);
+        write(rrd_simple_file->fd, "\0", 1);   /* poke */
+        lseek(rrd_simple_file->fd, 0, SEEK_SET);
+        if(rrd_simple_file->file_start == NULL)
         {
-            rrd_file->file_start = mmap(0, new_size, rrd_file->mm_prot, 
-                rrd_file->mm_flags, rrd_file->fd, 0);
+            rrd_simple_file->file_start = mmap(0, new_size, rrd_simple_file->mm_prot, 
+                rrd_simple_file->mm_flags, rrd_simple_file->fd, 0);
         }
         else
-            munmap(rrd_file->file_start, old_size);
-            rrd_file->file_start = mmap(0, new_size, rrd_file->mm_prot, 
-                rrd_file->mm_flags, rrd_file->fd, 0);
+            munmap(rrd_simple_file->file_start, old_size);
+            rrd_simple_file->file_start = mmap(0, new_size, rrd_simple_file->mm_prot, 
+                rrd_simple_file->mm_flags, rrd_simple_file->fd, 0);
 
-        if (rrd_file->file_start == MAP_FAILED) {
+        if (rrd_simple_file->file_start == MAP_FAILED) {
             rrd_set_error("m(re)maping file : %s", 
                       rrd_strerror(errno));
             return -1;
         }
     }
-    memcpy(rrd_file->file_start + rrd_file->pos, buf, count);
+    memcpy(rrd_simple_file->file_start + rrd_file->pos, buf, count);
     rrd_file->pos += count;
     return count;       /* mimmic write() semantics */
 #else
-    ssize_t   _sz = write(rrd_file->fd, buf, count);
+    ssize_t   _sz = write(rrd_simple_file->fd, buf, count);
 
     if (_sz > 0)
         rrd_file->pos += _sz;
@@ -636,8 +658,10 @@
 void rrd_flush(
     rrd_file_t *rrd_file)
 {
-    if (fdatasync(rrd_file->fd) != 0) {
-        rrd_set_error("flushing fd %d: %s", rrd_file->fd,
+    rrd_simple_file_t *rrd_simple_file;
+    rrd_simple_file = (rrd_simple_file_t *)rrd_file->pvt;
+    if (fdatasync(rrd_simple_file->fd) != 0) {
+        rrd_set_error("flushing fd %d: %s", rrd_simple_file->fd,
                       rrd_strerror(errno));
     }
 }
