开发者

character device permission issues

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 开发者_Go百科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


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.


Are you sure of the 0 0 major/minor device identifiers ?

As explained here,

  • major number (the first 0 in your command) is the identifier of the driver you want to use for your device.
  • minor number (the second 0 in your command) is the identifier of the device managed by the driver referenced by the major code.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