Ejemplo n.º 1
0
        private void GetDiskFSInfoSector()
        {
            DiskStream.Seek(512, SeekOrigin.Begin);
            byte[] bTemp = new byte[512];
            DiskStream.Read(bTemp, 0, 512);
            DiskFSInfoSector = new FSInfoSector(bTemp);

            //Actualizamos espacio libre aprox
            long spaceAvailableBytes = DiskFSInfoSector.GetFreeClusterCount() * DiskBootSector.GetBytesPerCluster();

            //GB
            if (spaceAvailableBytes >= (1024 * 1024 * 1024))
            {
                float tamano = spaceAvailableBytes / (1024 * 1024 * 1024);
                freeSpaceAvailable.Text = "" + tamano + " GB";
            }
            //MB
            else if (spaceAvailableBytes >= (1024 * 1024))
            {
                float tamano = spaceAvailableBytes / (1024 * 1024);
                freeSpaceAvailable.Text = "" + tamano + " MB";
            }
            //KB
            else if (spaceAvailableBytes >= 1024)
            {
                float tamano = spaceAvailableBytes / 1024;
                freeSpaceAvailable.Text = "" + tamano + " KB";
            }
            else
            {
                freeSpaceAvailable.Text = "" + spaceAvailableBytes + " bytes";
            }
        }
Ejemplo n.º 2
0
        public FilesystemInformation(BootSector BS, FSInfoSector FSInfo)
        {
            InitializeComponent();
            this.MaximumSize = this.MinimumSize = this.Size;
            BootSector       = BS;
            FSInfoSector     = FSInfo;

            //General
            this.volumeIDLabel.Text = BootSector.GetVolumeID();
            this.volumeLabel.Text   = BootSector.GetVolumeLabel();

            //Boot Sector
            this.labelBPS.Text = BootSector.GetBytesPerSector().ToString();
            this.labelSPC.Text = BootSector.GetSectorsPerCluster().ToString();
            this.labelSectoresReservados.Text = BootSector.GetReservedSectors().ToString();
            this.labelTotalSectores.Text      = BootSector.GetTotalSectoresFAT32().ToString();
            this.labelFATSize.Text            = BootSector.SizeOfFAT().ToString();

            //FSInfo Sector
            this.lastAllocatedCluster.Text = FSInfoSector.GetLastAllocatedCluster().ToString();
            this.freeClusters.Text         = FSInfoSector.GetFreeClusterCount().ToString();

            //File Allocation Table
            fatSize.Text    = BootSector.SizeOfFAT().ToString();
            fat1Offset.Text = BootSector.FATOffset().ToString();
            fat2Offset.Text = BootSector.FAT2Offset().ToString();
        }
Ejemplo n.º 3
0
        private void Formatear()
        {
            try
            {
                if (DiskStream != null)
                {
                    //Nulificar archivo
                    DiskStream.Seek(0, SeekOrigin.Begin);
                    DiskStream.SetLength(0);
                    DiskStream.Flush();
                    DiskStream.SetLength(DiskSize);
                    DiskStream.Flush();

                    //Escribir el BootSector
                    BootSector BootSector = new BootSector((int)DiskStream.Length, NewsectorPorCluster, NewVolumeLabel);
                    BootSector.WriteBootSector(DiskStream);

                    //Escribir FSInfoSector
                    FSInfoSector FSInfoSector = new FSInfoSector();
                    FSInfoSector.WriteInformationSector(DiskStream);

                    //Inicializar Tabla FAT - Offset 32 despues de los sectores reservados
                    FileAllocationTable NewFAT = new FileAllocationTable(BootSector);
                    NewFAT.WriteNewFAT(DiskStream);
                    FSInfoSector.UpdateFreeClusters(1, BootSector);
                    FSInfoSector.UpdateLastAllocatedCluster(2);
                    FSInfoSector.WriteInformationSector(DiskStream);

                    MessageBox.Show("La imagen de disco ha sido formateada!", "Formato Completo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 4
0
        private void Formatear(FileStream stream)
        {
            try
            {
                byte SectoresPorCluster = 0x00;

                //Obtener el numero de sectores por cluster
                switch (tamanoSectoresPorCluster.SelectedIndex)
                {
                case 0:
                    //1 sector por cluster = Clusters de 512 bytes
                    SectoresPorCluster = 0x01;
                    break;

                case 1:
                    //2 sectores por cluster = Clusters de 1 KiB
                    SectoresPorCluster = 0x02;
                    break;

                case 2:
                    //4 sectores por cluster = Clusters de 2 KiB
                    SectoresPorCluster = 0x04;
                    break;

                case 3:
                    //8 sectores por cluster = Clusters de 4 KiB
                    SectoresPorCluster = 0x08;
                    break;

                case 4:
                    //16 sectores por cluster = Clusters de 8 KiB
                    SectoresPorCluster = 0x10;
                    break;

                case 5:
                    //32 sectores por cluster = Clusters de 16KiB
                    SectoresPorCluster = 0x20;
                    break;

                default:
                    SectoresPorCluster = 0x01;
                    break;
                }

                //Escribir el BootSector
                BootSector BootSector = new BootSector((int)stream.Length, SectoresPorCluster, txtVolLabel.Text);
                BootSector.WriteBootSector(stream);

                //Escribir FSInfoSector
                FSInfoSector FSInfoSector = new FSInfoSector();
                FSInfoSector.WriteInformationSector(stream);

                //Inicializar Tabla FAT - Offset 32, despues de los sectores reservados
                FileAllocationTable NewFAT = new FileAllocationTable(BootSector);
                NewFAT.WriteNewFAT(stream);
                FSInfoSector.UpdateFreeClusters(1, BootSector);
                FSInfoSector.UpdateLastAllocatedCluster(2);
                FSInfoSector.WriteInformationSector(stream);

                MessageBox.Show("La imagen de disco ha sido creada y formateada!", "Formato Completo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }