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

                SlowDisk disk = new SlowDisk(1);
                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");

                VirtualNode file1 = dir1.CreateFileNode("file1");
                TestFileWriteRead(file1, r, 0, 100);
                TestFileWriteRead(file1, r, 0, 500);
                TestFileWriteRead(file1, r, 250, 100);

                vfs.Unmount("/");

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

                disk.TurnOff();
            }
            catch (Exception ex)
            {
                Console.WriteLine("VFS test failed: " + ex.Message);
            }
        }
Esempio n. 2
0
        static void TestPhysicalFileSystem()
        {
            SlowDisk disk = new SlowDisk(1);

            disk.TurnOn();

            int SECTOR_SIZE = disk.BytesPerSector;

            //free sector
            {
                FREE_SECTOR freeWrite = new FREE_SECTOR(disk.BytesPerSector);
                disk.WriteSector(0, freeWrite.RawBytes);
                FREE_SECTOR freeRead = FREE_SECTOR.CreateFromBytes(disk.ReadSector(0));
                CheckSectorBytes(freeWrite, freeRead);
            }

            //drive info
            {
                DRIVE_INFO driveWrite = new DRIVE_INFO(disk.BytesPerSector, 101);
                disk.WriteSector(1, driveWrite.RawBytes);
                DRIVE_INFO driveRead = DRIVE_INFO.CreateFromBytes(disk.ReadSector(1));
                CheckSectorBytes(driveWrite, driveRead);
            }

            //dir node
            {
                DIR_NODE dirWrite = new DIR_NODE(disk.BytesPerSector, 103, "dir1", 10);
                disk.WriteSector(2, dirWrite.RawBytes);
                DIR_NODE dirRead = DIR_NODE.CreateFromBytes(disk.ReadSector(2));
                CheckSectorBytes(dirWrite, dirRead);
            }

            //file node
            {
                FILE_NODE fileWrite = new FILE_NODE(disk.BytesPerSector, 104, "file1", 100);
                disk.WriteSector(3, fileWrite.RawBytes);
                FILE_NODE fileRead = FILE_NODE.CreateFromBytes(disk.ReadSector(3));
                CheckSectorBytes(fileWrite, fileRead);
            }

            //data sector
            {
                byte[] testData = new byte[DATA_SECTOR.MaxDataLength(disk.BytesPerSector)];
                for (int i = 0; i < testData.Length; i++)
                {
                    testData[i] = (byte)(i + 1);
                }

                DATA_SECTOR dataWrite = new DATA_SECTOR(disk.BytesPerSector, 105, testData);
                disk.WriteSector(4, dataWrite.RawBytes);
                DATA_SECTOR dataRead = DATA_SECTOR.CreateFromBytes(disk.ReadSector(4));
                CheckSectorBytes(dataWrite, dataRead);
            }

            disk.TurnOff();
        }
Esempio n. 3
0
        static void TestSeveralSectors()
        {
            SlowDisk disk = new SlowDisk(1);

            disk.TurnOn();

            byte[] testdata = new byte[disk.BytesPerSector];

            for (int i = 0; i < disk.BytesPerSector; i++)
            {
                testdata[i] = (byte)(i % 256);
            }

            TestSector(disk, 0, testdata);
            TestSector(disk, 1, testdata);
            TestSector(disk, disk.SectorCount - 1, testdata);
        }
Esempio n. 4
0
        static void TestfileSystem()
        {
            try
            {
                Random   r    = new Random();
                SlowDisk disk = new SlowDisk(1);
                disk.TurnOn();

                FileSystem fs = new SimpleFS();
                fs.Format(disk);
                fs.Mount(disk, "/");

                Directory root = fs.GetRootDirectory();
                root.CreateDirectory("Testing123");

                Directory dir = root.CreateDirectory("nested");

                File file = dir.CreateFile("nestedfile");

                FileStream filestream = file.Open();
                filestream.Write(0, CreateTestBytes(r, 142));
                filestream.Close();

                root.CreateFile("rootfile");

                fs.Find("/rootfile");
                FSEntry f        = fs.Find("/nested/nestedfile");
                string  fullname = f.FullPathName;

                RescursivelyPrintDirectories(root);

                fs.Unmount("/");
                disk.TurnOff();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Test File System failed. Ex: " + ex.Message);
            }
        }