kernel modules - big problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I  tried out this module:-

-----------hello.c--------------
#include <linux/module.h>

int init_module () {
	printk ("Hello World\n");
	return (0);
}

void cleanup_module () {
	}

------------hello.c-------------

It gave me the following error when I insmoded the hello.o:-

?Could not find the kernel version this module was compiled for.?

I tried this modification:-
-----------hello.c--------------
#include <rtl.h>
#include <linux/module.h>

int init_module () {
	printk ("Hello World\n");
	return (0);
}

void cleanup_module () {
	}

------------hello.c-------------
 It gave me the following error during compilation:-
?No such file or directory : rtl.h

I tried this modification instead:-
-----------hello.c--------------
#define MODULE
#define __KERNEL__
#include <linux/module.h>

int init_module () {
	printk ("Hello World\n");
	return (0);
}

void cleanup_module () {
	}

------------hello.c-------------
It gave me the following error when I tried to insmod hello.o :-
Kernel version mismatch.

My kernel version is 2.4.18-14

I tried this make file:-
--------------Makefile------------------
KDIR = /usr/src/linux
include $(KDIR)/.config

CFLAGS = -D__KERNEL -DMODULE -I$(KDIR)/include -Wall

all: hello.o

--------------Makefile------------------

It gave me the following error during the make:-
No such file or directory :/usr/src/linux/.config

--------------Makefile------------------
CC=gcc
MODCFLAGS := -Wall ?DMODULE ?D __KERNEL__  -DLINUX
                              -I /lib/modules/?uname-r/build/include
hello.o:                   hello.c/usr/include/linux/version.h
                               $ (CC) $ (MODCFLAGS) ? c hello.c
                               echo insmod hello.o to turn it on
                               echo rmmod hello to turn it off
                               echo
                               echo X and kernel programming do not
                               echo Do the insmod and rmmod from outside X.
--------------Makefile------------------

It told me the module hello.o was up to date but when I tried to insmod it, it
gave me the same error. Also when I tried lsmod, I could not find hello.o in
the list of modules.

I tried out this module and it did not work out.
---------------------------------------------my_pid.c-------------------------
-----------------
#include <linux/module.h>
#include <linux/proc_fs.h>
int my_pid_read(char *buf, char **start, off_t offset,
int len, int unused)
{
struct task_struct *p;
int length = 0;
/* iterate through the run queue */
p = init_task.next_run;
while (p != &init_task)
{
length +=sprintf(buf+length, "%i ", p->pid);
p = p->next_run;
}
return length;
}
struct proc_dir_entry my_pid_proc_entry =
{
0, /* low_ino: innode number; 0=dynamic allocation */
6, "my_pid", /* length of name and name of node */
S_IFREG | S_IRUGO, /* type and permissions */
1, 0, 0, /* nlinks, owner, group */
0, /* size--unused */
NULL, /* operations--use defaults */
&my_pid_read, /* function used to read data */
};
int init_module(void)
{
/* registration of the node */
proc_register(&proc_root, &my_pid_proc_entry);
printk("<1>Module my_pid is loaded\n");
return 0;
}
3
Advanced Linux Programming M. Barbeau
void cleanup_module(void)
{
/* unregistration of the node */
proc_unregister(&proc_root,
my_pid_proc_entry.low_ino);
printk("<1>Module my_pid is unloaded\n");
}
---------------------------------------------my_pid.c-------------------------
-----------------
It gave me parse errors during compilation.


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux