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的更多相关文章
随机推荐
- 一段完整的创建表格的SQL代码
一段完整的创建表格的SQL代码 使用SQL语句创建一张表,不仅可以可以快速熟悉SQL语句,还可以从这看出一个人对该技能点的熟悉程度. 这里先说明几点: PRIMARY KEY:主键,一张表中只允许有一 ...
- SqlHelper发布——比你期望的还要多的多(例如比MyBatis-Pagehelper性能更高)
SqlHelper发布——比Mybatis-PageHelper性能更高 起源 前段时间开启了一个新的项目,在选择分页插件时,发现github上很流行的一个是pagehelper,在百度上搜索了一下, ...
- python I/O复用
select是阻塞式的方法
- F#周报2019年第24期
新闻 ML.NET 1.1发布与模型构建器升级 .NET Core 3.0预览版6发布 尝试新的System.Text.Json API F#调用Infer.NET 匿名记录类型文档 了解FableC ...
- RFC的远程调用-异步
接上篇RFC的远程调用-同步(https://www.cnblogs.com/BruceKing/p/11169930.html). TABLES:USR21. DATA:A TYPE USR21-P ...
- ASP.NET Core快速入门(第6章:ASP.NET Core MVC)--学习笔记
课程链接:http://video.jessetalk.cn/course/explore 良心课程,大家一起来学习哈! 任务40:介绍 1.Individual authentication 模板 ...
- string 字符串 的一些使用方法
Java语言中,把字符串作为对象来处理,类String就可以用来表示字符串(类名首字母都是大写的). 字符串常量是用双引号括住的一串字符. 例如:"Hello World" Str ...
- 解决maven项目中web.xml is missing and <failOnMissingWebXml> is set to true
web.xml is missing and <failOnMissingWebXml> is set to true 是因为项目中没有web.xml文件, 步骤如下:
- IO流总结---- 字节流 ,字符流, 序列化 ,数据操作流,打印流 , Properties 集合
笔记内容: 什么是流 字节流 字符流 序列化 数据操作流(操作基本数据类型的流)DataInputStream 打印流 Properties 集合 什么是流: 流是个抽象的概念,是对输入输出设备的抽象 ...
- element-ui Rate组件源码分析整理笔记(十三)
Rate组件源码比较简单,有添加部分注释 main.vue <template> <!--valuenow当前的评分 valuetext当前显示的文本--> <div c ...