获取分区在Windows列表 [英] Obtain a list of partitions on Windows

查看:142
本文介绍了获取分区在Windows列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我移植文件系统到Windows,和我写贴片机可执行更多的Windows类似的界面。这个过程的一部分是让用户找到一个分区,并选择一个驱动器号。最终分区的选择已经导致一些我可以用开的CreateFile()的open() fopen()函数或相似的。

I'm porting a filesystem to Windows, and am writing a more Windows-like interface for the mounter executable. Part of this process is letting the user locate a partition and pick a drive letter. Ultimately the choice of partition has to result in something I can open using CreateFile(), open(), fopen() or similar.

的Windows似乎围绕卷,这似乎不太类似于磁盘的概念,并只出现对于已经安装的文件系统。

Windows seems to revolve around the concept of volumes, which don't seem quite analogous to disks, and only occur for already mounted filesystems.

有前途的线索我已经包括:

Promising leads I've had include:

  • IOCTL_DISK_GET_DRIVE_LAYOUT_EX
  • Physical Disks and Volumes
  • Displaying Volume Paths

然而,这些都结束卷或抵消其,而不是的/ dev / sda1的分区的特定风格处理我了。

However these all end in volumes or offsets thereof, not the /dev/sda1 partition-specific-style handle I'm after.

这个问题是一个非常类似的事情后,我认为是一个赏金,直到我观察OP后是物理磁盘的名称,而不是分区。 这个答案包含方法蛮力分区名称,我想想避免(或看到一个包含文件范围为可能的路径)。

This question is after a very similar thing, I considered a bounty until I observed the OP is after physical disk names, not partitions. This answer contains a method to brute force partition names, I'd like to avoid that (or see documentation containing bounds for the possible paths).

我想:


  • 正确的术语和未挂载分区的文件在Windows中。

  • 一个有效的和记录的方法来获取可靠所有可用的分区。

  • 最接近适合分区的文件抽象在Linux中可用,其中所有IO绑定到磁盘分区的相应区域中打开。

虽然主要目的仍然是打开原始分区,它出现在溶液可以包括第一获取的句柄每个磁盘驱动器,然后使用依次获取每个分区。如何枚举所有磁盘驱动器(即使那些没有安装卷上它们了)是必需的。

While the main goal is still opening raw partitions, it appears the solution may involve first acquiring a handle to each disk drive, and then using that in turn to acquire each partition. How to enumerate all the disk drives (even those without mounted volumes on them already) is required.

推荐答案

正如你指出,你可以使用的 IOCTL_DISK_GET_DRIVE_LAYOUT_EX 来获得分区的列表。

As you noted, you can use IOCTL_DISK_GET_DRIVE_LAYOUT_EX to get a list of partitions.

有相关概念很好地概括这里。不知缺少的环节对你来说是

There's a good overview of the related concepts here. I wonder if the missing link for you is

检测硬盘的类型

有没有具体的功能,以
  编程方式检测的类型
  磁盘上的特定文件或目录
  位于。有间接
  方法。

There is no specific function to programmatically detect the type of disk a particular file or directory is located on. There is an indirect method.

首先,请拨打 GetVolumePathName 。然后,
  叫的CreateFile 来打开音量
  使用的路径。接下来,使用
   IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
  与卷手柄,以获得
  磁盘数量和使用的磁盘数量
  构建磁盘路径,如
  \\?\\ PhysicalDriveX。最后,使用
   IOCTL_DISK_GET_DRIVE_LAYOUT_EX
  获取分区列表,并检查
  的PARTITIONTYPE在每个条目
  分区列表。

First, call GetVolumePathName. Then, call CreateFile to open the volume using the path. Next, use IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS with the volume handle to obtain the disk number and use the disk number to construct the disk path, such as "\?\PhysicalDriveX". Finally, use IOCTL_DISK_GET_DRIVE_LAYOUT_EX to obtain the partition list, and check the PartitionType for each entry in the partition list.

磁盘管理控制$的全部名单C $ CS 的可能有更多的,这将是有益的。说实话,我不知道怎么的Unix分区名称映射到Windows,也许它只是不直接。

The full list of disk management control codes may have more that would be useful. To be honest I'm not sure how the Unix partition name maps onto Windows, maybe it just doesn't directly.

这篇关于获取分区在Windows列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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