Deny Mac system using cached data when copy

22 Views Asked by At

I'm developing a encrypt & decrypt filesystem on Mac. I use MacFuse to realize this filesystem and mount it under a folder.

By doing this I can hook the open file method when the user are trying to open the encrypted file(such as A.rtf) under the mounted folder. Then I will decrypt A.rtf and generate a new decrypted file, let's call it as B.rtf. In the hooked open file method, I will return B.rtf file descriptor so that the user can open the decrypted file.

All worked fine, until I opened the encrypted file once and copied it. It seems the Mac system directly uses the decrypted cache data when doing the copy, so the decrypted content will be copied.

I tried add fcntl(fd, F_NOCACHE, 1); fcntl(fd, F_NODIRECT, 1) after int fd = open([p UTF8String], mode);, but it not work.

After some research, I know that there is some relationship between the DesktopServicesHelper process and the copy operation, so I tried don't decrypt the file when system process DesktopServicesHelper trying to open the encrypted file. But it still does not work, the Mac system seems to directly hand over the cache data to the DesktopServicesHelper process, then DesktopServicesHelper creates a new file in the copy target path with decrypted data.

So is there a way to tell the Mac system not to cache my data when I open a file?

0

There are 0 best solutions below