实验六 文件系统设计结果

合集下载

文件管理系统实验报告

文件管理系统实验报告

一、实验目的本次实验旨在通过设计和实现一个简单的文件管理系统,加深对文件管理原理的理解,掌握文件系统的基本操作,包括文件的创建、删除、修改、查询等,并了解文件系统的目录结构和管理机制。

二、实验环境1. 操作系统:Windows 102. 开发工具:Visual Studio 20193. 编程语言:C++4. 实验时间:2023年10月25日三、实验内容1. 文件系统的目录结构设计2. 文件的基本操作实现3. 文件系统的存储管理4. 文件系统的安全机制四、实验步骤1. 目录结构设计根据文件系统的需求,设计以下目录结构:```根目录│├── 文件夹A│ ├── 文件1.txt│ └── 文件2.txt│├── 文件夹B│ └── 文件3.txt│└── 文件夹C```2. 文件的基本操作实现(1)文件创建```cppvoid CreateFile(const std::string& filePath, const std::string& content) {// 检查文件是否存在if (CheckFileExist(filePath)) {std::cout << "文件已存在!" << std::endl;return;}// 创建文件std::ofstream file(filePath);if (file.is_open()) {file << content;file.close();std::cout << "文件创建成功!" << std::endl;} else {std::cout << "文件创建失败!" << std::endl;}}```(2)文件删除```cppvoid DeleteFile(const std::string& filePath) {// 检查文件是否存在if (!CheckFileExist(filePath)) {std::cout << "文件不存在!" << std::endl;return;}// 删除文件if (remove(filePath) == 0) {std::cout << "文件删除成功!" << std::endl;} else {std::cout << "文件删除失败!" << std::endl;}}```(3)文件修改```cppvoid ModifyFile(const std::string& filePath, const std::string& newContent) {// 检查文件是否存在if (!CheckFileExist(filePath)) {std::cout << "文件不存在!" << std::endl; return;}// 修改文件内容std::ofstream file(filePath, std::ios::trunc); if (file.is_open()) {file << newContent;file.close();std::cout << "文件修改成功!" << std::endl; } else {std::cout << "文件修改失败!" << std::endl; }}```(4)文件查询```cppvoid QueryFile(const std::string& filePath) {// 检查文件是否存在if (!CheckFileExist(filePath)) {std::cout << "文件不存在!" << std::endl; return;}// 读取文件内容std::ifstream file(filePath);if (file.is_open()) {std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());std::cout << "文件内容:" << content << std::endl;file.close();} else {std::cout << "文件读取失败!" << std::endl;}}```3. 文件系统的存储管理文件系统采用磁盘文件作为存储介质,通过文件操作实现对文件的读写。

文件系统设计实验报告

文件系统设计实验报告

文件系统设计实验报告文件系统设计实验报告一、引言在计算机科学领域,文件系统是操作系统中的一个重要组成部分,用于管理和组织计算机存储设备上的文件和目录。

一个高效稳定的文件系统对于计算机系统的正常运行至关重要。

本实验旨在设计一个简单但功能完善的文件系统,并通过实验验证其性能和可靠性。

二、实验背景文件系统是计算机操作系统的核心组成部分之一,它负责管理计算机存储设备上的文件和目录。

一个好的文件系统应该具备以下特点:高效的文件存取速度、可靠的数据完整性、良好的扩展性和灵活性。

三、实验目标本实验的主要目标是设计一个简单但功能完善的文件系统,并通过实验验证其性能和可靠性。

具体而言,我们将实现以下功能:1. 文件的创建、读取、写入和删除。

2. 目录的创建、删除和遍历。

3. 文件和目录的权限管理。

4. 文件系统的容量管理。

5. 文件系统的备份和恢复。

四、实验设计与实现1. 文件和目录的创建、读取、写入和删除在文件系统中,文件和目录都是通过数据块来存储的。

我们可以使用链表或树的数据结构来组织文件和目录之间的关系。

为了提高文件的读取和写入效率,可以采用缓存机制,将最近访问的文件块缓存在内存中。

2. 目录的创建、删除和遍历目录是文件系统中用于组织和管理文件的一种特殊文件。

为了实现目录的创建、删除和遍历功能,我们可以使用树的数据结构来表示目录结构,并通过递归算法来实现目录的遍历。

3. 文件和目录的权限管理为了保护文件和目录的安全,我们可以为每个文件和目录设置权限。

权限可以分为读、写和执行三种类型。

通过权限管理,可以限制用户对文件和目录的操作,提高文件系统的安全性。

4. 文件系统的容量管理文件系统的容量管理是指对文件和目录所占用的存储空间进行管理。

为了有效利用存储空间,我们可以使用位图或链表等数据结构来管理存储空间的分配和释放。

5. 文件系统的备份和恢复为了保证文件系统的可靠性,我们可以定期对文件系统进行备份。

备份可以通过复制文件和目录的数据块来实现。

操作系统实验报告6

操作系统实验报告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服务。

文件系统 实验报告

文件系统 实验报告

文件系统实验报告引言文件系统是操作系统中的一部分,用于管理计算机中的文件和目录。

