<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7655.1">
<TITLE>RE: Getting 'bad file number' error writing to device driver</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>I am calling the driver from an Android program (OMAP4/Blaze). It calls a c++ program via JNI which then calls the device driver.<BR>
Someone suggested it might be a permissions problem - the program is running in user mode.<BR>
<BR>
on Blaze board, /system/bin<BR>
# ls -l<BR>
-rwxrwxrwx system system 7636 2011-09-30 03:53 mydriver<BR>
<BR>
Will strace still be useful?<BR>
In general, in Linux, how does one enable a user program to call a custom device driver?<BR>
<BR>
Anil<BR>
<BR>
<BR>
-----Original Message-----<BR>
From: Daniel Baluta [<A HREF="mailto:daniel.baluta@gmail.com">mailto:daniel.baluta@gmail.com</A>]<BR>
Sent: Thu 10/13/2011 5:09 PM<BR>
To: Philip Anil-QBW348<BR>
Cc: kernelnewbies@kernelnewbies.org<BR>
Subject: Re: Getting 'bad file number' error writing to device driver<BR>
<BR>
Hello,<BR>
<BR>
> I am trying to write to mydriver but get a 'Bad file number' error.<BR>
><BR>
> int fd = open("/dev/mydriver",O_RDWR);<BR>
><BR>
> this opens successfully as fd is not -1.<BR>
><BR>
> ssize_t bytesToWrite = strlen(buf);<BR>
><BR>
> value is: bytesToWrite 28<BR>
><BR>
> ssize_t bytesWritten = write(fd,buf,bytesToWrite);<BR>
><BR>
> value is: bytesWritten -1<BR>
><BR>
> __android_log_print(ANDROID_LOG_INFO,__FILE__,"ANIL<BR>
> strerror(errno) %s", strerror(errno));<BR>
><BR>
> value is: strerror(errno) Bad file number<BR>
<BR>
Please use strace and let us know the full trace of system calls.<BR>
Also, if possible<BR>
could you paste the 'write' function of your driver?<BR>
<BR>
thanks,<BR>
Daniel.<BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>