实验三 文件系统实验
操作系统实验实验报告

操作系统实验实验报告一、实验目的操作系统是计算机系统中最为关键的核心软件,它管理着计算机的硬件资源和软件资源,为用户提供了一个方便、高效、稳定的工作环境。
本次操作系统实验的目的在于通过实际操作和实践,深入理解操作系统的基本原理和核心概念,掌握操作系统的基本功能和操作方法,提高对操作系统的认识和应用能力。
二、实验环境本次实验使用的操作系统为 Windows 10 专业版,开发工具为Visual Studio 2019,编程语言为 C 和 C++。
实验硬件环境为一台配备Intel Core i7 处理器、16GB 内存、512GB SSD 硬盘的个人计算机。
三、实验内容(一)进程管理实验1、进程创建与终止通过编程实现创建新的进程,并在完成任务后终止进程。
在实验中,我们使用了 Windows API 函数 CreateProcess 和 TerminateProcess 来完成进程的创建和终止操作。
通过观察进程的创建和终止过程,深入理解了进程的生命周期和状态转换。
2、进程同步与互斥为了实现进程之间的同步与互斥,我们使用了信号量、互斥量等同步对象。
通过编写多线程程序,模拟了多个进程对共享资源的访问,实现了对共享资源的互斥访问和同步操作。
在实验中,我们深刻体会到了进程同步与互斥的重要性,以及不正确的同步操作可能导致的死锁等问题。
(二)内存管理实验1、内存分配与释放使用 Windows API 函数 VirtualAlloc 和 VirtualFree 进行内存的分配和释放操作。
通过实验,了解了内存分配的不同方式(如堆分配、栈分配等)以及内存释放的时机和方法,掌握了内存管理的基本原理和操作技巧。
2、内存分页与分段通过编程模拟内存的分页和分段管理机制,了解了内存分页和分段的基本原理和实现方法。
在实验中,我们实现了简单的内存分页和分段算法,对内存的地址转换和页面置换等过程有了更深入的理解。
(三)文件系统实验1、文件操作使用 Windows API 函数 CreateFile、ReadFile、WriteFile 等进行文件的创建、读取和写入操作。
操作系统实验报告6

操作系统实验报告6一、实验目的本次操作系统实验的主要目的是深入了解和掌握操作系统中进程管理、内存管理、文件系统等核心概念和相关技术,通过实际操作和观察,增强对操作系统工作原理的理解,并提高解决实际问题的能力。
二、实验环境本次实验使用的操作系统为 Windows 10,实验工具包括 Visual Studio 2019 等。
三、实验内容(一)进程管理实验1、创建多个进程,并观察它们的运行状态和资源占用情况。
通过编写简单的C++程序,使用Windows API 函数创建多个进程。
在程序中,设置不同的进程优先级和执行时间,观察操作系统如何调度这些进程,以及它们对 CPU 使用率和内存的影响。
2、进程间通信实现了进程间的管道通信和消息传递。
通过创建管道,让两个进程能够相互交换数据。
同时,还使用了 Windows 的消息机制,使进程之间能够发送和接收特定的消息。
(二)内存管理实验1、内存分配与释放使用 C++的动态内存分配函数(如`malloc` 和`free`),在程序运行时动态申请和释放内存。
观察内存使用情况,了解内存碎片的产生和处理。
2、虚拟内存管理研究了 Windows 操作系统的虚拟内存机制,通过查看系统的性能监视器,观察虚拟内存的使用情况,包括页面文件的大小和读写次数。
(三)文件系统实验1、文件操作进行了文件的创建、读取、写入、删除等基本操作。
通过编写程序,对不同类型的文件(如文本文件、二进制文件)进行处理,了解文件系统的工作原理。
2、目录操作实现了目录的创建、删除、遍历等功能。
了解了目录结构在文件系统中的组织方式和管理方法。
四、实验步骤(一)进程管理实验步骤1、打开 Visual Studio 2019,创建一个新的 C++控制台项目。
2、在项目中编写代码,使用`CreateProcess` 函数创建多个进程,并设置它们的优先级和执行时间。
3、编译并运行程序,通过任务管理器观察进程的运行状态和资源占用情况。
文件系统实验报告

文件系统实验报告文件系统实验报告篇一:内核,文件系统实验报告一嵌入式系统实验报告(一) 091180083刘浩通信工程一、实验目的了解嵌入式系统的开发环境,内核的下载和启动过程;了解Linux内核源代码的目录结构及相关内容;了解Linux内核各配置选项的内容和作用;掌握Linux内核的编译过程;理解嵌入式操作系统文件系统的类型和作用;了解jffs2文件系统的优点及其在嵌入式系统中的作用;掌握busybx软件制作嵌入式文件系统的方法;掌握Linux嵌入式文件系统的挂载过程。
二、嵌入式系统开发实验1、mini和tftp(1)串口通信的硬件基础:嵌入式系统一般通过异步串行接口(UART)进行初级引导。
本实验中用到的是RS-232C标准的接口。
(2)软件结构:mini 运行mini,Ctrl+A-进入mini的cnfiguratin界面。
对串行通信接口进行配置,如串行通信口的设置,波特率、数据位等串口参数的设置。
保存好设置后以后可以不用再设置。
(3)btlader引导:给开发板加电,任意按下一个键进入btlader界面。
可以通过命令行方式进行设置,按0进入命令行模式,出现 51bard,可以设置开发板和pc机的ip地址:set myipaddr 192.168.207.113(设置开发板的ip地址),set destipaddr 192.168.207.13(设置pc机的ip地址)。
注意ip地址的设置:使其处于同一网段,并且避免和其他系统的ip发生冲突。
(4)通过btlader的主菜单可以完成很多功能,3——下载内核,4——将内核烧进flash,5——下载文件系统,6——将文件系统烧进flash,7——启动嵌入式操作系统等。
由于btlader需要从服务器上下载内核和文件系统,一般采用tftp服务。
进入/etc/xinetd.d/tftp修改配置,注意一定要关闭防火墙,否则可能导致下载时出问题。
再设置完后要重新启动tftp服务。
文件系统实验

6.1 二级目录文件系统设计6.1.1 目的和要求本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。
6.1.2 实验内容为DOS系统设计一个简单的二级文件系统。
要求做到以下几点:(1)可以实现下列几条命令LOGIN 用户登陆DIR 列文件目录CREATE 创建文件DELETE 删除文件OPEN 打开文件CLOSE 关闭文件READ 读文件WRITE 写文件(2)列目录时要列出文件名,物理地址,保护码和文件长度。
(3)源文件可以进行读写保护。
6.1.3 实验环境(1)PC兼容机(2)Windows、DOS系统(3)TC语言6.1.4 实验提示(1)首先应确定文件系统的数据结构:主目录、子目录及活动文件等。
主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。
(2)用户创建的文件,可以编号存储于磁盘上。
如:file0,file1,file2…并以编号作为物理地址,在目录中进行登记。
6.1.5 实验参考代码参考程序见下(本程序需要在c:下建一个名为osfile的目录及一个名为file的子目录):#include "stdio.h"#include "string.h"#include "conio.h"#include "stdlib.h"#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("c:\\osfile\\mfd","rb"))==NULL){fp_mfd=fopen("c:\\osfile\\mfd","wb");fclose(fp_mfd);}for(i=0;i<MAX;i++) fpaddrno[i]=0;// textattr(BLACK*16|WHITE);system("cls");// clrscr(); /*clear screen*/LoginF(); /*user login*///clrscr();system("cls");if(loginsuc==1) /*Login Successfully*/{while (1){wgetchar=0;if (choiceend==1){printf("\n\nC:\\%s>",strupr(dirname));} //strupr将所有小写字母转换成大写else printf("Bad command or file name.\nC:\\%s>",strupr(username));gets(choice);strcpy(choice,ltrim(rtrim(strlwr(choice)))); //strlwr将所有大写字母转换成小写if (strcmp(choice,"dir")==0) choice1=1;else if(strcmp(choice,"creat")==0) choice1=2;else if(strcmp(choice,"delete")==0) choice1=3;else if(strcmp(choice,"attrib")==0) choice1=4;else if(strcmp(choice,"open")==0) choice1=5;else if(strcmp(choice,"close")==0) choice1=6;else if(strcmp(choice,"read")==0) choice1=7;else if(strcmp(choice,"modify")==0) choice1=8;else if(strcmp(choice,"exit")==0) choice1=9;else if(strcmp(choice,"cls")==0) choice1=10;else if(strcmp(choice,"cd")==0) choice1=11;else if(strcmp(choice,"help")==0) choice1=20;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("\nYou have exited this system.");QuitF();exit(0);break;case 10:choiceend=1; system("cls"); /*clrscr();*/break;case 11:CdF();choiceend=1;break;case 20:help();choiceend=1;break;default:choiceend=0;}}}else printf("\nAccess denied.");}void help(void){printf("\nThe Command List\n");printf("\nCd Attrib Creat Modify Read Open Cls Delete Exit Close\n"); }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("\n\nLogin Name:");gets(loginame);ltrim(rtrim(loginame));fp_mfd=fopen("c:\\osfile\\mfd","rb");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("Login Password:");InputPW(loginpw); /*input password,use '*' replace*/if (strcmp(loginpw,logincpw)==0){strcpy(username,strupr(loginame));strcpy(dirname,username);fp_mfd=fopen("c:\\osfile\\mfd","rb");for(j=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!=0;j++){strcpy(str,"c:\\osfile\\");strcat(str,ufd_lp.ufdname); //strcat字符串连接函数ufd[j]=(OSUFD*)malloc(sizeof(OSUFD));strcpy(ufd[j]->ufdname,strupr(ufd_lp.ufdname));fp_ufd=fopen(str,"rb");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("\n\nLogin successful! Welcome to this FileSystem\n\n");loginsuc=1;return;}else{printf("\n\n");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")==0){loginsuc=0;flag=0;return;}}}}else{printf("New Password(<=8):");InputPW(loginpw); /*input new password,use '*' replace*/printf("\nConfirm Password(<=8):"); /*input new password,use '*' replace*/ InputPW(logincpw);if (strcmp(loginpw,logincpw)==0){strcpy(ufd_lp.ufdname,strupr(loginame));strcpy(ufd_lp.ufdpword,loginpw);fp_mfd=fopen("c:\\osfile\\mfd","ab");fwrite(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd);fclose(fp_mfd);strcpy(username,strupr(loginame));strcpy(dirname,loginame);strcpy(str,"c:\\osfile\\");strcat(str,username);if((fp_ufd=fopen(str,"rb"))==NULL){fp_ufd=fopen(str,"wb");fclose(fp_ufd);}fp_mfd=fopen("c:\\osfile\\mfd","rb");for(j=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!=0;j++) {strcpy(str,"c:\\osfile\\");strcat(str,ufd_lp.ufdname);ufd[j]=(OSUFD*)malloc(sizeof(OSUFD));strcpy(ufd[j]->ufdname,strupr(ufd_lp.ufdname));fp_ufd=fopen(str,"rb");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("\n\nLogin Successful! Welcome to this System\n\n");loginsuc=1;return;}else{printf("\n\n");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")==0){loginsuc=0;flag=0;return;}}}}}}void SetPANo(int RorW) /*Set physical address num,0-read,1-write*/{int i,j;if (RorW==0){if((fp_file_p=fopen("c:\\osfile\\file\\file_p","rb"))==NULL){fp_file_p=fopen("c:\\osfile\\file\\file_p","wb");fclose(fp_file_p);}fp_file_p=fopen("c:\\osfile\\file\\file_p","rb");for(i=0;fread(&j,sizeof(int),1,fp_file_p)!=0;i++)fpaddrno[j]=1;/*for(i=1;i<MAX;i++)if ((i%13)==0) fpaddrno[i]=1;*/}else{fp_file_p=fopen("c:\\osfile\\file\\file_p","wb");/*for(i=1;i<MAX;i++)if((i%13)==0) fpaddrno[i]=0;*/for(i=0;i<MAX;i++)if (fpaddrno[i]==1)fwrite(&i,sizeof(int),1,fp_file_p);}fclose(fp_file_p);}void InputPW(char *password) /*input password,use '*' replace*/{int j;for(j=0;j<=7;j++){password[j]=getch();if ((int)(password[j])!=13){if((int)(password[j])!=8)putchar('*');else{if (j>0){j--;j--;putchar('\b');putchar(' ');putchar('\b');}else j--;}}else{password[j]='\0';break;}}password[j]='\0';}void DirF() /*Dir FileSystem*/{int i,j,count=0;char sfmode[25],sfpaddr[25],str[25];int ExistD(char *dirname); /*Whether DirName Exist,Exist-i,Not Exist-0*///clrscr();system("cls");if (strcmp(strupr(ltrim(rtrim(dirname))),"")!=0){printf("\n\nC:\\%s>dir\n",dirname);printf("\n%14s%16s%14s%10s%18s\n","FileName","FileAddress","FileLength","Type","FileMode"); j=ExistD(dirname);for(i=0;i<fcount[j];i++){if ((i%16==0)&&(i!=0)){printf("\nPress any key to continue..");getch();//clrscr();system("cls");printf("\n%14s%16s%14s%10s%18s\n","FileName","FileAddress","FileLength","Type","FileMode");}itoa(ufd[j]->ufdfile[i].fpaddr,str,10);strcpy(sfpaddr,"file");strcat(sfpaddr,str);if (ufd[j]->ufdfile[i].fmode==0) strcpy(sfmode,"Read Only");else if(ufd[j]->ufdfile[i].fmode==1) strcpy(sfmode,"Write Only");else if(ufd[j]->ufdfile[i].fmode==2)strcpy(sfmode,"Read And Write");else strcpy(sfmode,"Protect");printf("%14s%16s%14d%10s%18s\n",ufd[j]->ufdfile[i].fname,sfpaddr,ufd[j]->ufdfile[i].flength," <FILE>",sfmode);}printf("\n %3d file(s)\n",fcount[j]);}else{printf("\n\nC:\\>dir\n");printf("\n%14s%18s%8s\n","DirName","OwnFileCount","Type");for(i=0;i<ucount;i++){if ((i%16==0)&&(i!=0)){printf("\nPress any key to continue...");getch();// clrscr();system("cls");printf("\n%14s%18s%8s\n","DirName","OwnFileCount","Type");}printf("%14s%18d%8s\n",ufd[i]->ufdname,fcount[i],"<UFD>");count=count+fcount[i];}printf("\n %3d dir(s),%5d file(s)\n",ucount,count);}}int ExistD(char *dirname) /*Whether DirName Exist,Exist-i,Not Exist-0*/{int i;int exist=0;for(i=0;i<ucount;i++)if (strcmp(strupr(ufd[i]->ufdname),strupr(dirname))==0){exist=1;break;}if (exist) return(i);else return(-1);}void CdF() /*Exchange Dir*/{char dname[MAXNAME];char *rtrim(char *str); /*remove the trailing blanks.*/char *ltrim(char *str); /*remove the heading blanks.*/int ExistD(char *filename); /*Whether FileName Exist,Exist-i,Not Exist-0*/printf("\nPlease input DirName (cd..-Previous dir; DirNAME-cd [DirNAME]):");gets(dname);ltrim(rtrim(dname));if (ExistD(dname)>=0) strcpy(dirname,strupr(dname));else if(strcmp(strupr(dname),"CD..")==0) strcpy(ltrim(rtrim(dirname)),"");else printf("\nError.\'%s\' does not exist.\n",dname);}void CreateF() /*Create File*/{int fpaddrno,flag=1,i;char fname[MAXNAME],str[50],str1[50],strtext[255],a[25];char fmode[25];char *rtrim(char *str); /*remove the trailing blanks.*/char *ltrim(char *str); /*remove the heading blanks.*/int FindPANo(); /*find out physical address num*/int WriteF1(); /*write file*/int ExistF(char *filename); /*Whether FileName Exist,Exist-i,Not Exist-0*/int ExistD(char *dirname);if (strcmp(strupr(dirname),strupr(username))!=0){printf("\nError. You must create file in your own dir.\n");wgetchar=1;}else{printf("\nPlease input FileName:");gets(fname);ltrim(rtrim(fname));if (ExistF(fname)>=0){printf("\nError. Name \'%s\' has already existed.\n",fname);wgetchar=1;}else{printf("Please input FileMode(0-Read Only, 1-Write Only, 2-Read and Write, 3-Protect):");gets(fmode);ltrim(rtrim(fmode));if((strcmp(fmode,"0")==0)||(strcmp(fmode,"1")==0)||(strcmp(fmode,"2")==0)||(strcmp(fmode,"3") ==0)){fpaddrno=FindPANo();if (fpaddrno>=0){i=ExistD(username);strcpy(ufd[i]->ufdfile[fcount[i]].fname,fname);ufd[i]->ufdfile[fcount[i]].fpaddr=fpaddrno;ufd[i]->ufdfile[fcount[i]].fmode=atoi(fmode);ifopen[i][fcount[i]].ifopen=0;ifopen[i][fcount[i]].openmode=4;strcpy(str,"c:\\osfile\\file\\file");itoa(fpaddrno,str1,10);strcat(str,str1);fp_file=fopen(str,"wb");fclose(fp_file);fcount[i]++;while(flag){printf("Input text now(Y/N):");gets(a);ltrim(rtrim(a));ufd[i]->ufdfile[fcount[i]-1].flength=0;if(strcmp(strupr(a),"Y")==0){fp_file=fopen(str,"wb+");ufd[i]->ufdfile[fcount[i]-1].flength=WriteF1();flag=0;}else if(strcmp(strupr(a),"N")==0){flag=0;wgetchar=1;}}printf("\n\'%s\' has been created successfully!\n",fname);}else{printf("\nFail!No Disk Space. Please format your disk.\n");wgetchar=1;} }else {printf("\nError. FileMode\'s Range is 0-3\n");wgetchar=1;} }}}int ExistF(char *filename) /*Whether FileName Exist,Exist-i,Not Exist-0*/ {int i,j;int exist=0;int ExistD(char *dirname);j=ExistD(dirname);for(i=0;i<fcount[j];i++)if (strcmp(strupr(ufd[j]->ufdfile[i].fname),strupr(filename))==0) {exist=1;break;}if (exist) return(i);else return(-1);}int FindPANo() /*find out physical address num*/{int i;for(i=0;i<MAX;i++)if (fpaddrno[i]==0) {fpaddrno[i]=1;break;}if (i<MAX) return(i);else return(-1);}int WriteF1() /*write file*/{int length=0;char c;printf("Please input text(\'#\' stands for end):\n");while((c=getchar())!='#'){fprintf(fp_file,"%c",c);if (c!='\n') length++;}fprintf(fp_file,"\n");fclose(fp_file);return(length);}void DeleteF() /*Delete File*/{char fname[MAXNAME];char str[50],str1[50];int i,j,k,flag=1;char a[25]; /*whether delete*/char *rtrim(char *str); /*remove the trailing blanks.*/char *ltrim(char *str); /*remove the heading blanks.*/int ExistF(char *filename); /*Whether FileName Exist,Exist-i,Not Exist-0*/ int ExistD(char *dirname);if (strcmp(strupr(dirname),strupr(username))!=0){printf("\nError. You can only delete file in your own dir.\n");wgetchar=1;} else{printf("\nPlease input FileName:");gets(fname);ltrim(rtrim(fname));i=ExistF(fname);if (i>=0){k=ExistD(username);if(ifopen[k][i].ifopen==1){printf("\nError. \'%s\' is in open status. Close it before delete.\n",fname);wgetchar=1;} else{while(flag){printf("\'%s\' will be deleted. Are you sure(Y/N):",fname);gets(a);ltrim(rtrim(a));if(strcmp(strupr(a),"Y")==0){fpaddrno[ufd[k]->ufdfile[i].fpaddr]=0;itoa(ufd[k]->ufdfile[i].fpaddr,str,10);for(j=i;j<fcount[k]-1;j++){strcpy(ufd[k]->ufdfile[j].fname,ufd[k]->ufdfile[j+1].fname);ufd[k]->ufdfile[j].fpaddr=ufd[k]->ufdfile[j+1].fpaddr;ufd[k]->ufdfile[j].flength=ufd[k]->ufdfile[j+1].flength;ufd[k]->ufdfile[j].fmode=ufd[k]->ufdfile[j+1].fmode;ifopen[k][j]=ifopen[k][j+1];}fcount[k]--;strcpy(str1,"c:\\osfile\\file\\file");strcat(str1,str);remove(str1);flag=0;printf("\n\'%s\' has been deleted successfully.\n",fname);wgetchar=1;}else if(strcmp(strupr(a),"N")==0){printf("\nError. \'%s\' hasn\'t been deleted.\n",fname);wgetchar=1;flag=0;}}}}else{printf("\nError. \'%s\' does not exist.\n",fname);wgetchar=1;}}}void ModifyFM() /*Modify FileMode*/{char fname[MAXNAME],str[50];int i,j,k,flag;char fmode[25]; /*whether delete*/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*/int ExistF(char *filename); /*Whether FileName Exist,Exist-i,Not Exist-0*/int ExistD(char *dirname);if (strcmp(strupr(dirname),strupr(username))!=0) {printf("\nError.You can only modify filemode in yourself dir.\n");wgetchar=1;}else{ printf("\nPlease input FileName:");gets(fname);ltrim(rtrim(fname));i=ExistF(fname);if (i>=0){k=ExistD(username);if(ifopen[k][i].ifopen==1){printf("\nError.\'%s\' is in open status. Close it before modify.\n",fname);wgetchar=1;}else{if(ufd[k]->ufdfile[i].fmode==0) strcpy(str,"read only"); /*FileMode*/else if(ufd[k]->ufdfile[i].fmode==1) strcpy(str,"write only");else if(ufd[k]->ufdfile[i].fmode==2) strcpy(str,"read and write");else strcpy(str,"Protect");printf("\'%s\' filemode is %s.\n",fname,strupr(str));printf("Modify to(0-read only,1-write only,2-read and write,3-Protect):");gets(fmode);ltrim(rtrim(fmode));if(strcmp(fmode,"0")==0){ufd[k]->ufdfile[i].fmode=0;printf("\n\'%s\' has been modified to READ ONLY mode successfully.\n",fname);wgetchar=1;}else if(strcmp(fmode,"1")==0){ufd[k]->ufdfile[i].fmode=1;printf("\n\'%s\' has been modified to WRITE ONLY mode successfully.\n",fname);wgetchar=1;}else if(strcmp(fmode,"2")==0){ufd[k]->ufdfile[i].fmode=2;printf("\n\'%s\' has been modified to READ AND WRITE mode successfully.\n",fname);wgetchar=1;}else if(strcmp(fmode,"3")==0){ufd[k]->ufdfile[i].fmode=3;printf("\n\'%s\' has been modified to FORBID mode successfully.\n",fname);wgetchar=1;}else {printf("\nError.\'%s\' is not modified.\n",fname);wgetchar=1;}}}else{printf("\nError. \'%s\' dose not exist.\n",fname);wgetchar=1;}}}void OpenF() /*Open File*/{char fname[MAXNAME];char str[25],str1[25],fmode[25];int i,k;char *rtrim(char *str); /*remove the trailing blanks.*/char *ltrim(char *str); /*remove the heading blanks.*/int ExistF(char *filename); /*Whether FileName Exist,Exist-i,Not Exist-0*/int ExistD(char *dirname);if (strcmp(strupr(ltrim(rtrim(dirname))),"")==0){printf("\nError. Please change to ufd dir before open.\n");wgetchar=1;return;}printf("\nPlease input FileName:");gets(fname);ltrim(rtrim(fname));i=ExistF(fname);if (i>=0){k=ExistD(dirname);if(!ifopen[k][i].ifopen){if (ufd[k]->ufdfile[i].fmode==3){printf("\nError. The file\'s mode is FORBID. Can not open.\n");wgetchar=1;}else{printf("Please input FileOpenMode(0-Read Only,1-Write Only,2-Read and Write):");gets(fmode);ltrim(rtrim(fmode));if((strcmp(fmode,"0")==0)||(strcmp(fmode,"1")==0)||(strcmp(fmode,"2")==0)){if(fmode[0]=='0') /*open file with read only mode*/{strcpy(str,"read only");if((ufd[k]->ufdfile[i].fmode==0)||(ufd[k]->ufdfile[i].fmode==2)) ifopen[k][i].ifopen=1;}else if(fmode[0]=='1') /*open file with write only mode*/{strcpy(str,"write only");if((ufd[k]->ufdfile[i].fmode==1)||(ufd[k]->ufdfile[i].fmode==2)) ifopen[k][i].ifopen=1;}else if(fmode[0]=='2') /*open file with read and write mode*/{strcpy(str,"read and write");if(ufd[k]->ufdfile[i].fmode==2) ifopen[k][i].ifopen=1;}if(ufd[k]->ufdfile[i].fmode==0) strcpy(str1,"read only"); /*FileMode*/else if(ufd[k]->ufdfile[i].fmode==1) strcpy(str1,"write only");else if(ufd[k]->ufdfile[i].fmode==2) strcpy(str1,"read and write");if(ifopen[k][i].ifopen==1){ifopen[k][i].openmode=atoi(fmode);if (ifopen[k][i].openmode==0) strcpy(str,"read only");else if(ifopen[k][i].openmode==1) strcpy(str,"write only");else if(ifopen[k][i].openmode==2) strcpy(str,"read and write");printf("\n\'%s\' has been opened. OpenMode is %s,FileModeis %s\n",fname,strupr(str),strupr(str1));wgetchar=1;}else{printf("\nError. \'%s\' hasn\'t been opened. OpenMode Error. OpenMode is %s,but FileMode is %s\n",fname,strupr(str),strupr(str1));wgetchar=1;}}else {printf("\nError. FileOpenMode\'s Range is 0-2\n");wgetchar=1;}}}else {printf("\nError. \'%s\' is in open status.\n",fname);wgetchar=1;}}else{printf("\nError. \'%s\' does not exist.\n",fname);wgetchar=1;}}void CloseF() /*Close File*/{int i,k,n=0;char fname[MAXNAME];char *rtrim(char *str); /*remove the trailing blanks.*/char *ltrim(char *str); /*remove the heading blanks.*/int ExistF(char *filename); /*Whether FileName Exist,Exist-i,Not Exist-0*/int ExistD(char *dirname);if (strcmp(strupr(ltrim(rtrim(dirname))),"")==0){printf("\nError. Please convert to ufd dir before close.\n");wgetchar=1;return;}k=ExistD(dirname);printf("\nOpen File(s) In This Ufd:\n");/*display openned file*/for(i=0;i<fcount[k];i++){if (ifopen[k][i].ifopen==1) {printf("%15s",ufd[k]->ufdfile[i].fname);n++;}if((n%4==0)&&(n!=0)) printf("\n");}printf("\n%d files openned.\n",n);if (n==0) wgetchar=1;if(n!=0){printf("\nPlease input FileName:");gets(fname);ltrim(rtrim(fname));i=ExistF(fname);if(i>=0){if(ifopen[k][i].ifopen==1){ifopen[k][i].ifopen=0;ifopen[k][i].openmode=4;printf("\n\'%s\' has been closed successfully.\n",fname);wgetchar=1;}else {printf("\nError.\'%s\' is in closing status.\n",fname);wgetchar=1;}}else {printf("\nError. \'%s\' is not exist.\n",fname);wgetchar=1;}}}void ReadF() /*Read File*/{int i,k,n=0;char fname[MAXNAME];char str[255],str1[255],c;char *rtrim(char *str); /*remove the trailing blanks.*/char *ltrim(char *str); /*remove the heading blanks.*/int ExistF(char *filename); /*Whether FileName Exist,Exist-i,Not Exist-0*/int ExistD(char *dirname);if (strcmp(strupr(ltrim(rtrim(dirname))),"")==0) {printf("\nError.Please convert to ufd dir before read.\n");wgetchar=1;return;}printf("\nCaution:Open file first\n");printf("Opened File(s) List:\n");k=ExistD(dirname);for(i=0;i<fcount[k];i++){if (ifopen[k][i].ifopen==1)if ((ifopen[k][i].openmode==0) ||(ifopen[k][i].openmode==2)){printf("%15s",ufd[k]->ufdfile[i].fname);n++;}if((n%4==0)&&(n!=0)) printf("\n");}printf("\n%d files openned.\n",n);if (n==0) wgetchar=1;if(n!=0){printf("\nPlease input FileName:");gets(fname);ltrim(rtrim(fname));i=ExistF(fname);if(i>=0){if(ifopen[k][i].ifopen==1){if((ifopen[k][i].openmode==0) ||(ifopen[k][i].openmode==2)){itoa(ufd[k]->ufdfile[i].fpaddr,str,10);strcpy(str1,"file");strcat(str1,str);strcpy(str,"c:\\osfile\\file\\");strcat(str,str1);fp_file=fopen(str,"rb");fseek(fp_file,0,0);printf("\nThe text is:\n\n");printf(" ");while(fscanf(fp_file,"%c",&c)!=EOF)if (c=='\n') printf("\n ");else printf("%c",c);printf("\n\n%d Length.\n",ufd[k]->ufdfile[i].flength);fclose(fp_file);wgetchar=1;}else{printf("\nError.\'%s\' has been opened with WRITE ONLY mode. It isn\'tread.\n",fname);wgetchar=1;}}else {printf("\nError.\'%s\' is in closing status. Please open it before read\n",fname);wgetchar=1;} }else {printf("\nError. \'%s\' does not exist.\n",fname);wgetchar=1;}}}void WriteF() /*Write File*/{int i,k,n=0;char fname[MAXNAME];char str[50],str1[50],a[50];char *rtrim(char *str); /*remove the trailing blanks.*/char *ltrim(char *str); /*remove the heading blanks.*/int ExistF(char *filename); /*Whether FileName Exist,Exist-i,Not Exist-0*/int ExistD(char *dirname);int WriteF1(); /*write file*/if (strcmp(strupr(ltrim(rtrim(dirname))),"")==0) {printf("\nError. Please convert to ufd dir before write.\n");wgetchar=1;return;}k=ExistD(dirname);printf("\nOpen File(s) with write only mode or read and write mode:\n");/*display openned files with writable mode*/for(i=0;i<fcount[k];i++){if (ifopen[k][i].ifopen==1)if ((ifopen[k][i].openmode==1) ||(ifopen[k][i].openmode==2)){printf("%15s",ufd[k]->ufdfile[i].fname);n++;}if((n%4==0)&&(n!=0)) printf("\n");}。
实验三 Linux操作系统安全实验 (一)

