Media Transfer Protocol MTP (SOLVED)

Using applications, configuring, problems
Message
Author
tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#21 Post by tempestuous »

can8v wrote:my initial idea is that I could use udev rules to detect my Nexus 7 connection via USB, when it is detected then run a script that will mount the Nexus 7 via go-mtpfs.
That's a very good idea, and I would like to help you ... but the inner workings of udev are "black magic" to me.
can8v wrote:Even if I figure out this udev rule, this is not very universal and would require anybody doing this to customize the script ...
... and change the udev rule to detect their device instead of a Nexus 7
Let me say that, in principle, what you need is some form of udev rule which will identify any/all MTP devices which may be connected to Puppy, then launch the appropriate go-mtpfs commands.
What may assist you is the MTP udev rule from gnomad2, which I now attach. As you can see, it contains a long list of USB device ID's of known MTP devices.

But here's another idea you may like - what about a bash wrapper script which does the following:
- launches go-mtpfs
- launches ROX, to the directory specified by go-mtpfs (/root/MTP by my suggestion)
- the wrapper script determines when ROX is closed, then ...
- unmounts the device (with fusermount)
- displays a message - probably via gtkdialog, saying something like
"your MTP device has been unmounted, and is now safe to disconnect"
can8v wrote:

Code: Select all

go-mtpfs "Nexus 7" &
BE CAREFUL ... the expression which follows "go-mtpfs" defines the directory where the (FUSE) mountpoint is located - so you have specified a Linux directory which includes a space - and that's problematic in Linux.
Attachments
69-libmtp.rules.gz
(9.3 KiB) Downloaded 713 times

gcmartin

#22 Post by gcmartin »

Thanks everyone and especially @Tempestuous

This is great as PUPPY distro can now be smarter with this additional to the arcenal. This makes for a great opportunity to provide backup for Android information on Puppy, not to mention the read-write convenience.

Puppy, with the changes added over the last year along with the advances and OOTB functionality being provided by the 64bit developers has changed the positioning of what a PUP is capable of when any user boots to the desktop. And, its all OOTB if this can find its way into the Puppy build process, WOOF-CE and the PUP builders are aware of its availability.

1 year ago, few had smart-devices. Today, most of us have some kind of smart-device in close proximity.

This can assist transfer of program files/apps to the connected smart-devices; not to mention the potential development-test cycle for Android apps built on a PUP. All being done over the same wire charging the handheld device.

THANKS!!!

User avatar
Ted Dog
Posts: 3965
Joined: Wed 14 Sep 2005, 02:35
Location: Heart of Texas

#23 Post by Ted Dog »

I will be driving to internet service just to download this.. :lol: no I m not kidding.
The cup of coffee from a giftcard is just bonus...

can8v
Posts: 586
Joined: Sat 15 Jul 2006, 08:20
Location: Yuba City, CA
Contact:

#24 Post by can8v »

tempestuous wrote:
can8v wrote:my initial idea is that I could use udev rules to detect my Nexus 7 connection via USB, when it is detected then run a script that will mount the Nexus 7 via go-mtpfs.
That's a very good idea, and I would like to help you ... but the inner workings of udev are "black magic" to me.
can8v wrote:Even if I figure out this udev rule, this is not very universal and would require anybody doing this to customize the script ...
... and change the udev rule to detect their device instead of a Nexus 7
Let me say that, in principle, what you need is some form of udev rule which will identify any/all MTP devices which may be connected to Puppy, then launch the appropriate go-mtpfs commands.
What may assist you is the MTP udev rule from gnomad2, which I now attach. As you can see, it contains a long list of USB device ID's of known MTP devices.

But here's another idea you may like - what about a bash wrapper script which does the following:
- launches go-mtpfs
- launches ROX, to the directory specified by go-mtpfs (/root/MTP by my suggestion)
- the wrapper script determines when ROX is closed, then ...
- unmounts the device (with fusermount)
- displays a message - probably via gtkdialog, saying something like
"your MTP device has been unmounted, and is now safe to disconnect"
can8v wrote:

Code: Select all

go-mtpfs "Nexus 7" &
BE CAREFUL ... the expression which follows "go-mtpfs" defines the directory where the (FUSE) mountpoint is located - so you have specified a Linux directory which includes a space - and that's problematic in Linux.
You are right a space would certainly not be universally appropriate and could cause problems for some people.
I took a look at the udev rules you posted, I think you are correct in that making udev work universally could be a bit like black magic. Certainly not something I am going to grasp easily. I have another idea that I will explore that should prove much simpler. I will get to that later today and post back the results.

can8v
Posts: 586
Joined: Sat 15 Jul 2006, 08:20
Location: Yuba City, CA
Contact:

Mount and unmount scripts

#25 Post by can8v »

I have written the following simple scripts that will mount and unmount a MTP device connected via USB after installing the appropriate pet package that Tempestuous posted above.
I use custom actions in Thunar to setup right click menu entries that will mount the device or unmount the device. After mounting the script takes me right to the directory that the device is mounted to. Also I changed the directory to /mnt/MTPdevice (just my preference. If you like /root/MTP better you can change that easily in the script.
Read the comments for instructions.
Mount Script

Code: Select all

#!/bin/bash
# Put this script in the /root/my-applications/bin directory and make it executable
# Change to mnt directory
cd /mnt
# Mount any detectable MTP device at /mnt/MTPdevice
go-mtpfs "MTPdevice" &
# Start your favorite file manager in the directory where the MTP device is mounted. You can comment out this line if you would rather navigate to this directory in the file manager window that is already open.
thunar /mnt/MTPdevice
# If you use Thunar for file management you can configure a custom action (Edit->Configure Custom Actions) for a right click menu option on the /mnt/MTPdevice directory that will issue the command  fusermount -u MTPdevice. This will give you a convenient right click option to unmount your device prior to disconnecting it from USB. I haven't used ROX in quite a long time, but there is likely a similar option for ROX users.
# Just an aside, if you do not have an MTP device connected when you call this script the file manager you called above will simply open with nothing mounted at the /mnt/MTPdevice directory. If you later connect an MTP device simply run this script again.
# I only have one MTP device and don't know what this would do if two or more were connected via USB when the script is executed.
Unmount Script

Code: Select all

#!/bin/bash
# Put this script in the /root/my-applications/bin directory and make it executable
# changes directory to the mount point for the MTP device
cd /mnt
# unmounts the MTP device
fusermount -u MTPdevice
# In Thunar make a custom right click action that will execute this script, so that you can unmount your MTP device at any time from the right click menu in Thunar.
# Edit->Configure Custom Actions THen on the command line enter this script unmountMTP.sh it should find it if you have it in the /root/my-applications/bin directory.
# A similar setup should be available in other filemanager such as ROX, though I don't use them, so I cannot advise on how to set them up.
If anybody has more than one MTP device I would love to know how this setup handles a situation where more than one MTP device is connected via USB when the script is run. Please test and report your results here. If anybody using ROX or other file managers can provide helpful hints for running these scripts from a right click menu within a file manager other than Thunar or some other quick and easy (gui) way of starting the scripts I am sure that would help many folks out, as well. I realize most Puppy users probably are not using Thunar.
I experimented with running the script prior to launching the filemanager, and this also worked, but I couldn't figure out how to get the file manager to open in a directory other than /mnt (or whatever the parent directory to the directory that the MTP device is mounted to, in my case /mnt). That would have been my preference over starting the script from a right click menu in the filemanager, but I couldn't live with the file manager always opening to /mnt even if I click a drive icon for the CD drive for example. Obviously I could set it to use thunar /mnt/sr0, but then it would always open to the directory. I could pass in a variable easily enough and use the variable to set the directory to open thunar to, but I couldn't figure out how to get the appropriate variable to pass into the script. Bottom line here is that I am obviously not quite satisfied with this solution, so there might be some improvements in the future, if somebody doesn't get to it before me.

**EDIT**
I borrowed a second Nexus 7 from my wife (no easy task prying it from her fingers mind you), then connected both MTP devices to USB ports and ran the scripts to mount them using gomtpfs. The results were kind of unpredictable. Neither device mounted to the mount point and the Pup Camera application kept popping up despite the fact the both devices were still clearly set to use MTP rather than PTP. No matter what I tried neither device would mount until the other was disconnected from the USB port. So I think that is a limitation of the gomtpfs library. The gomtpfs library is still more stable than libmtp, which I have tried in a couple of other distros. It didn't seem to matter if I was using Arch, Lubuntu or whatever, when using libmtp to mount my Nexus 7, I ran into occasional permission denied errors when trying to transfer files to or from the device, regardless of whether or not I had the appropriate permissions. It seemed a bit random when I would get the errors, but it didn't seem to matter which distro I used. It did however, work most of the time and sometimes I could try transferring the same file later and it would work fine. I don't have this issue with gomtpfs, so I am more than happy to have the limitation of only being able to mount one MTP device at a time.

User avatar
Ted Dog
Posts: 3965
Joined: Wed 14 Sep 2005, 02:35
Location: Heart of Texas

#26 Post by Ted Dog »

Hay its for the betterment of unknown persons on the intertubes, what was she thinking :lol: Tell her thanks from all the rest of the web for her help.

can8v
Posts: 586
Joined: Sat 15 Jul 2006, 08:20
Location: Yuba City, CA
Contact:

#27 Post by can8v »

Ted Dog wrote:Hay its for the betterment of unknown persons on the intertubes, what was she thinking :lol: Tell her thanks from all the rest of the web for her help.
Ted dog, what are you talking about?

User avatar
Ted Dog
Posts: 3965
Joined: Wed 14 Sep 2005, 02:35
Location: Heart of Texas

#28 Post by Ted Dog »

first line after edit. :wink:

can8v
Posts: 586
Joined: Sat 15 Jul 2006, 08:20
Location: Yuba City, CA
Contact:

#29 Post by can8v »

@Ted Dog
Wow I was slow on the uptake there. Anyway she enjoys the puppy linux media server in our home, makes good use use of the puppy firewall, without even realizing it, and saves plenty of cash on her husband's OS and software, but hassles me when I need her tablet for six minutes of testing. In her defense however, she was reading a book on the very tablet that I needed, when I asked her for it and with much begging she finally relented and let me borrow it. She is definitely a keeper, besides she tolerates me spending countless hours pursuing my tech passions and weeks long backpacking trips. Not just any woman would go for that.

can8v
Posts: 586
Joined: Sat 15 Jul 2006, 08:20
Location: Yuba City, CA
Contact:

#30 Post by can8v »

I did quite a bit more testing on this and discovered that sometimes after the

Code: Select all

fusermount -u MTPdevice
command the device is still mounted. I haven't been able to figure out why this is as it has only happened a couple of times. I modified my unmount script to inform the user of the mount status of the MTP device after the the unmount script runs, so that if it is still mounted they will be aware and hopefully not unplug the device. In any case simply running the script again seems to unmount the device. A little strange, but tolerable. Here is the new script. It will notify you of the mount status in the terminal if you are running the script from the terminal. If you are running the script outside the terminal then a gtk dialog will notify of the mount status after the script runs.

Code: Select all

#!/bin/bash
# Put this script in the /root/my-applications/bin directory and make it executable
# Change directory to the mount point for the MTP device.
# In Thunar make a custom right click action that will execute this script, so that you can unmount your MTP device at any time from the right click menu in Thunar.
# Edit->Configure Custom Actions THen on the command line enter this script unmountMTP.sh it should find it if you have it in the /root/my-applications/bin directory.
# A similar setup should be available in other filemanager such as ROX, though I don't use them, so I cannot advise on how to set them up.
cd /mnt
# unmounts the MTP device.
fusermount -u MTPdevice
# Detect if MTP device unmount was successful.
# Looking for an empty mount directory so we need an empty variable
FILE=""
#Specify the directory the device was mounted to.
DIR="/mnt/MTPdevice"
# look for empty MTP mount directory
if [ "$(ls -A $DIR)" ]; then
    MOUNT_STATUS="MTP Device is still mounted."
else
    MOUNT_STATUS="MTP device unmounted successfully."
fi
# echo the MOUNT_STATUS variable in case the script is being run from the terminal
echo $MOUNT_STATUS
# Use GTK Dialog in case the script is being run from outside the terminal
export MAIN_DIALOG='
 <vbox>
  <text>
    <label>'$MOUNT_STATUS'</label>
  </text>
 </vbox>'
gtkdialog --program MAIN_DIALOG

tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#31 Post by tempestuous »

can8v wrote:sometimes after the

Code: Select all

fusermount -u MTPdevice
command the device is still mounted.
Could the problem be that the go-mtpfs process is still running, and possibly remounting your device?
Earlier in this thread when I suggested using the "&" to background the process, I was actually a little worried about this.
I suggest you experiment by fully shutting down go-mtpfs before running the "fusermount -u" command.

There's another small potential problem I see -
can8v wrote:

Code: Select all

cd /mnt
go-mtpfs "MTPdevice" &
This will mount your device at /mnt/MTPdevice
... but does that directory need to be created, first ??

tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#32 Post by tempestuous »

can8v wrote:I borrowed a second Nexus 7 from my wife, then connected both MTP devices to USB ports ...
...
and the Pup Camera application kept popping up ...
Yes, the guilty udev rule is /etc/udev/rules.d/88-puppy-autodetect.rules
specifically, this line -

Code: Select all

ACTION=="add", SUBSYSTEM=="usb", ENV{INTERFACE}=="6/1/*", RUN+="/usr/sbin/pupautodetect camera"
You could either comment out this line, or delete/shift this entire udev rule altogether.

can8v
Posts: 586
Joined: Sat 15 Jul 2006, 08:20
Location: Yuba City, CA
Contact:

#33 Post by can8v »

tempestuous wrote:
can8v wrote:sometimes after the

Code: Select all

fusermount -u MTPdevice
command the device is still mounted.
Could the problem be that the go-mtpfs process is still running, and possibly remounting your device?
Earlier in this thread when I suggested using the "&" to background the process, I was actually a little worried about this.
I suggest you experiment by fully shutting down go-mtpfs before running the "fusermount -u" command.

There's another small potential problem I see -
can8v wrote:

Code: Select all

cd /mnt
go-mtpfs "MTPdevice" &
This will mount your device at /mnt/MTPdevice
... but does that directory need to be created, first ??
Yes the directory needs to be created first. I should not have assumed people would realize to use the script without modification you would have to create this directory instead of /root/MTP. I am going to modify the script to look for the directory and create it if necessary and also change the unmount script to display a nicer splash message and hopefully have a 100% success rate, making the splash message nothing more than insurance.

gcmartin

#34 Post by gcmartin »

Can8v wrote: ... Yes the directory needs to be created first. I should not have assumed people would realize to use the script without modification you would have to create this directory instead of /root/MTP ...
I am wondering if what @Tempestuous shares was " is there anything already in /dev (or Linux) that can be/should be used?"

can8v
Posts: 586
Joined: Sat 15 Jul 2006, 08:20
Location: Yuba City, CA
Contact:

#35 Post by can8v »

Here is my working copy of my unmount script. It uses notify for the safe to eject MTP device message. I am now satisfied with the mount/unmount scripts and don't see any changes in the future, but you never know.

Code: Select all

#!/bin/bash
# Put this script in the /root/my-applications/bin directory and make it executable
# Change directory to the mount point for the MTP device.
# In Thunar make a custom right click action that will execute this script, so that you can unmount your MTP device at any time from the right click menu in Thunar.
# Edit->Configure Custom Actions THen on the command line enter this script unmountMTP.sh it should find it if you have it in the /root/my-applications/bin directory.
# A similar setup should be available in other filemanager such as ROX, though I don't use them, so I cannot advise on how to set them up.
cd /mnt
# unmounts the MTP device.
fusermount -u MTPdevice
# Detect if MTP device unmount was successful.
# Looking for an empty mount directory so we need an empty variable
FILE=""
#Specify the directory the device was mounted to.
DIR="/mnt/MTPdevice"
# look for empty MTP mount directory
if [ "$(ls -A $DIR)" ]; then
    MOUNT_STATUS="MTP Device is still mounted. Please unmount the device before removing it."
else
    MOUNT_STATUS="MTP device unmounted successfully. It is now safe to remove your MTP device"
fi
# echo the MOUNT_STATUS variable in case the script is being run from the terminal
echo $MOUNT_STATUS
# Use GTK Dialog in case the script is being run from outside the terminal
export MAIN_DIALOG='
 <vbox>
  <text>
    <label>'$MOUNT_STATUS'</label>
  </text>
 </vbox>'
notify-send -t 6000 -i usbpendrive_unmount "$MOUNT_STATUS" 
Thanks again to Tempestuous, for compiling go-mtpfs and turning me onto it.

Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#36 Post by Sylvander »

I use xfe and ROX...
Plus...
I'm no Puppy/Linux expert.
Any chance of a PET file [to do the above] for me?

gcmartin

#37 Post by gcmartin »

Or should this somehow land in WOOF-CE for system building?

can8v
Posts: 586
Joined: Sat 15 Jul 2006, 08:20
Location: Yuba City, CA
Contact:

#38 Post by can8v »

@gcmartin I think it should.

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#39 Post by 01micko »

Some interesting results with my wife's gear.. (mine's pretty cool too can8v :wink: )
  • Samsung Galaxy Note (1st version, jellybean)
    Samsung Galaxy Tab 3 (recent model, jellybean)
