3.10.17 procfs示例
/*
* wesley
* the linux module sample of procfs
*
* wesley for testing
* 2013-12-23 14:50:14
* insmod sampleproc.ko 加载模块
* rmmod sampleproc 卸载模块
* dmesg 来查看显示内容
* lsmod 显示加载模块
http://blog.chinaunix.net/uid-23390992-id-3026872.html
http://blog.chinaunix.net/uid-24432676-id-2607766.html
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <net/net_namespace.h>
#include <linux/mm.h>
MODULE_LICENSE("XJLI/GPL");
struct proc_data_t{
int a;
int b;
} ;
struct _DATA_INFO{
int data1;
int data2;
};
static struct _DATA_INFO data_info[2];
static void *sampleproc_seq_start(struct seq_file *s, loff_t *pos)
{
static unsigned long counter = 0;
if ( *pos == 0 )
{
return &counter;
}
else
{
*pos = 0;
return NULL;
}
}
static void *sampleproc_seq_next(struct seq_file *s, void *v, loff_t *pos)
{
return NULL;
}
static void sampleproc_seq_stop(struct seq_file *s, void *v)
{
}
static int sampleproc_seq_show(struct seq_file *s, void *v)
{
struct inode *i = s->private;
struct _DATA_INFO *info = PDE_DATA(i);
seq_printf(s, "%d----%d", info->data1, info->data2);
return 0;
}
struct proc_data_t data;
static struct seq_operations sampleproc_seq_ops = {
.start = sampleproc_seq_start,
.next = sampleproc_seq_next,
.stop = sampleproc_seq_stop,
.show = sampleproc_seq_show
};
static int sampleproc_proc_open(struct inode *inode, struct file *file)
{
int ret = seq_open(file, &sampleproc_seq_ops);
if (!ret) {
struct seq_file *sf = file->private_data;
sf->private = inode;
}
return ret;
}
static const struct file_operations sampleproc_file_ops = {
.owner = THIS_MODULE,
.open = sampleproc_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
static int sampleproc_init(void)
{
//struct proc_dir_entry *proc;
data.a = 10;
data.b = 20;
printk(KERN_INFO "sampleproc_init");
data_info[0].data1=1;
data_info[0].data2=2;
proc_create_data("proc_test1", 0, NULL, &sampleproc_file_ops, &data_info[0]);
data_info[1].data1=3;
data_info[1].data2=4;
proc_create_data("proc_test2", 0, NULL, &sampleproc_file_ops, &data_info[1]);
/*第三个参数设置为NULL,默认在/proc/下建立名字为test_proc的文件*/
//proc = proc_create("sampleproc", 0, NULL, &sampleproc_file_ops);
//if (!proc)
// goto -1;
return 0;
}
static void sampleproc_exit(void)
{
printk(KERN_INFO "sampleproc_exit");
remove_proc_entry("proc_test1", NULL);
remove_proc_entry("proc_test2", NULL);
}
module_init(sampleproc_init);
module_exit(sampleproc_exit);
3.10.17 procfs示例的更多相关文章
- 背水一战 Windows 10 (17) - 动画: ThemeTransition(过渡效果)
[源码下载] 背水一战 Windows 10 (17) - 动画: ThemeTransition(过渡效果) 作者:webabcd 介绍背水一战 Windows 10 之 动画 ThemeTrans ...
- 发现struct proc_dir_entry内核3.10.17移到internal中去了,倒
struct proc_dir_entry 原:2.6.38.8 在#include <linux/proc_fs.h> 现:3.10.17 在fs/proc/internal.h:str ...
- Windows 8.1 正式版微软官方原版镜像下载(新增10/17新版下载)
中文版:中国区OEM预装版本,特定国家版,锁定语言,其它功能和核心版没有区别.简体中文单语言版:锁定语言,其它功能和核心版没有区别.专业版+核心版[零售版][推荐]:镜像内包含专业版(Professi ...
- Dell Technology Summit(2018.10.17)
时间:2018.10.17地点:北京国家会议中心
- 10.17 NOIP模拟赛
目录 2018.10.17 NOIP模拟赛 A 咒语curse B 神光light(二分 DP) C 迷宫maze(次短路) 考试代码 B 2018.10.17 NOIP模拟赛 时间:1h15min( ...
- WIN8.1 PRO RTM VOL.Enterprise.2013.10.17
Windows 8.1 Pro VL (x64) - DVD (Chinese-Simplified)ISO|Chinese - Simplified|发布日期: 2013/10/17文件名: cn_ ...
- 2020.10.17 JZOJ 提高B组T2 导弹拦截
2020.10.17 JZOJ 提高B组T2 导弹拦截 题目 Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统. 敌国的导弹形成了立体打击,每个导弹可以抽象成一个三维空间中的 ...
- Lucene 4.10.2开发示例
这里面用的是比较新的Lucene4.10.2 做的一个实例.(lucene的索引不能太大,要不然效率会很低.大于1G的时候就必须考虑分布索引的问题) 先介绍一下Lucene的几个参数意义: Index ...
- 10.17 linux 文件权限
文件权限模拟练习 [root@wen ~]# groupadd incahome[root@wen ~]# usersdd oldboy -g incahome-bash: usersdd: comm ...
随机推荐
- 如何在MFC对话框应用程序中使用ColorPicker控件
在日常的应用程序开发中,当涉及到曲线绘制时,为了将多条不同类型的曲线区分开,常常需要将它们指定不同的颜色.今天在这里简单的记录一下,如何实现及使用ColorPicker控件.程序用到4个文件依次为:C ...
- 计划任务crontab
安装crontab服务 1, yum install -y vixie-cron 如果提示crond命令不存在,可能被误删除了,CentOS下可以通过这个命令重新安装: yum -y install ...
- shiro realm 注解失败问题解决过程
做为一名在.net混了八九年的老兵油子,转战java时间并不长,刚开始做项目完全是凭借对C#的认识来做,虽然遇到一些问题,但实际结果显示C#在语言上和java还是有很大相似度,而且微软的MVC与Spr ...
- ASP.NET MVC Model绑定的简单应用
Model绑定是 MVC 框架根据 HTTP 请求数据创建 .NET 对象的一个过程. 一.简单类型 1.单一值
- 3种不同的ContextMenu右键菜单演示
简单使用的右键菜单,希望能帮助大家.下面是截图和实例代码 实例预览 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/ ...
- 小白的CSS基础学习
CSS定义: CSS全称为“层叠样式表 (Cascading Style Sheets)”,它主要是用于定义HTML内容在浏览器内的显示样式. CSS代码语法: css样式选择组成部分:选择符+声明( ...
- Vue数据绑定隐藏的神坑....
今天被Vue的一个坑给折磨了一天,终于发现是什么问题,我们先来模拟一个场景: 代码如下: <!DOCTYPE html> <html lang="en"> ...
- iOS 3DES加密解密(一行代码搞定)
3DES(或称为Triple DES)是三重数据加密算法(TDEA,Triple Data Encryption Algorithm)块密码的通称.它相当于是对每个数据块应用三次DES加密算法.由于计 ...
- C/C++构建系统 GNU autotool
我们在网上经常可以看到c/c++开源的项目,其中很多都是使用GNU的构建系统进行配置和编译的,如果按照规范构造这些的步骤,有一定的门槛和复杂度,下文把关于auotools系列的工具和概要的流程简要汇总 ...
- 之一:CABasicAnimation - 基本动画
嗷呜嗷呜嗷呜 // 将视图作为属性方便后面执行多个不同动画 _myView = [[UIView alloc] init]; _myView.layer.position = CGPointMake( ...