使用IOCTL_DISK_SET_DRIVE_LAYOUT创建分区后,如何在此新创建的分区中创建新卷? [英] After partition was created using IOCTL_DISK_SET_DRIVE_LAYOUT, how do I create new volume in this newly created partition?

查看:165
本文介绍了使用IOCTL_DISK_SET_DRIVE_LAYOUT创建分区后,如何在此新创建的分区中创建新卷?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用,但Win32_Volume仅返回连接到该目录的所有n个现有驱动器号现有分区,但就我而言,该驱动器号尚未分配。



有任何建议吗?

解决方案

长话短说(这确实是长话!),事实证明,我错误地选择了错误的 PartitionType 。以前,我使用PARTITION_EXTENDED 0x05,在尝试另一个值:PARTITION_IFS 0x07之后,Windows直接要求我格式化分区。为避免这种情况,请在此处,我们必须等待几秒钟,以便新的驱动器号可用,然后调用 kernel32.GetLogicalDriveStringsA 来查询新驱动器(您必须在创建分区之前先调用此驱动器,然后将其进行比较,然后才能获得新驱动器驱动器号)。如果有可用的驱动器号,我们可以轻松地调用 Win32_Volume Format 方法来格式化驱动器。



这是低级kernel32调用+ WMI的结合,可以成功解决此问题。如果所有功能都在WMI中可用,对我们来说将更加容易。但是,是的,这不是我们在这里遇到的。


I am trying to create a new partition, format it and assign it a new drive letter via Python ctypes, using IOCTL_SET_DRIVE_LAYOUT. My initial coding attempt was done using this SO page : Python ctypes structure being overwritten when allocating more memory. You can see the definition of class DeviceIoControl there.

I successfully initialize the disk using IOCTL_DISK_CREATE_DISK, and create a new partition having certain size using IOCTL_DISK_SET_DRIVE_LAYOUT, below are the result in Disk Management:

.. but then, how do I create new volume in disk newly created partition?

I've try to use format method of Win32_Volume, but Win32_Volume only return all the n existing drive letters attached to existing partitions, while in my case, that drive letter is not assigned yet.

Any advice?

解决方案

Long story short (it really is a long story!), turn out, I mistakenly choose a wrong PartitionType. Previously I use PARTITION_EXTENDED 0x05, which after I experiment with another value : PARTITION_IFS 0x07, Windows directly asked me to format the partition. And to avoid this, as asked here, we have to wait for several seconds for the new drive letter to be available, and then call kernel32.GetLogicalDriveStringsA to query the new drive (you have to call this previously before creating the partition, and comparing the two, you will get the new drive letter). As the drive letter available, we can easily call Win32_Volume Format method to format the drive.

This is a mix of low level kernel32 call + WMI that bring about a successful solution for this problem. It will be way easier for us if all the functions were available in WMI. But, yeah, that's not we encounter here.

这篇关于使用IOCTL_DISK_SET_DRIVE_LAYOUT创建分区后,如何在此新创建的分区中创建新卷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