1、 int fpaddr; /*file physical address*/ int flength; /*file length*/ int fmode; /*file mode:0-Read Only;1-Write Only;2-Read and Write; 3-Protect;*/ char fnameMAXNAME; /*file name*/ OSFILE;typedef struct /*the structure of OSUFD*/ char ufdnameMAXNAME; /*ufd name*/ OSFILE ufdfileMAXCHILD; /*ufd own fil
2、e*/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 openmode; /*0-read only,1-write only,2-read and write,3-initial*/OSUFD_OPENMODE;OSUFD *ufdMAXCHILD; /*ufd and ufd own files
3、*/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; /*record login users name22*/char dirnameMAXNAME;/*record current directory*/int fpaddrnoMAX; /*record file physical address
4、 num*/OSUFD_OPENMODE ifopenMAXCHILDMAXCHILD; /*record file open/close*/int wgetchar; /*whether getchar()*/FILE *fp_mfd,*fp_ufd,*fp_file_p,*fp_file;void LoginF(); /*LOGIN FileSystem*/void DirF(); /*Dir FileSystem*/void CdF(); /*Change Dir*/void CreateF(); /*Create File*/void DeleteF(); /*Delete File*
5、/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();char *rtrim(char *str); /*remove the trailing blanks.*/char *ltrim(char *str); /*remove the heading blanks
6、.*/void InputPW(char *password); /*input password,use * replace*/void SetPANo(int RorW); /*Set physical address num*/int ExistD(char *dirname); /*Whether DirName Exist,Exist-i,Not Exist-0*/int WriteF1(); /*write file*/int ExistF(char *filename); /*Whether FileName Exist,Exist-i,Not Exist-0*/int Find
7、PANo(); /*find out physical address num*/void clrscr() system(cls);int main() int i,choice1; char choice50; /*choice operation:dir,create,delete,open,delete,modify,read,write*/ int choiceend=1; /*whether choice end*/ char *rtrim(char *str); char *ltrim(char *str); if(fp_mfd=fopen(c:osfilemfd.txt,rb)
8、=NULL) fp_mfd=fopen(wb fclose(fp_mfd); for(i=0;i,strupr(dirname); elseBad command or file name.nC:,strupr(username); gets(choice); /输入所选择的 strcpy(choice,ltrim(rtrim(strlwr(choice); /将输入的值赋给choice if (strcmp(choice,dir)=0) choice1=1; /依次将输入的值与dir,create等进行比较 else if(strcmp(choice,create)=0) choice1=2
9、; /如果输入create将choice1置为2通过switch选择,以下依次类推delete)=0) choice1=3;attrib)=0) choice1=4;open)=0) choice1=5;close)=0) choice1=6;read)=0) choice1=7;write)=0) choice1=8;exit)=0) choice1=9;)=0) choice1=10;cd)=0) choice1=11;help)=0) choice1=20; else choice1=12; /choice1=12时跳转到default,然后继续循环 switch(choice1) ca
10、se 1:DirF();choiceend=1;break; case 2:CreateF();if(!wgetchar) getchar(); case 3:DeleteF();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 2
11、0:help(); default:choiceend=0; else printf(nAccess denied. /登录成功void help(void) printf(nThe Command ListnnCd Attrib Create write Read Open Cls Delete Exit Closenchar *rtrim(char *str) /*除去末尾端的空格指针指向字符串第一个*/ int n=strlen(str)-1; /n为字符串长度减1 while(n=0) if(*(str+n)!= ) /末尾不存在空格 *(str+n+1)=0; /n表示结束符 bre
12、ak; else n-; /如果存在空格将空格去掉 if (nufdname,strupr(ufd_lp.ufdname); fp_ufd=fopen(str, fcountj=0; for(i=0;ufdj-ufdfilei,sizeof(OSFILE),1,fp_ufd)!i+,fcountj+) ifopenji.ifopen=0; ifopenji.openmode=4; fclose(fp_ufd); fclose(fp_mfd); ucount=j; SetPANo(0);nnLogin successful! Welcome to this FileSystemnn logins
13、uc=1; return;nn flag=1; while(flag) printf(Login Failed! Password Error. Try Again(Y/N): gets(a); ltrim(rtrim(a); if (strcmp(strupr(a),Y)=0) loginsuc=0; flag=0; else if(strcmp(strupr(a),N return; elseNew Password(=8): /*input new password,use nConfirm Password( InputPW(logincpw); strcpy(ufd_lp.ufdna
14、me,strupr(loginame); strcpy(ufd_lp.ufdpword,loginpw);ab fwrite(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd); strcpy(dirname,loginame); / strcpy(str, strcat(str,username); strcat(str, if(fp_ufd=fopen(str, / ifopenji.openmode=4;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.txt)=NULL) /如果文件未读成功 fp_file_p=fopen( /创建该文件 fclose(fp_file_p); fp_file_p=fopen( /j,sizeof(i
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1