操作系统之字符显示的控制实验

实验目的

按下F12,后面终端显示键盘的字符全部用’*'代替;再次按下F2,后面终端显示键盘的字符又恢复正常。

实验过程

编写press_f12_handle函数

// linux-0.11/kernel/chr_drv/tty_io.c
int switch_show_char_flag = 0;
void press_f12_handle(void)
{
	if (switch_show_char_flag == 0)
	{
		switch_show_char_flag = 1;
	}
	else if (switch_show_char_flag == 1)
	{
		switch_show_char_flag = 0;
	}
}

这个函数是用来响应f12按键的映射接口。

修改tty_table

// 此位置将原有的func改为press_f12_handle
.long press_f12_handle,none,none,none		/* 58-5B f12 ? ? ? */

修改con_write

void con_write(struct tty_struct * tty)
{
	int nr;
	char c;

	nr = CHARS(tty->write_q);
	while (nr--) {
		GETCH(tty->write_q,c);
		// 增加此段代码
		if (switch_show_char_flag == 1)
		{
			c = '*';
		}
		...

修改tty.h

// 在头文件中加入下面的代码
extern int switch_show_char_flag;
void press_f12_handle(void);

实验结果

在这里插入图片描述

总结

本质是将即将写入终端的字符替换为’*’。这样一来就达成了目的。

猜你喜欢

转载自blog.csdn.net/m0_38099380/article/details/89221596