添加一个proc下的子目录

本文详细介绍了如何在Linux内核2.6.38.8版本的drivers目录下创建一个名为except的子目录。通过一系列步骤,包括新建Kconfig和Makefile文件,设置menuconfig菜单选项,编写except.c源代码,最终实现新内核编译后在/proc目录下可见except目录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

刚刚尝试编译内核成功,就接着试验一下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);




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值