1

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?

scopchanov
  • 7,966
  • 10
  • 40
  • 68
Gkhan
  • 103
  • 1
  • 9

1 Answers1

2

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";
} 
HMD
  • 2,202
  • 6
  • 24
  • 37
  • Thank you for your suggestion i think it will work.How can i have CAP_SYS_ADMIN privilage? – Gkhan Nov 08 '17 at 05:51
  • You are welcome, checkout [this](https://stackoverflow.com/questions/26504457/how-to-use-cap-sys-admin) to learn how to have `CAP_SYS_ADMIN`. – HMD Nov 08 '17 at 06:38
  • i examined this link.What is 'ep executable-name' – Gkhan Nov 08 '17 at 06:48
  • It's not `ep executable-name`. it's `cap_sys_admin+ep` and `executable-name`. Here `executable-name` refers to your application (binary) name, The file that you execute for your application to run. – HMD Nov 08 '17 at 06:51
  • i exactly write this ; sudo setcap cap_sys_admin+ep /appFilepath/app.run .But didn't work – Gkhan Nov 08 '17 at 07:11
  • hmm... write what? – HMD Nov 08 '17 at 07:13
  • i wrote application path+application name after cap_sys_admin+ep – Gkhan Nov 08 '17 at 07:15
  • What didn't work? the command or `umount` function? did you get `libcap` package? – HMD Nov 08 '17 at 07:15
  • i just downloaded libcap package .What will i do with this ? – Gkhan Nov 08 '17 at 07:27
  • You need to install the package, if you don't know how to do that you can either learn how to install package on you Linux machine or ask another question to get help for that, the rule is `one question per topic`. – HMD Nov 08 '17 at 07:35
  • Ok.Thanks for your answers. – Gkhan Nov 08 '17 at 08:42
  • By the i opened new title.https://stackoverflow.com/questions/47175017/how-to-install-package-on-linux – Gkhan Nov 08 '17 at 08:57