📄 dioctl.c
字号:
/************************************************************//***** dioctl.c, this is a test program for upperdrv.c *****//************************************************************/#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/ioctl.h>#include <stdlib.h>#include <string.h>#include <fcntl.h>#include <unistd.h>#include <errno.h>#include <asm/io.h>/************************************************************//***** define some constants used in upperdrv.c *****//************************************************************/#ifndef _UPPER_DEVICE_H#define _UPPER_DEVICE_H#include <linux/ioctl.h>#define UPPER_MAJOR 117#define UPPER_LOW2UPPER 1 // change the input string from low to upper characters#define UPPER_UNCHAN 0 //copy the input string to the output#define UPPER_MAGIC UPPER_MAJOR#define UPPER_RESET _IO(UPPER_MAGIC,0) // reset the data#define UPPER_QUERY_NEW_MSG _IO(UPPER_MAGIC,1) // check for new message#define UPPER_QUERY_MSG_LENGTH _IO(UPPER_MAGIC,2) // get message length#define IOC_NEW_MSG 1#endifint cmd;int main(int argc,char **argv) { int fd,len=0,quit=0; int dbg; if(argc<3){ printf("usage: dioctl+device name+[cmd]:cmd=1:change from below to upper;cmd=0:not change\n"); exit(0);} fd=open("/dev/upper",O_WRONLY); if(fd<=0) { printf("Error opening device for writing!\n"); return 0; } else printf("open device success\n"); while(!quit){ sscanf(argv[2],"%d",&cmd); printf("cmd=%d",cmd); while(ioctl(fd,UPPER_QUERY_NEW_MSG)) usleep(1000); if(cmd==1){ len=ioctl(fd,UPPER_LOW2UPPER,NULL); printf("len=%d,check if it is 2, then ioctl(fd,UPPER_LOW2UPPER) OK!\n",len); quit=1; } else if(cmd==0){ len=ioctl(fd,UPPER_UNCHAN,NULL); printf("len=%d,check if it is 3, then ioctl(fd,UPPER_UNCHAN) OK!\n",len); quit=1; } if(!len) return 0; printf("device ioctl changed!\n"); } close(fd);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -