




已閱讀5頁,還剩15頁未讀, 繼續(xù)免費閱讀
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
文件系統(tǒng)設計1文件系統(tǒng)下列幾條命令LOGIN用戶登陸DIR列文件目錄CREATE創(chuàng)建文件DELETE刪除文件OPEN打開文件CLOSE關閉文件READ讀文件WRITE寫文件列目錄時要列出文件名,物理地址,保護碼和文件長度。源文件可以進行讀寫保護。首先應確定文件系統(tǒng)的數(shù)據(jù)結構:主目錄、子目錄及活動文件等。主目錄和子目錄都以文件的形式存放于磁盤,這樣便于查找和修改。用戶創(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)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 校長課堂唱歌活動方案
- 校長述職活動方案
- 江蘇互聯(lián)網(wǎng)培訓活動方案
- 殘疾人送鮮花活動方案
- 水電安全活動方案
- 漢堡店充值活動方案
- 正規(guī)公司服裝策劃方案
- 河南微信活動方案
- 汽車俱樂部開展活動方案
- 殘疾人集中服務活動方案
- 城鎮(zhèn)污泥標準檢驗方法CJT221-2023 知識培訓
- 屋頂分布式光伏電站施工組織設計方案
- DB11T 1034.2-2024交通噪聲污染緩解工程技術規(guī)范 第2部分:聲屏障措施
- 四川省成都市金牛區(qū)2023-2024學年七年級下學期期末數(shù)學試題
- DL-T664-2016帶電設備紅外診斷應用規(guī)范
- 中華民族共同體概論課件專家版6第六講 五胡入華與中華民族大交融(魏晉南北朝)
- 海南師范大學2022年計算機網(wǎng)絡期末試題及答案
- 廣西大學附屬中學2023-2024學年高一化學第二學期期末質量檢測模擬試題含解析
- 新型激光焊接解決方案 解決電機定子焊接難題
- 停車場智能管理系統(tǒng)培訓教材課件
- 醫(yī)學影像技術及其臨床應用
評論
0/150
提交評論