教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 政务民生 >

操作系统2014课程设计(4)

来源:网络收集 时间:2026-07-24
导读: default: printf(\ break; } } else break; } printf(\ printf(\ } 2.文件系统 参考程序见下(本程序需要在c:下建一个名为osfile的目录及一个名为file的子目录): #include \#include \#include \#include \ #def

default: printf(\ break; } }

else break; }

printf(\ printf(\ }

2.文件系统

参考程序见下(本程序需要在c:下建一个名为osfile的目录及一个名为file的子目录):

#include \#include \#include \#include \

#define MAXNAME 25 /*the largest length of mfdname,ufdname,filename*/ #define MAXCHILD 50 /*the largest child*/

#define MAX (MAXCHILD*MAXCHILD) /*the size of fpaddrno*/

typedef struct /*the structure of OSFILE*/

{int fpaddr; /*file physical address*/ int flength; /*file length*/

int fmode; /*file mode:0-Read Only;1-Write Only;2-Read and Write(default);*/ char fname[MAXNAME]; /*file name*/ } OSFILE;

typedef struct /*the structure of OSUFD*/ {char ufdname[MAXNAME]; /*ufd name*/ OSFILE ufdfile[MAXCHILD]; /*ufd own file*/ }OSUFD;

typedef struct /*the structure of OSUFD'LOGIN*/ {char ufdname[MAXNAME]; /*ufd name*/ char ufdpword[8]; /*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 *ufd[MAXCHILD]; /*ufd and ufd own files*/ OSUFD_LOGIN ufd_lp;

int ucount=0; /*the count of mfd's ufds*/

int fcount[MAXCHILD]; /*the count of ufd's files*/ int loginsuc=0; /*whether login successfully*/

char username[MAXNAME]; /*record login user's name22*/ char dirname[MAXNAME];/*record current directory*/ int fpaddrno[MAX]; /*record file physical address num*/

OSUFD_OPENMODE ifopen[MAXCHILD][MAXCHILD]; /*record file open/close*/ int wgetchar; /*whether getchar()*/

FILE *fp_mfd,*fp_ufd,*fp_file_p,*fp_file;

void main() {int i,j,choice1;

char choice[50]; /*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*/ 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_mfd=fopen(\ {fp_mfd=fopen(\fclose(fp_mfd); }

for(i=0;i

textattr(BLACK*16|WHITE); clrscr(); /*clear screen*/ LoginF(); /*user login*/ clrscr();

if(loginsuc==1) /*Login Successfully*/ {while (1) {wgetchar=0; if (choiceend==1)

{printf(\

else printf(\ gets(choice);

strcpy(choice,ltrim(rtrim(strlwr(choice)))); if (strcmp(choice,\ else if(strcmp(choice,\ else if(strcmp(choice,\ else if(strcmp(choice,\ else if(strcmp(choice,\ else if(strcmp(choice,\ else if(strcmp(choice,\ else if(strcmp(choice,\ else if(strcmp(choice,\ else if(strcmp(choice,\ else if(strcmp(choice,\ else if(strcmp(choice,\ else choice1=12; switch(choice1)

{case 1:DirF();choiceend=1;break;

case 2:CreateF();choiceend=1;if(!wgetchar) getchar();break; case 3:DeleteF();choiceend=1;if(!wgetchar)getchar();break; case 4:ModifyFM();choiceend=1;if(!wgetchar) getchar();break; case 5:choiceend=1;OpenF();if (!wgetchar) getchar();break; case 6:choiceend=1;CloseF();if (!wgetchar) getchar();break; case 7:choiceend=1;ReadF();if (!wgetchar) getchar();break; case 8:choiceend=1;WriteF();if (!wgetchar) getchar();break; case 9:printf(\ QuitF();exit(0);break;

case 10:choiceend=1;clrscr();break; case 11:CdF();choiceend=1;break; case 20:help();choiceend=1;break; default:choiceend=0; } } }

else printf(\}

void help(void) {

printf(\

printf(\}

char *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 (n<0) str[0]='\\0'; return str; }

char *ltrim(char *str) /*remove the heading blanks.*/ {char *rtrim(char *str); strrev(str); rtrim(str); strrev(str); return str; }

void LoginF() /*LOGIN FileSystem*/

{char loginame[MAXNAME],loginpw[9],logincpw[9],str[50]; int i,j,flag=1; char a[25];

int findout; /*login user not exist*/

char *rtrim(char *str); /*remove the trailing blanks.*/ char *ltrim(char *str); /*remove the heading blanks.*/

void InputPW(char *password); /*input password,use '*' replace*/ void SetPANo(int RorW); /*Set physical address num*/ while(1) {findout=0;

printf(\ gets(loginame);

ltrim(rtrim(loginame));

fp_mfd=fopen(\

for(i=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!=0;i++) if (strcmp(strupr(ufd_lp.ufdname),strupr(loginame))==0) {findout=1;

strcpy(logincpw,ufd_lp.ufdpword); }

fclose(fp_mfd);

if (findout==1) /*user exist*/ {printf(\

InputPW(loginpw); /*input password,use '*' replace*/ if (strcmp(loginpw,logincpw)==0) {strcpy(username,strupr(loginame)); strcpy(dirname,username);

fp_mfd=fopen(\

for(j=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!=0;j++) {strcpy(str,\ strcat(str,ufd_lp.ufdname);

ufd[j]=(OSUFD*)malloc(sizeof(OSUFD));

strcpy(ufd[j]->ufdname,strupr(ufd_lp.ufdname)); fp_ufd=fopen(str,\ fcount[j]=0;

for(i=0;fread(&ufd[j]->ufdfile[i],sizeof(OSFILE),1,fp_ufd)!=0;i++,fcount[j]++) {ifopen[j][i].ifopen=0; ifopen[j][i].openmode=4;} fclose(fp_ufd);} fclose(fp_mfd); ucount=j; SetPANo(0);

printf(\ loginsuc=1; return;} else

{printf(\ flag=1; while(flag)

{printf(\ gets(a);

ltrim(rtrim(a));

i …… 此处隐藏:3025字,全部文档内容请下载后查看。喜欢就下载吧 ……

操作系统2014课程设计(4).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/447902.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)