刚刚尝试编译内核成功,就接着试验一下proc目录创建,其实也只是依样画葫芦了,不甚理解。
希望创建的目录名为except,现归纳步骤如下:
1、cd ~/src/linux-2.6.38.8/drivers;
2、mkdir except
3、cd except/
4、新建文件Kconfig,并写入:(此处为添加menuconfig的菜单选项)
menu "Vtop Exception support"
config EXCEPT
tristate "Vtop Exception support"
---help---
Vtop Exception is used to dump exception information into file when core dumped .
---help---
If you want Vtop Exception support, you should say Y here.
---help---
This Vtop Exception support can be built as a module.
endmenu
5、新建文件Makefile,写入:
obj-$(CONFIG_EXCEPT) += except.o
6、cd ..
7、在文件Makefile末尾添加:
obj-$(CONFIG_EXCEPT) += except/
8、在文件Kconfig末尾添加:
source "drivers/except/Kconfig"
9、cd except/
10、新建文件except.c
11、编辑完成后再sudo make menuconfig时,选择except模块,然后进行内核编译即可,新内核安装后重启,执行"ls /proc"命令即可看到except目录存在;
附1 except.c文件内容如下:
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/timer.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/blkdev.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/completion.h>
#include <linux/unistd.h>
#include <linux/spinlock.h>
#include <linux/kmod.h>
#include <linux/interrupt.h>
#include <linux/notifier.h>
#include <linux/cpu.h>
#include <linux/mutex.h>
#include <linux/proc_fs.h>
static struct proc_dir_entry *proc_except;
/**
* except_init_procfs - create except and except/exceptin procfs
*/
int __init except_init_procfs(void)
{
struct proc_dir_entry *pde;
proc_except = proc_mkdir("except", NULL);
if (!proc_except)
return -ENOMEM;
}
/**
* except_exit_procfs - Remove except/except and except from procfs
*/
void except_exit_procfs(void)
{
remove_proc_entry("except", NULL);
}
static int __init init_except(void)
{
int error;
error = except_init_procfs();
return error;
}
static void __exit exit_except(void)
{
except_exit_procfs();
}
subsys_initcall(init_except);
module_exit(exit_except);