023 操作系统集合_模拟UNIX文件系统的设计及实现
                    联系方式 Email: lw510@qq.com      QQ: 497053418       MSN: lw510@qq.com
以下仅为该设计的基本说明介绍,若需要完整的设计和论文,建议您购买本设计.
023 操作系统集合_模拟UNIX文件系统的设计及实现样本
(样本只提供该系统的基本情况介绍,若需要完整的设计和论文,建议您购买本系统,凡是购买本站系统的,本站均根据您的要求,把系统上的开发信息,题目等修改成符合您的要求)
 

本设计包含内容:源代码+毕业论文
论文大概:
一、设计思想说明
本系统是模拟实现多用户多目录的文件系统(8个用户),在系统出现登录后 ,输入用户与口令,在用户登录系统后,可建立文件卷,将用户输入的文件保存在指定的文件中。系统的命令与其命令的具体实现:
(1) login:用户登录;
(2) create:新建文件
(3) read:查看文件
(4) write文件写入
(5) del:删除文件
(6) cd:改变目录
(7) mkdir:新建目录
(8) dir:列出当前目录下的所有文件及子目录
(9) logout: 用户退出系统
此模拟系统共提供了上述命令,并根据命令的含义与要求,用visual C++6.0编程来完成所有具体操作。该系统可以模拟完成用户的登陆和验证,列出文件和目录,新建目录,改变目录,创立和编写文件,删除文件和退出系统等功能。
二、系统结构说明
用户结构:账号与密码结构
typedef struct users
{
 char     name[8];
 char     pwd[10];
}users;
本系统有8个默认的用户名,前面是用户名,后面为密码,用户登陆时只要输入正确便可进入系统,否则提示失败要求重新输入。
users usrarray[8] =
{
 "usr1","usr1",
 "usr2","usr2",
 "usr3","usr3",
 "usr4","usr4",
 "usr5","usr5",
 "usr6","usr6",
 "usr7","usr7",
 "usr8","usr8",
};
三、数据结构说明
1、文件结构链表
struct fnode
{
    char filename[FILENAME_LENGTH];
 int  isdir;
 int isopen;
 char content[255];
 fnode *parent;
 fnode *child;
 fnode *prev;
 fnode *next;
};
3.函数介绍
fnode *initfile(char filename[],int isdir);//初始化文件或目录 
 void createroot();//建立系统根目录
 int run();系统运行
 int findpara(char *topara);对参数进行处理
 bool chklogin(char *users, char *pwd);检查账号与口令
 void help();命令列表
 int mkdir();建立目录
 int create();建立文件
 int read();读取文件
 int write();写入文件
 int del();删除文件
 int cd();切换目录
 int dir();文件与目录列表
四、各模块流程图
               用户登录

                 验证        否
               

 
      建立目录         建立文件

      建立、切换     建立、显示、写入、删除
                 退出

五、程序清单
#include "stdio.h"
#include "iostream.h"
#include "string.h"
#include "iomanip.h"

#define FILENAME_LENGTH 10 //文件名称长度
#define COMMAND_LENGTH 10  //命令行长度
#define PARA_LENGTH 30    //参数长度
 
 

//账号结构
 typedef struct users
{
 char     name[8];
 char     pwd[10];
}users;
 //文件结构
struct fnode
{
    char filename[FILENAME_LENGTH];
 int  isdir;
 int isopen;
 char content[255];
 fnode *parent;
 fnode *child;
 fnode *prev;
 fnode *next;
};

//账号
users usrarray[8] =
{
 "usr1","usr1",
 "usr2","usr2",
 "usr3","usr3",
 "usr4","usr4",
 "usr5","usr5",
 "usr6","usr6",
 "usr7","usr7",
 "usr8","usr8",
};
 fnode *initfile(char filename[],int isdir);
 void createroot();
 int run();
 int findpara(char *topara);
 bool chklogin(char *users, char *pwd);
 void help();
 int mkdir();
 int create();
 int read();
 int write();
 int del();
 int cd();
 int dir();
fnode *root,*recent,*temp,*ttemp;
char para[PARA_LENGTH],command[COMMAND_LENGTH],temppara[PARA_LENGTH],recentpara[PARA_LENGTH];

//创建文件与目录结点
 fnode* initfile(char filename[],int isdir)
{
    fnode *node=new fnode;
    strcpy(node->filename,filename);
    node->isdir=isdir;
 node->isopen=0;
 node->parent=NULL;
    node->child=NULL;
 node->prev=NULL;
 node->next=NULL;
 return node;
}
//创建文件存储结点
void createroot ()
{
   recent=root=initfile("/",1);
   root->parent=NULL;
   root->child=NULL;
   root->prev=root->next=NULL;
   strcpy(para,"/");
  
  }
