0

As the title asks, how can I I map file IO from a file to an existing device?

I am using a higher level programming language on one of these common SoC single board computers running Linux. This language has a library to access the serial port to send TX and receive RX data. The library accesses /dev/ttyAMA0 to do reading and writing, but unfortunately when you create the Serial object it does so by opening /dev/ttyAMA0 using exclusive access denying other processes or even other instances of the Serial object from using /dev/ttyAMA0.

In my case I wanted to write two separate programs. One program that write to the serial port TX, and another program to read from the serial port RX, but this library won't allow it since its opens /dev/ttyAMA0 using exclusive access. I am thinking with Linux it should be possible to create a second or even a third file which would act as pseudo terminal or something and take any reads or writes and just map all IO access to /dev/ttyAMA0.

So my question is, how can I create a file (or a pseudo tty) on Linux that maps all reads and writes to a device like /dev/ttyAMA0?

0

Assuming /dev/ttyAMA0 is a device node, you could potentially create additional nodes with the same major/minor number which would map to the same device.

For example to do this for /dev/zero, find out what the major & minor numbers are:

carbon# ls -l /dev/zero 
crw-rw-rw- 1 root root 1, 5 May 29 02:16 /dev/zero

Major number is 1, minor number is 5 and the device is a character one.

Create another device node with the same parameters, probably as root:

mknod /dev/zero-dup c 1 5

Now you can use /dev/zero-dup as a copy of /dev/zero.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.