Given any file on an ext4 filesystem, it is possible (using filefrag -v) to get the list of real offsets+lengths where that file is located on the underlying block device.
Is it safe to open the device and write to them, all that while the filesystem is mounted read-write? Can it cause fs corruption? I'm asking because I'm going to implement an alternative loop driver, which will bypass the filesystem layer completely, therefore having much better performance.
If I remember correctly, swapfile is implemented exactly that way. Please correct me if told something wrong.
Is the answer filesystem-dependent? What can happen if the file is suddenly deleted, and these offsets become reused for some metadata?
Finally, is there a way to lock a file from being relocated by e4defrag or similar things? What is the best way to prevent a file from being deleted (being in kernel space)? Is there some kernel internals I can use to get the list of file's extents?