Newbie questions on the kernel programming - Linux

This is a discussion on Newbie questions on the kernel programming - Linux ; Hi all, I am learning linux kernel programming starting from "The Linux Kernel Module Programming Guide"( http://www.faqs.org/docs/kernel/ ) . I have background in Windows DDK, but I am confused on the following topics. Can anyone here give me some hints. ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Newbie questions on the kernel programming

  1. Newbie questions on the kernel programming

    Hi all,

    I am learning linux kernel programming starting from "The Linux Kernel
    Module Programming Guide"(http://www.faqs.org/docs/kernel/) . I have
    background in Windows DDK, but I am confused on the following topics.
    Can anyone here give me some hints.

    1) MODULE_PARM() macro (http://www.faqs.org/docs/kernel/x350.html)
    static short int myshort = 1;
    static int myint = 420;
    static long int mylong = 9999;
    static char *mystring = "blah";

    MODULE_PARM (myshort, "h");
    MODULE_PARM (myint, "i");
    MODULE_PARM (mylong, "l");
    MODULE_PARM (mystring, "s");

    In the sample code, it is said the MODULE_PARM macro can allow
    arguments to be passed to the driver module. But how?

    2) Character Device Drivers(http://www.faqs.org/docs/kernel/x571.html)
    I can not catch the key points in this section. What should I learn
    from the "chardev.c" sample? How can I install the module as a device?
    How can I call the functions in the driver?

    3) The /proc File System(http://www.faqs.org/docs/kernel/x716.html)
    What's the main points in the section. How does the /proc file system
    matter linux kernel programming?


    Many thanks!


    Liang Chen


  2. Re: Newbie questions on the kernel programming

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1


    leo.liang.chen@gmail.com wrote:
    > Hi all,
    >
    > I am learning linux kernel programming starting from "The Linux Kernel
    > Module Programming Guide"(http://www.faqs.org/docs/kernel/) . I have
    > background in Windows DDK, but I am confused on the following topics.
    > Can anyone here give me some hints.
    >
    > 1) MODULE_PARM() macro (http://www.faqs.org/docs/kernel/x350.html)
    > static short int myshort = 1;
    > static int myint = 420;
    > static long int mylong = 9999;
    > static char *mystring = "blah";
    >
    > MODULE_PARM (myshort, "h");
    > MODULE_PARM (myint, "i");
    > MODULE_PARM (mylong, "l");
    > MODULE_PARM (mystring, "s");
    >
    > In the sample code, it is said the MODULE_PARM macro can allow
    > arguments to be passed to the driver module. But how?


    When the module is invoked (via modprobe or insmod), you can specify
    the values to be passed to the module as 'options' to the load command

    In /etc/modules.conf, you include an "options" line that gives the
    values for your modules parameters
    options mymodule myshort=5 myint=-3100 mylong=99999999
    mystring="argh"

    Alternately, you specify them on the modprobe or insmod commandline
    modprobe mymodule myshort=1 myint=-7 mylong=9999999 mystring="blah"
    or
    insmod mymodule myshort=1 myint=-7 mylong=9999999 mystring="blah"


    > 2) Character Device Drivers(http://www.faqs.org/docs/kernel/x571.html)
    > I can not catch the key points in this section. What should I learn
    > from the "chardev.c" sample? How can I install the module as a device?
    > How can I call the functions in the driver?


    character devices do not support "random" access, or features that
    require "random access", so you implement null (return error value)
    functions for the entrypoints that service lseek, mmap, readdir, etc.
    Really, a character device only really must support read, write, open,
    close, and may support ioctl, etc. so those are the functions you /do/
    implement.

    Finally, you have to connect the driver when you load it, and
    disconnect it to unload it.



    > 3) The /proc File System(http://www.faqs.org/docs/kernel/x716.html)
    > What's the main points in the section. How does the /proc file system
    > matter linux kernel programming?


    The /proc filesystem is used by the linux kernel (and kernel tools like
    device drivers) to externalize status information and accept control
    information. Think of it as an easier-to-use alternate to ioctl. A
    device driver doesn't /have/ to implement a /proc interface, but it can
    do so to accept control information, or to provide feedback that
    otherwise must be handled through an ioctl or another device I/O.


    - --
    Lew Pitcher
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.3 (MingW32) - WinPT 0.11.12

    iD8DBQFElsC3agVFX4UWr64RAtPXAKDbME76HQgOTbwjQoibTK Uuhv+rnwCgobSW
    xxKcprdUHSdY86Up4tY/0to=
    =s9Qx
    -----END PGP SIGNATURE-----


  3. Re: Newbie questions on the kernel programming

    On 2006-06-19, Lew Pitcher wrote:

    >> 3) The /proc File
    >> System(http://www.faqs.org/docs/kernel/x716.html) What's the
    >> main points in the section. How does the /proc file system
    >> matter linux kernel programming?

    >
    > The /proc filesystem is used by the linux kernel (and kernel
    > tools like device drivers) to externalize status information
    > and accept control information. Think of it as an
    > easier-to-use alternate to ioctl. A device driver doesn't
    > /have/ to implement a /proc interface, but it can do so to
    > accept control information, or to provide feedback that
    > otherwise must be handled through an ioctl or another device
    > I/O.


    Specifically, I've found it invaluable for providing a way to
    look at the module's "internal" state for diagnostic/debugging.

    --
    Grant Edwards grante Yow! PARDON me, am I
    at speaking ENGLISH?
    visi.com

  4. Re: Newbie questions on the kernel programming

    leo.liang.chen@gmail.com wrote:
    > I am learning linux kernel programming starting from "The Linux
    > Kernel
    > Module Programming Guide"(http://www.faqs.org/docs/kernel/) .


    That's an old version, you should use
    http://tldp.org/LDP/lkmpg/2.6/html/index.html instead.

    --
    Markku Kolkka
    markku.kolkka@iki.fi



+ Reply to Thread