From mboxrd@z Thu Jan 1 00:00:00 1970 From: valdis.kletnieks@vt.edu (valdis.kletnieks at vt.edu) Date: Mon, 22 Oct 2018 07:38:49 -0400 Subject: Modify a file content from block layer In-Reply-To: References: Message-ID: <244318.1540208329@turing-police.cc.vt.edu> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org On Mon, 22 Oct 2018 13:56:27 +0530, jitendra kumar khasdev said: > Is there any way, by which I could write/update the sectors of a file > (which already exist or created in user space) from the block layer > interfaces? As usual, I'm going to start with: Step 0: What problem are you trying to solve by doing this? The problem is that the kernel shouldn't be scribbling on files itself, and that's *extremely* discouraged. The gory details of why basically boil down to "the VFS assumes that all filesytem scribbling is called from a user process context", which causes all sorts of problems if you're in a non-user process context, or a non-process context entirely. The only two in-kernel uses of this that I know of are the acct() system call and the disk quota system - and the case can be made that for the limited case of disk quotas, the file system should do the work. And BSD accounting dates back to before Linux, and when Linux sprouted an acct() system call, there was a good reason to work the same way as the BSD/ SYSV version did it - and even more importantly, it happened *way* before netlink interfaces happened. If we were re-doing it today, netlink would be a slam dunk. Ponder the fact that the kernel is up to over 15M lines of code, and there's only two in-tree users that scribble on files from inside the kernel. If it was a good idea, we'd probably have more examples of it... In general, you'll have a *much* easier time of it if you avoid writing files from within the kernel - see as an alternate design the kernel printk() buffer and the way that dmesg/syslog reads it out to userspace, or the ways that perf gets its data out to userspace. (There's also deep philosophical issues if you're over-writing blocks of a user created file, because users have a very reasonable expectation that if they write a given piece of data into a file system, they get the exact same data back when they read it...) -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 486 bytes Desc: not available URL: