Commits

Michał Górny committed becc809

Remove mmap() support.

This is hard to maintain and will become mostly useless with the new
libmirage API.

Comments (0)

Files changed (4)

 PKG_CHECK_MODULES([LIBMIRAGE], [libmirage gobject-2.0])
 
 AC_SYS_LARGEFILE
-AC_CHECK_FUNCS([ftruncate mmap posix_fallocate])
+AC_CHECK_FUNCS([posix_fallocate])
 
 AC_ARG_WITH([libassuan],
 	[AS_HELP_STRING([--without-libassuan],
 	return expssize * (len-sstart);
 }
 
-gboolean miragewrap_output_track(gpointer const out, const gint track_num, FILE* const f,
+gboolean miragewrap_output_track(const gint track_num, FILE* const f,
 		void (*report_progress)(gint, gint, gint)) {
-	const gboolean use_mmap = !!out;
 	GError *err = NULL;
 	gint sstart, len, bufsize;
 	MIRAGE_Track *track;
 
 	{
 		gint i, olen;
-		guint8* buf = use_mmap ? out : g_malloc(bufsize);
+		guint8* buf = g_malloc(bufsize);
 
 		len--; /* well, now it's rather 'last' */
 		if (!quiet)
 					report_progress(-1, 0, 0);
 				g_printerr("Unable to read sector %d: %s\n", i, err->message);
 				g_object_unref(track);
-				if (!use_mmap)
-					g_free(buf);
+				g_free(buf);
 				g_error_free(err);
 				return FALSE;
 			}
 				g_printerr("Data read returned %d bytes while %d was expected\n",
 						olen, bufsize);
 				g_object_unref(track);
-				if (!use_mmap)
-					g_free(buf);
+				g_free(buf);
 				return FALSE;
 			}
 
-			if (!use_mmap) {
-				if (fwrite(buf, olen, 1, f) != 1) {
-					if (!quiet)
-						report_progress(-1, 0, 0);
-					g_printerr("Write failed on sector %d%s%s", i,
-							ferror(f) ? ": " : " but error flag not set\n",
-							ferror(f) ? g_strerror(errno) : "");
-					g_object_unref(track);
-					g_free(buf);
-					return FALSE;
-				}
-			} else
-				buf += olen;
+			if (fwrite(buf, olen, 1, f) != 1) {
+				if (!quiet)
+					report_progress(-1, 0, 0);
+				g_printerr("Write failed on sector %d%s%s", i,
+						ferror(f) ? ": " : " but error flag not set\n",
+						ferror(f) ? g_strerror(errno) : "");
+				g_object_unref(track);
+				g_free(buf);
+				return FALSE;
+			}
 		}
 
 		if (!quiet) {
 			report_progress(track_num, len, len);
 			report_progress(-1, 0, 0);
 		}
-		if (!use_mmap)
-			g_free(buf);
+		g_free(buf);
 	}
 
 	g_object_unref(track);
 gboolean miragewrap_open(const gchar* const fn, const gint session_num);
 gint miragewrap_get_track_count(void);
 gsize miragewrap_get_track_size(const gint track_num);
-gboolean miragewrap_output_track(gpointer const out, const gint track_num, FILE* const f,
+gboolean miragewrap_output_track(const gint track_num, FILE* const f,
 		void (*report_progress)(gint, gint, gint));
 void miragewrap_free(void);
 
 #include <string.h>
 #include <errno.h>
 
-#if defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)
-#	include <sys/types.h>
-#	include <sys/stat.h>
-#	include <sys/mman.h>
+#ifdef HAVE_POSIX_FALLOCATE
 #	include <fcntl.h>
-#	include <unistd.h>
-#else
-#	ifdef HAVE_POSIX_FALLOCATE
-#		include <fcntl.h>
-#	endif
 #endif
 
 #ifndef NO_SYSEXITS
 gboolean quiet = FALSE;
 gboolean verbose = FALSE;
 
-#if defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)
-static gboolean force_stdio = FALSE;
-#endif
-
 static void version(const gboolean mirage) {
 	const gchar* const ver = mirage ? miragewrap_get_version() : NULL;
 	g_printerr("mirage2iso %s, using libmirage %s\n", VERSION, ver ? ver : "unknown");
 	return TRUE;
 }
 
-#if defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)
-static gint mmapio_open(const gchar* const fn, const gsize size, FILE** const f, gpointer* const out) {
-	int fd;
-	gpointer buf;
-
-	*f = fopen(fn, "w+b");
-	if (!*f) {
-		g_printerr("Unable to open output file: %s", g_strerror(errno));
-		return EX_CANTCREAT;
-	}
-
-	fd = fileno(*f);
-	if (!common_posix_filesetup(fd, size))
-		return EX_CANTCREAT;
-
-	if (ftruncate(fd, size) == -1) {
-		g_printerr("ftruncate() failed: %s", g_strerror(errno));
-
-		if (errno == EPERM || errno == EINVAL)
-			return EX_OK; /* we can't expand the file, so will try stdio */
-		else
-			return EX_IOERR;
-	}
-
-	buf = mmap(NULL, size, PROT_WRITE, MAP_SHARED, fd, 0);
-	if (buf == MAP_FAILED)
-		g_printerr("mmap() failed: %s", g_strerror(errno));
-	else
-		*out = buf;
-
-	return EX_OK;
-}
-#endif
-
 static gint stdio_open(const gchar* const fn, const gsize size, FILE** const f) {
 	if (*f)
 		*f = freopen(fn, "wb", *f);
 		return EX_CANTCREAT;
 	}
 
-#if (defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)) || defined(HAVE_POSIX_FALLOCATE)
+#if defined(HAVE_POSIX_FALLOCATE)
 	if (!common_posix_filesetup(fileno(*f), size))
 		return EX_CANTCREAT;
 #endif
 
 	gsize size = miragewrap_get_track_size(track_num);
 	FILE *f = NULL;
-	gpointer out = NULL;
 	gint ret = EX_OK;
 
 	if (size == 0)
 		if (verbose)
 			g_printerr("Using standard output stream for track %d\n", track_num);
 	} else {
-#if defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)
-		if (!force_stdio)
-			ret = mmapio_open(fn, size, &f, &out);
-#endif
-
-		if (!ret && !out)
-			ret = stdio_open(fn, size, &f);
+		ret = stdio_open(fn, size, &f);
 
 		if (ret) {
 			if (f) {
 			g_printerr("Output file '%s' open for track %d\n", fn, track_num);
 	}
 
-	if (!miragewrap_output_track(out, track_num, f, &report_progress)) {
-#if defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)
-		if (out && munmap(out, size))
-			g_printerr("munmap() failed: %s", g_strerror(errno));
-#endif
+	if (!miragewrap_output_track(track_num, f, &report_progress)) {
 		if (!use_stdout && fclose(f))
 			g_printerr("fclose() failed: %s", g_strerror(errno));
 		return EX_IOERR;
 	}
 
-#if defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)
-	if (out && munmap(out, size))
-		g_printerr("munmap() failed: %s", g_strerror(errno));
-#endif
-
 	if (!use_stdout && fclose(f)) {
 		g_printerr("fclose() failed: %s", g_strerror(errno));
 		return EX_IOERR;
 		{ "password", 'p', 0, G_OPTION_ARG_STRING, NULL, "Password for the encrypted image", "PASS" },
 		{ "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, "Disable progress reporting, output only errors", NULL },
 		{ "session", 's', 0, G_OPTION_ARG_INT, NULL, "Session to use (default: the last one)", "N" },
-		{ "stdio", 'S', 0, G_OPTION_ARG_NONE, &force_stdio, "Force using stdio instead of mmap()", NULL },
 		{ "stdout", 'c', 0, G_OPTION_ARG_NONE, NULL, "Output the image into stdout instead of a file", NULL },
 		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Increase progress reporting verbosity", NULL },
 		{ "version", 'V', 0, G_OPTION_ARG_NONE, NULL, "Print program version and exit", NULL },
 	opts[0].arg_data = &force;
 	opts[1].arg_data = &passbuf;
 	opts[3].arg_data = &session_num;
-	opts[5].arg_data = &use_stdout;
-	opts[7].arg_data = &want_version;
-	opts[8].arg_data = &newargv;
+	opts[4].arg_data = &use_stdout;
+	opts[6].arg_data = &want_version;
+	opts[7].arg_data = &newargv;
 
 	opt = g_option_context_new(NULL);
 	g_option_context_add_main_entries(opt, opts, NULL);
 	}
 
 	if (use_stdout) {
-#if defined(HAVE_FTRUNCATE) && defined(HAVE_MMAP)
-		if (force_stdio && !quiet)
-			g_printerr("--stdout already implies --stdio, no need to specify it\n");
-		else
-			force_stdio = TRUE;
-#endif
 		if (force && !quiet)
 			g_printerr("--force has no effect when --stdout in use\n");
 	}