字符设备权限问题
我希望能够直接写入字符设备。这就是我所做的:
cd /dev
mknod moo c 0 0
echo hello >> moo
我
bash: moo: Permission denied
尝试使用 chmod 为拥有用户提供写访问权限,如下所示:
chmod 777 moo
然后,当我尝试写入它时,我被告知该设备或地址不存在。 ls 另有通知。
另外值得注意的是,据我所知,将 0 0 作为主要次要数字对会导致 Linux 为设备提供一些方便。
我一定在这里遗漏了一些基本的东西,我认为设备节点可以被视为普通文件。谁能告诉我我做错了什么?理想情况下,我想创建一个所有者可以写入并且任何人都可以读取的字符设备节点(我知道 777 是这里的错误权限,我将在最终版本中修复它)。
我也(最初)尝试通过 Python 与它对话,这给了我同样的问题。
编辑:
0 0 是错误的做法。我曾经读过一篇文章,告诉我它会起作用,但它是骗人的。我需要做的是制作一个字符设备模块和一个匹配的节点,然后使用它
I want to be able to write directly to a character device. Here's what I do:
cd /dev
mknod moo c 0 0
echo hello >> moo
I get
bash: moo: Permission denied
I tried using chmod to give the owning user write access like so:
chmod 777 moo
Then when I tried writing to it I was informed that the device or address does not exist. ls informs me otherwise.
Also worth noting is that as far as I know giving 0 0 as the major minor number pair causes Linux to just give the device something convenient.
I must be missing something fundamental here, I thought device nodes could be treated as normal files. Can anyone tell me what I'm doing wrong? Ideally I would like to make a character device node that the owner can write to and anyone can read from (I know 777 is the wrong permission here, I'll fix that in the final version).
I also (initially) tried talking to it via Python and that gave me the same issues.
EDIT:
0 0 was the wrong thing to do. I read a thing once that told me it would work, it lied. What I need to do is make a character device module and a node to match then use that
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所有设备都有在驱动程序中定义的特定主设备号和次设备号。您无法将其设置为您想要的任何值,并且
0 0
看起来严重无效。你必须想出有效的方案,也许你就会成功。主要编号和次要编号将节点条目与特定驱动程序联系起来。不,
/dev/*
文件与其他文件不同。它们很特殊,因为内核将输入/输出/控制操作重定向到特定的驱动程序例程。All devices have specific major and minor numbers defined in drivers. You cannot set it to whatever you want, and
0 0
looks severely invalid. You have to come up with valid ones, and maybe then you'll succeed.The major and minor numbers tie the node entry to a specific driver. And no, the
/dev/*
files are not like any others. They are special because the kernels redirects the input/output/control operations to specific driver routines.您确定 0 0 主/次设备标识符吗?
正如此处解释的,
我所说的驱动程序,是内核所看到的驱动程序。
您在示例中尝试做的是创建一个没有任何驱动程序的设备......它将无法工作(正如您已经经历过的那样;))。
为什么需要字符设备?根据您的需要(一名编写者,多名读者),您可以使用命名管道 mkfifo甚至标准文件;)
Are you sure of the 0 0 major/minor device identifiers ?
As explained here,
What I called driver, is a driver as seen by the kernel.
What you're trying to do in your example is to create a device without any driver behind... it will not work (as you already experienced ;) ).
Why do you need a character device ? According to your need (one writer, multiple readers) you could use a named pipe with mkfifo or even standard files ;)