资源描述
院系:—————— 专业班级:——————— 姓名:——————— 学号:——————
装 订 线
《linux设备驱动程序设计》课程试卷A
适用专业: 考试日期: 闭卷
所需时间:120分钟 总分:100分
一、 填空题(每空1分,共10分)
1. 驱动程序全称为______________,是一种可以使计算机和________通信的特殊程序。
2. Linux设备驱动程序可以分为__________、__________、___________三类。
3. Linux内核主要由以下五个子系统组成____________、__________
____________、_______________、________________
二、 问答题(每题10分,共70分)
1. 什么是设备驱动?请详细说明 (10分)
2. 无操作系统和有操作系统的设备驱动的区别在哪里?为什么要使用操作系统? (10分)
3. 驱动程序可以分为哪两类?请举例说明 (10分)
4. LINUX中引入了“模块”的概念,那么什么是“模块”?它有什么特点? (10分)
主设备号和次设备号是什么?LINUX中如何使用它们?(10分)
5. MAKEFILE的用途是什么?下面是一个简单的MAKEFILE文件,试分析其每句的功能 (10分)
aaa = hello.o
hello:global.o $(aaa)
hello.o: global.h
global.o:global.h
clean:
rm *.o hello
7. 常用的驱动编写相关的命令有以下几个,请分别写出它们的用途: (10分)
printk
Insmod
Lsmod
Rmmod
Dmesg
三、程序阅读(共20分)
下面是一个比较完整的驱动程序例子,请阅读代码,详细写出每段的意义 (每空2分,共20分)
头文件 略
MODULE_LICENSE("GPL");
#define MAJOR_NUM 252 ①
static ssize_t hello_read(struct file *, char *, size_t, loff_t * off);
static ssize_t hello_write(struct file *, const char *, size_t, loff_t * off);
static int hello_open(struct inode *inode,struct file *filp);
static int hello_release(struct inode *inode,struct file *filp);
struct file_operations hello_fops =
{
open: hello_open,
read: hello_read,
write: hello_write,
release:hello_release,
}; ②
static int global_var = 0;
static int __init hello_init(void)
{
int ret;
ret = register_chrdev(MAJOR_NUM, "hello", &hello_fops);
if (ret)
{
printk("hello register failure!\n");
}
else
{
printk("hello register success!\n");
}
return ret;
} ③
static void __exit hello_exit(void)
{
int ret;
ret = unregister_chrdev(MAJOR_NUM, "hello");
if (ret)
{
printk("hello unregister failure\n!");
}
else
{
printk("hello unregister success!\n");
}
} ④
static int hello_open(struct inode *inode,struct file *filp)
{
printk("this is hello_open!\n");
return 0;
} ⑤
static int hello_release(struct inode *inode,struct file *filp)
{
printk("this is hello_release!\n");
return 0;
} ⑥
static ssize_t hello_read(struct file *filp, char *buf, size_t len, loff_t *off)
{
printk("this is hello_read!\n");
if (copy_to_user(buf, &global_var, sizeof(int)))
{
return 0;
}
return sizeof(int);
} ⑦
static ssize_t hello_write(struct file *filp, const char *buf, size_t len, loff_t *off)
{
printk("this is hello_write!\n");
if (copy_from_user(&global_var, buf, sizeof(int)))
{
return 0;
}
return sizeof(int);
} ⑧
module_init(hello_init); ⑨
module_exit(hello_exit); ⑩
展开阅读全文