当前位置: 首页 > news >正文

网站系统分析的步骤有哪些wordpress 重写分页

网站系统分析的步骤有哪些,wordpress 重写分页,济南网站建设599,免费ppt模板下载花在上面我们介绍了使用 seq_file 需要实现的一些函数和相关结构体#xff0c;现在我们把它们组合起来#xff0c;介绍以下 通过 proc 来使用 seq_file 的一般步骤#xff0c;而 seq_file 在其他方面的应用方法也是一样的。 (1) 实现 seq_operations #xff0c;也就是前面我…在上面我们介绍了使用 seq_file 需要实现的一些函数和相关结构体现在我们把它们组合起来介绍以下 通过 proc 来使用 seq_file 的一般步骤而 seq_file 在其他方面的应用方法也是一样的。 (1) 实现 seq_operations 也就是前面我们介绍的 seq_file 的底层数据操作函数集示例如下 static struct seq_operations proc_seq_ops { .start proc_seq_start, .next proc_seq_next, .stop proc_seq_stop, .show proc_seq_show }; 这些回调函数都是需要根据你所要获取的序列数据结构来实现的。 (2) 实现 struct file_operations 中的 open 函数这个 open 函数的实现也是非常简单固定格式无私有数据 情况实例如下 static int proc_seq_open(struct inode *inode, struct file *file) { return seq_open(file, proc_seq_ops); }; seq_open 的实现如下此函数实现在 seq_file.c 中。 int seq_open(struct file *file, const struct seq_operations *op) struct seq_file *p; WARN_ON(file-private_data); p kzalloc(sizeof(*p), GFP_KERNEL); if (!p) return -ENOMEM; file-private_data p; mutex_init(p-lock); p-op op; // No refcounting: the lifetime of p is constrained // to the lifetime of the file. p-file file; /* * Wrappers around seq_open(e.g. swaps_open) need to be * aware of this. If they set f_version themselves, they * should call seq_open first and then set f_version. */ file-f_version 0; /* * seq_files support lseek() and pread(). They do not implement * write() at all, but we clear FMODE_PWRITE here for historical * reasons. * * If a client of seq_files a) implements file.write() and b) wishes to * support pwrite() then that client will need to implement its own * file.open() which calls seq_open() and then sets FMODE_PWRITE. */ file-f_mode ~FMODE_PWRITE; return 0; } seq_file 结构会在 seq_open 中申请并附在 file 的私有数据成员 private_data 中。可以看到一般就是使用 seq_file 中的一个 APIseq_open目的是向 seq_file 结构体中注册一个 struct seq_operations 。 另外还有 int seq_open_private(struct file *filp, const struct seq_operations *ops,int psize)函数此函数会为 seq_file 的私有数据申请空间。 若需要私有数据可使用 seq_open_private 接口。 (3) 实现 struct file_operations proc_ops示例如下 static struct file_operations proc_ops { .owner THIS_MODULE, .open proc_seq_open, .read seq_read, .llseek seq_lseek, .release seq_release, }; 大家可以看到以上的 read、llseek、release 都是有 seq_file 提供的接口函数直接注册即可唯有 open 是 需要自己实现的。 在 seq 中是没有实现 write 操作的因此如果根据需要添加 write 操作需要再 file_ops 中单独添加。 (4)注册 proc 文件注册包含 seq_file 操作函数的 file_operations 结构体到 proc_fops。我的测试程序中的实 例代码如下 …… proc_test_entry create_proc_entry(proc_seq, 0644, NULL); if (proc_test_entry NULL) { ret -ENOMEM; cleanup_test_data(); pr_err(proc_test: Couldnt create proc entry\n); } else { proc_test_entry-proc_fops proc_ops; pr_info(proc_test: Module loaded.\n); } 示例 #include linux/module.h #include linux/kernel.h #include linux/slab.h #include linux/kernel_stat.h #include linux/fs.h #include linux/proc_fs.h #include linux/seq_file.h #define MAX_CPU_NUM 32 #define RPT_LINE_MAXLEN 1024 unsigned int last_user[MAX_CPU_NUM]; unsigned int last_system[MAX_CPU_NUM]; unsigned int last_nice[MAX_CPU_NUM]; unsigned int last_idle[MAX_CPU_NUM]; unsigned int last_si[MAX_CPU_NUM]; unsigned int last_hi[MAX_CPU_NUM]; static struct proc_dir_entry *monitor_root_dir; static struct proc_dir_entry *proc_tos; #define LEFT(x) (((unsigned)x) / 10) #define RIGHT(x) (((unsigned)x) % 10) #define SEQ_START_TOKEN ((void *)1) static void *tos_get_cpuinfo_start(struct seq_file *f, loff_t *pos) { void *v NULL; v *pos ? pos : SEQ_START_TOKEN; return v; } static int tos_get_cpuinfo_show(struct seq_file *f, void *v) { unsigned int user0, system0, nice0, idle0, si 0, hi 0; unsigned int sum; int cpu_num num_possible_cpus(); int i; if (v SEQ_START_TOKEN){ for(i0;icpu_num;i){ user kcpustat_cpu(i).cpustat[CPUTIME_USER]-last_user[i]; nice kcpustat_cpu(i).cpustat[CPUTIME_NICE]-last_nice[i]; system kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]-last_system[i]; idle kcpustat_cpu(i).cpustat[CPUTIME_IDLE]-last_idle[i]; si kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]-last_si[i]; hi kcpustat_cpu(i).cpustat[CPUTIME_IRQ]-last_hi[i]; sum usernicesystemidle si hi; if(sum0){ user1; nice 0; system 89; idle 10; si 0; hi 0; sum usernicesystemidle si hi; } seq_printf(f, CPU Load Information:(%d %s)\n,cpu_num,cpu_num1?cpus:cpu); seq_printf(f, cpu%d:\n,i); seq_printf(f, %-18s%u.%u%%\n, User, LEFT(user*1000/sum), RIGHT(user*1000/sum)); seq_printf(f, %-18s%u.%u%%\n, System, LEFT(system*1000/sum), RIGHT(system*1000/sum)); seq_printf(f, %-18s%u.%u%%\n, Nice, LEFT(nice*1000/sum), RIGHT(nice*1000/sum)); seq_printf(f, %-18s%u.%u%%\n, Si, LEFT(si*1000/sum), RIGHT(si*1000/sum)); seq_printf(f, %-18s%u.%u%%\n, Hi, LEFT(hi*1000/sum), RIGHT(hi*1000/sum)); seq_printf(f, %-18s%u.%u%%\n, Idle, LEFT(idle*1000/sum), RIGHT(idle*1000/sum)); } seq_printf(f, \n); } return 0; } static void *tos_get_cpuinfo_next(struct seq_file *f, void *v, loff_t *pos) { (*pos); return v SEQ_START_TOKEN ? NULL : NULL;//只获取一次 } static void tos_get_cpuinfo_stop(struct seq_file *f, void *v) { /* Nothing to do */ } static const struct seq_operations tos_get_cpuinfo_sops { .start tos_get_cpuinfo_start, .next tos_get_cpuinfo_next, .stop tos_get_cpuinfo_stop, .show tos_get_cpuinfo_show }; static int tos_get_cpuinfo_open(struct inode *inode, struct file *filp) { return seq_open(filp, tos_get_cpuinfo_sops); } static const struct file_operations tos_get_cpuinfo_fopes { .open tos_get_cpuinfo_open, .read seq_read, .llseek seq_lseek, .release seq_release, }; static int __init tos_get_cpuinfo_init(void) { static struct proc_dir_entry *entry; proc_tos proc_mkdir(tos, 0); if (!proc_tos) { printk(tos proc mkdir tos failed!\n); return -1; } monitor_root_dir proc_mkdir(tos/monitor, NULL); if(monitor_root_dir NULL){ printk(tos/monitor proc mkdir tos failed!\n); if(proc_tos) remove_proc_entry(tos, NULL); return -ENOMEM; } entry proc_create(cpu, 0644, monitor_root_dir, tos_get_cpuinfo_fopes); if(!entry) { printk(create_proc_entry error); if(monitor_root_dir) remove_proc_entry(tos/monitor, NULL); if(proc_tos) remove_proc_entry(tos, NULL); return -1; } return 0; } static void __exit tos_get_cpuinfo_exit(void) { remove_proc_entry(cpu, monitor_root_dir); if(monitor_root_dir) remove_proc_entry(tos/monitor, NULL); if(proc_tos) remove_proc_entry(tos, NULL); } MODULE_LICENSE(GPL); module_init(tos_get_cpuinfo_init); module_exit(tos_get_cpuinfo_exit); 复杂的示例可阅读内核源码 fib_trie.c查看路由的 proc 文件的实现其中遍历路由树时使用的自己的迭代 器迭代器在 seq-private 记录。
http://www.zqtcl.cn/news/275474/

