summaryrefslogtreecommitdiff
path: root/sys-fs/mtpfs
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/mtpfs
reinit the tree, so we can have metadata
Diffstat (limited to 'sys-fs/mtpfs')
-rw-r--r--sys-fs/mtpfs/Manifest17
-rw-r--r--sys-fs/mtpfs/files/mtpfs-1.1-fix-mutex-crash.patch70
-rw-r--r--sys-fs/mtpfs/files/mtpfs-1.1-g_printf.patch10
-rw-r--r--sys-fs/mtpfs/files/mtpfs-1.1-unitialized-variable.patch12
-rw-r--r--sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0001-Use-GMutex-instead-of-GStaticMutex.patch49
-rw-r--r--sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0002-Free-rawdevices-after-opening-the-connected-device.patch28
-rw-r--r--sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0003-Allocate-additional-byte-for-trailing-null.patch55
-rw-r--r--sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0004-Use-storageid-to-access-storageArea.patch42
-rw-r--r--sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0005-Use-O_ACCMODE-to-pull-out-the-access-portion-of-the-.patch46
-rw-r--r--sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0006-Check-for-find_storage-failures.patch109
-rw-r--r--sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0007-Use-path-instead-of-fields-0-for-find_storage.patch29
-rw-r--r--sys-fs/mtpfs/metadata.xml21
-rw-r--r--sys-fs/mtpfs/mtpfs-1.0.ebuild45
-rw-r--r--sys-fs/mtpfs/mtpfs-1.1-r3.ebuild56
14 files changed, 589 insertions, 0 deletions
diff --git a/sys-fs/mtpfs/Manifest b/sys-fs/mtpfs/Manifest
new file mode 100644
index 000000000000..b7907cbc00be
--- /dev/null
+++ b/sys-fs/mtpfs/Manifest
@@ -0,0 +1,17 @@
+AUX mtpfs-1.1-fix-mutex-crash.patch 2115 SHA256 59f00dfd07219501044e72d0de22705d6e418576381775b1e511d4a38d525668 SHA512 800e1dd3d2b76503ee7ba03bbdce8cd43c6a64b4444d3f2f9b49e155b86b005c98ff2019043cbc440762ed8c4dc675a4666fe0fa4bfbc3c89971a2aeb16538e1 WHIRLPOOL d5cd84e9c920329d05bf952bd26af8e826adfffe05a53ecc4c2d505d9dc558268cd6555f81764d5d957459c7636e1538250244e6cbb6d8be3513154a55798d1a
+AUX mtpfs-1.1-g_printf.patch 166 SHA256 640bf1028c13420b7ab86644291a169275117b187ba29dd1544a94ce65a82e53 SHA512 97ba9291dbcad22c149f5edb89fd67a92b678843caa7b1fa397c9d2c6205bfc591c31696f108732eef9b20bfe767df8e33d5a356d8e975c02eb0a28f773f2006 WHIRLPOOL 5889c1edd9f3dc1e06891e9d6348c077bf5b3dfef048bc79141b574cd31f3107288d6b83735cb0ee305f43b28e72fb09ce3aa98c262b8be3cbf308fb91f9df42
+AUX mtpfs-1.1-unitialized-variable.patch 346 SHA256 869c659af32c0b999694e6f6973728c98458dd1e31630514dbaa03f35e3aaf68 SHA512 17bec46c584435ff4e636a0b66c612605cdf2ecb029c92058be4e97981758edef31fef7ec31f2e79816fa0c6c3590fe8730abadbe0cbcef825abecdd05aeae8c WHIRLPOOL 2d5e6bffc2157fea6d5aca7d80002c5dd7a6b8bef9d64ddbfd8f71e78099a19945f5da477cb6e082ac5128865a73afa0d89d0089f117526c85715b6ec1e9a33f
+AUX mtpfs-1.1-wking-patches/0001-Use-GMutex-instead-of-GStaticMutex.patch 1793 SHA256 ed917b52aee3bde917bcdca66ba7bb74446ce62b21f3bda1eaaeca2287d1a5d3 SHA512 a6277bc8a80f65dc685560510ee510367269243826d80f8ef69af5baff1ca6cefc5fec203bd96f997ab1aa111f85404a7fa4c3bffc8f3d0338f090e576773587 WHIRLPOOL 9d9964e0089337cb7c745bdecd62241a55912d0da69f88afb48a69f77d32ebf9169d8b01f4961efefdadfd5d5bcb96fa566644740eea66d2a160b14805122e86
+AUX mtpfs-1.1-wking-patches/0002-Free-rawdevices-after-opening-the-connected-device.patch 872 SHA256 855e7bc9ac9832aca1e2d0cf705394598705b84dac5efef400182a26d33b452c SHA512 281093f81abba85ab2c2cde33ffb19db330332b57366bb3a9574a2f1c0c3378ac55915b421f9ed853212849f629b0bace0ddec5890d5fe521821acdfe6a50277 WHIRLPOOL 9ac78fb8eca27c2947b3f23af2ed4a4f6abc0dd0cac956d87bc634a799719df91b35daace3dc2bd476813c6c832d08d13894dcd0c8f502f60ddcbaf560ffbec8
+AUX mtpfs-1.1-wking-patches/0003-Allocate-additional-byte-for-trailing-null.patch 2016 SHA256 c95459399a0aae4e9036594c45b0d3f37f9b710f7a8e08ca6a02dcc9522d52f7 SHA512 23d1cf5b70795c5b09d935bd3ca0f362a24f79047072068f48a61a390f3db3010602a79047034a6cb9496ba36012e238ec306bd7849086df6f8166b8f3ed0fbd WHIRLPOOL 8ae0aca19e6abd8882781186baa36105a53dd9bc2d66ef14581d13959bfdf2cee937865519c7a9f84c42aec6c49ad285a0348686fa3eaaf652489d776887553a
+AUX mtpfs-1.1-wking-patches/0004-Use-storageid-to-access-storageArea.patch 1889 SHA256 1a88c83644f2718d010e153ec020fca69be6d9abb05c3a0492d68f7eb31dec93 SHA512 4c6163f7ef4d57998060c5bb6c81e6625c92ba0d45cd4b53d0549148245d6eeab0fb95a7996e6bd2f0bcc3c1938171dbaa18c67bc5e1086be7e9b8c7328c308d WHIRLPOOL b46f8ea2b1ca48211f307339ed24585cdf32f87f74a1d04d2e6fa027b72067e93b7206360dfcd9b1aca894b8596fb0a01958d80677a70c68cb3f874d09ba9edd
+AUX mtpfs-1.1-wking-patches/0005-Use-O_ACCMODE-to-pull-out-the-access-portion-of-the-.patch 1264 SHA256 6ca8a1abc3879bfa3f705c9144afeefb4c565b959ca3c64c25563ac2c746ad71 SHA512 547c4d1d48832cf9f4735ec194350cf45786dd259788f498edd02d6801718376ca47b96a83ed72b5f660b70638a37edae1778aa99d763d6d969659c519f9c2b3 WHIRLPOOL 1608b324e3da0ef3c976eb14dfd37830fc6837c0bac4ebade9f367ed8700c052ded99426f8f23eb23f4a7eee26ba8dbcacf3e8828c3d5cdb7879fb0d5bc457c7
+AUX mtpfs-1.1-wking-patches/0006-Check-for-find_storage-failures.patch 3484 SHA256 c1c6a88aa1bd9cc06bec9dc365cff39b190a2b0ef94464add82b48b0387f323e SHA512 c43ab62c8d63d6e9c2b42de74a4a25fbb6edf87d0f46128796c7e4e61704a5ee7753fafffbcfbbbc116e180cc1a8d8a3aa8a9b4cb9d3a031ffd8d3d67e201da3 WHIRLPOOL d528a802499fb336a48f5fda8ebed556134f68932a3b31e6fd02999cfc0815dfc3db87719fd48aa37be045882dcb4f3ba9e95d86287dfd852398cebf40cbcfa8
+AUX mtpfs-1.1-wking-patches/0007-Use-path-instead-of-fields-0-for-find_storage.patch 987 SHA256 aeda7d6c23fe4f76014eeb044419e644f199eb618344147dc91d1945016a2e7f SHA512 b358816389cbde3679bd1e50505f9e68de9ffe68041dfdc48af9ae64d1453d1ce7c3ab4ee4b6260a6d42d520225ad91c6cf6cd8d05cd561e3b72d102fd6dcbdb WHIRLPOOL 6290a2b562b32d51ee01d9cf1dff4f1c24213f0171177ff60d27405106b96f2a598e6344b4a8224c23cd83f01e9b07bdcd5f4b914a12f916dfb12691323d1f06
+DIST mtpfs-1.0.tar.gz 104242 SHA256 879ccf929a7ce395af30ae81314850a5cb55a0056107477016121b9392c49c13 SHA512 af3bd067410f51bf76619a5d98a23c2a5755d2f5e2764221af145a463ab1b819332b00e358887488f2e26e29c91dcabceedf5f8637d97a9b2ba06b91281a6a4d WHIRLPOOL 074effa8933a26cf6a98af92c7629833cd0a831baae3fb3c296eda62b22477df9d43404b2452644e83ae0902e427717854ec9c4cd5fa1c9705d83b82471f3476
+DIST mtpfs-1.1.tar.gz 108329 SHA256 1baf357de16995a5f0b5bc1b6833517a77456481d861cdba70f1ce1316ce4c1d SHA512 627f1a5efa024276f58857e0cb2a2b3057ab9ba6c26d8dcba9de066f4c0efc56a5c991e000e67763b874ee9feb1d9a1e176872b56dd13b146823e8724f2052c8 WHIRLPOOL 891b84f52cbb1ab19f25a45ac73253b0fd1c0f3340d5989eca7cc33ac04c964e3a21062969e9995f90bd0b3b82ebe819854c5de2a729a3efe95d06da1d094d7b
+EBUILD mtpfs-1.0.ebuild 986 SHA256 d978f0e21d3872c39b00f4d889dee204a100c3c8e14cfe3ccd3da2d6bbcd62c1 SHA512 9069b27f5d76131502438c1bbc9d329efa5c295a4a36403e14119c887eeb5d0e5523cbfa15ed3d63b4f2af8651d15aa7cd5e435c42d765f3c80b62f2109f6c4d WHIRLPOOL 2990d51d429d94e1f9a6504da25b017a247e6201f2a0badee48ab2ec366ac549f91963df43dc1aa8a54970de8e43bc205b0481c19af1ee4b10a77036b8cca839
+EBUILD mtpfs-1.1-r3.ebuild 1269 SHA256 0688ecb3817e7998c2a99de411c667d13b9b12679dab4c5a487cee7357d995b3 SHA512 c12f11172555e927eb4335bebfe05105c6346db378a8e838fc4186947f9bf8dec66e07126401219cfdefc68d9683a108f0ca450cd4d0bb31c35d20099c159f79 WHIRLPOOL 5a2d228f34c8cd550a4c33ff0255d54628112a1c1ffb4c1ba5c4e5ac61e86421ad1d400ba8e5c63ce25a2d1a4339793ab0782caebe11be49cbb7f0e9f2546113
+MISC ChangeLog 3830 SHA256 2ece11e75a85cdcc8dd9adfc75d388aaa10d15fab19fe7a11d17c1a94a26ea03 SHA512 529ea283a16c4e114ca1b460b2b3a393570e99f83352b675768ddeef10d45034c716443fc082faba437aa16b321a092750cf23a046c42a01e87cad938e4b3ee2 WHIRLPOOL c3776d01cfe610f498288f0a1cc45512b256456105fbfda888bbb63a19950bf1c3c4a560819c6777069033b9d97951f10b5d8be71f0d1f1386a4427e3dcedc44
+MISC ChangeLog-2015 2139 SHA256 800d9a7933bbb894ddf295122f08e4d6b385764074a5a97f8d1d39029f4f9e45 SHA512 523a815ce76e756abb93fd6f1f007abc6030bd7cf3fe0acfc768e46ec9254d941e96a876fa0720f128095d6367dc2c7b62e2cb4639efdc75c75c92b13c918467 WHIRLPOOL af6d4f75d19318f56c0484982f6fdaa9cbba5d569055cc2bf5d0e96e9a1943add5a632932cff90f1f69a2cd6d514e75ea5a120fa8791739701ef2e3351cfd1e4
+MISC metadata.xml 684 SHA256 386028895870823e388ab73218c8356349f10730d3e44a589b9ba570edd223a7 SHA512 725d050ed87be3de8beff0e97178452e806261e704aaaaf523982deb2fc803c771949bee9ac0651747323b3294d584470e49e4877a3cf5e8f2301f477a543955 WHIRLPOOL 69ac7b0afdfcfb200999f35fa00840d754bdaa98367079c6ab9d854c735244d5c201565acc8fa13247af1608ea9faeb7a2bad9680e5d50006ac468e9462c23c2
diff --git a/sys-fs/mtpfs/files/mtpfs-1.1-fix-mutex-crash.patch b/sys-fs/mtpfs/files/mtpfs-1.1-fix-mutex-crash.patch
new file mode 100644
index 000000000000..b344fc44bc1e
--- /dev/null
+++ b/sys-fs/mtpfs/files/mtpfs-1.1-fix-mutex-crash.patch
@@ -0,0 +1,70 @@
+commit c30d53648a713a3f7f7711f081732aa814c6e74d
+Author: Sergei Trofimovich <siarheit@google.com>
+Date: Sat May 30 23:20:42 2015 +0100
+
+ mtpfs.c: remove all unlocking calls from mtpfs_getattr_real
+
+ Lock is already acquired/freed in the caller function 'mtpfs_getattr'.
+ Noticed when trying to use mtpfs today :)
+
+ Should also fix the same issue https://github.com/cjd/mtpfs/issues/1
+ as I get the same backtrace.
+
+ Signed-off-by: Sergei Trofimovich <siarheit@google.com>
+
+diff --git a/mtpfs.c b/mtpfs.c
+index e5e1b03..553d282 100644
+--- a/mtpfs.c
++++ b/mtpfs.c
+@@ -776,5 +776,5 @@ mtpfs_getattr_real (const gchar * path, struct stat *stbuf)
+ {
+ int ret = 0;
+- if (path==NULL) return_unlock(-ENOENT);
++ if (path==NULL) return -ENOENT;
+ memset (stbuf, 0, sizeof (struct stat));
+
+@@ -787,5 +787,5 @@ mtpfs_getattr_real (const gchar * path, struct stat *stbuf)
+ stbuf->st_mode = S_IFDIR | 0777;
+ stbuf->st_nlink = 2;
+- return_unlock(0);
++ return 0;
+ }
+
+@@ -799,5 +799,5 @@ mtpfs_getattr_real (const gchar * path, struct stat *stbuf)
+ stbuf->st_blocks = 2;
+ stbuf->st_mtime = time(NULL);
+- return_unlock(0);
++ return 0;
+ }
+ }
+@@ -808,5 +808,5 @@ mtpfs_getattr_real (const gchar * path, struct stat *stbuf)
+ stbuf->st_mode = S_IFDIR | 0777;
+ stbuf->st_nlink = 2;
+- return_unlock(0);
++ return 0;
+ }
+
+@@ -843,9 +843,9 @@ mtpfs_getattr_real (const gchar * path, struct stat *stbuf)
+ stbuf->st_blocks = 2;
+ stbuf->st_mtime = time(NULL);
+- return_unlock(0);
++ return 0;
+ }
+ playlist = playlist->next;
+ }
+- return_unlock(-ENOENT);
++ return -ENOENT;
+ }
+
+@@ -864,9 +864,9 @@ mtpfs_getattr_real (const gchar * path, struct stat *stbuf)
+ stbuf->st_mode = S_IFREG | 0777;
+ stbuf->st_mtime = file->modificationdate;
+- return_unlock(0);
++ return 0;
+ }
+ }
+
+- return_unlock(-ENOENT);
++ return -ENOENT;
+ }
+
diff --git a/sys-fs/mtpfs/files/mtpfs-1.1-g_printf.patch b/sys-fs/mtpfs/files/mtpfs-1.1-g_printf.patch
new file mode 100644
index 000000000000..21e08c848acb
--- /dev/null
+++ b/sys-fs/mtpfs/files/mtpfs-1.1-g_printf.patch
@@ -0,0 +1,10 @@
+diff --git a/mtpfs.h b/mtpfs.h
+index f9532fa..1042a3d 100644
+--- a/mtpfs.h
++++ b/mtpfs.h
+@@ -32,2 +32,5 @@
+ #endif
++#ifdef DEBUG
++#include <glib/gprintf.h>
++#endif
+
diff --git a/sys-fs/mtpfs/files/mtpfs-1.1-unitialized-variable.patch b/sys-fs/mtpfs/files/mtpfs-1.1-unitialized-variable.patch
new file mode 100644
index 000000000000..fb49624515b8
--- /dev/null
+++ b/sys-fs/mtpfs/files/mtpfs-1.1-unitialized-variable.patch
@@ -0,0 +1,12 @@
+https://bugs.gentoo.org/556690
+--- mtpfs.c.old 2015-08-04 21:56:13.080712801 +0200
++++ mtpfs.c 2015-08-04 21:20:54.822965092 +0200
+@@ -1324,7 +1324,7 @@ main (int argc, char *argv[])
+ LIBMTP_raw_device_t * rawdevices;
+ int numrawdevices;
+ LIBMTP_error_number_t err;
+- int i;
++ int i = 0;
+
+ int opt;
+ extern int optind;
diff --git a/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0001-Use-GMutex-instead-of-GStaticMutex.patch b/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0001-Use-GMutex-instead-of-GStaticMutex.patch
new file mode 100644
index 000000000000..9c1970bb59fd
--- /dev/null
+++ b/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0001-Use-GMutex-instead-of-GStaticMutex.patch
@@ -0,0 +1,49 @@
+From 39872d8ff354c40d881f416e3b8b6df911379d37 Mon Sep 17 00:00:00 2001
+From: "W. Trevor King" <wking@tremily.us>
+Date: Sun, 23 Aug 2015 12:05:35 -0700
+Subject: [PATCH 1/7] Use GMutex instead of GStaticMutex
+
+The static version was deprecated in GLib 2.32 [1], which was released
+on 2012-03-24 [2]. The difference between the two was that before
+2.32, GMutex could not be statically allocated. Since 2.32, GMutex
+can be statically allocated, so there's no reason to use GStaticMutex
+anymore.
+
+[1]: https://developer.gnome.org/glib/unstable/glib-Deprecated-Thread-APIs.html#GStaticMutex
+[2]: https://git.gnome.org/browse/glib/tag/?h=glib-2-32&id=2.32.0
+---
+ mtpfs.c | 4 ++--
+ mtpfs.h | 2 +-
+ 2 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/mtpfs.c b/mtpfs.c
+index 553d282..286cd24 100644
+--- a/mtpfs.c
++++ b/mtpfs.c
+@@ -28,8 +28,8 @@ static void dump_mtp_error()
+ #define dump_mtp_error()
+ #endif
+
+-#define enter_lock(a...) do { DBG("lock"); DBG(a); g_static_mutex_lock(&device_lock); } while(0)
+-#define return_unlock(a) do { DBG("return unlock"); g_static_mutex_unlock(&device_lock); return a; } while(0)
++#define enter_lock(a...) do { DBG("lock"); DBG(a); g_mutex_lock(&device_lock); } while(0)
++#define return_unlock(a) do { DBG("return unlock"); g_mutex_unlock(&device_lock); return a; } while(0)
+
+ void
+ free_files(LIBMTP_file_t *filelist)
+diff --git a/mtpfs.h b/mtpfs.h
+index 789eccb..f812ea6 100644
+--- a/mtpfs.h
++++ b/mtpfs.h
+@@ -73,7 +73,7 @@ static GSList *lostfiles = NULL;
+ static GSList *myfiles = NULL;
+ static LIBMTP_playlist_t *playlists = NULL;
+ static gboolean playlists_changed = FALSE;
+-static GStaticMutex device_lock = G_STATIC_MUTEX_INIT;
++static GMutex device_lock = G_STATIC_MUTEX_INIT;
+
+
+ #endif /* _MTPFS_H_ */
+--
+2.5.3
+
diff --git a/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0002-Free-rawdevices-after-opening-the-connected-device.patch b/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0002-Free-rawdevices-after-opening-the-connected-device.patch
new file mode 100644
index 000000000000..616ae1230ae6
--- /dev/null
+++ b/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0002-Free-rawdevices-after-opening-the-connected-device.patch
@@ -0,0 +1,28 @@
+From 2fb900e9e915f9ec6ac2f233255a0a527da164c2 Mon Sep 17 00:00:00 2001
+From: "W. Trevor King" <wking@tremily.us>
+Date: Sun, 23 Aug 2015 21:59:45 -0700
+Subject: [PATCH 2/7] Free rawdevices after opening the connected device
+
+Avoid leaking the raw-device memory. For a similar example in the
+libmtp source, see LIBMTP_Get_First_Device [1].
+
+[1]: https://sourceforge.net/p/libmtp/code/ci/libmtp-1-1-9/tree/src/libmtp.c#l1690
+---
+ mtpfs.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/mtpfs.c b/mtpfs.c
+index 286cd24..bdd5f46 100644
+--- a/mtpfs.c
++++ b/mtpfs.c
+@@ -1390,6 +1390,7 @@ main (int argc, char *argv[])
+
+ fprintf(stdout, "Attempting to connect device\n");
+ device = LIBMTP_Open_Raw_Device(&rawdevices[i]);
++ free (rawdevices);
+ if (device == NULL) {
+ fprintf(stderr, "Unable to open raw device %d\n", i);
+ return 1;
+--
+2.5.3
+
diff --git a/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0003-Allocate-additional-byte-for-trailing-null.patch b/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0003-Allocate-additional-byte-for-trailing-null.patch
new file mode 100644
index 000000000000..20cff00e32ee
--- /dev/null
+++ b/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0003-Allocate-additional-byte-for-trailing-null.patch
@@ -0,0 +1,55 @@
+From 3929648c83910a45a37e84b4d3e5316631ce7c6b Mon Sep 17 00:00:00 2001
+From: "W. Trevor King" <wking@tremily.us>
+Date: Mon, 24 Aug 2015 00:08:24 -0700
+Subject: [PATCH 3/7] Allocate additional byte for trailing null
+
+These variables needs a byte for every character in the path and an
+additional trailing null, but the length returned by strlen excludes
+the trailing null.
+---
+ mtpfs.c | 8 ++++----
+ 1 file changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/mtpfs.c b/mtpfs.c
+index bdd5f46..e31acd9 100644
+--- a/mtpfs.c
++++ b/mtpfs.c
+@@ -416,7 +416,7 @@ parse_path (const gchar * path)
+ LIBMTP_folder_t *folder;
+ gchar **fields;
+ gchar *directory;
+- directory = (gchar *) g_malloc (strlen (path));
++ directory = (gchar *) g_malloc (strlen (path) + 1);
+ directory = strcpy (directory, "");
+ fields = g_strsplit (path, "/", -1);
+ res = -ENOENT;
+@@ -488,7 +488,7 @@ mtpfs_release (const char *path, struct fuse_file_info *fi)
+ gchar *filename = g_strdup("");
+ gchar **fields;
+ gchar *directory;
+- directory = (gchar *) g_malloc (strlen (path));
++ directory = (gchar *) g_malloc (strlen (path) + 1);
+ directory = strcpy (directory, "/");
+ fields = g_strsplit (path, "/", -1);
+ int i;
+@@ -1089,7 +1089,7 @@ mtpfs_mkdir_real (const char *path, mode_t mode)
+ gchar **fields;
+ gchar *directory;
+
+- directory = (gchar *) g_malloc (strlen (path));
++ directory = (gchar *) g_malloc (strlen (path) + 1);
+ directory = strcpy (directory, "/");
+ fields = g_strsplit (path, "/", -1);
+ int i;
+@@ -1168,7 +1168,7 @@ mtpfs_rename (const char *oldname, const char *newname)
+ gchar *filename;
+ gchar **fields;
+ gchar *directory;
+- directory = (gchar *) g_malloc (strlen (newname));
++ directory = (gchar *) g_malloc (strlen (newname) + 1);
+ directory = strcpy (directory, "/");
+ fields = g_strsplit (newname, "/", -1);
+ int i;
+--
+2.5.3
+
diff --git a/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0004-Use-storageid-to-access-storageArea.patch b/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0004-Use-storageid-to-access-storageArea.patch
new file mode 100644
index 000000000000..755e2902c0f1
--- /dev/null
+++ b/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0004-Use-storageid-to-access-storageArea.patch
@@ -0,0 +1,42 @@
+From 89ec461a73a2479fb5766b6b65a44e6e5b699b94 Mon Sep 17 00:00:00 2001
+From: "W. Trevor King" <wking@tremily.us>
+Date: Mon, 24 Aug 2015 00:34:41 -0700
+Subject: [PATCH 4/7] Use storageid to access storageArea
+
+'i' is indexing playlist->tracks here, and we don't want to look in a
+sequential storage areas for each track.
+
+I've also added a null-folder check. I'm not sure if -ENOENT is the
+right code for "we can't find the parent directory in the storage area
+that contains the child", but it's the only non-success code that
+mtpfs_getattr_real returned before this commit. And returning
+anything is probably better than segfaulting when we try and
+dereference folder with 'folder->parent_id'. I've added a logging
+message to help debug things when we do get a null folder.
+---
+ mtpfs.c | 9 ++++++++-
+ 1 file changed, 8 insertions(+), 1 deletion(-)
+
+diff --git a/mtpfs.c b/mtpfs.c
+index e31acd9..9f924a9 100644
+--- a/mtpfs.c
++++ b/mtpfs.c
+@@ -832,7 +832,14 @@ mtpfs_getattr_real (const gchar * path, struct stat *stbuf)
+ filesize = filesize + strlen(file->filename) + 2;
+ while (parent_id != 0) {
+ check_folders();
+- folder = LIBMTP_Find_Folder(storageArea[i].folders,parent_id);
++ folder =
++ LIBMTP_Find_Folder
++ (storageArea[storageid].folders, parent_id);
++ if (folder == NULL) {
++ DBG ("could not find %d in storage-area %d",
++ parent_id, storageid);
++ return -ENOENT;
++ }
+ parent_id = folder->parent_id;
+ filesize = filesize + strlen(folder->name) + 1;
+ }
+--
+2.5.3
+
diff --git a/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0005-Use-O_ACCMODE-to-pull-out-the-access-portion-of-the-.patch b/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0005-Use-O_ACCMODE-to-pull-out-the-access-portion-of-the-.patch
new file mode 100644
index 000000000000..03bfb4c4709b
--- /dev/null
+++ b/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0005-Use-O_ACCMODE-to-pull-out-the-access-portion-of-the-.patch
@@ -0,0 +1,46 @@
+From 00bd3be1310fb36a3b2eddc931eb48c89744b2b4 Mon Sep 17 00:00:00 2001
+From: "W. Trevor King" <wking@tremily.us>
+Date: Mon, 24 Aug 2015 01:31:17 -0700
+Subject: [PATCH 5/7] Use O_ACCMODE to pull out the access portion of the open
+ flags
+
+Following [1]. I'm using cp from GNU Coreutils 8.23, and it's setting
+my flags to 32769 (O_WRONLY + 0x8000).
+
+[1]: http://www.gnu.org/software/libc/manual/html_node/Access-Modes.html#index-0_005fACCMODE
+---
+ mtpfs.c | 18 ++++++++++++------
+ 1 file changed, 12 insertions(+), 6 deletions(-)
+
+diff --git a/mtpfs.c b/mtpfs.c
+index 9f924a9..a82d479 100644
+--- a/mtpfs.c
++++ b/mtpfs.c
+@@ -949,12 +949,18 @@ mtpfs_open (const gchar * path, struct fuse_file_info *fi)
+ if (item_id < 0)
+ return_unlock(-ENOENT);
+
+- if (fi->flags == O_RDONLY) {
+- DBG("read");
+- } else if (fi->flags == O_WRONLY) {
+- DBG("write");
+- } else if (fi->flags == O_RDWR) {
+- DBG("rdwrite");
++ switch (fi->flags & O_ACCMODE) {
++ case O_RDONLY:
++ DBG ("read");
++ break;
++ case O_WRONLY:
++ DBG ("write");
++ break;
++ case O_RDWR:
++ DBG("rdwrite");
++ break;
++ default:
++ DBG ("unexpected access mode: %d", fi->flags & O_ACCMODE);
+ }
+
+ int storageid;
+--
+2.5.3
+
diff --git a/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0006-Check-for-find_storage-failures.patch b/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0006-Check-for-find_storage-failures.patch
new file mode 100644
index 000000000000..84fb3464227c
--- /dev/null
+++ b/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0006-Check-for-find_storage-failures.patch
@@ -0,0 +1,109 @@
+From 8860e176c8fb38006dc58516a5e5d9a1aab7be49 Mon Sep 17 00:00:00 2001
+From: "W. Trevor King" <wking@tremily.us>
+Date: Mon, 24 Aug 2015 01:07:49 -0700
+Subject: [PATCH 6/7] Check for find_storage failures
+
+Instead of just blindly using storageArea[-1].
+---
+ mtpfs.c | 28 ++++++++++++++++++++++++++++
+ 1 file changed, 28 insertions(+)
+
+diff --git a/mtpfs.c b/mtpfs.c
+index a82d479..3fe17b8 100644
+--- a/mtpfs.c
++++ b/mtpfs.c
+@@ -317,6 +317,7 @@ find_storage(const gchar * path)
+ }
+ }
+ }
++ DBG ("could not find storage for %s", path);
+ return -1;
+ }
+
+@@ -422,6 +423,9 @@ parse_path (const gchar * path)
+ res = -ENOENT;
+ int storageid;
+ storageid = find_storage(path);
++ if (storageid < 0) {
++ return res;
++ }
+ for (i = 0; fields[i] != NULL; i++) {
+ if (strlen (fields[i]) > 0) {
+ if (fields[i + 1] != NULL) {
+@@ -495,6 +499,9 @@ mtpfs_release (const char *path, struct fuse_file_info *fi)
+ int parent_id = 0;
+ int storageid;
+ storageid = find_storage(fields[0]);
++ if (storageid < 0) {
++ return_unlock (-ENOENT);
++ }
+ for (i = 0; fields[i] != NULL; i++) {
+ if (strlen (fields[i]) > 0) {
+ if (fields[i + 1] == NULL) {
+@@ -715,6 +722,9 @@ mtpfs_readdir (const gchar * path, void *buf, fuse_fill_dir_t filler,
+ int i;
+ int storageid = -1;
+ storageid=find_storage(path);
++ if (storageid < 0) {
++ return_unlock (-ENOENT);
++ }
+ // Get folder listing.
+ int folder_id = 0;
+ if (strcmp (path, "/") != 0) {
+@@ -812,6 +822,9 @@ mtpfs_getattr_real (const gchar * path, struct stat *stbuf)
+
+ int storageid;
+ storageid=find_storage(path);
++ if (storageid < 0) {
++ return -ENOENT;
++ }
+
+ if (g_ascii_strncasecmp (path, "/Playlists",10) == 0) {
+ LIBMTP_playlist_t *playlist;
+@@ -965,6 +978,9 @@ mtpfs_open (const gchar * path, struct fuse_file_info *fi)
+
+ int storageid;
+ storageid=find_storage(path);
++ if (storageid < 0) {
++ return_unlock (-ENOENT);
++ }
+ FILE *filetmp = tmpfile ();
+ int tmpfile = fileno (filetmp);
+ if (tmpfile != -1) {
+@@ -1096,6 +1112,9 @@ mtpfs_mkdir_real (const char *path, mode_t mode)
+ item = g_slist_find_custom (myfiles, path, (GCompareFunc) strcmp);
+ int item_id = parse_path (path);
+ int storageid = find_storage(path);
++ if (storageid < 0) {
++ return_unlock (-ENOENT);
++ }
+ if ((item == NULL) && (item_id < 0)) {
+ // Split path and find parent_id
+ gchar *filename = g_strdup("");
+@@ -1161,6 +1180,9 @@ mtpfs_rmdir (const char *path)
+ return_unlock(0);
+ }
+ int storageid=find_storage(path);
++ if (storageid < 0) {
++ return_unlock (-ENOENT);
++ }
+ folder_id = lookup_folder_id (storageArea[storageid].folders, (gchar *) path, NULL);
+ if (folder_id < 0)
+ return_unlock(-ENOENT);
+@@ -1223,7 +1245,13 @@ mtpfs_rename (const char *oldname, const char *newname)
+ LIBMTP_file_t *file;
+
+ int storageid_old=find_storage(oldname);
++ if (storageid_old < 0) {
++ return_unlock (-ENOENT);
++ }
+ int storageid_new=find_storage(newname);
++ if (storageid_new < 0) {
++ return_unlock (-ENOENT);
++ }
+ if (strcmp (oldname, "/") != 0) {
+ folder_id = lookup_folder_id (storageArea[storageid_old].folders, (gchar *) oldname, NULL);
+ }
+--
+2.5.3
+
diff --git a/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0007-Use-path-instead-of-fields-0-for-find_storage.patch b/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0007-Use-path-instead-of-fields-0-for-find_storage.patch
new file mode 100644
index 000000000000..b52439162cfd
--- /dev/null
+++ b/sys-fs/mtpfs/files/mtpfs-1.1-wking-patches/0007-Use-path-instead-of-fields-0-for-find_storage.patch
@@ -0,0 +1,29 @@
+From 76ff042e1334fdbef9803ea71b5d8b1d380efd7e Mon Sep 17 00:00:00 2001
+From: "W. Trevor King" <wking@tremily.us>
+Date: Mon, 24 Aug 2015 20:58:26 -0700
+Subject: [PATCH 7/7] Use 'path' instead of 'fields[0]' for find_storage
+
+When my path is '/Internal storage/Music/...', fields[0] will be an
+empty string, and find_storage will fail to find a storage area that
+matches that empty string. All of our other find_storage calls use
+the full path, so follow that example here.
+---
+ mtpfs.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/mtpfs.c b/mtpfs.c
+index 3fe17b8..291f49d 100644
+--- a/mtpfs.c
++++ b/mtpfs.c
+@@ -498,7 +498,7 @@ mtpfs_release (const char *path, struct fuse_file_info *fi)
+ int i;
+ int parent_id = 0;
+ int storageid;
+- storageid = find_storage(fields[0]);
++ storageid = find_storage(path);
+ if (storageid < 0) {
+ return_unlock (-ENOENT);
+ }
+--
+2.5.3
+
diff --git a/sys-fs/mtpfs/metadata.xml b/sys-fs/mtpfs/metadata.xml
new file mode 100644
index 000000000000..cc200ab69553
--- /dev/null
+++ b/sys-fs/mtpfs/metadata.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <maintainer type="person">
+ <email>voyageur@gentoo.org</email>
+ <name>Bernard Cafarelli</name>
+ </maintainer>
+ <maintainer type="person">
+ <email>slyfox@gentoo.org</email>
+ <name>Sergei Trofimovich</name>
+ </maintainer>
+
+ <longdescription>
+ MTPfs is a FUSE filesystem that supports reading and writing from any
+ MTP device, as supported by libmtp. MTPfs includes extra features such
+ as playlist and meta information support for MP3 players.
+ </longdescription>
+ <use>
+ <flag name="mad">Enable handling of MP3's metadata</flag>
+ </use>
+</pkgmetadata>
diff --git a/sys-fs/mtpfs/mtpfs-1.0.ebuild b/sys-fs/mtpfs/mtpfs-1.0.ebuild
new file mode 100644
index 000000000000..0968c88c8653
--- /dev/null
+++ b/sys-fs/mtpfs/mtpfs-1.0.ebuild
@@ -0,0 +1,45 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=4
+
+DESCRIPTION="A FUSE filesystem providing access to MTP devices"
+HOMEPAGE="https://www.adebenham.com/mtpfs/"
+SRC_URI="https://www.adebenham.com/debian/${P}.tar.gz"
+
+LICENSE="GPL-3"
+SLOT="0"
+KEYWORDS="amd64 x86"
+IUSE="debug"
+
+DEPEND="dev-libs/glib:2
+ media-libs/libid3tag
+ media-libs/libmad
+ media-libs/libmtp
+ sys-fs/fuse"
+RDEPEND="${DEPEND}"
+
+DOCS=(AUTHORS NEWS README)
+
+src_prepare() {
+ sed -e "/#include <string.h>/ a\
+ #include <stdlib.h>" -i mtpfs.h id3read.c || die #implicit
+}
+
+src_configure() {
+ econf $(use_enable debug)
+}
+
+pkg_postinst() {
+ einfo "To mount your MTP device, issue:"
+ einfo " /usr/bin/mtpfs <mountpoint>"
+ echo
+ einfo "To unmount your MTP device, issue:"
+ einfo " /usr/bin/fusermount -u <mountpoint>"
+
+ if use debug; then
+ echo
+ einfo "You have enabled debugging output."
+ einfo "Please make sure you run mtpfs with the -d flag."
+ fi
+}
diff --git a/sys-fs/mtpfs/mtpfs-1.1-r3.ebuild b/sys-fs/mtpfs/mtpfs-1.1-r3.ebuild
new file mode 100644
index 000000000000..5fb9a655bf96
--- /dev/null
+++ b/sys-fs/mtpfs/mtpfs-1.1-r3.ebuild
@@ -0,0 +1,56 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit eutils
+
+DESCRIPTION="A FUSE filesystem providing access to MTP devices"
+HOMEPAGE="https://www.adebenham.com/mtpfs/"
+SRC_URI="https://www.adebenham.com/files/mtp/${P}.tar.gz"
+
+LICENSE="GPL-3"
+SLOT="0"
+KEYWORDS="~amd64 ~x86"
+IUSE="debug mad"
+
+RDEPEND="dev-libs/glib:2
+ >=media-libs/libmtp-1.1.2
+ sys-fs/fuse
+ mad? (
+ media-libs/libid3tag
+ media-libs/libmad
+ )"
+DEPEND="${RDEPEND}
+ virtual/pkgconfig"
+
+DOCS=(AUTHORS NEWS README)
+
+src_prepare() {
+ sed -e "/#include <string.h>/ a\
+ #include <stdlib.h>" -i mtpfs.h id3read.c || die #implicit
+
+ epatch "${FILESDIR}"/${P}-fix-mutex-crash.patch
+ epatch "${FILESDIR}"/${P}-unitialized-variable.patch
+ epatch "${FILESDIR}"/${P}-wking-patches/*.patch
+ epatch "${FILESDIR}"/${P}-g_printf.patch
+}
+
+src_configure() {
+ econf $(use_enable debug) \
+ $(use_enable mad)
+}
+
+pkg_postinst() {
+ einfo "To mount your MTP device, issue:"
+ einfo " /usr/bin/mtpfs <mountpoint>"
+ echo
+ einfo "To unmount your MTP device, issue:"
+ einfo " /usr/bin/fusermount -u <mountpoint>"
+
+ if use debug; then
+ echo
+ einfo "You have enabled debugging output."
+ einfo "Please make sure you run mtpfs with the -d flag."
+ fi
+}