Here is my udev rules file (ref), including my Galaxy W (GT-I8150 - which lsusb id's as Galaxy S2!) and the Nexus 7:

Code: Select all

# MTP mode under ICS 4.0+ : automatic mount & umount when plugged (USB debug on & off)
ENV{ID_MODEL}=="Nexus_7", ENV{ID_MODEL_ID}=="4e41", ACTION=="add", RUN+="/usr/sbin/pupautodetect android-device"
ENV{ID_MODEL}=="GT-I8150", ENV{ID_MODEL_ID}=="6860", ACTION=="add", RUN+="/usr/sbin/pupautodetect android-device"
ENV{ID_MODEL}=="SAMSUNG_Android", ENV{ID_MODEL_ID}=="6860", ACTION=="add", RUN+="/usr/sbin/pupautodetect android-device"
Yes, yes, I hacked /usr/sbin/pupautodetect to run a different proggy (my script) when detected, which works nicely; more later on that.

Note that the Note and the Tab mount under the same rule.. sadly pupcamera pops up with those too, so there is possibly something in the Samsung ROM causing that (or perhaps its a jellybean thing). Neither my Nexus 7 (2012 - kit-kat 4.4.2) or my Galaxy W (CyanogenMod 9 [= ICS, 4.04], basically stock Android) pop up pupcamera.

dmesg output (you can see the same device ID but different serial number for Note [1st] and Tab) :

Code: Select all

[   29.281515] usb 2-3: new high-speed USB device number 2 using ehci-pci
[   29.407007] usb 2-3: New USB device found, idVendor=04e8, idProduct=6860
[   29.407021] usb 2-3: New USB device strings: Mfr=2, Product=3, SerialNumber=4
[   29.407030] usb 2-3: Product: SAMSUNG_Android
[   29.407037] usb 2-3: Manufacturer: SAMSUNG
[   29.407042] usb 2-3: SerialNumber: 0019783c0e622f
[   77.219213] usb 2-3: USB disconnect, device number 2
[  134.629481] usb 2-3: new high-speed USB device number 3 using ehci-pci
[  134.755762] usb 2-3: New USB device found, idVendor=04e8, idProduct=6860
[  134.755776] usb 2-3: New USB device strings: Mfr=2, Product=3, SerialNumber=4
[  134.755785] usb 2-3: Product: SAMSUNG_Android
[  134.755792] usb 2-3: Manufacturer: SAMSUNG
[  134.755798] usb 2-3: SerialNumber: 520004e442e9a000
[  137.731896] usb 2-3: USB disconnect, device number 3
[  137.987887] usb 2-3: new high-speed USB device number 4 using ehci-pci
[  138.113197] usb 2-3: New USB device found, idVendor=04e8, idProduct=6860
[  138.113210] usb 2-3: New USB device strings: Mfr=2, Product=3, SerialNumber=4
[  138.113218] usb 2-3: Product: SAMSUNG_Android
[  138.113225] usb 2-3: Manufacturer: SAMSUNG
[  138.113231] usb 2-3: SerialNumber: 520004e442e9a000
[  236.163979] usb 2-3: USB disconnect, device number 4
Still mount and unmount fine. Phone says "phone" in /mnt/MTPdevice, tablet says "tablet".. well "duh..!"

Now I just have to con the son into letting me test his Nexus 5 (Chrissy pressy).

:roll:
Puppy Linux Blog - contact me for access

gcmartin

#40 Post by gcmartin »

Reprinted above
Last edited by gcmartin on Sun 26 Jan 2014, 00:15, edited 2 times in total.

Post Reply