Resolving data_offset and data_len

Matthew Dillon dillon at
Wed May 27 14:39:42 PDT 2009

:I am currently implementing the `read' call in Linux VFS.
:I have a variable of type `struct hammer_inode' and I would like to get
:the file's offset and length, so I can fetch it from disk using sb_bread().
:The field `ino_leaf' contains `data_offset' and `data_len', which is
:what I am looking for. But these fields currently contain incorrect data.
:I am retrieving the `struct hammer_inode' using a call to
:hammer_get_inode(). I tried inserting hammer_ip_resolve_data(&cursor)
:somewhere into that function, but that didn't help and `ino_leaf' still
:contains incorrect data.
:Any hints or advice?

    The code you want to examine is hammer_vop_strategy_read().  This
    is the core function used by DragonFly to read data from a file.  It
    performs the B-Tree operations necessary to collect the data into
    a buffer.

    Reading the data via the B-Tree is a bit confusing because data_offset 
    in a B-Tree element is *NOT* the base offset for the data block but
    instead the ending offset for the data block.  i.e. the offset in
    the file for the data is actually (cursor.leaf->data_offset -

    The other confusing bit is that HAMMER uses data extents.  Even though
    they aren't completely dynamic they must still be considered
    variable-length, so collecting a buffer requires a B-Tree traversal
    for the offset range.

    You should be able to adapt the hammer_vop_strategy_read() code for
    linux, it does all the hard work.

					Matthew Dillon 
					<dillon at>

More information about the Hammer mailing list