TasteProgram.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using DiscUtils;
  3. using DiscUtils.Ntfs;
  4. using DiscUtils.Partitions;
  5. using DiscUtils.Streams;
  6. using DiscUtils.Vhd;
  7. using System.IO;
  8. using System.Management;
  9. namespace SvdCli
  10. {
  11. internal class TasteProgram
  12. {
  13. private static void Main(string[] args)
  14. {
  15. var volumes = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Volume");
  16. foreach (ManagementObject volume in volumes.Get())
  17. {
  18. volume.Get();
  19. var letter = volume["DriveLetter"];
  20. var label = volume["Label"];
  21. if (label is string str && str == "RamDisk")
  22. {
  23. volume["DriveLetter"] = "Z:";
  24. volume.Put();
  25. }
  26. }
  27. }
  28. private static void CreateNtfsImage()
  29. {
  30. var diskSize = 5L * 1024 * 1024 * 1024;
  31. using (var fs = new FileStream(@"z:\test.img", FileMode.OpenOrCreate))
  32. {
  33. {
  34. VirtualDisk destDisk = DiscUtils.Raw.Disk.Initialize(fs, Ownership.None, diskSize);
  35. BiosPartitionTable.Initialize(destDisk, WellKnownPartitionType.WindowsNtfs);
  36. var volMgr = new VolumeManager(destDisk);
  37. var label = "ZZZZZZ";
  38. using (var destNtfs =
  39. NtfsFileSystem.Format(volMgr.GetLogicalVolumes()[0], label, new NtfsFormatOptions()))
  40. {
  41. destNtfs.CreateDirectory("temp");
  42. }
  43. //commit everything to the stream before closing
  44. fs.Flush();
  45. }
  46. }
  47. using (var fs = new FileStream(@"z:\test.img", FileMode.OpenOrCreate))
  48. {
  49. VirtualDisk destDisk = new DiscUtils.Raw.Disk(fs, Ownership.None);
  50. var volMgr = new VolumeManager(destDisk);
  51. using var sparseStream = volMgr.GetLogicalVolumes()[0].Open();
  52. new NtfsFileSystemChecker(sparseStream).Check(Console.Out, ReportLevels.All);
  53. }
  54. }
  55. }
  56. }