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

2019-08-31 15:43

struct filsys filsys; struct pwd pwd[PWDNUM]; struct user user[USERNUM]; FILE *fd;

struct inode *cur_path_inode; int user_id; int iHave_formated; int iCur_free_block_index;

main( )

{ unsigned short ab_fd1,ab_fd2,ab_fd3,ab_fd4,ab_fd5; char *buf;

char file_content_buf[BLOCKSIZ];

char c;

printf(\

printf(\ if(getchar( )=='y')

printf(\ getchar();

if((c=getchar( ))=='y') {

printf(\ format( );

iHave_formated = 1; printf(\ }

else

printf(\

printf(\ install( );

printf(\ _dir( );

printf(\ login(2118,\ user_id=0;

printf(\

mkdir(\ _dir();

printf(\

chdir(\ _dir();

printf(\

ab_fd1=creat(2118,\ _dir();

printf(\

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

write(2118,ab_fd1,buf,BLOCKSIZ*6+5); printf(\ close(2118,ab_fd1); printf(\ free(buf);

mkdir(\

printf(\

chdir(\

printf(\

ab_fd2=creat(2118,\ printf(\

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

write(2118,ab_fd2,buf,BLOCKSIZ*4+20); printf(\ close(2118,ab_fd2); free(buf);

printf(\ chdir(\

printf(\

ab_fd3=creat(2118,\ buf=(char *)malloc(BLOCKSIZ*10+255); write(2118,ab_fd3,buf,BLOCKSIZ*3+255); close(2118,ab_fd3); free(buf);

delete(\ printf(\

ab_fd4=creat(2118,\ buf=(char *)malloc(BLOCKSIZ*8+300); printf(\

write(2118,ab_fd4,buf,BLOCKSIZ*8+300); printf(\ close(2118,ab_fd4); free(buf);

printf(\

ab_fd3=open(2118,\ printf(\

buf=(char *)malloc(BLOCKSIZ*3+100); write(2118,ab_fd3,buf,BLOCKSIZ*3+100); printf(\ close(2118,ab_fd3);

ab_fd5=creat(2118,\文件5\

write(2118,ab_fd5,\me see what Spring is like\\nOn Jupiter and Mars\\n带我飞向月球,让我在群星中嬉戏,让我看看木星和火星上的春天\\n\ close(2118,ab_fd5);

ab_fd5=open(2118,\文件5\

read(2118,ab_fd5,file_content_buf,BLOCKSIZ); printf(\读出文件5的内容: %s\\n\ close(2118,ab_fd5);

printf(\ free(buf); _dir( ); chdir(\

printf(\ logout(2118);

printf(\ halt( ); }

4、初始化磁盘格式程序format( ) (文件名format.c)

#include \#include \ format( )

{ struct inode *inode;

struct direct dir_buf[BLOCKSIZ/(DIRSIZ+2)];

struct pwd passwd[BLOCKSIZ/(PWDSIZ+4)]; /* {

{2116,03,\ {2117,03,\ {2118,04,\ {2119,04,\ {2220,05,\ }; */

//struct filsys;

unsigned int block_buf[BLOCKSIZ/sizeof(int)]; char *buf; int i,j;

/* creat the file system file */

memset(dir_buf,0,(BLOCKSIZ/(DIRSIZ+2))*sizeof(struct direct)); fd=fopen(\

buf=(char *)malloc((DINODEBLK+FILEBLK+2)*BLOCKSIZ*sizeof(char)); if (buf==NULL) exit(0);

printf(\

fseek(fd,0,SEEK_SET);

fwrite(buf,1,(DINODEBLK+FILEBLK+2)*BLOCKSIZ*sizeof(char),fd); /*0.initialize the passwd*/

passwd[0].p_uid=2116;passwd[0].p_gid=03; strcpy(passwd[0].password,\ passwd[1].p_uid=2117;passwd[1].p_gid=03; strcpy(passwd[1].password,\ passwd[2].p_uid=2118;passwd[2].p_gid=04; strcpy(passwd[2].password,\ passwd[3].p_uid=2119;passwd[3].p_gid=04; strcpy(passwd[3].password,\ passwd[4].p_uid=2220;passwd[4].p_gid=05; strcpy(passwd[4].password,\

/*给main()中的密码表pwd[PWDNUM]填入内容*/ pwd[0].p_uid=2116;pwd[0].p_gid=03; strcpy(pwd[0].password,\ pwd[1].p_uid=2117;pwd[1].p_gid=03; strcpy(pwd[1].password,\ pwd[2].p_uid=2118;pwd[2].p_gid=04;

strcpy(pwd[2].password,\ pwd[3].p_uid=2119;pwd[3].p_gid=04; strcpy(pwd[3].password,\ pwd[4].p_uid=2220;pwd[4].p_gid=05; strcpy(pwd[4].password,\

/*1.creat the main directory and its sub dir etc and the file password*/

inode=iget(0); /*0 empty dinode id */ inode->di_mode=DIEMPTY; iput(inode);

inode=iget(1); /*1 main dir id*/ inode->di_number=1;

inode->di_mode=DEFAULTMODE|DIDIR; inode->di_size=3*sizeof(struct direct);

inode->di_addr[0]=0; /* block 0# is used by the main directory*/ strcpy(dir_buf[0].d_name,\ dir_buf[0].d_ino=1;

strcpy(dir_buf[1].d_name,\ dir_buf[1].d_ino=1;

strcpy(dir_buf[2].d_name,\ dir_buf[2].d_ino=2;

fseek(fd,DATASTART,SEEK_SET);

fwrite(dir_buf,1,3*sizeof(struct direct),fd); iput(inode);

inode=iget(2); /*2 etc dir id*/ inode->di_number=1;

inode->di_mode=DEFAULTMODE|DIDIR; inode->di_size=3*sizeof(struct direct);

inode->di_addr[0]=1; /*block 1# 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*sizeof(struct direct),fd);


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

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

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

马上注册会员

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