2022年c++操作系统仿linux二级文件管理系统 .pdf
《2022年c++操作系统仿linux二级文件管理系统 .pdf》由会员分享,可在线阅读,更多相关《2022年c++操作系统仿linux二级文件管理系统 .pdf(20页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、实现了操作系统的管理员与用户登录权限的分离,还有文件夹的增删改查文件的增删改查 ,模拟 linux 。main.cpp #include #include #include BFSystem.h using namespace std; FBSystem *g_FBSystem = NULL; int main() int a; char g_UserName256; /用户名char g_PassWord256; /密码g_FBSystem = new FBSystem(); /用户验证coutg_UserName; cout密码 : ; char c,m = ?; int i; for(i
2、=0;i3;i+) do c = getch(); while(c9); mi = c; putchar(*); while(1) /回车继续 c = getch(); if(c=13) break; if(g_FBSystem-Login(g_UserName,m) coutendl; cout 登陆成功 !endl; cout 欢迎 :; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 20 页 - - - - - - - - - coutg_UserNameendl
3、; else coutendl; cout 无此用户 :g_UserName 输入任意键退出!exit; return 0; /系统初始化g_FBSystem-Initialize(); char time32; strcpy(time,g_FBSystem-GetTime(); /将后者复制给前者printf( 时间 :%sn,time); g_FBSystem-ShowMenu(); while (1) memset(g_FBSystem-m_CommandTemp,NULL,32); /将g_FBSystem-m_CommandTemp 全部变成null cin.sync(); /清除
4、cin 缓冲区for (int i=0; im_CurPathi0!=0) coutm_CurPathi; cing_FBSystem-m_CommandTemp; int commandID = g_FBSystem-SeekCommand(g_FBSystem-m_CommandTemp); char name256; char name1256; char text256; memset(text,0,256); switch(commandID) case 0: cinname; g_FBSystem-CreateDirectory(name); break; case 1: cinn
5、ame; g_FBSystem-DeleteDirectory(name); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 20 页 - - - - - - - - - break; case 2: cinname; cinname1; g_FBSystem-RenameDirectory(name, name1); break; case 3: cinname; g_FBSystem-OpenDirectory(name); break; case 4: cinnam
6、e; g_FBSystem-CreateFile(name); break; case 5: cinname; g_FBSystem-DeleteFile(name); break; case 6: cinname; cinname1; g_FBSystem-RenameFile(name, name1); break; case 7: g_FBSystem-Format(); break; case 8: cinname; g_FBSystem-Read(name); break; case 9: cinname; g_FBSystem-Write(name); break; case 10
7、: g_FBSystem-ShowMenu(); break; case 11: g_FBSystem-ShowAllFiles(); break; case 12: g_FBSystem-ReturnPreDirectory(); break; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 20 页 - - - - - - - - - case 13: cinname; g_FBSystem-Inquiry(name); break; case 14: cinname
8、0; g_FBSystem-FuzzyInquiry(name0); break; case 15: g_FBSystem-Exit(); return 0; break; default: break; return 0; FBSystem.cpp #include BFSystem.h FBSystem:FBSystem() m_NumOfObject = 0; /初始化对象数目为0 strcpy(m_UserName1,yjz); strcpy(m_Password1,123); strcpy(m_UserName2,jj); strcpy(m_Password2,123); strcp
9、y(m_Command0,mkdir); /初始化命令行strcpy(m_Command1,mddir); strcpy(m_Command2,rndir); strcpy(m_Command3,cd); strcpy(m_Command4,mkfile); strcpy(m_Command5,mdfile); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 20 页 - - - - - - - - - strcpy(m_Command6,rnfile); strcpy(
10、m_Command7,format); strcpy(m_Command8,read); strcpy(m_Command9,write); strcpy(m_Command10,menu); strcpy(m_Command11,dir); strcpy(m_Command12,cd.); strcpy(m_Command13,query); strcpy(m_Command14,fquery); strcpy(m_Command15,exit); memset(m_CommandTemp, NULL, 32); memset(m_CurPath, NULL, 2560); strcpy(m
11、_CurPath0, root); this-m_CurPathFatherID = 0; this-m_CurPathID = 0; this-m_CurMaxID = 0; this-m_CurFaID = 0; this-m_pow=0; bool FBSystem:Login(char* _userName, char* _password) if (strcmp(_userName, m_UserName1)=0&strcmp(_password, m_Password1)=0) m_pow=1; return true; if (strcmp(_userName, m_UserNa
12、me2)=0&strcmp(_password, m_Password2)=0) m_pow=0; return true; return false; void FBSystem:Initialize() FILE *m_FilePoint=fopen(system,rb); /以只读方式打开系统文件名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 20 页 - - - - - - - - - if(m_FilePoint=NULL) printf( 无法打开:); pr
13、intf(system); fseek(m_FilePoint,0,0); /定 位文件 指针到文件起始位置int num; fread(&num,4,1,m_FilePoint); m_NumOfObject = num; if (num0) fseek(m_FilePoint, 4, SEEK_SET); /相对于文件起始点第5个字节的位置for (int i = 0; im_ObjectList.push_back(*temp); fclose(m_FilePoint); bool FBSystem:CreateDirectory(char* _dirName) for(this-m_O
14、bjectIterator = m_ObjectList.begin(); m_ObjectIterator!= m_ObjectList.end(); +m_ObjectIterator) if (!strcmp(m_ObjectIterator-name, _dirName) & m_ObjectIterator-type = 0) cout 目录名重复!fatherID = this-m_CurPathID; strcpy(temp-lastTime,time); strcpy(temp-name,_dirName); 名师资料总结 - - -精品资料欢迎下载 - - - - - - -
15、 - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 20 页 - - - - - - - - - temp-objectID = GetMaxID(); temp-size = 0; temp-type = 0; /0 为目录this-m_ObjectList.push_back(*temp); return true; bool FBSystem:DeleteDirectory(char* _dirName) for(this-m_ObjectIterator = m_ObjectList.begin(); m_ObjectIterator
16、!= m_ObjectList.end(); +m_ObjectIterator) if (!strcmp(m_ObjectIterator-name, _dirName) & m_ObjectIterator-type =0) /检查该目录是否为非空list:iterator temp; for(temp = m_ObjectList.begin();temp!= m_ObjectList.end();+temp) if (temp-fatherID = m_ObjectIterator-objectID) cout不能删除非空的目录!m_ObjectIterator = m_ObjectL
17、ist.begin(); m_ObjectIterator!= m_ObjectList.end(); +m_ObjectIterator) if (!strcmp(m_ObjectIterator-name, _srcName) & m_ObjectIterator-type = 0) strcpy(m_ObjectIterator-name, _descName); return true; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 20 页 - - - - -
18、 - - - - return true; bool FBSystem:OpenDirectory(char* _name) for(this-m_ObjectIterator = m_ObjectList.begin(); m_ObjectIterator!= m_ObjectList.end(); +m_ObjectIterator) /存在该名称且类型为目录if (!strcmp(m_ObjectIterator-name, _name) & m_ObjectIterator-type=0) int temp =0; for (int i=0; iobjectID; return tru
19、e; if (!strcmp(root, _name) memset(m_CurPath, NULL, 2560); strcpy(m_CurPath0, root); m_CurPathFatherID = 0; m_CurPathID = 0; return true; cout错误操作 !m_ObjectIterator = m_ObjectList.begin(); m_ObjectIterator!= m_ObjectList.end(); +m_ObjectIterator) if (!strcmp(m_ObjectIterator-name, _fileName) & m_Obj
20、ectIterator-type =1) cout 文件名重复 !fatherID = this-m_CurPathID; strcpy(temp-lastTime,time); strcpy(temp-name,_fileName); temp-objectID = GetMaxID(); temp-size = 0; temp-type = 1; /0 为目录this-m_ObjectList.push_back(*temp); FILE *p = fopen(_fileName,w+); fclose(p); return true; bool FBSystem:DeleteFile(c
21、har* _fileName) for(this-m_ObjectIterator = m_ObjectList.begin(); m_ObjectIterator!= m_ObjectList.end(); +m_ObjectIterator) if (!strcmp(m_ObjectIterator-name, _fileName) & m_ObjectIterator-type =1) remove(m_ObjectIterator-name); m_ObjectIterator = m_ObjectList.erase(m_ObjectIterator); return true; r
22、eturn true; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 20 页 - - - - - - - - - bool FBSystem:RenameFile(char* _srcName, char* _descName) for(this-m_ObjectIterator = m_ObjectList.begin(); m_ObjectIterator!= m_ObjectList.end(); +m_ObjectIterator) if (!strcmp(m
23、_ObjectIterator-name, _srcName) & m_ObjectIterator-type = 1) strcpy(m_ObjectIterator-name, _descName); rename(_srcName,_descName); return true; return true; void FBSystem:Format() for(this-m_ObjectIterator = m_ObjectList.begin(); m_ObjectIterator!= m_ObjectList.end(); +m_ObjectIterator) if(m_ObjectI
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年c+操作系统仿linux二级文件管理系统 2022 c+ 操作系统 linux 二级 文件 管理 系统
限制150内