多級(jí)目錄管理及Linux代碼分析 操作系統(tǒng)課程設(shè)計(jì)報(bào)告(6)_第1頁
多級(jí)目錄管理及Linux代碼分析 操作系統(tǒng)課程設(shè)計(jì)報(bào)告(6)_第2頁
多級(jí)目錄管理及Linux代碼分析 操作系統(tǒng)課程設(shè)計(jì)報(bào)告(6)_第3頁
多級(jí)目錄管理及Linux代碼分析 操作系統(tǒng)課程設(shè)計(jì)報(bào)告(6)_第4頁
多級(jí)目錄管理及Linux代碼分析 操作系統(tǒng)課程設(shè)計(jì)報(bào)告(6)_第5頁
已閱讀5頁,還剩32頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、哈爾濱理工大學(xué)課程設(shè)計(jì)(計(jì)算機(jī)操作系統(tǒng))題目: 多級(jí)目錄管理及l(fā)inux代碼分析 班級(jí): 姓名: 指導(dǎo)教師: 系主任: 2014年03月01日目 錄1多級(jí)目錄管理課程設(shè)計(jì)11.1 題目分析11.2 數(shù)據(jù)結(jié)構(gòu)11.3 流程圖11.4 實(shí)現(xiàn)技術(shù)21.5 設(shè)計(jì)結(jié)論和心得22 linux代碼分析32.1時(shí)鐘和定時(shí)器中斷42.2tvecs結(jié)構(gòu)及其實(shí)現(xiàn)42.3間隔定時(shí)器itimer42.4函數(shù)調(diào)用關(guān)系圖4第1章1多級(jí)目錄管理課程設(shè)計(jì)1.1 題目分析在現(xiàn)代計(jì)算機(jī)系統(tǒng)中,都要存儲(chǔ)大量的文件,為了能對(duì)這些文件實(shí)施有效的管理,必須對(duì)他們加以妥善組織,這主要是通過文件目錄來實(shí)現(xiàn)的。對(duì)于大型文件系統(tǒng),通常采用三級(jí)或三

2、級(jí)以上的目錄結(jié)構(gòu),以提高對(duì)目錄的檢索速度和文件系統(tǒng)的性能。多級(jí)文件目錄又成為樹型目錄結(jié)構(gòu),主目錄在這里被成為根目錄,把數(shù)據(jù)文件成為樹葉,其他的目錄均作為樹的結(jié)點(diǎn)。本課程設(shè)計(jì)要求設(shè)計(jì)一個(gè)基于多級(jí)文件目錄的文件管理系統(tǒng)。通過具體的文件存儲(chǔ)空間的管理、文件的物理結(jié)構(gòu)、目錄結(jié)構(gòu)和文件操作的實(shí)現(xiàn),加深對(duì)文件系統(tǒng)內(nèi)部功能和實(shí)現(xiàn)過程的理解。主要要求有:1.在內(nèi)存中開辟一個(gè)虛擬磁盤空間作為文件存儲(chǔ)器,在其上實(shí)現(xiàn)一個(gè)多級(jí)文件目錄的文件管理系統(tǒng);2.文件物理結(jié)構(gòu)可采用顯式鏈接或其他方法;3.文件目錄結(jié)構(gòu)采用多級(jí)目錄結(jié)構(gòu),每個(gè)目錄項(xiàng)包含文件名、物理地址、長度等信息,還可以通過目錄項(xiàng)實(shí)現(xiàn)對(duì)文件的讀和寫的保護(hù);4.設(shè)計(jì)

3、一個(gè)較實(shí)用的用戶界面,方便用戶使用。1.2 數(shù)據(jù)結(jié)構(gòu)1).文件夾數(shù)據(jù)結(jié)構(gòu)體:typedef struct mfd /主文件目錄 char username100; char password100; file *fp; /文件目錄指針mfd;2).用戶文件數(shù)據(jù)結(jié)構(gòu)體:typedef struct ufd /用戶文件目錄 char filename256; char protect; /保護(hù)碼 int length; /文件長度ufd;3).功能實(shí)現(xiàn)命令數(shù)據(jù)結(jié)構(gòu)體:typedef struct comm /命令串char string256; /用戶命令串 struct comm *next;

4、/后繼指針:指向命令各參數(shù)所在的結(jié)點(diǎn)comm;mfd mainfdn; /主文件目錄數(shù)組ufd userfdm; /用戶文件目錄數(shù)組ofd openfdl; /打開文件目錄數(shù)組comm *command; /命令串指針int next;disk;1.3 流程圖開始輸入用戶判斷是否存在yesno刪除文件創(chuàng)建子目錄改變子目錄列出子目錄關(guān)閉文件打開文件創(chuàng)建文件讀文件寫文件是否退出結(jié)束noyes 圖1程序流程圖1.4 實(shí)現(xiàn)技術(shù)1.運(yùn)行后主界面顯示圖2主界面2.輸入login命令 用戶登陸,當(dāng)用戶賬號(hào)不存在時(shí),即可創(chuàng)建:圖3創(chuàng)建用戶3.創(chuàng)建用戶下文件功能實(shí)現(xiàn):圖4創(chuàng)建用戶4.打開文件open命令功能的實(shí)

5、現(xiàn)圖5打開文件5.讀文件read命令功能實(shí)現(xiàn)圖6.讀文件6. 寫文件write命令功能實(shí)現(xiàn),及對(duì)內(nèi)容中添加實(shí)現(xiàn)圖7寫文件8.退出文件logout操作圖8退出文件1.5 設(shè)計(jì)結(jié)論和心得這次操作系統(tǒng)課程設(shè)計(jì),在編寫過程中,遇到很多難題,特別是在操作系統(tǒng)實(shí)驗(yàn)中不曾注意到的問題,也有許多新的問題,在實(shí)際反復(fù)調(diào)試運(yùn)行中,不斷加深了對(duì)操作系統(tǒng)的理解,也很大地程度上提高了編程的能力,由于對(duì)重要概念的把握程度還不夠深入,在實(shí)際理解編寫時(shí)遇到很多不該發(fā)生的問題。不過,都很好的解決并牢牢地掌握住了。通過做多級(jí)目錄文件系統(tǒng),我知道了多級(jí)目錄文件系統(tǒng)的工作原理,在打開文件時(shí)系統(tǒng)是如何進(jìn)行操作的,并加深了理解。希望在以

6、后的學(xué)習(xí)中,繼續(xù)保持這份昂揚(yáng)的斗志,繼續(xù)努力學(xué)習(xí)計(jì)算機(jī)方面的知識(shí),永不懈怠。通過這次課程設(shè)計(jì),不僅讓我了解了多級(jí)目錄文件系統(tǒng),更重要的還讓我學(xué)會(huì)了、或者說是驗(yàn)證了“做事一定要有次序和對(duì)事物的總體把握”這句話。開始我一味的進(jìn)行調(diào)試,急切的想僥幸調(diào)試出來,但由于沒有進(jìn)行深入的考慮,我調(diào)試了很久都沒沒有成功,我仔細(xì)的分析題目,分析材料,在原由的基礎(chǔ)上我進(jìn)行了改正,我最后還是調(diào)試成功了,雖然還是經(jīng)過了一翻努力,當(dāng)然汗水還是留的很值,這次操作系統(tǒng)實(shí)習(xí),不僅讓我對(duì)操作系統(tǒng)這門課程有了更深入的研究、對(duì)很多重要的概念有了鞏固和掌握,還給了我今后做事的啟示。做事要塌實(shí),不能想著一步登天,要有計(jì)劃,有目的的進(jìn)行做

7、事。盲目真的不應(yīng)該再在我們新一代的大學(xué)生身上出現(xiàn)了,我們應(yīng)該認(rèn)真找到自己的缺點(diǎn)并且及時(shí)改正。在這里,我如果不說感謝的話,不知道要說些什么好;首先感謝學(xué)校和父母,然后更重要的是感謝老師的教導(dǎo)?!盎畹嚼?,學(xué)到老”,這也是我整個(gè)學(xué)習(xí)過程中的一次經(jīng)驗(yàn)、一次總結(jié),我相信它肯定會(huì)給我今后的學(xué)習(xí)有所啟示和指導(dǎo)作用。附錄:源程序代碼:#include #include /里面有clrscr()清屏函數(shù) #include #include #include /內(nèi)存分配函數(shù)#include #include #define n 30 /用戶數(shù)#define m 20 /一個(gè)用戶可保存m個(gè)文件#define l 5

