Linux Kernel module Atomic mode

2019-08-18 01:13发布

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条回答
爷的心禁止访问
2楼-- · 2019-08-18 01:43

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).

查看更多
登录 后发表回答