Linux内核模块原子模式 [英] Linux Kernel module Atomic mode

查看:98
本文介绍了Linux内核模块原子模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发linux内核模块以执行读/写操作. 它读取输入文件并将内容写入输出文件. 我必须在代码中引入原子模式. 我想知道是否有一种方法可以在原子模式下进行部分写入的情况下从写入的文件中还原更改.

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.

请回复.

推荐答案

如果程序出现错误,我想删除已写入输出文件的所有内容.

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.

您可以简单地在外壳程序或应用程序代码中执行此操作:将(2)写入某个临时文件,然后重命名(2 )成功的文件或 unlink(2)失败时.或者您可以在某些Shell脚本中执行此操作(例如,将stdout重定向到一个临时文件,然后将其重定向为mvrm).您需要更多地了解 inodes .

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.

如果您坚持要与内核相关,请考虑 FUSE

If you insist on having something kernel related, consider FUSE

NB:通常不希望内核代码写入文件.仅应用程序代码使用以下文件中的文件系统代码编写文件内核.

NB: kernel code is usually not expected to write files. Only application code are writing files, using some filesystem code in the kernel.

PS:您可能对 inotify(7)感兴趣a>.

PS: You might be perhaps interested by inotify(7).

这篇关于Linux内核模块原子模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