净雾天空吧 关注:8贴子:3,645
  • 6回复贴,共1

『ゞ﹎话说』吧都废了~

只看楼主收藏回复

不过废也就废了~~也没怎样嘛~~~~
啊~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
本小姐现在压力太大了~~~任务太重了~~~但还是提不起精神去搞它~~话说也么嫩多时间留给偶搞了吧~~~
好困~~~今天晚上交ODBC~话说要求偶还不是很了~~
然后明天要交图形学的作业~三个小程序~外加一个么布置的大作业~~再然后还有接口的实验~~再再然后有词法和语法分析~~再再再然后C++的另一个大作业~~~再再再再然后啊~OSP还有两个或三个实验吧~~再再再再再然后~每周必不可少的数据库的折磨~~~最后是期末复习~~又将是无数个通宵啊~~~
话说~~还有不到半个月就考试了吧~~LN哪嫩多时间啊~~~可还是想玩~~真是不愿意学习~~~



IP属地:上海1楼2007-12-16 01:28回复
    真是群会写文档的人~~~


    IP属地:上海2楼2007-12-16 01:31
    回复
      好歹也给个例子看嘛~~唉~~上课没听~~果然不知道他想干什么~~~


      IP属地:上海3楼2007-12-16 01:34
      回复
        睡觉去了~~睡醒再搞吧~~~


        IP属地:上海4楼2007-12-16 01:43
        回复
          函数scull_open()

          int scull_open(struct inode *inode,struct file *filp)
          {
           MOD_INC_USE_COUNT; // 增加该模块的用户数目 
           printk("This chrdev is in open\n"); 
           return 0; 
           }


          IP属地:上海5楼2007-12-20 08:45
          回复
            函数scull_write()
            int scull_write(struct inode *inode,struct file *filp,const char  *buffer,int count)
            {
             if(count < 0) 
             return –EINVAL; 
             if(scull.usage || scull.new_msg) 
             return –EBUSY; 
             scull.usage = 1; 
             kfree(scull.data); 
             data = kmalloc(sizeof(char) *(count+1),GFP_KERNEL); 
             if(!scull.data) { return ENOMEM; } 
             copy_from_user(scull.data,buffer,count + 1); 
             scull.usage = 0; 
             scull.new_msg = 1; 
             return count;

            函数scull_read()
            int scull_read(struct inode *inode,struct file *filp,char *buffer,int  count)
            {
             int length; 
             if(count < 0) 
             return –EINVAL; 
             if(scull.usage) 
             return –EBUSY; 
             scull.usage = 1; 
             if(scull.data == 0) 
             return 0; 
             length = strlen(scull.data);
             if(length < count) 
             count = length; 
             copy_to_user(buf,scull.data,count + 1); 
             scull.new_msg = 0; 
             scull.usage = 0; 
             return count; 

            函数scull_ioctl()
            #include <linux/ioctl.h> 
            #define SCULL_MAJOR 0 
            #define SCULL_MAGIC SCULL_MAJOR 
            #define SCULL_RESET _IO(SCULL_MAGIC,0)  // 重置数据 
            #define SCULL_QUERY_NEW_MSG _IO(SCULL_MAGIC,1) // 检查新的消息 
            #define SCULL_QUERY_MSG_LENGTH _IO(SCULL_MAGIC,2)// 获取消息长度
            #define IOC_NEW_MSG 1
            static int usage,new_msg; // 控制标志
            static char *data;

            int scull_ioctl(struct inode *inode,struct file *filp,unsigned long int cmd,unsigned long arg)
            {
             int ret=0; 
             switch(cmd) {
            (续)
             case SCULL_RESET: 
             kfree(data); 
             data = NULL; 
             usage = 0; 
             new_msg = 0; 
             break; 
             case SCULL_QUERY_NEW_MSG: 
             if(new_msg) 
             return IOC_NEW_MSG; 
             break; 
             case SCULL_QUERY_MSG_LENGTH: 
             if(data == NULL){ return 0; }
             else { return strlen(data); }
             break;
             default:
             return –ENOTTY; 
             }
             return ret;
            }


            IP属地:上海6楼2007-12-20 08:45
            回复
              函数scull_release()
              void scull_release(struct inode *inode,struct file *filp)

               MOD_DEC_USE_COUNT; // 该模块的用户数目减1
               printk("This chrdev is in release\n");
               return 0; 
               #ifdef DEBUG 
               printk("scull_release(%p,%p)\n",inode,filp); 
               #endif 


              测试函数源代码testproc.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 "chardev.h" // 定义字符设备 
              void write_proc(void); 
              void read_proc(void); 
              main()函数
              main(int argc,char **argv)

               if(argc == 1) { 
               puts("syntax: testprog[write|read]\n"); 
               exit(0); 
               } 
               if(!strcmp(argv[1], "write")) 
               { write_porc(); } 
               else if(!strcmp(argv[1],"read")) 
               { read_proc(); } 
               else 
               { puts("testprog: invalid command!\n"); } 
               return 0; 
              }
              write_proc()函数
              void write_proc() 

               int fd,len,quit = 0; 
               char buf[100]; 
               fd = open("/dev/chrdev",O_WRONLY); 
               if(fd <= 0) { 
               printf("Error opening device for writing!\n"); 
               exit(1); 
               } 
               while(!quit) { 
               printf("\n Please write into:"); 
               gets(buf); 
               if(!strcmp(buf,"exit")) 
               quit = 1;
              (续)
               while(ioctl(fd,DYNCHAR_QUERY_NEW_MSG)) 
               usleep(100); 
               len = write(fd,buf,strlen(buf)); 
               if(len < 0) { 
               printf("Error writing to device!\n"); 
               close(fd); 
               exit(1); 
               } 
               printf("\n There are %d bytes written to device!\n",len);
               } 
               close(fd); 
              }
              read_proc()函数
              void read_proc()

               int fd,len,quit = 0; 
               char *buf = NULL; 
               fd=open("/dev/chrdev",O_RDONLY); 
               if(fd < 0) { 
               printf("Error opening device for reading!\n""); 
               exit(1); 
               } 
               while(!quit) { 
               printf("\n Please read out:"); 
               while(!ioctl(fd,DYNCHAR_QUERY_NEW_MSG)) 
               usleep(100); // 获取消息长度 
              (续)
               len = ioctl(fd,DYNCHAR_QUERY_MSG_LENGTH,NULL); 
               if(len) { 
               if(buf != NULL) 
               free(buf); 
               buf = malloc(sizeof(char) * (len+1)); 
               len = read(fd,buf,len); 
               if(len < 0) { 
               printf("Error reading from device!\n"); } 
               else { 
               if(!strcmp(buf,"exit") { 
               ioctl(fd,DYNCHAR_RESET); // 复位
               quit = 1; 
               }
              (续)
               else 
               printf("%s\n",buf); 
               } 
               } 
               } 
               free(buf); 
               close(fd);
              }


              IP属地:上海7楼2007-12-20 08:45
              回复