LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-16-2010, 07:19 AM   #1
rtlab
LQ Newbie
 
Registered: Mar 2010
Posts: 7

Rep: Reputation: 0
Smile Kernel Module


Hello everyone,
I am writing a very simple kernel module that is available on the net.
But while compiling it I am getting the error for include files.

Can anyone please tell me what is the procedure for include files for kernel modules.

It would be really helpful if I get an example or a link I can get to learn about include files and kernel module programming starting from basics.
 
Old 03-16-2010, 07:21 AM   #2
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 69
Well what is the exact error? What is your code? What does the module do? What are the lines that are erroring? What command are you using to compile? How much do you already understand about kernel development?
 
Old 03-16-2010, 07:37 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
rtlab;
I'm guessing that you are referring to C statements such as:
#include "stdio.h"

Are you already familiar with C programming? If not, I would not try to learn C by writing kernel modules.
 
Old 03-16-2010, 07:53 AM   #4
rtlab
LQ Newbie
 
Registered: Mar 2010
Posts: 7

Original Poster
Rep: Reputation: 0
I know C programming by the way.
The Module I got only have printk in the init_module() and that in cleanup_module().
as i said i got it from the net.

It has a include file named uaccess.h
It is not getting this file.
I dont know where exactly the kernel module needs its include files.
Is there any specific location.

I am compiling it using gcc.
and then using a Makefile for making a .ko .
Which I suppose then will be inserted as a module using "insmod"
and removed using "rmmod"

If there is any other way to do it please tell me.

I am reading Linux Kernel Module Programming .pdf O'reilly 2nd edition.

Last edited by rtlab; 03-16-2010 at 07:55 AM.
 
Old 03-16-2010, 07:55 AM   #5
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 69
I think there is more than one module on the net, like three or four, so perhaps you could link us? Paste it in?

Does uaccess.h exist on your machine? Can we see your Makefile?
 
Old 03-16-2010, 08:04 AM   #6
rtlab
LQ Newbie
 
Registered: Mar 2010
Posts: 7

Original Poster
Rep: Reputation: 0
the code looks something like this
I dont know why it requires that uaccess.h

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/uaccess.h>

int init_module(void)
{
printk(KERN_INFO "init_module() called\n");
return 0;
}

void cleanup_module(void)
{
printk(KERN_INFO "cleanup_module() called\n");
}

I tried to locate uaccess.h but not in linux named folder
currently i dont hvae that machine with me so I can not tell you all the details surely



Makefile looks like this

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
 
Old 03-16-2010, 08:05 AM   #7
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware & Slackware64 14.1
Posts: 7,453
Blog Entries: 55

Rep: Reputation: Disabled
What distro are you using? Have you got the kernel headers installed?
 
Old 03-16-2010, 08:11 AM   #8
rtlab
LQ Newbie
 
Registered: Mar 2010
Posts: 7

Original Poster
Rep: Reputation: 0
I am using Red Hat Enterprise 4.
I am new to this. Pardon me but,
what is Kernel headers?
 
Old 03-16-2010, 08:30 AM   #9
rtlab
LQ Newbie
 
Registered: Mar 2010
Posts: 7

Original Poster
Rep: Reputation: 0
How do I see for the Kernel Headers
 
Old 03-16-2010, 08:34 AM   #10
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware & Slackware64 14.1
Posts: 7,453
Blog Entries: 55

Rep: Reputation: Disabled
I've never used Red Hat, but you should be able to search for and install them via your package manager. Look for "linux kernel headers", they're the include files needed for building modules.
 
Old 03-16-2010, 11:20 AM   #11
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by rtlab View Post
I am using Red Hat Enterprise 4.
I am new to this. Pardon me but,
what is Kernel headers?
Almost any C program relies on information stored in header files (xxx.h). If the program is going to interface with the Linux kernel, then it needs the header files that were used to compile the particular version of the kernel in use. (These are the "kernel headers")

If you install the full source code for the kernel, you will get the headers automatically. Or--you can typically install only the headers.

