收藏 分销(赏)

操作系统课程设计报告样本.doc

上传人:人****来 文档编号:11178868 上传时间:2025-07-04 格式:DOC 页数:73 大小:2.86MB 下载积分:16 金币
下载 相关 举报
操作系统课程设计报告样本.doc_第1页
第1页 / 共73页
操作系统课程设计报告样本.doc_第2页
第2页 / 共73页


点击查看更多>>
资源描述
资料内容仅供您学习参考,如有不当之处,请联系改正或者删除。 课程设计说明书 设计名称: 操作系统课程设计      题 目: 文件访问接口设计           学生姓名: 陈小浪 专 业: 计算机科学与技术 班 级: 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
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 研究报告 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服