Re: simple example of ready-to-load miscdevice module on ubuntu 10.04?

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

 



On Sun, 25 Jul 2010, Daniel Baluta wrote:

> On Sat, Jul 24, 2010 at 11:05 PM, Robert P. J. Day
> <rpjday@xxxxxxxxxxxxxx> wrote:
> > On Sat, 24 Jul 2010, Dave Hylands wrote:
> >
> >> Hi Robert,
> >>
> >> On Sat, Jul 24, 2010 at 6:25 AM, Robert P. J. Day wrote:
> >> >
> >> >  (i'm sure i can eventually track this down, but maybe someone can
> >> > save me the time.)
> >> ...snip...
> >> >  fair enough.  now, however, i'd like to find (again, on my ubuntu
> >> > 10.04 system) an example driver that uses dynamic minor number
> >> > allocation and that's *not* built into the kernel so i can use that as
> >> > a demo of what happens when one loads such a driver.  and, so far, i
> >> > haven't found an example like that yet -- every driver that does that
> >> > is, on this system, configured to be built into the kernel.
> >> >
> >> >  anyone know of such an example?  i briefly grep'ped thru drivers/
> >> > for the macro MISC_DYNAMIC_MINOR but every example i saw was, on this
> >> > system, configured to be built into the kernel.
> >>
> >> I'm just in the process of upgrading to 10.04, so I don't have a
> >> definitive answer, but you could try the following
> >>
> >> cd /lib/modules/2.6.whatever
> >> grep -r misc_register *
> >>
> >> That seems to come up with quite a few potential candidates.
> >
> >  true, but that doesn't distinguish between drivers that have a
> > reserved minor number, and those that request a dynamic one.  i'm sure
> > there's a simple solution to this, i just don't know what it is.
>
> I suggest to write your own char driver. It won't take more than 30
> lines of code.

  yes, i know, but (once again), that's not the point.  the point was
to see if there was a sample module that just happened to be lying
around on a stock ubuntu 10.04 system that students could "modprobe"
to see what happens, at which point they could have a benchmark for
what *their* driver would behave like.  and dave hylands found one in
short order:  scsi_tgt.

  it's the perfect example -- it appears to come pre-loaded on ubuntu
10.04; it doesn't appear to have any dependencies; it predictably
showed up as:

$ ls -l /dev/tgt
crw-rw---- 1 root root 10, 55 2010-07-25 03:22 /dev/tgt
$

and the source file drivers/scsi/scsi_tgt_if.c is eminently readable
and shows clearly that it's a dynamic minor number allocation.  it's
exactly what i was looking for.

  not to belabour the point, but there's a reason i'm trying to do it
this way in my course.  it's one thing to write, "i'm about to show
you how to do X."  but before that happens, i want to make sure i've
established the rationale for *why* i'm about to explain it.  and a
simple way to do that is to demonstrate that "X" is used in numerous
places in the kernel *already*, and how to test it and see it in
operation before writing any code.

  it's, for example, how i explained how to write /proc files.  before
i put down any code, i pointed at places in the kernel source that
were doing the same thing, so the student can now rest assured, "ah,
i'm not just going to learn how to do something, but it's something
lots of other source is doing, too."  in short, if i can't point at
*some* example in the current kernel source that's implementing
something, it's hard to defend why i should be teaching anyone else
how to do it.

  ok, i've rambled enough.  back to work.  and thanks for the example,
dave.

rday

-- 

========================================================================
Robert P. J. Day                               Waterloo, Ontario, CANADA

        Top-notch, inexpensive online Linux/OSS/kernel courses
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================

[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