gpt4 book ai didi

c++ - 获取 Windows 上的分区列表

转载 作者:可可西里 更新时间:2023-11-01 12:43:33 25 4
gpt4 key购买 nike

目标

我正在将一个文件系统移植到 Windows,并且正在为安装器可执行文件编写一个更像 Windows 的界面。这个过程的一部分是让用户找到一个分区并选择一个驱动器号。最终,分区的选择必须导致我可以使用 CreateFile()open()fopen() 或类似方法打开的内容。

线索

Windows 似乎围绕卷的概念展开,它似乎与磁盘不太相似,并且只出现在已经安装的文件系统上。

我获得的有前途的线索包括:

然而,这些都以卷或其偏移量结尾,而不是我所追求的 /dev/sda1 分区特定样式句柄。

This question 是在一个非常相似的事情之后,我认为是赏金,直到我观察到 OP 是在物理磁盘名称之后,而不是分区之后。 This answer 包含一种暴力破解分区名称的方法,我想避免这种情况(或查看包含可能路径边界的文档)。

问题

我愿意:

  • 正确的术语和 Windows 中卸载分区的文档。
  • 可靠地检索所有可用分区的有效且记录在案的方法。
  • 最接近 Linux 中可用的分区文件抽象,其中所有 IO 都绑定(bind)到磁盘的适当区域以打开分区。

更新0

虽然主要目标仍然是打开原始分区,但看起来解决方案可能涉及首先获取每个磁盘驱动器的句柄,然后依次使用它来获取每个分区。需要如何枚举所有磁盘驱动器(甚至是那些尚未安装卷的磁盘驱动器)。

最佳答案

如您所述,您可以使用 IOCTL_DISK_GET_DRIVE_LAYOUT_EX获取分区列表。

相关概念有很好的概述here .我想知道您缺少的链接是否是

Detecting the Type of Disk

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.

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.

完整列表disk management control codes可能有更多有用的东西。老实说,我不确定 Unix 分区名称是如何映射到 Windows 上的,也许只是不直接映射。

关于c++ - 获取 Windows 上的分区列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4042212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com