How to open and write to a block driver within a character driver?

Greg Freemyer greg.freemyer at gmail.com
Thu Oct 6 19:03:03 EDT 2011


On Thu, Oct 6, 2011 at 6:43 PM, Yang Xiang <pointyx at live.com> wrote:
> Hi Greg,
>
> Let me rephrase my question then.
>
> If I am in kernel space and in another device driver and I need to write a
> log entry of some sort to another block device, do I just perform an "open"
> and "write" as if I am in user space?
>
> I am very new at this so bear with me on this.
>
> Thanks in advance.
> yx

First, always post replies at the bottom of messages on kernel mailing
lists. Note how I had to delete much of the earlier thread in order to
reply properly.

Second,

If by log, you mean output text based log messages:

The standard behavior is you log your messages to the  ring buffer.
(kprintf and family will do that for you.)

Then userspace pulls it out of the ring buffer and writes it to a file
(or block device).  Your distro probably uses syslogd or rsyslogd for
the userspace side.  It is highly configurable and you can setup a
dedicated logfile for just you.

If you mean more of a binary transaction log like a filesystem uses,
then it gets more complicated.  There are very few kernel drivers that
maintain a transaction log on a dedicated block device.  I don't know
how they do it, but I'd look at filesystem code the supports an
external partition for the transaction logs.

HTH
Greg (not KH)



More information about the Kernelnewbies mailing list