实验三Linux操作系统安全一、实验目的及要求(一)实验目的通过实验熟悉Linux环境下的用户管理、进程管理以及文件管理的相关操作命令。
掌握linux操作系统中相关的系统安全配置方法,建立linux操作系统的基本安全框架。
(二)实验要求根据实验中介绍的Linux操作系统的各项安全性实验要求,详细观察记录设置前后系统的变化,给出分析报告。
使用RPM对系统的软件进行管理,验证系统内软件的完整性,并分析结果。
试比较Linux下网了服务安全设置与Windows下安全设置异同。
二、实验环境安装Red hat9.0操作系统的计算机一台三、实验内容1、账户和口令安全2、文件系统管理安全3、查看和更改PAM模块设置4、RPM软件管理5、系统安全配置四、实验步骤任务一账户和口令安全1、查看和添加账户(1)在X_Windows窗口中单击鼠标右键,选择“信件中断”,输入下面的命令行:[root@localhost root]#useradd mylist利用useradd命令新建名为mylist的新账户。
(2)输入命令行:[root@localhost root]#cat/etc/shadow利用cat查看系统中的账户列表。
用su命令切换到新建的账户,重复步骤(2),检查shadow文件的权限设置是否安全。
设置安全时,普通用户mylist应该没有查看该系统文件的权限。
在终端中出现如下的提示:Cat:/etc/shadow:权限不够2、添加和更改密码(1)在终端输入[root@localhost root]#passwd mylist为新建账户添加密码。
注意:系统管理员无需输入原来密码即可以利用passwd命令添加或改变任意用户的密码,但普通用户只能改变自己的密码。
(2)输入后依次出现如下提示:Changjing passwd for user mylist.New passwd:Retype new passwd:Passwd:all authentication tokens updated susscessfully.输入密码,Linux系统不会将输入显示出来。
操作系统文件管理实验

