Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
        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);
        }
        public void Delete()
        {
            if (IsDirectory)
            {
                //nuke children
                LoadChildren();
                foreach (VirtualNode child in children.Values.ToArray())
                {
                    child.Delete();
                }
                CommitChildren();
            }

            // make sectors free!
            //overwirte node sector
            FREE_SECTOR freeSector = new FREE_SECTOR(drive.Disk.BytesPerSector);

            drive.Disk.WriteSector(nodeSector, freeSector.RawBytes);

            //overwrite data sectors
            int lba = DataSectorAt;

            while (lba != 0)
            {
                DATA_SECTOR dataSector = DATA_SECTOR.CreateFromBytes(drive.Disk.ReadSector(lba));
                drive.Disk.WriteSector(lba, freeSector.RawBytes);
                lba = dataSector.NextSectorAt;
            }

            // remove this node from it's parent node
            parent.LoadChildren();
            parent.children.Remove(Name);
            parent.CommitChildren();
        }
Esempio n. 5
0
        public void Delete()
        {
            /* make sectors free!
             * - wipe data for this node from the disk
             * - wipe this node from parent directory from the disk
             * - remove this node from it's parent node
             */

            // Don't try to nuke the root!
            if (parent == null)
            {
                throw new Exception("Can't delete the root!");
            }

            // Recurse into directory contents and delete children
            if (IsDirectory)
            {
                LoadChildren();
                // Loop throught a copy of the children cahce and delete each
                foreach (VirtualNode child in children.Values.ToArray())
                {
                    child.Delete();
                }
                // NOTE: do not need to call CommitChildren();
            }

            // Replace data sector(s) with free sector(s)
            FREE_SECTOR free         = new FREE_SECTOR(drive.Disk.BytesPerSector);
            int         dataSectorAt = sector.FirstDataAt;

            while (dataSectorAt != 0)
            {
                // Read the data sector om and save nextSectorAt
                DATA_SECTOR dataSector       = DATA_SECTOR.CreateFromBytes(drive.Disk.ReadSector(dataSectorAt));
                int         nextDataSectorAt = dataSector.NextSectorAt;

                // Replace it
                drive.Disk.WriteSector(dataSectorAt, free.RawBytes);

                // Next one
                dataSectorAt = nextDataSectorAt;
            }

            // Replace node sector with free sector
            drive.Disk.WriteSector(nodeSector, free.RawBytes);

            // Remove ourself from our parent and commit paren'ts list of children
            parent.LoadChildren();
            parent.children.Remove(Name);
            parent.CommitChildren();
        }
Esempio n. 6
0
        public void Delete()
        {
            // make sectors free!
            // wipe this node and sector(s) from the disk
            // remove this node from the virtual directory children list and commit to disk

            // if this is a file, then nuke its node sector and data sectors
            if (IsFile)
            {
                LoadBlocks();
                foreach (VirtualBlock vb in blocks)
                {
                    vb.DeleteBlock();
                }
                // empty the cache
                blocks = null;
            }

            // if directory, nuke just the node sector, Data sector, and children
            if (IsDirectory)
            {
                LoadChildren();
                foreach (VirtualNode vn in children.Values.ToList())
                {
                    vn.Delete();
                }
                children = null;

                // Delete data sector
                FREE_SECTOR freeData = new FREE_SECTOR(drive.Disk.BytesPerSector);
                drive.Disk.WriteSector(sector.FirstDataAt, freeData.RawBytes);
            }


            // remove this node from parent directory
            parent.LoadChildren();
            parent.children.Remove(Name);
            parent.CommitChildren();

            // Finally, free this nodes NODE_SECTOR
            FREE_SECTOR free = new FREE_SECTOR(drive.Disk.BytesPerSector);

            drive.Disk.WriteSector(nodeSector, free.RawBytes);
        }
Esempio n. 7
0
        public void DeleteBlock()
        {
            FREE_SECTOR free = new FREE_SECTOR(drive.Disk.BytesPerSector);

            drive.Disk.WriteSector(sectorAddress, free.RawBytes);
        }