RE: Problem in Reading the Device file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> 
> --- Greg KH <greg@xxxxxxxxx> wrote:
> 
> > On Tue, Jan 10, 2006 at 06:22:40AM -0800, kanishk
> > rastogi wrote:
> > >      if(fd=open("/dev/kanishk",O_RDWR)<=0)
> > 
> > 
> > Are you sure /dev/kanishk has been created (by you,
> 
> ----> Yes the device file had been created by me and
> checked.
> in fact in the dmesg (after executing the user prog)
> the last message was from the open function...
> 
> the user prog runs "open func" sucessfully but while
> running "read func" stops. and when i press enter it
> comes out and displays  
> 

I believe this is a clue that the problem is a C coding problem and not
a kernel problem.
I believe that in this statement 

	if(fd=open("/dev/kanishk",O_RDWR)<=0)

The value that is assigned to 'fd' is the result of the condition
"open("/dev/kanishk",O_RDWR)<=0", not the result of the open function.
The resulting value (zero) is thus assigned to fd, so when you call the
read function, you are actually reading from stdin instead of that
device.  You need to put parentheses around
"fd=open("/dev/kanishk",O_RDWR)<=0" to insure that the statement is
parsed correctly, or preferably do the assignment/function call before
the if statement so it is more clear what is happening.

I hope this helps.
	Bob Bennett

> 
> Data Returned is :1// this shows the value returned by 
> read(while i am returning 0 from driver's read. Data Entered 
> is :  //this shows the data
> 
> > you don't have the
> > logic in your example to have udev create it), and
> > it has the proper
> > permissions and the proper major/minor number
> > assigned to it?
> > 
> > thanks,
> > 
> > greg k-h
> > 
> > --
> > Kernelnewbies: Help each other learn about the Linux
> > kernel.
> > Archive:      
> > http://mail.nl.linux.org/kernelnewbies/
> > FAQ:           http://kernelnewbies.org/faq/
> > 
> > 
> 
> 
> 
> 		
> __________________________________________ 
> Yahoo! DSL - Something to write home about. 
> Just $16.99/mo. or less. 
> dsl.yahoo.com 
> 
> 
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 
> 
> 

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux