Ejemplo 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);
        }
Ejemplo n.º 2
0
        private DRIVE_INFO sector;      // caching entire sector for now

        public VirtualDrive(DiskDriver disk, int driveInfoSector, DRIVE_INFO sector)
        {
            this.disk               = disk;
            this.driveInfoSector    = driveInfoSector;
            this.bytesPerDataSector = DATA_SECTOR.MaxDataLength(disk.BytesPerSector);
            this.sector             = sector;
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public void Mount(DiskDriver disk, string mountPoint)
        {
            // for the first mounted drive, expect mountPoint to be named FSConstants.PATH_SEPARATOR as the root
            if (drives.Count == 0 && mountPoint != FSConstants.PATH_SEPARATOR.ToString())
            {
                throw new Exception("Expected first mounted dist to be at root directory!");
            }

            // read drive info from disk, load root node and connect to mountPoint

            DRIVE_INFO   driveInfo = DRIVE_INFO.CreateFromBytes(disk.ReadSector(DRIVE_INFO_SECTOR));
            VirtualDrive drive     = new VirtualDrive(disk, DRIVE_INFO_SECTOR, driveInfo);

            DIR_NODE rootSector = DIR_NODE.CreateFromBytes(disk.ReadSector(ROOT_DIR_SECTOR));

            rootNode = new VirtualNode(drive, ROOT_DIR_SECTOR, rootSector, null);

            drives.Add(mountPoint, drive);
        }
Ejemplo n.º 6
0
        public void Mount(DiskDriver disk, string mountPoint)
        {
            // read drive info from disk, load root node and connect to mountPoint
            // for the first mounted drive, expect mountPoint to be named FSConstants.ROOT_DIR_NAME as the root

            //read drive info for disk to determin what sector contains its root node
            DRIVE_INFO diSector = DRIVE_INFO.CreateFromBytes(disk.ReadSector(DRIVE_INFO_SECTOR));

            int rootNodeAt = diSector.RootNodeAt;

            VirtualDrive drive = new VirtualDrive(disk, DRIVE_INFO_SECTOR, diSector);

            DIR_NODE rootNodeSector = DIR_NODE.CreateFromBytes(disk.ReadSector(rootNodeAt));

            if (rootNode == null)
            {
                rootNode = new VirtualNode(drive, rootNodeAt, rootNodeSector, null);
            }

            drives.Add(mountPoint, drive);
        }
Ejemplo n.º 7
0
        public void Mount(DiskDriver disk, string mountPoint)
        {
            // read drive info from disk, load root node and connect to mountPoint
            // for the first mounted drive, expect mountPoint to be named "/", FSConstants.ROOT_DIR_NAME, as the root

            try
            {
                // Step 1: Read infor from the disk to understand it's directory structure
                // Read DRIVE_INFO from FRIVE_INFO_SECTOR
                DRIVE_INFO  di = DRIVE_INFO.CreateFromBytes(disk.ReadSector(DRIVE_INFO_SECTOR));
                DIR_NODE    dn = DIR_NODE.CreateFromBytes(disk.ReadSector(di.RootNodeAt));
                DATA_SECTOR ds = DATA_SECTOR.CreateFromBytes(disk.ReadSector(dn.FirstDataAt));


                // Step 2: Join th new disk into the virtual file system structure, at the mount point.
                // Create a VistualDrive for the disk
                VirtualDrive vd = new VirtualDrive(disk, DRIVE_INFO_SECTOR, di);


                if (rootNode == null)
                {
                    // Create a VirtualNode to represent the root dictionaru, at the mount point.
                    // Set the VFS's root node, if this is the first disk to be mounted.
                    rootNode = new VirtualNode(vd, di.RootNodeAt, dn, null);
                }
                else
                {
                    // TODO: Extra Credit:  Handle 2nd dick mounted to exsisting VFS
                    // Create a virtual node for this new disk's root
                    // "join" the new node to the exsisting node structure at the mount point
                }

                // Add a new VirtualDrive to drives dictionary, using te mountPoint as the key
                drives.Add(mountPoint, vd);
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to mount disk");
            }
        }