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 ...
随机推荐
- Jupyter notebook 使用
1. 安装代码自动补全 需安装 nbextensions 插件,网站:https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/ins ...
- Centos7 下cobbler安装及配置
1.背景介绍 作为运维,在公司经常遇到一些机械性重复工作要做,例如:为新机器装系统,一台两台机器装系统,可以用光盘.U盘等介质安装,1小时也完成了,但是如果有成百台的服务器还要用光盘.U盘去安装,就显 ...
- MySQL数字类型学习笔记
数字类型 最近在看<MySQL技术内幕:SQL编程>并做了笔记,所以本博客是一篇笔记类型博客,分享出来方便自己复习,也可以帮助他人 整型 类型 占用空间 最小值(SIGNED) 最大值(S ...
- 【MySQL】MySQL 8.0的SYS视图
MySQL的SYS视图 MySQL8.0的发展越来越趋同与Oracle,为了更好的监控MySQL的一些相关指标,出现了SYS视图,用于监控. 1.MySQL版本 (root@localhost) [s ...
- Oracle基础教程(一)
本文链接:https://blog.csdn.net/GoldenKitten/article/details/84947386 以下内容为转载以上博客,自己做了略微的补充,如需查看原文,请点击上面的 ...
- oracle里面查询重复数据的方法
一张person表,有id和name的两个字段,id是唯一的不允许重复,id相同则认为是重复的记录. select id from group by id having count(*) > 1 ...
- 聊聊业务系统中投递消息到mq的几种方式
背景 电商中有这样的一个场景: 下单成功之后送积分的操作,我们使用mq来实现 下单成功之后,投递一条消息到mq,积分系统消费消息,给用户增加积分 我们主要讨论一下,下单及投递消息到mq的操作,如何实现 ...
- Python入门你要懂哪些?
前言 什么是计算机语言 计算机就是一台用来计算的机器,人让计算机干什么计算机就得干什么! 需要通过计算机的语言来控制计算机(也就是编程语言)! 计算机语言其实和人类的语言没有本质的区别,不同点就是交流 ...
- 用AI思维给成本降温,腾讯WeTest兼容性测试直击底价!
WeTest 导读 当AI成为各行业提高产业效率的动能,很多人开始疑惑,这架智能化的“无人机”何时在移动应用测试中真正落地?在今年的国际数码互动娱乐博览会(ChinaJoy)上,腾讯WeTest给出了 ...
- Junit4模板
模板 MallApplicationTests import org.junit.runner.RunWith; import org.springframework.boot.test.contex ...