Archive for the ‘MTP’ Category

A Sync Script for MTP Device

July 29, 2009

I’m less concerned about managing albums on my Samsung S3 from within Linux than I am “changing” content like podcasts, images, shopping and to-do lists, etc. This is no problem at all in Windows because MTP is perfectly supported under it.

The S3 has a file structure which separates “datacasts” from other audio content. I’d been using a quick little script that would copy every ogg, mp3, and/or wma file in the current directory (specifically, ~/podcasts) to my S3’s Datacasts directory. It was fine for doing that, but I wanted it to do a little more than that so I could use one directory as a “sync” folder for more file types. Then I could move all content I want to that folder, run one script, and my podcasts would go to Datacasts, text files would go to Texts, and pics would go to Pictures; as I’ve written before, the device isn’t fine-tuned enough to automatically put each kind of file in an appropriate directory so I wanted my script to assure everything goes exactly where I want it. Otherwise I’d have to go to the “File manager” directory and trace through it to other folders to find my content. This way I know exactly where everything is.

One important thing to note about libmtp and mtp-tools (mtp-examples in Fedora) is that directories are referred by their ID numbers rather than their names. It’s easy to get the directory ID numbers for these using the mtp-folders command. For example, I used the following to get the “Pictures” directory:

% mtp-folders | grep -i pictures

This reported back the folder “Pictures” with an ID number 32776. Other MTP devices will likely have different ID numbers for different things so double check your own device before using the following script.

Once I had the relevant directory numbers, I could set up a few functions to send files to them through a case command for each file type I want to manage. Here’s the current version of my script:

# - Wed Jul 29 14:33:14 CDT 2009

# moves files from PWD to MTP device via mtp-sendfile
# and deletes the file from PWD. Use this for podcasts,
# text files, and images rather than for music kept
# on the system. 

# mtp-folders for my Samsung S3
# 32773 = Datacasts
# 32774 = Texts
# 32776 = Pictures

function move_podcast_files  {
	mtp-sendfile $SYNC_THIS_FILE 32773
	echo "removing $SYNC_THIS_FILE from $PWD..."

function move_text_files  {
	mtp-sendfile $SYNC_THIS_FILE 32774
	echo "removing $SYNC_THIS_FILE from $PWD..."

function move_image_files  {
	mtp-sendfile $SYNC_THIS_FILE 32776
	echo "removing $SYNC_THIS_FILE from $PWD..."

	case $SYNC_THIS_FILE in
		*.mp3)	move_podcast_files                                 ;;
		*.ogg)	move_podcast_files                                 ;;
		*.wma)	move_podcast_files                                 ;;
		*.txt)	move_text_files                                    ;;
		*.TXT)	move_text_files                                    ;;
		*.jpg)	move_image_files                                   ;;
		*.jpeg)	move_image_files		                   ;;
		*.JPG)	move_image_files		                   ;;
		*) echo "are you sure $SYNC_THIS_FILE goes to MTP device?" ;;

Nothing fancy, and someone will no doubt have a better solution (feel free to opine) or suggest moving some of the repetitive commands in each function to the for loop. It’s a work in progress and works the way I want. Caveats and additional points:

  • I use mksh and edited this to /bin/sh; change to suit your needs if /bin/sh doesn’t link to your preferred shell. EDIT (sorry!): That includes possibly having to edit the functions if your shell (e. g., CSH or TCSH?) uses C/POSIX functionname () {…} semantics rather than function functionname {…}.
  • Add or remove file types based on your own needs. I convert all my images to jpg for convenience.
  • I used single entries for each file type because I may end up adding more to the functions, e. g., adding custom id tags to mp3 and/or oggs (can’t add tags to wma in Linux as far as I know).
  • I haven’t bothered putting videos on my S3 even though it’s capable. I don’t even know if/how I can convert to the format Samsung requires videos be in to play on their devices. RTFM.
  • Delete the rm/echo commands in the functions if you want to keep local copies.
  • In my cheap original script for ogg, mp3, wma, I used ‘for FILETYPE in *.{ogg,wma,mp3}’ which resulted in error messages if one or more weren’t in the directory.
  • I’ll most likely add POD_SYNC_DIR so I can run the script from any directory or from a dynamic directory (dmenu or ion3’s F3 menu) which reads from $PATH. No big deal because I tend to wget files directly to ~/podcasts and always have a terminal open. Whatever.

