LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 10-03-2012, 07:48 AM   #1
s.kr
LQ Newbie
 
Registered: Oct 2012
Posts: 8

Rep: Reputation: Disabled
Question 'write_begin' in 'generic_perform_write' function


Good Day!


I am looking for the path that write operation happens in kernel.
after some steps I got the 'generic_perform_write': a function in filemap.c file.
This function calls 'write begin' in line 2324(according to lxr).

It seems that different file systems can have different implementation of it('write_begin'). I guess it is possible to access data before it goes to store in this function.

Could you help me please and tell me how I can access data in 'write_begin'. Which input of this function makes data available for me and how?


with many thanks.
 
Old 10-03-2012, 09:04 AM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,665
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
You are seeing one of the first driver-specific calls being made. These are the architecturally-defined points at which the specific behaviors of different file systems may begin to diverge. If you want to intercept the operation, then I suggest that you do it through your own custom-made file system driver ... even if that driver only passes-off most of the calls directly to another one.
 
Old 10-04-2012, 03:31 AM   #3
s.kr
LQ Newbie
 
Registered: Oct 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Thanks for reply.


you know, I am trying to figure out that part of kernel code and my main problem is misunderstanding.

as I mentioned before the 'write_begin' function has 7 inputs:
a file structure
an address-space structure
and ...

I think the data will be available in this function with its input. But I can not find a pointer(or any other way) to that.

Could you help me to find that please?


With many thanks.
 
Old 10-17-2012, 12:09 AM   #4
s.kr
LQ Newbie
 
Registered: Oct 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Hello!

Is there anyone can help me please?

Do you know another related forum that can solve my problem?


thanks.
 
Old 10-17-2012, 08:29 AM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,665
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
You will have to write your own custom driver which somehow locates the real one and re-directs calls to it ... intercepting the write_begin call first.

Left as an exercise to the reader.
 
Old 10-22-2012, 07:33 AM   #6
zishan.shaikh
LQ Newbie
 
Registered: Dec 2011
Location: Pune, India
Distribution: Fedora 17
Posts: 6

Rep: Reputation: Disabled
If you have traced the write flow right from the beginning, you would have observed that the data to be written to the file system is put in the 'iovec' variable in do_sync_write() in fs/read_write.c.
At line 2324 in filemap.c, you can find the data of type 'const char __user *buf' in the 'iov' variable.
After it is passed to the generic_perform_write() function, it is contained in the variable struct iov_iter i.
You can access your data via i->iov struct. Check the structure iovec and you will get what you need, i guess.

Regards,
Zishan.
 
1 members found this post helpful.
Old 10-24-2012, 07:21 AM   #7
s.kr
LQ Newbie
 
Registered: Oct 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Thanks for your answer. It was very helpful.

I want to manipulate data in a file system(yaffs). I want to find a way to access to it. yaffs has its own write_begin and write_end function. Is there anyway to access to data there. I mean iovec is the only way to reach data?
Do you know any other way to manipulate data in file system?

With many thanks.
 
Old 10-24-2012, 08:17 AM   #8
zishan.shaikh
LQ Newbie
 
Registered: Dec 2011
Location: Pune, India
Distribution: Fedora 17
Posts: 6

Rep: Reputation: Disabled
Hi,

I have not worked on yaffs!
Maybe you could try putting printk's in the source, try and print the values which are human readable and then recompile the source! Do some kind of write operation on the file system and observe the log messages.

Regards,
Zishan
 
Old 10-24-2012, 08:19 AM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,665
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
I'll bet there's a macro for this. I'd look thoroughly through the source-code of other similar drivers. It just can't be "hard to do," and it would of course be important to be able to easily and accurately do it right.
 
Old 10-26-2012, 02:59 AM   #10
s.kr
LQ Newbie
 
Registered: Oct 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Thanks for reply again.

sundialsvcs, you are talking about a macro. Which macro do you mean?
I can not understand your meaning. Could you explain more?

I want to manipulate data in the FS. for example I am going to check whether a special word exist in data is going to write or not(exact before write to disk). I want to access data in the file system that have its own write_begin and write_end implementation. As zishan.shaikh said, data is in iovec and it seems that the data does not send to FS. But I have no Idea that how it can be possible: a FS does not get data before write to disk?(or it gets, but I have to search it more?)
 
  


Reply



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
[SOLVED] How can a friend function access a public function from a base class? lesca Programming 1 11-17-2010 01:56 PM
Passing data from interrupt handler function to tasklet function in kernel programmin double-out Programming 2 05-18-2010 10:10 PM
[SOLVED] Threaded function cannot call a function with extern "C" but nonthreaded function can morty346 Programming 16 01-12-2010 05:00 PM
how to print function names & parmaters each time control enters the function? tanniru Linux - Networking 1 09-11-2008 01:21 AM
Compilation issue when Function is parameter in function call on LINUX sa20358 Linux - Software 2 07-24-2008 10:19 PM

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

All times are GMT -5. The time now is 04:48 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