问题
I am developing linux kernel module to perform read/write operations. It reads an input file and write the content to an output file. I have to introduce atomic mode to my code. I wanted to know if there is a way to revert changes from a written file in case of partial write for atomic mode.
I want to delete all content I have written to an output file in case my programs gives an error.
Please reply.
回答1:
I want to delete all content I have written to an output file in case my programs gives an error.
I would avoid developing a kernel module for that purpose.
You can simply do that in the shell or in the application code: write(2) into some temporary file, then rename(2) the file on success or unlink(2) it on failure. Or you could do that in some shell script (e.g. redirecting stdout to a temporary file, then mv
or rm
it). You need to understand more what inodes are.
If you insist on having something kernel related, consider FUSE
NB: kernel code is usually not expected to write files. Only application code are writing files, using some filesystem code in the kernel.
PS: You might be perhaps interested by inotify(7).
来源:https://stackoverflow.com/questions/22111933/linux-kernel-module-atomic-mode