简体   繁体   English

使用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?

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 . 我正在尝试创建一个新分区,对其进行格式化,并使用IOCTL_SET_DRIVE_LAYOUT通过Python ctypes为其分配新的驱动器 My initial coding attempt was done using this SO page : Python ctypes structure being overwritten when allocating more memory . 我最初的编码尝试是使用此SO页面完成的: 分配更多内存时,Python ctypes结构被覆盖 You can see the definition of class DeviceIoControl there. 您可以在那里看到class DeviceIoControl的定义。

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: 我使用IOCTL_DISK_CREATE_DISK成功初始化了磁盘,并使用IOCTL_DISK_SET_DRIVE_LAYOUT创建了具有一定大小的新分区,以下是“磁盘管理”中的结果:

分区创建成功

.. 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. 我尝试使用Win32_Volume的格式方法,但Win32_Volume仅返回连接到现有分区的所有n个现有驱动器号,而在我的情况下,该驱动器号尚未分配。

Any advice? 有什么建议吗?

Long story short (it really is a long story!), turn out, I mistakenly choose a wrong PartitionType . 长话短说(这确实是长话!),结果,我错误地选择了错误的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. 以前,我使用PARTITION_EXTENDED 0x05,在尝试了另一个值:PARTITION_IFS 0x07后,Windows直接要求我格式化分区。 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). 为了避免这种情况,如这里所要求的,我们必须等待几秒钟以使新的驱动器号可用,然后调用kernel32.GetLogicalDriveStringsA来查询新的驱动器(在创建分区并进行比较之前,必须先调用此驱动器)两者,您将获得新的驱动器号)。 As the drive letter available, we can easily call Win32_Volume Format method to format the drive. 如果有可用的驱动器号,我们可以轻松地调用Win32_Volume Format方法来格式化驱动器。

This is a mix of low level kernel32 call + WMI that bring about a successful solution for this problem. 这是低级kernel32调用+ WMI的组合,可以成功解决此问题。 It will be way easier for us if all the functions were available in WMI. 如果所有功能都在WMI中可用,对我们来说将更加容易。 But, yeah, that's not we encounter here. 但是,是的,这不是我们在这里遇到的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM