Monday, December 21, 2009

Website updated

While updating some contents in my site - http://sam.botcyb.org, I thought of changing the looks as well. After spending almost a day fiddling with the stylesheet I couldn't come up with a design that pleased me. Frustrated, I came up with the best solution - dump all stylesheet and images. Pure text in pure html, nothing else!

(UPDATE: Finally added a css once again! - 21/12/09 )

Wednesday, December 16, 2009

Wikileaks blocked by BSNL - India follows China in censorship

At last it seems like India is following China's footsteps in restricting her citizens' access to the Internet. Wikileaks.org - a well known site that "publishes anonymous submissions and leaks of sensitive governmental, corporate, organizational, or religious documents, while attempting to preserve the anonymity and untraceability of its contributors" (description from wikipedia entry ) has been apparently blocked by the Sarkari ISP- BSNL. Tonight, while trying to lookup a "confidential" (alas! no longer confidential) working paper (wikileaks link) about India's proposed "Multipurpose National Identity Card" (link), I was unable to reach Wikileaks.org from my BSNL Broadband connection directly, although the site could be opened through most public proxy servers. Just to verify that it is indeed the Sarkari BSNL who is trying to act smart, I connected through Airtel Mobile Office EDGE connection and I could easily view the page. What a shame for a "Democratic Republic". It seems India is really trying to join the "elite" league of countries like China and Iran. (Others kindly check if your ISP allows access to Wikileaks.org , if not try this mirror at a different IP address - wikileaks.se .)

Friday, October 9, 2009

My new Nokia 5800 Xpressmusic

Recently I bought a Nokia 5800 Xpressmusic Smartphone to replace my aging Nokia 6600. 5800 is Nokia's first device based on the S60 5th Edition platform, running Symbian OS v9.4 on a 434MHz ARM11 CPU. Notable features include large(3.2inch 640x360) resistive touchscreen with tactile feedback, HSDPA(3.5G), 802.11b/g WLAN support, GPS (with optional AGPS), accelerometer, stereo FM radio with RDS, 3.2Mpixel camera with Carl Zeiss Optics, blah blah... the list is quite long. For a complete list of specifications see the link to the device specs page, there is no point in copy-pasting the list here.

After unpacking I plugged in an Airtel 2G SIM and the 8GB MicroSD that came with the device. Unfortunately the state owned BSNL is the only mobile service provider in India providing 3G connectivity. Though BSNL has excellent 2G coverage all over the country, their 3G coverage is limited only to few cities. Other operators are yet to receive licenses to roll out 3G networks. So for the time being, I'll have to remain contended with 2G services, which means no high speed data and no video call.

The sound quality of the device didn't really disappoint me, however being an Xpressmusic phone, I had expected better quality headphones. The HS-45 headphone that comes with it, is of average quality. I plugged in my friend's Sennheiser headset and the audio quality simply blew me away. So there is nothing inherently wrong with the device's audio output, it is just that the supplied headphones are of mediocre quality.

The inbuilt browser is nice. Adobe Flash is properly supported (in fact excellent flash support, one can watch YouTube videos smoothly over a WLAN connection).

GPS reception is good, I could get my location even indoors. However the initial lock-in time is variable. Sometimes is takes upto 5mins to lock-in to the satellite signals, whereas at other times it takes less than a minute. However with AGPS enabled, startup becomes lightning quick. AGPS allows the device to download the ephemeral data about the GPS satellites from Nokia's AGPS server through the internet, rather than decoding the same from the GPS signals. AGPS works only if a cellular packet data connection is available (for some strange reason it can't use WLAN).
 The Nokia Maps application is utter crap, atleast for me. It doesn't provide any detail about any location in eastern India. On the other hand Google Maps just rocks. In the satellite view, I could even figure out the room of the building, where I was. Google Maps also provides turn by turn navigation instruction for traveling from point A to point B on the map. With inbuilt Google Latitude, selected friends can see my instant location on the planet at anytime and I can see them on the map as well.

The inbuilt mail client is simple with minimal features but works quite well. I configured it for periodically monitoring my Gmail Inbox and a few other IMAP Folders and alert me whenever a new mail arrives.

The music player app is good enough for playing wma, mp3, aac, aac+, awb and perhaps someother formats as well. However syncing the music folder with my GNU/Linux computer was a bit troublesome. I'll write about this in a subsequent post. Initially I had to use Nokia Music(part of Ovi Suite) on Windows XP to transfer tracks.
The device comes with a subscription to Nokia music store, which allows downloading of first 100 tracks from the site free of cost. Unfortunately all the songs in Nokia's music store incorporates Microsoft's DRM, making them unplayable in my GNU/Linux laptop. Really annoying! I can't freely play songs that I have legally downloaded.

