文件管理課程設(shè)計(jì)報(bào)告_第1頁
文件管理課程設(shè)計(jì)報(bào)告_第2頁
文件管理課程設(shè)計(jì)報(bào)告_第3頁
文件管理課程設(shè)計(jì)報(bào)告_第4頁
文件管理課程設(shè)計(jì)報(bào)告_第5頁
已閱讀5頁,還剩23頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、操作系統(tǒng)課程設(shè)計(jì)報(bào)告姓 名:xxx_學(xué)號(hào):xxxxxxxxxxxx_專 業(yè) 年 級(jí):軟件2班指 導(dǎo) 教 師:_xx_2016年 3月1日1 概述目的:本實(shí)驗(yàn)的目的是通過一個(gè)簡單多用戶文件系統(tǒng)的設(shè)計(jì),加深理解文件系統(tǒng)的內(nèi)部功能及內(nèi)部實(shí)現(xiàn)。意義: 本系統(tǒng)是基于linux平臺(tái)運(yùn)行在終端上的虛擬二級(jí)文件管理系統(tǒng).模擬真正的文件管理系統(tǒng),并采用用戶登錄機(jī)制對(duì)文件和文件夾進(jìn)行創(chuàng)建,修改,刪除的操作。對(duì)于文件夾而言,可以進(jìn)行創(chuàng)建刪除的操作;對(duì)于文件而言,可以創(chuàng)建,修改,刪除。刪除文件夾時(shí),同時(shí)刪除相應(yīng)文件夾下的文件。采用用戶登錄使得用戶管理文件更方便,并形成了二級(jí)的文件管理模式。主要任務(wù):為DOS系統(tǒng)設(shè)計(jì)一

2、個(gè)簡單的二級(jí)文件系統(tǒng).要求做到以下幾點(diǎn): 可以實(shí)現(xiàn)下列命令: login 用戶登錄 dir 列文件目錄 create 創(chuàng)建文件 delete 刪除文件 open 打開文件 close 關(guān)閉文件 read 讀文件 write 寫文件 列目錄時(shí)要列出文件名、物理地址、保護(hù)碼和文件長度。 源文件可以進(jìn)行讀寫保護(hù)2 系統(tǒng)設(shè)計(jì)(1)設(shè)計(jì)思路 程序中要求每個(gè)用戶在登陸后才可對(duì)其擁有的文件進(jìn)行操作,用戶對(duì)于其他

3、用戶的文件無操作權(quán).文件操作包括瀏覽、創(chuàng)建、刪除、打開、關(guān)閉、閱讀、寫入、修改模式。其他操作包括新建用戶、幫助、用戶登入、用戶登出、退出系統(tǒng). 在程序文件夾下有個(gè)名為“file”的系統(tǒng)根目錄,此目錄下包括:一個(gè)名為“mfd"的文件,記錄所有注冊過的帳號(hào)及密碼;用戶文件,以用戶名作為文件名,內(nèi)容為其擁有的文件名及屬性;一個(gè)名為“keiji"的文件夾。“keiji”文件夾中包括:“file。p”指針文件,記錄所有已用的物理地址;一些以物理地址為名的文件,內(nèi)容為文件內(nèi)容. (2) 數(shù)據(jù)結(jié)構(gòu) file結(jié)構(gòu)體系統(tǒng)文件。數(shù)據(jù)結(jié)構(gòu): fp

4、addrint,文件的物理地址、flengthint,文件長度、fmodeint,文件模式 0。只讀;1??蓪?;2??勺x寫;3。保護(hù)、 fnamechar,文件名; filemode結(jié)構(gòu)體文件狀態(tài)數(shù)據(jù)結(jié)構(gòu): isopenint,文件當(dāng)前狀態(tài),0.關(guān)閉;1。打開、modeint,文件模式 0。只讀;1??蓪?;2.可讀寫。(3)初始化 user結(jié)構(gòu)體用戶信息數(shù)據(jù)結(jié)構(gòu): unamechar,用戶名、upasswordchar,用戶密碼; userfile結(jié)構(gòu)體用戶文件數(shù)據(jù)結(jié)構(gòu): unamechar,用戶名、uf

