您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 咨询培训 > 计算机操作系统教程实验指导(第2版)
11.编程管理文件makefikefilsys:main.oingetput.oiallfre.oballfre.oname.oaccess.olog.oclose.ocreat.odelete.odir.oopen.ordwt.oformat.oinstall.ohalt.occ-ofilsysmain.oingetput.oiallfre.oballfre.oname.oaccess.olog.oclose.ocreat.odelete.odir.oopen.ordwt.oformat.oinstall.ohalt.omain.o:main.cfilesys.hcc-cmain.cigetput.o:igetput.cfilesys.hcc-cigetput.ciallfre.o:iallfre.cfilesys.hcc-ciallfre.cballfre.o:ballfre.cfilesys.hcc-cballfre.cname.o:name.cfilesys.hcc-cname.caccesse.o:access.cfilesys.hcc-caccess.clog.o:log.cfilesys.hcc-clog.cclose.o:close.cfilesys.hcc-cclose.ccreat.o:creat.cfilesys.hcc-ccreat.cdelete.o:delete.cfilesys.hcc-cdelete.cdir.o:dir.cfilesys.hcc-cdir.copen.o:open.cfilesys.hcc-copen.crdwt.o:rdwt.cfilesys.hcc-crdwt.cformat.o:format.cfilesys.hcc-cformat.cinstall.o:install.cfilesys.hcc-cinstall.chalt.o:halt.ccc-chalt.c2.头文件filesye.h#defineBLOCKSIZE512#defineSYSOPENFILE40#defineDIRNUM128#definePWDSIZ14#definePWDNUM12#defineNOFILE20#defineNADDR102#defineNHINO128#defineUSERNUM10#defineDINODESIZ32#defineFILEBLK512#defineNICFREE50#defineNICNOD50#defineDINODESTART2*BLOCKSIZ#defineDATASTART(2+DINODEBLK)*BLOCKSIZ#defineDIEMPTY00000#defineDIFILE01000#defineDIDIR02000#defineUDIREAD00001#defineUDIWRITE00002#defineUDIEXICUTE00004#defineGDIREAD00010#defineGDIWRITE00020#defineGDIEXICUTE00040#defineODIREAD00100#defineODIWRITE00200#defineODIEXICUTE00400#defineREAD1#defineWRITE2#defineEXICUTE3#defineDEFAULTMODE00777#defineIUPDATE00002#defineSUPDATE00001#defineFREAD00001#defineFWRITE00002#defineFAPPEND00004#defineDISKFULL655253#defineSEEL..SET0/*文件系统数据结构*、structinode{structinode*i_frow;structinode*i_back;chari_flag;unsignedinti_ino;unsignedinti_count;unsignedshortdi_number;unsignedshortdi_moder;unsignedshortdi_uid;unsignedshortdi_gid;unsignedshortdi_size;unsignedintdi_addr[NADDR];};structdinode{unsignedshortdi_number;unsignedshortdi_moder;unsignedshortdi_uid;unsignedshortdi_gid;unsignedlongdi_size;unsignedintdi_addr[NADDR];};structdireet{chard_name[DIRSIZ];unsignedintd_ino;};structfilsys{unsignedshorts_size;unsignedlongs_fsize;4unsignedints_nfree;unsignedshorts_pfree;unsignedints_free[NICFREE];unsignedints_ninode;unsignedshorts_pinode;unsignedints_inode[NICINOD];unsignedints_rinode;chars_fmod;};structpwd{unsignedshortp_uid;unsignedshortp_gid;charpssword[PWDSIZE];};strcutdir{structdirectdirect[DIRNUM];intsize;};structhinode{structinode*i_forw;};structuser{unsignedshortu_default_mode;unsignedshortu_uid;unsignedshortu_gid;unsignedshortu_ofile[NOFILE];};/*下为全局变量*/externstructhinodehinode[NHINO];externstructdirdir;5externstructfilesys_ofile[SYSOPENFILE];externstructfilsysfilsys;externstructpwdpwd{PWDNUM];externFILE*fd;externstructinode*cur_path_inode;externintuser_id;externstructinode*iget()externiput();externunsignedintballoc();externbfree();externstructinode*ialloc();externifree();externunsignedintnamei();externunsignedshortiname();externunsignedintaccess();extern_dir();externmkdir();externchdir();externunsignedshortopen();externcreat();externunsignedintread();externunsignedintwrite();externintlogin();externinstall();externformat();externclose();externhalt();3.主程序main()(文件名main.c)#includestdio.h6#includefilesys.hstructhinodehinode[NHINO];structdirdir;structfilesys_ofile[SYSOPENFILE];structfilsysfilsys;structpwdpwd[PWDNUM];structuseruser[USERNUM];FILE*fd;structinode*cur_path_inode;intuer_id;main(){unsignedshortab_fd1,ab_fd2,ab_fd3,ab_fd4;unsignedshortbhy_fd1;char*buf;printf(\nDoyouwanttoformatthedisk\n);if(getchar()=='y')printf(\nFormatwilleraseallcontextonthedisk\n);if(getchar()=='y')format();install();_dir();long(2118,abcd);user_id=0;7mkdir(a2118);chdir(a2118);wj_fd1=creat(2118,ab_file0.c,01777);buf=(char*)malloc(BLOCKSIZ*6+5);write(ab_fd1,buf,BLOCKSIZ*6+5);close(user_id,ab_fd1);free(buf);mkdir(subdir);chdir(subdir);wj_fd2=creat(2118,file1.c,01777);buf=(char*)malloc(BLOCKSIZ*4+20);write(ab_fd2,buf,BLOCKSIZ*4+20);close(user_id,ab_fd2);free(buf);chdir(..);ab_fd3=creat(2118,_file2.c,01777);buf=(char*)malloc(BLOCKSIZ*10+255);write(ab_fd3,buf,BLOCKSIZ*3+255);close(ab_fd3);free(buf);delete(ab_file0.c);ab_fd4=creat(2118,ab_file3.c,01777);buf=(char*)malloc(BLOCKSIZ*8+300);write(ab_fd4,buf,BLOCKSIZ*8+300);close(ab_fd4);free(buf);8ab_fd3=open(2188,ab_file2.c,FAPPEND);buf=(char*)malloc(BLOCKSIZ*3+100);write(ab_fd3,buf,BLOCKSIZ*3+100);close(ab_fd3);free(buf);_dir();chdir(..);logout();halt();}4.初始化磁盘格式程序format()(文件名format.c)#includestdio.h#includefilesys.hformat(){structinode*inode;structdirectdir_buf[BLOCKSIZ/(DIRSIZ+2)];structpwdpasswd[BLOCKSIZ/(PWDSIZ+4)];/*{{2116,03,dddd};{2117,03,bbbb};{2118,04,abcd};{2119,04,cccc};{2220,05,eeee};};*/9structfilsys;unsignedintblock_buf[BLOCKSIZ/sizeof(int)];char*buf;inti,j;/*creatthefilesystemfile*/fd=fopen(filesystem,r+w+b);buf=(char*)malloc(DINODENLK+FILEBLK+2)*BLOCKSIZ*sizeof(char));if(buf==NULL){printf(\nfilesystemfilecreatfailed!!!\n);exit(0);}fseek(fd,0,SEEK_SET);fwrite(buf,1,(DINODENLK+FILEBLK+2)*BLOCKSIZ*sizeof(char),fd);/*0.initializethepasswd*/passwd[0].p_uid=2116;passwd[0].p_gid=03;strcpy(passwd
本文标题:计算机操作系统教程实验指导(第2版)
链接地址:https://www.777doc.com/doc-3353324 .html