Ubuntu 12.04,make tests about proc entry.
helloworld.c source code:
-----------------Begin-----------------------
#include <linux/module.h>
#include <linux/proc_fs.h>
MODULE_LICENSE("Dual BSD/GPL");
static int status_read(char *page, char **start, off_t off,int count, int *eof, void *data){
int len=0;
len += sprintf(page + len, "status:%lu \n", jiffies);
return len;
}
static int hello_init(void)
{
struct proc_dir_entry *entry;
printk(KERN_ALERT "Hello, world\n");
entry = create_proc_entry( "info_zhuyj", 0644, NULL );
if (NULL == entry){
printk(KERN_INFO "fortune: Couldn't create proc entry\n");
}
entry->read_proc = status_read;
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
remove_proc_entry("info_zhuyj", NULL);
}
module_init(hello_init);
module_exit(hello_exit);
----------------------------End----------------------------
Makefile:
----------------------Begin--------------------------------
KDIR:=/usr/src/linux-headers-3.2.0-39-generic
all:
$(MAKE) -C $(KDIR) M=$(PWD)
clean:
helloworld.c source code:
-----------------Begin-----------------------
#include <linux/module.h>
#include <linux/proc_fs.h>
MODULE_LICENSE("Dual BSD/GPL");
static int status_read(char *page, char **start, off_t off,int count, int *eof, void *data){
int len=0;
len += sprintf(page + len, "status:%lu \n", jiffies);
return len;
}
static int hello_init(void)
{
struct proc_dir_entry *entry;
printk(KERN_ALERT "Hello, world\n");
entry = create_proc_entry( "info_zhuyj", 0644, NULL );
if (NULL == entry){
printk(KERN_INFO "fortune: Couldn't create proc entry\n");
}
entry->read_proc = status_read;
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
remove_proc_entry("info_zhuyj", NULL);
}
module_init(hello_init);
module_exit(hello_exit);
----------------------------End----------------------------
Makefile:
----------------------Begin--------------------------------
ifneq ($(KERNELRELEASE),)
mymodule-objs:=helloworld.o
obj-m:=helloworld.o
else
PWD:=$(shell pwd)
KVER:=$(shell uname -r)KDIR:=/usr/src/linux-headers-3.2.0-39-generic
all:
$(MAKE) -C $(KDIR) M=$(PWD)
clean:
@rm -rf .*.com *.o *.mod.c *.ko .tmp_versions modules.order Module.symvers
endif
-----------------------------End--------------------------------------------------