8、 /用戶只能一次打開l個(gè)文件typedef struct mfd /主文件目錄char username100; char password100; file *fp; /文件目錄指針mfd;typedef struct ufd /用戶文件目錄char filename256; char protect; /保護(hù)碼 int length; /文件長度ufd;typedef struct ofd /打開文件目錄char filename256; char opencode; /打開保護(hù)碼 int *fp; /讀寫指針ofd;typedef struct comm /命令串char string2

9、56; /用戶命令串 struct comm *next; /后繼指針:指向命令各參數(shù)所在的結(jié)點(diǎn)comm;mfd mainfdn; /主文件目錄數(shù)組ufd userfdm; /用戶文件目錄數(shù)組ofd openfdl; /打開文件目錄數(shù)組comm *command; /命令串指針char username100;int usernum,savenum,opennum;int workfile;void init(); /初始化主文件目錄數(shù)組void init_ufd(char *username); /初始化用戶文件目錄void mesg(char *str); /輸出函數(shù)char *getus

10、er(); /設(shè)置用戶函數(shù)聲明char *getpass(); /設(shè)置口令函數(shù)聲明comm *readcommand(); /讀命令串函數(shù)聲明void login(); /用戶登錄void setpass(); /設(shè)置口令void create(); /創(chuàng)建用戶文件void mydelete(); /刪除void myread(); /讀void myopen(); /打開void myclose(); /關(guān)閉void mywrite(); /寫void help(); /幫助void main() init();printf(ntt );printf(ntt 多級(jí)文件目錄的文件管理系統(tǒng) );

11、printf(ntt );printf(ntt選擇命令: );printf(ntt login setpass create );printf(ntt open read write delete);printf(ntt help exit copy rename);printf(ntt首次使用請(qǐng)輸入help命令請(qǐng)求幫助 );printf(ntt使用中歡迎以help 請(qǐng)求幫助 ); while(1) readcommand(); if(strcmp(command-string,create)=0)create();else if(strcmp(command-string,delete)=0

12、)mydelete(); else if(strcmp(command-string,open)=0) myopen(); else if(strcmp(command-string,close)=0) myclose(); else if(strcmp(command-string,read)=0) myread(); else if(strcmp(command-string,write)=0) mywrite(); else if(strcmp(command-string,login)=0) login(); else if(strcmp(command-string,setpass)

13、=0) setpass(); else if(strcmp(command-string,help)=0) help(); else if(strcmp(command-string,exit)=0)break; else mesg(bad command!);void mesg(char *str) printf(n %sn,str);void init() /初始化主文件目錄數(shù)組 file *fp; /文件指針 char tempname20,temppass20; usernum=0; /全局變量初始化 savenum=0; opennum=0; strcpy(username,); /