相关文章:

  • 蓝色系列的网站邓砚谷电子商务网站建设
  • 德阳市住房和城乡建设局网站首页一个服务器可以建多少个网站
  • 建一个电商网站多少钱一起做网店货源app
  • 做网站用lunx代理记账 营销型网站
  • 凡客做网站怎么样WordPress分类目录 前100篇
  • 腾讯wordpress 建站教程本地的上海网站建设公司
  • 深圳市南山区住房和建设局官方网站上海专业网站建设公司站霸网络
  • 建网站的8个详细步骤网站集约化建设讲话
  • 建设局哪个网站查证南京注册公司多少钱
  • 免费的网站制作郑州中森网站建设
  • 网站关键词搜不到了濮阳网络教育
  • 推荐股票的好网站如何做好网站宣传
  • 免费网站模板网大型网络游戏
  • 网站开发语言数据库有几种广东省建设厅官网查询
  • 建新建设集团有限公司网站土巴兔装修公司电话
  • 百度网站审核期时间wordpress如何实现收费会员制
  • delphi 2010 网站开发wordpress 变装小说
  • asp.net电子商务网站前台模板企业所得税优惠政策2021年小微企业
  • 成都网站建设 lkcms深圳做网站哪个公司最好
  • 网站降权处理关于网站建设心得体会
  • 互联网站点与wordpress集成软件
  • 网站页面图片布局如何设计最新热点新闻事件
  • 学网站建设难四会市城乡规划建设局网站
  • 网站源码分享网html代码入门基础
  • 农产品网站开发方案陕西建设网成绩查询
  • 网站效益分析iis添加网站ip地址
  • 宣传海报在什么网站做网站建设的能力
  • 温州网站优化优化课程设置
  • 企业推广网站有哪些做百度推广需要什么条件
  • 如何实现网站的快速排名怎么做网站模板