5、ilefile,用戶擁有的文件數(shù)組3 系統(tǒng)實(shí)現(xiàn)#include <stdio。h  #include stdlib。h>    include <conio.h   include <time。hinclude <string。hdefine MaxUser 100 /定義最大mdf目錄文件#define MaxDisk 5121024 / 模擬最大磁盤空間 512kdefine

6、0;commandAmount 12 / 對(duì)文件操作指令數(shù)char diskMaxDisk;  / 模擬512k磁盤空間typedef struct distTable  /磁盤塊結(jié)構(gòu)體        int maxlength;        int start;       

7、 int useFlag;        distTable next;    diskNode;    diskNode *diskHead; struct fileTable    /文件塊結(jié)構(gòu)體           

8、0;char fileName10;    int strat;          /文件在磁盤存儲(chǔ)空間的起始地址 int length;         /文件內(nèi)容長度        int maxlength;  &

9、#160;   /文件的最大長度    char fileKind3;   /文件的屬性讀寫方式        struct tm timeinfo;    bool openFlag;       /判斷是否有進(jìn)程打開了文件   

10、0;  /fileTable next;    ;/兩級(jí)目錄結(jié)構(gòu)體    typedef struct user_file_directory  /用戶文件目錄文件UFD            /char fileName10;       

11、0;fileTable *file;user_file_directory next;    UFD;    /UFD headFile;    typedef struct master_file_directory  /主文件目錄MFD            char use

12、rName10;        char password10;        UFD user;    MFD;    MFD userTableMaxUser;    int used=0;/定義MFD目錄中用已有的用戶數(shù)/文件管理   

13、0;void fileCreate(char fileName,int length,char fileKind);  /創(chuàng)建文件void fileWrite(char fileName);  / 寫文件 void fileCat(char fileName);        /讀文件    void fileRen(char fileN

14、ame,char rename);  / 重命名文件void fileFine(char fileName);               /查詢文件    void fileDir(char UserName);  / 顯示某一用戶的所有文件void fileClose(char fileName

15、); / 關(guān)閉以打開的文件void fileDel(char fileName);              /刪除文件    void chmod(char fileName,char kind);  /修改文件的讀寫方式 int requestDist(int startPostion,int maxLe

16、ngth); /磁盤分配查詢    void initDisk();  / 初始化磁盤void freeDisk(int startPostion);    /磁盤空間釋放    void diskShow();          /顯示磁盤使用情況/用戶管理    v

17、oid userCreate();    int login();    int userID=-1;   /用戶登錄的ID號(hào),值為-1時(shí)表示沒有用戶登錄       int main()            char ordercommandAm

