欢迎来到得力文库 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
得力文库 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    多用户多级目录文件系统的实现-课程设计.doc

    • 资源ID:91491897       资源大小:651KB        全文页数:27页
    • 资源格式: DOC        下载积分:14.9金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要14.9金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    多用户多级目录文件系统的实现-课程设计.doc

    课 程 设 计 课程名称_操作系统 _ 题目名称_多用户多级目录文件系统的实现 _ 学生学院_计算机学院_文件管理系统一 设计目的:编写并调试一个树型目录结构的文件系统,模拟文件管理工作流程。二 设计要求: 设计多用户文件系统,采用多级文件目录。至少要有十个以上的实用命令,应设置文件保护措施。设计一个较实用的用户界面,方便用户使用,界面要为用户提供足够的选择信息,不需用户打入冗长的命令。三 设计内容本程序设计了一个树形目录结构的文件管理系统,初始化系统默认根目录为root,根目录下为11个用户的注册目录,包括一个超级用户su和十个普通用户stud01stud10,初始化的树形分支结构如下:root su stud01 stud02 stud03 stud04 stud05 stud06 stud07 stud08 stud09stud10初始化后各个用户注册目录下均为空,用户可进行创建编辑文件,显示文件内容,删除文件,复制文件,粘贴文件,创建目录,删除目录,更改工作目录,显示当前工作目录的全路径,显示当前目录下的全部内容,寻求帮助及用户切换等操作,当只有目录可以为分支节点创建其目录下的子目录或者文件(这里指的文件为除目录外的终端文件),也可以为叶子节点以待必要的时候在其目录下创建子目录或者文件使其成为分支节点,而文件只能是叶子节点。程序运行时要求输入用户名及其密码,初始化时su和stud01stud10相应的密码分别为su,01stud,02stud,03stud,04stud,05stud,06stud,07stud,08stud,09stud,10stud,系统将验证输入的用户名及其密码,并提示是否输入正确,错误要求重新输入。用户密码只有超级用户su才能更改,普通用户没有权限进行此操作。登录后系统在每个命令提示符前加【用户名】,表示当前的登录用户,若登录用户为su时,命令提示符为#符号,若为普通用户,命令提示符为$符号,而且工作目录也指向当前登录用户的注册目录下。而只有登录用户为su时才可以访问根目录及其所有用户的注册目录下的所有目录以及文件,登录用户为普通用户时只能访问根目录以及当前用户注册目录下的所有子目录和文件,如当前用户为stud01,就无权访问su以及stud02stud10目录下及其目录下的所有子目录和文件。进入系统后,根据系统各命令的功能进行相应的操作,系统所有的命令参数及其功能如下:su,stud01,stud02,stud03,stud04,stud05,stud06,stud07,stud08,stud09,stud10:输入用户名进行用户切换,输入用户名后系统会要求输入用户密码,只有输入正确,用户切换才能成功;pwd:显示当前工作目录的全路径名; ls:列出当前目录下的内容,包括所有子目录以及文件,列出时在目录名后面标记“/”,在终端文件后面标记“*”; mkdir:在当前目录下建立子目录,输入此命令后,系统提示“directory name:”,要求输入要建立的子目录名,倘若当前目录下已经存在同名子目录,系统会提示“directory already exist”; rmdir:删除当前目录下已经存在的子目录,输入此命令后,系统提示“directory name:”,即输入要删除的子目录名,倘若你要删除的子目录在当前目录下不存在,系统提示“directory not exist”;vi:在当前目录下建立编辑文件,输入此命令后,系统提示“file name:”,要求输入要编辑的文件名,倘若当前目录下已经存在该文件,系统会显示该文件内容,进入编辑界面,若当前目录下没有该文件创建进入编辑界面;vi编辑状态下,提示符为“:”,编辑命令及其功能为:i进行文本行的输入,系统提示输入要输入文本的行,若该行已存在则清空重新等待输入;d删除指定的行,系统提示“linenum:”,输入行数进行删除;list显示当前编辑文本的内容;wq对文本修改进行存储并退出,系统同时提示“Now saving the file!Press any key and exit.”;cat:显示当前目录下文件的内容,输入此命令后,系统提示“file name:”,倘若你要查看的文件不在当前目录下,系统提示“file not exist”; rm:删除当前目录下已经存在的文件,输入此命令后,系统提示“file name:”,倘若你要删除的文件不在当前目录下,系统提示“file not exist”;cd:改变当前目录,输入此命令后,系统提示“directory name or symbol:”,要求输入子目录名字或者父目录标识,当输入子目录名时,若存在,当前的工作目录会改到子目录,若不存在,系统提示“subdirectory not exist!”,当输入“.”时,当前目录会返回到上一级父目录,若当前目录已经是根目录,系统会提示“That is already root directory!”,当输入“/”,工作目录返回到根目录root,当输入“.”,当前的工作目录保持不变,当输入“”,即直接按回车而不输入任何字符,工作目录将返回用户注册目录下;cp:复制文件内容到缓冲区以备粘贴,输入此命令后,系统提示“file name:”,倘若你要复制的文件不在当前目录下,系统提示“file not exist”;paste:创建新的文件并将缓冲区的内容写进或者用缓冲区的内容覆盖已存在文件的内容,输入此命令后,系统提示“file name:”,若当前目录下不存在此文件,则创建并写将缓冲区的内容,若存在,系统提示“File already exist!Cover it or not?y/n:”,输入y或Y覆盖原有文件,输入n或N拒绝此操作。chpw:在超级用户状态下更改用户密码,如当前用户不为su运行此命令,系统会提示“You have no right to change user password!”; help:查看系统命令参数的功能;exit:退出文件管理系统。四 程序运行举例程序运行时,当输入用户名su和密码su后系统提示登录成功,按任意键进入文件管理界面。进入用户操作界面后,由于当前的用户为su,故命令提示符为#,提示符前也会显示当前用户名,输入pwd确定当前的工作目录,登录后系统默认目录为用户注册目录/root/su。在当前目录下创建新的目录chaoyang和新的文件QQ,并编辑文件QQ,最后用wq保存并退出,用ls命令查看当前目录下的所有内容,目录名的后缀为/,文件为*。当输入命令为copy时,系统提示“command not found”,即不存在此命令参数,当输入cp而输入要复制的文件名为chaoyang,系统提示要复制的文件不存在“file not exist”,随后复制文件QQ并粘贴创建新的文件ye,用cat命令查看文件内容,可确定复制成功。用ls查看当前目录下的全部内容并用rm命令删除文件QQ,用ls确定是否已删除该文件。进行工作目录更改,运行命令cd,根据提示“directory name or symbol:”输入chaoyang,进入chaoyang目录下,用pwd查看目录路径确认,用cd加标志/返回根目录,用cd返回用户注册目录下。用命令cd加标识“.”返回当前工作目录的上一级目录,如/root/su返回到/root,在根目录下用cd命令,根据要求输入用户名进入该用户的注册目录访问,若当前的登录用户不为超级用户,无权访问其他用户的注册目录及其以下所有内容。输入用户名stud01,系统要求输入相应的密码01stud,若验证成功命令提示符变为$,其左边为stud01,表明当前的登录用户已切换到stud01,返回到root目录下运行cd加目录名stud02,企图进入目录stud02进行访问,系统提示“Current user don't access other users' files or dirrctory!”,即普通用户不能访问其他用户注册目录及其一下所有文件和子目录。在登录用户为stud01的情况下,输入命令chpw,系统提示你没有权力更改用户密码“You have no right to change user password!”,重新切换到用户su,将stud01用户的登录密码改为01,运用新的密码重新登录。返回工作目录到根目录下,进行创建目录,创建文件,删除目录,删除文件,系统会警告“Don't allow this operation in root directory!”,在根目录下不允许这些操作,即使在超级用户下也不行。运行help参看命令参数及其功能。五 设计思想创建节点的结构属性为:struct nodechar name256;/*节点名称*/char code256;/*若节点为用户注册目录,保存相应的用户密码*/int attribute;/*attribute为1时表示节点为目录,为0表示节点为文件*/struct node *parent,*firstchild,*nextsibling;/*定义双亲节点,孩子节点,兄弟节点*/struct line *start,*last;*p;/*定义节点的结构属性*/指针p时刻指向当前的工作目录,fistchild指向节点的第一个孩子,nextsibling链接相邻的节点以便进行访问。文件以及目录的创建,查看,复制,粘贴,删除等所有操作都是基于结构体以及链表的操作,同时编辑文件的操作也是采用链表对编辑内容进行记忆,所以所有操作并不是实际的磁盘操作,只有程序运行完才释放所有的内存空间。因此只要程序运行完重新运行,原先在初始化目录下进行的相关操作结果都不会存在,这也是该程序局限性所在,有待改善。六 程序运行环境本程序是在Turboc2.0下设计和调试的,设计语言为C语言。七 设计感悟在熟悉unix文件系统结构的基础上,通过所学的C语言和数据结构知识设计此文件管理系统,深化了自己对C语言以及链表结构体等数据结构的理解和应用,同时加深了对操作系统之文件系统中文件和目录相关操作与内存磁盘分配和释放的关系。八 源程序及其注释#include"string.h"#include"stdio.h"#include"stdlib.h"#include"math.h"#include"conio.h"#define getnode(type)(type*)malloc(sizeof(type)char sign;/*命令提示符*/char title256;/*当前用户名*/int num=255;int symbol=0;int show=0;char str256;struct linechar text81;int num;/*行号*/struct line *next;/*指向下一个输入项目的指针*/struct line *prior;/*指向前一项目的指针*/;/*定义文件编辑行的结构属性*/struct line *start;/*指向表中第一项目的指针*/struct line *last;/*指向表中最后一个项目的指针*/struct line *begin;/*指向缓冲区第一项目的指针*/struct line *end;/*指向缓冲区最后一个项目的指针*/struct line *find(),*dls_store();struct nodechar name256;/*节点名称*/char code256;/*若节点为用户注册目录,保存相应的用户密码*/int attribute;/*attribute为1时表示节点为目录,为0表示节点为文件*/struct node *parent,*firstchild,*nextsibling;/*定义双亲节点,孩子节点,兄弟节点*/struct line *start,*last;*p;/*定义节点的结构属性*/typedef struct node NODE;NODE *root,*g,*su,*user1,*user2,*user3,*user4,*user5,*user6,*user7,*user8,*user9,*user10;main()p=getnode(NODE);initialization();entry();while(symbol=0)clrscr();entry();clrscr();printf("%s%c",title,sign);while(num!=0)gets(str);operation();switch(num)case 1:pwd();printf("n%s%c",title,sign);num=255;break;case 2:ls();printf("n%s%c",title,sign);num=255;break;case 3:mkdir();printf("n%s%c",title,sign);num=255;break;case 4:cd();printf("n%s%c",title,sign);num=255;break;case 5:vi();printf("n%s%c",title,sign);num=255;break;case 6:rm();printf("n%s%c",title,sign);num=255;break;case 7:rmdir();printf("n%s%c",title,sign);num=255;break; case 8:help();printf("n%s%c",title,sign);num=255;break;case 9:cat();printf("n%s%c",title,sign);num=255;break;case 10:change();printf("n%s%c",title,sign);num=255;break;case 11:copy();printf("n%s%c",title,sign);num=255;break;case 12:paste();printf("n%s%c",title,sign);num=255;break;case 13:chpw();printf("n%s%c",title,sign);num=255;break;default:printf("ncommand not foundn%s%c",title,sign);initialization()/*初始化根目录和用户目录*/root=getnode(NODE);strcpy(root->name,"root");root->attribute=1;root->parent=NULL;user10=getnode(NODE);strcpy(user10->name,"stud10");strcpy(user10->code,"10stud");user10->attribute=1;user10->parent=root;user10->firstchild=NULL;user10->nextsibling=NULL;user9=getnode(NODE);strcpy(user9->name,"stud09");strcpy(user9->code,"09stud");user9->attribute=1;user9->parent=root;user9->firstchild=NULL;user9->nextsibling=user10;user8=getnode(NODE);strcpy(user8->name,"stud08");strcpy(user8->code,"08stud");user8->attribute=1;user8->parent=root;user8->firstchild=NULL;user8->nextsibling=user9;user7=getnode(NODE);strcpy(user7->name,"stud07");strcpy(user7->code,"07stud");user7->attribute=1;user7->parent=root;user7->firstchild=NULL;user7->nextsibling=user8;user6=getnode(NODE);strcpy(user6->name,"stud06");strcpy(user6->code,"06stud");user6->attribute=1;user6->parent=root;user6->firstchild=NULL;user6->nextsibling=user7;user5=getnode(NODE);strcpy(user5->name,"stud05");strcpy(user5->code,"05stud");user5->attribute=1;user5->parent=root;user5->firstchild=NULL;user5->nextsibling=user6;user4=getnode(NODE);strcpy(user4->name,"stud04");strcpy(user4->code,"04stud");user4->attribute=1;user4->parent=root;user4->firstchild=NULL;user4->nextsibling=user5;user3=getnode(NODE);strcpy(user3->name,"stud03");strcpy(user3->code,"03stud");user3->attribute=1;user3->parent=root;user3->firstchild=NULL;user3->nextsibling=user4;user2=getnode(NODE);strcpy(user2->name,"stud02");strcpy(user2->code,"02stud");user2->attribute=1;user2->parent=root;user2->firstchild=NULL;user2->nextsibling=user3;user1=getnode(NODE);strcpy(user1->name,"stud01");strcpy(user1->code,"01stud");user1->attribute=1;user1->parent=root;user1->firstchild=NULL;user1->nextsibling=user2;su=getnode(NODE);strcpy(su->name,"su");strcpy(su->code,"su");su->attribute=1;su->parent=root;su->firstchild=NULL;su->nextsibling=user1;root->firstchild=su;root->nextsibling=NULL;entry()/*系统登录界面,验证用户及密码*/int h;char username256,password256;h=0;g=getnode(NODE);g=su;printf("nn");printf("tt*FILE MANAGE SYSTEM*n");printf("nnnnnnn");printf("ttuser:");gets(username);printf("n");printf("ttpassword:");gets(password);while(g!=NULL)if(strcmp(username,g->name)=0)h=1;if(strcmp(password,g->code)=0)symbol=1;printf("nttSucceed in logging on!Press any key and enter.");p=g;if(strcmp(username,"su")=0) sign='#'else sign='$'strcpy(title,username);else printf("nttIncorrect password!");break;else g=g->nextsibling;if(h=0) printf("nttIncorrect username!");getch();change()/*切换用户*/NODE *u;char password256;printf("npassword:");gets(password);u=root->firstchild;while(strcmp(str,u->name)!=0)u=u->nextsibling;if(strcmp(password,u->code)!=0) printf("nIncorrect password!");elsep=u;g=u;strcpy(title,str);if(strcmp(str,"su")=0) sign='#'else sign='$'begin=NULL;end=NULL;show=0;operation()/*验证输入的命令参数*/NODE *u;u=root->firstchild;if(strcmp(str,"exit")=0)num=0;else if(strcmp(str,"pwd")=0)num=1;else if(strcmp(str,"ls")=0)num=2;else if(strcmp(str,"mkdir")=0)num=3;else if(strcmp(str,"cd")=0)num=4;else if(strcmp(str,"vi")=0)num=5;else if(strcmp(str,"rm")=0)num=6;else if(strcmp(str,"rmdir")=0)num=7;else if(strcmp(str,"help")=0)num=8;else if(strcmp(str,"cat")=0)num=9;else if(strcmp(str,"cp")=0)num=11;else if(strcmp(str,"paste")=0)num=12;else if(strcmp(str,"chpw")=0) num=13;else while(u!=NULL&&strcmp(str,u->name)!=0)u=u->nextsibling;if(u!=NULL)num=10;pwd()/*显示当前的工作路径*/NODE *t,*L,*k;L=getnode(NODE);L->firstchild=NULL;t=p;dok=getnode(NODE);strcpy(k->name,p->name);k->firstchild=L->firstchild;L->firstchild=k;p=p->parent;while(p!=NULL);for(k=L->firstchild;k!=NULL;k=k->firstchild)printf("/%s",k->name);printf("n");p=t;mkdir()/*创建子目录*/if(p!=root)NODE *q,*t,*w;t=p;w=p;q=getnode(NODE);printf("ndirectory name:");scanf("%s",q->name);q->attribute=1;w=w->firstchild;while(strcmp(w->name,q->name)!=0|w->attribute!=1)&&w!=NULL)w=w->nextsibling;if(w!=NULL) printf("ndirectory already exist");elseq->parent=p;q->firstchild=NULL;q->nextsibling=p->firstchild;p->firstchild=q;p=t;gets(str);else printf("nDon't allow this operation in root directory!");ls()/*显示当前目录下的所有内容,后缀为/的表示目录,*的表示文件*/NODE *t;t=p;p=p->firstchild;printf("n");while(p!=NULL)if(p->attribute=1) printf("%s/t",p->name);else printf("%s*t",p->name);p=p->nextsibling;p=t;cd()/*改变当前的工作目录*/NODE *t;int flag=1;printf("ndirectory name or symbol:");gets(str);if(strcmp(str,".")=0)/*返回当前目录的上一级目录*/if(p->parent!=NULL) p=p->parent;else printf("nThat is already root directory!");else if(strcmp(str,"")=0)/*返回用户注册子目录*/p=g;else if(strcmp(str,"/")=0)/*返回根目录*/while(p->parent!=NULL) p=p->parent;else if(strcmp(str,".")=0)/*保持当前目录不变*/else/*当前目录改变为指定的子目录*/if(p!=root|sign!='$')t=p;p=p->firstchild;while(p!=NULL&&flag)if(strcmp(str,p->name)=0&&p->attribute=1) flag=0;else p=p->nextsibling;if(p=NULL)printf("nsubdirectory not exist!");p=t;elseif(strcmp(str,g->name)!=0)printf("nCurrent user don't access other users' files or dirrctory!");else p=g;rm()/*删除文件*/if(p!=root)NODE *t,*s;t=p;printf("nfile name:");gets(str);p=p->firstchild;if(strcmp(str,p->name)=0&&p->attribute=0)t->firstchild=p->nextsibling;p=t;elsewhile(strcmp(str,p->name)!=0|p->attribute!=0)&&p!=NULL)s=p;p=p->nextsibling;if(p!=NULL)s->nextsibling=p->nextsibling;free(p);else printf("nfile not exist");p=t;else printf("nDon't allow this operation in root directory!");rmdir()/*删除子目录*/if(p!=root)NODE *t,*s;t=p;printf("ndirectory name:");gets(str);p=p->firstchild;if(strcmp(str,p->name)=0&&p->attribute=1)t->firstchild=p->nextsibling;p=t;elsewhile(strcmp(str,p->name)!=0|p->attribute!=1)&&p!=NULL)s=p;p=p->nextsibling;if(p!=NULL)s->nextsibling=p->nextsibling;free(p);else printf("ndirectory not exist");p=t;else printf("nDon't allow this operation in root directory!");help()/*提示命令参数功能*/printf("n*COMMAND PARAMETER*n");printf("su,stud01,stud02,stud03,stud04,stud05,stud06,stud07,stud08,stud09,stud10:n");printf(" help you switch to other user;n");printf("pwd:display the path of current directory or file;n");printf("ls:display all subdirectory and file under current directory,symbol * n");printf(" denotes file name,symbol / denotes directory name;n"); printf("mkdir:create a subdirectory under current directory;n");printf("rmdir:delete a subdirectory under current directory;n");printf("vi:create a file under current directory and edit;n");printf("rm:create a file under current directory;n");printf("cat:display file content;n");printf("cp:copy file content into buffer and save;n");printf("paste:creat a file and overwrite with buffer content;n");printf("cd:choose the path and enter into subdurectory or parent directory,n");printf("tfor enample,when system requests to input the subdirectory name or then");printf(" parent directory symbol,if you input subdirectory name,current directoryn");printf(" will point to the subdirectory,if you input .,current directory willn");printf(" point to father directory,if you input /,current directory will pointn");printf(" to root directory,if you input .,current director

    注意事项

    本文(多用户多级目录文件系统的实现-课程设计.doc)为本站会员(沧海****B)主动上传,得力文库 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知得力文库 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于得利文库 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

    © 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

    黑龙江省互联网违法和不良信息举报
    举报电话:0468-3380021 邮箱:hgswwxb@163.com  

    收起
    展开