操作系统实验三:文件管理一.实验目的1.加深对文件,目录,文件系统等概念的理解。
2.掌握UNIX文件系统的目录结构。
3.掌握有关UNIX文件系统操作的常用命令。
4.了解有关文件安全方面的知识。
二.实验内容1.使用pwd,cd,ls等命令浏览文件系统。
2.使用cat,cp,mv,head,tail,rm等命令查看你的文件。
3.使用ln命令进行文件的硬连接和符号连接。
4.使用find,grep命令进行文件查找和模式匹配。
5.使用chmod命令修改文件的权限。
三.实验步骤启动LINUX系统,首先以超级用户ROOT身份登录注册后(占用第一用户平台),然后以普通用户Mengqc(或其他用户名)身份登录注册后,在第二用户平台(<alt>+F2)练习文件管理有关命令.一般在[mengqc @ localhost mengqc]$提示符下键入有关命令。
1.浏览文件系统〈1〉运行pwd命令,确定你当前的工作目录(为/ home/mengqc)。
〈2〉利用以下命令显示当前工作目录的内容:(理解各字段意义。
)ls –l〈3〉运行以下命令:(反馈信息中.代表本身目录,..代表其父目录;选项a可以显示隐藏文件;选项i可以显示文件的I节点号)ls –ai〈4〉使用mkdir命令建立一个子目录subdir,并用ls查看当前目录。
下附本实验文件目录结构。
Mkdir subdir/根目录Ls –lBin dev home rootMengqc mlwjsubdirfa(file1)〈5〉使用带-d选项的ls命令,你只能看到有关子目录的信息(.表示本身目录)。
Ls -d〈6〉使用cd命令,将工作目录改到根目录(/)上。
①用相对路径将工作目录改到根目录。
Pwd 显示当前目录为 /home/mengqcCd .. 相对路径,返回上一级。
Pwd 反馈显示当前目录为 /homeCd .. 相对路径,再返回上一级。
Pwd 反馈显示当前目录为 /Cd /home/mengqc 恢复本身目录(也可以cd↙ ).Pwd 反馈显示当前目录为 /home/mengqc②用绝对路径将工作目录改到根目录。
文件系统模拟实验(C-实验教材)

