FAT文件系统操作系统课程设计实验报告Word格式.docx

上传人:b****5 文档编号:20919925 上传时间:2023-01-26 格式:DOCX 页数:26 大小:22.75KB
下载 相关 举报
FAT文件系统操作系统课程设计实验报告Word格式.docx_第1页
第1页 / 共26页
FAT文件系统操作系统课程设计实验报告Word格式.docx_第2页
第2页 / 共26页
FAT文件系统操作系统课程设计实验报告Word格式.docx_第3页
第3页 / 共26页
FAT文件系统操作系统课程设计实验报告Word格式.docx_第4页
第4页 / 共26页
FAT文件系统操作系统课程设计实验报告Word格式.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

FAT文件系统操作系统课程设计实验报告Word格式.docx

《FAT文件系统操作系统课程设计实验报告Word格式.docx》由会员分享,可在线阅读,更多相关《FAT文件系统操作系统课程设计实验报告Word格式.docx(26页珍藏版)》请在冰豆网上搜索。

FAT文件系统操作系统课程设计实验报告Word格式.docx

⑻、文件拷贝

#CopyFile老文件,新文件,为新文件创建一个目录项,并将老文件内容复制到新文件中,并同时修改FAT内容和位示图内容

⑼、显示位示图内容

#ShowBitMP,将位示图内容(已有信息部分),显示在屏幕上(按十六进制)

⑽、显示FAT内容

#ShowFAT,将FAT内容(已有信息部分),显示在屏幕上(按十六进制)

4、程序的总体流程为:

⑴、输出提示符#,等待接受命令,分析键入的命令;

⑵、对合法的命令,执行相应的处理程序,否则输出错误信息,继续等待新命令

(1、请参考“03.FAT32文件系统简介.doc”中,有关文件系统的规定;

2、请参考WinHex中,目录所显示的信息进行编程)

//关于FAT和MAP表的解释

//用bitset库,做MAP的是否判断,因为作业要求从数据块从128位开始,所以bitset的前128位被置为-1,同样FAT表也是,其次,MAP表和FAT表同样是用数组方式做保存,这样就略过了是对具体地址的操作,从数组的下标很容易的定位,

关于对FAT表和MAP表的用法

1.当要用到数据块是,查询MAP表(因为只做比较查询即可),查询到的未用位置置1,然后在FAT表上进行相应记录,在本程序做出的规定是,当文件夹FAT表做-1,若是文件则按照FAT做对应的顺序记录,最后一块同样是-1结束,

2.回收的时候,是按照FAT表的首项,做顺序置0,然后MAP也在相应位置置0

#include<

iostream>

stdio.h>

stdlib.h>

string>

#include<

bitset>

/***********************************************************/

//AUTHOR:

CHENLOG

//ENVIROMENT:

VC2008WIN7

//DATE:

2011-6-5VERSION1.0

usingnamespacestd;

constintBLOCKNUM_SIZE=2;

//盘块号大小

constintBLOCK_SIZE=1024;

//一个盘块大小数

constintBLOCK_NUM=10001;

//盘块数量

constintDISK_SIZE=1024*1000*10;

//磁盘大小

constintLIST_SIZE=32;

//目录项大小

constintMAP_SIZE=10001;

//MAP长度

constintFATNUM=125;

//FAT的盘块数第块没有用

constintFATLIST=512;

//每个盘口FAT的记录数

constintDATABEG=128;

//数据项开始FAT号

structFCB

{

charfname[8];

//文件名

charexname[3];

//扩展名

shortfnum;

//首块号

intlength;

//文件大小,目录则文件大小为;

};

structfatid{

shortid[FATNUM*FATLIST];

//FAT大小512个记录一块

}*FAT;

structmap{

bitset<

MAP_SIZE>

maplist;

}*MAP;

structDIR

structFCBlist[LIST_SIZE+1];

}*filedir;

intcurrentid=128;

//当前FAT号

intcurrentdir=128;

//当前目录块号初始化是+1由于第个单元没有使用

char*file;

//磁盘的首地址

char*FilePath="

myfat"

;

//window文件保存地址

FILE*fp;

//window文件地址

stringCURRENT="

root\\"

//当前路径

charcmd[30];

//输入指令

charcommand[16];

/*

*对文件存储器进行格式化

*创建根目录

*

*/

voidfindBit(structmap*MAP)

}

voidinit(structfatid*FAT)

inti,j;

for(i=1;

i<

FATNUM*FATLIST;

i++)//第块不使用

{

if(i>

DATABEG)

FAT->

id[i]=0;

else

id[i]=-1;

}

voidformat()

booli;

FAT=(structfatid*)(file+BLOCK_SIZE);

//当前FAT地址

MAP=(structmap*)(file+(FATNUM+1)*BLOCK_SIZE);

//初始化位示图

init(FAT);

FAT->

id[0]=9872;

filedir=(structDIR*)(file+(FATNUM+1+2)*BLOCK_SIZE);

//当前目录指针地址

id[128]=-1;

id[0]=9872-1;

strcpy(filedir->

list[0].fname,"

."

);

list[0].exname,"

dir"

filedir->

list[0].fnum=currentdir;

list[0].length=0;

list[1].fname,"

.."

list[1].exname,"

list[1].fnum=currentdir;

list[1].length=0;

