操作系统实验报告模板 联系客服

发布时间 : 星期一 文章操作系统实验报告模板更新完毕开始阅读030dc12d4b35eefdc8d333e1

int i,FcbIndex;

//确保没有打开过该文件 = 相同名字 + 相同目录

for(i=0;i

if(openlist->f[i].type ==GENERAL && strcmp(openlist->f [i].fname,file)==0 &&openlist->f[i].fatherBlockNum == current) {

printf(\该文件已经被打开!\\n\ return 0; } }

//确保有空的打开文件项 if(openlist->files == OPEN_MAX) {

printf(\打开文件数目达到上限!无法再打开新文件.\\n\ return 0; }

//确保当前目录下有该文件,并且记录下它的FCB下标

struct dirFile *dir; //当前目录的指针

if(current==2)

dir=&(osPoint->root); else

dir=(struct dirFile *)(osPoint->data [current-3]);

for(i = 1;i< BlockFcbCount;i++) { //查找该文件

if(dir->fcb[i].type==GENERAL && strcmp(dir->fcb[i].fname,file)==0 ) {

FcbIndex=i; break; } }

if(i==BlockFcbCount) {

printf(\当前目录下不存在该文件!\\n\ return 0; }

//装载新文件进入打开文件列表,(FCB信息,文件数++) ??难道名字过不来? openlist->f[OpenFileCount] = dir->fcb[FcbIndex]; //FCB拷贝 openlist->files ++; printf(\文件打开成功!\\n\ OpenFileCount++; return 1; }

int close(char *file)

{

//释放该文件所占内存 //释放用户打开文件列表表项 int i;

//在打开文件列表中查找 file(还需要考虑同名不同目录文件的情况!!!) for(i=0;i

if((openlist->f [i].type = GENERAL)&&

(strcmp(openlist->f [i].fname,file)==0)) {

if(openlist->f[i].fatherBlockNum == current) { break; } else {

printf(\该文件已打开,但未在当前目录下,无法关闭!\\n\ return 0; } } }

if(i==OPEN_MAX) {

printf(\该文件未在打开列表

中!\\n\ return 0; }

int active=i; openlist->files --;

openlist->f[active].initialize(); OpenFileCount--; printf(\该文件已关闭!\\n\ return 1; } void main() {

/*********************************************************************/ printf(\我的文件系统

************************* \\n\

printf(\ :安全退出 \\n\

printf(\创建目录. \\n\

printf(\删除目录. \\n\

printf(\ dirname :显示当前目录下信息. \\n\

printf(\创建一个新文件,并且打开. \\n\

printf(\选择一个打开的文件写入信息 \\n\

printf(\ filename :选择一个打开的文件读取信息. \\n\

printf(\-----------------\\n\\n\

printf(\ filename :删除文件. while(1){ \\n\

cout<

printf(\ filename :打开文件. \\n\

printf(\关闭文件. \\n\

//创建用户文件打开表 openlist=new OPENLIST; //申请虚拟空间并且初始化 BaseAddr=(char *)malloc(DiskSize); //虚拟磁盘初始化

osPoint=(struct DISK *)(BaseAddr); //加载磁盘文件

if((fp=fopen(FilePath,\

fread(BaseAddr,sizeof(char),DiskSize,fp); printf(\加载磁盘文件( %s )成功,现 在可以进行操作了!\\n\\n\ }

else{

printf(\这是你第一次使用该文件 管理系统!\\t正在初始化...\\n\ format();

printf(\初始化已经完成,现在可以 进行操作了!\\n\\n\ }

cin>>cmd; if(cmd==\

cin>>command; mkdir(command); }

else if(cmd==\ cin>>command; rmdir(command); }

else if(cmd==\ listshow(); }

else if(cmd==\ cin>>command; create(command); } else if(cmd==\ cin>>command; write(command); }

else if(cmd==\ cin>>command; read(command);

}

else if(cmd==\ cin>>command; delfile(command); }

else if(cmd==\ cin>>command; open(command); }

else if(cmd==\ cin>>command; close(command);

}

else if(cmd==\ exit(); break; }

else cout<<\无效指令,请重新输入:\ }

printf(\system!\\n\ }

【实验截图】

这是刚打开时的界面