mtools: version bump to 4.0.23

Upstream has integrated our patches, and fix a timing error in the lock
logic.  Upgrade to get them all.

BUG=chromium:933818
TEST=precq passes

Change-Id: I84d2d5362e473b72ffc3c762eadeed97922d172f
Reviewed-on: https://chromium-review.googlesource.com/1481101
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Nichols <mikenichols@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Nichols <mikenichols@chromium.org>
diff --git a/sys-fs/mtools/Manifest b/sys-fs/mtools/Manifest
index 6e2c466..a061feb 100644
--- a/sys-fs/mtools/Manifest
+++ b/sys-fs/mtools/Manifest
@@ -1 +1 @@
-DIST mtools-4.0.18.tar.bz2 420190 SHA256 59e9cf80885399c4f229e5d87e49c0c2bfeec044e1386d59fcd0b0aead6b2f85 SHA512 3981a4727aa4e2ec5c931201b236f52fcd1c9d55f888cb2fbdc5c4172402e2b229ede9a5005b972ffdad59bcb861e2fcc01404845e521116419079ae78239090 WHIRLPOOL 478ae2187e3a44ebad8f9b5fca869d80a7bcb0b55183af59bc361c2efd241e6e69be0194e18c690ff156ba808d9fc52ad2303aeff606d09b4e478f90b51186f9
+DIST mtools-4.0.23.tar.bz2 418592 BLAKE2B 442f552087a5d53ef0ead6161cdad7997dc45a3e210c2cb442a8b2ba42866152f93e4a1f5b58df8d68316168374ea034b390bcf4c607ac3a1c477c4ec5e7842c SHA512 c8c48adedc3f3e4eeafead27ce80172c9cb9690b575618842001ed16aa0011dcd2bc517882ea4bf01a73810ba151aa4b86f8ce2f97d6e8a0177d09be71a6d1ed
diff --git a/sys-fs/mtools/files/mtools-4.0.18-attr.patch b/sys-fs/mtools/files/mtools-4.0.18-attr.patch
deleted file mode 100644
index 3cd770b..0000000
--- a/sys-fs/mtools/files/mtools-4.0.18-attr.patch
+++ /dev/null
@@ -1,51 +0,0 @@
-From e8437f906ca86fd5b1cac20d240a0e114c5df7a9 Mon Sep 17 00:00:00 2001
-From: Mike Frysinger <vapier@gentoo.org>
-Date: Thu, 9 Mar 2017 16:06:54 -0800
-Subject: [PATCH] fix unused attribute in func definition
-
-UNUSED is for wrapping variable decls, not for variables in a function
-definition.  It will insert a semi-colon into the mix which makes clang
-upset:
-x86_64-cros-linux-gnu-clang  -DHAVE_CONFIG_H -DSYSCONFDIR=\"/etc/mtools\" \
-	-DCPU_x86_64 -DVENDOR_cros -DOS_linux_gnu -O2 -pipe -O2 -pipe \
-	-march=x86-64 -msse3 -g -fno-exceptions -fno-unwind-tables \
-	-fno-asynchronous-unwind-tables  -clang-syntax -Wall \
-	-fno-strict-aliasing -I.  -I.  -c mainloop.c
-mainloop.c:89:15: error: expected ')'
-int unix_loop(UNUSED(Stream_t *Stream), MainParam_t *mp, char *arg,
-              ^
-./sysincludes.h:106:47: note: expanded from macro 'UNUSED'
-                                              ^
-
-Arguably this should fail on gcc too, but it doesn't today.
-
-URL: https://crbug.com/644387
----
- mainloop.c | 4 ++--
- 1 file changed, 2 insertions(+), 2 deletions(-)
-
-diff --git a/mainloop.c b/mainloop.c
-index f5f8349f1472..69af9a80c3e4 100644
---- a/mainloop.c
-+++ b/mainloop.c
-@@ -86,7 +86,7 @@ static const char *fix_mcwd(char *ans)
- }
- 
- int unix_dir_loop(Stream_t *Stream, MainParam_t *mp); 
--int unix_loop(UNUSED(Stream_t *Stream), MainParam_t *mp, char *arg,
-+int unix_loop(Stream_t *Stream UNUSEDP, MainParam_t *mp, char *arg,
- 	      int follow_dir_link);
- 
- static int _unix_loop(Stream_t *Dir, MainParam_t *mp,
-@@ -95,7 +95,7 @@ static int _unix_loop(Stream_t *Dir, MainParam_t *mp,
- 	return unix_dir_loop(Dir, mp);
- }
- 
--int unix_loop(UNUSED(Stream_t *Stream), MainParam_t *mp,
-+int unix_loop(Stream_t *Stream UNUSEDP, MainParam_t *mp,
- 	      char *arg, int follow_dir_link)
- {
- 	int ret;
--- 
-2.12.0
-
diff --git a/sys-fs/mtools/files/mtools-4.0.18-locking.patch b/sys-fs/mtools/files/mtools-4.0.18-locking.patch
deleted file mode 100644
index 3b53c73..0000000
--- a/sys-fs/mtools/files/mtools-4.0.18-locking.patch
+++ /dev/null
@@ -1,163 +0,0 @@
-https://crbug.com/508713
-https://lists.gnu.org/archive/html/info-mtools/2016-11/msg00000.html
-
-From 04df65ed797e47da5b423c7f9aec99d82dfde400 Mon Sep 17 00:00:00 2001
-From: Mike Frysinger <vapier@chromium.org>
-Date: Wed, 7 Sep 2016 12:33:42 -0400
-Subject: [PATCH] add support for retrying device locking
-
-When running syslinux's install phase, it will run a bunch of mtools
-commands in quick succession.  If you're on a fast enough machine, it
-can often fail with errors like:
-plain floppy: device "/proc/2908/fd/3" busy (Resource temporarily unavailable):
-Cannot initialize 'S:'
-Bad target s:/ldlinux.sys
-syslinux: failed to create ldlinux.sys
-
-The issue is that after some of the mtools calls, the kernel notices
-that the fs image has changed, so it notifies userspace.  This wakes
-up udev which grabs a lock on the device to rescan it for changes
-(e.g. updated fs metadata like UUID).  The udev phase does not finish
-before syslinux fires off another mtools call which means mtools now
-fails with a locking error.
-
-You can recreate this with a simple test:
-- loop mount a fat fs image
-- open the loop device for writing
-- generate a mtools.conf pointing the file to /proc/$pid/fd/$fd
-- run mattrib && mcopy
-- see udev open/lock the loop device after mattrib runs to probe it
-- see mcopy fail because udev is still holding the lock
-
-To fix things, we teach mtools to retry its locking calls temporarily.
-If it still fails after a timeout, we abort like normal.  We also make
-this behavior configurable by adding a new global timeout option.
----
- config.c      |  2 ++
- mtools.h      |  1 +
- mtools.texi   |  7 +++++++
- mtools.tmpl.5 |  4 ++++
- plain_io.c    | 10 ++++++++++
- xdf_io.c      | 11 +++++++++++
- 6 files changed, 35 insertions(+)
-
-diff --git a/config.c b/config.c
-index f08688399d1d..ea4178452f6a 100644
---- a/config.c
-+++ b/config.c
-@@ -63,6 +63,7 @@ unsigned int mtools_no_vfat=0;
- unsigned int mtools_numeric_tail=1;
- unsigned int mtools_dotted_dir=0;
- unsigned int mtools_twenty_four_hour_clock=1;
-+unsigned int mtools_lock_timeout=30;
- unsigned int mtools_default_codepage=850;
- const char *mtools_date_string="yyyy-mm-dd";
- char *country_string=0;
-@@ -90,6 +91,7 @@ static switches_t global_switches[] = {
-       (caddr_t) &mtools_twenty_four_hour_clock, T_UINT },
-     { "MTOOLS_DATE_STRING",
-       (caddr_t) &mtools_date_string, T_STRING },
-+    { "MTOOLS_LOCK_TIMEOUT", (caddr_t) &mtools_lock_timeout, T_UINT },
-     { "DEFAULT_CODEPAGE", (caddr_t) &mtools_default_codepage, T_UINT }
- };
- 
-diff --git a/mtools.h b/mtools.h
-index ef98e942ee2c..fa8c1bdc8a1b 100644
---- a/mtools.h
-+++ b/mtools.h
-@@ -188,6 +188,7 @@ extern unsigned int mtools_ignore_short_case;
- extern unsigned int mtools_no_vfat;
- extern unsigned int mtools_numeric_tail;
- extern unsigned int mtools_dotted_dir;
-+extern unsigned int mtools_lock_timeout;
- extern unsigned int mtools_twenty_four_hour_clock;
- extern const char *mtools_date_string;
- extern unsigned int mtools_rate_0, mtools_rate_any;
-diff --git a/mtools.texi b/mtools.texi
-index 1085789c1cb6..1c7ad94d40f9 100644
---- a/mtools.texi
-+++ b/mtools.texi
-@@ -658,6 +658,10 @@ DOSEMU image files.
- @vindex MTOOLS_FAT_COMPATIBILITY
- @vindex MTOOLS_LOWER_CASE
- @vindex MTOOLS_NO_VFAT
-+@vindex MTOOLS_DOTTED_DIR
-+@vindex MTOOLS_NAME_NUMERIC_TAIL
-+@vindex MTOOLS_TWENTY_FOUR_HOUR_CLOCK
-+@vindex MTOOLS_LOCK_TIMEOUT
- @cindex FreeDOS
- 
- Global flags may be set to 1 or to 0.
-@@ -692,6 +696,9 @@ clash would have happened.
- @item MTOOLS_TWENTY_FOUR_HOUR_CLOCK
- If 1, uses the European notation for times (twenty four hour clock),
- else uses the UK/US notation (am/pm)
-+@item MTOOLS_LOCK_TIMEOUT
-+How long, in seconds, to wait for a locked device to become free.
-+Defaults to 30.
- @end table
- 
- Example:
-diff --git a/mtools.tmpl.5 b/mtools.tmpl.5
-index 565fdd7513aa..8cdaaf2ba929 100644
---- a/mtools.tmpl.5
-+++ b/mtools.tmpl.5
-@@ -106,6 +106,10 @@ clash would have happened.
- \&\fR\&\f(CWMTOOLS_TWENTY_FOUR_HOUR_CLOCK\fR\ 
- If 1, uses the European notation for times (twenty four hour clock),
- else uses the UK/US notation (am/pm)
-+.TP
-+\&\fR\&\f(CWMTOOLS_LOCK_TIMEOUT\fR\ 
-+How long, in seconds, to wait for a locked device to become free.
-+Defaults to 30.
- .PP
- Example:
- Inserting the following line into your configuration file instructs
-diff --git a/plain_io.c b/plain_io.c
-index c9d8418b8b4d..3dc035c9ce92 100644
---- a/plain_io.c
-+++ b/plain_io.c
-@@ -632,7 +632,17 @@ APIRET rc;
- #ifndef __CYGWIN__
- #ifndef OS_mingw32msvc
- 	/* lock the device on writes */
-+ retry:
- 	if (locked && lock_dev(This->fd, mode == O_RDWR, dev)) {
-+		/* retry the lock in case another system process (e.g. udev)
-+		 * has temporarily locked the device.  this happens when you
-+		 * run multiple mtools commands at once which triggers the
-+		 * system to lock/rescan/unlock. */
-+		static int retries = 0;
-+		if (errno == EAGAIN && retries++ < mtools_lock_timeout * 10) {
-+			usleep(100);
-+			goto retry;
-+		}
- 		if(errmsg)
- #ifdef HAVE_SNPRINTF
- 			snprintf(errmsg,199,
-diff --git a/xdf_io.c b/xdf_io.c
-index f0db3b3d9f38..8f64f6348f0c 100644
---- a/xdf_io.c
-+++ b/xdf_io.c
-@@ -638,7 +638,18 @@ Stream_t *XdfOpen(struct device *dev, char *name,
- 		goto exit_2;
- 
- 	/* lock the device on writes */
-+ retry:
- 	if (lock_dev(This->fd, mode == O_RDWR, dev)) {
-+		/* retry the lock in case another system process (e.g. udev)
-+		 * has temporarily locked the device.  this happens when you
-+		 * run multiple mtools commands at once which triggers the
-+		 * system to lock/rescan/unlock. */
-+		static int retries = 0;
-+		if (errno == EAGAIN && retries++ < mtools_lock_timeout * 10) {
-+			usleep(100);
-+			goto retry;
-+		}
-+
- #ifdef HAVE_SNPRINTF
- 		snprintf(errmsg,199,"xdf floppy: device \"%s\" busy:", 
- 			dev->name);
--- 
-2.9.0
-
diff --git a/sys-fs/mtools/files/mtools-4.0.18-memset.patch b/sys-fs/mtools/files/mtools-4.0.18-memset.patch
deleted file mode 100644
index cf8d724..0000000
--- a/sys-fs/mtools/files/mtools-4.0.18-memset.patch
+++ /dev/null
@@ -1,27 +0,0 @@
-From bafeabbc474a98314e8cecf42c8339e1da21fea2 Mon Sep 17 00:00:00 2001
-From: Mike Frysinger <vapier@gentoo.org>
-Date: Thu, 9 Mar 2017 16:23:19 -0800
-Subject: [PATCH] fix typo in scsi_cmd setup
-
-The memset call ends up referring to the function scsi_cmd and
-clearing its memory instead of the local my_scsi_cmd variable.
----
- scsi.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/scsi.c b/scsi.c
-index 7510edcefe95..85ff3bc3dc55 100644
---- a/scsi.c
-+++ b/scsi.c
-@@ -170,7 +170,7 @@ int scsi_cmd(int fd, unsigned char *cdb, int cmdlen, scsi_io_mode_t mode,
- 	/*
- 	** Init the command
- 	*/
--	memset(&scsi_cmd,0,sizeof(scsi_cmd));
-+	memset(&my_scsi_cmd,0,sizeof(my_scsi_cmd));
- 	my_scsi_cmd.interface_id    = 'S';
- 	my_scsi_cmd.dxfer_direction = (mode == SCSI_IO_READ)?(SG_DXFER_FROM_DEV):(SG_DXFER_TO_DEV);
- 	my_scsi_cmd.cmd_len         = cmdlen;
--- 
-2.12.0
-
diff --git a/sys-fs/mtools/metadata.xml b/sys-fs/mtools/metadata.xml
index dd09ab6..56c1244 100644
--- a/sys-fs/mtools/metadata.xml
+++ b/sys-fs/mtools/metadata.xml
@@ -5,7 +5,4 @@
 	<email>base-system@gentoo.org</email>
 	<name>Gentoo Base System</name>
 </maintainer>
-<upstream>
-	<remote-id type="cpe">cpe:/a:mtools:*</remote-id>
-</upstream>
 </pkgmetadata>
diff --git a/sys-fs/mtools/mtools-4.0.18-r2.ebuild b/sys-fs/mtools/mtools-4.0.18-r2.ebuild
deleted file mode 100644
index 4729200..0000000
--- a/sys-fs/mtools/mtools-4.0.18-r2.ebuild
+++ /dev/null
@@ -1,53 +0,0 @@
-# Copyright 1999-2017 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-
-EAPI="5"
-
-inherit flag-o-matic eutils
-
-DESCRIPTION="utilities to access MS-DOS disks from Unix without mounting them"
-HOMEPAGE="https://www.gnu.org/software/mtools/ https://savannah.gnu.org/projects/mtools"
-SRC_URI="mirror://gnu/${PN}/${P}.tar.bz2"
-
-LICENSE="GPL-3"
-SLOT="0"
-KEYWORDS="*"
-IUSE="X elibc_glibc"
-
-DEPEND="
-	!elibc_glibc? ( virtual/libiconv )
-	X? (
-		x11-libs/libICE
-		x11-libs/libXau
-		x11-libs/libSM
-		x11-libs/libX11
-		x11-libs/libXt
-	)"
-RDEPEND="${DEPEND}"
-
-src_prepare() {
-	# Don't throw errors on existing directories
-	sed -i -e "s:mkdir:mkdir -p:" mkinstalldirs || die
-
-	epatch "${FILESDIR}"/${P}-locking.patch # https://crbug.com/508713
-	epatch "${FILESDIR}"/${P}-attr.patch # https://crbug.com/644387
-	epatch "${FILESDIR}"/${P}-memset.patch
-}
-
-src_configure() {
-	# 447688
-	use elibc_glibc || append-libs iconv
-	econf \
-		--sysconfdir="${EPREFIX}"/etc/mtools \
-		$(use_with X x)
-}
-
-src_install() {
-	emake DESTDIR="${D}" install
-	dodoc README* Release.notes
-
-	insinto /etc/mtools
-	doins mtools.conf
-	# default is fine
-	sed -i -e '/^SAMPLE FILE$/s:^:#:' "${ED}"/etc/mtools/mtools.conf || die
-}
diff --git a/sys-fs/mtools/mtools-4.0.23.ebuild b/sys-fs/mtools/mtools-4.0.23.ebuild
new file mode 100644
index 0000000..d4f3dbe
--- /dev/null
+++ b/sys-fs/mtools/mtools-4.0.23.ebuild
@@ -0,0 +1,54 @@
+# Copyright 1999-2018 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI="6"
+
+inherit flag-o-matic
+
+DESCRIPTION="utilities to access MS-DOS disks from Unix without mounting them"
+HOMEPAGE="https://www.gnu.org/software/mtools/ https://savannah.gnu.org/projects/mtools"
+SRC_URI="mirror://gnu/${PN}/${P}.tar.bz2"
+
+LICENSE="GPL-3"
+SLOT="0"
+KEYWORDS="*"
+IUSE="X elibc_glibc"
+
+RDEPEND="
+	!elibc_glibc? ( virtual/libiconv )
+	X? (
+		x11-libs/libICE
+		x11-libs/libXau
+		x11-libs/libSM
+		x11-libs/libX11
+		x11-libs/libXt
+	)"
+DEPEND="${RDEPEND}"
+
+src_prepare() {
+	default
+
+	# Don't throw errors on existing directories
+	sed -i -e "s:mkdir:mkdir -p:" mkinstalldirs || die
+}
+
+src_configure() {
+	# 447688
+	use !elibc_glibc && use !elibc_musl && append-libs "-liconv"
+	local myeconfargs=(
+		--sysconfdir="${EPREFIX%/}"/etc/mtools
+		$(use_with X x)
+	)
+	econf "${myeconfargs[@]}"
+}
+
+src_install() {
+	local -a DOCS=( README* Release.notes )
+	default
+
+	insinto /etc/mtools
+	doins mtools.conf
+
+	# default is fine
+	sed -i -e '/^SAMPLE FILE$/s:^:#:' "${ED%/}"/etc/mtools/mtools.conf || die
+}