- 1、本文档共25页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
#include stdio.h
#include memory.h
#include string
#include iostream
using namespace std;
struct FCB
{
char fname[16]; //文件名
int type; //1代表普通文件2代表目录文件0表示空文件
int size; //文件大小
int fatherBlockNum; //当前的父目录盘块号
int firstBlockNum; //该文件第一个盘块号
int currentBlockNum; //当前的盘块
int lastBlockNum;
void initialize()
{
strcpy(fname,\0);
type = 0;
size =0;
fatherBlockNum = firstBlockNum = currentBlockNum =lastBlockNum= 0;
}
};
/*常量设置*/
const char* FilePath = C:\\myfiles;
const int BlockSize = 512; //盘块大小(可配置)
const int OPEN_MAX = 5; //能打开最多的文件数
const int BlockCount = BlockSize/sizeof(int); //盘块数
const int DiskSize = BlockSize*BlockCount; //磁盘大小
const int BlockFcbCount = BlockSize/sizeof(FCB);//目录文件的最多FCB数
const int m=16; //位示图的列数
const int n=BlockCount/m; //位示图的行数
//const int IOBUF_SIZE = 512;
//char IOBuffer[IOBUF_SIZE];
int OpenFileCount = 0;
struct OPENLIST //用户文件打开表
{
int files; //当前打开文件数
FCB f[OPEN_MAX]; //FCB拷贝
OPENLIST()
{
files=0;
for(int i=0;iOPEN_MAX;i++){
f[i].fatherBlockNum=-1;//为分配打开
f[i].type=0;
}
}
};
/*-------------目录文件结构---------------*/
struct dirFile
{
struct FCB fcb[BlockFcbCount];
void init(int _FatherBlockNum,int _FirstBlockNum, int _CurrentBlockNum,int _LastBlockNum,char *name)//父块号,第一个盘块号,当前块号,目录名
{
strcpy(fcb[0].fname,name); //本身的FCB
fcb[0].fatherBlockNum=_FatherBlockNum;
fcb[0].firstBlockNum=_FirstBlockNum;
fcb[0].currentBlockNum=_CurrentBlockNum;
fcb[0].lastBlockNum=_LastBlockNum;
fcb[0].type=2; //标记目录文件
for(int i=1;iBlockFcbCount;i++)
{
fcb[i].fatherBlockNum=_CurrentBlockNum; //标记为子项
fcb[i].type=0; // 标记为空白项
}
}
};
/**********************************************************************/
struct DISK
{
int FAT1[BlockCount]; //FAT1
int FAT2[BlockCount]; //FAT2
struct dirFile root; //根目录
int map[n][m]; //位示图,最初都为0
int check[n][m]; //check数组用于一致性检查,作为数据计数器;
ch
文档评论(0)