os操作系统实验指导(7)

2019-08-31 15:43

iput(inode);

inode=iget(3); /*3 password id*/ inode->di_number=1;

inode->di_mode=DEFAULTMODE|DIFILE; inode->di_size=BLOCKSIZ;

inode->di_addr[0]=2; /* block 2# is used by the password file*/ for(i=5;i

strcpy(passwd[i].password,\ }

fseek(fd,DATASTART+2*BLOCKSIZ,SEEK_SET); fwrite(passwd,1,BLOCKSIZ,fd); iput(inode);

/*2.initialize the superblock*/ filsys.s_isize=DINODEBLK; filsys.s_fsize=FILEBLK;

filsys.s_ninode=DINODEBLK*BLOCKSIZ/DINODESIZ-4; filsys.s_nfree=FILEBLK-3; for(i=0;i

{ /*begin with 4,0,1,2,3,is used by main,etc,password*/ filsys.s_inode[i]=4+i; }

filsys.s_pinode=0;

filsys.s_rinode=NICINOD+4;

block_buf[NICFREE-1]=FILEBLK+1; /*FILEBLK+1 is a flag of end*/ 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[NICFREE]=NICFREE;

fseek(fd,DATASTART+BLOCKSIZ*(i-1),SEEK_SET); fwrite(block_buf,1,BLOCKSIZ,fd); }

i+=NICFREE;

iCur_free_block_index = i;

for(i=i,j=1;i>3;i--,j++) filsys.s_free[NICFREE-j]=i; filsys.s_pfree=NICFREE-j+1;

filsys.s_pinode=0;

fseek(fd,BLOCKSIZ,SEEK_SET);

fwrite(&filsys,1,sizeof(struct filsys),fd);

fclose(fd); }

5、进入文件系统程序install( ) (文件名install.c)

#include \#include \#include \

install( ) { int i,j;

int return_value;

/*0. open the file column*/

if(iHave_formated == 1)

fd=fopen(\ else

fd=fopen(\ if (fd==NULL)

{ printf(\ exit(0); }

printf(\/*1. read the filsys from the superblock*/ fseek(fd,BLOCKSIZ,SEEK_SET);

// fwrite(&filsys,1,sizeof(struct filsys),fd); 原来的代码 fread(&filsys,sizeof(struct filsys),1,fd);

/*2. initialize the inode hash chain */

for (i=0;i

/*3. initialize the sys_ofile */

for (i=0;i

/*4. initialize the user */

for (i=0;i

user[i].u_ofile[j]=SYSOPENFILE+1; }

/*5. read the main directory to initialize the dir */

dir.size=cur_path_inode->di_size/(sizeof(struct direct));

for(i=0;i

{ strcpy(dir.direct[i].d_name,\ dir.direct[i].d_ino=0; }

fseek(fd,DATASTART+BLOCKSIZ*cur_path_inode->di_addr[i],SEEK_SET); fread(&dir.direct[(BLOCKSIZ/(DIRSIZ+2))*i],1,BLOCKSIZ,fd); }

fseek(fd,DATASTART+BLOCKSIZ*cur_path_inode->di_addr[i],SEEK_SET); if(i == 0)

fread(&dir.direct[BLOCKSIZ/(DIRSIZ+2)*i],1,cur_path_inode->di_size,fd); else //i>1

fread(&dir.direct[BLOCKSIZ/(DIRSIZ+2)*i],1,cur_path_inode->di_size%BLOCKSIZ,fd); }

for(i=0;i

cur_path_inode=iget(1);

6、退出程序halt( ) (文件名halt.c)

#include \#include \

halt( )

{ struct inode *inode; int i,j;

/*1. write back the current dir */ chdir(\

iput(cur_path_inode);

/*2. free the u_ofile and sys_ofile and inode */ for(i=0;i

if (user[i].u_ofile[j]!=SYSOPENFILE+1) { close(user[i].u_ofile[j]); user[i].u_ofile[j]=SYSOPENFILE+1; }

/* 3. write back the filesys to the disk */ fseek(fd,BLOCKSIZ,SEEK_SET);

fwrite(&filsys,1,sizeof(struct filsys),fd); /*4. close the file system column*/ fclose(fd);

/*5. say GOOD BYE to all the user */

printf(\exit(0); }

7、获取释放i节点内容程序iget( )/iput( ) (文件名igetput.c)

#include \#include \#include \

struct inode *iget(dinodeid) /*iget( )*/ unsigned int dinodeid; { int existed=0,inodeid; long addr;

struct inode *temp; struct inode *newinode; inodeid=dinodeid%NHINO;

if (hinode[inodeid].i_forw==NULL) {

existed=0; }

else {

temp=hinode[inodeid].i_forw; while (temp)

if (temp->i_ino==inodeid) /* existed */ { existed=1; temp->i_count++; return temp; }

else temp=temp->i_forw; /* not existed */ }

/* not existed */

/*1. calculate the addr of the dinode in the file sys column */

addr=DINODESTART+dinodeid*sizeof(struct dinode);

/*2. malloc the new inode */

newinode=(struct inode *)malloc(sizeof(struct inode)); memset(newinode,0,(sizeof(struct inode)));

/*3. read the dinode to the inode */ fseek(fd,addr,SEEK_SET);

fread(&(newinode->di_number),sizeof(struct dinode),1,fd);

/*4. put it into hinode [inodeid] queue */

newinode->i_forw = hinode[inodeid].i_forw; newinode->i_back=newinode;

if(newinode->i_forw != NULL)

newinode->i_forw->i_back=newinode;

hinode[inodeid].i_forw=newinode;

/*5. initialize the inode */ newinode->i_count=1;

newinode->i_flag=0; /* flag for not update */ newinode->i_ino=dinodeid; return newinode; }

int iput(pinode) /*iput( )*/ struct inode *pinode;


os操作系统实验指导(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:六年级下册英语素材-英语名词单复数变化规律及练习题 - 通用版

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: