操作系统实验报告文件管理内容摘要:

***读写系统超级块信息***********************************/ void Read_Boot() //读取磁盘超级块数据 信息 { rewind(fsPtr)。 fread(amp。 FsSupBlk,sizeof(struct Super_Block),1,fsPtr)。 return。 } void FileBoot() //超级块数据信息存盘 { rewind(fsPtr)。 fwrite(amp。 FsSupBlk,sizeof(struct Super_Block),1,fsPtr)。 return。 15 } /***********************FAT 操作 ***********************************/ void LoadFat() //装载全部 FAT 到内存 { fseek(fsPtr,*512,SEEK_SET)。 fread(fat_buffer,sizeof(long int), ,fsPtr)。 return。 } void SaveFat() //FAT 到文件 FAT 区 { fseek(fsPtr,*512,SEEK_SET)。 fwrite(fat_buffer,sizeof(long int),fsPtr)。 return。 } /***********************显示超级块信息 ***********************************/ void boot_dis() { printf(=%ld\n,)。 printf(=%d\n,)。 printf(=%d\n,)。 printf(=%d\n,)。 16 printf(=%d\n,)。 printf(=%d\n,)。 printf(=%d\n,)。 printf(=%ld\n,)。 printf(=%ld\n,)。 } /***********************系统初始化 ***********************************/ void Sys_Init() //初始化 { fsPtr=fopen(DiskName,rb+)。 if(fsPtr == NULL) Create_Disk()。 Read_Boot()。 //boot_dis()。 LoadFat()。 return。 } /***********************显示操作 ***********************************/ void dir() //显示目录下的文件 { int i,countFile=0。 char str[16]。 long int n,pos_dir,pos_fat。 17 coutendl。 pos_dir=*512。 pos_fat=*512。 fseek(fsPtr,pos_dir,SEEK_SET)。 while(ftell(fsPtr)pos_fat) { fread(amp。 filefcb[0],sizeof(struct FCB_Block),16 ,fsPtr)。 for(i=0。 i16。 i++) if(filefcb[i].flag == 1) //文件占有 { countFile++。 n = filefcb[i].file_length。 printf( %15s%s%15d bytes\n, filefcb[i].file_name,file,n)。 } } coutendl。 printf( 总共有 %d 个文件 \n,countFile)。 printf( 系统总共有 %ld 个物理块可用 \n\n,)。 } /*************************查找文件 *******************************/ //查找文件 ,文件存在 返回当前 FCB 数组下标,否则返回 1 18 int Find_File(char *filename) { int i。 long int pos_dir,pos_fat。 pos_dir=*512。 pos_fat=*512。 find_fcb=0。 fseek(fsPtr,pos_dir,SEEK_SET)。 while(ftell(fsPtr)pos_fat) { find_fcb++。 fread(amp。 filefcb[0],sizeof(struct FCB_Block),16 ,fsPtr)。 for(i=0。 i16。 i++) if(filefcb[i].flag!=1) { if(strcmp(filename,filefcb[i].file_name) == 0) return i。 } //文件存在 } return 1。 } /*************************创建文件 *******************************/ void create(char *fname,long int num) //在当前目录下创建一个名字为 str 的文件,长度为 num { int i,j。 //true 表示没有与该名字重名的文件 int tempnode。 19 long int pos_dir,getnum=0。 unsigned long int blkcount。 blkcount= num/512+1。 //计算需要的物 理块 if( blkcount) //磁盘没有足够空间 { printf(\n 磁盘没有足够空间,不能建立。 \n\n)。 return。 } tempnode=Find_File(fname)。 if (tempnode!=1) //表示文件存在 { printf(\n 文件已经存在,不需要建立。 \n\n)。 return。 } // 建立文件的处理 pos_dir=*。 fseek(fsPtr,pos_dir,SEEK_SET)。 //定位到目录区 for(i=0。 i。 i++) { //Read_Block(i+,(char *)filefcb)。 fread(amp。 filefcb[0],sizeof(struct FCB_Block),16 ,fsPtr)。 for(j=0。 j16。 j++) 20 if(filefcb[j].flag == 1) //找到空目录项 { // 分配空间 , 标记 FCB 数据项,并将 FCB 写磁盘 getnum=Get_Block(blkcount)。 if(getnum==1){ printf(不能分配存储空间 \n)。 return。 } filefcb[j].file_start=getnum。 filefcb[j].flag = 1。 filefcb[j].file_length=num。 strcpy(filefcb[j].file_name,fname)。 //filefcb[].file_time= //filefcb[].file_date= // 改变磁盘 FCB 值 pos_dir=pos_dir+sizeof(struct FCB_Block)*(i*16+j)。 fseek(fsPtr,pos_dir,SEEK_SET)。 //定位到目录区的 FCB 项 fwrite(amp。 filefcb[j],sizeof(struct FCB_Block),1 ,fsPtr)。 //Write_Block(i+,(char *)filefcb)。 printf( 文件占用了 %d 个物理块 \n,blkcount)。 printf( 系统还。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。