文件系统实验1.1实验目的和要求1.1.1实验目的通常把文件与管理信息资源的管理程序的集合称为文件系统,它是操作系统中负责存取和管理信息资源的模块,采用统一的方法管理用户信息和系统信息的存储、检索、更新、共享和保护,并为用户提供一套行之有效的文件使用及操作方法。
本实验利用高级语言编写程序模拟文件系统,了解文件系统的基本结构和文件的各种操作方法,加深理解文件系统的内部功能及内部实现,从而帮助学生对各种文件操作命令的实质内容和执行过程有比较深入的了解。
1.1.2实验要求1.采用高级语言编写程序模拟文件系统,文件系统采用多级目录结构,实现对文件和目录的创建、删除、重命名、变更权限、显示文件内容、修改文件内容等操作。
2.撰写实验报告,报告应包含以下内容:(1)实验目的;(2)实验内容;(3)设计思路;(4)程序流程图;(5)程序中主要数据结构和函数说明;(6)带注释的源程序代码;(7)程序运行结果及分析(8)实验收获与体会1.2预备知识1.2.1文件和文件系统1.文件概念现代计算机系统中都配置了外存,大量的程序和数据以文件的形式存放在外存。
如果由用户直接管理文件,不仅要求用户熟悉外存特性,了解各种文件的属性,以及它们在外存上的位置,而且多用户环境下还必须能保持数据的安全性和一致性,这是用户不能胜任的。
因而,现代操作系统中都配备文件系统,以适应系统资源管理和用户使用信息的需要。
文件是指由创建者所定义的、具有文件名的一组相关元素的集合。
用户通过文件名就可对文件进行访问,文件名是由字母或数字组成的字母或数字串,其格式和长度都因系统而异。
操作系统提供文件系统的优点有:(1)便于用户使用。
(2)文件安全可靠。
(3)系统能有效利用存储空间,优化安排不同属主文件的位置。
(4)文件系统还能提供文件共享功能。
2.文件命名在不同的操作系统中对文件名的规定有所不同,文件名的格式和长度因系统而异。
一般来说,文件名由文件名和扩展名两部分组成,前者用于标识文件,后者用于区分文件类型,中间用“.”分割开来,它们都是字母或数字所组成的字母数字串。
文件系统 实验

