实验六 文件系统设计结果
文件管理系统实验报告

一、实验目的本次实验旨在通过设计和实现一个简单的文件管理系统,加深对文件管理原理的理解,掌握文件系统的基本操作,包括文件的创建、删除、修改、查询等,并了解文件系统的目录结构和管理机制。
二、实验环境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一、实验目的本次操作系统实验的主要目的是深入了解和掌握操作系统中进程管理、内存管理、文件系统等核心概念和相关技术,通过实际操作和观察,增强对操作系统工作原理的理解,并提高解决实际问题的能力。
二、实验环境本次实验使用的操作系统为 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篇)

第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文件管理(实验报告)班级:姓名:学号:在本节实验中,通过对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”文件的内容,并成功保存。
操作系统课程实验报告-实验六文件系统

hierarchy, filesCompareOutput = diffDir(sys.argv[1], sys.argv[2])
print('{0}\n 比较文件结构:\n{0}'.format(' '*10)) PrintHierarchy(hierarchy) print() if len(filesCompareOutput) != 0:
subname[1])
# 合并结果
filesCompareOutput += subCompareOutput
sameFileHierarchy.append(('{0}'.format(name),
subFileHierarchy))
elif ( os.path.isfile(subname[0])
华南理工大学 操作系统课程实验报告
实验概述
【实验目的及要求】
加深对 linux 文件系统的理解。 实现一个“difftree”命令,其功能是比较两个目录下的文件结构和文件信 息。当在命令行方式下执行“difftree <dir1> <dir2>”命令时,能够比较目录 dir1 和 目录 dir2 是否具有相同的结构,对相同的部分,进一步比较相同文件名的 文件内容。列出比较的文件系统结构图。 本实验是对单个文件比较的扩展,设计中需要考虑目录操作。
for item in hierarchy: if isinstance(item, tuple): print(' '*level*3 + ' ' + item[0] + '/') PrintHierarchy(item[1], level+1) else: print(' '*level*3 + ' ' + item)
计算机软件系统文件系统设计试验报告

实验步骤与调试过程:
用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件。另外,为了简便文件系统未考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容。主要数据结构:节点2.磁盘i结点3.目录项结构4.超级块 5.用户密码6.目录7.查找i内存节点的hash表8.系统打开表9.用户打开表
疑难小结:
通过本次试验,我对文件系统设计思想有了进一步的了解,通过动手实现其文件系统设计,更加深刻的理解了文件系统设计的不同特点。同时,在实验过程中,回顾书本上的理论知识,巩固了我的知识。了解了,文件系统实际是为用户提供一个解释执行相关命令的环境。主程序中的大部分语句都被用来执行相应的命令。应确定文件系统的数据结构:主目录、子目录及活动文件等。主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。用户创建的文件,可以编号存储于磁盘上。如file0,file1,file2...并以编号作为物理地址,在目录中进行登记。
Step25 调用ope写文件3后关闭文件3
Step28 释放缓冲
Step29 用户退出(logout)
Step30 关闭(halt)
End
。
1.编写管理文件makefile
本文件系统程序用编写makefile管理工具进行管理。其内容如下:
设置:主要函数节点内容获取函数iget()(详细描述略)。2.节点内容释放函数iput()(详细描述略)。3.目录创建函数mkdir()(详细描述略)。4.目录搜索函数namei()(详细描述略)。5.磁盘块分配函数balloc()(详细描述略)。6.磁盘块释放函数bfree()(详细描述略)。7.分配i节点区函数ialloc()(详细描述略)。8.解释结点区函数ifree( )(详细描述略)。9.搜索当前目录下文件的函数iname( )(详细描述略)。10.访问控制函数access( )(详细描述略)。11.显示目录和文件函数_dir( )(详细描述略)。12.改变当前目录用函数chdir( )(详细描述略)。13.打开文件函数open( )(详细描述略)。14.创建文件函数create( )(详细描述略)。15.读文件用函数read( )(详细描述略)。16.读文件用函数write( )(详细描述略)。17.用户登陆函数login( )(详细描述略)。18.用户退出函数logout( )(详细描述略)。19.文件系统格式化函数format( )(详细描述略)。20.进入文件系统函数install( )(详细描述略)。21.关闭文件函数close( )(详细描述略)。22.退出文件系统函数halt( )(详细描述略)。23.文件删除函数delecte( )(详细描述略)。
操作系统文件系统实验报告

操作系统文件系统实验报告操作系统文件系统实验报告引言操作系统是计算机系统中的重要组成部分,负责管理计算机的硬件和软件资源,为用户提供一个友好的界面和高效的资源管理。
文件系统作为操作系统的一个重要组成部分,负责管理计算机中的文件和目录,提供文件的读写和存储功能。
本实验旨在深入了解操作系统文件系统的原理和实现方式,并通过实际操作来加深对文件系统的理解。
一、实验背景操作系统中的文件系统是一个层次化的结构,它将计算机中的存储空间划分为若干个逻辑单元,用来存储和管理文件和目录。
文件系统的设计和实现涉及到文件的组织方式、文件的存储结构、文件的访问方式等多个方面。
本实验将以Linux操作系统为例,通过使用Linux文件系统的一些基本命令和操作,来深入了解文件系统的原理和实现方式。
二、实验目的1. 了解文件系统的基本概念和原理。
2. 掌握Linux文件系统的基本命令和操作。
3. 熟悉文件的读写和存储方式。
4. 加深对文件系统的理解和应用。
三、实验内容1. 文件系统的基本概念和原理文件系统是操作系统中用来管理文件和目录的一种机制,它将计算机中的存储空间划分为若干个逻辑单元,用来存储和管理文件和目录。
文件系统的基本概念包括文件、目录、路径等,文件是计算机中存储数据的基本单位,目录是用来组织和管理文件的一种方式,路径是用来定位文件和目录的一种方式。
2. Linux文件系统的基本命令和操作Linux操作系统是一个开源的操作系统,它提供了丰富的文件系统命令和操作。
通过使用这些命令和操作,可以对文件和目录进行创建、删除、复制、移动等操作。
例如,可以使用"mkdir"命令来创建一个新的目录,使用"rm"命令来删除一个文件,使用"cp"命令来复制一个文件,使用"mv"命令来移动一个文件等。
3. 文件的读写和存储方式文件的读写是文件系统的一项重要功能,它可以通过读取和写入文件来实现对文件内容的访问和修改。
实验六 文件系统设计结果

实验六文件系统设计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]->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();*/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;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\'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*/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");}。
操作系统实验文件系统报告

