linux tty core code,Linux tty core 源码分析.doc

本文详细分析了Linux 2.6.27内核中的ttycore源码,该核心为tty设备(串口、控制台、虚拟终端)提供公共平台。文章介绍了如何注册字符设备驱动,如tty_cdev、console_cdev、ptmx_cdev和vc0_cdev,并通过cdev_init和register_chrdev_region函数将它们添加到/dev目录下。
摘要由CSDN通过智能技术生成

Linux tty core 源码分析

Linux tty core 源码分析

[日期:2011-02-08]来源:CSDN? 作者:sirzjp本文以linux 2.6.27内核为基础,阅读tty core 源码并作注解,自己接触时间不长,希望与爱好者共同分享,错误之处还望指正。

linux tty core 是建立在字符设备驱动的基础之上,并为tty类型设备(串口、控制台、虚拟终端)提供一个公用的平台。所以任何一个tty设备驱动的注册都是作为一个字符设备驱动而操作的。下面我们看看代码中是如何处理的:

/* 3/2004 jmc: why do these devices exist? */

//tty核心默认在内核中实现的字符型tty设备驱动

static struct cdev tty_cdev, console_cdev;#ifdef CONFIG_UNIX98_PTYSstatic struct cdev ptmx_cdev;#endif#ifdef CONFIG_VTstatic struct cdev vc0_cdev;#endif

/*?* Ok, now we can initialize the rest of the tty devices and can count?* on memory allocations, interrupts etc..?*/static int __init tty_init(void){

//在字符设备模型中加入注册tty_cdev驱动并加入/dev/tty这样的设备

?cdev_init(&tty_cdev, &tty_fops);?if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) ||???? register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0)? panic("Couldn't register /dev/tty driver\n");?device_create_drvdata(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL,???????? "tty");

//在字符设备模型中加入注册console_cdev驱动并加入/dev/console这样的设备

?cdev_init(&console_cdev, &console_fops);?if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) ||???? register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0)? panic("Couldn't register /dev/console driver\n");?device_create_drvdata(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), NULL,???????? "console");

//在字符设备模型中加入注册ptmx_cdev驱动并加入/dev/ptmx这样的设备

#ifdef CONFIG_UNIX98_PTYS?cdev_init(&ptmx_cdev, &ptmx_fops);?if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||???? register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)? panic("Couldn't register /dev/ptmx driver\n");?device_create_drvdata(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx");#endif

//在字符设备模型中加入注册vc0_cdev驱动并加入/dev/tty0这样的设备

#ifdef CONFIG_VT?cdev_init(&vc0_cdev, &console_fops);?if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) ||???? register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)? panic("Couldn't register /dev/tty0 driver\n");?device_create_drvdata(tty_cl

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值