操作系统2014课程设计(4)
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));
相关推荐:
- [政务民生]2013年公共基础知识热点问题(七)
- [政务民生]检验检测机构资质认定评审准则及释义20
- [政务民生]关于印发重庆市房屋建筑和市政基础设施
- [政务民生]1、隧道洞身开挖支护施工技术交底书
- [政务民生]2015年山东省17地市中考语文试题分类汇
- [政务民生]2-高级会计师资格考试和评审流程图
- [政务民生]2018版中国清分机行业发展分析及前景策
- [政务民生]新课改高中政治探究
- [政务民生]2018-2024年中国新型组合房屋行业投资
- [政务民生]2015年上海市春季高考数学模拟试卷五
- [政务民生]灌砂法及环刀法测压实度(带计算过程)
- [政务民生]运筹学实验2求解非线性规划
- [政务民生]劝学、逍遥游默写(教师卷)
- [政务民生]《运筹学》 - 期末考试 - 试卷A - 答案
- [政务民生]八年级英语下册 Module 6 Hobbies测试
- [政务民生]2019年宪法知识竞赛试题库100题(含答
- [政务民生]自动化英文文献翻译
- [政务民生]公文格式实施细则
- [政务民生]高一地理上册课堂跟踪练习题6
- [政务民生]会计继续教育习题及答案
- 第三章 无约束最优化方法
- 泛读教程第三册答案
- 魏晋南北朝文学
- 幂的运算复习题
- 城市环境问题的成因与治理策略_以社会
- 钢结构行业产业链及竞争分析研究
- 新型热塑性弹性体增韧聚丙烯的研究
- 中国旅游地理B卷试题及答案
- (苏教版)五年级数学上册第三单元测试卷
- 不稳定性心绞痛诊断与治疗
- 俞氏国际后勤职能部门绩效考核办法
- GB7258-2017新标准考试题含答案
- 小学生汉字听写比赛活动方案
- 1.3《平抛运动》学案 教科版必修2
- 2011香港特别行政区公务员考试复习资料
- 考虑水力条件变化的城市给水管网可靠性
- 表面活性剂在油田开发和生产中的应用
- ITT内部培训资料-FI端吸泵的介绍
- 文明守纪,从我做起学生发言稿
- 初中读《聊斋志异》心得体会800字范文




