Linux - KernelThis forum is for all discussion relating to the Linux kernel.
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.
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?
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.
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.
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?
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.
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.
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?)