LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 12-06-2010, 08:55 PM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
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?

Thanks in advance.
 
Old 12-07-2010, 09:12 PM   #2
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Check this out:
http://tldp.org/LDP/khg/HyperNews/ge...ces/block.html

and
block_read()
http://www.users.pjwstk.edu.pl/~jms/...lock_read.html

Don't you think it is a high time you should learn how to search Google ?
 
1 members found this post helpful.
Old 12-08-2010, 03:07 AM   #3
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
Thanks for your reply, anishakaul!

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.
 
Old 12-08-2010, 03:18 AM   #4
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
Oh, and people, make sure you read http://kerneltrap.org/node/4717 and http://kernelnewbies.org/FAQ/WhyWrit...romKernelIsBad before going ahead with it.
 
Old 12-08-2010, 03:20 AM   #5
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
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??
 
Old 12-08-2010, 03:28 AM   #6
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
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?
 
Old 12-08-2010, 03:45 AM   #7
prodev05
Member
 
Registered: Jul 2009
Location: Planet Earth
Distribution: Unix & Linux Variants
Posts: 304

Rep: Reputation: 20
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.


reg


Happy Programming
 
Old 12-08-2010, 03:51 AM   #8
prodev05
Member
 
Registered: Jul 2009
Location: Planet Earth
Distribution: Unix & Linux Variants
Posts: 304

Rep: Reputation: 20
anishakaul

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.

reg
 
Old 12-08-2010, 03:58 AM   #9
prodev05
Member
 
Registered: Jul 2009
Location: Planet Earth
Distribution: Unix & Linux Variants
Posts: 304

Rep: Reputation: 20
eantoranz

here is your system call filp_open goto page 484 chapter 17 and there its starts.


Best regards

Happy programming
 
Old 12-08-2010, 03:58 AM   #10
prodev05
Member
 
Registered: Jul 2009
Location: Planet Earth
Distribution: Unix & Linux Variants
Posts: 304

Rep: Reputation: 20
eantoranz

here is your system call filp_open goto page 484 chapter 17 and there its starts.


Best regards

Happy programming
 
Old 12-08-2010, 04:37 AM   #11
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
How about looking into the function named: block_read_full_page(), You must be right, it seems that function has been renamed.

The /fs/buffer.c has its definition.

Last edited by Aquarius_Girl; 12-08-2010 at 04:47 AM.
 
Old 12-08-2010, 09:29 AM   #12
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
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. :-)
 
Old 12-08-2010, 03:57 PM   #13
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
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.
 
Old 12-09-2010, 03:06 AM   #14
prodev05
Member
 
Registered: Jul 2009
Location: Planet Earth
Distribution: Unix & Linux Variants
Posts: 304

Rep: Reputation: 20
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.
 
Old 12-09-2010, 03:14 AM   #15
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Check this out:

stat()
http://linux.die.net/man/2/stat
 
  


Reply

Tags
block devices, linux, module



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Alan Cox on open-source development vs. proprietary development LXer Syndicated Linux News 0 10-25-2007 04:21 PM
LXer: Tools and open standards through Open Source development LXer Syndicated Linux News 0 04-24-2007 01:01 AM
LXer: Open Community Tools: An open stack development platform LXer Syndicated Linux News 0 04-07-2007 01:46 PM
how to open a file inside a kernel module yugandhar Linux - Kernel 2 08-11-2006 06:43 AM
Novell to Open SuSE Pro for open development HenchmenResourc Linux - News 0 08-02-2005 10:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 05:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration