I am developing a Qt application for Linux (Ubuntu) in which I use USB drive to backup some content. Application should unmount the target drive after copying stuff. I have a udev
rule file to mount USB at a specific location with ENV{mount_options}="relatime,users,umask=0,uid=user,gid=user"
where user represents my user name.
I tried using this without any luck.
const char* usb = "/mnt/mountpoint/usbdrive";
if (!umount(usb))
{
qDebug() << "Device unmounted";
}
else
{
qDebug() << "Can't unmount" << strerror(errno); //this prints Operation not permitted
}
Could someone please help me here? Am I using umount
right?
Thanks in advance.
On Windows, you can unmount a drive by clicking the USB icon in the bottom-right side of the screen and then clicking Eject.
usb {mount | unmount} Description. Enables or disables the inserted USB drive. Command context. Manager ( # )
Open File Explorer by pressing Windows key + E . On the left, click This PC. On the right, right-click your USB flash drive. Select Eject.
Appropriate privilege (Linux: the CAP_SYS_ADMIN capability) is required to unmount file systems.
Per umount
the code is fine. However you need privilege to umount devices.
The CAP_SYS_ADMIN capability allows a process to perform various administrative tasks, namely: calling mount(), umount(). There are two worth articles about capabilities here:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With