操作系统课程设计-二级文档管理系统.doc_第1页
操作系统课程设计-二级文档管理系统.doc_第2页
操作系统课程设计-二级文档管理系统.doc_第3页
操作系统课程设计-二级文档管理系统.doc_第4页
操作系统课程设计-二级文档管理系统.doc_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

青 岛 科 技 大 学操 作 系 统 课 程 设 计计算机092学生班级_0908010209学生学号_Angelo学生姓名_ 2012626_年 _月 _日操作系统课程设计(二级文件管理系统)一、课程设计要求 从所给题目中选择一个,分析设计要求,给出解决方案,建立必要的数据结构,设计总体流程(包括界面),详细设计必要的算法,测试结果。基于Windows或Linux操作系统都可以,编程语言不限。二、设计目的 深入了解文件管理系统,初步掌握文件管理系统的实现方法。三、选择题目 设计一个简单的二级文件系统设计内容:编写程序模拟实现一个简单的文件管理系统,设计一个较实用的用户界面,方便用户使用。设计要求:提供以下相关文件操作:(1)具有login (用户登录)(2)系统初始化(建文件卷、提供登录模块)(3)文件的创建: create(4)文件的打开:open(5)文件的读:read(6)文件的写:write(7)文件关闭:close(8)删除文件:delete (9)创建目录(建立子目录):mkdir(10)列出文件目录:dir(11)退出:loyout四、程序设计(1) 开发环境Ubuntu 11.10 GCC(GNU Compiler Collection,GNU编译器套装) C语言编程(2) 设计思想 文件管理仅针对相应用户,用户注册时,自动分配对应的文件空间,该用户所有的文件保存在该用户空间下。用户只有对自己空间中的目录或文件具有权限。 文件管理系统,模拟Linux文件管理指令格式,模拟实现ls、cat、rm、cd、mkdir等基础文件管理指令,并具有较明朗的操作界面。(3) 流程设计结束创建文件删除文件读文件写文件创建文件夹删除文件夹目录跳转查看所有文件查看帮助查看所有目录 退出选择操作登陆注册开 始开始界面1、系统执行流程图2、创建文件(夹)输入文件(夹)名结束文件(夹)是否存在创建文件(夹)开始文件已存在,无法创建3、删除文件(夹)删除文件(夹)输入文件(夹)名结束文件(夹)是否存在文件(夹)不存在开始(4) 主要模块设计#define MaxUser 20 /最大用户数#define commandAmount 9 /指令数char _user20; /当前用户名char currentDir255; /当前所在目录typedef struct UserMess /所有用户信息 char _UserName20; char _UserPwd20; struct UserMess *nextUser;_UserMess;_UserMess *firstUser;typedef struct FolderDir /目录路径信息 char _Dir255; struct FolderDir *fatherDir;_RootDir;_RootDir *rootFolder;typedef struct Folder /当前目录子目录信息 char _FolderName100; struct Folder *nextFolder;_Folder;_Folder *firstFolder;typedef struct File /当前目录下文件信息 char _FileName100; struct File *nextFile;_File;_File *firstFile;(5) 功能函数设计 void init(); /初始化部分内容int ReadUserMess(); /读取已有用户信息int userCreate(int sumUsers); /用户注册int login(); /登录void createRootFolder(char username); /为新用户分配空间void TraverseFolder(char path); /遍历文件及文件夹void ListFileAndFolder(); /显示当前文件夹下所有文件void ChangeDir(char folderName); /目录跟换void Delete(char fName); /删除文件或文件夹void CatFile(char fName); /打开文件,查看文件内容void AddContent(char fName); /向文件写入内容void CreateFile(char fName); /创建文件void CreateFolder(char folderName); /创建文件夹void HelpFile(); /帮助文件(6) 运行部分截图图1 模拟的指令预览,以及系统支持指令格式图2 用户登录,并查看根目录下所有文件及文件夹图3 查看文件内容,并写入信息图4 目录跳转功能图5 删除文件、删除目录五、程序代码#include #include #include #include #include #include #define MaxUser 20#define commandAmount 9char _user20;char currentDir255;typedef struct UserMess char _UserName20; char _UserPwd20; struct UserMess *nextUser;_UserMess;_UserMess *firstUser;typedef struct FolderDir char _Dir255; struct FolderDir *fatherDir;_RootDir;_RootDir *rootFolder;typedef struct Folder char _FolderName100; struct Folder *nextFolder;_Folder;_Folder *firstFolder;typedef struct File char _FileName100; struct File *nextFile;_File;_File *firstFile;void init(); /初始化部分内容int ReadUserMess(); /读取已有用户信息int userCreate(int sumUsers); /用户注册int login(); /登录void createRootFolder(char username); /为新用户分配空间void TraverseFolder(char path); /遍历文件及文件夹void ListFileAndFolder(); /显示当前文件夹下所有文件void ChangeDir(char folderName); /目录跟换void Delete(char fName); /删除文件或文件夹void CatFile(char fName); /打开文件,查看文件内容void AddContent(char fName); /向文件写入内容void CreateFile(char fName); /创建文件void CreateFolder(char folderName); /创建文件夹void HelpFile(); /帮助文件int main() int logined=0; int select; char ch; char ordercommandAmount9; strcpy(order0,create); strcpy(order1,rm); strcpy(order2,cat); strcpy(order3,write); strcpy(order4,ls); strcpy(order5,cd); strcpy(order6,exit); strcpy(order7,mkdir); strcpy(order8,help); char command15,command_str1255; int i,j; init(); int userNum = ReadUserMess(); / printf(User count:%dn,userNum); int isright=1; while(isright=1) printf(*n); printf( 1、Creat usern); printf( 2、loginn); printf(*n); printf(Please chooce the function key: ); int choice; setbuf(stdin,NULL); scanf(%d,&choice); if(choice=1) logined=userCreate(userNum); isright=0; else if(choice=2) logined=login(userNum); isright=0; TraverseFolder(currentDir); if(logined =1) while(logined) / command0=0; for(i=0;i15;i+) commandi=0; for(i=0;i255;i+) command_str1i=0; /command_str10=0; setbuf(stdin,NULL); printf(n%s :$ ,_user); for(i=0,j=0;ch = getchar();i+) if(j=1) if(ch= | ch =n) command_str1i=0; break; else command_str1i=ch; if(j=0) if(ch= ) i=-1; j+; else if(ch =n) commandi=0; break; else commandi=ch; printf(n); for(i=0;inextFile !=NULL) if(strcmp(fi-_FileName,fName)=0) printf(Files is Exist! Create failed!n); return; fi =fi-nextFile; FILE *fp; fp=fopen(fSavePath,w); if(fp=NULL) printf(File create failed!n); else printf(File create success!n); TraverseFolder(currentDir);void TraverseFolder(char path) _Folder *p; _File *q; firstFolder = (_Folder *)malloc(sizeof(_Folder); firstFolder-nextFolder = NULL; firstFile =(_File *)malloc(sizeof(_File); firstFile-nextFile =NULL; struct dirent* entry=NULL; DIR *pDir; pDir=opendir(path); while(NULL!=(entry=readdir(pDir) if(entry-d_type=8) q=(_File *)malloc(sizeof(_File); strcpy(q-_FileName,entry-d_name); q-nextFile=firstFile; firstFile=q; /printf(%s ,entry-d_name); else if(entry-d_type=4) if(strcmp(entry-d_name, .) != 0) &(strcmp(entry-d_name, .) != 0) & (entry-d_name0 != .) p = (_Folder *)malloc(sizeof(_Folder); strcpy(p-_FolderName,entry-d_name); p-nextFolder = firstFolder; firstFolder=p; / printf(Folder:%s ,entry-d_name); /d_type:4表示目录,8表示文件 void ListFileAndFolder() _File *fi; fi=firstFile; printf(n*n); printf(Files :n); while(fi-nextFile != NULL) printf(%s ,fi-_FileName); fi=fi-nextFile; printf(nn); _Folder *fo; fo=firstFolder; printf(Folders:n); while(fo-nextFolder!=NULL) printf(%s ,fo-_FolderName); fo= fo-nextFolder; printf(n); printf(*n); void Delete(char fName) printf(%s,fName); int isExist=0; char fSavePath255; /文件或文件夹存储完整路径 strcpy(fSavePath,currentDir); _File *fi; fi=firstFile; while(fi-nextFile !=NULL) if(strcmp(fi-_FileName,fName)=0) isExist=1; break; fi=fi-nextFile; if(isExist=1) strcat(fSavePath,/); strcat(fSavePath,fName); remove(fSavePath); printf(nFile %s delete success!n,fName); _Folder *fo; fo = firstFolder; while(fo-nextFolder !=NULL) if(strcmp(fo-_FolderName,fName)=0) isExist=1; break; fo = fo-nextFolder; if(isExist=1) strcat(fSavePath,/); strcat(fSavePath,fName); rmdir(fSavePath); printf(n Folder %s delete success!n,fName); TraverseFolder(currentDir);void CatFile(char fName) char ch; int isExist=0; char fSavePath255; /文件或文件夹存储完整路径 strcpy(fSavePath,currentDir); _File *fi; fi=firstFile; while(fi-nextFile !=NULL) if(strcmp(fi-_FileName,fName)=0) isExist=1; break; fi=fi-nextFile; if(isExist=1) strcat(fSavePath,/); strcat(fSavePath,fName); FILE *fp; fp=fopen(fSavePath,r); if(fp=NULL) printf(File not exist!n); else printf(n%ss Content : *n,fName); ch=fgetc(fp); while(ch!= EOF) if(ch = n) printf(n); else printf(%c,ch); ch=fgetc(fp); printf(n*End*n); void CreateFolder(char folderName) int dir; char folderPath255; _Folder *fo; fo=firstFolder; while(fo-nextFolder !=NULL) if(strcmp(fo-_FolderName,folderName)=0) printf(Folder is Exist! Create failed!n); return; fo =fo-nextFolder; strcpy(folderPath,currentDir); strcat(folderPath,/); strcat(folderPath,folderName); dir = mkdir(folderPath,0777); if(dir = -1) printf(nCreate Folder Failed!n); else printf(nCreate Folder Success!n); TraverseFolder(currentDir);void AddContent(char fName) char ch; int i; char inputs500; int isExist=0; char fSavePath255; /文件或文件夹存储完整路径 strcpy(fSavePath,currentDir); _File *fi; fi=firstFile; while(fi-nextFile !=NULL) if(strcmp(fi-_FileName,fName)=0) isExist=1; break; fi=fi-nextFile; if(isExist=1) strcat(fSavePath,/); strcat(fSavePath,fName); FILE *fp; fp=fopen(fSavePath,at); if(fp =NULL) printf(Can not addContent to file!n); return; else setbuf(stdin,NULL); printf(Pleasr input content:_(500 words allowed)n); for(i=0;ifatherDir != NULL) rootFolder = rootFolder-fatherDir; for(i=0;i_Dir); TraverseFolder(currentDir); return; _Folder *fo; fo=firstFolder; while(fo-nextFolder != NULL) if(strcmp(fo-_FolderName,folderName)=0) isExist=1; break; else if(fo-nextFolder !=NULL) fo=fo-nextFolder; if(isExist=1) strcpy(sonFolder,currentDir); strcat(sonFolder,/); strcat(sonFolder,folderName); for(i=0;i_Dir,sonFolder); sonDir-fatherDir=rootFolder; rootFolder=sonDir; int userCreate(int sumUsers) char c; char userName20; char userPwd20; int i; if(sumUsers=MaxUser) printf(n create user unsuccess! will Over max users! n); else setbuf(stdin,NULL);/清空缓存 printf(Please input user Name: ); for(i=0;inextUser != NULL) if(!strcmp(userp-_UserName,userName) printf(/n); printf(该用户名已存在,创建用户失败/n); return 0; userp = userp-nextUser; userNamei= ;printf(n); setbuf(stdin,NULL); printf(Please input user password:);for(i=0;i20,c=getchar();i+) if(c=n) break; else us

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论