This blog has moved! Redirecting...
You should be automatically redirected. If not, visit and update your bookmarks.

Thursday, March 15, 2007

Gnome automount options

On a default Fedora installation, Gnome will automatically mount (with some default options) any recognized volumes as soon as an external storage device is plugged in. While the defaults might be fine in general, sometimes it is necessary to supply some more options.

The tool responsible for automating the mount (gnome-volume-manager) gets additional options from the /system/storage/default_options/$fstype$/mount_options key of gconf -- the Gnome "system registry". One can check/modify existing entries (one a per user basis) by running:

$ gconf-editor /system/storage/default_options &

This should launch the graphical configuration editor with the default_options key selected. Under this key are the entries for different filesystems. Default mount options can then be changed by selecting the desired filesystem and editing the mount_options key.

If a required filesystem type is not listed, then it can be added by using the gconftool-2 utility. E.g. if we wanted to add the ext3 filesystem to the configuration database with the options "sync" and "uid=", we would run the command:

$ gconftool-2 -t list --list-type string -s /system/storage/default_options/ext3/mount_options "[sync,uid=]"

Next time an external volume is plugged in, it will be mounted with the additional options specified! It should be noted that regardless of the options supplied via gconf, some mount options are always present: r(o|w),noexec,nosuid,nodev. At the moment I do not know how to change them.

The main motivation for finding out about the defaults is that I wanted to add "sync" as a default option. This causes data to be written immediately to the device, instead of being buffered first -- a useful option to have for external devices. It should minimized data loss in case of an accidental removal (without running umount first). However, it should also be noted that for solid state drives (e.g. flash), this may result in a shortening of service life and poorer performance.

Update [Sun Mar 18, 2007]:
I've done some rudimentary throughput performance testing with both the sync and async modes and the performance hit with sync appears to be quite severe (at least 20 times slower than async) -- even with a high performance HDD as the target. In light of this, I am removing sync from the list of default options. Given the type of data I'm likely to store on the device, speed is certainly more valuable than data integrity.

Test results:
Testing was carried out on a FAT32 volume. For each mode, both the transfer time and the subsequent un-mount time (indicating the time needed to flush the buffer) are shown.


$ time dd if=/dev/zero of=/tmp/usb/dummy bs=8k count=130000 && time sudo umount /tmp/usb/
130000+0 records in
130000+0 records out
1064960000 bytes (1.1 GB) copied, 45.9035 seconds, 23.2 MB/s

real 0m46.026s
user 0m0.035s
sys 0m2.915s

real 0m11.680s
user 0m0.003s
sys 0m0.263s


$ time dd if=/dev/zero of=/tmp/usb/dummy bs=8k count=130000 && time sudo umount /tmp/usb/
130000+0 records in
130000+0 records out
1064960000 bytes (1.1 GB) copied, 969.384 seconds, 1.1 MB/s

real 16m13.525s
user 0m0.048s
sys 0m12.156s

real 0m0.842s
user 0m0.004s
sys 0m0.199s

Tuesday, March 13, 2007

Streaming TV!!

I'm sorry if this is illegal - but being stuck in Germany, I had to do something about not being able to watch the Cricket World Cup and I am happy to say I found a solution!

Here's what you need to do:
  • Download "sopcast" from here and put it in a suitable place
  • Download the stdc++5 library also from here
  • Extract the files from the library as explained in the README
Now you're more-or-less done. To see a list of available channels, go here. As you can see, the sky is the limit. If you want to view a particular channel, let's say ESPN, copy the ID number of the channel (which at the time of writing this post was 6003). Now navigate to the place you extracted the sp-sc and execute

$ ./sp-sc sop://$channel_id$ 3908 8908 > /dev/null &

Here, the 3912 might vary, so check the URL of the channel anyway. Replace $channel_id$ with the channel ID. Here 3908 is the local port and 8908 is the player port. Now fire up VLC or any player capable of opening a network stream and open the http url http://localhost:8908/tv.asf.

That's it. Enjoy your show. Oh, if you want to "change" the channel, I can't think of any other way other than doing "killall -9 sp-sc" before repeating the process.

Labels: , ,

Thursday, March 08, 2007

Using screen

My God! I can't believe I didn't put more effort into looking into screen earlier. This is such a wonderful utility. Just imagine ssh-ing to a machine and having your work go on even if you face a network disconnection. Wonderful stuff!
To start a screen, type "screen" at the prompt.
You have now opened a screen. It can support multiple windows. So if you have multiple tasks, you need not open many different terminals. Try it out. Run top in the current screen. Now, open a new window by the key sequence "ctrl-a" "c". Each window can support a task as a normal shell would. To scroll through the windows, use "ctrl-a" "p" for the previous window or "ctrl-a" "n" for the next one. If you go back to the first window, you'll see top still running.
If you desire, you can also open several screens. In case you have ssh-ed to a machine and you'd like to log out but still keep your process running, you need to detach the screen before logging out. In order to detach a screen, use the key sequence "ctrl-a" "d". You will now be returned to the shell. To see the status of all the screens, do "screen -ls". The output looks something like:

[silverstreak@silverstreak Desktop]$ screen -ls
There are screens on:
22077.pts-0.silverstreak (Detached)
22153.pts-0.silverstreak (Detached)
2 Sockets in /var/run/screen/S-silverstreak.

Since both screens are detached, it's ok to log off without losing any work. When you log back on, the screens will still remain detached. In order to re-attach a screen (let's say we want to re-attach the first one in the list), do "screen -r 22077.pts-0.silverstreak". Very simple and very handy!


Printing man pages

I never did this because I was too afraid about how many commands it would involve. Actually, it's extremely simple!

Let's say you have a printer installed by the name of "printer_1". If you want to print the contents of the man page related to chmod on this printer, do the following:

$ man -t chmod | lpr -P printer_1

Here, you are piping the contents of the chmod man page through lpr to the installed printer. If you don't use a printer name, the default printer will be used.

If instead of printing the contents out, you want to make a pdf file out of them, simply do

$ man -t chmod > && ps2pdf && rm

Labels: , , ,

Friday, March 02, 2007

MATLAB - Interrupting function execution

MATLAB itself does not provide any way of arbitrarily interrupting/pausing a function at mid-execution to examine the internal function stack/variables. It is a pity since such a mechanism would be an extremely valuable debugging tool.

Finally, I realized that this is not as impossible as it seems. In fact, it is EXTREMELY simple! All that is required are four lines of code in any script/function:

[statcode, result] = system('ls sometoken');
if statcode == 0

The system command is used to run system console commands. Here, a simple check is made for the existence of the file 'sometoken' in the current directory. If the file exists, statcode is set to zero and the if condition is satisfied. The keyboard command is then executed which causes MATLAB to pause execution and return control to the command line! In order to continue execution, 'sometoken' must be deleted/removed from the current directory and the command return must be issued.

The best place for this code is perhaps in any loop that might exist in the MATLAB script/function. Then, to cause execution to pause, one simply needs to create a file 'sometoken' in the current directory.