Linux 内核模块中的文件 I/O [英] File I/O in a Linux kernel module

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

问题描述

我正在编写一个需要打开和读取文件的 Linux 内核模块.实现这一目标的最佳方法是什么?

I'm writing a Linux kernel module that needs to open and read files. What's the best way to accomplish that?

推荐答案

请问您为什么要打开文件?

Can I ask why are you trying to open a file?

我喜欢关注 Linux 的开发(出于好奇,我不是内核开发人员,我是做 Java 的),之前看到过关于这个问题的讨论.我能够找到关于此的 LKML 消息,基本上提到这通常是一个坏主意.我几乎肯定 LWN 在去年就报道了它,但我找不到这篇文章.

I like to follow Linux development (out of curiosity, I'm not a kernel developer, I do Java), and I've seen discussion of this question before. I was able to find a LKML message about this, basically mentioning it's usually a bad idea. I'm almost positive that LWN covered it in the last year, but I'm having trouble finding the article.

如果这是一个私有模块(比如一些自定义硬件并且模块不会被分发)那么你可以这样做,但我的印象是如果你要提交你的代码到主线然后可能不被接受.

If this is a private module (like for some custom hardware and the module won't be distributed) then you can do this, but I'm under the impression that if you are going to submit your code to the mainline then it may not be accepted.

Evan Teran 提到了 sysfs,这对我来说似乎是个好主意.如果你真的需要做更难的自定义东西,你总是可以制作新的 ioctrls.

Evan Teran mentioned sysfs, which seems like a good idea to me. If you really need to do harder custom stuff you could always make new ioctrls.

好的,我找到了我要找的文章,它来自 Linux Journal.它解释了为什么做这种事情通常是一个坏主意,然后继续告诉你到底该怎么做.

OK, I found the article I was looking for, it's from Linux Journal. It explains why doing this kind of stuff is generally a bad idea, then goes on to tell you exactly how to do it anyway.

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

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