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

Reply via email to