ksync
#include <linux/init.h> #include <linux/module.h> #include <linux/types.h> #include <linux/fs.h> #include <linux/cdev.h> #include <linux/device.h> #include <linux/uaccess.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/miscdevice.h> #include <linux/signal.h> #include <linux/timer.h> #include <linux/slab.h> #define printw(fmt, ...) ({printk( KERN_ERR "[ksync] " fmt, ##__VA_ARGS__); 0; }) ; struct cdev testcdev; struct class *myclass; static struct fasync_struct *async; ][] = {}; int hexdump(unsigned char *name, unsigned char *data, unsigned short len) { unsigned char *buf; int i, p, ret; unsigned ] = {}; unsigned ; tmp_len = sprintf(tmp, "%s hex(len=%d): ", name, len); ) len = ; buf = kmalloc( (len + ) * + tmp_len, GFP_KERNEL); memset(buf, ) * + tmp_len); memcpy(buf, tmp, tmp_len); == len)) { printw("%s\n", buf); kfree(buf); ; } , p = tmp_len; i < len; i++) { ret = sprintf((buf + p), "%02x ", *(data + i)); p = p + ret; } printw("%s\n", buf); kfree(buf); ; } void ksync_send(unsigned short cmd, unsigned char *buffer, short len) { unsigned ] = {}; sprintf(string, "%s(0x%x, %d)", __func__, cmd, len); memcpy(fsync_buffer[] + , (); memcpy(fsync_buffer[] + , (); memcpy(fsync_buffer[] + , buffer, len); hexdump(], len+); kill_fasync(&async, SIGIO, POLL_IN); } void ksync_recv(unsigned short cmd, unsigned char *buffer, short len) { unsigned ] = {}; sprintf(string, "%s(0x%x, %d)", __func__, cmd, len); hexdump(string, buffer, len); ksync_send(0x57, buffer, len); } int char_open(struct inode *inode, struct file *filp) { printw("char_open ok...\n"); ; } static int char_fasync(int fd, struct file *filp, int mode) { return fasync_helper(fd, filp, mode, &async); } int char_release(struct inode *inode,struct file *filp) { printw("char close\n"); , filp, );; } int char_ioctl (struct inode *inode, struct file *filelp, unsigned int cmd, unsigned long args) { ; } ssize_t char_write(struct file *filp, const char __user *buffer, size_t count, loff_t *offset) { unsigned ]; printw("%s\n", __func__); ], buffer, count)) { return -EFAULT; } hexdump("char_write", buffer, count); memcpy((], ); ksync_recv( info[], fsync_buffer[] + , info[] ); printw("char_write ok...\n"); return count; } ssize_t char_read(struct file *filp, char __user *buffer, size_t count, loff_t *offset) { int ret; ret = copy_to_user( (unsigned ], count); != ret) { printw("[%s][%d][err]\n", __func__, __LINE__); return -EFAULT; } filp->f_pos += count; hexdump(], count); printw("char_read ok...\n"); ; } struct file_operations fop = { .open = char_open, .release = char_release, .compat_ioctl = char_ioctl, .write = char_write, .read = char_read, .fasync = char_fasync, }; int __init a_init(void) { dev_t dev; int ret; dev = MKDEV(major,); ret = register_chrdev_region(dev,,"char"); if(ret) { alloc_chrdev_region(&dev,,,"char"); major = MAJOR(dev); } testcdev.owner = THIS_MODULE; cdev_init(&testcdev, &fop); cdev_add(&testcdev, dev, ); myclass = class_create(THIS_MODULE, "char_class"); device_create(myclass,NULL,dev,NULL, "ksync"); printw("module init ok ...\n"); ; } void __exit a_exit(void) { dev_t dev; dev = MKDEV(major ,); device_destroy(myclass, dev); class_destroy(myclass); cdev_del(&testcdev); unregister_chrdev_region(dev,); printw("module exit ok....\n"); } module_init(a_init); module_exit(a_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("..."); MODULE_DESCRIPTION("ksync"); MODULE_VERSION("V1.0");
#include <stdio.h> #include <unistd.h> #include <signal.h> #include <fcntl.h> int g_fd; unsigned ][] = {}; int hexdump(unsigned char *name, unsigned char *data, unsigned short len) { unsigned char *buf; int i, p, ret; unsigned ] = {}; unsigned ; tmp_len = sprintf(tmp, "%s hex(len=%d): ", name, len); ) len = ; buf = ) * + tmp_len); memset(buf, ) * + tmp_len); memcpy(buf, tmp, tmp_len); == len)) { printf("%s\n", buf); free(buf); ; } , p = tmp_len; i < len; i++) { ret = sprintf((buf + p), "%02x ", *(data + i)); p = p + ret; } printf("%s\n", buf); free(buf); ; } void ksync_recv(unsigned short cmd, unsigned char *buffer, short len) { } void ksync_send(unsigned short cmd, unsigned char *buffer, short len) { unsigned ]; int ret; memcpy(s_buf + , (); memcpy(s_buf + , (); memcpy(s_buf + , buffer, len); hexdump(); ret = write(g_fd, s_buf, len + ); printf("write ret %d\n", ret); } void sig_handler(int sig) { int ret; unsigned ]; unsigned ]; if(sig == SIGIO) { ret = read(g_fd, r_buf, ); memcpy((], r_buf + , ); memcpy((], r_buf + , ); hexdump(]+); ksync_recv(info[], r_buf + , info[]); } return; } int main(void) { unsigned ]; signal(SIGIO, sig_handler); g_fd = open("/dev/ksync", O_RDWR); == g_fd) { printf("open err\n"); ; } printf("open %d\n", g_fd); fcntl(g_fd, F_SETOWN, getpid()); fcntl(g_fd, F_SETFL, fcntl(g_fd, F_GETFL) | FASYNC); ) { memset(input, ); gets(input); fflush(stdin); ) continue; ksync_send(0x56, input, strlen(input) ); } ; }
# Makefile for PEDD EXTRA_CFLAGS += -Wframe-larger-than= ifneq ($(CROSS_COMPILE),) EXTRA_CFLAGS += -DARC_SDP endif ifeq ($(KERNELRELEASE),) ifeq ($(CROSS_COMPILE),) KERNELDIR ?= /lib/modules/$(shell uname -r)/build else KERNELDIR ?= /workspace/bpcie/output/build/linux-arc-axs101--3.13 endif PWD := $(shell pwd) modules: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules modules_install: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install clean: rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions *.symvers *.order *.out .PHONY: modules modules_install clean else obj-m := ksync_drv.o endif
ksync的更多相关文章
- 使用ksync 加速基于k8s 的应用开发
ksync 实际上实现了类似 docker docker run -v /foo:/bar 的功能,可以加速我们应用的开发&&运行 安装 mac os curl https://v ...
随机推荐
- bzoj1812 [IOI2005]riv河流
题目链接 problem 给出一棵树,每个点有点权,每条边有边权.0号点为根,每个点的代价是这个点的点权\(\times\)该点到根路径上的边权和. 现在可以选择最多K个点.使得每个点的代价变为:这个 ...
- COM 编程基础
DirectX 采用了 COM 标准.而 DirectShow 是一套完全基于 COM 的应用系统.要想深入学习 DirectShow,掌握一些 COM 编程的基础知识是必不可少的. 一.COM 是什 ...
- React: React组件创建的三种方式
一.简介 在前面介绍的React组件知识中,对于组件的创建我只是用了其中某一种方式.其实,在2013年React诞生之初,对于React组件的创建,仅仅只有一种方式,也即createClass函数,在 ...
- mysql8报错解析
1. 场景描述 想把测试数据导一份到本地使用,乱入装了mysql8,使用springboot项目启动的时候报: java.sql.SQLException: The server time zone ...
- 《细说PHP》第四版 样章 第18章 数据库抽象层PDO 2
18.2 PDO所支持的数据库 使用PHP可以处理各种数据库系统,包括MySQL.PostgreSQL.Oracle.MsSQL等.但访问不同的数据库系统时,其所使用的PHP扩展函数也是不同的.例如 ...
- 利用Python进行数据分析-Pandas(第一部分)
利用Python进行数据分析-Pandas: 在Pandas库中最重要的两个数据类型,分别是Series和DataFrame.如下的内容主要围绕这两个方面展开叙述! 在进行数据分析时,我们知道有两个基 ...
- hyper-v Centos7 网卡配置无效
环境: Win 10 Hyper-v 安装虚拟机:Centos 7 遇到问题: 网络配置无效,使用命令“ip addr” 网卡没有出现在列表中,显示了一个奇怪的网卡名字如“enp0s010f”,配置文 ...
- jsp页面科学计数法显示问题的解决办法
在JSP页面中返回的double类型的数值,如果数值过大,就会被显示成科学计数法. 这个问题通常出现在表单填写的input中,因此是必须要解决的问题. JSTL提供了标准的数值格式化标签,使用上非常简 ...
- 常用regex正则表达式
[单个]字符匹配 任意字符:表示由任意字符组成 \\:匹配一个'\' \n:匹配换行 \t:匹配制表符 [单个]字符集(可以从里面任选一个字符) [abc]:可以是字母abc中任意一个 [^abc]: ...
- 英语阅读——A meaningful life
这篇文章是<新视野大学英语>第四册的第八单元的文章. 1 The death of an angel of animal rights activism(活动家) does not rat ...