云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 操作系统实验文件系统设计

操作系统实验文件系统设计

  • 62 次阅读
  • 3 次下载
  • 2025/6/1 14:50:27

strcpy(dir_buf[2].d_name, \ dir_buf[2].d_ino=2; fseek(fd,DATASTART,SEEK_SET); fwrite(dir_buf,1,3*(DIRSIZ+2),fd); iput(inode); inode=iget(2); // 2 etc dir id inode->di_number=1; inode->di_mode=DEFAULTMODE|DIDIR; inode->di_size=3*(DIRSIZ+2); inode->di_addr[0]=1; //block 0#is used by the etc directory 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, \ 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);//3 password id inode->di_number=1; inode->di_mode=DEFAULTMODE|DIDIR; inode->di_size=BLOCKSIZ; inode->di_addr[0]=2; //block 2#is used by the password file for(i=5;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;i2;i-=NICFREE) { for(j=0;j2;i--) {

filsys.s_free[NICFREE-1+i-j]=i; } filsys.s_pfree=NICFREE-1-j+3; filsys.s_pinode=0; fseek(fd,BLOCKSIZ,SEEK_SET); fwrite(&filsys.s_isize,1,sizeof(filsys),fd); fseek(fd,BLOCKSIZ,SEEK_SET); fread(&filsys.s_isize,1,sizeof(filsys),fd); }

5.进入文件系统程序install()(文件名install.c) #include #include #include \install() { int i,j;

//1.read the filsys from the superblock fseek(fd,BLOCKSIZ,SEEK_SET); fread(&filsys,1,sizeof(struct filsys),fd); //2.initialize the inode hash chain for(i=0;i

//3.initialize the sys_file for(i=0;i

// 4.initialize the user for(i=0;i

// 5 read the main directory to initialize the dir cur_path_inode=iget(1); dir.size=cur_path_inode->di_size/(DIRSIZ+2); for(i=0;idi_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); fread(&dir.direct[(BLOCKSIZ)/(DIRSIZ+2)*i],1,cur_path_inode->di_size%BLOCKSIZ,fd); }

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

// 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 GOODBYE to all the user printf(\ exit(0); }

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

struct inode *iget(dinodeid) //iget() unsigned int dinodeid; { int existed=0,inodeid; long addr; struct inode *temp,*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 { // not existed temp=temp->i_forw; } } }

//not existed

//1.calculate the addr of the dinode in the file sys column addr=DINODESTART+dinodeid*DINODESIZ; // 2.malloc the new inode newinode=(struct inode *)malloc(sizeof(struct inode)); // 3.read the dinode to the inode fseek(fd,addr,SEEK_SET); fread(&(newinode->di_number),DINODESIZ,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 irlode newinode->i_count=1; newinode->i_flag=0; newinode->i_ino=dinodeid; newinode->di_size=3*(DIRSIZ+2); if(dinodeid==3) newinode->di_size=BLOCKSIZ; return newinode; }

iput(pinode) // iput() struct inode *pinode; { long addr; unsigned int block_num; int i; if(pinode->i_count>1) { pinode->i_count--; return; } else { if(pinode->di_number!=0) { //write back the inode addr=DINODESTART+pinode->i_ino*DINODESIZ; fseek(fd,addr,SEEK_SET); fwrite(&pinode->di_number,DINODESIZ,1,fd); } else { // rm the inode & the block of the file in the disk block_num=pinode->di_size/BLOCKSIZ; for(i=0; idi_addr[i]); ifree(pinode->i_ino); }

// free the inode in the memory if(pinode->i_forw==NULL) pinode->i_back->i_forw=NULL; else { pinode->i_forw->i_back=pinode->i_back; pinode->i_back->i_forw=pinode->i_forw; } ifree(pinode); } }

8.i节点分配和释放函数ialloc()和ifree()(文件名iallfre.c) #include #include \

static struct dinode block_buf[BLOCKSIZ/DINODESIZ]; struct inode *ialloc() //ialloc { struct inode *temp_inod; unsigned int cur_di; int i,count,block_end_flag; if(filsys.s_pinode==NICINOD) { // s_inode empty i=0; count=0; block_end_flag=1; filsys.s_pinode=NICINOD-1; cur_di=filsys.s_rinode; while((count

搜索更多关于: 操作系统实验文件系统设计 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

strcpy(dir_buf[2].d_name, \ dir_buf[2].d_ino=2; fseek(fd,DATASTART,SEEK_SET); fwrite(dir_buf,1,3*(DIRSIZ+2),fd); iput(inode); inode=iget(2); // 2 etc dir id inode->di_number=1; inode->di_mode=DEFAULTMODE|DIDIR; inode->di_size=3*(DIRSIZ+2); inode->di_addr[0]=1; //block 0#is used by the etc directory strcpy(dir_buf[0].d_name, \ dir_buf[0].d_ino=1; strcpy(dir_buf[1].d_name, \ dir_buf[

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com