操作系統(tǒng)課程設(shè)計(jì)二級(jí)文件系統(tǒng)_第1頁(yè)
操作系統(tǒng)課程設(shè)計(jì)二級(jí)文件系統(tǒng)_第2頁(yè)
操作系統(tǒng)課程設(shè)計(jì)二級(jí)文件系統(tǒng)_第3頁(yè)
操作系統(tǒng)課程設(shè)計(jì)二級(jí)文件系統(tǒng)_第4頁(yè)
操作系統(tǒng)課程設(shè)計(jì)二級(jí)文件系統(tǒng)_第5頁(yè)
已閱讀5頁(yè),還剩36頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、操作系統(tǒng)課程設(shè)計(jì)報(bào)告操作系統(tǒng)課程設(shè)計(jì)報(bào)告專(zhuān) 業(yè):計(jì)算機(jī)信息處理 【設(shè)計(jì)目的】1. 課程設(shè)計(jì)目的是通過(guò)一個(gè)簡(jiǎn)單多用戶(hù)文件系統(tǒng)的設(shè)計(jì),加深理解文件系統(tǒng)的內(nèi)部功能和內(nèi)部實(shí)現(xiàn)。2. 結(jié)合數(shù)據(jù)結(jié)構(gòu)、程序設(shè)計(jì)、計(jì)算機(jī)原理等課程的知識(shí),設(shè)計(jì)一個(gè)二級(jí)文件系統(tǒng),進(jìn)一步理解操作系統(tǒng)。3. 通過(guò)對(duì)實(shí)際問(wèn)題的分析、設(shè)計(jì)、編程實(shí)現(xiàn),提高學(xué)生實(shí)際應(yīng)用、編程的能力【設(shè)計(jì)內(nèi)容】1、delete 刪除文件2、open 打開(kāi)文件3、close 關(guān)閉文件4、write 寫(xiě)文件【實(shí)驗(yàn)環(huán)境】windows7系統(tǒng) visual studio 2010【相關(guān)知識(shí)綜述】本文件系統(tǒng)采用兩級(jí)目錄,其中第一級(jí)對(duì)應(yīng)于用戶(hù)賬號(hào),第二級(jí)對(duì)應(yīng)于用戶(hù)帳號(hào)下

2、的文件。另外,為了簡(jiǎn)便文件系統(tǒng)未考慮文件共享,文件系統(tǒng)安全以及管道文件與設(shè)備文件等特殊內(nèi)容。首先應(yīng)確定文件系統(tǒng)的數(shù)據(jù)結(jié)構(gòu):主目錄、子目錄及活動(dòng)文件等。主目錄和子目錄都以文件的形式存放于磁盤(pán),這樣便于查找和修改。用戶(hù)創(chuàng)建的文件,可以編號(hào)存儲(chǔ)于磁盤(pán)上。如:file0,file1,file2并以編號(hào)作為物理地址,在目錄中進(jìn)行登記?!驹O(shè)計(jì)思路】1 主要數(shù)據(jù)結(jié)構(gòu)#define maxname 25 /*the largest length of mfdname,ufdname,filename*/#define maxchild 50 /*the largest child每個(gè)用戶(hù)名下最多有50個(gè)文件*

3、/#define max (maxchild*maxchild) /*the size of fpaddrno*/typedef struct /*the structure of osfile定義主文件*/int fpaddr; /*file physical address*/ int flength; /*file length*/ int fmode; /*file mode:0-read only;1-write only;2-read and write; 3-protect;*/ char fnamemaxname; /*file name*/ osfile;typedef st

