I was just wondering why should the open implementation fail while returing
non-zero values. Is there any norm that driver is not supposed to handle the
error conditions on open system call?

Thanks and Regards,
Abhi

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of
Arnd C. Heursch
Sent: Tuesday, September 17, 2002 11:19 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: [Rtl]writing a simple device driver


perhaps return 0 in the open function
returning 1 or n in read and write is ok, because
read() expects as return value the number of bytes read.



Abhijit wrote:
>
> Try returning 0 instead of 1 from device_open function (device_read you
are
> not using in your context). That minimum change should make it work.
>
> Thanks and Regards,
> Abhi
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of
> Bhanu Nagendra P.
> Sent: Tuesday, September 17, 2002 4:16 AM
> To: [EMAIL PROTECTED]
> Subject: [Rtl]writing a simple device driver
>
> I have tried to write an experimental simple device driver as follows:
>
> <==================
> int device_read(struct file *filp, char *buf, size_t count,
>                 loff_t *f_pos)
> {
>   printk(KERN_DEBUG "closed device\n");
>                 return 1;
> }
>
> int device_open (struct inode* i,struct file* f)
> {
>   printk(KERN_DEBUG "opened device\n");
>                 return 1;
> }
>
> struct file_operations device_fns = {
>    read: device_read,
>     open:       device_open
>    };
>
> int init_module(void)
> {
>         register_chrdev(17,"device",&device_fns);
>                 return 0;
> }
>
> void free_module(void)
> {
>   unregister_chrdev(17,"device");
> }
>
> ===========================================>
>
> I also
> * compiled the file
> * created a /dev/device entry using mknod at major number 17
> * inserted the above module
>
> When I try to open the device from a program:
>
> <================
> main()
> {
>  int fd;
>
>  fd=open("/dev/device",O_RDONLY);
>  printf("fd=%d\n",fd);
>  close(fd);
> }
> ==================>
>
> I always get an fd value back as -1.
>
> Is there anything obviously wrong in the way I am going about things?
>
> Thanks,
> -Bhanu
>
> _______________________________________________
> Rtl mailing list
> [EMAIL PROTECTED]
> http://www2.fsmlabs.com/mailman/listinfo.cgi/rtl
>
> _______________________________________________
> Rtl mailing list
> [EMAIL PROTECTED]
> http://www2.fsmlabs.com/mailman/listinfo.cgi/rtl

--
Dipl.-Phys. Arnd C.Heursch, wissenschaftlicher Mitarbeiter,
Institut fuer Informationstechn.Systeme 3, Prof. Rzehak, Prof. Teege
Universitaet der Bundeswehr Muenchen
Geb.41/300 Zimmer 0302, Werner Heisenberg Weg 39, D-85577 Neubiberg
http://www.informatik.unibw-muenchen.de/inst3/index_de.php
Tel.: 089/6004-2404 oder -2542 (Sekr.) | Fax: 089/6004-3898
E-Mail: [EMAIL PROTECTED]
_______________________________________________
Rtl mailing list
[EMAIL PROTECTED]
http://www2.fsmlabs.com/mailman/listinfo.cgi/rtl

_______________________________________________
Rtl mailing list
[EMAIL PROTECTED]
http://www2.fsmlabs.com/mailman/listinfo.cgi/rtl

Reply via email to