📄 mainwaitingthread.cpp
字号:
#include"disk.h"
disk DISK;
//int userthreadfunction();
DWORD WINAPI userthreadfunction(LPVOID threadNo);
openfilemanager otemp;
void main()
{
/*
InitializeConditionVariable (&thereisspace);
InitializeConditionVariable (&thereisapplication);
InitializeCriticalSection (&ArrayLock);
InitializeCriticalSection (&getLock);
InitializeCriticalSection (&putLock);
*/
cout<<"请输入你的用户名与密码:"<<endl;
cout<<"之后是用户名密码验证,开辟新的线程,并根据用户名信息装载权能字列表,以便之后的权限访问控制,"<<endl
<<"但由于时间问题没有将这部分完成所以这个程序是没有访问控制的,也没有用户信息的储存,因此用户名与密码随便输入就行"<<endl;
char username[20];
char userpassword[20];
cin>>username;
cout<<"用户名输入完成,请输入密码"<<endl;
cin>>userpassword;
cout<<"如果是第一次使用该文件系统,则一定要先进行格式化并装载文件系统,你是否需要格式化:Y/N"<<endl;
char c;
cin>>c;
fstream iof("filesystem",ios::binary|ios::in|ios::out);
if(!iof){
cout<<"cannot open such a file"<<endl;
return;
}
DISK.disk_open(iof);
if(c!='N'&&c!='n'){
cout<<"格式化需要5到6秒左右时间"<<endl;
DISK.format();
DISK.installfilesystem();
}
// userthreadfunction();
DWORD id;
HANDLE hks= CreateThread (NULL, 0,userthreadfunction, NULL, 0, &id);
WaitForSingleObject (hks, INFINITE);
iof.close();
}
/*
void kedispatchfunction(LPVOID threadNo)
{
switch(applynum){
case APPLYNUM_CD:{//先改变当前路径并获得新的服务句柄
cp->add((userdata_cd*)threadNo->file
DWORD result=0;
return result;
}
*/
//int userthreadfunction()
DWORD WINAPI userthreadfunction(LPVOID threadNo)
{
cout<<"*******************************************************************"<<endl
<<"****姓名:邹少聪 学号:200630473254 班级:计算机科学与技术1班****"<<endl
<<"****实验名称:文件系统的模拟 "<<endl
<<"*******************************************************************"<<endl;
char code[40];
char codetemp[20];
currentpath userpath("root");
userpath.format();
// cp=&userpath;
servicehandle sh=otemp.createopenfileitem(&userpath);
cout<<"该文件系统的命令列表如下:如果指令不理解怎样用可参考开发文档的例子"<<endl
<<"cd…: 改变目录:改变当前工作目录,目录不存在时给出出错信息。如:root/cd foldername又如 root/ok/cd .."<<endl
<<"dir…: 显示目录,显示所有子目录及文件名。如:root/dir"<<endl
<<"md…: 创建目录:在指定路径或当前路径下创建指定目录。重名时给出错信息。如:root/md foldername"<<endl
<<"rd …: 删除目录:删除指定目录下所有文件和子目录。要删目录不空时,要给出提示是否要删除。如:root/rd foldername"<<endl
<<"newfile …: 利用外部文件建立文件。即将外部文件复制到这个文件系统的当前路径。如: root/newfile filename"<<endl
<<"out…:与newfile指令相反,将指定文件复制到外部程序所在目录处。如:root/out sourcefile desfile "<<endl
<<"cat …: 打开文件。如:root/cat filename"<<endl
<<"copy …: 拷贝文件.如:copy -i sourcefile desfile"<<endl
<<"exit:关闭文件系统。"<<endl;
mystring ms;
ms.open(code);
while(true){
cin.get();
cout<<userpath.cp;
cout<<"/";
cin.get(code,40);
//////////////
ms.gobeg();
ms.get(codetemp);
////////////////
if(strcmp(codetemp,"cd")==0){//先改变当前路径并获得新的服务句柄 cd
ms.get(codetemp);
if(codetemp[0]=='r'&&codetemp[1]=='o'&&codetemp[2]=='o'&&codetemp[3]=='t'&&(codetemp[4]=='/'||codetemp[4]=='\0')){
currentpath temp(codetemp);
temp.format();
servicehandle sh2=otemp.createopenfileitem(&temp);
if(sh2!=NULL){
userpath.open(codetemp);
userpath.format();
}
else
cout<<"there is no such a file"<<endl;
}
else {
if(strcmp(codetemp,".")==0);
else if(strcmp(codetemp,"..")==0){
userpath.sub();
sh=otemp.createopenfileitem(&userpath);
}
else{
userpath.add(codetemp);
servicehandle sh2=otemp.createopenfileitem(&userpath);
if(sh2!=NULL){
sh=otemp.createopenfileitem(&userpath);
otemp.deleteitem(sh2);
}
else{
cout<<"there is no such a file"<<endl;
userpath.sub();
}
}
}
}
else if(strcmp(codetemp,"dir")==0){/////////////dir
kernel_folderbrowse(sh);
}
else if(strcmp(codetemp,"md")==0){////////////////////////////////md
ms.get(codetemp);
kernel_createfolder(sh,codetemp);
}
else if(strcmp(codetemp,"rd")==0){//////////////////////////rd
ms.get(codetemp);
kernel_folderdeleteitem(sh,codetemp);
}
else if(strcmp(codetemp,"newfile")==0){//////////////////////////////////newfile
ms.get(codetemp);
kernel_createfile(sh,codetemp);
}
else if(strcmp(codetemp,"cat")==0){//先获取新的句柄,再浏览文件 cat
ms.get(codetemp);
userpath.add(codetemp);
servicehandle sh2=otemp.createopenfileitem(&userpath);
kernel_filecat_text(sh2);
userpath.sub();
otemp.deleteitem(sh2);
}
else if(strcmp(codetemp,"del")==0){//////////////////////del
ms.get(codetemp);
kernel_folderdeletefile(sh,codetemp);
}
else if(strcmp(codetemp,"copy")==0){////////////////////////////////copy
ms.get(codetemp);
char ttt[20];
if(strcmp(codetemp,"-i")==0){
ms.get(codetemp);
userpath.add(codetemp);
servicehandle sh2=otemp.createopenfileitem(&userpath);
if(sh2==NULL){
cout<<"the source file is not exit in this folder"<<endl;
userpath.sub();
continue;
}
else{
strcpy(ttt,"1/");
strcat(ttt,codetemp);
kernel_fileoutcopy(sh2,ttt);
userpath.sub();
otemp.deleteitem(sh2);
}
}
else{
cout<<"wrong input"<<endl;
continue;
}
ms.get(codetemp);
currentpath cptemp(codetemp);
cptemp.format();
servicehandle sh3=otemp.createopenfileitem(&cptemp);
kernel_createfile(sh3,ttt+2);
otemp.deleteitem(sh3);
// system("del codetemptext.txt");
}
else if(strcmp(codetemp,"out")==0){//先获取新的句柄,再复制文件 out
ms.get(codetemp);
userpath.add(codetemp);
servicehandle sh2=otemp.createopenfileitem(&userpath);
if(sh2==NULL){
cout<<"the source file is not exit in this folder"<<endl;
userpath.sub();
}
else{
ms.get(codetemp);
if(codetemp[0]=='\0'){
cout<<"the destination file is not written"<<endl;
}
else
kernel_fileoutcopy(sh2,codetemp);
userpath.sub();
otemp.deleteitem(sh2);
}
}
else if(strcmp(codetemp,"info")==0){
cout<<":用100M的文件来模拟,一块1K,分102400块,boot block与super block占一个块,"<<endl
<<"即使第0块,freespace map占13个块,从第1块到第13块,每块内部用1000个位来"<<endl
<<"表示1000个块的空闲与使用状况,inodelist用50块,由第14块一直到第64块,每"<<endl
<<"块放12个node,每个inode 84字节。"<<endl;
}
else if(strcmp(codetemp,"cd..")==0){
cout<<"请在cd与..之间加空格"<<endl;
}
else if(strcmp(codetemp,"exit")==0)
break;
else cout<<"wrong input"<<endl;
// cout<<endl;
}
return 0;
}
/*
int userthreadfunction(){
currentpath x("root");
x.format();
servicehandle sh=otemp.createopenfileitem(&x);
kernel_createfolder(sh,"ok2");
//kernel_folderbrowse(sh);
kernel_createfolder(sh,"ok");
cout<<x.cp<<endl;
kernel_folderbrowse(sh);
// kernel_folderdeleteitem(sh,"ok2");
// kernel_folderbrowse(sh);
currentpath xx("root/ok");
xx.format();
servicehandle sh_new=otemp.createopenfileitem(&xx);
kernel_createfolder(sh_new,"yes");
kernel_folderdeleteitem(sh,"ok");
kernel_folderdeleteitem(sh,"wc");
cout<<xx.cp<<endl;
kernel_folderbrowse(sh_new);
xx.add("yes");
servicehandle sh_new2=otemp.createopenfileitem(&xx);
kernel_createfolder(sh_new2,"haha");
cout<<xx.cp<<endl;
kernel_folderbrowse(sh_new);
cout<<xx.cp<<endl;
kernel_folderbrowse(sh_new2);
return 0;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -