// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Spludlow.Io { public class Format { public static string FormatDisk(string volume, string fileSystem, string label) { //ReFS 4096 64K //NTFS 512 1024 2048 4096 8192 16K 32K 64K 128K 256K 512K 1M 2M //FAT 512 1024 2048 4096 8192 16K 32K 64K (128K, 256K for sector size > 512 bytes). //FAT32 512 1024 2048 4096 8192 16K 32K 64K (128K, 256K for sector size > 512 bytes). //exFAT 512, 1024, 2048, 4096, 8192, 16K, 32K, 64K, 128K, 256K, 512K, 1M, 2M, 4M, 8M, 16M, 32M. /// FS:filesystem Specifies the type of the file system(FAT, FAT32, exFAT, // NTFS, UDF, ReFS). List options = new List(); options.Add(volume); if (fileSystem != null) options.Add("/FS:" + fileSystem); options.Add("/V:" + label); options.Add("/Q"); // quick options.Add("/X"); // force options.Add("/Y"); // yes //options.Add("/A:" + "64K"); // allocation unit sizes StringBuilder arguments = new StringBuilder(); foreach (string option in options) { if (arguments.Length > 0) arguments.Append(" "); arguments.Append(option); } SpawnProcess.ProcessExitInfo info = Spludlow.SpawnProcess.Run(@"C:\Windows\System32\format.com", arguments.ToString(), 0); //Spludlow.Log.Report("FormatDisk " + volume, info.StandardOutput); if (info.ExitCode != 0 || info.StandardError.Length > 0) { Spludlow.Log.Error("FormatDisk " + volume + ", Exit Code:" + info.ExitCode, info.StandardError); throw new ApplicationException("FormatDisk Error " + info.ExitCode); } return info.StandardOutput; } } }