当前位置:首页 > 操作系统实验文件系统设计
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+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+size
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 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 <结果> 对上述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 $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 file0.c f xxx --- --- 3077block chain:4 5 6 7 8 9 10 subbdir d xxx xxx xxx 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
CURRENT DIRECTORY.
. d xxx xxx xxx
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,读者可从本程序中观察到这点。
共分享92篇相关文档