In our system we use mmap()
on the /dev/mem
file to access a memory mapped hardware device. However, using this device file requires running the application in superuser mode (sudo
) in order to write to the physical device. We are looking for a way to get rid of this limitation.
Supposedly, one can change the access permissions on the device file. However, this is not a recommended solution.
One suggestion we had is, instead of writing a new, full kernel mode device driver for the hardware, we can duplicate the /dev/mem
device, changing its write permission, and use mmap()
on the new device.
Reading a few manual pages, I found the mknod
command. So I used it to create a special file, emem
, with similar attributes to the /dev/mem
file (esp., the major and Minor versions of the device) . Using the new file in my program, I still needed the duso
. So, I changed its attributes to full r/w permissions, but it did not change the need for sudo
.
Next, I tried changing the permissions of dev/mem
itself to 0777, but it did not help either.
Which leads to the following questions:
Is the need for
sudo
privilege comes from usingmmap()
or from the specific devices it maps?If the former, how to eliminate this?
If the latter, how can I duplicate the
/dev/mem
functionality, with full permissions?