创建虚拟磁盘挂载点
我已使用 ImDisk 库和 .NET 包装器在我的 C# 应用程序中创建虚拟磁盘。但是,在创建设备后,我显然还需要创建一个挂载点,以便设备实际显示为驱动器号。我不完全理解应该为其提供什么来创建安装点,但我相信这更多地涉及虚拟设备而不是库。
我的函数:
public bool CreateRAMDisk()
{
// Create Empty RAM Disk
char driveLetter = ImDiskAPI.FindFreeDriveLetter();
ImDiskAPI.CreateDevice(52428800, 0, 0, 0, 0, ImDiskFlags.DeviceTypeHD | ImDiskFlags.TypeVM, null, false, driveLetter.ToString(), ref deviceID, IntPtr.Zero);
string mountPoint = driveLetter + @":\Device\ImDisk0";
ImDiskAPI.CreateMountPoint(mountPoint, deviceID);
// Format the Drive for NTFS
if (FormatDrive(driveLetter.ToString(), "NTFS", true, 4096, "", false))
{
CreateMountPoint 定义:
public static void CreateMountPoint(string Directory, uint DeviceNumber);
//
// Summary:
// Creates a mount point for an ImDisk virtual disk on an empty subdirectory
// on an NTFS volume.
//
// Parameters:
// Directory:
// Path to an empty subdirectory on an NTFS volume
//
// DeviceNumber:
// Device number of an existing ImDisk virtual disk
更新
FormatDrive 函数:
public static bool FormatDrive(string driveLetter, string fileSystem, bool quickFormat, int clusterSize, string label, bool enableCompression)
{
driveLetter = driveLetter + ":";
if (driveLetter.Length != 2 || driveLetter[1] != ':'|| !char.IsLetter(driveLetter[0]))
{
return false;
}
//query and format given drive
ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"select * from Win32_Volume WHERE DriveLetter = '" + driveLetter + "'");
foreach (ManagementObject vi in searcher.Get())
{
vi.InvokeMethod( "Format", new object[] {fileSystem, quickFormat, clusterSize, label, enableCompression} );
}
return true;
}
I have used the ImDisk library with the .NET wrapper to create a Virtual Disk in my C# application. However, after I create the device, I apparently need to create a Mount Point as well for the device to actually show as a Drive Letter. I don't completely understand what is supposed to be supplied for it to create a Mount Point, but I believe this pertains more to Virtual devices than the library.
My Function:
public bool CreateRAMDisk()
{
// Create Empty RAM Disk
char driveLetter = ImDiskAPI.FindFreeDriveLetter();
ImDiskAPI.CreateDevice(52428800, 0, 0, 0, 0, ImDiskFlags.DeviceTypeHD | ImDiskFlags.TypeVM, null, false, driveLetter.ToString(), ref deviceID, IntPtr.Zero);
string mountPoint = driveLetter + @":\Device\ImDisk0";
ImDiskAPI.CreateMountPoint(mountPoint, deviceID);
// Format the Drive for NTFS
if (FormatDrive(driveLetter.ToString(), "NTFS", true, 4096, "", false))
{
CreateMountPoint Definition:
public static void CreateMountPoint(string Directory, uint DeviceNumber);
//
// Summary:
// Creates a mount point for an ImDisk virtual disk on an empty subdirectory
// on an NTFS volume.
//
// Parameters:
// Directory:
// Path to an empty subdirectory on an NTFS volume
//
// DeviceNumber:
// Device number of an existing ImDisk virtual disk
UPDATE
FormatDrive Function:
public static bool FormatDrive(string driveLetter, string fileSystem, bool quickFormat, int clusterSize, string label, bool enableCompression)
{
driveLetter = driveLetter + ":";
if (driveLetter.Length != 2 || driveLetter[1] != ':'|| !char.IsLetter(driveLetter[0]))
{
return false;
}
//query and format given drive
ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"select * from Win32_Volume WHERE DriveLetter = '" + driveLetter + "'");
foreach (ManagementObject vi in searcher.Get())
{
vi.InvokeMethod( "Format", new object[] {fileSystem, quickFormat, clusterSize, label, enableCompression} );
}
return true;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,在 CreateDevice() 中传递的参数存在一些问题,这使得它不会生成错误,但无法完全完成设置过程。
感谢您的帮助!
Turns out their were some issues with the parameters being passed in CreateDevice(), which was allowing it to not generate errors but not fully completing the setup process.
Thanks for the help!
您必须在driveLetter参数末尾添加“:”
you must add ":" at the end of driveLetter parameter