如何使用 C++ 列出连接到 Linux 计算机的硬盘?
我需要使用 C++ 列出连接到 Linux 计算机的硬盘驱动器。
是否有任何 C 或 C++ 函数可以执行此操作?
I need to list the harddisk drives attached to the Linux machine using the C++.
Is there any C or C++ function available to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
没有。没有标准 C 或 C++ 函数可以做到这一点。您将需要一个 API。
但你可以使用:
Nope. No standard C or C++ function to do that. You will need a API.
But you can use:
看看我制作的这个简单的 /proc/mounts 解析器。
Take a look at this simple /proc/mounts parser I made.
您可以使用 libparted
http://www.gnu.org/software/parted/api/
ped_device_probe_all() 是检测设备的调用。
You can use libparted
http://www.gnu.org/software/parted/api/
ped_device_probe_all() is the call to detect the devices.
它不是一个函数,但您可以从 /proc/partitions 读取活动内核分区或从 /sys/block 的目录列表中列出所有块设备
Its not a function, but you can read the active kernel partitions from /proc/partitions or list all the block devices from dir listing of /sys/block