📄 harddevice.h
字号:
#ifndef HardDevice_tag
#define HardDevice_tag
#include <vector>
#include "HDblock.h"
#include "Nfile.h"
#define BLOCK_NUM 512
#define FILENAME "hddrv.hdr"
class HardDevice //虚拟磁盘
{
private:
HDblock bk[BLOCK_NUM];
//const static std::string FILENAME="hddrv.hdr";//对应文件名
int blk_sum_num;//磁盘总块数 BLOCK_NUM
//int inode_blk_num;//i节点所占块数 1
int blk_free_num;//空闲块总数 BLOCK-inode_blk_num
//int *p_blk_free;//
//////////////std::vector<int>p_blk_free;
//DiNode *p_inode_index;//i节点数组
//std::vector<DiNode>p_inode_index;
int inode_num;//inode 个数
Index_File *rootfile;
public:
HardDevice(std::string filename=FILENAME)
{
blk_sum_num=BLOCK_NUM;//总块数
std::ifstream phyDev(filename.c_str(),std::ios::in|std::ios::binary);
if(phyDev.is_open())
{
/* for(int i=0;i<BLOCK_NUM;i++)
{
//phyDev.read(bk+i,BLOCK_SIZE);
phyDev>>bk[i];
}
//专用块中读取信息
bk[1].readInt(&blk_free_num);
bk[1].readInt(&inode_num);
HDblock* p_hbk=&bk[2];
while(1)
{
int tmp;
if(p_hbk->readInt(&tmp))
{
p_blk_free.push_back(tmp);
continue;
}
if(!(p_hbk->hasNext()))
{
break;
}
else
{
p_hbk=&bk[p_hbk->getNext()];
}
}
p_hbk=&bk[6];
while(1)
{
DiNode tmp(0,0,0);
if(p_hbk->readDinode(&tmp))
{
p_inode_index.push_back(tmp);
continue;
}
if(!(p_hbk->hasNext()))
{
break;
}
else
{
p_hbk=&bk[p_hbk->getNext()];
}
}
*/
}
else //新建磁盘
{//0号块不用,从1号块开始
blk_sum_num=BLOCK_NUM;//总块数
//bk[1].write(blk_sum_num);
blk_free_num=BLOCK_NUM-1-1-4-16;//空闲块数
//bk[1].write(blk_free_num);
for(int i=22;i<500;i++)
{
bk[i].setFree();
}
inode_num=1;// i节点数
//bk[1].write(inode_num);
rootfile=new Index_File ("/",getFreeBlock(),pcurUser->getUid(),NULL);
//p_inode_index.push_back(*(rootfile->getInode()));
}
}
/* ~HardDevice()
{
std::string filename=FILENAME;
std::ofstream phyDev(filename.c_str(),std::ios::out|std::ios::binary);
{
//专用块中写入信息
}
if(phyDev.is_open())
{
for(int i=0;i<BLOCK_NUM;i++)
{
//phyDev.read(bk+i,BLOCK_SIZE);
phyDev<<bk[i];
}
}
else//新建磁盘
{
}
//debug
phyDev.close();
system("del hddrv.hdr");
}
*/
HDblock* getFreeBlock()
{
for(int i=22;i<500;i++)
{
if(bk[i].setUsed())
return bk+i;
}
return 0;
}
Index_File*getRoot()
{
return rootfile;
}
HDblock *getBlock(int n)
{
return &bk[n];
}
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -