Nachos实验报告.docVIP

  • 26
  • 0
  • 约2.09万字
  • 约 11页
  • 2017-11-10 发布于江苏
  • 举报
Nachos实验报告

计算机科学与技术学院实验报告:10 ? 实验题目:具有二级索引的文件系统 姓名:李威 学号:200800130090 日期:2013-12-1 学号:201100300259 班级:11级软件3班 Email:sduliwei@163.com 实验目的: Nachos的文件系统中保存文件内容所在扇区索引的“文件头“目前只占用一个扇区, 为了可以使Nachos文件系统创建较大的文件,将”文件头”扩大到两个扇区,也就是实现二级索引。 硬件环境:? 软件环境: Linux操作系统,Nachos操作系统 实验步骤: 通过实验5的扩展文件大小的实验,了解了nachos 系统的对文件系统的管理。本次实验的目的主要是 扩大Nachos系统可以创建的文件的大小,使用两个扇区来保存文件头的信息。 为了达到这个目的,首先了解nachos 自带的文件系统的文件头的结构: 保存在一个扇区中,第一个int保存了文件的字节数(numBytes),第二个int保存了使用的扇区数 (numSectors),第三个数据结构是文件所在的各个扇区号(dataSectors[NumDiresct])。 也就是说,Nachos系统采用的是索引式的文件管理方式。 因而,要实现nachos文件系统的二级索引,可以使第一个索引节点(也就是原有的文件头那个扇区)的 dataSectors数组的最后一个元素保留第二个索引节点(也就是第二个扇区)的引用(也就是扇区号)。 如果文件大小不超过一个索引节点可以保留的内容,则这个最后一个元素的值为-1。 通过分析可知,需要修改filehdr.cc中的内容。 代码如下: bool FileHeader::Allocate(BitMap *freeMap, int fileSize) { numBytes = fileSize; numSectors = divRoundUp(fileSize, SectorSize); if (freeMap-NumClear() numSectors) return FALSE; // not enough space /*如果文件大小超过索引节点中保存扇区号的数目,则返回false*/ else if(NumDirect + NumDirect2 = numSectors) return FALSE;//the filesys cannot support such big file /*toNextNode 是保留第二个索引节点的扇区号*/ int toNextNode=NumDirect-1; //toNextNode is the Sector number of the second node of the filehdr //if the second node is not needed, then dataSector[toNextNode]=-1 if(numSectors toNextNode) { for (int i = 0; i numSectors; i++) dataSectors[i] = freeMap-Find();//为文件分配扇区 dataSectors[toNextNode] = -1; } //If the numSectors excends the rage of dataSectors, else{ for (int i = 0; i toNextNode; i++) dataSectors[i] = freeMap-Find(); dataSectors[toNextNode] = freeMap-Find();//找一个空闲的扇区,作为第二个扇区,索引节点 //this is the content,i.e.filehdr of the allocated sectors, of the second node int dataSectors2[NumDirect2]; for (int i = 0; i numSectors - NumDirect; i++) dataSectors2[i] = freeMap-Find();//为文件分配扇区 //the fefault synchDisk-WriteSector do not include the second node //so write back the new build node synchDisk-Write

文档评论(0)

1亿VIP精品文档

相关文档