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的更多相关文章
随机推荐
- postgresql in 优化
原sql: SELECT res_id_ori FROM wk_sheet A, wk_page b WHERE A .wk_sheet_id = b.wk_sheet_id ') ; 原sql执行计 ...
- Autoware 笔记 No. 5——基于GNSS的定位
1. 前言 在之前的笔记No.2 中,我们直接采用ndt_matching的方法实现定位,但需要在打开rviz中,通过2D Pose Estimate指定初始位置.加入GNSS后,可以帮助ndt_ma ...
- MicroPython:基于TPYBoard集合MAX7219点阵模块制作表白女神神器
转载请注明文章来源,更多教程可自助参考docs.tpyboard.com,QQ技术交流群:157816561,公众号:MicroPython玩家汇 前言 又是一年毕业季,只有到了毕业季才会意识到自己又 ...
- 动画展现十大经典排序算法(附Java代码)
0.算法概述 0.1 算法分类 十种常见排序算法可以分为两大类: 比较类排序:通过比较来决定元素间的相对次序,由于其时间复杂度不能突破O(nlogn),因此也称为非线性时间比较类排序. 非比较类排序: ...
- 状态(State)模式--设计模式
定义与特点 1.1 定义 状态模式允许一个对象在其内部状态改变的时候改变其行为.这个对象看上去就像是改变了它的类一样. 1.2 特点 状态模式优点: 封装了转换规则,并枚举可能的状态,它将所有与某个状 ...
- HTTP Error 502.5 - ANCM Out-Of-Process Asp.Net Core发布到IIS失败
问题概述 asp.net core网站发布到windows server 2012r2 IIS后,出现这个报错.dotnet xx.dll命令网站能够正常运行.说明不是程序问题. 经过一番折腾终于部署 ...
- Tomcat 简单容器化
Tomcat 容器化 思考 问题1 , Tomcat 容器化,Tomcat 如何配置 APR 连接器 Tomcat 的基础镜像已经是开启了 APR. 问题2, Tomcat 是每次都需要重新构建. 一 ...
- c# 如何获取当前方法的调用堆栈
c# 调试程序时常常需要借助 call stack 查看调用堆栈,实际上通过code也可以获取: class Program { static void Main(string[] args) { T ...
- Google开发者F12工具面板-network详解
1 开发者工具面板 面板上包含了Elements面板.Console面板.Sources面板.Network面板.Performance面板.Memory面板.Application面板.Sec ...
- XMind破解版,2019年8月好使
越来越多的公司用思维导图了,进行编写测试用例,以下为破解版,亲身实验才发 的 ,中国时间2019年8月5日 下载安装包: 链接:https://pan.baidu.com/s/1-ubJLPSEpH ...