汇编简单的操作系统.docx

上传人:b****8 文档编号:9038945 上传时间:2023-02-02 格式:DOCX 页数:46 大小:23.28KB
下载 相关 举报
汇编简单的操作系统.docx_第1页
第1页 / 共46页
汇编简单的操作系统.docx_第2页
第2页 / 共46页
汇编简单的操作系统.docx_第3页
第3页 / 共46页
汇编简单的操作系统.docx_第4页
第4页 / 共46页
汇编简单的操作系统.docx_第5页
第5页 / 共46页
点击查看更多>>
下载资源
资源描述

汇编简单的操作系统.docx

《汇编简单的操作系统.docx》由会员分享,可在线阅读,更多相关《汇编简单的操作系统.docx(46页珍藏版)》请在冰豆网上搜索。

汇编简单的操作系统.docx

汇编简单的操作系统

114

Step24

Step25open()

Step26

Step27

Step28

Step29logout

Step30halt

End

1.makefile

makefile

makefile

filsys:

main.oigetput.oiallfre.oballfre.oname.oaccess.olog.oclose.ocreat.odelete.odir.oopen.ordwt.oformat.oinstall.ohalt.cc–ofilsysmain.oigetput.oiallfre.oballfre.o

name.oaccess.olog.oclose.ocreat.odelete.odir.oopen.ordwt.oformat.oinstall.ohalt.o

main.o:

main.cfilesys.h

cc–cmain.c

igetput.o:

igetput.cfilesys.h

cc–cigetput.c

iallfre.o:

iallfre.cfilesys.h

cc–ciallfre.c

ballfre.o:

ballfre.cfilesys.h

cc–caccess.c

log.o:

log.cfilesys.h

cc–clog.c

close.o:

close.cfilesys.h

cc–cclose.c

creat.o:

creat.cfilesys.h

cc–ccreat.c

115

delete.o:

delete.cfilesys.h

cc–cdelete.c

dir.o:

dir.cfilesys.h

cc–cdir.c

open.o:

open.cfilesys.h

cc–copen.c

rdwt.o:

rdwt.cfilesys.h

cc–crdwt.c

format.o:

format.cfilesys.h

cc–cformat.c

install.o:

install.cfilesys.h

cc–cinstall.c

halt.o:

halt.c

cc–chalt.c

2.filesys.h

filesys.h

filesys.h

#defineBLOCKSIZ512

#defineSYSOPENFILE40

#defineDIRSIZ14

#definePWDSIZ12

#definePWDNUM32

#defineNOFILE20

#defineNADDR10

#defineNHINO128/*mustbepowerof2*/

#defineUSERNUM10

#defineDINODESIZ32

/*filsys*/

#defineDINODEBLK32

#defineFILEBLK512

#defineNICFREE50

#defineNICINOD50

#defineDINODESTART2*BLOCKSIZ

#defineDATASTART(2+DINODEBLK)*BLOCKSIZ

116

/*di_mode*/

#defineDIEMPTY00000

#defineDIFILE01000

#defineDIDIR02000

#defineUDIREAD00001/*user*/

#defineUDIWRITE00002

#defineUDIEXICUTE00004

#defineGDIREAD00010/*group*/

#defineGDIWRITE00020

#defineGDIEXICUTE00040

#defineODIREAD00100/*other*/

#defineODIWRITE00200

#defineODIEXICUTE00400

#defineREAD1

#defineWRITE2

#defineEXICUTE3

#defineDEFAULTMODE00777

/*i_flag*/

#defineIUPDATE00002

/*s_fmod*/

#defineSUPDATE00001

/*f_flag*/

#defineFREAD00001

#defineFWRITE00002

#defineFAPPEND00004

/*error*/

#defineDISKFULL65535

/*fseekorigin*/

#defineSEEK_SET0

structinode{

structinode*i_forw;

structinode*i_back;

117

chari_flag;

unsignedinti_ino;

unsignedinti_count;

unsignedshortdi_number;

unsignedshortdi_mode;

unsignedshortdi_uid;

unsignedshortdi_gid;

unsignedshortdi_size;

unsignedintdi_addr[NADDR];

};

structdinode{

unsignedshortdi_number;

unsignedshortdi_mode;

unsignedshortdi_uid;

unsignedshortdi_gid;

unsignedlongdi_size;

unsignedintdi_addr[NADDR]

};

stuctdirect{

chard_name[DIRSIZ];

unsignedintd_ino;

};