它提供了数据的存储、访问、组织和管理功能,是操作系统的基础之一。

本实验通过实现一个简单的文件系统来深入理解文件系统的原理和实现方式。

实验目的1. 了解文件系统的基本概念和原理;2. 学习文件系统的设计和实现方法;3. 掌握文件系统的基本操作。

实验环境本次实验使用的是Ubuntu 20.04操作系统。

实验步骤1. 文件系统的设计在开始实现文件系统之前,我们首先需要设计文件系统的结构和功能。

1.1 文件系统的结构文件系统通常由三个主要部分组成:文件控制块、目录和数据块。

文件控制块用于存储文件的属性和元数据,目录用于组织文件和子目录,数据块用于存储文件的实际内容。

1.2 文件系统的功能文件系统需要提供以下功能:- 文件的创建、读取、修改和删除;- 目录的创建、读取、修改和删除;- 文件和目录的查找;- 文件的权限管理。

2. 文件系统的实现2.1 文件系统的初始化在实现文件系统之前,我们首先需要初始化文件系统。

包括创建超级块、位图和根目录,并将它们写入磁盘。

2.2 文件和目录的操作在文件系统中,我们需要实现文件和目录的基本操作,包括创建文件、创建目录、读取文件内容、修改文件内容和删除文件。

2.3 文件系统的其他操作除了基本的文件和目录操作之外,文件系统还需要实现其他一些功能,如文件查找、权限管理等。

3. 文件系统的测试在完成文件系统的实现后,我们需要对其进行测试,以验证其功能是否正常。

3.1 创建文件和目录我们首先创建一些文件和目录,检查它们是否被正确地写入磁盘,并且能够被正确地读取。

3.2 读取和修改文件我们随机选择一些文件,读取它们的内容,并对其内容进行修改。

修改后,我们再次读取文件,确保修改成功。

3.3 删除文件和目录我们尝试删除一些文件和目录,并检查它们是否被成功地删除。

4. 结果与讨论经过测试,我们发现我们实现的文件系统功能正常,能够按照我们的预期进行文件和目录的创建、读取、修改和删除等操作。

文件管理实验报告结果(3篇)

文件管理实验报告结果(3篇)

第1篇一、实验目的本次实验旨在通过实际操作,验证文件管理的有效性和可行性,并对文件管理系统的性能进行评估。

通过实验,了解文件管理的相关原理和方法,提高文件管理的实践能力。

二、实验环境1. 操作系统:Windows 102. 文件管理系统:Windows文件管理器3. 实验数据:实验过程中产生的文件和数据三、实验内容1. 文件创建与删除2. 文件夹创建与删除3. 文件与文件夹的复制、移动、重命名4. 文件属性的设置与修改5. 文件搜索与查找6. 文件权限管理7. 文件压缩与解压四、实验步骤1. 文件创建与删除(1)在Windows文件管理器中,新建一个名为“实验文件.txt”的文本文件。

(2)在“实验文件.txt”上右击,选择“删除”,确认删除。

2. 文件夹创建与删除(1)在Windows文件管理器中,新建一个名为“实验文件夹”的文件夹。

(2)在“实验文件夹”上右击,选择“删除”,确认删除。

3. 文件与文件夹的复制、移动、重命名(1)将“实验文件.txt”复制到“实验文件夹”中。

(2)将“实验文件.txt”移动到桌面。

(3)将“实验文件.txt”重命名为“实验文件修改.txt”。

4. 文件属性的设置与修改(1)在“实验文件修改.txt”上右击,选择“属性”,设置文件属性为“只读”。

(2)修改“实验文件修改.txt”的属性为“隐藏”。

5. 文件搜索与查找(1)在Windows文件管理器中,输入“实验文件”进行搜索。

(2)使用“查找”功能,查找“实验文件修改.txt”。

6. 文件权限管理(1)在“实验文件夹”上右击,选择“属性”,点击“安全”标签。

(2)添加用户权限,设置权限为“完全控制”。

7. 文件压缩与解压(1)将“实验文件夹”压缩为“实验文件夹.zip”。

(2)解压“实验文件夹.zip”到指定位置。

五、实验结果与分析1. 文件创建与删除:实验成功创建和删除了文件,验证了文件管理的可行性。

2. 文件夹创建与删除:实验成功创建和删除了文件夹,验证了文件管理的可行性。

操作系统:实验6文件管理(实验报告)

操作系统:实验6文件管理(实验报告)

操作系统:实验6文件管理(实验报告)班级:姓名:学号:在本节实验中,通过对Windows 提供的文件与文件夹加密、磁盘配额管理、创建紧急修复磁盘、进行磁盘清理、执行备份操作、使用CHKDSK 维护文件完整性和整理磁盘碎片等功能进行操作:1) 熟悉Windows 的文件系统。

2) 明确应用NTFS 文件系统的积极意义。

3) 掌握优化Windows 磁盘子系统的基本方法。

4) 进一步理解现代操作系统文件管理知识。

1. 工具/准备工作在开始本节实验之前,请回顾教材的相关内容。

