gpt4 book ai didi

linux - QT umount() 函数不起作用

转载 作者:太空狗 更新时间:2023-10-29 12:40:21 26 4
gpt4 key购买 nike

当我写下这段代码时;

int removeUSB = umount("/media/pi/USB_Device");
if(!removeUSB)
qDebug()<<"USB is removed.";
else
qDebug()<<"USB is not removed."

USB 无法移除。我正在调试屏幕中显示“USB 未移除”消息。我错过了什么?感谢您的所有回答。

最佳答案

我相信您正在调用的umount 函数不是QT 函数,它是由glibc 库提供的函数。请参阅:umount(2)手册页和 glibc documentation for mount/umount .

这两个页​​面都说如果卸载调用不成功,它会返回 -1 并将全局变量 errno 设置为错误代码。错误代码可以在 errno 上找到手册页。

您可能会看到如下错误:

if(umount("/media/pi/USB_Device")) 
qDebug()<<"Error removing USB Deviced: " << strerror(errno);
else
qDebug()<<"USB is removed."

strerror 函数将错误代码转换为人类可读的字符串。

无法卸载设备的可能原因包括:

  • 您的进程或某些其他进程可能在设备中打开了一个文件,在这种情况下,返回的错误号将是 EBUSY。 lsof 命令对于确定哪个进程使文件系统繁忙非常有用。

  • 运行该进程的用户可能没有所需的权限,在这种情况下,错误代码将为 EPERM。

关于linux - QT umount() 函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47195274/

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