structfilsys{

unsignedshorts_isize;

unsignedlongs_fsize

unsignedints_nfree;

unsignedshorts_pfree;

unsignedints_free[NICFREE];

unsignedints_ninode;/*numberoffreeinodeins_inode*/

unsignedshorts_pinode;/*pointerofthesinode*/

unsignedints_inode[NICINOD];

unsignedints_rinode;/*rememberinode*/

chats_fmod;

};

structpwd{

unsignedshortp_uid;

unsignedshortp_gid;

118

charpassword[PWDSIZ];

};

structdir{

structdirectdirect[DIRNUM];

intsize;

};

structhinode{

structinode*i_forw;/*hash*/

};

structfile{

charf_flag;

unsignedintf_count;

structinode*f_inode;

unsignedlongf_off;/*read/writecharacterpointer*?

};

structuser{

unsignedsjpitu_default_mode;

unsignedsjpitu_uid;

unsignedsjpitu_gid;

unsignedsjpitu_ofile[NOFILE];

/*systemopenfilepointernumber*/

};

externstructhinodehinode[NHINO];

externstructdirdir;

externstructfilesys_ofile[SYSOPENFILE];

externstructfilesysfilsys;

externstructpwdpwd[PWDNUM];

externstructuseruser[USERNUM];

externFILE*fd;/*thefilesystemcolumnofallthesystem*/

externstructinode*cur_path_inode;

externintuser_id;

/*proptypeofthesubroutionusedinthefilesystem*/

externstructinode*iget();

externinput();

externunsignedintballoc();

externbfree();

119

externstructinode*ialloc();

externifree();

externunsignedintnamei();

externunsignedshortiname()

externunsignedintaccess();

extern_dir()

externmkdir();

externchdir();

externunsignedshortopen();

externcreat();

externunsignedintread();

externunsignedintwrite();

externintlogin();

externlogout();

externinstall();

externformat();

externclose();

externhalt();

3.main()main.c

main.c

#include

#include“filesys.h”

strictjompdejompde[NHINO];

structdirdir;

structfilesys_ofile[SYSOPENFILE];

structfilsysfilsys;

structpwdpwd[PWDNUM];

structuseruser[USERNUM];

FILE*fd;

structinode*cur_path_inode;

intuser_id;

main()

{

unsignedshortab_fd1.ab_fd2.ab_fd3.ab_fd4;

unsignedshortbhy_fdl;

120

char*buf;

print(“\nDoyouwanttoformatthedisk\n”);

if(getchar()==‘y’)

printf(“\nFormatwilleraseallcontextonthedisk\nAreYouSure!

!

\n”);

if(getchar()==‘y’)

format();

install();

_dir();

login(2118,“abcd”);

user_id=0;

mkdir(“a2118”);

chdir(“a2118”);

wifd1=creat(2118.“ab_file0.c”.01777);

buf=(char*)malloc(BLOCKSIZ*6+5);

write(ab_fdl.buf.BLOCKSIZ*6+5);

close(user_id.ab_fdl);

free(buf);

mkdir(“subdir”);

chdir(“subdir”);

wj_fd2=creat(2118.“file1.c”.01777);

buf=(char*)malloc(BLOCKSIZ*4+20);

write(ab_fd2,buf,BLOCKSIZ*4+20);

close(user_id,ab_fd2);

free(buf);

chdir(“..”);

ab_fd3=creat(2118.“_file2.c”,01777);

buf=(char*)malloc(BLOCKSIZ*10+255);

write(ab_fd3,but,BLOCKSIZ*3+255);

close(ab_fd3);

free(buf);

delete(“ab_file0.c”);

sb_fd4=creat(2118.“ab_file3.c”.01777);

buf=(char*)malloc(BLOCKSIZ*8+300);

write(aab_fd4,buf,BLOCKSIZ*8+300);

close(ab_fd4);

free(buf);

121

ab_fd3=open(2118,“ab_file2.c”.FAPPEND);

buf=(char*)malloc(BLOCKSIZ*3+100);

write(ab_fd3,buf,BLOCKSIZ*3+100);

close(ab_fd3);

free(buf);

_dir();

chdir(“..”);

logout();

halt();

}

4.format()format.c

#include

#include“filesys.h”

format()

