On 28/04/16 04:32, arshad hussain wrote: > On Thu, Apr 28, 2016 at 7:28 AM, Manoj Rao <linux@xxxxxxxxxxxxxxxx> wrote: >> Hi All, >> >> I'm looking for a way to get a filename associated with a given physical >> block (ideally what I'd like is a mapping of filename <=> all the allocated >> blocks for this file). > > If you have not done already, this could be a good starting point. > Look at FIBMAP IOCTL. > > Here is one usage of FIEMAP, demonstrated via hdparam. > # hdparm --fibmap <your file name> > >> >> Is there a recommended way to do this already in kernel? if not, then where >> should I start looking to add changes? > > Not sure about what would be the Recommended method. But this could be done > in user-space vs doing it in kernel space. For example, consider cases like > single file restore - there will be a requirement to figure out the > logical - physical block allocation for a file which could be achieved > through... > Read superblock > Read dentry - Home into the required inode (file) > Read inode - to figure out the location of block. > > Note: This is not generic - and would require changes as layout is different > for filesystems. > > Thanks > Arshad > If you are going to create anything based on VFS (Virtual File Switch), I recommend reading this article from LWN. https://lwn.net/Articles/57369/ Even create a small memory-bound file system to get comfortable with the API. If you want a version that works with current mainline, check out: https://github.com/luisbg/toy_kernel_modules/blob/master/toyfs/toyfs.c Sorry it doesn't have comments yet, I will be adding those very soon. Happy hacking, Luis _______________________________________________ Kernelnewbies mailing list Kernelnewbies@xxxxxxxxxxxxxxxxx http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies