Archive for July, 2012

Posted: July 31, 2012 in Uncategorized
Advertisements

#include<linux/module.h>

/*following header file needs to be included for all proc file system related function calls*/
#include<linux/proc_fs.h>

/*
Function : read_procmem
Desc : Following function performs the functionality to provide data to the page pointed by buf pointer. Whenever a read system call is issued to the files belonging to this driver in /proc file system , this is the function responsible to provide the data to the read system call.
*/
int read_procmem(char *buf, char **start, off_t offset,int count, int *eof, void *data){
char p[]="Hello Friend...I am from testFile but I am not in testFile\n";
printk("Test Function\n");
sprintf(buf,"%s",p);
*eof=1;
return sizeof(p);
}

static int __init mymodule_init(void)
{
/*following function call creates a file named /proc/testFile /proc file system
this function takes argument as fileName, file mode,base directory, read_proc function name and data pointer to be passed to read_proc function.
*/
create_proc_read_entry("testFile",0,NULL,read_procmem,NULL);
printk("My Module Has been loaded\n");
return 0;
}

static void __exit mymodule_exit(void)
{
/*following function call removes the file from the /proc file system
One must remove all the files from /proc while performing the cleanup otherwise it may leave the kernel in unstable state and may result in crash.
this function takes on argument as the fileName and the base directory structure pointer.
*/
remove_proc_entry("testFile",NULL);
printk("My Module has been unregistered\n");
return;
}

module_init(mymodule_init);
module_exit(mymodule_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("KAPIL JAIN");
MODULE_DESCRIPTION("Test Module");
MODULE_VERSION("0:0.1-1");

above is the sample code to generate the file named testFile in /rpoc directory. Save the above code to a file named mydriver.c and copy the file to the directory “drivers/misc” in your linux source code and add the entry in the in the same directory’s Makefile as :
obj-m += mydriver.o
Now compile the driver by issuing the following command from the same directory:
make -C ../../ SUBDIRS=$PWD modules
it will generate a mydriver.ko file in the same directory. load the driver to the memory :
insmod mydriver.ko
look for following message in dmesg output :
My Module Has been loaded
Now if you will look into the /proc directory, you will see the file named testFile. Check its size, it says 0Bytes. Now issue the cat command on the file:
cat /proc/testFile
It should give the following output:
Hello Friend...I am from testFile but I am not in testFile
In dmesg output also you will see following message:
Test Function
Whenever the file read is issued on the dynamic file from /proc, it’s output is generated by the corresponding driver’s function whose prototype is as follows:
int (*read_proc)(char *page, char **start, off_t offset, int count, int *eof, void *data);
Sine there is actually no static content in any of the file in proc file system and all the content is generated on request, hence it is called the virtual file system. It resides there but its not actually there. 🙂

http://www.dodgycoder.net/2012/02/coding-tricks-of-game-developers.html?m=1/
must read…Inspirational, knowledgeable and Funny 🙂

I have learnt this small trick on how to bring back the cursor once your mouse is hanged in linux distros. For the people aware of using the shortcuts, this may not be a new thing but it seems to be very helpful to one of my colleague and he forced me to write this post.
Problem Statement : While using VMware on linux machines, after pressing the CTRL+ALT (key combination to come out of the VMware virtual monitor), mouse cursor is not visible.
Resolution : You need to minimize the VMware window. Default Key combination to minimize the window in various desktop environments is as follows:
GNOME : ALT+F9
LXDE : SUPER+D (SUPER is the the one on keyboard with microsoft logo)
Unity : CTRL + ALT +D
KDE : ALT+F10
OPENBOX : same as LXDE
XFCE 4 : CTRL+ALT+D
FLUXBOX : same as openbox

Above shortcuts may vary depending on the version of desktop environment and system configuration like I have configured SUPER+D on all of my desktop environment to minimize the windows. Well configuring the desktop environments is an all-together different story. Here after minimizing the VMware you can see your cursor back but if you again un-minimize the VMware and move the cursor onto the screen , you may lose the cursor again. So what you need to do is instead of moving the cursor over the vmware screen, move it sideways not crossing the screen and bring it to the VMware toolbar. Now you can poweroff/restart/whataever you want to do from VMware menu.