操作系统实验文件系统报告简介本文档是操作系统实验报告的文件系统部分。
在这个实验中,我们将通过实现一个简单的文件系统来了解文件系统的基本原理和实现方式。
本文档将介绍文件系统的设计和实现,以及在实验中遇到的问题和解决方案。
设计和实现文件系统结构我们的文件系统采用了简单的单级目录结构。
每个文件都有一个唯一的文件名和文件扩展名,以及相应的文件内容。
文件系统中的所有文件都存储在一个文件中,我们通过偏移量来访问每个文件。
文件系统接口我们实现了以下文件系统接口来对文件系统进行操作:•create_file(filename, extension): 创建一个新文件。
•delete_file(filename, extension): 删除一个文件。
•open_file(filename, extension): 打开一个文件。
•close_file(file): 关闭一个文件。
•read_file(file, offset, length): 从文件中读取数据。
•write_file(file, data): 向文件中写入数据。
•seek_file(file, offset): 设置文件指针的位置。
通过这些接口,我们可以对文件进行创建、删除、读取和写入操作,以及设置文件指针的位置。
文件系统实现我们的文件系统是在操作系统内核中进行实现的。
在内存中维护了一个文件控制块(FCB)表,用于记录文件的元数据信息,比如文件名、扩展名、大小和位置等。
文件内容存储在一个独立的数据块中。
为了实现文件的持久化,我们将文件系统的存储映射到了一个文件中。
在系统启动时,我们会将这个文件读取到内存中,并建立起文件控制块表和数据块的映射关系。
文件的创建、删除和读写操作都是通过操作文件控制块表和数据块来完成的。
具体实现涉及到文件的分配和释放,以及文件指针的管理等问题。
遇到的问题和解决方案在实验中,我们遇到了一些问题,主要集中在文件的读写和文件指针的管理方面。
文件系统设计试验报告

cc-c log.c
close.o:close.c filesys.h
cc-c close.c
creat.eat.c
delete.o:delete.c filesys.h
cc-c delete.c
dir.o:dir.c filesys.h
filsys:main.o iallfre.o ballfre.o name.o access.o log.o close.o creat.o delete.o dir.o
open.o rdwt.o format.o install.o halt.o cc-o filsys main.o iallfre.o ballfre.o
halt.o:halt.c
cc-c halt.c
cc-c dir.c
open.o:open.c filesys.h
cc-c open.c
rdwt.o:rdwt.c filesys.h
cc-c rdwt.c
format.o:format.c filesys.h
cc-c format.c
install.o: install.c filesys.h
cc-c install.c
Step8 写文件0
Step9 关闭文件0和释放缓冲
Step10 调用mkdir()和chdir()创建子目录
Step11 调用create(),创建文件1
Step12 分配缓冲区
Step13 写文件1
Step14 关闭文件1和释放缓冲
Step15 调用chdir将当前目录移到上一级
Step16 调用create(),创建文件2
实验结果:
文件系统实验报告