int mkdir()

 temp=initfile(" ",1);
 cin>>temp->filename;
 if(recent->child==NULL) 
   {
     temp->parent=recent;
  temp->child=NULL;
  recent->child=temp;
  temp->prev=temp->next=NULL;
    
  }
   else
   {
    ttemp=recent->child;
 while(ttemp->next)
 {
    ttemp=ttemp->next;
    if(strcmp(ttemp->filename,temp->filename)==0&&ttemp->isdir==1)
    {
        printf("对不起,目录已存在!");
     return 1;
     }
 }
      ttemp->next=temp;
   temp->parent=NULL;
   temp->child=NULL;
   temp->prev=ttemp;
   temp->next=NULL;
  
  }
return 1;
}
int create()

 temp=initfile(" ",0);
 cin>>temp->filename;
 cin>>temp->content;
 if(recent->child==NULL) 
   {
     temp->parent=recent;
  temp->child=NULL;
  recent->child=temp;
  temp->prev=temp->next=NULL;
  cout<<"文件建立成功!"<<endl;
  }
   else
   {
    ttemp=recent->child;
 while(ttemp->next)
 {
    ttemp=ttemp->next;
    if(strcmp(ttemp->filename,temp->filename)==0&&ttemp->isdir==0)
    {
        printf("对不起,文件已存在!");
     return 1;
     }
 }
      ttemp->next=temp;
   temp->parent=NULL;
   temp->child=NULL;
   temp->prev=ttemp;
   temp->next=NULL;
   cout<<"文件建立成功!"<<endl;
   }
   
return 1;
}

int dir()
{
int i=0,j=0;
temp=new fnode;
temp=recent;
if(temp!=root)
{cout<<"      <DIR>                         "<<".."<<endl;i++;}
if(temp->child==NULL)
{
    cout<<"Total: "<<" directors                  " <<i<<"          files                "<< j <<endl;
 return 1;
}
temp=temp->child;
while(temp)
{
    if(temp->isdir)
 {cout<<"      <DIR>                        "<<temp->filename<<endl;i++;}
 else
 {cout<<"      <FILE>                       "<<temp->filename<<endl;j++;}
 temp=temp->next;
 }
cout<<"Total: "<<" directors                  " <<i<<"          files                "<< j <<endl;
}

int read()
{
char filename[FILENAME_LENGTH];
cin>>filename;
   if(recent->child==NULL)
   {
   cout<<"文件不存在!"<<endl;
   return 1;
  }
   if(strcmp(recent->child->filename,filename)==0)
   {
    cout<<recent->child->content<<endl;
    return 1;
  }
   else
   {
   temp=recent->child;
   while(temp->next)
   {
   if(strcmp(temp->next->filename,filename)==0)
   {cout<<temp->next->content<<endl;
   return 1;}
  }
   cout<<"文件不存在!"<<endl;
  
   }
 
}
int write()
{
char filename[FILENAME_LENGTH];
cin>>filename;
   if(recent->child==NULL)
   {
   cout<<"文件不存在!"<<endl;
   return 1;
  }
   if(strcmp(recent->child->filename,filename)==0)
   {
    recent->child->isopen=1;//设置文件标记为打开
    cin>>recent->child->content;
    recent->child->isopen=0;//设置文件标记为关闭
    cout<<"文件写入成功!"<<endl;
    return 1;
  }
   else
   {
   temp=recent->child;
   while(temp->next)
   {
   if(strcmp(temp->next->filename,filename)==0)
   {
    recent->child->isopen=1;//设置文件标记为打开
       cin>>temp->next->content;
    recent->child->isopen=0;//设置文件标记为关闭
    cout<<"文件写入成功!"<<endl;
   return 1;}
  }
   cout<<"文件不存在!"<<endl;
  
   }
}
int cd()
{  char topara[PARA_LENGTH];
 cin>>topara;
   if(strcmp(topara,"..")==0)
   {
      int i;
   while(recent->prev)
   recent=recent->prev;
   if(recent->parent)
   {
   recent=recent->parent;
   }
     
   i=strlen(para);
   while(para[i]!='/' && i>0) i--;
   if(i!=0)
    para[i]='\0';
   else
    para[i+1]='\0';
}
else
{
 findpara(topara);
}
return 1;
}
int findpara(char *topara)
{
   int i=0;
   int sign=1;
   if(strcmp(topara,"/")==0)
   {
    recent=root;
    strcpy(para,"/");
    return 1;
   }
   temp=recent;
   strcpy(temppara,para);
   if(topara[0]=='/')
   {
    recent=root->child;
    i++;
    strcpy(para,"/");
   }
   else
   {
      if(recent!=NULL && recent!=root)
          strcat(para,"/");
        if(recent && recent->child)
  {
   if(recent->isdir)
           recent=recent->child;
         else
   {
      printf("路径错误!\n");
   return 1;
  }
  }
}
   while(i<=strlen(topara) && recent)
   {
    int j=0;
    if(topara[i]=='/' && recent->child)
    {
    i++;
    if(recent->isdir)
        recent=recent->child;
    else
    {printf("路径错误\n");
        return 0;
   }
    strcat(para,"/");
  }
   while(topara[i]!='/' && i<=strlen(topara))
   {
      recentpara[j]=topara[i];
   i++;j++;
   }
   recentpara[j]='\0';
   while((strcmp(recent->filename,recentpara)!=0 || (recent->isdir!=1)) && recent->next!=NULL)
   {
       recent=recent->next;
  }
   if(strcmp(recent->filename,recentpara)==0)
   {
    if(recent->isdir==0)
    {strcpy(para,temppara);
    recent=temp;
    printf("是文件不是目录。\n");
    return 0;
   }
    strcat(para,recent->filename);
  }
   if(strcmp(recent->filename,recentpara)!=0 || recent==NULL)
   {
   strcpy(para,temppara);
   recent=temp;
   printf("输入路径错误\n");
   return 0;
   }
  }
return 1;
}
int del()
{
  char filename[FILENAME_LENGTH];
  cin>>filename;
 
  temp=new fnode;
 
 
  if(recent->child)
  {
    temp=recent->child;
 while(temp->next && (strcmp(temp->filename,filename)!=0 || temp->isdir!=0))
        temp=temp->next;
 if(strcmp(temp->filename,filename)!=0)
 {
    cout<<"不存在该文件!"<<endl;
    return 0;
 }
 }
  else
  {
    cout<<"不存在该文件!"<<endl;
  return 0;
 }
 
  if(temp->parent==NULL)
  {
   temp->prev->next=temp->next;
   if(temp->next)
     temp->next->prev=temp->prev;
        temp->prev=temp->next=NULL;
 }
  else
  {
   if(temp->next)
    temp->next->parent=temp->parent;
   temp->parent->child=temp->next;
 }
  delete temp;
  cout<<"文件已删除!"<<endl;
}
 