18、ount10;        strcpy(order0,”create”);  strcpy(order1,"rm”); strcpy(order2,"cat");strcpy(order3,”write”); strcpy(order4,”fine");strcpy(order5,”chmod”);  strcpy(order6,"ren”); strcpy(order7,”dir”);

19、60; strcpy(order8,"close”);strcpy(order9,"return”);  strcpy(order10,"exit”); strcpy(order11,”df”);  char command50,command_str110,command_str210,command_str35,command_str43;  int i,k,j; int length;    init

20、Disk();                     /初始化磁盤        for(i=0;iMaxUser;i+)          /初始化用戶UFD目錄文件的頭指針  

21、0;         userTablei.user=(UFD )malloc(sizeof(UFD));            userTablei。user->next=NULL;                

22、;while(1)                    printf("*n”);            printf(”            &

23、#160;     1、Creat usern”);            printf(”                  2、loginn”);       

24、60;    printf("*n”);            printf("Please chooce the function key:”);            int choice;    

25、0;       scanf("%d”,choice);            if(choice=1) userCreate();            else if(choice=2) userID=login();  &#

26、160;         else printf("您的輸入錯(cuò)誤!請重新選擇n"); while(userID!=1)                       fflush(stdin);printf(”*n"); 

27、 printf(” create-創(chuàng)建 格式:create a1 1000 rw,將創(chuàng)建名為a1,長度為1000字節(jié)可讀可寫的文件n");    printf(” rm-刪除 格式:rm a1,將刪除名為a1的文件n");  printf(” cat查看文件內(nèi)容 格式:cat a1,顯示a1的內(nèi)容n”);  printf(” write寫入  格式

28、:write a1n”);    printf(” fine查詢 格式:fine a1 ,將顯示文件 a1的屬性n");    printf(” chmod修改 格式:chmod a1 r,將文件al的權(quán)限改為只讀方式n”); printf(” ren重命名 格式:ren a1 b1 ,將a1改名為b1n”);   &

29、#160;  printf(" dir顯示文件 格式:dir aaa,將顯示aaa用戶的所有文件n”);    printf(” df顯示磁盤空間使用情況 格式:dfn”);    printf(” close-關(guān)閉文件 格式:close a1,將關(guān)閉文件a1n”);      printf(" return退出用戶,返回登錄界

30、面n”);   printf(" exit退出程序n”);printf("*n”);    printf("please imput your command:”); gets(command);  int select;  for(i=0;commandi!=' '&commandi!=0;i+) /command_str1字符串存儲(chǔ)命令的操作類型 &

31、#160;         command_str1i=commandi; k=i;        command_str1k=0'              for(i=0;i<commandAmount;i+)    &#

32、160;               if(!strcmp(command_str1,orderi)           select=i; break;     if(i=commandAmount)      printf(&

33、quot;您輸入的命令有誤,請重新輸入n"); continue;       for(i=k+1,k=0;commandi!= '&commandi!=0;i+,k+)    /commmand_str2字符串存儲(chǔ)文件名或用戶名command_str2k=commandi; command_str2k=0;  k=i;       swit

34、ch(select)           case 0:for(i=k+1,k=0;commandi!=' ;i+,k+)   command_str3k=commandi; command_str3k=0; k=i; j=1;          length=0;   

35、   /初始化文件長度            for(i=strlen(command_str3)1;i=0;i)   /把字符串轉(zhuǎn)換為十進(jìn)制         length+=(command_str3i-48)j;  j=10; for(i=k+1,k=0;commandi!= commandi!

36、=0';i+,k+)                        command_str4k=commandi;  command_str4k='0;      fileCreate(command_str2,length,command_str4);break

37、; case 1:fileDel(command_str2);break; case 2:fileCat(command_str2);break;  case 3:fileWrite(command_str2);break;case 4:fileFine(command_str2);break;    case 5:for(i=k+1,k=0;commandi!=' commandi!=0;i+,k+)      &#

38、160;              command_str3k=commandi;  command_str3k=0';                    chmod(command_str2,command_str3);bre

39、ak;  case 6:for(i=k+1,k=0;commandi!='0;i+,k+) command_str3k=commandi;  command_str3k=0;                fileRen(command_str2,command_str3);break;  case 7:fileDir(command_st

40、r2);break; case 8:fileClose(command_str2);break;  case 9:UFD *p;       for(p=userTableuserID。usernext;p!=NULL;p=pnext)  /退出用戶之前關(guān)閉所有打的文件               

41、         if(pfile>openFlag)                            p-fileopenFlag=false; system("cls"); 

42、userID=1;break; case 10:exit(0);break; case 11:diskShow();break;          return 0;           void userCreate()          

43、;  char c;     char userName10;  int i;    if(usedMaxUser)                printf(”請輸入用戶名:");       &

44、#160;    for(i=0;c=getch();i+)             if(c=13) break; else        userNamei=c;  printf(”c”,c);         us

45、erNamei=0;for(i=0;iused;i+)                  if(!strcmp(userTablei。userName,userName)                     

46、0;printf("n”);        printf(”該用戶名已存在,創(chuàng)建用戶失敗n”);  system(”pause”);  return;                strcpy(userTableused。userName,userName);printf(”n”);  

47、          printf(”請輸入密碼:”); for(i=0;c=getch();i+)              if(c=13) break;  else            

48、0;      userTableused.passwordi=c;  printf("*”);         userTableuserID.passwordi=0; printf("n”);         printf(”創(chuàng)建用戶成功n”); used+;   

49、      system("pause”);          else              printf(”創(chuàng)建用戶失敗,用戶已達(dá)到上限n”);           

50、60;system("pause”);          fflush(stdin);         int login()            char name10,psw10;char c; int i,times; &

51、#160;      printf("請輸入用戶名:”);  for(i=0;c=getch();i+)               if(c=13) break; else              

52、; namei=c;  printf("%c",c);         namei=0;       for(i=0;iused;i+)                if(!strcmp(userTablei。userName,name)

53、   break;           if(i=used)              printf(”n您輸入的用戶名不存在n"); system(”pause");  return 1;        fo

54、r(times=0;times<3;times+)            memset(psw,0,sizeof(psw); printf("n請輸入密碼:"); for(i=0;c=getch();i+)           if(c=13) break; else   

55、       pswi=c; printf(”);      printf(”n");       for(i=0;i<used;i+)             if(!strcmp(psw,userTablei。password) 

56、               printf(”用戶登錄成功n”); system(”pause”);  break;                 if(i=used) printf("您輸入的密碼錯(cuò)誤,您還有d次輸入機(jī)會(huì)n”,2times);&#

57、160; if(times=2) exit(0);                        else break;               fflush(stdin);&

58、#160;return i;      void initDisk()            diskHead=(diskNode )malloc(sizeof(diskNode));  diskHead-maxlength=MaxDisk; diskHeaduseFlag=0; diskHead-start=0;   

59、;  diskHead-next=NULL;        int requestDist(int startPostion,int maxLength)            int flag=0;  /標(biāo)記是否分配成功   diskNode p,q,temp; &#

60、160;      p=diskHead;        while(p)                    if(p->useFlag=0&pmaxlengthmaxLength)     

61、               startPostion=pstart;               q=(diskNode )malloc(sizeof(diskNode));   qstart=p->start;   &#

62、160;            q->maxlength=maxLength;  quseFlag=1; qnext=NULL;                diskHead-start=p>start+maxLength;    &#

63、160;           diskHead-maxlength=p>maxlengthmaxLength; flag=1; temp=p;                if(diskHead-next=NULL) diskHeadnext=q;  else 

64、                       while(temp->next) temp=tempnext;   tempnext=q;               

65、60;  break;   p=pnext;                return flag;           void fileCreate(char fileName,int length,char fileKind

66、)            /int i,j;        time_t rawtime;        int startPos;        UFD *fileNode,p; 

67、0;      for(p=userTableuserID.user-next;p!=NULL;p=pnext)                    if(!strcmp(pfilefileName,fileName)          

68、                  printf(”文件重名,創(chuàng)建文件失敗n");  system("pause");  return;               if(requestDist(startPo

69、s,length))              fileNode=(UFD )malloc(sizeof(UFD);            fileNode>file=(fileTable *)malloc(sizeof(fileTable));  /這一步必不可少,因?yàn)閒ileNode里面的

70、指針也需要申請地址,否則fileNode-file指向會(huì)出錯(cuò) strcpy(fileNodefile>fileName,fileName); strcpy(fileNode-file>fileKind,fileKind);  fileNodefilemaxlength=length;  fileNode->file->strat=startPos;   fileNode->fileopenFlag=false;     tim

71、e(rawtime);      fileNode-file-timeinfo=localtime(rawtime);  fileNode->next=NULL;            if(userTableuserID.user>next=NULL)  userTableuserID.usernext=fileNode;  else 

72、0;                     p=userTableuserID.usernext; while(pnext) p=pnext;     pnext=fileNode;           &#

73、160;     printf(”創(chuàng)建文件成功n”);            system(”pause”);else                   printf(”磁盤空間已滿或所創(chuàng)建文件超出磁盤空閑容量,磁盤空間分配失敗n&quo

74、t;);  system(”pause”);            void freeDisk(int startPostion)            diskNode p;        for(p=diskHead;p!=N

75、ULL;p=pnext)                    if(pstart=startPostion)  break;        puseFlag=false;      void fileDel(char 

76、fileName)            UFD *p,*q,*temp;        q=userTableuserID。user; p=q>next;  while(p)               if(!

77、strcmp(p-file-fileName,fileName) break;  else                    p=p-next; q=q->next;                i

78、f(p)                if(p>fileopenFlag!=true)      /先判斷是否有進(jìn)程打開該文件           temp=p;         &

79、#160;      q->next=p>next;                freeDisk(temp>filestrat);  /磁盤空間回收 free(temp);     printf(”文件刪除成功n”); system(”pause”); &#

80、160;  else                printf(”該文件已被進(jìn)程打開,刪除失敗n”);    system("pause”);                else  &

81、#160;           printf(”沒有找到該文件,請檢查輸入的文件名是否正確n”);  system("pause”);                 void fileCat(char fileName)    

82、        int startPos,length; int k=0;UFD *p,q;     q=userTableuserID.user;      for(p=q->next;p!=NULL;p=pnext)            

83、 if(!strcmp(pfilefileName,fileName) break;         if(p)             startPos=pfile-strat; length=p->file>length;         p>fi

84、leopenFlag=true;    /文件打開標(biāo)記            printf("*n”);    for(int i=startPos;k<length;i+,k+)                &

85、#160;           if(i%50=0) printf(”n");  /一行大于50個(gè)字符換行  printf(”c",diski);                printf(”nn*n”);   printf(”%s已被r

86、ead進(jìn)程打開,請用close命令將其關(guān)閉n”,p->file->fileName);   system("pause”);            else              printf(”沒有找到該文件,請檢查輸入的文件名是否正確n”);  system("

87、;pause");          void fileWrite(char fileName)            UFD p,q;        q=userTableuserID。user;     &

88、#160;  int i,k,startPos;        for(p=qnext;p!=NULL;p=pnext)                    if(!strcmp(pfile->fileName,fileName)   break;&#

89、160;          if(p)               if(!strcmp(pfile>fileKind,"r")      /判斷文件類型           

90、;                 printf("該文件是只讀文件,寫入失敗n”);  system(”pause”); return;            char str500;      &

91、#160;     printf(”please input content:n”);gets(str);        startPos=p-file>strat;           p-file>openFlag=true;    /文件打開標(biāo)記 pfilelength=

92、strlen(str);            if(pfile-length>p-file>maxlength)                       printf(”寫入字符串長度大于該文件的總長度,寫入失敗n”); 

93、 system(”pause”);  return;               for(i=startPos,k=0;k(int)strlen(str);i+,k+)diski=strk;            printf(”文件寫入成功,請用close命令將該文件關(guān)閉n"); 

94、60;system(”pause”);     else            printf("沒有找到該文件,請檢查輸入的文件名是否正確n"); system(”pause");                 

95、60; void fileFine(char fileName)        UFD p,*q;        q=userTableuserID。user;        for(p=q-next;p!=NULL;p=pnext)       &

96、#160;            if(!strcmp(p>file-fileName,fileName))                break;           if(p)   &#

97、160;           printf(”*n");            printf(”文件名:%sn",pfile->fileName); printf(”文件長度:dn”,pfile-maxlength);     printf("文件在存儲(chǔ)空間的起始地址:dn

98、",p->file-strat);            printf("文件類型:%sn",pfile>fileKind);            printf(”創(chuàng)建時(shí)間:sn”,asctime(p-file>timeinfo));      &#

99、160;     printf("*n");            system("pause");          else             

100、60;printf(”沒有找到該文件,請檢查輸入的文件名是否正確n”);  system("pause”);             void chmod(char fileName,char kind)            UFD p,q;   

101、     q=userTableuserID.user;        for(p=q->next;p!=NULL;p=pnext)                if(!strcmp(p-file->fileName,fileName)  break;   

102、0;if(p)          strcpy(p-file->fileKind,kind); printf(”修改文件類型成功n”); system(”pause”);          else        printf(”沒有找到該文件,請檢查輸入的文件名是否正確n");&#

103、160;system("pause");                   void fileRen(char fileName,char name)            UFD p,*q;   

104、     q=userTableuserID。user;        for(p=qnext;p!=NULL;p=p>next)                    if(!strcmp(p->filefileName,fileName) &#

105、160; break;           if(p)                    while(q-next)              &

106、#160;    if(!strcmp(qnext>file>fileName,name))                       printf("您輸入的文件名已存在,重命名失敗n”);  system(”pause”);    return;

107、60;                  q=q->next;              strcpy(p>file-fileName,name); printf(”重命名成功n”);   system("pause”);

108、60;        else                   printf("沒有找到該文件,請檢查輸入的文件名是否正確n"); system(”pause”);           

109、        void fileDir(char userName)            UFD *p;  int i,k;     for(i=0;i<MaxUser;i+)        

110、0;           if(!strcmp(userTablei。userName,userName))             k=i;break;                 &

111、#160;          if(i=MaxUser)                    printf(”沒有找到該用戶,請檢查輸入用戶名是否正確n”); system(”pause");        &#

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(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)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論