试验四文件系统一、实验目的1、用高级语言编写和调试一个简单的文件系统,模拟文件管理的工作过程。
从而对各种文件操作命令的实质容和执行过程有比较深入的了解。
2、要求设计一个n个用户的文件系统,每次用户可以保存M个文件。
用户在一次运行中只能打开一个文件,对文件必须设置保护措施,且至少有create、delete、open、close、read、write等命令。
二、实验题目:采用二级目录结构实现磁盘文件操作。
要求:1.普通文件的目录项包括文件名,文件类型,文件长度,指向文件容的指针容。
2.目录文件的目录项包括目录名,指向下一级目录块的指针容。
假定每个目录文件最多只能占用一个块;3.程序功能方面的要求:需要实现一个命令行操作界面,包含如下命令:4.程序实现方面的要求:(1)、对于重名(创建时),文件不存在(删除时),目录不存在(改变目录时)等错误操作情况,程序应该做出相应处理并给出错误信息,但是程序不得因此而退出。
(2)、界面友好,程序强壮。
(3)、设置界面的提示符,提示的命令以及调试的方法应和前面的要求一致。
不要自己设计命令或者附加不要求的功能。
三.实验源程序文件名: Filesystem_s.cpp执行文件名: Project1.exe四.实验分析1)总论:该系统是一个多用户、多任务的实时操作系统。
对用户和用户的文件数目并没有上限。
也就是说该系统允许任何用户申请空间,而且在其目录下的文件数目并不做任何的限制。
该系统的操作命令如下:①、bye-用户注销命令。
当使用该命令时,用户退出系统。
命令格式:run\bye↙系统注销该用户并回到登陆界面。
②、close-删除用户注册信息命令。
执行该命令后,用户在系统中的所有信息,包括该用户目录下的所有文件都被删除。
命令格式:run\close↙.完成后返回登陆界面。
③、create-在当前目录下创建一个文件,且该文件不能跟系统中的文件重名。
该文件的管理信息登录到用户文件信息管理模块中。
操作系统实验---文件系统

实验报告实验题目:文件系统姓名:学号:课程名称:操作系统所在学院:信息科学与工程学院专业班级:计算机任课教师:实验项目名称文件系统一、实验目的与要求:1、通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能及其内部实现。
2、熟悉文件管理系统的设计方法,加深对所学各种文件操作的了解及其操作方法的特点。
3、通过模拟文件系统的实现,深入理解操作系统中文件系统的理论知识, 加深对教材中的重要算法的理解。
4、通过编程实现这些算法,更好地掌握操作系统的原理及实现方法,提高综合运用各专业课知识的能力。
二、实验设备及软件:一台PC(Linux系统)三、实验方法(原理、流程图)试验方法(1)首先应当确定文件系统的数据结构:主目录、子目录以及活动文件等。
主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。
(2)用户创建文件,可以编号存储于磁盘上。
如file0,file1,file2…并以编号作为物理地址,在目录中登记。
文件系统功能流程图图1.文件系统总体命令分析图 2.登录流程图图 3. ialloc流程图图4.balloc流程图图5.密码修改流程图图6.初始化磁盘图 7.显示所有子目录 dir/ls 操作流程图图8.创建文件 creatfile 、创建目录 mkdir 流程图图9.改变当前路径 cd 操作流程图实验原理1.文件操作◆mkdir 创建目录文件模块,输入 mkdir 命令,回车,输入文件名,回车,即会在当前目录文件下创建一个名为刚刚输入的文件名的目录文件。
在该创建过程中首先要判断该目录中有没有同名的文件,如果有的话就创建失败,还要判断在该目录下有没有创建文件的权限,有权限才可以创建。
具体流程图查看第二节,系统流程图设计部分。
◆del 删除文件模块,输入 del命令,回车,输入文件名,回车,即会在当前目录文件下删除一个名为刚刚输入的文件名的数据文件。
在该删除过程中要判断该目录中是否存在该文件,如果不存在就没有必要执行该操作了,还要判断在该目录下有没有删除文件的权限,有权限才可以删除。
文件系统的构建实验报告