Finally, mtp-tools (mtp-examples in Fedora) has the mtp-delfile command which is a bit clumsy. To remove files, I tend to delete them directly from the S3 after I listen or use gphotofs (fuse) to mount the device and delete or copy back files I want to keep. In fact, I highly recommend using gphotofs or other applications utilizing libgphoto2 for copying files from a MTP device back to a computer. Unfortunately, libgphoto2 doesn’t copy/move files and directories from computer to device or else it would be ideal, but it’s for cameras rather than media devices. Maybe the libgphoto people and libmtp people can do more collaboration and maybe even merge their projects for better all-around support of cameras and media players using PTP/MTP.

UPDATE 2009-07-29 20:01 CDT: Version 2 of the above script now does rudimentary logging which, when I’m finished, will maintain a list of the file ID numbers to (hopefully) ease removal of files without using the other utilities mentioned in the last paragraph.

Another Way (Maybe) to Skin The MTP Cat

July 19, 2009

I knew there was a nexus between MTP and PTP but I hadn’t checked to see if I could use libgphoto2 to access my Samsung S3 before today. I decided to check because I saw the S3 listed among the devices supported by libgphoto2. Imagine that.

I’d already installed gtkam, which uses libgphoto2, to manage my old Kodak digital camera. I looked to see if the S3 was among the “cameras” listed in the camera selection dialog. It wasn’t listed there but several similar Samsung models were. I didn’t have anything to lose so I plugged it in. I then ran the “detect” option and, voila, I had a listing for my MTP device. I expanded the entry and I had access to everything on the device.


