proc新接口
注意,在較新版本的內(nèi)核中,procfs的函數(shù)接口有所變化。
| 系統(tǒng) | 內(nèi)核版本 |
|---|---|
| Linux | 5.10.111 |
在驅(qū)動(dòng)中添加以下代碼:
#include < linux/kernel.h >
#include < linux/module.h >
#include < linux/init.h >
#include < linux/proc_fs.h >
#include < linux/seq_file.h >
struct proc_dir_entry *my_proc_entry;
static int proc_clk_show(struct seq_file *m, void *v)
{
seq_printf(m,
"pll0: %lu Mhzn"
"pll1: %lu Mhzn"
"pll2: %lu Mhzn",
100, 200, 300);
return 0;
}
static int clk_info_open(struct inode *inode, struct file *filp)
{
return single_open(filp, proc_clk_show, NULL);
}
static const struct proc_ops clk_stat_proc_fops = {
.proc_open = clk_info_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_release = seq_release,
};
static int __init my_module_init(void)
{
my_proc_entry = proc_create("clk", 0, NULL, &clk_stat_proc_fops);
return 0;
}
static void __exit my_module_exit(void)
{
proc_remove(my_proc_entry);
}
module_init(my_module_init);
module_exit(my_module_exit);
MODULE_LICENSE("GPL");
新的proc接口中,將原來的struct file_operations換成了struct proc_ops,其中成員函數(shù)也添加了對(duì)應(yīng)的前綴proc,但本質(zhì)還是一樣的,只是換了名字,更加規(guī)范了一些。
-
內(nèi)核
+關(guān)注
關(guān)注
4文章
1436瀏覽量
42470 -
接口
+關(guān)注
關(guān)注
33文章
9441瀏覽量
156076 -
驅(qū)動(dòng)
+關(guān)注
關(guān)注
12文章
1927瀏覽量
88172 -
Linux
+關(guān)注
關(guān)注
88文章
11624瀏覽量
217836
發(fā)布評(píng)論請(qǐng)先 登錄
Linux驅(qū)動(dòng)中創(chuàng)建procfs接口的方法
Linux平臺(tái)/proc虛擬文件系統(tǒng)詳解
Linux proc文件系統(tǒng)詳解
USB接口驅(qū)動(dòng)的移植介紹
Linux內(nèi)核空間設(shè)備驅(qū)動(dòng)程序的開發(fā)
需要了解的Linux中 /proc/[pid] 目錄的各文件
Linux驅(qū)動(dòng)開發(fā)-proc接口介紹
AIO 3399ProC工具Linux Upgrade Tool 1.34
AIO 3399ProC工具Linux Upgrade Tool v1.24
AIO 3399ProC解合包工具(Linux)
AIO 3399ProC Linux SDK源碼包(僅支持RK3399Pro)
如何通過proc接口發(fā)起系統(tǒng)請(qǐng)求
Linux驅(qū)動(dòng)中procfs接口的創(chuàng)建
Linux中的proc介紹

Linux驅(qū)動(dòng)proc新接口介紹
評(píng)論