




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实验四 文件系统实验一 .目的要求 1、用高级语言编写和调试一个简单的文件系统,模拟文件管理的工作过程。从而对各种文件操作命令的实质内容和执行过程有比较深入的了解。 2、要求设计一个 n个用户的文件系统,每次用户可保存m个文件,用户在一次运行中只能打开一个文件,对文件必须设置保护措施,且至少有Create、delete、open、close、read、write等命令。二 .例题: 1、设计一个10个用户的文件系统,每次用户可保存10个文件,一次运行用户可以打开5个文件。2、程序采用二级文件目录(即设置主目录MFD)和用户文件目录(UED)。另外,为打开文件设置了运行文件目录(AF
2、D)。3、为了便于实现,对文件的读写作了简化,在执行读写命令时,只需改读写指针,并不进行实际的读写操作。4、算法与框图: 因系统小,文件目录的检索使用了简单的线性搜索。 文件保护简单使用了三位保护码:允许读写执行、对应位为 1,对应位为0,则表示不允许读写、执行。 程序中使用的主要设计结构如下: 主文件目录和用户文件目录( MFD、UFD) 打开文件目录( AFD)(即运行文件目录)M D FU F DA F D用户名文件名打开文件名文件目录指针保护码打开保护码用户名文件长度读写指针文件目录指针文件名··文件系统算法的流程图如下:三
3、.实验题: 1、增加 23个文件操作命令,并加以实现。(如移动读写指针,改变文件属性,更换文件名,改变文件保护级别)。#include<iostream>#include<string>#include<conio.h>using namespace std;struct TYPE_UFD stringFile_Name; boolRead; boolWrite; boolExecute; intLength_File;struct TYPE_MFD stringUser_Name; TYPE_UFD*Pointer;struct TYPE_AF
4、D intFile_ID; boolRead; boolWrite; boolExecute; intPointer;class TYPE_FILE_SYSTEMpublic: 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;void TYPE_FILE_SYSTEM:Initial( void ) _Number_Users
5、= 10; _Number_Files = 10; _MaxNumber_Open_Files = 5; _UFD = new TYPE_UFD _Number_Users*_Number_Files; _MFD = new TYPE_MFD _Number_Users; int i=0; for( i=0 ; i<_Number_Users ; i+ ) _MFDi.Pointer = &(_UFDi*_Number_Files); _AFD = new TYPE_AFD _MaxNumber_Open_Files; _MFD0.User_Name = "chaoch
6、ao" _UFD0.File_Name = "chaochao1.txt" _UFD0.Length_File = 10; _UFD0.Read = true; _UFD0.Write = false; _UFD0.Execute = true; _UFD1.File_Name = "chaochao2.txt" _UFD1.Length_File = 20; _UFD1.Read = true; _UFD1.Write = false; _UFD1.Execute = false; for( i=2 ; i<_Number_Files
7、; 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
8、<< "User name:" cin >> User_Name; 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 ); co
9、ut << "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 << ">" ;
10、 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<_Nu
11、mber_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"
12、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 " <&
13、lt; 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 &
14、lt;< "-" 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;
15、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
16、 information of the new file:" << endl; cout << "File name : " cin >> temp; UFDi.File_Name = temp; cout << "Read (y/n):" do choice = getch(); while( choice!='y' && choice!='n' ); if( choice = 'y' ) UFDi.Read = true; els
17、e UFDi.Read = false; cout << endl; cout << "Write (y/n):" do choice = getch(); while( choice!='y' && choice!='n' ); if( choice = 'y' ) UFDi.Write = true; else UFDi.Write = false; cout << endl; cout << "Execute (y/n):" do cho
18、ice = getch(); while( choice!='y' && choice!='n' ); if( choice = 'y' ) UFDi.Execute = true; else UFDi.Execute = false; cout << endl; cout << "Length :" cin >> temp_int; if( temp_int > 0 ) UFDi.Length_File = temp_int; cout << "
19、Ok , the new file " << UFDi.File_Name << " is created!" << endl; else if( Command = "delete" ) cout << "Please enter the file name :" cin >> temp; for( i=0 ; i<_Number_Files ; i+ ) if( (UFDi.Length_File!=-1)&&(UFDi.File_Name
20、=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(
21、 Number_Open_Files = _MaxNumber_Open_Files ) cout << "Error: you have already opened " << Number_Open_Files << " files." << endl; else cout << "Please enter the file name :" cin >> temp; for( i=0 ; i<_Number_Files ; i+ ) if( (UFDi.
22、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.
23、File_ID = i; _AFDtemp_int.Pointer = 0; cout << "Please configure the open mode :" << endl; if( UFDi.Read = true ) cout << "Read (y/n):" do choice = getch(); while( choice!='y' && choice!='n' ); if( choice = 'y' ) _AFDtemp_int.Read
24、 = true; else _AFDtemp_int.Read = false; cout << endl; else _AFDtemp_int.Read = false; if( UFDi.Write = true ) cout << "Write (y/n):" do choice = getch(); while( choice!='y' && choice!='n' ); if( choice = 'y' ) _AFDtemp_int.Write = true; else _AF
25、Dtemp_int.Write = false; cout << endl; else _AFDtemp_int.Write = false; 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
26、.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 << " !" &l
27、t;< endl; break; else if( Command = "close" ) cout << "Please enter the file name :" cin >> 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 , ple
28、ase 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 << " isn't open ." << endl; else _AFDte
29、mp_int.File_ID = -1; Number_Open_Files-; cout << "Ok , the file " << temp << " is closed ." << endl; else if( Command = "read" ) cout << "Please enter the file name :" cin >> temp; for( i=0 ; i<_Number_Files ; i+ ) if( (U
30、FDi.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
31、_Files ) cout << "The file " << temp << " isn't open ." << endl; else if( _AFDtemp_int.Read = true ) cout << "Ok , read the file " << temp << " successfully." << endl; else cout << "Error: the open
32、 mode of the file doesn't allow you to read it ." << endl; else if( Command = "write" ) cout << "Please enter the file name :" cin >> temp; for( i=0 ; i<_Number_Files ; i+ ) if( (UFDi.Length_File!=-1)&&(UFDi.File_Name=temp) ) break; if( i = _
33、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 << " isn't open ." << endl; else if( _AFDtemp_int.Write = true ) cout << "Ok , write the file " << temp << " successfully." << endl; else cout << "Error: the open mode of the file doesn't a
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 采购管理的内容与目标
- 编制说明-番茄日光温室全产业链管理技术规范
- 高考数学复习讲义:平面向量
- 乙肝患者护理教学要点
- 《活法1》名著导读好书
- 细胞中的能量通货
- 橡胶厂消防课件
- 护理侵权责任法解析
- 心理个案护理
- 排气护理备课
- 浙江省衢州市(2024年-2025年小学三年级语文)人教版期末考试(下学期)试卷(含答案)
- 第一单元名著导读《艾青诗选》作业设计-部编版语文九年级上册
- 《银行业从业人员职业操守和行为准则》课件
- 人工气候室投标书
- 云南省文山州2023-2024学年八年级下学期期末语文试卷
- 2024年第九届“鹏程杯”五年级语文邀请赛试卷
- 2024年国家开放大学《思想道德与法治》形考大作业参考答案
- (高清版)JTG D50-2017 公路沥青路面设计规范
- 基于X-13A-S季节调整方法的铁路客运量预测分析
- 广东省汕头市2022-2023学年六年级下学期语文期末考试试卷(含答案)
- 上海市初中生命科学学业会考总复习
评论
0/150
提交评论