Mapping of Filename to allocated blocks

Manoj Rao linux at manojrajarao.com
Wed Jul 20 21:46:47 EDT 2016


Thanks Arshad, Luis for the response.
This project was on back burner for a while and now it's
coming back to life.

tl;dr: I'm looking for a way to tell if a given inode object
belongs to a persistent block device or not ex: a sysfs node
doesn't have a corresponding block device backing it.

I looked into the source code for hdparm implementation.
I was able to borrow a lot of it and move them in kernel (for
academic purposes only). Here's my (very limited) understanding so
far, hdparm tries to read a storage device's 'geometry' which includes
info such as cylinders, heads, sectors etc. on mechanical disks. One
of the key parameters of a storage device is the start_lba which is
basically the first block on a persistent device that contains data
from a given file. In hdparm, it is able to get this info by simply
reading from the block device's sysfs node, under,
/sys/dev/block/.../start
I intend to do something similar in the kernel by doing something
similar to when the above sysfs node is read. The implementation for
this is partition-generic.c
However, I need to run this for each and every read system call which
includes all the procfs, sysfs and other RAM fs based file reads. My
code is causing the kernel to panic at some point due to an illegal
memory access while trying to obtain the starting sector/block for the
file that's currently being read. My hunch is the crash occurs when
file being read is on a non-persistent fs such as a sysfs node
I have gotten hold of the inode structure and I'm trying to find if
a given inode is stored persistently or not and I've been unable to
find this information so far. I have all the appropriate NULL checks
and each time it crashes the accessed address points a garbage,
non-zero address. Any thoughts or inputs are highly
appreciated. Thanks.

​​
--
​Manoj​


On Wed, Apr 27, 2016 at 8:32 PM, arshad hussain <arshad.super at gmail.com>
wrote:

> On Thu, Apr 28, 2016 at 7:28 AM, Manoj Rao <linux at manojrajarao.com> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160720/a6f83b84/attachment.html 


More information about the Kernelnewbies mailing list