[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 3/5] Patch lib/hivex.c to use mmap / munmap replacement





--
Unix _IS_ user friendly - it's just
selective about who its friends are!
diff --git a/lib/hivex.c b/lib/hivex.c
index 3063c45..7f483cf 100644
--- a/lib/hivex.c
+++ b/lib/hivex.c
@@ -30,7 +30,11 @@
 #include <unistd.h>
 #include <errno.h>
 #include <iconv.h>
-#include <sys/mman.h>
+#ifdef HAVE_MMAP
+  #include <sys/mman.h>
+#else
+  #include "mmap.h"
+#endif
 #include <sys/stat.h>
 #include <assert.h>
 
@@ -98,6 +102,11 @@ struct hive_h {
   /* For writing. */
   size_t endblocks;             /* Offset to next block allocation (0
                                    if not allocated anything yet). */
+
+#ifndef HAVE_MMAP
+  /* Internal data for mmap replacement */
+  void *p_winmap;
+#endif
 };
 
 /* NB. All fields are little endian. */
@@ -312,7 +321,11 @@ hivex_open (const char *filename, int flags)
   h->size = statbuf.st_size;
 
   if (!h->writable) {
+#ifdef HAVE_MMAP
     h->addr = mmap (NULL, h->size, PROT_READ, MAP_SHARED, h->fd, 0);
+#else
+    h->addr = mmap (NULL, h->size, PROT_READ, MAP_SHARED, h->fd, 0, &(h->p_winmap));
+#endif
     if (h->addr == MAP_FAILED)
       goto error;
 
@@ -534,7 +547,11 @@ hivex_open (const char *filename, int flags)
     free (h->bitmap);
     if (h->addr && h->size && h->addr != MAP_FAILED) {
       if (!h->writable)
+#ifdef HAVE_MMAP
         munmap (h->addr, h->size);
+#else
+        munmap (h->addr, h->size, &(h->p_winmap));
+#endif
       else
         free (h->addr);
     }
@@ -557,7 +574,11 @@ hivex_close (hive_h *h)
 
   free (h->bitmap);
   if (!h->writable)
+#ifdef HAVE_MMAP
     munmap (h->addr, h->size);
+#else
+    munmap (h->addr, h->size, &(h->p_winmap));
+#endif
   else
     free (h->addr);
   if (h->fd >= 0)

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]