教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 学前教育 >

山大操作系统课程设计报告(全套)(8)

来源:网络收集 时间:2026-05-20
导读: /*toNextNode 是保留第二个索引节点的扇区号*/ int toNextNode=NumDirect-1; //toNextNode is the Sector number of the second node of the filehd //if the second node is not needed, then dataSector[toNextNo

/*toNextNode 是保留第二个索引节点的扇区号*/

int toNextNode=NumDirect-1; //toNextNode is the Sector number of the second node of the filehd

//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->WriteSector(dataSectors[toNextNode], (char *)dataSectors2); }

return TRUE;

/*revised*/ }

void

FileHeader::Deallocate(BitMap *freeMap) {

/*toNextNode 是保留第二个索引节点的扇区号*/

int toNextNode= NumDirect - 1;

// test if has the second node if(dataSectors[toNextNode]==-1) {

for (int i = 0; i < numSectors; i++) {

ASSERT(freeMap->Test((int) dataSectors[i])); // ought to be marked! freeMap->Clear((int) dataSectors[i]); } }

//has a second node, then find it, then clean the bitmap, then else {

//clear the first n-1 bit,remain the toNextNode int i=0;

for ( ; i < toNextNode; i++) {

ASSERT(freeMap->Test((int) dataSectors[i])); // ought to be marked! freeMap->Clear((int) dataSectors[i]); }

int dataSectors2[NumDirect2];

synchDisk->ReadSector(dataSectors[toNextNode], (char *)dataSectors2); freeMap->Clear((int) dataSectors[toNextNode]);//clear the toNextNode

for( ; i < numSectors; i++)

freeMap->Clear((int) dataSectors2[i-toNextNode]);//toNextNode==the number of filehdr item} } int

FileHeader::ByteToSector(int offset) {

ASSERT(offset<=numBytes);

/*toNextNode 是保留第二个索引节点的扇区号*/

int toNextNode = NumDirect - 1; //test if offset excedes the first node if(offset / SectorSize < toNextNode)

return(dataSectors[offset / SectorSize]); else {

int dataSectors2[NumDirect2];

synchDisk->ReadSector(dataSectors[toNextNode], (char *)dataSectors2); return (dataSectors2[offset / SectorSize - toNextNode]); } }

void

FileHeader::Print() {

/*revised*/ int i, j, k;

/*toNextNode 是保留第二个索引节点的扇区号*/

int toNextNode = NumDirect - 1;

char *data = new char[SectorSize];

//test if there is a second node if(dataSectors[toNextNode] == -1) {

printf(\ for (i = 0; i < numSectors; i++) printf(\ printf(\

for (i = k = 0; i < numSectors; i++) { synchDisk->ReadSector(dataSectors[i], data);

for (j = 0; (j < SectorSize) && (k < numBytes); j++, k++) { if ('\\040' <= data[j] && data[j] <= '\\176') // isprint(data[j])

printf(\ else

printf(\}

printf(\ } }

// If there is a secondary index,

// first read in the dataSectors2 from the Disk. // Then, deallocate the data blocks for this file.

// At last, deallocate the block that dataSector2 locates. else {

int dataSectors2[NumDirect2];

synchDisk->ReadSector(dataSectors[toNextNode], (char *)dataSectors2); //1, print the filedre items

printf(\ for (i = 0; i < toNextNode; i++) printf(\for(; i < numSectors; i++)

printf(\ printf(\

//2,print the content of the first node pointed for (i = k = 0; i < toNextNode; i++) { synchDisk->ReadSector(dataSectors[i], data);

for (j = 0; (j < SectorSize) && (k < numBytes); j++, k++) { if ('\\040' <= data[j] && data[j] <= '\\176') // isprint(data[j]) printf(\ else

printf(\}

printf(\ }

//3,print the content of the second node pointed for( ; i < numSectors; i++) {

synchDisk->ReadSector(dataSectors2[i - toNextNode], data);

for (j = 0; (j < SectorSize) && (k < numBytes); j++, k++) { if ('\\040' <= data[j] && data[j] <= '\\176') // isprint(data[j]) printf(\ else

printf(\}

printf(\

…… 此处隐藏:1071字,全部文档内容请下载后查看。喜欢就下载吧 ……
山大操作系统课程设计报告(全套)(8).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/598633.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)