文件管理系統(tǒng)課程設(shè)計(jì)---多用戶多級(jí)目錄文件系統(tǒng)的實(shí)現(xiàn)_第1頁(yè)
已閱讀1頁(yè),還剩26頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、<p><b>  課 程 設(shè) 計(jì)</b></p><p>  課程名稱_____操作系統(tǒng) ____ </p><p>  題目名稱_多用戶多級(jí)目錄文件系統(tǒng)的實(shí)現(xiàn) _ </p><p>  學(xué)生學(xué)院_____計(jì)算機(jī)學(xué)院_________</p><p><b>  專業(yè)班級(jí) </b&g

2、t;</p><p>  學(xué) 號(hào) 3    </p><p><b>  學(xué)生姓名     </b></p><p>  指導(dǎo)教師      </p><p><b>  2008年 1月</b></p><p><b>  文件管理系統(tǒng)</b>&

3、lt;/p><p><b>  設(shè)計(jì)目的:</b></p><p>  編寫(xiě)并調(diào)試一個(gè)樹(shù)型目錄結(jié)構(gòu)的文件系統(tǒng),模擬文件管理工作流程。</p><p><b>  設(shè)計(jì)要求:</b></p><p> ?、伲O(shè)計(jì)多用戶文件系統(tǒng),采用多級(jí)文件目錄。</p><p>  ②.至少要有十

4、個(gè)以上的實(shí)用命令,應(yīng)設(shè)置文件保護(hù)措施。</p><p> ?、郏O(shè)計(jì)一個(gè)較實(shí)用的用戶界面,方便用戶使用,界面要為用戶提供足夠的選擇信息,不需用戶打入冗長(zhǎng)的命令。</p><p><b>  設(shè)計(jì)內(nèi)容</b></p><p>  本程序設(shè)計(jì)了一個(gè)樹(shù)形目錄結(jié)構(gòu)的文件管理系統(tǒng),初始化系統(tǒng)默認(rèn)根目錄為root,根目錄下為11個(gè)用戶的注冊(cè)目錄,包括一個(gè)超

5、級(jí)用戶su和十個(gè)普通用戶stud01~stud10,初始化的樹(shù)形分支結(jié)構(gòu)如下:</p><p><b>  root</b></p><p>  su stud01 stud02 stud03 stud04 stud05 stud06 stud07 stud08 stud09stud10</p><p&g

6、t;  初始化后各個(gè)用戶注冊(cè)目錄下均為空,用戶可進(jìn)行創(chuàng)建編輯文件,顯示文件內(nèi)容,刪除文件,復(fù)制文件,粘貼文件,創(chuàng)建目錄,刪除目錄,更改工作目錄,顯示當(dāng)前工作目錄的全路徑,顯示當(dāng)前目錄下的全部?jī)?nèi)容,尋求幫助及用戶切換等操作,當(dāng)只有目錄可以為分支節(jié)點(diǎn)創(chuàng)建其目錄下的子目錄或者文件(這里指的文件為除目錄外的終端文件),也可以為葉子節(jié)點(diǎn)以待必要的時(shí)候在其目錄下創(chuàng)建子目錄或者文件使其成為分支節(jié)點(diǎn),而文件只能是葉子節(jié)點(diǎn)。</p><

7、;p>  程序運(yùn)行時(shí)要求輸入用戶名及其密碼,初始化時(shí)su和stud01~stud10相應(yīng)的密碼分別為su,01stud,02stud,03stud,04stud,05stud,06stud,07stud,08stud,09stud,10stud,系統(tǒng)將驗(yàn)證輸入的用戶名及其密碼,并提示是否輸入正確,錯(cuò)誤要求重新輸入。用戶密碼只有超級(jí)用戶su才能更改,普通用戶沒(méi)有權(quán)限進(jìn)行此操作。登錄后系統(tǒng)在每個(gè)命令提示符前加【用戶名】,表示當(dāng)前的登錄

8、用戶,若登錄用戶為su時(shí),命令提示符為#符號(hào),若為普通用戶,命令提示符為$符號(hào),而且工作目錄也指向當(dāng)前登錄用戶的注冊(cè)目錄下。而只有登錄用戶為su時(shí)才可以訪問(wèn)根目錄及其所有用戶的注冊(cè)目錄下的所有目錄以及文件,登錄用戶為普通用戶時(shí)只能訪問(wèn)根目錄以及當(dāng)前用戶注冊(cè)目錄下的所有子目錄和文件,如當(dāng)前用戶為stud01,就無(wú)權(quán)訪問(wèn)su以及stud02~stud10目錄下及其目錄下的所有子目錄和文件。</p><p>  進(jìn)入系

