mirror of
https://github.com/gatieme/LDD-LinuxDeviceDrivers.git
synced 2026-11-09 08:38:04 +08:00
测试的proc_test驱动包括只读proc_entry, 只写proc_entry和可读写proc_entry...
This commit is contained in:
1 parent
75a59c184c
commit
e27e7ef9ce
17 files changed
+1269
-73
No files matched your search
@@ -2,7 +2,7 @@ all:github
|
||||
|
||||
|
||||
|
||||
COMMIT="更新了CFS调度器类的学习实例和博客信息..."
|
||||
COMMIT="测试的proc_test驱动包括只读proc_entry, 只写proc_entry和可读写proc_entry..."
|
||||
|
||||
.PHONY : github
|
||||
github:
|
||||
|
||||
File renamed without changes.
@@ -17,6 +17,13 @@ ROOT=..
|
||||
#PLATFORM=$(shell $(ROOT)/systype.sh)
|
||||
#include $(ROOT)/Make.defines.$(PLATFORM)
|
||||
|
||||
# my driver description
|
||||
DRIVER_VERSION := "1.0.0"
|
||||
DRIVER_AUTHOR := "Gatieme @ AderStep Inc..."
|
||||
DRIVER_DESC := "Linux input module for Elo MultiTouch(MT) devices"
|
||||
DRIVER_LICENSE := "Dual BSD/GPL"
|
||||
|
||||
|
||||
MODULE_NAME := print_vmarea
|
||||
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
@@ -1,18 +1,78 @@
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
|
||||
obj-m := hello.o
|
||||
|
||||
else
|
||||
|
||||
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
|
||||
PWD := $(shell pwd)
|
||||
|
||||
all:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules
|
||||
|
||||
clean:
|
||||
make -C $(KERNELDIR) M=$(PWD) clean
|
||||
|
||||
|
||||
endif
|
||||
# ------------------------------------------------------------------------------
|
||||
#
|
||||
# Makefile for the LDD-LinuxDeviceDrivers.
|
||||
#
|
||||
# Author: gatieme
|
||||
# Create: 2016-07-29 15:50:46
|
||||
# Last modified: 2016-07-29 16:10:29
|
||||
# Description:
|
||||
# This program is loaded as a kernel(v2.6.18 or later) module.
|
||||
# Use "make install" to load it into kernel.
|
||||
# Use "make remove" to remove the module out of kernel.
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
ROOT=..
|
||||
#PLATFORM=$(shell $(ROOT)/systype.sh)
|
||||
#include $(ROOT)/Make.defines.$(PLATFORM)
|
||||
|
||||
# my driver description
|
||||
DRIVER_VERSION := "1.0.0"
|
||||
DRIVER_AUTHOR := "Gatieme @ AderStep Inc..."
|
||||
DRIVER_DESC := "Linux input module for Elo MultiTouch(MT) devices"
|
||||
DRIVER_LICENSE := "Dual BSD/GPL"
|
||||
|
||||
|
||||
MODULE_NAME := hello
|
||||
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
|
||||
#CFG_FLAGS += -O2 -I./
|
||||
#EXTRA_CFLAGS += $(C_FLAGS) $(CFG_INC) $(CFG_INC)
|
||||
|
||||
|
||||
|
||||
obj-m := $(MODULE_NAME).o #print_vmarea.o
|
||||
|
||||
else
|
||||
|
||||
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
|
||||
PWD := $(shell pwd)
|
||||
|
||||
modules:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules
|
||||
|
||||
modules_install:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules_install
|
||||
|
||||
|
||||
|
||||
insmod:
|
||||
sudo insmod $(MODULE_NAME).ko
|
||||
|
||||
reinsmod:
|
||||
sudo rmmod $(MODULE_NAME)
|
||||
sudo insmod $(MODULE_NAME).ko
|
||||
|
||||
github:
|
||||
cd $(ROOT) && make github
|
||||
|
||||
rmmod:
|
||||
sudo rmmod $(MODULE_NAME)
|
||||
|
||||
test :
|
||||
sudo ../injector/memInjector -l stack -m random -t word_0 --time 1 --timeout 3 -p 1
|
||||
|
||||
clean:
|
||||
make -C $(KERNELDIR) M=$(PWD) clean
|
||||
rm -f modules.order Module.symvers Module.markers
|
||||
|
||||
.PHNOY:
|
||||
modules modules_install clean
|
||||
|
||||
|
||||
|
||||
endif
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
|
||||
static ssize_t hello_read(struct file * file, char * buf, size_t count, loff_t *ppos)
|
||||
static ssize_t hello_read(
|
||||
struct file * file,
|
||||
char * buf,
|
||||
size_t count,
|
||||
loff_t *ppos)
|
||||
{
|
||||
char *hello_str = "Hello, world!\n";
|
||||
|
||||
@@ -64,7 +68,7 @@ static struct miscdevice hello_dev =
|
||||
* What functions to call when a program performs file
|
||||
* operations on the device.
|
||||
*/
|
||||
&hello_fops
|
||||
&hello_fops,
|
||||
};
|
||||
|
||||
|
||||
@@ -79,8 +83,11 @@ static int __init hello_init(void)
|
||||
ret = misc_register(&hello_dev);
|
||||
if (ret != 0)
|
||||
{
|
||||
printk(KERN_ERR
|
||||
"Unable to register \"Hello, world!\" misc devicen");
|
||||
printk(KERN_ERR "Unable to register \"Hello, world!\" misc devicen");
|
||||
}
|
||||
else
|
||||
{
|
||||
printk(KERN_INFO "register \"Hello World!\" misc devicen...\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -91,6 +98,7 @@ module_init(hello_init);
|
||||
static void __exit hello_exit(void)
|
||||
{
|
||||
misc_deregister(&hello_dev);
|
||||
printk(KERN_INFO "deregister \"Hello World!\" misc devicen...\n");
|
||||
}
|
||||
module_exit(hello_exit);
|
||||
|
||||
@@ -106,7 +114,3 @@ MODULE_VERSION(DRIVER_VERSION);
|
||||
MODULE_AUTHOR(DRIVER_AUTHOR);
|
||||
MODULE_DESCRIPTION(DRIVER_DESC);
|
||||
MODULE_LICENSE(DRIVER_LICENSE);
|
||||
|
||||
|
||||
module_init(globalmem_init);
|
||||
module_exit(globalmem_exit);
|
||||
@@ -1,2 +0,0 @@
|
||||
/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/driver/hello/hello.ko
|
||||
/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/driver/hello/hello.o
|
||||
@@ -1,19 +1,78 @@
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
|
||||
obj-m := hello.o
|
||||
|
||||
else
|
||||
|
||||
#KERNELDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
KERNELDIR ?= /usr/src/linux-headers-3.14.0
|
||||
|
||||
PWD := $(shell pwd)
|
||||
|
||||
all:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules
|
||||
|
||||
clean:
|
||||
make -C $(KERNELDIR) M=$(PWD) clean
|
||||
|
||||
|
||||
endif
|
||||
# ------------------------------------------------------------------------------
|
||||
#
|
||||
# Makefile for the LDD-LinuxDeviceDrivers.
|
||||
#
|
||||
# Author: gatieme
|
||||
# Create: 2016-07-29 15:50:46
|
||||
# Last modified: 2016-07-29 16:10:29
|
||||
# Description:
|
||||
# This program is loaded as a kernel(v2.6.18 or later) module.
|
||||
# Use "make install" to load it into kernel.
|
||||
# Use "make remove" to remove the module out of kernel.
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
ROOT=..
|
||||
#PLATFORM=$(shell $(ROOT)/systype.sh)
|
||||
#include $(ROOT)/Make.defines.$(PLATFORM)
|
||||
|
||||
# my driver description
|
||||
DRIVER_VERSION := "1.0.0"
|
||||
DRIVER_AUTHOR := "Gatieme @ AderStep Inc..."
|
||||
DRIVER_DESC := "Linux input module for Elo MultiTouch(MT) devices"
|
||||
DRIVER_LICENSE := "Dual BSD/GPL"
|
||||
|
||||
|
||||
MODULE_NAME := hello
|
||||
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
|
||||
#CFG_FLAGS += -O2 -I./
|
||||
#EXTRA_CFLAGS += $(C_FLAGS) $(CFG_INC) $(CFG_INC)
|
||||
|
||||
|
||||
|
||||
obj-m := $(MODULE_NAME).o #print_vmarea.o
|
||||
|
||||
else
|
||||
|
||||
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
|
||||
PWD := $(shell pwd)
|
||||
|
||||
modules:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules
|
||||
|
||||
modules_install:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules_install
|
||||
|
||||
|
||||
|
||||
insmod:
|
||||
sudo insmod $(MODULE_NAME).ko
|
||||
|
||||
reinsmod:
|
||||
sudo rmmod $(MODULE_NAME)
|
||||
sudo insmod $(MODULE_NAME).ko
|
||||
|
||||
github:
|
||||
cd $(ROOT) && make github
|
||||
|
||||
rmmod:
|
||||
sudo rmmod $(MODULE_NAME)
|
||||
|
||||
test :
|
||||
sudo ../injector/memInjector -l stack -m random -t word_0 --time 1 --timeout 3 -p 1
|
||||
|
||||
clean:
|
||||
make -C $(KERNELDIR) M=$(PWD) clean
|
||||
rm -f modules.order Module.symvers Module.markers
|
||||
|
||||
.PHNOY:
|
||||
modules modules_install clean
|
||||
|
||||
|
||||
|
||||
endif
|
||||
|
||||
@@ -1,43 +1,76 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
/*
|
||||
* "Hello, world!" minimal kernel module - /proc version
|
||||
*
|
||||
* Valerie Henson <val@nmt.edu>
|
||||
*
|
||||
*/
|
||||
|
||||
MODULE_LICENSE("Dual BSD/GPL");
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/proc_fs.h>
|
||||
|
||||
/*
|
||||
* print the module information
|
||||
* Write "Hello, world!" to the buffer passed through the /proc file.
|
||||
*/
|
||||
static void print_module(void)
|
||||
|
||||
static int
|
||||
hello_read_proc(char *buffer, char **start, off_t offset, int size, int *eof,
|
||||
void *data)
|
||||
{
|
||||
struct module *mod;
|
||||
char *hello_str = "Hello, world!\n";
|
||||
int len = strlen(hello_str); /* Don't include the null byte. */
|
||||
/*
|
||||
* We only support reading the whole string at once.
|
||||
*/
|
||||
if (size < len)
|
||||
return -EINVAL;
|
||||
/*
|
||||
* If file position is non-zero, then assume the string has
|
||||
* been read and indicate there is no more data to be read.
|
||||
*/
|
||||
if (offset != 0)
|
||||
return 0;
|
||||
/*
|
||||
* We know the buffer is big enough to hold the string.
|
||||
*/
|
||||
strcpy(buffer, hello_str);
|
||||
/*
|
||||
* Signal EOF.
|
||||
*/
|
||||
*eof = 1;
|
||||
|
||||
printk(KERN_ALERT "this module: %p==%p\n", &__this_module, THIS_MODULE);
|
||||
printk(KERN_ALERT "module state: %d\n", THIS_MODULE->state);
|
||||
printk(KERN_ALERT "module name: %s\n", THIS_MODULE->name);
|
||||
return len;
|
||||
|
||||
list_for_each_entry(mod, *(&THIS_MODULE->list.prev), list);
|
||||
printk(KERN_ALERT "module name: %s\n", mod->name);
|
||||
printk(KERN_ALERT "module state: %d\n", THIS_MODULE->state);
|
||||
}
|
||||
|
||||
|
||||
static int hello_init(void)
|
||||
static int __init
|
||||
hello_init(void)
|
||||
{
|
||||
print_module( );
|
||||
|
||||
printk(KERN_ALERT "run in cpu %d\n", get_cpu());
|
||||
|
||||
printk(KERN_ALERT "PAGE_OFFSET : 0x%lx, TASK_SIZE : 0x%lx", PAGE_OFFSET, TASK_SIZE);
|
||||
|
||||
/*
|
||||
* Create an entry in /proc named "hello_world" that calls
|
||||
* hello_read_proc() when the file is read.
|
||||
*/
|
||||
if (create_proc_read_entry("hello_world", 0, NULL, hello_read_proc,
|
||||
NULL) == 0) {
|
||||
printk(KERN_ERR
|
||||
"Unable to register \"Hello, world!\" proc file\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
module_init(hello_init);
|
||||
|
||||
|
||||
static void hello_exit(void)
|
||||
static void __exit
|
||||
hello_exit(void)
|
||||
{
|
||||
remove_proc_entry("hello_world", NULL);
|
||||
}
|
||||
|
||||
|
||||
module_init(hello_init);
|
||||
module_exit(hello_exit);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Valerie Henson <val@nmt.edu>");
|
||||
MODULE_DESCRIPTION("\"Hello, world!\" minimal module");
|
||||
MODULE_VERSION("proc");
|
||||
@@ -0,0 +1,87 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
#
|
||||
# Makefile for the LDD-LinuxDeviceDrivers.
|
||||
#
|
||||
# Author: gatieme
|
||||
# Create: 2016-07-29 15:50:46
|
||||
# Last modified: 2016-07-29 16:10:29
|
||||
# Description:
|
||||
# This program is loaded as a kernel(v2.6.18 or later) module.
|
||||
# Use "make install" to load it into kernel.
|
||||
# Use "make remove" to remove the module out of kernel.
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
ROOT=..
|
||||
#PLATFORM=$(shell $(ROOT)/systype.sh)
|
||||
#include $(ROOT)/Make.defines.$(PLATFORM)
|
||||
|
||||
# my driver description
|
||||
DRIVER_VERSION := "1.0.0"
|
||||
DRIVER_AUTHOR := "Gatieme @ AderStep Inc..."
|
||||
DRIVER_DESC := "Linux input module for Elo MultiTouch(MT) devices"
|
||||
DRIVER_LICENSE := "Dual BSD/GPL"
|
||||
|
||||
|
||||
|
||||
MODULE_NAME := proc-test
|
||||
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
|
||||
#CFG_FLAGS += -O2 -I./
|
||||
#EXTRA_CFLAGS += $(C_FLAGS) $(CFG_INC) $(CFG_INC)
|
||||
|
||||
|
||||
#MODULE_NAME := proc-test
|
||||
|
||||
RESMAIN_CORE_OBJS := main.o
|
||||
RESMAIN_GLUE_OBJS := ro.o wo.o rw.o
|
||||
|
||||
|
||||
|
||||
proc-test-objs := $(RESMAIN_GLUE_OBJS) $(RESMAIN_CORE_OBJS)
|
||||
obj-m := $(MODULE_NAME).o #proc-test.o
|
||||
|
||||
else
|
||||
|
||||
#MODULE_NAME := proc-test
|
||||
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
#KERNELDIR ?= /home/gatieme/Work/Kernel/
|
||||
PWD := $(shell pwd)
|
||||
|
||||
modules:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules
|
||||
|
||||
modules_install:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules_install
|
||||
|
||||
|
||||
|
||||
insmod:
|
||||
sudo insmod $(MODULE_NAME).ko
|
||||
|
||||
reinsmod:
|
||||
sudo rmmod $(MODULE_NAME)
|
||||
sudo insmod $(MODULE_NAME).ko
|
||||
|
||||
github:
|
||||
cd $(ROOT) && make github
|
||||
|
||||
rmmod:
|
||||
sudo rmmod $(MODULE_NAME)
|
||||
|
||||
test :
|
||||
sudo ../injector/memInjector -l stack -m random -t word_0 --time 1 --timeout 3 -p 1
|
||||
|
||||
clean:
|
||||
make -C $(KERNELDIR) M=$(PWD) clean
|
||||
rm -f modules.order Module.symvers Module.markers
|
||||
|
||||
.PHNOY:
|
||||
modules modules_install clean
|
||||
|
||||
|
||||
|
||||
endif
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Author: HIT CS HDMC team.
|
||||
* Last modified by zhaozhilong: 2010-1-14
|
||||
*/
|
||||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
|
||||
#define DEBUG
|
||||
|
||||
|
||||
/*
|
||||
* 3.10以后内核的proc文件
|
||||
* 废弃了原来的create_proc_entry接口
|
||||
* 3.9 http://lxr.free-electrons.com/ident?v=3.9&i=create_proc_entry
|
||||
* 2.10 http://lxr.free-electrons.com/ident?v=3.10;i=create_proc_entry
|
||||
*
|
||||
* 而引入了
|
||||
* 1. proc_create创建proc文件,
|
||||
* 2. seq_file(Sequence file:序列文件)接口
|
||||
* 3. signal_file接口
|
||||
*
|
||||
* **proc_create创建proc文件**
|
||||
* 使用proc_create需要关联file_operations
|
||||
* 首先要调用创建proc文件的函数,需要绑定flie_operations
|
||||
*
|
||||
* ***seq_file接口操作proc文件*
|
||||
* http://blog.chinaunix.net/uid-28253945-id-3382865.html
|
||||
* 由于procfs的默认操作函数只使用一页的缓存,
|
||||
* 在处理较大的proc文件时就有点麻烦,
|
||||
* 并且在输出一系列结构体中的数据时也比较不灵活,
|
||||
* 需要自己在read_proc函数中实现迭代,容易出现Bug。
|
||||
* 所以内核黑客们对一些/proc代码做了研究,抽象出共性,
|
||||
* 最终形成了seq_file(Sequence file:序列文件)接口。
|
||||
* 这个接口提供了一套简单的函数来解决以上proc接口编程时存在的问题,
|
||||
* 使得编程更加容易,降低了Bug出现的机会。
|
||||
* 在需要创建一个由一系列数据顺序组合而成的虚拟文件或一个较大的虚拟文件时,
|
||||
* 推荐使用seq_file接口。
|
||||
*
|
||||
* 一般地,内核通过在procfs文件系统下建立文件来向用户空间提供输出信息,
|
||||
* 用户空间可以通过任何文本阅读应用查看该文件信息,
|
||||
* 但是procfs 有一个缺陷,如果输出内容大于1个内存页,需要多次读,
|
||||
* 因此处理起来很难,另外,如果输出太大,速度比较慢,
|
||||
* 有时会出现一些意想不到的情况,
|
||||
* Alexander Viro实现了一套新的功能,使得内核输出大文件信息更容易,
|
||||
* 该功能出现在2.4.15(包括2.4.15)以后的所有2.4内核以及2.6内核中,
|
||||
* 尤其 是在2.6内核中,已经大量地使用了该功能。
|
||||
* 要想使用seq_file功能,开发者需要包含头文件linux/seq_file.h,
|
||||
* 并定义与设置一个seq_operations结构(类似于file_operations结构):
|
||||
*
|
||||
* 但是我个人认为,并不是只有procfs才可以使用这个seq_file接口,
|
||||
* 因为其实seq_file是实现的是一个操作函数集,这个函数集并不是与proc绑定的,
|
||||
* 同样可以用在其他的地方。
|
||||
*
|
||||
**/
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
|
||||
|
||||
#define CREATE_PROC_ENTRY
|
||||
// #warning "use create_proc_entry in " #LINUX_VERSION_CODE
|
||||
|
||||
#else
|
||||
#define PROC_CREATE
|
||||
// #warning "use proc_create in " #LINUX_VERSION_CODE
|
||||
#define PROC_SEQ_FILE_OPERATIONS
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/seq_file.h>
|
||||
#endif
|
||||
|
||||
#if defined(CREATE_PROC_ENTRY) || defined(PROC_CREATE)
|
||||
|
||||
#else
|
||||
#error "you must define one of CREATE_PROC_ENTRY and PROC_CREATE"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* _CONFIG_H_ */
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Author: HIT CS HDMC team.
|
||||
* Create: 2010-3-12 8:20:01
|
||||
* Last modified: 2010-6-13 14:13:47
|
||||
*/
|
||||
|
||||
#ifndef __MAIN_H_INCLUDE__
|
||||
#define __MAIN_H_INCLUDE__
|
||||
|
||||
/*
|
||||
* common include header files
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
#define MAX_LINE 256 /// max length of a line
|
||||
#define DELIMITER '\n' /// the char is used to split the taskinfo
|
||||
#define PERMISSION 0644 /// proc node permission
|
||||
/*
|
||||
* return values
|
||||
*/
|
||||
#define OK 0
|
||||
#define FAIL -1
|
||||
|
||||
/*
|
||||
* proc files
|
||||
*/
|
||||
#define PROC_DIR "/proc/proc_test"
|
||||
#define PROC_READ_ONLY_ENTRY "read_only"
|
||||
#define PROC_WRITE_ONLY_ENTRY "write_only"
|
||||
#define PROC_READ_WRITE_ENTRY "read_write"
|
||||
|
||||
#endif // #define __MAIN_H_INCLUDE__
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Author: HIT CS HDMC team.
|
||||
* Create: 2010-3-12 8:50
|
||||
* Last modified: 2010-6-13 14:06:20
|
||||
* Description:
|
||||
* Memory fault injection engine running as a kernel module.
|
||||
* This module will create "/proc/memoryEngine/" directory and 9 proc nodes.
|
||||
* Write roramenters and request to these proc nodes and read the output from related proc node.
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
char ro_buffer[MAX_LINE] = "READ ONLY!!!";
|
||||
|
||||
|
||||
#ifndef PROC_SEQ_FILE_OPERATIONS
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int proc_read_ro(char * page,char **start, off_t off, int count, int * eof,void * data)
|
||||
{
|
||||
int iLen;
|
||||
iLen = sprintf(page, "%s", ro_buffer);
|
||||
return iLen;
|
||||
}
|
||||
|
||||
const struct file_operations ro_fops =
|
||||
{
|
||||
.owner = THIS_MODULE,
|
||||
.read = proc_read_ro, // read only
|
||||
//.write = proc_write_ro, // write only
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
// seq_operations -> show
|
||||
static int seq_show_ro(struct seq_file *m, void *v)
|
||||
{
|
||||
/*
|
||||
char buf[MAX_LINE];
|
||||
int ret = 0;
|
||||
|
||||
ret = sprintf(buf, "%ls", ack_ro);
|
||||
*/
|
||||
|
||||
seq_printf(m, "%s", ro_buffer);
|
||||
|
||||
return 0; //!! must be 0, or will show nothing T.T
|
||||
}
|
||||
|
||||
|
||||
// seq_operations -> open
|
||||
static int proc_open_ro(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, seq_show_ro, NULL);
|
||||
}
|
||||
|
||||
const struct file_operations proc_ro_fops =
|
||||
{
|
||||
.owner = THIS_MODULE,
|
||||
.open = proc_open_ro,
|
||||
.read = seq_read,
|
||||
//.write = proc_write_ro,
|
||||
.llseek = seq_lseek,
|
||||
.release = single_release,
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Author: HIT CS HDMC team.
|
||||
* Create: 2010-3-12 8:50
|
||||
* Last modified: 2010-6-13 14:06:20
|
||||
* Description:
|
||||
* Memory fault injection engine running as a kernel module.
|
||||
* This module will create "/proc/memoryEngine/" directory and 9 proc nodes.
|
||||
* Write rwramenters and request to these proc nodes and read the output from related proc node.
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int proc_write_rw(struct file *file, const char *buffer, unsigned long count, void * data)
|
||||
{
|
||||
int iRet;
|
||||
char srw[MAX_LINE];
|
||||
|
||||
if(count <= 0) { return FAIL; }
|
||||
memset(srw, '\0', sizeof(srw));
|
||||
iRet = copy_from_user(srw, buffer, count);
|
||||
if(iRet) { return FAIL; }
|
||||
iRet = sscanf(srw,"%lx",&rw);
|
||||
if(iRet != 1) { return FAIL; }
|
||||
dbginfo("Rcv rw:0x%lx\n",rw);
|
||||
return count;
|
||||
}
|
||||
|
||||
#ifndef PROC_SEQ_FILE_OPERATIONS
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int proc_read_rw(char * rwge,char **start, off_t off, int count, int * eof,void * data)
|
||||
{
|
||||
int iLen;
|
||||
dbginfo("0x%lx\n", ack_rw);
|
||||
iLen = sprintf(rwge, "%lx", ack_rw);
|
||||
return iLen;
|
||||
}
|
||||
|
||||
const struct file_operations proc_rw_fops =
|
||||
{
|
||||
.owner = THIS_MODULE,
|
||||
.read = proc_read_rw, // read
|
||||
.write = proc_write_rw, // write
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
// seq_operations -> show
|
||||
static int seq_show_rw(struct seq_file *m, void *v)
|
||||
{
|
||||
/*
|
||||
char buf[MAX_LINE];
|
||||
int ret = 0;
|
||||
dbginfo("0x%lx\n", ack_rw);
|
||||
ret = sprintf(buf, "%lx", ack_rw);
|
||||
*/
|
||||
|
||||
dbginfo("0x%lx\n", ack_rw);
|
||||
seq_printf(m, "%lx", ack_rw);
|
||||
|
||||
return 0; //!! must be 0, or will show nothing T.T
|
||||
}
|
||||
|
||||
|
||||
// seq_operations -> open
|
||||
static int proc_open_rw(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, seq_show_rw, NULL);
|
||||
}
|
||||
|
||||
const struct file_operations proc_rw_fops =
|
||||
{
|
||||
.owner = THIS_MODULE,
|
||||
.open = proc_open_rw,
|
||||
.read = seq_read,
|
||||
.write = proc_write_rw,
|
||||
.llseek = seq_lseek,
|
||||
.release = single_release,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Author: HIT CS HDMC team.
|
||||
* Create: 2010-3-12 8:50
|
||||
* Last modified: 2010-6-13 14:06:20
|
||||
* Description:
|
||||
* Memory fault injection engine running as a kernel module.
|
||||
* This module will create "/proc/memoryEngine/" directory and 9 proc nodes.
|
||||
* Write paramenters and request to these proc nodes and read the output from related proc node.
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
|
||||
/*
|
||||
* proc entries
|
||||
*/
|
||||
|
||||
|
||||
|
||||
char ro_buffer[MAX_LINE] =
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int proc_write_ctl( struct file *file,
|
||||
const char *buffer,
|
||||
unsigned long count,
|
||||
void * data)
|
||||
{
|
||||
int iRet;
|
||||
char sCtl[MAX_LINE];
|
||||
|
||||
if(count <= 0)
|
||||
{
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
memset(sCtl, '\0', sizeof(sCtl));
|
||||
|
||||
iRet = copy_from_user(sCtl, buffer, count);
|
||||
if(iRet)
|
||||
{
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
iRet = sscanf(sCtl,"%d",&ctl);
|
||||
if(iRet != 1)
|
||||
{
|
||||
return FAIL;
|
||||
}
|
||||
dbginfo("Rcv ctl : %d\n", ctl);
|
||||
do_request( );
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
const struct file_operations proc_ctl_fops =
|
||||
{
|
||||
.owner = THIS_MODULE,
|
||||
//.read = proc_read_ctl, // can read
|
||||
.write = proc_write_ctl, // write only
|
||||
};
|
||||
@@ -72,7 +72,7 @@ static struct file_operations exam_seq_fops = {
|
||||
static int __init exam_seq_init(void)
|
||||
{
|
||||
|
||||
entry = create_proc_entry("exam_esq_file", 0, NULL);
|
||||
entry = create_proc_entry("exam_esq_file", 0666, NULL);
|
||||
if (entry)
|
||||
entry->proc_fops = &exam_seq_fops;
|
||||
|
||||
|
||||
Reference in new issue
Block a user