文件系统的构建实验报告 实验名称:文件系统的构建实验目的:掌握磁盘的工作原理和操作系统进行文件管理的原理实验原理:硬盘的MBR :MBR (Main Boot Record ),按其字面上的理解即为主引导记录区,位于整个硬盘的0磁道0柱面1扇区。
在总共512字节的主引导扇区中,MBR 只占用了其中的446个字节(偏移0000--偏移01BD ),另外的64个字节(偏移01BE--偏移01FD )交给了DPT(Disk Partition Table 硬盘分区表),最后两个字节"55,AA"(偏移01FE- 偏移01FF )是分区的结束标志。
这个整体构成了硬盘的主引导扇区。
硬盘依据分区表中的信息把硬盘划分为最多四个分区(对于扩展分区,可进一步划分为多个逻辑分区)。
U 盘采用类似的方法划分分区。
每个分区或软盘上可建立独立的文件系统。
下图是FAT 文件系统空间分布结构。
实验内容:在掌握磁盘的工作原理和操作系统进行文件管理原理的基础上,自行设计实现在磁盘上建立文件系统的软件,该软件应该具有与Format 类似的功能,至少支持一种文件系统格式,如FAT 、NTFS 或EXT2,至少能够对一种媒体进行格式化,如软盘,U 盘或硬盘(不得在实验室的机器上进行硬盘格式化的实验)等。
不能直接调用操作系统提供的格式化工具或类似SHFormatDrive ()的高层系统函数实现该软件。
在Windows 环境可使用biosdisk()函数完成底层盘操作,在Linux 环境上可参考format 的源代码。
比较自己设计实现的软件.与FORMAT ,分析存在什么异同。
背景知识介绍 一个分区或磁盘能作为文件系统使用前,需要初始化,并将记录数据结构写到磁盘上。
这个过程就叫建立文件系统。
大部分linux 文件系统种类具有类似的通用结构。
其中心概念是超级块superblock, i 节点inode, 数据块data block,目录块directory block, 和间接块indirection block 。
Linux文件系统实验报告

}
temp=temp->child;
while(temp)
{
if(temp->isdir)
{cout<<" <DIR> "<<temp->filename<<endl;i++;}
else
{cout<<" <FILE> "<<temp->filename<<endl;j++;}
temp=temp->next;
关闭文件:可通过选择关闭文件的功能选项,来关闭系统中所有打开的文件,如果没有文件被打开,则系统会显示没有文件打开。
删除用户、文件、文件夹:用户可通过选择删除的功能选项来删除不想再保存的文件和文件夹,删除后,用户会自动注销;当选择删除用户的功能选项时,系统会删除该用户,以及该用户所创建的所有文件和文件夹。
node->child=NULL;
node->prev=NULL;
node->next=NULL;
return node;
}
//创建文件存储结点
void createroot ()
{
recent=root=initfile("/",1);
root->parent=NULL;
root->child=NULL;
root->prev=root->next=NULL;
strcpy(para,"/");
}
int mkdir()
{
temp=initfile(" ",1);
模拟文件系统实验报告

操作系统大型试验实验报告姓名:XX班级:软件工程110x学号:201126630xxx一、名称操作系统大型试验。
二、目的用C++编写出一个简单的模拟文件系统,实现目录的添加、删除、重命名,文件的添加、删除、重命名、文件和目录、文件的拷贝。
三、要求开发工具:word,vc win32api1.设计和实现一个简单的文件系统,要求包括目录、普通文件和文件的存储2.文件系统的目录结构采用类似Linux的树状结构;3.要求模拟的操作包括:a)目录的添加、删除、重命名;b)目录的显示(列表)c)文件的添加、删除、重命名d)文件和目录的拷贝4.用户进入时显示可用命令列表;用户输入help时显示所有命令的帮助文档;输入某个命令+?时显示该条命令的使用说明5.用户输入exit时退出该系统6.实验实现基于windows平台;7.实验开发语言可以选用C/c++等四、设计1.主要思路说明本模拟系统通过一个大小固定的数组要代表物理盘块,假设共有1024块,新增目录占一块,新增文件占一块,文件中可输入内容,内容假设定义为5个字符占一块,超出则应新申请空间。
模拟物理盘块的数组中,数组内容为-99代表改物理盘块内容为空,可使用,其他数字均代表该物理盘块被占用,其中-3代表是占用文件的末结点,其他整数代表是文件内容的下一个寻址下标,另有一个string类型的数组来存储内容,模拟文件写入了对应下标的物理盘块中。
设置了一个全局指针指向根结点,一个全局指针指向当前操作目录。
搜索空白物理盘块时采用顺序搜索物理盘块数组。
存储形式主要采用类似二叉树结构,如目录为根,目录下的第一个文件或目录存在根的子节点,目录下的其他文件或目录存在第一个文件或目录的兄弟节点,以此类推。
本程序仅seperate()函数使用现成代码,此函数功能为将输入命令串分离,仅仅起到美观作用,其余所有代码均为原创!2.申优功能:1)能实现动态增长,即当输入文件的内容大小大于分配的模拟物理盘块时系统能够自动寻找空物理盘块并分配,将超出的内容保存在新的物理盘块中,若超出模拟磁盘大小,则超出部分不保存且返回提示。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 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*/。