Skip to contentSkip to conversation

parameters passing problem in driver module

DISCUSSION Srinivas Surabhi 2 participants 2 messages Feb 20, 2001

lore
Share & tools
lore
#0 lore raw

In application program ,code for call to write system call is given below...

      #include<fcntl.h>
    main()
	 { 
	  int count,fd;
	 fd=open("/dev/pseudo",O_RDWR);
	  write(fd,buff,5);
	  }

In driver module code for getting the buffer and count

    #include<all related header files...>
     
    int psuedo_write(struct inode*in,struct file*fp,char *buf,int count)
    {
      kprintf("<1>pseudo_write routine called \n");
      kprintf("<1>count=%d \n",count);
      kprintf("<1>buffer=%s \n",buff);
      return 0;
    } 

/******so here after inserting the module into the kernel using insmod pseudo.o and executing the application cc -c pseudo_app.c, the o/p on console is *****/

"pseudo_write routine called"
"count=9988345352" /*garbage*/
"buffer=@#%h" . /*garbage*/

/*** but neither the buffer is carried from user space to kernel space nor the count, why?***/Please help me
out.

#1 lore raw
Quoted 10 lines · Srinivas Surabhi

In application program ,code for call to write system call is given below...

      #include<fcntl.h>
    main()
	 { 
	  int count,fd;
	 fd=open("/dev/pseudo",O_RDWR);
	  write(fd,buff,5);
	  }
Quoted 5 lines

In driver module code for getting the buffer and count

#include<all related header files...>

int psuedo_write(struct inode*in,struct file*fp,char *buf,int count)

This should read:

static ssize_t pseudo_write(struct file* file,
const char *buf,
size_t count,
loff_t* ppos);

Quoted 10 lines
    {
      kprintf("<1>pseudo_write routine called \n");
      kprintf("<1>count=%d \n",count);
      kprintf("<1>buffer=%s \n",buff);
      return 0;
    } 

/******so here after inserting the module into the kernel using insmod pseudo.o and executing the application cc -c pseudo_app.c, the o/p on console is *****/

Quoted 7 lines

"pseudo_write routine called"
"count=9988345352" /*garbage*/
"buffer=@#%h" . /*garbage*/

/*** but neither the buffer is carried from user space to kernel space nor the count, why?***/Please help me
out.

Not strange at all, you're using the wrong parameters so you get what you asked for: garbage in, garbage out.

You get the source for all other drivers for free. Use it.

Erik

Signature · 5 lines
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2783635  Fax: +31-15-2781843  Email: [email protected]
WWW: http://www-ict.its.tudelft.nl/~erik/