{

structinode*inode;

structdirectdir_buf[BLOCKSIZ/(DIRSIZ+2)];

structpwdpasswd[BLOCKSIZ/(PWDSIZ+4)];

/*

{

{2116,03,“dddd”},

{2117,03,“bbbb”},

{2118,04,“abcd”},

{2119,04,“cccc”},

{2120,05,“eeee”},

};

*/

structfilsys;

unsignedintblock_buf[BLOCKSIZ/sizeof(int)];

char*buf;

intI,jl

/*creatthefilesystemfile*/

fd=(char*)malloc((DINODEBLK+FILEBLK+2)*BLOCKSIZ*sizeof(char));

if(buf==NULL)

{

122

printf(“\nfilesystemfilecreatfailed!

!

!

\n”);

exit(0);

}

fseek(fd,0,SEEK_SET);

fwrite(buf,1,(DINODEBLK+FILEBLK+2)*BLOCKSIZ*sizeof(char),fd);

/*0.initializethepasswd*/

passwd[0].p_uid=2116;passwd[0].p_gid=03;

strepy(passwd[0].password,“dddd”);

passwd[1].p_uid=2117;passwd[1].p_gid=04;

strepy(passwd[1].password,“bbbb”);

passwd[2].p_uid=2118;passwd[2].p_gid=04;

strepy(passwd[2].password,“abcd”);

passwd[3].p_uid=2119;passwd[3].p_gid=04;

strepy(passwd[3].password,“cccc”);

passwd[4].p_uid=2120;passwd[4].p_gid=05;

strepy(passwd[2].password,“eeee”);

/*1.creatthemaindirecroryanditssubdiretcandthefilepassword*/

inode=iget(0);/*0emptydinodeid*/

inode->di_mode=DIEMPTY;

iput(inode);

inode=iget

(1);/*1maindirid*/

inode->di_muber=1;

inode->di_mode=DEFAULTMODE|DIDIR;

inode->di_size=3*(DIRSIZ+2);

inode->di_addr[0]=0;/*block0#isusedbythemaindirectory*/

strcpy(dir_buf[0].d_name,“..”);

dir_buf[0].d_ino=1;

strcpy(dir_buf[1].d_name.“.”);

dir_buf[1].d_ino=2;

strcpy(dir_buf[2].d_name.“etc”);

dir_buf[2].d_ino=2;

fseek(fd,DATASTART,SEEK_SET);

fwrite(dir_buf,1,3*(DIRSIZ+2).FD);

iput(inode);

inode=iget

(2);/*2etcdirid*/

inode->di_number=1;

123

inode->di_mode=DEFAULTMODE|DIDIR;

inode->di_size=3*(DIRSIZ+2);

inode->di_addr[0]=1;/*block1#isusedbytheetcdirectory*/

strcpy(dir_buf[0].d_name,“..”);

dir_buf[0].d_ino=1;

strcpy(dir_buf[1].d_name,“.”);

dir_buf[1].d_ino=2;

strcpy(dir_buf[2].d_name,“password”);

dir_buf[2].d_ino=3;

fseek(fd,DATASTART+BLOCKSIZ*1,SEEK_SET);

fwrite(dir_buf,1,3*(DIRSIZ+2),fd);

iput(inode);

inode=iget(3);/*3passwordid*/

inode->di_number=1;

inode->di_mode=DEFAULTMODE|DIFILE;

inode->di_size=BLOCKSIZ;

inode->di_addr[0]=2;/*block2#isusedbythepasswordfile*/

for(I=5;i

{

passwd[i].p_uid=0;

passwd[i].p_gid=0;

strcpy(passwd[i].password.“”);

}

fseek(fd,DATASTART+2*BLOCKSIZ,SEEK_SET);

fwrite(passwd,1,BLOCKSIZ,fd);

iput(inode);

/*2.initializethesuperblock*/

filsys.s_isize=DINODEBLK;

filsys.s_isize=FILEBLK;

filsys.s_ninode=DINODEBLK*BLOCKSIZ/DINODESIZ–4

filsys.s_nfree=FILEBLK–3;

for(I=o;i

{

/*beginwith4,0,1,2,3,isusedbymain.etc.password*?

filsys.s_inode[i]=4+I;

}

124

filsys.s_pinode=0;

filsys.s_rinode=NICINOD+4;

block_buf[NICFREE–1]=FILEBLK+1;/*FILEBLK+1isaflagofend*/

for(I=0;i

block_buf[NICFREE–2–i]=FILEBLK-I;

fseek(fd,DATASTART+BLOCKSIZ*(FILEBLK–NICFREE–1),SEEK_SET);

fwrite(block_buf,1.BLOCKSIZ,fd);

for(i=FILEBLK–NICFREE–1;i>2;i-=NICFREE)

{

for(j=0;j

{

block_buf[j]=i–j;

}

fseek(fd,DATASTART+BLOCKSIZ*(i–1),SEEK_SET);

fwrite(block_buf,1,BLOCKSIZ,f

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

当前位置:首页 > PPT模板 > 动态背景

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

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