//
// main.cpp
// OS
//
// Created by TNT on 2018/8/10.
// Copyright © 2018年 TNT. All rights reserved.
//
#include "Header.h"
#define MaxDisk 512*1024 //一个扇区512字节,假设有1024个扇区,模拟磁盘的大小
int Max_User=10;
int Max_Open=5;
int Max_End=0;
UFD_ptr pufd=NULL;
MFD_ptr pmfd=NULL;
AFD_ptr pafd=NULL;
char User_name[30]; //存放当前用户的用户名
char flag='n';
char Disk_Size[MaxDisk]; //最后在打印输出的时候,用RWX表示即可
typedef struct Disk_Table
{
int Max_length; //最大长度
int Start; //开始位置
}Disk_Node;
Disk_Node Disk_Head;
void Init_Disk()
{
Disk_Head.Max_length=MaxDisk;
Disk_Head.Start=0;
}
bool Init_MFD()
{
pmfd=(MFD *)new MFD; //带头节点的单向链表
MFD *p=pmfd;
ifstream ifs("MFD.txt"); //文件的输入流对象
if(!ifs)
{
cerr<<"错误:无法打开文件"<<endl;
p->next=NULL;
p->Ufd_next=NULL;
return false;
}
while(!ifs.eof())
{
p->next=(MFD *)new MFD;
ifs>>p->next->User_name>>p->next->User_passwd>>p->next->End;
if(p->next->End>Max_End)
Max_End=p->next->End;
p=p->next;
p->Ufd_next=NULL;
p->next=NULL;
}
ifs.close();
return true;
}
void Print_UFD()
{
UFD *p=pufd->next;
if(!p)
{
cout<<"抱歉,该用户没有创建任何文件,请先创建。"<<endl;
return ;
}
cout<<"文件名\t\t最大文件长度\t文件权限\t起始位置\t文件长度"<<endl;
while(p)
{
cout<<p->File_name<<"\t\t"<<p->Max_File_length;
if(p->Protect==0)
cout<<"\t\t"<<"---";
else if(p->Protect==1)
cout<<"\t\t"<<"r-x";
else if(p->Protect==2)
cout<<"\t\t"<<"rwx";
cout<<"\t\t"<<p->Start;
cout<<"\t\t"<<p->File_length<<endl;
p=p->next;
}
}
bool Init_UFD(char *name)
{
ifstream ifs(name);
pufd=(UFD *)new UFD;
UFD *p=pufd;
char temp[MaxDisk];
bool Index=false;
if(!ifs)
{
cerr<<"错误:无法打开文件"<<endl;
p->next=NULL;
return false;
}
while(!ifs.eof())
{
memset(temp,'\0',sizeof(temp));
p->next=(UFD *)new UFD;
if(!Index)
{
pmfd->Ufd_next=p->next;
Index=true;
}
ifs>>p->next->File_name>>p->next->Max_File_length>>p->next->Protect>>p->next->Start>>p->next->File_length;
ifs>>temp;
if(temp[0]=='#')
temp[0]='\0';
for(int i=p->next->Start,j=1;j<=p->next->Max_File_length-1;i++,j++)
{
Disk_Size[i]=temp[j-1];
if(!Disk_Size[i])
break;
}
Disk_Head.Max_length-=p->next->Max_File_length;
// Disk_Head.Start+=p->next->Max_File_length;
p=p->next;
p->next=NULL;
}
ifs.close();
return true;
}
void Rename_File()
{
string File_name;
UFD *temp=pufd;
char Index;
SD:
cout<<"请输入文件的名字:"<<endl;
cin>>File_name;
while(temp)
{
if(temp->File_name==File_name)
{
cout<<"请输入新的文件名:"<<endl;
cin>>File_name;
temp->File_name=File_name;
break;
}
temp=temp->next;
}
if(!temp)
{
cout<<"抱歉,输入的文件不存在,无法完成重命名文件操作,是否继续操作<y/n>?"<<endl;
cin>>Index;
if(Index=='y')
goto SD;
else
return ;
}
else
cout<<"修改成功。"<<endl;
}
bool User_Check()
{
string User_passwd;
int Count=0;
while(1)
{
cout<<"请输入用户名:";
cin>>User_name;
INIT:
cout<<"请输入密码:";
cin>>User_passwd;
MFD *p=pmfd->next;
char temp[30];
memset(temp,'\0',sizeof(temp));
strcpy(temp,User_name);
Count++;
while(p)
{
if(User_name==p->User_name)
{
if(User_passwd==p->User_passwd)
cout<<"登入成功."<<endl;
else
{
cout<<"抱歉,密码错误,登陆失败,请重新输入。"<<endl;
if(Count==3)
{
cout<<"密码错误次数过多,系统运行结束。"<<endl;
return false;
}
goto INIT;
}
strcat(temp,".txt");
Init_UFD(temp);
// Print_UFD();
Disk_Head.Start=Max_End;
return true;
}
p=p->next;
}
cout<<"用户名不存在,请重新输入。"<<endl;
}
// return false;
}
void Init_AFD()
{
pafd=(AFD *)new AFD;
pafd->next=NULL;
}
bool Create_MFD()//创建文件命令
{
string User_name;
char User_passwd[30];
MFD *p = pmfd;
cout<<"请输入要创建的用户名: ";
cin>>User_name;
cout<<"请输入"<<User_name<<"用户的密码:(默认为:admin)";
getchar();
cin.getline(User_passwd,30);
if(User_passwd[0]=='\0')
strcpy(User_passwd,"admin");
while(p)
{
if(User_name==p->User_name)
{
cout<<"此用户名已存在。"<<endl;
return false;
}
if(!p->next)
break;
p= p->next;
}
p->next = (MFD *)new MFD; //尾插法
p=p->next;
p->User_name=User_name;
p->User_passwd=User_passwd;
p->End=0;
p->next = NULL;
p->Ufd_next = NULL;
Max_User--;
return true;
}
bool Create_UFD()//创建文件命令
{
string File_name;
UFD *p = pufd;
unsigned int Protect;
int Max_File_length;
cout<<"请输入要创建的文件名: ";
cin>>File_name;
cout<<"请输入要创建的文件保护类型(0/1/2):";
cin>>Protect;
cout<<"请输入文件的最大容量:"<<endl;
cin>>Max_File_length;
while(p)
{
if(File_name==p->File_name)
{
cout<<"此文件名已存在。"<<endl;
return false;
}
if(!p->next)
break;
p= p->next;
}
p->next = (UFD *)new UFD; //尾插法
p=p->next;
p->File_name=File_name;
p->Max_File_length=Max_File_length;
p->Start=Disk_Head.Start;
p->Protect = Protect;
p->File_length = 0; //刚创建文件时,文件是空的
Disk_Head.Start+=Max_File_length;
p->next = NULL;
return true;
}
bool Delete_UFD() //关于主目录的用户文件夹的文件删除,如果文件已经打开了,不能删除
{
string File_name;
cout<<"请输入要删除的文件名:";
cin>>File_name;
UFD *p=pufd,*temp;
AFD *pa=pafd;
while(pa->next)
{
if(File_name==pa->next->File_name)
{
cout<<"抱歉,该文件已被打开,请先关闭,再进行删除操作。"<<endl;
return false;
}
}
while(p->next)
{
if(File_name==p->next->File_name)
{
temp=p->next;
p->next=p->next->next; //如果说要回收模拟的磁盘空间的话,应该是回收最大长度
delete temp;
cout<<"文件删除成功!!!"<<endl;
return true;
}
p=p->next;
}
cout<<"抱歉,要删除的文件不存在。"<<endl;
return false;
}
bool Open()
{
string File_name;
unsigned int Protect;
cout<<"请输入要打开的文件名:";
cin>>File_name;
UFD *p=pufd->next;
AFD *pa=pafd->next;
while(pa)
{
if(File_name==pa->File_name)
{
cout<<"文件"<<File_name<<"已经打开。"<<endl;
return true;
}
if(!pa->next)
break;
pa=pa->next;
}
if(!pa) //如果找不到,或者打�
没有合适的资源?快使用搜索试试~ 我知道了~
c++操作系统文件管理系统.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共6个文件
plist:2个
xcworkspacedata:1个
h:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
![star](https://csdnimg.cn/release/downloadcmsfe/public/img/star.98a08eaa.png)
温馨提示
c++源码
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 6 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
- 冠位巴萨辛山の翁2023-12-21这个资源总结的也太全面了吧,内容详实,对我帮助很大。
![avatar](https://profile-avatar.csdnimg.cn/5465b9e06f8e4477b25655a3a2e8e8ed_q6115759.jpg!1)
GeekyGuru
- 粉丝: 1798
- 资源: 1099
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)