




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实验四 文件系统实验一 . 目的要求 1、用高级语言编写和调试一个简单的文件系统,模拟文件管理的工作过程。从而对各种文件操作命令的实质内容和执行过程有比较深入的了解。 2、要求设计一个 n个用户的文件系统,每次用户可保存m个文件,用户在一次运行中只能打开一个文件,对文件必须设置保护措施,且至少有Create、delete、open、close、read、write等命令。二 . 例题: 1、设计一个10个用户的文件系统,每次用户可保存10个文件,一次运行用户可以打开5个文件。2、程序采用二级文件目录(即设置主目录MFD)和用户文件目录(UED)。另外,为
2、打开文件设置了运行文件目录(AFD)。3、为了便于实现,对文件的读写作了简化,在执行读写命令时,只需改读写指针,并不进行实际的读写操作。4、算法与框图: 因系统小,文件目录的检索使用了简单的线性搜索。 文件保护简单使用了三位保护码:允许读写执行、对应位为 1,对应位为0,则表示不允许读写、执行。 程序中使用的主要设计结构如下: 主文件目录和用户文件目录( MFD、UFD) 打开文件目录( AFD)(即运行文件目录)M D FU F DA F D用户名文件名打开文件名文件目录指针保护码打开保护码用户名文件长度读写指针文件目录指针文件名··
3、;文件系统算法的流程图如下:三 . 实验题: 1、 增加 23个文件操作命令,并加以实现。(如移动读写指针,改变文件属性,更换文件名,改变文件保护级别)。代码如下:/1、增加 23个文件操作命令,并加以实现。(如移动读写指针,改变文件属性,更换文件名,改变文件保护级别)。#include<iostream>#include<string>#include<conio.h>using namespace std;struct TYPE_UFD stringFile_Name; boolRead; boolWrite; boolExec
4、ute; intLength_File;struct TYPE_MFD stringUser_Name; TYPE_UFD*Pointer;struct TYPE_AFD 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;
5、 TYPE_UFD *_UFD; TYPE_AFD *_AFD;void TYPE_FILE_SYSTEM:Initial( void ) _Number_Users = 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*_Numb
6、er_Files); _AFD = new TYPE_AFD _MaxNumber_Open_Files; _MFD0.User_Name = "zaq" _UFD0.File_Name = "file1.txt" _UFD0.Length_File = 10; _UFD0.Read = true; _UFD0.Write = false; _UFD0.Execute = true; _UFD1.File_Name = "file2.txt" _UFD1.Length_File = 20; _UFD1.Read = true; _UF
7、D1.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_O
8、pen_Files; string User_Name; string Command; TYPE_UFD *UFD; do do cout << "已创建用户名为zaqn指令有:create delete open dir diropen write read logout shutdown nn" cout << "请输入用户名:" cin >> User_Name; for( User_ID=0 ; User_ID<_Number_Users ; User_ID+ ) if( _MFDUser_ID.Use
9、r_Name = User_Name ) break; if( User_ID = _Number_Users ) cout << "用户名错误,请再次输入 ." << endl; while( User_ID = _Number_Users ); cout << "欢迎登录 , " << User_Name << " !" << endl; UFD = _MFDUser_ID.Pointer; for( i=0 ; i<_MaxNumber_Open_Fi
10、les ; i+ ) _AFDi.File_ID = -1; Number_Open_Files = 0; do cout << "C:" << User_Name << ">" ; cin >> Command; if( Command = "dir" ) cout << endl; cout << "打开用户 " << User_Name <<"的文件 " << endl; co
11、ut << "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 << "
12、;-" 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 &l
13、t;< endl; cout << endl; else if( Command = "diropen" ) cout << endl; cout << "打开用户 " << User_Name << "的文件 " <<endl; cout << "t" << "Statet" << "Open File name" << endl; for( i=0
14、 ; 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 <
15、< "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 <
16、;< "Error: 已有名为 " << _Number_Files << " 的文件." << endl; else cout << "请输入新文件信息:" << endl; cout << "文件名 : " cin >> temp; UFDi.File_Name = temp; cout << "文件权限 : " cout << "Read (y/n):" d
17、o choice = getch(); while( choice!='y' && choice!='n' ); if( choice = 'y' ) UFDi.Read = true; else UFDi.Read = false; cout << endl; cout << "Write (y/n):" do choice = getch(); while( choice!='y' && choice!='n' ); if( choic
18、e = 'y' ) UFDi.Write = true; else UFDi.Write = false; cout << endl; cout << "Execute (y/n):" do choice = getch(); while( choice!='y' && choice!='n' ); if( choice = 'y' ) UFDi.Execute = true; else UFDi.Execute = false; cout << endl;
19、cout << "Length :" cin >> temp_int; if( temp_int > 0 ) UFDi.Length_File = temp_int; cout << "新文件 " << UFDi.File_Name << " 已建立!" << endl; else if( Command = "delete" ) cout << "请输入文件名 :" cin >> temp;
20、for( i=0 ; i<_Number_Files ; i+ ) if( (UFDi.Length_File!=-1)&&(UFDi.File_Name=temp) ) break; if( i = _Number_Files ) cout << "文件名错误,请再次输入 ." << endl; else UFDi.Length_File = -1; cout << "文件 " << UFDi.File_Name << " 已删除 ." <<
21、; endl; else if( Command = "open" ) if( Number_Open_Files = _MaxNumber_Open_Files ) cout << "Error: 你已经打开了 " << Number_Open_Files << " 文件." << endl; else cout << "请输入文件名:" cin >> temp; for( i=0 ; i<_Number_Files ; i+ ) if
22、( (UFDi.Length_File!=-1)&&(UFDi.File_Name=temp) ) break; if( i = _Number_Files ) cout << "文件名错误,请再次输入 ." << 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;
23、_AFDtemp_int.Pointer = 0; cout << "请定义打开方式 :" << endl; 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 = fa
24、lse; 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 _AFDtemp_int.Write = false; cout <&l
25、t; 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.Execute = false; cout << endl
26、; else _AFDtemp_int.Execute; cout << "文件 " << temp << " 已打开 ." << endl; else if( Command = "logout" ) cout << "再见 , " << User_Name << " !" << endl; break; else if( Command = "close" ) cout <
27、;< "请输入文件名 :" cin >> temp; for( i=0 ; i<_Number_Files ; i+ ) if( (UFDi.Length_File!=-1)&&(UFDi.File_Name=temp) ) break; if( i = _Number_Files ) cout << "文件名错误,请再次输入 ." << endl; else for( temp_int=0 ; temp_int<_MaxNumber_Open_Files ; temp_int+ )
28、if( _AFDtemp_int.File_ID = i ) break; if( temp_int = _MaxNumber_Open_Files ) cout << "文件 " << temp << " 未打开 ." << endl; else _AFDtemp_int.File_ID = -1; Number_Open_Files-; cout << "文件 " << temp << " 已关闭 ." << end
29、l; else if( Command = "read" ) cout << "请输入文件名 :" cin >> temp; for( i=0 ; i<_Number_Files ; i+ ) if( (UFDi.Length_File!=-1)&&(UFDi.File_Name=temp) ) break; if( i = _Number_Files ) cout << "文件名错误,请再次输入 ." << endl; else for( temp_int=0 ;
30、 temp_int<_MaxNumber_Open_Files ; temp_int+ ) if( _AFDtemp_int.File_ID = i ) break; if( temp_int = _MaxNumber_Open_Files ) cout << "文件 " << temp << " 未打开 ." << endl; else if( _AFDtemp_int.Read = true ) cout << "文件 " << temp <<
31、; " 成功读取." << endl; else cout << "Error: 文件打开模式错误 ." << endl; else if( Command = "write" ) cout << "请输入文件名 :" cin >> temp; for( i=0 ; i<_Number_Files ; i+ ) if( (UFDi.Length_File!=-1)&&(UFDi.File_Name=temp) ) break; if(
32、 i = _Number_Files ) cout << "文件名错误,请再次输入 ." << 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 << "文件 " << temp << " 未打开 ." <
33、< endl; else if( _AFDtemp_int.Write = true ) cout << "文件 " << temp << " 成功写入." << endl; else cout << "Error: 文件打开模式错误 ." << endl; else if( Command = "shutdown" ) cout << "正在注销." << endl; cout <<
34、; "再见 , " << User_Name << " !" << endl; cout << "正在关机." << endl; break; else cout << "指令错误,请再次输入 ." << endl; while( Command != "logout" && Command != "shutdown" ); while( Command != "sh
35、utdown" );int main() TYPE_FILE_SYSTEM FS; FS.Initial(); FS.Start(); return 0;2、 编一个通过屏幕选择命令的文件管理系统,每屏要为用户提供足够的选择信息,不需要打入冗长的命令。 代码如下:#include <iostream>using namespace std;/2、编一个通过屏幕选择命令的文件管理系统,每屏要为用户提供足够的选择信息,不需要打入冗长的命令。#include <stdio.h>#include <stdlib.h>#include <string.
36、h>#define getpch(type) (type*)malloc(sizeof(type)void Select();int userNum=0;struct mdf char userName20; struct ufd* p; mdf20;struct ufd char fileName20; char File50; struct ufd * next;*fp,*tp,*p,*begin;typedef struct ufd UFD;void show( UFD *f) begin=f; if(begin->next=NULL) printf("该用户名下尚
37、无文件!n"); else printf("该用户名下所有文件:n"); begin=begin->next; while(begin!=NULL) printf("%s: %sn",begin->fileName,begin->File); begin=begin->next; void Operation(UFD *f) int i; char filename20,file50; begin=f;label: printf("请选择操作:n 1:create; 2:delete; 3:read; 4:wr
38、ite; 5:open;n 6:close; 7:Chang File's Name; 8:Show All The Filen"); scanf("%d",&i); if(i=1) tp=getpch(UFD); printf("请输入文件名:"); scanf("%s",filename); printf("n请输入文件内容:"); scanf("%s",file); strcpy(tp->fileName,filename); strcpy(tp->F
39、ile,file); tp->next=NULL; p=begin; p->next=tp; printf("n文件创建完毕!n"); goto label; else if(i=2) printf("请输入文件名:"); scanf("%s",filename); p=begin->next; while(strcmp(p->fileName,filename)!=0&&p!=NULL) p=p->next; if(p=NULL) printf("文件不存在!n");
40、 else tp=begin; while(tp->next!=p) tp=tp->next; tp->next=p->next; free(p); printf("文件已删除!n"); goto label; else if(i=3) printf("请输入文件名:"); scanf("%s",filename); p=begin->next; while(strcmp(p->fileName,filename)!=0&&p!=NULL) p=p->next; if(p=NULL) printf("文件不存在!n"); else printf("%s: %sn",
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 《深圳市培育发展精密仪器设备产业集群行动计划(2022-2025年)》
- 委托代扣医保协议书
- 学校餐厅供应协议书
- 姐弟家产分割协议书
- 国库集中收付协议书
- 安全知情保密协议书
- 婚后财产存款协议书
- 工伤费用结清协议书
- 坡地权属分配协议书
- 学生回家自学协议书
- 四年级下册语文课外阅读题三(5篇含答案)
- 山东省济南市槐荫区2024年五年级数学第二学期期末学业水平测试试题含解析
- 五年级小数乘法练习题300道及答案
- 万达商家入驻商场合同(2024版)
- 【课件】初心与使命-时代的美术担当+课件-高中美术人美版(2019)美术鉴赏
- DLT 722-2014 变压器油中溶解气体分析和判断导则
- 北师大版五年级下册英语教案
- 铝合金薄板的热处理工艺与性能的研究
- 四川省成都市郫都区2023-2024学年数学五下期末调研试题含解析
- 四年级数学思维训练题
- DB63T 2286-2024 电化学储能电站消防设施要求
评论
0/150
提交评论