Ejemplo n.º 1
0
        static void TestVirtualFileSystem()
        {
            try
            {
                Random r = new Random();

                VolatileDisk disk = new VolatileDisk(1);
                //PersistentDisk disk = new PersistentDisk(1, "disk1");
                disk.TurnOn();

                VirtualFS vfs = new VirtualFS();

                vfs.Format(disk);
                vfs.Mount(disk, "/");
                VirtualNode root = vfs.RootNode;

                VirtualNode dir1 = root.CreateDirectoryNode("dir1");
                dir1.CreateDirectoryNode("foo");
                dir1.CreateDirectoryNode("bar");
                VirtualNode dir2 = root.CreateDirectoryNode("dir2");
                dir2.CreateDirectoryNode("hah!");

                VirtualNode file1 = dir1.CreateFileNode("file1");
                TestFileWriteRead(file1, r, 0, 100);    // 1 sector
                TestFileWriteRead(file1, r, 0, 500);    // 2 sectors
                TestFileWriteRead(file1, r, 250, 500);  // 3 sectors
                dir2.CreateFileNode("another");

                vfs.Unmount("/");

                vfs.Mount(disk, "/");
                RecursivelyPrintNodes(vfs.RootNode);

                disk.TurnOff();
            }
            catch (Exception ex)
            {
                Console.WriteLine("VFS test failed: " + ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }
Ejemplo n.º 2
0
        static void TestVirtualFileSystem()
        {
            try
            {
                Random r = new Random();

                VolatileDisk disk = new VolatileDisk(1);
                //PersistentDisk disk = new PersistentDisk(1, "disk1");
                disk.TurnOn();

                VirtualFS vfs = new VirtualFS();

                vfs.Format(disk);
                vfs.Mount(disk, "/");

                VirtualNode root = vfs.RootNode;
                VirtualNode dir1 = root.CreateDirectoryNode("dir1");
                VirtualNode dir2 = root.CreateDirectoryNode("dir2");
                dir2.CreateDirectoryNode("dir3");
                dir1.CreateDirectoryNode("dir4");
                dir2.CreateDirectoryNode("dir5");


                VirtualNode file1 = dir1.CreateFileNode("file1");
                VirtualNode file2 = dir1.CreateFileNode("file2");
                VirtualNode file3 = dir2.CreateFileNode("file3");
                VirtualNode file4 = dir2.CreateFileNode("file4");

                TestFileWriteRead(file1, r, 0, 100);    // 1 sector
                TestFileWriteRead(file1, r, 42, 77);

                TestFileWriteRead(file1, r, 0, 500);    // 2 sectors
                TestFileWriteRead(file1, r, 250, 500);  // 3 sectors
                TestFileWriteRead(file1, r, 275, 700);  // 4 sectors

                RecursivelyPrintNodes(vfs.RootNode);

                Console.WriteLine("Rename!");
                dir1 = vfs.RootNode.GetChild("dir1");
                dir1.Rename("newdir1");
                RecursivelyPrintNodes(vfs.RootNode);

                // Move something
                Console.WriteLine("Move!");
                dir2 = vfs.RootNode.GetChild("dir2");
                dir1.Move(dir2);
                RecursivelyPrintNodes(vfs.RootNode);

                // Make sure disk is correct
                Console.WriteLine("Unmount/mount!");
                vfs.Unmount("/");
                vfs.Mount(disk, "/");
                RecursivelyPrintNodes(vfs.RootNode);

                // Delete
                Console.WriteLine("Delete file!");
                VirtualNode file6 = vfs.RootNode.CreateFileNode("file6");
                file6.Write(0, CreateTestBytes(r, 1000));
                Console.WriteLine("File before deleting!");
                RecursivelyPrintNodes(vfs.RootNode);
                file6.Delete();
                Console.WriteLine("File after deleting!");
                RecursivelyPrintNodes(vfs.RootNode);

                // Delete directory
                Console.WriteLine("Delete Directory!");
                VirtualNode deleteDir2 = vfs.RootNode.GetChild("dir2");
                VirtualNode deleteDir1 = deleteDir2.GetChild("newdir1");
                //deleteDir2.Delete();
                deleteDir1.Delete();
                Console.WriteLine("...After deleting Directory!");
                RecursivelyPrintNodes(vfs.RootNode);

                disk.TurnOff();
                Console.WriteLine("TestVirtualFileSystem success!");
            }
            catch (Exception ex)
            {
                Console.WriteLine("VFS test failed: " + ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }