Beispiel #1
0
 public VirtualDrive(DiskDriver disk, int driveInfoSector, DRIVE_INFO sector)
 {
     mDisk               = disk;
     mDriveInfoSector    = driveInfoSector;
     mBytesPerDataSector = DATA_SECTOR.MaxDataLength(disk.BytesPerSector);
     mSector             = sector;
 }
Beispiel #2
0
        public void Format(DiskDriver disk)
        {
            //wipe the disk
            FREE_SECTOR freeSector = new FREE_SECTOR(disk.BytesPerSector);

            for (int i = 0; i < disk.SectorCount; i++)
            {
                disk.WriteSector(i, freeSector.RawBytes);
            }

            //format it
            DRIVE_INFO driveInfo = new DRIVE_INFO(disk.BytesPerSector, Constants.ROOT_DIR_SECTOR);

            disk.WriteSector(Constants.DRIVE_INFO_SECTOR, driveInfo.RawBytes);


            DIR_NODE rootNode = new DIR_NODE(disk.BytesPerSector, Constants.ROOT_DATA_SECTOR, "/", 0);

            disk.WriteSector(Constants.ROOT_DIR_SECTOR, rootNode.RawBytes);


            DATA_SECTOR rootData = new DATA_SECTOR(disk.BytesPerSector, 0, new byte[1]);

            disk.WriteSector(Constants.ROOT_DATA_SECTOR, rootData.RawBytes);
        }
Beispiel #3
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();
        }
Beispiel #4
0
        public void Mount(DiskDriver disk, string mountPoint)
        {
            if (mDrives.Count == 0 && mountPoint.Length != 1 && mountPoint[0] != '/')
            {
                throw new Exception("First disk must be mounted at the root");
            }

            //add virtual drive
            DRIVE_INFO   driveInfo = DRIVE_INFO.CreateFromBytes(disk.ReadSector(Constants.DRIVE_INFO_SECTOR));
            VirtualDrive newDrive  = new VirtualDrive(disk, Constants.DRIVE_INFO_SECTOR, driveInfo);

            mDrives.Add(mountPoint, newDrive);

            //add root dir, make node, add it
            int         rootNodeAt      = driveInfo.RootNodeAt;
            DIR_NODE    newDriveRootDir = DIR_NODE.CreateFromBytes(disk.ReadSector(rootNodeAt));
            VirtualNode virtualNode     = new VirtualNode(newDrive, rootNodeAt, newDriveRootDir, null);

            if (mDrives.Count == 1)
            {
                mRootNode = virtualNode;
            }
        }