An introduction to Linux Device Drivers – #1

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

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

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 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 …


An introduction to Linux Device Drivers – #0

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.

Fedora 11 offline mirror setup at BCREC

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.

Software Freedom Day 2009, Kolkata

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

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

Day 2, DGPLUG Fedora Activity Day, 2009 …

15th May, 2009, Day 2, DGPLUG FAD in Dr. B. C. Roy Engineering College, Durgapur.

It was around 11:30 AM, that we started the 2nd Day of FAD. The number of participants were less than the Day 1, it was around 15, but we could see some new faces. The ECE students couldn’t join because they had their internals and Lab Examinations the very same day. We started the day with some cool videos from on Okular, KSnapshot, Packagekit, etc.

It was followed by a session on basic shell commands by Harsh Verma (yevlempy). He showed to the participants the usage of basic shell commands like cp, mv, rm, … and others. Arindam Ghosh gave a nice intro on the FHS, i.e, File Hierarchy System of Linux systems. The students simultaneously tried the shell commands being taught in their respective terminals. Then Arindam and Subhodip started speaking on the execution rights and thus the chmod command. They lucidly explained the features of chmod and how to use it. Then they explained to the students that it is because of the Linux way of file permissions that Linux is very secure against viruses. They also laid stress on the evils of Graphical root login and told that they can always use the terminal for root access while logged in as normal user to do administrative tasks. They also said why to learn using the command line.

Then I ( rtnpro) took on the how to install softwares in Fedora via the YUM package manager and Package-kit. I configured the system being used for the presentation to use the Fedora 10 repository in my Pocket Hard-drive … I call it Mirror-in-a-Disk , he..he.. 🙂 . Then Subhodip explained what is a repository, and the details of /etc/yum.repos.d/ and the details in the *.repo files. Then I showed them how to install softwares via YUM and its other options like search, grouplist, groupinstall, update, etc. Then I also showed how to install packages via the Package-Kit.

It was followed by a session on the Vi Text Editor by Dibyanshu Jaiswal. He explained to the students the basics of the Vi text editor and some advanced features of it. In between, Subhodip and Arindam setup a local mirror in a computer Lab 207 to cater to the local needs for installing packages in BCREC. Other text editors like Gedit and Kwrite were also showed. Then there was a break.

After a 30 minute break, I started taking on a session on GCC, the GNU Compiler Collection.  Just as I started the session, I saw some new faces showing up. It was welcoming. I also showed them how to use google search and wikipedia to find information. For this I myself did a wkipedia search on GCC and showed it to them. Its so easy to get info 🙂 . In between Arindam and Subhodip kept on explaining on what needed more explanation to make these new topics clear. I told the basic do’s and dont’s in gcc like avoiding conio.h, using int main in place of void main. I started with the classic Hello World program and introduced to them-c, -x, -std, -o, -lm and -I options of GCC. Then we did some class assignments like the Fibonacci series. I showed them a c program involving command line arguments. There were some wonder moments during the c drills. A girl practised so much Python lately that she was typing Python code in place of c code. Here, have a look. Then Arindam and Subhodip introduced the Anjuta IDE to the students. The students who were finding the command line hard found it interesting.

A Power cut again disrupted the proceedings. However, that did not stop Subhodip from giving the students a sneak peek into Java in near-darkness on a laptop with the stuents surrounding him. He also showed them his GSoC JOSM project work, which he developed using Java. Having distributed Fedora 10 DVDs, Fedora 10 FEL Live DVDs, and stickers, we called it a day at 5:45 p.m.

Stay tuned for event Pics.

DGPLUG Fedora Activity Day … Day 1, 14 May 2009

The Linux Users’ Group of Durgapur, i.e, DGPLUG conducted a Fedora Activity Day in Dr. B. C. Roy Engineering College, Durgapur. Though it was planned to be a 1 day FAD, it got extended to one more day, i.e, 15th May 2009. The people working for this FAD to happen are Harsh Verma, Kishan Goyal, me , i.e, Ratnadeep Debnath (rtnpro), Subhodip Biswas, Arindam Ghosh, Meejanur Rahaman, Dibyanshu Jaiswal. Also, we had Rangeen Basu Roy Chowdhury with us. And also Arpita, Amrita, Debashree were there to talk on Inkscape. There was also with us Sunny Sharma, another FOSS enthusiast.

The event began at 12:00 PM in the Computer Science Department Lab No. 207 of BCREC. Projector and other necessary things were arranged beforehand by the DGPLUG volunteers working for the event. The Lab computers ran on Live Fedora Electronic Lab DVD, and a few ran on FEL Live USB. Around 25 students from various Departments like CSE, IT and ECE participated in the event. The event began with Arindam Ghosh talking on the Fedora Project. It was followed by Kishan Goyal speaking on “Myths about Linux busted with Fedora”. In between, whenever needed, Subhodip Biswas elucidated some of the topics being discussed. This was followed by a presentation on Inkscape by Amrita, Arpita and Debashree and a hands-on session on Inkscape. This was followed by me, Rangeen and Sunny giving a demo of KDE to the participants. It was around 2:10 that the 1st session ended. Then there was a break.

It was around 3:00 PM that we resumed the session. Rangeen then started with the introduction of IRC to the participants and soon Arindam and Subhodip joined the discussion. An Airtel Mobile Office Connection was arranged for the purpose. Since Airtel does not allow IRC clients like ChatZilla, X-Chat, etc. we had to use for the purpose. The participants were shown how to use the IRC. Shrink (Shreyank Gupta), Roshan08, mbuf (Shakthi Kannan) were online that time and took part in the live demo of IRC. The particiapnts were told about IRC ettiquetes.

It was followed by Rangeen’s session on Fedora Electronic Lab. Rangeen prepared some cool slides for the purpose which made the students interested in the topic. He showed them various cool FEL tools and did some small exercises on them with the students. The session was great except for the unepected power cuts that disturbed the session. Finally the FAD Day 1 was wrapped up at 4:30 PM. The participants were very enthusiastic. It was announced that the 15th May is going to be a day long session on Programming ( c, java, etc.) using FOSS tools.

After the session enden, Rangeen left for Bankura. We went back to our mess happy and exhausted.

Pictures of today’s eventw will be uploaded soon.

DGPLUG Fedora Activity Day, 2009

A Fedora Activity Day is going to be conducted by the Linux Users’ Group of Durgapur, DGPLUG in Dr. B. C. Roy Engneering College, Durgapur on 14 May, 2009.

The agenda of this FAD is to increase FOSS awareness among the students of BCREC and to introduce them to the wide spectrum of things that they can do in Linux in their day to day life.

Fedora is not just an operating system, it is a community comprised of people coming from different walks of life, yet all believing in the foundations of Fedora

Freedom Friends Features First

There is a place for anyone in Fedora, for anyone who wants to contribute, irrespective of their technical skill level. We will be trying to convey this message with the help of a talk on Fedora Project. Then, there will be a session on “Fedora in your day to day life”.

This will be followed by workshops on :

  • Introduction to Vim text editor
  • Coding in c and c++ in Linux, introduction to gcc and gdb, an Introduction to Anjuta IDE.
  • Basic shell commands
  • Programming in Java in Linux
  • An introduction to FEL

Rangeen Basu Roy Chowdhury has consented to take the session on FEL. Programming in Java in Linux will be taken by Arindam Ghosh and Subhodip Biswas, Introduction to gcc and gdb and coding in c by Ratnadeep Debnath, Basic shell commands by Harsh Verma, and Introduction to Vim text editor and Anjuta IDE by Kishan Goyal. In “Fedora in your day to day life”, Amrita, Debashree and Arpita will be talking on the Free graphic and imaging tools like Inkscape and Gimp. If required, Fedora installations will also be done. Free Fedora 10 installation DVDs will be distributed.

People working to conduct this FAD :

  • Arindam Ghosh
  • Subhodip Biswas
  • Ratnadeep Debnath
  • Harsh Verma
  • Kishan Goyal

Expected attendees : Students of 1st, 2nd and 3rd year from CSE, IT, ECE, EIE of Dr. B. C. Roy Engineering College.

The DGPLUG FAD 2009 event page can be found at

Further details and updates will be notified soon. Any suggestions are welcome.