实验四 文件系统实验

合集下载

操作系统-第四次实验报告-文件系统

操作系统-第四次实验报告-文件系统
操作系统实验报告 文件系统
全部代码可执行
实验介绍
本实验要求在假设的I/O 系统之上开发一个简单的文件系统, 这样做既能让实验者对文 件系统有整体了解,又避免了涉及过多细节。用户通过create, open, read 等命令与文件系统 交互。文件系统把磁盘视为顺序编号的逻辑块序列,逻辑块的编号为0 至L-1。I/O 系统利 用内存中的数组模拟磁盘。 实际物理磁盘的结构是多维的:有柱面、磁道、扇区等概念。I/O 系统的任务是隐藏磁 盘的结构细节,把磁盘以逻辑块的面目呈现给文件系统。逻辑块顺序编号,编号取值范围为 0 至L -1,其中L 表示磁盘的存储块总数。实验中,我们可以利用字符数组ldisk[L][B] 构 建磁盘模型,其中B 表示每个存储块的长度。I/O 系统从文件系统接收命令,根据命令指定 的逻辑块号把磁盘块的内容读入命令指定的内存区域, 或者把命令指定的内存区域内容写入 磁盘块。内存区域内容写入磁盘块。
整体组织
注:我定义的文件系统中,磁盘分为两大部分:数据区和保留区。其中保留区中又包含位图区和文件 描述符区,数据区的首部是文件的目录项,也就是说,文件的目录项在文件创建时会创建相应的目录 项在数据区的文件首部;而位图区用于表征数据的占用情况,例如数据区的第 N 块被分配了,那么位 图区中也要做相应的改变。
struct filesign { int file_length; int filesign_flag; int file_block;
int file_block_ary[FILE_BLOCK_LENGTH]; }; struct contents { char filename[FILE_NAME_LENGTH];
文件的读 int read(int,int,int)

操作系统实验_文件系统

操作系统实验_文件系统

广州大学学生实验报告开课学院及实验室:计算机科学与工程实验室 2015 年12 月8日实验课操作系统实验成绩程名称实验项实验4 文件系统指导老师陈康民目名称一、实验目的1. 对文件管理有进一步了解2. 利用文件备份实验加深对文件管理的了解3. 熟悉fopen()、fread()、 fwrite()、fclose() 的使用二、实验内容利用函数fopen(), fread(), fwrite(), fclose() 来实现简单的文件备份,即将一个文件的内容拷贝到另一个文件中去。

三、实验原理利用函数fopen(), fread(), fwrite(), fclose() 来实现简单的文件备份四、实验设备PC(操作系统:Fedora,含GCC)五、实验要求完成利用函数fopen(), fread(), fwrite(), fclose() 来实现简单的文件备份,即将一个文件的内容拷贝到另一个文件中去。

并进行分析参考程序提供错误解决方案。

六、实验程序9.c:#include <sys/types.h>#include <stdio.h>#include <stdlib.h>int main(void){char buf; //建立缓冲区FILE *source, *backup; //设立FILE结构指针if ((source = fopen("source.dat", "r")) == NULL) //若以只读形式source.dat成功打开,则fopen()返回FILE指针source{printf("Error in opening file.\n");exit(1);}if ((backup = fopen("backup.dat", "w")) == NULL) //若以只写形式backup.dat无法打开,则创建文件不成功{printf("Error in creating file.\n");exit(1);}while (fread(&buf, sizeof(buf), 1, source) == 1) //用fread函数读取source的一个buf大小的数据到缓冲区{if (fwrite(&buf, sizeof(buf), 1, backup) == 0) //用fwrite函数把一个buf大小的缓冲区数据写入backup{//若写入错误,则打印“写入文件错误”printf("Error in wrinting file.\n");exit(1);}}if (ferror(source)) //读取文件source出现错误{printf("Error in reading file.\n");exit(1);}if (fclose(source)) //source流的关闭出现错误{printf("Error in close file.\n");exit(1);}if (fclose(backup)) //backup流的关闭出现错误{printf("Error in close file.\n");exit(1);}return 0;}9.c结果截图实验结果1:源文件source.dat内容如下:编译运行后多了个Backup.dat文件实验分析1:此方案1,用char buf;重新定义缓冲区,程序中if (!(source = fopen("source.dat", "r")))和if (!(backup = fopen("backup.dat", "w")))中的表达式虽然没有错误,但这种写法不太好,因fopen()返回的是一个地址或者空值,这样写会影响程序的可读性,同时在某些机器上可能引发错误,所以改为if ((source = fopen("source.dat", "r")) == NULL)和if ((backup = fopen("backup.dat", "w")) == NULL)。

国开 操作系统 实验4:文件管理实验

国开 操作系统 实验4:文件管理实验

实验4:文件管理实验
一、目的:
1、加深对文件、目录、文件系统等概念的理解。

2、掌握Linux 文件系统的目录结构。

3、掌握有关Linux 文件系统操作的常用命令。

4、了解有关文件安全性方面的知识。

二、条件:
需要一个Linux的环境
1、在Win10系统启用Linux子系统
2、在Win10应用商店安装Ubuntu应用
3、
三、过程:
1、浏览文件系统
用到pwd、ls、mkdir、cd命令
不带参数的cd命令,工作目录回到了用户的默认目录
cd ../.. 执行后,工作目录回到了/根目录
2、查看文件
用到data、head、tail、ls、man、date、cp、mv、rm命令
man date
建立链接后第2个字段从1变成2
3、文件查找和目录
用到了find、grep命令
4、修改文件存取权限
chmod命令
四、总结:Linux是一个多用户的现代操作系统,提供了丰富和强大的文件管理的命令。

掌握这些命令对于我们深入Linux学习是必需的。

实验四 文件管理实验

实验四  文件管理实验

实验四文件管理实验◆实验名称:文件管理实验◆仪器、设备:计算机◆参考资料:操作系统实验指导书◆实验目的:设计一个n个用户的文件系统,用户在一次运行中只能打开一个文件,有Create、delete、open、close、read、write等命令。

◆实验内容:为DOS系统设计一个简单的二级文件系统。

要求可以实现下列几条命令CREATE 创建文件DELETE 删除文件OPEN 打开文件CLOSE 关闭文件READ 读文件WRITE 写文件◆实验原理、数据(程序)记录:#define MAXNAME 25 /*the largest length of mfdname,ufdname,filename*/#define MAXCHILD 50 /*the largest child*/#define MAX (MAXCHILD*MAXCHILD) /*the size of fpaddrno*/void CreateF() /*Create File*/{int fpaddrno,flag=1,i;char fname[MAXNAME],str[50],str1[50],strtext[255],a[25];char fmode[25];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 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 beforeread\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");}printf("\n%d files open.\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==1) ||(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);if (ufd[k]->ufdfile[i].flength!=0){printf("\n\'%s\' has text. Overwrite or Append(O-overwrite,A-Append,else-not write):",fname);gets(a);ltrim(rtrim(a));if (fp_file!=NULL) fclose(fp_file);if (strcmp(strupr(a),"O")==0){printf("\nOverwrite\n");fp_file=fopen(str,"wb");ufd[k]->ufdfile[i].flength=0;ufd[k]->ufdfile[i].flength=WriteF1();}else if(strcmp(strupr(a),"A")==0){printf("\nAppend\n");fp_file=fopen(str,"ab");ufd[k]->ufdfile[i].flength=ufd[k]->ufdfile[i].flength+WriteF1();}else{printf("\nError.\'%s\' has not been written.\n",fname);fclose(fp_file);wgetchar=1;} }else{fp_file=fopen(str,"wb");ufd[k]->ufdfile[i].flength=WriteF1();}}else{printf("\nError. \'%s\' has been opened with read only mode.It isn\'twrited.\n",fname);wgetchar=1;}}else{printf("\nError. \'%s\' is in closing status. Please open it beforewrite\n",fname);wgetchar=1;}}else{printf("\nError. \'%s\' does not exist.\n",fname);wgetchar=1;}}}◆实验结果及分析通过实验实现了有Create、delete、open、close、read、write等命令的简单的文件系统。

实验四文件操作

实验四文件操作

实验四文件操作一、实验目的1.熟悉和理解文件系统的概念和文件系统的类型。

2.掌握文件系统的挂载方法。

3.学会Linux中数据备份的方法。

4.了解Linux系统中文件系统的管理机制。

二、实验内容1.挂载文件系统。

2.监视文件系统状态。

3.维护文件系统。

4.软盘的使用。

5.硬盘的使用。

6.数据备份和压缩。

7.在GNOME下管理磁盘三、实验环境1.装有Linux系统的计算机。

2.软磁盘和光盘各一张。

四、实验步骤(一)挂载文件系统1.手工挂载文件系统①用mount命令挂载文件系统。

命令格式:mount [-fnrvw] [-t type] device dir其中:-t type:指定文件系统类型;device:待安装文件系统的块设备名;dir:安装点(目录);-f: 模拟一个文件系统的挂装过程,用它可以检查一个文件系统是否可以正确挂装。

-n:挂装一个文件系统,但不在fstab文件中生成与之对应的设置项。

-v:命令进展注释,给出mount命令每个操作步骤的注释。

-r:将文件系统挂载为只读模式;-w:将文件系统挂载为读写模式。

操作:在软驱中插入一张磁盘,然后将软驱挂载为msdos文件类型。

②挂载软磁盘的命令:mount -t msdos /dev/fd0 /mnt/floppy挂载完成后,用ls命令查看软磁盘中包括的文件。

③用mount命令还可以显示所有已安装的文件系统。

命令格式:mount [-hV]2.手工卸载文件系统用umount命令卸载文件系统。

命令格式:umount [-hV]umount [-a] [-n] [-v] [-t types]其中:-h:显示帮助信息。

-V:显示版本信息。

-a:表示要卸载/etc/fstab中的所有文件系统;-n:卸除时不要将信息存入/etc/mtab文件中。

-v:执行时显示详细的信息。

-t types:指定文件系统的类型。

操作:卸载软盘的msdos文件系统。

①命令:umount -t msdos /dev/fd0卸载完成后,从软盘驱动器中取出软盘。

实验四 磁盘和文件系统管理心得

实验四 磁盘和文件系统管理心得

实验四磁盘和文件系统管理心得前言实验四主要涉及磁盘和文件系统的管理,通过对磁盘分区、文件系统格式化、文件的创建、删除和修改等操作,我们能够更好地理解和掌握磁盘和文件系统的相关概念和原理。

本文将从以下几个方面对实验四的心得进行全面、详细、完整且深入地探讨。

磁盘分区的原理与方法磁盘分区是指将一个物理硬盘分成多个逻辑区域的操作。

通过对磁盘进行合理分区,可以充分利用磁盘空间,并为不同用途的数据提供不同的存储空间。

磁盘分区有两种常见的方法:主引导记录(Master Boot Record,MBR)分区和GUID分区表(GUID Partition Table,GPT)。

MBR分区MBR分区是一种传统的分区方式,适用于BIOS引导的系统。

MBR分区表将硬盘的第一个扇区(512字节)用于存储分区表的信息,包括主引导记录、分区表项等。

MBR分区最多支持4个主分区或3个主分区加一个扩展分区。

其中,扩展分区可以进一步划分逻辑分区。

GPT分区GPT分区是一种新的分区方式,适用于UEFI引导的系统。

GPT分区通过GUID(全局唯一标识符)来标识分区,解决了MBR分区的一些限制,如只能支持最多4个主分区等。

GPT分区表存储在硬盘末尾的一个独立区域,可以容纳更多的分区信息。

文件系统的选择与格式化文件系统是操作系统用来管理和组织文件的一种方式。

常见的文件系统有FAT32、NTFS、ext4等。

在进行文件系统格式化之前,我们需要选择适合自己需求的文件系统。

FAT32文件系统FAT32是一种通用的文件系统,在各个操作系统中都能够良好地兼容。

它支持的单个文件最大为4GB,簇大小可以灵活配置。

然而,FAT32文件系统对于大容量硬盘的利用率较低,而且不支持文件权限和加密等高级功能。

NTFS文件系统NTFS是Windows操作系统中常用的文件系统,它支持大容量硬盘,单个文件最大支持16TB。

NTFS文件系统具有更高的稳定性和安全性,支持文件权限、加密和压缩等功能。

实验四 磁盘和文件系统管理心得

实验四 磁盘和文件系统管理心得

实验四磁盘和文件系统管理心得实验四磁盘和文件系统管理心得一、实验背景磁盘和文件系统管理是计算机操作系统中非常重要的一部分,它涉及到了计算机存储和数据管理的方方面面。

在本次实验中,我们主要学习了磁盘的分区、格式化以及文件系统的创建与管理等内容。

二、实验过程1. 磁盘分区在Windows操作系统中,我们可以通过“磁盘管理”来对硬盘进行分区。

首先需要在“我的电脑”中找到硬盘驱动器,右键点击选择“管理”,进入“计算机管理”界面后,在左侧的菜单栏中选择“磁盘管理”,然后就可以对硬盘进行分区操作了。

2. 磁盘格式化在将硬盘进行分区之后,我们还需要对每个分区进行格式化。

格式化可以将硬盘上的数据清空,并为其创建一个新的文件系统。

在Windows操作系统中,我们同样可以通过“磁盘管理”来进行格式化操作。

3. 文件系统创建与管理在Linux操作系统中,我们可以使用mkfs命令来创建文件系统。

例如,在Ubuntu下创建ext4文件系统时,可以使用以下命令:sudo mkfs.ext4 /dev/sdb1其中,“/dev/sdb1”表示要创建文件系统的设备名称。

除了创建文件系统之外,我们还可以使用一些命令来管理文件系统。

例如,使用mount命令可以将文件系统挂载到指定的目录下:sudo mount /dev/sdb1 /mnt此时,/dev/sdb1设备上的文件系统就会被挂载到/mnt目录下。

另外,我们还可以使用umount命令来卸载已经挂载的文件系统:sudo umount /mnt三、实验心得通过本次实验,我对磁盘和文件系统管理有了更深入的了解。

在实际应用中,我们需要根据具体情况来对磁盘进行分区和格式化,并创建适合自己的文件系统。

同时,在管理文件系统时,我们也需要注意保护数据安全,并遵循相关规范和标准。

总之,在今后的学习和工作中,我将继续深入研究磁盘和文件系统管理相关知识,并不断提升自己的技能水平。

实验四 磁盘和文件系统管理心得

实验四 磁盘和文件系统管理心得

实验四磁盘和文件系统管理心得
实验四磁盘和文件系统管理心得
在本次实验中,我们学习了磁盘和文件系统的管理。

通过实验,我对磁盘和文件系统的概念及其管理方式有了更深入的了解和体验。

首先,磁盘管理是操作系统最基本的功能之一。

磁盘是计算机存储信息的主要设备,因此,对磁盘的管理显得尤为重要。

在实验中,我了解了磁盘的分区和格式化两个重要操作。

分区可以将一个大磁盘划分为多个逻辑分区,方便对不同的数据进行管理。

而格式化则是将分区或整个磁盘进行数据擦除,以便重新存储数据。

此外,我还学习了磁盘空间的管理,包括磁盘空间的容量、使用情况等,这些都是磁盘管理的重要内容。

其次,文件系统管理也是操作系统的重要功能之一。

文件系统是指计算机用来管理文件的一组规则和程序。

在实验中,我学习和掌握了文件的基本操作,如文件的创建、删除、拷贝和移动等。

同时,我还学习了文件系统的组成和结构,包括目录、文件描述符和索引节点等。

这些知识对文件系统的管理非常有帮助。

总之,通过本次实验,我深入了解了磁盘和文件系统的管理方式,掌握了它们的基本操作和原理,并且实践了相关操作。

这些知识对我今
后的计算机学习和工作都将有帮助。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验四文件系统实验一 . 目的要求1、用高级语言编写和调试一个简单的文件系统,模拟文件管理的工作过程。

从而对各种文件操作命令的实质内容和执行过程有比较深入的了解。

2、要求设计一个 n个用户的文件系统,每次用户可保存m个文件,用户在一次运行中只能打开一个文件,对文件必须设置保护措施,且至少有Create、delete、open、close、read、write等命令。

二 . 例题:1、设计一个10个用户的文件系统,每次用户可保存10个文件,一次运行用户可以打开5个文件。

2、程序采用二级文件目录(即设置主目录[MFD])和用户文件目录(UED)。

另外,为打开文件设置了运行文件目录(AFD)。

3、为了便于实现,对文件的读写作了简化,在执行读写命令时,只需改读写指针,并不进行实际的读写操作。

4、算法与框图:①因系统小,文件目录的检索使用了简单的线性搜索。

②文件保护简单使用了三位保护码:允许读写执行、对应位为 1,对应位为0,则表示不允许读写、执行。

③程序中使用的主要设计结构如下:主文件目录和用户文件目录( MFD、UFD)打开文件目录( AFD)(即运行文件目录)文件系统算法的流程图如下:三 . 实验题:1、增加 2~3个文件操作命令,并加以实现。

(如移动读写指针,改变文件属性,更换文件名,改变文件保护级别)。

#include <stdio.h>#include <stdlib.h>#include <string.h>#define getpch(type) (type*)malloc(sizeof(type))int userNum=0;struct mdf{char userName[20];struct UFD* p;} mdf[20];struct ufd{char fileName[20];char File[50];struct ufd * next;}*fp,*tp,*p,*begin;typedef struct ufd UFD ;void show(struct UFD *f){begin=f;if(begin->next==NULL) printf("该用户名下尚无文件!\n");else{printf("该用户名下所有文件:\n");begin=begin->next;while(begin!=NULL){printf("%s: %s\n",begin->fileName,begin->File);begin=begin->next;}}}void Operation(struct UFD *f){int i;char filename[20],file[50];begin=f;label:printf("请选择操作:\n 1:create; 2:delete; 3:read; 4:write; 5:open;\n 6:lose; 7:Chang File's Name; 8:Show All The File\n"); scanf("%d",&i);if(i==1){tp=getpch(UFD);printf("请输入文件名:");scanf("%s",filename);printf("\n请输入文件内容:");scanf("%s",file);strcpy(tp->fileName,filename);strcpy(tp->File,file);tp->next=NULL;p=begin;p->next=tp;printf("\n文件创建完毕!\n");goto label;}else if(i==2){printf("请输入文件名:");scanf("%s",filename);p=begin->next;while(strcmp(p->fileName,filename)!=0&&p!=NULL) p=p->next;if(p==NULL) printf("文件不存在!\n");else{tp=begin;while(tp->next!=p) tp=tp->next;tp->next=p->next;free(p);printf("文件已删除!\n");}goto label;}else if(i==3){printf("请输入文件名:");scanf("%s",filename);p=begin->next;while(strcmp(p->fileName,filename)!=0&&p!=NULL) p=p->next;if(p==NULL) printf("文件不存在!\n");else{printf("%s: %s\n",p->fileName,p->File);}goto label;}else if(i==4){printf("请输入文件名:");scanf("%s",filename);printf("\n请输入文件内容:");scanf("%s",file);p=begin->next;while(p!=NULL){if(!(strcmp(p->fileName,filename))){strcpy(p->File,file);printf("\n替换了以%s为名的文件!\n",filename); goto label;}p=p->next;}tp=getpch(UFD);strcpy(tp->fileName,filename);strcpy(tp->File,file);tp->next=NULL;p=begin;p->next=tp;printf("\n创建了以%s为名的文件!\n",filename);goto label;}else if(i==5){goto label;}else if(i==6){printf("功能被关闭,无法操作了\n");Select();}else if(i==7){printf("请输入要改名的文件名:");scanf("%s",filename);while(p!=NULL){if(!(strcmp(p->fileName,filename))){printf("\n请输入新的文件名:");scanf("%s",filename);strcpy(p->fileName,filename);printf("\n文件名已更改!\n");goto label;}p=p->next;}printf("文件不存在!\n");goto label;}else if(i==8){show(f);goto label;}else{goto label;}}void Select(){char username[20];int i;printf("请输入用户名:\n");scanf("%s",username);for(i=0; i<userNum; i++){if(!strcmp(mdf[i].userName,username)){fp= mdf[i].p;if(fp!=NULL){printf("该用户已创建文件:\n");while(fp!=NULL){fp=fp->next;printf("%s\n",fp->fileName);}}else{printf("该用户尚未创建任何文件!\n"); }fp= mdf[i].p;Operation(fp);}}if(i>=userNum){printf("该用户不存在,创建新用户?\n 1:是 2:否\n");scanf("%d",&i);if(i==1){strcpy(mdf[userNum++].userName,username);printf("已创建用户!\n");i=userNum-1;fp= mdf[i].p;Operation(fp);}else{printf("查询其它?\n 1:是 2:否\n");scanf("%d",&i);if(i==1){Select();}else{printf("谢谢使用!\n");return;}}}}int main(){int i;for(i=0; i<20; i++){tp=getpch(UFD);tp->next=NULL;mdf[i].p=tp;}Select();return 0;}2、编一个通过屏幕选择命令的文件管理系统,每屏要为用户提供足够的选择信息,不需要打入冗长的命令。

#include <stdio.h>#include <stdlib.h>#include <string.h>#define getpch(type) (type*)malloc(sizeof(type))int userNum=0;struct mdf{char userName[20];struct UFD* p;} mdf[20];struct ufd{char fileName[20];char File[50];struct ufd * next;}*fp,*tp,*p,*begin;typedef struct ufd UFD;void show(struct UFD *f){begin=f;if(begin->next==NULL) printf("该用户名下尚无文件!\n");else{printf("该用户名下所有文件:\n");begin=begin->next;while(begin!=NULL){printf("%s: %s\n",begin->fileName,begin->File);begin=begin->next;}}}void Operation(struct UFD *f){int i;char filename[20],file[50];begin=f;label:printf("请选择操作:\n 1:create; 2:delete; 3:read; 4:write; 5:open;\n 6:lose; 7:Chang File's Name; 8:Show All The File\n"); scanf("%d",&i);if(i==1){tp=getpch(UFD);printf("请输入文件名:");scanf("%s",filename);printf("\n请输入文件内容:");scanf("%s",file);strcpy(tp->fileName,filename);strcpy(tp->File,file);tp->next=NULL;p=begin;p->next=tp;printf("\n文件创建完毕!\n");goto label;}else if(i==2){printf("请输入文件名:");scanf("%s",filename);p=begin->next;while(strcmp(p->fileName,filename)!=0&&p!=NULL) p=p->next;if(p==NULL) printf("文件不存在!\n");else{tp=begin;while(tp->next!=p) tp=tp->next;tp->next=p->next;free(p);printf("文件已删除!\n");}goto label;}else if(i==3){printf("请输入文件名:");scanf("%s",filename);p=begin->next;while(strcmp(p->fileName,filename)!=0&&p!=NULL) p=p->next;if(p==NULL) printf("文件不存在!\n");else{printf("%s: %s\n",p->fileName,p->File);}goto label;}else if(i==4){printf("请输入文件名:");scanf("%s",filename);printf("\n请输入文件内容:");scanf("%s",file);p=begin->next;while(p!=NULL){if(!(strcmp(p->fileName,filename))){strcpy(p->File,file);printf("\n替换了以%s为名的文件!\n",filename); goto label;}p=p->next;}tp=getpch(UFD);strcpy(tp->fileName,filename);strcpy(tp->File,file);tp->next=NULL;p=begin;p->next=tp;printf("\n创建了以%s为名的文件!\n",filename);goto label;}else if(i==5){goto label;}else if(i==6){printf("功能被关闭,无法操作了\n");Select();}else if(i==7){printf("请输入要改名的文件名:");scanf("%s",filename);while(p!=NULL){if(!(strcmp(p->fileName,filename))){printf("\n请输入新的文件名:");scanf("%s",filename);strcpy(p->fileName,filename);printf("\n文件名已更改!\n");goto label;}p=p->next;}printf("文件不存在!\n");goto label;}else if(i==8){show(f);goto label;}else{goto label;}}void Select(){char username[20];int i;printf("请输入用户名:\n");scanf("%s",username);for(i=0; i<userNum; i++){if(!strcmp(mdf[i].userName,username)){fp= mdf[i].p;if(fp!=NULL){printf("该用户已创建文件:\n");while(fp!=NULL){fp=fp->next;printf("%s\n",fp->fileName);}}else{printf("该用户尚未创建任何文件!\n"); }fp= mdf[i].p;Operation(fp);}}if(i>=userNum){printf("该用户不存在,创建新用户?\n 1:是 2:否\n");scanf("%d",&i);if(i==1){strcpy(mdf[userNum++].userName,username);printf("已创建用户!\n");i=userNum-1;fp= mdf[i].p;Operation(fp);}else{printf("查询其它?\n 1:是 2:否\n");scanf("%d",&i);if(i==1){Select();}else{printf("谢谢使用!\n");return;}}}}int main(){int i;for(i=0; i<20; i++){tp=getpch(UFD);tp->next=NULL;mdf[i].p=tp;}Select();return 0;}3、设计一个树型目录结构的文件系统,其根目录为 root,各分支可以是目录,也可以是文件,最后的叶子都是文件。

相关文档
最新文档