printkd
#include <linux/fs.h> #include <asm/uaccess.h> #include <linux/namei.h> #include <linux/vmalloc.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/list.h> #include <linux/timer.h> #include <linux/workqueue.h> #define BUFSIZE (1024) static struct file *pFile = NULL; static char *pBuf = NULL; static struct delayed_work printkd_work; static struct workqueue_struct *printkd_workqueue = NULL; int printkd2sd(const char *buf, int bufLength) { mm_segment_t old_fs; if(NULL == buf) { printk("%s pBuf pFile null\n", __func__); ; } if (IS_ERR(pFile)) { printk("%s pFile null\n", __func__ ); ; } old_fs = get_fs(); set_fs(KERNEL_DS); if(bufLength != pFile->f_op->write(pFile, (char *)buf, bufLength, &pFile->f_pos) ) { printk("%s: write err\n", __FUNCTION__); set_fs(old_fs); ; } set_fs(old_fs); ; } int printkd2buf(char *buf, unsigned short len) { ; ; == len)) { printk("%s(), par err\n"); ; } if(len >= BUFSIZE) { ret = printkd2sd(pBuf, p); p = ; ret = printkd2sd(buf, len); } - p) ) { memcpy( (pBuf + p), buf, len); p = p + len; } else { ret = printkd2sd(pBuf, p); memcpy(pBuf, buf, len); p = len; } return ret; } static asmlinkage int vscnprintkd(const char *fmt, va_list args) { ]; int ret; unsigned int printed_len; printed_len = vscnprintf( printk_buf , (), fmt, args); ret = printkd2buf(printk_buf, printed_len ); return ret; } static void printkd_init_work(struct work_struct *work) { mm_segment_t old_fs; pFile = filp_open(); if (IS_ERR(pFile)) { printk("%s filp_open error\n", __func__ ); ; } pBuf = vmalloc(BUFSIZE + ); if(NULL == pBuf) { printk("%s vmalloc err\n", __func__); goto close_file; } printkd2buf("printkd log start...\n", sizeof("printkd log start...\n") ); printk("%s(), ok!\n", __func__); return; close_file: filp_close(pFile, NULL); pFile = NULL; printk("%s(), err!\n", __func__); queue_delayed_work(printkd_workqueue, &printkd_work, HZ * ); return; } int printkd_init(void ) { printkd_workqueue = create_workqueue("printkd_init"); INIT_DELAYED_WORK(&printkd_work, printkd_init_work); queue_delayed_work(printkd_workqueue, &printkd_work, HZ * ); } int printkd_read_log( char **pBuf) { struct inode *inode = NULL; mm_segment_t oldfs; char *buf = NULL; unsigned ; int ret; if((NULL == pFile) || (NULL == pBuf) ) { printk("%s pFile pBuf null\n", __func__); ; } oldfs = get_fs(); set_fs(KERNEL_DS); if (!pFile->f_op) { printk("%s: File Operation Method Error\n", __FUNCTION__); goto __fs_close; } inode = pFile->f_path.dentry->d_inode; if (!inode) { printk("%s: Get inode from pFile failed\n", __FUNCTION__); goto __fs_close; } file_length = i_size_read(inode->i_mapping->host); && (file_length < * ) )) { printk("%s file size error\n", __FUNCTION__); goto __fs_close; } buf = vmalloc(file_length + ); if (!buf) { printk("%s alloctation memory failed\n", __FUNCTION__); goto __fs_close; } pFile->f_op->llseek(pFile, , SEEK_SET); ret = vfs_read(pFile, buf, file_length, &pFile->f_pos); if (ret != file_length) { printk("%s: vfs_read error, file_length:%d, ret:%d\n", __FUNCTION__, file_length, ret); pFile->f_op->llseek(pFile, , SEEK_END); goto free_buf; } pFile->f_op->llseek(pFile, , SEEK_END); printk("%s file_length:0x%x\n", __func__, file_length); *pBuf = buf; set_fs(oldfs); printk("%s(), ok!\n", __func__); return file_length; free_buf: vfree(buf); __fs_close: set_fs(oldfs); printk("%s(), error!\n", __func__); ; } asmlinkage int printkd(const char *fmt, ...) { va_list args; int r; va_start(args, fmt); r = vscnprintkd(fmt, args); va_end(args); return r; }
printkd的更多相关文章
随机推荐
- torch_11_BEGAN
BEGAN: 创新: 1.不是考虑生成图片与真实图片之间的真实的分布,而是估计分布的误差的分布之间的差距. 2.G,D的能力平衡提出了一种均衡的概念 3.提供了一种超参数,这超参数可以在图片的多样性和 ...
- STS 重写父类方法的操作
本来这种东西真的没什么好写的,但是很多时候真的是要用到的,不知道的话自己手动敲,会累死人的.所以记录在这里,自己的笔记,有需要的赶紧拿去,省的手动录入那么辛苦. 在代码窗口点击右键,依次选择“Sour ...
- redis 阻塞原因
1.内因: A.api或数据结构使用不合理: 如:对一个包含上万元素的hash结构执行hgetall操作,数据量大且命令复杂度O(n),必然阻塞 B.慢查询:前面有介绍 C.大对象: 执行./redi ...
- .NET Core 多框架支持(net45+netstandard20)实践中遇到的一些问题总结
.NET Core 多框架支持(net45+netstandard20)实践中遇到的一些问题总结 前言 本文主要是关于.NET Standard 代码 在多框架 和 多平台 支持自己实践过程中遇到的一 ...
- vue中使用Ajax(axios)、vue函数中this指向问题
Vue.js 2.0 版本推荐使用 axios 来完成 ajax 请求.Axios 是一个基于 Promise 的 HTTP 库,可以用在浏览器和 node.js 中. axios中文文档库:http ...
- 一文教您如何通过 Docker 搭建反向代理 Ngnix,并配置 Https SSL 证书
欢迎关注个人微信公众号: 小哈学Java, 每日推送 Java 领域干货文章,关注附送 100G 海量学习资源哟!! 个人网站: https://www.exception.site/docker/h ...
- Asp.Net Core Mvc Razor之RazorPage
在AspNetCore.Mvc.Razor命名空间中的RazorPage继承RazorPageBase,并定义的属性为: HttpContext Context 表示当前请求执行的HttpContex ...
- Triangulation by Ear Clipping(耳切法处理多边形三角划分)(转载)
转载自: https://www.cnblogs.com/xignzou/p/3721494.html 使用EarClipping三角化多边形(翻译) ---Triangulation by Ear ...
- es7之修饰器
什么是修饰器 修饰器其实就是一个普通的函数,用来修饰类以及类的方法. 比如: @test class DecoratorTest { } function test(target) { target. ...
- es6中,promise使用过程的小总结
参考资料传送门:戳一戳 1.是什么 Promise是异步编程的一种解决方案,有三种状态:pending(进行中).fulfilled(已成功)和rejected(已失败); 一般成功了状态用resol ...