Given 2 applications that both read/write to a file for output I m
trying to come up with a way to
let the second application use the output of the first as input.
Both these programs *want* filenames for input & output, so I cant just
program A | program B .. I cant even create a FIFO device and let
the programs use
this for input & output, effectivly doing the same, because the
programs find out they're
talking to a special file with fstat() and try to lseek() and ioctl()
on these 'files' .. generatin a
SIGPIPE or ESPIPE.
So I wanted to make a kernel module for a very simple device .. one that
these applications can
write to or read from , but it also implements lseek and ioctl ..
Let me start by saying .. if there's an easier way to do this, Id love
to hear about it!
but, if there isnt, Ive been trying to do it like this:
open() has a structure with (struct file*) entries for a 'reader' and a
'writer', it decides which 2
processes are trying to hook up with eachother based on the struct
inode argument to open().
Once it has both a reader and a writer it will accept read() and
write() requests; The first process
to make the request ends up at a module_interruptible_sleep_on() loop
which checks for a
complementary request. The second process makes the complementary
request, finds the other
process waiting, the driver performs the copy from user space buffer to
user space buffer,
wakes up the process that was asleep and returns both with the number of
bytes that was transferred.
the lseek() and ioctl() handlers just report whats going on at this
point , lseek() also adjusts
struct file->f_pos to the desired value.
In theory this should work fine, I think .. but in practice the process
thats supposed to write to this
device does :
open( .. O_WRONLY|O_CREATE, .)
FSTAT(5, ....) tells it it's talking to a device
mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE, 429467295 , 0) ???
ioctl(5, TCGETS, 0xbffffb0c ) ??
write(5, ... , 4096)
my device recognizes the open and ioctl() just fine, but never gets
the write. Instead the process
performing the write gets stuck in an uninterruptable wait .
The first thing I dont understand is the fd parameter to mmap(..) ..
that doesnt look like a fd does it ?
Second, the write() .. why doesnt this show up at my driver and where
is the uninterruptable
wait coming from ? Im assuming this is related to the mmap()
Could I just flat out refuse the mmap() ? its not in my Fops structure
now, but maybe thats not good enough ?
open to any suggestions,