操作系统文件系统的设计与实现_课程设计(编辑修改稿)内容摘要:

1,fp)。 //文件目录 } fseek(fp,512L,0)。 fwrite(amp。 emptytable,sizeof(struct empty),1,fp)。 //位示图 fclose(fp)。 } void dir() //显示文件目录 { int i,j。 FILE *fp。 if((fp=fopen(filesys,rb))==NULL) { printf(can not open file \n)。 exit(0)。 } fseek(fp,512L,0)。 //空闲盘块表的定位 fread(amp。 emptytable,sizeof(struct empty),1,fp)。 rewind(fp)。 //文件目录表的定位 num=。 for(i=0。 inum。 i++) fread(amp。 file[i],sizeof(struct filename),1,fp)。 if (num!=0) 12 { printf(系统所有文件 :\n)。 for(i=0,j=1。 inum。 i++,j++) { printf(%s.%s ,file[i].name,file[i].ext)。 if(j==5) { printf(\n)。 j=1。 } } } printf(\n 文件数量为 %d ,num)。 fclose(fp)。 } void type() //显示文件内容 { FILE *fp。 int i,j。 if((fp=fopen(filesys,rb))==NULL) { printf(can not open file \n)。 exit(0)。 } fseek(fp,512L,0)。 fread(amp。 emptytable,sizeof(struct empty),1,fp)。 rewind(fp)。 num=。 for(i=0,j=0。 inum。 i++,j++) { fread(amp。 file[i],sizeof(struct filename),1,fp)。 printf(%s.%s ,file[i].name,file[i].ext)。 if(j==5) printf(\n)。 } printf(\n)。 char name[12],ext1[8]。 printf(请输入所要查询的文件名 :\n)。 gets(name)。 //scanf(%s,name)。 //getchar()。 printf(请输入扩展名 :)。 gets(ext1)。 //scanf(%s,ext1)。 getchar()。 if(*(name+0)==39。 \039。 ) { printf(文件名不能为空 ! \n)。 return。 } 13 if(*ext1==39。 \039。 ) strcpy(ext1,txt)。 int sign=0。 for(i=0。 inum。 i++) if((strcmp(file[i].name,name)==0) amp。 amp。 (strcmp(file[i].ext,ext1)==0)) { printf( 所找文件为第 %d 个文件 \n,i+1)。 sign=1。 break。 } if(sign==0) { printf(无此文件 \n)。 return。 } //显示文件 int b,m,n。 b=file[i].i。 n=file[i].size。 printf( 该文件位于第 %d 块 \n,b+1)。 printf( 从文件读出的文件长度为 :%d\n,n)。 //fseek(fp,b*512L,0)。 char cc。 printf( 文件内容为 :\n)。 printf( )。 for( m=0,j=1。 mn。 m++,j++) { fseek(fp,b*512L+m,0)。 //fread(amp。 cc,sizeof(char),1,fp)。 cc=fgetc(fp)。 printf(%c,cc)。 if(j%40==0)printf(\n )。 } printf(\n)。 fclose(fp)。 } void delfile() //删除一个文件 { FILE *fp。 int i。 if((fp=fopen(filesys,r))==NULL) { 14 printf(can not open file \n)。 exit(0)。 } fseek(fp,512L,0)。 fread(amp。 emptytable,sizeof(struct empty),1,fp)。 rewind(fp)。 num=。 for(i=0。 inum。 i++) fread(amp。 file[i],sizeof(struct filename),1,fp)。 char name[12],ext1[8]。 printf(请输入文件名 :\n)。 gets(name)。 //scanf(%s,name)。 getchar()。 printf(请输入扩展名 :\n)。 gets(ext1)。 //scanf(%s,ext1)。 getchar()。 if(*name==39。 \039。 ) { printf(文件名不能为空 ! \n)。 return。 } if(*ext1==39。 \039。 ) strcpy(ext1,txt)。 char judge。 printf(是否删除文件 %s.%s [y/n],name,ext1)。 scanf(%c,amp。 judge)。 getchar()。 if((judge==39。 y39。 )||(judge==39。 Y39。 )) printf(准备删除文件 %s.%s !\n,name,ext1)。 else if((judge==39。 n39。 )||(judge==39。 N39。 )) return。 else { printf(系统默认放弃 !\n)。 return。 } int sign=0。 for(i=0。 inum。 i++){ if((strcmp(file[i].name,name)==0)amp。 amp。 (strcmp(file[i].ext,ext1)==0)) { sign=1。 break。 } } if(sign==0) 15 { printf(文件名错 \n)。 return。 } //回收空间 int b=file[i].i。 int Amount=file[i].Amount。 int j。 for(j=0。 jAmount。 j++) [b++]=0。 for( j=i。 jnum1。 j++) { strcpy(file[j].name,file[j+1].name)。 strcpy(file[j].ext,file[j+1].ext)。 file[j].i=file[j+1].i。 file[j].size=file[j+1].size。 file[j].Amount=file[j+1].Amount。 } =。 num=。 WriteFile()。 printf(删除成功。 \n。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。