* Write USB Device Driver entry not called
@ 2004-10-21 11:44 eshwar
2004-10-13 6:15 ` Raj
0 siblings, 1 reply; 9+ messages in thread
From: eshwar @ 2004-10-21 11:44 UTC (permalink / raw)
To: Linux Kernel Mailing List
I am writing usb Device Driver for vendor specific Device for the kernel
2.6.8 ... When i have loaded my skelton usb driver
ioctl,read,probe,disconnect,release entry points are working fine but when i
issue write() returns as bad file descriptor.... even though i have open the
device file with S_IWUSR
The error message is comming vfs_wirte() function
if (!(file->f_mode & FMODE_WRITE))
return -EBADF;
It seems to be f_mode is not set with FMODE_WRITE
Can any one help me to fix this problem.... Thanks in Advance
Regards
Eshwar
The skelton driver is as follows and application code follows the driver
code...
Driver.c
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/usb.h>
#include <asm/uaccess.h>
/* Function prototypes */
static int otg_cli_open ( struct inode *inode, struct file *file);
/* Function prototypes */
static int otg_cli_open ( struct inode *inode, struct file *file);
static void otg_cli_disconnect( struct usb_interface *intf);
static int otg_cli_release ( struct inode *inode, struct file *file);
static ssize_t otg_cli_read (struct file *file, char *buffer, size_t count,
loff_t *ppos);
static ssize_t otg_cli_write (struct file *file, const char *buffer,
size_t count, loff_t *ppos);
static int otg_cli_probe( struct usb_interface *intf,
const struct usb_device_id *id);
static struct usb_device_id otg_device_id[] = {
{ USB_INTERFACE_INFO(USB_CLASS_VENDOR_SPEC, 0x00, 0xff) },
{},
};
struct usb_driver otg_cli_driver = {
.owner = THIS_MODULE,
.name = "xyz",
.probe = otg_cli_probe,
.disconnect = otg_cli_disconnect,
.id_table = otg_device_id,
};
static struct file_operations otg_cli_fops = {
.owner = THIS_MODULE,
.write = otg_cli_write,
.open = otg_cli_open,
.read = otg_cli_read,
.release = otg_cli_release,
};
static struct usb_class_driver otg_cli_class = {
.name = "xyz",
.fops = &otg_cli_fops,
};
static struct usb_class_driver otg_cli_class = {
.name = "moschip-otg",
.fops = &otg_cli_fops,
.mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFCHR,
.minor_base = 250,
};
static int otg_cli_ioctl ( struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
printk("Eshwar: otg_cli_ioctl");
return 0;
}
static ssize_t otg_cli_read (struct file *file, char *buffer,
size_t count, loff_t *ppos)
{
printk("Eshwar: otg_cli_read");
return 0;
}
static ssize_t otg_cli_write (struct file *file, const char *buffer,
size_t count,loff_t *ppos)
{
printk("Eshwar: otg_cli_write");
return 0;
}
static int otg_cli_open ( struct inode *inode, struct file *file)
{
printk("Eshwar: otg_cli_open");
return 0;
}
static int otg_cli_release ( struct inode *inode, struct file *file)
{
printk("Eshwar: otg_cli_release");
return 0;
}
static int otg_cli_probe( struct usb_interface *intf,
const struct usb_device_id *id)
{
printk("Eshwar: otg_cli_probe\n");
return 0;
}
static void otg_cli_disconnect( struct usb_interface *intf)
{
printk("Eshwar: otg_cli_disconnect\n");
usb_deregister_dev (intf, &otg_cli_class);
}
static int __init otg_cli_init(void)
{
printk ("Eshwar: otg_cli_init\n");
/* register this driver with the USB subsystem */
usb_register(&otg_cli_driver);
return 0;
}
/* OTG cleanup module */
static void __exit otg_cli_exit(void)
{
usb_deregister(&otg_cli_driver);
}
module_init (otg_cli_init);
module_exit (otg_cli_exit);
app.c
int main(int argc, char *argv[])
{
int devfd;
char send[512];
memset(send,'a',512);
devfd = open("/dev/usb/dabusb10",O_APPEND | S_IRUSR| S_IWUSR );
if ( write(devfd,send,512) < 0) {
printf ("write Failed\n");
return -1;
}
return 0;
}
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: Write USB Device Driver entry not called
2004-10-21 11:44 Write USB Device Driver entry not called eshwar
@ 2004-10-13 6:15 ` Raj
2004-10-21 17:52 ` eshwar
0 siblings, 1 reply; 9+ messages in thread
From: Raj @ 2004-10-13 6:15 UTC (permalink / raw)
To: eshwar; +Cc: Linux Kernel Mailing List
>
> devfd = open("/dev/usb/dabusb10",O_APPEND | S_IRUSR| S_IWUSR );
Did your open() succeed here ??? i guess S_IRUSR etc is used when you
create a new file and not when you open a new one.
> if ( write(devfd,send,512) < 0) {
> printf ("write Failed\n");
> return -1;
> }
well , if open fails above, then....
-- Raj
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: Write USB Device Driver entry not called
2004-10-13 6:15 ` Raj
@ 2004-10-21 17:52 ` eshwar
2004-10-13 6:38 ` Raj
2004-10-13 10:37 ` Alan Cox
0 siblings, 2 replies; 9+ messages in thread
From: eshwar @ 2004-10-21 17:52 UTC (permalink / raw)
To: Raj; +Cc: Linux Kernel Mailing List
Open is sucessfull.... I don't think the problem the flags of open
Eshwar
----- Original Message -----
From: "Raj" <inguva@gmail.com>
To: "eshwar" <eshwar@moschip.com>
Cc: "Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>
Sent: Wednesday, October 13, 2004 11:45 AM
Subject: Re: Write USB Device Driver entry not called
> >
> > devfd = open("/dev/usb/dabusb10",O_APPEND | S_IRUSR| S_IWUSR );
>
> Did your open() succeed here ??? i guess S_IRUSR etc is used when you
> create a new file and not when you open a new one.
>
> > if ( write(devfd,send,512) < 0) {
> > printf ("write Failed\n");
> > return -1;
> > }
>
> well , if open fails above, then....
>
> -- Raj
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: Write USB Device Driver entry not called
2004-10-21 17:52 ` eshwar
@ 2004-10-13 6:38 ` Raj
2004-10-13 10:37 ` Alan Cox
1 sibling, 0 replies; 9+ messages in thread
From: Raj @ 2004-10-13 6:38 UTC (permalink / raw)
To: eshwar; +Cc: Linux Kernel Mailing List
On Thu, 21 Oct 2004 23:22:02 +0530, eshwar <eshwar@moschip.com> wrote:
> Open is sucessfull.... I don't think the problem the flags of open
>
Try this: open("/dev/usb/dabusb10",O_WRONLY | O_APPEND );
######
raj
######
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: Write USB Device Driver entry not called
2004-10-21 17:52 ` eshwar
2004-10-13 6:38 ` Raj
@ 2004-10-13 10:37 ` Alan Cox
2004-10-23 1:42 ` eshwar
1 sibling, 1 reply; 9+ messages in thread
From: Alan Cox @ 2004-10-13 10:37 UTC (permalink / raw)
To: eshwar; +Cc: Raj, Linux Kernel Mailing List
On Iau, 2004-10-21 at 18:52, eshwar wrote:
> Open is sucessfull.... I don't think the problem the flags of open
I do. See any book on C/Unix style file opening. For an existing file
you want
open("foo", O_flags)
for a new file possibly
open("foo", O_CREAT|o_flags, S_Iblah)
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: Write USB Device Driver entry not called
2004-10-13 10:37 ` Alan Cox
@ 2004-10-23 1:42 ` eshwar
2004-10-14 3:39 ` Raj
0 siblings, 1 reply; 9+ messages in thread
From: eshwar @ 2004-10-23 1:42 UTC (permalink / raw)
To: Alan Cox; +Cc: Raj, Linux Kernel Mailing List
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;
Eshwar
----- Original Message -----
From: "Alan Cox" <alan@lxorguk.ukuu.org.uk>
To: "eshwar" <eshwar@moschip.com>
Cc: "Raj" <inguva@gmail.com>; "Linux Kernel Mailing List"
<linux-kernel@vger.kernel.org>
Sent: Wednesday, October 13, 2004 4:07 PM
Subject: Re: Write USB Device Driver entry not called
> On Iau, 2004-10-21 at 18:52, eshwar wrote:
> > Open is sucessfull.... I don't think the problem the flags of open
>
> I do. See any book on C/Unix style file opening. For an existing file
> you want
> open("foo", O_flags)
>
> for a new file possibly
>
> open("foo", O_CREAT|o_flags, S_Iblah)
>
>
> -
> 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/
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: Write USB Device Driver entry not called
2004-10-23 1:42 ` eshwar
@ 2004-10-14 3:39 ` Raj
2004-10-21 3:54 ` eshwar
0 siblings, 1 reply; 9+ messages in thread
From: Raj @ 2004-10-14 3:39 UTC (permalink / raw)
To: eshwar; +Cc: Alan Cox, Linux Kernel Mailing List
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
######
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: Write USB Device Driver entry not called
2004-10-14 3:39 ` Raj
@ 2004-10-21 3:54 ` eshwar
2004-10-14 4:19 ` Raj
0 siblings, 1 reply; 9+ messages in thread
From: eshwar @ 2004-10-21 3:54 UTC (permalink / raw)
To: Raj; +Cc: Alan Cox, Linux Kernel Mailing List
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/
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: Write USB Device Driver entry not called
2004-10-21 3:54 ` eshwar
@ 2004-10-14 4:19 ` Raj
0 siblings, 0 replies; 9+ messages in thread
From: Raj @ 2004-10-14 4:19 UTC (permalink / raw)
To: eshwar; +Cc: Alan Cox, Linux Kernel Mailing List
On Thu, 21 Oct 2004 09:24:52 +0530, eshwar <eshwar@moschip.com> wrote:
> 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....
It's this simple. File was opened for Read-Only. So for vfs_read it is
a 'good' file
descriptor. And for vfs_write it is a 'BAD' file descriptor.
--
######
raj
######
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2004-10-14 4:20 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-21 11:44 Write USB Device Driver entry not called eshwar
2004-10-13 6:15 ` Raj
2004-10-21 17:52 ` eshwar
2004-10-13 6:38 ` Raj
2004-10-13 10:37 ` Alan Cox
2004-10-23 1:42 ` eshwar
2004-10-14 3:39 ` Raj
2004-10-21 3:54 ` eshwar
2004-10-14 4:19 ` Raj
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.