Today we’ll be discussing a basic c code, the famous hello.c, which will be loaded as a kernel module and discuss some of the basic aspects related to it.

#include <linux/init.h>

#include <linux/module.h>

MODULE_LICENSE (“GPL”); // included in module.h, tells about the license the code is having.

static int __init hello_init (void)

{

printk (KERN_ALERT “Hello, world\n”);

return 0;

}

static void __exit hello_exit (void)

{

printk (KERN_ALERT “Goodbye\n”);

}

module_init (hello_init);     // hello_init is the initialization function

module_exit (hello_exit);     //hello_exit is the exit function

The header <linux/init.h> contain various declarations and definitions related to the loading and cleaning up of modules. The macros module_init and module_exit are declared in the <linux/init.h>. The argument functions passed to module_init( ) and module_exit( ) are executed at the loading and unloading times respectively of a module. The initialization function, basically, sets up the device to be used later. The exit function cleans up the device ( opposite to initialization).

Now coming to the __init and __exit terms used in the code. The __init in static int __init hello_init (void) specifies that the hello_init function is executed only at module load time. The module loader drops the initialization function for other uses once the module is loaded. The initialization function better be static since they are not meant to be visible outside the specific file ( not mandatory though). Similar explanation goes for __exit. This makes the exit function executed only at exit time.

The printk function, at a first glance, might look identical to printf of <stdio.h>, but printk lets you set priority levels for the message, like KERN_ALERT, KERN_INFO, etc. We’ll discuss about them later.

How to compile the code and execute it. Let us assume that you named the source file above as hello.c. Use any suitable text editor to write a Makefile as below :

obj-m    += hello.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
rm -f *~

I hope you have the kernel source in your system. If not you can get the kernel source from kernel.org. If you are using Fedora, you can do:

# yum install kernel-devel

To compile, in the current directory ( where there is hello.c and the Makefile) do :

$ make

Then change to super user by : $su <enter>

and do : # insmod ./hello.ko

If you do : # tail -f /var/log/messages (You can open this in a separate terminal to view the system logs)

then you will be able to see a line saying “Hello, world”. This is what your hello_init( ) was supposed to do at module load time. You can also see the module name “hello” among the list of loaded modules doing lsmod. Now you can unload the module do :

# rmmod hello

Now in /var/log/messages, you will see “Goodbye”. This is due to hello_exit( ).

continued …

I’ll be honest, I am neither a kernel hacker nor a device driver writer, but I want to be one. I am studying the Linux Device Drivers 3, the LDD 3. It is an effort from my end to document what I have understood from reading the LDD 3. There might be some errors or misinterpretation on my part and I will be glad if anyone corrects me. I will be trying to keep the things as correct as possible.

We ( me, Bama and Subhrodeep) left for Ganga Sagar Mela from ISKCON, Mayapur along with ISKCON devotees on the Monday morning of Jan 11, 2010. We had lots of fun in the bus. Fisrt, our bus was special. It was the bus in which there was the Gour Nitai deity. We started the journey with Narsimha Arati and we prayed for a safe journey. Then we chanted the holy names and the devotees from outside India started melodious kirtans.

We reached Govinda’s at Kolkata at around 1 PM. There we all had Prasadam. Then we resumed our journey towards the Diamond harbour. It was evening when we reached there. Then we had to take a ferry from one of the JETTYs to cross the Ganga river. I don’t exactly remember from which JETTY we got on the ferry (as we were moved from one JETTY to another a couple of times). I was tired, but the chanting of the HARE KRISHNA maha mantra kept my spirits up. Once on the ferry, we again started sankirtan. After some time ( I think more than an hour) we reached the island of Kapil Muni. After waiting for some time in long queues, we finally got on a bus to the Ganga Sagar camp site.