Anyway as a concluding remark, I must add that the phone is quite hackable(though nothing compared to a Freerunner!), in the sense that Nokia freely provides the SDK/S60 emulator as well as the Symbian C++, Open C++ and Java API for accessing the device features. Nokia has also ported Python to the S60 platform and I could easily get a Python shell running on the device. I could access the shell through a serial console emulated  over a bluetooth link. The well documented APIs, helped me to very easily write simple Python scripts to play around with the sensors(accelerometer, rotation, ambient light, proximity and gps positioning) scattered throughout the device. I haven't written any full fledged application, but the potentials are limitless.

Saturday, April 11, 2009

Making inactve USB Hard Disk spin down automatically in Linux.

I have a 400GB Seagate IDE HDD connected to Mars, our hostel's file-server using an USB enclosure. The USB enclosure is a cheap "Made in China" product. Consequently it has some special "features". One such notable "feature" is that the disk is kept spinning by the controller even if there has been no disk I/O for a long time. I have three other USB disks connected to the same machine, a 1TB Seagate FreeAgent Desk External Drive, a 500GB Maxtor Basics External Drive and a 2.5" 60GB Fujitsu SATA Disk inside a Transcend USB enclosure. All of these spin down themselves if there has been no I/O for sometime. Keeping the hard disk spinning unnecessarily for ever, not only wastes power but also overheats the drive, thereby reducing its life.

I tried noflushd, which is supposed to force idle hard disks to spin down, but found it to be of no help. USB enclosure generally work by performing an SCSI emulation over USB. sdparm is an utility which can be used to send simple SCSI commands. A peep into its manpage revealed that the disk could be ordered to spin down by sudo sdparm -C stop /dev/sdb1 where sdb1 is the required disk (the disk has a single partition, "sdparm -C stop /dev/sdb1" and "sdparm -C stop /dev/sdb" did the same thing here, however if there are multiple partitions, it is more meaningful to specify "/dev/sdb" rather than "/dev/sdb1", since it is the disk that stops spinning).

However I need to do this automatically whenever the disk is idle. First, it is necessary to check whether the disk is active or idle. Info about disk I/O is available from /proc/diskstats.
cat /proc/diskstats | grep sdb1
shows info about sdb1, the output is something line this:
8 17 sdb1 210583 56943 24739612 2328860 11777 24804 292648 69260 0 1209770 2397450

It has several fields after "sdb1", denoting the following:
Field 1 -- No. of reads issued
Field 2 -- No. of reads merged
Field 3 -- No. of sectors read
Field 4 -- No. of milliseconds spent reading
Field 5 -- No. of writes completed
Field 6 -- No. of writes merged
Field 7 -- No. of sectors written
Field 8 -- No. of milliseconds spent writing
Field 9 -- No. of I/Os currently in progress
Field 10 -- No. of milliseconds spent doing I/Os
Field 11 -- weighted No. of milliseconds spent doing I/Os


Field 9 is of importance here, a nonzero value indicates disk activity. Any particular field can be dug out easily using grep and AWK (mawk interpreter is the obvious choice here).
cat /proc/diskstats | grep $DISKNAME | mawk '{ print $(NF-2) }' does the trick.
mawk '{ print i }' prints the ith field.
The variable NF is equal to the number of fields. We are interested in the field 3rd from the end. Hence $(NF-2).
Now this is probabilistic, if there is no I/O in that particular instant
cat /proc/diskstats | grep $DISKNAME | mawk '{ print $(NF-2) }'
will yield 0. To ensure that the disk is really inactive, the check has to be carried out quite a few times.

There is another pitfall, there are 4 USB disks connected to the machine. Which one would be named sdb is not fixed. At every reboot this may change. On the other hand uuid of a disk never changes (unless the partition table is modified). So the name of the disk has to determined from its uuid. grep, AWK, and sed comes to our rescue once again.
DISKNAME=`ls -l /dev/disk/by-uuid/ | grep "c5df6a02-b7a6-4f39-ad26-7eb915b76709" | mawk '{ print $(NF) }' | sed s_\.\.\/\.\.\/__`
What this essentially does is explained below.
"ls -l /dev/disk/by-uuid/" gives the following output

