资源描述:
《操作系统文件操作.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验四文件操作一、实验名称:简单文件系统的实现二、实验目的要求在TC、VB、Delphi、C++Builder等语言与开发环境中,实现对文件的各项操作<复制、打开、保存、录入、查找、显示属性等);使学生进一步了解文件的主要操作。b5E2RGbCAP三、实验内容为DOS系统设计一个简单的二级文件系统。要求做到以下几点:①可以实现下列几条命令LOGIN用户登陆DIR列文件目录CREATE创建文件DELETE删除文件OPEN打开文件CLOSE关闭文件READ读文件WRITE写文件MODIFY修改文件内容②列目录时要列出文件名,物理地址,保护码和文件长度。③源文件
2、可以进行读写保护。四、实验提示①首先应确定文件系统的数据结构:主目录、子目录及活动文件等。主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。p1EanqFDPw②用户创建的文件,可以编号存储于磁盘上。如:file0,file1,file2…并以编号作为物理地址,在目录中进行登记。DXDiTa9E3d五、实验运行结果参考程序见下:#include"stdio.h"#include"string.h"#include"conio.h"#include"stdlib.h"#defineMAXNAME25/*thelargestlengthofmfdna
3、me,ufdname,filename*/RTCrpUDGiT#defineMAXCHILD50/*thelargestchild*/#defineMAX(MAXCHILD*MAXCHILD>/*thesizeoffpaddrno*/5PCzVD7HxA21/21typedefstruct/*thestructureofOSFILE*/{intfpaddr。/*filephysicaladdress*/jLBHrnAILgintflength。/*filelength*/intfmode。/*filemode:0-ReadOnly。1-WriteOnly。
4、2-ReadandWrite(default>。*/xHAQX74J0Xcharfname[MAXNAME]。/*filename*/}OSFILE。typedefstruct/*thestructureofOSUFD*/{charufdname[MAXNAME]。/*ufdname*/OSFILEufdfile[MAXCHILD]。/*ufdownfile*/}OSUFD。typedefstruct/*thestructureofOSUFD'LOGIN*/{charufdname[MAXNAME]。/*ufdname*/charufdpword[8]。/
5、*ufdpassword*/}OSUFD_LOGIN。typedefstruct/*fileopenmode*/{intifopen。/*ifopen:0-close,1-open*/intopenmode。/*0-readonly,1-writeonly,2-readandwrite,3-initial*/LDAYtRyKfE}OSUFD_OPENMODE。OSUFD*ufd[MAXCHILD]。/*ufdandufdownfiles*/OSUFD_LOGINufd_lp。intucount=0。/*thecountofmfd'sufds*/intfco
6、unt[MAXCHILD]。/*thecountofufd'sfiles*/Zzz6ZB2Ltkintloginsuc=0。/*whetherloginsuccessfully*/charusername[MAXNAME]。/*recordloginuser'sname22*/dvzfvkwMI1chardirname[MAXNAME]。/*recordcurrentdirectory*/intfpaddrno[MAX]。/*recordfilephysicaladdressnum*/rqyn14ZNXIOSUFD_OPENMODEifopen[MAXCH
7、ILD][MAXCHILD]。/*recordfileopen/close*/EmxvxOtOcointwgetchar。/*whethergetchar(>*/FILE*fp_mfd,*fp_ufd,*fp_file_p,*fp_file。voidmain(>{inti,j,choice1。charchoice[50]。/*choiceoperation:dir,create,delete,open,delete,modify,read,write*/SixE2yXPq5intchoiceend=1。/*whetherchoiceend*/char*rt
8、rim(char*str>。/*removethetrailing