14、用戶使用時(shí),建立一個(gè)mainfile.txt文件,包括每個(gè)用戶的用戶名和口令 /然后,才能運(yùn)行此程序 if(fp=fopen(mainfile.txt,r)!=null)/以讀方式打開文件mainfile.txt while(!feof(fp)/若不是文件尾 strcpy(tempname,); /清空數(shù)組操作 fgets(tempname,20,fp); /讀用戶名 if(strcmp(tempname,)!=0) fgets(temppass,20,fp); tempnamestrlen(tempname)-1=0; /設(shè)置串結(jié)束符 temppassstrlen(temppass)-1=0

15、; strcpy(mainfdusernum.username,tempname); /生成mainfd數(shù)組 strcpy(mainfdusernum.password,temppass); /生成userfd數(shù)組 usernum+; /生成usernum的值 if(usernum=n)break; fclose(fp); void init_ufd(char *username) /初始化用戶文件目錄file *fp; char tempfile100,tempprot; int templength; savenum=0; opennum=0; workfile=-1; if(fp=fop

16、en(username,r+)!=null)while(!feof(fp) strcpy(tempfile,); fgets(tempfile,50,fp); if(strcmp(tempfile,)!=0) fscanf(fp,%c,&tempprot); fscanf(fp,%d,&templength); tempfilestrlen(tempfile)-1=0; strcpy(userfdsavenum.filename,tempfile); /文件名 tect=tempprot; /保護(hù)碼 userfdsavenum.length=templengt

17、h; /文件長度 savenum+; fgets(tempfile,50,fp); char *getuser() /設(shè)置用戶函數(shù)聲明char username20; char temp; int i; username0=0; for(i=0;i20;)while(!kbhit(); /按用戶名規(guī)則輸入用戶名 temp=getch(); if(isalnum(temp)|temp=_|temp=(char)13) usernamei=temp; if(usernamei=(char)13) usernamei=0; break; putchar(temp); i+; usernamei=0;

18、 return username;char *getpass() /設(shè)置口令函數(shù)聲明char password20; char temp; int i; password0=0; for(i=0;i); gets(line); /輸入一個(gè)命令串 for(i=0;i0) /對(duì)命令行中的子串進(jìn)行處理tempend=0; newp=(comm*)malloc(sizeof(comm*); strcpy(newp-string,temp); newp-next=null; if(command=null) command=newp; /把各子串鏈成一個(gè)鏈表 else p=command; while(

19、p-next!=null) p=p-next; p-next=newp; p=command; return command;void login() /用戶注冊(cè)file *fp; int i; char password20,confirm20,tempname20; if(command-next=null)printf(n user name:); strcpy(tempname,getuser(); /輸入用戶名并且返回之 else if(command-next-next!=null)mesg(too many parameters!);return; else strcpy(tem

20、pname,command-next-string); for(i=0;i=usernum) /新用戶printf(n 新用戶賬號(hào),輸入你的密碼兩次!); printf(n 密碼:); strcpy(password,getpass(); /輸入口令并且返回之printf(n 密碼:); strcpy(confirm,getpass(); /第二次輸入口令 if(strcmp(password,confirm)=0) /兩次輸入的口令是否相同的處理情況if(usernum=n) /用戶數(shù)不能超過nmesg(創(chuàng)建新賬號(hào)錯(cuò)誤!用戶賬號(hào)字符超過限制.n 登陸失敗!); elsestrcpy(main

21、fdusernum.username,tempname); /把新用戶和口令填入mainfd中 strcpy(mainfdusernum.password,password); usernum+; strcpy(username,tempname); mesg(創(chuàng)建新用戶!n 登陸成功恭喜!); init_ufd(username); /初始化用戶文件目錄 fp=fopen(mainfile.txt,w+); /把新用戶填入mainfile.txt文件中 for(i=0;iusernum;i+)fputs(mainfdi.username,fp); fputs(n,fp); fputs(mai

22、nfdi.password,fp); fputs(n,fp); fclose(fp); else /兩次輸入的口令是否相同的處理情況mesg(創(chuàng)建新用戶失敗!兩次輸入密碼不一致!); mesg(登陸失敗!); else /注冊(cè)過的用戶登陸printf(n 密碼:); strcpy(password,getpass(); if(strcmp(mainfdi.password,password)!=0)mesg(登陸失敗!輸入密碼錯(cuò)誤!); elsemesg(登陸成功恭喜你!); strcpy(username,tempname); init_ufd(username);void setpass(

23、) /重新設(shè)置口令int i; file *fp; char oldpass20,newpass20,confirm20; if(strcmp(username,)=0) mesg(no user login!); elseprintf(n 舊密碼:); strcpy(oldpass,getpass(); for(i=0;iusernum;i+)if(strcmp(mainfdi.username,username)=0) break; if(strcmp(mainfdi.password,oldpass)!=0)mesg(舊密碼錯(cuò)誤!); elseprintf(n 新密碼:); strcpy

24、(newpass,getpass(); printf(n 確認(rèn)密碼:); strcpy(confirm,getpass(); if(strcmp(newpass,confirm)!=0)mesg(密碼修改錯(cuò)誤! 確認(rèn)密碼錯(cuò)誤.請(qǐng)重新輸入);elsestrcpy(mainfdi.password,newpass); mesg(password changed!); fp=fopen(mainfile.txt,w+); for(i=0;inext=null) mesg(too few parameters!);else /存在2個(gè)或3個(gè)參數(shù)的處理strcpy(tempfile,);tempcode

25、=r; if(strcmp(command-next-string,/r)=0)tempcode=r;type=1;else if(strcmp(command-next-string,/w)=0)tempcode=w;type=1; else if(strcmp(command-next-string,/d)=0)tempcode=d; type=1; else if(command-next-string0=/) mesg(error! /r /w /d request!); else if(command-next-next!=null) mesg(too many parameters

26、!);else strcpy(tempfile,command-next-string);if(type=1) /三個(gè)參數(shù)的情況補(bǔ)充if(command-next-next!=null)if(command-next-next-next!=null)mesg(too many parameters!);else strcpy(tempfile,command-next-next-string);else mesg(too few parameters!);if(strcmp(tempfile,)!=0)for(i=0;i=savenum) mesg(file not existed!);els

27、e /文件存在的情況for(i=0;iopennum;i+)if(strcmp(tempfile,openfdi.filename)=0)break;if(i=l) /打開的文件已經(jīng)占滿了5個(gè)名額mesg(error! cannot open file! nimber of opened files limited!);else /打開處理strcpy(openfdopennum.filename,tempfile);openfdopennum.opencode=tempcode;workfile=opennum;opennum+;mesg(file open success!); void

28、myclose() /關(guān)閉文件int i,j;char tempfile100;if(strcmp(username,)=0) mesg(no user login!); elseif(command-next=null) mesg(too few parameters!); else if(command-next-next!=null) mesg(too many parameters!); elsestrcpy(tempfile,command-next-string);for(i=0;i=savenum) /文件不存在mesg(文件不存在!);else for(j=0;j=opennu

29、m) /文件存在了但是沒有打開mesg(文件存在了但是沒有打開!); else /文件存在并且打開strcpy(openfdj.filename,); openfdj.opencode= ; opennum-; mesg(文件關(guān)閉成功!);void mydelete() /刪除文件int i,j;int tempsave; /用于確定被刪除文件在數(shù)組userfdm中的位置char tempfile100;file *fp;if(strcmp(username,)=0) mesg(沒有用戶登陸!); elseif(command-next=null) mesg(too few parameter

30、s!); else if(command-next-next!=null) mesg(太多參數(shù)導(dǎo)致錯(cuò)誤!); elsestrcpy(tempfile,command-next-string);for(i=0;i=savenum) /文件不存在mesg(the file donot existed!);else for(j=0;jopennum;j+)if(strcmp(openfdj.filename,tempfile)=0)break;if(jopennum) /文件存在了但是打開mesg(文件不能刪除!);mesg(首先需要關(guān)閉它!); else /文件存在并且沒有打開strcpy(use

31、rfdtempsave.filename,); tect= ; userfdtempsave.length=0;savenum-;for(i=tempsave;i=savenum;i+) /從新將數(shù)組userfdm排序strcpy(userfdi.filename,userfdi+1.filename); tect=userfdi+1.protect; userfdi.length=userfdi+1.protect; mesg(file delete!);fp=fopen(username,w+); /寫回到文件username fo

32、r(i=0;inext=null) mesg(參數(shù)太少導(dǎo)致錯(cuò)誤!);else if(command-next-next!=null)mesg(參數(shù)太多導(dǎo)致錯(cuò)誤!);elsestrcpy(tempfile,command-next-string);for(i=0;i=savenum) mesg(文件不存在!);else tempsave=i;for(i=0;i=opennum) mesg(文件沒有打開!);elseif(userfdtempsave.lengthnext=null) mesg(參數(shù)太少導(dǎo)致錯(cuò)誤!);else if(command-next-next!=null)mesg(參數(shù)太多導(dǎo)致錯(cuò)誤);elsestrcpy(tempfile,command-next-string);for(i=0;i=savenum) mesg(文件不存在!);else tempsave=i;for(i=0;i=opennum) mesg(文件沒有打開!);els

溫馨提示

  • 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. 人人文庫網(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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論