From 4d061c1b6191e7d4071240b36822c75a8550bf0f Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Wed, 2 Nov 2005 19:11:29 +0000 Subject: 2005-11-02 Christophe Fergeau * configure.ac: * src/db-artwork-writer.c: (ipod_buffer_grow_mapping), (ipod_buffer_maybe_grow): added fallback code for systems not having mremap (pretty much all non-linux systems actually) git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1136 f01d2545-417e-4e96-918e-98f8d0dbbcb6 --- ChangeLog | 7 +++++++ configure.ac | 1 + src/db-artwork-writer.c | 36 ++++++++++++++++++++++++++++++------ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index a3b1790..9503146 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-11-02 Christophe Fergeau + + * configure.ac: + * src/db-artwork-writer.c: (ipod_buffer_grow_mapping), + (ipod_buffer_maybe_grow): added fallback code for systems not having + mremap (pretty much all non-linux systems actually) + 2005-11-02 Christophe Fergeau * src/db-artwork-writer.c: (ipod_buffer_destroy): diff --git a/configure.ac b/configure.ac index 452dc2a..8642b01 100644 --- a/configure.ac +++ b/configure.ac @@ -51,6 +51,7 @@ AC_PROG_LIBTOOL AC_PROG_LN_S AC_PROG_MAKE_SET AC_PROG_INTLTOOL([0.21]) +AC_CHECK_FUNCS(mremap) PKG_CHECK_MODULES(LIBGPOD, glib-2.0 gobject-2.0) LIBGPOD_CFLAGS="$LIBGPOD_CFLAGS -Wall" diff --git a/src/db-artwork-writer.c b/src/db-artwork-writer.c index bfe3f62..d96b6fa 100644 --- a/src/db-artwork-writer.c +++ b/src/db-artwork-writer.c @@ -74,6 +74,7 @@ ipod_buffer_destroy (iPodBuffer *buffer) g_free (buffer); } + static void * ipod_buffer_get_pointer (iPodBuffer *buffer) { @@ -102,6 +103,32 @@ ipod_buffer_grow_file (struct iPodMmapBuffer *mmap_buf, off_t new_size) return 0; } + +static void * +ipod_buffer_grow_mapping (iPodBuffer *buffer, size_t size) +{ + void *new_address; +#ifdef HAVE_MREMAP + + new_address = mremap (buffer->mmap->mmap_area, buffer->mmap->size, + buffer->mmap->size + size, 0); +#else + munmap (buffer->mmap->mmap_area, buffer->mmap->size); + new_address = mmap (buffer->mmap->mmap_area, buffer->mmap->size + size, + PROT_READ | PROT_WRITE, MAP_SHARED, + buffer->mmap->fd, 0); +#endif + /* Don't allow libc to move the current mapping since this would + * force us to be very careful wrt pointers in the rest of the code + */ + if (new_address != buffer->mmap->mmap_area) { + return MAP_FAILED; + } + + return new_address; +} + + static int ipod_buffer_maybe_grow (iPodBuffer *buffer, off_t offset) { @@ -111,15 +138,12 @@ ipod_buffer_maybe_grow (iPodBuffer *buffer, off_t offset) return 0; } - /* Don't allow libc to move the current mapping since this would - * force us to be very careful wrt pointers in the rest of the code - */ - new_address = mremap (buffer->mmap->mmap_area, buffer->mmap->size, - buffer->mmap->size + IPOD_MMAP_SIZE, 0); + new_address = ipod_buffer_grow_mapping (buffer, IPOD_MMAP_SIZE); if (new_address == MAP_FAILED) { - g_print ("Failed to mremap buffer: %s\n", strerror (errno)); + g_print ("Failed to mremap buffer\n"); return -1; } + if (ipod_buffer_grow_file (buffer->mmap, buffer->mmap->size + IPOD_MMAP_SIZE) != 0) { return -1; -- cgit