文件管理系統(tǒng)源代碼_第1頁(yè)
文件管理系統(tǒng)源代碼_第2頁(yè)
文件管理系統(tǒng)源代碼_第3頁(yè)
文件管理系統(tǒng)源代碼_第4頁(yè)
文件管理系統(tǒng)源代碼_第5頁(yè)
已閱讀5頁(yè),還剩18頁(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、文件管理系統(tǒng)源代碼文件管理系統(tǒng)一、實(shí)驗(yàn)?zāi)康耐ㄟ^(guò)設(shè)計(jì)一個(gè)多用戶文件系統(tǒng), 了解操作系統(tǒng)中文件的組織與管理, 熟悉文件管理所用 的數(shù)據(jù)結(jié)構(gòu),加深對(duì)文件系統(tǒng)內(nèi)部功能實(shí)現(xiàn)過(guò)程的理解。二、實(shí)驗(yàn)內(nèi)容1用 C 語(yǔ)言或 C+ 語(yǔ)言設(shè)計(jì)一個(gè)最多包括 N 個(gè)用戶的多用戶文件系統(tǒng), 約定每個(gè)用戶 最多保存 M 個(gè)文件。同時(shí)限制一個(gè)用戶在進(jìn)入系統(tǒng)后,最多打開(kāi) L 個(gè)文件。2系統(tǒng)應(yīng)具備一定的健壯性。即能夠檢查用戶所輸入命令的正確性,出錯(cuò)時(shí)顯示出必 要的信息。另外,對(duì)文件需設(shè)置必要的保護(hù)措施。3文件目錄結(jié)構(gòu)采用兩級(jí)目錄結(jié)構(gòu) : 主文件目錄和用戶文件目錄/* 用戶數(shù) */* 一個(gè)用戶可保存 M 個(gè)文件 */ /*用戶只能一

2、次打開(kāi) L 個(gè)文件 */ /* 主文件目錄 */#includeio.h #includeconio.h #includestdio.h #includestdlib.h #includemalloc.h #includestring.h #includectype.h #define N 30 #define M 20 #define L 5 typedef struct MFD char username100;char password100;FILE fp;/*文件指針 */MFD;/typedef struct UFD /* 用戶文件目錄 */ char filename256;ch

3、ar protect;/* 保護(hù)碼 */int length;/* 文件長(zhǎng)度 */ UFD;/* 打開(kāi)文件目錄 */ typedef struct OFDchar filename256;char opencode; /* 打開(kāi)保護(hù)碼 */ int fp; /* 讀寫(xiě)指針 */OFD;/ typedef struct COMM /* 命令串 */char string256; /* 命令 */struct COMM *next;/* 后繼指針 */ COMM;/* 主文件目錄數(shù)組 */* 用戶文件目錄數(shù)組 */* 打開(kāi)文件目錄數(shù)組 */* 命令串指針 */MFD mainfdN;UFD use

4、rfdM;OFD openfdL;/ COMM*command; char username10;int usernum,savenum,opennum; int workfile;void init();void init_ufd(char *username);/* void mesg(char *str);char *getpass();char *getuser();COMM *readcommand();void login();void logout();void setpass();void create();void mydelete();void myread();void

5、myopen();void myclose();void mywrite();void help();void dir();void mycopy();void myrename();/初始化用戶文件目錄 */ /*消息 */* 設(shè)置口令函數(shù)聲明 */* 設(shè)置用戶函數(shù)聲明 */* 讀命令串函數(shù)聲明 */* 用戶登錄 */* 用戶注銷 */* 設(shè)置口令 */* 創(chuàng)建文件 */* 刪除文件 */* 讀文件 */* 打開(kāi)文件 */* 關(guān)閉文件 */* 寫(xiě)文件 */*幫助 */* 列文件目錄 */* 復(fù)制文件 */* 重命名文件名 */void main()init();for(;)readcomma

6、nd();if(strcmp(command-string,create)=0)create();else if(strcmp(command-string,delete)=0)文件管理系統(tǒng)源代碼文件管理系統(tǒng)源代碼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)

7、=0) mywrite();else if(strcmp(command-string,copy)=0) mycopy();else if(strcmp(command-string,rename)=0) myrename();else if(strcmp(command-string,login)=0) login();else if(strcmp(command-string,setpass)=0) setpass();else if(strcmp(command-string,logout)=0) logout();else if(strcmp(command-string,help)=

8、0) help();else if(strcmp(command-string,dir)=0) dir();else if(strcmp(command-string,exit)=0) break;elsemesg(Bad command!);/void init()FILE *fp;char tempname20,temppass20;int i=0;usernum=0;savenum=0;opennum=0;strcpy(username,); if(fp=fopen(mainfile.txt,r)!=NULL) while(!feof(fp)strcpy(tempname,);fgets

9、(tempname,20,fp);if(strcmp(tempname,)!=0)fgets(temppass,20,fp); tempnamestrlen(tempname)-1=0; temppassstrlen(tempname)-1=0; strcpy(mainfdusernum.username,tempname); strcpy(mainfdusernum.password,tempname); usernum+;fclose(fp);/void init_ufd(char *username)/* 初始化用戶文件目錄 */FILE *fp;char tempfile100,tem

10、pprot;int templength;savenum=0;opennum=0;workfile=-1;if(fp=fopen(username,w+)!=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); userfdsavenum.

11、protect=tempprot; userfdsavenum.length=templength; savenum+;fgets(tempfile,50,fp);文件管理系統(tǒng)源代碼fclose(fp);/void mesg(char *str)printf(n %sn,str);/char *getuser()char username20;char temp;int i;username0=0;for(i=0;i10;)while(!kbhit();temp=getch();if(isalnum(temp)|temp=_|temp=13) usernamei=temp; if(userna

12、mei=13)usernamei=0; break;putchar(temp);i+;usernamei=0;return(username);/char *getpass()char password20;char temp;int i;password0=0;for(i=0;i);gets(line);for(i=0;i0)tempend=0;newp=(COMM *)malloc(sizeof(COMM *);文件管理系統(tǒng)源代碼strcpy(newp-string,temp);newp-next=NULL;if(command=NULL) command=newp;elsep=comma

13、nd;while(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(tempn

14、ame,command-next-string);for(i=0;i=usernum)/* 新用戶 */printf(n new user account,enter your password twice!); printf(n Password:);strcpy(password,getpass();/* 輸入口令且返回之 */ printf(n Password:);strcpy(confirm,getpass(); /* 第二次輸入口令 */ if(strcmp(password,confirm)=0)/* 用戶數(shù)不能超過(guò) N*/ if(usernum=N)mesg(Create ne

15、w account false!number of user asscount limited.n login fasle!);elsestrcpy(mainfdusernum.username,tempname);/* 把新用戶和口令填入 mainfd 中 */strcpy(mainfdusernum.password,password); usernum+;strcpy(username,tempname);mesg(Create a new user!n login success!);init_ufd(username);/* 初始化用戶文件目錄 */fp=fopen(mainfile

16、.txt,w+);/* 把新用戶填入 mainfile.txt 文件中 */for(i=0;inext!=NULL)mesg(Too many parameters!);else if(strcmp(username,)=0)mesg(No user login!);else strcpy(username,); opennum=0; savenum=0; workfile=-1; mesg(User logout!);/void setpass() /* 修改口令 */int i=0;FILE *fp;char oldpass20,newpass20,confirm20; if(strcmp

17、(username,)=0) mesg(No user login!);else printf(n Old password:); strcpy(oldpass,getpass(); for(int i=0;iusernum;i+) if(strcmp(mainfdi.username,username)=0) break; if(strcmp(mainfdi.password,oldpass)!=0) mesg(Old password error!);elseprintf(n New password:); strcpy(newpass,getpass(); printf(n Confir

18、m password:);文件管理系統(tǒng)源代碼strcpy(confirm,getpass(); if(strcmp(newpass,confirm)!=0)mesg(Password not change! confirm different.);else strcpy(mainfdi.password,newpass); mesg( Password change !);fp=fopen(mainfile.txt,w+); for(i=0;inext=NULL) mesg(Too few parametets!);else if(command-next-next!=NULL)mesg(To

19、o many parameters!);elsefor(i=0;inext-string)=0) break;if(i=M)mesg(Error! connot create file! number of files limited!); else文件管理系統(tǒng)源代碼strcpy(userfdsavenum.filename,command-next-string); tect=r;userfdi.length=rand();savenum+; mesg(Create file success!); fp=fopen(username,w+); for(i=0;inext

20、=NULL) mesg(Too few parametets!);else if(command-next-next!=NULL) mesg(Too many parameters!);else for(i=0;inext-string)=0) break;if(i=savenum)mesg(Error! the file not existed!); else tempsave=i; for(i=0;inext-string,openfdi.filename)=0) break; if(i=opennum) mesg(File not open);/else if(tempsave=save

21、num-1) savenum-;else for(;tempsavesavenum-1;tempsave+) strcpy(userfdtempsave.filename,userfdtempsave+1.filename); tect=userfdtempsave+1.protect; userfdtempsave.length=userfdtempsave+1.length;savenum-; mesg(Delete file success!); fp=fopen(username,w+);for(i=0;inext=NULL)mesg(Too few

22、 parametets!);else if(command-next-next!=NULL)mesg(Too many parameters!);elsestrcpy(tempfile,command-next-string); for(i=0;i=savenum) mesg(File not existed!);elsetempsave=i;for(i=0;i=opennum) mesg(File not opened);else if(userfdtempsave.lengthnext=NULL)mesg(Too few parameters!);文件管理系統(tǒng)源代碼elsestrcpy(t

23、empfile,);tempcode=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 p

24、arameters!);elsestrcpy(tempfile,command-next-string);if(type=1)if(command-next-next!=NULL)if(command-next-next-next!=NULL) mesg(Too many parameters!);else strcpy(tempfile,command-next-next-string);elsemesg(Too few parameters!);if(strcmp(tempfile,)for(i=0;i=savenum)mesg(File not existed!);elsefor(i=0

25、;iopennum;i+)if(strcmp(tempfile,openfdi.filename)=0)break;if(i=L)mesg(Error! connot open file! number of opened files limited!);else strcpy(openfdopennum.filename,tempfile); openfdopennum.opencode=tempcode; workfile=opennum;opennum+;mesg(File open success!);/void myclose()/* 關(guān)閉 */int i=0;int tempsav

26、e=0;char tempfile100;if(strcmp(username,)=0)mesg(No user lgoin!);else if(command-next=NULL)mesg(Too few parametets!);else if(command-next-next!=NULL)mesg(Too many parameters!);else strcpy(tempfile,command-next-string); for(i=0;i=savenum) mesg(File not existed!);elsefor(i=0;i=opennum) mesg(File not o

27、pened);elseif(i=opennum-1) opennum-;else for(;inext=NULL) mesg(Too few parametets!);else if(command-next-next!=NULL) mesg(Too many parameters!);else strcpy(tempfile,command-next-string);for(i=0;i=savenum) mesg(File not existed!);elsetempsave=i;for(i=0;i=opennum) mesg(File not opened);elsemesg(File w

28、rite);int tt=rand();if(userfdtempsave.length=1000)printf(n The file size from %d KB to %d KB,userfdtempsave.length,userfdtempsave.length+tt);/* else if(userfdtempsave.lenght=1000)printf(n The file size from 1000 KB);*/ elseprintf(n The file size form %d,%d KB to %d,%d KB,userfdtempsave.length/1000,u

29、serfdtempsave.length%1000,userfdtempsave.length+tt/10 00,userfdtempsave.length+tt%1000);userfdtempsave.length=userfdtempsave.length+tt;文件管理系統(tǒng)源代碼/void help()/* 幫助 */static char *cmd=login,setpass,logout,create, open,read,write,close,delete,dir, help,exit,copy,rename;static char *cmdhlp=aommand format

30、: login ,command format:setpass,command format:logout,command format:create ,command format:open /r/w/d ,command format:read ,command format:write ,command format:close ,command format:delete ,command format:dir /u/o/f,command format:help ,command format:exit,command format:copy ,command format:rena

31、me ;static char *detail=explain:user login in the file system.,explain:modify the user password.,explain:user logout the file system.,explain:creat a new file.,explain:/r - read only deflautnt/w - list opened files nt/d -read,modify and delete.,explain:read the file.,explain:modify the file.,explain

32、:close the file.,explain:delete the file.,explain:/u - list the user accountnt/0 - list opened filesnt/f -list user filedeflaut.,explain: - list the command detail format and explain.nt deflaut list the command.,explain:exit from the file sysytem.,explain:copy from one file to another file.,explain:

33、modify the file name.;int helpnum=14;int i=0;if(command-next=NULL)mesg(cmdhlp10);mesg(detail10);mesg(step 1: login);printf(t if old user then login,if user not exist then create new user);mesg(step 2: open the file for read(/r),write(/w)or delete(/d);printf(t you can open one or more files.one comma

34、nd can open one file); mesg(step 3: read,write or delete some one file);printf(t you can operate one of the opened files.one command can open one file); mesg(step 4: close the open file);printf(t you can close one of the opened files.one command can open one file); mesg(step 5: user logout.close all

35、 the user opened files);printf(n command list:);for(i=0;inext-next!=NULL)mesg(Too many parameters!);elsefor(i=0;inext-string,cmdi)=0) break;if(i=helpnum)mesg(the command not existed!);elsemesg(cmdhlpi); mesg(detaili);/void dir()/* 列目錄文件 */int i=0;int type=0;char tempcode;if(strcmp(username,)=0)mesg(

36、No user login!);elseif(command-next=NULL)tempcode=f;else if(strcmp(command-next-string,/u)=0) tempcode=u;else if(strcmp(command-next-string,/o)=0)tempcode=o;else if(strcmp(command-next-string,/f)=0)tempcode=f;else if(command-next-string0=/) mesg(Error! /u/o/f request!);else if(command-next-next!=NUL

37、L) mesg(Too many parameters!);if(u=tempcode)printf(list the user accountn); printf(usenamen);for(i=0;iusernum;i+) printf(%sn,mainfdi.username);else if(f=tempcode)printf(list opened filesn); printf(filename length protectn); for(i=0;isavenum;i+) printf(%s%s%d%s%s%cn,userfdi.filename, ,userfdi.length,

38、KB, ,tect);else if(o=tempcode)printf(list user filesn);printf(filename opencoden); for(i=0;inext=NULL)mesg(Too few parametets!);else if(command-next-next=NULL)mesg(Too few parametets!);else if(command-next-next-next!=NULL)mesg(Too many parameters!);elsestrcpy(sourfile,command-next-string)

39、; strcpy(destfile,command-next-next-string); for(i=0;i=savenum)printf(n the source file not eixsted!);else for(i=0;i=opennum)printf(n the source file not opened!);elsefor(j=0;jopennum;j+)if(strcmp(destfile,openfdi.filename)=0)break;if(jopennum)mesg(Error! the destination file opened,you must close it f

溫馨提示

  • 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ù)網(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)論