What gets me is that this (in #!/Jaunty) is the current version of gtkam and libgphoto2 2.4.2 (current is 2.4.6 and the S3 is named among supported devices in that version). Even with the current version of libmtp, I don’t have the ability to see things by directory (not shown but take my word for it: “Datacasts” and all  the other directories are listed above this “Music” directory) when using apps like rhythmbox. My only option is to use mtp-tools (aka “mtp-examples” to those of you still hitting my blog searching for Fedora help). The only options I have in rhythmbox are to view by artist, song, album, etc. Useful but limited. At least mtp-tools is adequate to manage the device.

I haven’t looked to see if there are any other apps using libgphoto2 to manage MTP devices or to allow mounting them via fuse. Speaking of fuse, the version of mtpfs in Jaunty’s repositories is of no use to me. I can mount the device but a command like ls results with question marks rather than file sizes and permissions. It also shows the filenames but doesn’t allow any other operation on them.

Anyway, it’s nice to see there might be another way to use MTP devices under non-Windows operating systems and that it may actually yield better results. Of course, I’ve only tried to read files and directories and delete files. It may be back to square one if I try to add files.

UPDATE: I installed gphotofs, a fuse system for libgphoto2 which allows PTP/MTP cameras to be mounted as any other filesystem. Yes! I can mount the device and have full access of it. Just deleted a bunch of podcasts from the Datacasts directory.


My shell, mksh, carries text beyond the screen (<) so you can’t see the rm command but you can see the result. Finally something freaking works right.

UPDATE 2: Add another 16MB (27MB when various {u} dependencies are removed) of cruft removed. Gone are rhythmbox, libmtp, libusb-dev (needed to recompile libmtp), mtp-tools, mtpfs, etc. It’s redundant to gphoto2/gphotofs and I have much better access to my device now.

UPDATE 3: Using gphotofs is very easy, especially if you’ve used fuse before. You need to be in group plugdev. I chose to create a mount point in my home directory (~/mtp) rather than use a point like /mnt. To mount, first make sure fuse is loaded (lsmod if it was built as a module) and then use the gphotofs command:

gphotofs ~/mtp

Or whatever your mount point is. Once mounted, you can navigate and issue commands as you would any other directory (in a terminal, file manager, whatever you want). When finished, unmount the point:

fusermount -u ~/mtp

Or whatever your mount point is. Give it a moment to umount and then you can remove your device. It’ll work for your camera (if the camera is MTP or PTP) as well.

UPDATE 4: Fuck. If it’s too good to be true, it probably is. I can read from the device and copy and delete from it. Copying to it:

cp: cannot create regular file... Function not implemented

So tomorrow I reinstall libmtp and mtp-tools. Yippee.

continued MTP Issues – crunchbang and Ubuntu Jaunty Jacksh*t

July 14, 2009

NOTE: Resolved, see update at end of article.

After doing a little hunting through Ubuntu-related forums, I double-checked the version of libmtp that came with crunchbang and saw it was version 0.3.0. I tried one of the older suggested “fixes” by setting a udev rule and adding myself to group audio. This gave me partial access to my Samsung S3.

What do I mean by partial? First, the device remained “unrecognized” using mtp-detect. That’s probably why it continued to not connect when running rhythmbox; I gave up on gpodder because it puts out sqlite-related errors every time I open it (saw that when tried launching from terminal). Second, I could send files to the device but they wouldn’t go to specified directories. The files went to the default files directory rather than to either the Music or Datacasts (podcasts) directory; I sent using the number code for the Datacasts directory and that didn’t work.

I decided to download and install the source tarball. This required installing gcc and related packages, as well as libusb-dev (compiling libmtp requires libusb headers). I used –prefix=/usr to build over the installed package and –program-prefix=mtp- as suggested in the documentation to prevent conflicts with other applications I may install later (e. g., sox). INSTALL also suggested –enable-hotplugging but this resulted in an error that it’s not a recognized option. Go figure.

After installing, I plugged in my S3 and fired up rhythmbox. I saw the S3 was available in the left panel and, once its files were read, I was able to browse it. While that’s a very good improvement, rhythmbox doesn’t show things in the S3’s file hierarchy but rather only as artist, album, etc.


I just tried to send the same podcast to the Datacasts directory with mtp-sendfile and got a segfault. Great fuck, just what I need. I’m not asking for a miracle here. I just want to be able to at least manipulate things one way or another, and hopefully with enough control that I can put files where I want them and delete them when I want. I also looked to see if I can use rhythmbox to delete the podcast I copied last night (which went to the default files folder). Nope because it’s in the generic file folder rather than Music; I can still listen to it by navigating to the files folder. So now I have to see if I can figure out why the segfault, see if I can use mtp-tools to do it at all (did under Fedora), or see if there’s some way (via plugin?) to get rhythmbox to see the directory structure on the S3 rather than just what’s in Music.

Geez. Always fucking something, huh.

I’m not as pissed off at libmtp or Linux in general about this as I am Samsung for using MTP in the first place and peddling it as an ogg-friendly device. What a fucking nightmare this has been. First it didn’t really support ogg because of the firmware it came with and now it’s a pain in the ass getting it to work under non-Windows operating systems.

That’s it for today. Back to Windows to get some real work done. I can get more done without all these fucking headaches.

UPDATE 14 July 2009 @ 13:05 – Fixed by compiling libmtp 3.7 from Debian (INSTALL no longer mentions the hotplugging option for configure). No segfaults, deleted one old podcast and sent a test file to Datacasts without any errors:

% mtp-folders |grep Datacast                                                                                    
32773    Datacasts

% mtp-sendfile startx_old.ogg 32773                                                                             
libmtp version: 0.3.7

Sending startx_old.ogg to 32773
Sending file...
Progress: 14866 of 14866 (100%)
New file ID: -2147155907

I’m happier now. Wonder how long that’ll last if I decide to compile a custom kernel later while the All Star game is on.

getting ready for crunchbang de-bloat, etc.

July 11, 2009

I haven’t changed things around much yet beyond what I wrote yesterday. I’ve started looking at what I can remove and what I’ll have to live with. Here’s a list of the things from dry runs I did earlier to see what I can do without causing major breakage:

The following packages will be REMOVED:
 abiword abiword-common abiword-help abiword-plugin-grammar 
 abiword-plugin-mathview gnumeric gnumeric-common gnumeric-doc 
 libgoffice-0-6 libgoffice-0-6-common 
0 packages upgraded, 0 newly installed, 10 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 60.4MB will be freed.

The following packages will be REMOVED:
0 packages upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 1012kB will be freed.

The following packages will be REMOVED:
 claws-mail claws-mail-html2-viewer claws-mail-i18n claws-mail-pgpinline 
 claws-mail-pgpmime claws-mail-trayicon tango-icon-theme-claws-mail-3.6.0 
0 packages upgraded, 0 newly installed, 7 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 9720kB will be freed.

The following packages will be REMOVED:
 linux-headers-2.6.28-13 linux-headers-2.6.28-13-generic 
0 packages upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 74.7MB will be freed.

The following packages will be REMOVED:
 crunchbang-gwibber-theme gedit-plugins gwibber libmetacity0 metacity 
 metacity-common python-gnome2-desktop 
0 packages upgraded, 0 newly installed, 7 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 16.6MB will be freed.

The following packages will be REMOVED:
 nvidia-173-modaliases nvidia-180-modaliases nvidia-71-modaliases 
 nvidia-96-modaliases nvidia-common 
0 packages upgraded, 0 newly installed, 5 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 459kB will be freed.

The following packages will be REMOVED:
 libpurple-bin libpurple0 pidgin pidgin-data 
0 packages upgraded, 0 newly installed, 4 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 28.9MB will be freed.

The following packages will be REMOVED:
0 packages upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 14.5MB will be freed.

The following packages will be REMOVED:
 vim vim-gtk vim-gui-common vim-runtime xchat 
0 packages upgraded, 0 newly installed, 5 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 30.2MB will be freed.

The following packages will be REMOVED:
 libexo-0.3-0 libthunar-vfs-1-2 libxfce4util4 libxfcegui4-4 libxfconf-0-2 
 thunar-data xfburn xfconf 
0 packages upgraded, 0 newly installed, 8 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 19.5MB will be freed.

I think I counted over 200MB and that’s without counting things like gpodder, which is of no use to me if MTP support is lacking for my S3 (so libmtp and mtp-tools will go), and a few other things in that list. I can also get rid of some of the CD/DVD tools (brasero if it’s not in that list above) since I don’t have any plans to start toting around a USB CD/DVD which will probably outweigh my AA1. My mini CDRW bit the dust when I was taking care of family last year. I haven’t been able to find another device this small and thumbdrives are big enough now that I don’t see any reason to get an external optical device. Even Microsoft is considering putting the Windows 7 installer on a USB drive to make installation easier for netbook users. What’s funny is, Microsoft may beat most of the big Linux distros to the punch — with most distros, live images can be put on USB media via external tools like unetbootin or Fedora’s live USB creator. There are only a handful which have USB-ready images that can be installed via simple scripts. I think that’s the future whether netbooks and nettops ever outsell traditional computers.


Yes, that’s the old CDRW next to my AA1. If anyone knows of a DVD-RW (or Blu-Ray!) this small, please let me know.

By the way, no problems like I had in Fedora yet with wifi even though I’ve tested suspend/resume. The only thing that continues to be an issue is the initial association with the wrong AP before it re-associates with my router. I really, really don’t like that but I haven’t looked to see what I can do to stop it. In addition to the stuff in dmesg, iwconfig shows the association with SSID=”the wrong one” and then after the nm-applet icon changes to show that it’s connected iwconfig shows SSID=”my router.”

I have some other things I have to take care of today and a busy evening, too. It might be tomorrow before I get down to business.

crunchbang – More JWM Screenshots

July 10, 2009

Here are a couple more screenshots. New shell is mksh. Added a few more entries to .jwmrc and also uncommented the Debian part of the default menu. I also moved the <Dock/> tag down so there’s not that big empty space between the applets and clock (compare this emacs shot to the next two).


Remembered to get “free -mt” after a reboot.


I also took the openbox keybindings out of the .conkyrc and added in the other mount points I want to see. I’ll probably set up something like xbindkeys so my keybindings are the same regardless of which window manager I use.


That’s it. I have some reports to finish so I can call it a day. Tomorrow I’ll probably start pruning some of the things from my list last night and see what I can do to keep NetworkManager — or whatever alternative I can find — from associating with any other AP before it connects to mine. I also need to see if I can find out what the problem is with libmto and mtp-tools and my S3; it’s not being detected at all under #! right now.

Update 20090709 pm – installed crunchbang

July 9, 2009

I did some backups this afternoon and installed crunchbang. I made a few partition changes. One thing I almost regretted off the bat was only setting aside only 5GB for / and now it’s about half full. I have separate partitions for /home and /boot as well; this time I decided to go ahead and set up a really large FAT partition (mount point /windows in Linux, D: in Windows) to share data between operating systems. I transferred my music collection and some documents to the FAT partition and set up links (shortcuts) in Windows so everything is basically just as it was before.


I know, I know. That’s a little harder than Vivaldi and Schubert.

I have a few nits to pick. I love the fact #! has some of my favorite apps. I went to use naim and it’s configured to open in GNU screen. Fine, I can live with that. But after it showed that it was starting in screen, I did C-a c to open a new terminal instance within screen. Nothing happened. So I tried again. Then I opened another terminal to check. Sure as shit, screen was running but naim was running separate. WTF?! So I shut down naim, attached to the screen session, and tried to start naim again. It detached screen and started running on its own. I quit naim again and tried starting within screen again using the –no-screen flag, got some error messages, and then naim finally started within the screen session rather than outside it. I’ve used naim and screen so much that I know this shouldn’t be happening. I didn’t spend any time beyond that to see what was happening, but I have the most recent sources and I’ll probably go ahead and recompile it myself so that it functions the way I want it to.

Another thing, #! has a few remaining clues that it once offered xfce. I don’t know if some of those things are there as dependencies of something else. I saw libthunar-vfs* and xfburn (brasero is in the base as well) along with a couple libxfce* things. Could be in use, but I’m going to see what happens when I start de-bloating (heh) it this weekend.

Speaking of which, I went quickly through the list to find things to get rid of after installing emacs22-nox. Here’s the starting point. Maybe will fit when I’m done. 


 That’s subject to change — I don’t know what some of these (agave?) are and there may have been something else I overlooked as I quickly edited the list. I’ll leave any of those lynch-pin packages that look like they’ll remove half the system with them. I know I don’t need kernel headers. I love vim and mutt but I’d rather leverage emacs for all I can. I also like dwm but I doubt I’ll use it on my AA1, even though I’ll probably install ratpoison sooner than later.

My impressions over all are really positive. Surprisingly positive. I didn’t have a bunch of stupid icons to delete from either the desktop or the menu. I didn’t have to go find dubious codecs or closed source stuff (Skype, Flash) I want. I had a few services to shut off by default but that’s going to happen with just about any distro anymore.

That’s it for today. It’s bedtime.

Using libmtp, mtp-tools in Fedora 10

July 4, 2009

Working on MTP-stuff while watching the first day’s time trials in the Tour de Lance. I removed rhythmbox several days ago along with the big load of Gnome bloatware I ditched. No big deal.


Just for background, my MTP device is a Samsung S3 (YP-S3). The S3 was on my wishlist because it’s capable of playing OGG and video; it also has a cool touchpad interface instead of a stupid wheel thing. Unfortunately, just because it plays ogg files doesn’t mean it plays fairly with non-Windows operating systems. It was purchased from a big box electronics store which runs its own music download site; this retailer sells custom-flashed models to work with their store and this custom firmware removes OGG-capability (even though the retailer’s site provides specs suggesting it does play ogg files). I installed the default firmware for the device to get OGG support on it; Windows, though, will wrongly suggest these files won’t play on the device when copying. And despite being capable of playing back video, the videos must first be converted for the device using Samsung’s software that comes with it. I chose to not install it so I don’t watch videos. Finally, the other fly in the ointment with the device is that it’s MTP rather than UMS. UMS is standard USB storage and MTP is Microsoft Transfer Protocol. Of course, the packaging and specs don’t tell the consumer that it’s MTP and not plug-and-use like any standard USB device.

Fortunately, there is some MTP support for non-Windows operating systems via libmtp. The project has had some support from Microsoft. Contrary to the naysayers and haters, Microsoft wants wider adoption of their protocols. After all, a Zune sale makes them money whether the user wants to use it in Windows or Linux. Unfortunately, the ease/difficulty of getting devices to work depends on how they’re set up by manufacturers and how many developers or owners have provided information to the developers. Some applications which use libmtp work better than others, which also is affected by which version of libmtp is being used.

There are several applications which use libmtp to support MTP devices. These include amarok and rhythmbox, but also include lesser-known applications and utilities.

I installed mtpfs, a fuse filesystem allowing the device to be mounted, in Debian but was unimpressed with it. I didn’t see mtpfs in Fedora. I don’t know if I’ll bother with compiling it. In Debian, I was able to mount the device and navigate directories to read files but had zero control over files. Like other MTP utilities, there was scant information to help me resolve the problems. I wish it had worked because I love the fuse approach for things like this.

I also looked briefly at gnomad2 (in Fedora) but was put off by a few things. The worst part was the non-recognition of my device (not too surprising since the application isn’t a general MTP manager but targeted to a couple specific devices). The other thing — and this is the kind of aggravating thing some programmers do that pisses me off — is that it uses graphical interface boxes for the main part of the application or its preferences designed for high resolution screens so that on a smaller screem (such as my AA1) a user has to press alt to scroll the thing up off the screen to get to the options on bottom. Maybe the developer isn’t aware that scrollbars allow users to navigate below a certain point if their screens aren’t the same size as his. I removed it after having to push it up the screen repeatedly to find more options to see if it might be tweakable to find and work with my device. I just said, “Fuck it.”

While most users would feel more comfortable using an application like amarok or rhythmbox which uses libmtp, libmtp comes with its own set of tools (usually called mtp-tools for some strange reason). These tools are command-line and not very well documented. Maybe they’d be easier to use if they were, eh.

The first thing I had to do was figure out which Fedora package has mtp-tools. After looking through the mtp-related files (via yum search and yum info) I realized “libmtp-examples” is mtp-tools. Whatever. I installed it and started seeing what I could do with it.

One important command to see if the device is recognized is mtp-detect. This command will provide details about the device — name, ID numbers, directories, and capabilities. Once you know the device is recognizable by libmtp, you can look at managing it (the list of mtp commands is posted below).

I wanted to copy a couple test podcasts to one particular directory. I didn’t know off the top of my head if using mtp-sendfile would result in my podcasts going to the Music directory or to the root directory. After transferring them — one of which resulted in an error — I disconnected the S3, turned it on, and started looking for it. Music? No. But it did land in the file manager’s Music folder, and it played when I selected it.

So I had to figure out  how to manage the directory structure on the device. It’s offputting to have everything go in one directory when there’s a full tree of directories to manage things better. The mtp-folders command produces a list of folders, each with a number in front of it.

After doing a few searches, I learned that I can’t name destination directories when transferring files but rather need to use their number codes (available via mtp-folders). Once I knew that it was easy to send my podcasts to “Datacasts” on my Samsung S3.


I still get the “unknown options” error message but the files are going to my “Datacasts” directory; when sending to “Datacasts” by name, they were going to the root of the Music directory and accessible only in the File Manager rather than under Music (stupid, huh). Also note that the permissions require root access to the device. Go figure. I’ll add a new group for it or something but it’s not a big deal since Windows will ignore the permissions anyway.

There are a variety of mtp-tool commands. As you can see, though, I used mtp-connect –sendfile instead of mtp-sendfile. No matter because mtp-sendfile, mtp-delfile, mtp-getfile, mtp-newfolder, and mtp-sendtr are all links to mtp-connect.

mtp-albumart        mtp-emptyfolders    mtp-getplaylist     mtp-reset           mtp-trexist
mtp-albums          mtp-files           mtp-hotplug         mtp-sendfile
mtp-connect         mtp-folders         mtp-newfolder       mtp-sendtr
mtp-delfile         mtp-format          mtp-newplaylist     mtp-thumb
mtp-detect          mtp-getfile         mtp-playlists       mtp-tracks

I’ll see if I can put together a better, more comprehensive tutorial on using these devices without installing bloated apps like those mentioned above.