实验快速文件系统一.实验目的通过对3种文件读写模式的模拟,了解快速文件系统是怎样操作的;并掌握文件读写对应的API。
二.实验要求设计三个函数int filter(char source,char*denst),其中source:源文件,即从哪个文件读。
sink:目标文件,即写到哪个文件。
分别用三种方法来实现一个对文件的操作:1)无缓冲方式:表示用的标志位是FILE_FLAG_NO_BUFFERING。
2)缓冲方式:表示用的标志位是FILE_FLAG_SEQUENTIAL_SCAN。
3)异步方式:表示用的标志位是FILE_FLAG_OVERLAPPED。
filter函数的作用是从源文件中读数据,将数据写入denst文件中去。
通过记录各种操作模式的读写时间,分析其结果。
三.背景知识正如我们所知道的:CPU运算速度最快,外部设备最慢。
如果CPU的每次操作都必须等待外设完成,那么CPU宝贵的运行时间就会大大浪费。
下面就介绍两种Windows 2000中解决这个不匹配问题的方法:高速缓存和异步传输。
1.文件高速缓存文件高速缓存是CPU访问外设的一个“中间设备”。
说是设备,其实它不是真正的物理“设备”,而是一种核心级内存映像机制。
由于它被设置在内存中,因此速度非常快,可以部分解决CPU与硬盘速度差异的问题。
文件高速缓存的原理:进程顺序读取:读了文件的第一个字节,读第二个、一直到读出所有的字节。
利用这个原理可以进行“预取”,也就是说,在进程没请求读磁盘之前就先把文件读出来并放到高速缓存中。
在第一次读入后,将文件数据保存在高速缓存中。
这样,下次再读时就不必再从硬盘而可以从缓存中读取。
LRU(LeastRecently Used,最近最少使用)的原则,可以将不常使用的文件从缓存中删除以节省高速缓存空间。
文件高速缓存“事后写”机制:进程写磁盘——写的内容交给高速缓存——寻找CPU空闲的时间写到磁盘上要写磁盘的进程就可以不必等待磁盘写完毕以后再继续工作,这也就节省了整个进程的执行时间。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实验三文件系统实验
一.目的要求
1. 用高级语言编写和调试一个简单的文件系统,模拟文件管理的工作过程。
从而对各种文件操作命令的实质内容和执行过程有比较深入的了解。
2. 要求设计一个n个用户的文件系统,每次用户可保存m个文件,用户在一次运行中只能打开一个文件,对文件必须设置保护措施,且至少有Create、delete、open、close、read、write等命令。
二.例题:
●设计一个10个用户的文件系统,每次用户可保存10个文件,一次运行
用户可以打开5个文件。
●程序采用二级文件目录(即设置主目录[MFD])和用户文件目录(UED)。
另外,为打开文件设置了运行文件目录(AFD)。
●为了便于实现,对文件的读写作了简化,在执行读写命令时,只需改读
写指针,并不进行实际的读写操作
●算法与框图:
1.因系统小,文件目录的检索使用了简单的线性搜索。
2.文件保护简单使用了三位保护码:允许读写执行、对应位为1,对应位
为0,则表示不允许读写、执行。
3.程序中使用的主要设计结构如下:
●主文件目录和用户文件目录(MFD、UFD)
●打开文件目录(AFD)(即运行文件目录)
MDF:
(1)用户名
(2)文件目录指针
(3)用户名
(4)文件目录指针
UFD
(1)文件名
(2)保护码
(3)文件长度
(4)文件名
AFD
(1)打开文件名
(2)打开保护码
(3)读写指针
文件系统算法的流程图如下:
三.实验题:
1.增加2~3个文件操作命令,并加以实现。
(如移动读写指针,改变文件属性,
更换文件名,改变文件保护级别)。
2.编一个通过屏幕选择命令的文件管理系统,每屏要为用户提供足够的选择信
息,不需要打入冗长的命令。
3.设计一个树型目录结构的文件系统,其根目录为root,各分支可以是目录,
也可以是文件,最后的叶子都是文件。
4.根据学校各级机构,编制一文件系统。