How file operations are dispatched to the console

% This paragraph is quite low-level, and can be happily skipped over. Needless to say, a \ device is accessed though the filesystem. This paragraph details all steps from the device file to the actual console functions. Moreover, the following information is extracted from the 1.1.73 source code, and it may be slightly different from the 1.0 source. When a device inode is opened, the function <#2612#> chrdev_open()<#2612#> (or <#2613#> blkdev_open()<#2613#>, but we'll stick to character devices) in <#2614#>../../fs/devices.c<#2614#> gets executed. This function is reached by means of the structure <#2615#> def_chr_fops<#2615#>, which in turn is referenced by <#2616#> chrdev_inode_operations<#2616#>, used by all the filesystem types (see the previous section about filesystems). <#2617#> chrdev_open<#2617#> takes care of specifying the device operations by substituting the device specific <#2618#> file_operations<#2618#> table in the current <#2619#> filp<#2619#> and calls the specific <#2620#> open()<#2620#>. Device specific tables are kept in the array <#2621#> chrdevs[]<#2621#>, indexed by the major device number, and filled by the same <#2622#> ../../fs/devices.c<#2622#>. If the device is a tty one (aren't we aiming at the console?), we come to the tty drivers, whose functions are in <#2623#> tty_io.c<#2623#>, indexed by <#2624#> tty_fops<#2624#>. Thus, <#2625#> tty_open()<#2625#> calls <#2626#> init_dev()<#2626#>, which allocates any data structure needed by the device, based on the minor device number. The minor number is also used to retrieve the actual driver for the device, which has been registered through <#2627#> tty_register_driver()<#2627#>. The driver, then, is still another structure used to dispatch computation, just like <#2628#> file_ops<#2628#>; it is concerned with writing and controlling the device. The last data structure used in managing a tty is the line discipline, described later. The line discipline for the console (and any other tty device) is set by <#2629#> initialize_tty_struct()<#2629#>, invoked by <#2630#> init_dev<#2630#>. Everything we touched in this paragraph is device-independent. The only console-specific particular is that <#2631#> console.c<#2631#>, has registered its own driver during <#2632#> con_init()<#2632#>. The line discipline, on the contrary, in independent of the device.

#tex2html_wrap2964#

.

#tex2html_wrap2966#