欢迎来到天天文库
浏览记录
ID:9295753
大小:20.73 KB
页数:21页
时间:2018-04-27
《操作系统-文件系统源代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#include#include#defineBLOCKSIZE1024#defineSIZE1024000#defineEND65535#defineFREE0#defineROOTBLOCKNUM2#defineMAXOPENFILE10typedefstructFCB//unsigned{charfilename[8];charexname[3];unsignedcharattribute;charreserve[10];//me:保留区(图3-2MS-DOS的文件控
2、制块)unsignedshorttime;unsignedshortdata;unsignedshortfirst;unsignedlonglength;}fcb;typedefstructFAT{unsignedshortid;}fat;typedefstructUSEROPEN{fcbopenfile[MAXOPENFILE];chardir[MAXOPENFILE][80];//me:用来记录每个打开文件所在的目录名,以方便用户打开不同目录下具有相同文件名的不同文件。//me:即,相应打开文件所在的目录名,这样方便快速检查出指定文件是否已经打开intcount;}user
3、open;typedefstructBLOCK0/*引导块内容*/{charinformation[200];//赋值50时本身已经越界unsignedchar*startblock;//me:虚拟磁盘上数据区开始位置}block0;unsignedchar*myvhard;useropen*openfilelist;charcurrentdir[80];//me:记录当前目录的目录名(包括目录的路径)unsignedchar*startp;//me:记录虚拟磁盘上数据区开始位置voidinitsys();voidformat();voidstartsys();voidexit
4、sys();voidcreate();intopen(char*filename);voidclose(intfd);voidmywrite(intfd,char*buff);voidmyread(intfd,char*buff);voiddeletefile(char*filename);voidls();voidlistopenfile();voidcd(char*dirname);//系统初始化:创建虚盘和格式化虚盘voidinitsys(){myvhard=(unsignedchar*)malloc(SIZE);memset(myvhard,0,SIZE);format
5、();}voidformat(){FILE*fp;time_t*now;structtm*nowtime;unsignedchar*p;fat*fat1,*fat2;fcb*root;inti,a;block0*b0;now=(time_t*)malloc(sizeof(time_t));p=myvhard;b0=(block0*)p;strcpy(b0->information,"Myfilesystem,version0.01,blocksizeis1K,wholesizeis1000K,emulateFAT16,Maxopenfilenumberis10");//prin
6、tf("%s",b0->information);p+=BLOCKSIZE;//me:将虚拟磁盘的第一块分配给了引导块//me:给两个FAT各分配两个盘块fat1=(fat*)(p);fat2=(fat*)(p+BLOCKSIZE*2);//me:对于每个FAT中,前面5个块设置为已分配,后面995个块设置为空闲;//me:即,将两个fat表的前5个表项的id赋值END,第6项为的id赋值6(指向虚拟磁盘的第6块(即根目录文件所在块))fat1->id=END;fat2->id=END;fat1++;fat2++;fat1->id=END;fat2->id=END;fat1
7、++;fat2++;fat1->id=END;fat2->id=END;fat1++;fat2++;fat1->id=END;fat2->id=END;fat1++;fat2++;fat1->id=END;fat2->id=END;fat1++;fat2++;fat1->id=6;fat2->id=6;fat1++;fat2++;fat1->id=END;fat2->id=END;fat1++;fat2++;//me:从第7个表项开始,初始化全部是空闲的for(i=7;i
此文档下载收益归作者所有