bool chklogin(char *users, char *pwd)
{
 int i;
 for(i=0; i<8; i++)
 {
  if( (strcmp(users,usrarray[i].name)==0) && (strcmp(pwd,usrarray[i].pwd)==0))
   return true;
 }
 return false;
}
void help(void)
{
 cout<<"                  命  令  一  览               "<<endl;
 cout<<endl;
 cout<<"create:             建立文件。                "<<endl;
 cout<<"read:               读取文件。                  "<<endl;
 cout<<"write:              写入文件,支持多线程          "<<endl;
 cout<<"del   :             删除文件。                  "<<endl;
 cout<<"mkdir:              建立目录。                "<<endl;
 cout<<"cd:                 切换目录。                  "<<endl;
 cout<<"logout:             退出登录。                "<<endl;
}
int run()
{
  cout<<"unix:"<<para<<">";
  cin>>command;
   if(strcmp(command,"mkdir")==0)
   mkdir();
 else if(strcmp(command,"dir")==0)
   dir();
 else if(strcmp(command,"cd")==0)
   cd();
  else if(strcmp(command,"create")==0)
   create();
 else if(strcmp(command,"read")==0)
   read();
 else if(strcmp(command,"write")==0)
   write();
else if(strcmp(command,"del")==0)
   del();
else if(strcmp(command,"help")==0)
   help();
  else if(strcmp(command,"logout")==0)
 return 0;
    else
  cout<<"请参考help提供的命令列表!"<<endl;
 }
int main()
{
int i=0;
bool in=false;
char users[8],pwd[12];
   cout<<"|-----------------------------------------------------------------|"<<endl;
   cout<<"|                       c语言模拟unix文件系统                     |"<<endl;
   cout<<"|            账号:usr1-usr8      密码:usr1-usr8           |"<<endl;
   cout<<"|                      你只有三次机会来试验账号                   |"<<endl;
   cout<<"|                  键入help可以获取帮助                     |"<<endl;
   cout<<"|_________________________________________________________________|"<<endl;
   cout<<endl;
while(i<3)
{
cout<<"Login:";
cin>>users;
cout<<"Pass:";
cin>>pwd;
if(chklogin(users,pwd))
{in=true;break;}
i++;
}
createroot();
while(in)
{
if(!run())
break;
}
}
六、程序使用说明书
1、 请把软盘中的unix.exe拷贝到电脑中,运行即可;
2、 运行界面如下图:
 
3、 进入之后可以输入 “help”,根据帮助目录输入响应命令即可。如下图:
以下是各命令的说明:
 
七、体会
作为一个模拟的系统,我真正体会到了《操作系统》的作用,并对许多抽象的概念有了真正的理解,由于课本并没有太多例子可供参考,没有老师所说的13章或14章,去完成这样一个编程,对我来说花了很多时间,而且经常要与同学互相交流和探讨,也参考了大量的书籍,但还有不少需要改进之处,请老师指导完善,使我学到更多的东西,加深我的理解和认识。
 
 
 
 

 

 
023 操作系统集合_模拟UNIX文件系统的设计及实现
 

关闭窗口

与本站联系的时候,为了提高效率,请告诉本站您需要的设计编号与题目。如:001VBAC人事管理系统
编码说明:001VBAC人事管理系统,其中001VBAC 为该毕业设计的编号,VB代表开发语言,AC代表数据库(ACCESS)
版权所有:510计算机论文网:http://www.lw510.com/程序制作:510论文
Email: LW510@QQ.COM  QQ: 497053418   MSN: LW510@QQ.COM