




已閱讀5頁,還剩15頁未讀, 繼續(xù)免費閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
文件系統(tǒng)設(shè)計1文件系統(tǒng)下列幾條命令LOGIN用戶登陸DIR列文件目錄CREATE創(chuàng)建文件DELETE刪除文件OPEN打開文件CLOSE關(guān)閉文件READ讀文件WRITE寫文件列目錄時要列出文件名,物理地址,保護碼和文件長度。源文件可以進行讀寫保護。首先應(yīng)確定文件系統(tǒng)的數(shù)據(jù)結(jié)構(gòu):主目錄、子目錄及活動文件等。主目錄和子目錄都以文件的形式存放于磁盤,這樣便于查找和修改。用戶創(chuàng)建的文件,可以編號存儲于磁盤上。如:file0,file1,file2并以編號作為物理地址,在目錄中進行登記。程序見下(本程序需要在c:下建一個名為osfile的目錄及一個名為file的子目錄):#includestdio.h#includestring.h#includeconio.h#includestdlib.h#defineMAXNAME25/*thelargestlengthofmfdname,ufdname,filename*/#defineMAXCHILD50/*thelargestchild*/#defineMAX(MAXCHILD*MAXCHILD)/*thesizeoffpaddrno*/typedefstruct/*thestructureofOSFILE*/intfpaddr;/*filephysicaladdress*/intflength;/*filelength*/intfmode;/*filemode:0-ReadOnly;1-WriteOnly;2-ReadandWrite(default);*/charfnameMAXNAME;/*filename*/OSFILE;typedefstruct/*thestructureofOSUFD*/charufdnameMAXNAME;/*ufdname*/OSFILEufdfileMAXCHILD;/*ufdownfile*/OSUFD;typedefstruct/*thestructureofOSUFDLOGIN*/charufdnameMAXNAME;/*ufdname*/charufdpword8;/*ufdpassword*/OSUFD_LOGIN;typedefstruct/*fileopenmode*/intifopen;/*ifopen:0-close,1-open*/intopenmode;/*0-readonly,1-writeonly,2-readandwrite,3-initial*/OSUFD_OPENMODE;OSUFD*ufdMAXCHILD;/*ufdandufdownfiles*/OSUFD_LOGINufd_lp;intucount=0;/*thecountofmfdsufds*/intfcountMAXCHILD;/*thecountofufdsfiles*/intloginsuc=0;/*whetherloginsuccessfully*/charusernameMAXNAME;/*recordloginusersname22*/chardirnameMAXNAME;/*recordcurrentdirectory*/intfpaddrnoMAX;/*recordfilephysicaladdressnum*/OSUFD_OPENMODEifopenMAXCHILDMAXCHILD;/*recordfileopen/close*/intwgetchar;/*whethergetchar()*/FILE*fp_mfd,*fp_ufd,*fp_file_p,*fp_file;voidmain()inti,j,choice1;charchoice50;/*choiceoperation:dir,create,delete,open,delete,modify,read,write*/intchoiceend=1;/*whetherchoiceend*/char*rtrim(char*str);/*removethetrailingblanks.*/char*ltrim(char*str);/*removetheheadingblanks.*/voidLoginF();/*LOGINFileSystem*/voidDirF();/*DirFileSystem*/voidCdF();/*ChangeDir*/voidCreateF();/*CreateFile*/voidDeleteF();/*DeleteFile*/voidModifyFM();/*ModifyFileMode*/voidOpenF();/*OpenFile*/voidCloseF();/*CloseFile*/voidReadF();/*ReadFile*/voidWriteF();/*WriteFile*/voidQuitF();/*QuitFileSystem*/voidhelp();if(fp_mfd=fopen(c:osfilemfd,rb)=NULL)fp_mfd=fopen(c:osfilemfd,wb);fclose(fp_mfd);for(i=0;i,strupr(dirname);elseprintf(Badcommandorfilename.nC:%s,strupr(username);gets(choice);strcpy(choice,ltrim(rtrim(strlwr(choice);if(strcmp(choice,dir)=0)choice1=1;elseif(strcmp(choice,creat)=0)choice1=2;elseif(strcmp(choice,delete)=0)choice1=3;elseif(strcmp(choice,attrib)=0)choice1=4;elseif(strcmp(choice,open)=0)choice1=5;elseif(strcmp(choice,close)=0)choice1=6;elseif(strcmp(choice,read)=0)choice1=7;elseif(strcmp(choice,modify)=0)choice1=8;elseif(strcmp(choice,exit)=0)choice1=9;elseif(strcmp(choice,cls)=0)choice1=10;elseif(strcmp(choice,cd)=0)choice1=11;elseif(strcmp(choice,help)=0)choice1=20;elsechoice1=12;switch(choice1)case1:DirF();choiceend=1;break;case2:CreateF();choiceend=1;if(!wgetchar)getchar();break;case3:DeleteF();choiceend=1;if(!wgetchar)getchar();break;case4:ModifyFM();choiceend=1;if(!wgetchar)getchar();break;case5:choiceend=1;OpenF();if(!wgetchar)getchar();break;case6:choiceend=1;CloseF();if(!wgetchar)getchar();break;case7:choiceend=1;ReadF();if(!wgetchar)getchar();break;case8:choiceend=1;WriteF();if(!wgetchar)getchar();break;case9:printf(nYouhaveexitedthissystem.);QuitF();exit(0);break;case10:choiceend=1;clrscr();break;case11:CdF();choiceend=1;break;case20:help();choiceend=1;break;default:choiceend=0;elseprintf(nAccessdenied.);voidhelp(void)printf(nTheCommandListn);printf(nCdAttribCreatModifyReadOpenClsDeleteExitClosen);char*rtrim(char*str)/*removethetrailingblanks.*/intn=strlen(str)-1;while(n=0)if(*(str+n)!=)*(str+n+1)=0;break;elsen-;if(n0)str0=0;returnstr;char*ltrim(char*str)/*removetheheadingblanks.*/cha
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 經(jīng)濟安全戰(zhàn)略的制定試題及答案
- 2025年軟考重要注意事項及試題及答案
- 戰(zhàn)略實施中的個體因素重要性試題及答案
- 網(wǎng)絡(luò)數(shù)據(jù)加密方法試題與答案總結(jié)
- 軟件設(shè)計師考試重要知識點試題及答案
- 2025年VB考試復(fù)習(xí)指南及試題與答案
- 2025不動產(chǎn)抵押協(xié)議合同范本
- 杭汽輪合作協(xié)議
- 結(jié)果導(dǎo)向的工作方法計劃
- 從失敗中學(xué)習(xí)的個人計劃
- 優(yōu)質(zhì)課件:幾代中國人的美好夙愿
- 2024老舊小區(qū)改造質(zhì)量驗收規(guī)范
- 被詐騙的起訴書范文
- 產(chǎn)品供貨方案、售后服務(wù)方案
- 全球健康智慧樹知到課后章節(jié)答案2023年下浙江大學(xué)
- 無違法犯罪記錄證明申請表(個人)
- 阿里巴巴java開發(fā)手冊-阿里系
- 2023年07月浙江建設(shè)技師學(xué)院200人筆試歷年常考點試卷附帶答案詳解
- 神經(jīng)重癥康復(fù)中國專家共識-醫(yī)學(xué)課件
- 中國真正丹道理法及工程次第闡真
- 2023年廣東深圳市檢察機關(guān)招錄勞動合同制書記員150人筆試模擬試題及答案解析
評論
0/150
提交評論