Exemplo n.º 1
0
        public void Format(DiskDriver disk)
        {
            // wipe all sectors of disk and create minimum required DRIVE_INFO, DIR_NODE and DATA_SECTOR

            // Wipe all sectors (replace with "zeroes" are FREE_SECTOR)
            int         bps  = disk.BytesPerSector;
            FREE_SECTOR free = new FREE_SECTOR(bps);

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

            // Create DRIVE_INFO
            DRIVE_INFO di = new DRIVE_INFO(bps, ROOT_DIR_SECTOR);

            disk.WriteSector(DRIVE_INFO_SECTOR, di.RawBytes);

            // Create and write the DIR_NODE for the root node...
            DIR_NODE dn = new DIR_NODE(bps, ROOT_DATA_SECTOR, FSConstants.ROOT_DIR_NAME, 0);

            disk.WriteSector(ROOT_DIR_SECTOR, dn.RawBytes);

            // ... and an empty DATA_SECTOR
            DATA_SECTOR ds = new DATA_SECTOR(bps, 0, null); // 0 = no next data sector, nul = empty set

            disk.WriteSector(ROOT_DATA_SECTOR, ds.RawBytes);
        }
Exemplo n.º 2
0
        public void Format(DiskDriver disk)
        {
            // wipe all sectors of disk and create minimum required DRIVE_INFO, DIR_NODE and DATA_SECTOR

            FREE_SECTOR free = new FREE_SECTOR(disk.BytesPerSector);

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

            // DRIVE_INFO
            DRIVE_INFO drive = new DRIVE_INFO(disk.BytesPerSector, ROOT_DIR_SECTOR);

            disk.WriteSector(DRIVE_INFO_SECTOR, drive.RawBytes);

            // DIR_NODE for root node
            DIR_NODE rootDir = new DIR_NODE(disk.BytesPerSector, ROOT_DATA_SECTOR, FSConstants.PATH_SEPARATOR.ToString(), 0);

            disk.WriteSector(ROOT_DIR_SECTOR, rootDir.RawBytes);

            // DATA_SECTOR for root node
            DATA_SECTOR data = new DATA_SECTOR(disk.BytesPerSector, 0, new byte[] { 0 });

            disk.WriteSector(ROOT_DATA_SECTOR, data.RawBytes);
        }
Exemplo n.º 3
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);
        }
        public void Format(DiskDriver disk)
        {
            // wipe all sectors of disk and create minimum required DRIVE_INFO, DIR_NODE and DATA_SECTOR

            //how many sectors
            int numSectors = disk.SectorCount;

            FREE_SECTOR freeSector = new FREE_SECTOR(disk.BytesPerSector);

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

            DRIVE_INFO diSector1 = new DRIVE_INFO(disk.BytesPerSector, ROOT_DIR_SECTOR);

            disk.WriteSector(0, diSector1.RawBytes);

            DIR_NODE rootDirSector = new DIR_NODE(disk.BytesPerSector, ROOT_DATA_SECTOR, FSConstants.ROOT_DIR_NAME, 0);

            disk.WriteSector(ROOT_DIR_SECTOR, rootDirSector.RawBytes);


            DATA_SECTOR rootDataSector = new DATA_SECTOR(disk.BytesPerSector, 0, new byte[DATA_SECTOR.MaxDataLength(disk.BytesPerSector)]);

            disk.WriteSector(ROOT_DATA_SECTOR, rootDataSector.RawBytes);
        }
Exemplo n.º 5
0
        static bool TestSector(DiskDriver disk, int lba, byte[] testdata)
        {
            disk.WriteSector(lba, testdata);
            byte[] s       = disk.ReadSector(lba);
            bool   success = Compare(testdata, s);

            Console.WriteLine("Compare " + success.ToString());

            return(success);
        }