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
All devices have specific major and minor numbers defined in drivers. You cannot set it to whatever you want, and
0 0looks 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.