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 ... 
随机推荐
- linux TCP: time wait bucket table overflow
			早上一台rabbitmq和Java所在的服务器,客户端反馈超级卡,看io和cpu都不高.发现六七万消息挤压,临时性问题解决之后,看/var/log/messages,发现很多TCP: time wai ... 
- Hibernate(八)__级联操作、struts+hibernate+接口编程架构
			级联操作 所谓级联操作就是说,当你进行主对象某个操作时,从对象hibernate自动完成相应操作. 比如: Department <---->Student 对象关系,我希望当我删除一个d ... 
- 12个优秀用户体验的移动应用程序 UI 设计
			最美丽的,现代化的和惊人的移动 UI 设计就在这里.今天,我们挑选了12个来自 Behance 和 Dribbble 网站的优秀用户体验的手机界面设计.这些界面设计作品都是由世界各地的优秀设计师分享, ... 
- 【初窥javascript奥秘之事件机制】论“点透”与“鬼点击”
			前言 最近好好的研究了一番移动设备的点击响应速度,期间不断的被自己坑,最后搞得焦头烂额,就是现在可能还有一些问题,但是过程中感觉自己成长不少, 最后居然感觉对javascript事件机制有了更好的认识 ... 
- Web安全之点击劫持(ClickJacking)
			点击劫持(ClickJacking)是一种视觉上的欺骗手段.大概有两种方式,一是攻击者使用一个透明的iframe,覆盖在一个网页上,然后诱使用户在该页面上进行操作,此时用户将在不知情的情况下点击透明的 ... 
- sqlmap笔记
			sqlmap -u "注入链接" --其他参数或命令 (-v 1表示回显出注入过程) [判断指定字段是否存在注入点]当链接包含两个参数时,可用-p开关选择要注入的参数,例检测id是 ... 
- .net 模拟登录Post提交
			最近在做一个项目,要求集成到第三方系统中,由于先前没有做过类似的活,所以折腾了几天,蹭着有闲情的时候记录一下. 以下实例,都是我用Asp.net语言进行开发的,关于HTML元素的获取,使用的是Goog ... 
- Tint(着色器)的兼容实现
			我们在做控件的时候可以使用tint这个属性给控件上色,这样在很多情况下能减少不同色彩的资源色彩.在MD设计中,控件颜色随着主体改变也是一大要点,今天我们就来看看如何使用它. 使用步骤:1.建立一个控件 ... 
- iOS界面传值的方式(7种)
			iOS传值的方式 属性传值 方法传值 代理传值(delegate) block传值 单例模式方式 通知notification方式 UserDefault或者文件方式 1.属性传值 情况:A页面跳转到 ... 
- Android 项目实战--手机卫士(实现splash)
			从今天开始根据之前学习的android的基础知识,实战一下,实现一个简单功能的android手机卫士 本文地址:http://www.cnblogs.com/wuyudong/p/5899283.ht ... 