From there, we took the road no. 4 to ISKCON’s camp site. We met Sankarshan Prabhu ( General Manager, ISKCON, Mayapur). We took Prasadam at around 12:30 PM and then went to our tent for sleep. Next day, we woke up for Darshanarati. After Darsanarati, we got registered as volunteers for ISKCON to serve the pilgrims. ISKCON here was one of the NGOs to serve the pilgrims coming from different places. Among the various services provided by ISKCON, a few are free Prasadam distribution ( or the FOOD FOR LIFE) for 1.5 lac pilgrims, free accomodation for pilgrims, free medical support to pilgrims, Gita Donation, book distribution, lectures on spirituality and how to chant Hare Krsna to be happy. etc.

After having morning prasadam, we went for Nagar Sankirtan. We circumnavigated the island doing sankirtan and dancing. After returning from Nagar Sankirtan, we had our lunch Prasadam, and then we took some rest. From afternoon onwards, we setup some stalls for book, picture, chanting kits and other gift item distribution. It was very nice experience to help Srinivas and Tirthanga Prabhu in the stalls and interacting with many inquisitive pilgrims and answer their queries. Each day there were aratis, dramas, bhajans, lectures, nagar sankirtan, etc. We were most of the time busy serving and were not at all tired. I assisted Gauranga Chaitanya Prabhu to show pilgrims how to chant the HARE KRISHNA maha mantra and we did chanting sessions throughout the day. Similar was the schedule for the other days. I also made some new friends, one of them is Premavikasa Prabhu. He plays nice mridanga, sings great and what to speak of his dancing. It’s like there are springs in his joints. :D HARIBOL

On 14/01/2010, we had bath in Ganga Sagar at around 2 PM. The water was chilly though. We prayed to Ganga Mata to give us Krsna Prema. We didn’t come to Ganga Sagar to wash our sins. We came here to serve other devotees and we don’t care for sins or good karma. Wherever we are, if we are able to chant the holy name, we are liberated -> happy. The weather in the island was good, not that cold as we expected. Good water supply was arranged by the Government. The water was being pumped out continuously from under the ground, so it was warm. Nice tasty prasadam was cool. We got T-Shirts for being volunteers for Ganga Sagar 2010.

On Friday, 15/01/2010, we left for Durgapur with the devotees from Durgapur at around 12:30 PM. It was a whole day journey. It was also a solar eclipse that day. It was quite troublesome to get on the ferry. After that the journey was smooth. We reached Namkhana at around 4:30 PM. There the bus from Durgapur, ISKCON was waiting. We board the bus, and soon I fell asleep. We reached the ISKCON temple, Durgapur at 1:15 PM.

The trip to Ganga Sagar was indeed sanctifying and I hope I will be able to chant HARE KRISHNA with more devotion.

Now I am back to my mess and I have to work. Have to read LDD 3, top in the semesters, need to code and chant.

Yesterday, I finally completed downloading the Fedora 12 i686 DVD iso. I then tried to install Fedora 12 from iso, as I did when I installed Fedora 11 from its ISO image. But this time, when it came to customizing the packages, it was asking for a network connection to get the softwares from the online repositories ( when no Install Disc was inserted) and when I kept the F11 DVD inserted in my laptop, it took the package list from the F11 DVD. Didn’t expect that.

Then I tried installing F12 from a DVD, and installation was completed successfully. It good to see EXT4 support for GRUB this time. Also, there is the default kms support for NVIDIA cards with the Nouveau driver. But the Nouveau driver is still limited to provide 2D support only ( work is going on for enabling its 3D suport).  Fedora 12 implements improvements in Xorg. The official NVIDIA driver this time comes with customizable PowerMizer and allows to chose among different screen resolutions ( which was missing before till Fedora 11 and the then latest NVIDIA drivers). This not the end of the story for NVIDIA cards. Even after installing Nvidia drivers, nouveau won’t let it start. You have to add the following kernel option for the kernel in which you installed Nvidia :

rdblacklist=nouveau vga=0×318

The latest official NVIDIA driver is a bit faulty (w.r.t the Xorg implementation in Fedora 12), and does not properly support OpenGL. Compiz does not work, KDE does not behave properly, neither do Moblin Desktop Environment with the current state of NVIDIA drivers.

