LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   'write_begin' in 'generic_perform_write' function (https://www.linuxquestions.org/questions/linux-kernel-70/write_begin-in-generic_perform_write-function-4175430267/)

s.kr 10-03-2012 07:48 AM

'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.

sundialsvcs 10-03-2012 09:04 AM

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.

s.kr 10-04-2012 03:31 AM

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.

s.kr 10-17-2012 12:09 AM

Hello!

Is there anyone can help me please?

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


thanks.

sundialsvcs 10-17-2012 08:29 AM

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.

zishan.shaikh 10-22-2012 07:33 AM

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.

s.kr 10-24-2012 07:21 AM

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.

zishan.shaikh 10-24-2012 08:17 AM

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

sundialsvcs 10-24-2012 08:19 AM

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.

s.kr 10-26-2012 02:59 AM

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?)


All times are GMT -5. The time now is 04:51 AM.