操作体统课程设计模拟二级文件管理系统c内容摘要:

cur=head。 while(curnext!=NULL) { cur=curnext。 } } memset(path,0,sizeof(path))。 strcpy(path,user[i].name)。 path[strlen(user[i].name)]=39。 /39。 cout登陆成功 endl。 sum=0。 return 1。 } else { cout密码错误。 还有 m次登陆机会 endl。 } } } } cout用户名不存在。 还有 n次登陆机会 endl。 } exit(0)。 } void initfcb() { head=new FileControlBlocks。 headfront=NULL。 headnext=NULL。 headparent=NULL。 headchild=NULL。 headfstyle=39。 \039。 memset(headfilename,0,sizeof(headfilename))。 headfilename[0]=39。 /39。 headfstyle=0。 //类型 ,文件或者文件夹 headaddr=0。 headsize=0。 //文件大小 headpriority=0。 memset(headctime,0,sizeof(headctime))。 cur=head。 } int isexist() { FileControlBlocks *p=head。 while(pnext!=NULL) { p=pnext。 //coutpfilenamenameendl。 if(strcmp(pfilename,name)==0) { return 1。 } } return 0。 } void createFile() { toAbsolutePath()。 if(isexist()) { cout文件已存在。 endl。 return。 } int size。 int addr。 cout文件大小(字节数):。 cinsize。 getchar()。 int len。 if(size%512) len=size/512+1。 else len=size/512。 cout需要的块数 lenendl。 int s=0。 for(int i=0。 i256。 i++) //分配空间 { s=0。 for(int j=0。 j+i256amp。 amp。 jlen。 j++) { if(fileBlock[i+j].used==0) //需求空间内有块已被占用 { s++。 } else { i=j+i。 break。 } } if(s==len) //成功找到足够空间时 s 的值不变 { addr=i。 for(int k=0。 ks。 k++,i++) { fileBlock[i].used=1。 } break。 } } if(slen) { cout找不到足够的存储空间。 文件创建失败。 endl。 return。 } for(int i=addr。 ilen+addr。 i++) { memset(fileBlock[i].content,0,sizeof(fileBlock[i].content))。 } FileControlBlocks *fcb=new FileControlBlocks。 strcpy(fcbfilename,name)。 fcbaddr=addr。 fcbsize=size。 fcbfstyle=0。 time_t t = time(0)。 strftime( fcbctime, sizeof(fcbctime), %Y/%m/%d,localtime(amp。 t))。 curnext=fcb。 fcbfront=cur。 fcbparent=NULL。 fcbchild=NULL。 fcbnext=NULL。 cur=fcb。 sum+=size。 if(headparent!=NULL) { headparentsize+=size。 } else { headsize+=size。 } int i=curaddr。 cout文件创建成功 ! 其块号是: iendl。 } void mkdir() { toAbsolutePath()。 if(isexist()) { cout文件或文件夹已经存在 endl。 return。 } FileControlBlocks *fcb=new FileControlBlocks。 strcpy(fcbfilename,name)。 fcbaddr=0。 fcbsize=0。 fcbfstyle=1。 time_t t = time(0)。 strftime( fcbctime, sizeof(fcbctime), %Y/%m/%d,localtime(amp。 t))。 curnext=fcb。 fcbfront=cur。 fcbparent=NULL。 fcbchild=NULL。 fcbnext=NULL。 cur=fcb。 FileControlBlocks *fcb1=new FileControlBlocks。 strcpy(fcb1filename,name)。 fcb1addr=0。 fcb1size=0。 fcb1fstyle=0。 //time_t t = time(0)。 strftime( fcb1ctime, sizeof(fcb1ctime), %Y/%m/%d,localtime(amp。 t))。 curchild=fcb1。 fcb1front=NULL。 fcb1parent=cur。 fcb1child=NULL。 fcb1next=NULL。 cout文件夹创建成功 !endl。 } void cd() { FileControlBlocks *p=head。 if(!strcmp(name,..)) { if(headparent!=NULL) { head=headparent。 cur=head。 while(headfront!=NULL) { head=headfront。 } while(curnext!=NULL) { cur=curnext。 } path[strlen(path)1]=39。 \039。 for(int i=strlen(path)1。 i) { if(path[i]==39。 /39。 ) { break。 } path[i]=39。 \039。 } return。 } else { cout已是本用户顶层目录。 endl。 return。 } } else { toAbsolutePath()。 while(pnext!=NULL) { p=pnext。 if(strcmp(pfilename,name)==0) { head=pchild。 cur=head。 strcpy(path,name)。 path[strlen(path)]=39。 /39。 while(curnext!=NULL) { cur=curnext。 } break。 } } } } void dir() { char *l[]={文件 ,目录 }。 FileControlBlocks *p=cur。 //int sum=0,used=0。 while(pfront!=NULL) p=pfront。 printf(目录名 \t 文件名 \t 文件大小 \t 类型 \t 创建时间 \n)。 while(pnext!=NULL) { p=pnext。 coutpath\t。 toRelativePath(pfilename)。 printf(%s\t%d\t\t%s\t%s\n,name,psize,l[pfstyle],pctime)。 }。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。