文件系统的管理Word格式.docx
- 文档编号:20177751
- 上传时间:2023-01-17
- 格式:DOCX
- 页数:18
- 大小:336.89KB
文件系统的管理Word格式.docx
《文件系统的管理Word格式.docx》由会员分享,可在线阅读,更多相关《文件系统的管理Word格式.docx(18页珍藏版)》请在冰豆网上搜索。
2.查打开文件表afd
未找到,下一步
未找到,返回(文件名不对)
3.查用户文件目录ufd
4.将对应表目从ufd中删除
5.释放回收文件记录空间
6释放表目结点空间free(*q2),返回
(4)写文件pwrite()
1.输入文件名=〉x未找到,返回(文件未打开)
3.分配记录存储空间=〉pname=〉p→name
4.提示用户输入记录数据
sex=〉p→sex
5.将该记录插在串联文件链尾
6.置修改标志1=〉flag
7.文件长度计数length++,返回
(5)读文件pread()
1.输入文件名
未找到,返回
3.提示用户输入
欲查找记录号=〉Ri
4查找串联文件,找到第Ri个记录(未找到Ri出错返回)
5输出记录号,姓名,性别等记录信息后,返回
注:
1.可在找到记录显示内容后,询问用户是否要修改记录值?
若要修改则输入新的记录值(姓名或性别)存入记录(结点)
2.若采用顺序文件结构,可用动态数组存放记录
上述两函数(读/写)稍作修改即可
3.可根据上述算法思想编写pread和pwrite函数
(6)其它程序模块(函数)
print1():
显示主目录
print2():
显示当前用户的文件目录
print3():
显示文件内容
close():
退出某用户操作时,关闭所有打开文件(注意:
必要时复制打开文件的文件长度及文件物理地址到用户文件目录的对应文件表目中)
四运行结果
1.创建主目录
2.创建文件目录
2
3.打开文件目录
4.显示文件目录
5.写文件-添加姓名:
lq和性别:
6.写文件-添加姓名:
whb和性别:
1
7.显示所建文件内容
8.读文件
9.在所读文件中修改文件
10.显示修改后内容
五源代码
#include<
stdio.h>
structlinkf/*主目录*/
{charusername[16];
structlinks*next;
};
structlinkr/*文件——记录类型*/
{charname[16];
intsex;
structlinkr*next;
structlinks/*用户文件目录*/
{charfilename[16];
structlinkr*headlink;
intlength;
structlinkt/*打开文件表*/
intflag;
structlinkt*next;
structlinkfmfd[5];
structlinks*ufd,*p2,*q2;
structlinkr*p,*q;
structlinkt*afd,*p3,*q3;
charX[16],s,username[16];
intr,i,w,n,m,j,t,flag;
voidprint1()
{inti,j;
printf("
\nMFD:
\n"
);
----------------\n"
for(i=0;
i<
n;
i++)
{printf("
|%s"
mfd[i].username);
\n----------------\n"
}
voidprint2()
{inti;
if(flag==i&
&
ufd!
=NULL)
\nMFD__[%s]\n"
p2=mfd[i].next;
+_UFD-Filename_+_Length_+\n"
while(p2!
|%10s|%4d|\n"
p2->
filename,p2->
length);
p2=p2->
next;
+--------------+--------------+\n"
if(ufd==NULL)printf("
\nUFD_[%s]isNULL\n"
username);
if(afd!
{p3=afd;
\n\nAFD_[%s]\n"
+-----Filename-----+----length---+\n"
while(p3!
|%12s|%d|\n"
p3->
filename,p3->
p3=p3->
+------------------|-------------+\n"
elseprintf("
\n\nAFD_[%s]isNULL\n"
voidprint3()
charsex[8];
p3=afd;
Inputprinting-filename:
"
scanf("
%s"
X);
if(p3!
{while((strcmp(p3->
filename,X)!
=0)&
(p3->
next!
=NULL))
if(strcmp(p3->
=0)
Thefilehasn'
topened!
else
if(p3->
headlink==NULL)printf("
ThefileisNULL!
else{p=p3->
headlink;
i=1;
|num|name|sex|\n"
---------------------------------------\n"
while(p!
{if(p->
sex==1)strcpy(sex,"
man"
elsestrcpy(sex,"
woman"
printf("
|%5d|%10s|%6s|\n"
i,p->
name,sex);
i++;
p=p->
}elseprintf("
voidpcreate()
{printf("
Inputcreatefilename:
scanf("
q2=ufd;
if(q2!
{while((strcmp(q2->
(q2->
q2=q2->
if(strcmp(q2->
filename,X)==0)
Filehasalreadybeencreated!
return;
p2=(structlinks*)malloc(sizeof(structlinks));
if(ufd==NULL)ufd=p2;
elseq2->
next=p2;
strcpy(p2->
filename,X);
p2->
length=0;
next=NULL;
headlink=NULL;
CreateFileFinished!
voidpopen()
{p2=ufd;
InputOpenfilename:
if(p2!
{while((strcmp(p2->
(p2->
if(strcmp(p2->
{q3=afd;
{while((strcmp(q3->
(q3->
q3=q3->
if(strcmp(q3->
Thefile\"
%s\"
hasbeenopened.\n"
p3=(structlinkt*)malloc(sizeof(structlinkt));
if(afd==NULL)afd=p3;
elseq3->
next=p3;
strcpy(p3->
length=p2->
length;
headlink=p2->
flag=0;
hasbeenopened.\n"
Can'
tfind\"
filein\"
USER.\n"
X,username);
voidpclose()
{
Inputclosefilename:
q3=p3=afd;
while((strcmp(q3->
q3->
{
p3=q3;
q3=q3->
}
if(strcmp(q3->
{
if(q3==afd)afd=q3->
elsep3->
next=q3->
if(q3->
flag==1)
{
p2=ufd;
while(strcmp(p2->
filename,q3->
filename)!
=0&
p2=p2->
if(strcmp(p2->
filename)==0)
{p2->
length=q3->
headlink=q3->
}
}
q3=NULL;
free(q3);
printf("
\nThefileisclosed.\n"
return;
Youhasn'
topenedfile%s.\n"
close()
while(afd!
p3=afd;
afd=afd->
p2=ufd;
while(strcmp(p2->
=NULL)
p2=p2->
if(strcmp(p2->
filename)==0&
p3->
p2->
length=p3->
headlink=p3->
free(p3);
pread()
{
intrecord_no;
intmodify_flag;
charnew_name[16];
intnew_sex=0;
q3=afd;
PleaseInputFilenametoberead:
while((strcmp(q3->
=0)&
(q3->
PleaseopenFilebefore"
PleaseInputFiletoberecord:
%d"
&
record_no);
if(record_no<
=q3->
length)
p=q3->
for(i=1;
record_no;
i++)p=p->
name:
%sandsex:
%d\n"
p->
name,p->
sex);
Doyouwanttomodifytherecord?
1--yes2--no\n"
modify_flag);
if(modify_flag==1)
PleaseInputnewname:
new_name);
PleaseInputnewsex:
new_sex);
strcpy(p->
name,new_name);
p->
sex=new_sex;
modifyrecordOK!
Pleaseinputnum:
hasnotopened.\n"
main()
{afd=NULL;
ufd=NULL;
for(i=0;
5;
{strcpy(mfd[i].username,"
"
mfd[i].next=NULL;
UsernumberN(N<
=5)="
n);
{w=0;
UserMFDusernameX[%d]="
i+1);
for(j=0;
j<
j++)
if(strcmp(mfd[j].username,X)==0)w=1;
if(w==0)strcpy(mfd[i].username,X);
\nTheUsernamehasbeenCreated!
i--;
do
{print1();
Inputusernameyouwanttooperate:
(i<
n&
(strcmp(mfd[i].username,username)!
=0));
i++);
if(i>
=n){printf("
NotfoundUsername!
}while(i>
=n);
t=0;
flag=i;
ufd=mfd[i].next;
\n------------------------------------\n"
1--Creat2--Open3--Delete\n"
4--cLose5--Read6--Write\n"
7--disPlay8--fileplay9--Quit\n"
------------------------------------\n"
Select[]\b\b"
s);
switch(s)
{case'
1'
:
pcreate();
break;
case'
2'
popen();
3'
pdelete();
4'
pclose();
5'
pread();
6'
pwrite();
7'
print2();
8'
print3();
9'
t=1;
close();
mfd[i].next=ufd;
}while(!
t);
\n---------------------------------------\n"
|1--Editotheruser,2--Quit|\n"
);
m);
if(m==2)r=1;
elser=0;
r);
六总结
经过本次操作系统课程设计,本人在各种资料的引导下,完成设计。
通过该本次试验,收获颇多。
对实验原理有更深的理解,掌握了什么是文件系统,操作系统是如何对文件目录和文件进行管理的,管理工作的基本过程及其各阶段的基本任务,熟悉了文件管理系统程序总流程框图,了解了文件的生成过程、构造过程及其相关的技术对课本上的知识有了更深的理解,课本上的知识师机械的,表面的。
通过把该算法的内容,算法的执行顺序在计算机上实现,把原来以为很深奥的书本知识变的更为简单,对实验原理有更深的理解。
对该理论在实践中的应用有深刻的理解,通过把该算法的内容,算法的执行顺序在计算机上实现,知道和理解了该理论在计算机中是怎样执行的,对该理论在实践中的应用有深刻的理解。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 文件系统 管理