From c041eb7ccb55c36d9cded3c55133c0cf9321c801 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Mon, 23 Jun 2008 14:50:05 +0000 Subject: [PATCH] ebl Add mmap unmmap implementation for win32 and tokyodbm git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@7222 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/win32/compat/compat.cpp | 64 ++++++++++++++++++++++++++++++ bacula/src/win32/compat/compat.h | 10 +++++ bacula/technotes-2.5 | 2 + 3 files changed, 76 insertions(+) diff --git a/bacula/src/win32/compat/compat.cpp b/bacula/src/win32/compat/compat.cpp index 2583ad2904..9a6fde9694 100644 --- a/bacula/src/win32/compat/compat.cpp +++ b/bacula/src/win32/compat/compat.cpp @@ -2349,6 +2349,70 @@ file_dup2(int, int) } #endif +/* + * Emulation of mmap and unmmap for tokyo dbm + */ +void *mmap(void *start, size_t length, int prot, int flags, + int fd, off_t offset) +{ + DWORD fm_access = 0; + DWORD mv_access = 0; + HANDLE h; + HANDLE mv; + + if (length == 0) { + return MAP_FAILED; + } + if (!fd) { + return MAP_FAILED; + } + + if (flags & PROT_WRITE) { + fm_access |= PAGE_READWRITE; + } else if (flags & PROT_READ) { + fm_access |= PAGE_READONLY; + } + + if (flags & PROT_READ) { + mv_access |= FILE_MAP_READ; + } + if (flags & PROT_WRITE) { + mv_access |= FILE_MAP_WRITE; + } + + h = CreateFileMapping((HANDLE)_get_osfhandle (fd), + NULL /* security */, + fm_access, + 0 /* MaximumSizeHigh */, + 0 /* MaximumSizeLow */, + NULL /* name of the file mapping object */); + + if (!h || h == INVALID_HANDLE_VALUE) { + return MAP_FAILED; + } + + mv = MapViewOfFile(h, mv_access, + 0 /* offset hi */, + 0 /* offset lo */, + length); + CloseHandle(h); + + if (!mv || mv == INVALID_HANDLE_VALUE) { + return MAP_FAILED; + } + + return (void *) mv; +} + +int munmap(void *start, size_t length) +{ + if (!start) { + return -1; + } + UnmapViewOfFile(start); + return 0; +} + #ifdef HAVE_MINGW /* syslog function, added by Nicolas Boichat */ void openlog(const char *ident, int option, int facility) {} diff --git a/bacula/src/win32/compat/compat.h b/bacula/src/win32/compat/compat.h index 01802706ac..1a1be74b74 100644 --- a/bacula/src/win32/compat/compat.h +++ b/bacula/src/win32/compat/compat.h @@ -379,4 +379,14 @@ int win32_ftruncate(int fd, int64_t length); #undef ftruncate #define ftruncate win32_ftruncate +/* mmap implementation for tokyodbm */ +#define PROT_WRITE 0x2 /* Page can be written. */ +#define PROT_READ 0x1 /* page can be read */ +#define MAP_SHARED 0x01 /* Share changes. */ +#define MAP_FAILED ((void *) -1) + +void *mmap(void *start, size_t length, int prot, int flags, + int fd, off_t offset); +int munmap(void *start, size_t length); + #endif /* __COMPAT_H_ */ diff --git a/bacula/technotes-2.5 b/bacula/technotes-2.5 index 7d4f3ca543..f8bfd299c7 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -30,6 +30,8 @@ vtape driver General: +23Jun08 +ebl Add mmap/unmmap implementation for tokyodbm under win32 kes Make first step toward eliminating globals from config scanning. Also should be a workaround for FORTIFY_SOURCE GNU C bug -- fixes bug #1042. -- 2.39.5