Using O_DIRECT for file writing in a kernel module

From: Hanson, Jonathan M
Date: Fri Feb 11 2005 - 20:00:19 EST


I'm trying to write to a file with the O_DIRECT flag from a
kernel module in a 2.4 series of kernel on x86 hardware. I've learned
that the O_DIRECT flag requires that the amount of data written and the
file offset pointer must be multiples of the underlying "block size."
To try things out I've been successful is writing to a file with
O_DIRECT in user space using multiples of PAGE_SIZE.
However, when I try to do the same from my kernel module I'm
always greeted with an -EINVAL as the return code from the write call
when trying multiples of PAGE_SIZE. Then I realized that the kernel uses
four megabyte pages and not four kilobyte pages so I tried passing four
megabytes of data to the write call but also got -EINVAL in return.
Is it possible to use O_DIRECT to write a file from a kernel
module? If so, what size of data do I need to pass so that it will work?
I've been through Google and the kernel source code but didn't see an
answer as to the size required to get it to work.
Thanks in advance for any assistance offered.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/