summaryrefslogtreecommitdiff
path: root/sys-fs/mtools
diff options
context:
space:
mode:
authorV3n3RiX <venerix@redcorelinux.org>2017-10-09 18:53:29 +0100
committerV3n3RiX <venerix@redcorelinux.org>2017-10-09 18:53:29 +0100
commit4f2d7949f03e1c198bc888f2d05f421d35c57e21 (patch)
treeba5f07bf3f9d22d82e54a462313f5d244036c768 /sys-fs/mtools
reinit the tree, so we can have metadata
Diffstat (limited to 'sys-fs/mtools')
-rw-r--r--sys-fs/mtools/Manifest13
-rw-r--r--sys-fs/mtools/files/mtools-4.0.18-attr.patch51
-rw-r--r--sys-fs/mtools/files/mtools-4.0.18-locking.patch163
-rw-r--r--sys-fs/mtools/files/mtools-4.0.18-memset.patch27
-rw-r--r--sys-fs/mtools/metadata.xml8
-rw-r--r--sys-fs/mtools/mtools-4.0.15.ebuild43
-rw-r--r--sys-fs/mtools/mtools-4.0.17.ebuild44
-rw-r--r--sys-fs/mtools/mtools-4.0.18-r2.ebuild53
-rw-r--r--sys-fs/mtools/mtools-4.0.18.ebuild49
9 files changed, 451 insertions, 0 deletions
diff --git a/sys-fs/mtools/Manifest b/sys-fs/mtools/Manifest
new file mode 100644
index 000000000000..3d06e59c9885
--- /dev/null
+++ b/sys-fs/mtools/Manifest
@@ -0,0 +1,13 @@
+AUX mtools-4.0.18-attr.patch 1804 SHA256 61c9a15bfe60e0f934250324adf16280e138a68524a169b8202aa3623c43e046 SHA512 45bc3d5baa37c634b8f97d55251a7dec2f7062515529c0dec65572826ff2d7673f189c544fa73d164156823cd3ae78bcb664b3fb22e5eac34198fdfe45c9e244 WHIRLPOOL ccfd956d4379aa2d0c618dba8f8add113cfd24b6c16556c23f45d42915c1b4dcb057cc070a9e682837d88fbad8b49bc131706f3b82be1528159c2a3fc17db7ea
+AUX mtools-4.0.18-locking.patch 5744 SHA256 e7ba375d863662652fc830f37cc96da5ef12595e85189662f8e6903e523b020c SHA512 0698b5c5f5d4c22f3439a835c3bb6f73a90c3030073f3497fa04a8e29241af867f664f253b37299d69ca043858b55e7290aaab1fa6f751084a52e7812cae4170 WHIRLPOOL a67d766585a55ded8631242944c6d410aae796ad0037b125902c01c7bcfac3b63b8f71cb56cd331031ded1efbf75775664e83ca8e4b56a9a3f14fce33a91f031
+AUX mtools-4.0.18-memset.patch 877 SHA256 7c0fdb68507bc3242fe38f603f49ea253cb82cad7e6a85dd1cc8e0cc41c26413 SHA512 1e8d697c1cd98a7fedaed96e6019b6af96bf5ed6633f50f7c45649555a27727d93ba828e2852f23fb633832902bdb93c23afacd7022c72adf5c4a146f5b8a1a8 WHIRLPOOL e9b6d3dc3af8079857a252b0c4b1a061fbec9e15c4592436b003a54bcb576c0a2698aa864a3fc49790db88942303fade40d3ae062d1f4359995918660566105c
+DIST mtools-4.0.15.tar.bz2 386339 SHA256 290defca107cc183a17c98d3f7d00db02228b724084a2a818f1dd6ea86973899 SHA512 0ee4d060ffb95c0e5b0e859634bee50e056aaa7d3917fdbcc4fd8ca86710b1d93ef252bec588d5c010f2fb6081853e76338b966e4584e510728be4ec3113e0da WHIRLPOOL c4ab4cb1f0b1fd4c3540ef81379d3976590f1433135ab75b1ec2de4e0e219ba33fdbb5778289f76d3eea90d27259ae9145a4152942abda8f7057f38ba0e9e65d
+DIST mtools-4.0.17.tar.bz2 412310 SHA256 0ecc358e30a72d215b1d4c625b27e67121cd6f6075370dfb791ef2a8b980ecb6 SHA512 0ad44bc9d7088d8a0edc648ac81fb4c9ea522c8d7561717f02475514186081050c283c0393bf32358b95ea60554713c26ea7e06074041d3fbdcaf642aec2e1ce WHIRLPOOL ce220067850ac91cbe8a2687b82be4afe2cf3f3f1a3444bb3e02c6ac2ffa470dc7825c2e0c5fc72c9010839d956f8a1351b4944194336a38c38ce0ef37387327
+DIST mtools-4.0.18.tar.bz2 420190 SHA256 59e9cf80885399c4f229e5d87e49c0c2bfeec044e1386d59fcd0b0aead6b2f85 SHA512 3981a4727aa4e2ec5c931201b236f52fcd1c9d55f888cb2fbdc5c4172402e2b229ede9a5005b972ffdad59bcb861e2fcc01404845e521116419079ae78239090 WHIRLPOOL 478ae2187e3a44ebad8f9b5fca869d80a7bcb0b55183af59bc361c2efd241e6e69be0194e18c690ff156ba808d9fc52ad2303aeff606d09b4e478f90b51186f9
+EBUILD mtools-4.0.15.ebuild 832 SHA256 106993c4d46e483b7cefda3feb1309b40a00561a270df7678a347de13e65e0ae SHA512 9a108e56611864710598fb7d624305aa2f3efd4cf85dad7ee9a7a71f57645caf9604fc42295ae4c1f66fbe30bfb2494ba199b84b0336ac2e976e2b9be33c1ecf WHIRLPOOL 6aabc3fef49d9569eac7f19052319790480cf66b723cd17bef777d3d658efe5cb650072bd0726247430f9165eeefbb522e049264e160f4b7e7134a5521f2f205
+EBUILD mtools-4.0.17.ebuild 901 SHA256 9f38cee1d1f6fdc39419ed76768f0bb34f3b5d62a14929eb57121b5da8462fdd SHA512 047da0fb150a4e9196bafc7731f4d6ea5456284923b64f9735c56f554c5692b677e4a16c7af91d2feec76fd2dd04b3d97617a03289bb5c38533782991c354246 WHIRLPOOL 0b752df1623fd9cc26e918f0167b8989bcede8d3f12854b57688f19fb86911d35da790126f7f54f80db5d08d9dcc6c36213ce975158a25c4b99035f1e1ce6eb3
+EBUILD mtools-4.0.18-r2.ebuild 1315 SHA256 197ee7df9ce5d6bbd2066e9bae0cf18e72fa14d5c0a1bcd597d172b18c559548 SHA512 d194c1458418d5f4acc5e3d421c1896f0346ffee846b157e8971b0f7109e83ec737e84f9b7c2927ce28e3341c1721d3e83acd273ba16b6da156c3d93055dae9c WHIRLPOOL 60221a6a46b15941fa44a02bfe798ad19b30b0fc0765839658a7c08bd48ee412f4f7398a57ce30d888b66066ce41dfa1cc62b63fc452dc7802937736e1b4a65d
+EBUILD mtools-4.0.18.ebuild 1080 SHA256 2def1e66b13a10bbec05c56e092331e015720b29223b66c7232b5542affbf86e SHA512 f777db7ae901411b303fe9259ad151b16145f1576fbf71429cf6242b1e10b9347943fdd38de3c995f95c34d1150d33e6377f276fde6b3a6c364a82eacf1e96d4 WHIRLPOOL a231600180859c2c4d50ae0894177ab9fbb2c519dad10bb2ac7e5c66936cd4bff57f35d890a5f1252ff8386dcaece7b90af2a70fdf020699ccec5dccef02b68a
+MISC ChangeLog 3625 SHA256 3bca4f88d84904ddfadc9c44580a38a4516f81c6e139d15bf371df7e91a02ecb SHA512 b3f6cc620016f2c624a812932f6721bdabfbf2ffebfe021e5bd2bb7e43cf88ca72e03fac06aad9e660f7d85da56a2c6958f3d0adbbd670b867e4bf71bc311a9d WHIRLPOOL 56ee7c04a8d2ca2d5eed374c45cc9687fbe2513ce50696ac955b4538f41fef4d07951101fbeac8d942520414e898c49b18e9509fa09f504473ff865230d639ef
+MISC ChangeLog-2015 7242 SHA256 66998bd20162d56feacd37164b855394b865804476b1d20770c1d2ac53757070 SHA512 208317962e12cd4d58c7c4bfdf6616e0a4032038c93befb83980898c0b73305c8cd84d5a6c708905d782124991fe0ce7d7668ff5eecd62edbfb22b94b53d74af WHIRLPOOL 30735130f290305f405ae8ebef1a97a768633285e50888a854e90acd2bb9df608ced8dbf498df9d35f72214ce6d3f8ef3daaec2d905f526feaa53d83b9c873ae
+MISC metadata.xml 253 SHA256 d82c33ef453113a5c1ebe250dcba373c22934a69b0a86c6ab15a5ca589c25b91 SHA512 54a9069aeb4165d2dff3d473c8001bc51613aac9dff3f7f5e9971a9891a737a31511ffa11cbd523febe581ac1d9de2bdf2f40410f0c4239138f2ccca3ef15555 WHIRLPOOL e5aee23acff864609953a1e4de768f0e4aef704b44c53c021f28573e1ca5c99f1a46d92935ecec2449f7b4419a36d8373127d0ecfa8d7bae72d835e1839eb3f8
diff --git a/sys-fs/mtools/files/mtools-4.0.18-attr.patch b/sys-fs/mtools/files/mtools-4.0.18-attr.patch
new file mode 100644
index 000000000000..3cd770be8bde
--- /dev/null
+++ b/sys-fs/mtools/files/mtools-4.0.18-attr.patch
@@ -0,0 +1,51 @@
+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
new file mode 100644
index 000000000000..3b53c73c645c
--- /dev/null
+++ b/sys-fs/mtools/files/mtools-4.0.18-locking.patch
@@ -0,0 +1,163 @@
+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
new file mode 100644
index 000000000000..cf8d724406df
--- /dev/null
+++ b/sys-fs/mtools/files/mtools-4.0.18-memset.patch
@@ -0,0 +1,27 @@
+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
new file mode 100644
index 000000000000..56c124413057
--- /dev/null
+++ b/sys-fs/mtools/metadata.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+<maintainer type="project">
+ <email>base-system@gentoo.org</email>
+ <name>Gentoo Base System</name>
+</maintainer>
+</pkgmetadata>
diff --git a/sys-fs/mtools/mtools-4.0.15.ebuild b/sys-fs/mtools/mtools-4.0.15.ebuild
new file mode 100644
index 000000000000..ac63b4f3c75a
--- /dev/null
+++ b/sys-fs/mtools/mtools-4.0.15.ebuild
@@ -0,0 +1,43 @@
+# Copyright 1999-2013 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI="2"
+
+inherit autotools
+
+DESCRIPTION="utilities to access MS-DOS disks from Unix without mounting them"
+HOMEPAGE="http://mtools.linux.lu/"
+SRC_URI="mirror://gnu/${PN}/${P}.tar.bz2"
+
+LICENSE="GPL-3"
+SLOT="0"
+KEYWORDS="alpha amd64 arm hppa ppc ppc64 sparc x86"
+IUSE="X"
+
+DEPEND="
+ X? (
+ x11-libs/libICE
+ x11-libs/libXau
+ x11-libs/libSM
+ x11-libs/libX11
+ x11-libs/libXt
+ )"
+RDEPEND="${DEPEND}"
+
+src_prepare() {
+ eautoconf #341443
+}
+
+src_configure() {
+ econf \
+ --sysconfdir=/etc/mtools \
+ $(use_with X x)
+}
+
+src_install() {
+ emake -j1 DESTDIR="${D}" install || die
+ insinto /etc/mtools
+ doins mtools.conf || die
+ dosed '/^SAMPLE FILE$/s:^:#:' /etc/mtools/mtools.conf # default is fine
+ dodoc README* Release.notes
+}
diff --git a/sys-fs/mtools/mtools-4.0.17.ebuild b/sys-fs/mtools/mtools-4.0.17.ebuild
new file mode 100644
index 000000000000..126e15a993df
--- /dev/null
+++ b/sys-fs/mtools/mtools-4.0.17.ebuild
@@ -0,0 +1,44 @@
+# Copyright 1999-2011 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI="4"
+
+DESCRIPTION="utilities to access MS-DOS disks from Unix without mounting them"
+HOMEPAGE="http://mtools.linux.lu/"
+SRC_URI="mirror://gnu/${PN}/${P}.tar.bz2"
+
+LICENSE="GPL-3"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ppc ~ppc64 ~sparc ~x86"
+IUSE="X"
+
+DEPEND="
+ 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
+}
+
+src_configure() {
+ econf \
+ --sysconfdir=/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:^:#:' "${D}"/etc/mtools/mtools.conf || die
+}
diff --git a/sys-fs/mtools/mtools-4.0.18-r2.ebuild b/sys-fs/mtools/mtools-4.0.18-r2.ebuild
new file mode 100644
index 000000000000..b24e3026f32b
--- /dev/null
+++ b/sys-fs/mtools/mtools-4.0.18-r2.ebuild
@@ -0,0 +1,53 @@
+# 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="~alpha ~amd64 ~arm ~hppa ~ppc ~ppc64 ~sparc ~x86 ~x64-macos ~x64-solaris"
+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 && use !elibc_musl && append-libs "-liconv"
+ 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.18.ebuild b/sys-fs/mtools/mtools-4.0.18.ebuild
new file mode 100644
index 000000000000..20531ff7b2d8
--- /dev/null
+++ b/sys-fs/mtools/mtools-4.0.18.ebuild
@@ -0,0 +1,49 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI="4"
+
+inherit flag-o-matic
+
+DESCRIPTION="utilities to access MS-DOS disks from Unix without mounting them"
+HOMEPAGE="http://mtools.linux.lu/"
+SRC_URI="mirror://gnu/${PN}/${P}.tar.bz2"
+
+LICENSE="GPL-3"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ppc ~ppc64 ~sparc ~x86 ~x64-macos ~x64-solaris"
+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
+}
+
+src_configure() {
+ # 447688
+ use !elibc_glibc && use !elibc_musl && append-libs "-liconv"
+ 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
+}