1、 OSFILE;typedef struct /*the structure of OSUFD*/ char ufdnameMAXNAME; /*ufd name*/ OSFILE ufdfileMAXCHILD; /*ufd own file*/ OSUFD;typedef struct /*the structure of OSUFDLOGIN*/ char ufdpword8; /*ufd password*/ OSUFD_LOGIN;typedef struct /*file open mode*/ int ifopen; /*ifopen:0-close,1-open*/ int o
2、penmode; /*0-read only,1-write only,2-read and write,3-initial*/ OSUFD_OPENMODE;OSUFD *ufdMAXCHILD; /*ufd and ufd own files*/OSUFD_LOGIN ufd_lp;int ucount=0; /*the count of mfds ufds*/int fcountMAXCHILD; /*the count of ufds files*/int loginsuc=0; /*whether login successfully*/char usernameMAXNAME; /
3、*record login users name22*/char dirnameMAXNAME;/*record current directory*/int fpaddrnoMAX; /*record file physical address num*/OSUFD_OPENMODE ifopenMAXCHILDMAXCHILD; /*record file open/close*/int wgetchar; /*whether getchar()*/FILE *fp_mfd,*fp_ufd,*fp_file_p,*fp_file;void main()int i,j,choice1; ch
4、ar choice50; /*choice operation:dir,create,delete,open,delete,modify,read,write*/ int choiceend=1; /*whether choice end*/ char *rtrim(char *str); /*remove the trailing blanks.*/ char *ltrim(char *str); /*remove the heading blanks.*/ void LoginF(); /*LOGIN FileSystem*/ void DirF(); /*Dir FileSystem*/
5、 void CdF(); /*Change Dir*/ void CreateF(); /*Create File*/ void DeleteF(); /*Delete File*/ void ModifyFM(); /*Modify FileMode*/ void OpenF(); /*Open File*/ void CloseF(); /*Close File*/ void ReadF(); /*Read File*/ void WriteF(); /*Write File*/ void QuitF(); /*Quit FileSystem*/ void help(); if(fp_mf
6、d=fopen(c:osfilemfd,rb)=NULL) fp_mfd=fopen(wb); fclose(fp_mfd); for(i=0;i,strupr(dirname); else printf(Bad command or file name.nC:,strupr(username); gets(choice); strcpy(choice,ltrim(rtrim(strlwr(choice); if (strcmp(choice,dir)=0) choice1=1; else if(strcmp(choice,creat)=0) choice1=2;delete)=0) choi
7、ce1=3;attrib)=0) choice1=4;open)=0) choice1=5;close)=0) choice1=6;read)=0) choice1=7;modify)=0) choice1=8;exit)=0) choice1=9;cls)=0) choice1=10;cd)=0) choice1=11;help)=0) choice1=20; else choice1=12; switch(choice1) case 1:DirF();choiceend=1;break; case 2:CreateF();if(!wgetchar) getchar(); case 3:De
8、leteF();wgetchar)getchar(); case 4:ModifyFM(); case 5:OpenF();if (! case 6:CloseF(); case 7:ReadF(); case 8:WriteF(); case 9:printf(nYou have exited this system. QuitF();exit(0); case 10:clrscr(); case 11:CdF(); case 20:help(); default:choiceend=0;else printf(nAccess denied.void help(void)nThe Comma
9、nd ListnnCd Attrib Creat Modify Read Open Cls Delete Exit Closenchar *rtrim(char *str) /*remove the trailing blanks.*/int n=strlen(str)-1; while(n=0) if(*(str+n)!= ) *(str+n+1)=0; break; else n-; if (nufdname,strupr(ufd_lp.ufdname); fp_ufd=fopen(str, fcountj=0; for(i=0;ufdj-ufdfilei,sizeof(OSFILE),1
10、,fp_ufd)!i+,fcountj+) ifopenji.ifopen=0; ifopenji.openmode=4; fclose(fp_ufd); ucount=j; SetPANo(0);nnLogin successful! Welcome to this FileSystemnn loginsuc=1; return; elsenn flag=1; while(flag)Login Failed! Password Error. Try Again(Y/N): gets(a); ltrim(rtrim(a); if (strcmp(strupr(a),Y)=0) loginsuc
11、=0;flag=0; else if(strcmp(strupr(a),N)=0)loginsuc=0;return;New Password(=8): /*input new password,use nConfirm Password( InputPW(logincpw); strcpy(ufd_lp.ufdname,strupr(loginame); strcpy(ufd_lp.ufdpword,loginpw);ab fwrite(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd); strcpy(username,strupr(loginame); strcp
12、y(dirname,loginame); strcpy(str, strcat(str,username); if(fp_ufd=fopen(str, fp_ufd=fopen(str, SetPANo(0);nnLogin Successful! Welcome to this Systemnnvoid SetPANo(int RorW) /*Set physical address num,0-read,1-write*/int i,j; if (RorW=0) if(fp_file_p=fopen(osfilefilefile_p fp_file_p=fopen( fclose(fp_f
13、ile_p); fp_file_p=fopen(j,sizeof(int),1,fp_file_p)! fpaddrnoj=1; /*for(i=1; if (i%13)=0) fpaddrnoi=1; if(i%13)=0) fpaddrnoi=0; if (fpaddrnoi=1) fwrite(&i,sizeof(int),1,fp_file_p);void InputPW(char *password) /*input password,use int j;j0) j-;j-;bputchar( else j-; passwordj= passwordj=void DirF() /*D
14、ir FileSystem*/int i,j,count=0; char sfmode25,sfpaddr25,str25; int ExistD(char *dirname); /*Whether DirName Exist,Exist-i,Not Exist-0*/ if (strcmp(strupr(ltrim(rtrim(dirname),)!dirn,dirname);n%14s%16s%14s%10s%18snFileNameFileAddressFileLengthTypeFileMode j=ExistD(dirname);fcountj; if (i%16=0)&(i!=0)
15、nPress any key to continue. getch(); itoa(ufdj-ufdfilei.fpaddr,str,10); strcpy(sfpaddr,file strcat(sfpaddr,str); if (ufdj-ufdfilei.fmode=0) strcpy(sfmode,Read Only else if(ufdj-ufdfilei.fmode=1) strcpy(sfmode,Write Onlyufdfilei.fmode=2)strcpy(sfmode,Read And Write else strcpy(sfmode,Protect%14s%16s%14d%10s%18sn,ufdj-ufdfilei.fname,sfpaddr,ufdj-ufdfilei
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1