From: Markku Savela <msa@moth.iki.fi>
To: greg@kroah.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: How to get /dev entry created automaticly for dynamic major number?
Date: Thu, 25 Jan 2007 15:11:15 +0200 [thread overview]
Message-ID: <200701251311.l0PDBFD0025319@moth.iki.fi> (raw)
In-Reply-To: <20070125082544.GA16300@kroah.com> (message from Greg KH on Thu, 25 Jan 2007 00:25:44 -0800)
Solution found!
> On Thu, Jan 25, 2007 at 09:35:07AM +0200, Markku Savela wrote:
> > If want to write a loadable module which "implements" a char device
> > ("virtual", no real device present). How do I get the correct
> > "/dev/foo" to appear automaticly?
> From: Greg KH <greg@kroah.com>
> If you look in the book, Linux Device Drivers, third edition, free
> online, there's a section on what is needed for udev to work properly.
>
> The ideas are still the same, but the way to do it has changed since the
> book was written. Just use a struct device and a class, and you will be
> fine. Look at the misc device core or the mem code in
> drivers/char/mem.c for examples of what you need to do.
Thanks! The solution seems to work. The final *obstacle* was, that
class_* symbols were not available until I added the
LICENSE("GPL"). Here is the resulting template, maybe useful for
someone, and just for verification, that I got it right.
...
static int foo_major = 0;
static struct class *foo_class;
static struct class_device *foo_device;
...
static int __init foo_init(void)
{
foo_major = 0;
foo_class = NULL;
foo_device = NULL;
foo_major = register_chrdev(foo_major, "foo", &foo_fops);
if (foo_major <= 0)
return -EIO;
foo_class = class_create(THIS_MODULE, "foo");
if (IS_ERR(foo_class))
{
return PTR_ERR(foo_class);
}
foo_device = class_device_create(foo_class, NULL, MKDEV(foo_major, 0), NULL, "foo0");
if (IS_ERR(foo_device))
{
return PTR_ERR(foo_device);
}
return 0;
}
static void __exit foo_exit(void)
{
if (foo_device && !IS_ERR(foo_device))
class_device_del(foo_device);
if (foo_class && !IS_ERR(foo_class))
class_destroy(foo_class);
if (foo_major > 0)
unregister_chrdev(foo_major, "foo");
}
module_init(foo_init);
module_exit(foo_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Markku Savela");
MODULE_DESCRIPTION("Just fooling around");
next prev parent reply other threads:[~2007-01-25 13:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-25 7:35 How to get /dev entry created automaticly for dynamic major number? Markku Savela
2007-01-25 8:25 ` Greg KH
2007-01-25 13:11 ` Markku Savela [this message]
2007-01-25 13:17 ` Markku Savela
2007-01-25 13:37 ` Jiri Kosina
2007-01-25 15:51 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200701251311.l0PDBFD0025319@moth.iki.fi \
--to=msa@moth.iki.fi \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox