static void TestPhysicalFileSystem() { // try reading/writing various types of sectors // use CheckBytes() to compare what was written vs. read VolatileDisk disk = new VolatileDisk(1); disk.TurnOn(); // FREE_SECTOR FREE_SECTOR free1 = new FREE_SECTOR(disk.BytesPerSector); disk.WriteSector(0, free1.RawBytes); FREE_SECTOR free2 = FREE_SECTOR.CreateFromBytes(disk.ReadSector(0)); CheckBytes("Free1", free1, "free2", free2); Console.WriteLine("FREE_SECTOR successful"); // DRIVE_INFO int rootNodeAt = 1; DRIVE_INFO drive1 = new DRIVE_INFO(disk.BytesPerSector, rootNodeAt); disk.WriteSector(0, drive1.RawBytes); DRIVE_INFO drive2 = DRIVE_INFO.CreateFromBytes(disk.ReadSector(0)); CheckBytes("drive1", drive1, "drive2", drive2); Console.WriteLine("DRIVE_SECTOR successful"); // DIR_NODE DIR_NODE rootDir1 = new DIR_NODE(disk.BytesPerSector, 2, FSConstants.PATH_SEPARATOR.ToString(), 42); disk.WriteSector(rootNodeAt, rootDir1.RawBytes); DIR_NODE rootDir2 = DIR_NODE.CreateFromBytes(disk.ReadSector(rootNodeAt)); CheckBytes("rootDir1", rootDir1, "rootDir2", rootDir2); Console.WriteLine("DIR_NODE successful"); // FILE_NODE FILE_NODE file1 = new FILE_NODE(disk.BytesPerSector, 8, "file1", 1000); disk.WriteSector(5, file1.RawBytes); FILE_NODE file2 = FILE_NODE.CreateFromBytes(disk.ReadSector(5)); CheckBytes("file1", file1, "file2", file2); Console.WriteLine("FILE_NODE successful"); // DATA_SECTOR byte[] filedata = CreateTestBytes(new Random(), DATA_SECTOR.MaxDataLength(disk.BytesPerSector)); DATA_SECTOR data1 = new DATA_SECTOR(disk.BytesPerSector, 9, filedata); disk.WriteSector(8, data1.RawBytes); DATA_SECTOR data2 = DATA_SECTOR.CreateFromBytes(disk.ReadSector(8)); CheckBytes("data1", data1, "data2", data2); Console.WriteLine("DATA_SECTOR successful"); disk.TurnOff(); }
static void TestPhysicalFileSystem() { // try reading/writing various types of sectors // use CheckBytes() to compare what was written vs. read VolatileDisk disk = new VolatileDisk(1); disk.TurnOn(); // write free sector to disk FREE_SECTOR freeSector1 = new FREE_SECTOR(disk.BytesPerSector); disk.WriteSector(0, freeSector1.RawBytes); //read sector byte[] bytes = disk.ReadSector(0); FREE_SECTOR freeSector2 = FREE_SECTOR.CreateFromBytes(bytes); //check if what was read is what was written CheckBytes("free_sector1", freeSector1, "freeSector2", freeSector2); // write drive info sector to disk DRIVE_INFO diSector1 = new DRIVE_INFO(disk.BytesPerSector, 42); disk.WriteSector(0, diSector1.RawBytes); //read sector byte[] bytes2 = disk.ReadSector(0); DRIVE_INFO diSector2 = DRIVE_INFO.CreateFromBytes(bytes2); //check if what was read is what was written CheckBytes("diSector1", diSector1, "diSector2", diSector2); // TODO: DIR_NODE // TODO: FILE_NODE // TODO: DATA_SECTOR disk.TurnOff(); }
static void TestPhysicalFileSystem() { // try reading/writing various types of sectors // use CheckBytes() to compare what was written vs. read VolatileDisk disk = new VolatileDisk(1); disk.TurnOn(); // FREE_SECTOR // Initialize a FREE_SECTOR and write it to disk. FREE_SECTOR free1 = new FREE_SECTOR(disk.BytesPerSector); disk.WriteSector(0, free1.RawBytes); // REad the sector back and compare. byte[] freeBytes = disk.ReadSector(0); Console.WriteLine("Read sector 0, type = " + SECTOR.GetTypeFromBytes(freeBytes)); FREE_SECTOR free2 = FREE_SECTOR.CreateFromBytes(freeBytes); CheckBytes("Written Free sector", free1, "Read Free sector", free2); // TODO: DRIVE_INFO // TODO: DIR_NODE // TODO: FILE_NODE //FILE_NODE file1 = new FILE_NODE(disk.BytesPerSector, 11, "foo", 12); // DATA_SECTOR int datalen = DATA_SECTOR.MaxDataLength(disk.BytesPerSector); byte[] databytes = new byte[datalen]; DATA_SECTOR data1 = new DATA_SECTOR(disk.BytesPerSector, 42, databytes); disk.WriteSector(41, data1.RawBytes); disk.TurnOff(); }