简体   繁体   中英

How to capture and modify read and writes on file using Dlang or cpp

Let's say that another program is to write or read a specific file. When it does that, I need to be able to take that read or write and handle the way I like (for example, program X wants to read a file located at /path/file.txt, but program Y (my program) takes that read "request" and instead gives program X the encryption first 2KiB of another file located at /path/file2). Essentially, any time a specified file is being read or written to, my program will be called and it will handle the read or write request in Dlang or C++. I cannot create a new file system for this :( and it has to at least work with Linux (so anything specific to Linux works). Also, it is crucial that I RESPOND to the read or write and not preprocess the result, sorry this was not clear in the example.

What you need is a seek-able FIFO (named pipe). It has been proposed but as far as I know it has not been implemented yet (check Linux kernel changelogs, maybe it has but I do not know about it).

As suggested, a new, tiny filesystem is your best option. Luckily it is pretty simple to write one with the FUSE project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM