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

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

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

  • 62 次阅读
  • 3 次下载
  • 2025/6/3 3:34:10

printf(\ return 0; } temp_buf=buf; off=sys_ofile[user[user_id].u_ofile[fd1]].f_off; if((off+size)>inode->di_size) size=inode->di_size-off; block_off=off%BLOCKSIZ; block=off/BLOCKSIZ; if(block_off+sizedi_addr[block]*BLOCKSIZ+block_off,SEEK_SET); fread(buf,1,size,fd); return size; } fseek(fd,DATASTART+inode->di_addr[block]*BLOCKSIZ+block_off,SEEK_SET); fread(temp_buf,1,BLOCKSIZ-block_off,fd); temp_buf+=BLOCKSIZ-block_off; j=(inode->di_size-off-block_off)/BLOCKSIZ; for(i=0;i<(size-block_off)/BLOCKSIZ; i++) { fseek(fd,DATASTART+inode->di_addr[j+i]*BLOCKSIZ,SEEK_SET); fread(temp_buf,1,BLOCKSIZ,fd); temp_buf+=BLOCKSIZ; } block_off=(size-block_off)%BLOCKSIZ; block=inode->di_addr[off+size/BLOCKSIZ+1]; fseek(fd,DATASTART+block*BLOCKSIZ,SEEK_SET); fread(temp_buf,1,block_off,fd); sys_ofile[user[user_id].u_ofile[fd1]].f_off+=size; return size; }

unsigned int write(fd1,buf,size) int fd1; char *buf;

unsigned int size; { unsigned long off; int block,block_off,i,j,k=0; struct inode *inode; char *temp_buf; inode=sys_ofile[user[user_id].u_ofile[fd1]].f_inode; temp_buf=buf; off=sys_ofile[user[user_id].u_ofile[fd1]].f_off; block_off=off%BLOCKSIZ; block=off/BLOCKSIZ; if(block_off+sizedi_addr[block]*BLOCKSIZ+block_off,SEEK_SET); fwrite(buf,1,size,fd); printf(\ return size; } if(sys_ofile[user[user_id].u_ofile[fd1]].f_flag==FAPPEND) { fseek(fd,DATASTART+inode->di_addr[block]*BLOCKSIZ+block_off,SEEK_SET); fwrite(temp_buf,1,BLOCKSIZ-block_off,fd); temp_buf+=BLOCKSIZ-block_off; k=1; } for(i=0;i<(size-k*(BLOCKSIZ-block_off)) { /BLOCKSIZ;i++) inode->di_addr[block+1+i]=balloc();

fseek(fd,DATASTART+inode->di_addr[block+k+i]*BLOCKSIZ,SEEK_SET); fwrite(temp_buf,1,BLOCKSIZ,fd); temp_buf+=BLOCKSIZ; } block_off=(size-k*(BLOCKSIZ-block_off))%BLOCKSIZ; block=inode->di_addr[block+k+i]=balloc(); fseek(fd,DATASTART+block*BLOCKSIZ,SEEK_SET); fwrite(temp_buf,1,block_off,fd); sys_ofile[user[user_id].u_ofile[fd1]].f_off+=size; inode->di_size=sys_ofile[user[user_id].u_ofile[fd1]].f_off; return size; }

18.注册和退出函数login()和logout()(文件名log.c) #include #include \int login(uid,passwd) //logn() unsigned short uid; char *passwd; { int i,j; for(i=0;i

int logout(uid) //logout() unsigned short uid; { int i,j,sys_no; struct inode *inode; for(i=0; i

for(j=0;j

19.打印输出函数dirlt()(文件名dirlt.c) #include #include \dirlt(j) int j; { int i; printf(\ for(i=0; i

<结果>

对上述makefiie文件进行编译后可得执行文件\。在Linux或UNIX系统V以上版本环境下,运行filsys,可对上述文件系统程序进行测试。其结果如下: $filsys〈CR> $format

$Do you want to format the disk?y

$Format will erase ail context on the disk.Are You Sure?y $install $dir

CURRENT DIRECTORY: . d xxx xxx xxx

block chain:1 .. d xxx xxx xxxblock chain:2

$login(2118, \$mkdir a2118 $chdir a2118

$create(user_id, \$write(ab_fd1,buf,3077) $close(user_id,ab_d1) $mkdir subdir $chdir subdir

$create(user_id, \$write(ab_fd2,buf,2068) $chdir ..

$create(user_id, \$write(ab_fd3.b11f,1791) $close(user_id,ab_d3)

$dir

CURRENT DIRECTORY:

. d xxx xxx xxx

block chain:1 .. d xxx xxx xxxblock chain:2

file0.c f xxx --- --- 3077block chain:4 5 6 7 8 9 10 subbdir d xxx xxx xxx

biokc chain:11

file2.c f xxx --- --- 1791block chain:17 18 19 20 $delete file0.c

$creat(user_id, \$write(ab_d4,buf,4396) $close(user_id,ab_fd4) $dir

CURRENT DIRECTORY:

. d xxx xxx xxx

block chain:1 .. d xxx xxx xxxblock chain:2 subdir d xxx xxx xxxblock chain:11 file2.c f xxx 1791block chain:17 18 19 20 file3.c f xxx 4396block chain:4 5 6 7 8 9 10 21 22 23 $open(user_id, \$write(ab_fd3,buf,1636) $close(user_id,ab_fd3) $dir

CURRENT DIRECTORY.

. d xxx xxx xxx

block chain:1 .. d xxx xxx xxxbiock chain:2 subdir d xxx xxx xxxblock chain:11

file2.c f xxx xxx xxx 3427block chain:17 18 19 20 24 25 26 file3.c f xxx xxx xxx 4396block chain:4 5 6 7 8 9 10 21 22 23 $chdir ..

$logout(2118)

no user in the file system. $halt

Good bye.See you next time.Please turn off the switch.

注意,本文件系统程序未使用命令交互解释工具Shell,读者可从本程序中观察到这点。

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

共分享92篇相关文档

文档简介:

printf(\ return 0; } temp_buf=buf; off=sys_ofile[user[user_id].u_ofile[fd1]].f_off; if((off+size)>inode->di_size) size=inode->di_size-off; block_off=off%BLOCKSIZ; block=off/BLOCKSIZ; if(block_off+sizedi_addr[block]*BLOCKSIZ+block_off,SEEK_SET); fread(buf,1,size,fd); return size; } fseek(fd,DATASTART+inode->di_addr[block]*BLOCKSIZ+block_

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价: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