fp=fopen(FilePath,"

w+"

fwrite(file,sizeof(char),DISK_SIZE,fp);

fclose(fp);

printf("

初始化已经完成,现在可以进行操作了!

\n\n"

*创建子目录

intmkdir(char*str)

{

intblockid;

//将要创建的FAT号

intblockdir;

//将要创建的目录块号

intlistnum;

//目录块内编号

structfatid*flagid;

structDIR*dir;

//当前目录指针

structmap*MAP;

structfatid*FAT;

if(strcmp(str,"

"

)==0)

printf("

目录名称不能为空\n"

return0;

dir=(structDIR*)(file+(currentdir)*BLOCK_SIZE);

for(i=DATABEG+1;

BLOCK_NUM;

i++)//从128块数据块实际上的块开始搜索

if(MAP->

maplist[i]==0)

break;

if(i>

BLOCK_NUM)

内存不足\n"

MAP->

maplist[i]=1;

//map置即已用

for(i=2;

LIST_SIZE;

i++)

if(strcmp(dir->

list[i].fname,str)==0)

{

printf("

目录下有同名文件夹\n"

return0;

}

if(strcmp(dir->

list[i].fname,"

)==0)//有空的目录块且无重名,第一版本的时候与上面的循环放在一起,存在一个情况是前面的建立的目录删除后,直接被同名的覆盖了

LIST_SIZE)

flagid=(structfatid*)(file+BLOCK_SIZE);

//fat首位地址

for(j=DATABEG+1;

j<

j++)

if(flagid->

id[j]==0)

blockdir=j;

strcpy(dir->

list[i].fname,str);

dir->

list[i].fnum=blockdir;

list[i].exname,"

list[i].length=0;

dir=(structDIR*)(file+blockdir*BLOCK_SIZE);

//为新目录项创建根目录

list[0].fnum=blockdir;

flagid->

id[j]=-1;

//修改FAT目录尾部

FAT->

id[0]=FAT->

id[0]-1;

printf("

已经成功创建目录%s\n"

str);

return0;

*显示目录

intlistshow()

inti,sumfile,sumdir,fl[100],dr[100];

//fl为文件的号数,dr为目录的号数

sumfile=sumdir=0;

dir=(structDIR*)(file+currentdir*BLOCK_SIZE);

for(i=0;

if(dir->

list[i].length==0&

&

(strcmp(dir->

)!

=0)&

(dir->

list[i].fnum!

=0))//为目录的

dr[sumdir]=i;

sumdir++;

list[i].length!

=0&

strcmp(dir->

=0)//为目录的

fl[sumfile]=i;

sumfile++;

sumdir;

%s文件夹\n"

dir->

list[dr[i]].fname);

sumfile;

%s%s文件\n"

list[fl[i]].fname,dir->

list[fl[i]].exname);

\n"

\n在该目录下共有%d个文件,%d个文件夹\n\n"

sumfile,sumdir-2);

*删除子目录

intrmdir(char*str)

inti;

intflag=0;

//FAT号

intblocknum;

//目录块

structDIR*flagdir;

//标记目录块

charc='

a'

//做用户交互

intm=2;

//从第三个子目录项开始搜索要删除的目录项情况

FAT=(structfatid*)(file+BLOCK_SIZE);

dir=(structDIR*)(file+currentdir*BLOCK_SIZE);

//当前目录指针

MAP=(structmap*)(file+(FATNUM+1)*BLOCK_SIZE);

list[i].fname,str)==0)//找到要删除的子目录

该文件夹下不存在%s"

while

(1)

是否确认?

(Y/N)"

cin>

>

c;

if((c=='

y'

||c=='

Y'

)||(c=='

n'

N'

))

break;

if(c=='

blocknum=dir->

list[i].fnum;

flagdir=(structDIR*)(file+blocknum*BLOCK_SIZE);

while(m!

=LIST_SIZE)

if(strcmp(flagdir->

list[m].fname,"

=0)

该目录下有子文件或者子目录,不能删除该目录"

m++;

//父目录DIR

list[i].fnum=0;

strcpy(flagdir->

//要删除目录的DIR

flagdir->

list[0].fnum=0;

maplist[blocknum]=0;

id[blocknum]=0;

id[0]+1;

*更改当前目录

intchangedir(char*str)

//当前目录位置

intflagnum;

//temp的目录位置

structDIR*flagdir,*dir;

structfatid*FAT;

stringstrflag;

//为了改当前显示的代码

if(strcmp("

str)==0)//判断是不是上层目录

blocknum=currentdir;

list[0].fnum==dir->

list[1].fnum)//根目录的特征

return1;

currentdir=dir->

list[1].fnum;

//改变当前目录指针

flagdir=(structDIR*)(file+currentdir*BLOCK_SIZE);

//去上层的目录地址

for(intj=0;

if(flagdir->

list[j].fnum==blocknum)

{

strflag=flagdir->

list[j].fname;

}

CURRENT=CURRENT.substr(0,(CURRENT.length()-strflag.length())-1);

return1;

i++)//子目录

list[i].fname,str)==0&

currentdir=dir->

找不到指定的目录%s\n"

CURRENT=CURRENT+str+"

\\"

return1;

*创建文件

intcreate(char*str,intlength)

//getfilename

inti,j,l,t,k;

intfid;

//FAT的首块号

intflag;

//文件的首块判断

charname[8]={0};

//文件名称

charexname[3]={0};

//文件扩展名

inttemplength;

//temp文件长度

templength=length;

l=strlen(str);

//取文件名

l;

name[i]=str[i];

if(str[i+1]=='

.'

=8)

文件名称过长\n"

//去扩展名

j=0;

i++;

//除去点

k=l-i;

for(j=0;

k;

if(str[i]=='

\0'

exname[j]=str[i];

i++;

if(strcmp(name,"

0"

文件名称不能为空\n"

if(length>

id[0])

文件超出磁盘容纳空间\n"

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 机械仪表

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1