9、統(tǒng)后,根據(jù)系統(tǒng)各命令的功能進(jìn)行相應(yīng)的操作,系統(tǒng)所有的命令參數(shù)及其功能如下:</p><p>  su,stud01,stud02,stud03,stud04,stud05,stud06,stud07,stud08,stud09,stud10:輸入用戶名進(jìn)行用戶切換,輸入用戶名后系統(tǒng)會(huì)要求輸入用戶密碼,只有輸入正確,用戶切換才能成功;</p><p>  pwd:顯示當(dāng)前工作目錄的全路徑名;

10、</p><p>  ls:列出當(dāng)前目錄下的內(nèi)容,包括所有子目錄以及文件,列出時(shí)在目錄名后面標(biāo)記“/”,在終端文件后面標(biāo)記“*”;</p><p>  mkdir:在當(dāng)前目錄下建立子目錄,輸入此命令后,系統(tǒng)提示“directory name:”,要求輸入要建立的子目錄名,倘若當(dāng)前目錄下已經(jīng)存在同名子目錄,系統(tǒng)會(huì)提示“directory already exist”;</p>

11、<p>  rmdir:刪除當(dāng)前目錄下已經(jīng)存在的子目錄,輸入此命令后,系統(tǒng)提示“directory name:”,即輸入要?jiǎng)h除的子目錄名,倘若你要?jiǎng)h除的子目錄在當(dāng)前目錄下不存在,系統(tǒng)提示“directory not exist”;</p><p>  vi:在當(dāng)前目錄下建立編輯文件,輸入此命令后,系統(tǒng)提示“file name:”,要求輸入要編輯的文件名,倘若當(dāng)前目錄下已經(jīng)存在該文件,系統(tǒng)會(huì)顯示該文件內(nèi)容

12、,進(jìn)入編輯界面,若當(dāng)前目錄下沒(méi)有該文件創(chuàng)建進(jìn)入編輯界面;</p><p>  vi編輯狀態(tài)下,提示符為“:”,編輯命令及其功能為:i--進(jìn)行文本行的輸入,系統(tǒng)提示輸入要輸入文本的行,若該行已存在則清空重新等待輸入;d――刪除指定的行,系統(tǒng)提示“l(fā)inenum:”,輸入行數(shù)進(jìn)行刪除;list――顯示當(dāng)前編輯文本的內(nèi)容;wq――對(duì)文本修改進(jìn)行存儲(chǔ)并退出,系統(tǒng)同時(shí)提示“Now saving the file!Press

13、 any key and exit......”;</p><p>  cat:顯示當(dāng)前目錄下文件的內(nèi)容,輸入此命令后,系統(tǒng)提示“file name:”,倘若你要查看的文件不在當(dāng)前目錄下,系統(tǒng)提示“file not exist”;</p><p>  rm:刪除當(dāng)前目錄下已經(jīng)存在的文件,輸入此命令后,系統(tǒng)提示“file name:”,倘若你要?jiǎng)h除的文件不在當(dāng)前目錄下,系統(tǒng)提示“file n

14、ot exist”;</p><p>  cd:改變當(dāng)前目錄,輸入此命令后,系統(tǒng)提示“directory name or symbol:”,要求輸入子目錄名字或者父目錄標(biāo)識(shí),當(dāng)輸入子目錄名時(shí),若存在,當(dāng)前的工作目錄會(huì)改到子目錄,若不存在,系統(tǒng)提示“subdirectory not exist!”,當(dāng)輸入“..”時(shí),當(dāng)前目錄會(huì)返回到上一級(jí)父目錄,若當(dāng)前目錄已經(jīng)是根目錄,系統(tǒng)會(huì)提示“That is already

15、root directory!”,當(dāng)輸入“/”,工作目錄返回到根目錄root,當(dāng)輸入“.”,當(dāng)前的工作目錄保持不變,當(dāng)輸入“”,即直接按回車而不輸入任何字符,工作目錄將返回用戶注冊(cè)目錄下;</p><p>  cp:復(fù)制文件內(nèi)容到緩沖區(qū)以備粘貼,輸入此命令后,系統(tǒng)提示“file name:”,倘若你要復(fù)制的文件不在當(dāng)前目錄下,系統(tǒng)提示“file not exist”;</p><p>  

16、paste:創(chuàng)建新的文件并將緩沖區(qū)的內(nèi)容寫(xiě)進(jìn)或者用緩沖區(qū)的內(nèi)容覆蓋已存在文件的內(nèi)容,輸入此命令后,系統(tǒng)提示“file name:”,若當(dāng)前目錄下不存在此文件,則創(chuàng)建并寫(xiě)將緩沖區(qū)的內(nèi)容,若存在,系統(tǒng)提示“File already exist!Cover it or not?y/n:”,輸入y或Y覆蓋原有文件,輸入n或N拒絕此操作。</p><p>  chpw:在超級(jí)用戶狀態(tài)下更改用戶密碼,如當(dāng)前用戶不為su運(yùn)行此

17、命令,系統(tǒng)會(huì)提示“You have no right to change user password!”;</p><p>  help:查看系統(tǒng)命令參數(shù)的功能;</p><p>  exit:退出文件管理系統(tǒng)。</p><p><b>  程序運(yùn)行舉例</b></p><p>  程序運(yùn)行時(shí),當(dāng)輸入用戶名su和密碼su

18、后系統(tǒng)提示登錄成功,按任意鍵進(jìn)入文件管理界面。</p><p>  進(jìn)入用戶操作界面后,由于當(dāng)前的用戶為su,故命令提示符為#,提示符前也會(huì)顯示當(dāng)前用戶名,輸入pwd確定當(dāng)前的工作目錄,登錄后系統(tǒng)默認(rèn)目錄為用戶注冊(cè)目錄/root/su。</p><p>  在當(dāng)前目錄下創(chuàng)建新的目錄chaoyang和新的文件QQ,并編輯文件QQ,最后用wq保存并退出,用ls命令查看當(dāng)前目錄下的所有內(nèi)容,目錄

19、名的后綴為/,文件為*。</p><p>  當(dāng)輸入命令為copy時(shí),系統(tǒng)提示“command not found”,即不存在此命令參數(shù),當(dāng)輸入cp而輸入要復(fù)制的文件名為chaoyang,系統(tǒng)提示要復(fù)制的文件不存在“file not exist”,隨后復(fù)制文件QQ并粘貼創(chuàng)建新的文件ye,用cat命令查看文件內(nèi)容,可確定復(fù)制成功。</p><p>  用ls查看當(dāng)前目錄下的全部?jī)?nèi)容并用rm命

20、令刪除文件QQ,用ls確定是否已刪除該文件。</p><p>  進(jìn)行工作目錄更改,運(yùn)行命令cd,根據(jù)提示“directory name or symbol:”輸入chaoyang,進(jìn)入chaoyang目錄下,用pwd查看目錄路徑確認(rèn),用cd加標(biāo)志/返回根目錄,用cd返回用戶注冊(cè)目錄下。</p><p>  用命令cd加標(biāo)識(shí)“..”返回當(dāng)前工作目錄的上一級(jí)目錄,如/root/su返回到/r

21、oot,在根目錄下用cd命令,根據(jù)要求輸入用戶名進(jìn)入該用戶的注冊(cè)目錄訪問(wèn),若當(dāng)前的登錄用戶不為超級(jí)用戶,無(wú)權(quán)訪問(wèn)其他用戶的注冊(cè)目錄及其以下所有內(nèi)容。</p><p>  輸入用戶名stud01,系統(tǒng)要求輸入相應(yīng)的密碼01stud,若驗(yàn)證成功命令提示符變?yōu)?,其左邊為[stud01],表明當(dāng)前的登錄用戶已切換到stud01,返回到root目錄下運(yùn)行cd加目錄名stud02,企圖進(jìn)入目錄stud02進(jìn)行訪問(wèn),系統(tǒng)提示

22、“Current user don't access other users' files or dirrctory!”,即普通用戶不能訪問(wèn)其他用戶注冊(cè)目錄及其一下所有文件和子目錄。</p><p>  在登錄用戶為stud01的情況下,輸入命令chpw,系統(tǒng)提示你沒(méi)有權(quán)力更改用戶密碼“You have no right to change user password!”,重新切換到用戶su,將s

23、tud01用戶的登錄密碼改為01,運(yùn)用新的密碼重新登錄。</p><p>  返回工作目錄到根目錄下,進(jìn)行創(chuàng)建目錄,創(chuàng)建文件,刪除目錄,刪除文件,系統(tǒng)會(huì)警告“Don't allow this operation in root directory!”,在根目錄下不允許這些操作,即使在超級(jí)用戶下也不行。</p><p>  運(yùn)行help參看命令參數(shù)及其功能。</p>&

24、lt;p><b>  設(shè)計(jì)思想</b></p><p>  創(chuàng)建節(jié)點(diǎn)的結(jié)構(gòu)屬性為:</p><p>  struct node{</p><p>  char name[256];/*節(jié)點(diǎn)名稱*/</p><p>  char code[256];/*若節(jié)點(diǎn)為用戶注冊(cè)目錄,保存相應(yīng)的用戶密碼*/</p>

25、<p>  int attribute;/*attribute為1時(shí)表示節(jié)點(diǎn)為目錄,為0表示節(jié)點(diǎn)為文件*/</p><p>  struct node *parent,*firstchild,*nextsibling;/*定義雙親節(jié)點(diǎn),孩子節(jié)點(diǎn),兄弟節(jié)點(diǎn)*/</p><p>  struct line *start,*last;</p><p>  }

