Re: Newbie questions on the kernel programming



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


leo.liang.chen@xxxxxxxxx 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

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

.



Relevant Pages

  • Problems with Belkin F5D6050u - not responding at boot
    ... I'm using the Berlios at76c503-rfmd driver with a Belkin F5D6050u ... Jan 11 15:20:13 linux kernel: usb.c: registered new driver usbdevfs ... Jan 11 15:20:13 linux kernel: uhci.c: USB Universal Host Controller Interfaceriver v1.1 ... Jan 11 15:20:13 linux kernel: hub.c: USB hub found ...
    (comp.os.linux.networking)
  • Re: 2.6.16 serious consequences / GPL_EXPORT_SYMBOL / USB drivers of major vendor excluded
    ... Only the kernel offers low latency and timeline processing ... using usbfs directly, no kernel driver needed. ... That seems _very_ large for a Linux kernel driver. ... release your code under this same license. ...
    (Linux-Kernel)
  • Re: Linux-2.6.12
    ... Just fills me with confidence about the GPL'd nature of this driver. ... * downright wrong changes to the Linux kernel that occurred in ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: New proposed DRM interface design
    ... the Linux kernel isn't about minimizing interfaces. ... > copy of scsi helpers into each scsi driver either, ...
    (Linux-Kernel)
  • USB driver woes--hiddev is getting in the way!
    ... I wrote a USB driver for a custom HID device and all was well (passed ... Apr 19 14:33:05 linux kernel: myusb: unsupported module, ...
    (comp.os.linux.development.system)