操作系统实验四文件系统实验

上传人:E**** 文档编号:118463159 上传时间:2019-12-15 格式:PDF 页数:16 大小:270.47KB
返回 下载 相关 举报
操作系统实验四文件系统实验_第1页
第1页 / 共16页
操作系统实验四文件系统实验_第2页
第2页 / 共16页
操作系统实验四文件系统实验_第3页
第3页 / 共16页
操作系统实验四文件系统实验_第4页
第4页 / 共16页
操作系统实验四文件系统实验_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《操作系统实验四文件系统实验》由会员分享,可在线阅读,更多相关《操作系统实验四文件系统实验(16页珍藏版)》请在金锄头文库上搜索。

1、西北农林科技大学信息工程学院实习报告西北农林科技大学信息工程学院实习报告 实验四实验四 文件系统实验文件系统实验 一一 . .目的要求目的要求 1、用高级语言编写和调试一个简单的文件系统,模拟文件管理的工作过程。从 而对各种文件操作命令的实质内容和执行过程有比较深入的了解。 2、要求设计一个 n 个用户的文件系统,每次用户可保存 m 个文件,用户在一次 运行中只能打开一个文件, 对文件必须设置保护措施, 且至少有 Create、 delete、 open、close、read、write 等命令。 二二 . .实验实验内容内容 文件系统算法的流程图如下: 三三 . . 实验题:实验题: 1、

2、增加 23 个文件操作命令,并加以实现。(如移动读写指针,改变文件属 性,更换文件名,改变文件保护级别)。 2、 编一个通过屏幕选择命令的文件管理系统,每屏要为用户提供足够的选择信 息,不需要打入冗长的命令 第一题和第二题表达意思类似,所以合并成一个程序了 #include #include #include #define getpch(type) (type*)malloc(sizeof(type) int userNum=0; struct mdf char userName20; struct UFD* p; mdf20; struct ufd char fileName20; cha

3、r File50; struct ufd * next; *fp,*tp,*p,*begin; typedef struct ufd UFD ; void show(struct UFD *f) begin=f; if(begin-next=NULL) printf(该用户名下尚无文件!n); else printf(该用户名下所有文件:n); begin=begin-next; while(begin!=NULL) printf(%s: %sn,begin-fileName,begin-File); begin=begin-next; void Operation(struct UFD *f

4、) int i; char filename20,file50; begin=f; label: printf(请选择操作:n 1:create; 2:delete; 3:read; 4:write; 5:open;n 6:lose; 7:Chang Files Name; 8:Show All The Filen); scanf(%d, if(i=1) tp=getpch(UFD); printf(请输入文件名:); scanf(%s,filename); printf(n 请输入文件内容:); scanf(%s,file); strcpy(tp-fileName,filename); st

5、rcpy(tp-File,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 if(p=NULL) printf(文件不存在!n); else tp=begin; while(tp-next!=p) tp=tp-next; tp-next=p-next; free(p); printf(文件已删除!n)

6、; goto label; else if(i=3) printf(请输入文件名:); scanf(%s,filename); p=begin-next; while(strcmp(p-fileName,filename)!=0 if(p=NULL) printf(文件不存在!n); else printf(%s: %sn,p-fileName,p-File); goto label; else if(i=4) printf(请输入文件名:); scanf(%s,filename); printf(n 请输入文件内容:); scanf(%s,file); p=begin-next; while

7、(p!=NULL) if(!(strcmp(p-fileName,filename) strcpy(p-File,file); printf(n 替换了以%s 为名的文件!n,filename); goto label; p=p-next; tp=getpch(UFD); strcpy(tp-fileName,filename); strcpy(tp-File,file); tp-next=NULL; p=begin; p-next=tp; printf(n 创建了以%s 为名的文件!n,filename); goto label; else if(i=5) goto label; else

8、if(i=6) printf(功能关闭,无法操作n); Select(); else if(i=7) printf(请输入要改名的文件名:); scanf(%s,filename); while(p!=NULL) if(!(strcmp(p-fileName,filename) printf(n 请输入新的文件名:); scanf(%s,filename); strcpy(p-fileName,filename); printf(n 文件名已更改!n); goto label; p=p-next; printf(文件不存在!n); goto label; else if(i=8) show(f

9、); goto label; else goto label; void Select() char username20; int i; printf(请输入用户名:n); scanf(%s,username); for(i=0; inext; printf(%sn,fp-fileName); else printf(该用户尚未创建任何文件!n); fp= mdfi.p; Operation(fp); if(i=userNum) printf(该用户不存在,创建新用户?n 1:是 2:否n); scanf(%d, if(i=1) strcpy(mdfuserNum+.userName,use

10、rname); printf(已创建用户!n); i=userNum-1; fp= mdfi.p; Operation(fp); else printf(查询其它?n 1:是 2:否n); scanf(%d, if(i=1) Select(); else printf(谢谢使用!n); return; int main() int i; for(i=0; inext=NULL; mdfi.p=tp; Select(); return 0; 输入用户名,创建用户名为 2015012860 的新用户,选择创建新文件文件名为 Shiyan4, 选择操作,显示该用户下所有文件 将用户名为 shiyan

11、4 的文件名改为文件名为 caozuoxitong 的文件 用 read 读取文件名为 caozuoxitong 的文件内容 用 delete 删除文件名为 caozuoxitong 的文件。 3、 设计一个树型目录结构的文件系统,其根目录为 root,各分支可以是目录, 也可以是文件,最后的叶子都是文件。 #include #include #include #define getpch(type) (type*)malloc(sizeof(type) char s50; struct node char fileName20; char file200; struct node *chil

12、d,*brother; node,*head; typedef struct node File; void init() head=getpch(File); strcpy(head-fileName,根目录 root); strcpy(head-file,root); head-child=head-brother=NULL; void insertDep() File* p; p=getpch(File); printf(请输入目录名称:); scanf(%s,s); strcpy(p-fileName,s); printf(n 请输入目录的基本信息:); scanf(%s,s); strcpy(p-file,s); p-brother=p-child=NULL; if(head-child=NULL) head-child=p; else p-brother=head-child; head-child=p; File* haveDep(char *s) File *p; p=he

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号