26、*p;/*定義節(jié)點(diǎn)的結(jié)構(gòu)屬性*/</p><p>  指針p時(shí)刻指向當(dāng)前的工作目錄,fistchild指向節(jié)點(diǎn)的第一個(gè)孩子,nextsibling鏈接相鄰的節(jié)點(diǎn)以便進(jìn)行訪問(wèn)。</p><p>  文件以及目錄的創(chuàng)建,查看,復(fù)制,粘貼,刪除等所有操作都是基于結(jié)構(gòu)體以及鏈表的操作,同時(shí)編輯文件的操作也是采用鏈表對(duì)編輯內(nèi)容進(jìn)行記憶,所以所有操作并不是實(shí)際的磁盤(pán)操作,只有程序運(yùn)行完才釋放所有的內(nèi)存

27、空間。因此只要程序運(yùn)行完重新運(yùn)行,原先在初始化目錄下進(jìn)行的相關(guān)操作結(jié)果都不會(huì)存在,這也是該程序局限性所在,有待改善。</p><p><b>  程序運(yùn)行環(huán)境</b></p><p>  本程序是在Turboc2.0下設(shè)計(jì)和調(diào)試的,設(shè)計(jì)語(yǔ)言為C語(yǔ)言。</p><p><b>  設(shè)計(jì)感悟</b></p>&l

28、t;p>  在熟悉unix文件系統(tǒng)結(jié)構(gòu)的基礎(chǔ)上,通過(guò)所學(xué)的C語(yǔ)言和數(shù)據(jù)結(jié)構(gòu)知識(shí)設(shè)計(jì)此文件管理系統(tǒng),深化了自己對(duì)C語(yǔ)言以及鏈表結(jié)構(gòu)體等數(shù)據(jù)結(jié)構(gòu)的理解和應(yīng)用,同時(shí)加深了對(duì)操作系統(tǒng)之文件系統(tǒng)中文件和目錄相關(guān)操作與內(nèi)存磁盤(pán)分配和釋放的關(guān)系。</p><p><b>  源程序及其注釋</b></p><p>  #include"string.h"&

29、lt;/p><p>  #include"stdio.h"</p><p>  #include"stdlib.h"</p><p>  #include"math.h"</p><p>  #include"conio.h"</p><p>

30、  #define getnode(type)(type*)malloc(sizeof(type))</p><p>  char sign;/*命令提示符*/</p><p>  char title[256];/*當(dāng)前用戶名*/</p><p>  int num=255;</p><p>  int symbol=0;</p>

31、;<p>  int show=0;</p><p>  char str[256];</p><p>  struct line{</p><p>  char text[81];</p><p>  int num;/*行號(hào)*/</p><p>  struct line *next;/*指向下一個(gè)輸

32、入項(xiàng)目的指針*/</p><p>  struct line *prior;/*指向前一項(xiàng)目的指針*/</p><p>  };/*定義文件編輯行的結(jié)構(gòu)屬性*/</p><p>  struct line *start;/*指向表中第一項(xiàng)目的指針*/</p><p>  struct line *last;/*指向表中最后一個(gè)項(xiàng)目的指針*/&

33、lt;/p><p>  struct line *begin;/*指向緩沖區(qū)第一項(xiàng)目的指針*/</p><p>  struct line *end;/*指向緩沖區(qū)最后一個(gè)項(xiàng)目的指針*/</p><p>  struct line *find(),*dls_store();</p><p>  struct node{</p>&l

34、t;p>  char name[256];/*節(jié)點(diǎn)名稱*/</p><p>  char code[256];/*若節(jié)點(diǎn)為用戶注冊(cè)目錄,保存相應(yīng)的用戶密碼*/</p><p>  int attribute;/*attribute為1時(shí)表示節(jié)點(diǎn)為目錄,為0表示節(jié)點(diǎn)為文件*/</p><p>  struct node *parent,*firstchild,*

35、nextsibling;/*定義雙親節(jié)點(diǎn),孩子節(jié)點(diǎn),兄弟節(jié)點(diǎn)*/</p><p>  struct line *start,*last;</p><p>  }*p;/*定義節(jié)點(diǎn)的結(jié)構(gòu)屬性*/</p><p>  typedef struct node NODE;</p><p>  NODE *root,*g,*su,*user1,*use

36、r2,*user3,*user4,*user5,*user6,*user7,*user8,*user9,*user10;</p><p><b>  main()</b></p><p><b>  {</b></p><p>  p=getnode(NODE);</p><p>  initial

37、ization();</p><p><b>  entry();</b></p><p>  while(symbol==0){clrscr();entry();}</p><p><b>  clrscr();</b></p><p>  printf("[%s]%c",ti

38、tle,sign);</p><p>  while(num!=0)</p><p><b>  {</b></p><p>  gets(str);</p><p>  operation();</p><p>  switch(num){</p><p>  case

39、1:pwd();printf("\n[%s]%c",title,sign);num=255;break;</p><p>  case 2:ls();printf("\n[%s]%c",title,sign);num=255;break;</p><p>  case 3:mkdir();printf("\n[%s]%c",tit

40、le,sign);num=255;break;</p><p>  case 4:cd();printf("\n[%s]%c",title,sign);num=255;break;</p><p>  case 5:vi();printf("\n[%s]%c",title,sign);num=255;break;</p><p&g

41、t;  case 6:rm();printf("\n[%s]%c",title,sign);num=255;break;</p><p>  case 7:rmdir();printf("\n[%s]%c",title,sign);num=255;break; </p><p>  case 8:help();printf("\n[%s]%

42、c",title,sign);num=255;break;</p><p>  case 9:cat();printf("\n[%s]%c",title,sign);num=255;break;</p><p>  case 10:change();printf("\n[%s]%c",title,sign);num=255;break;&l

43、t;/p><p>  case 11:copy();printf("\n[%s]%c",title,sign);num=255;break;</p><p>  case 12:paste();printf("\n[%s]%c",title,sign);num=255;break;</p><p>  case 13:chpw()

44、;printf("\n[%s]%c",title,sign);num=255;break;</p><p>  default:printf("\ncommand not found\n[%s]%c",title,sign);</p><p><b>  }</b></p><p><b>  

45、}</b></p><p><b>  }</b></p><p>  initialization()/*初始化根目錄和用戶目錄*/</p><p><b>  {</b></p><p>  root=getnode(NODE);</p><p>  strc

46、py(root->name,"root");</p><p>  root->attribute=1;</p><p>  root->parent=NULL;</p><p>  user10=getnode(NODE);</p><p>  strcpy(user10->name,"s

47、tud10");</p><p>  strcpy(user10->code,"10stud");</p><p>  user10->attribute=1;</p><p>  user10->parent=root;</p><p>  user10->firstchild=NULL

48、;</p><p>  user10->nextsibling=NULL;</p><p>  user9=getnode(NODE);</p><p>  strcpy(user9->name,"stud09");</p><p>  strcpy(user9->code,"09stud&qu

49、ot;);</p><p>  user9->attribute=1;</p><p>  user9->parent=root;</p><p>  user9->firstchild=NULL;</p><p>  user9->nextsibling=user10;</p><p>  u

50、ser8=getnode(NODE);</p><p>  strcpy(user8->name,"stud08");</p><p>  strcpy(user8->code,"08stud");</p><p>  user8->attribute=1;</p><p>  use

51、r8->parent=root;</p><p>  user8->firstchild=NULL;</p><p>  user8->nextsibling=user9;</p><p>  user7=getnode(NODE);</p><p>  strcpy(user7->name,"stud07&

52、quot;);</p><p>  strcpy(user7->code,"07stud");</p><p>  user7->attribute=1;</p><p>  user7->parent=root;</p><p>  user7->firstchild=NULL;</p>

53、;<p>  user7->nextsibling=user8;</p><p>  user6=getnode(NODE);</p><p>  strcpy(user6->name,"stud06");</p><p>  strcpy(user6->code,"06stud");</

54、p><p>  user6->attribute=1;</p><p>  user6->parent=root;</p><p>  user6->firstchild=NULL;</p><p>  user6->nextsibling=user7;</p><p>  user5=getnod

55、e(NODE);</p><p>  strcpy(user5->name,"stud05");</p><p>  strcpy(user5->code,"05stud");</p><p>  user5->attribute=1;</p><p>  user5->pare

56、nt=root;</p><p>  user5->firstchild=NULL;</p><p>  user5->nextsibling=user6;</p><p>  user4=getnode(NODE);</p><p>  strcpy(user4->name,"stud04");<

57、/p><p>  strcpy(user4->code,"04stud");</p><p>  user4->attribute=1;</p><p>  user4->parent=root;</p><p>  user4->firstchild=NULL;</p><p>

58、;  user4->nextsibling=user5;</p><p>  user3=getnode(NODE);</p><p>  strcpy(user3->name,"stud03");</p><p>  strcpy(user3->code,"03stud");</p><

59、p>  user3->attribute=1;</p><p>  user3->parent=root;</p><p>  user3->firstchild=NULL;</p><p>  user3->nextsibling=user4;</p><p>  user2=getnode(NODE);<

60、;/p><p>  strcpy(user2->name,"stud02");</p><p>  strcpy(user2->code,"02stud");</p><p>  user2->attribute=1;</p><p>  user2->parent=root;<

61、;/p><p>  user2->firstchild=NULL;</p><p>  user2->nextsibling=user3;</p><p>  user1=getnode(NODE);</p><p>  strcpy(user1->name,"stud01");</p><

62、;p>  strcpy(user1->code,"01stud");</p><p>  user1->attribute=1;</p><p>  user1->parent=root;</p><p>  user1->firstchild=NULL;</p><p>  user1-&g

63、t;nextsibling=user2;</p><p>  su=getnode(NODE);</p><p>  strcpy(su->name,"su");</p><p>  strcpy(su->code,"su");</p><p>  su->attribute=1;&l

64、t;/p><p>  su->parent=root;</p><p>  su->firstchild=NULL;</p><p>  su->nextsibling=user1;</p><p>  root->firstchild=su;</p><p>  root->nextsibl

65、ing=NULL;</p><p><b>  }</b></p><p>  entry()/*系統(tǒng)登錄界面,驗(yàn)證用戶及密碼*/</p><p><b>  {</b></p><p><b>  int h;</b></p><p>  char

66、username[256],password[256];</p><p><b>  h=0;</b></p><p>  g=getnode(NODE);</p><p><b>  g=su;</b></p><p>  printf("\n\n");</p>

67、<p>  printf("\t\t********FILE MANAGE SYSTEM********\n");</p><p>  printf("\n\n\n\n\n\n\n");</p><p>  printf("\t\tuser:");</p><p>  gets(username)

68、;</p><p>  printf("\n");</p><p>  printf("\t\tpassword:");</p><p>  gets(password);</p><p>  while(g!=NULL)</p><p><b>  {</b&g

69、t;</p><p>  if(strcmp(username,g->name)==0)</p><p><b>  {</b></p><p><b>  h=1;</b></p><p>  if(strcmp(password,g->code)==0)</p><

70、;p><b>  {</b></p><p><b>  symbol=1;</b></p><p>  printf("\n\t\tSucceed in logging on!Press any key and enter......");</p><p><b>  p=g;<

71、/b></p><p>  if(strcmp(username,"su")==0) sign='#';</p><p>  else sign='$';</p><p>  strcpy(title,username);</p><p><b>  }</b>&

72、lt;/p><p>  else printf("\n\t\tIncorrect password!");</p><p><b>  break;</b></p><p><b>  }</b></p><p>  else g=g->nextsibling;</p&g

73、t;<p><b>  }</b></p><p>  if(h==0) printf("\n\t\tIncorrect username!");</p><p><b>  getch();</b></p><p><b>  }</b></p>&l

74、t;p>  change()/*切換用戶*/</p><p><b>  {</b></p><p><b>  NODE *u;</b></p><p>  char password[256];</p><p>  printf("\npassword:");</

75、p><p>  gets(password);</p><p>  u=root->firstchild;</p><p>  while(strcmp(str,u->name)!=0)u=u->nextsibling;</p><p>  if(strcmp(password,u->code)!=0) printf(&q

76、uot;\nIncorrect password!");</p><p><b>  else{</b></p><p><b>  p=u;</b></p><p><b>  g=u;</b></p><p>  strcpy(title,str);</p&

77、gt;<p>  if(strcmp(str,"su")==0) sign='#';</p><p>  else sign='$';</p><p>  begin=NULL;end=NULL;</p><p><b>  show=0;</b></p><

78、p><b>  }</b></p><p><b>  }</b></p><p>  operation()/*驗(yàn)證輸入的命令參數(shù)*/</p><p><b>  {</b></p><p><b>  NODE *u;</b></p>

79、<p>  u=root->firstchild;</p><p>  if(strcmp(str,"exit")==0)num=0;</p><p>  else if(strcmp(str,"pwd")==0)num=1;</p><p>  else if(strcmp(str,"ls&

80、quot;)==0)num=2;</p><p>  else if(strcmp(str,"mkdir")==0)num=3;</p><p>  else if(strcmp(str,"cd")==0)num=4;</p><p>  else if(strcmp(str,"vi")==0)nu

81、m=5;</p><p>  else if(strcmp(str,"rm")==0)num=6;</p><p>  else if(strcmp(str,"rmdir")==0)num=7;</p><p>  else if(strcmp(str,"help")==0)num=8;</p&

82、gt;<p>  else if(strcmp(str,"cat")==0)num=9;</p><p>  else if(strcmp(str,"cp")==0)num=11;</p><p>  else if(strcmp(str,"paste")==0)num=12;</p><p

83、>  else if(strcmp(str,"chpw")==0) num=13;</p><p><b>  else {</b></p><p>  while(u!=NULL&&strcmp(str,u->name)!=0)u=u->nextsibling;</p><p>  if(

84、u!=NULL)num=10;</p><p><b>  }</b></p><p><b>  }</b></p><p>  pwd()/*顯示當(dāng)前的工作路徑*/</p><p><b>  {</b></p><p>  NODE *t,*L,*

85、k;</p><p>  L=getnode(NODE);</p><p>  L->firstchild=NULL;</p><p><b>  t=p;</b></p><p><b>  do</b></p><p><b>  {</b>&

86、lt;/p><p>  k=getnode(NODE);</p><p>  strcpy(k->name,p->name);</p><p>  k->firstchild=L->firstchild;</p><p>  L->firstchild=k;</p><p>  p=p->

87、;parent;</p><p>  }while(p!=NULL);</p><p>  for(k=L->firstchild;k!=NULL;k=k->firstchild)</p><p><b>  {</b></p><p>  printf("/%s",k->name)

88、;</p><p><b>  }</b></p><p>  printf("\n");</p><p><b>  p=t;</b></p><p><b>  }</b></p><p>  mkdir()/*創(chuàng)建子目錄*/&l

89、t;/p><p><b>  {</b></p><p>  if(p!=root)</p><p><b>  {</b></p><p>  NODE *q,*t,*w;</p><p><b>  t=p;</b></p><p&g

90、t;<b>  w=p;</b></p><p>  q=getnode(NODE);</p><p>  printf("\ndirectory name:");</p><p>  scanf("%s",q->name);</p><p>  q->attribut

91、e=1;</p><p>  w=w->firstchild;</p><p>  while((strcmp(w->name,q->name)!=0||w->attribute!=1)&&w!=NULL)</p><p><b>  {</b></p><p>  w=w->

92、;nextsibling;</p><p><b>  }</b></p><p>  if(w!=NULL) printf("\ndirectory already exist");</p><p><b>  else</b></p><p><b>  {<

93、/b></p><p>  q->parent=p;</p><p>  q->firstchild=NULL;</p><p>  q->nextsibling=p->firstchild;</p><p>  p->firstchild=q;</p><p><b> 

94、 }</b></p><p><b>  p=t;</b></p><p>  gets(str);</p><p><b>  }</b></p><p>  else printf("\nDon't allow this operation in root dire

95、ctory!");</p><p><b>  }</b></p><p>  ls()/*顯示當(dāng)前目錄下的所有內(nèi)容,后綴為/的表示目錄,*的表示文件*/</p><p><b>  {</b></p><p><b>  NODE *t;</b></p>

96、<p><b>  t=p;</b></p><p>  p=p->firstchild;</p><p>  printf("\n");</p><p>  while(p!=NULL)</p><p><b>  {</b></p><

97、p>  if(p->attribute==1) printf("%s/\t",p->name);</p><p>  else printf("%s*\t",p->name);</p><p>  p=p->nextsibling;</p><p><b>  }</b>&l

98、t;/p><p><b>  p=t;</b></p><p><b>  }</b></p><p>  cd()/*改變當(dāng)前的工作目錄*/</p><p><b>  {</b></p><p><b>  NODE *t;</b>

99、</p><p>  int flag=1;</p><p>  printf("\ndirectory name or symbol:");</p><p>  gets(str);</p><p>  if(strcmp(str,"..")==0)/*返回當(dāng)前目錄的上一級(jí)目錄*/</p>

100、<p><b>  {</b></p><p>  if(p->parent!=NULL) p=p->parent;</p><p>  else printf("\nThat is already root directory!");</p><p><b>  }</b>

101、</p><p>  else if(strcmp(str,"")==0)/*返回用戶注冊(cè)子目錄*/</p><p><b>  {</b></p><p><b>  p=g;</b></p><p><b>  }</b></p><

102、p>  else if(strcmp(str,"/")==0)/*返回根目錄*/</p><p><b>  {</b></p><p>  while(p->parent!=NULL) p=p->parent;</p><p><b>  }</b></p><p

103、>  else if(strcmp(str,".")==0){}/*保持當(dāng)前目錄不變*/</p><p>  else/*當(dāng)前目錄改變?yōu)橹付ǖ淖幽夸?/</p><p><b>  {</b></p><p>  if(p!=root||sign!='$'){</p><p>&

104、lt;b>  t=p;</b></p><p>  p=p->firstchild;</p><p>  while(p!=NULL&&flag)</p><p><b>  {</b></p><p>  if(strcmp(str,p->name)==0&&

105、;p->attribute==1) flag=0;</p><p>  else p=p->nextsibling;</p><p><b>  }</b></p><p>  if(p==NULL)</p><p><b>  {</b></p><p>  p

106、rintf("\nsubdirectory not exist!");</p><p><b>  p=t;</b></p><p><b>  }</b></p><p><b>  }</b></p><p><b>  else</b&

107、gt;</p><p><b>  {</b></p><p>  if(strcmp(str,g->name)!=0)</p><p>  printf("\nCurrent user don't access other users' files or dirrctory!");</p>

108、<p><b>  else p=g;</b></p><p><b>  }</b></p><p><b>  }</b></p><p><b>  }</b></p><p>  rm()/*刪除文件*/</p><

109、;p><b>  {</b></p><p>  if(p!=root)</p><p><b>  {</b></p><p>  NODE *t,*s;</p><p><b>  t=p;</b></p><p>  printf("

110、;\nfile name:");</p><p>  gets(str);</p><p>  p=p->firstchild;</p><p>  if(strcmp(str,p->name)==0&&p->attribute==0)</p><p><b>  {</b>&

111、lt;/p><p>  t->firstchild=p->nextsibling;</p><p><b>  p=t;</b></p><p><b>  }</b></p><p><b>  else</b></p><p><b&g

112、t;  {</b></p><p>  while((strcmp(str,p->name)!=0||p->attribute!=0)&&p!=NULL)</p><p><b>  {</b></p><p><b>  s=p;</b></p><p> 

113、 p=p->nextsibling;</p><p><b>  }</b></p><p>  if(p!=NULL){s->nextsibling=p->nextsibling;free(p);}</p><p>  else printf("\nfile not exist");</p>

114、<p><b>  p=t;</b></p><p><b>  }</b></p><p><b>  }</b></p><p>  else printf("\nDon't allow this operation in root directory!")

115、;</p><p><b>  }</b></p><p>  rmdir()/*刪除子目錄*/</p><p><b>  {</b></p><p>  if(p!=root)</p><p><b>  {</b></p><p

116、>  NODE *t,*s;</p><p><b>  t=p;</b></p><p>  printf("\ndirectory name:");</p><p>  gets(str);</p><p>  p=p->firstchild;</p><p>

117、  if(strcmp(str,p->name)==0&&p->attribute==1)</p><p><b>  {</b></p><p>  t->firstchild=p->nextsibling;</p><p><b>  p=t;</b></p>&l

118、t;p><b>  }</b></p><p><b>  else</b></p><p><b>  {</b></p><p>  while((strcmp(str,p->name)!=0||p->attribute!=1)&&p!=NULL)</p&g

119、t;<p><b>  {</b></p><p><b>  s=p;</b></p><p>  p=p->nextsibling;</p><p><b>  }</b></p><p>  if(p!=NULL){s->nextsibling=

120、p->nextsibling;free(p);}</p><p>  else printf("\ndirectory not exist");</p><p><b>  p=t;</b></p><p><b>  }</b></p><p><b>  }&

121、lt;/b></p><p>  else printf("\nDon't allow this operation in root directory!");</p><p><b>  }</b></p><p>  help()/*提示命令參數(shù)功能*/</p><p><b&

122、gt;  {</b></p><p>  printf("\n****COMMAND PARAMETER****\n");</p><p>  printf("su,stud01,stud02,stud03,stud04,stud05,stud06,stud07,stud08,stud09,stud10:\n");</p>

123、<p>  printf(" help you switch to other user;\n");</p><p>  printf("pwd:display the path of current directory or file;\n");</p><p>  printf("ls:display all subdir

124、ectory and file under current directory,symbol * \n");</p><p>  printf(" denotes file name,symbol / denotes directory name;\n"); </p><p>  printf("mkdir:create a subdirecto

125、ry under current directory;\n");</p><p>  printf("rmdir:delete a subdirectory under current directory;\n");</p><p>  printf("vi:create a file under current directory and edit

126、;\n");</p><p>  printf("rm:create a file under current directory;\n");</p><p>  printf("cat:display file content;\n");</p><p>  printf("cp:copy file co

127、ntent into buffer and save;\n");</p><p>  printf("paste:creat a file and overwrite with buffer content;\n");</p><p>  printf("cd:choose the path and enter into subdurectory o

128、r parent directory,\n");</p><p>  printf("\tfor enample,when system requests to input the subdirectory name or the\n");</p><p>  printf(" parent directory symbol,if you inpu

129、t subdirectory name,current directory\n");</p><p>  printf(" will point to the subdirectory,if you input ..,current directory will\n");</p><p>  printf(" point to father di

130、rectory,if you input /,current directory will point\n");</p><p>  printf(" to root directory,if you input .,current directory will not alter,if input\n");</p><p>  printf("

131、 nothing and enter,current directory will point to registered user directory;\n");</p><p>  printf("help:if you have any doubt,input help and seek system help\n");</p><p>  printf

132、("exit:end the file system operation\n");</p><p><b>  }</b></p><p>  edit()/*對(duì)文件內(nèi)容編輯*/</p><p><b>  {</b></p><p>  int choice;</p>

133、;<p>  char s[80],fname[80];</p><p>  struct line *info;</p><p>  int linenum=1;</p><p>  int guide=0;</p><p><b>  do{</b></p><p>  ch

134、oice=menu_select();</p><p>  switch(choice){</p><p>  case 1:printf("linenum:");</p><p><b>  gets(s);</b></p><p>  linenum=atoi(s);</p><

135、;p>  enter(linenum);</p><p><b>  break;</b></p><p>  case 2:delete();</p><p><b>  break;</b></p><p>  case 3:list();</p><p><

136、b>  break;</b></p><p><b>  case 4:</b></p><p>  save();start=NULL;last=NULL;guide=1;</p><p><b>  break;</b></p><p><b>  }</b&g

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 眾賞文庫(kù)僅提供信息存儲(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)論