第1关:编写一个显示文件内容的程序
用visual打开os/linux-0.11-lab/b,创建mycat.c程序
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#define MSG_LEN 80
#define FILE_FROM "/usr/root/hello.c"
int main()
{
int fd, num;
char msg[MSG_LEN+1];
/* welcome */
printf("\n\rHi, press ENTER to continue...\n\r");
read(0, msg, 1);
/* open and read the file */
if ((fd=open(FILE_FROM,O_RDONLY,0)) < 0) {
printf("Open file error.\n\r");
return 1;
}
if ((num = read(fd, msg, MSG_LEN))<0) {
printf("Read file error.\n\r");
return 1;
}
close(fd);
/* display on screen */
msg[num] = '\0';
printf("Content of file \"%s\":\n\r---\n\r%s---\n\r", FILE_FROM, msg);
return 0;
}
打开0内核虚拟机输入:
- mdir b:mycat.c
- mcopy b:mycat.c .
- uemacs /etc/rc
编辑文件,保存的快捷键是 Ctrl-x,s
,退出的快捷键是 Ctrl-x, Ctrl-c
。
然后输入
- gcc mycat.c
- ./a.out
即可测评(测评失败可多测几遍)。
第2关:版本 0 内核中文件的读取过程分析
进入gdb调试之后
- b do_execve
- c
- commands 2
- p current->start_code+filename
- end
- c
- c
- b sys_read
- c
- c
- b add_request
- c
- p *dev
- p *req
- b wake_up
- c
- b sched.c:141
- c
- c
- c
- p c
第四关.txt: