Re: Cannot open from user space a misc device - why ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

my previous post with open method seems to be wrong.

On Sun, Feb 22, 2009 at 8:11 PM, Kevin Wilson <wkevils@xxxxxxxxx> wrote:
> 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

Minor number couldn't be bigger like 255. I think this cause a problem
with opening.
I change to e.g. : 149 and works fine without open method.

Please check.

I think also udev should check max. values for minor and major numbers.
I don't use udev but I set entry in device table and then get error when run
makedevs with minor 300. Seems makedevs works properly.


>
> 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 ecartis@xxxxxxxxxxxx
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>

good luck,

Marek

-- 
as simple as primitive as possible
----------------------------------------------
Marek Beliško - open-nandra
Ruská Nová Ves 219
08005 Prešov
Slovakia
http://open-nandra.com

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux