Getting a block from a block device?

Javier Martinez Canillas martinez.javier at gmail.com
Tue Nov 8 07:08:41 EST 2011


On Tue, Nov 8, 2011 at 12:06 PM, Dan Luedtke <maildanrl at googlemail.com> wrote:
> Hallo everyone,
>
> could someone please give me a hint on how to get a block (e.g. 512
> bytes) from a block device from a kernel module?
>
> What .txt should I consult? Which headerfiles must I include?
> Where can I find the required function's definitions?
>
> In userspace I used fopen() with the device path as filename, I bet it
> isn't that easy in kernel mode.
>

Well even when is not considered a good practice, you can invoke the
file operations syscall handlers from your module.

Look at this LJ article: http://www.linuxjournal.com/node/8110/print

But I think that the right question is not _how_ to do it but _why_.

The kernel can't assume a filesystem layout and the location of a file.

Can you tell what are you trying to achieve? Maybe there are better
ways to do it.

Best regards,

-- 
Javier Martínez Canillas
(+34) 682 39 81 69
Barcelona, Spain



More information about the Kernelnewbies mailing list