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的更多相关文章
随机推荐
- jenkins环境自动部署
https://my.oschina.net/tonystark/blog/1920889 示例脚本: #!/bin/bash #export BUILD_ID=dontKillMe这一句很重要,这样 ...
- Prometheus K8S中部署Alertmanager
Prometheus K8S中部署Alertmanager 设置告警和通知的主要步骤如下:一.部署Alertmanager二.配置Prometheus与Alertmanager通信三.配置告警 1. ...
- kali渗透综合靶机(八)--Billu_b0x靶机
kali渗透综合靶机(八)--Billu_b0x靶机 靶机下载地址:https://download.vulnhub.com/billu/Billu_b0x.zip 一.主机发现 1.netdisco ...
- Blazor应用程序基于策略的授权
原文:https://chrissainty.com/securing-your-blazor-apps-configuring-policy-based-authorization-with-bla ...
- python数据挖掘介绍
目录 一:什么是数据挖掘 二:数据挖掘的基本任务 三:数据挖掘流程 四:数据挖掘建模工具 在python对数据的处理方式中,数据挖掘和数据分析是两个重要的方式,目的是为了从数据中获取具有科研或者商 ...
- 进程调度算法spf,fpf,时间片轮转算法实现
调度的基本概念:从就绪队列中按照一定的算法选择一个进程并将处理机分配给它运行,以实现进程并发地执行. 进程信息 struct node { string name;//进程名称 int id;//进程 ...
- Java实现QQ邮件发送
首先我们需要两个jar包,点击下面即可下载这两个包: JavaMail mail.jar 1.4.5 JAF(版本 1.1.1) activation.jar 我们这里采用QQ邮箱发送邮件为例,代码如 ...
- js删除html标记 去掉所有html标记
js删除html标记 去掉所有html标记 function delHtml(str){ return str.replace(/<[^>]+>/g,""); / ...
- AOD.NET实现数据库事物Transaction
在开始介绍文章主要内容前先简单说一下事务 1.事务介绍 事务是一种机制.是一种操作序列,它包含了一组数据库操作命令,这组命令要么全部执行,要么全部不执行.因此事务是一个不可分割的工作逻辑单元.在数据库 ...
- 【设计模式】Builder
前言 Builder设计模式,允许一步一步构建一个复杂的对象.将构建步骤抽象出来,让每个具体的Builder去实现构建步骤的内容.这样子就可以用同样的构建步骤,构建出不一样的对象.在Director类 ...