实验四 系统实验.doc_第1页
实验四 系统实验.doc_第2页
实验四 系统实验.doc_第3页
实验四 系统实验.doc_第4页
实验四 系统实验.doc_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验四 文件系统实验一 . 目的要求 1、用高级语言编写和调试一个简单的文件系统,模拟文件管理的工作过程。从而对各种文件操作命令的实质内容和执行过程有比较深入的了解。 2、要求设计一个 n个用户的文件系统,每次用户可保存m个文件,用户在一次运行中只能打开一个文件,对文件必须设置保护措施,且至少有Create、delete、open、close、read、write等命令。二 . 实验题目1、增加 23个文件操作命令,并加以实现。(如移动读写指针,改变文件属性,更换文件名,改变文件保护级别)。2、编一个通过屏幕选择命令的文件管理系统,每屏要为用户提供足够的选择信息,不需要打入冗长的命令。 3、设计一个树型目录结构的文件系统,其根目录为 root,各分支可以是目录,也可以是文件,最后的叶子都是文件。4、根据学校各级机构,编制一文件系统。程序运行结果如下:实验过程与结果:(可写多页)1) 程序运行时,首先提示输入一个用户名(字母表示,az):2) 输入的用户名不存在时,提示;否则,打开相应用户的文件列表:3) 每个用户最多可以保存10个文件,超出时将提示出错。当进行删除文件操作时,运行结果如下:程序源代码(C+):#include#include#includeusing namespace std;struct TYPE_UFD/用户文件目录 stringFile_Name;/文件名 boolRead;/读保护码,true为可读 boolWrite;/写保护码,true为可写 boolExecute;/执行保护码,true为可执行 intLength_File;/文件长度;struct TYPE_MFD/主文件目录 stringUser_Name;/用户名 TYPE_UFD*Pointer;/用户文件目录指针;struct TYPE_AFD/打开文件目录 intFile_ID;/打开的文件号 boolRead;/读保护码,true为可读 boolWrite;/写保护码,true为可写 boolExecute;/执行保护码,true为可执行 intPointer;/读写指针;class TYPE_FILE_SYSTEM/文件系统类public: void Initial( void );/初始化 void Start( void );/开始运行文件系统private: int_Number_Users;/用户的数量 int_Number_Files;/每个用户可保存的文件数 int_MaxNumber_Open_Files;/每个用户在每次执行中打开的最大文件数 TYPE_MFD *_MFD;/主文件目录 TYPE_UFD *_UFD;/用户文件目录 TYPE_AFD *_AFD;/运行文件目录;main()/主函数 TYPE_FILE_SYSTEM FS; FS.Initial(); FS.Start(); return 0;void TYPE_FILE_SYSTEM:Initial( void ) _Number_Users = 10; _Number_Files = 10; _MaxNumber_Open_Files = 5; /UFD的初始化 _UFD = new TYPE_UFD _Number_Users*_Number_Files; / /MFD的初始化 _MFD = new TYPE_MFD _Number_Users; for( int i=0 ; i_Number_Users ; i+ ) _MFDi.Pointer = &(_UFDi*_Number_Files); / /AFD的初始化 _AFD = new TYPE_AFD _MaxNumber_Open_Files; / / _MFD0.User_Name = YANGFAN; _UFD0.File_Name = YANGFAN1.txt; _UFD0.Length_File = 10; _UFD0.Read = true; _UFD0.Write = false; _UFD0.Execute = true; _UFD1.File_Name = YANGFAN2.txt; _UFD1.Length_File = 20; _UFD1.Read = true; _UFD1.Write = false; _UFD1.Execute = false; for( i=2 ; i_Number_Files ; i+ ) _UFDi.File_Name = ; _UFDi.Length_File = -1;/表示没有文件 _UFDi.Read = false; _UFDi.Write = false; _UFDi.Execute = false; /void TYPE_FILE_SYSTEM:Start( void ) int User_ID; int i,temp_int; string temp; char choice; int Number_Open_Files;/当前用户打开的文件数 string User_Name;/当前登录的有户名 string Command;/当前用户输入的命令 TYPE_UFD *UFD;/当前登录的用户的文件目录 do/计算机开机 do/用户登录 cout User_Name; /在MFD中查找该用户 for( User_ID=0 ; User_ID_Number_Users ; User_ID+ ) if( _MFDUser_ID.User_Name = User_Name ) break; if( User_ID = _Number_Users ) cout Bad user name , please try again . endl; while( User_ID = _Number_Users ); cout Ok , welcome to login , User_Name ! endl; UFD = _MFDUser_ID.Pointer; /初始化运行文件列表 for( i=0 ; i_MaxNumber_Open_Files ; i+ ) _AFDi.File_ID = -1; Number_Open_Files = 0; / do /接收命令 cout C: User_Name ; cin Command; / if( Command = dir ) /显示用户文件列表 cout endl; cout Files of user User_Name endl; cout t Statet Lengtht File name endl; for( i=0 ; i_Number_Files ; i+ ) if( UFDi.Length_File != -1 )/该文件项不空 /打印文件状态,即保护码 cout t ; if( UFDi.Read = true ) cout R; else cout -; if( UFDi.Write = true ) cout W; else cout -; if( UFDi.Execute = true ) cout E; else cout -; /打印文件长度 cout t; cout UFDi.Length_File; /打印文件名 cout t; cout UFDi.File_Name endl; cout endl; / else if( Command = diropen ) /显示用户文件列表 cout endl; cout Opening Files of user User_Name endl; cout t Statet Open File name endl; for( i=0 ; i_MaxNumber_Open_Files ; i+ ) if( _AFDi.File_ID != -1 )/该文件项不空 /打印文件状态,即保护码 cout t ; if( _AFDi.Read = true ) cout R; else cout -; if( _AFDi.Write = true ) cout W; else cout -; if( _AFDi.Execute = true ) cout E; else cout -; /打印文件名 cout t; cout UFD_AFDi.File_ID.File_Name endl; cout endl; / else if( Command = create ) /查找是否该用户还有空的文件项,即是否还可以新建文件 for( i=0 ; i_Number_Files ; i+ ) if( UFDi.Length_File = -1 ) break; if( i = _Number_Files ) cout Error: you have already had _Number_Files files . endl; else cout Please enter the information of the new file: endl; cout temp; UFDi.File_Name = temp; / /read cout Read (y/n):; do choice = getch(); while( choice!=y & choice!=n ); if( choice = y ) UFDi.Read = true; else UFDi.Read = false; cout endl; / / /write cout Write (y/n):; do choice = getch(); while( choice!=y & choice!=n ); if( choice = y ) UFDi.Write = true; else UFDi.Write = false; cout endl; / / /execute cout Execute (y/n):; do choice = getch(); while( choice!=y & choice!=n ); if( choice = y ) UFDi.Execute = true; else UFDi.Execute = false; cout endl; / / /length cout temp_int; if( temp_int 0 ) UFDi.Length_File = temp_int; / cout Ok , the new file UFDi.File_Name is created! endl; else if( Command = delete ) cout temp; /查找要删除的文件名 for( i=0 ; i_Number_Files ; i+ ) if( (UFDi.Length_File!=-1)&(UFDi.File_Name=temp) ) break; if( i = _Number_Files )/没找到这个文件名的文件 cout Bad file name , please try again . endl; else/成功找到文件 UFDi.Length_File = -1;/删除文件 cout Ok , the file UFDi.File_Name is deleted . endl; else if( Command = open ) if( Number_Open_Files = _MaxNumber_Open_Files ) cout Error: you have already opened Number_Open_Files files. endl; else cout temp; /查找要打开的文件名 for( i=0 ; i_Number_Files ; i+ ) if( (UFDi.Length_File!=-1)&(UFDi.File_Name=temp) ) break; if( i = _Number_Files )/没找到这个文件名的文件 cout Bad file name , please try again . endl; else Number_Open_Files+; for( temp_int=0 ; temp_int_MaxNumber_Open_Files ; temp_int+ ) if( _AFDtemp_int.File_ID = -1 ) break; _AFDtemp_int.File_ID = i; _AFDtemp_int.Pointer = 0; cout Please configure the open mode : endl; / /read if( UFDi.Read = true ) cout Read (y/n):; do choice = getch(); while( choice!=y & choice!=n ); if( choice = y ) _AFDtemp_int.Read = true; else _AFDtemp_int.Read = false; cout endl; else _AFDtemp_int.Read = false; / / /write if( UFDi.Write = true ) cout Write (y/n):; do choice = getch(); while( choice!=y & choice!=n ); if( choice = y ) _AFDtemp_int.Write = true; else _AFDtemp_int.Write = false; cout endl; else _AFDtemp_int.Write = false; / / /execute if( UFDi.Execute = true ) cout Execute (y/n):; do choice = getch(); while( choice!=y & choice!=n ); if( choice = y ) _AFDtemp_int.Execute = true; else _AFDtemp_int.Execute = false; cout endl; else _AFDtemp_int.Execute; cout Ok , the file temp is open . endl; else if( Command = logout ) cout Ok , see you later , User_Name ! endl; break; else if( Command = close ) cout temp; /查找要打开的文件名 for( i=0 ; i_Number_Files ; i+ ) if( (UFDi.Length_File!=-1)&(UFDi.File_Name=temp) ) break; if( i = _Number_Files )/没找到这个文件名的文件 cout Bad file name , please try again . endl; else /找到了这个文件 for( temp_int=0 ; temp_int_MaxNumber_Open_Files ; temp_int+ ) if( _AFDtemp_int.File_ID = i ) break; if( temp_int = _MaxNumber_Open_Files )/该文件没有处于执行状态 cout The file temp isnt open . endl; else/该文件处于执行状态 _AFDtemp_int.File_ID = -1; Number_Open_Files-; cout Ok , the file temp is closed . endl; else if( Command = read ) cout temp; /查找要打开的文件名 for( i=0 ; i_Number_Files ; i+ ) if( (UFDi.Length_File!=-1)&(UFDi.File_Name=temp) ) break; if( i = _Number_Files )/没找到这个文件名的文件 cout Bad file name , please try again . endl; else /找到了这个文件 for( temp_int=0 ; temp_int_MaxNumber_Open_Files ; temp_int+ ) if( _AFDtemp_int.File_ID = i ) break; if( temp_int = _MaxNumber_Open_Files )/该文件没有处于执行状态 cout The file temp isnt open . endl; else/该文件处于执行状态 if( _AFDtemp_int.Read = true ) cout Ok , read the file temp successfully. endl; else cout Error: the open mode of the file doesnt allow you to read it . endl; else if( Command = write ) cout temp; /查找要打开的文件名 for( i=0 ; i_Number_Files ; i+ ) if( (UFDi.Le

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论