Gkhan
Gkhan

Reputation: 133

Copying Text File to USB Stick

When I copy text file to USB Flash Memory with this line in Raspberry Pi 3;

if (QFile::copy(LastDayWaitListSource, LastDayWaitListTarget)) {
    qDebug() << "Copy OK";
}

Copy OK was appeared in the debug screen.

Then remove USB Flash memory from Raspberry Pi , and plug in to the Windows 10 Laptop to see the text file.There is no text file in USB flash memory.

Then I repeat same process with one different process.

After copying the text file, I opened the USB flash memory directory in Linux /media/pi/USB_Stick_Dir to see the copied text file. And I saw copied text file.Then I removed USB Flash memory from Raspberry Pi , and plug in to the Windows 10 Laptop and this time I saw the copied text file in Windows also.

Why is this happening?

Upvotes: 1

Views: 953

Answers (1)

HMD
HMD

Reputation: 2226

The problem is you are not unmounting your USB drive before removing it from your Linux system. try:

sudo umount /media/pi/USB_Stick_Dir

EDIT : You can do this inside your Qt program too, to do this you need to have CAP_SYS_ADMIN privilege.

The CAP_SYS_ADMIN capability allows a process to perform various administrative tasks, like calling mount()and umount(). You can do something like this to unmount your drive within your program :

int res = umount("/media/pi/USB_Stick_Dir")
if (!res) {
    qDebug() << "Device unmounted successfuly";
} 

Upvotes: 2

Related Questions