Package: jmtpfs
Version: 0.5-2

Hello,
I encountered the following bug in jmtpfs, while connected to Android:

After doing mount I have:
   mntpoint/Internal Storage
and
   mntpoint/SD Card

If I create a file at the top of one of the directories-volumes,
like "touch mntpoint/SD Card/test", the one
which is not "primary" under Android, will not have the file created.
Instead it will be adopted by the primary one.

So
1/ files can clash due to same filename:
       touch mntpoint/Internal Storage/a; touch mntpoint/SD Card/a
2/ the file will not be written on the sdcard (unless it's primary)


I found the following patch to fix it. I also found the relevant code  Android.

It seems the "coordinates" of a file (transfered over mtp protocol) are
(storageId, parent, name).
Files at the top have the parent as 0, yet Android expects 0xFFFFFFFF.

So while getMetadata(), in src/MtpFolder.cpp, indeed does:
        if (folderId==0)
        {
                folderId = 0xFFFFFFFF;

the wrong  MtpFolder::CreateFile(const std::string& name) does not.


The Android part does the test for if (parent == MTP_PARENT_ROOT):
https://code.google.com/p/android-source-browsing/source/browse/media/mtp/MtpServer.cpp?repo=platform--frameworks--base&name=android-4.2.2_r1.2&r=3762c311729fe9f3af085c14c5c1fb471d994c03#824
(look for "// special case the root")


diff --git a/src/MtpFolder.cpp b/src/MtpFolder.cpp
index 0fff40b..abd1ef2 100644
--- a/src/MtpFolder.cpp
+++ b/src/MtpFolder.cpp
@@ -123,12 +123,15 @@ void MtpFolder::mkdir(const std::string& name)



+#define MTP_PARENT_ROOT 0xFFFFFFFF
 void MtpFolder::CreateFile(const std::string& name)
 {
        if (name.length() > MAX_MTP_NAME_LENGTH)
                throw MtpNameTooLong();

-       NewLIBMTPFile newFile(name, m_folderId, m_storageId);
+       NewLIBMTPFile newFile(name,
+                              (m_folderId == 0)?MTP_PARENT_ROOT:m_folderId,
+                              m_storageId);
        TemporaryFile empty;
        m_device.SendFile(newFile, empty.FileNo());
        m_cache.clearItem(((LIBMTP_file_t*)newFile)->item_id);


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to