lkml.org 
[lkml]   [2004]   [Oct]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: Write USB Device Driver entry not called
Date
if I modify the code like this

char abc;
if(read(fd,&abc,1) < 0)
perror("read to bar failed: ");
close(fd);

Which will be sucess... This intern states that my file descriptor is right
.... but write returns EBADF... both are contradicting statements....

Eshwar

----- Original Message -----
From: "Raj" <inguva@gmail.com>
To: "eshwar" <eshwar@moschip.com>
Cc: "Alan Cox" <alan@lxorguk.ukuu.org.uk>; "Linux Kernel Mailing List"
<linux-kernel@vger.kernel.org>
Sent: Thursday, October 14, 2004 9:09 AM
Subject: Re: Write USB Device Driver entry not called


> On Sat, 23 Oct 2004 07:12:56 +0530, eshwar <eshwar@moschip.com> wrote:
> > I agree but the return value from the vfs_write should not be the -EBADF
> > (Bad File descriptor) it might be -EACCES (premission denied)... Correct
me
> > if I am wrong...
> >
> > this can be code in fs/read_write.c vfs_write()
> >
> > if (!(file->f_mode & FMODE_WRITE))
> > return -EACCES;
>
> Wrong. You are confused between file perms & mode of access to files.
> If you cannot open a file due to insufficient perms, then EACCESS is
> what you get.
> If you opened a file for reading, but you tried to write, the you get a
EBADF.
>
> Run the following code, after you create two files, 'foo' ( perms 0400
> ) and 'bar' ( 0700 ).
>
> #include <fcntl.h>
>
> int main()
> {
> int fd;
>
> fd = open("foo",O_WRONLY);
>
> if(fd < 0)
> perror("Opening foo:");
> else
> close (fd);
>
> fd = open("bar",O_RDONLY);
>
> if(fd < 0)
> perror("Opening bar: ");
> else {
> if(write(fd,'a',1) < 0)
> perror("Write to bar failed: ");
> close(fd);
> }
>
> }
>
> Output would be:
> Opening foo:: Permission denied
> Write to bar failed: : Bad file descriptor
> --
> ######
> raj
> ######
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:07    [W:0.037 / U:7.648 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site