kernel module development: how to open block devices and use them (open, seek, read).
Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
kernel module development: how to open block devices and use them (open, seek, read).
Hi!
I'm experimenting with linux module development. I want to open a block device and be able to basically open it, seek it, read from it and close it. Is there an easy example I could follow on how to do it?
First, let me get it off my chest: I do know how to search in google (:-P).
Anyways, though the information I needed was not exactly _there_, your two links were able to point me in the right direction after a while of google and linux code digging (see? I can do it! :-D). If I do make it, I'll let you know of the final results.
Thanks!
PS Just in case someone is looking around here, the keyword is _filp_. Check filp_open and filp_close.
Why? Is block_read() not used for reading block device drivers? I have not got the privilege to use them myself yet, but the tldp site says they are the one!
and this link talks about filp_open being used in character devices??
Keep in mind I'm still a newbie on kernel development (and expect to remain like that for quite a while) but I _think_ the function is not available anymore:
Code:
$ grep -Hni block_read /proc/kallsyms
/proc/kallsyms:6952:c022da60 T block_read_full_page
/proc/kallsyms:27439:c0734380 r __ksymtab_block_read_full_page
/proc/kallsyms:32536:c073d32c r __kcrctab_block_read_full_page
/proc/kallsyms:38048:c0747170 r __kstrtab_block_read_full_page
$
And also I downloaded the whole code of 2.6.32.26 and made a search for the function... perhaps it's been renamed?
Give me some time. I'll check-out my code repository and share you. kernel from 2.4 to 2.6 has major source changes. Also in this book the last page contain source pages. You can search for the function.
I believe what you are trying is very basic level. So you have to checkout the old source. Current kernel source doesn't have single identity. Its being share among the variables. Fully customized with more modules.
tldp document is not updated frequently. Instead we can try the doc section from the kernel source tree. That would be very helpful for the programming.
Anishakaul, prodev05, thanks for your kind feedback. I'll be playing a little bit with filp_open to see where I can get to. I'll be giving you my feedback as I move forward on the small project. Then again, thanks. :-)
Guys, is there a way to find out the size of a file after I open it with filp_open? I'm checking in the file operations and also in the properties of file but found nothing related. The only thing is the size of an inode, but I think file has a list of inodes and not just one to get the size from.
File Size (du -h) can be used in the apps layer on top of the kernel. Inode is the appropriate key to work with the file system functions.
Opening a file to perform some action and the only permitted actions is to read and write. Once the written data is saved then the file size will be committed to allocate the disk space (this result would be expected by Inode to capture and update. Also limitation of blocks will be done here) Until that the written data will be cache, that will be managed by the file system VFS layer.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.