




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、中北大學(xué)操作系統(tǒng)課程設(shè)計(jì)說(shuō) 明 書(shū)學(xué) 院、系:軟件學(xué)院專(zhuān) 業(yè):軟件工程學(xué) 生 姓 名:學(xué) 號(hào):0921010414設(shè) 計(jì) 題 目:基于linux的模擬文件系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn) 起 迄 日 期: 2011年12月22日- 2012年1月7日指 導(dǎo) 教 師:2012 年 1月 7 日1 需求分析 所要實(shí)現(xiàn)的功能: (1) 設(shè)計(jì)一個(gè)10個(gè)用戶(hù)的文件系統(tǒng)。每個(gè)用戶(hù)最多可以保存10個(gè)文件,一次運(yùn)行用戶(hù)可打開(kāi)多個(gè)文件。(2) 程序采用二級(jí)文件目錄。(即設(shè)置主目錄(mfd)和用戶(hù)文件目錄(ufd)。另外,可打開(kāi)文件設(shè)置指針。(3) 為了方便實(shí)現(xiàn),對(duì)文件的讀寫(xiě)作了簡(jiǎn)化。在執(zhí)行讀寫(xiě)命令時(shí),只需改讀寫(xiě)指針。并不進(jìn)行實(shí)
2、際的讀寫(xiě)操作。(4) 實(shí)現(xiàn)的基本功能主要包括:改變目錄(cd),創(chuàng)建目錄(md),顯示目錄(dir),刪除目錄(rd),打開(kāi)全部文件(openall),打開(kāi)單個(gè)文件(open),建立一個(gè)文件(create),刪除一個(gè)文件(delete),寫(xiě)文件(write),讀文件(read),改文件的保護(hù)碼(change),退出(exit)等。考慮特殊情況如:各個(gè)命令對(duì)全路徑和相對(duì)路徑的支持、目錄不存在時(shí),給出錯(cuò)誤信息、不能用cd進(jìn)入文件、命令之中不能有空格(如 ex it,給出錯(cuò)誤提示)、相對(duì)路徑的解析、路徑中的空格剔除、新建目錄或文件時(shí)的問(wèn)題、重名問(wèn)題、目錄或文件的名字長(zhǎng)度限制、目錄或文件的名字中包含不
3、合法字符(注意空格)、刪除目錄或文件時(shí)的問(wèn)題、刪除不存在的文件或目錄給出錯(cuò)誤提示、刪除目錄時(shí)目錄不為空(如果該目錄為空,則可刪除,否則給出是否做刪除提示,刪除操作將該目錄下的全部文件和子目錄都刪除)、進(jìn)入到某個(gè)目錄下,卻要?jiǎng)h除本目錄或上級(jí)目錄、不能用delete刪除目錄、不能用rd刪除文件等都要考慮在內(nèi)。最終獲得的成果就是:在系統(tǒng)中用一個(gè)文件來(lái)模擬一個(gè)磁盤(pán);此系統(tǒng)至少有:create、delete、open、close、read、write等和部分文件屬性的功能。實(shí)現(xiàn)這個(gè)文件系統(tǒng)。能實(shí)際演示這個(gè)文件系統(tǒng)?;旧鲜沁M(jìn)入一個(gè)界面(此界面就是該文件系統(tǒng)的界面)后,可以實(shí)現(xiàn)設(shè)計(jì)的操作要求。2 總體設(shè)計(jì)
4、 2.1系統(tǒng)活動(dòng)圖 用戶(hù)管理系統(tǒng)文件目錄管理系統(tǒng)新建目錄刪除目錄進(jìn)入目錄打開(kāi)文件路徑控制登陸退出 目錄內(nèi)文件管理系統(tǒng)新建文件讀文件寫(xiě)文件 刪除 移動(dòng)登陸退出 注冊(cè) 登陸 退出 2.2 頭文件:#include #include #include 2.3結(jié)構(gòu)體:typedef struct file char name10; struct file *next;file *fp;file;typedef struct contentchar name10;file *filehead;int f_num;struct content *next;content;typedef struct us
5、er char name10; char psw10; content *conhead;int c_num; struct user *next;user;2.4 全局變量和函數(shù):void registe()int login()void menuuser()void foldercreate()void folderdelete()void folderviewallfiles()void folderintofolder()void menufolder()void filecreate()void fileread()void filewrite()void filedelete()v
6、oid filemove()3 詳細(xì)設(shè)計(jì)用戶(hù)管理系統(tǒng):registe():用戶(hù)注冊(cè)login():用戶(hù)登錄目錄管理系統(tǒng):foldercreate():新建目錄folderdelete():刪除目錄folderintofolder():進(jìn)入目錄folderviewallfiles():顯示所有目錄內(nèi)的所有文件absolutepathfilecontroller():通過(guò)絕對(duì)路徑直接讀文件文件管理系統(tǒng):filecreate():新建文件filedelete():刪除文件filemove():跨目錄移動(dòng)文件fileread():讀文件filewrite():寫(xiě)文件3.1 用戶(hù)管理系統(tǒng): 截圖3-1相
7、關(guān)核心代碼:/step0void registe()if(user_num=10)printf(has 10 users.you have no access to registern);return;/allocate new memory block for new useruser *add,*last;add=(user *)malloc(sizeof(user);add-next=null;if(user_head=null)user_head=add;elselast=user_head;while(last-next!=null)last=last-next;last-next=
8、add;user_num+;/fulfill the new userchar name10,psw10;user *check;char buffer2;fgets(buffer,2,stdin);unr:printf(now create a new user:nuser name(9,only alphabet and number can be used):n);scanf(%s,name);check=user_head;while(check!=add)if(strcmp(name,check-name)=0)printf(username exist.please re-inpu
9、t:n);goto unr;check=check-next;strcpy(add-name,name);fgets(buffer,2,stdin);printf(password(10):n);fgets(psw,10,stdin);strcpy(add-psw,psw);add-conhead=null;add-c_num=0;/successprintf(successn);return;/step0int login()if(user_head=null)printf(system has no usern);return 0;char buffer2;fgets(buffer,2,s
10、tdin);char name10,psw10;user *check;printf(press # if you wanna quitn);unl:printf(username:n);scanf(%s,name);if(name0=#)return 0;check=user_head;while(check!=null)if(!strcmp(check-name,name)break;elsecheck=check-next;if(check=null)printf(no such user.nplease re-input:n);goto unl;/match passwordfgets
11、(buffer,2,stdin);printf(password:n);fgets(psw,11,stdin);if(strcmp(psw,check-psw)!=0)printf(wrong passwordn);goto unl;printf(nn*welcome back!%s*nn,check-name);cur_user=check;return 1;void main(int argc, char* argv)user_num=0;user_head=null;cur_user=null;int choice;for(;)printf(*main menu*n);printf(1.
12、 new usern);printf(2. loginn);printf(0. exitn);printf(*n);printf(%d user existn,user_num);printf(input your choice:);scanf(%d,&choice);switch(choice)case 1:registe();continue;case 2:if(login()menuuser();continue;case 0:printf(thanks for usingn);exit(0);default:printf(wrong input!n);3.2 目錄管理系統(tǒng): 截圖3-2
13、相關(guān)核心代碼:/step0-1void menuuser()void foldercreate();void folderdelete();void folderviewallfiles();void folderintofolder();void absolutepathfilecontroller();user *current;content *gothrough;current=cur_user;gothrough=current-conhead;for(;)printf(*%ss content*n,cur_user-name);printf(1.create a foldern);
14、printf(2.get in to a foldern);printf(3.delete a foldern);printf(4.view all filesn);printf(5.read a file directly by absolute pathn);printf(6.log outn);printf(0.shut down file_systemn);printf(view all your folders below:%d folders totaln,current-c_num);if(current-conhead=null)printf(|nno folder.n);el
15、segothrough=current-conhead;while(gothrough!=null)printf(|n%sn,gothrough-name);gothrough=gothrough-next;printf(*);printf(ninput your choice:n);int choice;scanf(%d,&choice);switch(choice)case 1:foldercreate();continue;case 2:folderintofolder();continue;case 3:folderdelete();continue;case 4:folderview
16、allfiles();continue;case 5:absolutepathfilecontroller();continue;case 6:printf(nthanks for usingnn);return;case 0:printf(nthanks for usingn);cur_user=null;cur_con=null;exit(0);default:printf(wrong input!n);/step1void foldercreate()user *user;user=cur_user;/allocate new memory block for new foldercon
17、tent *add,*last;add=(content *)malloc(sizeof(content);add-next=null;if(user-conhead=null)user-conhead=add;elselast=user-conhead;while(last-next!=null)last=last-next;last-next=add;user-c_num+;add-filehead=null;add-f_num=0;/fulfill the new folder namechar name10;content *check;char buffer2;fgets(buffe
18、r,2,stdin);con_r:printf(now create a new folder:nfolder name(9,only alphabet and number can be used):n);scanf(%s,name);check=user-conhead;while(check!=add)if(strcmp(name,check-name)=0)printf(folder name exist.please re-input:n);goto con_r;check=check-next;/check legality of the nameint i=0;for(;i=97
19、&namei=48&namei=65&namei=90)/uppercontinue;elseif(namei=0)break;elseprintf(is a illegal input!nplease re-input:n,namei);goto con_r;strcpy(add-name,name);printf(donenn);return;/step1void folderdelete()if(cur_user-conhead=null)printf(no foldernn);return;content *front,*current;char name10;printf(press
20、 # if you wanna quitn);con_d:printf(folder name:n);scanf(%s,name);if(name0=#)return;/seek folder namecurrent=cur_user-conhead;while(current!=null)if(!strcmp(current-name,name)break;elsecurrent=current-next;if(current=null)printf(no such folder.nplease re-input:n);goto con_d;/if has any fileswhile(cu
21、rrent-filehead!=null)char buffer2;fgets(buffer,2,stdin);printf(folder not empty!if you sure you wanna delete?(y/n)n);char judge;scanf(%c,&judge);if(judge=n|judge=y|judge=n|judge=y)if(judge=n|judge=n)return;elsebreak;elseprintf(please input y or nn);continue;/user recognisechar psw10;printf(input you
22、r user password to recognise:);char buffer2;fgets(buffer,2,stdin);fgets(psw,10,stdin);if(strcmp(cur_user-psw,psw)!=0)printf(wrong password!ndelete function failledn);return;/execute delete operationfront=cur_user-conhead;if(front=current)/if curren is the head filecur_user-conhead=current-next;free(
23、current);printf(has been deletedn1n);return;while(front-next!=current)front=front-next;front-next=current-next;free(current);cur_user-c_num-;printf(has been deletedn2n);return;/step1void folderviewallfiles()printf(nscan all your file:n);content *con;con=cur_user-conhead;int fi_num=0;while(con!=null)
24、printf(|%s-n,con-name);file *fi;fi=con-filehead;while(fi!=null)printf(|%sn,fi-name);printf(|n);fi=fi-next;fi_num+=con-f_num;con=con-next;printf(total:%d folders,%d filesnn,cur_user-c_num,fi_num);return;/step1void folderintofolder()void menufolder();if(cur_user-conhead=null)printf(you has no foldern)
25、;return;printf(now get into a folder:nfolder name(9):n);char name10;char buffer2;fgets(buffer,2,stdin);content *check;printf(type # if you wanna quitn);con_g:printf(folder name:ncd );scanf(%s,name);if(name0=#)return;check=cur_user-conhead;while(check!=null)if(!strcmp(check-name,name)break;elsecheck=
26、check-next;if(check=null)printf(no such folder.nplease re-input:n);goto con_g;/successcur_con=check;menufolder();return;/step void absolutepathfilecontroller()printf(n_n);printf(format:/n);printf(_n);char name28;printf(press # if you wanna quitn);absolute:printf(absolute file path:n);scanf(%s,name);
27、if(name0=#)return;char folder_name10;char file_name14;/analyse the absolute path/get folder nameif(name0=/)printf(no folder name!please re-input:n);goto absolute;int i=0,j=0;while(namei!=/&i=9)if(namei=0)printf(wrong formatn);goto absolute;folder_namei=namei;i+;folder_namei=0;i+;/get file nameif(nam
28、ei=0)printf(no ,please re-inputn);goto absolute;while(namei+j!=0&jconhead;while(folder_checker!=null)if(!strcmp(folder_checker-name,folder_name)break;elsefolder_checker=folder_checker-next;if(folder_checker=null)printf(no such folder.nplease re-input:n);goto absolute;/seek filefile *file_checker;fil
29、e_checker=folder_checker-filehead;while(file_checker!=null)if(!strcmp(file_checker-name,file_name)break;elsefile_checker=file_checker-next;if(file_checker=null)printf(no such file.nplease re-input:n);goto absolute;/read the filechar fullname20=pro/;strcat(fullname,file_name);printf(=ndetails:nn);fil
30、e_checker-fp=fopen(fullname,r);char ch;while(ch!=eof)putchar(ch=getc(file_checker-fp);printf(n=n);fclose(file_checker-fp);return;3.2 文件管理系統(tǒng): 截圖3-3相關(guān)核心代碼:/step1-2void menufolder()void filecreate();void fileread();void filewrite();void filedelete();void filemove();file *gothrough;content *current;curr
31、ent=cur_con;gothrough=current-filehead;char buffer2;int choice;for(;)fgets(buffer,2,stdin);printf(nfolder:%sn,current-name);printf(1.create a new filen);printf(2.read a filen);printf(3.write to a filen);printf(4.delete a filen);printf(5.move a filen);printf(6.back to user-menun);printf(0.shut down f
32、ile_systemnn);printf(view all your files below:%d files totaln,current-f_num);if(current-filehead=null)printf(|nno file.n);elsegothrough=current-filehead;while(gothrough!=null)printf(|n%sn,gothrough-name);gothrough=gothrough-next;printf();printf(ninput your choice:n);choice=-1;scanf(%d,&choice);swit
33、ch(choice)case 1:filecreate();continue;case 2:fileread();continue;case 3:filewrite();continue;case 4:filedelete();continue;case 5:filemove();continue;case 6:printf(nnow in your ufd:nn);cur_con=null;return;case 0:printf(nthanks for usingn);cur_user=null;cur_con=null;exit(0);default:printf(wrong input
34、!n);/step2void filecreate()content *cur_content;cur_content=cur_con;/allocate new memory block for new files indexfile *add,*last;add=(file *)malloc(sizeof(file);add-next=null;add-fp=null;if(cur_content-filehead=null)cur_content-filehead=add;elselast=cur_content-filehead;while(last-next!=null)last=l
35、ast-next;last-next=add;cur_content-f_num+;/fulfill the new folder namechar name10;file *check;char buffer2;fgets(buffer,2,stdin);file_r:printf(now create a new file:nfile name(9,only alphabet and number can be used):n);scanf(%s,name);check=cur_content-filehead;while(check!=add)if(strcmp(name,check-n
36、ame)=0)printf(file name exist.please re-input:n);goto file_r;check=check-next;/check legality of the nameint i=0;for(;i=97&namei=48&namei=65&namei=90)/uppercontinue;elseif(namei=0)break;elseprintf(is a illegal input!nplease re-input:n,namei);goto file_r;strcpy(add-name,name);char fullname20=pro/;str
37、cat(fullname,name);add-fp=fopen(fullname,w);if(add-fp=null)printf(error when create a file in desknpease contact system managern);goto file_r;fclose(add-fp);printf(donenn);return;/step2void fileread()if(cur_con-filehead=null)printf(no filenn);return;printf(nnow read a file:n);file *current;char name
38、10;printf(press # if you wanna quitn);file_r:printf(file name:n);scanf(%s,name);if(name0=#)return;/seek file namecurrent=cur_con-filehead;while(current!=null)if(!strcmp(current-name,name)break;elsecurrent=current-next;if(current=null)printf(no such file.nplease re-input:n);goto file_r;char fullname2
39、0=pro/;strcat(fullname,name);printf(=ndetails:nn);current-fp=fopen(fullname,r);char ch;while(ch!=eof)putchar(ch=getc(current-fp);printf(n=n);fclose(current-fp);return;/step2void filewrite()if(cur_con-filehead=null)printf(no filenn);return;printf(nnow read a file:n);file *current;char name10;printf(p
40、ress # if you wanna quitn);file_r:printf(file name:n);scanf(%s,name);if(name0=#)return;/seek file namecurrent=cur_con-filehead;while(current!=null)if(!strcmp(current-name,name)break;elsecurrent=current-next;if(current=null)printf(no such file.nplease re-input:n);goto file_r;char fullname20=pro/;strc
41、at(fullname,name);printf(=ntype details:(tpye in # to finish the text)nn);current-fp=fopen(fullname,a+);char ch;ch=getchar();while(ch!=#)putc(ch,current-fp);ch=getchar();fclose(current-fp);printf(=);return;/step2void filedelete()if(cur_con-filehead=null)printf(no filenn);return;file *front,*current;
42、char name10;printf(press # if you wanna quitn);file_d:printf(file name:n);scanf(%s,name);if(name0=#)return;/seek file namecurrent=cur_con-filehead;while(current!=null)if(!strcmp(current-name,name)break;elsecurrent=current-next;if(current=null)printf(no such file.nplease re-input:n);goto file_d;/exec
43、ute delete operationfront=cur_con-filehead;if(front=current)/if curren is the head filecur_con-filehead=current-next;free(current);printf(has been deletedn1n);return;while(front-next!=current)front=front-next;front-next=current-next;free(current);cur_con-f_num-;printf(has been deletedn2n);return;/st
44、ep2void filemove()printf(n=nnow move a file from folder %s to another foldern=n,cur_con-name);/move indexcontent *target_con,*current_con;if(cur_con-filehead=null)printf(no filenn);return;file *front_f,*current_f,*tar_f;char name10;printf(press # if you wanna quitn);file_m:printf(file name:n);scanf(%s,name);if(name0=#)return;/seek file namecurrent_f=cur_con-filehead;while(current_f!=null)if(!strcmp(current_f-name,name)break;elsecurrent_f=current_f-next;if(current_f=null)printf(no such file.nplease re-input:n);goto file_m;/get target folder valuec
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 廣播電視設(shè)備用網(wǎng)絡(luò)通信模塊考核試卷
- 城市垃圾填埋場(chǎng)規(guī)劃考核試卷
- 文化創(chuàng)意產(chǎn)業(yè)的資本運(yùn)作與市場(chǎng)發(fā)展動(dòng)態(tài)考核試卷
- 意外傷害保險(xiǎn)在旅游業(yè)的風(fēng)險(xiǎn)管理考核試卷
- 乳飲料的無(wú)乳糖配方設(shè)計(jì)與市場(chǎng)潛力考核試卷
- 文具企業(yè)產(chǎn)品線規(guī)劃考核試卷
- 葡萄加工售賣(mài)合同范本
- 旅游門(mén)票售賣(mài)合同范本
- 土建付款合同范本
- 第四季度營(yíng)銷(xiāo)工作重點(diǎn)計(jì)劃及時(shí)間表安排方案
- 2025年幼兒園膳食工作計(jì)劃
- 《基于二維激光SLAM的AGV導(dǎo)航系統(tǒng)設(shè)計(jì)》
- 藥劑學(xué)第9版課件:第一章-緒論
- 《下載-綜合布線》課件
- 電化學(xué)儲(chǔ)能系統(tǒng)測(cè)試操作方法
- (高清版)DB43∕T 1588.28-2019 小吃湘菜 第28部分:武岡空餅
- 第六單元 共同面對(duì)的全球性問(wèn)題 知識(shí)清單
- 老年病科重點(diǎn)專(zhuān)科建設(shè)
- 工程投標(biāo)文件范本完整版
- 小學(xué)二年級(jí)開(kāi)學(xué)家長(zhǎng)會(huì)課件2024-2025學(xué)年
- 語(yǔ)文跨學(xué)科合作:語(yǔ)文與數(shù)學(xué)的融合
評(píng)論
0/150
提交評(píng)論