sambit@mars:~$ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 2009-04-07 14:20 0db6e806-8d4b-4968-8ccc-c00af59bb065 -> ../../sdc1
lrwxrwxrwx 1 root root 10 2009-04-07 14:20 4294e561-df28-4ddd-a689-0aba31d4d663 -> ../../sda2
lrwxrwxrwx 1 root root 10 2009-04-07 14:20 4cb989c6-87b7-4179-bb4d-81b2b0193ab2 -> ../../sdd1
lrwxrwxrwx 1 root root 10 2009-04-07 14:20 4cf2093e-f08c-4127-ae75-fff11edd81ae -> ../../sdd2
lrwxrwxrwx 1 root root 10 2009-04-07 14:20 87ba9975-056d-4635-85e4-53f1c76d57fb -> ../../sda3
lrwxrwxrwx 1 root root 10 2009-04-07 14:20 a74b47fb-a33c-4a5a-ad62-0bc831f6ffda -> ../../sdd3
lrwxrwxrwx 1 root root 10 2009-04-07 14:20 af0c007b-a15c-4661-84eb-7dc689dec861 -> ../../sda1
lrwxrwxrwx 1 root root 10 2009-04-10 22:09 c5df6a02-b7a6-4f39-ad26-7eb915b76709 -> ../../sdb1


ls -l /dev/disk/by-uuid/ | grep "c5df6a02-b7a6-4f39-ad26-7eb915b76709"
narrows it to:
lrwxrwxrwx 1 root root 10 2009-04-10 22:09 c5df6a02-b7a6-4f39-ad26-7eb915b76709 -> ../../sdb1


ls -l /dev/disk/by-uuid/ | grep "c5df6a02-b7a6-4f39-ad26-7eb915b76709" | mawk '{ print $(NF) }'
prints the last field:
../../sdb1

Finally sed puts some finishing touches, by replacing "../../" in "../../sdb1" with "".

ls -l /dev/disk/by-uuid/ | grep "c5df6a02-b7a6-4f39-ad26-7eb915b76709" | mawk '{ print $(NF) }' | sed s_\.\.\/\.\.\/__

sdb1

So putting everything together, the script at-last looks something like this:

#################################################################################################################################
#!/bin/bash
DISKNAME=`ls -l /dev/disk/by-uuid/ | grep "c5df6a02-b7a6-4f39-ad26-7eb915b76709" | mawk '{ print $(NF) }' | sed s_\.\.\/\.\.\/__`
let a=0
#check 100 times with 0.1s gaps,
#and go on adding
for i in `seq 0 100`
do
let a=`cat /proc/diskstats | grep $DISKNAME | mawk '{ print $(NF-2) }'`+a
sleep 0.1s
done
echo $a
if [ $a == 0 ]
then
echo "No Activity"
sdparm -C stop /dev/$DISKNAME
else
echo "Disk Active"
fi
exit 0
#################################################################################################################################

I added this to crontab and made it run hourly. The hard disk can rest in peace for sometime in between heavy work now.

Saturday, February 7, 2009

IISERK Haringhata Campus

Making a post after quite a long time. In the meantime a lot of things have changed here. This is my first post after moving to the Haringhata Campus. From the hustle and bustle of Kolkata we were suddenly "teleported" to the calm and serene atmosphere of Haringhata, quite a bit jump it was.
The location didn't quite disappoint me, though many "mall hoppers" and a few "privileged ones" (their homes are in Kolkata) who earlier could slip into the comfort of their homes every weekend easily were unhappy, it has become a bit more difficult for them to do so now. However one thing that I really miss is the 2Mbits connection. There is no broadband connection yet in the hostel, and currently we are trying hard to manage using a 17KBytes Wireless Dialup connection over CDMA. There is little chance of getting any high speed connection in this remote location. The administrative building does have a decent leased line, but it is at a few minutes of walking distance from the hostel making it difficult to land up there late at night.
Apart from this annoyance, life is quite peaceful here. Being located far from the city, the night sky remains glare-free, which provoked a few of my friends to plan to buy a telescope for star-gazing. I am too looking forward for this.

Thursday, January 8, 2009

Adventures with IPv6

I spent the past couple of days, tinkering with an old Linux box, trying to set up a fully functional IPv6 network, complete with an IPv6 webserver, nameserver, mailserver, network router and firewall.
The job is partly done.
The nameserver, webserver, network router and firewall are working quite well.
The website can be accessed here http://oak.ipv6.iiserk.net(Provided you have IPv6 connectivity). It runs on a rickety PIII running Ubuntu 8.04.1 and connected to my friend's home ADSL connection. Power failure are quite a common affair in our region (in almost the whole country, to be honest!) and there is no power backup for the server, so if it appears to be down, kindly check back sometime later.
The nameserver ns1.ipv6.iiserk.net manages the DNS records for the subdomain ipv6.iiserk.net.
I hope to get the mailserver up and running quite soon.
I'll also come up with a detailed documentation on how I got the things running, sometime in the near future.
Anyway for this half-crappy IPv6 implementation, I got this from Hurrican Electric Internet Services:

(It is a certificate, but removed the JScript, as it was causing the page to load slowly)
It started with "newbie" level, and is improving!
More on IPv6 soon... may be in a day or two.