操作系统课程设计Linux二级文件系统设计
- 格式:docx
- 大小:56.70 KB
- 文档页数:37
《操作系统课程设计》实验报告学号:姓名:苏州大学计算机科学与技术学院2014年9月操作系统课程设计实验报告目录目录 (1)一、实验环境 (2)二、实验报告总体要求 (2)实验一编译L INUX内核 (3)实验二观察L INUX行为 (7)实验三进程间通信 (14)操作系统课程设计实验报告一、实验环境Linux平台◆硬件平台:普通PC机硬件环境。
◆操作系统:Linux环境,例如,红旗Linux或Red Hat Linux;启动管理器使用GRUB。
◆编译环境:伴随着操作系统的默认gcc环境。
◆工作源码环境:一个调试的内核源码,版本不低于2.4.20。
二、实验报告总体要求在2013年11月25日前提交实验报告。
实验报告至少要求包含以下内容:1.引言:概述本次实验所讨论的问题,工作步骤,结果,以及发现的意义。
2.问题提出:叙述本篇报告要解决什么问题。
注意不可以抄写实验要求中的表述,要用自己的话重新组织我们这里所提出的问题。
3.解决方案:叙述如何解决自己上面提出的问题,可以用小标题 3.1,3.2…等分开。
这是实验报告的关键部分,请尽量展开来写。
注意,这部分是最终课程设计的基本分的部分。
这部分不完成,本课程设计不会及格。
4.实验结果:按照自己的解决方案,有哪些结果。
结果有异常吗?能解释一下这些结果吗?同别人的结果比较过吗?注意,这部分是实验报告出彩的地方。
本课程设计要得高分,应该在这部分下功夫。
5.结束语:小结并叙述本次课程设计的经验、教训、体会、难点、收获、为解决的问题、新的疑惑等。
6.附录:加了注释的程序清单,注释行数目至少同源程序行数目比1:2,即10行源程序,至少要给出5行注释。
操作系统课程设计实验报告实验一编译Linux内核实验时间6小时实验目的认识Linux内核的组成,掌握配置、编译、安装Linux内核的步骤。
实验目标下载2.6.19或更新的Linux内核,配置该内核使其支持NTFS,并在新的内核中修改其版本为Linux NameTestKernel x.x.x,其中,Name是你的名字(汉语拼音);x.x.x是新内核的版本号,最后在你的机器上编译安装这个新内核。
《操作系统》课程设计一、课程目标知识目标:1. 让学生掌握操作系统的基本概念,包括进程、线程、内存管理、文件系统等核心知识;2. 了解操作系统的历史发展,掌握不同类型操作系统的特点及使用场景;3. 掌握操作系统的性能评价方法和常用的调度算法。
技能目标:1. 培养学生运用操作系统知识解决实际问题的能力,如分析系统性能瓶颈、优化系统资源分配等;2. 培养学生具备基本的操作系统编程能力,如进程创建、线程同步、文件操作等;3. 提高学生的团队协作能力和沟通能力,通过小组讨论和项目实践,学会共同解决问题。
情感态度价值观目标:1. 培养学生对操作系统学科的兴趣,激发学生的学习热情,使其形成积极向上的学习态度;2. 培养学生具备良好的信息素养,尊重知识产权,遵循法律法规;3. 培养学生的创新精神和批判性思维,敢于质疑、勇于探索,形成独立思考的能力。
课程性质:本课程为计算机科学与技术专业的核心课程,旨在让学生掌握操作系统的基本原理和实现方法,提高学生的系统分析和编程能力。
学生特点:学生具备一定的编程基础和计算机系统知识,具有较强的逻辑思维能力和动手实践能力。
教学要求:结合学生特点和课程性质,注重理论与实践相结合,通过案例分析和项目实践,帮助学生将所学知识内化为具体的学习成果。
在教学过程中,关注学生的学习进度和反馈,及时调整教学策略,确保课程目标的实现。
二、教学内容1. 操作系统概述:介绍操作系统的定义、发展历程、功能、类型及特点,对应教材第一章内容。
- 操作系统的起源与发展- 操作系统的功能与类型- 操作系统的主要特点2. 进程与线程:讲解进程与线程的概念、状态、调度算法,对应教材第二章内容。
- 进程与线程的定义与区别- 进程状态与转换- 进程调度算法3. 内存管理:分析内存管理的基本原理、策略和技术,对应教材第三章内容。
- 内存分配与回收策略- 虚拟内存技术- 页面置换算法4. 文件系统:介绍文件系统的基本概念、结构、存储原理,对应教材第四章内容。
操作系统实验-文件系统设计文件系统设计1.目的和要求本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。
实验要求:①在系统中用一个文件来模拟一个磁盘;②此系统至少有:Create、delete、open、close、read、write 等和部分文件属性的功能。
③实现这个文件系统。
④能实际演示这个文件系统。
基本上是进入一个界面(此界面就是该文件系统的界面)后,可以实现设计的操作要求。
2.实验内容1)设计一个10个用户的文件系统,每次用户可保存10个文件,一次运行用户可以打开5个文件。
2)程序采用二级文件目录(即设置主目录MFD)和用户文件目录(UFD)。
另外,为打开文件设置了运行文件目录(AFD)。
3)为了便于实现,对文件的读写作了简化,在执行读写命令时,只需改读写指针,并不进行实际的读写操作。
4)因系统小,文件目录的检索使用了简单的线性搜索。
5)文件保护简单使用了三位保护码:允许读写执行、对应位为1,对应位为0,则表示不允许读写、执行。
6)程序中使用的主要设计结构如下:主文件目录和用户文件目录(MFD、UFD),打开文件目录(AFD)即运行文件目录。
3.实验环境VC 6.04.实验提示1) format 格式化只写打开模拟文件,初始化超级快,初始化dinode 位图 block 位图,初始化主目录,初始化etc 目录,初始化管理员admin 目录,初始化用户xiao 目录,初始化用户passwd 文件,写入模拟硬盘文件。
2 )install 安装读写打开模拟文件,读取dinode 位图 block 位图,读取主目录,读取etc 目录,读取管理员admin 目录,读取用户xiao 目录,读取用户passwd 文件。
3 )login 登陆用户输入用户名和密码,在passwd 文件中查找是否有此用户,核对密码。
正确则登陆成功,当前目录设定到当前用户文件夹下。
Login登录结束是,登录成功输入用户名查找是否有改用户名输入密码是否密码是否正确否4 )ialloc 申请inode 空间先检测inode 位图是否加锁,是则退出。
河南城建学院《操作系统》课程设计说明书设计题目:UNIX/Linux文件系统分析专业:计算机科学与技术指导教师:邵国金耿永军陈红军班级:0614082学号:061408261姓名:贠炳森同组人:叶矿辉、陈宇计算机科学与工程系2011年1月7日前言在现在计算机更新如此迅速的时代要学好计算机软件技术,特别是操作系统的学习,不仅要努力学好课本上的基础知识,还要经常在图书馆看些有关这方面的书籍,而更重要的是要有足够的实践经验,也要注重和同学的交流,经常尝试性的做些小的操作系统,对自己技术的提升会有很大的帮助。
同时,学习计算机操作系统技术,除了需要刻苦努力外,还需要掌握软件和操作系统的原理与设计技巧。
如何学习和掌握操作系统技术的原理与实际技巧呢?除了听课和读书之外,最好的方法恐怕就是在实践中练习。
例如,自己设计一个小型操作系统,多使用操作系统,多阅读和分析操作源代码等。
但由于我们的条件和学时有限,在理论学习过程中没有给同学们提供更多的实验机会。
本操作系统课程设计,是给同学提供一个集中实验的机会。
希望同学们通过该设计加深对所学习课程的理解。
本设计是基于课程中学到的UNIX系统调用,使用操作系统环境是Red Hat Linux 9,言语开发环境是Linux的GNU C或C++。
我做的课程设计是:Linux/Unix文件系统分析。
在Linux系统下,使用与文件相关的系统调用实现对物理设备文件的读写,参照Linux系统源代码以及Grub 系统的源代码,对不同介质上的FAT格式文件系统进行分析。
要求在Linux环境下设计出C语言程序,实现以下功能:1)分析UNIX SysV/Linux系统引导记录的作用;2)分析UNIX SysV/Linux的超级块及其结构,并建立相关数据结构,通过编程实现UNIX SysV/Linux文件系统内各部分的定位。
3)至少要实现对给定i节点文件的只读访问目录一.系统环境 (3)1.1硬件环境 (3)1.2软件环境 (3)二.设计目的及要求 (3)三.总体设计 (5)四.详细设计 (6)五.调试与测试 (6)六.设计中遇到的问题及解决方法 (6)七.Linux/Unix文件系统分析源程序清单 (7)7.1 头文件 (7)7.2 示例程序 (10)八.运行结果及分析 (16)8.1 linux文件系统读取 (16)8.2 UNIX文件系统读取 (18)九.心得体会 (19)十.参考文献 (20)Linux/Unix文件系统分析一.系统环境1.1硬件环境cpu为pentium4双线程技术,频率为2.8GHZ,内存为256MB。
文件系统的设计及实现内容要求:为Linux系统设计一个简单的二级文件系统。
要求做到以下几点:1.可以实现下列几条命令:login 用户登录dir 列目录create 创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件2.列目录时要列出文件名,物理地址,保护码和文件长度。
3.源文件可以进行读写保护。
程序设计1.设计思想:采用两级目录,其中第一级对应于用户账号,第二级对应于用户账号下的文件。
2.主要数据结构:(1) i节点struct inode {struct inode *i_forw;struct inode *i_back;char i_flag;unsigned int i_ino;unsigned int i_count;unsigned short di_number;unsigned short di_mode;unsigned short di_uid;unsigned short di_gid;unsigned int di_addr [NADDR];(2) 磁盘i节点struct dinode{unsigned short di_number;unsigned short di_mode;unsigned short di_uid;unsigned short di_gid;unsigned long di_size;unsigned int di_addr [NADDR];}(3) 目录项结构struct direct{char d_name [DIRSIZ]; unsigned int d_ino;}(4) 超级块struct filsys{unsigned short s_isize; unsigned long s_fsize; unsigned int s_nfree; unsigned short s_pfree; unsigned int s_free[NICFREE]; unsigned int s_ninode; unsigned short s_pinode; unsigned int s_inode[NICINOD]; unsigned int s_rinode;char s_fmod;};(5) 用户密码struct pwd{unsigned short p_uid; unsigned short p_gid;char *password [PWDSIZ];};(6) 目录struct dir{struct direct direct[DIRNUM]; int size;};(7) 查找内存i节点的hash表struct hinode{struct inode *i_frow;};(8) 系统打开表struct file{char f_flag;unsigned int f_count;struct inode *f_inode; unsigned long f_off;};(9) 用户打开表struct user{unsigned short u_default_mode; unsigned short u_uid;unsigned short u_gid;unsigned short u_ofile[NOFILE];};3.主要函数(1) i节点内容获取函数iget()(2) i节点内容释放函数iput()(3) 目录创建函数mkdir()(4) 目录搜索函数namei()(5) 磁盘块分配函数balloc()(6) 磁盘块释放函数bfree()(7) 分配节点区函数ialloc()(8) 释放i节点区函数ifree()(9) 搜索当前目录下文件的函数iname()(10) 访问控制函数access()(11) 显示目录和文件用函数_dir()(12) 改变当前目录用函数chdir()(13) 打开文件函数open()(14) 创建文件函数create()(15) 读文件用函数read()(16) 写文件用函数write()(17) 用户登录函数login()(18) 用户退出函数logout()(19) 文件系统格式化函数format()(20) 进入文件系统函数install()(21) 关闭文件函数close()(22) 退出文件系统函数halt()(23) 文件删除函数delete()4.主程序说明BeginStep1 对磁盘进行格式化Step2 调用install(),进入文件系统Step3 调用_dir(),显示当前目录Step4 调用login(),用户注册Step5 调用mkdir()和chdir()创建目录Step6 调用creat()创建文件0Step7 分配缓冲区Step8 写文件0Step9 关闭文件0和释放缓冲Step10 调用mkdir()和chdir()创建子目录Step11 调用creat(),创建文件1Step12 分配缓冲区Step13 写文件1Step14 关闭文件1和释放缓冲Step15 调用chdir()将当前目录移到上一级Step16 调用creat(),创建文件2Step17 分配缓冲区Step18 调用write(),写文件2Step19 关闭文件2和释放缓冲Step20 调用delete(),删除文件0Step21 调用creat(),创建文件3Step22 为文件3分配缓冲区Step23 调用write(),写文件3Step24 关闭文件3并释放缓冲区Step25 调用open(),打开文件2Step26 为文件2分配缓冲Step27 写文件3后关闭文件3Step28 释放缓冲Step29 用户退出(logout)Step30 关闭(halt)End该文件系统实际是为用户提供一个解释执行相关命令的环境。
模拟一个简单二级文件管理系统设计目的:通过具体的文件存储空间的管理、文件的物理结构、目录结构和文件操作的实现,加深对文件系统内部功能和实现过程的理解。
设计内容:模拟一个简单二级文件管理系统一、实验内容描述1 实验目标本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能及内部实现.2 实验要求为DOS系统设计一个简单的二级文件系统.要求做到以下几点:①可以实现下列命令:login 用户登录dir 列文件目录create 创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件②列目录时要列出文件名、物理地址、保护码和文件长度.③源文件可以进行读写保护.二、程序主要内容1设计思路程序中要求每个用户在登陆后才可对其拥有的文件进行操作,用户对于其他用户的文件无操作权.文件操作包括浏览、创建、删除、打开、关闭、阅读、写入、修改模式.其他操作包括新建用户、帮助、用户登入、用户登出、退出系统.在程序文件夹下有个名为“file”的系统根目录,此目录下包括:一个名为“mfd”的文件,记录所有注册过的帐号及密码;用户文件,以用户名作为文件名,内容为其拥有的文件名及属性;一个名为“keiji”的文件夹.“keiji”文件夹中包括:“file.p”指针文件,记录所有已用的物理地址;一些以物理地址为名的文件,内容为文件内容.2 数据结构file结构体系统文件数据结构:fpaddrint,文件的物理地址、flengthint,文件长度、fmodeint,文件模式0.只读;1.可写;2.可读写;3.保护、fname[]char,文件名;filemode结构体文件状态数据结构:isopenint,文件当前状态,0.关闭;1.打开、modeint,文件模式0.只读;1.可写;2.可读写;3.初始化;user结构体用户信息数据结构:uname[]char,用户名、upassword[]char,用户密码;userfile结构体用户文件数据结构:uname[]char,用户名、ufile[]file,用户拥有的文件数组.代码:#include <stdio.h>#include <stdlib.h>#include <conio.h>#include <time.h>#include <string.h>#define MaxUser 100 //定义最大MDF主目录文件#define MaxDisk 512*1024 //模拟最大磁盘空间#define commandAmount 12 //对文件操作的指令数//存储空间管理有关结构体和变量char disk[MaxDisk]; //模拟512K的磁盘存储空间typedef struct distTable //磁盘块结构体{int maxlength;int start;int useFlag;distTable *next;}diskNode;diskNode *diskHead;struct fileTable //文件块结构体{char fileName[10];int strat; //文件在磁盘存储空间的起始地址int length; //文件内容长度int maxlength; //文件的最大长度char fileKind[3]; //文件的属性——读写方式struct tm *timeinfo;bool openFlag; //判断是否有进程打开了该文件//fileTable *next;};//两级目录结构体typedef struct user_file_directory //用户文件目录文件UFD {//char fileName[10];fileTable *file;user_file_directory *next;}UFD;//UFD *headFile;typedef struct master_file_directory //主文件目录MFD{char userName[10];char password[10];UFD *user;}MFD;MFD userTable[MaxUser];int used=0; //定义MFD目录中用已有的用户数//文件管理void fileCreate(char fileName[],int length,char fileKind[]); //创建文件void fileWrite(char fileName[]); //写文件void fileCat(char fileName[]); //读文件void fileRen(char fileName[],char rename[]); //重命名文件void fileFine(char fileName[]); //查询文件void fileDir(char UserName[]); //显示某一用户的所有文件void fileClose(char fileName[]); //关闭已打开的文件void fileDel(char fileName[]); //删除文件void chmod(char fileName[],char kind[]); //修改文件的读写方式int requestDist(int &startPostion,int maxLength); //磁盘分配查询void initDisk(); //初始化磁盘void freeDisk(int startPostion); //磁盘空间释放void diskShow(); //显示磁盘使用情况//用户管理void userCreate();int login();int userID=-1; //用户登录的ID号,值为-1时表示没有用户登录int main(){char order[commandAmount][10];strcpy(order[0],"create");strcpy(order[1],"rm");strcpy(order[2],"cat");strcpy(order[3],"write");strcpy(order[4],"fine");strcpy(order[5],"chmod");strcpy(order[6],"ren");strcpy(order[7],"dir");strcpy(order[8],"close");strcpy(order[9],"return");strcpy(order[10],"exit");strcpy(order[11],"df");charcommand[50],command_str1[10],command_str2[10],command_str3[5],command_str4[3];int i,k,j;int length;initDisk(); //初始化磁盘for(i=0;i<MaxUser;i++) //初始化用户UFD目录文件的头指针{userTable[i].user=(UFD *)malloc(sizeof(UFD));userTable[i].user->next=NULL;}while(1){printf("********************************************\n");printf(" 1、Creat user\n");printf(" 2、login\n");printf("********************************************\n");printf("Please chooce the function key:>");int choice;scanf("%d",&choice);if(choice==1) userCreate();else if(choice==2) userID=login();else printf("您的输入有误,请重新选择\n");while(userID!=-1){fflush(stdin);printf("———————————————————————————————————————\n");printf(" create-创建格式:create a1 1000 rw,将创建名为a1,长度为1000字节可读可写的文件\n");printf(" rm-删除格式:rm a1,将删除名为a1的文件\n");printf(" cat-查看文件内容格式:cat a1,显示a1的内容\n");printf(" write-写入格式:write a1\n");printf(" fine-查询格式:fine a1 ,将显示文件a1的属性\n");printf(" chmod-修改格式:chmod a1 r,将文件a1的权限改为只读方式\n");printf(" ren-重命名格式:ren a1 b1 ,将a1改名为b1\n");printf(" dir-显示文件格式:dir aaa,将显示aaa用户的所有文件\n");printf(" df-显示磁盘空间使用情况格式:df\n");printf(" close-关闭文件格式:close a1,将关闭文件a1\n");printf(" return-退出用户,返回登录界面\n");printf(" exit-退出程序\n");printf("————————————————————————————————————————\n");printf("please imput your command:>");gets(command);int select;for(i=0;command[i]!=' '&&command[i]!='\0';i++) //command_str1字符串存储命令的操作类型command_str1[i]=command[i];k=i;command_str1[k]='\0';for(i=0;i<commandAmount;i++){if(!strcmp(command_str1,order[i])){select=i;break;}}if(i==commandAmount){printf("您输入的命令有误,请重新输入\n");continue;}for(i=k+1,k=0;command[i]!=' '&&command[i]!='\0';i++,k++) //commmand_str2字符串存储文件名或用户名command_str2[k]=command[i];command_str2[k]='\0';k=i;switch(select){case 0:for(i=k+1,k=0;command[i]!=' ';i++,k++)command_str3[k]=command[i];command_str3[k]='\0';k=i;j=1;length=0; //初始化文件长度for(i=strlen(command_str3)-1;i>=0;i--) //把字符串转换为十进制{length+=(command_str3[i]-48)*j;j*=10;}for(i=k+1,k=0;command[i]!=' '&&command[i]!='\0';i++,k++)command_str4[k]=command[i];command_str4[k]='\0';fileCreate(command_str2,length,command_str4);break;case 1:fileDel(command_str2);break;case 2:fileCat(command_str2);break;case 3:fileWrite(command_str2);break;case 4:fileFine(command_str2);break;case 5:for(i=k+1,k=0;command[i]!=' '&&command[i]!='\0';i++,k++)command_str3[k]=command[i];command_str3[k]='\0';chmod(command_str2,command_str3);break;case 6:for(i=k+1,k=0;command[i]!='\0';i++,k++)command_str3[k]=command[i];command_str3[k]='\0';fileRen(command_str2,command_str3);break;case 7:fileDir(command_str2);break;case 8:fileClose(command_str2);break;case 9:UFD *p;for(p=userTable[userID].user->next;p!=NULL;p=p->next) //退出用户之前关闭所有打的文件if(p->file->openFlag)p->file->openFlag=false;system("cls");userID=-1;break;case 10:exit(0);break;case 11:diskShow();break;}}}return 0;}void userCreate(){char c;char userName[10];int i;if(used<MaxUser){printf("请输入用户名:");for(i=0;c=getch();i++){if(c==13) break;elseuserName[i]=c;printf("%c",c);}userName[i]='\0';for(i=0;i<used;i++){if(!strcmp(userTable[i].userName,userName)){printf("\n");printf("该用户名已存在,创建用户失败\n");system("pause");return;}}strcpy(userTable[used].userName,userName);printf("\n");printf("请输入密码:");for(i=0;c=getch();i++){if(c==13) break;elseuserTable[used].password[i]=c;printf("*");}userTable[userID].password[i]='\0';printf("\n");printf("创建用户成功\n");used++;system("pause");}else{printf("创建用户失败,用户已达到上限\n");system("pause");}fflush(stdin);}int login(){char name[10],psw[10];char c;int i,times;printf("请输入用户名:");for(i=0;c=getch();i++){if(c==13) break;elsename[i]=c;printf("%c",c);}name[i]='\0';for(i=0;i<used;i++){if(!strcmp(userTable[i].userName,name))break;}if(i==used){printf("\n您输入的用户名不存在\n");system("pause");return -1;}for(times=0;times<3;times++){memset(psw,'\0',sizeof(psw));printf("\n请输入密码:");for(i=0;c=getch();i++){if(c==13) break;elsepsw[i]=c;printf("*");}printf("\n");for(i=0;i<used;i++){if(!strcmp(psw,userTable[i].password)){printf("用户登录成功\n");system("pause");break;}}if(i==used){printf("您输入的密码错误,您还有%d次输入机会\n",2-times);if(times==2) exit(0);}else break;}fflush(stdin);return i;}void initDisk(){diskHead=(diskNode *)malloc(sizeof(diskNode));diskHead->maxlength=MaxDisk;diskHead->useFlag=0;diskHead->start=0;diskHead->next=NULL;}int requestDist(int &startPostion,int maxLength){int flag=0; //标记是否分配成功diskNode *p,*q,*temp;p=diskHead;while(p){if(p->useFlag==0&&p->maxlength>maxLength){startPostion=p->start;q=(diskNode *)malloc(sizeof(diskNode));q->start=p->start;q->maxlength=maxLength;q->useFlag=1;q->next=NULL;diskHead->start=p->start+maxLength;diskHead->maxlength=p->maxlength-maxLength;flag=1;temp=p;if(diskHead->next==NULL) diskHead->next=q;else{while(temp->next) temp=temp->next;temp->next=q;}break;}p=p->next;}return flag;}void fileCreate(char fileName[],int length,char fileKind[]){//int i,j;time_t rawtime;int startPos;UFD *fileNode,*p;for(p=userTable[userID].user->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName)){printf("文件重名,创建文件失败\n");system("pause");return;}}if(requestDist(startPos,length)){fileNode=(UFD *)malloc(sizeof(UFD));fileNode->file=(fileTable *)malloc(sizeof(fileTable)); //这一步必不可少,因为fileNode里面的指针也需要申请地址,否则fileNode->file指向会出错strcpy(fileNode->file->fileName,fileName);strcpy(fileNode->file->fileKind,fileKind);fileNode->file->maxlength=length;fileNode->file->strat=startPos;fileNode->file->openFlag=false;time(&rawtime);fileNode->file->timeinfo=localtime(&rawtime);fileNode->next=NULL;if(userTable[userID].user->next==NULL)userTable[userID].user->next=fileNode;else{p=userTable[userID].user->next;while(p->next) p=p->next;p->next=fileNode;}printf("创建文件成功\n");system("pause");}{printf("磁盘空间已满或所创建文件超出磁盘空闲容量,磁盘空间分配失败\n");system("pause");}}void freeDisk(int startPostion){diskNode *p;for(p=diskHead;p!=NULL;p=p->next){if(p->start==startPostion)break;}p->useFlag=false;}void fileDel(char fileName[]){UFD *p,*q,*temp;q=userTable[userID].user;p=q->next;while(p){if(!strcmp(p->file->fileName,fileName)) break;else{p=p->next;q=q->next;}}if(p){if(p->file->openFlag!=true) //先判断是否有进程打开该文件{temp=p;q->next=p->next;freeDisk(temp->file->strat); //磁盘空间回收free(temp);printf("文件删除成功\n");system("pause");}elseprintf("该文件已被进程打开,删除失败\n");system("pause");}}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}void fileCat(char fileName[]){int startPos,length;int k=0;UFD *p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){startPos=p->file->strat;length=p->file->length;p->file->openFlag=true; //文件打开标记printf("*****************************************************\n");for(int i=startPos;k<length;i++,k++){if(i%50==0) printf("\n"); //一行大于50个字符换行printf("%c",disk[i]);}printf("\n\n*****************************************************\n");printf("%s已被read进程打开,请用close命令将其关闭\n",p->file->fileName);system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}void fileWrite(char fileName[]){UFD *p,*q;q=userTable[userID].user;int i,k,startPos;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){if(!strcmp(p->file->fileKind,"r")) //判断文件类型{printf("该文件是只读文件,写入失败\n");system("pause");return;}char str[500];printf("please input content:\n");gets(str);startPos=p->file->strat;p->file->openFlag=true; //文件打开标记p->file->length=strlen(str);if(p->file->length>p->file->maxlength){printf("写入字符串长度大于该文件的总长度,写入失败\n");system("pause");return;}for(i=startPos,k=0;k<(int)strlen(str);i++,k++)disk[i]=str[k];printf("文件写入成功,请用close命令将该文件关闭\n");system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}void fileFine(char fileName[])UFD *p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){printf("********************************************\n");printf("文件名:%s\n",p->file->fileName);printf("文件长度:%d\n",p->file->maxlength);printf("文件在存储空间的起始地址:%d\n",p->file->strat);printf("文件类型:%s\n",p->file->fileKind);printf("创建时间:%s\n",asctime(p->file->timeinfo));printf("********************************************\n");system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}void chmod(char fileName[],char kind[]){UFD *p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){strcpy(p->file->fileKind,kind);printf("修改文件类型成功\n");system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}void fileRen(char fileName[],char name[]){UFD *p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){while(q->next){if(!strcmp(q->next->file->fileName,name)){printf("您输入的文件名已存在,重命名失败\n");system("pause");return;}q=q->next;}strcpy(p->file->fileName,name);printf("重命名成功\n");system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}void fileDir(char userName[]){UFD *p;int i,k;for(i=0;i<MaxUser;i++){if(!strcmp(userTable[i].userName,userName)){k=i;break;}}if(i==MaxUser){printf("没有找到该用户,请检查输入用户名是否正确\n");system("pause");return;}else{p=userTable[k].user->next;printf("************************************************************************* *******\n");printf("文件名文件长度文件在磁盘的起始地址文件类型创建时间\n");for(;p!=NULL;p=p->next)printf("%s %d %d %s %s",p->file->fileName, p->file->maxlength,p->file->strat,p->file->fileKind,asctime(p->file->timeinfo));printf("************************************************************************* *******\n");system("pause");}}void diskShow(){diskNode *p;int i=0,unusedDisk=0;printf("************************************************************************* **\n");printf(" 盘块号起始地址容量(bit) 是否已被使用\n");for(p=diskHead;p!=NULL;p=p->next,i++){if(p->useFlag==false) unusedDisk+=p->maxlength;printf(" %d %d %d %d \n",i,p->start,p->maxlength,p->useFlag);}printf("************************************************************************* **\n");printf("磁盘空间总容量:512*1024bit 已使用:%dbit 末使用:%dbit\n\n",MaxDisk-unusedDisk,unusedDisk);system("pause");}void fileClose(char fileName[]){UFD *p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){p->file->openFlag=false;printf("%s文件已关闭\n",p->file->fileName);system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}运行结果视图:(略)。
操作系统课程设计Linux一、教学目标本课程的教学目标是使学生掌握Linux操作系统的核心概念、原理和应用技能。
通过本课程的学习,学生将能够:1.理解操作系统的基本原理,包括进程管理、内存管理、文件系统和输入/输出系统。
2.掌握Linux操作系统的安装、配置和管理方法。
3.熟练使用Linux命令行界面,进行日常操作和系统管理。
4.掌握Linux常用命令、 shell脚本编写和系统监控工具的使用。
5.了解Linux操作系统在服务器、嵌入式设备和云计算等领域的应用。
二、教学内容本课程的教学内容分为五个部分:1.操作系统概述:介绍操作系统的定义、功能和分类,以及Linux操作系统的历史和发展。
2.进程管理:讲解进程的基本概念、进程控制、进程同步和互斥、死锁及其解决方法。
3.内存管理:介绍内存分配与回收策略、内存保护、虚拟内存和分页分段机制。
4.文件系统:讲解文件和目录结构、文件访问控制、文件系统性能优化和磁盘空间分配策略。
5.输入/输出系统:介绍I/O设备管理、中断和DMA机制、设备驱动程序和I/O调度策略。
三、教学方法本课程采用多种教学方法相结合的方式,以提高学生的学习兴趣和主动性:1.讲授法:教师讲解操作系统的核心概念和原理,引导学生掌握基本知识。
2.讨论法:学生针对实际案例和问题进行讨论,培养学生的思考和分析能力。
3.案例分析法:分析Linux操作系统的实际应用案例,使学生了解操作系统的应用场景。
4.实验法:安排实验室课时,让学生亲自动手进行系统安装、配置和调试,提高学生的实践能力。
四、教学资源本课程的教学资源包括:1.教材:选用权威、实用的Linux操作系统教材,如《Linux操作系统原理与应用》。
2.参考书:提供相关的学术论文、技术博客和在线文档,供学生拓展阅读。
3.多媒体资料:制作课件、教学视频和演示文稿,辅助学生理解和记忆。
4.实验设备:提供Linux服务器、虚拟机和实验室环境,让学生进行实际操作。
v .. . ..
. . . 资 料. .
操作系统(2014年秋季学期)
实 验 报 告
系别:计算机科学与技术 班级:信安12-1班 姓名:*** 学号:
实验名称:进程调度
NORTH CHINA UNIVERSITY OF TECHNOLOGY
2022-4-26 2/17
.
Word 资料
NORTH CHINA UNIVERSITY OF TECHNOLOGY
2022-4-26 4/17
.
Word 资料
NORTH CHINA UNIVERSITY OF TECHNOLOGY
.
Word 资料
NORTH CHINA UNIVERSITY OF TECHNOLOGY
.
Word 资料
NORTH CHINA UNIVERSITY OF TECHNOLOGY
}
五、编译过程截图
(下面是一个例子,换上你自己的图)
六、测试用例
(下面是一个例子,换上你自己的)
文字叙述一下测试过程的实例。
如先创建用户***、再产生文件****、再打开文件****,再写入内容********,再退出,再打开用户***,再将文件读出,读出的内容应该是*******。
等等。
六、实验结果
(下面是一个例子,换上你自己的图,给出根据测试用例的截图)。
操作系统课程设计报告专业:计算机信息处理学号:08201328姓名:杨馨雨提交日期:2011-7-14【设计目的】1.课程设计目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。
2.结合数据结构、程序设计、计算机原理等课程的知识,设计一个二级文件系统,进一步理解操作系统。
3.通过对实际问题的分析、设计、编程实现,提高学生实际应用、编程的能力【设计内容】1、delete删除文件2、open打开文件3、close关闭文件4、write写文件【实验环境】Windows7系统Visualstudio2010【相关知识综述】本文件系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件。
另外,为了简便文件系统未考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容。
首先应确定文件系统的数据结构:主目录、子目录及活动文件等。
主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。
用户创建的文件,可以编号存储于磁盘上。
如:file0,file1,file2…并以编号作为物理地址,在目录中进行登记。
【设计思路】1主要数据结构#define MAXNAME25/*thelargestlengthofmfdname,ufdname,filename*/#define MAXCHILD50/*thelargestchild每个用户名下最多有50个文件*/#define MAX(MAXCHILD*MAXCHILD)/*thesizeoffpaddrno*/typedefstruct/*thestructureofOSFILE定义主文件*/{int fpaddr;/*filephysicaladdress*/int flength;/*filelength*/int fmode;/*filemode:0-ReadOnly;1-WriteOnly;2-ReadandWrite;3-Protect;*/char fname[MAXNAME];/*filename*/}OSFILE;typedefstruct/*thestructureofOSUFD定义用户文件目录*/{char ufdname[MAXNAME];/*ufdname*/OSFILEufdfile[MAXCHILD];/*ufdownfile*/}OSUFD;typedefstruct/*thestructureofOSUFD'LOGIN定义登陆*/{char ufdname[MAXNAME];/*ufdname*/char ufdpword[8];/*ufdpassword*/}OSUFD_LOGIN;typedefstruct/*fileopenmode定义操作方式*/{int ifopen;/*ifopen:0-close,1-open*/int openmode;/*0-readonly,1-writeonly,2-readandwrite,3-initial*/}OSUFD_OPENMODE;2主要函数void LoginF();/*LOGINFileSystem*/void DirF();/*DirFileSystem*/void CreateF();/*CreateFile*/void DeleteF();/*DeleteFile*/void ModifyFM();/*ModifyFileMode*/void OpenF();/*OpenFile*/void CloseF();/*CloseFile*/void ReadF();/*ReadFile*/void WriteF();/*WriteFile*/void QuitF();/*QuitFileSystem*/void CdF();/*ChangeDir*/void help();【主要程序段】1Delete函数voidDeleteF()/*DeleteFile*/{charfname[MAXNAME],str[50],str1[50];inti,k,j;intfpaddrno1;if(strcmp(strupr(ltrim(rtrim(dirname))),"")==0)/*无法删除主目录的文件*/{printf("\.\n");wgetchar=1;}if(strcmp(strupr(dirname),strupr(username))!=0)/*无法删除非自己目录的文件*/{printf("\.\n");wgetchar=1;}else{printf("\nPleaseinputFileName:");gets(fname);fopen==1)/*文件打开时无法删除*/{printf("\nError.\'%s\'.\n",fname);wgetchar=1;}else{if(ufd[k]->ufdfile[i].fmode==3)/*被保护的文件无法删除*/{printf("\nError.\'%s\'.\n",fname);wgetchar=1;}else{fpaddrno1=ufd[k]->ufdfile[i].fpaddr;xt");remove(str);n",fname);wgetchar=1;}}}else'%s\'dosenotexist.\n",fname);wgetchar=1;}}}2Open函数voidOpenF()/*OpenFile*/{charfname[MAXNAME];inti,k,j;if(strcmp(strupr(dirname),strupr(username))!=0)/*在自己的目录里才能打开*/{printf("\.\n");wgetchar=1;}else{k=ExistD(username);for(j=0;j<fcount[k];j++){printf("%15s",ufd[k]->ufdfile[j].fname);}printf("\nPleaseinputFileName:");gets(fname);fopen==1)'%s\'isinopenstatus.\n",fname);wgetchar=1;}else{ifopen[k][i].ifopen=1;mode==0)/*根据文件的模式设置打开模式*/{ifopen[k][i].openmode=0;}elseif(ufd[k]->ufdfile[i].fmode==1){ifopen[k][i].openmode=1;}elseif(ufd[k]->ufdfile[i].fmode==2){ifopen[k][i].openmode=2;}elseifopen[k][i].openmode=3;printf("\n\'%s\'isopenedsuccessfully\n",fname);wgetchar=1;}}else'%s\'dosenotexist.\n",fname);wgetchar=1;}}}3Close函数voidCloseF()/*CloseFile*/{charfname[MAXNAME];inti,k,j;if(strcmp(strupr(dirname),strupr(username))!=0)/*不在自己的目录里没法进行*/{printf("\.\n");wgetchar=1;}else{k=ExistD(username);for(j=0;j<fcount[k];j++)/*列出已经打开的文件*/ {if(ifopen[k][j].ifopen==1)name);}printf("\nPleaseinputFileName:");gets(fname);fopen=0;/*关闭文件*/printf("\n\'%s\'closedsuccessfully\n",fname);wgetchar=1;}else'%s\'dosenotexist.\n",fname);wgetchar=1;}}}4Write函数voidWriteF()/*WriteFile*/{inti,k,n=0;intlength;charfname[MAXNAME],values[1000];charstr[255],str1[255],c;if(strcmp(strupr(ltrim(rtrim(dirname))),"")==0)n");wgetchar=1;return;}printf("\nCaution:Openfilefirst\n");printf("OpenedFile(s)List:\n");k=ExistD(dirname);fopen==1)name);n++;}if((n%4==0)&&(n!=0))printf("\n");}printf("\n%dfilesopenned.\n",n);if(n==0)wgetchar=1;fopen==1)penmode==1)||(ifopen[k][i].o penmode==2))paddr,str,10);xt");fp_file=fopen(str,"ab");length=ufd[k]->ufdfile[i].flengt h+length;n",ufd[k]->ufdfile[i].flength);printf("\n\nYouhavewritefilesuccessfully!!");fclose(fp_file);wgetchar=0;}elseif(ifopen[k][i].openmode==0)'%s\'\'twrite.\n",fname) ;wgetchar=1;}else'%s\'\'twrite.\n",fname);wgetchar=1;}}else'%s\'\n",fname);wgetchar=1;}}else'%s\'doesnotexist.\n",fname);wgetchar=1;}}}【程序流程设计】1总的功能结构图:2部分子模块程序流程图(1)打开命令的程序流程图:(2)关闭命令的程序流程图:(3)写命令的程序流程图:(4)删除命令的程序流程图:【测试结果】1删除文件2打开的文件不能删除3打开文件,其中已经打开的文件不能再次打开3关闭文件4写文件,其中只有打开了文件才能写入5写文件6只读文件和保护文件不能写入7其他函数【参考文献】计算机操作系统,西安电子科技大学出版社,方敏主编, 【源程序清单】#include""#include""#include""#include""#define MAXNAME25/*thelargestlengthofmfdname,ufdname,filename*/#define MAXCHILD50/*thelargestchild每个用户名下最多有50个文件*/#define MAX(MAXCHILD*MAXCHILD)/*thesizeoffpaddrno*/typedefstruct/*thestructureofOSFILE定义主文件*/{int fpaddr;/*filephysicaladdress*/int flength;/*filelength*/int fmode;/*filemode:0-ReadOnly;1-WriteOnly;2-ReadandWrite;3-Protect;*/ char fname[MAXNAME];/*filename*/}OSFILE;typedefstruct/*thestructureofOSUFD定义用户文件目录*/{char ufdname[MAXNAME];/*ufdname*/OSFILEufdfile[MAXCHILD];/*ufdownfile*/}OSUFD;typedefstruct/*thestructureofOSUFD'LOGIN定义登陆*/char ufdname[MAXNAME];/*ufdname*/char ufdpword[8];/*ufdpassword*/}OSUFD_LOGIN;typedefstruct/*fileopenmode定义操作方式*/{int ifopen;/*ifopen:0-close,1-open*/int openmode;/*0-readonly,1-writeonly,2-readandwrite,3-protect*/}OSUFD_OPENMODE;void LoginF();/*LOGINFileSystem*/void DirF();/*DirFileSystem*/void CreateF();/*CreateFile*/void DeleteF();/*DeleteFile*/void ModifyFM();/*ModifyFileMode*/void OpenF();/*OpenFile*/void CloseF();/*CloseFile*/void ReadF();/*ReadFile*/void WriteF();/*WriteFile*/void QuitF();/*QuitFileSystem*/void CdF();/*ChangeDir*/void help();char*rtrim(char*str);/*removethetrailingblanks.*/char*ltrim(char*str);/*removetheheadingblanks.*/void InputPW(char*password);/*inputpassword,use'*'replace*/int ExistD(char*dirname);/*WhetherDirNameExist,Exist-i,NotExist-0*/int WriteF1();/*writefile*/int ExistF(char*filename);/*WhetherFileNameExist,Exist-i,NotExist-0*/void SetPANo(int RorW);/*Setphysicaladdressnum*/int FindPANo();/*findoutphysicaladdressnum*/int ucount=0;/*thecountofmfd'sufds用户数*/int fcount[MAXCHILD];/*thecountofufd'sfiles子文件数*/int loginsuc=0;/*whetherloginsuccessfully登陆成功*/char username[MAXNAME];/*recordloginuser'sname22用户名*/char dirname[MAXNAME];/*recordcurrentdirectory使用的用户目录*/int fpaddrno[MAX];/*recordfilephysicaladdressnum物理地址号,存放自己所创建的所有文件的地址*/int wgetchar;/*whethergetchar()*/OSUFD*ufd[MAXCHILD];/*ufdandufdownfiles*/OSUFD_LOGINufd_lp;;QuitF();exit(0);break;case10:clrscr();choiceend=1;break;case11:CdF();choiceend=1;break;;}char*rtrim(char*str)/*removethetrailingblanks.去掉登陆用户名的尾空格*/int n=strlen(str)-1;while(n>=0){if(*(str+n)!=''){*(str+n+1)='\0';break;}else n--;}if(n<0)str[0]='\0';return str;}char*ltrim(char*str)/*removetheheadingblanks.去掉登陆用户名的头空格*/ {strrev(str);name),strupr(filename))==0){exist=1;break;}if(exist)return(i);elsereturn(-1);}int FindPANo()/*findoutphysicaladdressnum*/{int i;for(i=0;i<MAX;i++)if(fpaddrno[i]==0){fpaddrno[i]=1;break;}if(i<MAX)return(i);elsereturn(-1);}int WriteF1()/*writefile*/{int length=0;char c;printf("Pleaseinputtext(\'#\'standsforend):\n");while((c=getchar())!='#'){fprintf(fp_file,"%c",c);if(c!='\n')length++;}fprintf(fp_file,"\n");fclose(fp_file);return(length);}void LoginF()/*LOGINFileSystem登陆函数*/{char loginame[MAXNAME],loginpw[9],logincpw[9],str[50];xt");ufd[j]=(OSUFD*)malloc(sizeof(OSUFD));fopen=0;ifopen[j][i].openmode=4;}fclose(fp_ufd);}fclose(fp_mfd);ucount=j;SetPANo(0);printf("\n\nLoginsuccessful!WelcometothisFileSystem\n\n");loginsuc=1;return;}else xt");if((fp_ufd=fopen(str,"rb"))==NULL){fp_ufd=fopen(str,"wb");fclose(fp_ufd);}fp_mfd=fopen("d:\\osfile\\","rb");for(j=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!=0;j++){strcpy(str,"d:\\osfile\\");strcat(str,;strcat(str,".txt");ufd[j]=(OSUFD*)malloc(sizeof(OSUFD));strcpy(ufd[j]->ufdname,strupr);fp_ufd=fopen(str,"rb");for(i=0;fread(&ufd[j]->ufdfile[i],sizeof(OSFILE),1,fp_ufd)!=0;i++,fcount[j]++)fopen =0;ifopen[j][i].openmode=4;}fclose(fp_ufd);}fclose(fp_mfd);ucount=j;SetPANo(0);printf("\n\nLoginSuccessful!WelcometothisSystem\n\n");loginsuc=1;return;}else");getch();clrscr();printf("\n%14s%16s%14s%10s%18s\n","FileName","FileAddress","FileLength","Type","Fil eMode");}itoa(ufd[j]->ufdfile[i].fpaddr,str,10);mode==0)strcpy(sfmode,"ReadOnly");elseif(ufd[j]->ufdfile[i].fmode==1)strcpy(sfmode,"WriteOnly");elseif(ufd[j]->ufdfile[i].fmode==2)strcpy(sfmode,"ReadAndWrite");else strcpy(sfmode,"Protect");printf("%14s%16s%14d%10s%18s\n",ufd[j]->ufdfile[i].fname,sfpaddr,ufd[j]->ufdfile[i] .flength,"<FILE>",sfmode);}printf("\n%3dfile(s)\n",fcount[j]);}else.");getch();clrscr();printf("\n%14s%18s%8s\n","DirName","OwnFileCount","Type");}printf("%14s%18d%8s\n",ufd[i]->ufdname,fcount[i],"<UFD>");count=count+fcount[i];}printf("\n%3ddir(s),%5dfile(s)\n",ucount,count);}}void CreateF()/*CreateFile*/{int fpaddrno,flag=1,i;char fname[MAXNAME],str[50],str1[50],a[25];char fmode[25];if(strcmp(strupr(dirname),strupr(username))!=0)n");wgetchar=1;}else{printf("\nPleaseinputFileName:");gets(fname);ltrim(rtrim(fname));if(ExistF(fname)>=0){printf("\\'%s\'hasalreadyexisted.\n",fname);wgetchar=1;}else{printf("PleaseinputFileMode(0-ReadOnly,1-WriteOnly,2-ReadandWrite,3-Protect):");gets(fmode);ltrim(rtrim(fmode));if((strcmp(fmode,"0")==0)||(strcmp(fmode,"1")==0)||(strcmp(fmode,"2")==0)||(strcmp( fmode,"3")==0)){fpaddrno=FindPANo();if(fpaddrno>=0)name,fname);paddr=fpaddrno;ufd[i]->ufdfile[fcount[i]].fmode=atoi(fmode);ifopen[i][fcount[i]].ifopen=0;ifopen[i][fcount[i]].openmode=4;strcpy(str,"d:\\osfile\\file\\file");itoa(fpaddrno,str1,10);strcat(str,str1);strcat(str,".txt");fp_file=fopen(str,"wb");fclose(fp_file);fcount[i]++;while(flag){printf("Inputtextnow(Y/N):");gets(a);ltrim(rtrim(a));ufd[i]->ufdfile[fcount[i]-1].flength=0;if(strcmp(strupr(a),"Y")==0){fp_file=fopen(str,"wb+");length=WriteF1();flag=0;}elseif(strcmp(strupr(a),"N")==0){flag=0;wgetchar=1;}}printf("\n\'%s\'hasbeencreatedsuccessfully!\n",fname);}else{printf("\nFail!.\n");wgetchar=1;}}else{printf("\\'sRangeis0-3\n");wgetchar=1;}}}}void DeleteF()/*DeleteFile*/{char fname[MAXNAME],str[50],str1[50];int i,k,j;int fpaddrno1;if(strcmp(strupr(ltrim(rtrim(dirname))),"")==0)/*无法删除主目录的文件*/{printf("\.\n");wgetchar=1;}if(strcmp(strupr(dirname),strupr(username))!=0)/*无法删除非自己目录的文件*/ {printf("\.\n");wgetchar=1;}else{printf("\nPleaseinputFileName:");gets(fname);fopen==1)/*文件打开时无法删除*/{printf("\nError.\'%s\'.\n",fname);wgetchar=1;}else{if(ufd[k]->ufdfile[i].fmode==3)/*被保护的文件无法删除*/{printf("\nError.\'%s\'.\n",fname);wgetchar=1;}else{fpaddrno1=ufd[k]->ufdfile[i].fpaddr;xt");remove(str);n",fname);wgetchar=1;}}}else'%s\'dosenotexist.\n",fname);wgetchar=1;}}}void ModifyFM()/*ModifyFileMode*/{char fname[MAXNAME],str[50];int i,k;char fmode[25];/*whetherdelete*/if(strcmp(strupr(dirname),strupr(username))!=0){printf("\.\n");wgetchar=1;}else{printf("\nPleaseinputFileName:");gets(fname);ltrim(rtrim(fname));i=ExistF(fname);if(i>=0){k=ExistD(username);if(ifopen[k][i].ifopen==1){printf("\nError.\'%s\'.\n",fname);wgetchar=1;}else{if(ufd[k]->ufdfile[i].fmode==0)strcpy(str,"readonly");/*FileMode*/elseif(ufd[k]->ufdfile[i].fmode==1)strcpy(str,"writeonly");elseif(ufd[k]->ufdfile[i].fmode==2)strcpy(str,"readandwrite");else strcpy(str,"Protect");printf("\'%s\'filemodeis%s.\n",fname,strupr(str));printf("Modifyto(0-readonly,1-writeonly,2-readandwrite,3-Protect):");gets(fmode);ltrim(rtrim(fmode));if(strcmp(fmode,"0")==0){ufd[k]->ufdfile[i].fmode=0;printf("\n\'%s\'hasbeenmodifiedtoREADONLYmodesuccessfully.\n",fname);wgetchar=1;}elseif(strcmp(fmode,"1")==0){ufd[k]->ufdfile[i].fmode=1;printf("\n\'%s\'hasbeenmodifiedtoWRITEONLYmodesuccessfully.\n",fname);wgetchar=1;}elseif(strcmp(fmode,"2")==0){ufd[k]->ufdfile[i].fmode=2;printf("\n\'%s\'hasbeenmodifiedtoREADANDWRITEmodesuccessfully.\n",fname);wgetchar=1;}elseif(strcmp(fmode,"3")==0){ufd[k]->ufdfile[i].fmode=3;printf("\n\'%s\'hasbeenmodifiedtoFORBIDmodesuccessfully.\n",fname);wgetchar=1;}else{printf("\nError.\'%s\'isnotmodified.\n",fname);wgetchar=1;}}}else{printf("\nError.\'%s\'dosenotexist.\n",fname);wgetchar=1;}}}void OpenF()/*OpenFile*/{char fname[MAXNAME];int i,k,j;if(strcmp(strupr(dirname),strupr(username))!=0)/*在自己的目录里才能打开*/ {printf("\.\n");wgetchar=1;}else{k=ExistD(username);for(j=0;j<fcount[k];j++){printf("%15s",ufd[k]->ufdfile[j].fname);}printf("\nPleaseinputFileName:");gets(fname);fopen==1)'%s\'isinopenstatus.\n",fname);wgetchar=1;}else{ifopen[k][i].ifopen=1;mode==0)/*根据文件的模式设置打开模式*/{ifopen[k][i].openmode=0;}elseif(ufd[k]->ufdfile[i].fmode==1){ifopen[k][i].openmode=1;}elseif(ufd[k]->ufdfile[i].fmode==2){ifopen[k][i].openmode=2;}else ifopen[k][i].openmode=3;printf("\n\'%s\'isopenedsuccessfully\n",fname);wgetchar=1;}}else'%s\'dosenotexist.\n",fname);wgetchar=1;}}}void CloseF()/*CloseFile*/{char fname[MAXNAME];int i,k,j;if(strcmp(strupr(dirname),strupr(username))!=0)/*不在自己的目录里没法进行*/ {printf("\.\n");wgetchar=1;}else{k=ExistD(username);for(j=0;j<fcount[k];j++)/*列出已经打开的文件*/{if(ifopen[k][j].ifopen==1)name);}printf("\nPleaseinputFileName:");gets(fname);fopen=0;'%s\'dosenotexist.\n",fname);wgetchar=1;}}}void ReadF()/*ReadFile*/{int i,k,n=0;char fname[MAXNAME];char str[255],str1[255],c;if(strcmp(strupr(ltrim(rtrim(dirname))),"")==0)n");wgetchar=1;return;}printf("\nCaution:Openfilefirst\n");printf("OpenedFile(s)List:\n");k=ExistD(dirname);for(i=0;i<fcount[k];i++){if(ifopen[k][i].ifopen==1)name);n++;}if((n%4==0)&&(n!=0))printf("\n");}printf("\n%dfilesopenned.\n",n);if(n==0)wgetchar=1;fopen==1){if((ifopen[k][i].openmode==0)||(ifopen[k][i].openmode==2))paddr,str,10);strcpy(str1,"file");strcat(str1,str);strcpy(str,"d:\\osfile\\file\\");strcat(str,str1);strcat(str,".txt");fp_file=fopen(str,"rb");fseek(fp_file,0,0);printf("\nThetextis:\n\n");printf("");while(fscanf(fp_file,"%c",&c)!=EOF)if(c=='\n')printf("\n");else printf("%c",c);printf("\n\n%dLength.\n",ufd[k]->ufdfile[i].flength);fclose(fp_file);wgetchar=1;}elseif(ifopen[k][i].openmode==1)'%s\'\'tread.\n",fname);wgetchar=1;}else'%s\'\'tread.\n",fname);wgetchar=1;}}else{printf("\nError.\'%s\'\n",fname);wgetchar=1;}}else{printf("\nError.\'%s\'doesnotexist.\n",fname);wgetchar=1;}}}void WriteF()/*WriteFile*/{int i,k,n=0;int length;char fname[MAXNAME],values[1000];char str[255],str1[255],c;if(strcmp(strupr(ltrim(rtrim(dirname))),"")==0)n");wgetchar=1;return;}printf("\nCaution:Openfilefirst\n");printf("OpenedFile(s)List:\n");k=ExistD(dirname);fopen==1)name);n++;}if((n%4==0)&&(n!=0))printf("\n");}printf("\n%dfilesopenned.\n",n);if(n==0)wgetchar=1;fopen==1)penmode==1)||(ifopen[k][i].openmode==2))paddr,str,10);x t");fp_file=fopen(str,"ab");length=ufd[k]->ufdfile[i].flength+length;n",ufd[k]->ufdfile [i].flength);printf("\n\nYouhavewritefilesuccessfully!!");fclose(fp_file);wgetchar=0;}elseif(ifopen[k][i].openmode==0)'%s\'\'twrite.\n",fname);wgetchar=1;}else'%s\'\'twrite.\n",fname);wgetchar=1;}}else'%s\'\n",fname);wgetchar=1;}}else'%s\'doesnotexist.\n",fname);wgetchar=1;}}}void QuitF()/*QuitFileSystem*/{int i,j;char str[50];SetPANo(1);if(fp_mfd!=NULL)fclose(fp_mfd);xt");fp_ufd=fopen(str,"wb");fclose(fp_ufd);fp_ufd=fopen(str,"ab");for(i=0;i<fcount[j];i++)fwrite(&ufd[j]->ufdfile[i],sizeof(OSFILE),1,fp_ufd);fclose(fp_ufd);}}void CdF()/*ExchangeDir更换用户*/{char dname[MAXNAME];printf("\nPleaseinputDirName:");gets(dname);ltrim(rtrim(dname));if(ExistD(dname)>=0)strcpy(dirname,strupr(dname));elseif(strcmp(strupr(dname),"CD..")==0)strcpy(ltrim(rtrim(dirname)),"");else printf("\nError.\'%s\'doesnotexist.\n",dname);}void help(void){printf("\nTheCommandList\n");printf("\nCdAttribCreatewriteReadOpenClsDeleteExitClose\n");}【设计总结】UNIX系统中的文件系统是人们最感兴趣的,也是最成功的一部分。
操作系统课程设计Linux二级文件系
统设计
操作系统课程设计报告专业:软件工程
学号:
姓名:马
提交日期: /1/10
【设计目的】
1、经过一个简单多用户文件系统的设计,加深理解文件系统的内
部功能和内部实现
2、结合数据结构、程序设计、计算机原理等课程的知识,设计一
个二级文件系统,进一步理解操作系统
3、经过对实际问题的分析、设计、编程实现,提高学生实际应用、编程的能力
【设计内容】
为Linux系统设计一个简单的二级文件系统。
要求做到以下几点:
1.能够实现下列几条命令:
login 用户登录
dir 列目录
create 创立文件
delete 删除文件
open 打开文件
close 关闭文件
read 读文件
write 写文件
cd 进出目录
2.列目录时要列出文件名,物理地址,保护码和文件长度
3.源文件能够进行读写保护
【实验环境】
C++
DevCpp
【设计思路】
本文件系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件。
另外,为了简便文件系统未考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容。
首先应确定文件系统的数据结构:主目录、子目录及活动文件等。
主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。
用户创立的文件,能够编号存储于磁盘上。
如:file0,file1,file2…并以编号作为物理地址,在目录中进行登记。
结构体:
typedef struct /*the structure of OSFILE*/
{
int fpaddr; /*file physical address*/ int flength; /*file length*/
int fmode; /*file mode:0-Read Only;1-Write Only;2-Read and Write; 3-Protect;*/
char fname[MAXNAME]; /*file name*/
} OSFILE; //存放重要信息
typedef struct /*the structure of OSUFD*/
{
char ufdname[MAXNAME]; /*ufd name*/
OSFILE ufdfile[MAXCHILD]; /*ufd own file*/
}OSUFD; //用户下面的文件
typedef struct /*the structure of OSUFD'LOGIN*/
{
char ufdname[MAXNAME]; /*ufd name*/
char ufdpword[8]; /*ufd password*/
} OSUFD_LOGIN;
typedef struct /*file open mode*/
{
int ifopen; /*ifopen:0-close,1-open*/
int openmode; /*0-read only,1-write only,2-read and write,3-initial*/
}OSUFD_OPENMODE;
主要的函数说明:
void LoginF(); /*LOGIN FileSystem用户登录*/
void DirF(); /*Dir FileSystem列目录*/
void CdF(); /*Change Dir改变目录*/
void CreateF(); /*Create File创立文件*/
void DeleteF(); /*Delete File删除文件*/
void ModifyFM(); /*Modify FileMode修改*/
void OpenF(); /*Open File打开文件*/
void CloseF(); /*Close File关闭文件*/
void ReadF(); /*Read File读文件*/
void WriteF(); /*Write File写文件*/
void QuitF(); /*Quit FileSystem离开文件系统*/
void help();
其它重要函数:
void clrscr() //清屏
int ExistD(char *dirname) /*Whether DirName Exist,Exist-i,Not Exist-0*/
int ExistF(char *filename) /*Whether FileName Exist,Exist-i,Not Exist-0*/。