Полезная информация

next up previous contents
Next: Character Device Drivers Up: The VFS Previous: The open() and release()

The init() function

This function is not actually included in the file_operations structure, but you are required to implement it, because it is this function that registers the file_operations structure with the VFS in the first place -- without this function, the VFS could not route any requests to the driver. This function is called when the kernel first boots and is configuring itself. init() is passed a variable holding the address of the current end of used memory. The init function then detects all devices, allocates any memory it will want based on how many devices exist (this is often used to hold such things as queues, for interrupt driven devices), and then, saving the addresses it needs, it returns the new end of memory. You will have to call your init() function from the correct place: for a character device, this is chr_dev_init() in .../kernel/chr_dev/mem.c. In general, you will only pass the memory_start variable to your init() function.

While the init() function runs, it registers your driver by calling the proper registration function. For character devices, this is register_chrdev().gif register_chrdev() takes three arguments: the major device number (an int), the ``name'' of the device (a string), and the address of the device_fops file_operations structure.

When this is done, and a character or block special file is accessed, the VFS filesystem switch automagically routes the call, whatever it is, to the proper function, if a function exists. If the function does not exist, the VFS routines take some default action.

The init() function usually displays some information about the driver, and usually reports all hardware found. All reporting is done via the printk() function.

Converted on:
Mon Apr 1 10:20:16 EST 1996