首页 多用户多级目录结构文件系统设计与实现毕业设计(论文)word格式

多用户多级目录结构文件系统设计与实现毕业设计(论文)word格式

举报
开通vip

多用户多级目录结构文件系统设计与实现毕业设计(论文)word格式多用户多级目录结构文件系统设计与实现毕业设计(论文)word格式 操作系统课程设计 姓名: 学号: 班级: 电话: 邮箱: 课程设计题目: 一个多用户多级目录结构文件系统设计与实现 编译环境: Linux 运行环境: Linux 一、设计思想说明 1 设计环境 课程设计的环境是Linux 操作系统。 设计时可利用Linux 提供的文件管理的功能调用,建立一个模拟的文件系统。基本思想是,在Linux 系统中创建一个较大容量的文件,作为所设计的文件系统的“文件卷”,并利用Linux 系统的功能...

多用户多级目录结构文件系统设计与实现毕业设计(论文)word格式
多用户多级 目录 工贸企业有限空间作业目录特种设备作业人员作业种类与目录特种设备作业人员目录1类医疗器械目录高值医用耗材参考目录 结构文件系统 设计 领导形象设计圆作业设计ao工艺污水处理厂设计附属工程施工组织设计清扫机器人结构设计 与实现毕业设计(论文)word 格式 pdf格式笔记格式下载页码格式下载公文格式下载简报格式下载 操作系统课程设计 姓名: 学号: 班级: 电话: 邮箱: 课程设计题目: 一个多用户多级目录结构文件系统设计与实现 编译环境: Linux 运行环境: Linux 一、设计思想说明 1 设计环境 课程设计的环境是Linux 操作系统。 设计时可利用Linux 提供的文件管理的功能调用,建立一个模拟的文件系统。基本思想是,在Linux 系统中创建一个较大容量的文件,作为所设计的文件系统的“文件卷”,并利用Linux 系统的功能调用,编写各程序模块。 2、文件卷的组织 以 1M 的存储器空间作为文件空间,空间“分块”,编号为 0#,(BLKMAX-1)# 。“分块”就是规定对文件卷的读/写以块为单位,每次读/写的起点为块大小的整倍数。分块主要体现在文件卷的读/写模块上。 # define BSIZE 512 /* 512bytes/块 */ # define BLKMAX 2048 /* 共2048 块 */ 块的作用: 0# 块是专用块(超级块)。前半部用于存放文件卷空间的位示图0# (bitmap),位状态='0' 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf 示对应块空闲,状态='1'表示已分配。后半部的最后32 个字节用 (BLKMAX-1)#块用于存放于存放根目录的目录结构。0#块不参与文件空间的动态分配。1#, 文件(普通文件和子目录文件)的信息。 二、系统结构的说明 本文件管理系统分为五层,上层调用下层,下层为上层服务。以下为各层(由低到高)的简要说明: 1、块管理层,通过TBlock类实现 设下列主要函数: balloc()--块分配函数 brelse()--块释放函数 bread()—读一块函数 bwrite()—写一块函数 2、FCB管理层,通过TFcb类实现 功能涉及到FCB结构的操作,定义了一些与FCB操作相关的函数 3、打开文件管理层,通过TOFile类实现 功能为涉及ofile结构的操作。 4、命令解释层,通过TEnter类和TOrder类实现 功能为接受来自用户的命令,并解释、执行用户提出的文件访问操作。按系统的的功能 要求,可以Open(),Close(),Read(),Write();等函数。 三、数据结构的说明 用户信息的存储结构: struct UserNode//注册用户信息 { char d_flag; //标识该用户信息是否有效,超级用户为用户数目,,1表示无效 char d_uid; /*用户标识,为0时表示是超级*/ char d_gid; /*同组用户标识*/ char d_name[8];/*用户名,但不超过八个字节,超过八位自动截取*/ char password[8];/*用户密码但不超过八位,超过八位自动截取*/ }; 目录文件结点信息存储结构: struct dir { unsigned short d_mode; //文件属性及访问权限,<=0时为空结构 char d_uid; //文件主标识 char d_gid; //文件主同组用户标识 int d_fsize; //文件大小(字节),作为目录结构时为该目录下文件个数 char d_name[8]; //文件名 int d_add[10]; //存放文件信息的空间地址(块号) }; Fcb在内存中的结构: struct SFcb { char f_count; /*文件访问计数*/ char f_flag; /*标志字*/ int f_blkno; /*存放本文件目录结构的块号*/ int f_number; /*文件目录结构所在块内偏移序号*/ unsigned short f_mode; /*文件属性*/ /*以下各项信息在文件打开时从struct dir获取*/ char f_uid; char f_gid; int f_fsize; char f_name[8]; int f_add[10]; }; 文件目录存储位置存储结构: struct Hfcb//用于Namei函数,返回文件目录结构存储位置 { int blkno; //存放本文件目录结构的块号 int offset; //文件目录结构所在块内偏移序号 }; 打开文件结构: struct HOFile { char o_flag; //标志字 int o_count; //访问计数 struct SFcb* o_fcbp; //对就打开文件FCB结构指针 int o_offset; //文件当前读/写指针 }; 内存中的用户结点结构: struct TUser { char u_name[8]; //用户名,登录时使用 char u_uid; //用户标识,文件创建时的文件主 char u_gid; //同组用户标识 struct SFcb *u_cdir; //现行工作目录标识 int u_error; //执行文件管理函数时返回的错误代码,创建文件时被用来存储文件 设置 char*u_base; //读/写文件时信息存储区始址 int u_count; //读/写文件时信息字节数 int u_offset; //读/写文件的相对位移量 char u_obuf[8]; //文件路径名分量暂存区(查找文件时用) struct SFcb* u_pdir; //新文件父目录FCB指针(文件创建时用) struct HOFile *u_ofile[5];//本用户打开文件表 }; 四、算法 流程 快递问题件怎么处理流程河南自建厂房流程下载关于规范招聘需求审批流程制作流程表下载邮件下载流程设计 图 开始 Y 第一次运行, 初始化 N 用户登陆 N 登陆成功, Y 接收命令 解析命令 N 退出, 实现命令 Y 结束 五、系统调用列表 系统调用原型 功能 入口、出口参数说明 void Cd(string para) 设置目录 para为要打开的文件名 void Cd__() 返回上层目录 void Create(string str) 创建文件 str为要建立的文件的文件名 void Del(string para) 删除文件 para为要删除的文件名 void Dir() 列文件目录 void Exit() 退出系统 void Help() 输出帮助文件 void Md(string para) 建立目录 para为要建立的目录名 void Rd(string para) 删除目录 para为要删除的目录名 void Set(string para) 调整文件属性 para为要调整的文件名 void Wr(string para) 写入文件 para为要写入的文件名 六、主要函数列表 函数原型 功能 入口、出口参数说明 int TBlock::Balloc() 块分配 bool TFcb::CD(char* 设置文件目录 dirname为目录名,user为当dirname,TUser& user) 前的用户结构指针 bool TFcb::CD__(TUser 返回上一级目录 user为当前的用户结构指针 &user) bool TFcb::CreateDir(char* 建立一个目录 dirname为目录名,user为当dirname,TUser& user) 前的用户结构指针 bool TFcb::DelDir(char* 删除目录 dirname为目录名,user为当dirname,TUser& user) 前的用户结构指针 bool TFcb::DelFile(char* 删除文件 filename为文件名,user为当filename,TUser& user) 前的用户结构指针 void TFcb::Directory(TUser& 获取当前目录信息 user为当前的用户结构指针 user) bool TFcb::FCFile(char* 创建文件 filename为文件名,user为当filename,TUser& user) 前的用户结构指针 void 初始化 info为初始的用户信息结构 TBlock::FirstInit(USERINFO 实体 info) void TFcb::JustWrRight(char* 判断用户是否对该文件有写fname为文件名,user为当前fname,TUser& user) 权限 的用户结构指针 bool TFcb::OpenFile(char* 打开文件 fdname为文件名,user为当fdname,TUser& user) 前的用户结构指针 void TFcb::ReadFile(char* 读出文件 fname为文件名,user为当前fname,TUser& user) 的用户结构指针 void TFcb::SetFile(int 更改文件权限 flag为新权限标识,fname为flag,TUser& user,char* 文件名,user为当前的用户结fname) 构指针 bool TFcb::Write(dir* td) 写文件 dir为文件所在目录的结构 七、程序清单及注析 1、 以下为block.h的内容: #include #include #include #include #include #include using namespace std; #define BLOCK 512 #define BLOCKNUM 2048 #define DN 8 #define USERNUM 10 //最大用户数 #define FILENUM 9 //每个块能存储的文件目录结构数量 /*FCB标志字(f_flag)的各种标志定义为:*/ #define FLOCK 01 /*FCB访问互斥标志*/ #define FUPD 02 /*本FCB代表的文件已修改*/ #define FCHG 04 /*本FCB结构中某些信息已被修改*/ #define FCBFLAG 05 //本fcb结构未被使用 #define FCBUSE 07 //本fcb结构已被使用 #define OFFLAG 06 //本HOfile结构未被使用 #define OFUSE 03 //本HOfile结构已被使用 //文件属性及文件访问权限(即d_mode和f_mode)定义: #define ROOT 111 #define IFROOT 011 //子目录中存储父目录的结构 #define IFMT 0070000 //文件类型屏蔽字 #define IFDIR 0010000 //子目录文件 #define IFREG 0020000 //普通文件 #define IREAD 0400 //文件主“读”权限 #define IWRITE 0200 //文件主“写”权限 #define IEXEC 0100 //文件主“执行”权限 #define GREAD 040 //同组用户“读”权限 #define GWRITE 020 //同组用户“写”权限 #define GEXEC 010 //同组用户“执行”权限 #define OREAD 04 //其它用户“读”权限 #define OWRITE 02 //其它用户“写”权限 #define OEXEC 01 //其它用户“执行”权限 #define NONODE 100 inline bool bit_on(unsigned char ui,int pos){return ui&(1<2048) break; bit=i%DN; byte=(i-bit)/DN; if(bit_on(bitmap[byte],bit)==true) continue; else { bit_setone(bitmap[byte],bit); char* tempbuf=NULL; if((tempbuf=new char[BLOCK])==NULL) { cout<<"内存不足!"<=2048) i=i%2048; } return -1; } void TBlock::Brelse(int bno)//释放块 { int byte,bit; bit=bno%DN; byte=(bno-bit)/DN; bit_setzero(bitmap[byte],bit); char* tempbuf=NULL; tempbuf=new char[BLOCK]; for(int i=0;i=2048) return false; bit=bno%DN; byte=(bno-bit)/DN; if(bit_on(bitmap[byte],bit)==true) { fseek(pf,(long)(bno*BLOCK),SEEK_SET); fread(tempbuf,sizeof(char),BLOCK,pf); return true; } else return false; } bool TBlock::BWrite(int bno,char* tempbuf)//写块函数 { if(bno>=2048||tempbuf==NULL) return false; int byte,bit; bit=bno%DN; byte=(bno-bit)/DN; if(bit_on(bitmap[byte],bit)==false) return false; else { fseek(pf,bno*BLOCK,SEEK_SET); fwrite(tempbuf,sizeof(char),BLOCK,pf); return true; } } void TBlock::CheckFirst()//检查存在操作文件,即模拟磁盘空间的文件,以判断是否是第一次启动系统 { if((pf=fopen("storage","r"))==NULL) TBlock::first=true; else fclose(pf); } void TBlock::CreateFile(USERINFO info)//创建模拟磁盘的文件 { if((pf=fopen("storage","w+"))==NULL) { cout<<"创建文件失败"<d_fsize=BLOCK-sizeof(dir);//根目录结构的块内存储偏移地址 tdir->d_gid=tempdir.d_gid; tdir->d_uid=tempdir.d_uid; tdir->d_mode=tempdir.d_mode; int na; for(na=0;na<8;na++) tdir->d_name[na]=tempdir.d_name[na]; for(i=0;i<10;i++) { tdir->d_add[i]=tempdir.d_add[i]; } tdir->d_add[0]=0; for(i=1;id_mode=NONODE; } BWrite(bno,tchar); delete[]tchar; } void TBlock::FirstInit(USERINFO info)//第一次初始化 { CreateFile(info);//创建模拟磁盘文件 int i=0,byte,bit,j; for(i=0;i<512;i++) buf[i]='\0'; for(i=0;i<2048;i++) { bit=i%DN; byte=(i-bit)/DN; bit_setzero(bitmap[byte],bit); } bit_setone(bitmap[0],0);//分配0#块 int tempbno=Balloc(); for(i=0;i<256;i++) //将bitmap写入buf { buf[i]=(char)bitmap[i]; } USERINFO temp; info.d_flag=1; info.d_uid=0; char* tempchar; tempchar=(char*)(&info); for(j=0;jd_mode==IFDIR)//如果该目录存在则将user中当前目录指针,指向该目录 { user.u_cdir->f_fsize=td->d_fsize; user.u_cdir->f_gid=td->d_gid; user.u_cdir->f_uid=td->d_uid; user.u_cdir->f_mode=td->d_mode; int na; for(na=0;na<8;na++) user.u_cdir->f_name[na]=td->d_name[na]; for(int i=0;i<10;i++) { user.u_cdir->f_add[i]=td->d_add[i]; } user.u_cdir->f_blkno=fd.blkno; user.u_cdir->f_number=fd.offset; delete[]tempbuf; return true; } else { cout<<"Can not find the DIR!\n"; delete[]tempbuf; return false; } } bool TFcb::CD__(TUser &user)//用于cd..命令,进入上一层目录 { char* tempbuf=NULL; if((tempbuf=new char[BLOCK])==NULL) { cout<<"RAM deficient!"<f_add[0],tempbuf);//读出存在子目录中根目录的信息 dir* td=(dir*)(tempbuf); blk=td->d_add[0]; offset=td->d_fsize; block.Bread(blk,tempbuf);//从真正存放根目录的地方读出跟目录信息 td=(dir*)(tempbuf+offset); if(td->d_mode==IFDIR||td->d_mode==IFROOT||td->d_mode==ROOT)//确保该目录的存在 { user.u_cdir->f_fsize=td->d_fsize; user.u_cdir->f_gid=td->d_gid; user.u_cdir->f_uid=td->d_uid; user.u_cdir->f_mode=td->d_mode; int na; for(na=0;na<8;na++) user.u_cdir->f_name[na]=td->d_name[na]; for(int i=0;i<10;i++) { user.u_cdir->f_add[i]=td->d_add[i]; } user.u_cdir->f_blkno=blk; user.u_cdir->f_number=offset; delete[]tempbuf; return true; } else { cout<<"Can not find the DIR!\n"; delete[]tempbuf; return false; } } bool TFcb::CheckUW(char* tempuser,char* tempw,TUser& refuser)//用户登陆时,验证用户名和密码 { if(tempuser==NULL||tempw==NULL) return false; int i=0,basic=256,f; USERINFO *un=NULL; char* tempbuf=NULL; if((tempbuf=new char[512])==NULL) { cout<<"RAM deficient!\n"; exit(0); } if((block.Bread(0,tempbuf))==false)//读出存储用户信息的块即#0块 return false; for(i=0;id_flag==-1)//判断该位置是不是存储了用户信息 continue; else { if((strcmp(tempuser,un->d_name))==0)//判断是否是该用户 { if((strcmp(tempw,un->password))==0)//判断密码是否相符 { //初始化根目录的fcb dir* tempdir=(dir*)(tempbuf+BLOCK-sizeof(dir)); int tempnum=Balfcb(); //初始化user if(tempnum==-1) cout<<"Can not build so many FCB's!\n"; tfcb[tempnum].f_count=1; tfcb[tempnum].f_flag=FCBUSE; tfcb[tempnum].f_blkno=0; tfcb[tempnum].f_number=BLOCK-sizeof(dir); tfcb[tempnum].f_uid=tempdir->d_uid; tfcb[tempnum].f_gid=tempdir->d_gid; tfcb[tempnum].f_fsize=tempdir->d_fsize; tfcb[tempnum].f_mode=tempdir->d_mode; int na; for(na=0;na<8;na++) tfcb[tempnum].f_name[na]=tempdir->d_name[na]; for(f=0;f<10;f++) tfcb[tempnum].f_add[f]=tempdir->d_add[f]; //初始化用户结构 for(na=0;na<8;na++) user[fun].u_name[na]=un->d_name[na]; user[fun].u_uid=un->d_uid; user[fun].u_gid=un->d_gid; user[fun].u_cdir=&tfcb[tempnum]; for(f=0;f<5;f++) user[fun].u_ofile[f]=NULL; delete[]tempbuf; return true; } else continue; } else continue; } } return false; } bool TFcb::CreateDir(char* dirname,TUser& user)//创建目录 { Hfcb fd; fd=Namei(dirname,user);//查找是否存在同名文件目录 if(fd.blkno!=-1) { cout<<"A DIR in the name have existed!\n"; return false; } fd=FindFree(user);//查找空闲的存储区域 int i; if(fd.blkno==-1) { cout<<"Storage space deficient!\n"; return false; } char* tempbuf=NULL; if((tempbuf=new char[BLOCK])==NULL) { cout<<"RAM deficient!\n"; return false; } char* tempblock=NULL; if((tempblock=new char[BLOCK])==NULL) { cout<<"RAM deficient!\n"; return false; delete[]tempbuf; } for(i=0;id_add[i]=-1; newdir->d_gid=user.u_gid; newdir->d_uid=user.u_uid; newdir->d_mode=IFDIR; newdir->d_fsize=1; int na; for(na=0;na<8;na++) newdir->d_name[na]=dirname[na]; if((newdir->d_add[0]=block.Balloc())==-1)//为新建的目录,分配一个空闲块 { cout<<"Storage space deficient!\n"; delete[]tempbuf; delete[]tempblock; return false; } else { block.Bread(newdir->d_add[0],tempblock);//读出当前目录结构的块 dir* rootdir=(dir*)(tempblock);//子目录中存储上一层目录结构(类似于DOS中..目录 的作用) for(i=0;i<10;i++) { rootdir->d_add[i]=-1; } rootdir->d_add[0]=user.u_cdir->f_blkno;//父目录所存储的块 rootdir->d_fsize=user.u_cdir->f_number;//父目录存储在块中的偏移地址 rootdir->d_gid=user.u_cdir->f_gid; rootdir->d_uid=user.u_cdir->f_uid; rootdir->d_mode=IFROOT; int na=0; for(na=0;na<8;na++) rootdir->d_name[na]=user.u_cdir->f_name[na]; for(i=1;id_mode=NONODE; } user.u_cdir->f_fsize+=1; TFcb::SaveDirfcb(user.u_cdir);//将修改后的父目录结构写回磁盘 block.BWrite(fd.blkno,tempbuf);//将目录文件结构写入磁盘 block.BWrite(newdir->d_add[0],tempblock);//将子目录下面的信息写入磁盘 delete[]tempbuf; delete[]tempblock; return true; } } void TFcb::Directory(TUser& user)//用于dir命令 { char* tempbuf=NULL; int i=0,j,count,k; dir* tempdir=NULL; if((tempbuf=new char[BLOCK])==NULL) { cout<<"RAM deficient!\n"; return ; } for(i=0;if_fsize;i++)//遍历所以有目录结构 { if(user.u_cdir->f_add[i]<=0||user.u_cdir->f_add[i]>=2048) { break; } else { block.Bread(user.u_cdir->f_add[i],tempbuf); for(j=0;jf_fsize;j++) { tempdir=(dir*)(tempbuf+j*sizeof(dir)); if(tempdir->d_mode!=NONODE)//说明些结构已经被使用 { if(tempdir->d_mode==IFDIR||tempdir->d_mode==IFROOT)//为子目录时 { if(tempdir->d_mode==IFROOT) cout<<".."<<" "; else { for(k=0;k<8;k++) cout<d_name[k]; } cout<<" "; cout<<""<d_name[k]; cout<<" "; cout<d_fsize<<"B"; cout<<" "; if(tempdir->d_mode==IREAD) cout<<"self\"read\"\n"; if(tempdir->d_mode==IWRITE) cout<<"self\"write\"\n"; if(tempdir->d_mode==IEXEC) cout<<"self\"run\"\n"; if(tempdir->d_mode==GREAD) cout<<"group\"read\"\n"; if(tempdir->d_mode==GWRITE) cout<<"group\"write\"\n"; if(tempdir->d_mode==GEXEC) cout<<"group\"run\"\n"; if(tempdir->d_mode==OREAD) cout<<"other\"read\"\n"; if(tempdir->d_mode==OWRITE) cout<<"other\"write\"\n"; if(tempdir->d_mode==OEXEC) cout<<"other\"run\"\n"; count++; } } else continue; } } } delete[]tempbuf; } bool TFcb::DelDir(char* dirname,TUser& user)//删除目录 { Hfcb fd=Namei(dirname,user);//查找该目录结构存储的位置 if(fd.blkno==-1) { cout<<"Can not find the DIR!\n"; return false; } char* tempbuf=NULL; if((tempbuf=new char[BLOCK])==NULL) { cout<<"RAM deficient!\n"; return false; } block.Bread(fd.blkno,tempbuf); dir* td=(dir*)(tempbuf+fd.offset); if(td->d_uid==user.u_cdir->f_uid||user.u_cdir->f_uid==0)//判断该用户是否有权限删除该目录 { if(td->d_fsize>1)//如果该目录下还有文件或目录(..目录除外),则不能删除 { cout<<"Can not delete a not empty DIR!\n"; return false; } int i; for(i=0;i<10;i++)//释放该目录所占用的磁盘块 { if(td->d_add[i]>0&&td->d_add[i]<2048) { block.Brelse(td->d_add[i]); } else break; } td->d_mode=NONODE;//将置目录结构置为空闲状态 user.u_cdir->f_fsize-=1;//将父目录中文件目录数量减1 SaveDirfcb(user.u_cdir);//将父目录结构写回磁盘 block.BWrite(fd.blkno,tempbuf);//将修改后的目录结构块写回磁盘 delete[]tempbuf; return true; } else { cout<<"You have no right to delete the DIR!\n"; return false; } } bool TFcb::DelFile(char* filename,TUser& user)//删除文件。用于del命令 { Hfcb hf; hf=Namei(filename,user);//查找该文件结构存储的位置 if(hf.blkno==-1) { cout<<"Can not find the file!\n"; return false; } char* tempbuf=NULL; if((tempbuf=new char[BLOCK])==NULL) { cout<<"RAM deficient!\n"; return false; } block.Bread(hf.blkno,tempbuf); dir* fd=(dir*)(tempbuf+hf.offset); if(fd->d_mode==IFDIR) { cout<<"Can not find the file!\n"; delete[]tempbuf; return false; } if(fd->d_uid==user.u_uid||user.u_uid==0)//user为文件主或超级用户 { fd->d_mode=NONODE; for(int i=0;i<10;i++)//释放文件所占的块空间 { if(fd->d_add[i]>0&&fd->d_add[i]<2048) { //cout<<"add"<d_add[i]<d_add[i]); } else break; } block.BWrite(hf.blkno,tempbuf); user.u_cdir->f_fsize-=1; SaveDirfcb(user.u_cdir);//将当前目录的fcb写回硬盘 delete[]tempbuf; return true; } else { cout<<"You have no right to delete the file!\n"; return false; delete[]tempbuf; } } bool TFcb::FCFile(char* filename,TUser& user)//用于create命令,创建文件 { if(filename==NULL) return false; Hfcb fdpos; dir* td=NULL; char* tempbuf=NULL; fdpos=Namei(filename,user);//查找是否存在同名目录文件 if(fdpos.blkno!=-1) { cout<<"The file have existed!\n"; return false; } else { fdpos=FindFree(user);//查找空闲的文件目录结构空间 if(fdpos.blkno==-1)//未到空闲空间 { cout<<"Storage space inficient, can not build a file!\n"; return false; } else { if((tempbuf=new char[BLOCK])==NULL) { cout<<"RAM deficient!\n"; return false; } //创建文件 block.Bread(fdpos.blkno,tempbuf);//读出存储目录结构的块 td=(dir*)(tempbuf+fdpos.offset); td->d_gid=user.u_gid; td->d_mode=user.u_error; int na=0; for(na=0;na<8;na++) td->d_name[na]=filename[na]; td->d_uid=user.u_uid; td->d_fsize=0; for(int i=0;i<10;i++) { td->d_add[i]=-1; } Write(td); user.u_cdir->f_fsize+=1; SaveDirfcb(user.u_cdir);//将修之后的当前目录信息存到硬盘中去 block.BWrite(fdpos.blkno,tempbuf); delete[]tempbuf; return true; } } } Hfcb TFcb::FindFree(TUser& user)//fd.blkno=-1时说明没有找到空闲空间 { Hfcb fd; fd.blkno=-1; char* tempbuf=NULL; dir* td=NULL; if((tempbuf=new char[BLOCK])==NULL) { cout<<"RAM deficient!\n"; return fd; } for(int i=0;i<10;i++) { if(user.u_cdir->f_add[i]<=0||user.u_cdir->f_add[i]>=2048) { if((user.u_cdir->f_add[i]=block.Balloc())==-1)//-1时表示没有分配到磁盘块空间 { cout<<"Storage space deficient!\n"; return fd; } else { fd.blkno=user.u_cdir->f_add[i]; fd.offset=0; return fd; } } else//查找该块中是否还有空间空间 { block.Bread(user.u_cdir->f_add[i],tempbuf); for(int j=0;jd_mode==NONODE) { fd.blkno=user.u_cdir->f_add[i]; fd.offset=sizeof(dir)*j; return fd; } } } } return fd; } bool TFcb::IsFirst() { return first; } void TFcb::JustWrRight(char* fname,TUser& user)//判断用户是否对该文件有写权限 {//用户权限说明请看文档中的说明 if(fname==NULL) { cout<<"Can not find the file!\n"; return ; } bool write=false; char* tempbuf=NULL; dir* df=NULL; if((tempbuf=new char[BLOCK])==NULL) { cout<<"RAM deficient!\n"; return ; } Hfcb tf; tf=Namei(fname,user);//查找是否存在该文件 if(tf.blkno!=-1) { block.Bread(tf.blkno,tempbuf); df=(dir*)(tempbuf+tf.offset); if(user.u_uid==0||user.u_uid==df->d_uid)//如果用户标识相同或是超级用户 { if(user.u_uid==0)//如果是超级用户,则对任何文件有写权限 write=true; if(df->d_mode!=IREAD&&df->d_mode!=IEXEC) write=true; else write=false; } else { if(user.u_gid==df->d_gid)//该文件为同组用户写权限 { if(df->d_mode==GWRITE||df->d_mode==OWRITE||df->d_mode==OREAD) write=true; else write=false; } else { if(df->d_mode==OWRITE)//其它用户写权限 write=true; else write=false; } } } else { cout<<"Can not find the file!\n"; delete[]tempbuf; return ; } if(write==true)//如果有写权限,则调用写函数 { Write(df); block.BWrite(tf.blkno,tempbuf); delete[]tempbuf; } else { cout<<"You have no right to write the file!\n"; delete[]tempbuf; } } Hfcb TFcb::Namei(char* fdname,TUser& user)//of.blkno=-1时说明没有找到该名字的文件 { Hfcb of; of.blkno=-1; char* tempbuf=NULL; dir* td=NULL; if((tempbuf=new char[BLOCK])==NULL) { cout<<"RAM deficient!"<f_add[i]<=0||user.u_cdir->f_add[i]>=2048)//限制不能超过模拟磁盘空 间 { return of; } else { block.Bread(user.u_cdir->f_add[i],tempbuf); for(int j=0;jd_mode!=NONODE&&strcmp(fdname,td->d_name)==0)//确认是否是所要查找的文件目录 { of.blkno=user.u_cdir->f_add[i]; of.offset=j*sizeof(dir); return of; } } } } return of; } bool TFcb::OpenFile(char* fdname,TUser& user)//用于open命令,找打开文件 { bool open; if(fdname==NULL) { cout<<"Can not find the file!"<d_uid||user.u_uid==0)//如果是超级用户或文件主则有权限打开文件 open=true; else { if(user.u_gid==fd->d_gid)//同组用户则根据文件属性来决定是否有权限打开文件 { if(fd->d_mode!=IEXEC) open=true; else { if(fd->d_mode!=IREAD&&fd->d_mode!=IEXEC&&fd->d_mode!=GEXEC)//其他用户也根据文件属性来决定是否有权限打开文件 open=true; else open=false; } } } if(open=true) { if(fd->d_mode==IFROOT||fd->d_mode==ROOT||fd->d_mode==IFDIR) { cout<<"Can not open the DIR!"<f_count=1; user.u_pdir->f_flag=FCBUSE;//置fcb已经用标志 user.u_pdir->f_blkno=tf.blkno; user.u_pdir->f_number=tf.offset; user.u_pdir->f_mode=fd->d_mode; user.u_pdir->f_uid=fd->d_uid; user.u_pdir->f_gid=fd->d_gid; user.u_pdir->f_fsize=fd->d_fsize; int na; for(na=0;na<8;na++) user.u_pdir->f_name[na]=fd->d_name[na]; for(int c=0;c<10;c++) user.u_pdir->f_add[c]=fd->d_add[c]; delete[]tempbuf; return true; } else { cout<<"Can not allocate the FCB!"<d_uid==user.u_uid||td->d_uid==0)//同一用户或是超级用户 {//判断是否有权限读该文件 if(td->d_uid==0) { read=true; } else { if(td->d_mode!=IEXEC) read=true; else read=false; } } else { if(td->d_gid==user.u_gid)//如果是同组用户 { if(td->d_mode==GREAD||td->d_mode==GWRITE||td->d_mode==IFREG||td->d_mode==O READ||td->d_mode==OWRITE||td->d_mode==OEXEC) read=true; else read=false; } else {//其它用户 if(td->d_mode==OREAD||td->d_mode==OWRITE||td->d_mode==IFREG) read=true; else read=false; } } if(read==true) { int i,j,k; cout<d_add[i]!=-1)//读文件 { block.Bread(td->d_add[i],readbuf); for(k=0;j<=td->d_fsize&&kf_blkno,tempbuf); fd=(dir*)(tempbuf+tfcb->f_number); fd->d_fsize=tfcb->f_fsize; fd->d_gid=tfcb->f_gid; fd->d_uid=tfcb->f_uid; fd->d_mode=tfcb->f_mode; for(int j=0;j<8;j++) { fd->d_name[j]=tfcb->f_name[j]; } for(int i=0;i<10;i++) { fd->d_add[i]=tfcb->f_add[i]; } block.BWrite(tfcb->f_blkno,tempbuf); } void TFcb::SetFile(int flag,TUser& user,char* fname)//用于set命令,设置文件属性 { char* tempbuf=NULL; Hfcb fc=Namei(fname,user);//查找该文件 if(fc.blkno==-1) { cout<<"Can not find the file!"<d_uid==user.u_uid||user.u_uid==0)//文件主和超级用户具有改变该文件的属性的权限 { fd->d_mode=flag; block.BWrite(fc.blkno,tempbuf); delete[]tempbuf; return ; } else { cout<<"You have no right to modify the file's attributes!"<d_flag==1) continue; else {//将用户信息写入buf tuser->d_flag=1; tuser->d_gid=info.d_gid; tuser->d_uid=info.d_uid; for(j=0;j<8;j++) { tuser->d_name[j]=info.d_name[j]; tuser->password[j]=info.password[j]; } block.BWrite(0,buf); block.SetFirst(); break; } } if(i>USERNUM) cout<<"Sorry,can not accept new users!"<d_flag==-1) continue; else { cout<d_name; cout<d_gid; cout<d_uid<>input; cin.getline(input,BLOCK,'$'); int i,j,bno,ilength; for(i=0;id_fsize==0)//如果该文件为新文件 { for(i=0;id_add[0]=bno; td->d_fsize=ilength; block.BWrite(bno,tempbuf); return true; } else {//如果该文件为旧文件(即已经有内容 block.Bread(td->d_add[0],tempbuf); for(i=td->d_fsize,j=0;jd_fsize+=ilength; block.BWrite(td->d_add[0],tempbuf); return true; } } 3、以下为openfile.h的内容: #include"fileprocess.h" #include class TOFile { public: TOFile(); int BalOF(); //分配HOFile数组 int Balpof(TUser& user); //分配user中的Hofile指针数组 void BreOF(int bof); //释放HOFile数组 bool OFCd(char* dirname,TUser& user);//设置用户 bool OFCd__(TUser& user);//返回上一层目录 bool OFIsFirst(); //true表示第一次进入系统 bool OFCheckUW(char* tempuser,char* tempword,TUser& refuser);//检验用户名和密码 bool OFCloseFile(char* fdname,TUser& user);//关闭文件 bool OFDelDir(char* dirname,TUser& user);//删除目录 bool OFDelFile(char* filename,TUser& user);//删除文件 void OFDirectory(TUser& user);//遍历目录 void NewUser(USERINFO un);//创建新用户 bool OFCFile(char* filename,TUser& user);//创建文件 bool OFCreateDir(char* dirname,TUser& user);//创建目录 void OFNamei(char* filename,TUser& user){;} bool OFOpenFile(char* fdname,TUser& user);//打开文件 void OFRead(char* filename,TUser& user);//读文件 void OFSet(int flag,TUser& user,char* fname);//设置文件属性 void OFShowUser(); //显示所有用户信息 void OFWrite(char* filename,TUser& user);//写文件 protected: TFcb fcb; int cofile; }; TOFile::TOFile() { cofile=0; InitOFile(); } int TOFile::BalOF()//分配ofile数组 { int i; for(i=0;io_fcbp->f_name)==0) {//关闭文件,释放其占用的资源 user.u_ofile[i]->o_fcbp->f_flag=FCBFLAG; user.u_ofile[i]->o_flag=OFFLAG; user.u_ofile[i]=NULL; return true; } } return false; } bool TOFile::OFCheckUW(char* tempuser,char* tempword,TUser& refuser)//检查用户名和密 码 { return fcb.CheckUW(tempuser,tempword,refuser); } bool TOFile::OFCreateDir(char* dirname,TUser &user)//创建目录 { return fcb.CreateDir(dirname,user); } void TOFile::OFDirectory(TUser& user)//遍历目录 { fcb.Directory(user); } bool TOFile::OFDelDir(char* dirname,TUser& user)//删除目录 { return fcb.DelDir(dirname,user); } bool TOFile::OFDelFile(char* filename,TUser& user)//删除文件 { return fcb.DelFile(filename,user); } bool TOFile::OFIsFirst() { return fcb.IsFirst(); } bool TOFile::OFCFile(char* filename,TUser& user)//创建文件 { return fcb.FCFile(filename,user); } bool TOFile::OFOpenFile(char* fdname,TUser& user)//打开文件 { int bno,bnop; int i=0; Hfcb fd; fd=fcb.Namei(fdname,user); for(i=0;i<5;i++) { if(user.u_ofile[i]!=NULL) { if(fd.blkno==user.u_ofile[i]->o_fcbp->f_blkno&&fd.offset==user.u_ofile[i]->o_fcbp->f_nu mber)//判断该文件是否已经打开 { cout<<"The file have been opened!\n"; return false; } } } bno=BalOF(); if(bno==-1) { cout<<"Can not open so many files!\n"; return false; } bnop=Balpof(user); if(bnop==-1) { cout<<"Can not open so many files!\n"; fcb.Brefcb(bno); return false; } if(fcb.OpenFile(fdname,user)==true)//成功打开文件 { ofile[bno].o_count=1; ofile[bno].o_flag=OFUSE; ofile[bno].o_fcbp=user.u_pdir; user.u_ofile[bnop]=&ofile[bno]; return true; } else {//打开文件失败,释放刚才申请的资源 fcb.Brefcb(bno); user.u_ofile[bnop]=NULL; return false; } } void TOFile::OFRead(char* filename,TUser& user)//读文件 { int i=0; Hfcb fd; fd=fcb.Namei(filename,user);//查找该文件的存储块,以存储位置来识别已经打开的同名 文件是同一文件,还是不同目录下的同名文件 for(i=0;i<5;i++) { if(user.u_ofile[i]!=NULL) { if(fd.blkno==user.u_ofile[i]->o_fcbp->f_blkno&&fd.offset==user.u_ofile[i]->o_fcbp->f_nu mber)//判断文件是否打开 { fcb.ReadFile(filename,user); return ; } } } if(i>=5) cout<<"Open the file, then you can use this command!\n"; } void TOFile::OFSet(int flag,TUser& user,char* fname)//设置文件属性 { fcb.SetFile(flag,user,fname); } void TOFile::OFShowUser()//显示已注册用户信息 { fcb.ShowUser(); } void TOFile::OFWrite(char* filename,TUser& user)//写文件 { int i=0; Hfcb fd; fd=fcb.Namei(filename,user);//查找该文件的存储块,以存储位置来识别已经打开的同名 文件是同一文件,还是不同目录下的同名文件 for(i=0;i<5;i++) { if(user.u_ofile[i]!=NULL) { if(fd.blkno==user.u_ofile[i]->o_fcbp->f_blkno&&fd.offset==user.u_ofile[i]->o_fcbp->f_nu mber)//判断文件是否打开 { fcb.JustWrRight(filename,user);//判断该用户是否有权限写文件 return ; } } } if(i>=5) cout<<"Open the file, then you can use this command!\n"; } class TEnter { public: TEnter(); void Enter(); bool CheckUP(string tempuser,string temppw,TUser& refuser); //确认用户名是否存在,确 认密码是否正确 bool CFile(string filename); //创建新文件 bool ECd(string dirname); //设置目录 bool ECd__(); //返回上一层目录 bool ECloseFile(string filename); //关闭文件 bool ECreateDir(string dirname); //创建目录 void ERead(string filename); //读文件 void EWrite(string filename); //写文件 bool EDelDir(string dirname); //删除目录 bool EDelFile(string filename); //删除文件 void EDirectory(); //列文件目录 void ESet(int flag,string fname);//设置文件属性 bool EOpenFile(string fname); //打开文件 void EShowUser(); //显示用户信息 void NewUser(); //创建新用户 void Namei(char* filename,TUser& user); //检找文件 // bool IsExist(string tempuser); //检查用户名是否存在 void Init(); //用户登陆 bool IsFirst(); //检查是否是第一次启动程序 bool IsSucess(); //成功返回true void SToChar(string str,char* ctr); //将string转换成char数组(8位) protected: string User; //存储用户名 string Pword; //存储密码 bool Sucess; //登陆成功与否的标志 TOFile tofile; }; TEnter::TEnter() { if(IsFirst()==true) { NewUser();//创建第一个用户 } Init();//用户登陆并初始化系统参数 } bool TEnter::CheckUP(string tempuser,string temppw,TUser &refuser)//检查用户和密码是否正 确 { if(tempuser.length()<=0||temppw.length()<=0)//如果用户名或密码长度为0,则返回false return false; char tu[8],tp[8]; int i=0; for(i=0;i<8;i++) { tu[i]='\0'; tp[i]='\0'; } //将用户名由string类型转化成为具有8个元素的数组 if(tempuser.length()<8)//如果输入用户名小于8位 { for(i=0;i=3) exit(0); cout<<"login: "; cin>>username; password=getpass("password: "); count++; if(CheckUP(username,password,user[fun])==true)//验证用户名和密码 { cout<<"Welcome, "<>tuser; tword1=getpass("new password: "); tword2=getpass("confirm password: "); if(tword1==tword2)//检查两次密码输入是否相符 { cout<<"Please input your group id: "; cin>>uid; un.d_flag=1; un.d_uid=uid; un.d_gid=(tuser[0]+tuser[1])/2; for(i=0;i<8;i++) { un.d_name[i]='\0'; un.password[i]='\0'; } if(sizeof(tuser)<8)//格式化用户名 { for(i=0;if_name[c]!='\0'&&c<8) { cout<f_name[c]; c++; } cout<<">"; begin: for(i=0;i<80;i++) { array[i]=getchar(); if(array[i]!='\n') continue; else break; } if(array[0]=='\n') goto begin; TCmd::CharToString(In1,In2,i); StrUp(In1);//小写字母变大写 TranOr=Tran(In1); switch(TranOr) { case CD: Cd(In2);break; case CD_: Cd_();break; case CD__: Cd__();break; case CATCON: Create(In2);break; case DEL: Del(In2);break; case DIR: Dir();break; case EXIT: Exit();break; case HELP: Help();break; case MD: Md(In2);break; case NEW: New();break; case RD: Rd(In2);break; case MORE: Open(In2); Read(In2); Close(In2); break; case CHMOD: Set(In2);break; case SHOWUSER: ShowUser();break; case WR: Open(In2); Wr(In2); Close(In2);break; default: cout<<"'"<>in; StrUp(in); int pr=TCmd::Properly(in); if(pr!=-1) { enter.ESet(pr,para); } else { cout<<"Unacceptible file attribute!\n"; } } void TCmd::StrUp(string &str) { int i=0; for(i=0;i=97&&str[i]<=122) { str[i]=str[i]-32; } } } Or TCmd::Tran(string temp) { if(temp=="CD") return CD; if(temp=="CD.") return CD_; if(temp=="CD~") return CD__; if(temp=="CATCON") return CATCON; if(temp=="DELETE") return DEL; if(temp=="DIR") return DIR; if(temp=="LOGOUT") return EXIT; if(temp=="HELP") return HELP; if(temp=="MD") return MD; if(temp=="NEW") return NEW; if(temp=="MORE") return MORE; if(temp=="RD") return RD; if(temp=="USER") return SHOWUSER; if(temp=="CHMOD") return CHMOD; if(temp=="WRITE") return WR; return WRONG; } void TCmd::Wr(string para) { enter.EWrite(para); } 5、以下为filesystem.h的内容: #include"cmd.h" void main() { cout<<"\n******************************************************************* ******"; cout<<"\n************************** File System ********************************"; cout<<"\n******************************************************************* ******\n\n"; TCmd cp; } 八、调试记录 1、 文件操作: 2、 目录操作: 九、使用说明 命令名 格式 功能 举例 New New 新建用户 New User User 显示现有用户 User Catcon Catcon [filename] 新建文件 Catcon file1 Write Write [filename] 写入文件 Write file2 More More [filename] 显示文件内容 More file1 Delete Delete [filename] 删除文件 Delete file2 Chmod Chmod [filename] 改变文件权限 Chmod file1 Dir Dir 显示当前目录信息 Dir Cd Cd [dirname] 进入下级目录 Cd iczj1 Cd~ Cd~ 返回上级目录 Cd~ Md Md [dirname] 建立新目录 Md iczj1 Rd Rd [dirname] 删除目录 Rd iczj2 Help Help 显示帮助文档 Help Logout Logout 退出系统 Logout 十、体会 这次的操作系统大作业的工作量比较大,我投入了很多的时间和精力才完成了系统的设计。不过这些付出都是值得的,因为我收获了更多。首先,在开发系统的过程中,我对操作系统的功能实现,特别是文件管理这一块的内容有了较深的理解,这个理解程度是看书所无法达到的。另外,这次开发要使用到文件存取的操作来实现数据块资料的存取,从而使我对文件存取的操作更熟悉了。最后,操作系统大作业的经历在很大程度上磨练了我的意志,同时锻炼了我个人的编程思维。 十一、编译方法 用telnet远程登陆Linux服务器,在./filesystem/目录下运行: g++ -o filesystem.out filesystem.cpp
本文档为【多用户多级目录结构文件系统设计与实现毕业设计(论文)word格式】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_833902
暂无简介~
格式:doc
大小:224KB
软件:Word
页数:104
分类:工学
上传时间:2017-09-18
浏览量:135