您好,欢迎来到宝玛科技网。
搜索
您的当前位置:首页操作系统文件管理实验报告

操作系统文件管理实验报告

来源:宝玛科技网
 - .

操作系统实验报告

. 实验名称:文件管理

专业班级:网络工程1301 学 号: XX:

2015 年 6 月 16 日

-可修遍-

- .

实验一文件管理

一、实验目的

文件管理是操作系统的一个非常重要的组成部分。 学生应用高级语言编写和调试一个简单的文件系统,模拟文件管理的工作过程。从而对各种文件操作命令的实质容和执行过程有比较深入的了解,掌握它们的实施方法,加深理解课堂上讲授过的知识。

二、预备知识

1. VS2010的使用 2. C#的学习

3. 文件主目录与子目录的理解

三、实验容与步骤

用高级语言编写和调试一个简单的文件系统, 模拟文件管理的工作过程。要求设计一个10 个用户的文件系统,每次用户可保存 10 个文件,一次运行用户可以打开5 个文件。系统能够检查打入命令的正确性,出错时能显示出错原因。对文件必须设置保护措施,例如只能执行,允许读等。在每次打开文件时,根据本次打开的要求,在此设置保护级别, 即有二级保护。 文件的操作至少有Create、 delete、 open、close、read、write 等命令。 所编写的程序应采用二级文件目录, 即设置主文件目录和用户文件目录。前者应包含文件主及它们的目录区指针;后者应给出每个文件占有的文件目录,即文件名,保护码,文件长度以及它们存放的位置等。另外为打开文件设置运行文件目录(AFD) ,在文件打开时应填入打开文件号,本次打开保护码和读写指针等。 程序流程图:

. -可修遍-

- .

逻辑设计:

使用线性数组表表示MFD,泛型数组表示 UFD,每个元素包括用户ID、保存的文件数、再使用线性表表示文件信息,每个元素包括文件名,文件属性(保护码) ,文件的状态等信息。 物理设计: //主目录

private FileUser[] mfd; //当前用户

private FileUser currentuser; ///

/// 文件

///

public class FileObject { public string filename; public int size=20; public int read=0; public int write = 0; public string author; }

///

/// 文件系统用户 ///

public class FileUser { public string username;

. -可修遍-

- .

public List ufd = new List(); public int filecount=0; } 步骤详述: 1、主目录及用户目录机构显示:

2、当前操作用户登录:

3、文件管理系统菜单:

4、create命令:

5、open命令:

.

-可修遍-

- .

6、close命令:

7、delete命令:

8、read命令

9、write命令

10、exit命令

四、实验总结

通过这次的课程设计使我认识到要将操作系统这门计算机专业的课学好不仅仅是要把书上的基本知识学好而且还要不断进行实践,将所学的跟实践操作结合起来才能更好地巩固所学,才能提高自己实践能力.通过这次的设计使我认识到只停留在表面理解问题是很难使问题得到很好的解决的,实践能力与理论知识同样重要。可以说此课程设计的理论难度并不大,但是若要深入发掘其中的东西,并

. -可修遍-

- .

且实际去编程实现,就遇到了相当大的难度。因为与之涉及的很多方面并没有学过,需要自己去自学和实践检验。

五、程序清单

using System;

using System.Collections.Generic; using System.Linq; using System.Text;

namespace filemanagesystem {

class Program {

static void Main(string[] args) {

//初始化用户自模拟文件系统

ExplorerInUser explorer = new ExplorerInUser(); } }

///

/// 文件管理系统for用户自模拟 ///

public class ExplorerInUser

. -可修遍-

- .

{

//命令列表

private string[] mand = { \"create\ //主目录

private FileUser[] mfd; //当前用户

private FileUser currentuser; ///

/// 构造函数 /// public ExplorerInUser() {

INI(); }

///

/// 初始化系统 /// private void INI() {

if (currentuser == null) {

//主目录实现

. -可修遍-

- .

IniUserList(); }

//系那是菜单 InilizeMenu(); bool isinput = false; //输入正确的命令 while (!isinput) {

string input = Console.ReadLine(); isinput=mandGroup(input); } }

#region 主目录 ///

/// 获取用户个数 /// /// private int GetUserCount() {

string input = Console.ReadLine(); try

. -可修遍-

- .

{

int user_size = Convert.ToInt32(input); return user_size; }

catch (Exception e) {

Console.WriteLine(e.Message); return 0; } }

///

/// 生成用户及用户管理文件 ///

private void IniUserList() {

int user_size = GetUserCount(); mfd=new FileUser[user_size]; for (int i = 0; i < user_size; i++) {

mfd[i] = new FileUser(); mfd[i].username = \"mfd_user_\"+i; mfd[i].filecount = 3;

. -可修遍-

- .

Console.WriteLine(\"mfd:\" + mfd[i].username + \+

mfd[i].filecount);

for (int j = 0; j < 3; j++) {

FileObject file=new FileObject (); file.author = mfd[i].username;

Console.WriteLine(\"--ufd:\"+file.filename+\ file.filename=\"file\"+j; mfd[i].ufd.Add(file); } } IniLogin(); }

///

/// 用户登录 /// private void IniLogin() {

Console.WriteLine(\"请输入用户名:\"); bool issuccess = false;

while (!issuccess)

. -可修遍-

- .

{

string username = Console.ReadLine(); for (int i = 0; i < mfd.Length; i++) {

if (mfd[i].username.Equals(username)) {

issuccess = true; currentuser = mfd[i];

Console.WriteLine(\"当前用户:\"+username); break; } }

if (!issuccess) {

Console.WriteLine(\"请重新输入输入用户名:\"); } } }

#endregion

#region 菜单 ///

. -可修遍-

- .

/// 初始化菜单 ///

private void InilizeMenu() {

Console.WriteLine(\"欢迎进入文件管理系统!\"); Console.WriteLine(\"------create-------\"); Console.WriteLine(\"------open---------\"); Console.WriteLine(\"------close--------\"); Console.WriteLine(\"------delete-------\"); Console.WriteLine(\"------read---------\"); Console.WriteLine(\"------write--------\"); Console.WriteLine(\"------exit---------\"); Console.WriteLine(\"请输入操作命令:\"); }

///

/// 功能分组判断 ///

/// ///

private bool mandGroup(string mand) {

bool isexit = true;

. -可修遍-

- .

switch (mand) {

case \"create\": create(); break; case \"open\": open(); break; case \"close\": close(); break; case \"delete\": delete(); break; case \"read\": read(); break; case \"write\": write(); break; case \"exit\": exit(); return true; break; default:

isexit = false; break; }

if (isexit) { INI(); }

else { Console.WriteLine(\"请重新输入操作命令:\"); } return isexit; }

#endregion

#region 操作命令方法 ///

. -可修遍-

- .

/// 创建新的文件 ///

private void create() {

Console.WriteLine(\"请输入新件名:\"); string filename = Console.ReadLine(); currentuser.filecount++; FileObject file = new FileObject(); file.filename = filename;

file.author = currentuser.username; currentuser.ufd.Add(file);

Console.WriteLine(\"成功创建文件!\");

}

///

/// 打开指定的文件 /// private void open() {

Console.WriteLine(\"请输入文件名:\"); string filename = Console.ReadLine(); for (int i = 0; i < currentuser.ufd.Count; i++) {

. -可修遍-

- .

if (currentuser.ufd[i].filename.Equals(filename)) {

Console.WriteLine(\"成功打开文件!\"); Console.WriteLine(\"ID:\"+i);

Console.WriteLine(\"FileName:\"+filename); Console.WriteLine(\"Size:\" + currentuser.ufd[i].size); Console.WriteLine(\"Autor:\" + currentuser.ufd[i].author); return; }

} Console.WriteLine(\"文件不存在!\"); }

///

/// 关闭所有打开的文件 ///

private void close() {

Console.WriteLine(\"已关闭文件\"); }

///

/// 删除文件 /// private void delete() {

. -可修遍-

- .

Console.WriteLine(\"请输入文件名:\"); string filename = Console.ReadLine(); for (int i = 0; i < currentuser.ufd.Count; i++) {

if (currentuser.ufd[i].filename.Equals(filename)) {

currentuser.ufd.RemoveAt(i);

Console.WriteLine(\"成功删除文件!\"); return; }

} Console.WriteLine(\"文件不存在!\"); }

///

/// 读取文件 /// private void read() {

Console.WriteLine(\"请输入文件名:\"); string filename = Console.ReadLine(); for (int i = 0; i < currentuser.ufd.Count; i++) {

if (currentuser.ufd[i].filename.Equals(filename)) {

. -可修遍-

- .

Console.WriteLine(\"已读取文件!\"); return; }

} Console.WriteLine(\"文件不存在!\"); }

///

/// 写入文件 /// private void write() {

Console.WriteLine(\"请输入文件名:\"); string filename = Console.ReadLine(); for (int i = 0; i < currentuser.ufd.Count; i++) {

if (currentuser.ufd[i].filename.Equals(filename)) {

Console.WriteLine(\"已写入文件!\"); return; }

} Console.WriteLine(\"文件不存在!\"); }

///

/// 退出系统

. -可修遍-

- .

///

private void exit() {

Console.WriteLine(\"您好,您已经成功退出系统!\"); Console.ReadKey(); }

#endregion }

///

/// 文件 /// public class FileObject { public string filename; public int size=20; public int read=0; public int write = 0; public string author; }

///

/// 文件系统用户 /// public class FileUser {

. -可修遍-

- .

public string username;

public List ufd = new List(); public int filecount=0; } }

. -可修遍-

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- baomayou.com 版权所有 赣ICP备2024042794号-6

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务