Fedora 12 implements initramfs (using Dracut) rather than initrd. Boot up has become faster. F12 also allows runtime starting and stopping of bluetooth drivers. NetworkManager has undergone some improvements ( write capabilities to system wide network connections). There has been also a number of improvements in the Virtualization arena (qemu + kvm). Empathy has replaced Pidgin and gnote has replaced Tomboy. The previous plymouth startup screen from F11 has been retained. Fedora has always been developer friendly distro with an array of latest developer tools.

But at the end of the day, even after having an Nvidia graphics card, I can’t turn on the 3d effects. Hope that Nvidia will resolve this problem soon or Nouveau starts supporting 3D. Apart from that everything is fine. I have setup my required devel environment and it’s time to work. I also made a small 300 MB dump of the basic packages I have installed in my system to support multimedia and other things. It has also got a script to autorun the install process. I will soon upload it online.

Have a nice day :)

Saturday, 31 October, 2009 I set up an offline Fedora 11 mirror in BCREC. I used the fedx makefile for the purpose of syncing the repository from my pocket HDD to the mirror PC ( an HP dual core system with Fedora 10 installed in it). I then setup a dhcpd server in the machine with the help of gdhcpd. I wrote a how to use the service and put it on the Desktop. I also wrote a fedora-local.repo which could be used by the clients to configure their machines to use the service. This should enable newbies without internet connection to get packages and softwares of Fedora 11.

11th October, 2009, I, Kishan and Meejanur started our journey to Malda for the workshop at IMPS College. We boarded the Gour Express from Burdhaman Junction at 00:30 Hrs 12-10-2009. Kushal and Harsh boarded the same train from Sealdah. We reached Malda Town at around 6 AM in the morning. We got together in the station and had some chit-chat amongst ourselves. Kushal was taken to a hotel for his stay and we were taken to the college hostel by the college vehicle ( Maruti Omni).

WORKSHOP Day 1 12/10/2009

After having some rest, we freshened up and had some breakfast. We then went to the college at around 9:15 AM. It was a session for the 4th year IT students of IMPS college. Kushal gave a brief introduction on FOSS and then asked us to give a small introduction on Fedora and about our activities and how we started using Fedora. Then followed a session on Python from the very basics. We assisted Kushal by helping the students solve their doubts in their places. It was only coding using the python shell for the 1st day. Students were asked to solve a few problems. Good performers were given Fedora Badges. The session lasted till 1:00 PM and then there was a break.

After the break, it was time for the session for the 3rd year IT students of the college. Kushal gave an introductory talk on FOSS and Fedora. Then just like the previous session, it was all Python, hisss… They started enjoying python already because of its simplicity, elegance. It was all Python for the day, but only in the interpreter.

WORKSHOP Day 2 13/10/2009

The session started with the 4th year students of IT as the day before. They were introduced to the vi editor, and then some python scripting using the vi editor. Then they were told about various projects they can do within Fedora. Kushal also told them about git. Kushal also demoed them some PyQt and PyGTK applications and some Django. They seemed to like Django among others.

Time for a break.

After the lunch, it was time for the 2nd year students of IT. They have learnt C in the previous semester and were then doing Data Structures. So they were given a very basic introduction to vi editor followed by C with gcc. Then it was followed by a basic session on Python.

WORKSHOP Day 3  14/10/2009

The 3rd day of workshop started with the 3rd year IT students. They continued with Python. They along with some teachers started enjoying python. In the second session, the 2nd year IT students were taught more python. Python is simple, more readable, and after all the codes written in Python are much smaller to those written in C. The students were also told how to start contributing. Some students brought their laptops for installing Fedora. We also made a 1GB mini repository with basic packages and a shell script to automatically install them.

The 3 Day Fedora workshop was indeed a good experience for us. But it will be a success if the students start contributing to the community. For this, the teachers have an important role to play and we hope they will.

Event pics can be found at

http://www.flickr.com/photos/kushaldas/sets/72157622631345996/

I became desperate yesterday night to do some useful things, anything. Had a long offline Puja Holidays. I was struggling to understand “How to write Makefiles”, and yesterday it clicked and I ended up writing a Makefile for the ongoing fedX project. Though the makefile which I wrote is not that great, but I have a start now. Committed the changes to the fedX repository at

