资源描述:
《操作系统资料操作》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实验四文件操作一、实验名称:简单文件系统的实现二、实验目的要求在TCVRDelphi、C++Builder等语言与开发环境中,实现对文件的各项操作(复制、打开、保存、录入、查找、显示属性等);使学生进一步了解文件的主要操作。三、实验内容为DOS系统设计一个简单的二级文件系统。要求做到以下几点:①可以实现下列几条命令LOGIN用户登陆DIR列文件目录CREATE创建文件DELETE删除文件OPEN打开文件CLOSE关闭文件READ读文件WRITE写文件MODIFY修改文件内容②列目录时要列出文件名,物理地址,保护码和文件长
2、度。③源文件可以进行读写保护。四、实验提示①首先应确定文件系统的数据结构:主目录、子目录及活动文件等。主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。②用户创建的文件,可以编号存储于磁盘上。如:file0,file1,file2…并以编号作为物理地址,在目录中进行登记。五、实验运行结果参考程序见下:#include"stdio.h"#include"string.h"#include"conio.h"#include"stdlib.h"#defineMAXNAME25/thelargestlengthofmf
3、dname,ufdname,filename/19/20#defineMAXCHILD50/thelargestchild/#defineMAX(MAXCHILDMAXCHILD)/thesizeoffpaddrno/typedefstruct/thestructureofOSFILE/{intfpaddr;/filephysicaladdress/intflength;/filelength/intfmode;/filemode:0-ReadOnly;1-WriteOnly;2-ReadandWrite(default
4、);/charfname[MAXNAME];/filename/}OSFILE;typedefstruct/thestructureofOSUFD/{charufdname[MAXNAME];/ufdname/OSFILEufdfile[MAXCHILD];/ufdownfile/}OSUFD;typedefstruct/thestructureofOSUFD'LOGIN/{charufdname[MAXNAME];/ufdname/charufdpword[8];/ufdpassword/}OSUFD_LOGIN;ty
5、pedefstruct/fileopenmode/{intifopen;/ifopen:0-close,1-open/intopenmode;/0-readonly,1-writeonly,2-readandwrite,3-initial/}OSUFD_OPENMODE;OSUFDufd[MAXCHILD];/ufdandufdownfiles/OSUFD_LOGINufd_lp;intucount=0;/thecountofmfd'sufds/intfcount[MAXCHILD];/thecountofufd'sfi
6、les/intloginsuc=0;/whetherloginsuccessfully/charusername[MAXNAME];/recordloginuser'sname22/chardirname[MAXNAME];/recordcurrentdirectory/intfpaddrno[MAX];/recordfilephysicaladdressnum/OSUFD_OPENMODEifopen[MAXCHILD][MAXCHILD];/recordfileopen/close/intwgetchar;/whet
7、hergetchar()/FILEfp_mfd,fp_ufd,fp_file_p,fp_file;voidmain(){inti,j,choice1;charchoice[50];/choiceoperation:dir,create,delete,open,delete,modify,read,write/intchoiceend=1;/whetherchoiceend/charrtrim(charstr);/removethetrailingblanks./charltrim(charstr);/removetheh
8、eadingblanks./voidLoginF();/LOGINFileSystem/voidDirF();/DirFileSystem/voidCdF();/ChangeDir/voidCreateF();/CreateFile/voidDeleteF();/DeleteFile/voidModifyFM();/