Linux Kernel module Atomic mode

[亡魂溺海] 提交于 2019-12-13 04:16:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!