gpt4 book ai didi

c++ - 在 Linux 上用 C++ 挂载 NTFS 设备?

转载 作者:IT王子 更新时间:2023-10-29 01:10:12 25 4
gpt4 key购买 nike

我正在尝试在我的 C++ 应用程序中安装外部驱动器。我最初尝试使用 mount(2) 但失败了:

int ret = mount(deviceName.c_str(), mountPoint.c_str(), fsType.c_str(), 0, NULL);

errno 为 19,ENODEV(内核中未配置文件系统类型)

但是,如果我切换到使用 mount(8) 它工作正常:

std::string cmd = "mount -t " + fsType + " " + deviceName + " " + mountPoint;
int ret = system(cmd.c_str());

mount(2) 是否有不同的可接受文件系统类型列表?这是一个 ntfs 设备,所以我使用 ntfs-3g 作为 fstype。我检查了/proc/filesystems 并发现它没有列出,所以我尝试了 fuseblk 但这只是将错误更改为 22,EINVAL

使用 mount(2) 挂载 NTFS 设备的正确方法是什么?

最佳答案

mount.2 只是一个内核调用。 mount.8 是一个完整的外部工具,它的扩展超出了内核的功能。

我想您可能正在寻找 libmount这是一个库,实现了 mount.8 完成的整个安装魔法。较新的安装版本也使用它。它在 util-linux 中提供.

关于c++ - 在 Linux 上用 C++ 挂载 NTFS 设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12298401/

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