资源描述
课程设计阐明书
设计名称: 操作系统课程设计
题 目: 文献访问接口设计
学生姓名: 陈小浪
专 业: 计算机科学与技术
班 级: 12级1班
学 号: 314118
指引教师: 任朝晖
日 期: 年 9 月 15 日
课程设计任务书
计算机科学与技术 专业 年级 班
一、 设计题目
文献访问接口设计
二、 重要内容
运用C语言设计,详细涉及:
1、 基本文献内容输入
2、 基本文献内容输出
3、 创立文献
4、 打开文献
5、 关闭文献
6、 文献缓冲区管理
7、 文献句柄管理
8、读顺序文献
9、写顺序文献
10、读随机文献
11、写随机文献
12、文本文献操作验证程序
上述功能由两某些程序验证,中断驻留程序和验证程序。一方面运营中断驻留程序,然后运营验证程序得到预期成果。
三、 详细规定
本设计目是通过BIOS调用设计简朴文献访问接口,使学生掌握程序接口设计办法。
规定学生在熟悉比BIOS、DOS操作系统中断接口及程序接口基本上,运用C语言设计简朴文献访问接口,最后通过程序验证接口对的性。
四、 进度安排
依照教学筹划,课程设计时间为:2周。
1. 规定解说、资料查找、系统分析,概要设计 (2天)
2. 系统详细设计、功能设计(2天)
3. 算法实现、编程调试(5天)
4. 功能演示、资料整顿、课程设计阐明书编写。(1天)
五、 完毕后应上交材料
课程设计阐明书纸质文档
六、 总评成绩
指引教师 签名日期 年 月 日
系 主 任 审核日期 年 月 日
目 录
一、程序概述 1
1.1完毕任务 1
1.2解决问题 1
二、概念原理 1
2.1基本概念 1
2.2基本原理 2
三、总体设计 2
3.1实现办法 2
3.2技术路线 2
四、详细设计 2
4.1重要函数 2
4.2引用函数 3
五、完毕状况 3
六、使用阐明 3
七、设计总结 4
7.1系统特色 4
7.2经验教训 5
7.3实践感受 5
参照资料 6
附 录 7
一、程序概述
1.1完毕任务
本设计规定编写一种简朴文献访问接口设计,运用C语言,DOS,BIOS中断调用进行设计。重要完毕规定中所提到功能如:创立文献,删除文献,打开文献,关闭文献,基本文献内容输入,基本文献内容输出,读顺序文献,写顺序文献,文本文献操作验证程序,文献缓冲区管理 实现。
1.2解决问题
在设计过程重要遇到了如下问题:一是关于中断理解,二是在理解了中断意义之后,进行中断函数如int86(),int86x(),intdos(),intdos()等函数调用不是很清晰。
解决过程:通过与同窗讨论,在网上查阅了有关书籍和学过课本,如《C高档实用设计》以及《80x86汇编语言程序设计》之后,便有了比较清晰思路。关于函数调用参数设计,基本上是基于这些:构造体WORDREGS,BYTEREGS,SREGS,联合体REGS ,文献属性字节,以及汇编语言中int 21H dos系统功能调用中中断类型(重要是21H)以及调用功能号查询和设立。
下面重要简介上述提及几种构造体跟联合体:
//以字作为单位寄存器所组合构造体
Struct WORDREGS
{
Unsigned int ax,bx,cx,dx,si,di,cflag,flags;
};
//以字节作为单位寄存器做组合构造体
Struct BYTEREGS
{
Unsigned char al,ah,bl,bh,cl,ch,dl,dh;
};
//由上述两个构造体所组合共用体(联合体)
Union REGS
{
Struct WORDREGS x;
Struct BYTEREGS h;
};
//由段寄存器组合构造体
Struct SREGS
{
Unsigned int es,cs,ss,ds;
};
二、概念原理
2.1基本概念
中断
中断:顾名思义,是指当浮现需要时,CPU暂时停止当前程序执行转而执行解决新状况程序和执行过程。即在程序运营过程中,系统浮现了一种必要由CPU及时解决状况,此时,CPU暂时中断程序执行转而解决这个新状况过程就叫做中断。本课题中涉及为dos中断跟bios中断。
文献访问接口
所谓访问接口,事实上即为顾客通过dos状态下提示,键入有关命令后,作为访问有关文献操作中介,即类似一种中转站。而系统同步也需要在响应了顾客键入命令后执行预先编写好相应程序,并将程序执行成果通过中介,即文献访问接口,输出给顾客。而事实上在系统响应一次顾客命令时,系统进行了一次IO中断。
中断驻留程序
中断驻留程序,指是当加载进内存程序执行完毕后,依然可以保存产生暂时数据跟暂时状态,而在下一次调用时继续执行。
验证程序
本课题验证程序,指是,当用dos,bios中断调用编写好有关用于文献访问函数并执行之后,用C语言高档函数如fopen(),fprintf(),fgetc(),fclose()等函数来验证上述编写访问函数与否可行。本课题中用fopen(),fclose()来验证用dos中断调用所编写函数CloseFile(),CreateFile()和CloseFile();用fgetc(),fprintf()等函数来验证用dos中断调用所编写WriteToFile()和ReadFromFile()函数;除此之外,像ftell(),fseek()等验证是同样道理。只需基于上述由dos,bios中断调用所编写函数.
系统调用
系统调用,顾名思义,说是操作系统提供应顾客程序调用一组“特殊”接口。顾客程序可以通过这组“特殊”接口来获得操作系统内核提供服务,例如顾客可以通过文献系统有关调用祈求系统打开文献、关闭文献或读写文献,可以通过时钟有关系统调用获得系统时间或设立定期器等。
从逻辑上来说,系统调用可被当作是一种内核与顾客空间程序交互接口,它好比一种中间人,把顾客进程祈求传达给内核,待内核把祈求解决完毕后再将解决成果送回给顾客空间。
2.2基本原理
本课题运营成果,一方面是在运营开始时给定了10个选取开关,供顾客选取,每当接受一次顾客选取时,系统将进行一次IO中断,之后执行相应中断服务程序,在这里是指由dos,bios中断调用编写好函数,调用结束时,将暂时成果保存,并退出中断,继续响应顾客选取,直到顾客选取了退出。
如下图所示:
三、总体设计
3.1实现办法
程序通过选取开关switch...case将用dos,bios调用编写函数组合起来供顾客做出选取。在相应解决顾客选取编写函数中,重要核心是dos功能中断调用函数编写,其中涉及中断类型号,中断功能调用号等设立,以及响应顾客选取后中断服务程序编写。
此外,可以通过参看当前工作目录下文献信息或者通过Validate开头有关函数进行程序运营成果验证
3.2技术路线
整个程序设计流程,环绕着bios,dos功能中断调用这一主线,编写好有关文献操作函数,在响应顾客选取之后,相应执行有关函数
四、详细设计
4.1重要函数
Int OperOfSel():
用于显示可供顾客选取功能,并提示顾客作出相应功能选取
Void CreateFile(char filename[80]):
用于创立一种新文献:依照顾客输入文献名进行文献创立,如果文献创立失败:如磁盘空间已满或者已经存在该文献,即创立失败
Int DeleteFile(char filename[80]):
用于删除一种文献,如果删除成功,将返回文献代号,否则删除失败:也许是不存在该文献
Int OpenFile(char filename[80]):
用于打开一种文献,如果打开成功,则返回文献代号,否则打开失败,也许是不存在该文献
Void CloseFile(filename[80]):
用于关闭一种文献
Void WriteToFile(filename[80]):
用于写顺序文献 基本文献内容输入 以及文献缓冲区管理:一方面依照顾客输入文献名打开一种文献,如果存在该文献,则打开成功,开始写入内容,此时继续接受顾客输入内容,注意,输入直到顾客键入回车键即表达输入完毕,此时将输入内容依照文献缓冲区管理规则将顾客输入内容进行存储至指定文献名文献中
Void ReadFromFile(filename[80]):
用于读顺序文献 基本文献内容输出 以及文献缓冲区管理:从指定文献中读取文献中内容,并输出;
Void ValidateOpenFile(char filename[80]):
用于验证上述文献访问函数编写对的性:用于验证创立文献 打开文献与否成功
Void ValidateReadFile(char filename[80]):
用于验证上述文献访问函数编写对的性:用于验证上述中 WriteToFile(filename[80])以及 ReadFromFile(filename[80]):函数
4.2引用函数
Clrscr()
用于清空屏幕作用
五、完毕状况
本程序完毕了其中9项,可以实现文献创立,打开,关闭,基本文献内容输入,输出,文献缓冲区管理,以及文本文献验证程序,写顺序文献,读顺序文献。由于对文献句柄以及写,读随机文献理解不是很清晰,故而没有动手实践完毕。此外,本程序在dos下进行演示,需要依照提示来进行输入,不容许顾客胡乱输入,否则有也许程序解决不了,即本程序在某种限度上还不是很稳定,安全。但从理论上角度上讲,只要操作合理,那么本程序将可以实现相应功能。
六、使用阐明
运营成功后进行首页,开始接受顾客选取
接着进行相应功能选项前面相应数字输入,在这里以1,5,6,10为例,其她为同样道理
1:为创立一种新文献
表达test.txt文献已经存在,故而创立失败 查看目录,果然已经存在了test.txt,故而提示创立失败
再次执行1号功能选取:newfile.txt创立成功
查看目录下,果然创立了newfile.txt
进行10号功能选取
成果将浮现清空屏幕效果
进行5号功能选取:
输入成功,提示输入了多少个字符 ,上述记录了一下(涉及字符)为63个 在目录打开此文献,果然是写入了这些内容
下面进行6号功能演示
上述演示成果 正好符合了其中规定
其她功能演示也是同样道理
七、设计总结
7.1系统特色
在本系统中已初步实现一种可访问文献接口,可以正常解析命令并执行,在解析命令方面,采用中断函数调用以及功能类型号选取设立形式,达到直接与底层“打交道”
作用,效率高
7.2经验教训
在编程过程中要多使用库函数中自带内容,不必此外再去编写已有功能,这样不但能节约时间,也能提高程序可靠性。要多理解库函数,可以阅读相应协助文献来获得有用信息。遇到问题多与教师同窗讨论,可以协助自己跳出思维定势。
7.3实践感受
每次课程设计都是对咱们所学知识一种深化,在实践过程中能遇到许多问题,遇到问题à分析问题à解决问题,这样对知识理解得到一种升华。实践过程中学到都是印象非常深刻,因此后来要多参加这样实践,认真对待每一次机会。
本次课程设计,其实从某种限度上来说,还是挺有难度,由于,之前对于C语言理解是通过其高档函数,如文献访问中,正是通过其高档函数来访问。刚开始还不知所措,网上简介也很模糊,主线很难找到关于dos中断进行文献访问接口有关设计。日后在于伙伴讨论下,懂得了C高档实用设计这本书,从次书中受益匪浅,加上80x86汇编语言程序设计,更是增长了自己对于汇编见识,从此更加必定了汇编在底层操纵作用!
并且通过本次课程设计,结识了讨论重要性,我个人觉得编码正是如此,如果遇到了一种人难以解决,那么最佳是提出来与伙伴或者同窗一同探讨,这不但能直到别人向想法,更能让自己结识自己局限性,更有甚者,可以增长自己见识!!!!!
参照资料
1、《计算机操作系统教程》(第2版)张尧学 史美林 编著 清华大学出版社
2、《操作系统实验指引》任爱华 李鹏 刘方毅 清华大学出版社
3、《操作系统实验教程——核心技术与编程实例》顾宝根 王立松 顾喜梅 科学出版社
4、《80x86汇编语言程序设计》沈美明,温冬婵编著,清华大学出版社
5,、《C高档实用程序设计》王世元 编著 清华大学出版社
6、 《C语言程序设计》谭浩强 编著 清华大学出版社
附录:源代码<在TurboC3.0环境>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<process.h>
#include<dos.h>
#include<bios.h>
//The number of type of interrupt
#define INTER 0x21
//The size of filename
#define Num 80
//the number of characters
#define CNum 9
//Function Of Selection
int OperOfSel()
{
//clrscr();
printf("\n\n\n\n------------Function Of Selection------------\n");
printf("\n0 Exit \n1 Create a new file \n2 Delete a existing file ");
printf("\n3 Open a existing file \n4 Close an existing file ");
printf("\n5 Input basic contents to existing file ");
printf("\n6 Output basic contents from existing file ");
printf("\n7 To validate the file is open or not ");
printf("\n8 To validate the reading contents from file ");
//printf("\n9 To validate the writting contents to file ");
printf("\n10 Clean the screen");
printf("\n\n------------Function Of Selection------------\n");
int sel;
printf("\n--------Input Your Selction:");
scanf("%d",&sel);
return sel;
}
//Create a new file
void CreateFile(char filename[80])
{
union REGS inregs,outregs;
struct SREGS segregs;
//The function number of create file is 5B
inregs.h.ah=0x5B;
//Set the segment address and effective address
inregs.x.dx=FP_OFF(filename);
segregs.ds=FP_SEG(filename);
//Set the attribute of file
inregs.x.cx=0;
int86x(INTER,&inregs,&outregs,&segregs);
if(outregs.x.ax==2)
{
printf("\n-------Fail To Create New File-----------------\n");
return;
}
if(outregs.x.ax==80)
{
printf("\n-----Fail to create file:%s The file has benn existed-----\n",filename);
return;
}
printf("\n----Create New File:%s Successfully!The File's Attribute is:%d-----\n",filename,outregs.x.cx);
printf("------The FileCode is:%d\n",outregs.x.ax);
}
//Delete a exist file
int DeleteFile(char filename[80])
{
union REGS inregs,outregs;
struct SREGS segregs;
//The function number of create file is 41
inregs.h.ah=0x41;
inregs.x.dx=FP_OFF(filename);
segregs.ds=FP_SEG(filename);
intdosx(&inregs,&outregs,&segregs);
int result = outregs.x.ax;
return result;
}
//Open an existing file
int OpenFile(char filename[80])
{
union REGS inregs,outregs;
struct SREGS segregs;
int result;
inregs.h.ah=0x3D;
inregs.x.dx=FP_OFF(filename);
segregs.ds=FP_SEG(filename);
//Set the way to access file
inregs.h.al=2;
int86x(INTER,&inregs,&outregs,&segregs);
//You Can Through CreateFile() To Know The FileCode as test
//printf("Successfully open file :%d \n",outregs.x.ax);
/*if(2==outregs.x.ax)
{
printf("\n----------Fail To Open The File:%s May not exist\n",filename);
}
else
{
printf("\n----Successfully Opening The File:%s The FileCode Is:%d\n",filename,outregs.x.ax);
}
*/
result = outregs.x.ax;
return result;
}
//Close The Existing File
void CloseFile(char filename[80])
{
union REGS inregs,outregs;
struct SREGS segregs;
int result;
int FileCode;
//To Close The File :We Should Open The File Firstly;The File Should be exist
inregs.h.ah=0x3D;
inregs.x.dx=FP_OFF(filename);
segregs.ds=FP_SEG(filename);
//Set the way to access file
inregs.h.al=2;
int86x(INTER,&inregs,&outregs,&segregs);
//You Can Through CreateFile() To Know The FileCode as test
//printf("Successfully open file :%d \n",outregs.x.ax);
/*if(2==outregs.x.ax)
{
printf("\n----------Fail To Open The File:%s May not exist\n",filename);
}
else
{
printf("\n----Successfully Opening The File:%s The FileCode Is:%d\n",filename,outregs.x.ax);
}
*/
result = outregs.x.ax;
if(2==result)
{
//printf("\n----------Open the file:%s Failly! It may not exist------------\n",filename);
printf("\n-----------Fail to close the file:%s It may not exist-------\n",filename);
}
else
{
//printf("\n-------Open the file:%s Successfully! Now the file will be close----\n",filename);
FileCode = outregs.x.ax;
inregs.h.ah = 0x3E;
inregs.x.bx = FileCode;
int rel = intdos(&inregs,&outregs);
printf("\n-----Close File:%s Successfully! rel=%d -----\n",filename,rel);
}
}
//Input Contents To Existing File
void WriteToFile(char filename[80])
{
union REGS inregs,outregs;
struct SREGS segregs;
int result;
int FileCode;
char WriteContents[CNum];
inregs.h.ah=0x3D;
inregs.x.dx=FP_OFF(filename);
segregs.ds=FP_SEG(filename);
inregs.h.al=2;
int86x(INTER,&inregs,&outregs,&segregs);
result = outregs.x.ax;
if(2==result)
{
printf("\n---Can not input contents to file:%s ! It may not exist------------\n",filename);
}
else
{
//printf("\n-------Open the file:%s Successfully! Now the file will be close----\n",filename);
//---------Very Important Here :To Abosrb The Enter KeyCode;
getchar();
printf("\n\n----Input The Writting Contents:\n");
/*gets(WriteContents);
//printf("WriteContents:%s \n",WriteContents);
//int CharNum=0,i=0;
int i=0;
while(WriteContents[i]!='\0')
{
//CharNum++;
i++;
}
*/
int count=0;
//printf("CharNum=%d i=%d\n",CharNum,i);
//printf("i=%d\n",i);
int temp=0;
int sumChar=0;
for(int i=0;i<=CNum-1;i++)
{
//WriteContents[i] = getchar();
//WriteContents[i] = '';
if(count==1)
{
WriteContents[i]=temp;
i++;
count=0;
}
scanf("%c",&WriteContents[i]);
if(WriteContents[i]=='\n')
{
//printf("i=%d\n",i);
break;
}//if(WriteContents[i]=='\n') end
if(i==CNum-1)
{
//getchar();
//printf("Hello World\n");
//return;
FileCode = result;
inregs.h.ah=0x40;
inregs.x.dx=FP_OFF(WriteContents);
//inregs.x.dx=FP_OFF(WriteContents);
segregs.ds=FP_SEG(WriteContents);
inregs.x.bx=FileCode;
inregs.x.cx=i;
//printf("inregs.x.cx=%d\n",inregs.x.cx);
//int86x(INTER,&inregs,&outregs,&segregs);
intdosx(&inregs,&outregs,&segregs);
//printf("Now The Ax=%d\n",outregs.x.ax);
//printf("inregs.x.bx=%d\n",inregs.x.bx);
//printf("Hello World\n");
temp = WriteContents[i];
count = count+1;
i = -1;
sumChar += outregs.x.ax;
}//if(i==8) end
//printf("%c",WriteContents[i]);
}//end for circle;
/*char TempContents[8];
for(int k=0;k<i;k++)
{
TempContents[k] = WriteContents[k];
}*/
//printf("\n\n--the rest of the contents of file:%s are listed below---\n",filename);
//printf("WriteContents=%s\n",WriteContents);
//printf("WriteContents[0]=%c WriteContents[1]=%c\n",WriteContents[0],WriteContents[1]);
/*for(int j=0;j<i;j++)
{
printf("%c",WriteContents[j]);
}
printf("\n");*/
//printf("end for circle i=%d\n",i);
//printf("WriteContents= %s i=%d\n",WriteContents,i);
//printf("i=%d\n",i);
/*for(int j=0;j<i;j++)
{
printf("%c",WriteContents[j]);
}
printf("\n");*/
FileCode = result;
inregs.h.ah=0x40;
inregs.x.dx=FP_OFF(WriteContents);
segregs.ds=FP_SEG(WriteContents);
inregs.x.bx=FileCode;
inregs.x.cx=i;
//printf("inregs.x.cx=%d\n",inregs.x.cx);
//int86x(INTER,&inregs,&outregs,&segregs);
intdosx(&inregs,&outregs,&segregs);
sumChar += outregs.x.ax;
printf("\n\n---The number of contents you have write to file are:%d--\n",sumChar);
//printf("Now The Ax=%d\n",outregs.x.ax);
//printf("inregs.x.bx=%d\n",inregs.x.bx);
//printf("i=%d\n",i);
}
}
//Read Contents From Existing File;
void ReadFromFile(char filename[80])
{
union REGS inregs,outregs;
struct SREGS segregs;
int result;
char ReadContents[CNum*1024];
inregs.h.ah=0x3D;
inregs.x.dx=FP_OFF(filename);
segregs.ds=FP_SEG(filename);
inregs.h.al=2;
intdosx(&inregs,&outregs,&segregs);
result = outregs.x.ax;
if(2==result)
{
printf("\n---Can not read contents from file:%s ! The file may not exist------------\n",filename);
}
else
{
//printf("\n---Now I'll Read Contents From File:%s\n",filename);
inregs.x.bx=result;
inregs.h.ah=0x3F;
//printf("%d\n",inregs.x.bx);
inregs.x.dx=FP_OFF(ReadContents);
segregs.ds=FP_SEG(ReadContents);
inregs.x.cx=1024;
intdosx(&inregs,&outregs,&segregs);
printf("-----Real Number Of Read Characters in file:%s :%d\n",filename,outregs.x.ax);
//printf("ReadContents= %s\n",ReadContents);
printf("\n-----The Contents Of File:%s Are Listed Below: \n",filename);
for(int i=0;i<outregs.x.ax;i++)
{
printf("%c",ReadContents[i]);
}
printf("\n");
/*for(int i=0;i<1024;i++)
{
printf("%c",ReadContents[i]);
if(ReadContents[i]=='\0')
{
break;
}
}*/
/*int i=0;
while(ReadContents[i]!=NULL)
{
i++;
}
printf("i=%d\n",i);*/
/*for(int j=0;j<i-2;j++)
{
printf("%c",ReadContents[j]);
}
printf("\n");
*/
}
}
//validate function one:open file:after create one file,you can validate the
//file is exist or not!
void ValidateOpenFile(char filename[80])
{
FILE *fp;
fp=fopen(filename,"r");
if(!fp)
{
printf("\n-----Open file:%s Failly!fail to validate open file function-------\n",filename);
return;
}
else
{
printf("\n-----Open file:%s Successfully!success to validate open file function----\n",filename);
}
fclose(fp);
}
//validate function two:read file :after writting contents to one file,you can
//validate the contents whether it has been written to it or not!!
void ValidateReadFile(char filename[80])
{
FILE *fp;
fp = fopen(filename,"r");
if(!fp)
{
printf("\n-------Can not read contents from file:%s It may not exist---------\n",filename);
return;
}
else
{
int count=0;
printf("\n----Read contents from file:%s successfully!The below are the contents----\n",filename);
char ch;
whi
展开阅读全文