资源简介

广东工业大学 操作系统 实验四 文件系统

一、实验目的
模拟文件系统实现的基本功能,了解文件系统的基本结构和文件的各种管理方法,加深理解文件系统的内部功能及内部实现。通过用高级语言编写和调试一个简单的文件系统,模拟文件管理的工作过程,从而对各种文件操作命令的实质内容和执行过程有比较深入的了解。

二、实验内容和要求
编程模拟一个简单的文件系统,实现文件系统的管理和控制功能。要求本文件系统采用
两级目录,即设置主文件目录[MFD]和用户文件目录[UED]。另外,为打开文件设置运行文件
目录[AFD]。设计一个10个用户的文件系统,每次用户可保存10个文件,一次运行用户可
以打开5个文件,并对文件必须设置保护措施。在用户程序中通过使用文件系统提供的Create、open、read、write、close、delete等文件命令,对文件进行操作。
……
……
……

资源截图

代码片段和文件信息

#include
#include
#include
#include
using namespace std;

class AFD; //类声明
class MFD;

//用户文件目录
class UFD{
protected:
string fname; //文件名
int pcode; //保护码
int length; //文件长度(AFD中为写指针)
public:
UFD *next;

virtual void printfile();
UFD *findfile1(string fname);
string getfname();
int getpcode();
int getlength();
void addfile();
void editfile(int len); //更新文件长度
void createfile();
void deletefile(AFD *run);
void openfile(AFD *run);
void bye(AFD *run);
};


//运行目录文件
class AFD:public UFD{
private:
int readp; //读指针
public:
AFD *next; //下一打开文件

virtual void printfile();
AFD *findfile2(string fname);
int getreadp();
void addfile(AFD *runstring nameint codeint len); //添加打开文件
void editfile(int wlenint rlen); //更新读写指针
void readfile();
void writefile();
void closefile(UFD *user);
};


//主文件目录
//MFD带头结点
class MFD{
public:
string uname; //用户名
UFD *dir; //该用户文件目录指针
MFD *next; //下一用户

void init(); //新建MFD初始化
UFD* finduser(string username); //搜索用户
};

//初始化MFD内容
void MFD::init(){
uname=“\n“;
dir=NULL;
next=NULL;
MFD *temp1=this;
UFD *temp2;
int usernum;
int filenum;
cout<<“===========新建MFD===========“< cout<<“创建用户数:“;
cin>>usernum;
for(int i=1;i<=usernum;i++){
temp1->next=new MFD;
cout<<“\n第“< cin>>temp1->next->uname;

cout<<“用户“<next->uname<<“文件数:“;
cin>>filenum;
temp1->next->dir=new UFD;
temp2=temp1->next->dir;
temp2->next=NULL;
for(int j=0;j temp2->next=new UFD;
temp2->next->addfile();
temp2=temp2->next;
}

temp1->next->next=NULL;
temp1=temp1->next;
}
}

//传入用户名
//在MFD查找用户
//返回用户UFD指针
UFD* MFD::finduser(string username){
MFD *temp;
for(temp=next;temp;temp=temp->next){ //查找用户
if(0==temp->uname.compare(username))return temp->dir; //用户名比较
}
return NULL; //没找到用户
}

//------------------------------------------------------------------------------------
//增加UFD文件
//用于修改文件内容
void UFD::addfile(){
cout<<“创建文件名:“;
cin>>fname;getchar();
cout<<“文件“< for(cin>>pcode;pcode!=1&&pcode!=2&&pcode!=3;){
cout<<“重新输入保护码(1.读 2.写 3.执行):“;
cin>>pcode;
}
cout<<“文件“< for(cin>>length;cin.fail();){
cerr<<“长度输入错误“< cin.clear();
cout<<“重新输入文件“< }
next=NULL;
}

//创建UFD文件
void UFD::createfile(){
UFD *temp;
temp=new UFD;
temp->addfile();
temp->next=next;
next=temp;
}

//查找用户文件
//返回相应文件前一指针
UFD* UFD::findfile1(string fname){
UFD *temp1*temp2;
for(temp1=thistemp2=temp1->next;temp2;){
if(0==temp2->fname.compare(fname))break; //比较找到文件
temp1=temp2;
temp2=temp2->next;
}
if(!temp2)return NULL; //没找到
else return temp1; //找到返回前一指针
}

//传入AFD
//查找并删除要求文件
void UFD::deletefile(AFD *run){
string name;
UFD *delf*temp;
AFD *delf2*temp2;
printfile();
cout<<“输入要删除文件名:“;
cin>>name;getchar()

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5379  2010-11-20 10:24  8.png

     文件      10362  2010-11-20 10:25  9.png

     文件      11058  2010-11-20 10:27  10.png

     文件       8247  2010-11-20 10:28  11.png

     文件       2450  2010-11-20 10:29  12.png

     文件       5213  2010-11-20 10:30  13.png

     文件       9230  2010-11-20 11:16  文件系统.cpp

     文件     577622  2010-12-14 19:09  文件系统.exe

     文件      11508  2010-11-20 10:17  1.png

     文件       2178  2010-11-20 10:17  2.png

     文件       5084  2010-11-20 10:18  3.png

     文件       8185  2010-11-20 10:19  4.png

     文件       7386  2010-11-20 10:20  5.png

     文件       4548  2010-11-20 10:24  6.png

     文件       4490  2010-11-20 10:24  7.png

----------- ---------  ---------- -----  ----

               672940                    15


评论

共有 条评论