操作系统文件管理系统模拟实验.doc

上传人:b****3 文档编号:2004366 上传时间:2022-10-26 格式:DOC 页数:18 大小:188.50KB
下载 相关 举报
操作系统文件管理系统模拟实验.doc_第1页
第1页 / 共18页
操作系统文件管理系统模拟实验.doc_第2页
第2页 / 共18页
操作系统文件管理系统模拟实验.doc_第3页
第3页 / 共18页
操作系统文件管理系统模拟实验.doc_第4页
第4页 / 共18页
操作系统文件管理系统模拟实验.doc_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

操作系统文件管理系统模拟实验.doc

《操作系统文件管理系统模拟实验.doc》由会员分享,可在线阅读,更多相关《操作系统文件管理系统模拟实验.doc(18页珍藏版)》请在冰豆网上搜索。

操作系统文件管理系统模拟实验.doc

文件管理系统模拟

1.实验目的

通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能及内部实现

2.实验内容

为Linux系统设计一个简单的二级文件系统。

要求做到以下几点:

(1)可以实现下列几条命令(至少4条)

login 用户登录

dir 列文件目录

create 创建文件

delete 删除文件

open 打开文件

close 关闭文件

read 读文件

write 写文件

(2)列目录时要列出文件名、物理地址、保护码和文件长度;

(3)源文件可以进行读写保护。

3.实验提示

(1)首先应确定文件系统的数据结构:

主目录、子目录及活动文件等。

主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。

(2)用户创建的文件,可以编号存储于磁盘上。

入file0,file1,file2…并以编号作为物理地址,在目录中进行登记。

4.源代码

#include

#include

#include

#defineMEM_D_SIZE1024*1024//总磁盘空间为1M

#defineDISKSIZE1024 //磁盘块的大小1K

#defineDISK_NUM1024 //磁盘块数目1K

#defineFATSIZEDISK_NUM*sizeof(structfatitem) //FAT表大小

#defineROOT_DISK_NOFATSIZE/DISKSIZE+1 //根目录起始盘块号

#defineROOT_DISK_SIZEsizeof(structdirect) //根目录大小

#defineDIR_MAXSIZE1024 //路径最大长度为1KB

#defineMSD5 //最大子目录数5

#defineMOFN5 //最大文件深度为5

#defineMAX_WRITE1024*128 //最大写入文字长度128KB

structfatitem/*size8*/

{

intitem;/*存放文件下一个磁盘的指针*/

charem_disk;/*磁盘块是否空闲标志位0空闲*/

};

structdirect

{

/*-----文件控制快信息-----*/

structFCB

{

charname[9];/*文件/目录名8位*/

charproperty;/*属性1位目录0位普通文件*/

intsize;/*文件/目录字节数、盘块数)*/

intfirstdisk;/*文件/目录起始盘块号*/

intnext;/*子目录起始盘块号*/

intsign;/*1是根目录0不是根目录*/

}directitem[MSD+2];

};

structopentable

{

structopenttableitem

{

charname[9];/*文件名*/

intfirstdisk;/*起始盘块号*/

intsize;/*文件的大小*/

}openitem[MOFN];

intcur_size;/*当前打文件的数目*/

};

structfatitem*fat;/*FAT表*/

structdirect*root;/*根目录*/

structdirect*cur_dir;/*当前目录*/

structopentableu_opentable;/*文件打开表*/

intfd=-1;/*文件打开表的序号*/

char*bufferdir;/*记录当前路径的名称*/

char*fdisk;/*虚拟磁盘起始地址*/

voidinitfile();

voidformat();

voidenter();

voidhalt();

intcreate(char*name);

intopen(char*name);

intclose(char*name);

intwrite(intfd,char*buf,intlen);

intread(intfd,char*buf);

intdel(char*name);

intmkdir(char*name);

intrmdir(char*name);

voiddir();

intcd(char*name);

voidprint();

voidshow();

voidinitfile()

{

fdisk=(char*)malloc(MEM_D_SIZE*sizeof(char));/*申请1M空间*/

format();

}

voidformat()

{

inti;

FILE*fp;

fat=(structfatitem*)(fdisk+DISKSIZE);/*计算FAT表地址,引导区向后偏移1k)*/

/*-----初始化FAT表------------*/

fat[0].item=-1;/*引导块*/

fat[0].em_disk='1';

for(i=1;i

{

fat[i].item=i+1;

fat[i].em_disk='1';

}

fat[ROOT_DISK_NO].item=-1;/*存放根目录的磁盘块号*/

fat[ROOT_DISK_NO].em_disk='1';

for(i=ROOT_DISK_NO+1;i

{

fat[i].item=-1;

fat[i].em_disk='0';

}

/*-----------------------------------------------*/

root=(structdirect*)(fdisk+DISKSIZE+FATSIZE);/*根目录的地址*/

/*初始化目录*/

/*---------指向当前目录的目录项---------*/

root->directitem[0].sign=1;

root->directitem[0].firstdisk=ROOT_DISK_NO;

strcpy(root->directitem[0].name,".");

root->directitem[0].next=root->directitem[0].firstdisk;

root->directitem[0].property='1';

root->directitem[0].size=ROOT_DISK_SIZE;

/*-------指向上一级目录的目录项---------*/

root->directitem[1].sign=1;

root->directitem[1].firstdisk=ROOT_DISK_NO;

strcpy(root->directitem[1].name,"..");

root->directitem[1].next=root->directitem[0].firstdisk;

root->directitem[1].property='1';

root->directitem[1].size=ROOT_DISK_SIZE;

if((fp=fopen("disk.dat","wb"))==NULL)

{

printf("Error:

\nCannotopenfile\n");

return;

}

for(i=2;i

{

root->directitem[i].sign=0;

root->directitem[i].firstdisk=-1;

strcpy(root->directitem[i].name,"");

root->directitem[i].next=-1;

root->directitem[i].property='0';

root->directitem[i].size=0;

}

if((fp=fopen("disk.dat","wb"))==NULL)

{

printf("Error:

\nCannotopenfile\n");

return;

}

if(fwrite(fdisk,MEM_D_SIZE,1,fp)!

=1)/*把虚拟磁盘空间保存到磁盘文件中*/

{

printf("Error:

\nFilewriteerror!

\n");

}

fclose(fp);

}

voidenter()

{

FILE*fp;

inti;

fdisk=(char*)malloc(MEM_D_SIZE*sizeof(char));/*申请1M空间*/

if((fp=fopen("disk.dat","rb"))==NULL)

{

printf("Error:

\nCannotopenfile\n");

return;

}

if(!

fread(fdisk,MEM_D_SIZE,1,fp))/*把磁盘文件disk.dat读入虚拟磁盘空间(内存)*/

{

printf("Error:

\nCannotreadfile\n");

exit(0);

}

fat=(structfatitem*)(fdisk+DISKSIZE);/*找到FAT表地址*/

root=(structdirect*)(fdisk+DISKSIZE+FATSIZE);/*找到根目录地址*/

fclose(fp);

/*--------------初始化用户打开表------------------*/

for(i=0;i

{

strcpy(u_opentable.openitem[i].name,"");

u_opentable.openitem[i].firstdisk=-1;

u_opentable.openitem[i].size=0;

}

u_opentable.cur_size=0;

cur_dir=root;/*当前目录为根目录*/

bufferdir=(char*)malloc(DIR_MAXSIZE*sizeof(char));

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 工程科技 > 纺织轻工业

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1