Hello,

  Following is a simple kernel module of 40 lines which only registers a
misc device. I insmod the module and it is ok; the return value of
misc_register() is 0.
ls -al /dev/mymodule
gives:
crw-rw---- 1 root root 10, 300 22-02-09 20:58 /dev/mymodule
which is ok.
However, when I try, from a user space program, to open the device,
by calling open("/dev/mymodule", O_RDONLY) , I get an error.
The error I get when running the user space program is:
open: No such device or address

I would appreciate if anyone has an idea why is it so. The kernel
module and the user space
program are below.

kernel module:
#define MY_MINOR 300

static long my_ioctl(struct file *filp, unsigned int cmd, unsigned long data)
 {
  return 0;
 }

 struct file_operations mymodule_fops =
 {
        .owner   = THIS_MODULE,
        .unlocked_ioctl = my_ioctl,
        .compat_ioctl   = my_ioctl,
 };

static struct miscdevice my_dev = {
        MY_MINOR,
        "mymodule",
        &mymodule_fops,
};

static int __init mymodule_init(void)
  {
        int ret;
        mymodule_fops.owner = THIS_MODULE;
        ret = misc_register(&my_dev);
  printk("ret = %d\n",ret);
        if (ret)
         return -1;
        return 0;
 }

 static void __exit mymodule_exit(void)
 {
         misc_deregister(&my_dev);
 }
module_init(mymodule_init)
module_exit(mymodule_exit)
-----------------


The user space program:

int main()
{
  int fd;

  fd = open("/dev/mymodule", O_RDONLY);
        if (fd == -1) {
                perror("open");
                exit(1);
        }
  printf("open succeeded\n");   

}

Regards,
Kevin

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to [email protected]
Please read the FAQ at http://kernelnewbies.org/FAQ

Reply via email to