I have the kernel headers on my system, but their is no "uaccess.h"----BUT: This Google search suggests strongly that "uaccess" has nothing to do with the kernel:
http://www.google.com/search?q=uacce...ient=firefox-a

Please tell us if what you are doing is related to anything in that google search.
 
Old 03-16-2010, 11:27 AM   #12
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 69
Quote:
Originally Posted by pixellany View Post
I have the kernel headers on my system, but their is no "uaccess.h"----BUT: This Google search suggests strongly that "uaccess" has nothing to do with the kernel:
That might be something to look into:
Code:
root@jcmain:~# locate uaccess.h|head -15
/usr/lib/vmware/modules/source/vmblock-only/include/compat_uaccess.h
/usr/lib/vmware/modules/source/vmmon-only/include/compat_uaccess.h
/usr/lib/vmware/modules/source/vmnet-only/compat_uaccess.h
/usr/lib/vmware/modules/source/vsock-only/include/compat_uaccess.h
/usr/src/linux-2.6.30-custom/arch/alpha/include/asm/uaccess.h
/usr/src/linux-2.6.30-custom/arch/arm/include/asm/uaccess.h
/usr/src/linux-2.6.30-custom/arch/avr32/include/asm/uaccess.h
/usr/src/linux-2.6.30-custom/arch/blackfin/include/asm/uaccess.h
/usr/src/linux-2.6.30-custom/arch/cris/include/arch-v10/arch/uaccess.h
/usr/src/linux-2.6.30-custom/arch/cris/include/arch-v32/arch/uaccess.h
/usr/src/linux-2.6.30-custom/arch/cris/include/asm/uaccess.h
/usr/src/linux-2.6.30-custom/arch/frv/include/asm/uaccess.h
/usr/src/linux-2.6.30-custom/arch/h8300/include/asm/uaccess.h
/usr/src/linux-2.6.30-custom/arch/ia64/include/asm/uaccess.h
/usr/src/linux-2.6.30-custom/arch/m32r/include/asm/uaccess.h
And so:
Code:
root@jcmain:~# head -6 /usr/src/linux-2.6.30-custom/include/linux/uaccess.h 
#ifndef __LINUX_UACCESS_H__
#define __LINUX_UACCESS_H__

#include <linux/preempt.h>
#include <asm/uaccess.h>
Which then leads to:

Code:
root@jcmain:~# head -6 /usr/src/linux-2.6.30-custom/arch/x86/include/asm/uaccess.h 
#ifndef _ASM_X86_UACCESS_H
#define _ASM_X86_UACCESS_H
/*
 * User space memory access functions
 */
#include <linux/errno.h>
If thats any good.
 
Old 03-16-2010, 01:36 PM   #13
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Noted...

You have now exceeded my knowledge and understanding.....
"uaccess.h" does not exist on my system---I don't know if that is related to the fact that I have the kernel headers, but not the sources.
 
Old 03-16-2010, 01:58 PM   #14
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Squeeze 2.6.32.9 SMP AMD64
Posts: 3,289

Rep: Reputation: 126Reputation: 126
Quote:
Originally Posted by jamescondron View Post
I think there is more than one module on the net, like three or four, so perhaps you could link us? Paste it in?
This bears repeating. Can you please give a link to where you're getting this module so that there is at least some context to what you are trying to accomplish.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a kernel module call the function of another kernel module sceadu Programming 3 05-02-2011 02:22 AM
Compile and load kernel module automatically after boot? (Intel NIC module) touser Linux - Newbie 3 08-29-2009 08:45 PM
2in1 problem thread. (nvidia kernel module vs X module, and strange workbug phenom) htedrom Linux - Software 15 10-04-2007 10:55 PM
[Error] Kernel Module : No kernel module build environment saman007uk Debian 7 09-09-2006 06:34 PM
kernel module ignorant newbie looking for any one with kernel module knowledge cpoet Slackware 4 11-24-2003 09:37 PM


All times are GMT -5. The time now is 05:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration