123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System;
- using DiscUtils;
- using DiscUtils.Ntfs;
- using DiscUtils.Partitions;
- using DiscUtils.Streams;
- using DiscUtils.Vhd;
- using System.IO;
- using System.Management;
- namespace SvdCli
- {
- internal class TasteProgram
- {
- private static void Main(string[] args)
- {
- var volumes = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Volume");
- foreach (ManagementObject volume in volumes.Get())
- {
- volume.Get();
- var letter = volume["DriveLetter"];
- var label = volume["Label"];
- if (label is string str && str == "RamDisk")
- {
- volume["DriveLetter"] = "Z:";
- volume.Put();
- }
- }
- }
- private static void CreateNtfsImage()
- {
- var diskSize = 5L * 1024 * 1024 * 1024;
- using (var fs = new FileStream(@"z:\test.img", FileMode.OpenOrCreate))
- {
- {
- VirtualDisk destDisk = DiscUtils.Raw.Disk.Initialize(fs, Ownership.None, diskSize);
- BiosPartitionTable.Initialize(destDisk, WellKnownPartitionType.WindowsNtfs);
- var volMgr = new VolumeManager(destDisk);
- var label = "ZZZZZZ";
- using (var destNtfs =
- NtfsFileSystem.Format(volMgr.GetLogicalVolumes()[0], label, new NtfsFormatOptions()))
- {
- destNtfs.CreateDirectory("temp");
- }
- //commit everything to the stream before closing
- fs.Flush();
- }
- }
- using (var fs = new FileStream(@"z:\test.img", FileMode.OpenOrCreate))
- {
- VirtualDisk destDisk = new DiscUtils.Raw.Disk(fs, Ownership.None);
- var volMgr = new VolumeManager(destDisk);
- using var sparseStream = volMgr.GetLogicalVolumes()[0].Open();
- new NtfsFileSystemChecker(sparseStream).Check(Console.Out, ReportLevels.All);
- }
- }
- }
- }
|