Getting 'bad file number' error writing to device driver

Philip Anil-QBW348 anil.philip at motorolasolutions.com
Fri Oct 14 19:42:07 EDT 2011


I am calling the driver from an Android program (OMAP4/Blaze). It calls a c++ program via JNI which then calls the device driver.
Someone suggested it might be a permissions problem - the program is running in user mode.

on Blaze board, /system/bin
# ls -l
-rwxrwxrwx system   system       7636 2011-09-30 03:53 mydriver

Will strace still be useful?
In general, in Linux, how does one enable a user program to call a custom device driver?

Anil


-----Original Message-----
From: Daniel Baluta [mailto:daniel.baluta at gmail.com]
Sent: Thu 10/13/2011 5:09 PM
To: Philip Anil-QBW348
Cc: kernelnewbies at kernelnewbies.org
Subject: Re: Getting 'bad file number' error writing to device driver
 
Hello,

> I am trying to write to mydriver but get a 'Bad file number' error.
>
> int fd = open("/dev/mydriver",O_RDWR);
>
> this opens successfully as fd is not -1.
>
> ssize_t bytesToWrite = strlen(buf);
>
> value is: bytesToWrite 28
>
> ssize_t bytesWritten = write(fd,buf,bytesToWrite);
>
> value is: bytesWritten -1
>
> __android_log_print(ANDROID_LOG_INFO,__FILE__,"ANIL
> strerror(errno) %s",  strerror(errno));
>
> value is: strerror(errno) Bad file number

Please use strace and let us know the full trace of system calls.
Also, if possible
could you paste the 'write' function of your driver?

thanks,
Daniel.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111014/842860f3/attachment.html 


More information about the Kernelnewbies mailing list