4、ruct /*the structure of osufd定義用戶(hù)文件目錄*/char ufdnamemaxname; /*ufd name*/osfile ufdfilemaxchild; /*ufd own file*/osufd;typedef struct /*the structure of osufdlogin定義登陸*/char ufdnamemaxname; /*ufd name*/ char ufdpword8; /*ufd password*/ osufd_login;typedef struct /*file open mode定義操作方式*/int ifopen; /*

5、ifopen:0-close,1-open*/ int openmode; /*0-read only,1-write only,2-read and write,3-initial*/osufd_openmode;2 主要函數(shù)void loginf(); /*login filesystem*/void dirf(); /*dir filesystem*/void createf(); /*create file*/void deletef(); /*delete file*/void modifyfm(); /*modify filemode*/void openf(); /*open f

6、ile*/void closef(); /*close file*/void readf(); /*read file*/void writef(); /*write file*/void quitf(); /*quit filesystem*/void cdf(); /*change dir*/void help();【主要程序段】1 delete函數(shù)void deletef() /*delete file*/ char fnamemaxname,str50,str150;int i,k,j;int fpaddrno1; if (strcmp(strupr(ltrim(rtrim(dirna

7、me),)=0) /*無(wú)法刪除主目錄的文件*/printf(nerror.please convert to ufd dir before delete.n);wgetchar=1;if (strcmp(strupr(dirname),strupr(username)!=0) /*無(wú)法刪除非自己目錄的文件*/printf(nerror.you can only modify filemode in yourself dir.n);wgetchar=1;elseprintf(nplease input filename:);gets(fname);/從鍵盤(pán)獲取所要?jiǎng)h除的文件名ltrim(rtri

8、m(fname);i=existf(fname);/獲取文件編號(hào)if (i=0)k=existd(username);if(ifopenki.ifopen=1)/*文件打開(kāi)時(shí)無(wú)法刪除*/printf(nerror.%s is in open status. close it before delete.n,fname);wgetchar=1;else if(ufdk-ufdfilei.fmode=3)/*被保護(hù)的文件無(wú)法刪除*/ printf(nerror.%s is in protect status. close it before delete.n,fname);wgetchar=1;

9、else fpaddrno1=ufdk-ufdfilei.fpaddr;/獲取文件對(duì)應(yīng)的物理文件名fpaddrnofpaddrno1=0;/回收盤(pán)塊for(j=i;jufdfilej=ufdk-ufdfilej+1;/從被刪除的文件號(hào)開(kāi)始,數(shù)組值全部前移一個(gè) strcpy(str,d:osfilefilefile);itoa(fpaddrno1,str1,10);/整數(shù)轉(zhuǎn)化成字符串strcat(str,str1);strcat(str,.txt);remove(str);/刪除物理文件fcountk-;/k用戶(hù)文件數(shù)量少1printf(n %sis deleted successfully.n

10、,fname);wgetchar=1;else/所要?jiǎng)h除的文件不存在 printf(nerror. %s dose not exist.n,fname);wgetchar=1;2 open函數(shù)void openf() /*open file*/ char fnamemaxname;int i,k,j; if (strcmp(strupr(dirname),strupr(username)!=0) /*在自己的目錄里才能打開(kāi)*/printf(nerror.you can only open in yourself dir.n);wgetchar=1;else k=existd(username)

11、; for(j=0;jufdfilej.fname); printf(nplease input filename:);gets(fname);/獲取所要打開(kāi)的文件名ltrim(rtrim(fname);i=existf(fname);/獲取目錄編號(hào)if (i=0)if(ifopenki.ifopen=1)/輸入的文件是打開(kāi)的printf(nerror.%s is in open status.n,fname);wgetchar=1;else ifopenki.ifopen=1;/修改為打開(kāi)的if(ufdk-ufdfilei.fmode=0)/*根據(jù)文件的模式設(shè)置打開(kāi)模式*/ ifopenki

12、.openmode=0; else if(ufdk-ufdfilei.fmode=1) ifopenki.openmode=1; else if(ufdk-ufdfilei.fmode=2) ifopenki.openmode=2; else ifopenki.openmode=3; printf(n%s is opened successfullyn,fname); wgetchar=1;else/文件不存在printf(nerror. %s dose not exist.n,fname);wgetchar=1;3 close函數(shù)void closef() /*close file*/cha

13、r fnamemaxname;int i,k,j; if (strcmp(strupr(dirname),strupr(username)!=0) /*不在自己的目錄里沒(méi)法進(jìn)行*/printf(nerror.you can only close file in yourself dir.n);wgetchar=1;else k=existd(username); for(j=0;jufdfilej.fname); printf(nplease input filename:);gets(fname);/從鍵盤(pán)上讀入所要關(guān)閉的文件ltrim(rtrim(fname);i=existf(fname

14、);/獲取文件編號(hào)if (i=0)ifopenki.ifopen=0;/*關(guān)閉文件*/printf(n %s closed successfullyn,fname);wgetchar=1;else/所要關(guān)閉的文件不存在printf(nerror. %s dose not exist.n,fname);wgetchar=1;4 write函數(shù)void writef() /*write file*/int i,k,n=0;int length;char fnamemaxname,values1000;char str255,str1255,c;if (strcmp(strupr(ltrim(rtr

15、im(dirname),)=0) /只能寫(xiě)自己目錄下的文件printf(nerror.please convert to ufd dir before write.n);wgetchar=1;return;printf(ncaution:open file firstn);printf(opened file(s) list:n);k=existd(dirname);/獲取目錄編號(hào)for(i=0;iufdfilei.fname);n+;if(n%4=0)&(n!=0) printf(n);printf(n%d files openned.n,n);if (n=0) wgetchar=1;/沒(méi)有

16、打開(kāi)的文件if(n!=0)printf(nplease input filename:);gets(fname);/從鍵盤(pán)獲取所要寫(xiě)的文件ltrim(rtrim(fname);i=existf(fname);/獲取文件編號(hào)if(i=0)if(ifopenki.ifopen=1)/如果文件是打開(kāi)的if(ifopenki.openmode=1) |(ifopenki.openmode=2)/文件是只寫(xiě),或者是可讀可寫(xiě)的itoa(ufdk-ufdfilei.fpaddr,str,10);/獲取文件對(duì)應(yīng)的物理地址strcpy(str1,file);strcat(str1,str);strcpy(str

17、,d:osfilefile);strcat(str,str1);strcat(str,.txt);fp_file=fopen(str,ab);/以二進(jìn)制只寫(xiě)的形式打開(kāi),每次將內(nèi)容添加到文件末尾接著上一次內(nèi)容length=writef1();ufdk-ufdfilei.flength=ufdk-ufdfilei.flength+length;/計(jì)算總長(zhǎng)度printf(nn%d length.n,ufdk-ufdfilei.flength);printf(nnyou have write file successfully!); fclose(fp_file);wgetchar=0;else if

18、(ifopenki.openmode=0)/文件是只讀的printf(nerror.%s has been opened with read only mode. it isnt write.n,fname);wgetchar=1;else/文件是保護(hù)的printf(nerror.%s has been opened with protect mode. it isnt write.n,fname);wgetchar=1;else /文件是關(guān)閉的printf(nerror.%s is in closing status. please open it before writen,fname);

19、wgetchar=1;else /所指定的文件不存在printf(nerror. %s does not exist.n,fname);wgetchar=1;【程序流程設(shè)計(jì)】1 總的功能結(jié)構(gòu)圖:2 部分子模塊程序流程圖(1)打開(kāi)命令的程序流程圖:(2)關(guān)閉命令的程序流程圖:(3)寫(xiě)命令的程序流程圖:(4)刪除命令的程序流程圖:【測(cè)試結(jié)果】1 刪除文件2 打開(kāi)的文件不能刪除3 打開(kāi)文件,其中已經(jīng)打開(kāi)的文件不能再次打開(kāi)3 關(guān)閉文件4 寫(xiě)文件,其中只有打開(kāi)了文件才能寫(xiě)入5 寫(xiě)文件6 只讀文件和保護(hù)文件不能寫(xiě)入7 其他函數(shù)【參考文獻(xiàn)】計(jì)算機(jī)操作系統(tǒng),西安電子科技大學(xué)出版社,方敏主編,2004.8部分函

20、數(shù)含義引用于【源程序清單】#include stdio.h#include string.h#include conio.h#include stdlib.h#define maxname 25 /*the largest length of mfdname,ufdname,filename*/#define maxchild 50 /*the largest child每個(gè)用戶(hù)名下最多有50個(gè)文件*/#define max (maxchild*maxchild) /*the size of fpaddrno*/typedef struct /*the structure of osfile定

21、義主文件*/int fpaddr; /*file physical address*/ int flength; /*file length*/ int fmode; /*file mode:0-read only;1-write only;2-read and write; 3-protect;*/ char fnamemaxname; /*file name*/ osfile;typedef struct /*the structure of osufd定義用戶(hù)文件目錄*/char ufdnamemaxname; /*ufd name*/osfile ufdfilemaxchild; /*

22、ufd own file*/osufd;typedef struct /*the structure of osufdlogin定義登陸*/char ufdnamemaxname; /*ufd name*/ char ufdpword8; /*ufd password*/ osufd_login;typedef struct /*file open mode定義操作方式*/int ifopen; /*ifopen:0-close,1-open*/ int openmode; /*0-read only,1-write only,2-read and write,3-protect*/osufd

23、_openmode;void loginf(); /*login filesystem*/void dirf(); /*dir filesystem*/void createf(); /*create file*/void deletef(); /*delete file*/void modifyfm(); /*modify filemode*/void openf(); /*open file*/void closef(); /*close file*/void readf(); /*read file*/void writef(); /*write file*/void quitf();

24、/*quit filesystem*/void cdf(); /*change dir*/void help();char *rtrim(char *str); /*remove the trailing blanks.*/char *ltrim(char *str); /*remove the heading blanks.*/void inputpw(char *password); /*input password,use * replace*/int existd(char *dirname); /*whether dirname exist,exist-i,not exist-0*/

25、int writef1(); /*write file*/int existf(char *filename); /*whether filename exist,exist-i,not exist-0*/void setpano(int rorw); /*set physical address num*/int findpano(); /*find out physical address num*/int ucount=0; /*the count of mfds ufds用戶(hù)數(shù)*/int fcountmaxchild; /*the count of ufds files子文件數(shù)*/in

26、t loginsuc=0; /*whether login successfully登陸成功*/char usernamemaxname; /*record login users name22用戶(hù)名*/char dirnamemaxname;/*record current directory使用的用戶(hù)目錄*/int fpaddrnomax; /*record file physical address num物?理地址號(hào),存放自己所創(chuàng)建的所有文件的地址*/int wgetchar; /*whether getchar()*/osufd *ufdmaxchild; /*ufd and ufd

27、 own files*/osufd_login ufd_lp;/用戶(hù)登錄結(jié)構(gòu)體類(lèi)型的變量osufd_openmode ifopenmaxchildmaxchild; /*record file open/close*/file *fp_mfd,*fp_ufd,*fp_file_p,*fp_file;/file 是變量類(lèi)型,實(shí)際上是語(yǔ)言定義的標(biāo)準(zhǔn)數(shù)據(jù)結(jié)構(gòu),用于文件void clrscr()/*清屏*/system(cls);void main()int i,choice1;char choice50; /*choice operation:dir,create,delete,open,delet

28、e,modify,read,write*/int choiceend=1; /*whether choice end*/fopen標(biāo)準(zhǔn)函數(shù),打開(kāi)文件msd.txt,打開(kāi)一個(gè)二進(jìn)制文件,只允許讀數(shù)據(jù),送返指針,指向file類(lèi)型對(duì)象。if(fp_mfd=fopen(d:osfilemfd.txt,rb)=null)fp_mfd=fopen(d:osfilemfd.txt,wb);/打開(kāi)一個(gè)二進(jìn)制文件,只允許寫(xiě)數(shù)據(jù)fclose(fp_mfd);/關(guān)閉一個(gè)流for(i=0;i,strupr(dirname);/表示以字符串型輸出else printf(bad command or file name.

29、choose helpnd:%s,strupr(dirname);/strupr-變?yōu)榇髮?xiě)字母gets(choice);strcpy(choice,ltrim(rtrim(strlwr(choice);/strlwr將字符串轉(zhuǎn)換為小寫(xiě)形式,strcpy(dest,char)復(fù)制 /ltrim(rtrim()去掉輸入用戶(hù)名的頭部和尾部空格if (strcmp(choice,dir)=0) choice1=1;/strcmp相同為0else if(strcmp(choice,create)=0) choice1=2;else if(strcmp(choice,delete)=0) choice1=

30、3;else if(strcmp(choice,attrib)=0) choice1=4;else if(strcmp(choice,open)=0) choice1=5;else if(strcmp(choice,close)=0) choice1=6;else if(strcmp(choice,read)=0) choice1=7;else if(strcmp(choice,write)=0) choice1=8;else if(strcmp(choice,exit)=0) choice1=9;else if(strcmp(choice,cls)=0) choice1=10;else if

31、(strcmp(choice,cd)=0) choice1=11;else if(strcmp(choice,help)=0) choice1=20;else choice1=12;switch(choice1)case 1:dirf();choiceend=1;break;case 2:createf();choiceend=1;if(!wgetchar) getchar();break;case 3:deletef();choiceend=1;if(!wgetchar)getchar();break;case 4:modifyfm();choiceend=1;if(!wgetchar) g

32、etchar();break;case 5:openf();choiceend=1;if (!wgetchar) getchar();break;case 6:closef();choiceend=1;if (!wgetchar) getchar();break;case 7:readf();choiceend=1;if (!wgetchar) getchar();break;case 8:writef();choiceend=1;if (!wgetchar) getchar();break;case 9:printf(nyou have exited this system.); quitf

33、();exit(0);break;case 10:clrscr();choiceend=1;break;case 11:cdf();choiceend=1;break;/更改目錄名稱(chēng)case 20:help();choiceend=1;break;default:choiceend=0;else printf(naccess denied.);char *rtrim(char *str) /*remove the trailing blanks.去掉登陸用戶(hù)名的尾空格*/int n=strlen(str)-1;while(n=0)if(*(str+n)!= )*(str+n+1)=0;brea

34、k;else n-;if (n0) str0=0;return str;char *ltrim(char *str) /*remove the heading blanks.去掉登陸用戶(hù)名的頭空格*/strrev(str);/字符的順序顛倒rtrim(str);strrev(str);return str;void setpano(int rorw) /*set physical address num,0-read,1-write物理地址*/int i,j;if (rorw=0)if(fp_file_p=fopen(d:osfilefilefile_p.txt,rb)=null)/只讀fp_

35、file_p=fopen(d:osfilefilefile_p.txt,wb);/只寫(xiě)fclose(fp_file_p);fp_file_p=fopen(d:osfilefilefile_p.txt,rb);/只讀/fread讀數(shù)據(jù)(輸入地址,大小,個(gè)數(shù),提供數(shù)據(jù)的文件),sizeof是內(nèi)存空間的大小不是長(zhǎng)度f(wàn)or(i=0;fread(&j,sizeof(int),1,fp_file_p)!=0;i+)fpaddrnoj=1;elsefp_file_p=fopen(d:osfilefilefile_p.txt,wb);/只寫(xiě)for(i=0;imax;i+)if (fpaddrnoi=1)fwr

36、ite(&i,sizeof(int),1,fp_file_p);/fwrite寫(xiě)數(shù)據(jù)輸出地址,字節(jié)數(shù),個(gè)數(shù),目標(biāo)文件)fclose(fp_file_p);void inputpw(char *password) /*input password,use * replace*/int j;for(j=0;j0)j-;putchar(b);putchar( );putchar(b);else j-;elsepasswordj=0; break;passwordj=0;int existd(char *dirname) /*whether dirname exist,exist-i,not exis

37、t-(-1)*/int i;int exist=0;for(i=0;iufdname),strupr(dirname)=0)exist=1;break;if (exist) return(i);else return(-1);int existf(char *filename) /*whether filename exist,exist-i,not exist-(-1)*/int i,j;int exist=0;j=existd(dirname);for(i=0;iufdfilei.fname),strupr(filename)=0)exist=1;break;if (exist) retu

38、rn(i);else return(-1);int findpano() /*find out physical address num*/int i;for(i=0;imax;i+)if (fpaddrnoi=0) fpaddrnoi=1;break;if (iufdname,strupr(ufd_lp.ufdname);fp_ufd=fopen(str,rb);fcountj=0;/當(dāng)前用戶(hù)文件數(shù)目for(i=0;fread(&ufdj-ufdfilei,sizeof(osfile),1,fp_ufd)!=0;i+,fcountj+)/記錄用戶(hù)文件ifopenji.ifopen=0;ifopenji.openmode=4;fclose(fp_ufd);fclose(

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論