views:

28

answers:

1

Hi Kernel Gurus,

I need to write a kernel module that simulate a "multicaster" Using the /proc file system.

Basically it need to support the following scenarios:

1) allow one write access to the /proc file and many read accesses to the /proc file.

2) The module should have a buffer of the contents last successful write. Each write should be matched by a read from all reader.

Consider scenario 2, a writer wrote something and there are two readers (A and B), A read the content of the buffer, and then A tried to read again, in this case it should go into a wait_queue and wait for the next message, it should not get the same buffer again.

I need to keep a map of all the pid's that already read the current buffer, and in case they try to read again and the buffer was not changed, they should be blocked until there is a new buffer. I'm trying to figure it there is a way i can save that info without a map. I heard there are some redundant fields inside the I/O system the I can use to flag a process if it already read the current buffer.

Can someone give me a tip where should i look for that field ? how can i save info on the current process without keeping a "map" of pid's and buffers ?

Thanks!

+1  A: 

Don't try and keep it based on the PID - that's simply the wrong level of abstraction.

Each time the file is opened there will be a new struct file created that references that instance of the open file. Store the information (the most recent buffer that was read by a given struct file) within the struct file itself.

You can use the private_data pointer within struct file to store the information you need. That's what it's there for.

caf