需要准备一台运行Windows 系统的计算机。

2. 实验内容与步骤(1) 请回答:1) Windows 支持哪3种主要的文件系统:a.__________________________________________________________________b.__________________________________________________________________c.__________________________________________________________________2) NTFS 文件系统只能用于哪些操作系统环境:________________________________________________________________ ____(2) 加密文件或文件夹。

1) 右键单击想要加密的文件或文件夹,然后单击“属性”命令。

2) 在“常规”选项卡上,单击“高级”按钮。

在“高级属性”对话框中,可以设置的文件属性有:________________________________________________________________ ____________________________________________________________________ ____________________________________________________________________ ________________________________________________________________________ 实验6 文件管理(3) 访问RSM服务。

文件系统实验报告

文件系统实验报告

一、实验目的1. 理解文件系统的基本概念和组成。

2. 掌握文件系统的创建、删除、修改和查询等基本操作。

3. 了解文件系统的性能分析和优化方法。

4. 提高对文件系统原理的理解和实际操作能力。

二、实验环境1. 操作系统:Windows 102. 文件系统:NTFS3. 实验软件:Windows资源管理器、Notepad++等三、实验内容1. 文件系统的基本概念和组成(1)文件:存储在文件系统中的数据单元,可以是程序、文档、图片等。

(2)目录:用于组织文件的结构,类似于文件夹。

(3)文件系统:管理存储设备上文件和目录的数据结构。

2. 文件系统的创建、删除、修改和查询等基本操作(1)创建文件:使用Notepad++创建一个名为“test.txt”的文本文件。

(2)创建目录:在Windows资源管理器中,创建一个名为“test”的目录。

(3)删除文件:选中“test.txt”文件,按Delete键删除。

(4)删除目录:选中“test”目录,按Delete键删除。

(5)修改文件:使用Notepad++打开“test.txt”文件,修改内容后保存。

(6)查询文件:在Windows资源管理器中,通过路径或搜索功能查找“test.txt”文件。

3. 文件系统的性能分析和优化方法(1)查看磁盘空间使用情况:在Windows资源管理器中,选中磁盘分区,查看磁盘空间使用情况。

(2)清理磁盘:使用Windows自带的磁盘清理工具清理磁盘垃圾文件。

(3)优化文件系统:使用Windows自带的磁盘碎片整理工具优化文件系统。

四、实验结果与分析1. 创建文件和目录实验结果显示,使用Notepad++创建了一个名为“test.txt”的文本文件,使用Windows资源管理器创建了一个名为“test”的目录。

2. 删除文件和目录实验结果显示,成功删除了“test.txt”文件和“test”目录。

3. 修改文件实验结果显示,使用Notepad++修改了“test.txt”文件的内容,并成功保存。

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

实验六文件系统设计1.目的和要求本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。

2.实验内容为DOS系统设计一个简单的二级文件系统,可以实现下列几条命令DIR 列文件目录CREATE 创建文件DELETE 删除文件MODIFY 修改文件OPEN 打开文件CLOSE 关闭文件列目录时要列出文件名,物理地址,保护码和文件长度。

3.实验环境①PC兼容机②Windows、DOS系统、Turbo c 2.0③C语言4.实验提示①首先应确定文件系统的数据结构:主目录、活动文件等。

主目录文件的形式存放于磁盘,这样便于查找和修改。

主目录结构:Ufdname 用户名Ufdfile 指向用户的活动文件活动文件结构:Fpaddr 文件物理地址Flength 文件长度Fmode 文件属性(file mode:0-Read Only;1-Write Only;2-Read and Write(default))Fname 文件名称②用户创建的文件,可以编号存储于磁盘上。

如:file0,file1,file2…并以编号作为物理地址,在目录中进行登记。

③本程序需要在c:下建一个名为osfile的目录及一个名为file的子目录,在利用程序创建了文件系统后,可以在这个文件夹下查看到相关的内容。

5.实验程序#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);*//*clrscr();*/ /*clear screen*/LoginF(); /*user login*//*clrscr();*/if(loginsuc==1) /*Login Successfully*/{while (1){wgetchar=0;if (choiceend==1){printf("\n\nC:\\%s>",strupr(dirname));}else printf("Bad command or file name.\nC:\\%s>",strupr(username));gets(choice);strcpy(choice,ltrim(rtrim(strlwr(choice))));if (strcmp(choice,"dir")==0) choice1=1;else if(strcmp(choice,"create")==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;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 Create Modify Read Open Cls Delete Exit Close\n");*/printf("Create : Create a file(You can initialize file's attribute and content.)\n");printf("Open : Open a file to modify\n");printf("Close : Close a file.\n");printf("Modify : Modify the opened file.\n");printf("Delete : Delete existed files.\n");printf("CD : Change current directory.\n");printf("Exit : Exit this program.\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);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();*/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","Ty pe","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();*/printf("\n%14s%16s%14s%10s%18s\n","FileName","FileAddress","FileLength","Ty pe","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]->uf dfile[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();*/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,FileMode is %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;{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(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\'t read.\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*/。

相关文档
最新文档