http://gitorious.org/~rtnpro/fedx/rtnpros-fedx-clone/

It was around 4:00 AM in the morning already. Made some changes in my gitorious project clones. Apart from that, I was trying to download the rpmfusion repositories for Fedora 11. I was using rsync on multiple screens for the purpose. But again and again, rsync used to stop downloading after working for sometime. Then I tried a Firefox addon “DownThemAll” and was very happy to see it work. All I needed was to browse the repository page listing all the packages, right click and select DownThemAll. And then I just needed to select where I want to save the downloaded files and start it. It downloads multiple files simultaneously and does not halt when one of the files cannot be downloaded, rather it pauses it and moves to others. It also supports resume, and has an option to skip the already downloaded files.

But I could not download the directories with DownThemAll. I guess it works only for files. Need to do some research on it. Any way, you can try to use DownThemAll. I think you will like it.

Finally, I went to sleep at 4:45 AM with my laptop running DownThemAll to download the rpmfusion repository. When I got up today morning, it was running fine. :D

On 15th September, 2009 the Software Freedom Day was celebrated in

The CSI Auditorium,

Computer Society of India, Kolkata Chapter,

5, Elgin Road, 4th Floor,

Kolkata – 700020

The following talks and discussions were planned for the SFD 2009, Kolkata :

A. Mani to speak on “The Fedora Project”

J. P. Mathews to speak on “Using Linux on PCs with limited resources”

Ratnadeep Debnath(me) to speak on “Fedora-12 Highlights”

Snehashish Chakraborty to speak on “RabbitMQ”

From Durgapur, me, Kishan Goyal, Harsh Verma and Bama Charan Kundu had come to Kolkata on 15th September to attend SFD. We reached the CSI auditorium at around 4:30 PM. There we met with A. Mani. We had a small introductory chat with each other. We were given some SFD goodies like badges, balloons, etc. Then we setup Kishan’s notebook for the purpose of presentation and successfully connected it to the projector.

At around 5:00 PM, J. P. Mathews and some people from DPS Technologies India, and Rohit joined us in the SFD’09. Some students ( engineering) also turned up. There were around 12 people attending the event. A. Mani welcomed everyone to the event and then J. P. Mathews said that Snehashish Chakraborty, unfortunately, could not come to the event. Then he distributed leaflets for the new

Sapienza Home PC coming preloaded with Ubuntu GNU/Linux.

Specifications : Intel ATOM Processor 230 @ 1.6 GHz + Intel original MotherBoard, IGB RAM, 160 GB SATA HDD,

17″ TFT Display with in-built speakers, Keyboard and mouse, Optional DVD drives, etc.

Starting from Rs. 14,900 onwards.

Then A. Mani came up with his talk on the Fedora Project. It was quite informative and introduced the attendees to the features of Fedora, the Fedora Community, foundations of Fedora, Open Source. It was followed by me ( rtnpro) talking on what is new Fedora 12. Topics of the talk were General Introduction to Fedora Project, Fedora Release Cycle, features in Fedora 11, things which couldn’t be implemented in Fedora 11, what’s new in Fedora 12, common Fedora 12 bugs, how to contribute to testing. As an example, I mentioned the various opensource projects that the members of DGPLUG has been involved into. I also highlighted the significance of portable repositories, which is of vital importance when internet connection is a constraint.  Slide used for the presentation can be found at

http://www.slideshare.net/rtnpro/fedora-12-introduction

Then there was a small break for tea. After that, J. P. Mathews gave his talk on Using Lnux on PCs with limited resources. He also discussed about the Sapienza Home PC, which is very affordable, running on Ubuntu GNU/Linux. Then he also mentioned about Linux being used at schools and educational institutions. LTSP is a good technology to be used for the purpose. He also showed interest in the ongoing Bijra Project of DGPLUG ( using LTSP). Idea of having a local flash storage in the LTSP terminals were also discussed. Open Source virtualization tools were also discussed and compared with VMWare. Mr. Mathews also mentioned a functional programming language named Erlang, and Open ERP frameworks.

