From mboxrd@z Thu Jan 1 00:00:00 1970 From: martinez.javier@gmail.com (Javier Martinez Canillas) Date: Tue, 8 Nov 2011 13:08:41 +0100 Subject: Getting a block from a block device? In-Reply-To: References: Message-ID: To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org On Tue, Nov 8, 2011 at 12:06 PM, Dan Luedtke 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