




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(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)告專 業(yè):軟件工程學(xué) 號(hào):11103303姓 名:程路峰提交日期:2014/1/2【設(shè)計(jì)目的】1、本實(shí)驗(yàn)的目的是通過一個(gè)簡(jiǎn)單多用戶文件系統(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)。.【設(shè)計(jì)內(nèi)容】為linux系統(tǒng)設(shè)計(jì)一個(gè)簡(jiǎn)單的二級(jí)文件系統(tǒng)。要求做到以下幾點(diǎn):可以實(shí)現(xiàn)下列幾條命令:login 用戶登錄dir 列目錄 attrib 修改文件屬性create 創(chuàng)建文件delete 刪除文件open 打開文件close 關(guān)閉文件read 讀文件write 寫文件cd 進(jìn)出目錄列目錄時(shí)要列出
2、文件名,物理地址,保護(hù)碼和文件長(zhǎng)度源文件可以進(jìn)行讀寫保護(hù).【實(shí)驗(yàn)環(huán)境】windows7操作平臺(tái)visual studio2010【相關(guān)知識(shí)綜述】理解二級(jí)目錄的文件系統(tǒng)的組織;掌握常用的數(shù)據(jù)結(jié)構(gòu);系統(tǒng)采用兩級(jí)目錄,其中第一級(jí)對(duì)應(yīng)于用戶賬號(hào),第二級(jí)對(duì)應(yīng)于用戶帳號(hào)下的文件;使用文件來模擬外存,進(jìn)行數(shù)據(jù)結(jié)構(gòu)設(shè)計(jì)和操作算法的設(shè)計(jì),實(shí)現(xiàn)一個(gè)文件系統(tǒng)并實(shí)現(xiàn)基本的文件操作(為了簡(jiǎn)便文件系統(tǒng),不考慮文件共享,文件系統(tǒng)安全以及管道文件與設(shè)備文件等特殊內(nèi)容)?!驹O(shè)計(jì)思路】采用的數(shù)據(jù)結(jié)構(gòu)、主要的函數(shù)說明、程序流程設(shè)計(jì)等本文件系統(tǒng)采用兩級(jí)目錄,其中第一級(jí)對(duì)應(yīng)于用戶賬號(hào),第二級(jí)對(duì)應(yīng)于用戶帳號(hào)下的文件。另外,為了簡(jiǎn)便文件系
3、統(tǒng)未考慮文件共享,文件系統(tǒng)安全以及管道文件與設(shè)備文件等特殊內(nèi)容。首先應(yīng)確定文件系統(tǒng)的數(shù)據(jù)結(jié)構(gòu):主目錄、子目錄及活動(dòng)文件等。主目錄和子目錄都以文件的形式存放于磁盤,這樣便于查找和修改。用戶創(chuàng)建的文件,可以編號(hào)存儲(chǔ)于磁盤上。如:file0,file1,file2并以編號(hào)作為物理地址,在目錄中進(jìn)行登記1.主要的數(shù)據(jù)結(jié)構(gòu)#define maxname 25 /*the largest length of mfdname,ufdname,filename表示三種文件的長(zhǎng)度都為25*/#define maxchild 50 /*the largest child每個(gè)用戶下可以有50個(gè)文件*/#define
4、 max (maxchild*maxchild) /*the size of fpaddrno定義一個(gè)常量2500個(gè)扇區(qū)*/typedef struct /*the structure of osfile*/int fpaddr; /*file physical address物理地址*/ int flength; /*file length文件長(zhǎng)度*/ int fmode; /*file mode:0-read only;1-write only;2-read and write; 3-protect;*/ char fnamemaxname; /*file name文件名*/ osfile
5、;typedef struct /*the structure of osufd*/char ufdnamemaxname; /*ufd name*/osfile ufdfilemaxchild; /*ufd own file*/osufd;/*osf文件的數(shù)據(jù)結(jié)構(gòu)*/typedef struct /*the structure of osufdlogin*/char ufdnamemaxname; /*ufd name*/ char ufdpword8; /*ufd password*/ osufd_login;typedef struct /*file open mode*/int ifo
6、pen; /*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 cdf(); /*change dir*/void createf(); /*create file*/void deletef(); /*delete file*/void modifyfm(); /*modify
7、 filemode*/void openf(); /*open file*/void closef(); /*close file*/void readf(); /*read file*/void writef(); /*write file*/void quitf(); /*quit filesystem退出文件系統(tǒng)*/void help();3總體功能程序結(jié)構(gòu)圖打開命令的程序流程圖 關(guān)閉命令的程序流程圖寫命令程序流程圖 刪除命令的程序流程圖:【部分源程序清單】打開函數(shù)void openf() int fc,i;char fnamemaxname,fmode25;int fm;printf(
8、nplease input filename:);gets(fname);ltrim(rtrim(fname);if (existf(fname)0)printf(nerror. name %s is not existed.n,fname);wgetchar=1;elsei=existd(username);for(int a=0;aufdfilea.fname)=0)fc=a;break;ifopenifc.ifopen=1;printf(please input openmode(0-read only, 1-write only, 2-read and write, 3-protect
9、):);gets(fmode);fm=atoi(fmode);ifopenifc.openmode=fm;printf(nopen successed);wgetchar=1;關(guān)閉函數(shù)void closef() char fnamemaxname;int i,k;if (strcmp(strupr(dirname),strupr(username)!=0) printf(nerror.you can only modify filemode in yourself dir.n);elseprintf(nplease input filename:);gets(fname);ltrim(rtri
10、m(fname); i=existf(fname); if (i=0) k=existd(username); if(ifopenki.ifopen=0) printf(nerror. %s has been closed. you can not close it again.n,fname);else ifopenki.ifopen=0; ifopenki.openmode=4; printf(%s has been closed successfully!,fname);else printf(nerror. %s dose not exist.n,fname);刪除函數(shù)void del
11、etef() /*delete file*/char fnamemaxname,str50,str150;int i,k,j;int fpaddrno1;if (strcmp(strupr(ltrim(rtrim(dirname),)=0) printf(nerror.please convert to ufd dir before delete.n);wgetchar=1;if (strcmp(strupr(dirname),strupr(username)!=0) printf(nerror.you can only modify filemode in yourself dir.n);w
12、getchar=1;elseprintf(nplease input filename:);gets(fname);ltrim(rtrim(fname);i=existf(fname);if (i=0)k=existd(username);if(ifopenki.ifopen=1)printf(nerror.%s is in open status. close it before delete.n,fname); wgetchar=1;elseif(ufdk-ufdfilei.fmode=3)printf(nerror.%s is in protect status. close it be
13、fore delete.n,fname); wgetchar=1;elsefpaddrno1=ufdk-ufdfilei.fpaddr;fpaddrnofpaddrno1=0;for(j=i;jufdfilej=ufdk-ufdfilej+1;strcpy(str,d:osfilefilefile);itoa(fpaddrno1,str1,10);strcat(str,str1);strcat(str,.txt);remove(str);fcountk-;printf(n %sis deleted successfully.n,fname);wgetchar=1;elseprintf(nerr
14、or. %s dose not exist.n,fname);wgetchar=1;寫入函數(shù)void writef() int i,k,m=0;int length;char fnamemaxname;char str255,str1255;if (strcmp(strupr(dirname),strupr(username)!=0) printf(nerror.please convert to ufd dir before write.n);wgetchar=1;return;printf(ncaution:open file firstn);printf(opened file(s) l
15、ist:n);k=existd(dirname);for(i=0;iufdfilei.fname);m+;if(m%4=0)&(m!=0) printf(n);printf(n%d files openned.n,m);if (m=0) wgetchar=1;if(m!=0)printf(nplease input filename:);gets(fname);ltrim(rtrim(fname);i=existf(fname);if(i=0)if(ifopenki.ifopen=1)if(ifopenki.openmode=1) |(ifopenki.openmode=2)itoa(ufdk
16、-ufdfilei.fpaddr,str,10);strcpy(str1,file);strcat(str1,str);strcpy(str,c:osfilefile);strcat(str,str1);strcat(str,.txt);fp_file=fopen(str,ab);length=writef1(); ufdk-ufdfilei.flength=ufdk-ufdfilei.flength+length;printf(nn%d length.n,ufdk-ufdfilei.flength);printf(nnyou have write file successfully!); f
17、close(fp_file);wgetchar=0;else if(ifopenki.openmode=0)printf(nerror.%s has been opened with read only mode. it isnt write.n,fname);wgetchar=1;elseprintf(nerror.%s has been opened with protect mode. it isnt write.n,fname);wgetchar=1;else printf(nerror.%s is in closing status. please open it before wr
18、iten,fname);wgetchar=1;else printf(nerror. %s does not exist.n,fname);wgetchar=1;【測(cè)試結(jié)果】登錄用戶 創(chuàng)建文件:打開文件:關(guān)閉文件:第一次讀文件(查看原文件內(nèi)容):寫文件:再次讀取文件(查看是否寫入成功) 列出目錄和幫助:刪除文件:【設(shè)計(jì)總結(jié)】【源程序】#include stdio.h#include string.h#include conio.h#include stdlib.h#define maxname 25 /*the largest length of mfdname,ufdname,filenam
19、e*/#define maxchild 50 /*the largest child*/#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 fnamema
20、xname; /*file name*/ osfile;typedef struct /*the structure of osufd*/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
21、mode*/int ifopen; /*ifopen:0-close,1-open*/ int openmode; /*0-read only,1-write only,2-read and write,3-initial*/osufd_openmode;osufd *ufdmaxchild; /*ufd and ufd own files*/osufd_login ufd_lp;int ucount=0; /*the count of mfds ufds*/int fcountmaxchild; /*the count of ufds files*/int loginsuc=0; /*whe
22、ther login successfully*/char usernamemaxname; /*record login users name22*/char dirnamemaxname;/*record current directory*/int fpaddrnomax; /*record file physical address num*/osufd_openmode ifopenmaxchildmaxchild; /*record file open/close*/int wgetchar; /*whether getchar()*/file *fp_mfd,*fp_ufd,*f
23、p_file_p,*fp_file;void loginf(); /*login filesystem*/void dirf(); /*dir filesystem*/void cdf(); /*change dir*/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 writ
24、ef(); /*write file*/void quitf(); /*quit filesystem*/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*/void setpano(int rorw); /*set physical address num*/int existd(c
25、har *dirname); /*whether dirname exist,exist-i,not exist-0*/int writef1(); /*write file*/int existf(char *filename); /*whether filename exist,exist-i,not exist-0*/int findpano(); /*find out physical address num*/ void clrscr()system(cls);void main()int i,choice1;char choice50; /*choice operation:dir
26、,create,delete,open,delete,modify,read,write*/int choiceend=1; /*whether choice end*/char *rtrim(char *str); /*remove the trailing blanks.*/char *ltrim(char *str); /*remove the heading blanks.*/if(fp_mfd=fopen(c:osfilemfd.txt,rb)=null)fp_mfd=fopen(c:osfilemfd.txt,wb);fclose(fp_mfd);for(i=0;i,strupr(
27、dirname);else printf(bad command or file name.nc:%s,strupr(username); gets(choice); strcpy(choice,ltrim(rtrim(strlwr(choice); if (strcmp(choice,dir)=0) choice1=1; else if(strcmp(choice,create)=0) choice1=2; else if(strcmp(choice,delete)=0) choice1=3; else if(strcmp(choice,attrib)=0) choice1=4; else
28、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(strcmp(choice,cd)=0) choice1=11; else if(st
29、rcmp(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) getchar();break;case 5:openf();choiceend=1;
30、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();exit(0);break;case 10:clrscr();choiceen
31、d=1;break;case 11:cdf();choiceend=1;break;case 20:help();choiceend=1;break;default:choiceend=0;else printf(naccess denied.);void help(void)printf(nthe command listn);printf(n 改變目錄-cd 修改文件屬性attrib 新建文件create 寫文件write 讀文件read 打開文件open 清屏cls 刪除delete 退出exit 關(guān)閉文件closen);char *rtrim(char *str) /*remove t
32、he trailing blanks.*/int n=strlen(str)-1;while(n=0)if(*(str+n)!= )*(str+n+1)=0;break;else n-;if (nufdname,strupr(ufd_lp.ufdname);fp_ufd=fopen(str,rb);fcountj=0;for(i=0;fread(&ufdj-ufdfilei,sizeof(osfile),1,fp_ufd)!=0;i+,fcountj+)ifopenji.ifopen=0;ifopenji.openmode=4;fclose(fp_ufd);fclose(fp_mfd);uco
33、unt=j;setpano(0);printf(nnlogin successful! welcome to this filesystemnn);loginsuc=1;return;elseprintf(nn);flag=1;while(flag)printf(login failed! password error. try again(y/n):);gets(a);ltrim(rtrim(a);if (strcmp(strupr(a),y)=0) loginsuc=0;flag=0;else if(strcmp(strupr(a),n)=0)loginsuc=0;flag=0;retur
34、n;elseprintf(new password(=8):);inputpw(loginpw); /*input new password,use * replace*/printf(nconfirm password(ufdname,strupr(ufd_lp.ufdname);fp_ufd=fopen(str,rb);for(i=0;fread(&ufdj-ufdfilei,sizeof(osfile),1,fp_ufd)!=0;i+,fcountj+)ifopenji.ifopen=0; ifopenji.openmode=4;fclose(fp_ufd);fclose(fp_mfd)
35、;ucount=j;setpano(0);printf(nnlogin successful! welcome to this systemnn);loginsuc=1;return; elseprintf(nn);flag=1;while(flag)printf(login failed! password error. try again(y/n):);gets(a);ltrim(rtrim(a);if (strcmp(strupr(a),y)=0) loginsuc=0;flag=0;else if(strcmp(strupr(a),n)=0)loginsuc=0;flag=0;retu
36、rn;void setpano(int rorw) /*set physical address num,0-read,1-write*/int i,j;if (rorw=0)if(fp_file_p=fopen(c:osfilefilefile_p.txt,rb)=null) fp_file_p=fopen(c:osfilefilefile_p.txt,wb);fclose(fp_file_p); fp_file_p=fopen(c:osfilefilefile_p.txt,rb);/for(i=0;fread(&j,sizeof(int),1,fp_file_p)!=0;i+)fpaddr
37、noj=1;/*for(i=1;imax;i+)if (i%13)=0) fpaddrnoi=1;*/elsefp_file_p=fopen(c:osfilefilefile_p.txt,wb);/*for(i=1;imax;i+)if(i%13)=0) fpaddrnoi=0;*/for(i=0;imax;i+)if (fpaddrnoi=1)fwrite(&i,sizeof(int),1,fp_file_p);fclose(fp_file_p);void inputpw(char *password) /*input password,use * replace*/int j;for(j=0;j0)j-;j-;putchar(b);putchar( );putchar(b);else j-;elsepasswordj=0;break;passwordj=0;void dirf() /*dir filesystem*/int i,j,count=0;char sfmode25,sfpaddr25,str25;clrscr();if (strcmp(strupr(ltrim(rtrim(dir
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 紙箱倉(cāng)儲(chǔ)安全管理制度
- 管網(wǎng)維護(hù)安全管理制度
- 家具樣板房管理制度
- led質(zhì)量管理制度
- 小餐館員工管理制度
- 綜合醫(yī)院分級(jí)管理制度
- 小公司業(yè)績(jī)管理制度
- 礦山起重物資管理制度
- 人員溝通與管理制度
- 生產(chǎn)運(yùn)行環(huán)節(jié)管理制度
- 濕地監(jiān)理實(shí)施細(xì)則
- 中小企業(yè)數(shù)字化轉(zhuǎn)型工作方案模板范文
- 收肌康復(fù)創(chuàng)新技術(shù)
- 《濟(jì)南市供用水合同》
- 智能化設(shè)備技術(shù)規(guī)格書范本
- 工程拆墻合同范本
- 2024夏季東南亞風(fēng)情水上樂園潑水電音節(jié)開幕式活動(dòng)方案-52P
- 模擬聯(lián)合國(guó)大會(huì)流程及議題講義模板
- 呼倫貝爾職業(yè)技術(shù)學(xué)院輔導(dǎo)員考試試題2024
- 無損檢測(cè)PTⅡ級(jí)滲透檢測(cè)理論考試題庫(kù)
- 《安全儀表系統(tǒng)SIS》課件
評(píng)論
0/150
提交評(píng)論