This was followed by free media distribution of Fedora 11 DVDs and Ubuntu 9 Live CDs.

The event concluded at around 7:15 PM. The discussions held during the event were very interesting and innovative. This marks a long path to travel. The event was a success with people  getting in their head to foster a general understanding of software freedom, and encourage adoption of free software and open standards.

Using Linux on PCs with Limited ResourcesU

Happy Durga Puja to all.

It has been a long run since I left for Durgapur after the Software Freedom Day,2009 at Kolkata. I reached Howrah station at around 8:15 PM on 15th September 2009. Though I got an  e-ticket for Durgapur in the Danapur Express which was about to leave from Howrah at 9:35 PM, I still didn’t have a hard copy. I thought I could get a print out at the station from the .html file of the e-ticket I was having in my mobile phone. As ill luck would have it, the one cyber cafe that was there in Howrah station was being demolished (might be for repairs … drastic). I had plenty of time though, so I went outside the station to try my luck. With some help from the folks out there, I started my venture to find a place to print my ticket. Couldn’t find any in the proximity. Finally I found one, but the shop’s printer ran out of ink. What the hell! It was 9:15 PM and so I returned and boarded the train. My mobile phone was almost out of charge, and so I transferred the only document of my ticket to my laptop. When the TTE came, I showed him the html file and after some arguments, I was able to convince him. It could have been worse. I didn’t have my Identity Card with me.

I reached Durgapur at 11:30 PM. Then at around 3:00 AM in the morning boarded the JHAJHA-Guwahati Express for AlipurDuar Junction, my father’s home town. Quite uneventful days in AlipurDuar and Coachbehar ( my mother’s home town) except for family reunion. Finally came back to Guwahati on 20th September, 2009.

First thing I did was install linux (omega) in my father’s computer and explained the advantages of it to my father. Next day, my father told his colleagues that in linux, you don’t need to worry about viruses ( in general). I started getting calls from them to install Linux in their systems too. I did two installs of Omega coupled with the other packages installed from the Fedora 11 repository I am carrying in my portable HDD.

Internet connection had been quite unstable here. The BSNL link most of the times is down and since yesterday, the phone line is dead. This week, mbuf made some new plans for fedx and told me to go through Makefile HowTo. He assigned me some tasks. Today I have completed the first one of them … that was to write a makefile rule to check is vsftpd is installed in a system. If not, to install it in the system. Made a commit today in my fedx’s clone at gitorious. Thanks to smartnet, it came as life saver, when BSNL is down.

This week, did lots of fun with my brother. Went for long distance biking, to restaurants, to computer shops to enquire about notebooks for him. Today it was Ashtami, we fasted till noon and offered pushpanjali to Goddess Durga. Then in the evening, me and my BRO went to see the Durga Pujas in Maligaon in the evening.

Tomorrow I plan to go to Accoland with my brother. Looking forward to a great day :D

Today, on 5th September, 2009, I completed writing the fedX wizard. I didn’t write it from scratch, though. I found the grsync source code, and the GtkAssistant tutorial in http://www.linuxquestions.org/linux/articles/Technical/New_GTK_Widgets_GtkAssistant very useful and informative for a newbie like me. I used parts of code from the above mentioned sources. I pushed the wizard.c file today in my gitorious clone of fedX at

http://gitorious.org/~rtnpro/fedx/rtnpros-clone

The code is not full proof, as is expected, but I will be working on refining the code. If bugs come during its usage, I will try to fix them. The fedX wizard asks the user to enter the source (updated repository in the external storage) and destination (repository in the offline mirror) when fedX is ran for the first time. Then using Glib g_key_file functions, we write this information and other default settings under the session name “fedX” in the grsync.ini file and save the settings. These settings can be updated any time from within grsync or by running the fedX wizard again.

Now, I have started working on the fedX launcher, which will be calling grsync with fedX as the default session. Apart from that, fedX also needs to verify the signatures of the packages in the updated repository to see if they are all from proper sources.

Next Page »